├── C++ ├── AtCoder │ └── ABC │ │ ├── abc170_a.cpp │ │ ├── abc170_b.cpp │ │ ├── abc170_c.cpp │ │ └── abc170_d.cpp ├── CCC │ ├── CCC Junior │ │ ├── ccc00j3.cpp │ │ ├── ccc04j2.cpp │ │ ├── ccc14j3.cpp │ │ ├── ccc17j1.cpp │ │ └── ccc17j2.cpp │ └── CCC Senior │ │ ├── ccc07s1.cpp │ │ ├── ccc11s2.cpp │ │ ├── ccc12s1.cpp │ │ ├── ccc21s1.cpp │ │ ├── ccc21s2.cpp │ │ ├── ccc23s1.cpp │ │ └── ccc23s3.cpp ├── CCO │ └── cco06p1.cpp ├── CSES │ ├── cses1068.cpp │ ├── cses1069.cpp │ ├── cses1070.cpp │ ├── cses1083.cpp │ └── cses1094.cpp ├── Codeforces │ ├── Avito Code Challenge │ │ └── cf981C.cpp │ ├── Codeforces Alpha Round │ │ └── cf20C.cpp │ ├── Codeforces Beta Round │ │ └── cf115A.cpp │ ├── Codeforces Global Round │ │ ├── cf1368A.cpp │ │ └── cf1368B.cpp │ ├── Codeforces Round │ │ ├── Div 1 │ │ │ ├── cf1007A.cpp │ │ │ ├── cf1264A.cpp │ │ │ ├── cf1292A.cpp │ │ │ └── cf1340A.cpp │ │ ├── Div 2 │ │ │ ├── cf1104B.cpp │ │ │ ├── cf1106B.cpp │ │ │ ├── cf1304B.cpp │ │ │ ├── cf1355A.cpp │ │ │ ├── cf625A.cpp │ │ │ └── cf959C.cpp │ │ ├── Div 3 │ │ │ ├── cf1006E.cpp │ │ │ ├── cf1213B.cpp │ │ │ ├── cf1324C.cpp │ │ │ └── cf1328A.cpp │ │ └── Div 4 │ │ │ └── cf1352A.cpp │ ├── Compete McGill │ │ ├── mcgill1A.cpp │ │ └── mcgill1B.cpp │ ├── Educational Codeforces Round │ │ ├── cf1373A.cpp │ │ └── cf1373B.cpp │ └── MailRu Cup │ │ └── cf1057A.cpp ├── DMOJ │ ├── AC │ │ ├── acc4p0.cpp │ │ └── acc4p1.cpp │ ├── BFS │ │ └── bfs19p2.cpp │ ├── DMOPC │ │ ├── dmopc14c1p2.cpp │ │ └── dmopc15c1p1.cpp │ ├── bf1easy.cpp │ ├── bf1hard.cpp │ ├── factorial.cpp │ ├── pwindsor18p3.cpp │ └── suomi.cpp └── Kattis │ └── alicedigital.cpp ├── Java ├── AtCoder │ ├── dpa.java │ ├── dpb.java │ ├── dpc.java │ ├── dpd.java │ ├── dpe.java │ ├── dpg.java │ ├── dph.java │ └── dpk.java ├── CCC │ ├── CCC Junior │ │ ├── ccc02j1.java │ │ ├── ccc03j1.java │ │ ├── ccc04j1.java │ │ ├── ccc04j3.java │ │ ├── ccc04j4.java │ │ ├── ccc05j3.java │ │ ├── ccc06j1.java │ │ ├── ccc06j2.java │ │ ├── ccc06j3.java │ │ ├── ccc06j4.java │ │ ├── ccc07j1.java │ │ ├── ccc07j2.java │ │ ├── ccc07j5.java │ │ ├── ccc08j1.java │ │ ├── ccc08j4.java │ │ ├── ccc09j1.java │ │ ├── ccc10j1.java │ │ ├── ccc10j4.java │ │ ├── ccc10j5.java │ │ ├── ccc11j1.java │ │ ├── ccc11j4.java │ │ ├── ccc11j5.java │ │ ├── ccc12j1.java │ │ ├── ccc13j1.java │ │ ├── ccc13j4.java │ │ ├── ccc14j1.java │ │ ├── ccc14j2.java │ │ ├── ccc15j1.java │ │ ├── ccc15j4.java │ │ ├── ccc15j5.java │ │ ├── ccc16j1.java │ │ ├── ccc17j3.java │ │ ├── ccc18j1.java │ │ ├── ccc18j2.java │ │ └── ccc18j3.java │ └── CCC Senior │ │ ├── ccc00s4.java │ │ ├── ccc01s3.java │ │ ├── ccc02s2p5.java │ │ ├── ccc03s3.java │ │ ├── ccc06s2.java │ │ ├── ccc07s2.java │ │ ├── ccc07s3.java │ │ ├── ccc07s4.java │ │ ├── ccc07s5.java │ │ ├── ccc08s2.java │ │ ├── ccc08s3.java │ │ ├── ccc09s1.java │ │ ├── ccc09s2.java │ │ ├── ccc09s4.java │ │ ├── ccc11s1.java │ │ ├── ccc11s3.java │ │ ├── ccc12s3.java │ │ ├── ccc12s5.java │ │ ├── ccc13s4.java │ │ ├── ccc13s5.java │ │ ├── ccc14s2.java │ │ ├── ccc14s3.java │ │ ├── ccc14s4.java │ │ ├── ccc15s1.java │ │ ├── ccc15s2.java │ │ ├── ccc15s3.java │ │ ├── ccc16s1.java │ │ ├── ccc16s2.java │ │ ├── ccc16s5.java │ │ ├── ccc17s1.java │ │ ├── ccc17s2.java │ │ ├── ccc17s3.java │ │ ├── ccc18s1.java │ │ ├── ccc18s2.java │ │ ├── ccc18s3.java │ │ ├── ccc19s1.java │ │ ├── ccc19s2.java │ │ ├── ccc20s1.java │ │ ├── ccc20s2.java │ │ ├── ccc96s5.java │ │ └── ccc99s4.java ├── CCO │ ├── cco08p4.java │ ├── cco12p2.java │ ├── cco18p1.java │ ├── cco20p1.java │ └── cco96p5.java ├── COCI │ ├── coci06c2p4.java │ ├── coci06p3.java │ ├── coci07c2p2.java │ ├── coci08c2p5.java │ └── coci09c1p1.java ├── Codeforces │ ├── ACMSGURU │ │ ├── APlusB.java │ │ ├── AToBMinusBToA.java │ │ ├── ScientificProblem.java │ │ └── TheSum.java │ ├── Codeforces Div 2 │ │ ├── cf1358A.java │ │ └── cf1358B.java │ └── Watermelon.java ├── DMOJ │ ├── 16bitswonly.java │ ├── BFS │ │ └── bfs19p1.java │ ├── BTS │ │ └── bts16p5.java │ ├── DMOPC │ │ ├── dmopc13c1p4.java │ │ ├── dmopc14c1p5.java │ │ ├── dmopc14c2p4.java │ │ ├── dmopc14c2p5.java │ │ ├── dmopc14c7p4.java │ │ ├── dmopc16c1p1.java │ │ ├── dmopc16c2p1.java │ │ ├── dmopc16c3p1.java │ │ ├── dmopc16c4p1.java │ │ ├── dmopc17c2p1.java │ │ ├── dmopc19c1p0.java │ │ ├── dmopc19c2p0.java │ │ ├── dmopc19c2p2.java │ │ ├── dmopc19c3p1.java │ │ ├── dmopc19c4p0.java │ │ └── dmopc19c4p1.java │ ├── DMPG │ │ └── dmpg15b4.java │ ├── GlobeX Cup │ │ ├── globexcup18s0.java │ │ ├── globexcup18s1.java │ │ ├── globexcup19j1.java │ │ └── globexcup19j2.java │ ├── Mock CCC │ │ ├── mockccc19j1.java │ │ ├── mockccc19j2.java │ │ ├── mockccc19s1.java │ │ ├── mockccc19s2.java │ │ ├── mockccc2020c1j4.java │ │ ├── nccc1j1.java │ │ ├── nccc1j2.java │ │ ├── nccc3j1.java │ │ ├── nccc3j3s1.java │ │ ├── nccc5j5s3.java │ │ └── nccc5s4.java │ ├── Mock CCO │ │ ├── mcco17p1.java │ │ └── ncco4d1p3.java │ ├── RTE │ │ └── rte16s3.java │ ├── TLE │ │ ├── tle16c4p1.java │ │ └── tle17c2p2.java │ ├── Triway Cup │ │ ├── tc18summera.java │ │ └── tc19summerj3.java │ ├── VMSS │ │ ├── pwindsor18p6.java │ │ ├── vmss7wc15c4p3.java │ │ ├── vmss7wc16c3p2.java │ │ └── vmss7wc16c3p3.java │ ├── Valentines Day │ │ ├── valday15p2.java │ │ ├── valentines18j1.java │ │ └── valentines18j2.java │ ├── aminusb.java │ ├── aplusb.java │ ├── bf1.java │ ├── bf3.java │ ├── hci16oversleep.java │ ├── helloworld.java │ ├── helloworldhard.java │ ├── lis.java │ ├── modinv.java │ ├── pickit.java │ ├── scroll.java │ ├── sssp.java │ ├── stnbd2.java │ ├── tss17b.java │ └── year2017p6.java ├── DWITE │ ├── dwite07c4p4.java │ ├── dwite08c4p4.java │ ├── dwite09c3p2.java │ └── dwite10c3p4.java ├── ECOO │ └── ecoo1p4.java ├── IOI │ ├── ioi1113.java │ └── ioi94p1.java ├── SPOJ │ ├── a2.java │ └── a3.java ├── UCC │ ├── ucc2020p1.java │ ├── ucc2020p2.java │ ├── ucc2020p3.java │ └── ucc2020p5.java ├── USACO │ ├── usaco20c3bp1.java │ ├── usaco20c3bp2.java │ └── usaco20c3bp3.java └── WCIPEG │ ├── Woburn Challenge │ ├── wc151j2.java │ ├── wc151s2.java │ ├── wc161s2.java │ └── wc96p5.java │ ├── a4b1.java │ ├── avatarbalance.java │ ├── graph1p2.java │ ├── intrvl.java │ ├── p100ex4.java │ ├── p287ex5.java │ ├── primestreet.java │ └── trickortreat.java ├── Python ├── CCC │ ├── CCC Junior │ │ ├── ccc00j1.py │ │ ├── ccc00j2.py │ │ ├── ccc00j4.py │ │ ├── ccc01j1.py │ │ ├── ccc01j2.py │ │ ├── ccc02j1.py │ │ ├── ccc02j2.py │ │ ├── ccc02s2.py │ │ ├── ccc03j2.py │ │ ├── ccc05j1.py │ │ ├── ccc05j2.py │ │ ├── ccc05j5.py │ │ ├── ccc07j3.py │ │ ├── ccc07j4.py │ │ ├── ccc08j2.py │ │ ├── ccc10j2.py │ │ ├── ccc11j2.py │ │ ├── ccc11j3.py │ │ ├── ccc12j2.py │ │ ├── ccc12j3.py │ │ ├── ccc12j4.py │ │ ├── ccc13j2.py │ │ ├── ccc13j3.py │ │ ├── ccc15j2.py │ │ ├── ccc15j3.py │ │ ├── ccc16j2.py │ │ ├── ccc16j3.py │ │ ├── ccc16j4.py │ │ ├── ccc19j1.py │ │ ├── ccc19j2.py │ │ ├── ccc19j3.py │ │ ├── ccc20j1.py │ │ ├── ccc20j2.py │ │ ├── ccc20j3.py │ │ └── ccc20j4.py │ └── CCC Senior │ │ ├── ccc03s1.py │ │ ├── ccc05s1.py │ │ ├── ccc05s2.py │ │ ├── ccc08s1.py │ │ ├── ccc10s1.py │ │ ├── ccc11s1.py │ │ ├── ccc12s2.py │ │ ├── ccc13s2.py │ │ └── ccc14s1.py ├── Codeforces │ └── Compete McGill │ │ ├── mcgill1E.py │ │ └── mcgill1F.py ├── DMOJ │ ├── 4ever.py │ ├── BTS │ │ ├── bts16p1.py │ │ └── bts18p1.py │ ├── DMOPC │ │ ├── dmopc14c1p3.py │ │ ├── dmopc18c1p0.py │ │ ├── dmopc19c2p1.py │ │ ├── dmopc19c3p0.py │ │ ├── dmopc19c7p0.py │ │ └── dmopc19c7p1.py │ ├── DMPG │ │ ├── dmpg15b1.py │ │ ├── dmpg15b2.py │ │ ├── dmpg15b3.py │ │ └── dmpg15b5.py │ ├── Mock CCC │ │ ├── mockccc2020c1j1.py │ │ ├── mockccc2020c1j2.py │ │ ├── nccc5j4s2.py │ │ ├── nccc6j1.py │ │ └── nccc6j2.py │ ├── Triway Cup │ │ ├── tc19summerf.py │ │ ├── tc19summerj1.py │ │ └── tc19summerj2.py │ ├── VPEX │ │ ├── vpex1p0.py │ │ ├── vpex1p1.py │ │ └── vpex1p2.py │ ├── WAC │ │ ├── wac2p1.py │ │ ├── wac3p1.py │ │ ├── wac3p2.py │ │ └── wac3p3.py │ ├── art0.py │ ├── binary.py │ ├── boolean.py │ ├── hailstone.py │ ├── pwindsor18p1.py │ ├── python1.py │ ├── quine.py │ ├── seed1.py │ ├── set.py │ ├── shortest1.py │ ├── sort1.py │ ├── stnbd1.py │ └── tsoc16c1p2.py └── Google Code Jam │ ├── gcj2019qr1.py │ ├── gcj2019qr2.py │ ├── gcj2020qr1.py │ ├── gcj2020qr2.py │ └── gcj2020qr3.py └── README.md /C++/AtCoder/ABC/abc170_a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int ans = 0; 9 | for (int i=1; i<=5; i++) { 10 | int x; cin >> x; 11 | if (x == 0) ans = i; 12 | } 13 | cout << ans << endl; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /C++/AtCoder/ABC/abc170_b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int x, y; cin >> x >> y; 9 | if (y%2 == 0 && y >= x*2 && y <= x*4) cout << "Yes" << endl; 10 | else cout << "No" << endl; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /C++/AtCoder/ABC/abc170_c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int x, n, a[101]; cin >> x >> n; 9 | for (int i=0; i> a[i]; 10 | sort(a, a+n); 11 | int j = find(a, a+n, x)-a; 12 | if (j == n) cout << x << endl; 13 | else { 14 | int k = 1; 15 | while (j-k >= 0 && j+k < n) { 16 | if (j-k >= 0 && a[j-k] != x-k) { 17 | cout << x-k << endl; 18 | return 0; 19 | } 20 | else if (j+k < n && a[j+k] != x+k) { 21 | cout << x+k << endl; 22 | return 0; 23 | } 24 | k++; 25 | } 26 | if (j-k < 0 || (j-k >= 0 && a[j-k] != x-k)) cout << x-k << endl; 27 | else cout << x+k << endl; 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /C++/AtCoder/ABC/abc170_d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXN 200002 4 | #define MAXA 1000002 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | 10 | int n, a[MAXN]; cin >> n; 11 | for (int i=1; i<=n; i++) cin >> a[i]; 12 | a[0] = 0; 13 | sort(a+1, a+n+1); 14 | bool hasdiv[MAXA]; fill(hasdiv, hasdiv+MAXA, true); 15 | int cnt = 0; 16 | 17 | for (int i=1; i<=n; i++) 18 | if (hasdiv[a[i]]) { 19 | if (a[i] != a[i+1]) cnt++; 20 | for (int j=a[i]; j 2 | using namespace std; 3 | 4 | int main() { 5 | int quarts; 6 | cin >> quarts; 7 | int ind = 0; 8 | int f; 9 | int s; 10 | int t; 11 | cin >> f; 12 | cin >> s; 13 | cin >> t; 14 | while (quarts>0) { 15 | ind++; 16 | if (ind%3==0) { 17 | t++; 18 | if (t%10==0) { 19 | quarts+=9; 20 | } 21 | } 22 | else if (ind%2==0) { 23 | s++; 24 | if (s%100==0) { 25 | quarts+=60; 26 | } 27 | } 28 | else { 29 | f++; 30 | if (f%35==0) { 31 | quarts+=30; 32 | } 33 | } 34 | quarts--; 35 | } 36 | cout << "Martha plays " << ind << " times before going broke."; 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C++/CCC/CCC Junior/ccc04j2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int x; 6 | int y; 7 | cin >> x; 8 | cin >> y; 9 | for (int i=x; i<=y; i++) { 10 | if ((i-x)%4==0 && (i-x)%3==0 && (i-x)%5==0) { 11 | cout << "All positions change in year " << i << endl; 12 | } 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C++/CCC/CCC Junior/ccc14j3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | int a = 100; 9 | int d = 100; 10 | int aRoll; 11 | int dRoll; 12 | for (int i=0; i> aRoll; 14 | cin >> dRoll; 15 | if (aRoll < dRoll){ 16 | a -= dRoll; 17 | } 18 | else if (aRoll > dRoll){ 19 | d -= aRoll; 20 | } 21 | } 22 | cout << a << endl; 23 | cout << d; 24 | } -------------------------------------------------------------------------------- /C++/CCC/CCC Junior/ccc17j1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int x; 6 | int y; 7 | cin >> x; 8 | cin >> y; 9 | if (x>0 && y>0) { 10 | cout << 1; 11 | } 12 | else if (x<0 && y>0){ 13 | cout << 2; 14 | } 15 | else if (x<0 && y<0){ 16 | cout << 3; 17 | } 18 | else if (x>0 && y<0){ 19 | cout << 4; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/CCC/CCC Junior/ccc17j2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | int k; 9 | cin >> k; 10 | int count = n; 11 | for (int i=0; i 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin >> n; 7 | for (int i=0; i> y >> m >> d; 12 | if (2007-y==18) { 13 | if (m==2) { 14 | if (d<=27) { 15 | cout << "Yes" << endl; 16 | } else { 17 | cout << "No" << endl; 18 | } 19 | } else if (m<2) { 20 | cout << "Yes" << endl; 21 | } else { 22 | cout << "No" << endl; 23 | } 24 | } else if (2007-y>18) { 25 | cout << "Yes" << endl; 26 | } else { 27 | cout << "No" << endl; 28 | } 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C++/CCC/CCC Senior/ccc11s2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin >> n; 7 | string a[n]; 8 | for (int i=0; i> a[i]; 10 | } 11 | int count = 0; 12 | for (int i=0; i> ans; 15 | if (a[i]==ans){ 16 | count++; 17 | } 18 | } 19 | cout << count; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++/CCC/CCC Senior/ccc12s1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin >> n; 7 | int ans = 0; 8 | for (int f=0; f 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | double n, h[10002], a=0; 8 | 9 | scanf("%lf", &n); 10 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | static int r[5000001] = {0}, c[5000001] = {0}; 6 | 7 | int main() { 8 | 9 | int m, n, k; 10 | 11 | scanf("%d", &m); 12 | scanf("%d", &n); 13 | scanf("%d", &k); 14 | 15 | for (int i=0; i> ch >> j; 18 | if (ch == 'R') 19 | r[j-1] = 1 - r[j-1]; 20 | else 21 | c[j-1] = 1 - c[j-1]; 22 | } 23 | 24 | int count = 0; 25 | 26 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int c; 7 | int tiles[2][200001]; 8 | 9 | scanf("%d", &c); 10 | 11 | for (int bocchi=0; bocchi= 0 && tiles[row][bocchi - 1] == 1) { 26 | length -= 2; 27 | } 28 | 29 | if (row == 1 && bocchi % 2 == 0 && tiles[0][bocchi] == 1) { 30 | length -= 2; 31 | } 32 | 33 | } 34 | } 35 | 36 | printf("%d\n", length); 37 | 38 | } -------------------------------------------------------------------------------- /C++/CCO/cco06p1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define MAXN 1001 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | 9 | int n; 10 | double d[MAXN]; 11 | cin >> n; 12 | 13 | for (int i=0; i> s >> d[i]; 16 | } 17 | 18 | sort(d, d+n); 19 | double idle = 0; 20 | 21 | for (int i=0; i 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | ll n; cin >> n; 9 | cout << n << " "; 10 | 11 | while (n != 1) { 12 | 13 | if (n%2) n = n*3+1; 14 | else n /= 2; 15 | 16 | cout << n << " "; 17 | 18 | } 19 | 20 | cout << endl; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /C++/CSES/cses1069.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | string s; cin >> s; 9 | 10 | int i = 1; 11 | int mx = 1; 12 | 13 | for (int j=1; j 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int n; cin >> n; 9 | if (n == 1) cout << 1 << endl; 10 | else if (n <= 3) cout << "NO SOLUTION" << endl; 11 | else { 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 | 17 | } 18 | -------------------------------------------------------------------------------- /C++/CSES/cses1083.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXN 200001 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | ll n; 10 | cin >> n; 11 | 12 | ll sum1 = 0; 13 | ll sum2 = n; 14 | 15 | for (ll i=0; i> j; 17 | sum1 += j; 18 | sum2 += i+1; 19 | } 20 | 21 | cout << sum2 - sum1 << endl; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /C++/CSES/cses1094.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | ll n; cin >> n; 9 | 10 | ll b = LONG_MIN; 11 | ll sum = 0; 12 | 13 | for (ll i=0; i> a; 15 | if (a < b) sum += b-a; 16 | else b = a; 17 | } 18 | 19 | cout << sum << endl; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /C++/Codeforces/Avito Code Challenge/cf981C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXN 200002 4 | 5 | using namespace std; 6 | 7 | vector adj[MAXN]; 8 | int v = 0; 9 | vector paths; 10 | 11 | void vertex(int node, int prev) { 12 | 13 | if (v == -1) return; 14 | 15 | if (adj[node].size() > 2) { 16 | if (v == 0) v = node; 17 | else { 18 | v = -1; 19 | return; 20 | } 21 | } 22 | for (int next:adj[node]) 23 | if (next != prev) 24 | vertex(next, node); 25 | } 26 | 27 | void get_paths(int node, int prev) { 28 | if (node != v && adj[node].size() == 1) 29 | paths.push_back(node); 30 | for (int next:adj[node]) 31 | if (next != prev) 32 | get_paths(next, node); 33 | } 34 | 35 | int main() { 36 | 37 | int n; cin >> n; 38 | 39 | for (int i=0; i> a >> b; 41 | adj[a].push_back(b); 42 | adj[b].push_back(a); 43 | } 44 | 45 | vertex(1, 0); 46 | 47 | if (v == -1) { 48 | cout << "No" << endl; 49 | return 0; 50 | } 51 | else if (v == 0) 52 | v = 1; 53 | 54 | cout << "Yes" << endl; 55 | 56 | get_paths(v, 0); 57 | 58 | cout << paths.size() << endl; 59 | 60 | for (int path:paths) 61 | cout << v << " " << path << endl; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Alpha Round/cf20C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXN 100001 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | ll n, m; cin >> n >> m; 10 | vector> adj[MAXN]; 11 | 12 | ll dist[MAXN]; fill(dist+2, dist+n+1, LLONG_MAX); 13 | dist[1] = 0; 14 | 15 | for (ll i=0; i> a >> b >> w; 17 | adj[a].push_back(make_pair(w, b)); 18 | adj[b].push_back(make_pair(w, a)); 19 | } 20 | 21 | priority_queue, vector>, greater>> q; 22 | q.push(make_pair(0, 1)); 23 | 24 | while (q.size()) { 25 | 26 | pair p = q.top(); q.pop(); 27 | ll node = p.second; 28 | 29 | for (pair next:adj[node]) 30 | if (dist[next.second] > dist[node] + next.first) { 31 | dist[next.second] = dist[node] + next.first; 32 | q.push(make_pair(dist[next.second], next.second)); 33 | } 34 | 35 | } 36 | 37 | if (dist[n] == LLONG_MAX) { 38 | cout << -1 << endl; 39 | return 0; 40 | } 41 | 42 | stack path; path.push(n); 43 | ll current = n; 44 | 45 | while (current != 1) { 46 | for (pair next:adj[current]) 47 | if (dist[next.second] == dist[current] - next.first) { 48 | current = next.second; 49 | break; 50 | } 51 | path.push(current); 52 | } 53 | 54 | while (path.size()) { 55 | cout << path.top() << " "; path.pop(); 56 | } 57 | cout << endl; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Beta Round/cf115A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXN 2002 4 | 5 | using namespace std; 6 | vector adj[MAXN]; 7 | int dep = 0; 8 | 9 | void depth(int v, int d) { 10 | if (!adj[v].size()) { 11 | dep = max(dep, d); 12 | return; 13 | } 14 | for (int next:adj[v]) depth(next, d+1); 15 | } 16 | 17 | int main() { 18 | 19 | int n; cin >> n; 20 | 21 | vector roots; 22 | 23 | for (int i=1; i<=n; i++) { 24 | int a; cin >> a; 25 | if (a != -1) adj[a].push_back(i); 26 | else roots.push_back(i); 27 | } 28 | 29 | int ans = 0; 30 | 31 | for (int r:roots) { 32 | dep = 0; 33 | depth(r, 1); 34 | ans = max(ans, dep); 35 | } 36 | 37 | cout << ans << endl; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Global Round/cf1368A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXA 50 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int t; cin >> t; 10 | 11 | for (int i=0; i> a >> b >> n; 14 | 15 | ll c = min(a, b); 16 | ll d = max(a, b); 17 | 18 | ll f[MAXA]; 19 | 20 | f[0] = 0; 21 | f[1] = 1; 22 | 23 | int j = 2; 24 | 25 | while (f[j-2]*c + f[j-1]*d <= n) { 26 | f[j] = f[j-1] + f[j-2]; 27 | j++; 28 | } 29 | 30 | cout << j-2 << endl; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Global Round/cf1368B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | ll k; cin >> k; 9 | string sub = "codeforces"; 10 | 11 | ll letters[10], number = 0; 12 | fill(letters, letters+10, 0); 13 | 14 | int i = 0; 15 | while (number < k) { 16 | letters[i++]++; 17 | i %= 10; 18 | 19 | number = 1; 20 | for (int j=0; j<10; j++) number *= letters[j]; 21 | } 22 | 23 | 24 | for (int i=0; i<10; i++) 25 | for (int j=0; j 2 | #define int long long 3 | #define MAXN 100001 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | 9 | int n, a[MAXN]; 10 | cin >> n; 11 | 12 | for (int i=0; i> a[i]; 13 | 14 | sort(a, a+n); 15 | 16 | int dupl = 0; 17 | int cnt = 0; 18 | for (int i=0; i 0 && a[i] != a[i-1]) { 20 | dupl = max(dupl, cnt); 21 | cnt = 0; 22 | } 23 | cnt++; 24 | } 25 | 26 | dupl = max(dupl, cnt); 27 | 28 | cout << (n - dupl) << endl; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 1/cf1264A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define MAXN 400001 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | ll t; cin >> t; 10 | 11 | for (ll i=0; i> n; 14 | ll a[MAXN]; 15 | 16 | for (ll j=0; j> a[j]; 17 | 18 | if (n < 6) { 19 | cout << "0 0 0" << endl; 20 | continue; 21 | } 22 | 23 | ll g = 1, s = 1, b = 1; 24 | 25 | while (g <= n && a[g-1] == a[g]) g++; 26 | while (g+s <= n && s <= g || a[g+s-1] == a[g+s]) s++; 27 | b = (n/2)-g-s; 28 | while (g+s+b > 1 && a[g+s+b-1] == a[g+s+b]) b--; 29 | if (g > 0 && s > 0 && b > 0 && g+s+b <= n/2 && g < s && g < b) cout << g << " " << s << " " << b << endl; 30 | else cout << "0 0 0" << endl; 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 1/cf1292A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define MAXN 100005 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | 9 | int n, q; 10 | int a[3][MAXN]; 11 | 12 | cin >> n >> q; 13 | 14 | fill(a[1], a[1]+n+2, 0); 15 | fill(a[2], a[2]+n+2, 0); 16 | 17 | int cols = 0; 18 | 19 | for (int i=0; i> r >> c; 22 | a[r][c] = 1-a[r][c]; 23 | if (a[r][c]) cols += a[3-r][c-1] + a[3-r][c] + a[3-r][c+1]; 24 | else cols -= a[3-r][c-1] + a[3-r][c] + a[3-r][c+1]; 25 | cout << (cols == 0 ? "Yes":"No") << endl; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 1/cf1340A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define MAXN 100001 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | 9 | int q; 10 | cin >> q; 11 | 12 | for (int i=0; i> n; 16 | 17 | int last = MAXN; 18 | bool possible = true; 19 | 20 | for (int j=0; j> p; 23 | if (p > last+1) 24 | possible = false; 25 | last = p; 26 | } 27 | 28 | cout << (possible ? "Yes":"No") << endl; 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 2/cf1104B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | signed main() { 7 | 8 | string s; 9 | cin >> s; 10 | 11 | stack side; 12 | int cnt = 0; 13 | 14 | for (char c:s) { 15 | if (!side.empty() && side.top() == c) { 16 | side.pop(); 17 | cnt++; 18 | } 19 | else side.push(c); 20 | } 21 | 22 | cout << (cnt%2==0 ? "No":"Yes") << endl; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 2/cf1106B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define MAXN 100002 4 | 5 | using namespace std; 6 | 7 | bool sortcost(const pair &a, const pair &b) { 8 | if (a.second == b.second) 9 | return a.first > b.first; 10 | return a.second > b.second; 11 | } 12 | 13 | signed main() { 14 | 15 | int n, m, a[MAXN], c[MAXN]; 16 | 17 | cin >> n >> m; 18 | 19 | vector> cheapest; 20 | 21 | for (int i=1; i<=n; i++) cin >> a[i]; 22 | for (int i=1; i<=n; i++) { 23 | cin >> c[i]; 24 | cheapest.push_back(make_pair(i, c[i])); 25 | } 26 | 27 | sort(cheapest.begin(), cheapest.end(), sortcost); 28 | 29 | for (int j=0; j> t >> d; 33 | 34 | int cost = 0; 35 | 36 | while (d > 0 && cheapest.size()) { 37 | 38 | if (d <= a[t]) { 39 | a[t] -= d; 40 | cost += d * c[t]; 41 | d = 0; 42 | } 43 | else { 44 | d -= a[t]; 45 | cost += a[t] * c[t]; 46 | a[t] = 0; 47 | } 48 | 49 | while (cheapest.size() && !a[cheapest.back().first]) cheapest.pop_back(); 50 | t = cheapest.back().first; 51 | 52 | } 53 | 54 | cout << (d == 0 ? cost:0) << endl; 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 2/cf1304B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define MAXN 101 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | 9 | int n, m; 10 | cin >> n >> m; 11 | 12 | string words [MAXN]; 13 | string reversed [MAXN]; 14 | 15 | for (int i=0; i> w; 18 | words[i] = w; 19 | reversed[i] = w; 20 | reverse(reversed[i].begin(), reversed[i].end()); 21 | } 22 | 23 | vector a; 24 | vector b; 25 | 26 | for (int i=0; i=0; i--) 57 | cout << b[i]; 58 | cout << endl; 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 2/cf1355A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | signed main() { 7 | 8 | int t; 9 | cin >> t; 10 | 11 | for (int i=0; i> a >> k; 15 | 16 | bool ended = false; 17 | 18 | for (int j=0; j 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | long long n, a, b, c; 8 | cin >> n >> a >> b >> c; 9 | 10 | long long ans1 = n/a; 11 | long long ans2 = 0; 12 | 13 | if (n >= b) { 14 | n -= b; 15 | ans2 = n/(b-c); 16 | n -= ans2*(b-c); 17 | n += b; 18 | if (n >= b) { 19 | n -= b-c; 20 | ans2++; 21 | } 22 | ans2 += n/a; 23 | } 24 | 25 | cout << max(ans1, ans2) << endl; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 2/cf959C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int n; cin >> n; 9 | 10 | if (n <= 5) cout << -1 << endl; 11 | else { 12 | cout << "1 2" << endl; 13 | cout << "1 3" << endl; 14 | cout << "1 4" << endl; 15 | for (int i=5; i<=n; i++) cout << "4 " << i << endl; 16 | } 17 | for (int i=1; i 2 | #define MAXN 200001 3 | 4 | using namespace std; 5 | 6 | vector adj[MAXN]; 7 | vector order; 8 | int children[MAXN]; 9 | 10 | int dfs(int node) { 11 | order.push_back(node); 12 | children[node] = 1; 13 | for (int next:adj[node]) 14 | children[node] += dfs(next); 15 | return children[node]; 16 | } 17 | 18 | int main() { 19 | 20 | int n, q; cin >> n >> q; 21 | 22 | for (int i=2; i<=n; i++) { 23 | int a; cin >> a; 24 | adj[a].push_back(i); 25 | } 26 | 27 | dfs(1); 28 | 29 | for (int i=0; i> u >> k; 31 | if (k == 1) 32 | cout << u << endl; 33 | else if (k <= children[u]) { 34 | int index = find(order.begin(), order.end(), u) - order.begin(); 35 | cout << order[index+k-1] << endl; 36 | } 37 | else cout << -1 << endl; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 3/cf1213B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | #define MAXN 150001 4 | 5 | using namespace std; 6 | 7 | signed main() { 8 | 9 | int t; 10 | cin >> t; 11 | 12 | for (int i=0; i> n; 16 | 17 | for (int j=0; j> a[j]; 19 | 20 | int minimum = 1000001; 21 | int counter = 0; 22 | for (int j=n-1; j>=0; j--) { 23 | if (a[j] > minimum) counter++; 24 | minimum = min(minimum, a[j]); 25 | } 26 | 27 | cout << counter << endl; 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 3/cf1324C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | signed main() { 7 | 8 | int t; 9 | cin >> t; 10 | 11 | for (int i=0; i> s; 15 | 16 | int maximum = 0; 17 | int r = 0; 18 | 19 | for (int j=0; j 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | signed main() { 7 | 8 | int t; 9 | cin >> t; 10 | 11 | for (int i=0; i> a >> b; 15 | 16 | cout << (a%b == 0 ? 0:-a%b+b) << endl; 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /C++/Codeforces/Codeforces Round/Div 4/cf1352A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | signed main() { 7 | 8 | int t; 9 | cin >> t; 10 | 11 | for (int i=0; i> n; 15 | 16 | int digit = pow(10, (int)log10(n)); 17 | 18 | vector values; 19 | 20 | while (digit > 0) { 21 | int rounded = (n/digit)*digit; 22 | if (rounded > 0) values.push_back(rounded); 23 | n %= digit; 24 | digit /= 10; 25 | } 26 | 27 | cout << values.size() << endl; 28 | 29 | for (int val:values) 30 | cout << val << " "; 31 | 32 | cout << endl; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /C++/Codeforces/Compete McGill/mcgill1A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | signed main() { 7 | 8 | int t; 9 | cin >> t; 10 | 11 | map handToIndex = { 12 | { 'R', 0 }, 13 | { 'P', 1 }, 14 | { 'S', 2 } 15 | }; 16 | 17 | char indexToHand [3] = {'R', 'P', 'S'}; 18 | 19 | for (int i=0; i> n; 22 | cin >> hands[0] >> hands[1] >> hands[2]; 23 | 24 | string seq; 25 | cin >> seq; 26 | 27 | string ans = ""; 28 | int wins = 0; 29 | 30 | for (char c:seq) { 31 | int k = handToIndex[c]; 32 | if (hands[(k+1)%3] > 0) { 33 | hands[(k+1)%3]--; 34 | wins++; 35 | ans += indexToHand[(k+1)%3]; 36 | } 37 | else ans += " "; 38 | } 39 | 40 | if (wins >= ceil(n/2.0)) { 41 | 42 | cout << "YES" << endl; 43 | 44 | string fin = ""; 45 | 46 | for (char c:ans) { 47 | if (c != ' ') fin += c; 48 | else for (int i=0; i<3; i++) { 49 | if (hands[i] > 0) { 50 | fin += indexToHand[i]; 51 | hands[i]--; 52 | break; 53 | } 54 | } 55 | } 56 | 57 | cout << fin << endl; 58 | 59 | } 60 | else 61 | cout << "NO" << endl; 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /C++/Codeforces/Compete McGill/mcgill1B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | 4 | using namespace std; 5 | 6 | bool finite(int a, int b) { 7 | 8 | if (b == 0) 9 | return a == 1; 10 | return finite(b, a%b); 11 | 12 | } 13 | 14 | signed main() { 15 | 16 | int t; 17 | cin >> t; 18 | 19 | for (int i=0; i> a >> b; 23 | 24 | cout << (finite(min(a, b), max(a, b)) ? "Finite":"Infinite") << endl; 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /C++/Codeforces/Educational Codeforces Round/cf1373A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | ll costa(ll n, ll a) { 7 | return n*a; 8 | } 9 | 10 | ll costb(ll n, ll b, ll c) { 11 | return ceil(n/double(b))*c; 12 | } 13 | 14 | int main() { 15 | 16 | int t; cin >> t; 17 | 18 | for (int i=0; i> a >> b >> c; 20 | ll costa1 = costa(1, a); 21 | ll costb1 = costb(1, b, c); 22 | ll costa2 = costa(b, a); 23 | ll costb2 = costb(b, b, c); 24 | if (costa1 < costb1) { 25 | if (costb2 < costa2) cout << 1 << " " << b << endl; 26 | else cout << 1 << " " << -1 << endl; 27 | } 28 | else if (costb1 < costa1) { 29 | if (costa2 < costb2) cout << b << " " << 1 << endl; 30 | else cout << -1 << " " << 1 << endl; 31 | } 32 | else { 33 | if (costb2 < costa2) cout << -1 << " " << b << endl; 34 | else if (costa2 < costb2) cout << b << " " << -1 << endl; 35 | else cout << -1 << " " << -1 << endl; 36 | } 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /C++/Codeforces/Educational Codeforces Round/cf1373B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int t; cin >> t; 9 | for (int i=0; i> s; 11 | vector v(s.begin(), s.end()); 12 | int cnt = 0; 13 | int j = 0; 14 | while (j+1 < v.size()) { 15 | if (v.at(j) != v.at(j+1)) { 16 | v.erase(v.begin()+j, v.begin()+j+2); 17 | cnt++; 18 | j = max(0, j-1); 19 | } 20 | else j++; 21 | } 22 | cout << (cnt%2 ? "DA":"NET") << endl; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /C++/Codeforces/MailRu Cup/cf1057A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAXN 200002 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int n, a[MAXN]; cin >> n; 9 | for (int i=2; i<=n; i++) cin >> a[i]; 10 | 11 | stack q; 12 | 13 | int node = n; 14 | 15 | while (node != 1) { 16 | q.push(node); 17 | node = a[node]; 18 | } 19 | 20 | cout << 1 << " "; 21 | while (q.size()) { 22 | cout << q.top() << " "; q.pop(); 23 | } 24 | cout << endl; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /C++/DMOJ/AC/acc4p0.cpp: -------------------------------------------------------------------------------- 1 | string f(){return "All Kill";} 2 | -------------------------------------------------------------------------------- /C++/DMOJ/AC/acc4p1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | string f(int N) { 6 | return to_string(N); 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /C++/DMOJ/BFS/bfs19p2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | char graph [n+1][n+1]; 12 | 13 | for (int i=1; i<=n; i++) { 14 | string s; 15 | cin >> s; 16 | for (int j=1; j<=n; j++) { 17 | graph[i][j] = s.at(j-1); 18 | } 19 | } 20 | 21 | int step [n+1][n+1]; 22 | 23 | for (int i=1; i<=n; i++) { 24 | for (int j=1; j<=n; j++) { 25 | step[i][j] = INT_MAX; 26 | } 27 | } 28 | step[1][1] = 0; 29 | 30 | list xq = {}; 31 | list yq = {}; 32 | 33 | xq.push_back(1); 34 | yq.push_back(1); 35 | 36 | while (!xq.empty()) { 37 | int x = xq.front(); 38 | int y = yq.front(); 39 | 40 | xq.pop_front(); 41 | yq.pop_front(); 42 | 43 | if (x+1<=n && graph[x+1][y] == '.' && step[x+1][y]>step[x][y]+1) { 44 | step[x+1][y] = step[x][y]+1; 45 | xq.push_back(x+1); 46 | yq.push_back(y); 47 | } 48 | if (y+1<=n && graph[x][y+1] == '.' && step[x][y+1]>step[x][y]+1) { 49 | step[x][y+1] = step[x][y]+1; 50 | xq.push_back(x); 51 | yq.push_back(y+1); 52 | } 53 | if (y-1>0 && graph[x][y-1] == '.' && step[x][y-1]>step[x][y]+1) { 54 | step[x][y-1] = step[x][y]+1; 55 | xq.push_back(x); 56 | yq.push_back(y-1); 57 | } 58 | 59 | } 60 | 61 | if (step[n][n] != INT_MAX) { 62 | long d = n-1; 63 | long r = step[n][n]/2 - (n-1); 64 | long l = n-1+r; 65 | cout << long(pow(d, 2) + pow(l, 2) + pow(r, 2)); 66 | } else { 67 | cout << -1; 68 | } 69 | return 0; 70 | } -------------------------------------------------------------------------------- /C++/DMOJ/DMOPC/dmopc14c1p2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int l; 6 | int w; 7 | cin >> l; 8 | cin >> w; 9 | int s; 10 | cin >> s; 11 | cout << ((l-l%s)/s)*((w-w%s)/s); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++/DMOJ/DMOPC/dmopc15c1p1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int n; 9 | cin >> n; 10 | 11 | string s; 12 | double max = -1; 13 | 14 | for (int i=0; i> name >> r; 18 | 19 | if (r > max) { 20 | max = r; 21 | s = name; 22 | } 23 | 24 | } 25 | 26 | cout << s << endl; 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/DMOJ/bf1easy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | string s; 9 | getline(cin, s); 10 | for (int i=1; i<=n; i++) { 11 | cout << i << " "; 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++/DMOJ/bf1hard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | int arr[n]; 10 | for (int i=0; i> arr[i]; 12 | } 13 | sort(arr, arr+n); 14 | for (int i=0; i 2 | using namespace std; 3 | 4 | unsigned long long exponent(int base, int exponent) 5 | { 6 | unsigned long long result = 1ULL; // 0th power of base is 1 7 | for (int i=0; i 33) { 23 | printf("%d\n", 0); 24 | } else { 25 | unsigned long long f = 1; 26 | for (int j=2; j<=a; j++) { 27 | f *= j; 28 | } 29 | printf("%llu\n", f % exponent(2, 32)); 30 | } 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C++/DMOJ/pwindsor18p3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int n; 7 | scanf("%d", &n); 8 | 9 | int sum = 0; 10 | 11 | for (int i=0; i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | long long m; 8 | cin >> n >> m; 9 | long long hold = 0; 10 | long long moved = 0; 11 | bool flag = true; 12 | for (int i=0; i> a; 15 | if (flag) { 16 | if (a >= m) hold += a-m; 17 | else if (a 2 | #define ll long long 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | int t; cin >> t; 9 | 10 | for (int i=0; i> n >> m; 13 | 14 | ll before = 0, after = 0, weight = 0, midpoint = 0; 15 | 16 | for (ll i=0; i> a; 18 | if (a <= m) { 19 | if (midpoint == m) 20 | weight = max(weight, before+after+m); 21 | if (a == m) before = after; 22 | else before = 0; 23 | after = 0; 24 | midpoint = a; 25 | } 26 | else after += a; 27 | } 28 | 29 | cout << max(weight, before+after+m) << endl; 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Java/AtCoder/dpa.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class dpa { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int n = sc.nextInt(); 11 | 12 | int [] h = new int [n]; 13 | 14 | for (int i=0; i=0; j--) 24 | if (j - w[i] >= 0) 25 | dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]); 26 | 27 | System.out.println(dp[W]); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Java/AtCoder/dpe.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class dpe { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int N = sc.nextInt(); 11 | int W = sc.nextInt(); 12 | 13 | int [] w = new int [N]; 14 | int [] v = new int [N]; 15 | 16 | int sum_v = 0; 17 | 18 | for (int i=0; i=0; j--) 30 | if (j - v[i] >= 0 && dp[j - v[i]] != Integer.MAX_VALUE) 31 | dp[j] = Math.min(dp[j], dp[j - v[i]] + w[i]); 32 | 33 | int max = 0; 34 | 35 | for (int i=0; i<=sum_v; i++) { 36 | if (dp[i] <= W && max < i) 37 | max = i; 38 | } 39 | 40 | System.out.println(max); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Java/AtCoder/dph.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class dph { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int h = sc.nextInt(); 10 | int w = sc.nextInt(); 11 | 12 | int [][] graph = new int [h][w]; 13 | long [][] paths = new long [h][w]; 14 | 15 | for (int i=0; i= 0 && !dp[i - a[j]]) 21 | dp[i] = true; 22 | 23 | // for (int i=0; i<=k; i++) 24 | // System.out.print(dp[i]+" "); 25 | // System.out.println(); 26 | 27 | System.out.println(dp[k] ? "First":"Second"); 28 | 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc03j1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class ccc03j1 { 3 | 4 | public static void main(String[] args) { 5 | // TODO Auto-generated method stub 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | int s = sc.nextInt(); 9 | int h = sc.nextInt(); 10 | for (int i=0; i=(int)Math.cbrt(s); i--) { 9 | if (i*i<=s) { 10 | System.out.println("The largest square has side length "+i+"."); 11 | break; 12 | } 13 | } 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc04j3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Arrays; 3 | public class ccc04j3 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int m = sc.nextInt(); 10 | String[] A = new String[n]; 11 | String[] B = new String[m]; 12 | for (int i=0;i='A' && c<='Z') { 13 | newS += c; 14 | } 15 | } 16 | for (int i=0; i'Z') { 21 | newC = (char)(newC-26); 22 | } 23 | System.out.print(newC); 24 | } 25 | 26 | 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc05j3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Stack; 3 | 4 | public class ccc05j3 { 5 | 6 | public static void main(String[] args) { 7 | // TODO Auto-generated method stub 8 | Scanner sc = new Scanner(System.in); 9 | Stack A= new Stack(); 10 | 11 | while (true) { 12 | String c = sc.nextLine(); 13 | if (c.equals("SCHOOL")) { 14 | break; 15 | } 16 | A.push(c); 17 | } 18 | while (true) { 19 | String D = A.pop(); 20 | String Direction = ""; 21 | if (D.equals("R")) { 22 | Direction = "LEFT"; 23 | } else if (D.equals("L")) { 24 | Direction = "RIGHT"; 25 | } 26 | if (A.isEmpty()) { 27 | System.out.println("Turn "+Direction+" into your HOME."); 28 | break; 29 | } 30 | String street = A.pop(); 31 | System.out.println("Turn "+Direction+" onto "+street+" street."); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc06j1.java: -------------------------------------------------------------------------------- 1 | import java.util.Hashtable; 2 | import java.util.Scanner; 3 | 4 | public class ccc06j1 { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | int c = sc.nextInt(); 11 | int d = sc.nextInt(); 12 | int count = 0; 13 | if (a==1) { 14 | count+=461; 15 | } else if (a==2) { 16 | count+=431; 17 | } else if (a==3) { 18 | count+=420; 19 | } 20 | if (b==1) { 21 | count+=100; 22 | } else if (b==2) { 23 | count+=57; 24 | } else if (b==3) { 25 | count+=70; 26 | } 27 | if (c==1) { 28 | count+=130; 29 | } else if (c==2) { 30 | count+=160; 31 | } else if (c==3) { 32 | count+=118; 33 | } 34 | if (d==1) { 35 | count+=167; 36 | } else if (d==2) { 37 | count+=266; 38 | } else if (d==3) { 39 | count+=75; 40 | } 41 | System.out.println("Your total Calorie count is "+count+"."); 42 | 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc06j2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class ccc06j2 { 3 | 4 | public static void main(String[] args) { 5 | // TODO Auto-generated method stub 6 | Scanner sc = new Scanner(System.in); 7 | int m = sc.nextInt(); 8 | int n = sc.nextInt(); 9 | int count = 0; 10 | for (int i=1; i<=m; i++) { 11 | for (int j=1; j<=n; j++) { 12 | if (i+j==10) { 13 | count++; 14 | } 15 | } 16 | } 17 | if (count==1) { 18 | System.out.println("There is "+count+" way to get the sum 10."); 19 | } 20 | else { 21 | System.out.println("There are "+count+" ways to get the sum 10."); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc06j3.java: -------------------------------------------------------------------------------- 1 | import java.util.Hashtable; 2 | import java.util.Scanner; 3 | public class ccc06j3 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | Hashtable table = new Hashtable(); 9 | table.put('a', "2"); 10 | table.put('b', "22"); 11 | table.put('c', "222"); 12 | table.put('d', "3"); 13 | table.put('e', "33"); 14 | table.put('f', "333"); 15 | table.put('g', "4"); 16 | table.put('h', "44"); 17 | table.put('i', "444"); 18 | table.put('j', "5"); 19 | table.put('k', "55"); 20 | table.put('l', "555"); 21 | table.put('m', "6"); 22 | table.put('n', "66"); 23 | table.put('o', "666"); 24 | table.put('p', "7"); 25 | table.put('q', "77"); 26 | table.put('r', "777"); 27 | table.put('s', "7777"); 28 | table.put('t', "8"); 29 | table.put('u', "88"); 30 | table.put('v', "888"); 31 | table.put('w', "9"); 32 | table.put('x', "99"); 33 | table.put('y', "999"); 34 | table.put('z', "9999"); 35 | while (true) { 36 | String S = sc.nextLine(); 37 | if (S.equals("halt")) { 38 | break; 39 | } 40 | int total = 0; 41 | String A = ""; 42 | for (int i=0;i l = new LinkedList(); 32 | while (true) { 33 | int found = -1; 34 | for (int i=0; i<8; i++) { 35 | if (A[i]==0) { 36 | found = i; 37 | A[i] = -1; 38 | l.add(i); 39 | break; 40 | } 41 | } 42 | if (found==-1) { 43 | break; 44 | } else { 45 | for (int col=0; col<8; col++) { 46 | if (B[found][col]==true) { 47 | A[col]--; 48 | } 49 | } 50 | } 51 | } 52 | if (l.size()!=7) { 53 | System.out.println("Cannot complete these tasks. Going to bed."); 54 | }else{ 55 | for (int m = 0;m=0; m--) { 31 | if (motel[i] - motel[m] >= a && motel[i] - motel[m] <= b) 32 | paths[i] += paths[m]; 33 | else if (motel[i] - motel[m] > b) 34 | break; 35 | } 36 | 37 | // for (int i=0; i25) { 11 | System.out.println("Overweight"); 12 | } else if (BMI>=18.5 && BMI<=25) { 13 | System.out.println("Normal weight"); 14 | } else if (BMI<18.5) { 15 | System.out.println("Underweight"); 16 | } 17 | 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc08j4.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class ccc08j4 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | while (true) { 10 | 11 | String s=sc.nextLine(); 12 | if (s.equals("0")){ 13 | break; 14 | } 15 | s=s.replace(" ", ""); 16 | if (s.length()==1){ 17 | System.out.println(s); 18 | } else { 19 | 20 | Stack a=new Stack(); 21 | 22 | for (int i=s.length()-1;i>=0;i--){ 23 | if (s.charAt(i)=='+'||s.charAt(i)=='-'){ 24 | String n=a.pop()+" "+a.pop()+" "+s.charAt(i); 25 | a.push(n); 26 | 27 | } else { 28 | a.push(s.substring(i,i+1)); 29 | } 30 | 31 | } 32 | 33 | if (a.size()==1&&a.peek().length()>1){ 34 | System.out.println(a.peek()); 35 | } 36 | 37 | } 38 | 39 | } 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc09j1.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class ccc09j1 { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | String a = sc.nextLine(); 8 | String b = sc.nextLine(); 9 | String c = sc.nextLine(); 10 | String s = "9780921418"+a+b+c; 11 | int count = 0; 12 | for (int i=0; i=3 && e<=4) { 10 | System.out.println("TroyMartian"); 11 | } 12 | if (a<=6 && e>=2) { 13 | System.out.println("VladSaturnian"); 14 | } 15 | if (a<=2 && e<=3) { 16 | System.out.println("GraemeMercurian"); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc11j5.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class ccc11j5 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int n = sc.nextInt(); 11 | 12 | int [] friends = new int [n+1]; 13 | Arrays.fill(friends, 1); 14 | 15 | for (int i=1; i0 && S<=20) { 15 | F = 100; 16 | } else if (S>20 && S<=30) { 17 | F = 270; 18 | } else if (S>30) { 19 | F = 500; 20 | } 21 | System.out.println("You are speeding and your fine is $"+F+"."); 22 | } 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc13j1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc13j1 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | System.out.println(b+b-a); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc13j4.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class ccc13j4 4 | { 5 | public static void main (String[] args) throws java.lang.Exception 6 | { 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | int c = sc.nextInt(); 10 | int [] chores = new int [c]; 11 | for (int i=0; icountB) { 20 | System.out.println("A"); 21 | } else if (countA2) { 10 | System.out.println("After"); 11 | } else if (m<2) { 12 | System.out.println("Before"); 13 | } else if (m==2) { 14 | if (d>18) { 15 | System.out.println("After"); 16 | } else if (d<18) { 17 | System.out.println("Before"); 18 | } else if (d==18) { 19 | System.out.println("Special"); 20 | } 21 | } 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc15j4.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc15j4 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | int M = sc.nextInt(); 9 | int [] R = new int [101]; 10 | int [] S = new int [101]; 11 | int [] sum = new int [101]; 12 | int T = 0; 13 | for (int i=0; i0) { 31 | System.out.println(i+" "+sum[i]); 32 | } 33 | } 34 | 35 | 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc15j5.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc15j5 { 4 | 5 | public static int [][] DP; 6 | public static void main(String[] args) { 7 | // TODO Auto-generated method stub 8 | Scanner sc = new Scanner(System.in); 9 | // n means how much pie 10 | // k means how many people 11 | // person 1 leaves 12 | // person 1 to left 13 | // k-1 people n-1 pie 14 | // person 1 stays 15 | // k people n-k pie 16 | int n = sc.nextInt(); 17 | int k = sc.nextInt(); 18 | DP = new int[n+1][k+1]; 19 | System.out.println(pie(n,k)); 20 | } 21 | public static int pie(int n, int k) { 22 | if (DP[n][k]!=0) { 23 | return DP[n][k]; 24 | } 25 | if (k==1) { 26 | return 1; 27 | } else if (n==k) { 28 | return 1; 29 | }else if (n=distance && (t-distance)%2 == 0) { 17 | System.out.println("Y"); 18 | } else { 19 | System.out.println("N"); 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc18j1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc18j1 { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int a = sc.nextInt(); 8 | int b = sc.nextInt(); 9 | int c = sc.nextInt(); 10 | int d = sc.nextInt(); 11 | if (a==8 || a==9) { 12 | if (b==c) { 13 | if (d==8 || d==9) { 14 | System.out.println("ignore"); 15 | } else { 16 | System.out.println("answer"); 17 | } 18 | } else { 19 | System.out.println("answer"); 20 | } 21 | } else { 22 | System.out.println("answer"); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Junior/ccc18j2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc18j2 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | String N = sc.nextLine(); 9 | String y = sc.nextLine(); 10 | String t = sc.nextLine(); 11 | char [] c = y.toCharArray(); 12 | char [] d = t.toCharArray(); 13 | int count = 0; 14 | for (int i=0; i=0) { 21 | dp[i] = Math.min(dp[i], dp[i-clubs[j]]+ 1); 22 | } 23 | } 24 | } 25 | if (dp[d] == 5281) { 26 | System.out.println("Roberta acknowledges defeat."); 27 | } else { 28 | System.out.println("Roberta wins in "+dp[d]+" strokes."); 29 | } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc01s3.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Arrays; 3 | import java.util.LinkedList; 4 | import java.util.Scanner; 5 | 6 | public class ccc01s3 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner sc = new Scanner(System.in); 11 | 12 | ArrayList adj [] = new ArrayList[26]; 13 | 14 | for (int i=0; i<26; i++) 15 | adj[i] = new ArrayList(); 16 | 17 | String s = sc.next(); 18 | 19 | LinkedList xs = new LinkedList(); 20 | LinkedList ys = new LinkedList(); 21 | 22 | 23 | while (!s.equals("**")) { 24 | 25 | int a = s.charAt(0) - 'A'; 26 | int b = s.charAt(1) - 'A'; 27 | 28 | adj[a].add(b); 29 | adj[b].add(a); 30 | 31 | xs.add(a); 32 | ys.add(b); 33 | 34 | s = sc.next(); 35 | 36 | } 37 | 38 | LinkedList q = new LinkedList(); 39 | boolean [] visited = new boolean[26]; 40 | 41 | int sum = 0; 42 | 43 | while (!xs.isEmpty()) { 44 | 45 | int x = xs.pop(); 46 | int y = ys.pop(); 47 | 48 | Arrays.fill(visited, false); 49 | 50 | q.add(0); 51 | 52 | while (!q.isEmpty()) { 53 | 54 | int c = q.pop(); 55 | visited[c] = true; 56 | 57 | for (int i=0; iv) { 31 | min = v; 32 | } 33 | } 34 | } 35 | if (min [] adj = new ArrayList [10000]; 15 | 16 | for (int i=1; i<=9999; i++) 17 | adj[i] = new ArrayList(); 18 | 19 | for (int i=0; i q = new LinkedList(); 37 | 38 | q.add(a); 39 | boolean loop = false; 40 | 41 | while (!q.isEmpty()) { 42 | 43 | int f = q.pop(); 44 | 45 | for (int i=0; i adj[] = new ArrayList[10000]; 13 | for (int i=1; i<=n; i++) 14 | adj[i] = new ArrayList(); 15 | 16 | while (true) { 17 | int a = sc.nextInt(); 18 | int b = sc.nextInt(); 19 | 20 | if (a == 0 && b == 0) 21 | break; 22 | 23 | adj[a].add(b); 24 | 25 | } 26 | 27 | int [] paths = new int[10000]; 28 | paths[n] = 1; 29 | 30 | for (int i=n-1; i>0; i--) { 31 | for (int j=0; j combos = new HashSet(); 10 | 11 | int r = sc.nextInt(); 12 | int l = sc.nextInt(); 13 | 14 | String [] board = new String [r]; 15 | sc.nextLine(); 16 | 17 | for (int i=0; itCount) { 22 | System.out.println("French"); 23 | } else { 24 | System.out.println("English"); 25 | } 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc11s3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc11s3 { 4 | 5 | static boolean solve(int m, int x, int y) { 6 | 7 | int sub = (int)Math.pow(5, m-1); 8 | 9 | if ((x >= 2*sub && x < 3*sub && y >= sub && y < 2*sub) || (x >= sub && x < 4*sub && y >= 0 && y < sub)) 10 | return true; 11 | if ((x >= sub && x < 2*sub && y >= sub && y < 2*sub) || 12 | (x >= 2*sub && x < 3*sub && y >= 2*sub && y < 3*sub) || 13 | (x >= 3*sub && x < 4*sub && y >= sub && y < 2*sub)) 14 | return solve(m-1, x%sub, y%sub); 15 | 16 | return false; 17 | 18 | } 19 | 20 | public static void main(String[] args) { 21 | 22 | Scanner sc = new Scanner(System.in); 23 | 24 | int t = sc.nextInt(); 25 | 26 | for (int i=0; i max2) 27 | max2 = a[m]; 28 | // System.out.println(max1+" "+max2); 29 | } 30 | 31 | 32 | int ans = 0; 33 | 34 | for (int i=1; i<=1000; i++) 35 | if (a[i] > 0) 36 | for (int j=i+1; j<=1000; j++) 37 | if ((a[i] == max1 && a[j] == max2) || (a[i] == max2 && a[j] == max1)) 38 | ans = Math.max(ans, Math.abs(i-j)); 39 | 40 | System.out.println(ans); 41 | 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc12s5.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Scanner; 3 | 4 | public class ccc12s5 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int r = sc.nextInt(); 11 | int c = sc.nextInt(); 12 | 13 | int [][] graph = new int [r][c]; 14 | 15 | int k = sc.nextInt(); 16 | 17 | for (int i=0; i=0 && graph[i-1][j] != 1) { 31 | dp[i][j] += dp[i-1][j]; 32 | } 33 | if (j-1>=0 && graph[i][j-1] != 1) { 34 | dp[i][j] += dp[i][j-1]; 35 | } 36 | } 37 | } 38 | 39 | System.out.println(dp[r-1][c-1]); 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc13s5.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ccc13s5 { 4 | 5 | static int findMin(int v, int c) { 6 | 7 | if (v == 1) 8 | return c; 9 | 10 | for (int i=2; i*i<=v; i++) 11 | if (v%i == 0) 12 | return findMin(v - v/i, c + (v - v/i)/(v/i)); 13 | 14 | return findMin(v - 1, c + v - 1); 15 | 16 | } 17 | 18 | public static void main(String[] args) { 19 | 20 | Scanner sc = new Scanner(System.in); 21 | 22 | int n = sc.nextInt(); 23 | System.out.println(findMin(n, 0)); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc14s2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class ccc14s2 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | LinkedList l1 = new LinkedList(); 10 | LinkedList l2 = new LinkedList(); 11 | for (int i=0; i mount = new Stack(); 12 | int [] order = new int [n]; 13 | for (int j=0; j branch = new Stack(); 19 | int index = 0; 20 | while (index { 8 | int tint; 9 | int x; 10 | int y_start; 11 | int y_end; 12 | public line(int X, int S, int E, int T) { 13 | tint = T; 14 | x = X; 15 | y_start = S; 16 | y_end = E; 17 | } 18 | public int compareTo(line o) { 19 | return x-o.x; 20 | } 21 | public String toString() { 22 | String s = ""; 23 | return "("+x +" "+y_start+" "+y_end+" "+tint+")"; 24 | } 25 | 26 | } 27 | static class point implements Comparable { 28 | int y; 29 | int tint; 30 | public point(int Y, int T) { 31 | y = Y; 32 | tint = T; 33 | } 34 | public int compareTo(point o) { 35 | return y-o.y; 36 | } 37 | } 38 | 39 | public static void main(String[] args) { 40 | Scanner sc = new Scanner(System.in); 41 | int n = sc.nextInt(); 42 | int k = sc.nextInt(); 43 | line [] lines = new line[2005]; 44 | for (int l=0; l A = new ArrayList(); 51 | 52 | long ans = 0; 53 | for (int l=0; l<2*n-1; l++) { 54 | A.add(new point(lines[l].y_start, lines[l].tint)); 55 | A.add(new point(lines[l].y_end, -lines[l].tint)); 56 | Collections.sort(A); 57 | int sum = 0; 58 | for (int l2=0; l2=k) { 61 | ans+=1L*(A.get(l2 + 1).y - A.get(l2).y) * (lines[l+1].x-lines[l].x); 62 | } 63 | } 64 | } 65 | System.out.println(ans); 66 | System.exit(0); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc15s1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Stack; 3 | 4 | public class ccc15s1 { 5 | 6 | public static void main(String[] args) { 7 | // TODO Auto-generated method stub 8 | Scanner sc = new Scanner (System.in); 9 | int k = sc.nextInt(); 10 | Stack st = new Stack<>(); 11 | for (int i=0; i 0 && num <= j && jerseys[num] >= x) { 31 | count++; 32 | jerseys[num] = -1; 33 | } 34 | 35 | } 36 | 37 | System.out.println(count); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc15s3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.TreeSet; 3 | 4 | public class ccc15s3 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int g = sc.nextInt(); 11 | int p = sc.nextInt(); 12 | 13 | int [] planes = new int [p]; 14 | 15 | TreeSet gates = new TreeSet(); 16 | 17 | for (int i=0; i l = new LinkedList(); 12 | for (int i=0; i=d[i]) { 25 | m = m+p[i]; 26 | } else { 27 | m = m+d[i]; 28 | } 29 | } 30 | } else if (q==2) { 31 | for (int i=0; i=d[n-1-i]) { 33 | m = m+p[i]; 34 | } else { 35 | m = m+d[n-1-i]; 36 | } 37 | } 38 | } 39 | System.out.println(m); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /Java/CCC/CCC Senior/ccc17s1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class ccc17s1 4 | { 5 | public static void main (String[] args) throws java.lang.Exception 6 | { 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | int [] a = new int [t]; 10 | int [] b = new int [t]; 11 | for (int i=0; i=0; i--) { 23 | a1[z] = a[i]; 24 | z++; 25 | } 26 | 27 | z=0; 28 | for (int i=(n+1)/2; i { 7 | double time; 8 | double pos; 9 | 10 | public Data(double t, double p) { 11 | time = t; 12 | pos = p; 13 | } 14 | 15 | public int compareTo(Data o) { 16 | return (int)(time-o.time); 17 | } 18 | 19 | } 20 | 21 | public static void main(String[] args) { 22 | 23 | Scanner sc = new Scanner(System.in); 24 | 25 | int n = sc.nextInt(); 26 | 27 | Data [] a = new Data[100001]; 28 | 29 | for (int i=0; i t.charAt(j-1) && geese[i] > hawks[j]) || (s.charAt(i-1) < t.charAt(j-1) && geese[i] < hawks[j])) 27 | dp[i][j] = Math.max(dp[i][j], dp[i-1][j-1] + geese[i] + hawks[j]); 28 | } 29 | } 30 | 31 | System.out.println(dp[n][n]); 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Java/COCI/coci06c2p4.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class coci06c2p4 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | System.out.println((n*(n-1)*(n-2)*(n-3))/24); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Java/COCI/coci06p3.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | 5 | public class coci067p3 { 6 | 7 | public static void main(String[] args) { 8 | FastReader sc = new FastReader(); 9 | int n = sc.nextInt(); 10 | int h = sc.nextInt(); 11 | 12 | int [] line = new int [500001]; 13 | 14 | int count = 0; 15 | 16 | for (int i=0; ib[1] && b[1]>b[2] && b[2]>b[3] && b[3]>b[4] && b[4]>b[5] && b[5]>b[6] && b[6]>b[7]) { 13 | System.out.println("descending"); 14 | } 15 | else if (b[0] val) { 15 | inc++; 16 | val += inc; 17 | } 18 | 19 | long sum = 0; 20 | 21 | for (long i=val; i>val-inc; i--) 22 | sum += i; 23 | 24 | System.out.println(sum); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Java/DMOJ/DMOPC/dmopc16c1p1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class dmopc16c1p1 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | int N = sc.nextInt(); 9 | int [] A = new int [N]; 10 | int count = 0; 11 | for (int i=0; i 0) 16 | minc += c; 17 | } 18 | 19 | System.out.println(minc); 20 | 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Java/DMOJ/DMOPC/dmopc19c1p0.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class dmopc19c1p0 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | long min = Long.MAX_VALUE; 10 | long max = Long.MIN_VALUE; 11 | for (int i=0; i val)) { 34 | return i; 35 | } 36 | else if (!less && arr[i] >= val && (i == 0 || arr[i-1] < val)) { 37 | return i; 38 | } 39 | } 40 | return -1; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Java/DMOJ/DMOPC/dmopc19c2p2.java: -------------------------------------------------------------------------------- 1 | package dmopc2019october; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Scanner; 5 | 6 | public class dmopc19c2p2 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int n = sc.nextInt(); 13 | int m = sc.nextInt(); 14 | 15 | int [][] graph = new int [n][m]; 16 | int [][] step = new int [n][m]; 17 | 18 | for (int i=0; i xq = new LinkedList(); 27 | LinkedList yq = new LinkedList(); 28 | 29 | xq.add(0); 30 | yq.add(0); 31 | 32 | while (!xq.isEmpty()) { 33 | int x = xq.pop(); 34 | int y = yq.pop(); 35 | 36 | if (x+1 step[x][y] + graph[x+1][y]) { 37 | xq.add(x+1); 38 | yq.add(y); 39 | step[x+1][y] = step[x][y] + graph[x+1][y]; 40 | } 41 | if (y+1 step[x][y] + graph[x][y+1]) { 42 | xq.add(x); 43 | yq.add(y+1); 44 | step[x][y+1] = step[x][y] + graph[x][y+1]; 45 | } 46 | } 47 | 48 | System.out.println(step[n-1][m-1]); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Java/DMOJ/DMOPC/dmopc19c3p1.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Scanner; 4 | 5 | public class dmopc19c3p1 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int n = sc.nextInt(); 12 | 13 | int [] nums = new int [200002]; 14 | int max = 0; 15 | int ind = 0; 16 | 17 | ArrayList modes [] = new ArrayList[200002]; 18 | 19 | for (int i=0; i max) { 26 | max = nums[a+100000]; 27 | ind++; 28 | modes[ind] = new ArrayList(); 29 | modes[ind].add(a); 30 | } 31 | } 32 | 33 | Collections.sort(modes[ind]); 34 | 35 | for (int i=0; i pos = new ArrayList(); 14 | ArrayList neg = new ArrayList(); 15 | 16 | for (int i=0; i 0) 19 | pos.add(c); 20 | else if (c < 0) 21 | neg.add(c); 22 | } 23 | 24 | Collections.sort(neg); 25 | 26 | int prod = 0; 27 | 28 | if (pos.size() > 0 || neg.size() > 0 && !(neg.size() == 1 && pos.size() == 0 && n > 1)) 29 | prod = 1; 30 | 31 | for (int i=0; i=0; i--) { 34 | 35 | if (s.charAt(i) == '1') 36 | prev = i; 37 | 38 | else if (prev != -1) 39 | v[i] = Math.min(v[i], prev - i); 40 | 41 | } 42 | 43 | long sum = 0; 44 | for (int i=0; i t = new TreeSet(); 22 | 23 | t.add(cards[0]); 24 | int took = 0; 25 | 26 | while (sec= sum) { 24 | sum += w[i]; 25 | count++; 26 | } 27 | } 28 | 29 | System.out.println(count); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Java/DMOJ/TLE/tle17c2p2.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class tle17c2p2 { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int k = sc.nextInt(); 11 | 12 | int [] u = new int [500003]; 13 | 14 | for (int i=1; i<=k; i++) 15 | u[i] = sc.nextInt(); 16 | 17 | Arrays.parallelSort(u, 1, k+1); 18 | 19 | u[k+1] = Integer.MAX_VALUE; 20 | 21 | int n = sc.nextInt(); 22 | 23 | for (int j=0; j f) 36 | break; 37 | 38 | if (u[mid] > f) 39 | r = mid-1; 40 | 41 | else 42 | l = mid+1; 43 | 44 | } 45 | 46 | System.out.println(f-mid); 47 | 48 | } 49 | 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /Java/DMOJ/Triway Cup/tc18summera.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class tc18summera { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | long n = sc.nextInt(); 10 | long b = sc.nextInt(); 11 | long a = sc.nextInt(); 12 | 13 | long left = 0; 14 | long right = n; 15 | long med = (left+right)/2; 16 | 17 | while (left!=right) { 18 | med = (left+right)/2; 19 | if (f(n, b, a, med)<=f(n, b, a, med+1)) { 20 | left = med+1; 21 | } 22 | else if (f(n, b, a, med)>=f(n, b, a, med+1)) { 23 | right = med; 24 | } 25 | } 26 | System.out.println(f(n, b, a, left)); 27 | 28 | } 29 | 30 | public static long f(long n, long b, long a, long x) { 31 | return (b*x+a)*(n-x); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /Java/DMOJ/Triway Cup/tc19summerj3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class tc19summerj3 { 4 | public static void main(String[] args) { 5 | 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int a = sc.nextInt(); 9 | int[] b = new int[a]; 10 | for(int i=0; i adj [] = new ArrayList[2001]; 8 | static boolean [] visited = new boolean[2001]; 9 | 10 | static void dfs(int r) { 11 | visited[r] = true; 12 | for (int i=0; i(); 27 | 28 | for (int i=0; i=K[i]) dp[i][j] = Math.max(dp[i-1][j], N[i]+dp[i-1][j-K[i]]); 20 | else dp[i][j] = dp[i-1][j]; 21 | 22 | } 23 | } 24 | System.out.println(dp[C][M]); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Java/DMOJ/Valentines Day/valentines18j1.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class valentines18j1 { 5 | 6 | public static void main(String[] args) { 7 | // TODO Auto-generated method stub 8 | Scanner sc = new Scanner(System.in); 9 | int t = sc.nextInt(); 10 | float [] M = new float [t]; 11 | for (int i=0; i10) { 17 | System.out.println("Something is wrong with these cuteness values"); 18 | } else if (M[t-1]>1 && M[t-1]<=10) { 19 | System.out.println("Cuteness by definition is similarity to Cactus"); 20 | } else { 21 | System.out.println("Cuteness by definition is similarity to Carol"); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Java/DMOJ/Valentines Day/valentines18j2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class valentines18j2 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner(System.in); 8 | int N = sc.nextInt(); 9 | int X = sc.nextInt(); 10 | int Y = sc.nextInt(); 11 | int fin = 0; 12 | int count = 1; 13 | while (true) { 14 | fin = fin+X; 15 | if (fin*2>=N) { 16 | break; 17 | } 18 | X = X-Y; 19 | count++; 20 | 21 | } 22 | 23 | if (X<=0) { 24 | System.out.println("RIP"); 25 | } else { 26 | System.out.println(count); 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Java/DMOJ/aminusb.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class aminusb { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | for (int i=0; i{ 7 | int node; 8 | int dist; 9 | Path (int _n, int _d){ 10 | node = _n; 11 | dist = _d; 12 | } 13 | 14 | public int compareTo(Path o) { 15 | return dist-o.dist; 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | 21 | Scanner sc = new Scanner(System.in); 22 | 23 | int n = sc.nextInt(); 24 | int m = sc.nextInt(); 25 | 26 | int [][] graph = new int [1001][1001]; 27 | 28 | for (int i=0; i= graph[u][v]) continue; 37 | graph[u][v] = w; 38 | graph[v][u] = w; 39 | } 40 | 41 | int distance[] = new int[1001]; 42 | for (int i=0; i pq = new PriorityQueue(); 46 | 47 | pq.add(new Path(0, 1)); 48 | 49 | while(!pq.isEmpty()) { 50 | Path p = pq.poll(); 51 | int dist = p.dist; 52 | int node = p.node; 53 | 54 | if (distance[node] < dist) continue; 55 | distance[node] = dist; 56 | 57 | for (int i=0; i 1000000000) return 1134903170; 10 | return fibonacci(b, a+b); 11 | } 12 | 13 | static int binarySearch(int arr[], int l, int r, int x) 14 | { 15 | if (r >= l) { 16 | int mid = l + (r - l) / 2; 17 | 18 | if (arr[mid] == x || (mid > 0 && (arr[mid] >= x && arr[mid-1] < x))) 19 | return mid; 20 | 21 | if (arr[mid] > x) 22 | return binarySearch(arr, l, mid - 1, x); 23 | 24 | return binarySearch(arr, mid + 1, r, x); 25 | } 26 | 27 | return -1; 28 | } 29 | 30 | 31 | public static void main(String[] args) { 32 | 33 | Scanner sc = new Scanner(System.in); 34 | 35 | for (int t=0; t<5; t++) { 36 | int n = sc.nextInt(); 37 | 38 | // fibonacci(0, 1); 39 | 40 | int ans = binarySearch(fib, 0, fib.length-1, n); 41 | 42 | if (fib[ans] > n && ans > 0 && fib[ans] - n > n - fib[ans-1]) 43 | System.out.println(fib[ans-1]); 44 | else 45 | System.out.println(fib[ans]); 46 | 47 | } 48 | 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /Java/ECOO/ecoo1p4.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ecoo1p4 { 4 | 5 | static int w; 6 | static int h; 7 | 8 | static void dfs(int x, int y, char [][] graph, boolean [][] visited) { 9 | visited[x][y] = true; 10 | if (x-1>=0 && graph[x-1][y] == 'X' && !visited[x-1][y]) { 11 | dfs(x-1, y, graph, visited); 12 | } 13 | if (y-1>=0 && graph[x][y-1] == 'X' && !visited[x][y-1]) { 14 | dfs(x, y-1, graph, visited); 15 | } 16 | if (x+1=0; j--) 21 | base[j] = Math.max(base[j] + temp[j], base[Math.max(j-1, 0)] + temp[j]); 22 | 23 | } 24 | 25 | Arrays.sort(base, 0, n); 26 | 27 | System.out.println(base[n-1]); 28 | 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /Java/SPOJ/a2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class a2 { 3 | 4 | public static void main(String[] args) { 5 | // TODO Auto-generated method stub 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Ready"); 8 | while (true) { 9 | String S = sc.nextLine(); 10 | if (S.equals(" ")) { 11 | break; 12 | } else if (S.equals("bd")||S.equals("db")) { 13 | System.out.println("Mirrored pair"); 14 | } else if (S.equals("pq")||S.equals("qp")) { 15 | System.out.println("Mirrored pair"); 16 | } else { 17 | System.out.println("Ordinary pair"); 18 | } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Java/SPOJ/a3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class a3 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Scanner sc = new Scanner (System.in); 8 | long t = sc.nextInt(); 9 | for (long a=0; a map [] = new ArrayList[1005]; 18 | 19 | for (int i=1; i<=l; i++) 20 | map[i] = new ArrayList(); 21 | 22 | for (int i=0; i queue = new LinkedList(); 29 | int [] steps = new int [1005]; 30 | Arrays.fill(steps, 1 << 30); 31 | 32 | queue.add(s); 33 | steps[s] = 0; 34 | 35 | while (!queue.isEmpty()) { 36 | 37 | int p = queue.pop(); 38 | 39 | for (int i=0; i steps[p] + 1) { 41 | steps[map[p].get(i)] = steps[p] + 1; 42 | queue.add(map[p].get(i)); 43 | } 44 | 45 | } 46 | 47 | System.out.println(steps[e]%1000); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Java/WCIPEG/Woburn Challenge/wc151j2.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class wc151j2 { 5 | 6 | public static void main(String[] args) { 7 | // TODO Auto-generated method stub 8 | Scanner sc = new Scanner(System.in); 9 | int N = sc.nextInt(); 10 | int M = sc.nextInt(); 11 | if (N%M==0) { 12 | int n = N/M; 13 | System.out.println(M+" group(s) of "+n); 14 | }else { 15 | int n = N/M; 16 | int r = N%M; 17 | System.out.println((M-r)+" group(s) of "+n); 18 | System.out.println(r+" group(s) of "+(n+1)); 19 | } 20 | 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /Java/WCIPEG/Woburn Challenge/wc96p5.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.LinkedList; 3 | import java.util.Scanner; 4 | 5 | public class wc96p5 { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int m = sc.nextInt(); 11 | int n = sc.nextInt(); 12 | 13 | int [][] graph = new int[m+1][n+1]; 14 | for (int i=1; i<=m; i++) { 15 | for (int j=1; j<=n; j++) { 16 | graph[i][j] = 0; 17 | } 18 | } 19 | 20 | while (true) { 21 | int a = sc.nextInt(); 22 | int b = sc.nextInt(); 23 | if (a==0 && b==0) break; 24 | graph[a][b] = 1; 25 | } 26 | 27 | int [][] apples = new int [m+1][n+1]; 28 | for (int i=1; i<=m; i++) { 29 | for (int j=1; j<=n; j++) { 30 | apples[i][j] = 0; 31 | } 32 | } 33 | apples[1][1] = graph[1][1]; 34 | 35 | LinkedList queue_X = new LinkedList(); 36 | LinkedList queue_Y = new LinkedList(); 37 | 38 | queue_X.add(1); 39 | queue_Y.add(1); 40 | 41 | while (!queue_X.isEmpty()) { 42 | int x = queue_X.pop(); 43 | int y = queue_Y.pop(); 44 | if (x+1<=m && apples[x][y]+graph[x+1][y]>apples[x+1][y]) { 45 | apples[x+1][y] = apples[x][y]+graph[x+1][y]; 46 | queue_X.add(x+1); 47 | queue_Y.add(y); 48 | } 49 | if (y+1<=n && apples[x][y]+graph[x][y+1]>apples[x][y+1]) { 50 | apples[x][y+1] = apples[x][y]+graph[x][y+1]; 51 | queue_X.add(x); 52 | queue_Y.add(y+1); 53 | } 54 | } 55 | 56 | System.out.println(apples[m][n]); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Java/WCIPEG/a4b1.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class a4b1 { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int [] a = new int [n]; 10 | for (int i=0; i l = new LinkedList(); 19 | 20 | l.add(new path(0, 0)); 21 | while (!l.isEmpty()) { 22 | path P = l.pop(); 23 | int N = P.node; 24 | int D = P.distance; 25 | if (D=0; i--) { 44 | if (i+1 < T) { 45 | left[i] += left[i+1]; 46 | right[i] += right[i+1]; 47 | } 48 | 49 | if (i+k < T) { 50 | 51 | long diff = Math.abs((left[i] - left[i+k] - n) - (right[i] - right[i+k])); 52 | 53 | if (min >= diff) { 54 | min = diff; 55 | index = i+1; 56 | } 57 | } 58 | } 59 | 60 | System.out.println(index); 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Java/WCIPEG/trickortreat.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class trickortreat { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int d = sc.nextInt(); 10 | int total = 0; 11 | int [] a = new int [n]; 12 | for (int i=0; id) { 21 | break; 22 | } else { 23 | total+=a[i]; 24 | sum++; 25 | } 26 | } 27 | System.out.println(sum); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc00j1.py: -------------------------------------------------------------------------------- 1 | s = input().split(' ') 2 | n = int(s[0]) 3 | m = int(s[1]) 4 | 5 | print('Sun Mon Tue Wed Thr Fri Sat') 6 | 7 | for i in range(0, n-1): 8 | print(' ', end='') 9 | 10 | for i in range(n, m+n): 11 | if len(str(i-n+1)) == 1: 12 | print(' ', end='') 13 | else: 14 | print(' ', end='') 15 | print(i-n+1, end='') 16 | if i%7 == 0 or i == m+n-1: 17 | print() 18 | else: 19 | print(' ', end='') 20 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc00j2.py: -------------------------------------------------------------------------------- 1 | m = int(input()) 2 | n = int(input()) 3 | 4 | count = 0 5 | 6 | d = {'0':'0', '1':'1', '8':'8', '6':'9', '9':'6'} 7 | 8 | for i in range(m, n+1): 9 | s = '' 10 | for c in str(i): 11 | if c in d: 12 | s += d[c] 13 | else: 14 | break 15 | if s != '' and int(s[::-1]) == i: 16 | count += 1 17 | 18 | print(count) 19 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc00j4.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | streams = [] 3 | for i in range(n): 4 | streams.append(int(input())) 5 | while True: 6 | l = int(input()) 7 | if l == 99: 8 | split = int(input())-1 9 | perc = int(input()) 10 | a = streams[split] 11 | if perc != 0 and perc != 100: 12 | streams[split] = a/(100/perc) 13 | streams.insert(split+1, a/(100/(100-perc))) 14 | elif perc == 0: 15 | streams[split] = 0 16 | streams.insert(split+1, a) 17 | else: 18 | streams[split] = a 19 | streams.insert(split+1, 0) 20 | elif l == 88: 21 | join = int(input())-1 22 | streams[join] = streams[join] + streams[join+1] 23 | streams.pop(join+1) 24 | else: 25 | break 26 | for s in streams: 27 | print(round(s), end=' ') 28 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc01j1.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | for i in range(1, n+1, 2): 3 | print('*'*i, end="") 4 | print(' '*(2*(n-i)), end="") 5 | print('*'*i, end="") 6 | print() 7 | for i in range(n-2, 0, -2): 8 | print('*'*i, end="") 9 | print(' '*(2*(n-i)), end="") 10 | print('*'*i, end="") 11 | print() -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc01j2.py: -------------------------------------------------------------------------------- 1 | x = int(input()) 2 | m = int(input()) 3 | 4 | mult = 0 5 | n = 'No such integer exists.' 6 | 7 | while (mult*m+1)/x < m: 8 | mult+=1 9 | if (mult*m+1)/x == (mult*m+1)//x: 10 | n = (mult*m+1)//x 11 | 12 | print(n) -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc02j1.py: -------------------------------------------------------------------------------- 1 | display = [""" * * * 2 | * * 3 | * * 4 | * * 5 | 6 | * * 7 | * * 8 | * * 9 | * * *""",""" 10 | * 11 | * 12 | * 13 | 14 | * 15 | * 16 | * 17 | """,""" * * * 18 | * 19 | * 20 | * 21 | * * * 22 | * 23 | * 24 | * 25 | * * *""",""" * * * 26 | * 27 | * 28 | * 29 | * * * 30 | * 31 | * 32 | * 33 | * * *""",""" 34 | * * 35 | * * 36 | * * 37 | * * * 38 | * 39 | * 40 | * 41 | """,""" * * * 42 | * 43 | * 44 | * 45 | * * * 46 | * 47 | * 48 | * 49 | * * *""",""" * * * 50 | * 51 | * 52 | * 53 | * * * 54 | * * 55 | * * 56 | * * 57 | * * *""",""" * * * 58 | * 59 | * 60 | * 61 | 62 | * 63 | * 64 | * 65 | """,""" * * * 66 | * * 67 | * * 68 | * * 69 | * * * 70 | * * 71 | * * 72 | * * 73 | * * *""",""" * * * 74 | * * 75 | * * 76 | * * 77 | * * * 78 | * 79 | * 80 | * 81 | * * *"""] 82 | n = int(input()) 83 | print(display[n]) 84 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc02j2.py: -------------------------------------------------------------------------------- 1 | consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 2 | 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'] 3 | while True: 4 | s = input().lower() 5 | if s=='quit!': 6 | break 7 | can = False 8 | while not can: 9 | if 'or' in s: 10 | if s.index('or')>0 and s.index('or')==len(s)-2 and len(s)>4 and s[s.index('or')-1] in consonants: 11 | s = s.replace('or', 'our', 1) 12 | else: 13 | s = s.replace('or', '$$$', 1) 14 | else: 15 | s = s.replace('$$$', 'or') 16 | can = True 17 | print(s) -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc02s2.py: -------------------------------------------------------------------------------- 1 | import math 2 | n = int(input()) 3 | d = int(input()) 4 | ans = '' 5 | if n//d>0: 6 | ans+=str(n//d)+" " 7 | if n%d!=0: 8 | gcf = 1 9 | for i in range(1, d): 10 | if (n%d)%i==0 and d%i==0 and i>gcf: 11 | gcf = i 12 | ans+=str((n%d)//gcf)+"/"+str(d//gcf) 13 | if ans=='': 14 | print(0) 15 | else: 16 | print(ans) -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc03j2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from math import sqrt 3 | input = sys.stdin.readline 4 | while True: 5 | n = int(input()) 6 | if n == 0: 7 | break 8 | x, y = int(sqrt(n)), int(sqrt(n)) 9 | while x*y != n: 10 | y += 1 11 | x = n//y 12 | print('Minimum perimeter is '+str(2*x+2*y)+' with dimensions '+str(x)+' x '+str(y)) 13 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc05j1.py: -------------------------------------------------------------------------------- 1 | d = int(input()) 2 | e = int(input()) 3 | w = int(input()) 4 | a = round(max(0, d-100)*0.25+e*0.15+w*0.2, 2) 5 | b = round(max(0, d-250)*0.45+e*0.35+w*0.25, 2) 6 | print("Plan A costs", a) 7 | print("Plan B costs", b) 8 | if ab: 11 | print("Plan B is cheapest.") 12 | else: 13 | print("Plan A and B are the same price.") -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc05j2.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = int(input()) 3 | count = 0 4 | for i in range (n, m+1): 5 | c = 0 6 | for j in range(1, i+1): 7 | if i%j==0: 8 | c+=1 9 | if c==4: 10 | count+=1 11 | print('The number of RSA numbers between', n, 'and', m, 'is', count) 12 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc05j5.py: -------------------------------------------------------------------------------- 1 | while True: 2 | s = input() 3 | if s == 'X': 4 | break 5 | pref = 0 6 | a = False 7 | monkey = True 8 | for c in s: 9 | if (c == 'A' and a) or (c == 'N' and not a) or pref < 0 or (c == 'S' and not a): 10 | monkey = False 11 | if c == 'B': 12 | pref += 1 13 | elif c == 'S': 14 | pref -= 1 15 | elif c == 'A': 16 | a = True 17 | elif c == 'N': 18 | a = False 19 | else: 20 | monkey = False 21 | 22 | if pref != 0: 23 | monkey = False 24 | 25 | if monkey: 26 | print('YES') 27 | else: 28 | print('NO') 29 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc07j3.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = [100, 500, 1000, 5000, 10000, 25000, 50000, 100000, 500000, 1000000] 3 | for i in range(n): 4 | a[int(input())-1] = 0 5 | l = len(a) 6 | i = 0 7 | while i sum(a)/len(a): 15 | print('deal') 16 | else: 17 | print('no deal') -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc07j4.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | t = input() 3 | if sorted(s.replace(' ', '')) == sorted(t.replace(' ', '')): 4 | print('Is an anagram.') 5 | else: 6 | print('Is not an anagram.') 7 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc08j2.py: -------------------------------------------------------------------------------- 1 | def buttonOne(lst): 2 | temp = lst.pop(0) 3 | lst.append(temp) 4 | return lst 5 | def buttonTwo(lst): 6 | temp = lst.pop(len(lst)-1) 7 | lst.insert(0, temp) 8 | return lst 9 | def buttonThree(lst): 10 | temp = lst.pop(0) 11 | lst.insert(1, temp) 12 | return lst 13 | 14 | s = ['A', 'B', 'C', 'D', 'E'] 15 | while True: 16 | btn = int(input()) 17 | n = int(input()) 18 | if btn == 1: 19 | for i in range(n): 20 | s = buttonOne(s)[:] 21 | elif btn == 2: 22 | for i in range(n): 23 | s = buttonTwo(s)[:] 24 | elif btn == 3: 25 | for i in range(n): 26 | s = buttonThree(s)[:] 27 | else: 28 | break 29 | 30 | for a in s: 31 | print(a, end=' ') -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc10j2.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | b = int(input()) 3 | c = int(input()) 4 | d = int(input()) 5 | s = int(input()) 6 | 7 | nc = 0 8 | nf = 1 9 | nd = 0 10 | bc = 0 11 | bf = 1 12 | bd = 0 13 | 14 | steps = 0 15 | 16 | while steps bd: 38 | print('Nikky') 39 | elif nd < bd: 40 | print('Byron') 41 | else: 42 | print('Tied') 43 | 44 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc11j2.py: -------------------------------------------------------------------------------- 1 | def getAltitude(h, t): 2 | return -6*t**4 + h*t**3 + 2*t**2 + t 3 | 4 | h = int(input()) 5 | m = int(input()) 6 | t = 1 7 | 8 | while getAltitude(h, t) > 0 and m > t: 9 | t += 1 10 | 11 | if getAltitude(h, t) <= 0: 12 | print('The balloon first touches ground at hour:\n'+str(t)) 13 | else: 14 | print('The balloon does not touch ground in the given time.') 15 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc11j3.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = int(input()) 3 | count = 2 4 | while n-m>=0: 5 | t = m 6 | m = n-m 7 | n = t 8 | count+=1 9 | print(count) -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc12j2.py: -------------------------------------------------------------------------------- 1 | a = [] 2 | flag = True 3 | for i in range(4): 4 | a.append(int(input())) 5 | if a[0]=a[i]: 8 | flag = False 9 | break 10 | if flag: 11 | print("Fish Rising") 12 | elif a[0]>a[1]: 13 | for i in range(2, len(a)): 14 | if a[i-1]<=a[i]: 15 | flag = False 16 | break 17 | if flag: 18 | print("Fish Diving") 19 | elif a[0]==a[1]: 20 | for i in range(2, len(a)): 21 | if a[i-1]!=a[i]: 22 | flag = False 23 | break 24 | if flag: 25 | print("Fish At Constant Depth") 26 | if not flag: 27 | print("No Fish") -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc12j3.py: -------------------------------------------------------------------------------- 1 | s = ['*x*', 2 | ' xx', 3 | '* *'] 4 | n = int(input()) 5 | for i in s: 6 | for num in range(n): 7 | for j in i: 8 | print(j*n, end="") 9 | print() -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc12j4.py: -------------------------------------------------------------------------------- 1 | k = int(input()) 2 | word = input() 3 | ans = '' 4 | for i in range(len(word)): 5 | ind = ord(word[i])-(3*(i+1)+k) 6 | if ind < 65: 7 | ind += 26 8 | ans += chr(ind) 9 | print(ans) -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc13j2.py: -------------------------------------------------------------------------------- 1 | sign = input() 2 | letters = ['I', 'O', 'S', 'H', 'Z', 'X', 'N'] 3 | flag = True 4 | for s in sign: 5 | if s not in letters: 6 | flag = False 7 | break 8 | 9 | if flag: 10 | print("YES") 11 | else: 12 | print("NO") 13 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc13j3.py: -------------------------------------------------------------------------------- 1 | n = int(input())+1 2 | flag = True 3 | while flag: 4 | flag = False 5 | for i in str(n): 6 | if str(n).count(i)>1: 7 | flag = True 8 | n+=1 9 | print(n-1) 10 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc15j2.py: -------------------------------------------------------------------------------- 1 | msg = input() 2 | n = msg.count(":-)") 3 | m = msg.count(":-(") 4 | if n==0 and m==0: 5 | print("none") 6 | elif n==m: 7 | print("unsure") 8 | elif n>m: 9 | print("happy") 10 | elif n0: 11 | if (n >= rhs1 and n < rhe1) or (n >= rhs2 and n < rhe2): 12 | i-=1 13 | else: 14 | i-=2 15 | n+=1 16 | 17 | h = str((n//60)%24) 18 | m = str(n%60) 19 | 20 | if len(h) == 1: 21 | h = '0'+h 22 | if len(m) == 1: 23 | m = '0'+m 24 | 25 | print(h+':'+m) 26 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc19j1.py: -------------------------------------------------------------------------------- 1 | a = int(input())*3 + int(input())*2 + int(input()) 2 | b = int(input())*3 + int(input())*2 + int(input()) 3 | if a>b: 4 | print('A') 5 | elif b>a: 6 | print('B') 7 | else: 8 | print('T') 9 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc19j2.py: -------------------------------------------------------------------------------- 1 | l = int(input()) 2 | for a in range(l): 3 | i, n = input().split() 4 | i = int(i) 5 | print(i*n) 6 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc19j3.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | for i in range(n): 3 | s = input() 4 | count = 1 5 | for c in range(len(s)): 6 | if c == len(s)-1 or s[c] != s[c+1]: 7 | print(count, s[c], end=' ') 8 | count = 1 9 | else: 10 | count += 1 11 | print() 12 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc20j1.py: -------------------------------------------------------------------------------- 1 | s = int(input()) 2 | m = int(input()) 3 | l = int(input()) 4 | print('happy' if s+2*m+3*l >= 10 else 'sad') 5 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc20j2.py: -------------------------------------------------------------------------------- 1 | p = int(input()) 2 | n = int(input()) 3 | r = int(input()) 4 | d = 0 5 | total = n 6 | while total <= p: 7 | d += 1 8 | total += n*(r**d) 9 | print(d) 10 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc20j3.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | minx = 101 3 | maxx = 0 4 | miny = 101 5 | maxy = 0 6 | for i in range(n): 7 | x, y = map(int, input().split(',')) 8 | minx = min(minx, x-1) 9 | maxx = max(maxx, x+1) 10 | miny = min(miny, y-1) 11 | maxy = max(maxy, y+1) 12 | print('%d,%d' % (minx, miny)) 13 | print('%d,%d' % (maxx, maxy)) 14 | -------------------------------------------------------------------------------- /Python/CCC/CCC Junior/ccc20j4.py: -------------------------------------------------------------------------------- 1 | def solve(t, s): 2 | for i in range(len(s)): 3 | if s[i:] + s[:i] in t: 4 | return 'yes' 5 | return 'no' 6 | 7 | t = input() 8 | s = input() 9 | print(solve(t, s)) 10 | -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc03s1.py: -------------------------------------------------------------------------------- 1 | n = 1 2 | transports = {54:19, 90:48, 99:77, 9:34, 40:64, 67:86} 3 | msg = '' 4 | while True: 5 | roll = int(input()) 6 | if n+roll<=100: 7 | n+=roll 8 | if n in transports: 9 | n = transports[n] 10 | if roll==0: 11 | msg+='You Quit!\n' 12 | break 13 | else: 14 | msg+='You are now on square '+str(n)+'\n' 15 | if n==100: 16 | msg+='You Win!\n' 17 | break 18 | print(msg) -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc05s1.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | keypad = [[], ['A', 'B', 'C'], ['D', 'E', 'F'], 3 | ['G', 'H', 'I'], ['J', 'K', 'L'], ['M', 'N', 'O'], 4 | ['P', 'Q', 'R', 'S'], ['T', 'U', 'V'], ['W', 'X', 'Y', 'Z']] 5 | for t in range(n): 6 | phon = input() 7 | ans = '' 8 | for p in phon: 9 | if p.isdigit(): 10 | ans += p 11 | elif p.isalpha(): 12 | for k in range(len(keypad)): 13 | if p in keypad[k]: 14 | ans += str(k+1) 15 | print(ans[0:3]+'-'+ans[3:6]+'-'+ans[6:10]) -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc05s2.py: -------------------------------------------------------------------------------- 1 | s = input().split(' ') 2 | c = int(s[0]) 3 | r = int(s[1]) 4 | 5 | x = 0 6 | y = 0 7 | 8 | while True: 9 | s = input().split(' ') 10 | rx = int(s[0]) 11 | ry = int(s[1]) 12 | if rx == 0 and ry == 0: 13 | break 14 | x = min(max(x+rx, 0), c) 15 | y = min(max(y+ry, 0), r) 16 | print(x, y) 17 | -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc08s1.py: -------------------------------------------------------------------------------- 1 | class City(object): 2 | def __init__(self, name, temp): 3 | self.name = name 4 | self.temp = temp 5 | 6 | city = "" 7 | cities = [] 8 | while city!="Waterloo": 9 | city, temp = input().split(" ") 10 | temp = int(temp) 11 | cities.append(City(city, temp)) 12 | mn = City("", 201) 13 | for c in cities: 14 | if mn.temp > c.temp: 15 | mn = c 16 | print(mn.name) -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc10s1.py: -------------------------------------------------------------------------------- 1 | class Computer(object): 2 | def __init__(self, name, r, s, d): 3 | self.name = name 4 | self.value = 2*r + 3*s + d 5 | def __gt__(self, other): 6 | if self.value == other.value: 7 | return self.name > other.name 8 | return self.value < other.value 9 | def __lt__(self, other): 10 | if self.value == other.value: 11 | return self.name < other.name 12 | return self.value > other.value 13 | 14 | n = int(input()) 15 | computers = [] 16 | for i in range(n): 17 | s = input().split(' ') 18 | computers.append(Computer(s[0], int(s[1]), int(s[2]), int(s[3]))) 19 | 20 | computers.sort() 21 | 22 | if (n == 1): 23 | print(computers[0].name) 24 | elif (n > 1): 25 | print(computers[0].name+'\n'+computers[1].name) 26 | 27 | -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc11s1.py: -------------------------------------------------------------------------------- 1 | n = int (input()) 2 | sCount = 0 3 | tCount = 0 4 | for i in range (n): 5 | s = str (input()) 6 | for j in range(len(s)): 7 | if (s[j].lower()=='s'): 8 | sCount += 1 9 | elif (s[j].lower()=='t'): 10 | tCount += 1 11 | if (sCount>=tCount): 12 | print("French") 13 | else: 14 | print("English") -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc12s2.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | val = 0 3 | roman = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} 4 | for c in range(0, len(s), 2): 5 | i = int(s[c]) * roman[s[c+1]] 6 | if c < len(s)-2 and roman[s[c+3]] > roman[s[c+1]]: 7 | i *= -1 8 | val += i 9 | print(val) 10 | -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc13s2.py: -------------------------------------------------------------------------------- 1 | w = int(input()) 2 | n = int(input()) 3 | t = [] 4 | for i in range(n): 5 | t.append(int(input())) 6 | if len(t) > 4: 7 | t.pop(0) 8 | if sum(t) > w: 9 | print(i) 10 | break 11 | if i == n-1: 12 | print(i+1) 13 | -------------------------------------------------------------------------------- /Python/CCC/CCC Senior/ccc14s1.py: -------------------------------------------------------------------------------- 1 | class Friend(object): 2 | def __init__(self, i, n): 3 | self.i = i 4 | self.n = n 5 | 6 | k = int(input()) 7 | lst = [] 8 | for i in range(k): 9 | lst.append(Friend(i+1, i+1)) 10 | m = int(input()) 11 | for i in range(m): 12 | r = int(input()) 13 | for roun in range(r, k+1, r): 14 | for l in lst: 15 | if l.i == roun: 16 | lst.remove(l) 17 | for l in range(1, len(lst)+1): 18 | lst[l-1].i = l 19 | for l in lst: 20 | print(l.n) -------------------------------------------------------------------------------- /Python/Codeforces/Compete McGill/mcgill1E.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | q = list(map(int, input().split(' '))) 3 | p = [0] 4 | i = 0 5 | for j in q: 6 | i += j 7 | p.append(i) 8 | diff = 1-min(p) 9 | for j in range(len(p)): 10 | p[j] += diff 11 | if sorted(p) != list(range(1, n+1)): 12 | print(-1) 13 | else: 14 | print(' '.join(map(str, p))) 15 | -------------------------------------------------------------------------------- /Python/Codeforces/Compete McGill/mcgill1F.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | n = int(input()) 4 | a = list(map(int, input().split(' '))) 5 | b = list(map(int, input().split(' '))) 6 | k = -1.1 7 | for j in range(len(a)): 8 | if a[j] < b[j] and k == -1.1: 9 | k = b[j] - a[j] 10 | elif a[j] == b[j] and k != -1.1: 11 | k = 0 12 | if k != -1.1: 13 | a[j] += k 14 | print("YES" if a == b else "NO") 15 | -------------------------------------------------------------------------------- /Python/DMOJ/4ever.py: -------------------------------------------------------------------------------- 1 | ones = ["", "one","two","three","four", "five", "six","seven","eight","nine","ten","eleven","twelve", "thirteen", "fourteen", "fifteen","sixteen","seventeen", "eighteen","nineteen"] 2 | twenties = ["","","twenty","thirty","forty", "fifty","sixty","seventy","eighty","ninety"] 3 | thousands = ["","thousand","million", "billion"] 4 | 5 | def num999(n): 6 | c = n % 10 7 | b = ((n % 100) - c) // 10 8 | a = ((n % 1000) - (b * 10) - c) // 100 9 | t = "" 10 | h = "" 11 | if a != 0: 12 | t = ones[a] + "hundred" 13 | if b <= 1: 14 | h = ones[n%100] 15 | elif b > 1: 16 | h = twenties[b] + ones[c] 17 | st = t + h 18 | return st 19 | 20 | def num2word(num): 21 | if num == 0: return 'zero' 22 | i = 3 23 | n = str(num) 24 | word = "" 25 | k = 0 26 | while(i == 3): 27 | nw = n[-i:] 28 | n = n[:-i] 29 | if int(nw) == 0: 30 | word = num999(int(nw)) + thousands[int(nw)] + word 31 | else: 32 | word = num999(int(nw)) + thousands[k] + word 33 | if n == '': 34 | i = i+1 35 | k += 1 36 | return word 37 | 38 | n = int(input()) 39 | 40 | chain = [n] 41 | 42 | while (n != 4): 43 | n = len(num2word(n)) 44 | print(n) -------------------------------------------------------------------------------- /Python/DMOJ/BTS/bts16p1.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | uc = 0 3 | lc = 0 4 | for c in s: 5 | if c.isalpha() and c.upper() == c: 6 | uc += 1 7 | elif c.isalpha(): 8 | lc += 1 9 | if uc > lc: 10 | print(s.upper()) 11 | elif lc > uc: 12 | print(s.lower()) 13 | else: 14 | print(s) -------------------------------------------------------------------------------- /Python/DMOJ/BTS/bts18p1.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | t = input() 3 | k = int(input()) 4 | 5 | for c in range(len(s)): 6 | if (s[c] == ' ') != (t[c] == ' '): 7 | k = 0 8 | break 9 | elif s[c] != t[c]: 10 | k -= 1 11 | 12 | if k <= 0: 13 | print('No plagiarism') 14 | else: 15 | print('Plagiarized') 16 | -------------------------------------------------------------------------------- /Python/DMOJ/DMOPC/dmopc14c1p3.py: -------------------------------------------------------------------------------- 1 | i = int(input()) 2 | sm = 0 3 | c = 0 4 | for l in range(i): 5 | sm += int(input()) 6 | c += 1 7 | s = int(input()) 8 | for l in range(s): 9 | sm += int(input()) 10 | c += 1 11 | print("{0:.3f}".format(sm/c)) 12 | -------------------------------------------------------------------------------- /Python/DMOJ/DMOPC/dmopc18c1p0.py: -------------------------------------------------------------------------------- 1 | a = [] 2 | for i in range(3): 3 | a.append(int(input())) 4 | if a == sorted(a): 5 | print('Good job!') 6 | else: 7 | print('Try again!') 8 | -------------------------------------------------------------------------------- /Python/DMOJ/DMOPC/dmopc19c2p1.py: -------------------------------------------------------------------------------- 1 | def median(arr): 2 | if len(arr)%2 == 0: 3 | return (arr[int(len(arr)/2)] + arr[int(len(arr)/2-1)])/2.0 4 | else: 5 | return arr[int(len(arr)/2)] 6 | 7 | n = int(input()) 8 | s = input().split(' ') 9 | a = [] 10 | for i in range(n): 11 | a.append(int(s[i])) 12 | a.sort() 13 | print(a[0], a[n-1], median(a[:int(n/2)]), median(a), end=' ') 14 | if len(a)%2 != 0: 15 | print(median(a[int(n/2)+1:])) 16 | else: 17 | print(median(a[int(n/2):])) 18 | -------------------------------------------------------------------------------- /Python/DMOJ/DMOPC/dmopc19c3p0.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | n = int(input()) 4 | 5 | for i in range(n): 6 | seq = input().split() 7 | for s in range(len(seq)): 8 | seq[s] = int(seq[s]) 9 | 10 | ari = True 11 | geo = True 12 | 13 | for j in range(8): 14 | if seq[j]+seq[j+2] != 2*seq[j+1]: 15 | ari = False 16 | if seq[j]*seq[j+2] != seq[j+1]**2: 17 | geo = False 18 | 19 | if ari and geo: 20 | print('both') 21 | elif ari: 22 | print('arithmetic') 23 | elif geo: 24 | print('geometric') 25 | else: 26 | print('neither') 27 | 28 | -------------------------------------------------------------------------------- /Python/DMOJ/DMOPC/dmopc19c7p0.py: -------------------------------------------------------------------------------- 1 | def avg(args): 2 | return sum(args)/len(args) 3 | a, b, c, d = map(int, input().split(' ')) 4 | q = [ 5 | (a, b), 6 | (a, c), 7 | (a, d), 8 | (b, c), 9 | (b, d), 10 | (c, d), 11 | (a, b, c), 12 | (a, b, d), 13 | (a, c, d), 14 | (b, c, d), 15 | (a, b, c, d) 16 | ] 17 | for i in q: 18 | print(avg(i)) 19 | -------------------------------------------------------------------------------- /Python/DMOJ/DMOPC/dmopc19c7p1.py: -------------------------------------------------------------------------------- 1 | a, b, c, d = map(int, input().split(' ')) 2 | if b == 0 and a= k) != (max(abs(c[i]-c[(i-1)%n]), abs(c[i]-c[(i+1)%n])) <= l): 8 | count += 1 9 | print(count) 10 | -------------------------------------------------------------------------------- /Python/DMOJ/Mock CCC/mockccc2020c1j1.py: -------------------------------------------------------------------------------- 1 | a = [] 2 | for i in range(4): 3 | a.append(int(input())) 4 | a.sort() 5 | print(a[0]) 6 | print(a[3]) 7 | -------------------------------------------------------------------------------- /Python/DMOJ/Mock CCC/mockccc2020c1j2.py: -------------------------------------------------------------------------------- 1 | c = int(input()) 2 | m = int(input()) 3 | k = int(input()) 4 | print(max((c, m))*k) 5 | -------------------------------------------------------------------------------- /Python/DMOJ/Mock CCC/nccc5j4s2.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | p = list(map(int, input().split(' '))) 3 | 4 | count = 0 5 | 6 | for i in range(0, n-1): 7 | for j in range(0, n-i-1): 8 | if p[j] < p[j+1]: 9 | t = p[j] 10 | p[j] = p[j+1] 11 | p[j+1] = t 12 | count += 1 13 | 14 | print(count) 15 | 16 | -------------------------------------------------------------------------------- /Python/DMOJ/Mock CCC/nccc6j1.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | b = int(input()) 3 | if a > b: 4 | print('CS452') 5 | elif b > a: 6 | print('PHIL145') 7 | -------------------------------------------------------------------------------- /Python/DMOJ/Mock CCC/nccc6j2.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | count = 0 3 | for i in range(len(s)): 4 | if s[i] != 'pusheen'[i]: 5 | count += 1 6 | print(count) 7 | -------------------------------------------------------------------------------- /Python/DMOJ/Triway Cup/tc19summerf.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | n = input() 4 | m = input() 5 | a = int(n.split(" ")[0]) 6 | b = int(n.split(" ")[1]) 7 | c = int(n.split(" ")[2]) 8 | x = int(m.split(" ")[0]) 9 | y = int(m.split(" ")[1]) 10 | z = int(m.split(" ")[2]) 11 | 12 | def chebyshev(a, b, c, x, y, z): 13 | return max(abs(a-x), abs(b-y), abs(c-z)) 14 | 15 | def euclid(a, b, c, x, y, z): 16 | return int(math.sqrt((a-x)**2+(b-y)**2+(c-z)**2)) 17 | 18 | def manhattan(a, b, c, x, y, z): 19 | return abs(x-a)+abs(y-b)+abs(z-c) 20 | 21 | print(chebyshev(a, b, c, x, y, z)) 22 | 23 | print(euclid(a, b, c, x, y, z)) 24 | 25 | print(manhattan(a, b, c, x, y, z)) -------------------------------------------------------------------------------- /Python/DMOJ/Triway Cup/tc19summerj1.py: -------------------------------------------------------------------------------- 1 | line = input() 2 | n = int(line.split(" ")[0]) 3 | m = int(line.split(" ")[1]) 4 | 5 | def check(n, m): 6 | if abs(n-m)>abs(n//2-m): 7 | return check(n//2, m) 8 | else: 9 | return n 10 | 11 | print(check(n, m)) -------------------------------------------------------------------------------- /Python/DMOJ/Triway Cup/tc19summerj2.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | nums = s.split(" ") 3 | n = int(nums[0]) 4 | m = int(nums[1]) 5 | 6 | arr = [] 7 | arr.append(0) 8 | 9 | for i in range(n): 10 | arr.append(int(input())) 11 | 12 | ans = 0 13 | 14 | for i in range(1, n+1): 15 | if arr[i]==1 and arr[i]!=arr[i-1]: 16 | ans+=1 17 | 18 | print(ans) -------------------------------------------------------------------------------- /Python/DMOJ/VPEX/vpex1p0.py: -------------------------------------------------------------------------------- 1 | a, b = map(int, input().split(' ')) 2 | print(a//b, a%b) -------------------------------------------------------------------------------- /Python/DMOJ/VPEX/vpex1p1.py: -------------------------------------------------------------------------------- 1 | 2 | s = map(int, input().split(' ')) 3 | t = map(int, input().split(' ')) 4 | print(max(sum(sorted(s)[1:]), sum(sorted(t)[1:]))) -------------------------------------------------------------------------------- /Python/DMOJ/VPEX/vpex1p2.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | x = list(map(int, input().split(' '))) 3 | print(len(x) - x.count(sum(x)//len(x))) 4 | -------------------------------------------------------------------------------- /Python/DMOJ/WAC/wac2p1.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 3 | print(days[(days.index(s)-55)%7]) -------------------------------------------------------------------------------- /Python/DMOJ/WAC/wac3p1.py: -------------------------------------------------------------------------------- 1 | s = list(map(int, input().split(' '))) 2 | v = 0 3 | if s[0] < -40: 4 | v += 1 5 | if s[1] >= 15: 6 | v += 1 7 | if s[2] > 50: 8 | v += 1 9 | if v >= 2: 10 | print('YES') 11 | else: 12 | print('NO') -------------------------------------------------------------------------------- /Python/DMOJ/WAC/wac3p2.py: -------------------------------------------------------------------------------- 1 | def calc(v): 2 | a = v//3 3 | b = (v-a)//2 4 | c = v-a-b 5 | return a*b*c 6 | 7 | d = int(input()) 8 | for i in range(d): 9 | h = int(input()) 10 | print(calc(h)) -------------------------------------------------------------------------------- /Python/DMOJ/WAC/wac3p3.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | m = int(input()) 3 | combos = [] 4 | points = [] 5 | for i in range(m): 6 | t = input().split(' ') 7 | combos.append(t[0]) 8 | points.append(int(t[1])) 9 | 10 | total = len(s) 11 | 12 | while len(s) > 0: 13 | cm = -1 14 | for com in range(len(combos)): 15 | if combos[com] == s[:len(combos[com])] and (cm == -1 or len(combos[com]) > len(combos[cm])): 16 | cm = com 17 | 18 | if cm == -1: 19 | s = s[1:] 20 | else: 21 | total += points[cm] 22 | s = s[len(combos[cm]):] 23 | 24 | print(total) -------------------------------------------------------------------------------- /Python/DMOJ/art0.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | vowels = ['a', 'e', 'i', 'o', 'u'] 3 | words = ['Hi! ', 'Bye! ', 'How are you? ', 'Follow me! ', 'Help! '] 4 | for i in range(n): 5 | s = input().lower() 6 | ans = '' 7 | for c in s: 8 | if c in vowels: 9 | ans += words[vowels.index(c)] 10 | elif c.isdigit(): 11 | ans += 'Yes! ' 12 | print(ans) -------------------------------------------------------------------------------- /Python/DMOJ/binary.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | for j in range(n): 3 | i = int(input()) 4 | b = str(bin(i))[2:] 5 | if len(b)%4!=0: 6 | b = '0'*(4-len(b)%4)+b 7 | l = [] 8 | for i in range(0, len(b), 4): 9 | l.append(b[i:4+i]) 10 | if len(l[len(l)-1])<4: 11 | l[len(l)-1] = '0'*(4-len(l[len(l)-1] ))+l[len(l)-1] 12 | b = ' '.join(l) 13 | print(b) -------------------------------------------------------------------------------- /Python/DMOJ/boolean.py: -------------------------------------------------------------------------------- 1 | msg = "print("+input()+")" 2 | exec(msg) -------------------------------------------------------------------------------- /Python/DMOJ/hailstone.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | op = 0 3 | while n != 1: 4 | if n%2 == 0: 5 | n //= 2 6 | else: 7 | n *= 3 8 | n += 1 9 | op += 1 10 | print(op) 11 | -------------------------------------------------------------------------------- /Python/DMOJ/pwindsor18p1.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | if 'java' in s: 3 | print(s.index('java')) 4 | else: 5 | print(len(s)) 6 | -------------------------------------------------------------------------------- /Python/DMOJ/python1.py: -------------------------------------------------------------------------------- 1 | Magic.__dict__['method'](None) -------------------------------------------------------------------------------- /Python/DMOJ/quine.py: -------------------------------------------------------------------------------- 1 | t = ['t =', '\nprint(t[0], t, t[1])'] 2 | print(t[0], t, t[1]) 3 | -------------------------------------------------------------------------------- /Python/DMOJ/seed1.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | parts = ['B', 'F', 'T', 'L', 'C'] 3 | missing = False 4 | for p in parts: 5 | if s.count(p)==0: 6 | print(p) 7 | missing = True 8 | if not missing: 9 | print('NO MISSING PARTS') -------------------------------------------------------------------------------- /Python/DMOJ/set.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | n = int(input()) 4 | a = set({}) 5 | for i in range(n): 6 | v = int(input()) 7 | if v not in a: 8 | a.add(v) 9 | print(len(a)) 10 | -------------------------------------------------------------------------------- /Python/DMOJ/shortest1.py: -------------------------------------------------------------------------------- 1 | while 1:1 -------------------------------------------------------------------------------- /Python/DMOJ/sort1.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = list(map(int, input().split(' '))) 3 | print(*a) 4 | i = 0 5 | while a != sorted(a): 6 | if a[i] > a[i+1]: 7 | t = a[i] 8 | a[i] = a[i+1] 9 | a[i+1] = t 10 | print(*a) 11 | i = (i+1)%(n-1) 12 | -------------------------------------------------------------------------------- /Python/DMOJ/stnbd1.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | dancers = [] 3 | for i in range(n): 4 | dancers.append(int(input())) 5 | if dancers[0] == sorted(dancers)[::-1][0] and dancers.count(dancers[0]) == 1: 6 | print('YES') 7 | else: 8 | print('NO') -------------------------------------------------------------------------------- /Python/DMOJ/tsoc16c1p2.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | if s.count('.') != 1: 3 | name = s 4 | ext = input().lower() 5 | else: 6 | name = s.split('.')[0] 7 | ext = s.split('.')[1].lower() 8 | print('"'+name+'"'+' - '+ext) 9 | -------------------------------------------------------------------------------- /Python/Google Code Jam/gcj2019qr1.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | n = [c for c in input()] 4 | m = ['0']*len(n) 5 | for c in range(len(n)): 6 | if n[c] == '4': 7 | n[c] = '3' 8 | m[c] = '1' 9 | print('Case #%d: %s %s' % (i+1, ''.join(n), ''.join(m).lstrip('0'))) 10 | -------------------------------------------------------------------------------- /Python/Google Code Jam/gcj2019qr2.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | n = int(input()) 4 | s = input() 5 | print('Case #%d: %s' % (i+1, s.replace('E', 'T').replace('S', 'E').replace('T', 'S'))) 6 | -------------------------------------------------------------------------------- /Python/Google Code Jam/gcj2020qr1.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | n = int(input()) 4 | trace = 0 5 | hor = 0 6 | ver = 0 7 | matrix = [] 8 | flipped = [] 9 | for r in range(n): 10 | matrix.append(list(map(int, input().split(' ')))) 11 | flipped.append([0]*n) 12 | trace += matrix[r][r] 13 | hor += 1 if len(set(matrix[r])) < len(matrix[r]) else 0 14 | for r in range(n): 15 | for c in range(n): 16 | flipped[r][c] = matrix[n-1-c][n-1-r] 17 | for c in range(n): 18 | ver += 1 if len(set(flipped[c])) < len(flipped[r]) else 0 19 | print('Case #%d: %d %d %d' % (i+1, trace, hor, ver)) 20 | -------------------------------------------------------------------------------- /Python/Google Code Jam/gcj2020qr2.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | s = input() 4 | sp = '' 5 | depth = 0 6 | for c in s: 7 | if int(c) > depth: 8 | sp += '('*(int(c)-depth) 9 | elif int(c) < depth: 10 | sp += ')'*(depth-int(c)) 11 | depth = int(c) 12 | sp += c 13 | sp += ')'*depth 14 | print('Case #%d: %s' % (i+1, sp)) 15 | -------------------------------------------------------------------------------- /Python/Google Code Jam/gcj2020qr3.py: -------------------------------------------------------------------------------- 1 | class Task(object): 2 | def __init__(self, i, s, e): 3 | self.index = i 4 | self.pos = s 5 | self.time = set(range(s, e)) 6 | self.person = '' 7 | def __gt__(self, other): 8 | if not chron: 9 | return self.pos > other.pos 10 | return self.index > other.index 11 | 12 | t = int(input()) 13 | for i in range(t): 14 | n = int(input()) 15 | chron = False 16 | tasks = [] 17 | for j in range(n): 18 | s, e = map(int, input().split(' ')) 19 | tasks.append(Task(j, s, e)) 20 | tasks.sort() 21 | chron = True 22 | c = set() 23 | j = set() 24 | ans = '' 25 | for task in tasks: 26 | time = task.time 27 | if not c.intersection(time): 28 | c = c.union(time) 29 | task.person = 'C' 30 | elif not j.intersection(time): 31 | j = j.union(time) 32 | task.person = 'J' 33 | else: 34 | ans = 'IMPOSSIBLE' 35 | break 36 | if ans != 'IMPOSSIBLE': 37 | tasks.sort() 38 | for task in tasks: 39 | ans += task.person 40 | print('Case #%d: %s' % (i+1, ans)) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Competitive-Programming 2 | All my AC solutions to competitive programming problems (DMOJ, WCIPEG, Codeforces, etc.), 2017-2020 3 | 4 | | Platform | Username | Submissions Page | Time Active | 5 | | --- | --- | --- | --- | 6 | | DMOJ | [ManchurioX](https://dmoj.ca/user/ManchurioX) | [ManchurioX's submissions](https://dmoj.ca/user/ManchurioX/solved) | 2018 - | 7 | | Codeforces | [ManchurioX](https://codeforces.com/profile/ManchurioX) | [ManchurioX's submissions](https://codeforces.com/submissions/ManchurioX) | 2020 - | 8 | | AtCoder | [ManchurioX](https://atcoder.jp/users/ManchurioX) | [ManchurioX's submissions](https://kenkoooo.com/atcoder/#/table/ManchurioX) | 2020 - | 9 | | CSES | [ManchurioX](https://cses.fi/user/17209) | [ManchurioX's submissions](https://cses.fi/problemset/user/17209/) | 2020 - | 10 | | WCIPEG | [kevincui1230](https://wcipeg.com/user/kevincui1230) | [kevincui1230's submissions](https://wcipeg.com/submissions/kevincui1230) | 2017 - 2019 | 11 | --------------------------------------------------------------------------------