├── SPOJ-BR ├── BIT.cpp ├── JBUSCA12.cpp ├── QUADRAD2.cpp ├── COMETA2.cpp ├── CORRID12.cpp ├── TAPETE14.cpp ├── PEDAGIO1.cpp ├── DIST13.cpp ├── TOMADA13.cpp ├── TRANSP11.cpp ├── POODLEMG.cpp ├── DADINHOS.cpp ├── OBIHANOI.cpp ├── FATORIA2.cpp ├── F91.cpp ├── JTACOGRA.cpp ├── CHAMADA1.cpp ├── JGANGO14.cpp ├── COLISAO07.cpp ├── JVESTI08.cpp ├── OVERF09.cpp ├── JFLIPE14.cpp ├── GUERRA12.cpp ├── AJUDE14.cpp ├── LINGUA14.cpp ├── INSENS8.cpp ├── SOMA13.cpp ├── PRIMO.cpp ├── ACOES1MG.cpp ├── PAR.cpp ├── TROCO13.cpp ├── JOAOMG.cpp ├── ALIENSMG.cpp ├── AUTO08.cpp ├── CHUVA11.cpp ├── NOTAS14.cpp ├── BACT09.cpp ├── ELEICOES.cpp ├── CAIXAMG.cpp ├── HIST.cpp ├── CHURRASC.cpp ├── PAO07.cpp ├── ACIDO.cpp ├── JFILA14.cpp ├── COSTA12.cpp ├── FUGIT09.cpp ├── SENHATIA.cpp ├── MINADO12.cpp ├── PALAVRMG.cpp ├── ALVO13.cpp ├── PUSAPO11.cpp ├── CARTEI14.cpp ├── FATORIAL.cpp └── SALDO.cpp ├── OBI └── N2 │ ├── 2011 │ └── F2 │ │ └── quadrado.cpp │ ├── 2013 │ └── F2 │ │ └── torneio.cpp │ ├── 2014 │ └── F2 │ │ └── Tapetes.cpp │ ├── 2015 │ └── F2 │ │ ├── chocolate.cpp │ │ └── calculo.cpp │ ├── 2016 │ └── F2 │ │ ├── pokemon.cpp │ │ ├── quase primo.cpp │ │ └── falta um.cpp │ ├── 2017 │ ├── F2 │ │ ├── papel.cpp │ │ └── sequencia.cpp │ ├── F3 │ │ └── postes.cpp │ └── F1 │ │ ├── game10.cpp │ │ └── botas.cpp │ └── 2018 │ ├── F3 │ ├── mancha.cpp │ ├── muro.cpp │ └── bolas.cpp │ ├── F1 │ ├── piso.cpp │ ├── figurinhas.cpp │ └── compensacao.cpp │ └── F2 │ └── elevador.cpp ├── URI ├── 1016.cpp ├── 1958.cpp ├── 1004.cpp ├── 1017.cpp ├── 1387.cpp ├── 1001.cpp ├── 1007.cpp ├── 1014.cpp ├── 2234.cpp ├── 1003.cpp ├── 1067.cpp ├── 1075.cpp ├── 1078.cpp ├── 1095.cpp ├── 1143.cpp ├── 1059.cpp ├── 1073.cpp ├── 1006.cpp ├── 1070.cpp ├── 1142.cpp ├── 1924.cpp ├── 2235.cpp ├── 1011.cpp ├── 1013.cpp ├── 1002.cpp ├── 1060.cpp ├── 1173.cpp ├── 2233.cpp ├── 1079.cpp ├── 1080.cpp ├── 1072.cpp ├── 1542.cpp ├── 2518.cpp ├── 1005.cpp ├── 1015.cpp ├── 1172.cpp ├── 1132.cpp ├── 1008.cpp ├── 1065.cpp ├── 1153.cpp ├── 1035.cpp ├── 1161.cpp ├── 1467.cpp ├── 1019.cpp ├── 1046.cpp ├── 1154.cpp ├── 1020.cpp ├── 1253.cpp ├── 1009.cpp ├── 1012.cpp ├── 1087.cpp ├── 1010.cpp ├── 1174.cpp ├── 2484.cpp ├── 1064.cpp ├── 2242.cpp ├── 1401.cpp ├── 1175.cpp ├── 1177.cpp ├── 1180.cpp ├── 1043.cpp ├── 1074.cpp ├── 1133.cpp ├── 1743.cpp ├── 1051.cpp ├── 1047.cpp ├── 1558.cpp ├── 1071.cpp ├── 1273.cpp ├── 1044.cpp ├── 1808.cpp ├── 2137.cpp ├── 2060.cpp ├── 1066.cpp ├── 1181.cpp ├── 1182.cpp ├── 2238.cpp ├── 2243.cpp ├── 1745.cpp ├── 1151.cpp ├── 1183.cpp ├── 1184.cpp ├── 1566.cpp ├── 1037.cpp ├── 1257.cpp ├── 1750.cpp ├── 1110.cpp ├── 2253.cpp ├── 1101.cpp ├── 1041.cpp ├── 1084.cpp ├── 2023.cpp ├── 1191.cpp └── 2479.cpp ├── Brazillian Summer Camp 2018 ├── Flows and Matchings │ └── statements.pdf ├── Strings Gauntlet │ ├── statements_basic.pdf │ ├── statements_advanced.pdf │ ├── A(Basic).cpp │ ├── C(Basic).cpp │ ├── N(Basic).cpp │ └── D(Basic).cpp └── Geometry Gauntlet │ ├── statements_basic.pdf │ └── statements_advanced.pdf ├── Codeforces ├── Official Rounds │ ├── 101 │ │ └── Div2A.cpp │ ├── 188 │ │ └── Div2C.cpp │ ├── 280 │ │ ├── Div2A.cpp │ │ ├── Div2B.cpp │ │ ├── Div2E.cpp │ │ └── Div2D.cpp │ ├── 291 │ │ └── Div2B.cpp │ ├── 296 │ │ ├── Div2A.cpp │ │ └── Div2D.cpp │ ├── 297 │ │ └── Div2A.cpp │ ├── 298 │ │ └── Div2A.cpp │ ├── 299 │ │ └── Div2B.cpp │ ├── 301 │ │ └── Div2A.cpp │ ├── 302 │ │ └── Div2A.cpp │ ├── 303 │ │ ├── Div2D.cpp │ │ ├── Div2A.cpp │ │ ├── Div2B.cpp │ │ └── Div2C.cpp │ ├── 308 │ │ └── Div2A.cpp │ ├── 309 │ │ └── Div2C.cpp │ ├── 345 │ │ ├── Div2A.cpp │ │ ├── Div2C.cpp │ │ └── Div2B.cpp │ ├── 366 │ │ └── Div2A.cpp │ ├── 372 │ │ └── Div2C.py │ ├── 374 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 375 │ │ └── Div2A.cpp │ ├── 376 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 377 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 378 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 379 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 381 │ │ ├── Div2C.cpp │ │ ├── Div2B.cpp │ │ └── Div2A.cpp │ ├── 382 │ │ ├── Div2C.cpp │ │ ├── Div2D.cpp │ │ └── Div2B.cpp │ ├── 383 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 384 │ │ ├── Div2C.cpp │ │ ├── Div2B.cpp │ │ └── Div2A.cpp │ ├── 385 │ │ └── Div2A.cpp │ ├── 386 │ │ ├── Div2A.cpp │ │ ├── Div2D.cpp │ │ └── Div2B.cpp │ ├── 387 │ │ └── Div2A.cpp │ ├── 388 │ │ ├── Div2B.cpp │ │ ├── Div2A.cpp │ │ └── Div2C.cpp │ ├── 389 │ │ └── Div2A.cpp │ ├── 394 │ │ └── Div2A.cpp │ ├── 396 │ │ └── Div2A.cpp │ ├── 397 │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── 401 │ │ └── Div2A.cpp │ ├── 402 │ │ └── Div2B.cpp │ ├── 403 │ │ └── Div2A.cpp │ ├── 404 │ │ ├── Div2A.cpp │ │ └── Div2C.cpp │ ├── 405 │ │ └── Div2A.cpp │ ├── 410 │ │ └── Div2A.cpp │ ├── 411 │ │ ├── Div2C.cpp │ │ ├── Div2A.cpp │ │ ├── Div2D.cpp │ │ └── Div2B.cpp │ ├── 415 │ │ ├── Div2C.cpp │ │ └── Div2A.cpp │ ├── 420 │ │ ├── Div2B.cpp │ │ └── Div2C.cpp │ ├── 422 │ │ └── Div2A.cpp │ ├── 428 │ │ └── Div2A.cpp │ ├── 435 │ │ └── Div2A.cpp │ ├── 437 │ │ ├── Div2B.cpp │ │ └── Div2A.cpp │ ├── 443 │ │ └── Div2A.cpp │ ├── 449 │ │ └── Div2A.cpp │ ├── 453 │ │ └── Div2A.cpp │ ├── 460 │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── 461 │ │ ├── Div2B.cpp │ │ ├── Div2C.cpp │ │ └── Div2A.cpp │ ├── 472 │ │ └── Div2D.cpp │ ├── 476 │ │ ├── Div2A.cpp │ │ └── Div2D.cpp │ ├── 486 │ │ └── Div3A.cpp │ ├── 491 │ │ └── Div2A.cpp │ ├── 501 │ │ ├── Div3A.cpp │ │ └── Div3C.cpp │ ├── 546 │ │ └── Div2B.cpp │ ├── Kotlin Heroes 4 │ │ └── Practice │ │ │ ├── A.kt │ │ │ ├── C.kt │ │ │ └── B.kt │ ├── Good Bye 2016 │ │ └── A.cpp │ ├── Educational Round 33 │ │ ├── B.cpp │ │ ├── A.cpp │ │ └── D.cpp │ ├── Aim Tech Round 4 │ │ └── Div2A.cpp │ ├── Educational Round 25 │ │ ├── A.cpp │ │ └── C.cpp │ ├── Avito Code Challenge 2018 │ │ ├── A.cpp │ │ └── B.cpp │ ├── Intel Code Challenge │ │ ├── A.cpp │ │ └── B.cpp │ ├── Educational Round 23 │ │ ├── C.cpp │ │ └── A.cpp │ └── Tinkoff Challenge - Elimination Round │ │ └── A.cpp └── Gym │ ├── 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) │ ├── F.cpp │ ├── A.cpp │ ├── K.cpp │ ├── M.cpp │ ├── I.cpp │ └── E.cpp │ ├── 2018 XI Samara Regional Intercollegiate Programming Contest │ ├── A.cpp │ ├── J.cpp │ ├── E.cpp │ └── B.cpp │ ├── 2019 XII Samara Regional Intercollegiate Programming Contest │ ├── I.cpp │ └── C.cpp │ ├── 2018 PSUT Coding Marathon │ └── C.cpp │ ├── Just Programming Contest 4.0 │ ├── J.cpp │ ├── I.cpp │ └── H.cpp │ ├── Just Programming Contest 1.0 │ └── G.cpp │ ├── 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017) │ ├── I.cpp │ ├── J.cpp │ └── F.cpp │ ├── 2016-2017 ACM-ICPC, NEERC, Central Subregional Contest │ └── H.py │ ├── La Salle-Pui Ching Programming Challenge 2017 │ └── A.cpp │ ├── 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) │ └── I.py │ └── La Salle-Pui Ching Programming Challenge 2016 │ ├── K.cpp │ └── B.cpp ├── LeetCode ├── General Problems │ ├── ReverseString.kt │ ├── FindMinimumInRotatedSortedArrayII.cs │ ├── ReverseWordsInAString.kt │ ├── MaximumProductOfThreeNumbers.kt │ ├── BestTimeToBuyAndSellStockII.kt │ ├── HammingDistance.kt │ ├── RemoveDuplicatesFromSortedArray.kt │ ├── AddDigits.cs │ ├── CoinChange.kt │ ├── Pow(x,n).kt │ ├── DetectCapital.cs │ ├── CountGoodTriplets.cpp │ ├── ArrangingCoins.kt │ ├── UglyNumberII.kt │ ├── LongestUncommonSubsequenceII.kt │ ├── MaximumProductOfWordLengths.kt │ ├── SingleNumber.kt │ ├── ShuffleAnArray.kt │ ├── SameTree.kt │ ├── HandOfStraights.kt │ ├── AllPathsFromSourceToTarget.cs │ ├── DecryptStringFromAlphabetToIntegerMapping.kt │ └── TopKFrequentElements.kt └── Contests │ ├── Weekly Contest 194 │ └── XOROperationInAnArray.cpp │ ├── Biweekly Contest 31 │ ├── CountOddNumbersInAnIntervalRange.cpp │ ├── MinimumNumberOfIncrementsOnSubarraysToFormATargetArray.cpp │ └── NumberOfSubarraysWithOddSum.cpp │ ├── Weekly Contest 199 │ ├── ShuffleString.cpp │ └── BulbSwitch.cpp │ ├── Weekly Contest 193 │ ├── RunningSumOf1DArray.cpp │ └── LeastNumberOfUniqueIntegersAfterKRemovals.cpp │ ├── Biweekly Contest 29 │ ├── TheKthFactorOfN.cpp │ └── AverageSalaryExcludingTheMinimumAndMaximumSalary.cpp │ ├── Weekly Contest 192 │ ├── ShuffleTheArray.cpp │ └── TheKStrongestValuesInArray.cpp │ ├── Weekly Contest 196 │ ├── CanMakeArithmeticProgressionFromSequence.cpp │ └── LastMomentBeforeAllAntsFallOutOfAPlank.cpp │ └── Weekly Contest 195 │ ├── CheckIfArrayPairsAreDivisibleByK.cpp │ └── PathCrossing.cpp ├── CSES ├── WeirdAlgorithm.cpp ├── MissingNumber.cpp ├── Repetitions.cpp ├── NumberSpiral.cpp ├── RemovalGame.cpp ├── IncreasingArray.cpp ├── ChessboardAndQueens.cpp ├── StickGame.cpp └── IncreasingSubsequence.cpp ├── Codechef ├── March Challenge 2018 │ └── MIXCOLOR.cpp └── March Lunchtime 2018 │ └── ZOZ.cpp ├── AtCoder ├── AGC23 │ └── A.cpp ├── EducationalDPContest │ ├── A.cpp │ └── K.cpp ├── ARC95 │ └── D.cpp ├── ARC96 │ └── C.cpp └── ARC93 │ └── C.cpp └── SPOJ ├── NOTATRI.cpp ├── FARIDA.cpp ├── IOIPALIN.cpp ├── ORGNZ.cpp ├── EDIST.cpp ├── COINS.cpp ├── KNAPSACK.cpp └── AIBOHP.cpp /SPOJ-BR/BIT.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /OBI/N2/2017/F2/papel.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/OBI/N2/2017/F2/papel.cpp -------------------------------------------------------------------------------- /OBI/N2/2018/F3/mancha.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/OBI/N2/2018/F3/mancha.cpp -------------------------------------------------------------------------------- /OBI/N2/2013/F2/torneio.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/OBI/N2/2013/F2/torneio.cpp -------------------------------------------------------------------------------- /URI/1016.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a; 5 | scanf("%d",&a); 6 | printf("%d minutos\n",a*2); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /URI/1958.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | long double numero; 5 | scanf("%lf",&numero); 6 | printf("%+.4E\n",numero); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /URI/1004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a,b; 5 | scanf("%d\n%d",&a,&b); 6 | printf("PROD = %d\n",a*b); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /URI/1017.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a,b; 5 | scanf("%d\n%d",&a,&b); 6 | printf("%.3lf\n",(a*b)/12.0); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Flows and Matchings/statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/Brazillian Summer Camp 2018/Flows and Matchings/statements.pdf -------------------------------------------------------------------------------- /URI/1387.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int esq,dir; 5 | while(scanf("%d %d",&esq,&dir), esq+dir!=0) printf("%d\n",esq+dir); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Strings Gauntlet/statements_basic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/Brazillian Summer Camp 2018/Strings Gauntlet/statements_basic.pdf -------------------------------------------------------------------------------- /SPOJ-BR/JBUSCA12.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n,res; 6 | scanf("%d",&n); 7 | res=n*4; 8 | printf("%d\n",res); 9 | return(0); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /SPOJ-BR/QUADRAD2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x,res; 6 | scanf("%d",&x); 7 | res=x*x; 8 | printf("%d\n",res); 9 | return(0); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Geometry Gauntlet/statements_basic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/Brazillian Summer Camp 2018/Geometry Gauntlet/statements_basic.pdf -------------------------------------------------------------------------------- /SPOJ-BR/COMETA2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | cout << 76-(n-1986)%76 + n << endl; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /SPOJ-BR/CORRID12.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int c,n,res; 6 | scanf("%d %d",&c,&n); 7 | res=c%n; 8 | printf("%d\n",res); 9 | return(0); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Geometry Gauntlet/statements_advanced.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/Brazillian Summer Camp 2018/Geometry Gauntlet/statements_advanced.pdf -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Strings Gauntlet/statements_advanced.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bira37/problem-solving/HEAD/Brazillian Summer Camp 2018/Strings Gauntlet/statements_advanced.pdf -------------------------------------------------------------------------------- /Codeforces/Official Rounds/411/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | cout << (n+1)/2 -1 << endl; 9 | } 10 | -------------------------------------------------------------------------------- /URI/1001.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int x,y; 6 | cin >> x >> y; 7 | cout << "X = " << x+y << endl; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /URI/1007.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a,b,c,d; 5 | scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d); 6 | printf("DIFERENCA = %d\n",(a*b-c*d)); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /URI/1014.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int km; 5 | double gas; 6 | scanf("%d\n%lf",&km,&gas); 7 | printf("%.3f km/l\n",km/gas); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /URI/2234.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | double x,y; 7 | cin >> x >> y; 8 | printf("%.2lf\n",x/y); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /SPOJ-BR/TAPETE14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n,m; 7 | cin >> n >> m; 8 | cout << m-1 + (n-m+1)*(n-m+1) << endl; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /URI/1003.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int x,y; 7 | cin >> x >> y; 8 | cout << "SOMA = " << x+y << endl; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/546/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | cin >> n >> k; 8 | cout << 3*n + min(n - k, k-1) << endl; 9 | } -------------------------------------------------------------------------------- /URI/1067.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x,i=1; 5 | scanf("%d",&x); 6 | while(i<=x) { 7 | printf("%d\n",i); 8 | i+=2; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /URI/1075.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i,n; 5 | scanf("%d",&n); 6 | for(i=1;i<10000;i++) { 7 | if(i%n == 2) printf("%d\n",i); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /URI/1078.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n,i; 5 | scanf("%d",&n); 6 | for(i=1;i<=10;i++){ 7 | printf("%d x %d = %d\n",i,n,n*i); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /URI/1095.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i=1,j=60; 5 | while(j>=0) { 6 | printf("I=%d J=%d\n",i,j); 7 | i+=3; 8 | j-=5; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /OBI/N2/2014/F2/Tapetes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | int l,n; 7 | cin>>l>>n; 8 | int r=n-1+(l-n+1)*(l-n+1); 9 | cout< 2 | 3 | int main() 4 | { 5 | int c,d,k,v,soma; 6 | scanf("%d %d\n%d %d",&c,&d,&k,&v); 7 | soma= ((c/d)*v) + (k*c); 8 | printf("%d\n",soma); 9 | return(0); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /SPOJ-BR/DIST13.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a1,a2,b1,b2,res; 6 | scanf("%d %d %d %d",&a1,&a2,&b1,&b2); 7 | res= abs(b1-a1)+abs(b2-a2); 8 | printf("%d\n",res); 9 | return(0); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /URI/1143.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | for(int i=1; i<=n; i++){ 9 | cout << i << " " << i*i << " " << i*i*i << endl; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/411/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int l,r; 7 | cin >> l >> r; 8 | if(l == r) cout << l << endl; 9 | else cout << 2 << endl; 10 | } 11 | -------------------------------------------------------------------------------- /URI/1059.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int numero=2; 5 | while(numero<=100) { 6 | if(numero%2==0) 7 | printf("%d\n",numero); 8 | numero++; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /URI/1073.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | long long x,i=2; 5 | scanf("%lld",&x); 6 | while(i<=x){ 7 | printf("%lld^2 = %lld\n",i,i*i); 8 | i+=2; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /SPOJ-BR/TOMADA13.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t1,t2,t3,t4,soma; 6 | scanf("%d %d %d %d",&t1,&t2,&t3,&t4); 7 | soma=t1+t2+t3+t4-3; 8 | printf("%d\n",soma); 9 | return(0); 10 | } 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SPOJ-BR/TRANSP11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b,c,x,y,z,soma; 6 | scanf("%d %d %d\n%d %d %d",&a,&b,&c,&x,&y,&z); 7 | soma=(x/a)*(y/b)*(z/c); 8 | printf("%d\n",soma); 9 | return(0); 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /SPOJ-BR/POODLEMG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,p; 7 | while(cin >> n >> p, n +p != 0) cout << "Poo" << string(max(min((n/p + (n%p != 0))-6, 14), 0), 'o') << "dle" << endl; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /URI/1006.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | double a,b,c,resultado; 5 | scanf("%lf\n%lf\n%lf",&a,&b,&c); 6 | resultado= ((a*2.0)+(b*3.0)+(c*5.0))/10; 7 | printf("MEDIA = %.1lf\n",resultado); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /LeetCode/General Problems/ReverseString.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun reverseString(s: CharArray): Unit { 3 | var n : Int = s.size 4 | for(i in 0 until n / 2) 5 | s[i] = s[n - i - 1].also {s[n - i - 1] = s[i]} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /SPOJ-BR/DADINHOS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x1,x2,x3; 5 | scanf("%d %d %d",&x1,&x2,&x3); 6 | while(x1+x2+x3!=0) { 7 | printf("%d\n",x1*x2*x3); 8 | scanf("%d %d %d",&x1,&x2,&x3); 9 | } 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /SPOJ-BR/OBIHANOI.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | long long n,teste=1,x,i; 5 | while(scanf("%lld",&n), n!=0){ 6 | x=1; 7 | for(i=0;i 2 | 3 | int main() { 4 | int x,i,j; 5 | scanf("%d",&x); 6 | if(x%2==0) i=x+1; 7 | else x=i; 8 | for(j=0;j<6;j++) { 9 | printf("%d\n",i); 10 | i+=2; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /URI/1142.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int k = 1; 9 | for(int i=0; i 2 | 3 | int main() { 4 | char str[101]; 5 | int n,i; 6 | scanf("%d",&n); 7 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int a,b,c; 7 | cin >> a >> b >> c; 8 | if(a == b || b == c || a==c || a+b == c || a+c == b || b+c == a) cout << "S" << endl; 9 | else cout << "N" << endl; 10 | } 11 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/384/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n; 7 | cin >> n; 8 | if(n == 1) cout << -1 << endl; 9 | else cout << n << " " << n+1 << " " << n*(n+1) << endl; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /LeetCode/General Problems/FindMinimumInRotatedSortedArrayII.cs: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public int FindMin(int[] nums) { 3 | int ans = nums[0]; 4 | for(int i=0; i 2 | #define pi 3.14159 3 | 4 | int main() { 5 | long long int raio; 6 | double soma; 7 | scanf("%lld",&raio); 8 | soma=(4.0/3)*pi*(raio*raio*raio); 9 | printf("VOLUME = %.3lf\n",soma); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /URI/1013.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a,b,c,maior,maior2; 5 | scanf("%d %d %d",&a,&b,&c); 6 | maior=(a+b+abs(a-b))/2; 7 | maior2=(maior+c+abs(maior-c))/2; 8 | printf("%d eh o maior\n",maior2); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/397/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | string x; 8 | cin >> n; 9 | for(int i=0; i> x; 11 | } 12 | cout << (n%2 ? "contest" : "home") << endl; 13 | } 14 | -------------------------------------------------------------------------------- /URI/1002.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | #define PI 3.14159 7 | 8 | int main() { 9 | double x; 10 | cin >> x; 11 | cout << "A=" << fixed << setprecision(4) << x*x*PI << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /URI/1060.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i,cont=0; 5 | float num; 6 | for(i=0;i<6;i++) { 7 | scanf("%f",&num); 8 | if(num>0) cont++; 9 | } 10 | printf("%d valores positivos\n",cont); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/386/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long a,b,c; 7 | cin >> a >> b >> c; 8 | 9 | long long ans = min(a, min(b/2, c/4)); 10 | 11 | cout << 1*ans + 2*ans + 4*ans << endl; 12 | } 13 | -------------------------------------------------------------------------------- /SPOJ-BR/FATORIA2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fat(int a){ 4 | if(a>1) return a*fat(a-1); 5 | return a; 6 | } 7 | 8 | int main(){ 9 | int a; 10 | scanf("%d",&a); 11 | if(a==0) printf("%d\n",a+1); 12 | else printf("%d\n",fat(a)); 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /LeetCode/General Problems/ReverseWordsInAString.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun reverseWords(s: String): String { 3 | var arr : MutableList = s.trim().split("\\s+".toRegex()).toMutableList() 4 | arr.reverse() 5 | return arr.joinToString(" ") 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /SPOJ-BR/F91.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f91(int n){ 4 | if(n<=100) f91(f91(n+11)); 5 | else return n-10; 6 | } 7 | 8 | int main(void) { 9 | int n,x; 10 | while(scanf("%d",&n),n!=0){ 11 | x=f91(n); 12 | printf("f91(%d) = %d\n",n,x); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /SPOJ-BR/JTACOGRA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin >> n; 7 | int soma =0; 8 | for(int i=0; i> x >> y; 11 | soma += x*y; 12 | } 13 | cout << soma << endl; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/405/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long a,b; 7 | cin >> a >> b; 8 | int ans =0; 9 | while(a <= b){ 10 | ans++; 11 | a = a*3; 12 | b = b*2; 13 | } 14 | cout << ans << endl; 15 | } 16 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/396/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | string x,y; 8 | cin >> x >> y; 9 | if(x == y) cout << -1 << endl; 10 | else cout << max(x.size(), y.size()) << endl; 11 | } 12 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/422/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int fat(int n){ 6 | if(n <= 1) return 1; 7 | else return n*fat(n-1); 8 | } 9 | 10 | int main(){ 11 | int a,b; 12 | cin >> a >> b; 13 | cout << fat(min(a,b)) << endl; 14 | } 15 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 194/XOROperationInAnArray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int xorOperation(int n, int start) { 4 | int x = 0; 5 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | cin >> n >> k; 8 | cin.ignore(); 9 | string v[n]; 10 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int p1,c1,p2,c2; 7 | cin >> p1 >> c1 >> p2 >> c2; 8 | if(p1*c1 == p2*c2) cout << 0 << endl; 9 | else if(p1*c1 < p2*c2) cout << 1 << endl; 10 | else cout << -1 << endl; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /URI/1173.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int vet[10],i; 5 | scanf("%d",&vet[0]); 6 | printf("N[0] = %d\n",vet[0]); 7 | for(i=1;i<=9;i++) { 8 | vet[i]=vet[i-1]*2; 9 | printf("N[%d] = %d\n",i,vet[i]); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /URI/2233.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long a,b,c; 7 | scanf("%llx %llx %llx", &a, &b, &c); 8 | long long x = (a/b)*(a/b); 9 | long long y = (b/c)*(b/c); 10 | long long res = x*y + x + 1; 11 | printf("%llx\n", res); 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Kotlin Heroes 4/Practice/A.kt: -------------------------------------------------------------------------------- 1 | fun main(args: Array) { 2 | var (t) = readLine()!!.split(' ').map({it.toInt()}); 3 | while(t > 0){ 4 | t--; 5 | var (a, b) = readLine()!!.split(' ').map({it.toInt()}); 6 | println(a+b); 7 | } 8 | 9 | } 10 | 11 | -------------------------------------------------------------------------------- /OBI/N2/2018/F1/piso.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int L,C; 8 | cin>>L>>C; 9 | int A1,A2; 10 | A1=2*L*C-L-C+1; 11 | A2=2*(L+C-2); 12 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | while(n--){ 9 | 10 | double a,b,c; 11 | cin >> a >> b >> c; 12 | cout << fixed << setprecision(1); 13 | cout << (a*2.0 + b*3.0 + c*5.0)/10.0 << endl; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LeetCode/General Problems/MaximumProductOfThreeNumbers.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maximumProduct(nums: IntArray): Int { 3 | nums.sort() 4 | nums.reverse() 5 | var len = nums.size 6 | return maxOf(nums[0]*nums[1]*nums[2], nums[len-1]*nums[len-2]*nums[0]) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /OBI/N2/2017/F3/postes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int s=0,c=0; 7 | int aux; 8 | for(int i=0;i>aux; 10 | if(aux<50){ 11 | s++; 12 | }else if(aux<85)c++; 13 | } 14 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int max = 0, pos = 0; 7 | for(int i=0; i<100; i++){ 8 | int x; 9 | cin >> x; 10 | if(x > max){ 11 | pos = i+1; 12 | max = x; 13 | } 14 | } 15 | cout << max << endl << pos << endl; 16 | } 17 | -------------------------------------------------------------------------------- /URI/1072.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n,x,in=0,out=0; 5 | scanf("%d",&n); 6 | while(n-- > 0) { 7 | scanf("%d",&x); 8 | if(x<=20 && x>=10) in++; 9 | else out++; 10 | } 11 | printf("%d in\n%d out\n",in,out); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /URI/1542.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int q,d,p; 7 | while(cin >> q, q){ 8 | cin>> d >> p; 9 | int res = abs(d*p*q/(q-p)); 10 | cout << res; 11 | if(res > 1) cout << " paginas" << endl; 12 | else cout << " pagina" << endl; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /URI/2518.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | double n; 7 | while(cin >> n){ 8 | double h,c,l; 9 | cin >> h >> c >> l; 10 | double hip = sqrt(c*c+h*h); 11 | cout << fixed << setprecision(4) << (hip*l*n)/10000. << endl; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Codeforces/Gym/2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | char a,p,b,e,c; 7 | cin >> a >> p >> b >> e >> c; 8 | if(a + b - '0' == c) cout << "YES" << endl; 9 | else cout << "NO" << endl; 10 | } 11 | -------------------------------------------------------------------------------- /LeetCode/Contests/Biweekly Contest 31/CountOddNumbersInAnIntervalRange.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOdds(int low, int high) { 4 | if(low == 0) low = 1; 5 | int val = high-low+1; 6 | int even = high/2 - (low-1)/2; 7 | return (val - even); 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /SPOJ-BR/COLISAO07.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int x1,x2,x3,x4,y1,y2,y3,y4; 7 | cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; 8 | 9 | if(x2 < x3 || y2 < y3 || x4 < x1 || y4 < y1) cout << 0 << endl; 10 | else cout << 1 << endl; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /SPOJ-BR/JVESTI08.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string x; 6 | int n, cont = 0; 7 | cin >> n; 8 | cin >> x; 9 | for(int i=0; i> y; 12 | if(y==x[i]) cont ++; 13 | } 14 | cout << cont << endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /URI/1005.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | #define PI 3.14159 7 | 8 | int main() { 9 | double x,y; 10 | cin >> x >> y; 11 | double m=(x*3.5+y*7.5)/11; 12 | cout << "MEDIA = " << fixed << setprecision(5) << m << endl; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/384/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n, k; 7 | long long ans; 8 | 9 | cin >> n >> k; 10 | ans = 1; 11 | while(k>0 && k%2 == 0){ 12 | ans++; 13 | k = k/2; 14 | } 15 | 16 | cout << ans << endl; 17 | } 18 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 199/ShuffleString.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string restoreString(string s, vector& indices) { 4 | string ans = s; 5 | for(int i=0; i 2 | #include 3 | 4 | int main() 5 | { 6 | float x1,x2,y1,y2,resultado; 7 | scanf("%f %f\n%f %f",&x1,&y1,&x2,&y2); 8 | resultado= sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));/* calcula a distancia entre 2 pontos */ 9 | printf("%.4f\n",resultado); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /URI/1172.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int vet[10],i; 5 | for(i=0;i<=9;i++) { 6 | scanf("%d",&vet[i]); 7 | if(vet[i]<=0) 8 | vet[i]=1; 9 | } 10 | for(i=0;i<=9;i++) { 11 | printf("X[%d] = %d\n",i,vet[i]); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/377/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | cin >> n >> k; 8 | int count = 1; 9 | int price = n; 10 | while(price%10 != k && price%10 != 0){ 11 | count++; 12 | price += n; 13 | } 14 | cout << count << endl; 15 | } 16 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/443/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int ans = 0; 9 | for(int i=0; i> s >> d; 12 | while(s <= ans) s+=d; 13 | ans = s; 14 | } 15 | cout << ans << endl; 16 | } 17 | -------------------------------------------------------------------------------- /SPOJ-BR/OVERF09.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int n; 8 | int x1,x2; 9 | char op; 10 | cin >> n >> x1 >> op >> x2; 11 | if(op == '+') x1+=x2; 12 | else x1*=x2; 13 | if(x1 <= n) cout << "OK" << endl; 14 | else cout << "OVERFLOW" << endl; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /URI/1132.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n,i,m,sum=0; 5 | scanf("%d %d",&n,&m); 6 | if(n>m) { 7 | for(i=m;i<=n;i++) if(i%13!=0) sum+=i; 8 | } 9 | else { 10 | for(i=n;i<=m;i++) if(i%13!=0) sum+=i; 11 | } 12 | printf("%d\n",sum); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/101/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string a,b,c; 7 | cin >> a >> b >> c; 8 | a += b; 9 | sort(a.begin(), a.end()); 10 | sort(c.begin(), c.end()); 11 | if(a == c) cout << "YES" << endl; 12 | else cout << "NO" << endl; 13 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/379/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int k2,k3,k5,k6; 7 | cin >> k2 >> k3 >> k5 >> k6; 8 | int num256 = min(min(k2,k5),k6); 9 | k2 = max(0, k2-num256); 10 | int num32 = min(k2,k3); 11 | cout << 256*num256 + 32*num32 << endl; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/379/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int k2,k3,k5,k6; 7 | cin >> k2 >> k3 >> k5 >> k6; 8 | int num256 = min(min(k2,k5),k6); 9 | k2 = max(0, k2-num256); 10 | int num32 = min(k2,k3); 11 | cout << 256*num256 + 32*num32 << endl; 12 | } 13 | -------------------------------------------------------------------------------- /URI/1008.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int numeroFuncionario, tempoTrabalho; 5 | float salarioHora; 6 | scanf("%d\n%d\n%f",&numeroFuncionario,&tempoTrabalho,&salarioHora); 7 | printf("NUMBER = %d\nSALARY = U$ %.2f\n",numeroFuncionario,tempoTrabalho*salarioHora); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /URI/1065.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num; 5 | int contadorPar=0,i; 6 | for(i=1;i<=5;i++) { 7 | scanf("%d",&num); 8 | if(num%2==0) { 9 | contadorPar++; 10 | } 11 | } 12 | printf("%d valores pares\n",contadorPar); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /URI/1153.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int numero,i,fat=1; 5 | scanf("%d",&numero); 6 | if(numero==1) 7 | printf("1\n"); 8 | else { 9 | for(i=2;i<=numero;i++) { 10 | fat*=i; 11 | } 12 | printf("%d\n",fat); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 193/RunningSumOf1DArray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector runningSum(vector& nums) { 4 | vector ans; 5 | ans.push_back(nums[0]); 6 | for(int i=1; i 2 | 3 | int main() { 4 | int in1,in2; 5 | scanf("%d %d",&in1,&in2); 6 | if(in1==1) { 7 | if(in2==1) { 8 | printf("A\n"); 9 | } 10 | else if(in2==0) { 11 | printf("B\n"); 12 | } 13 | } 14 | else if(in1==0) { 15 | printf("C\n"); 16 | } 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /URI/1035.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a,b,c,d,flag=0; 5 | scanf("%d %d %d %d",&a,&b,&c,&d); 6 | if((b>c)&&(d>a)&&(c+d>a+b)&&(c>0)&&(d>0)&&(a%2==0)) flag=1; 7 | if(flag==1) 8 | printf("Valores aceitos\n"); 9 | else printf("Valores nao aceitos\n"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /URI/1161.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | unsigned long long fat(unsigned long long n){ 6 | if(n == 1 || n == 0) return 1; 7 | else return n*fat(n-1); 8 | } 9 | 10 | int main(){ 11 | unsigned long long n,m; 12 | while(cin >> n >> m){ 13 | cout << fat(n) + fat(m) << endl; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /URI/1467.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a,b,c; 5 | while(scanf("%d %d %d",&a,&b,&c)!=EOF){ 6 | if(a==b && a==c) printf("*\n"); 7 | else if(a==c) printf("B\n"); 8 | else if(b==c) printf("A\n"); 9 | else if(a==b) printf("C\n"); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/394/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | int n,m; 8 | cin >> n >> m; 9 | if(n == 0 && m == 0) cout << "NO" << endl; 10 | else if(abs(n-m) <= 1) cout << "YES" << endl; 11 | else cout << "NO" << endl; 12 | } 13 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/372/Div2C.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | lst = 0 4 | for i in range(n): 5 | if i == 0: 6 | print(2) 7 | lst = 2 8 | else: 9 | j = i+1 10 | #print('lst = ' + str(lst)) 11 | #print('want = ' + str((j*(j+1))**2)) 12 | print((((j*(j+1))**2) - lst)//j) 13 | lst = ((j*(j+1))) 14 | 15 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/376/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | cin >> x; 8 | char ini = 'a'; 9 | int k = 0; 10 | for(int i=0; i v; 5 | for(int i=1; i<=n; i++){ 6 | if(n%i == 0) v.push_back(i); 7 | } 8 | if(v.size() < k) return -1; 9 | else return v[k-1]; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /URI/1019.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int tempo,h=0,m=0; 5 | scanf("%d",&tempo); 6 | while(tempo>=3600){ 7 | tempo-=3600; 8 | h++; 9 | } 10 | while(tempo>=60){ 11 | tempo-=60; 12 | m++; 13 | } 14 | printf("%d:%d:%d\n",h,m,tempo); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/375/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int a,b,c; 7 | vector v; 8 | cin >> a; 9 | cin >> b; 10 | cin >> c; 11 | v.push_back(a); 12 | v.push_back(b); 13 | v.push_back(c); 14 | sort(v.begin(), v.end()); 15 | cout << v[2] - v[0] << endl; 16 | } 17 | -------------------------------------------------------------------------------- /LeetCode/General Problems/BestTimeToBuyAndSellStockII.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maxProfit(prices: IntArray): Int { 3 | var ans : Int = 0 4 | var lst : Int = Int.MAX_VALUE 5 | for(x in prices){ 6 | ans += maxOf(0, x - lst) 7 | lst = x 8 | } 9 | return ans 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SPOJ-BR/GUERRA12.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int v[n]; 9 | int sum = 0; 10 | for(int i=0; i> v[i]; 12 | sum+= v[i]; 13 | } 14 | int i =0; 15 | int aux = 0; 16 | while(aux < sum/2) aux+=v[i++]; 17 | cout << i << endl; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 192/ShuffleTheArray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector shuffle(vector& nums, int n) { 4 | vector v; 5 | for(int i=0, j = n; i < n; i++, j++){ 6 | v.push_back(nums[i]); 7 | v.push_back(nums[j]); 8 | } 9 | return v; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /LeetCode/General Problems/HammingDistance.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun hammingDistance(x: Int, y: Int): Int { 3 | var hammer = 0 4 | for(i in 0..31){ 5 | var a = (x and (1 shl i)) 6 | var b = (y and (1 shl i)) 7 | if(a != b) hammer++ 8 | } 9 | return hammer 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /URI/1046.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int ini,fim,res; 5 | scanf("%d %d",&ini,&fim); 6 | if(fim-ini==0) { 7 | res=24; 8 | } 9 | else if(ini<24 && fim 2 | 3 | int main() { 4 | int idade,somaIdade=0,contadorEntrada=0; 5 | scanf("%d",&idade); 6 | while(idade>=0) { 7 | somaIdade+=idade; 8 | contadorEntrada+=1; 9 | scanf("%d",&idade); 10 | } 11 | printf("%.2f\n",(somaIdade*1.0)/contadorEntrada); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /CSES/WeirdAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef pair pii; 4 | 5 | 6 | int main(){ 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | long long n; 10 | cin>>n; 11 | while(n!=1){ 12 | cout< 2 | 3 | int main() { 4 | int pessoas,conta,soma=0,teste,i; 5 | scanf("%d",&pessoas); 6 | for(i=0;i 2 | 3 | int main() { 4 | int tempo,a=0,m=0; 5 | scanf("%d",&tempo); 6 | while(tempo>=365){ 7 | tempo-=365; 8 | a++; 9 | } 10 | while(tempo>=30){ 11 | tempo-=30; 12 | m++; 13 | } 14 | printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",a,m,tempo); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /URI/1253.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | string x; 8 | cin >> n; 9 | while(n--){ 10 | cin >> x; 11 | cin >> k; 12 | for(int i=0; i 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | int s,g; 7 | cin >> s >> g; 8 | if(s%g || s == g){ 9 | cout << -1 << endl; 10 | return 0; 11 | } 12 | int mul = s/g; 13 | 14 | cout << g << " " << s-g << endl; 15 | } 16 | -------------------------------------------------------------------------------- /SPOJ-BR/LINGUA14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | char c; 8 | bool flag = false; 9 | while(cin >> x, c = getchar()){ 10 | if(!flag) flag = true; 11 | else cout << " "; 12 | for(int i=0; i 2 | 3 | int main() { 4 | char nome[200]; 5 | double salarioNormal,totalVendas,totalSalario; 6 | scanf("%s\n%lf\n%lf",&nome,&salarioNormal,&totalVendas); 7 | totalSalario=salarioNormal+(totalVendas*15.0)/100; //calcula o salário com bônus 8 | printf("TOTAL = R$ %.2lf\n",totalSalario); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /LeetCode/General Problems/RemoveDuplicatesFromSortedArray.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun removeDuplicates(nums: IntArray): Int { 3 | var t : Int = 0 4 | for(i in 1..nums.size-1){ 5 | if(nums[i] != nums[t]){ 6 | t++; 7 | nums[t] = nums[i]; 8 | } 9 | } 10 | return t+1; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /URI/1012.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | double A,B,C; 5 | scanf("%lf %lf %lf",&A,&B,&C); 6 | printf("TRIANGULO: %.3lf\n",(A*C)/2.0); 7 | printf("CIRCULO: %.3lf\n",3.14159*(C*C)); 8 | printf("TRAPEZIO: %.3lf\n",((A+B)*C)/2.0); 9 | printf("QUADRADO: %.3lf\n",B*B); 10 | printf("RETANGULO: %.3lf\n",A*B); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /URI/1087.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int x1,y1,x2,y2; 7 | while(cin >> x1 >> y1 >> x2 >> y2, x1+x2+y1+y2!=0){ 8 | if(x1==x2 && y1 == y2) cout << 0 << endl; 9 | else if(abs(x1-x2) == abs(y1-y2)) cout << 1 << endl; 10 | else if(x1==x2 || y1 == y2) cout << 1 << endl; 11 | else cout << 2 << endl; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/461/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int ans = 0; 9 | for(int i=1; i<=n; i++){ 10 | for(int j = i; j <= n; j++){ 11 | int x = (i^j); 12 | if(x <= n && x >= j && (i+j) > x) ans++; 13 | } 14 | } 15 | cout << ans << endl; 16 | } -------------------------------------------------------------------------------- /LeetCode/General Problems/AddDigits.cs: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | private int f(int n){ 3 | int cur = 0; 4 | while(n > 0){ 5 | cur += n%10; 6 | n /= 10; 7 | } 8 | if(cur < 10) return cur; 9 | else return f(cur); 10 | } 11 | public int AddDigits(int num) { 12 | return f(num); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SPOJ-BR/INSENS8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x1,x2,y1,y2,i,soma=0,objetos,xsoma,ysoma; 5 | scanf("%d",&objetos); 6 | for(i=0;i 2 | 3 | int calculamdc(int x,int y){ 4 | if(y==0) return x; 5 | return calculamdc(y,x%y); 6 | } 7 | 8 | int main(){ 9 | int a1,b1,a2,b2,a,b,d; 10 | scanf("%d %d %d %d",&a1,&b1,&a2,&b2); 11 | a=(a1*b2+a2*b1); 12 | b=(b1*b2); 13 | d=calculamdc(a,b); 14 | a=a/d; 15 | b=b/d; 16 | printf("%d %d\n",a,b); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/383/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | long long n; 8 | cin >> n; 9 | if(n == 0) cout << 1 << endl; 10 | else if(n % 4 == 1) cout << 8 << endl; 11 | else if(n % 4 == 2) cout << 4 << endl; 12 | else if(n % 4 == 3) cout << 2 << endl; 13 | else if(n % 4 == 0) cout << 6 << endl; 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/476/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); cout.tie(0); 8 | 9 | int k,n,s,p; 10 | cin >> k >> n >> s >> p; 11 | 12 | int totp = (n+s-1)/s; 13 | 14 | totp *= k; 15 | 16 | cout << (totp+p-1)/p << endl; 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /URI/1010.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int numPeca,codigoPeca; 5 | float valorPeca,soma=0; 6 | scanf("%d %d %f\n",&codigoPeca,&numPeca,&valorPeca); 7 | soma+=(numPeca*valorPeca); 8 | scanf("%d %d %f",&codigoPeca,&numPeca,&valorPeca); 9 | soma+=(numPeca*valorPeca); 10 | printf("VALOR A PAGAR: R$ %.2f\n",soma); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /URI/1174.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | float *vet=(float*)malloc(sizeof(float)*100); 6 | int i; 7 | for(i=0;i<100;i++) { 8 | scanf("%f",&vet[i]); 9 | } 10 | for(i=0;i<100;i++) { 11 | if(vet[i]<=10) { 12 | printf("A[%d] = %.1f\n",i,vet[i]); 13 | } 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /URI/2484.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | while(cin >> x){ 8 | for(int i=0; i = MutableList(amount+1) {0} 4 | dp[0] = 1 5 | for(c in coins){ 6 | for(j in 0..amount-c){ 7 | dp[j+c] += dp[j] 8 | } 9 | } 10 | return dp[amount] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /URI/1064.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | float num,somaNum=0; 5 | int contadorPos=0,i; 6 | for(i=1;i<=6;i++) { 7 | scanf("%f",&num); 8 | if(num>0) { 9 | contadorPos++; 10 | somaNum+=num; 11 | } 12 | } 13 | printf("%d valores positivos\n%.1f\n",contadorPos,(somaNum*1.0)/contadorPos); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /URI/2242.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x,y; 7 | string c; 8 | cin >> c; 9 | for(int i=0, len = c.size(); i< len; i++){ 10 | if(c[i] == 'a' || c[i]== 'e' || c[i]== 'i' || c[i]== 'o' || c[i]== 'u') x+=c[i]; 11 | } 12 | y = x; 13 | reverse(x.begin(), x.end()); 14 | if(x==y) cout << 'S' << endl; 15 | else cout << 'N' << endl; 16 | } 17 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/461/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n,k; 7 | cin >> n >> k; 8 | set s; 9 | for(long long i =1; i<=min(k, 1000LL); i++){ 10 | if(s.count(n%i)){ 11 | cout << "No" << endl; 12 | return 0; 13 | } 14 | s.insert(n%i); 15 | } 16 | cout << "Yes" << endl; 17 | } -------------------------------------------------------------------------------- /CSES/MissingNumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int n; 6 | set conj; 7 | int aux; 8 | scanf("%d",&n); 9 | for(int i=1;i 2 | #define int long long 3 | #define endl '\n' 4 | using namespace std; 5 | 6 | signed main(){ 7 | ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 8 | int a,b; 9 | cin >> a >> b; 10 | int rem = (a%b); 11 | int tot = (a*a - b*b - rem*rem); 12 | cout << (tot+b-1)/b + rem << endl; 13 | } 14 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/280/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int PA(int n){ 6 | return (n*(n+1))/2; 7 | } 8 | 9 | int main(){ 10 | int n; 11 | cin >> n; 12 | if(n == 1) cout << 1 << endl; 13 | else { 14 | int ans = 0; 15 | for(int i=1, k = 1; i<=1000; i++, k+=PA(i)){ 16 | if(k <= n) ans = i; 17 | } 18 | cout << ans << endl; 19 | } 20 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/382/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | unsigned long long n; 8 | cin >> n; 9 | unsigned long long a=1,b=1,sum = 0; 10 | unsigned long long res = 1; 11 | sum = a+b; 12 | while(sum < n){ 13 | res++; 14 | a = b; 15 | b = sum; 16 | sum = a + b; 17 | } 18 | if(sum > n) res--; 19 | cout << res << endl; 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/460/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,m; 7 | cin >> n >> m; 8 | double ans = 10000000000000.00; 9 | for(int i=0; i> a >> b; 12 | ans = min(ans, m*(double)(a)/(double)(b)); 13 | } 14 | cout << fixed << setprecision(10); 15 | cout << ans << endl; 16 | } -------------------------------------------------------------------------------- /OBI/N2/2015/F2/chocolate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int met = n/2; 7 | int x1,y1,x2,y2; 8 | cin>>x1>>y1; 9 | cin>>x2>>y2; 10 | int x = min(x1,x2); 11 | int X = max(x1,x2); 12 | int y = min(y1,y2); 13 | int Y = max(y1,y2); 14 | if((x<=met && X>met )|| (y<=met && Y>met))cout<<"S"< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string str; 7 | int n; 8 | cin >> n; 9 | while(n--){ 10 | cin >> str; 11 | sort(str.begin(), str.end()); 12 | do { 13 | cout << str << endl; 14 | } while( next_permutation(str.begin(), str.end())); 15 | cout << endl; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Codeforces/Gym/2018 PSUT Coding Marathon/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int ans = 0; 4 | deque dq; 5 | int n; 6 | 7 | int32_t main(){ 8 | scanf("%d" , &n); 9 | for(int i = 0 ; i < n;i ++){ 10 | int x; 11 | scanf("%d" , &x); 12 | while(dq.size() && dq.back() <= x) dq.pop_back() ; 13 | if(dq.empty()) ans++; 14 | dq.push_back(x); 15 | } 16 | printf("%d\n" , ans); 17 | } 18 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/437/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ROOT 1 4 | 5 | using namespace std; 6 | 7 | 8 | int main(){ 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(0); 11 | int n; 12 | cin >> n; 13 | if(n == 1){ 14 | cout << "1 1" << endl << "1" << endl; 15 | return 0; 16 | } 17 | int k = 2*(n-1); 18 | cout << k << " " << 2 << endl; 19 | cout << "1 2" << endl; 20 | } 21 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 196/CanMakeArithmeticProgressionFromSequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canMakeArithmeticProgression(vector& arr) { 4 | sort(arr.begin(), arr.end()); 5 | int diff = arr[1] - arr[0]; 6 | for(int i=1; i 2 | #define MAXN 70 3 | #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 4 | using namespace std; 5 | 6 | int D[MAXN]; 7 | int E[MAXN]; 8 | int main(){ 9 | fastio; 10 | int N,A,D; 11 | cin>>N>>A>>D; 12 | int res=0; 13 | if(A>=D){ 14 | res=A-D; 15 | }else{ 16 | res=N-D+A; 17 | } 18 | 19 | cout< 2 | 3 | int main() { 4 | int vet[20],fim,i,aux; 5 | for(i=0;i<=19;i++) { 6 | scanf("%d",&vet[i]); 7 | } 8 | fim=19; 9 | for(i=0;i<=9;i++) { 10 | aux=vet[i]; 11 | vet[i]=vet[fim]; 12 | vet[fim]=aux; 13 | fim--; 14 | } 15 | for(i=0;i<=19;i++) { 16 | printf("N[%d] = %d\n",i,vet[i]); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /URI/1177.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int vet[1000],limite,i=0,cont=0; 5 | scanf("%d",&limite); 6 | while(i<1000) { 7 | if(cont=limite) { 12 | cont=0; 13 | } 14 | printf("N[%d] = %d\n",i,vet[i]); 15 | i++; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /URI/1180.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int vet[1000],i,tamanho,menor=1000000,posicao=0; 5 | scanf("%d",&tamanho); 6 | for(i=0;i<=tamanho-1;i++) { 7 | scanf("%d",&vet[i]); 8 | if(vet[i] 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int x1,x2,x3,y1,y2,y3; 8 | cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; 9 | cout << 3 << endl; 10 | cout << (x2 - x1) + x3 << " " << (y2 - y1)+ y3 << endl; 11 | cout << (x3 - x2) + x1 << " " << (y3 - y2)+ y1 << endl; 12 | cout << (x1 - x3) + x2 << " " << (y1 - y3)+ y2 << endl; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Good Bye 2016/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | int max = 240; 8 | int n,t; 9 | cin >> n >> t; 10 | int time = max - t; 11 | int ans = 0; 12 | for(int i=1; i<=n; i++){ 13 | if(5*i <= time){ 14 | ans++; 15 | time -= 5*i; 16 | } 17 | else break; 18 | } 19 | cout << ans << endl; 20 | } 21 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 195/CheckIfArrayPairsAreDivisibleByK.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canArrange(vector& arr, int k) { 4 | multiset s; 5 | for(int x : arr){ 6 | int y = (x%k + k)%k; 7 | if(s.find((k-y)%k) != s.end()) s.erase(s.find((k-y)%k)); 8 | else s.insert(y); 9 | } 10 | return s.size() == 0; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /URI/1043.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | float c,b,a,resultado; 5 | scanf("%f %f %f",&a,&b,&c); 6 | if((a 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 7 | int t; 8 | cin >> t; 9 | while(t--){ 10 | 11 | int n; 12 | set s; 13 | cin >> n; 14 | for(int i=0; i> x; 17 | s.insert(x); 18 | } 19 | cout << n - s.size() << endl; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/411/Div2D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MOD 1000000007 3 | 4 | using namespace std; 5 | 6 | 7 | int main(){ 8 | long long cnt = 0, ans = 0; 9 | string str; 10 | cin >> str; 11 | for(int i= str.size()-1; i>=0; i--){ 12 | if(str[i] == 'b') cnt= (cnt+1)%MOD; 13 | else { 14 | ans = (ans + cnt)%MOD; 15 | cnt = (cnt*2)%MOD; 16 | } 17 | } 18 | cout << ans << endl; 19 | } 20 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/280/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, l; 7 | cin >> n >> l; 8 | int v[n]; 9 | for(int i=0; i> v[i]; 10 | sort(v,v+n); 11 | double ans = max(v[0], l - v[n-1]); 12 | for(int i=1; i 2 | 3 | int main() { 4 | int n,x; 5 | scanf("%d",&n); 6 | while(n-- > 0) { 7 | scanf("%d",&x); 8 | if(x==0) printf("NULL\n"); 9 | else { 10 | if(x%2==0) printf("EVEN "); 11 | else printf("ODD "); 12 | if(x<0) printf("NEGATIVE\n"); 13 | else printf("POSITIVE\n"); 14 | } 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Codeforces/Gym/Just Programming Contest 4.0/J.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 1000000007 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | scanf("%d", &t); 8 | while(t--){ 9 | int n; 10 | scanf("%d", &n); 11 | long long acc = 1; 12 | for(int i=0; i& target) { 5 | 6 | long long bef = 0; 7 | long long ans = 0; 8 | for(int x : target){ 9 | ans += max(0LL, (long long)(x-bef)); 10 | bef = x; 11 | } 12 | return ans; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /SPOJ-BR/PRIMO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | long long n,i; 6 | scanf("%lld",&n); 7 | if(n<0) n=n*(-1); 8 | long double raiz=sqrt(n); 9 | if(n==2) printf("sim\n"); 10 | else if(n==1 || n%2 == 0) printf("nao\n"); 11 | else { 12 | for(i=3;i<=raiz;i+=2) 13 | if(n%i==0){ 14 | printf("nao\n"); 15 | goto ret; 16 | } 17 | printf("sim\n"); 18 | } 19 | ret:return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/387/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long int n; 7 | cin >> n; 8 | long long int a,b; 9 | a = 1; 10 | b= n; 11 | long long int pa=1,pb=n; 12 | while(a <= b){ 13 | while(a*b < n) a++; 14 | if(a*b == n){ 15 | pa = a; 16 | pb = b; 17 | } 18 | b--; 19 | } 20 | if(pa > pb) swap(pa,pb); 21 | cout << pa << " " << pb << endl; 22 | } 23 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/411/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | string ax = "aa"; 9 | string bx = "bb"; 10 | string a = "a"; 11 | string b = "b"; 12 | while(n>0){ 13 | if(n > 1){ 14 | cout << ax; 15 | n-=2; 16 | } 17 | else{ 18 | cout << a; 19 | n--; 20 | } 21 | swap(ax,bx); 22 | swap(a,b); 23 | } 24 | cout << endl; 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/461/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int x,y; 7 | cin >> y >> x; 8 | x--; 9 | if(x < 0){ 10 | cout << "No" << endl; 11 | return 0; 12 | } 13 | if(x == 0 && y > 0){ 14 | cout << "No" << endl; 15 | return 0; 16 | } 17 | y -= x; 18 | if(y%2 || y < 0) cout << "No" << endl; 19 | else cout << "Yes" << endl; 20 | } -------------------------------------------------------------------------------- /CSES/Repetitions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | string str; 7 | cin>>str; 8 | int maxi=0; 9 | int atual=0; 10 | char antigo='B'; 11 | for(int i=0;i<(int)str.size();i++){ 12 | if(str[i]==antigo){ 13 | atual++; 14 | } else{ 15 | antigo=str[i]; 16 | atual=1; 17 | } 18 | 19 | 20 | maxi=max(maxi,atual); 21 | } 22 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int ans; 9 | for(int i=1; i<=n; i++){ 10 | if(n%i == 0){ 11 | bool flag = false; 12 | for(int j=1; j<=15; j++){ 13 | if(((1< 2 | 3 | int calculaCompra(int n,int k){ 4 | if(n>k){ 5 | if(n-n/2 <= k) return 2; 6 | else if(n/2 <= k) return 1+ calculaCompra(n-n/2,k); 7 | else return calculaCompra(n/2,k) + calculaCompra(n-n/2,k); 8 | } 9 | else return 1; 10 | } 11 | 12 | int main(){ 13 | int n,k; 14 | while(scanf("%d %d",&n,&k), n!=0 || k!=0){ 15 | printf("%d\n",calculaCompra(n,k)); 16 | } 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Codeforces/Gym/2018 XI Samara Regional Intercollegiate Programming Contest/J.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int v[212345]; 9 | for(int i=0; i<212345; i++) v[i] = 0; 10 | for(int i=0; i> x; 13 | v[x]++; 14 | } 15 | 16 | int ans = 0; 17 | 18 | for(int i=0; i<212345; i++) ans += v[i]/2; 19 | 20 | cout << ans/2 << endl; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/345/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int a,b; 7 | cin >> a >> b; 8 | int ans = 0; 9 | 10 | while(true){ 11 | 12 | if(a > b) swap(a,b); 13 | if(a == 0 || b <= 1) break; 14 | a += 1; 15 | a = min(a, 100); 16 | b-=2; 17 | ans++; 18 | //cout << a << " " << b << endl; 19 | } 20 | 21 | cout << ans << endl; 22 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/388/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | int n; 8 | cin >> n; 9 | if(n%2 == 0){ 10 | cout << n/2 << endl; 11 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string par, impar; 7 | int n; 8 | int t = 0; 9 | while(cin >> n, n != 0){ 10 | if(t != 0) cout << endl; 11 | 12 | cin >> par >> impar; 13 | cout << "Teste " << ++t << endl; 14 | for(int i=0; i> x >> y; 17 | if((x+y)%2) cout << impar << endl; 18 | else cout << par << endl; 19 | } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /URI/1133.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int lim1,lim2,i,aux; 5 | scanf("%d %d",&lim1,&lim2); 6 | if(lim1>lim2) { //caso o segundo numero da entrada seja menor que o primeiro, eles sao trocados 7 | aux=lim1; 8 | lim1=lim2; 9 | lim2=aux; 10 | } 11 | for(i=lim1+1;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | bool v1[5],v2[5],v3[5]; 7 | for(int i=0; i<5; i++){ 8 | cin >> v1[i]; 9 | } 10 | for(int i=0; i<5; i++){ 11 | cin >> v2[i]; 12 | } 13 | for(int i=0; i<5; i++){ 14 | v3[i] = v1[i]^v2[i]; 15 | } 16 | int ans = 1; 17 | for(int i=0; i<5; i++){ 18 | ans = ans & v3[i]; 19 | } 20 | if(ans) cout << "Y" << endl; 21 | else cout << "N" << endl; 22 | } 23 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/297/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | multiset k; 9 | string s; 10 | cin >> s; 11 | int ans = 0; 12 | for(int i=0; i<2*n-2; i++){ 13 | if(i%2 == 0) k.insert(s[i] - 32); 14 | else { 15 | if(k.count(s[i])){ 16 | k.erase(k.find(s[i])); 17 | } 18 | else ans++; 19 | } 20 | } 21 | cout << ans << endl; 22 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/366/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define int long long 6 | 7 | int32_t main(){ 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(0); cout.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | 14 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | map words; 8 | cin >> x; 9 | int ans = 0; 10 | for(int i=0, len = x.size(); i 2 | #include 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 6 | int n,c,m; 7 | cin>>n>>c>>m; 8 | set S; 9 | for(int i=0;i>x; 12 | S.insert(x); 13 | } 14 | for(int i=0;i>x; 17 | if(S.find(x)!=S.end())S.erase(x); 18 | } 19 | cout< 2 | 3 | int main() { 4 | float x,soma=0; 5 | scanf("%f",&x); 6 | if(x<=2000.00) printf("Isento\n"); 7 | else { 8 | if(x>4500) { 9 | soma+=(x-4500)*0.28; 10 | x=x-(x-4500); 11 | } 12 | if(x>3000) { 13 | soma+=(x-3000)*0.18; 14 | x=x-(x-3000); 15 | } 16 | if(x>2000) { 17 | soma+=(x-2000)*0.08; 18 | x=x-(x-2000); 19 | } 20 | printf("R$ %.2f\n",soma); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /AtCoder/AGC23/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define int long long 5 | using namespace std; 6 | 7 | int32_t main(){ 8 | int n; 9 | map m; 10 | cin >> n; 11 | int v[n]; 12 | for(int i=0; i> v[i]; 13 | int sum = 0; 14 | int ans = 0; 15 | m[0]++; 16 | for(int i=0; i 2 | #define double long double 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | scanf("%d", &t); 8 | while(t--){ 9 | double oa, od, oda, obc; 10 | scanf("%Lf%Lf%Lf%Lf", &oa, &od, &oda, &obc); 11 | 12 | double k = sqrt(obc/oda); 13 | 14 | double oc = oa*k; 15 | double ob = od*k; 16 | 17 | printf("%.9Lf %.9Lf\n", oc - od, ob - oa); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/397/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | char last; 8 | cin >> x; 9 | if(x[0] == 'a') last = 'a'; 10 | else{ 11 | cout << "NO" << endl; 12 | return 0; 13 | } 14 | for(int i=1; i x[i]) last = max(x[i],last); 16 | else { 17 | cout << "NO" << endl; 18 | return 0; 19 | } 20 | } 21 | 22 | cout << "YES" << endl; 23 | } 24 | -------------------------------------------------------------------------------- /SPOJ-BR/TROCO13.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int n,v; 8 | cin >> n >> v; 9 | int dp[n+1]; 10 | for(int i = 0; i<=n; i++) dp[i] = -1; 11 | dp[0] = 0; 12 | for(int i=0; i> coin; 15 | for(int k = n-coin; k>=0; k--){ 16 | if(dp[k] != -1) dp[k+coin] = 0; 17 | } 18 | } 19 | 20 | if(dp[n] == 0) cout << "S" << endl; 21 | else cout << "N" << endl; 22 | } 23 | -------------------------------------------------------------------------------- /SPOJ/NOTATRI.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | while(cin >> n, n != 0){ 8 | int ans = 0; 9 | int v[n]; 10 | for(int i=0; i> v[i]; 12 | } 13 | sort(v,v+n); 14 | for(int i=0; i 2 | 3 | int main() { 4 | int h1,m1,h2,m2; 5 | int h=0,m=0; 6 | scanf("%d %d %d %d",&h1,&m1,&h2,&m2); 7 | if(h2>=h1) h=h2-h1; 8 | else { 9 | h=24-h1; 10 | if(h==24) h=0; 11 | h=h+h2; 12 | } 13 | if(h==0) h=24; 14 | if(m2>=m1) m=m2-m1; 15 | else { 16 | m=60-m1; 17 | if(m==60) m=0; 18 | h--; 19 | m=m+m2; 20 | } 21 | printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",h,m); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /URI/1558.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | int n; 8 | while(cin >> n){ 9 | bool flag = false; 10 | for(int i=0, len = sqrt(n); i<=len && !flag; i++){ 11 | int resto = n - i*i; 12 | int raiz = sqrt(resto); 13 | if(raiz*raiz == resto){ 14 | cout << "YES" << endl; 15 | flag = true; 16 | } 17 | } 18 | if(!flag) cout << "NO" << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/381/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int min = 0x3f3f3f3f; 8 | int n,m; 9 | cin >> n >> m; 10 | int a,b; 11 | for(int i =0; i> a >> b; 13 | if((b-a) < min) min = b-a; 14 | } 15 | min++; 16 | cout << min << endl; 17 | 18 | for(int i=0; i& salary) { 4 | int mn = 11234567; 5 | int mx = 0; 6 | int s = 0; 7 | for(int x : salary){ 8 | mn = min(mn, x); 9 | mx = max(mx, x); 10 | s += x; 11 | } 12 | return (double)(s - mn - mx)/(double)(salary.size()-2); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 196/LastMomentBeforeAllAntsFallOutOfAPlank.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int getLastMoment(int n, vector& left, vector& right) { 4 | int mx = 0; 5 | for(int x : left){ 6 | int dst = x; 7 | mx = max(mx, dst); 8 | } 9 | for(int x : right){ 10 | int dst = n-x; 11 | mx = max(mx, dst); 12 | } 13 | return mx; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/298/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | if(n <= 2) cout << 1 << endl << 1 << endl; 9 | else if(n == 3) cout << "2" << endl << "1 3" << endl; 10 | else { 11 | cout << n << endl; 12 | for(int i=2; i<=n; i+=2) cout << i << " "; 13 | for(int i=1; i<=n; i+=2) cout << i << " "; 14 | cout << endl; 15 | } 16 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/378/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | cin >> x; 8 | int maximo = 0, last = 0, sum = 0; 9 | x = x + "A"; 10 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | #define int long long 6 | 7 | int32_t main(){ 8 | int a,b,c,n; 9 | cin >> a >> b >> c >> n; 10 | a -= c; 11 | b -= c; 12 | if(a < 0 || b < 0){ 13 | cout << -1 << endl; 14 | return 0; 15 | } 16 | 17 | n -= (a+b+c); 18 | if(n <= 0){ 19 | cout << -1 << endl; 20 | return 0; 21 | } 22 | 23 | cout << n << endl; 24 | } -------------------------------------------------------------------------------- /SPOJ-BR/JOAOMG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n; 7 | whi: while(cin >> n, n){ 8 | long long aux = n*n; 9 | for(int i=1;i <= aux; i*=10){ 10 | int p1 = aux/i; 11 | int p2 = aux%i; 12 | if(p1 + p2 == n && p1 > 0 && p2 > 0){ 13 | cout << n << ": S" << endl; 14 | goto whi; 15 | } 16 | } 17 | if(n==1) cout << n << ": S" << endl; 18 | else cout << n << ": N" << endl; 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/437/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | string s; 8 | cin >> n; 9 | cin >> s; 10 | char last = s[0]; 11 | int cnt1 = 0, cnt2=0; 12 | for(int i=1; icnt2) cout << "YES" << endl; 18 | else cout << "NO" << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /OBI/N2/2016/F2/pokemon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 3 | #define pb push_back 4 | #define int long long 5 | using namespace std; 6 | 7 | int32_t main(){ 8 | fastio; 9 | int x; 10 | cin>>x; 11 | int v[3]; 12 | cin>>v[0]>>v[1]>>v[2]; 13 | sort(v,v+3); 14 | int r=0; 15 | for(int i=0;i<3;i++){ 16 | if(x>=v[i]){ 17 | r++; 18 | x-=v[i]; 19 | } 20 | } 21 | cout< 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | int n; 10 | while(cin >> n, n!=0){ 11 | string dna; 12 | set arvore; 13 | for(int i=0; i < n; i++){ 14 | cin >> dna; 15 | sort(dna.begin(),dna.end()); 16 | arvore.insert(dna); 17 | } 18 | 19 | cout << arvore.size() << endl; 20 | } 21 | return 0; 22 | } 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /SPOJ-BR/AUTO08.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char c; 5 | int contador=0; 6 | int n,i; 7 | scanf("%d\n",&n); 8 | i=1; 9 | while(i<=n) 10 | { 11 | scanf("%c",&c); 12 | switch(c) 13 | { 14 | case 'A':{ contador+=1; 15 | break; 16 | } 17 | case 'C':{ contador+=2; 18 | break; 19 | } 20 | case 'P':{ contador+=2; 21 | break; 22 | } 23 | } 24 | i++; 25 | } 26 | printf("%d\n",contador); 27 | return(0); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Codeforces/Gym/2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | int n ; 8 | cin>>n; 9 | vector v(n); 10 | for(int i = 0 ; i < n; i ++) cin>>v[i]; 11 | int x; 12 | int minmod = (int) 1e9 , vl = -1; 13 | cin>>x; 14 | for(int i = 0 ; i < n; i++){ 15 | if((x % v[i] )< minmod){ 16 | minmod = x%v[i]; 17 | vl = i; 18 | } 19 | } 20 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int k,a,b; 7 | cin >> k >> a >> b; 8 | if(a != 0 && a%k == 0 && b < k) cout << a/k << endl; 9 | else if(b != 0 && b%k == 0 && a < k) cout << b/k << endl; 10 | else if(a > k && a%k != 0 && b < k) cout << -1 << endl; 11 | else if(b > k && b%k != 0 && a < k) cout << -1 << endl; 12 | else if(b >= k && a >= k) cout << a/k + b/k << endl; 13 | else cout << -1 << endl; 14 | } 15 | -------------------------------------------------------------------------------- /LeetCode/General Problems/DetectCapital.cs: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public bool DetectCapitalUse(string word) { 3 | bool first = (word[0] >= 'A' && word[0] <= 'Z'); 4 | int capital = 0; 5 | for(int i=1; i= 'A' && word[i] <= 'Z') capital++; 7 | } 8 | 9 | if(capital == 0) return true; 10 | if(first && capital == word.Length-1) return true; 11 | return false; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /URI/1071.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int limiteMIN, limiteMAX, i,j,k; 6 | int soma=0; 7 | scanf("%d\n%d",&limiteMIN,&limiteMAX); 8 | if(limiteMIN>=limiteMAX){ 9 | i=limiteMAX; 10 | j=limiteMIN; 11 | } 12 | else { 13 | i=limiteMIN; 14 | j=limiteMAX; 15 | } 16 | for(k=i+1; k 2 | #define int long long 3 | using namespace std; 4 | 5 | vector num; 6 | 7 | void gen(int n){ 8 | num.push_back(n); 9 | if(10*n + 4 <= 1000000000) gen(10*n + 4); 10 | if(10*n + 7 <= 1000000000) gen(10*n + 7); 11 | } 12 | 13 | int32_t main(){ 14 | int n; 15 | cin >> n; 16 | gen(0); 17 | sort(num.begin(), num.end()); 18 | 19 | cout << lower_bound(num.begin(), num.end(), n) - num.begin() << endl; 20 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Aim Tech Round 4/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | set s; 7 | string x; 8 | cin >> x; 9 | int k; 10 | cin >> k; 11 | int cont =0; 12 | for(int i=0; i 2 | using namespace std; 3 | 4 | vector v; 5 | 6 | int check(){ 7 | for(int i=0;i<(int)v.size()-1;i++){ 8 | if(v[i+1]-v[i] >8)return false; 9 | } 10 | return true; 11 | } 12 | 13 | int main(){ 14 | int n; 15 | cin>>n; 16 | v.push_back(0); 17 | for(int i=0;i>x;v.push_back(x);} 18 | sort(v.begin(),v.end()); 19 | if(check()){ 20 | cout<<"S"< 2 | 3 | int main(){ 4 | int i,j,n; 5 | scanf("%d",&n); 6 | int a[n][n],somador; 7 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); cout.tie(0); 8 | 9 | int n; 10 | cin >> n; 11 | vector v(n); 12 | for(int i=0; i> v[i]; 13 | sort(v.begin(), v.end()); 14 | 15 | int sum = 0; 16 | int ans = 0; 17 | for(int i=0; i= sum){ 19 | ans++; 20 | sum += v[i]; 21 | } 22 | } 23 | cout << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /SPOJ-BR/NOTAS14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int n,i,entrada,notas[200],frequencia=0,maior=0; 5 | for(i=0;i<201;i++){ 6 | notas[i]=0; 7 | } 8 | scanf("%d",&n); 9 | for(i=0;imaior)){ 15 | maior=i; 16 | frequencia=notas[i]; 17 | } 18 | } 19 | printf("%d\n",maior); 20 | return 0; 21 | } 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /URI/1273.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | bool flag = false; 8 | while(cin >> n, n){ 9 | if(flag) cout << endl; 10 | if(!flag) flag = true; 11 | vector v(n); 12 | int maior = 0; 13 | for(int i =0; i> v[i]; 15 | int tam = v[i].size(); 16 | maior = max(maior, tam); 17 | } 18 | 19 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | int ans = 0; 8 | cin >> n; 9 | string s; 10 | cin >> s; 11 | int cont = 0; 12 | for(int i=0; i 2 | #include 3 | 4 | int main() { 5 | int num,gera,tempo,i,pos,resp; 6 | double maior; 7 | scanf("%d",&num); 8 | scanf("%d %d",&gera,&tempo); 9 | maior= tempo*log10(gera); 10 | pos=0; 11 | resp=0; 12 | for(i=1;i 2 | 3 | int main() { 4 | int numeroA, numeroB; 5 | scanf("%d %d",&numeroA,&numeroB); 6 | if(numeroA>=numeroB) { 7 | if(numeroA%numeroB==0) 8 | printf("Sao Multiplos\n"); 9 | else 10 | printf("Nao sao Multiplos\n"); 11 | } 12 | else { 13 | if(numeroB%numeroA==0) 14 | printf("Sao Multiplos\n"); 15 | else 16 | printf("Nao sao Multiplos\n"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /URI/1808.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string a; 7 | cin >> a; 8 | char x; 9 | int cont = 0; 10 | double total = 0; 11 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin >> s; 8 | int n = s.size(); 9 | s = '0' + s; 10 | int dp[n+1]; 11 | 12 | dp[0] = 0; 13 | int mx = 0; 14 | for(int i=1; i<=n; i++){ 15 | dp[i] = 0; 16 | for(int j=0; j<=i-1; j++) if(s[i] > s[j]) dp[i] = max(dp[i], dp[j]+1); 17 | mx = max(dp[i], mx); 18 | } 19 | 20 | cout << 26 - mx << endl; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/381/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,nsub; 7 | cin >> n >> nsub; 8 | int mood[n]; 9 | long long res = 0; 10 | for(int i=0; i> mood[i]; 12 | } 13 | for(int i=0; i> a >> b; 16 | a--; b--; 17 | int aux = 0; 18 | for(int j=a; j<=b; ++j){ 19 | aux += mood[j]; 20 | } 21 | if(aux > 0) res += aux; 22 | } 23 | 24 | cout << res << endl; 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Avito Code Challenge 2018/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin >> s; 8 | string t = s; 9 | reverse(t.begin(), t.end()); 10 | if(s != t){ 11 | cout << s.size() << endl; 12 | return 0; 13 | } 14 | s.pop_back(); 15 | t = s; 16 | reverse(t.begin(), t.end()); 17 | if(s != t){ 18 | cout << s.size() << endl; 19 | return 0; 20 | } 21 | 22 | cout << 0 << endl; 23 | } -------------------------------------------------------------------------------- /LeetCode/Contests/Biweekly Contest 31/NumberOfSubarraysWithOddSum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numOfSubarrays(vector& arr) { 4 | int v[2]; 5 | v[0] = v[1] = 0; 6 | int ans = 0; 7 | int s = 0; 8 | v[0] = 1; 9 | for(int x : arr){ 10 | s += x; 11 | if(s%2) ans += v[0]; 12 | else ans += v[1]; 13 | v[s%2]++; 14 | ans %= 1000000007; 15 | } 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /OBI/N2/2017/F2/sequencia.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int abs(int x){ 5 | if(x<0)return -x; 6 | return x; 7 | } 8 | 9 | int main(){ 10 | int n; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | int res=1; 15 | int ant = a[0]; 16 | int atual=1; 17 | for(int i=1;i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | map candidato; 9 | int n,maior=0; 10 | string r; 11 | cin >> n; 12 | for(int i=0; i < n; i++){ 13 | cin >> r; 14 | candidato[r]++; 15 | } 16 | r=candidato.begin()->first; 17 | for(pair x : candidato){ 18 | if(x.second > maior){ 19 | maior = x.second; 20 | r=x.first; 21 | } 22 | } 23 | cout << r << endl; 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /URI/2137.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | /** 8 | * Escreva a sua solução aqui 9 | * Code your solution here 10 | * Escriba su solución aquí 11 | */ 12 | int n; 13 | while(cin>>n){ 14 | string vet[n]; 15 | for(int i=0; i> vet[i]; 17 | } 18 | sort(vet,vet+n); 19 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n,k; 7 | cin >> n >> k; 8 | vector v; 9 | for(int i=0; i> x; 12 | v.push_back(x); 13 | } 14 | sort(v.begin(), v.end()); 15 | int ans = 0; 16 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin >> t; 8 | int c2=0,c3=0,c4=0,c5=0; 9 | for(int i=0; i> x; 12 | if(x%2 == 0) c2++; 13 | if(x%3 == 0) c3++; 14 | if(x%4 == 0) c4++; 15 | if(x%5 == 0) c5++; 16 | } 17 | cout << c2 << " Multiplo(s) de 2" << endl; 18 | cout << c3 << " Multiplo(s) de 3" << endl; 19 | cout << c4 << " Multiplo(s) de 4" << endl; 20 | cout << c5 << " Multiplo(s) de 5" << endl; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/404/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | map pol; 9 | pol["Tetrahedron"] = 4; 10 | pol["Cube"] = 6; 11 | pol["Octahedron"] = 8; 12 | pol["Dodecahedron"] = 12; 13 | pol["Icosahedron"] = 20; 14 | int n; 15 | cin >> n; 16 | int ans = 0; 17 | for(int i=0; i> x; 20 | ans+= pol[x]; 21 | } 22 | 23 | cout << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /SPOJ-BR/CAIXAMG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | double x,y,z1,z2; 7 | while(cin >> x >> y, x+y != 0){ 8 | double deltasqrt = sqrt(16*(x+y)*(x+y) - 48*x*y); 9 | z1 = 4*(x+y) + deltasqrt; 10 | z2 = 4*(x+y) - deltasqrt; 11 | z1/=24; 12 | z2/=24; 13 | cout << fixed << setprecision(4); 14 | if(-4*x -4*y + 24*z1 < 0) cout << z1 << " " << (x-2*z1)*(y - 2*z1)*z1 << endl; 15 | else cout << z2 << " " << (x-2*z2)*(y-2*z2)*z2 << endl; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /URI/1066.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n,i,par=0,impar=0,negativo=0,positivo=0; 5 | for(i=0;i<5;i++){ 6 | scanf("%d",&n); 7 | if(n%2==0) par++; 8 | else impar++; 9 | if(n<0) negativo++; 10 | else if(n>0) positivo++; 11 | } 12 | printf("%d valor(es) par(es)\n",par); 13 | printf("%d valor(es) impar(es)\n",impar); 14 | printf("%d valor(es) positivo(s)\n",positivo); 15 | printf("%d valor(es) negativo(s)\n",negativo); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /URI/1181.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int linha,i,j; 5 | float mat[12][12],soma=0; 6 | char operacao; 7 | scanf("%d\n%c",&linha,&operacao); 8 | for(i=0;i<=11;i++) { 9 | for(j=0;j<=11;j++) { 10 | scanf("%f",&mat[i][j]); 11 | if(i==linha) 12 | soma+=mat[i][j]; 13 | } 14 | } 15 | if(operacao=='S') 16 | printf("%.1f\n",soma); 17 | else if(operacao=='M') 18 | printf("%.1f\n",soma/12); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/376/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int vet[200000]; 5 | 6 | int main(){ 7 | int k; 8 | cin >> k; 9 | for(int i=0; i> vet[i]; 11 | } 12 | int flag = 0; 13 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, k; 7 | set< int > s; 8 | map m; 9 | cin >> n >> k; 10 | for(int i=0; i> x; 12 | s.insert(x); 13 | m[x] = i+1; 14 | } 15 | if(s.size() < k) cout << "NO" << endl; 16 | else { 17 | cout << "YES" << endl; 18 | while(k > 0){ 19 | k--; 20 | cout << m[(*s.begin())] << " "; 21 | s.erase(s.begin()); 22 | } 23 | cout << endl; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /SPOJ-BR/HIST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | while(cin >> n, n!=0){ 8 | map vis; 9 | int count=0; 10 | int acumulador = 0; 11 | for(int i = 0; i> x; 14 | if(vis[x] == 0){ 15 | count+= x + acumulador++; 16 | vis[x]=i+1; 17 | } 18 | else{ 19 | count+= (i-vis[x]+1); 20 | vis[x]=i+1; 21 | acumulador++; 22 | } 23 | } 24 | cout << count << endl; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /URI/1182.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int coluna,i,j; 5 | float mat[12][12],soma=0; 6 | char operacao; 7 | scanf("%d\n%c",&coluna,&operacao); 8 | for(i=0;i<=11;i++) { 9 | for(j=0;j<=11;j++) { 10 | scanf("%f",&mat[i][j]); 11 | if(j==coluna) 12 | soma+=mat[i][j]; 13 | } 14 | } 15 | if(operacao=='S') 16 | printf("%.1f\n",soma); 17 | else if(operacao=='M') 18 | printf("%.1f\n",soma/12); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /URI/2238.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a,b,c,d; 7 | cin >> a >> b >> c >> d; 8 | int mx = 2000000000; 9 | for(int i = 1; i<=sqrt(c); i++){ 10 | if(i%a == 0 && i%b != 0 && c%i == 0 && d%i != 0){ 11 | mx = min(mx, i); 12 | } 13 | if(c%i == 0){ 14 | if((c/i)%a == 0 && (c/i)%b != 0 && c%(c/i) == 0 && d%(c/i) != 0){ 15 | mx = min(mx, c/i); 16 | } 17 | } 18 | } 19 | if(mx == 2000000000) mx = -1; 20 | cout << mx << endl; 21 | } 22 | -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Strings Gauntlet/A(Basic).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | int j = 0; 10 | for(int i = 0; i < n; i++) { 11 | int z; 12 | cin >> z; 13 | 14 | 15 | int zj = i+z-1; 16 | if(!z) zj++; 17 | int lz = min(z, 1+(j-i)); 18 | 19 | //cout << zj << " " << lz << endl; 20 | for(; j <= zj; j++) { 21 | //cout << "-> " << lz << endl; 22 | cout << lz << " "; 23 | lz++; 24 | } 25 | } 26 | cout << endl; 27 | } 28 | -------------------------------------------------------------------------------- /Codeforces/Gym/2018 XI Samara Regional Intercollegiate Programming Contest/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s,t; 7 | cin >> s >> t; 8 | if(s.size() != t.size()){ 9 | cout << "NO" << endl; 10 | return 0; 11 | } 12 | int l = 0; 13 | int r = s.size()-1; 14 | while(l < s.size() && s[l] == t[l]) l++; 15 | while(r > l && s[r] == t[r]) r--; 16 | 17 | reverse(s.begin()+l, s.begin()+r+1); 18 | 19 | if(s == t) cout << "YES" << endl; 20 | else cout << "NO" << endl; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/381/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long a,b,c,n; 7 | cin >> n >> a >> b >> c; 8 | if(n % 4 == 0) cout << 0 << endl; 9 | else { 10 | n = 4 - (n%4); 11 | 12 | long long res; 13 | 14 | if(n==1) res = min(min(a, b+c), 3*c); 15 | 16 | else if(n == 2) { 17 | 18 | res = min(min(b, 2*a), 2*c); 19 | 20 | } 21 | 22 | else if(n == 3) { 23 | res = min(min(b + a, 3*a), c); 24 | } 25 | 26 | cout << res << endl; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/435/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ff first 3 | #define ss second 4 | #define pii pair 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | int n,k; 10 | cin >> n >> k; 11 | int count[20000]; 12 | for(int i=0; i<20000; i++){ 13 | count[i] = 0; 14 | } 15 | for(int i=0; i> x; 18 | count[x]++; 19 | } 20 | int ans = 0; 21 | for(int i=0; i& arr, int a, int b, int c) { 4 | int ans =0; 5 | int n = arr.size(); 6 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int vet[n]; 9 | int pre[n],pos[n]; 10 | for(int i=0; i> vet[i]; 12 | } 13 | pre[0] = 1; 14 | for(int i=1; i=0; i--){ 19 | pos[i] = min(pos[i+1]+1,vet[i]); 20 | } 21 | int res = 1; 22 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int a[6], b[6]; 7 | for(int i=0; i<6; i++) cin >> a[i]; 8 | for(int i=0; i<6; i++) cin >> b[i]; 9 | 10 | int den = 36; 11 | int num = 0; 12 | for(int i=0; i<6; i++){ 13 | for(int j=0; j<6; j++){ 14 | if(a[i] > b[j]) num++; 15 | if(a[i] == b[j]) den--; 16 | } 17 | } 18 | 19 | cout << fixed << setprecision(5) << double(num)/double(den) << endl; 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Gym/2016-2017 ACM-ICPC, NEERC, Central Subregional Contest/H.py: -------------------------------------------------------------------------------- 1 | inpts = open("input.txt") 2 | outpts = open("output.txt", "w") 3 | 4 | n = [x.strip() for x in inpts.readlines()] 5 | 6 | n = int(n[0]) 7 | ans = 1 8 | for i in range(1, 2): 9 | ans *= 8 10 | 11 | if n <= 1: 12 | outpts.write(str(ans) + '\n') 13 | else: 14 | for i in range(2, min(n+1, 10)): 15 | ans *= 9 16 | if n<=9: 17 | outpts.write(str(ans) + '\n') 18 | else: 19 | for i in range(10, n+1): 20 | ans *= 10 21 | outpts.write(str(ans) + '\n') 22 | -------------------------------------------------------------------------------- /Codeforces/Gym/2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)/J.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | int n ; 8 | cin>>n; 9 | double ans = 0.00; 10 | for(int i = 0 ; i < n ; i ++){ 11 | int x; 12 | cin>>x; 13 | if(x == 0) ans += 2.000; 14 | if(x == 1) ans += 1.000; 15 | if(x == 2) ans += 0.500; 16 | if(x == 4) ans+= 1.00/4.000; 17 | if(x == 8) ans+= 1.00/8.000; 18 | if(x == 16) ans+= 1.000/16.000; 19 | } 20 | cout< 2 | #define int long long 3 | using namespace std; 4 | const int M = 1e9+7; 5 | inline int mod(int a,int m){int r = a%m;if(r<0)r+=m;return r;} 6 | int dp[10010]; 7 | int32_t main(){ 8 | int n; 9 | cin>>n; 10 | dp[0]=1; 11 | for(int i=1;i<=n;i++){ 12 | dp[i]=0; 13 | if(i>=1){ 14 | dp[i]=mod(dp[i-1],M); 15 | } 16 | if(i>=2){ 17 | dp[i]=mod(dp[i]+4*dp[i-2],M); 18 | } 19 | if(i>=3){ 20 | dp[i]=mod(dp[i]+2*dp[i-3],M); 21 | } 22 | } 23 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin >> s; 8 | long long int cnt[3] = {0,0,0}; 9 | long long int ans = 0; 10 | for(char c: s){ 11 | if(c < '0' || c > '9'){ 12 | cnt[0]=cnt[1]=cnt[2]=0; 13 | continue; 14 | } 15 | int val = c - '0'; 16 | int aux[3]; 17 | for(int i=0; i<3; i++) aux[(i+val)%3] = cnt[i]; 18 | for(int i=0; i<3; i++) cnt[i] = aux[i]; 19 | cnt[val%3]++; 20 | ans += cnt[0]; 21 | //cout << ans << endl; 22 | } 23 | cout << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/377/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | cin >> n >> k; 8 | int vet[n]; 9 | int count = 0; 10 | for(int i=0; i> vet[i]; 11 | for(int i=1; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | bool vis[100001]; 7 | for(int i=0; i<100001; i++){ 8 | vis[i] = false; 9 | } 10 | 11 | int n; 12 | cin >> n; 13 | int ans = 0; 14 | int current = 0; 15 | for(int i =0; i< 2*n; i++){ 16 | int x; 17 | cin >> x; 18 | if(vis[x]){ 19 | vis[x] = false; 20 | current--; 21 | } 22 | else{ 23 | vis[x] = true; 24 | current++; 25 | } 26 | ans = max(ans, current); 27 | } 28 | 29 | cout << ans << endl; 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/460/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | cout.tie(0); 9 | int k; 10 | cin >> k; 11 | int cnt = 0; 12 | for(int i=10; i<=12000000; i++){ 13 | int curr = 0; 14 | int aux = i; 15 | while(aux > 0){ 16 | curr += aux%10; 17 | aux /=10; 18 | } 19 | if(curr == 10) cnt++; 20 | if(cnt == k){ 21 | cout << i << endl; 22 | return 0; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 195/PathCrossing.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPathCrossing(string path) { 4 | int u = 0, v = 0; 5 | set> s; 6 | s.insert(make_pair(u,v)); 7 | for(char c : path){ 8 | if(c == 'N') u++; 9 | else if(c == 'S') u--; 10 | else if(c == 'E') v++; 11 | else v--; 12 | if(s.count(make_pair(u,v))) return true; 13 | s.insert(make_pair(u,v)); 14 | } 15 | return false; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /LeetCode/General Problems/ArrangingCoins.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun arrangeCoins(n: Int): Int { 3 | var ans : Long = -1 4 | var l : Long = 1 5 | var r : Long = Int.MAX_VALUE.toLong() 6 | while(l <= r){ 7 | var m : Long = (l+r) shr 1 8 | var cnt : Long = ((m+1)*m)/2 9 | if(cnt <= n){ 10 | ans = m 11 | l = m+1 12 | } else { 13 | r = m-1 14 | } 15 | } 16 | return maxOf(0, ans.toInt()) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /OBI/N2/2018/F3/bolas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int check(vector v){ 4 | int ant = -1; 5 | for(int i=0;i<8;i++){ 6 | if(v[i]==ant)return false; 7 | ant = v[i]; 8 | } 9 | return true; 10 | } 11 | int main(){ 12 | vector v(8); 13 | for(int i=0;i<8;i++){ 14 | cin>>v[i]; 15 | } 16 | sort(v.begin(),v.end()); 17 | do{ 18 | if(check(v)){ 19 | cout<<"S"< 2 | #define MAXN 100100 3 | #define int long long 4 | using namespace std; 5 | 6 | int abs(int& a){ 7 | if(a<0)a*=-1; 8 | return a; 9 | } 10 | 11 | int32_t main(){ 12 | int n,h[MAXN]; 13 | cin>>n; 14 | for(int i=1;i<=n;i++)cin>>h[i]; 15 | int custo[MAXN]; 16 | custo[0]=0; 17 | custo[1]=0; 18 | for(int i=2;i<=n;i++){ 19 | custo[i]=custo[i-1]+abs(h[i]-h[i-1]); 20 | if(i>=3)custo[i]=min(custo[i],custo[i-2]+abs(h[i]-h[i-2])); 21 | } 22 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,s; 7 | char x; 8 | vector size; 9 | cin >> n; 10 | s=0; 11 | for(int i=0; i> x; 13 | if(x== 'W'){ 14 | if(s!=0) size.push_back(s); 15 | s=0; 16 | } 17 | else s++; 18 | } 19 | if(x=='B') size.push_back(s); 20 | cout << size.size() << endl; 21 | if(size.size() > 0){ 22 | cout << size[0]; 23 | for(int i=1; i 2 | 3 | using namespace std; 4 | 5 | bool prime(unsigned long long n){ 6 | unsigned long long limit = sqrt(n); 7 | for(unsigned long long i=2; i<=limit; i++){ 8 | if(n%i == 0) return false; 9 | } 10 | return true; 11 | } 12 | 13 | int main(){ 14 | unsigned long long n; 15 | cin >> n; 16 | if(n==2) cout << 1 << endl; 17 | else if(n%2 == 0) cout << 2 << endl; 18 | else if(prime(n)) cout << 1 << endl; 19 | else if(prime(n-2)) cout << 2 << endl; 20 | else cout << 3 << endl; 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/389/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,m,k; 7 | cin >> n >> m >> k; 8 | int place = (k+1)/2; 9 | int posx = 0, posy = 0; 10 | int count = 0; 11 | for(int i=1; i<=n; i++){ 12 | posx++; 13 | posy = 0; 14 | for(int j=1; j<=m; j++){ 15 | count++; 16 | posy++; 17 | if(count == place){ 18 | cout << posx << " " << posy << " "; 19 | if(k%2==1) cout << "L" << endl; 20 | else cout << "R" << endl; 21 | return 0; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/415/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MOD 1000000007 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | int n; 8 | cin >> n; 9 | long long v[n]; 10 | for(int i=0; i> v[i]; 11 | sort(v, v+n); 12 | long long ans = 0; 13 | long long power2[n+1]; 14 | power2[0] = 1; 15 | for(int i=1; i<=n; i++) power2[i] = (power2[i-1]*2)%MOD; 16 | for(int i=1; i<=n; i++){ 17 | ans = (ans + (v[i-1]*(power2[i-1] - power2[n-i]))%MOD)%MOD; 18 | } 19 | cout << ans << endl; 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Intel Code Challenge/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | string x; 9 | cin >> x; 10 | 11 | if(n == 12){ 12 | if(x[0] == '1' && x[1] >= '3' || ( x[0] >= '2')){ 13 | x[0] = '0'; 14 | } 15 | if(x[3] >= '6') x[3] = '0'; 16 | if(x[0] == '0' && x[1] == '0') x[0] = '1'; 17 | } 18 | 19 | else if(n == 24){ 20 | if(x[0] == '2' && x[1] >= '4' || (x[0] >= '3')) x[0] = '0'; 21 | if(x[3] >= '6') x[3] = '0'; 22 | } 23 | cout << x << endl; 24 | } 25 | -------------------------------------------------------------------------------- /CSES/NumberSpiral.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | int main() { 8 | int t, y, x; 9 | cin >> t; 10 | while (t--) { 11 | cin >> y >> x; 12 | int a = max(y, x); 13 | int b = min(y, x); 14 | ll s = ll(a - 1) * (a - 1); 15 | if (a == b) s += a; 16 | else if (a % 2) { 17 | if (x == a) s+= a * 2 - y; 18 | else s += x; 19 | } else { 20 | if (y == a) s += a * 2 - x; 21 | else s += y; 22 | } 23 | cout << s << endl; 24 | } 25 | } -------------------------------------------------------------------------------- /Codeforces/Gym/La Salle-Pui Ching Programming Challenge 2017/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define endl '\n' 4 | using namespace std; 5 | 6 | int32_t main() { 7 | ios_base::sync_with_stdio(false); cin.tie(0); 8 | int n; 9 | cin >> n; 10 | 11 | int nums[n]; 12 | for(int i = 0; i < n; i++) { 13 | cin >> nums[i]; 14 | } 15 | 16 | sort(nums, nums+n); 17 | 18 | long long ans = 0; 19 | 20 | for(int i = 0; i <= n; i++) { 21 | ans += max(0LL, min(n, nums[i]) - (i+1)); 22 | } 23 | 24 | cout << ans*2LL << endl; 25 | } 26 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/308/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | int mat[100][100] = {0}; 5 | int32_t main(){ 6 | int n; 7 | cin >> n; 8 | while(n--){ 9 | int a,b,c,d; 10 | cin >> a >> b >> c >> d; 11 | a--,b--,c--,d--; 12 | for(int i=a; i<=c; i++){ 13 | for(int j=b; j <= d; j++) mat[i][j]++; 14 | } 15 | } 16 | int ans = 0; 17 | for(int i=0; i<100; i++){ 18 | for(int j=0; j<100; j++){ 19 | ans += mat[i][j]; 20 | } 21 | } 22 | cout << ans << endl; 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/449/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl '\n' 3 | #define ff first 4 | #define ss second 5 | #define ii pair 6 | using namespace std; 7 | 8 | int main(){ 9 | ios_base::sync_with_stdio(false); 10 | int n,q; 11 | string s; 12 | cin >> n >> q; 13 | cin >> s; 14 | while(q--){ 15 | int l, r; 16 | char c1,c2; 17 | cin >> l >> r >> c1 >> c2; 18 | l--, r--; 19 | for(int i=l; i<=r; i++){ 20 | if(s[i] == c1) s[i] = c2; 21 | } 22 | } 23 | cout < 2 | #define int long long 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int32_t main(){ 7 | int n,m; 8 | cin >> n >> m; 9 | int v[m+1]; 10 | for(int i=0; i<=m; i++) v[i] = 0; 11 | for(int i=0; i> l >> r; 14 | for(int j=l; j<=r; j++) v[j]++; 15 | } 16 | vector ans; 17 | for(int i=1; i<=m; i++) if(v[i] == 0) ans.pb(i); 18 | cout << ans.size() << endl; 19 | for(int i=0; i = mutableListOf() 4 | var s : SortedSet = sortedSetOf() 5 | s.add(1) 6 | while(s.size > 0 && arr.size < n){ 7 | var current = s.first() 8 | s.remove(current) 9 | arr.add(current) 10 | s.add(current*2) 11 | s.add(current*3) 12 | s.add(current*5) 13 | } 14 | return arr.last().toInt() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Codechef/March Lunchtime 2018/ZOZ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define endl "\n" 4 | using namespace std; 5 | 6 | int32_t main(){ 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(0); cout.tie(0); 9 | int t; 10 | cin >> t; 11 | while(t--){ 12 | int n,k; 13 | cin >> n >> k; 14 | int v[n]; 15 | int sum = 0; 16 | for(int i=0; i> v[i]; 18 | sum += v[i]; 19 | } 20 | int ans = 0; 21 | for(int i=0; i sum - v[i]) ans++; 23 | } 24 | cout << ans << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/303/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); cout.tie(0); 8 | int n; 9 | cin >> n; 10 | vector v; 11 | for(int i=1; i<=n; i++){ 12 | bool ok = true; 13 | for(int j=1; j<=n; j++){ 14 | int x; 15 | cin >> x; 16 | if(x == 1 || x == 3) ok = false; 17 | } 18 | if(ok) v.push_back(i); 19 | } 20 | cout << v.size() << endl; 21 | for(int i=0; i 0) cout << endl; 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/404/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n,m; 7 | cin >> n >> m; 8 | if(m >= n){ 9 | cout << n << endl; 10 | return 0; 11 | } 12 | 13 | else { 14 | long long ans = m+1; 15 | long long l = 0, r = 1e10; 16 | long long aux = 0; 17 | while(l < r){ 18 | long long mid = (l+r)/2; 19 | 20 | if(mid*(mid+1)/2 + ans + mid >= n){ 21 | r= mid; 22 | } 23 | else { 24 | l = mid +1; 25 | } 26 | } 27 | 28 | cout << ans + l << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/428/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ff first 3 | #define ss second 4 | #define pii pair 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios_base::sync_with_stdio(false); 10 | 11 | int n,k; 12 | cin >> n >> k; 13 | int acc = 0; 14 | int ans = 0; 15 | int give = 0; 16 | for(int i=0; i> x; 19 | acc+=x; 20 | give += min(acc, 8); 21 | acc -= min(acc, 8); 22 | if(give < k) ans++; 23 | } 24 | if(give >= k) cout << ans+1 << endl; 25 | else cout << -1 << endl; 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/388/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int n; 8 | cin >> n; 9 | queue d,r; 10 | for(int i=0; i> c; 13 | if(c == 'D') d.push(i); 14 | else r.push(i); 15 | } 16 | 17 | while(!d.empty() && !r.empty()){ 18 | int x,y; 19 | x = d.front(); 20 | d.pop(); 21 | y = r.front(); 22 | r.pop(); 23 | if(x < y) d.push(x+n); 24 | else r.push(y+n); 25 | } 26 | 27 | if(d.empty()) cout << "R" << endl; 28 | else cout << "D" << endl; 29 | } 30 | -------------------------------------------------------------------------------- /Codeforces/Gym/2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)/I.py: -------------------------------------------------------------------------------- 1 | n, s = [int(x) for x in input().split()] 2 | 3 | cur = 0 4 | 5 | lst = {} 6 | for i in range(n): 7 | name, x = input().split() 8 | x = int(x) 9 | lst[x] = name 10 | 11 | ans = [] 12 | 13 | lst = sorted(lst.items(), key=lambda kv: kv[0], reverse=True) 14 | 15 | for x, name in lst: 16 | if cur + x <= s: 17 | ans.append(name) 18 | cur += x 19 | 20 | if cur == s: 21 | print(len(ans)) 22 | for name in ans: 23 | print(name) 24 | else: 25 | print (0) 26 | 27 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/345/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | map< pair, int> freq; 6 | int32_t main(){ 7 | int n; 8 | cin >> n; 9 | vector< pair > s; 10 | map mx, my; 11 | int ans = 0; 12 | for(int i=0; i> x >> y; 15 | ans -= freq[make_pair(x,y)]; 16 | ans += mx[x]; 17 | ans += my[y]; 18 | mx[x]++; 19 | my[y]++; 20 | freq[make_pair(x,y)]++; 21 | } 22 | 23 | cout < 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | int n, k; 8 | while(cin >> n >> k, n+k != 0){ 9 | int v[n]; 10 | priority_queue pq; 11 | map m; 12 | for(int i=0; i> v[i]; 14 | if(i < k) pq.push(-v[i]); 15 | } 16 | cout << -pq.top(); 17 | for(int i=k; i 2 | #define int long long 3 | #define MAXN 5050 4 | using namespace std; 5 | 6 | int dp[MAXN][MAXN]; 7 | int A[MAXN]; 8 | 9 | 10 | int solve(int l,int r){ 11 | if(r>n; 21 | memset(dp,-1,sizeof(dp)); 22 | for(int i=0;i>A[i]; 23 | cout<): Int { 3 | strs.sort() 4 | var ans = -1 5 | for (s in strs){ 6 | var cnt = 0 7 | for(x in strs){ 8 | var pt = 0 9 | for(c in x){ 10 | if(pt < s.length && s[pt] == c) pt++ 11 | } 12 | if(pt == s.length) cnt++ 13 | } 14 | if(cnt <= 1) ans = maxOf(ans, s.length.toInt()) 15 | } 16 | return ans 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Codeforces/Gym/2018 XI Samara Regional Intercollegiate Programming Contest/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define int long long 6 | 7 | int32_t main(){ 8 | int n; 9 | cin >> n; 10 | int x[n], y[n]; 11 | for(int i=0; i> x[i] >> y[i]; 12 | int ans = LLONG_MAX; 13 | for(int i=0; i 0) ans = min(ans, xb*yc - yb*xc); 21 | } 22 | cout << ans << endl; 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/386/Div2D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 80 3 | #define ff first 4 | #define ss second 5 | 6 | using namespace std; 7 | 8 | 9 | int main(){ 10 | int n,k,a,b; 11 | cin >> n >> k >> a >> b; 12 | 13 | char ca = 'G'; 14 | char cb = 'B'; 15 | 16 | string ans; 17 | int cnt = 0; 18 | while(a+b > 0){ 19 | if(a < b || cnt >= k){ 20 | swap(a,b); 21 | swap(ca,cb); 22 | cnt = 0; 23 | } 24 | if(a == 0){ 25 | cout << "NO" << endl; 26 | return 0; 27 | } 28 | ans+=ca; 29 | cnt++; 30 | a--; 31 | } 32 | cout << ans << endl; 33 | } 34 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/402/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | string x; 8 | int n; 9 | cin >> x; 10 | cin >> n; 11 | 12 | int zerocount = 0; 13 | 14 | for(int i=0; i< x.size(); i++){ 15 | if(x[i] == '0') zerocount++; 16 | } 17 | 18 | if(n > zerocount){ 19 | cout << x.size()-1 << endl; 20 | return 0; 21 | } 22 | 23 | int aux =0; 24 | int ans = 0; 25 | for(int i= x.size()-1; i>=1; i--){ 26 | if(x[i] == '0') aux++; 27 | else ans++; 28 | if(aux == n) break; 29 | } 30 | 31 | cout << ans << endl; 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/420/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | long long PA(long long x){ 6 | return ((x+1)*x)/2; 7 | } 8 | 9 | int main(){ 10 | ios_base::sync_with_stdio(false); 11 | long long a,b; 12 | long long max =0; 13 | cin >> a >> b; 14 | for(long long i=0; i<=b; i++){ 15 | //cout << "y = " << i << endl; 16 | long long point = (b-i)*a; 17 | //cout << "x = " << point << endl; 18 | //cout << (i+1)*PA(point) + (point+1)*PA(i) << endl; 19 | max = std::max(max, (i+1)*PA(point) + (point+1)*PA(i)); 20 | } 21 | cout << max << endl; 22 | } 23 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Educational Round 23/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | bool check(int n, int s){ 6 | int digit = 0; 7 | int num = n; 8 | while(n> 0){ 9 | digit += n%10; 10 | n/=10; 11 | } 12 | return (num - digit >= s); 13 | } 14 | int32_t main(){ 15 | int n,s; 16 | cin >> n >> s; 17 | int l = 0, r = n; 18 | int ans = n+1; 19 | while(l <=r ){ 20 | int m = (l+r)>>1; 21 | if(check(m,s)){ 22 | ans = m; 23 | r = m-1; 24 | } 25 | else l = m+1; 26 | } 27 | cout << n-ans + 1 << endl; 28 | } -------------------------------------------------------------------------------- /URI/1151.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num,anterior1,anterior2,i,proximo; 5 | scanf("%d",&num); 6 | if(num==1) 7 | printf("0\n"); 8 | else if(num==2) 9 | printf("0 1\n"); 10 | else if(num>=3) { 11 | printf("0 1"); 12 | anterior1=0; 13 | anterior2=1; 14 | for(i=3;i<=num;i++) { 15 | proximo=anterior1+anterior2; 16 | printf(" %d",proximo); 17 | anterior1=anterior2; 18 | anterior2=proximo; 19 | } 20 | printf("\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Gym/La Salle-Pui Ching Programming Challenge 2016/K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | int r,d; 7 | 8 | cin >> r >> d; 9 | 10 | 11 | int ans = 0; 12 | 13 | int c = 0; 14 | 15 | for(int i = 1; i<= r+d; i++){ 16 | c += floor(sqrt((r+d)*(r+d) - i*i)) + 1; 17 | } 18 | 19 | ans += 4*c + 1; 20 | 21 | c = 0; 22 | 23 | for(int i = 1; i<= r-d; i++){ 24 | c += ceil(sqrt((r-d)*(r-d) - i*i)); 25 | } 26 | 27 | ans -= 4*c; 28 | 29 | if(r-d > 0) ans--; 30 | 31 | cout << ans << endl; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Avito Code Challenge 2018/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | map m; 7 | int n; 8 | cin >> n; 9 | for(int i=0; i> id >> val; 12 | m[id] = max(m[id], val); 13 | } 14 | cin >> n; 15 | for(int i=0; i> id >> val; 18 | m[id] = max(m[id], val); 19 | } 20 | int ans = 0; 21 | for(pair x : m){ 22 | ans += x.second; 23 | } 24 | cout << ans << endl; 25 | } -------------------------------------------------------------------------------- /LeetCode/General Problems/MaximumProductOfWordLengths.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maxProduct(words: Array): Int { 3 | var ans : Int = 0 4 | var bitset : IntArray = IntArray(words.size) 5 | for(i in 0 until words.size){ 6 | for(c in words[i]) bitset[i] = bitset[i] or (1 shl (c.toInt() - 'a'.toInt())) 7 | } 8 | for(i in 0 until words.size){ 9 | for(j in i+1 until words.size) 10 | if(bitset[i] and bitset[j] == 0) ans = maxOf(ans, words[i].length*words[j].length) 11 | } 12 | return ans 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LeetCode/General Problems/SingleNumber.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun singleNumber(nums: IntArray): IntArray { 3 | var x = 0 4 | for(i in nums) x = x xor i 5 | 6 | var bt = 0 7 | for (b in 1 until 30){ 8 | if((x and (1 shl b)) != 0){ 9 | bt = b 10 | break 11 | } 12 | } 13 | val ans = IntArray(2) { 0 } 14 | for(i in nums){ 15 | if((i and (1 shl bt)) == 0) ans[0] = ans[0] xor i 16 | else ans[1] = ans[1] xor i 17 | } 18 | return ans; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SPOJ-BR/PAO07.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int checaTamanho(int *v,int particao,int pessoas,int paes){ 4 | int count=0; 5 | int i; 6 | for(i=0;i=pessoas) return 1; 8 | else return 0; 9 | } 10 | 11 | int main(void) { 12 | int i,esq=0,dir=10000,resp,n,t,meio; 13 | scanf("%d %d",&n,&t); 14 | int pao[t]; 15 | for(i=0;i 2 | 3 | int main() { 4 | int i,j,cont=0; 5 | float mat[12][12],soma=0; 6 | char operacao; 7 | scanf("%c",&operacao); 8 | for(i=0;i<=11;i++) { 9 | for(j=0;j<=11;j++) { 10 | scanf("%f",&mat[i][j]); 11 | } 12 | } 13 | for(j=1;j<=11;j++) { 14 | for(i=0;i<=j-1;i++) { 15 | soma+=mat[i][j]; 16 | cont++; 17 | } 18 | } 19 | if(operacao=='S') 20 | printf("%.1f\n",soma); 21 | else if(operacao=='M') 22 | printf("%.1f\n",soma/cont); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /URI/1184.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i,j,cont=0; 5 | float mat[12][12],soma=0; 6 | char operacao; 7 | scanf("%c",&operacao); 8 | for(i=0;i<=11;i++) { 9 | for(j=0;j<=11;j++) { 10 | scanf("%f",&mat[i][j]); 11 | } 12 | } 13 | for(i=1;i<=11;i++) { 14 | for(j=0;j<=i-1;j++) { 15 | soma+=mat[i][j]; 16 | cont++; 17 | } 18 | } 19 | if(operacao=='S') 20 | printf("%.1f\n",soma); 21 | else if(operacao=='M') 22 | printf("%.1f\n",soma/cont); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /URI/1566.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | scanf("%d", &t); 8 | while(t--){ 9 | int n; 10 | scanf("%d", &n); 11 | int aux[231]; 12 | for(int i=0; i<231; i++){ 13 | aux[i] = 0; 14 | } 15 | for(int i=0; i < n; i++){ 16 | int x; 17 | scanf("%d", &x); 18 | aux[x]++; 19 | } 20 | int flag = true; 21 | for(int i=0; i<231; i++){ 22 | while(aux[i]--){ 23 | if(flag){ 24 | printf("%d", i); 25 | flag = false; 26 | } 27 | else printf(" %d", i); 28 | } 29 | } 30 | cout << endl; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/382/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | double n1,n2; 8 | cin >> n >> n1 >> n2; 9 | vector p(n); 10 | for(int i=0; i> p[i]; 11 | sort(p.begin(),p.end()); 12 | reverse(p.begin(),p.end()); 13 | double sum2=0; 14 | double sum1=0; 15 | if(n2 < n1) swap(n1,n2); 16 | int k=0; 17 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | long long vet[100001]; 6 | 7 | int main(){ 8 | long long n,k; 9 | for(int i=0; i<=100000; i++) vet[i] = 0; 10 | cin >> n >> k; 11 | long long res = 0; 12 | for(int a=0; a> x; 15 | vet[x]++; 16 | } 17 | 18 | for(long long i=1; i<=100000; i++){ 19 | long long j; 20 | j = i^k; 21 | if(j <= 100000 && i < j) res += vet[i]*vet[j]; 22 | else if(i == j && vet[i]) { 23 | res += (vet[i]-1)*vet[i]/2; 24 | } 25 | } 26 | cout << res << endl; 27 | } 28 | -------------------------------------------------------------------------------- /SPOJ-BR/ACIDO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string x; 7 | while(cin >> x){ 8 | int n = x.size(); 9 | stack s; 10 | int ans = 0; 11 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | #define M 1000000007 6 | 7 | int main(){ 8 | long long n; 9 | cin >> n; 10 | long long v[n]; 11 | long long dp[1001][1001]; 12 | dp[0][0] = 1; 13 | for(int i=0; i<1001; i++){ 14 | dp[i][0] = 1; 15 | for(int j=1; j<=i; j++){ 16 | dp[i][j] = (dp[i-1][j] + dp[i-1][j-1])%M; 17 | } 18 | } 19 | for(int i=0; i> v[i]; 20 | int acc = v[0]; 21 | int res = 1; 22 | for(int i=1; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | deque q; 7 | int n; 8 | string x; 9 | cin >> n; 10 | cin >> x; 11 | 12 | if(x.size()%2){ 13 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | list l; 9 | for(int i=0; i> x; 12 | l.push_back(x); 13 | } 14 | int m; 15 | cin >> m; 16 | for(int i=0; i> k; 19 | list::iterator it = find(l.begin(), l.end(), k); 20 | if(it != l.end()) l.erase(it); 21 | } 22 | for(list::iterator it = l.begin(); it != l.end(); it++){ 23 | if(it != l.begin()) cout << " "; 24 | cout << *it; 25 | } 26 | cout << endl; 27 | } 28 | -------------------------------------------------------------------------------- /CSES/IncreasingArray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int n; 6 | vector vet; 7 | int aux; 8 | long long somaIni=0; 9 | cin>>n; 10 | for(int i=0;i>aux; 12 | somaIni+=aux; 13 | vet.push_back(aux); 14 | } 15 | long long somaF=0; 16 | for(int i=1;i) { 2 | var (t) = readLine()!!.split(' ').map({it.toInt()}); 3 | while(t > 0){ 4 | t--; 5 | 6 | var (a) = readLine()!!.split(' ').map({it.toInt()}); 7 | 8 | var arr : MutableList = mutableListOf() ; 9 | 10 | var pot = 1; 11 | 12 | while(a > 0){ 13 | var md = a % 10; 14 | if(md > 0){ 15 | arr.add(md*pot); 16 | } 17 | pot *= 10; 18 | 19 | a /= 10; 20 | } 21 | 22 | println(arr.size); 23 | println(arr.joinToString(" ")); 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /LeetCode/Contests/Weekly Contest 199/BulbSwitch.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minFlips(string target) { 4 | string cur; 5 | for(char c : target) cur += '0'; 6 | int ans = 0; 7 | int flips = 0; 8 | for(int i=0; i 2 | 3 | int calculaIntervalo(double num){ 4 | if(num<0 || num>100) 5 | printf("Fora de intervalo\n"); 6 | else { 7 | if(num<=25) 8 | printf("Intervalo [0,25]\n"); 9 | else if(num<=50) 10 | printf("Intervalo (25,50]\n"); 11 | else if(num<=75) 12 | printf("Intervalo (50,75]\n"); 13 | else if(num<=100) 14 | printf("Intervalo (75,100]\n"); 15 | } 16 | return 0; 17 | } 18 | int main() { 19 | double num; 20 | scanf("%lf",&num); 21 | calculaIntervalo(num); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /AtCoder/ARC95/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | int main(){ 8 | int n; 9 | scanf("%d", &n); 10 | ll v[n]; 11 | ll max_n = 0; 12 | for(int i=0; i> v[i]; 14 | max_n = max(max_n, v[i]); 15 | } 16 | 17 | ll a, b; 18 | double best = 1123456789.0; 19 | 20 | for(int i=0; i abs((double)max_n/2. - (double)v[i])){ 24 | a = max_n; 25 | b = v[i]; 26 | best = abs((double)max_n/2. - (double)v[i]); 27 | } 28 | } 29 | 30 | printf("%lld %lld\n", a, b); 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/476/Div2D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); cout.tie(0); 8 | int n,k; 9 | cin >> n >> k; 10 | int a[n]; 11 | for(int i=1; i> x; 14 | a[i] = x; 15 | } 16 | int acc = 0; 17 | int ans = INT_MAX; 18 | for(int i=1; i<=k; i++) acc += a[i]; 19 | ans = min(ans, acc); 20 | for(int i=k+1; i 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | int pre[(int)1e6+10]; 8 | 9 | string s; 10 | 11 | void prefix(int n) { 12 | pre[0] = 0; 13 | for(int i = 1; i < n; i++) { 14 | pre[i] = pre[i-1]; 15 | while(pre[i] > 0 && s[i] != s[pre[i]]) pre[i] = pre[pre[i]-1]; 16 | if(s[i] == s[pre[i]]) pre[i]++; 17 | } 18 | } 19 | 20 | int main() { 21 | ios_base::sync_with_stdio(false); 22 | cin >> s; 23 | int n = s.size(); 24 | prefix(n); 25 | 26 | for(int i = 0; i < n; i++) { 27 | cout << pre[i] << " "; 28 | } 29 | cout << endl; 30 | } 31 | -------------------------------------------------------------------------------- /Brazillian Summer Camp 2018/Strings Gauntlet/N(Basic).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int sz[27]; 6 | 7 | int solve(int n, int k){ 8 | if(k == (sz[n]/2)+1) return 0; 9 | else if(k > (sz[n]/2)+1) return (k - ((sz[n]/2)+1)); 10 | else return solve(n-1, k); 11 | } 12 | 13 | int main(){ 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(0); 16 | cout.tie(0); 17 | int n,k; 18 | sz[1] = 1; 19 | for(int i=2; i<=26; i++){ 20 | sz[i] =2*sz[i-1]+1; 21 | } 22 | while(cin >> n >> k){ 23 | k++; 24 | if(k == 1) cout << 0 << endl; 25 | else cout << solve(n, k) << endl; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Codeforces/Gym/2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n , k; 4 | double dp[1005][1005]; 5 | bool vis[1005][1005]; 6 | 7 | double solve(int i ,int j){ 8 | if(j == 0){ 9 | return i; 10 | } 11 | if(vis[i][j]) return dp[i][j]; 12 | vis[i][j] = 1; 13 | if(i == n){ 14 | return dp[i][j] = 0.5000*solve(i-1 , j-1) + 0.50000*solve(i , j-1); 15 | } 16 | return dp[i][j] = 0.500*(solve(i + 1 , j - 1) + solve(i , j - 1)); 17 | } 18 | 19 | int main(){ 20 | scanf("%d%d" , &n , &k); 21 | cout< 2 | 3 | using namespace std; 4 | 5 | int calculate(int n, int k){ 6 | int v[3]; 7 | v[0] = 0; 8 | v[1] = 0; 9 | v[2] = 0; 10 | v[k] = 1; 11 | for(int i=0; i> n >> k; 23 | n = n % 6; 24 | if(calculate(n,0) == k) cout << 0 << endl; 25 | else if(calculate(n,1) == k) cout << 1 << endl; 26 | else cout << 2 << endl; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/415/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | cin >> n >> k; 8 | int ans = 0; 9 | int sum = 0, qtd = n; 10 | for(int i = 0; i> x; 13 | sum+=x; 14 | } 15 | cout << fixed << setprecision(5); 16 | while(true){ 17 | int aux = sum/qtd; 18 | double aux2 = (double)aux; 19 | //cout << sum/(qtd*1.0) << endl; 20 | if(sum/(qtd*1.0) - aux*1.0 > 0.4999999999999999){ 21 | aux++; 22 | } 23 | if(aux == k) break; 24 | sum+=k; 25 | qtd++; 26 | ans++; 27 | } 28 | cout << ans << endl; 29 | } 30 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Kotlin Heroes 4/Practice/B.kt: -------------------------------------------------------------------------------- 1 | fun main(args: Array) { 2 | var (t) = readLine()!!.split(' ').map({it.toInt()}); 3 | while(t > 0){ 4 | t--; 5 | var (a, b) = readLine()!!.split(' ').map({it.toInt()}); 6 | var (c, d) = readLine()!!.split(' ').map({it.toInt()}); 7 | 8 | if(b == d && a + c == d){ 9 | println("Yes") 10 | } else if(a == c && b + d == a) { 11 | println("Yes") 12 | } else if(c == b && a + d == b){ 13 | println("Yes") 14 | } else if(b+c == d && d == a){ 15 | println("Yes") 16 | } else println("No") 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /URI/1257.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void calculaHash(char c,int it,int pos, int *soma){ 5 | (*soma)=(*soma)+it+pos+(c-'A'); 6 | } 7 | 8 | int main() { 9 | int testes,i,n,soma,k,tamanho,j; 10 | scanf("%d",&testes); 11 | for(k=0;k 2 | 3 | using namespace std; 4 | 5 | int dist(int a, int b) { 6 | return min(abs(a-b), 24-abs(a-b)); 7 | } 8 | 9 | int main(){ 10 | int n; 11 | cin >> n; 12 | 13 | int nums[n]; 14 | for(int i = 0; i < n; i++) { 15 | cin >> nums[i]; 16 | } 17 | sort(nums, nums+n); 18 | 19 | int ans1 = 0; 20 | for(int i = 0; i < n; i += 2) { 21 | ans1 += dist(nums[i], nums[i+1]); 22 | } 23 | 24 | int ans2 = 0; 25 | for(int i = 1; i < n-1; i += 2) { 26 | ans2 += dist(nums[i], nums[i+1]); 27 | } 28 | ans2 += dist(nums[0], nums[n-1]); 29 | 30 | cout << min(ans1, ans2) << endl; 31 | } 32 | -------------------------------------------------------------------------------- /OBI/N2/2015/F2/calculo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int a[1010],b[1010],c[1010]; 4 | 5 | int main(){ 6 | int n,m; 7 | cin>>n>>m; 8 | 9 | int carry=0; 10 | for(int i=0;i>a[i]; 12 | } 13 | for(int i=0;i>b[i]; 15 | } 16 | for(int i=max(n,m) - 1;i>=0;i--){ 17 | int soma = carry + a[i] + b[i]; 18 | c[i] = soma%2; 19 | if(soma>=2)carry=1; 20 | else carry=0; 21 | } 22 | int r = 0; 23 | for(int i=0;i0)r=i; 25 | } 26 | for(int i=0;i<=r;i++){ 27 | cout< 2 | #define F(i,n) for(int i=1;i<=n;i++) 3 | using namespace std; 4 | char s[10][10]; 5 | int r[20]; 6 | int c(int num,int j){ 7 | if(s[num][j]=='*')return 0; 8 | F(x,num-1){ 9 | if(j==r[x])return 0; 10 | if(abs(x-num)==abs(j-r[x]))return 0; 11 | } 12 | return 1; 13 | } 14 | 15 | int go(int num){ 16 | if(num==9)return 1; 17 | int a=0; 18 | F(j,8){ 19 | if(c(num,j)){ 20 | r[num]=j; 21 | a+=go(num+1); 22 | } 23 | } 24 | return a; 25 | } 26 | 27 | int main(){ 28 | F(i,8)F(j,8) 29 | cin>>s[i][j]; 30 | cout< 2 | #define int long long 3 | #define endl '\n' 4 | using namespace std; 5 | 6 | signed main(){ 7 | ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 8 | int n, x; 9 | cin >> n >> x; 10 | 11 | x = min(x, 4*n); 12 | 13 | vector arr(n); 14 | 15 | 16 | int cur = 0; 17 | arr[0] = 1; 18 | for(int i = 1; i <= x; i++) { 19 | 20 | int mov = i%n; 21 | 22 | cur = (cur + mov)%n; 23 | 24 | arr[cur] = 1; 25 | } 26 | 27 | cout << accumulate(arr.begin(), arr.end(), 0) << endl; 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Gym/Just Programming Contest 4.0/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int lst[200001]; 6 | 7 | int main(){ 8 | int t; 9 | scanf("%d", &t); 10 | while(t--){ 11 | int n; 12 | scanf("%d", &n); 13 | 14 | for(int i = 0; i < 200001; i++) lst[i] = -1; 15 | 16 | int dp[n]; 17 | dp[0] = 0; 18 | int c; 19 | scanf("%d", &c); 20 | lst[c] = 0; 21 | for(int i = 1; i < n; i++) { 22 | scanf("%d", &c); 23 | dp[i] = dp[i-1]; 24 | if(lst[c] != -1) dp[i] = min(dp[i], dp[lst[c]]); 25 | dp[i]++; 26 | lst[c] = i; 27 | } 28 | 29 | printf("%d\n", dp[n-1]); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/280/Div2E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | int n, m, dx, dy; 7 | cin >> n >> m >> dx >> dy; 8 | int v[n], g[n]; 9 | for(int i=0; i ans; 15 | for(int i=0; i> x >> y; 18 | int k = (y - v[x] + n)%n; 19 | g[k]++; 20 | if(g[k] > best){ 21 | best = g[k]; 22 | ans = make_pair(x,y); 23 | } 24 | } 25 | cout << ans.first << " " << ans.second << endl; 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/296/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int unsigned long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | int a,b; 7 | cin >> a >> b; 8 | int res = 0; 9 | while(true){ 10 | if(b == 0) break; 11 | if(a < b) swap(a,b); 12 | if(a > b){ 13 | 14 | int l = 1, r = 1123456789999; 15 | int ans = -1; 16 | while(l <= r){ 17 | int m = (l+r)/2; 18 | if(a > m*b){ 19 | ans = m; 20 | l = m+1; 21 | } 22 | else r = m-1; 23 | } 24 | res += ans; 25 | a -= ans*b; 26 | } 27 | else break; 28 | } 29 | cout << res+1 << endl; 30 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/453/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ii pair 3 | #define ff first 4 | #define ss second 5 | #define M 1000000007 6 | #define pb push_back 7 | #define endl '\n' 8 | using namespace std; 9 | 10 | typedef long long ll; 11 | 12 | int main(){ 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(0); cout.tie(0); 15 | 16 | int n,k; 17 | cin >> n >> k; 18 | int l = 0, r = 0; 19 | for(int i=0; i> x >> y; 22 | if(l <= x && x <= r) r = max(r,y); 23 | } 24 | if(r >= k) cout << "YES" << endl; 25 | else cout << "NO" << endl; 26 | } -------------------------------------------------------------------------------- /OBI/N2/2018/F1/compensacao.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 6 | int m,n; 7 | cin>>m>>n; 8 | vector saldo(n+1,0); 9 | int sum=0; 10 | for(int i=0;i>x>>v>>y; 13 | saldo[x]-=v; 14 | saldo[y]+=v; 15 | sum+=v; 16 | } 17 | int other = 0; 18 | for(int i=1;i<=n;i++){ 19 | if(saldo[i]>0)other+=saldo[i]; 20 | } 21 | if(other==sum){ 22 | cout<<"N"< 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main() { 6 | int a,b,c,x,y; 7 | cin >> a >> b >> c >> x >> y; 8 | int ans = 0; 9 | if(2LL*c <= a+b){ 10 | ans += 2LL*c*min(x,y); 11 | int tira = min(x,y); 12 | x -= tira; 13 | y -= tira; 14 | } 15 | else { 16 | ans += x*a + y*b; 17 | x = 0; 18 | y = 0; 19 | } 20 | if(x == 0){ 21 | swap(x,y); 22 | swap(a,b); 23 | } 24 | if(2*c <= a){ 25 | ans += 2*c*x; 26 | } 27 | else { 28 | ans += x*a; 29 | } 30 | cout << ans << endl; 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/301/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ii pair 4 | #define ff first 5 | #define ss second 6 | #define pb push_back 7 | 8 | using namespace std; 9 | 10 | int main(){ 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(0); cout.tie(0); 13 | 14 | int n; 15 | cin >> n; 16 | string a,b; 17 | cin >> a >> b; 18 | int ans = 0; 19 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | vector v; 9 | set s; 10 | int ans = 0; 11 | for(int i=0; i> x; 14 | if(s.count(x)) v.push_back(x); 15 | else s.insert(x); 16 | } 17 | 18 | while(s.size() > 0){ 19 | ans += s.size() -1; 20 | s.clear(); 21 | vector a; 22 | for(int x : v){ 23 | if(s.count(x)) a.push_back(x); 24 | else s.insert(x); 25 | } 26 | v = a; 27 | } 28 | 29 | cout << ans << endl; 30 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/410/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool check(string x){ 6 | string v = x; 7 | reverse(v.begin(), v.end()); 8 | if(x == v) return true; 9 | else return false; 10 | } 11 | 12 | int main(){ 13 | ios_base::sync_with_stdio(false); 14 | string x; 15 | cin >> x; 16 | for(int i=0; i 2 | 3 | int main(){ 4 | int i,j,l,c,costa=0; 5 | char mapa[1000][1000]; 6 | scanf("%d %d",&l,&c); 7 | for(i=0;i0 && i<999 && j>0 && j<999){ 18 | if(mapa[i-1][j]=='#' && mapa[i+1][j]=='#' && mapa[i][j+1]=='#' && mapa[i][j-1]=='#') costa--; 19 | } 20 | } 21 | } 22 | } 23 | printf("%d\n",costa); 24 | return 0; 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /URI/1110.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n,x; 7 | while(cin >> n, n!=0){ 8 | queue cartas; 9 | queue descarte; 10 | for(int i=1;i<=n;i++) cartas.push(i); 11 | cout << "Discarded cards: " << cartas.front(); 12 | cartas.pop(); 13 | x=cartas.front(); 14 | cartas.pop(); 15 | cartas.push(x); 16 | while(cartas.size()!= 1){ 17 | cout << ", " << cartas.front(); 18 | cartas.pop(); 19 | x=cartas.front(); 20 | cartas.pop(); 21 | cartas.push(x); 22 | } 23 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | while(getline(cin,s)){ 8 | bool valid = true, l = false, u = false, n = false; 9 | for(int i=0; i= 'a' && s[i] <= 'z') l = true; 11 | else if(s[i] >= 'A' && s[i] <= 'Z') u = true; 12 | else if(s[i] >= '0' && s[i] <= '9' ) n = true; 13 | else valid = false; 14 | } 15 | valid = valid & l & u & n; 16 | if(s.size() < 6 || s.size() > 32) valid = false; 17 | if(valid) cout << "Senha valida." << endl; 18 | else cout << "Senha invalida." << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/303/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); cout.tie(0); 8 | 9 | string s,t; 10 | cin >> s >> t; 11 | int n = s.size(); 12 | int diff = 0; 13 | for(int i=0; i 2 | 3 | int main() { 4 | char referencia; 5 | long long x=0,y=0,dist,distmax,registro,i,flag=0; 6 | scanf("%lld %lld",®istro,&distmax); 7 | for(i=0;idistmax*distmax) { 22 | flag=1; 23 | } 24 | } 25 | printf("%lld\n",flag); 26 | return 0; 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /URI/1101.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int lim1,lim2,num,soma=0,i,aux; 5 | scanf("%d %d",&lim1,&lim2); 6 | while(lim1>0 && lim2>0) { 7 | if(lim1>lim2) { //caso o segundo numero da entrada seja menor que o primeiro, eles sao trocados 8 | aux=lim1; 9 | lim1=lim2; 10 | lim2=aux; 11 | } 12 | for(i=lim1;i<=lim2;i++) { 13 | printf("%d ",i); 14 | soma+=i; 15 | if(i==lim2) 16 | printf("Sum=%d\n",soma); 17 | } 18 | scanf("%d %d",&lim1,&lim2); 19 | soma=0; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Codeforces/Gym/Just Programming Contest 4.0/H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n, m; 9 | int t; 10 | cin >> t; 11 | while(t--){ 12 | cin >> n >> m; 13 | int cont0 = 0, cont1 = 0; 14 | char x; 15 | for (int i=0; i> x; 18 | if (i==0 || j==0 || i==n-1 || j==m-1){ 19 | if (x == '0') cont0++; 20 | } 21 | else{ 22 | if (x == '1') cont1++; 23 | } 24 | } 25 | } 26 | if (cont0 > cont1) cout << -1 << endl; 27 | else cout << cont0 << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/291/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | pair normalize(int x, int y){ 5 | if(x == 0) return pair(0,1); 6 | else if(y==0) return pair(1,0); 7 | else{ 8 | if(x < 0){ 9 | x = -1*x; 10 | y = -1*y; 11 | } 12 | return pair(1, y/(x*1.0)); 13 | } 14 | } 15 | 16 | int main() { 17 | int n, x,y; 18 | set< pair > m; 19 | cin >> n >> x >> y; 20 | for(int i=0; i> a >> b; 23 | m.insert(normalize(x-a, y-b)); 24 | } 25 | cout << m.size() << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /SPOJ-BR/SENHATIA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int tamtia,min=0,max=0,num=0,tam=0,mintia,maxtia,numtia,i; 6 | char tia[1001]; 7 | scanf("%d %d %d %d",&tamtia,&mintia,&maxtia,&numtia); 8 | scanf("%s",tia); 9 | tam=strlen(tia); 10 | if(tam='a' && tia[i]<='z') min++; 14 | else if(tia[i]>='A' && tia[i]<='Z') max++; 15 | else if(tia[i]>='0' && tia[i]<='9') num++; 16 | } 17 | if(min>=mintia && (max>=maxtia && num>=numtia)) printf("Ok =/\n"); 18 | else printf("Ufa :)\n"); 19 | } 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /SPOJ/FARIDA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main() { 6 | int t; 7 | cin >> t; 8 | int test = 1; 9 | while(t--){ 10 | cout << "Case " << test++ << ": "; 11 | int n; 12 | cin >> n; 13 | int v[n]; 14 | int dp[n]; 15 | if(n == 0){ 16 | cout << 0 << endl; 17 | continue; 18 | } 19 | for(int i=0; i> v[i]; 21 | } 22 | dp[0] = v[0]; 23 | if(n > 1) dp[1] = max(v[0], v[1]); 24 | for(int i=2; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | int v[n]; 9 | int tot = 0; 10 | for(int i=0; i> v[i]; 11 | tot += abs(v[0]); 12 | for(int i=1; i 2 | 3 | int main(){ 4 | int n,i; 5 | scanf("%d",&n); 6 | int campo[n]; 7 | int contador[n]; 8 | for(i=0;i 2 | #include 3 | 4 | int main(){ 5 | int n,flag,i,j; 6 | char palavra[43]; 7 | scanf("%d",&n); 8 | for(i=0;i='A' && palavra[j]<='Z'){ 16 | palavra[j]=palavra[j]+32; 17 | } 18 | } 19 | j=0; 20 | while(j=palavra[j+1]) 22 | flag=1; 23 | j++; 24 | } 25 | if(flag==1) printf("%s: N\n",resp); 26 | else printf("%s: O\n",resp); 27 | } 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /SPOJ/IOIPALIN.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | string a, b; 9 | cin >> a; 10 | b = a; 11 | reverse(b.begin(), b.end()); 12 | int dp[a.size()+1][b.size()+1]; 13 | dp[0][0] = 0; 14 | 15 | int m = b.size(); 16 | for(int i=0; i<=n; i++) dp[i][0] = 0; 17 | for(int i=0; i<=m; i++) dp[0][i] = 0; 18 | 19 | for(int i=1; i<=n; i++){ 20 | for(int j=1; j<=m; j++){ 21 | if(a[i-1] != b[j-1]) dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 22 | if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1; 23 | } 24 | } 25 | 26 | cout << n - dp[n][n] << endl; 27 | } 28 | -------------------------------------------------------------------------------- /SPOJ/ORGNZ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | int32_t main(){ 7 | int n; 8 | cin >> n; 9 | int v[n]; 10 | int maior = 0; 11 | for(int i=0; i> v[i]; 13 | maior = max(maior, v[i]); 14 | } 15 | int cont[maior+1]; 16 | for(int i=0; i<=maior; i++) cont[i] = 0; 17 | for(int i=0; i 2 | 3 | int main() { 4 | float x,y; 5 | scanf("%f %f",&x,&y); 6 | if(x>0) { 7 | if(y>0) 8 | printf("Q1\n"); 9 | if(y<0) 10 | printf("Q4\n"); 11 | if(y==0) 12 | printf("Eixo X\n"); 13 | } 14 | if(x<0) { 15 | if(y>0) 16 | printf("Q2\n"); 17 | if(y<0) 18 | printf("Q3\n"); 19 | if(y==0) 20 | printf("Eixo X\n"); 21 | } 22 | if(x==0) { 23 | if(y!=0) 24 | printf("Eixo Y\n"); 25 | if(y==0) 26 | printf("Origem\n"); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /CSES/StickGame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int grundy[1000100]; 6 | int main(){ 7 | int n,k; 8 | cin>>n>>k; 9 | vector v(k); 10 | for(int i=0;i>v[i]; 11 | grundy[0]=0; 12 | for(int i=1;i<=n;i++){ 13 | int flag = false; 14 | for(int j=0;j=0){ 16 | if(grundy[i-v[j]]==0){ 17 | flag = true; 18 | break; 19 | } 20 | } 21 | } 22 | if(flag){ 23 | grundy[i] = 1; 24 | }else grundy[i]=0; 25 | } 26 | string s=""; 27 | for(int i=1;i<=n;i++){ 28 | if(grundy[i]==0)s+='L'; 29 | else s+='W'; 30 | } 31 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | int best = 0; 8 | int worst = 0; 9 | 10 | cin >> n >> k; 11 | 12 | int cont[101]= {}; 13 | 14 | for(int i=0; i> x; 17 | cont[x.size()]++; 18 | } 19 | 20 | string y; 21 | cin >> y; 22 | int len = y.size(); 23 | 24 | int ans = 0; 25 | for(int i=1; i 2 | #define MAXN 70 3 | #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 4 | using namespace std; 5 | 6 | int D[MAXN]; 7 | int E[MAXN]; 8 | int main(){ 9 | fastio; 10 | int n; 11 | cin>>n; 12 | int a; 13 | char pe; 14 | for(int i=0;i<=60;i++){ 15 | D[i]=0; 16 | E[i]=0; 17 | } 18 | 19 | for(int i=0;i>a>>pe; 21 | if(pe=='E'){ 22 | E[a]++; 23 | }else{ 24 | D[a]++; 25 | } 26 | } 27 | int res=0; 28 | for(int i=30;i<=60;i++){ 29 | int atual = min(E[i],D[i]); 30 | res+=atual; 31 | } 32 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin >> t; 8 | while(t--){ 9 | string a,b; 10 | cin >> a >> b; 11 | int dp[a.size()+1][b.size()+1]; 12 | int n = a.size(), m = b.size(); 13 | for(int i=0; i<=b.size(); i++) dp[0][i] = i; 14 | for(int i=0; i<=a.size(); i++) dp[i][0] = i; 15 | for(int i=1; i<=n; i++){ 16 | for(int j=1; j<=m; j++){ 17 | if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1]; 18 | else dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1])) + 1; 19 | } 20 | } 21 | cout << dp[a.size()][b.size()] << endl; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/378/Div2B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int left[n], right[n]; 9 | long long sl = 0,sr = 0; 10 | for(int i=0; i> left[i] >> right[i]; 12 | sl += left[i]; 13 | sr += right[i]; 14 | } 15 | long long maximize = abs(sl - sr); 16 | int res = -1; 17 | for(int i=0; i maximize){ 23 | res = i; 24 | maximize = abs(al - ar); 25 | } 26 | } 27 | cout << res+1 << endl; 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/501/Div3C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int32_t main(){ 7 | int n,m; 8 | cin >> n >> m; 9 | int s = 0; 10 | vector v; 11 | for(int i=0; i> a >> b; 14 | v.pb(a-b); 15 | s += a; 16 | } 17 | sort(v.begin(), v.end(), greater()); 18 | 19 | int compress = 0; 20 | if(s <=m){ 21 | cout << compress << endl; 22 | return 0; 23 | } 24 | for(int x : v){ 25 | s -= x; 26 | compress++; 27 | if(s <=m){ 28 | cout << compress << endl; 29 | return 0; 30 | } 31 | } 32 | cout << -1 << endl; 33 | } 34 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Educational Round 23/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ff first 3 | #define ss second 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | pair ini, fim; 9 | pair move; 10 | 11 | cin >> ini.ff >> ini.ss >> fim.ff >> fim.ss; 12 | cin >> move.ff >> move.ss; 13 | 14 | int difX = abs(fim.ff - ini.ff); 15 | int difY = abs(fim.ss - ini.ss); 16 | 17 | if(difX % move.ff || difY % move.ss) cout << "NO" << endl; 18 | else { 19 | int moveX = difX/move.ff; 20 | int moveY = difY/move.ss; 21 | 22 | if(abs(moveX - moveY) % 2) cout << "NO" << endl; 23 | else cout << "YES" << endl; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Intel Code Challenge/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int count[n]; 9 | string verse[n]; 10 | for(int i=0; i> count[i]; 11 | cin.ignore(); 12 | for(int i=0; i getStrongest(vector& arr, int k) { 4 | int m = ((arr.size() - 1) / 2); 5 | vector srt(arr); 6 | sort(srt.begin(), srt.end()); 7 | int mean = srt[m]; 8 | vector> strong; 9 | for(int x : arr){ 10 | strong.push_back(make_pair(abs(mean - x), x)); 11 | } 12 | sort(strong.begin(), strong.end(), greater>()); 13 | vector ans; 14 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | map best; 6 | 7 | long long compute(long long n){ 8 | if(n == 0) return 0; 9 | //cout << n << endl; 10 | long long c1,c2,c3; 11 | c1 = (best.count(n/2) ? best[n/2] : compute(n/2)); 12 | c2 = (best.count(n/3) ? best[n/3] : compute(n/3)); 13 | c3 = (best.count(n/4) ? best[n/4] : compute(n/4)); 14 | long long ans = c1+c2+c3; 15 | if(n < ans){ 16 | best[n] = ans; 17 | return ans; 18 | } 19 | else{ 20 | best[n] = n; 21 | return n; 22 | } 23 | } 24 | 25 | 26 | int main(){ 27 | long long n; 28 | while(cin >> n) cout << compute(n) << endl; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/472/Div2D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | int n; 7 | cin >> n; 8 | int below[n]; 9 | int under[n]; 10 | cin >> under[0]; 11 | below[0] = 0; 12 | int tot = 0; 13 | vector change; 14 | for(int i=1; i> under[i]; 16 | below[i] = below[i-1] + (under[i-1] - under[i]); 17 | tot += below[i]; 18 | change.push_back(i); 19 | if(below[i] < 0){ 20 | while(below[i] < 0){ 21 | tot += (i - change.back() + 1); 22 | change.pop_back(); 23 | below[i]++; 24 | } 25 | } 26 | } 27 | cout << tot << endl; 28 | } -------------------------------------------------------------------------------- /OBI/N2/2011/F2/quadrado.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main(){ 6 | srand(time(0)); 7 | int n,s; 8 | cin>>n>>s; 9 | int vall[n+1],valc[n+1]; 10 | 11 | 12 | for(int i=1;i<=n;i++)vall[i] = i; 13 | 14 | 15 | 16 | for(int i=1;i 2 | 3 | int main(void) { 4 | long long i,esq,dir,c,t,k,x,y,dist,meio; 5 | scanf("%lld %lld",&c,&t); 6 | long long circulo[c]; 7 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int size,n; 7 | cin >> size >> n; 8 | int w[n]; 9 | int v[n]; 10 | 11 | for(int i=0; i> w[i] >> v[i]; 13 | } 14 | 15 | int dp[size+1]; 16 | // for(int i=0; i=0; j--){ 22 | if(j+w[i] <= size && dp[j] != -1) 23 | dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]); 24 | } 25 | } 26 | 27 | int maior = 0; 28 | for(int i=0; i<=size; i++) maior = max(maior, dp[i]); 29 | cout << maior << endl; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/302/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int k; 7 | cin >> k; 8 | string s; 9 | cin >> s; 10 | 11 | vector v; 12 | set forb; 13 | for(int i=0; i< s.size(); i++){ 14 | if(forb.count(s[i])) continue; 15 | forb.insert(s[i]); 16 | v.push_back(i); 17 | } 18 | 19 | if(v.size() < k){ 20 | cout << "NO" << endl; 21 | return 0; 22 | } 23 | cout << "YES" << endl; 24 | while(v.size() > k) v.pop_back(); 25 | v.push_back(s.size()); 26 | for(int i=0; i 2 | #define int long long 3 | using namespace std; 4 | 5 | struct vertex{ 6 | int p, w; 7 | }; 8 | 9 | bool cmp(const vertex & a, const vertex & b){ 10 | return a.p + a.w < b.p + b.w; 11 | } 12 | 13 | int32_t main(){ 14 | int n; 15 | cin >> n; 16 | vertex v[n]; 17 | for(int i=0; i> v[i].p >> v[i].w; 19 | } 20 | sort(v, v+n, cmp); 21 | 22 | 23 | int ans = 1; 24 | int curr = 0; 25 | 26 | for(int i=1; i= v[i].w + v[curr].w){ 28 | ans++; 29 | curr = i; 30 | } 31 | } 32 | 33 | cout << ans << endl; 34 | } -------------------------------------------------------------------------------- /URI/1084.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,k; 7 | string v; 8 | while(cin >> n >> k, n + k !=0){ 9 | cin >> v; 10 | vector ans; 11 | int cont = 0; 12 | for(int i=0; i 0 && ans.back() < v[i] && cont < k){ 16 | ans.pop_back(); 17 | cont++; 18 | } 19 | ans.push_back(v[i]); 20 | } 21 | } 22 | 23 | while(cont < k){ 24 | cont++; 25 | ans.pop_back(); 26 | } 27 | for(int i=0; i< ans.size(); i++) cout << ans[i]; 28 | cout << endl; 29 | } 30 | 31 | } 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /URI/2023.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct kid{ 6 | string nome; 7 | int id; 8 | }; 9 | 10 | bool cmp(const kid & a, const kid & b){ 11 | return a.nome < b.nome; 12 | } 13 | 14 | int main(){ 15 | vector v; 16 | vector registro; 17 | 18 | string x; 19 | int k=0; 20 | while(getline(cin, x)){ 21 | registro.push_back(x); 22 | for(int i=0; i= 'A' && x[i] <= 'Z') x[i] += ('a' - 'A'); 24 | } 25 | kid aux; 26 | aux.id = k++; 27 | aux.nome = x; 28 | v.push_back(aux); 29 | } 30 | 31 | sort(v.begin(), v.end(), cmp); 32 | 33 | cout << registro[v[v.size()-1].id] << endl; 34 | } 35 | -------------------------------------------------------------------------------- /AtCoder/EducationalDPContest/K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAXK 100100 3 | using namespace std; 4 | 5 | int dp[MAXK]; 6 | int A[110]; 7 | 8 | int main(){ 9 | int n,k; 10 | cin>>n>>k; 11 | for(int i=0;i<=k;i++)dp[i]=-1; 12 | 13 | for(int i=0;i>A[i]; 14 | 15 | dp[0]=1; 16 | 17 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int z[1123456]; 6 | 7 | void precompute(string & s, int * z){ 8 | //string s = str + pattern; 9 | for(int i=0; i r){ 15 | r = i+z[i]-1; 16 | l = i; 17 | } 18 | } 19 | } 20 | 21 | int main(){ 22 | string s; 23 | cin >> s; 24 | precompute(s,z); 25 | for(int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | long long n,k; 8 | cin >> n >> k; 9 | long long v[n]; 10 | long long menor = INT_MAX; 11 | for(int i=0; i> v[i]; 13 | menor = min(menor, v[i]); 14 | } 15 | 16 | long long modulo = 0; 17 | modulo = v[0]%k; 18 | for(int i=1; i& arr, int k) { 4 | map cnt; 5 | for(int x : arr) cnt[x]++; 6 | vector v; 7 | for(pair p : cnt){ 8 | v.push_back(p.second); 9 | } 10 | sort(v.begin(), v.end()); 11 | int tot = v.size(); 12 | for(int i=0; i 0) break; 17 | tot--; 18 | } 19 | return tot; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/303/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | struct tree{ 6 | int x,h; 7 | }; 8 | 9 | int32_t main(){ 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(0); cout.tie(0); 12 | 13 | int n; 14 | cin >> n; 15 | tree v[n]; 16 | for(int i=0; i> v[i].x >> v[i].h; 17 | int ans = 1; 18 | int last = v[0].x; 19 | for(int i=1; i last){ 21 | ans++; 22 | last = v[i].x; 23 | } 24 | else if(i+1 == n || v[i].x + v[i].h < v[i+1].x){ 25 | ans++; 26 | last = v[i].x + v[i].h; 27 | } 28 | last = max(last, v[i].x); 29 | } 30 | cout << ans << endl; 31 | } 32 | -------------------------------------------------------------------------------- /URI/1191.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char prefixo[28]; 5 | char infixo[28]; 6 | 7 | void formapos(int inip,int fimp,int inii,int fimi){ 8 | int p1=inip,p2=fimp,i1=inii,i2=fimi; 9 | if(i2().toSortedMap() 4 | 5 | for(x in hand){ 6 | if(s.containsKey(x)) s[x] = s[x]!! +1 7 | else s[x] = 1 8 | } 9 | 10 | while(s.size > 0){ 11 | var cur = s.firstKey() 12 | for(i in cur until cur+W){ 13 | if(!s.containsKey(i)){ 14 | return false 15 | } 16 | s[i] = s[i]!! -1 17 | if(s[i] == 0) s.remove(i) 18 | } 19 | } 20 | return true 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /OBI/N2/2016/F2/quase primo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 3 | #define pb push_back 4 | #define int long long 5 | using namespace std; 6 | int n,k; 7 | 8 | int res=0; 9 | int v[50]; 10 | void solve(int id,int have,int par){ 11 | if(id==k){ 12 | int contri = n/have; 13 | if(par%2)contri = -contri; 14 | res+=contri; 15 | return ; 16 | } 17 | 18 | solve(id+1,have,par); 19 | if(have*v[id]<=n)solve(id+1,have*v[id],par+1); 20 | 21 | } 22 | 23 | 24 | int32_t main(){ 25 | fastio; 26 | cin>>n>>k; 27 | for(int i=0;i>v[i]; 29 | } 30 | solve(0,1,0); 31 | cout< 2 | 3 | int main(){ 4 | int npedra,nsapo,saposoma,saposub,pos,dist,i; 5 | scanf("%d %d",&npedra,&nsapo); 6 | int pedras[npedra]; 7 | for(i=0;i=0){ 22 | pedras[saposub]=1; 23 | saposub=saposub-dist; 24 | } 25 | } 26 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | int dp[6006][6006]; 6 | 7 | int main(){ 8 | int n; 9 | cin >> n; 10 | while(n--){ 11 | string a, b; 12 | cin >> a; 13 | b = a; 14 | reverse(b.begin(), b.end()); 15 | dp[0][0] = 0; 16 | 17 | int n = a.size(), m = b.size(); 18 | for(int i=0; i<=n; i++) dp[i][0] = 0; 19 | for(int i=0; i<=m; i++) dp[0][i] = 0; 20 | 21 | for(int i=1; i<=n; i++){ 22 | for(int j=1; j<=m; j++){ 23 | if(a[i-1] != b[j-1]) dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 24 | if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1; 25 | } 26 | } 27 | 28 | cout << n - dp[n][n] << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /URI/2479.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | char c; 9 | int comp=0, ncomp=0; 10 | vector v(n); 11 | for(int i=0; i> c >> v[i]; 13 | if(c == '-') ncomp++; 14 | else comp++; 15 | } 16 | for(int i=0; i 2 | #include 3 | #include 4 | using namespace std; 5 | vector v; 6 | vector pilha; 7 | 8 | int lis(){ 9 | 10 | // vector pilha; 11 | vector::iterator it; 12 | for(int i=0;i<(int)v.size();i++){ 13 | it = lower_bound(pilha.begin(),pilha.end(),v[i]); 14 | if(it==pilha.end()) pilha.push_back(v[i]); 15 | else *it = v[i]; 16 | } 17 | 18 | return pilha.size(); 19 | } 20 | 21 | 22 | int main() { 23 | int n, soma=0; 24 | cin >> n; 25 | // vector v; 26 | for (int i = 0; i < n; i++){ 27 | cin>>soma; 28 | v.push_back(soma); 29 | } 30 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin >> n; 8 | int v[n]; 9 | for(int i=0; i> v[i]; 11 | } 12 | 13 | int dp[n][2]; 14 | 15 | dp[0][0] = 1; 16 | dp[0][1] = 1; 17 | 18 | int mx = 1; 19 | for(int i=1; i v[j]) dp[i][1] = max(dp[i][1], dp[j][0]+1); 24 | if(v[i] < v[j]) dp[i][0] = max(dp[i][0], dp[j][1]+1); 25 | } 26 | mx = max(mx, max(dp[i][0], dp[i][1])); 27 | } 28 | cout << mx << endl; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/280/Div2D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n,x,y; 7 | cin >> n >> x >> y; 8 | long long lcm = (x*y)/__gcd(x,y); 9 | x = lcm/x; 10 | y = lcm/y; 11 | 12 | while(n--){ 13 | long long a; 14 | cin >> a; 15 | 16 | long long l = 0, r = (long long)1e17; 17 | long long ans = 0; 18 | while(l <= r){ 19 | long long m = (l+r)>>1; 20 | if(m/x + m/y >= a){ 21 | ans = m; 22 | r = m -1; 23 | } 24 | else l = m+1; 25 | } 26 | if(ans%x == 0 && ans%y == 0) cout << "Both" << endl; 27 | else if(ans%x == 0) cout << "Vanya" << endl; 28 | else cout << "Vova" << endl; 29 | } 30 | } -------------------------------------------------------------------------------- /LeetCode/General Problems/AllPathsFromSourceToTarget.cs: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | IList cur = new List(); 3 | private void go(int u, IList> paths, int[][] graph){ 4 | if(u == graph.Length-1){ 5 | paths.Add(new List(cur)); 6 | return; 7 | } 8 | foreach(int x in graph[u]){ 9 | cur.Add(x); 10 | go(x, paths, graph); 11 | cur.RemoveAt(cur.Count-1); 12 | } 13 | } 14 | public IList> AllPathsSourceTarget(int[][] graph) { 15 | IList> ans = new List>(); 16 | cur.Add(0); 17 | go(0, ans, graph); 18 | return ans; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LeetCode/General Problems/DecryptStringFromAlphabetToIntegerMapping.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun freqAlphabets(s: String): String { 3 | var i = 0 4 | var ans : String = "" 5 | while(i < s.length){ 6 | if(i+2 < s.length && s[i+2] == '#'){ 7 | var integ = 10*(s[i].toInt() - 48) + (s[i+1].toInt() - 48) 8 | var ch = ('a'.toInt() + integ - 1).toChar() 9 | ans += (ch) 10 | i += 3 11 | } else { 12 | var ch = ('a'.toInt() + (s[i].toInt() - 48) - 1).toChar() 13 | ans += (ch) 14 | i += 1 15 | } 16 | } 17 | return ans 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SPOJ-BR/CARTEI14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int anterior=0,i,numerocasas,numeroencomendas,tempo=0,encomenda; 5 | int esq,dir,meio; 6 | scanf("%d %d",&numerocasas,&numeroencomendas); 7 | int casas[numerocasas]; 8 | for(i=0;i 2 | 3 | using namespace std; 4 | 5 | #define int long long 6 | int32_t main() { 7 | int a,b,m; 8 | cin >> a >> b >> m; 9 | if(max(a,b) >= m){ 10 | cout << 0 << endl; 11 | return 0; 12 | } 13 | if(max(a,b) <= 0){ 14 | cout << -1 << endl; 15 | return 0; 16 | } 17 | int ans = 0; 18 | if(min(a,b) < 0){ 19 | int x = -min(a,b); 20 | int y = max(a,b); 21 | ans += (x + (y-1))/(y); 22 | x = -x; 23 | x += y*ans; 24 | a = x; 25 | b = y; 26 | } 27 | while(max(a,b) < m){ 28 | if(a > b) swap(a,b); 29 | a = a+b; 30 | ans++; 31 | } 32 | cout << ans << endl; 33 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Educational Round 33/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n; 6 | int v[1123]; 7 | 8 | bool solve(int i, int j1, int j2, int spec){ 9 | if(i == n) return true; 10 | bool flag = false; 11 | if(j1 == v[i]){ 12 | flag |= solve(i+1, j1, spec, j2); 13 | } 14 | else if(j2 == v[i]){ 15 | flag |= solve(i+1, j2, spec, j1); 16 | } 17 | else{ 18 | flag = false; 19 | } 20 | return flag; 21 | } 22 | 23 | int main(){ 24 | cin >> n; 25 | for(int i=0; i> v[i]; 27 | } 28 | bool flag = false; 29 | flag |= solve(0, 1, 2, 3); 30 | if(flag) cout << "YES" << endl; 31 | else cout << "NO" << endl; 32 | } -------------------------------------------------------------------------------- /Codeforces/Official Rounds/Educational Round 33/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, l; 7 | cin >> n >> l; 8 | int v[n]; 9 | for(int i=0; i> v[i]; 10 | int curr = 0; 11 | for(int i=0; i l){ 17 | cout << -1 << endl; 18 | return 0; 19 | } 20 | } 21 | int ans = 0; 22 | curr = 0; 23 | for(int i=0; i() } 4 | var cnt = mutableMapOf() 5 | for(x in nums){ 6 | if(cnt.containsKey(x)) cnt[x] = cnt[x]!!+1 7 | else cnt[x] = 1 8 | } 9 | for((key,v) in cnt){ 10 | tops[v].add(key) 11 | } 12 | var ans = IntArray(k) { 0 } 13 | var pt = 0 14 | for(x in nums.size downTo 1 step 1){ 15 | for(y in tops[x]){ 16 | if(pt < k) ans[pt++] = y 17 | } 18 | } 19 | return ans 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Codeforces/Gym/2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ii pair 3 | #define w first 4 | #define h second 5 | #define int long long 6 | using namespace std; 7 | 8 | 9 | int32_t main(){ 10 | int n; 11 | cin >> n; 12 | int v[n]; 13 | for(int i=0; i> v[i]; 14 | 15 | int l = 0; 16 | int r = 1e13; 17 | 18 | int ans = -1; 19 | 20 | while(l <= r){ 21 | int m = (l+r)>>1; 22 | 23 | int cnt = 0; 24 | for(int i=0; i= 2*m){ 27 | ans = m; 28 | l = m+1; 29 | } 30 | else r = m-1; 31 | } 32 | 33 | cout << ans << endl; 34 | } 35 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/384/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,a,b; 7 | cin >> n >> a >> b; 8 | if(a > b) swap(a,b); 9 | string x; 10 | cin >> x; 11 | int ini = a-1; 12 | int fim = b-1; 13 | int cost = 0; 14 | //cout << ini << " " << fim << endl; 15 | while(ini < fim){ 16 | int i; 17 | for(i = ini+1 ; i<=fim; i++){ 18 | //cout << "entrou" << endl; 19 | //cout << x[ini] << " " << x[i] << endl; 20 | if(x[i] == x[ini]){ 21 | ini = i; 22 | } 23 | } 24 | if(i == fim+1 && ini < fim){ 25 | cost++; 26 | ini++; 27 | } 28 | //cout << ini << " " << cost << endl; 29 | //getchar(); 30 | } 31 | cout << cost << endl; 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces/Official Rounds/420/Div2C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | int n; 8 | cin >> n; 9 | set s; 10 | int ans = 0; 11 | int need[n+1]; 12 | int last = -1; 13 | for(int i=1; i<=n; i++){ 14 | need[i] = -1; 15 | } 16 | for(int i=0; i<2*n; i++){ 17 | string order; 18 | cin >> order; 19 | if(order == "add") { 20 | int x; 21 | cin >> x; 22 | s.insert(x); 23 | if(x > *s.begin()) need[*s.begin()] = i; 24 | 25 | } 26 | else { 27 | if(need[*s.begin()] > last){ 28 | ans++; 29 | last = need[*s.begin()]; 30 | } 31 | s.erase(s.begin()); 32 | } 33 | } 34 | cout << ans << endl; 35 | } 36 | -------------------------------------------------------------------------------- /SPOJ-BR/FATORIAL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define debug 0 3 | #define int unsigned long long 4 | using namespace std; 5 | 6 | int memo[1000001]; 7 | 8 | int dp(int n){ 9 | if(n == 1) return 1; 10 | if(memo[n] != 0) return memo[n]; 11 | int ans = dp(n-1)*n; 12 | while(!(ans%10)) ans/=10; 13 | memo[n] = ans % 100000; 14 | return memo[n]; 15 | } 16 | 17 | int32_t main(){ 18 | ios_base::sync_with_stdio(false); 19 | int n; 20 | int t=0; 21 | for(int i=0; i<1000001; i++) memo[i] = 0; 22 | dp(1000000); 23 | while(cin >> n){ 24 | int ans = memo[n]; 25 | while(ans%10 == 0) ans/=10; 26 | cout << "Instancia " << ++t << endl; 27 | cout << ans%10 << endl; 28 | cout << endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/Gym/2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | #define int long long 5 | main(){ 6 | int n,k; 7 | cin >> n >> k; 8 | vector v(n); 9 | for(int &x : v) cin >> x; 10 | priority_queue, greater> pq; 11 | int tmp = 0, ans = 0; 12 | for(int i=0;;){ 13 | if(pq.size() < k && i < n){ 14 | pq.push(v[i]); 15 | i++; 16 | } 17 | else{ 18 | if(pq.empty()){ 19 | break; 20 | } 21 | else{ 22 | int ch = pq.top(); 23 | pq.pop(); 24 | tmp += ch; 25 | ans += tmp; 26 | } 27 | } 28 | } 29 | cout << ans << endl; 30 | } 31 | -------------------------------------------------------------------------------- /Codeforces/Gym/La Salle-Pui Ching Programming Challenge 2016/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define int long long // LEMBRAR DE TROCAR CASO PROBLEMA DE MEMORIA 6 | #define pii pair 7 | #define ieps (int) 1e6 8 | #define eps (int) 1e9 9 | #define mp make_pair 10 | #define pb push_back 11 | 12 | 13 | int32_t main(){ 14 | long double ax , by , cz; 15 | long double x , y, z; 16 | cin>>x>>y>>z; 17 | ax = 100.00000000001/x*1.00000000 , by = 100.0000000001/y*1.0000000, cz = 100.0000000001/z*1.0000000000; 18 | //cout< 2 | #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 3 | #define pb push_back 4 | #define int long long 5 | using namespace std; 6 | 7 | int sum[10]; 8 | 9 | int32_t main(){ 10 | fastio; 11 | int n; 12 | cin>>n; 13 | int fat=1; 14 | for(int i=1;i<=n;i++){ 15 | fat*=i; 16 | } 17 | memset(sum,0,sizeof(sum)); 18 | 19 | int deveria=0; 20 | for(int i=1;i<=n;i++){ 21 | deveria+=(i*(fat/n)); 22 | } 23 | for(int i=1;i>x; 27 | sum[j]+=x; 28 | } 29 | } 30 | for(int j=0;j 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n,teste=1; 7 | while(cin >> n, n!=0){ 8 | int ini=1,s,e,sum=0,saldoanterior=0; 9 | for(int i=1; i<=n; i++){ 10 | int x,y; 11 | cin >> x >> y; 12 | if((x-y)+sum >=0){ 13 | sum += (x-y); 14 | } 15 | else { 16 | sum = 0; 17 | ini = i+1; 18 | } 19 | if(sum > saldoanterior || (sum == saldoanterior && i-ini > e-s)){ 20 | saldoanterior = sum; 21 | s = ini; 22 | e = i; 23 | } 24 | } 25 | cout << "Teste " << teste++ << endl; 26 | if(saldoanterior > 0) { 27 | cout << s << " " << e << endl; 28 | } 29 | else cout << "nenhum" << endl; 30 | cout << endl; 31 | } 32 | } 33 | 34 | --------------------------------------------------------------------------------