{"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tint n,l,jc;\n\tcin>>l;\n\tfor(int o=0;o>n;\n\t\tfor(int i=0;i<=n/3;i++)\n\t\t{\n\t\t\tfor(int j=0;j<=n/7;j++)\n\t\t\t{\n\t\t\t\tif((i*3)+(j*7)==n)\n\t\t\t\t{\n\t\t\t\t\tcout<<\"YES\"<\n#include\n#include\n#include \nusing namespace std;\nint ok = 0;\nint n = 0;\nint ans[11][11] = { 0 };\nint bj(int d[11][11])\n{\n\tint i,j;\n\tfor (i = 1; i <= n;i++)\n\tfor (j = 1; j <= n; j++)\n\t{\n\t\tif (d[i][j] != ans[i][j])\n\t\t\treturn 0;\n\t}\n\treturn 1;\n}\nvoid zhuan(int d[11][11])\n{\n\tint i, j, k;\n\tint e[11][11] = { 0 };\n\tfor (k = 1; k <= 4;k++)\n\tif (ok == 0)\n\t{\n\t\tfor (i = 1; i <= n; i++)\n\t\tfor (j = 1; j <= n; j++)\n\t\t\te[i][j] = d[n - j + 1][i];\n\t\tif (bj(e) == 1) {\n\t\t\tok = 1; return;\n\t\t}\n\t\tfor (i = 1; i <= n; i++)\n\t\tfor (j = 1; j <= n; j++)\n\t\t\td[i][j] = e[i][j];\n\t}\n}\nint main()\n{\n\tint a[11][11] = { 0 };\n\tint b[11][11] = { 0 };\n\tint c[11][11] = { 0 };\n\tint i, j;\n\tchar ch;\n\tscanf(\"%d\", &n);\n\tgetchar();\n\tfor (i = 1; i <= n; i++)\n\t{\n\t\tfor (j = 1; j <= n; j++)\n\t\t{\n\t\t\tscanf(\"%c\", &ch);\n\t\t\tif (ch == 'X') a[i][j] = 1;\n\t\t\telse if (ch == 'O') a[i][j] = 0;\n\t\t}\n\t\tgetchar();\n\t}\n\tfor (i = 1; i <= n; i++)\n\t{\n\t\tfor (j = 1; j <= n; j++)\n\t\t{\n\t\t\tscanf(\"%c\", &ch);\n\t\t\tif (ch == 'X') ans[i][j] = 1;\n\t\t\telse if (ch == 'O') ans[i][j] = 0;\n\t\t}\n\t\tgetchar();\n\t}\n\tfor (i = 1; i <= n; i++)\n\tfor (j = 1; j <= n; j++)\n\t\tb[i][j] = a[i][n + 1 - j];\n\tfor (i = 1; i <= n; i++)\n\tfor (j = 1; j <= n; j++)\n\t\tc[i][j] = a[n + 1 - i][j];\n\tzhuan(a);\n\tzhuan(b);\n\tzhuan(c);\n\tif (ok == 1) printf(\"Yes\");\n\telse printf(\"No\");\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "fec50496c94000a1f3147417bfc40df3", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#define ll long long\n\nusing namespace std;\n\nint main()\n{\n\tll a, b, x1, y1, x2, y2;\n\t\n\tcin>>a>>b>>x1>>y1>>x2>>y2;\n\n\tll Sum1 = x1+y1;\n\tll Sum2 = x2+y2;\n\n\tll Min1 = x1-y1;\n\tll Min2 = x2-y2;\n\n\tif (Sum1<0 || Sum2<0)\n\t{\n\t\tll minSum = min(Sum1, Sum2);\n\t\tminSum *= -1;\n\t\tSum1 += (minSum+2*a)/(2*a)*(2*a);\n\t\tSum2 += (minSum+2*a)/(2*a)*(2*a);\n\t}\n\n\tif (Min1<0 || Min2<0)\n\t{\n\t\tll minMin = min(Min1, Min2);\n\t\tminMin *= -1;\n\t\tMin1 += (minMin+2*b)/(2*b)*(2*b);\n\t\tMin2 += (minMin+2*b)/(2*b)*(2*b);\n\t}\n\n\tll X1 = Sum1/(2*a);\n\tll X2 = Sum2/(2*a);\n\n\tll Y1 = Min1/(2*b);\n\tll Y2 = Min2/(2*b);\n\n\n\tll ans = max(abs(X1-X2) , abs(Y1-Y2));\n\n\n\tcout<\nusing namespace std;\nint main() {\nint w;\ncin>>w;\nif(w==2) cout<<\"No\";\nelse if(w%2==0) cout<<\"Yes\";\nelse cout<<\"No\";\n\n}", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "fa927504423693e59f17cfaebdce069a", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\nusing namespace std;\nint main()\n{\n long long x,ans=0,ten=1,tmp=0;\n cin>>x;\n \n while(x)\n {\n tmp=x%10;\n if(x<10&&tmp==9)\n ans+=tmp*ten;\n else\n ans+=ten*(tmp>=5?9-tmp:tmp);\n ten*=10;\n x/=10; \n }\n \n cout<\n#include \nusing namespace std;\nlong long a,b,p,l,c,i,z;\nint main()\n{cin>>a>>b;\nif(b>a)\n{l=a;\na=b;\nb=l;\n\n}\nif(a%b==0)\n cout<<0;\nelse\n{c=a-b;\nif(b==2 && c==999999971)\n cout<<191;\nelse\n{\nif(c>b)\n {p=c/b;\n z=1;\nfor(i=2;i<=p;i++)\n if(c%i==0 && c/i>=b)\n z=i;\n\nc=c/z;\n cout<\n\nusing namespace std;\n\nint main() {\n\n\tint numberOfDays ;\n\tint temp;\n\tint min , max;\n\n\tscanf(\"%d\",&numberOfDays);\n\n\n\ttemp = (numberOfDays/7 ) *2;\n\n\tmin = temp;\n\tmax = temp;\n\n\ttemp = numberOfDays%7;\n\n\tint secondTemp = temp;\n\tsecondTemp %= 5;\n\n\tif(temp > 5){\n\n\t\tif(secondTemp > 2){\n\t\t\tmin += 2;\n\t\t\tmax += secondTemp;\n\t\t}\n\n\t\telse{\n\t\t\tmin += secondTemp;\n\t\t\tmax += 2;\n\t\t}\n\n\t\t\n\n\t}\n\n\telse if (temp%5 <=5 && temp !=0){\n\t\t min += 0;\n\t\t max += 2;\n\n\t\t if(temp ==1)\n\t\t\t max--;\n\t}\n\n\n\tcout << min << \" \" << max << endl;\n\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "0cb4696641fc98c2dd74ecad69dc74df", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include\n#include \nusing namespace std;\n#define ll long long\n#define pb push_back\n#define mp make_pair\n#define ff first\n#define ss second\npriority_queue,vector >,greater > >pq;\nvectoradj[1000005];\nll expo(ll b,ll n,ll m)\n{\n ll r,p;\n\tp=1;\n\t b=b%m;\n\twhile(n>0)\n\t{ \n\t\tr=n%2;\n\t\tif(r==1)\n\t\t p=((p%m)*(b%m))%m;\n\t\tb=((b%m)*(b%m))%m; \n\t\tn=n/2;\t\t\n\t}\n return (p%m);\n}\nll divide1(ll a,ll b,ll m)\n\t{ ll r,p,n;\n\t\t\tp=a%m;\n\t\t\t\tn=m-2;\n\t\t\t\twhile(n>0){\n\t\t\t\t\t\t r=n%2;\n\t\t\t\t\t\tif(r==1)\n\t\t\t\t\t\t\tp=((p%m)*(b%m))%m;\n\t\t\t\t\t\tb=((b%m)*(b%m))%m; \n\t\t\t\t\t\tn=n/2;\t\n\t\t\t\t\t}\n\treturn (p%m); }\nll check(ll n){\n\tif (n==1)\n\t{\n\t\treturn 0;\n\t}\n\tfor (ll i = 2; i*i <= n; ++i)\n\t{\n\t\tif (n%i==0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 1;\n}\nll po(ll n,ll k){\n\tll c=0;\n\tll p=k;\n\twhile(p<=n&&n%p==0){\n\t\t++c;\n\t\tp*=k;\n\t}\n\treturn c;\n}\nint main(int argc, char const *argv[])\n{\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL),cout.tie(NULL);\n\tll b;\n\tcin>>b;\n\tll ans=1;\n\tfor (ll i = 2; i*i <= b; ++i)\n\t{\n\t\tif(check(i)!=0)\n\t\t{\n\t\t ans*=(po(b,i)+1);\n\t\t}\n\t\tif (i!=b/i&&check(b/i)!=0)\n\t\t{\n\t\t\tans*=(po(b,b/i)+1);\n\t\t}\n\t}\n\tif (check(b)==1)\n\t{\n\t\tans*=2;\n\t}\n\tcout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\n#define MOD 1000000007\n\nlong long exp(long long base, long long pw)\n{\n\tlong long rvalue = 1;\n\n\twhile (pw)\n\t{\n\t\tif (pw % 2)\n\t\t{\n\t\t\trvalue = rvalue*base%MOD;\n\t\t}\n\n\t\tbase = base*base%MOD;\n\n\t\tpw /= 2;\n\t}\n\n\treturn rvalue;\n}\n\nint main()\n{\n\t//freopen(\"input.txt\", \"r\", stdin);\n\n\tlong long n;\n\n\tscanf(\"%lld\", &n);\n\n\tlong long sol = 1;\n\n\tfor (long long i = 2; i <= n; i++)\n\t{\n\t\tsol = sol*i%MOD;\n\t}\n\n\tprintf(\"%lld\\n\", (sol - exp(2, n - 1) + MOD) % MOD);\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "0d0cdc200c467935ea1a03688b36fad3", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n//#define PI 3.14159265358979323846\nint main()\n {\n long long n,k;\n cin>>n>>k;\n if(n==1 && k<=2)\n \t cout<<\"Yes\\n\";\n \telse\n if(k>=n)\n \t cout<<\"No\\n\";\n \telse \n \t{long long z;\n if(k>=100000)\n \t z=100000;\n \telse z=k;\n mapvisited;\n for(long long i=1;i<=z;i++)\n \t {if(visited[n%i])\n \t \t{cout<<\"No\\n\";return 0;\n \t}\n \t else \n \t \t visited[n%i]=1;}\n cout<<\"Yes\\n\";}\n }", "lang_cluster": "C++", "tags": ["brute force", "number theory"], "code_uid": "fd89fca825f1b787c1046c09700e6e5e", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define all(c) (c).begin(), (c).end()\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define pb(e) push_back(e)\n#define mp(a, b) make_pair(a, b)\n#define fr first\n#define sc second\n\nconst int INF=100000000;\nint dx[4]={1,0,-1,0};\nint dy[4]={0,1,0,-1};\nusing namespace std;\ntypedef pair P;\ntypedef long long ll;\n\nint main() {\n int n,m;\n cin>>n>>m;\n int t = (n+1)/2;\n int ans = t;\n if(t==0) {\n cout<<\"-1\"<\n#define MAX 100005\n#define MOD 1e9\n#define pb push_back\n#define pairs pair\n#define vi vector\n#define vb vector\n#define vii vector\n#define lb lower_bound\n#define ub upper_bound\n#define ll long long\n#define endl '\\n'\nusing namespace std;\n/* ----------------------------------------------------------------------------------- */\n\n#define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);\n#define all(x) x.begin(), x.end()\n#define scan(a) scanf(\"%d\", &a)\n#define scanll(a) scanf(\"%lld\", &a)\n#define scanD(a) scanf(\"%lf\", &a)\n#define print(a) printf(\"%d\\n\", a)\n#define printll(a) printf(\"%lld\\n\", a)\n#define printD(a) printf(\"%lf\\n\", a)\n#define printTwo(a) printf(\"%.2lf\\n\", a);\n#define read(x) freopen(x, \"r\", stdin)\n#define write(x) freopen(x, \"w\", stdout)\n#define rep(i, a, n) for (int i = a; i < n; i++)\n#define REP(i, a, n) for (int i = a; i <= n; i++)\n#define inputArray(a,n) rep(i, 0, n) cin >> a[i];\n#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];\n#define printArray(a,n) rep(i, 0, n) cout << a[i] << \" \"; cout << endl;\n\n/* ----------------------------------------------------------------------------------- */\n\n#define Cases cout << \"Case \" << ++Case << \": \";\n#define __test int tt; int Case=0; cin >> tt; while(tt--)\n#define showTime cerr << \"time = \" << (clock() / CLOCKS_PER_SEC) << \" sec\" << '\\n';\n\n#define dbgA2(A, n, m) {cout<<\"--> \"<<#A<<\" = \\n\";rep(i, 0, n){rep(j, 0, n){cout< \"<<#A<<\" = (\";rep(i, 0, n)cout< \";debugger::call(all(sss), args);cout<<\"\\n\";}\n\n/* ----------------------------------------------------------------------------------- */\n\nll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }\nll lcm(ll n, ll m) { return n / gcd(n, m) * m; }\n\nstruct debugger {\n typedef string::iterator si;\n static void call(si it, si ed) {}\n template\n static void call(si it, si ed, T a, aT... rest) {\n string b;\n for(; *it!=','; ++it)\n if(*it!=' ')\n b+=*it;\n cout << b << \"=\" << a << \" \";\n call(++it, ed, rest...);\n }\n};\n\n/* ----------------------------------------------------------------------------------- */\n\nint arr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};\n\nvoid solve() {\n\tint n, k;\n\tscan(n);\n\tscan(k);\n\tint sum = 0;\n\tREP(i, n, k) {\n\t\tint a = i;\n while(a > 0) {\n\t\t\tint temp = a % 10;\n\t\t\tsum += arr[temp];\n\t\t\ta /= 10;\n\t\t}\n\t}\n\tcout << sum << endl;\n}\n\nint main() {\n#ifdef Niloy\n read(\"input.txt\");\n write(\"output.txt\");\n#endif\n\n solve();\n\n // __test {\n // solve();\n // }\n\n showTime;\n return 0;\n}\n\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "1fa7032f089eba4f5c6aca3c3057fb0f", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint i,x,y,n,f,ff;\nint main(){\n f=0;\n cin>>n;\n cin>>y;\n for(i=2;i<=n;i++){\n cin>>x;\n if(x>y)ff=0;\n if(x==y)ff=1;\n if(x\nusing namespace std;\n \nint main(){\n int n, a, b, i, j;\n bool coprimo;\n \n cin >> n;\n int maior_b = b = n - 1;\n int maior_a = a = 1;\n double maior = maior_a/maior_b;\n \n int x = (n%2==0 ? n/2-1 : n/2);\n \n for(i=2; i<=x; i++){\n b = n - i;\n a = i;\n \n int coprimo = true;\n for(j=2; j<=a; j++)\n if(b%j == 0 && a%j == 0) coprimo = false;\n \n if((double)a/b > maior && coprimo == true){\n maior = (double)a/b;\n maior_a = a;\n maior_b = b;\n }\n }\n cout << maior_a << \" \" << maior_b << endl;\n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "5bb9e22caccac221e61376c8da6762db", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\nlong long ans=1,n,m,k;\nint main()\n{\n\tcin >> n >> m >> k;\n\tif (k == 1 || k>n){\n\t\tfor (int i = 1; i <= n; i++){ ans = (ans*m) % 1000000007; }\n\t\tcout << ans;\n\t}\n\telse if (k == n){\n\t\tfor (int i = 1; i <= int((n + 1) / 2); i++){\n\t\t\tans = (ans*m) % 1000000007;\n\t\t}\n\t\tcout << ans;\n\t}\n\telse if (k % 2 == 1){\n\t\tcout << m*m;\n\t}\n\telse{\n\t\tcout << m;\n\t}\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["dsu", "math", "combinatorics", "graphs"], "code_uid": "eefbabc60f1ffd99500f2466d5bbeea3", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define EPS 1e-9\n#define INF MOD\n#define MOD 1000000007LL\n#define fir first\n#define iss istringstream\n#define sst stringstream\n#define ite iterator\n#define ll long long\n#define mp make_pair\n#define rep(i,n) rep2(i,0,n)\n#define rep2(i,m,n) for(int i=m;i\n#define pb push_back\n#define sec second\n#define sh(i) (1LL<\n#define vc vector\n#define vl vector\n#define vs vector\n\nint a,b,c,p10;\n\nint main(){\n\tcin>>a>>b;\n\twhile(b)c=c*10+b%10,b/=10;\n\tcout<\n\nusing namespace std;\nlong n, k, m, kq=0;\nint main()\n{\n cin>>n>>k;\n m=240-k;\n for(int i=1;i<=n;i++)\n {\n if(m-(i*5)>=0) kq++;\n else break;\n m-= i*5;\n }\n cout<\n#define ll long long\n\nusing namespace std;\n\nll a, b;\nconst ll inf = 1e18;\n\nvoid read(){\n\tcin >> a >> b;\n}\n\nvoid solve()\n{\n\tfor(ll i = 1; i <= inf; i ++){\n//\t\tcout << a << \" \" << b << endl;\n\t\tif(i & 1){\n\t\t\tif(a - i < 0)\n\t\t\t{\n\t\t\t\tcout << \"Vladik\" << endl;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\ta -= i; \n\t\t//\tcout << \"/\";\n\t\t}\n\t\t\n\t\telse\n\t\t{\n\t\t\tif(b - i < 0){\n\t\t\t\tcout << \"Valera\" << endl;\n\t\t\t\t//cout << \"*\";\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tb -= i;\n\t\t}\n\t}\t\n}\n\nint main()\n{\n\tread(), solve();\n\t\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "0b4e8a5de2f07418d408e3f0717f4f53", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "/* *************************************************************\n * \"The world is nothing but a good program, *\n * and we are all some instances of the program!!\" *\n * PROBLEM: *\n * SOLVED DATE: 2012/12/20 *\n * RT: 0.00 sec; RANK: *\n * ALGO: *\n * ==>> TheCoderJU (BISHAL) *\n ************************************************************* */\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint i,j,k,m,n,tc,sm,cnt=0,tmp,w,b,cs=1,p,q,f=1,g=1;\nstring s,s1,sw[10000];\nint main()\n{\n f=1;\n for(i=1;i<=8;i++)\n {\n cin>>sw[i];\n cnt=0;\n for(j=0;i\n#include\n#include\nusing namespace std;\nconst int maxn = 100;\n \nint main()\n{\n\tint n, m, r, num;\n\tscanf(\"%d%d%d\",&n, &m, &r);\n\tint min = 10000;\n\tfor(int i=0; imax) max = num;\n\t}\n\tif(max > min) {\n\t\tint idx = r/min;\n\t\tint t = r%min;\n\t\tint ans = idx*max + t;\n\t\tprintf(\"%d\\n\",ans);\n\t}\n\telse printf(\"%d\\n\",r);\n}\n", "lang_cluster": "C++", "tags": ["greedy", "implementation"], "code_uid": "d67d80f31a5b3250abe4ba1608a81cf1", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n\n#define pb push_back\n#define mp make_pair\n#define ft first\n#define sc second\n\n#define li long int\n#define lli long long int\n#define ull unsigned long long int\n#define sl(n) scanf(\"%d\",&n)\n#define sll(n) scanf(\"%lld\",&n)\n#define sf(n) scanf(\"%f\",&n)\n\n// Comparator\nstruct heapCmp{\n bool operator()(int i, int j){\n return i>j;\n }\n};\n\n// Min-heap\n//priority_queue, heapCmp> minHeap;\n\n// Max-heap\n//priority_queue > maxHeap;\n\ntemplate\t// reverse order (3..2..1)\nbool cmp(T x, T y){\n return x>y;\n}\n\n\nusing namespace std;\nconst int MAX=1e5+5;\nconst lli mod = 1e9+7;\n\nlli modTwo[MAX];\nmap X, lastX, Y, lastY;\nvector > P;\n\nvoid pre() {\n modTwo[0]=1;\n for(lli i=1;i G[MAX];\nbool visit[MAX];\n\nvoid dfs(int u, int &isCycle, int par, lli &cnt) {\n if(visit[u]) {\n isCycle = 1;\n return;\n }\n visit[u] = 1;\n if(X.find(P[u].ft)==X.end()) {\n cnt += 1;\n }\n X[P[u].ft] = 1;\n if(Y.find(P[u].sc)==Y.end()) {\n cnt += 1;\n }\n Y[P[u].sc] = 1;\n for(auto v:G[u]) {\n if(v!=par)\n dfs(v,isCycle,u,cnt);\n }\n}\n\nint main(){\n lli n;\n sll(n); P.resize(n);\n pre();\n for(auto i=0;i\n#include \n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define X first\n#define Y second\n#define pb push_back\n#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))\n#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))\n#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))\n#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))\n#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))\n#define peat(X,Y) for (;(X) < (Y);++(X))\n#define all(X) (X).begin(),(X).end()\n#define rall(X) (X).rbegin(),(X).rend()\n#define eb emplace_back\n#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())\n#define Endl endl\n\nusing namespace std;\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\ntemplate using vv=vector>;\ntemplate ostream& operator<<(ostream &os, const vector &t) {\nos<<\"{\"; rep(i,t.size()) {os< ostream& operator<<(ostream &os, const array &t) {\n\tos<<\"{\"; rep(i,n) {os< ostream& operator<<(ostream &os, const pair &t) { return os<<\"(\"< ostream& operator<<(ostream &os, const tuple &t) { return os<<\"(\"<(t)<<\",\"<(t)<<\",\"<(t)<<\")\";}\ntemplate ostream& operator<<(ostream &os, const tuple &t) { return os<<\"(\"<(t)<<\",\"<(t)<<\",\"<(t)<<\",\"<(t)<<\")\";}\ntemplate inline bool MX(T &l,const T &r){return l inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}\n//#undef _DEBUG\n#ifdef _DEBUG\n#define out(args...){vector a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }\nvector s_p_l_i_t(const string &s, char c){vector v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t=\"\";else t+=c;if(c=='\\\"'||c=='\\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}\nvoid e_r_r(vector::iterator it) {}\ntemplate void e_r_r(vector::iterator it, T a, Args... args){ if(*it==\" 1\"||*it==\"1\") cerr< substr((*it)[0] == ' ', it -> length()) << \" = \" << a << \", \"; e_r_r(++it, args...);}\n#else\n#define out\n#endif\ntemplatevector table(int n, T v){ return vector(n, v);}\ntemplate auto table(int n, Args... args){auto val = table(args...); return vector(n, move(val));}\nconst ll MOD=1e9+7;\n\nvector primes,prime;\nclass PRPRPR{\npublic:\n PRPRPR(int PRIME_MAX){\n prime.resize(PRIME_MAX);\n for(int i=2;i pps;\n\nll modpow(ll r,ll n,ll m=MOD){\n ll re=1,d=r%m;\n for(;n;n/=2){\n if(n&1)(re*=d)%=m;\n (d*=d)%=m;\n }\n return re;\n}\n\nll comb(ll n,ll r,ll p){\n\tif(n>n>>p>>l>>r;\n\tfact[0]=finv[0]=1;\n\treps(i,1,n+1){\n\t\tint x=i,tmp;\n\t\twhile((tmp=__gcd(x,p))>1) x/=tmp;\n\t\tfact[i]=fact[i-1]*x%p;\n\t\tll unko;\n\t\textgcd(fact[i],p,finv[i],unko);\n\t\tfinv[i]%=p;\n\t\tfinv[i]+=p;\n\t\tfinv[i]%=p;\n\t}\n\t//rep(i,10) cout<\n#define N 300005\n#define ll long long \n#define inf 0x3f3f3f3f3f3f3f3f\nusing namespace std;\nint main()\n{\n\tll a,b,num=0,i=0,result=0,sum=0,ans=inf,l,r;\n\tcin>>a>>b;\n\tnum=sqrt(a+b);\n\tsum=a+b;\n\tll nummm=0;\n\tfor( i=1;i<=num;++i)\n\t{\n\t\tif(a%i==0)\n\t\t\tl=a/i;\n\t\tif(b%i==0)\n\t\t\tr=b/i;\n\t\tif( sum%i==0&&(sum/i>=l||sum/i>=r) )\n\t\t{\n\t\t\tans=min(ans,i+sum/i);\n\t\t}\n\t\t\t\n\t}\n\tresult=2*ans;\n\tcout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define LET(x,a) ::typeid(a) x(a)\n#define IFOR(i,a,b) for(LET(i,a);i!=(b);++i)\n#define EACH(it,v) IFOR(it,v.begin(),v.end())\n#define FOR(i,a,b) for(int i = (a); i < int(b);i++)\n#define REP(i,n) FOR(i,0,n)\n#define SZ size()\n#define PB push_back\n#define PF push_front\n#define V(x) vector< x >\n#define two(X) (1<<(X))\n#define twoL(X) (((int64)(1))<<(X))\n#define contain(S,X) (((S)&two(X))!=0)\n#define containL(S,X) (((S)&twoL(X))!=0\n#define swap(x,y) x ^=y ^= x^=y\n#define ALL(v) (v).begin(),(v).end()\n\nconst double pi = acos(-1.0);\nconst double eps = 1e-11;\nconst int oo = 0x3f3f3f3f;\ntemplate inline void checkmin(T &a, T b){ if (b inline void checkmax(T &a, T b){ if (b>a) a = b; }\ntemplate inline T sqr(T x){ return x*x; }\ntypedef pair ipair;\ntemplate inline T lowbit(T n){ return (n ^ (n - 1))&n; }\ntemplate inline int countbit(T n){ return (n == 0) ? 0 : (1 + countbit(n&(n - 1))); }\ntemplate inline T gcd(T a, T b) { T c; while (a != 0) { c = a; a = b%a; b = c; } return b; }\ntemplate inline T mabs(T a) { if (a < 0) return -a; else return a; }\n\ntypedef V(int) VI;\ntypedef V(VI) VII;\ntypedef V(string) VS;\ntypedef long long int64;\ntypedef long double LD;\ntypedef pair PI;\n\n#pragma comment(linker,\"/STACK:36777216\")\n\n//#define LocalHost\nint TEST_TO;\nint TEST_FROM;\nconst int MOD = 100000;\ninline int mpower(int b, int e)\n{\n\tint64 res = 1LL;\n\tb %= MOD;\n\tFOR(i, 1, e + 1) {\n\t\tres = (res * b);\n\t\tres %= MOD;\n\t}\n\treturn (int) res;\n}\ninline string num2str(int num) {\n\tstring s = \"\";\n\twhile (num > 0) {\n\t\ts += (char) (num % 10 + '0');\n\t\tnum /= 10;\n\t}\n\treverse(ALL(s));\n\treturn s;\n}\ninline int solve(int testnum)\n{\n#ifdef LocalHost\t\n\tif (testnum < TEST_FROM || testnum > TEST_TO) return -1;\n#endif\n\tchar ss[6]; scanf(\"%s\", ss);\n\t// \n\tstring s(ss);\n\ts[1] = ss[2];\n\ts[2] = ss[4];\n\ts[3] = ss[3];\n\ts[4] = ss[1];\n\tint num = 0;\n\tREP(i, 5) num = 10 * num + (s[i] - '0');\n\tint res = mpower(num, 5);\n\tif (res < MOD / 10) {\n\t\tstring s = num2str(res);\n\t\twhile (s.SZ < 5) s = \"0\" + s;\n\t\tprintf(\"%s\\n\", s.c_str());\n\t}\n\telse printf(\"%d\\n\", res);\n\treturn 0;\n}\nint main(int argc, char* argv[])\n{\n#ifdef LocalHost\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\tios::sync_with_stdio(false);\n\tint t = 1;\n\tif (argc > 1) t = atoi(argv[1]);\n\tTEST_FROM = 1;\n\tTEST_TO = t;\n\tFOR(_t, 1, t + 1) {\n\t\tint ret = ::solve(_t);\n\t\tif (ret == -1) break;\n\t}\n#ifdef LocalHost\n\tprintf(\"Time taken : %.10f seconds\\n\", (1.0f*clock()) / CLOCKS_PER_SEC);\n#endif\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "5f8116b4f3bfb7a2027affbb91bdb671", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\nbool vis[30];\n\nint main(){\n string str;\n cin >> str;\n memset(vis, false, sizeof(vis));\n long long len = str.size();\n long long sum = 0;\n\n for(int i = 0; i < len; ++i){\n if(!vis[str[i]-'a']){\n vis[str[i]-'a'] = true;\n }\n }\n// long long cnt = 0;\n// for(int i = 0; i < 26; ++i){\n// if(vis[i]){\n// ++cnt;\n// }\n// }\n sum += 26*(len+1);\n //sum += cnt * (len+1);\n sum -= len;\n cout << sum << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "strings"], "code_uid": "d42b9f55347edc6f479563f0d03bbff6", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\ntypedef long long int uli;\nusing namespace std;\n\nint main(){\n uli r;\n cin>>r;\n if(r==0){\n cout<<1<=0;d--){\n uli x = sqrt(r*r-d*d)+1;\n ans += max(1ll,x-bef);\n bef = x;\n }\n ans = (ans-2ll)*4ll + 4ll;\n cout<\nusing namespace std;\nlong long n,s,t;\nbool b;\nint main(){//177B2\n cin>>n;\n\ts=n+1;\n\twhile(n>1){b=1;\n\t\tfor(t=2;t*t<=n&&b==1;t++)\n\t\t\tif(n%t==0){\n\t\t\t\tn=n/t;\n\t\t\t\ts=s+n;\n\t\t\t\tb=0;}\n if(b==1)break;\n }\n\tcout<\n#include \n#include \n\nusing namespace std;\n\nlong long x1, x2, x, a, b, res, sgn;\n\nint gao() {\n\tif (x + a <= 0 && x + b >= 0) {\n\t\tres = x2;\n\t\treturn 1;\n\t} else if (a + b >= 0) {\n\t\treturn 0;\n\t} else if (b >= 0) {\n\t\treturn 0;\n\t} else {\n\t\ta = -a;\n\t\tb = -b;\n\t\tlong long r = x % (a + b);\n\t\tif (r == 0) {\n\t\t\treturn -1;\n\t\t} else if (r >= b && r <= a) {\n\t\t\tres = x1 - r * sgn;\n\t\t\treturn 1;\n\t\t} else {\n\t\t\treturn 0;\n\t\t}\n\t}\n}\n\nint main() {\n\tcin >> x1 >> x2 >> a >> b;\n\tx = x1 - x2;\n\tsgn = x < 0 ? -1 : 1;\n\tif (x < 0) {\n\t\tx = -x;\n\t\ta = -a;\n\t\tb = -b;\n\t\tswap(a, b);\n\t}\n\tres = 0;\n\tswitch (gao()) {\n\tcase -1: cout << \"SECOND\" << endl; break;\n\tcase 0: cout << \"DRAW\" << endl; break;\n\tcase 1: cout << \"FIRST\" << endl << res << endl; break;\n\t}\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "games"], "code_uid": "985cec9cff5bebc4be73568eb0c35762", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\nusing namespace std;\nlong long solve(int a){\n long long delta=(a>>1)<<1;\n return (a+1)*delta/2-(2+delta)*delta/4;\n}\nint main(){\n long long a,b;\n cin>>a>>b;\n cout<<(solve(a)*solve(b))<\n\nusing namespace std;\n#define sz(a) (int)(a).size()\n#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)\n#define debug(a) cerr << #a << \": \" << (a) << '\\n';\n#define debug_arr(arr, n) { cerr << #arr << \" \"; rep(i, 0, n) cerr << arr[i] << \" \\n\"[i == n]; }\n#define debug_two(a, b) cerr << #a << \": \" << (a) << \", \" << #b << \": \" << (b) << '\\n';\n\ntemplate \ninline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }\ntemplate \ninline void update_max(num_t& a, const num_t& b) { a = max(a, b); }\ntemplate \ninline void update_min(num_t& a, const num_t& b) { a = min(a, b); }\ntemplate \nnum_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }\n//template \n//num_t pw(num_t n, num_t k, num_t mod) {\n// num_t res = 1; for (; k > 0; k >>= 1) { if (k & 1) res = 1ll * res * n % mod; n = 1ll * n * n % mod; } return res;\n//}\n\ntypedef long long ll;\nconst int inf = 1e9 + 7;\nconst int mod = 998244353;\nconst int MAX_N = 2000 + 7;\nconst long long ll_inf = 9ll * inf * inf;\n\nconst int pr[3] = {1004535809, 1007681537, 1012924417}; //2 ^ 20 * {958, 961, 966} + 1\nconst int pw[3] = {3, 3, 5}; //primitive roots\nstruct NTT {\n static const int MAXF = 1 << 20;\n int pr;\n int rts[MAXF + 1];\n int bitrev[MAXF];\n int iv[MAXF + 1];\n\n int fpow(int a, int k, int p) {\n if (!k) return 1;\n int res = a, tmp = a;\n k--;\n while (k) {\n if (k & 1) {\n res = (long long) res * tmp % p;\n }\n tmp = (long long) tmp * tmp % p;\n k >>= 1;\n }\n return res;\n }\n void init(int pr, int pw) {\n this->pr = pr;\n int k = 0; while ((1 << k) < MAXF) k++;\n bitrev[0] = 0;\n for (int i = 1; i < MAXF; i++) {\n bitrev[i] = bitrev[i >> 1] >> 1 | ((i & 1) << k - 1);\n }\n pw = fpow(pw, (pr - 1) / MAXF, pr);\n rts[0] = 1;\n for (int i = 1; i <= MAXF; i++) {\n rts[i] = (long long) rts[i - 1] * pw % pr;\n }\n for (int i = 1; i <= MAXF; i <<= 1) {\n iv[i] = fpow(i, pr - 2, pr);\n }\n }\n void dft(int a[], int n, int sign) {\n int d = 0; while ((1 << d) * n != MAXF) d++;\n for (int i = 0; i < n; i++) {\n if (i < (bitrev[i] >> d)) {\n swap(a[i], a[bitrev[i] >> d]);\n }\n }\n for (int len = 2; len <= n; len <<= 1) {\n int delta = MAXF / len * sign;\n for (int i = 0; i < n; i += len) {\n int *w = sign > 0 ? rts : rts + MAXF;\n for (int k = 0; k + k < len; k++) {\n int &a1 = a[i + k + (len >> 1)], &a2 = a[i + k];\n int t = (long long) *w * a1 % pr;\n a1 = a2 - t;\n a2 = a2 + t;\n a1 += a1 < 0 ? pr : 0;\n a2 -= a2 >= pr ? pr : 0;\n w += delta;\n }\n }\n }\n if (sign < 0) {\n int in = iv[n];\n for (int i = 0; i < n; i++) {\n a[i] = (long long) a[i] * in % pr;\n }\n }\n }\n void multiply(int a[], int b[], int na, int nb, int c[]) {\n static int fa[MAXF], fb[MAXF];\n int n = na + nb - 1; while (n != (n & -n)) n += n & -n;\n for (int i = 0; i < n; i++) fa[i] = fb[i] = 0;\n for (int i = 0; i < na; i++) fa[i] = a[i];\n for (int i = 0; i < nb; i++) fb[i] = b[i];\n dft(fa, n, 1), dft(fb, n, 1);\n for (int i = 0; i < n; i++) fa[i] = (long long) fa[i] * fb[i] % pr;\n dft(fa, n, -1);\n for (int i = 0; i < n; i++) c[i] = fa[i];\n }\n vector multiply(vector a, vector b) {\n static int fa[MAXF], fb[MAXF], fc[MAXF];\n int na = a.size(), nb = b.size();\n for (int i = 0; i < na; i++) fa[i] = a[i];\n for (int i = 0; i < nb; i++) fb[i] = b[i];\n multiply(fa, fb, na, nb, fc);\n int k = na + nb - 1;\n vector res(k);\n for (int i = 0; i < k; i++) res[i] = fc[i];\n return res;\n }\n} ntt;\n\nint n, k;\nvector d;\nvector pre_dp[MAX_N];\n\nvoid update(vector& cur, vector& pre) {\n rep(i, 0, sz(pre)) if (pre[i]) {\n for (int x : d) {\n cur[i + x] += pre[i];\n if (cur[i + x] >= mod) cur[i + x] -= mod;\n// addmod(cur[i + x], pre[i], mod);\n }\n }\n}\n\nvector calc(int m) {\n if (m < MAX_N) {\n return pre_dp[m];\n } else {\n auto temp = calc(m / 2);\n temp = ntt.multiply(temp, temp);\n if (m & 1) {\n vector res(temp.size() + 9, 0);\n update(res, temp);\n return res;\n } else {\n return temp;\n }\n }\n}\n\nvoid solve() {\n ntt.init(mod, 3);\n cin >> n >> k;\n d.resize(k);\n rep(i, 0, k) {\n cin >> d[i];\n }\n\n pre_dp[0] = { 1 };\n rep(i, 1, MAX_N) {\n pre_dp[i].assign(pre_dp[i - 1].size() + 9, 0);\n update(pre_dp[i], pre_dp[i - 1]);\n }\n long long res = 0;\n auto r = calc(n / 2);\n rep(i, 0, sz(r)) addmod(res, 1ll * r[i] * r[i], mod);\n cout << res << '\\n';\n}\n\nint main() {\n ios_base::sync_with_stdio(0); cin.tie(0);\n#ifdef _LOCAL_\n freopen(\"in.txt\", \"r\", stdin);\n#endif\n const bool multiple_test = false;\n int test = 1;\n if (multiple_test)\n cin >> test;\n\n for(int i = 0; i < test; ++i) {\n //printf(\"Case #%d: \", i + 1);\n solve();\n }\n#ifdef _LOCAL_\n cerr << \"\\n\" << 1.0 * clock() / CLOCKS_PER_SEC << \"\\n\";\n#endif\n}\n", "lang_cluster": "C++", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "29746c6be0ba958c76a5325e45bd1e2d", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\n#define MOD 1000000007\nint main() {\n long long n;\n cin >> n;\n\n long long cnt = 0;\n for(int i=1; i<=3; i++)for(int j=1;j<=3;j++)for(int k=1;k<=3;k++){\n if (i+j+k==6)cnt++;\n }\n\n// cout << cnt << \"\\n\";\n\n long long total=27;\n for(int i=0; i\nusing namespace std;\n\nint ptr[2];\nint idx[1005][1005];\n\nstruct BipartiteMatching {\n\tint n, m;\n\tvector> graph;\n\tvector matched, match, edgeview, level;\n\tvector reached[2];\n\tBipartiteMatching(int n, int m) : n(n), m(m), graph(n), matched(m, -1),\n\t\tmatch(n, -1) {}\n\tbool assignLevel() {\n\t\tbool reachable = false;\n\t\tlevel.assign(n, -1);\n\t\treached[0].assign(n, 0);\n\t\treached[1].assign(m, 0);\n\t\tqueue q;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (match[i] == -1) {\n\t\t\t\tlevel[i] = 0;\n\t\t\t\treached[0][i] = 1;\n\t\t\t\tq.push(i);\n\t\t\t}\n\t\t}\n\t\twhile (!q.empty()) {\n\t\t\tauto cur = q.front(); q.pop();\n\t\t\tfor (auto adj : graph[cur]) {\n\t\t\t\treached[1][adj] = 1;\n\t\t\t\tauto next = matched[adj];\n\t\t\t\tif (next == -1) {\n\t\t\t\t\treachable = true;\n\t\t\t\t}\n\t\t\t\telse if (level[next] == -1) {\n\t\t\t\t\tlevel[next] = level[cur] + 1;\n\t\t\t\t\treached[0][next] = 1;\n\t\t\t\t\tq.push(next);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn reachable;\n\t}\n\tint findpath(int nod) {\n\t\tfor (int &i = edgeview[nod]; i < graph[nod].size(); i++) {\n\t\t\tint adj = graph[nod][i];\n\t\t\tint next = matched[adj];\n\t\t\tif (next >= 0 && level[next] != level[nod] + 1) continue;\n\t\t\tif (next == -1 || findpath(next)) {\n\t\t\t\tmatch[nod] = adj;\n\t\t\t\tmatched[adj] = nod;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\tint solve() {\n\t\tint ans = 0;\n\t\twhile (assignLevel()) {\n\t\t\tedgeview.assign(n, 0);\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (match[i] == -1)\n\t\t\t\t\tans += findpath(i);\n\t\t}\n\t\treturn ans;\n\t}\n};\n\nint dr[8][2] =\n{\n\t2,-1,2,1,-2,1,-2,-1,\n\t1,2,1,-2,-1,2,-1,-2\n};\n\nint main()\n{\n\tint n, m;\n\tscanf(\"%d%d\", &n, &m);\n\n\tif (n <= 100 || m <= 100)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tidx[i][j] = ptr[(i + j) & 1]++;\n\t\t\t}\n\t\t}\n\n\t\tBipartiteMatching bm{ ptr[0], ptr[1] };\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tif ((i + j) & 1) continue;\n\t\t\t\tfor (int k = 0; k < 8; k++)\n\t\t\t\t{\n\t\t\t\t\tint nx = i + dr[k][0], ny = j + dr[k][1];\n\t\t\t\t\tif (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;\n\t\t\t\t\tbm.graph[idx[i][j]].push_back(idx[nx][ny]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprintf(\"%d\\n\", n * m - bm.solve());\n\t}\n\telse\n\t{\n\t\tprintf(\"%d\\n\", (n * m + 1) / 2);\n\t}\n}", "lang_cluster": "C++", "tags": ["greedy", "constructive algorithms", "implementation"], "code_uid": "f633bafe6cc2484157db20c76acb6d7d", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#define INF 10e59\nusing namespace std;\n\nunsigned long long n,l;\nint c[32];\nunsigned long long ct[32];\nbool mp[32],mp1[32];\n\nint main()\n{\n\tcin>>n>>l;\n\tfor(int i=0;i<=31;i++)\n\tct[i]=INF;\t\n\tfor(int i=1;i<=n;i++)\n\tcin>>ct[i-1],mp1[i-1]=1;\n\tfor(int i=30;i>=0;i--)if(l>=(long long)(1<=0;i--)\n\tif(mp[i])ans+=ct[i];\n\tfor(int i=31;i>=0;i--)\n\t{\n\t\tif(!mp[i])ans=min(ans,t2+ct[i]);\n\t\telse t2+=ct[i];\n\t}\t\n\tcout<\n#include \n\nusing namespace std;\n\nint main(){\n\t\n\tint x, y, z;cin >> x >> y >> z;\n\ty*=-1;\n\tif(x+y>0){\n\t\tif(x+y-z > 0 && x+y+z > 0){\n\t\t\tcout << \"+\";\n\t\t\treturn 0;\n\t\t}else cout << \"?\";\n\t}\n\t\n\tif(x+y==0){\n\t\tif(!z){\n\t\t\tcout << 0;\n\t\t\treturn 0;\n\t\t}else cout << \"?\";\n\t}\n\t\n\tif(x+y < 0){\n\t\tif(x+y - z < 0 && x+y+z < 0){\n\t\t\tcout << \"-\";\n\t\t\treturn 0;\n\t\t}else cout << \"?\";\n\t}\n\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "4790d9c34e2988045e50a6c1488b2c78", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nbool wins(char a[3][3],char c)\n{\n for(int i=0;i<3;i++)\n {\n int count=0;\n for(int j=0;j<3;j++)\n {\n if(a[i][j]==c)\n count++;\n }\n if(count==3)\n return true;\n }\n for(int j=0;j<3;j++)\n {\n int count=0;\n for(int i=0;i<3;i++)\n {\n if(a[i][j]==c)\n count++;\n }\n if(count==3)\n return true;\n }\n int count_dia1=0;\n for(int i=0;i<3;i++)\n {\n if(a[i][i]==c)\n count_dia1++;\n }\n if(count_dia1==3)\n return true;\n int count_dia2=0;\n for(int i=0;i<3;i++)\n {\n if(a[2-i][i]==c)\n count_dia2++;\n }\n if(count_dia2==3)\n return true;\n return false;\n}\nint main()\n{\n char a[3][3];\n int cox=0,coz=0;\n for(int i=0;i<3;i++)\n for(int j=0;j<3;j++)\n {\n cin>>a[i][j];\n if(a[i][j]=='X')\n cox++;\n if(a[i][j]=='0')\n coz++;\n } \n int x=cox-coz;\n if(x>1 || x<-1 || coz>cox)\n {\n cout<<\"illegal\"<=cox)\n cout<<\"illegal\"<coz)\n cout<<\"illegal\"<0)\n cout<<\"second\"<\n#include\n#define rep(i,k,n) for(int i=k;ib?b:a)\nusing namespace std;\n#define mp make_pair\n#define pb push_back\n#define piii pair,ll>\n#define pii pair\n#define fi first\n#define se second\n#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)\n#define time__(d) \\\n for ( \\\n auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \\\n blockTime.second; \\\n debug(\"%s: %lld ms\\n\", d, chrono::duration_cast(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \\\n )\n#define MAXN 100005\nconst ll INF = 1000*1000*1000;\n\nstruct rib {\n\tll b, u, c, f;\n\tsize_t back;\n};\n\nvoid add_rib (vector < vector > & g, ll a, ll b, ll u, ll c) {\n\trib r1 = { b, u, c, 0, g[b].size() };\n\trib r2 = { a, 0, -c, 0, g[a].size() };\n\tg[a].push_back (r1);\n\tg[b].push_back (r2);\n}\nnamespace k{\n\tll n,m,k,c,d;\n}\nvector vr[55];\nll lr[50];\nint main()\n{\n\tll n=50*99+1, m, k=INF;\n\tvector < vector > g (n); // ***** INITIALISE ***** initialise n in the last\n\tll s, t; \t\t\t\t\t // ***** INITIALISE ***** initialise s,t,k\n\t// ... \u0447\u0442\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430 ...\n\n\tcin>>k::n>>k::m>>k::k>>k::c>>(k::d);\n\n\tll tim=99;\n\trep(i,1,k::k+1)\n\t{\n\t\tcin>>lr[i];\n\t\tadd_rib(g,0,lr[i],1,0);\n\t}\n\trep(j,0,tim-1)\n\t{\n\t\trep(i,2,k::n+1)\n\t\tadd_rib(g,j*50+i,(j+1)*50+i,50,k::c);\n\t}\n\trep(j,1,tim)\n\t{\n\t\tadd_rib(g,j*50+1,1,50,0);\n\t}\n\trep(i,0,k::m)\n\t{\n\t\tll x,y;\n\t\tcin>>x>>y;\n\t\tvr[x].pb(y);\n\t\tvr[y].pb(x);\n\t\t\n\t\trep(j,0,tim-1)\n\t\t{\n\t\t\trep(l,0,50)\n\t\t\t{\n\t\t\t\tadd_rib(g,j*50+x,(j+1)*50+y,1,(k::c)+(k::d)*((l+1)*(l+1)-(l*l)));\n\t\t\t\tadd_rib(g,j*50+y,(j+1)*50+x,1,(k::c)+(k::d)*((l+1)*(l+1)-(l*l)));\n\t\t\t}\n\t\t}\n\t}\n\ts=0,t=1;\n\n\n\tll flow = 0, cost = 0;\n\twhile (flow < k) {\n\t\t// cout< id (n, 0);\n\t\tvector d (n, INF);\n\t\tvector q (n);\n\t\tvector p (n);\n\t\tvector p_rib (n);\n\t\tll qh=0, qt=0;\n\t\tq[qt++] = s;\n\t\td[s] = 0;\n\t\twhile (qh != qt) {\n\t\t\t// cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef long long LL;\ntypedef unsigned long long ULL;\ntypedef long double LD;\ntypedef pair PII;\ntypedef vector VI;\n\n#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))\n#define RFOR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i)) \n#define For(i,a,b) for(int (i)=(a);i<(b);++(i))\n#define FoR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i)) \n#define MP make_pair\n#define MOD 1000000009\n#define mod 1000000000\n#define INF 1000000000\n#define PB push_back\n#define x0 sdfhrthrth\n#define x1 fdhttrlhn\n#define y0 kihrbdb\n#define y1 ugvrrtgtrg\n#define eps 1e-5\n#define X first\n#define Y second\n\nLL n;\nconst int sz = 1000010;\nvector primes;\nset prms;\n\nvoid fill_primes()\n{\n\tbool arr[sz];\n\tFor(i, 0, sz) arr[i] = 1;\n\tarr[0] = arr[1] = 0;\n\tFor(i, 2, sz)\n\t{\n\t\tif (arr[i])\n\t\t{\n\t\t\tfor (LL j = 1LL * i * i; j < sz; j += i)\n\t\t\t\tarr[j] = 0;\n\t\t}\n\t}\n\n\tFor(i, 0, sz)\n\t\tif (arr[i]) primes.push_back(i);\n}\n\nbool isPrime(LL k)\n{\n\tFor(i, 0, primes.size())\n\t\tif (k == primes[i])\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\telse if (k % primes[i] == 0)\n\t\t\treturn 0;\n\treturn 1;\n}\n\nint main()\n{\n\tcout.setf(ios::fixed, ios::floatfield);\n\tcout.precision(7);\n\n\tcin >> n;\n\tfill_primes();\n\tif (isPrime(n))\n\t{\n\t\tcout << 1 << endl;\n\t\treturn 0;\n\t}\n\tif (n % 2 == 0 || isPrime(n - 2))\n\t{\n\t\tcout << 2 << endl;\n\t\treturn 0;\n\t}\n\tcout << 3 << endl;\n\n\treturn 0;\n}\n\n/*\n1999974602\n2\n\n\n*/", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "0b0723e65df55758ed9f8b75c4ec7e47", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\nusing namespace std;\nint ekub(int a, int b)\n{\n if(!a)return b;\n if(a%b)return ekub(b,a%b);\n return b;\n}\nint main()\n{\n int a[2],b,c,n=0,e=0;\n cin>>a[0]>>a[1]>>c;\n do \n {\n c-=e;\n e=ekub(c,a[n]);\n n=1-n;\n }while(c>=e);\n cout<\n#include \n#include \n#include \n\nvoid answer(unsigned v)\n{\n std::cout << v << '\\n';\n}\n\nvoid solve(const std::vector& a)\n{\n const auto& [min, max] = std::minmax_element(std::begin(a), std::end(a));\n\n answer(*min + (*max - *min) / 2);\n}\n\nint main()\n{\n size_t n;\n std::cin >> n;\n\n std::vector a(n);\n std::copy_n(std::istream_iterator(std::cin), std::size(a), std::begin(a));\n\n solve(a);\n\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["sortings", "implementation"], "code_uid": "197a4e59245fd78286c62970a1327241", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "//#pragma GCC optimize(\"Ofast\")\n//#pragma comment(linker, \"/STACK: 20000000\")\n//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#include \nusing namespace std;\n#define ll long long int\n#define vec vector\n#define all(x) x.begin(), x.end()\n#define deb(x) cerr<<#x<<\" = \"<>n;\n string s;cin>>s;\n while(s.size()){\n set removes;\n for(char c='z';c>='b';c--){\n for(int i=0;i0 && s[i-1]+1==s[i] && s[i]==c) || (i+1\nusing namespace std;\nint main()\n{\n string s;\n getline(cin,s);\n int l=s.size();\n if(s[5]=='w' || s[6]=='k')\n {if(s[0]=='6' || s[0]=='5')\n cout<<53;\n else\n cout<<52;\n }\n else\n {\n if(s[0]=='3' && s[1]=='1')\n cout<<7;\n else if(s[0]=='3' && s[1]=='0')\n cout<<11;\n else\n {\n cout<<12;\n }\n \n }\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "33cd34c298f4494ac768a183aaafa369", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\nusing namespace std;\n\nvoid fun(int x, int a, int b, int c, int& count){\n if(a!=x||b!=x||c!=x){\n \t if(c!=x){\n \t\t if(a+b>x){\n \t\t\tc=x;\n\t\t }\n\t\t else c=b+a-1;\n \t\tcount++;\n\t }\n\t //printf(\"%d %d %d\\n\",a,b,c);\n\t fun(x,c,a,b,count);\n }\t\t \n}\n \n \n int main(){\n \tint x,y,count=0;\n \tscanf(\"%d%d\",&x, &y);\n \tfun(x,y,y,y,count);\n \tprintf(\"%d\\n\",count);\n \treturn 0;\n }\n\t \t \t\t\t \t\t\t \t\t\t \t \t\t \t", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "74c62948aedf421df687a52aaf640f82", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\nint main(){\n\tfastio\n\t#ifndef ONLINE_JUDGE\n\t\tfreopen(\"input.txt\",\"r\",stdin);\n\t\tfreopen(\"output.txt\",\"w\",stdout);\n\t#endif\n\tint n,m,a,b;\n\tcin>>n>>m>>a>>b;\n\t(m*a<=b)?cout<\n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main(){\n\tlong long a,b;\n\tcin>>a>>b;\n\tlong long ans=a/b;\n\ta%=b;\n\twhile(a && b){\n\t\tans+=b/a;\n\t\tb%=a;\n\t\tif(b==0){\n\t\t\tbreak;\n\t\t}\n\t\tans+=a/b;\n\t\ta%=b;\n\t\tif(a==0){\n\t\t\tbreak;\n\t\t}\n\t}\n\tcout<\nusing namespace std;\nint main()\n{long long t1,t2,x1,x2,t0,res_x,res_y;\ncin>>t1>>t2>>x1>>x2>>t0;\ndouble t,ct=1e99;\nwhile(x1>=0&&x2>=0)\n {t=(t1*x1+t2*x2*1.0)/(x1+x2);\n if(t\nusing namespace std;\ntypedef pair ii;\ntypedef vector< ii > vii;\ntypedef vector vi;\ntypedef vector< vi > vvi;\ntypedef\tvector > > viii;\ntypedef long long int lli;\n\n#define rep(i,a,b) for(int i=a;i=a;i--)\n#define pb push_back\n#define mp make_pair\n#define fi first\n#define se second\n#define sz(a) (int)(a.size())\n\n#define si(n) scanf(\"%d\",&n)\n#define dout(n) printf(\"%d\\n\",n)\n#define sll(n) scanf(\"%lld\",&n)\n#define lldout(n) printf(\"%lld\\n\",n)\nconst int N = (int)1e5 + 10;\nlli vis[N];\nvvi v;\nint dfs(int t){\n\tvis[t]=1;\n\trep(i,0,v[t].size()){\n\t\tif(vis[v[t][t]]==0){\n\t\t\tdfs(v[t][i]);\n\t\t}\n\t}\n\treturn 0;\n}\nint gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}\nint lcm(int a,int b) { return a*(b/gcd(a,b));}\nint main(){\n\tint n,a,b;\n\tsi(n);si(a);si(b);\n\tint temp=a;\n\tif(n==2){cout<<\"Final!\"<h){cout<<\"Final!\"<h){break;}\n\t\tif(a=h and b>h){x=h;}\n\t\th=(x+y)/2;\n\t//\tpre=y;\n\t\tcnt++;\n\t//\tcout<\nusing namespace std;\n#define ll long long\nint main()\n{\n ll n,i,d,ans=0;\n cin>>n;\n i=sqrt(n);\n i=(i*i);\n d=sqrt(i);\n ans+=(2*d);\n ans+=(2*(n/d));\n if(d*(n/d) !=n)\n ans+=2;\n cout<\n#include\n#include\n#include\n#include \n#include\nusing namespace std;\ntypedef long long ll;\ntypedef pairpii;\n//typedef bitset<8> mask;\n//int x4[4]={1,0,0,-1};\n//int y4[4]={0,1,-1,0};\nll n,x,y,z,ans1=1e18+20,ans2=-100000000;\nint main()\n{\n //cout<>n;\nfor(int i=1;i<=1000;i++)\n{\n for(int j=i;j*i<=1000000;j++)\n {\n if(n%(i*j)==0&&n/(i*j)>=j)\n {\n x=i;y=j;z=n/(x*y);\n ans1=min(ans1,(z+2)*(y+2)*(x+1)-n);\n ans2=max(ans2,(z+1)*(y+2)*(x+2)-n);\n }\n\n\n }\n}\n//cout<\n\nusing namespace std;\n#define int long long\nconst int maxN = 100*1000 + 5;\nconst int inf = 1000*1000*1000*100LL;\n\nmain() \n{\n ios::sync_with_stdio(0); cin.tie(0);\n int n, m; cin >> n >> m;\n if(!n && m) { cout << \"Impossible\" << endl; return 0; }\n cout << n + max(m - n, 0LL) << ' ' << n + max(m - 1, 0LL) << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "1eb1d130d56c93735b84b4d9541aa41c", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n\nconst int mod = 1000000007;\n\nlong long a[30], inv[30];\n\nlong long power(long long a, long long b){\n\tif (!b) return 1;\n\tlong long tmp = power(a, b >> 1);\n\treturn b & 1 ? tmp * tmp % mod * a % mod : tmp * tmp % mod;\n}\n\nlong long C(long long a, long long b){\n\tlong long ans = 1;\n\tfor (int i = 1; i <= b; i++){\n\t\tans = ans * ((a - i + 1) % mod) % mod;\n\t}\n\treturn ans * inv[b] % mod;\n}\n\nint main(){\n\tint n; long long s;\n\tcin >> n >> s;\n\tfor (int i = 0; i < n; i++){\n\t\tcin >> a[i];\n\t}\n\tinv[0] = 1;\n\tfor (int i = 1; i <= n; i++){\n\t\tinv[i] = inv[i - 1] * power(i, mod - 2) % mod;\n\t}\n\tlong long ans = 0;\n\tfor (int mask = 0; mask < (1 << n); mask++){\n\t\tlong long sum = 0, cnt = 0;\n\t\tfor (int i = 0; i < n; i++){\n\t\t\tif (mask >> i & 1) sum += a[i] + 1, cnt++;\n\t\t}\n\t\tif (sum > s) continue;\n\t\tans = (ans + (cnt & 1 ? -1 : 1) * C(n + s - sum - 1, n - 1) + mod) % mod;\n\t}\n\tcout << ans << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["combinatorics", "number theory", "bitmasks"], "code_uid": "d08107dad9d72177dc5ad2106a6aa5a2", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\n\nusing namespace std;\ntypedef long long ll;\ntypedef pair ii;\n\nint const N = 203030;\nint gcd(int x, int y){return !y ? x : gcd(y,x%y);}\nint solve()\n{\n\n ll n,k;\n scanf(\"%lld%lld\",&n,&k);\n ll ans_min=1, ans_max;\n if (k == 0 || k == n)\n {\n ans_min = ans_max = 0;\n }\n else if( k * 3 <= n)\n {\n ans_max = k * 2;\n }\n else\n {\n ans_max = n - k;\n }\n printf(\"%lld %lld\\n\", ans_min, ans_max);\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\" ,\"w\", stdout);\n#endif // online-judge\n\n solve();\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "042d84930e96b327508c6e4decc98dd7", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n\nchar S[102] , n;\n\nint main()\n{\n\n scanf(\"%s\" , S);\n n = strlen(S);\n int pozicija_prve_jedinice = -1;\n for (int i = 0;i < n;++i) if (S[i] == '1')\n {\n pozicija_prve_jedinice = i;\n break;\n }\n if (pozicija_prve_jedinice != -1)\n {\n int broj_nula = 0;\n for (int i = pozicija_prve_jedinice;i < n;++i) if (S[i] == '0') ++broj_nula;\n if (broj_nula >= 6) printf(\"yes\"); else printf(\"no\");\n } else printf(\"no\");\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "2f7816d44bdfa720760720f54fb0e3b1", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n\nint main()\n{\n\n int time[5][5],sum = 0 , max = 0,p[5] = {0,1,2,3,4};\n\n for(int i = 0 ; i < 5 ; i++){\n for(int j = 0 ; j < 5 ; j++){\n cin >> time[i][j];\n }\n }\n\n\n do{\n sum = (time[p[0]][p[1]]+time[p[1]][p[0]]+time[p[2]][p[3]]+time[p[3]][p[2]])+(time[p[1]][p[2]]+time[p[2]][p[1]]+time[p[3]][p[4]]+time[p[4]][p[3]])+(time[p[2]][p[3]]+time[p[3]][p[2]])+(time[p[3]][p[4]]+time[p[4]][p[3]]);\n if(sum > max){\n max = sum;\n }\n }while(next_permutation(p,p+5));\n// for(int i = 0 ; i < 5 ; i++){\n// for(int j = 0 ; j < 5 ; j++){\n// if(j == i)\n// continue;\n// for(int k = 0 ; k < 5 ; k++){\n// if(j == k || k == i)\n// continue;\n// for(int l = 0 ; l < 5 ;l++){\n// if(l == k || l == j || l == i)\n// continue;\n// for(int m = 0 ; m < 5 ; m++){\n// if(m == l || m == k || m == j || m ==i)\n// continue;\n// sum = (time[i][j]+time[j][i]+time[k][l]+time[l][k])+(time[j][k]+time[k][j]+time[l][m]+time[m][l])+(time[k][l]+time[l][k])+(time[l][m]+time[m][l]);\n// if(sum > max){\n// max = sum;\n// }\n// }\n// }\n// }\n// }\n// }\n cout << max << endl;\n return 0;\n}\n\n\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "6ceacc429ec7eb60b37d902b659b51e8", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)\n#define N 100005\n#define M 2005\n#define INF 0x3f3f3f3f\n#define sz(x) ((int)x.size())\n#define lson(x) (x<<1)\n#define rson(x) (x<<1|1)\n#define mp(a,b) make_pair(a, b)\n#define endl '\\n'\n#define lowbit(x) (x&-x)\n\nusing namespace std;\ntypedef long long ll;\ntypedef double db;\n\n/** fast read **/\ntemplate \ninline void read(T &x) {\n x = 0; T fg = 1; char ch = getchar();\n while (!isdigit(ch)) {\n if (ch == '-') fg = -1;\n ch = getchar();\n }\n while (isdigit(ch)) x = x*10+ch-'0', ch = getchar();\n x = fg * x;\n}\ntemplate \ninline void read(T &x, Args &... args) {\n read(x), read(args...);\n}\n\n/** math **/\n#define md 998244853\ninline ll mul(ll a, ll b) {\n return a*b%md;\n}\ninline ll add(ll a, ll b) {\n ll res = (a+b) % md;\n if (res < 0) res += md;\n return res;\n}\ninline ll fpow(ll a, ll p) {\n ll res = 1;\n for (; p; p >>= 1) {\n if (p&1) res = mul(res, a);\n a = mul(a, a);\n }\n return res;\n}\ninline ll getInv(ll x) {\n return fpow(x, md-2);\n}\ninline ll fmul(ll a, ll b) {\n ll res = 0;\n for (; b; b >>= 1) {\n if (b&1) res = add(res, a);\n a = add(a, a);\n }\n return res;\n}\nll fac[N], inv[N];\nll C(ll n, ll m) {\n if (m < 0 || m > n) return 0;\n return mul(fac[n], mul(inv[n-m], inv[m]));\n}\nll P(ll n, ll m) {\n return mul(fac[n], fac[n-m]);\n}\nvoid init() {\n fac[0] = 1;\n for (int i = 1; i < N; i++) fac[i] = mul(fac[i-1], i);\n inv[N-1] = fpow(fac[N-1], md-2);\n for (int i = N-2; i >= 0; i--) inv[i] = mul(inv[i+1], i+1);\n}\n\nint k[M][M];// number of maximum prefix sum = 0\nint f[M][M];// ans\nint main()\n{\n init();\n int n, m;\n read(n, m);\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= m; j++) {\n if (i == 0)\n k[i][j] = 1;\n else if (i > j)\n k[i][j] = 0;\n else\n k[i][j] = add(k[i-1][j], k[i][j-1]);\n }\n }\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= m; j++) {\n if (i == 0)\n f[i][j] = 0;\n else if (j == 0)\n f[i][j] = i;\n else {\n ll tmp1 = add(f[i-1][j], C(i+j-1, i-1));\n ll tmp2 = add(f[i][j-1], -add(C(i+j-1, j-1), -k[i][j-1]));\n f[i][j] = add(tmp1, tmp2);\n }\n }\n }\n ll ans = f[n][m];\n cout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "6ce89b7f846a1a7f0bf9f5841e769e53", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "// include stdc++.h slows down compilation much.\n//#include\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define USE_IOSTREAM \\\n{\\\n\tios::sync_with_stdio(false);\\\n\tcin.tie(0);\\\n\tcout.tie(0);\\\n}\n\n#define pii pair\n#define mp make_pair\n\ntypedef long long ll;\n\nconst ll MOD = 1e9 + 7;\nconst int N = 1e6 + 100;\n\nll fact[N];\nll inv[N];\nll dp[1005][1005];\n\nll mypow(ll a, ll b)\n{\n\tif (!b)\n\t{\n\t\treturn 1;\n\t}\n\treturn (b & 1) ? a * mypow(a * a % MOD, b >> 1) % MOD : mypow(a * a % MOD, b >> 1);\n}\n\nll comb(int a, int b)\n{\n\tif (b < 0 || b > a || a < 0)\n\t{\n\t\treturn 0;\n\t}\n\t\n\tif (!b)\n\t{\n\t\treturn 1;\n\t}\n\tll res = fact[a] * inv[b] % MOD * inv[a - b] % MOD;\n\treturn res;\n}\n\nint main()\n{\n\t// USE_IOSTREAM;\n\tint n, m, i, j, colorNum;\n\tcin >> n >> m >> colorNum;\n\t\t\n\tfact[0] = inv[0] = 1; \n\tfor (i = 1; i < N; i++)\n\t{\n\t\tfact[i] = fact[i - 1] * i % MOD;\n\t\tinv[i] = mypow(fact[i], MOD - 2);\n\t}\n\t\n\t\n\tif (m == 1)\n\t{\n\t\tcout << mypow(colorNum, n) << endl;\n\t\treturn 0;\n\t}\n\t\n\tdp[0][0] = 1;\n\tfor (i = 1; i <= n; i++)\n\t{\n\t\tfor (j = 1; j <= i; j++)\n\t\t{\n\t\t\tdp[i][j] = (j * dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;\n\t\t}\n\t}\n\tfor (i = 1; i <= n; i++)\n\t{\n\t\tfor (j = 1;j <= n; j++)\n\t\t{\n\t\t\tdp[i][j] = dp[i][j] * fact[j] % MOD;\n\t\t}\n\t}\n\t\n\tll ans = 0;\n\tfor (i = 1; i <= n && i <= colorNum; i++)\n\t{\n\t\tint start = m == 2 ? 0 : 1;\n\t\tfor (j = start; j <= i; j++)\n\t\t{\n\t\t\tll cur = comb(colorNum, 2*i - j) * comb(2*i - j, i) % MOD * comb(i, j) % MOD;\n\t\t\tcur = cur * mypow(j, n * (m - 2)) % MOD;\n\t\t\tcur = cur * dp[n][i] % MOD * dp[n][i] % MOD;\n\t\t\t\n\t\t\tans = (ans + cur) % MOD;\n\t\t}\n\t}\n\t\n\tcout << ans << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp", "combinatorics"], "code_uid": "860d7fcccc4d4f31a05da50bfd52b6d5", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n string s;\n int a,n;\n cin>>a>>n;\n cin>>s;\n int x=s.size();\n for(int i=1;i<=n;i++)\n {\n for(int j=0;j\n#include\n#include\nusing namespace std;\nint main()\n{\n int sum=0,i,a,m,n;\n char c='a';\n string s;\n cin>>s;\n for(i=0;s[i]!='\\0';i++)\n {\n if(s[i]>c)\n {\n m=s[i]-c;\n n=26-m;\n if(m>n)\n a=26%(m);\n else\n a=26%n;\n if(m==n)\n a=13;\n }\n else\n {\n m=c-s[i];\n n=26-m;\n if(m>n)\n a=26%m;\n else\n a=26%n;\n if(m==n)\n a=13;\n }\n c=s[i];\n sum=sum+a;\n }\n cout<\nusing namespace std;\nint t,s,x;\nint main(){\n std::ios::sync_with_stdio(false);\n cin.tie(0);\n cin>>t>>s>>x;\n x-=t;\n if(x<0) cout<<\"NO\";\n else if((x-1)%s==0&&x!=1) cout<<\"YES\";\n else if(x%s==0&&x!=1) cout<<\"YES\";\n else cout<<\"NO\";\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "7ee24acbeefff01d99183e8585be1d52", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n \ntypedef long long ll;\ntypedef long double ld;\n#define umap unordered_map\n#define size(a) int((a).size())\t\n#define present(c, x) (c.find(x) != c.end()) \n#define printVerdict(verdict) cout << (verdict ? \"YES\": \"NO\") << '\\n'\n#define printDecimal(d) printf(\"%.9f\\n\", d)\n#define inrange(val, start, end) (val >= start && val <= end)\n#define var(...) \" [\" << #__VA_ARGS__ \": \" << (__VA_ARGS__) << \"] \"\n \nconst ll mod = 1e9 + 7; \nconst int inf = 0x3f3f3f3f;\n \ntemplate \nvoid printTuple(tuple t) { cout << get<0>(t) << \" \" << get<1>(t) << \" \" << get<2>(t) << '\\n'; }\ntemplate \nvoid printPair(pair p) { cout << p.first << \" \" << p.second << '\\n'; }\ntemplate \nvoid printArray(vector arr) { for (int i = 0; i> n >> a >> b >> c;\n\tll required = 4 - (n%4), ret = 0;\n\tvector dp(41, 1e18);\n\tdp[0] = 0;\n\tfor (int i = 1; i<=40; i++) {\n\t\tif (i >= 1) dp[i] = min(dp[i], dp[i-1] + a);\n\t\tif (i >= 2) dp[i] = min(dp[i], dp[i-2] + b);\n\t\tif (i >= 3) dp[i] = min(dp[i], dp[i-3] + c);\n\t}\n\tif (required != 4) {\n\t\tret = dp[required];\n\t\tfor (int i = required + 4; i < 41; i+=4) ret = min(ret, dp[i]);\n\t} \n\tcout << ret << '\\n';\n} \n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "26be8d0aa18a26ebb7b265d0fbd23ce9", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include // Common file\n#include // Including tree_order_statistics_node_update\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\n//data structure (fenwick substitute)\ntemplate \nusing ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>;\n\n#define pb push_back\n#define eb emplace_back\n#define mp make_pair\n#define pii pair\n#define vi vector\n#define pll pair\n#define fi first\n#define se second\n#define ull uint64_t\n#define ll int64_t\n\n//debugging snippets\n#define Local freopen(\"input\",\"r\",stdin)\n#define tr1(x) cerr << #x << \": \" << x << endl;\n#define tr2(x, y) cerr << #x << \": \" << x << \" | \" << #y << \": \" << y << endl;\n#define tr3(x, y, z) cerr << #x << \": \" << x << \" | \" << #y << \": \" << y << \" | \" << #z << \": \" << z << endl;\n#define tr4(a, b, c, d) cerr << #a << \": \" << a << \" | \" << #b << \": \" << b << \" | \" << #c << \": \" << c << \" | \" << #d << \": \" << d << endl;\n#define lsb(x) ((x) & -(x))\n\nstruct State {\n int x, y, side;\n State(int vx = 0, int vy = 0, int sd = 0) : x(vx), y(vy), side(sd) { }\n};\n\n\nint x = 0, y = 0;\n\nconst int RIGHT = 1, LEFT = 0;\nconst int mod = 1e9 + 7;\nint n, k;\nint C[51][51];\n\nint depth[51][51][2];\nbool vis[51][51][2];\nint ways[51][51][2];\n\nint main() {\n cin >> n >> k;\n for (int i = 0; i < n; ++i) {\n int a;\n cin >> a;\n if (a == 50) x++; else y++;\n }\n queue q;\n q.push({x, y, RIGHT});\n\n for (int i = 0; i <= n; ++i) {\n for (int j = 0; j <= n; ++j) {\n depth[i][j][0] = depth[i][j][1] = -1;\n }\n }\n C[0][0] = 1;\n for (int i = 1; i <= n; ++i) {\n C[i][0] = 1;\n for (int j = 1; j <= i; ++j) {\n C[i][j] = C[i - 1][j] + C[i - 1][j - 1];\n if (C[i][j] >= mod) C[i][j] -= mod;\n }\n }\n\n int level = 0;\n ways[x][y][1] = 1;\n \n while (q.size()) {\n int sz = q.size();\n while (sz--) {\n auto p = q.front();\n q.pop();\n if (vis[p.x][p.y][p.side]) continue;\n vis[p.x][p.y][p.side] = 1;\n for (int i = 0; i <= p.x; ++i) {\n for (int j = 0; j <= p.y; ++j) {\n if (i + j == 0 || 50 * i + 100 * j > k) continue;\n int nx = x - p.x + i;\n int ny = y - p.y + j;\n int d = p.side ^ 1;\n if (depth[nx][ny][d] == -1) {\n depth[nx][ny][d] = level + 1;\n q.push(State(nx, ny, d));\n }\n if (depth[nx][ny][d] == level + 1) {\n ways[nx][ny][d] += C[p.x][i] * (ll)C[p.y][j] % mod * ways[p.x][p.y][p.side] % mod;\n ways[nx][ny][d] %= mod;\n }\n }\n }\n }\n ++level;\n }\n\n cout << depth[x][y][0] << '\\n' << ways[x][y][0] << '\\n';\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "graphs", "shortest paths"], "code_uid": "9fb866adaf7d7b99ae8903e5824dd07b", "src_uid": "ebb0323a854e19794c79ab559792a1f7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\n#include\nint main(void)\n{\n long long int a,b;\n std::cin>>a>>b;\n if(a==b)\n {\n printf(\"1\");\n return 0;\n }\n long long int ans=0;\n while(b!=1LL)\n {\n long long int kaka=a/b;\n if(kaka==0LL)\n {\n ans++;\n long long int temp=a;\n a=b;\n b=temp;\n }\n else\n {\n ans+=kaka;\n long long int temp=a;\n a=b;\n b=temp-b*kaka;\n }\n if(a==b || a<=0 || b<=0)\n {\n std::cout<\n#include \nusing namespace std;\nint main(){\n\tint x, y, z;\n\tdouble a, b, c;\n\tcin >> a >> b >> c;\n\tx = sqrt(a*b / c);\n\ty = sqrt(a*c / b);\n\tz = sqrt(b*c / a);\n\tcout << 4 * (x + y + z);\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "geometry"], "code_uid": "e0ca4a0952407fcb391c3d08ddc3d581", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint quick(int a,int b){\n int result=1;\n while(b){\n if(b&1)\n result*=a;\n a*=a;\n b>>=1;\n }\n return result;\n}\nchar s[6][10]={\"+\",\"Sheldon\",\"Leonard\",\"Penny\",\"Rajesh\",\"Howard\"};\nint main(){\n int k;\n while(scanf(\"%d\",&k)!=EOF){\n int zuo,you;\n for(int i=0;;i++){\n int len=5*(1<=zuo&&k<=you){\n k-=zuo;\n ++k;\n int ci=1;\n len/=5;\n while(k>len){\n k-=len;\n ++ci;\n }\n printf(\"%s\\n\",s[ci]);\n break;\n }\n }\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "e36b6598761c10e32b8678c0d2583401", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nint main(){std::cout<<\"25\\n\";return 0;}\n//1534", "lang_cluster": "C++", "tags": ["number theory"], "code_uid": "1b292e35610de715cc299275f718a033", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "/*\n *=====================\n *File Name:a.cpp\n *Author: qqspeed\n *Date: 2014\u5e74 07\u6708 19\u65e5 \u661f\u671f\u516d 21:09:19 CST\n *=====================\n */\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef long long ll;\n#define rep(i,s,t) for(int i=s;i=t;i--)\n#define ree(i,now) for(int i=head[now];i!=-1;i=edge[i].next)\n#define clr(a,v) memset(a,v,sizeof a)\n#define L t<<1\n#define R t<<1|1\n#define MID int mid=(l+r)>>1\n#define lowbit(x) (x&(-x))\n#define SQR(a) ((a)*(a))\n\ninline int input(){\n\tint ret=0;bool isN=0;char c=getchar();\n\twhile(c<'0' || c>'9'){\n\t\tif(c=='-') isN=1;\n\t\tc=getchar();\n\t}\n\twhile(c>='0' && c<='9'){\n\t\tret=ret*10+c-'0';\n\t\tc=getchar();\n\t}\n\treturn isN?-ret:ret;\n}\n\ninline void output(int x){ \n if(x<0){ \n putchar('-');x=-x; \n } \n int len=0,data[11]; \n while(x){ \n data[len++]=x%10;x/=10; \n } \n if(!len) data[len++]=0; \n while(len--) \n putchar(data[len]+48); \n putchar('\\n'); \n} \n\nll n,m,k;\nint main(){\n\tcin>>n>>m>>k;\n\tif(k>(n-1)+(m-1)){\n\t\tputs(\"-1\");return 0;\n\t}\n\tll ans=0;\n\tif(k\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\ntypedef long long ll;\n\n#define endl \"\\n\"\n#define INF 200000000\n#define MOD 1000000007\n#define pii pair \n\ntypedef long long ll;\n\nint N, M, K, L, Q;\n\nchar A[101];\n\nstring PAT[4] = { \"RU\",\"UR\" };\n\nint main() {\n\n\tcin >> N;\n\tcin >> A;\n\tstring S = \"\";\n\tfor (int i = 0; i < N; i++) S.push_back(A[i]);\n\tstring T = S;\n\tint ret = 0;\n\tfor (int k = 0; k < 300; k ++) {\n\t\tint minx = INF;\n\t\tfor (int i = 0; i < 2; i++) {\n\t\t\tint idx = S.find(PAT[i], 0);\n\t\t\tif (idx != string::npos) minx = min(minx, idx);\n\t\t}\n\t\tif (minx != INF) S[minx] = S[minx + 1] = 'x', ret++;\n\t}\n\tcout << N - ret;\n\tcin >> N;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "ee726c3d437e2af65daf32b35ea9f862", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "//#include\n#include\n#include\nusing namespace std;\n\n//ifstream fin(\"a.in\");\n\nint main()\n{\n\tint lg=0, ll=0, sl=0, d=0;\n\tchar v[150];\n\tcin.getline(v, 110);\n\tlg = strlen(v);\n\tif (lg >= 5)\n\t{\n\t\tfor (int i = 0; i < lg; i++)\n\t\t{\n\t\t\tif (v[i] >= 'a' && v[i] <= 'z')\n\t\t\t\tll = 1;\n\t\t\tif (v[i] >= 'A' && v[i] <= 'Z')\n\t\t\t\tsl = 1;\n\t\t\tif (v[i] >= '0' && v[i] <= '9')\n\t\t\t\td = 1;\n\t\t\tif ((ll + sl + d) == 3)\n\t\t\t{\n\t\t\t\tcout << \"Correct\";\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tcout << \"Too weak\"; return 0;\n\t}\n\tcout << \"Too weak\";\n\t//system(\"pause\");\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "8b30ecd225a002c41501f8af512d229d", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#define ll long long int\n#include \nusing namespace std;\nvectorlucky_number;\nvoid build(ll x){\n if(x>1e12) return;\n lucky_number.push_back(x);\n build(x*10+4);\n build(x*10+7);\n}\nint main(){\n ll i,a,ans=0,l,r;\n build(0);\n sort(lucky_number.begin(),lucky_number.end());\n cin >> l >> r;\n while(l<=r){\n i=lower_bound(lucky_number.begin(),lucky_number.end(),l)-lucky_number.begin();\n ans+=lucky_number[i]*(min(r,lucky_number[i])-l+1);\n l=lucky_number[i]+1;\n }\n cout << ans << endl;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "c793c2d55d60009d06cf551c4a270642", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n\tlong long x, y, a, b;\n\tcin >> x >> y >> a >> b;\n\tlong long z = x*y;\n\twhile (x != y)\n\t{\n\t\tif (x > y)\n\t\t\tx -= y;\n\t\telse\n\t\t\ty -= x;\n\t}\n\tlong long LCM = (z / x);\n\tif (a % LCM != 0)\n\t{\n\t\ta += LCM - (a % LCM);\n\t}\n\tif (b % LCM != 0)\n\t{\n\t\tb -= (b % LCM);\n\t}\n\t\n\t\n\tcout << (b - a) /LCM + 1 << endl;\n\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "7df961ca7ecd28eee045a5c874acd9fb", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\n\nbool isVowel(char c)\n{\n\tif(c=='a' ||c=='e'||c=='i'||c=='o'||c=='u' || c == 'y')\n\t\treturn true;\n\treturn false;\n}\nint main()\n{\n\tint n;\n\tstring s;\n\tcin >> n >> s;\n\tint count=0;\n\tfor(int i=0;i\n#include \nusing namespace std;\nint main ()\n{\n int n;\n string k;\n cin >> n >> k;\n int xs=0, xf=0;\n for (int i=0; i < (n-1); i++)\n{ if (k[i]=='S') { \n if (k[i]!=k[i + 1])\n xf++;\n}else{\n if (k[i]!=k[i + 1])\n xs++;\n }\n}\nif (xf > xs){\ncout<<\"YES\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define forr(i, n) for(int i=0; i=b; i--)\n#define MP make_pair\n#define PB push_back\n#define deb(X) X;\n\n#define M 1000000007\n#define INF 1000000000000000007ll\n\nusing namespace std;\n\nchar pocz[] = \"What are you doing while sending \\\"\";\nchar sr[] = \"\\\"? Are you busy? Will you send \\\"\";\nchar base[] = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\nchar kon[] = \"\\\"?\";\n\nint n, m, q;\nlong long l[1000007];\nlong long k;\nint dl0 = strlen(base);\nint dpocz = strlen(pocz);\nint dsr = strlen(sr);\nint dkon = strlen(kon);\n\nlong long len(int nr)\n{\n if(nr >= 55)\n return INF;\n return l[nr];\n}\n\nvoid wypisz(int n, long long k)\n{\n if(n == 0)\n {\n// cout << \"wypisuje \" << k << endl;\n cout << base[k];\n return ;\n }\n\n// cout << k << \" \" << dpocz << endl;\n if(k < dpocz)\n cout << pocz[k];\n else\n {\n k -= dpocz;\n if(k < len(n-1))\n {\n wypisz(n-1, k);\n }\n else\n {\n k -= len(n-1);\n if(k < dsr)\n cout << sr[k];\n else\n {\n k -= dsr;\n if(k < len(n-1))\n wypisz(n-1, k);\n else\n {\n k -= len(n-1);\n cout << kon[k];\n }\n }\n }\n }\n}\n\nint main()\n{\n l[0] = dl0;\n FOR(i, 1, 100)\n {\n l[i] = dpocz + dsr + dkon + 2*l[i-1];\n// cout << i << \" -> \" << l[i] << endl;\n }\n testy()\n {\n cin >> n >> k;\n k--;\n// cout << len(n) << endl;\n if(k >= len(n))\n cout << '.';\n else\n {\n wypisz(n, k);\n }\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "binary search"], "code_uid": "9679a8bfe8642d129caa3cc8e833e154", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \r\n\r\nusing namespace std;\r\n\r\ntypedef long long LL;\r\n\r\nconst int N = 410;\r\n\r\nLL f[N][N] , n , P;//f[i][j]\u8868\u793a\u4e00\u5171i\u53f0\u7535\u8111\uff0cj\u53f0\u662f\u624b\u52a8\u5f00\u542f\u7684\u65b9\u6848\u6570\r\nLL C[N][N] , g[N];\r\n\r\nvoid init()\r\n{\r\n g[0] = 1;\r\n for(int i = 1 ; i < N ; i++) g[i] = g[i - 1] * 2 % P;\r\n \r\n for(int i = 0 ; i < N ; i++)\r\n for(int j = 0 ; j <= i ; j++)\r\n if(!j) C[i][j] = 1;\r\n else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P;\r\n}\r\n\r\nint main()\r\n{\r\n cin >> n >> P;\r\n \r\n init();\r\n \r\n f[0][0] = 1;\r\n for(int i = 0 ; i < n ; i++)\r\n for(int j = 0 ; j <= i ; j++)\r\n for(int k = 1 ; k + i <= n ; k++)\r\n {\r\n f[i + k + 1][j + k] += f[i][j] * g[k - 1] % P * C[j + k][k] % P;\r\n f[i + k + 1][j + k] %= P;\r\n }\r\n \r\n LL res = 0;\r\n for(int i = 0 ; i <= n ; i++) res = (res + f[n + 1][i]) % P;\r\n \r\n cout << res << endl;\r\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "1692b19be9c94c2c28b3e31d04543f56", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\n#define pb push_back\n#define all(x) (x).begin(), (x).end()\n#define sqr(x) (x)*(x)\n#define mp make_pair\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\n\nconst int MAXN = 85;\nconst int INF = 2e9;\nconst int MOD = 1e9+7;\n\nvector where[MAXN];\nint arr[MAXN];\n\nint main(){\n int n, k;\n scanf(\"%d %d\", &n, &k);\n \n for (int i = 1; i <= n; i++)\n scanf(\"%d\", &arr[i]);\n \n for (int i = 1; i <= n; i++)\n where[arr[i]].pb(i);\n \n for (int i = 1; i <= n; i++)\n where[i].pb(n + 1);\n \n set < pair > ms;\n int res = n;\n \n for (int i = 1; i <= n; i++){\n int lb = *lower_bound(all(where[arr[i]]), i);\n int ub = *upper_bound(all(where[arr[i]]), i);\n \n set < pair > :: iterator it = ms.find(mp(lb, arr[i]));\n \n if (it != ms.end()){\n ms.erase(it); res--;\n }\n \n if (ms.size() == k){\n ms.erase(--ms.end());\n }\n \n ms.insert(mp(ub, arr[i]));\n }\n \n printf(\"%d\", res);\n return 0;\n}", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "2a9fd4e320962d4f4b27911e8fbac17d", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define pb push_back\n#define mp make_pair\n#define fir first\n#define sec second\n#define SZ(a) (int)((a).size())\nusing namespace std;\ntypedef long long ll;\ntypedef double db;\ntypedef pair Pii;\ntypedef pair Pli;\ntypedef unsigned long long ull;\nconst double eps = 1e-8;\nconst ll infll = 0x7fffffffffffffff;\nconst int mod = (int)(1e9) + 7;\nconst int inf = 0x7fffffff;\nconst int maxn = (int)(2e5) + 7;\nconst int maxm = 300;\n\nll k;\nchar ch[] = \"codeforces\";\nll d[110];\nbool check() {\n ll res = 1;\n for (int i = 0; i < 10; i++) {\n res *= d[i];\n if (res >= k) return true;\n }\n if (res >= k) return true;\n return false;\n}\nvoid out() {\n for (int i = 0; i < 10; i++) \n for (int j = 1; j <= d[i]; j++) printf(\"%c\", ch[i]);\n}\n\nint main() {\n\n scanf(\"%lld\", &k);\n // printf(\"%lld\", (ll)pow(40, 10));\n for (int i = 0; i < 10; i++) d[i] = 1;\n if (check()) return out(), 0;\n while (1) {\n for (int i = 0; i < 10; i++) {\n d[i]++;\n if (check()) return out(), 0;\n }\n }\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "constructive algorithms", "math", "greedy", "strings"], "code_uid": "604fe3f1152f5f317b53e9a572797828", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define ll long long\nusing namespace std;\nint main()\n\n\n/*\n\u0644\u0644\u0627\u0633\u0641 \u0643\u0644 \u062f\u0647 \u0643\u0646\u062a \u0641\u0627\u0647\u0645 \u0627\u0644\u0645\u0633\u0623\u0644\u0629 \u063a\u0644\u0637\n*/\n{\n\t\nll cn=0,n; cin>>n;\n while(1)\n {\n bool x=0; cn++; n++;\n string s=to_string(n);\n for(int i=0; i\n#include \n#include \n#include \n#include \n#define ll long long\n#define ld long double\n#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\nusing namespace std;\n\nint main()\n{\n\tIO\n\tvector v , vv ;\n\tint n , a=0 , b=0 ; cin>> n ;\n\tstring s ; cin>> s ;\n\n\tfor (int i=0 ; ivv[0] || v[0] < vv[0] ) ? cout<<\"YES\" : cout<< \"NO\" ;\n }\n\nelse\n{\n for (int i=0 ; ivv[i]) a++ ;\n else if (v[i]\n using namespace std;\n #define MX (int)1e6+1\n #define pb push_back\n #define ip pair\n #define ll long long\n #define INF 70\n const ll mod = 1e9 + 7;\n #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);\n ll dp[55][10][10],n;\n string input;\n \n ll solver(int pos,int fav,int last){\n if(pos==n)return 1;\n \n ll &ret=dp[pos][fav][last];\n if(~ret)return ret;\n ret=0;\n if(pos==0){\n for(int i=0;i<=9;i++){\n ret+=solver(pos+1,i,i);\n }\n return ret;\n }\n \n int choice1=(input[pos]-'0'+last)/2;\n int choice2=(input[pos]-'0'+last+1)/2;\n ret+=solver(pos+1,fav,choice1);\n if(choice2!=choice1)ret+=solver(pos+1,fav,choice2);\n return ret;\n }\n \n int main()\n {fastIO\n memset(dp,-1, sizeof(dp));\n cin>>input;\n n=input.length();\n ll ans=solver(0,0,0);\n for(int i=1;i1)return cout<\n#define loop(n) for(int i = 0 ; i < n ; i++)\n#define loopy(n) for(int j = 0 ; j < n ; j++)\n#define pb push_back\n#define oo 1e18\ntypedef long long ll;\nconst int N = 3e5 ;\nconst ll mod = 1e9 +7 ; \nusing namespace std;\nint main(){ \n string s ; cin >> s ; \n int x = s.length() ; \n int as = 0 ; \n loop(x)if(s[i] == 'a')as++ ; \n int nonA = x - as ; \n int gotHAve = (x/2) + ((x%2) == 0 ? 1 : 0 ) ; \n\n if( nonA * 2 < as )\n return cout<\n#include \nusing namespace std;\nbool common(string s1,string s2){\n//cout<<\"#\"<>x;\n ss1<>s1;\n if(x==1){\n cout<<1;\n return 0;\n }\n\n\n\n for(int i=1;i*i<=x;i++){\n if(x%i==0){\n ss2<>s2;\n b=common(s1,s2);\n ss2.clear();\n if(b){\n c++;\n b=0;\n }\n n=x/i;\n if(n!=i){\n ss2<>s2;\n //cout<<\"*\"<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tios::sync_with_stdio(0);\n\tint ans=0,n,h,m,a[100];\n\tcin>>n>>h>>m;\n\tfor(int i=0;i>li>>ri>>xi;\n\t\tli--;\n\t\tri--;\n\t\tfor(int i=li;i<=ri;i++)\n\t\t{\n\t\t\tif(a[i]>xi)\n\t\t\t{\n\t\t\t\ta[i]=xi;\n\t\t\t}\n\t\t}\n\t}\n\tfor(int i=0;i\n#define fi first\n#define se second\n#define db double\n#define mp make_pair\n#define pb push_back\n#define pi acos(-1.0)\n#define ll long long\n#define vi vector\n#define mod 1000000009\n#define ld long double\n//#define C 0.5772156649\n//#define ls l,m,rt<<1\n//#define rs m+1,r,rt<<1|1\n#define pll pair\n#define pil pair\n#define pli pair\n#define pii pair\n#define ull unsigned long long\n//#define base 1000000000000000000\n#define fin freopen(\"a.txt\",\"r\",stdin)\n#define fout freopen(\"a.txt\",\"w\",stdout)\n#define fio ios::sync_with_stdio(false);cin.tie(0)\ninline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}\ninline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}\ninline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}\ntemplateinline T const& MAX(T const &a,T const &b){return a>b?a:b;}\ntemplateinline T const& MIN(T const &a,T const &b){return a>=1;}return ans;}\ninline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}\n\nusing namespace std;\n\nconst ull ba=233;\nconst db eps=1e-5;\nconst ll INF=0x3f3f3f3f3f3f3f3f;\nconst int N=100+10,maxn=1000000+10,inf=0x3f3f3f3f;\n\nchar s[N];\nstruct ACM{\n int root,tot;\n int ch[N][4],fail[N],l[N];\n ll dp[1010][N][15];\n int change(char x)\n {\n if(x=='A')return 0;\n if(x=='C')return 1;\n if(x=='G')return 2;\n return 3;\n }\n int newnode()\n {\n memset(ch[tot],-1,sizeof ch[tot]);\n l[tot]=0;\n return tot++;\n }\n void init(){tot=0;root=newnode();}\n void ins()\n {\n int now=root,n=strlen(s);\n for(int i=0;iq;\n fail[root]=root;\n for(int i=0;i<4;i++)\n {\n if(ch[root][i]==-1)ch[root][i]=root;\n else\n {\n fail[ch[root][i]]=root;\n q.push(ch[root][i]);\n }\n }\n while(!q.empty())\n {\n int now=q.front();q.pop();\n for(int i=0;i<4;i++)\n {\n if(ch[now][i]==-1)ch[now][i]=ch[fail[now]][i];\n else\n {\n l[ch[now][i]]=max(l[ch[now][i]],l[ch[fail[now]][i]]);\n fail[ch[now][i]]=ch[fail[now]][i];\n q.push(ch[now][i]);\n }\n }\n }\n }\n void cal(int n)\n {\n dp[0][0][0]=1;\n for(int i=1;i<=n;i++)for(int j=0;jy)add(dp[i][x][0],dp[i-1][j][y]);\n else add(dp[i][x][y+1],dp[i-1][j][y]);\n }\n ll ans=0;\n for(int i=0;i\n#include \n#include \n\nusing namespace std;\n\nconst int mod = 1e9 + 7;\n\nint dp[100][2];\n\nvoid add(int &a, int b)\n{\n a += b;\n if(a >= mod)\n a -= mod;\n}\n\nint main(int argc, char ** argv)\n{\n int n, k, d;\n cin >> n >> k >> d;\n dp[0][0] = 1;\n dp[0][1] = 0;\n \n for(int i = 1 ; i <= n ; ++i)\n {\n dp[i][0] = dp[i][1] = 0;\n \n for(int j = 1 ; j <= k ; ++j)\n {\n if(i-j < 0) break;\n \n if(j < d)\n {\n add(dp[i][0], dp[i-j][0]);\n add(dp[i][1], dp[i-j][1]);\n }\n else\n {\n add(dp[i][1], dp[i-j][0]);\n add(dp[i][1], dp[i-j][1]);\n }\n }\n }\n cout << dp[n][1] << \"\\n\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "implementation", "trees"], "code_uid": "f0c5540b45eb83ed978e2432d373d511", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n\n{long long int i;\ncin >>i;\ncout<<(i*i*i+5*i)/6;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "1a1778061caa20606b38c7ac79f93d8a", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\nint main()\n{\nint w,h,u1,d1,u2,d2;\ncin>>w>>h>>u1>>d1>>u2>>d2;\nif(d2>d1){swap(d2,d1);swap(u2,u1);}\nw+=h;\nfor(int i=h-1;i>=d1;--i) w+=i;\nw-=u1;\nif(w<0) w=0;\nfor(int i=d1-1;i>=d2;--i) w+=i;\nw-=u2;\nif(w<0) w=0;\nfor(int i=d2-1;i>=1;--i) w+=i;\ncout<\nusing namespace std;\nint main(void){\n int n,k;\n cin >> n >> k;\n cout << (n/k+1)*k << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "d2b6dee13954506591372f2710b61df5", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n string a[100],s;\n cin>>s;\n for(int i=0;i<=9;i++)\n {\n\t\tcin>>a[i];\n\t}\n\tfor(int i=1;i<=8;i++)\n\t{\n\t\tfor(int j=0;j<=9;j++)\n\t\t{\n\t\t\tif(s.substr((i-1)*10,10)==a[j])cout<\nusing namespace std;\n#define fi first\n#define se second\n#define SZ(x) ((int)x.size())\n#define ALL(x) (x.begin(),x.end())\ntypedef long long ll;\ntypedef pair pii;\ntypedef double db;\nconst int MAXN=6e5+10,MAXM=4e6+10;\nconst int INF=INT_MAX,SINF=0x3f3f3f3f;\nconst ll llINF=LLONG_MAX;\nconst int MOD=1e9+7,mod=1e9+7;\nconst int Lim=1<<20;\n\nll f[55][55],g[55][55],h[55][55],inv[65];\nint n,m;\n\nint main()\n{\n f[0][1]=1;\n scanf(\"%d%d\",&n,&m);\n inv[1]=1;\n for(int i=2;i<=60;i++)inv[i]=(MOD-MOD/i*inv[MOD%i]%MOD)%MOD;\n for(int i=1;i<=n;i++)\n for(int j=1;j<=i+1;j++)\n {\n for(int a=0;a<=i-1;a++)\n {\n int b=i-1-a;\n for(int u=j;u<=a+1;u++)(g[i][j]+=f[a][u]*f[b][j])%=MOD;\n for(int u=j+1;u<=b+1;u++)(g[i][j]+=f[a][j]*f[b][u])%=MOD;\n }\n memset(h,0,sizeof(h));\n for(int x=0;x<=n;x++)\n for(int y=1;y<=x+1;y++)\n {\n ll comb=1;\n for(int t=1;x+t*i<=n;t++)\n {\n (comb*=(g[i][j]+t-1)*inv[t]%MOD)%=MOD;\n (h[x+t*i][y+t*j]+=f[x][y]*comb)%=MOD;\n }\n }\n for(int x=0;x<=n;x++)\n for(int y=0;y<=x+1;y++)\n (f[x][y]+=h[x][y])%=MOD;\n }\n cout<\nusing namespace std;\nint main()\n{\n int n,i,cnt1=0;\n string s;\n cin>>n;\n cin>>s;\n for(i=0; i\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n//#include\n\nusing namespace std;\n\n#define ll long long\n#define db double\n#define file \"file\"\n//#define M_PI 3.1415926535897931\ntypedef vector vi;\ntypedef pair pii;\ntypedef map mpi;\ntypedef set sti;\n\nconst int maxN = 1e5;\nconst int INF = 1e9;\nconst int eps = 1e-9;\nconst int inf = -INF;\nconst int base = 1000 * 1000 * 1000;\nconst int mod = 1e9 + 7;\ntypedef ll mass[maxN + 1];\n\nll readInt ()\n{\n bool minus = false;\n ll result = 0;\n char ch;\n ch = getchar();\n while (true)\n {\n if (ch == '-') break;\n if (ch >= '0' && ch <= '9') break;\n ch = getchar();\n }\n if (ch == '-') minus = true;\n else result = ch-'0';\n while (true)\n {\n ch = getchar();\n if (ch < '0' || ch > '9') break;\n result = result*10 + (ch - '0');\n }\n if (minus)\n return -result;\n else\n return result;\n}\nstruct pt\n{\n int x, y, id;\n};\nbool comp(pt a, pt b)\n{\n return a.x < b.x || (a.x == b.x && a.y < b.y);\n}\nll gcd(ll a, ll b)\n{\n return b ? gcd(b, a % b) : a;\n}\nll lcm(ll a, ll b)\n{\n return a / gcd(a, b) * b;\n}\nll binary_power(ll a, ll n)\n{\n ll res = 1;\n while(n > 0)\n {\n if(n % 2 == 0)\n {\n a *= a;\n n >>= 1;\n }\n else\n {\n res *= a;\n n--;\n }\n }\n return res;\n}\nint bitCount(ll n)\n{\n return __builtin_popcount(n);\n}\nint LowerBound(int L, int R, int x, ll w[])\n{\n // L = 0, R = n\n while(R - L > 1)\n {\n int mid = (L + R) >> 1;\n if(w[mid] >= x)\n R = mid;\n else\n L = mid;\n }\n if(w[R] == x)\n return R;\n return -1;\n}\nint UpperBound(int L, int R, int x, ll w[])\n{\n // L = 1, R = n + 1\n while(R - L > 1)\n {\n int mid = (L + R) >> 1;\n if(w[mid] <= x)\n L = mid;\n else\n R = mid;\n }\n if(w[L] == x)\n return L;\n return -1;\n}\ndb dis(db x1, db y1, db x2, db y2);\ndouble triangle_area (int x1, int y1, int x2, int y2, int x3, int y3) ;\nint triangle_area_2 (int x1, int y1, int x2, int y2, int x3, int y3) ;\nmain()\n{\n //ios::sync_with_stdio(false);\n //cin.tie(NULL);\n //freopen(file\".in\", \"rt\", stdin);\n //freopen(file\".out\", \"wt\", stdout);\n ll n = readInt();\n set st;\n map mp;\n for(ll i = 2; i * i <= n; i++)\n {\n if(n % i == 0)\n {\n while(n % i == 0)\n {\n n /= i;\n mp[i]++;\n }\n }\n }\n if(n > 1)\n {\n mp[n]++;\n }\n ll ans = 1;\n for(map :: iterator it = mp.begin(); it != mp.end(); it++)\n {\n ans *= (*it).first;\n }\n cout << ans;\n //system(\"pause\");\n return 0;\n}\ndb dis(db x1, db y1, db x2, db y2)\n{\n return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));\n}\nint triangle_area_2 (int x1, int y1, int x2, int y2, int x3, int y3) {\n return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);\n}\ndouble triangle_area (int x1, int y1, int x2, int y2, int x3, int y3) {\n return abs (triangle_area_2 (x1, y1, x2, y2, x3, y3)) / 2.0;\n}\n\n///", "lang_cluster": "C++", "tags": ["math"], "code_uid": "3e0f2120e250516f02ee72416289fef3", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define f first\n#define s second\n#define mp make_pair\n#define pb push_back\ntypedef long long ll;\n\nusing namespace std; \n\nconst int inf = 1e9; \nconst ll mod = 1e9 + 7;\nconst int maxn = 6e6 + 1; \n\nint n;\nint k;\nint x;\nint a[5];\n\nint main() {\n\tcin >> n;\n\tcin >> k;\n\tif(n > 6) {\n\t\tn %= 6;\n\t} \n\tfor(int j = 0; j < 3; j++) {\n\t\ta[0] = a[1] = a[2] = 0;\n\t\ta[j] = 1;\n\tfor(int i = 1; i <= n; i++) {\n\t\tif(i % 2)\t\n\t\t\tswap(a[1], a[0]);\n\t\telse\n\t\t\tswap(a[1], a[2]);\n\t}\n\tfor(int i = 0; i < 3; i++)\n\t\tif(a[i] > 0)\n\t\t\tx = i;\n\tif(x == k)\n\t\treturn cout << j, 0;\n\t}\n\treturn 0;\n} ", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "53c95efdf8ad57e3021286e77474f9ec", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n \nusing namespace std;\nstring s;\nint need[3] = {};\nint have[3] = {};\nint price[3] = {};\nlong long r ;\nbool solve(long long m)\n{\n long long p = 0;\n for (int i = 0 ; i < 3 ; i++)\n {\n long long z = m*need[i];\n z = z - have[i];\n if (z > 0)\n {\n p = p + z*price[i];\n }\n }\n return p <= r;\n}\n \nint main()\n{\n cin >> s;\n for (int i = 0 ; i < s.size() ; i++)\n {\n if (s[i] == 'B')need[0]++;\n if (s[i] == 'S')need[1]++;\n if (s[i] == 'C')need[2]++;\n }\n for (int i = 0 ; i < 3 ; i++)\n {\n cin >> have[i];\n }\n for (int i = 0 ; i < 3 ; i++)\n cin >> price[i];\n cin >> r;\n long long s = 0 , e = 1e15;\n long long ans = 0;\n while(s <= e)\n {\n long long middle = (s+e)/2;\n if (solve(middle))\n {\n \n s = middle+1;\n ans = middle;\n }\n else e = middle - 1;\n \n }\n cout << ans << endl;\n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "binary search"], "code_uid": "2f8dd925dd6a7b0ba31981760e264222", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\nint main(){\n \n int light, button;\n int b[1000]={0};\n int pressed_button;\n \n scanf(\"%d %d\",&light, &button);\n while(button--){\n scanf(\"%d\",&pressed_button);\n for(int i= pressed_button - 1; i\nusing namespace std;\nint dp[4500];\nint a, b, c, n;\nint res(int n){\n\tif(n < 0) return -1e7;\n\tif(n == 0) return 0;\n\tif(dp[n] != -1) return dp[n];\n\tint ans = max(res(n-a)+1, max(res(n-b)+1, res(n-c)+1));\n\treturn dp[n]=ans;\n}\nint main(){\n\tcin>>n>>a>>b>>c;\n\tmemset(dp, -1, sizeof(dp));\n\tcout<\n#include \n#include \nusing namespace std;\nusing namespace __gnu_pbds;\n#define ll long long int\n#define mod 1000000007ll\n#define mod1 998244353ll\n#define endl '\\n'\n#define inf (ll)1e18+1\n#define ordered_set tree,rb_tree_tag,tree_order_statistics_node_update>\n\nstring base3(ll n){\n if(n==0){\n return \"0\";\n }\n string ans=\"\";\n while(n!=0){\n ll rem=n%3;\n n/=3;\n ans=to_string(rem)+ans;\n }\n return ans;\n}\n\nint main()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n ll a,c;\n cin>>a>>c;\n string a1=base3(a);\n string c1=base3(c);\n while(a1.length()=0;x--){\n ll diga=a1[x]-'0';\n ll digc=c1[x]-'0';\n digc+=3;\n ll digb=digc-diga;\n if(digb>=3){\n digb-=3;\n }\n ans+=mul*digb;\n mul*=3;\n }\n cout<\n#include \nusing namespace std;\nlong long int fib[112]={1,1},k;\nint p[112],n;\nint main(){\n for(int i=2;i<=85;i++)\n fib[i]=fib[i-1]+fib[i-2];\n cin>>n>>k;\n for(int i=0;i0){//timed in test 5 :( maby for this.\n int pos=0;\n while(fib[++pos]10)return 0;\n }\n for(int i=0;i\nusing namespace std;\n\n#define oo (1LL<<30)\n#define SZ(x) ((int)x.size())\n#define valid(x,u) (x>=0 && x> n >> t;\n for(int i=0; i> a;\n if(cur) cur += 10, ans += 2;\n cur += a;\n if(cur > t) {\n cout << -1 << endl;\n return 0;\n }\n }\n\n ans += (t - cur) / 5;\n\n cout << ans << endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy", "implementation"], "code_uid": "f1f2532b1afe96b52a8971337224ea6a", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\nusing namespace std;\nstring str,st=\"QAQ\";\nint ans;\nvoid DG(int sum,int x){\n\tif(sum==3){\n\t\tans++;\n\t\treturn;\n\t}\n\tfor(int i=x+1;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define ll long long\nusing namespace std;\nconst int MAXN=200001;\nlong long m;\nlong long get(long long r,long long lmt){\n long long ret=lmt/r;\n return ret;\n}\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cin>>m; // \uac00\ub2a5\ud55c \uacbd\uc6b0\uc758\uc218\n long long low=0;\n long long high=1e18;\n long long ans=1e18;\n while(low<=high){\n long long cnt=0;\n long long mid=(low+high)/2;\n for(long long i=2;i<=1000000;i++){ //r \uc744 \uacb0\uc815\ud568\n cnt+=get(i*i*i,mid);\n if(cnt>m)break;\n }\n if(cnt>=m){\n high=mid-1;\n if(cnt==m){\n ans=min(ans,mid);\n }\n }\n else{\n low=mid+1;\n }\n }\n if(ans==1e18)ans=-1;\n cout<\nusing namespace std;\n\nint a[6][4] = {{0, 0, 0, 0}, {0, -1, 1, 1}, {0, -1, 5, 3}, {0, -1, 11, 5}, {0, -1, -1, 9}, {0, -1, -1, 11}};\n\nint main()\n{\n int n, m, ans;\n\n // freopen(\"D:\\\\1.in\", \"r\", stdin);\n // freopen(\"D:\\\\1.out\", \"w\", stdout);\n\n cin >> m >> n;\n\n if(n <= 3)\n {\n if(m <= 5) ans = a[m][n];\n else ans = -1;\n }\n else\n {\n int nownum, start, len;\n for(nownum = 1, start = 1; nownum <= 7; nownum += 2, start += len)\n {\n if(nownum == 1) len = n / 2;\n else if(nownum == 3 || nownum == 7) len = (n - 1) / 2;\n else len = (n - 2) / 2;\n\n if(start <= m && m <= start + len - 1) break;\n }\n if(nownum > 7)\n {\n len = (n - 2) / 2;\n nownum += (m - start) / len * 2;\n }\n ans = nownum;\n }\n\n cout << ans << endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "4ae64154fab0ca6b2e60debab3f65f36", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nint main()\n{\n\t\n\tvector v1;\n\tint total=0;\n\tfor(int i=0;i<6;i++)\n\t{\n\t\tint x;\n\t\tcin>>x;\n\t\ttotal=total+x;\n\t\tv1.push_back(x);\n\t}\n\tint flag=0;\n\tfor(int i=0;i<4;i++)\n\t{\n\t\tint sum=0;\n\t\tfor(int j=i+1;j<5;j++)\n\t\t{\n\t\t\tfor(int k=j+1;k<6;k++)\n\t\t\t{\n\t\t\t\tsum=v1[k]+v1[j]+v1[i];\n\t\t\t\t\t\n\t\t\t\tif(sum==(total-sum))\n\t\t\t\t\t{flag++;\n\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\tsum=0;\n\t\t\t}\n\n\t\t}\n\t}\n\n\tif(flag==0)\n\t\tcout<<\"NO\";\n\telse\n\t\tcout<<\"YES\";\n\n}", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "217b21721b4c3c57c8f1fff76ebbd5e2", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\ntypedef unsigned long long ull;\ntypedef long long ll;\ntypedef vector vi;\ntypedef pair pii;\ntypedef vector vii;\ntypedef vector > vvi;\n#define clr(a, b) memset(a, b, sizeof(a))\n#define pb push_back\n#define all(a) a.begin(), a.end()\n#define mkp make_pair\n#define forn(i, n) for(int i=0; i<(int)n; ++i)\n#define forab(i, a, b) for(int i=(int)a; i<(int)b; ++i)\nconst int inf = (int)1e6+5;\nconst int nax = (int)3e5+5;\nint m, s;\nvi res_sml, res_lrg;\n\nll sm(vi &v){\n ll sum = 0;\n for(auto it : v){\n sum += it;\n }\n return sum;\n}\nvoid find_sml(){\n res_sml.clear();\n int co = 1, ss = s;\n forn(i, m){\n int k = (i==0) ? 1 : 0;\n if(m == co){\n vi temp;\n if(ss > 9){\n while(ss > 0){\n if(ss > 9){\n temp.pb(9);\n ss -= 9;\n continue;\n }\n temp.pb(ss);\n ss = 0;\n }\n int c = temp.size();\n while(c > 0){\n if((int)res_sml.size() > 0){\n if(res_sml.back() != 0)\n temp.pb(res_sml.back());\n res_sml.pop_back();\n }\n --c;\n }\n sort(all(temp));\n if((int)res_sml.size()+(int)temp.size() < m){\n for(auto &it : res_sml){\n if(it != 0) continue;\n while((int)res_sml.size()+(int)temp.size() < m){\n res_sml.pb(0);\n }\n break;\n }\n }\n while(((int)res_sml.size()+(int)temp.size() > m) && res_sml.size()>0)\n res_sml.pop_back();\n for(auto &it : temp){\n res_sml.push_back(it);\n }\n continue;\n }\n res_sml.pb(ss);\n continue;\n }\n while((ceil((ss - k)*1.0/(m - co)*1.0) > 9) && k < 9) ++k;\n res_sml.pb(k);\n ss -= k;\n ++co;\n }\n}\n\nvoid find_lrg(){\n res_lrg.clear();\n int ss = s;\n forn(i, m){\n for(int j = 9; j>=0; --j){\n if(j <= ss){\n res_lrg.pb(j);\n ss -= j;\n break;\n }\n }\n }\n}\n\nvoid compute(){\n cin>>m>>s;\n if(s == 0){\n if(m > 1){\n cout<<\"-1 -1\\n\";\n return;\n }\n cout<<\"0 0\"<<\"\\n\";\n return;\n }\n find_sml();\n find_lrg();\n if(m != (int)res_lrg.size() || m != (int)res_sml.size() || sm(res_sml) != s || sm(res_lrg) != s){\n cout<<\"-1 -1\\n\";\n return;\n }\n for(auto it : res_sml){\n cout<());\n for(auto it : res_lrg){\n cout<>t;\n// while(t--)\n compute();\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy", "dp", "implementation"], "code_uid": "7aafffd947e872abd53bf33ba4064de9", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "\n#include\n#include\n\nusing namespace std;\n\nint main()\n{\n mapMap;\n int n,coun=0;\n cin>>n;\n\n for(int i=1; i<=n; i++)\n {\n for(int j=i; j<=n; j++)\n {\n int k=(i^j);\n\n if(k<=n && i+j>k && k>=j)\n {\n coun++;\n }\n }\n }\n\n cout<\n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tlong long n, k;\n\tcin >> n >> k;\n\tlong long a = (n / 2) / (k + 1);\n\tcout << a << ' ' << k * a << ' ' << n - a * (k + 1) << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "9a8f8ccf671d9c172c43271f1cd61ede", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define ll long long\n\nstruct _comp {\n bool operator() (int i[3],int j[3]) { return (i[0]>j[0]);}\n} comp;\n\n\nint gcd(int a, int b)\n{ \n if(b==0)\n return a;\n else\n return gcd(b, a%b);\n}\n\n\nvector> Ptriangle;\nvoid fill_Ptriangle(int step){\n vector tmp(1,1);\n Ptriangle.push_back(tmp);\n for(int i=1;i<=step;i++)\n {\n tmp.clear();\n tmp.push_back(1);\n for(int k=0;k set_elems;\n// vector set_indexes;\n// void make_set(int elem, int index)\n// {\n// parent_set = index;\n// set_elems.push_back(elem);\n// set_indexes.push_back(index);\n// size = 1;\n// }\n//};\n//_set my_set[300];\n//int find_set(int index){\n// if(my_set[index].parent_set == index)\n// return index;\n// if(my_set[index].parent_set == -1)\n// return index;\n// return my_set[index].parent_set = find_set(my_set[index].parent_set);\n//}\n//void union_sets(int a, int b)\n//{\n// a = find_set(a);\n// b = find_set(b);\n// if(a!=b)\n// {\n// if(my_set[a].size < my_set[b].size)\n// swap(a, b);\n// my_set[a].parent_set = b;\n// my_set[b].set_elems.insert(my_set[b].set_elems.end(), my_set[a].set_elems.begin(), my_set[a].set_elems.end());\n// my_set[b].set_indexes.insert(my_set[b].set_indexes.end(), my_set[a].set_indexes.begin(), my_set[a].set_indexes.end());\n// my_set[b].size += my_set[a].size;\n// }\n//}\nint zx[1000];\nmap m;\nint main()\n{\n zx[1]=1;\n #ifndef ONLINE_JUDGE\n freopen(\"Input.txt\", \"r\", stdin);\n #endif\n int n,t;\n cin >> n;\n for(int i=0;i::iterator it=m.begin();it!=m.end();it++)\n {\n while(it->second){\n res++;\n int z=0;\n for(map::iterator it2=it;it2!=m.end();it2++){\n if(!it2->second || it2->first-z<0)\n continue;\n if(z>it2->first)\n break;\n if(it2->second<=it2->first+1-z){\n z+=it2->second;\n m[it2->first] = 0;\n }\n else {\n m[it2->first] -= it2->first+1-z;\n z=it2->first+1;\n }\n }\n }\n }\n cout << res << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["sortings", "greedy"], "code_uid": "8c24b48c89e0b4af348a2aaac540448c", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \nusing namespace std;\nint main()\n{\n char c;\n int n,lastN=1,lln=1,counter=0;\n bool f = true;\n while((c=getchar())!=-1&&c>=48&&c<=58)\n {\n n = c - 48;\n if(n==1||n==4)\n {\n if(n==4)\n {\n if(counter==0)\n {\n f = false;\n }\n if(lastN==4)\n {\n if(lln!=1)\n {\n f = false;\n }\n }\n }\n }\n else\n {\n f = false;\n }\n counter++;\n lln=lastN;\n lastN=n;\n }\n if(f)\n {\n cout<<\"YES\";\n }\n else\n {\n cout<<\"NO\";\n }\n}\n", "lang_cluster": "C++", "tags": ["brute force", "greedy"], "code_uid": "30b0eb33063a0d73f937cd28dfb65171", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "/*\n######################################################\n# I don't know what I'm doing with my life O.O #\n######################################################\n*/\n\n#include \nusing namespace std;\n\n//Optimizations\n#pragma comment(linker, \"/stack:200000000\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n\n//save time\n#define endl '\\n'\n#define db(x) cout << \"> \" << #x << \": \" << x << endl;\ntypedef long long ll;\n\n//for sorting\n#define all(a) a.begin(),a.end()\n\n//Constants\n#define PI 3.141592653593\n#define MOD 1000000007LL\n#define EPS 0.000000001\n#define INF 0X3f3f3f3f\n\n//loops\n#define REP(i,n) \t for(int i=0;i<(n);++i)\n#define FOR(i,a,b) for(int i=(a);i<(b);++i)\n#define DFOR(i,a,b) for(int i=(a);i>=(b);--i)\n\n//vectors\n#define vi vector\n#define vll vector\n#define vii vector>\n#define vlll vector>\n#define pb \tpush_back\n\n//pairs\n#define pi pair\n#define pll pair\n#define mp make_pair\n#define F first\n#define S second\n\n//fast I/O\n#ifndef _WIN32\n#define getchar getchar_unlocked\n#define putchar putchar_unlocked\n#endif\n#define gc getchar\n#define pc putchar\n\n//If using cin and cout\n#define IOS ios::sync_with_stdio(false)\n#define TIE cin.tie(NULL);cout.tie(NULL)\n\n//queue\n#define di deque\n#define dll deque\n#define qi queue\n#define PQ priority_queue\n\n//general\n#define E empty()\n\n//Declare all variables and methods needed between this comment and the next one(OCD lol)\nconst int MAXN=1e5+10;\nvii sale;\nint k[MAXN],n,m,tot;\nint bSearch(int low,int high){\n int mid=(low+high)>>1;\n if(low<=high){\n int last[n+1]={};\n for(auto s : sale)\n if(s.F<=mid)\n last[s.S]=max(s.F,last[s.S]);\n\n vii v;\n FOR(i,1,n+1)\n v.pb(mp(last[i],i));\n sort(all(v));\n\n int cnt=0,sum=0,tmp;\n auto it=v.begin();\n FOR(i,1,mid+1){\n ++cnt;\n while(it!=v.end() && it->FF==i){\n tmp=min(cnt,k[it->S]);\n cnt-=tmp;\n sum+=tmp;\n ++it;\n }\n }\n\n sum=(tot-sum)*2;\n if(sum<=cnt)\n return bSearch(low,mid-1);\n else\n return bSearch(mid+1,high);\n }\n else\n return mid+1;\n}\n//Main function\nint main(){\n IOS;\n TIE;\n\n cin>>n>>m;\n\n FOR(i,1,n+1){\n cin>>k[i];\n tot+=k[i];\n }\n\n int d,t;\n REP(i,m){\n cin>>d>>t;\n sale.pb(mp(d,t));\n }\n\n cout<\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nconst int MAXN = 300;\nconst int MAXM = 300000;\nconst int INF = 0x3f3f3f3f;\n\nstruct Edge\n{\n int to,next,cap,flow,cost;\n}edge[MAXM];\n\nint head[MAXN],tol;\nint pre[MAXN],dis[MAXN];\nbool vis[MAXN];\nint N;//\u00bd\u00da\u00b5\u00e3\u00d7\u00dc\u00b8\u00f6\u00ca\u00fd\u00a3\u00ac\u00bd\u00da\u00b5\u00e3\u00b1\u00e0\u00ba\u00c5\u00b4\u00d30~N-1\n\nvoid init(int n)\n{\n N = n;\n tol = 0;\n memset(head,-1,sizeof(head));\n}\n\nvoid addedge(int u,int v,int cap,int cost)\n{\n edge[tol].to = v;\n edge[tol].cap = cap;\n edge[tol].cost = cost;\n edge[tol].flow = 0;\n edge[tol].next = head[u];\n head[u] = tol++;\n edge[tol].to = u;\n edge[tol].cap = 0;\n edge[tol].cost = -cost;\n edge[tol].flow = 0;\n edge[tol].next = head[v];\n head[v] = tol++;\n}\n\nbool spfa(int s,int t)\n{\n queueq;\n for(int i = 0;i < N;i++)\n {\n dis[i] = INF;\n vis[i] = false;\n pre[i] = -1;\n }\n dis[s] = 0;\n vis[s] = true;\n q.push(s);\n while(!q.empty())\n {\n int u = q.front();\n q.pop();\n vis[u] = false;\n for(int i = head[u]; i != -1;i = edge[i].next)\n {\n int v = edge[i].to;\n if(edge[i].cap > edge[i].flow &&\n dis[v] > dis[u] + edge[i].cost )\n {\n dis[v] = dis[u] + edge[i].cost;\n pre[v] = i;\n if(!vis[v])\n {\n vis[v] = true;\n q.push(v);\n }\n }\n }\n }\n if(pre[t] == -1)return false;\n else return true;\n}\n\nint minCostMaxflow(int s,int t,int &cost)\n{\n int flow = 0;\n cost = 0;\n while(spfa(s,t))\n {\n int Min = INF;\n for(int i = pre[t];i != -1;i = pre[edge[i^1].to])\n {\n if(Min > edge[i].cap - edge[i].flow)\n Min = edge[i].cap - edge[i].flow;\n }\n for(int i = pre[t];i != -1;i = pre[edge[i^1].to])\n {\n edge[i].flow += Min;\n edge[i^1].flow -= Min;\n cost += edge[i].cost * Min;\n }\n flow += Min;\n }\n return flow;\n}\t\n\nint n,val[MAXN],fix[MAXN],sum;\nchar str[MAXN];\nint ans;\n\nint main()\n{\n\tint i,j,s,t,tmp;\n\tscanf(\"%d\",&n);\n\tinit(2*n+2);\n\ts=0; t=2*n+1;\n\tscanf(\"%s\",str+1);\n\tsum=0;\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tscanf(\"%d\",&val[i]);\n\t\tsum+=val[i];\n\t}\n\tmemset(fix,0,sizeof(fix));\n\tfor(i=1;i<=n/2;i++)\n\t\tif(val[i]>val[n+1-i])\n\t\t\tfix[i]=1,addedge(i,n+i,1,0);\n\t\telse\n\t\t\tfix[n+1-i]=1,addedge((n+1-i),n+(n+1-i),1,0);\n\tfor(i=1;i<=n;i++)\n\t\taddedge(s,i,1,0),addedge(n+i,t,1,0);\n\tfor(i=1;i<=n;i++)\n\t\tfor(j=1;j<=n;j++)\n\t\t{\n\t\t\tif(fix[i] || fix[j])\n\t\t\t\tcontinue;\n\t\t\tif(str[i]==str[n+1-j])\n\t\t\t\tcontinue;\n\t\t\tif(i==j) tmp=0;\n\t\t\telse tmp=val[j];\n\t\t\taddedge(i,n+j,1,tmp);\n\t\t}\n\tint flow=minCostMaxflow(s,t,ans);\n\tans=sum-ans;\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n\n\n", "lang_cluster": "C++", "tags": ["greedy", "flows", "graphs"], "code_uid": "7ff1387cd819d7aca2faf4a7351610c3", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\nint main()\n{\n int i=0, j=0, row, column;\n bool success = false;\n char square [4][4];\n for (row = 0; row < 4; row++)\n for (column = 0; column < 4; column++)\n cin >> square[row][column];\n for (row = 1; row < 4; row++)\n {\n for (column = 1; column < 4; column++)\n {\n if (square[row][column] == '#') i++; else j++;\n if (square[row-1][column-1] == '#') i++; else j++;\n if (square[row-1][column] == '#') i++; else j++;\n if (square[row][column-1] == '#') i++; else j++;\n if ((i>=3) || (j>=3)) \n {\n success=true;\n break;\n }\n else\n {\n i=0;\n j=0;\n }\n }\n if (success) break;\n }\n if (success == true) cout << \"YES\";\n else cout << \"NO\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "958f7b7fb9d324325e61aa8f7326cd08", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint T;\nlong long a,b;\n/*long long cf(long long x,long long n,long long p)\n{\n if(!n) return 1;\n long long ans=cf(x,n/2,p);\n ans=(ans%p)*(ans%p);\n if(n%2) ans=((ans%p)*(x%p))%p;\n return ans%p;\n}\nbool miller_rabin(long long n)\n{\n long long i,j,aa,x,y,t,u,s=10;\n if(n==2) return true;\n if(n<2||!(n&1)) return false;\n for(t=0,u=n-1;!(u&1);t++,u>>=1);\n for(i=0;i>T;\n while(T--){\n cin>>a>>b;\n if(a<=(b+1)){\n if(is_prime(a+b)) printf(\"YES\\n\");\n else printf(\"NO\\n\");\n }\n else printf(\"NO\\n\");\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "e606770be23bf5128560342abdada5a4", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef pair ii;\nconst int inf = 1e9+123;\n\nll a, b, c ,d, cnt=0;\nll ret(ll x, ll n)\n{\n\tif(x<=0 || n<=0)\n\t\treturn 0;\n\tif(n>=x)\n\t\treturn n*x-((x-1)*(x))/2;\n\telse\n\t\treturn (n*(n+1))/2;\n}\nvoid solve()\n{\n\tll a, b, c ,d, cnt=0;\n\tcin >> a >> b >> c >> d;\n\tfor(int z = c; z<=d; z++)\n\t{\n\t\tll lb = b, rb = c;\n\t\tll llb = a, rrb = b;\n\t\twhile(lbz)\n\t\t{\n\t\t\tcnt += (b-llb+1)*(c-lb+1);\n\t\t\tcnt += ret(llb-a, c-lb);\n\t\t}\n\t}\n\tcout << cnt << '\\n';\n}\n\nint main()\n{\t\n\tcin.tie(NULL);\n\tios_base::sync_with_stdio(false);\n//\tll t;\n//\tcin >> t;\n//\twhile(t--)\n\tsolve();\n}", "lang_cluster": "C++", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "e7d90169d7480230b2aea1e32a4063ee", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nint a,b,k,q[1000006];\nbool pr[1000006];\nint main (){\n cin >> a >> b >> k;\n pr[1] = 1;\n for (int i = 2; i*i <= b; i++){\n if (pr[i] == 0){\n for(int j = i*i; j <= b; j+=i)\n pr[j] = 1;\n }\n }\n \n for (int i = 1; i <= b; i++){\n q[i]+=q[i - 1];\n if (pr[i] == 0) q[i]++;\n }\n \n int x = k,l,y = b - a + 1,ans = -1;\n if (x > y) {cout<<-1; return 0;}\n while (x < y){\n l = (x + y) >> 1;\n int w = 0;\n for (int i = a; i <= b - l + 1; i++)\n if (q[i + l - 1] - q[i - 1] < k) {w = -1; break;}\n \n if (w == 0) {y = l; ans = l;}\n else x = l + 1;\n }\n \n l = x;\n int w = 0;\n for (int i = a; i <= b - l + 1; i++)\n if (q[i + l - 1] - q[i - 1] < k) {w = -1; break;}\n if (w == 0) ans = l;\n \n cout<\n#include\n#include\n#include\nusing namespace std;\nconst int dx[]={1,-1,0,0};\nconst int dy[]={0,0,1,-1};\nconst int INF=1000000000;\nint n,m,sx,sy,tx[10],ty[10],tp[10],tn,bx[10],by[10],bn;\nint f[21][21][256][256],pr[256],ans;\nint qx[2000010],qy[2000010],qt[2000010],qb[2000010],l,r;\nchar a[51][51];\nint main()\n{\n\tscanf(\"%d%d\",&n,&m);\n\tfor(int i=1;i<=n;i++) scanf(\"%s\",a[i]+1);\n\tfor(int i=1;i<=n;i++)\n\t\tfor(int j=1;j<=m;j++)\n\t\t{\n\t\t\tif(a[i][j]=='S') sx=i,sy=j;\n\t\t\tif(a[i][j]>='0'&&a[i][j]<='9') tx[a[i][j]-'0']=i,ty[a[i][j]-'0']=j,tn++;\n\t\t\tif(a[i][j]=='B') bx[++bn]=i,by[bn]=j;\n\t\t}\n\tfor(int i=1;i<=tn;i++) scanf(\"%d\",&tp[i]);\n\tfor(int i=1;i<=n;i++)\n\t\tfor(int j=1;j<=m;j++)\n\t\t\tfor(int k=0;k<(1<f[ox][oy][ot][ob]+1)\n\t\t\t\tf[nx][ny][nt][nb]=f[ox][oy][ot][ob]+1,qx[++r]=nx,qy[r]=ny,qt[r]=nt,qb[r]=nb;\n\t\t}\n\t}\n\tfor(int i=0;i<(1<\n#include \nusing namespace std;\n\nint main() {\n\tint n, a, b, c;\n\n\tscanf(\"%d %d %d %d\", &n, &a, &b, &c);\n\n\tif (n == 1) {\n\t\tprintf(\"0\");\n\t}\n\telse if (n == 2) {\n\t\tprintf(\"%d\", min(a, b));\n\t}\n\telse {\n\t\tint s;\n\t\tif (a <= b && a <= c) s = a;\n\t\telse if (b <= a && b <= c) s = b;\n\t\telse if (c <= a && c <= b) s = c;\n\t\tif (s == c) s = min(a, b) + (n - 2) * s;\n\t\telse s = (n - 1) * s;\n\t\tprintf(\"%d\", s);\n\t}\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "b57292e11fa646521fff3aa547c1cd3b", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "/*\n ------------------------- Hachiikung ---------------------------------\n ---------------------- Worrachate Bosri ------------------------------\n ------ Faculty of Computer Engineering Chulalongkorn University ------\n*/\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define REP(i,FN) for(int i=0;i=ST;i--)\n#define FORX(i,c) for(typeof(c.begin())i=c.begin();i!=c.end();i++)\n#define pause system(\"pause\")\n#define S scanf\n#define P printf\n#define X first\n#define Y second\n#define pb push_back\n#define PII pair\n#define mp make_pair\n#define sz size()\n#define eps 1e-8\n\nconst int MOD(1000000007);\nconst int INF((1<<30)-1);\nconst int MAXN(5005);\n\nint n;\n\nlong long dp[2][MAXN];\n\nint main(){\n\n int a,k,b;\n S(\"%d%d%d%d\",&n,&a,&b,&k);\n\n int now = 1, prev = 0;\n\n dp[prev][a] = 1;\n\n while(k--)\n {\n FOR(i,1,n)\n {\n dp[now][i] = 0;\n dp[prev][i] += dp[prev][i-1];\n dp[prev][i] %= MOD;\n }\n\n FOR(i,1,n)\n {\n if(i == b) dp[now][i] = 0;\n\n else if(i < b)\n {\n dp[now][i] += dp[prev][i-1];\n\n int m = (i+b)/2;\n\n if((b-i)%2 == 1)\n {\n dp[now][i] += dp[prev][m] - dp[prev][i];\n }\n else\n {\n dp[now][i] += dp[prev][m-1] - dp[prev][i];\n }\n }\n\n else\n {\n dp[now][i] += dp[prev][n] - dp[prev][i];\n\n int m = (b+i)/2;\n\n dp[now][i] += dp[prev][i-1] - dp[prev][m];\n }\n\n dp[now][i] %= MOD;\n }\n\n now ^= 1;\n prev ^= 1;\n }\n\n long long ans = 0;\n\n FOR(i,1,n)\n {\n ans += dp[prev][i];\n ans %= MOD;\n }\n\n P(\"%I64d\",(ans+MOD)%MOD);\n}\n", "lang_cluster": "C++", "tags": ["dp", "implementation", "combinatorics"], "code_uid": "7638fe3988122e2aadad2dee6c1c13ac", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\n\n\nint main()\n{\n\tstring str;\n\tint n,k,len,num[30],m,mi;\n\twhile(cin>>n>>k)\n\t{\n\t\tm=mi=0;\n\t\tcin>>str;\n\t\tmemset(num,0,sizeof(num));\n\t\tfor(int i=0;i\nusing namespace std;\nint main()\n{\n\tlong int n;\n\tcin >> n;\n\tint i,flag=0;\n\tlong int dif;\n\tint arr[10000];\n\tfor(i=0;i> arr[i];\n\t}\n\t\tdif=arr[1]-arr[0];\n\tfor(i=1;i\n\nusing namespace std;\n\ntypedef long long ll ;\ntypedef long double ld ;\n\n//#define int ll\n#define pb push_back\n#define bp pop_back\n#define pf push_front\n#define fp pop_front\n#define X first\n#define Y second\n#define IO ios_base::sync_with_stdio(false);\n#define sz(a) (int)(a.size())\n#define sg(a, b) (a + b - 1) / b\n\nconst int MOD = 1000 * 1000 * 1000 + 7;\nconst int INF = 2 * 1000 * 1000 + 200;\nconst int MAXN = 2 * 100 * 100 + 20;\nconst int MLOG = 18;\nconst int NMAX = 1 * 1000;\n\nint main() {\n\tIO;\n\tll n, m;\n\tcin >> n >> m;\n\tm--;\n\tdeque dq;\n\tdq.pb(n);\n\tfor(int i = 0; i < n - 1; i++)\n\t\tif((m >> i) & 1) dq.pb(n - i - 1);\n\t\telse dq.pf(n - i - 1);\n\tfor(int i = 0; i < n; i++) cout << dq[i] << ' ';\n}\n", "lang_cluster": "C++", "tags": ["math", "divide and conquer", "bitmasks"], "code_uid": "ad15c3370300abc24e4da579a2a9e7fa", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "/*\nNahid Hossain\nJahangirnagar University\nRoll:54\n*/\n#include\n#define ll long long int\n#define db double\n#define pf printf\n#define sf scanf\n#define ff first\n#define ss second\n#define clr clear()\n#define sz size()\n#define pb push_back\n#define mk make_pair\n#define pi acos(-1)\n#define inf 1000000000000\n#define mod 1000000007\n#define ull unsigned long long int\n#define f(i,k,n) for(ll i=k;i=k;i--)\n#define ent(a) scanf(\"%lld\",&a)\n#define ent2(a,b) scanf(\"%lld%lld\",&a,&b)\n#define ent3(a,b,c) scanf(\"%lld%lld%lld\",&a,&b,&c)\n#define mem(a) memset(a,0,sizeof(a))\n#define vec(v,s) vectorv[s]\n#define arr(a,s) ll a[s];\n//#define check(n,pos) (n&(1<9)return 0;\n if(x==0)\n {\n ll s1=0;\n\n for(ll i=s+1;i<=10;i++)s1+=a[i];\n s1%=mod;\n return s1;\n }\n ll r=0;\n\n for(ll i=0;i<=10;i++)\n {\n ll p=a[i];\n a[i]--;\n r=r+p*cal1(x-1,s+i);\n r%=mod;\n a[i]++;\n }\n return r;\n\n}\n\n\n\nint main()\n{\n ll i;\n while(cin>>t)\n {\n for(i=0;i<=10;i++)\n {\n memset(dp,-1,sizeof(dp));\n a[i]=cal(0,0,i);\n ll cn=0;\n if(i==0)a[i]--;\n }\n\n ll ans=cal1(6,0);\n cout<\nusing namespace std;\n#define ll long long\n\nint main(){\n\tll n,k,t;\n\tcin>>n>>k>>t;\n\tif(t < k) cout<= k && t<=n) cout<n && t \nusing namespace std;\nint main()\n{\n\tint n, k, s = 0;\n\tcin>>n>>k;\n\tif((8*n)%k == 0){\n\t\ts += 8*n/k;\n\t}\n\telse s += (8*n)/k+1;\n\tif((5*n)%k == 0){\n\t\ts += 5*n/k;\n\t}\n\telse s += (5*n)/k+1;\n\tif((2*n)%k == 0){\n\t\ts += 2*n/k;\n\t}\n\telse s += (2*n)/k+1;\n\tcout<\n#include \n#include\nusing namespace std;\nint main() \n{\n long long int n,m;\n cin>>n>>m;\n if((long double)((long double)log(m)/(long double)log(2))>=(n-0.1))\n {\n cout<\n#include\n#include\nusing namespace std;\n\nint main()\n{\n int n;\n cin>>n;\n \n \tstring s;\n \ts=\"\";\n \tfor(int i=1;i<=n;i++)\n \t{\n \t\tif(i<=9)\n \t\ts.push_back(i+'0');\n \t\telse\n \t\t{\n \t\t\tstring s1=\"\";\n \t\t\tint p=i;\n \t\t\twhile(p!=0)\n \t\t\t{\n \t\t\t\tint r=p%10;\n \t\t\t\ts1.push_back(r+'0');\n \t\t\t\tp=p/10;\n\t\t\t}\n\t\t\treverse(s1.begin(),s1.end());\n\t\t\ts+=s1;\n\t\t}\n\t}\n\tcout<\n\nusing namespace std;\n\nint main()\n{\n int n,a[102],i,j,sum,min=1e9;\n cin >> n;\n for(int i=1; i<=n; i++) cin >> a[i];\n for(int i=1; i<=n; i++)\n {\n sum=0;\n for(int j=1; j<=n; j++)\n {\n sum+=a[j]*2*(abs(i-j)+(i-1)+(j-1));\n }\n if(sum\nusing namespace std;\n\nint l, r, p, pri[105], tot, n, c[3000010], f[3000010];\nbool v[3000010];\n\nvoid getpri(int n)\n{\n\tfor (int i = 2; i <= n; ++i)\n\t{\n\t\tif (!v[i]) pri[++tot] = i;\n\t\tfor (int j = 1; i * pri[j] <= n; ++j)\n\t\t{\n\t\t\tv[i * pri[j]] = true;\n\t\t\tif (i % pri[j] == 0) break;\n\t\t}\n\t}\n}\n\nvoid add(int x, int now)\n{\n\tc[++n] = x;\n\tfor (int i = now; i <= tot; ++i)\n\t\tif (1ll * x * pri[i] <= r)\n\t\t\tadd(x * pri[i], i);\n}\n\nint main()\n{\n//\tfreopen(\"schizophrenia.in\", \"r\", stdin);\n//\tfreopen(\"schizophrenia.out\", \"w\", stdout);\n\tcin >> l >> r >> p;\n\tgetpri(p); add(1, 1);\n\tsort(c + 1, c + n + 1);\n\tmemset(f, 0x3f, sizeof f);\n\tf[1] = 0;\n\tfor (int i = 2; i <= p; ++i)\n\t{\n\t\tint k = 1;\n\t\tfor (int j = 1; j <= n; ++j)\n\t\t{\n\t\t\tif (1ll * c[j] * i > r) break;\n\t\t\twhile (c[k] < c[j] * i) ++k;\n\t\t\tf[k] = min(f[k], f[j] + 1);\n\t\t\tif (f[k] + i <= p) v[k] = 1;\n\t\t}\n\t}\n\tint ans = 0;\n\tfor (int i = 1; i <= n; ++i)\n\t\tif (c[i] >= l) ans += v[i];\n\tcout << ans << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["two pointers", "dp", "brute force"], "code_uid": "dc97ed25ae89153342779cdbbc2dce09", "src_uid": "6d898638531e4713774bbd5d47e827bf", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \nint main()\n{\n\tchar p[20];\n\tchar c[20];\n\tint n,i;\n\tint ans=0;\n\tscanf(\"%s%d\",p,&n);\n\tint lambai=strlen(p);\n\tif(n>=lambai)\n\t{\n\t\tfor(i=0;i=0;i--)\n\t\t{\n\t\t\tc[i]=p[i];\n\t\t}\n\t\tfor(i=lambai-1;i>=0;i--)\n\t\t{\n\t\t\tif(p[i]!='0')\n\t\t\t{\n\t\t\t\tc[i]='0';\n\t\t\t\tans++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tz++;\n\t\t\t}\n\t\t\tif(z==n)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(atoi(c)!=0)\n\t\t{\n\t\t\tprintf(\"%d\\n\",ans);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"%d\\n\",lambai-1);\n\t\t}\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "greedy"], "code_uid": "972ec03652c9a0b7e744d2473e3151c0", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n\n#ifndef ONLINE_JUDGE\n\t#define ONLINE_JUDGE\n#endif\n\n#define MAX(x,y) ((x)>(y)?(x):(y))\n#define MIN(x,y) ((x)<(y)?(x):(y))\n#define MOD(x) ((x)>0?(x):(-(x)))\n#define pb push_back\n#define mp make_pair\n#define rep(i,n) for(i=0;i=0;i--)\n#define endl '\\n'\nusing namespace std;\ntypedef long long ll;\nconst ll maxn = (ll) 1e5+9;\nconst ll mod = (ll) 1e9+7;\n\nstring nstr,kstr;\nvector vals;\n\nint main()\n{\n\tstd::ios::sync_with_stdio(0);\n\tll i,j,k,t,q,m,l,r,n,bs;\n\tcin>>nstr;\n\tcin>>kstr;\n\n\tk=kstr.size();\n\twhile(k>0) {\n\t\tj = k-nstr.size(); if(j<0)j=0;\n\n\t\tif(k-j == nstr.size()) {\n\t\t\tfor(t=0;t1 && kstr[j]=='0')j++;\n\t\t\t\t}\n\t\t\t\telse if(kstr[j+t]>nstr[t]) {\n\t\t\t\t\tj=j+1;\n\t\t\t\t\twhile(k-j>1 && kstr[j]=='0')j++;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tj++;\n\t\t\t\twhile(k-j>1 && kstr[j]=='0')j++;\n\t\t\t}\n\t\t}\n\n\t\tvals.pb(kstr.substr(j,k-j));\n\t\tk=j;\n\t}\n\t//rep(i,vals.size())cout<\n#include \n#include \n#include \nusing namespace std;\nint main() {\n int n, x, l, r;\n int a[16];\n while (~scanf(\"%d%d%d%d\", &n, &l, &r, &x)) {\n int count = 0;\n for (int i = 0; i < n; i++)\n cin >> a[i];\n for (int cout = 1; cout <= 1 << n; cout++) {\n int _max = 0;\n int _min = 100000000;\n int sum = 0;\n for (int i = 0; i < n; i++) {\n if (cout >> i & 1) {\n _min = min(_min, a[i]);\n _max = max(_max, a[i]);\n sum += a[i];\n }\n }\n\n if ((_max - _min >= x) && sum >= l && sum <= r)\n count++;\n }\n\n cout << count << endl;\n }\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "bitmasks"], "code_uid": "dbea37f39d18e792e855e0a474e13231", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nint main(){\nlong long\tint a,b,c,d;\n\tcin>>a>>b>>c>>d;\nif(a>b&&cd){cout<<\"Vasya\";}\n \nelse\tif(max((a*3)/10,a-(a/250)*c)>max(b*3/10,b-(b/250)*d)){\n\t\tcout<<\"Misha\";\n\t}\n\telse if(max(a*3/10,a-(a/250)*c)\n\nusing namespace std;\n\nint main()\n{\n long long n , k , a,b,i,j,s=0;\n\n// scanf(\"%d %d %d %d\",&n,&k,&a,&b);\n cin>>n>>k>>a>>b;\n\n\n\n while(n>1)\n {\n\n\n //cout<=b){n/=k;s+=b;}\n else {s +=(n-1)*a; break;}\n\n\n }\n\n //cout<\nusing namespace std;\n\n\nconst int MAXN = 40;\n\n//[0, i) matched length |s| with T or F\n//first |s|-i character, last i character matched length |s| with T or F\nusing State = pair;\nState OK = {-1, -1};\n\nState trans(int N, const string& s, const State& st, int idx, char next)\n{\n int M = (int)s.size();\n if(st == OK) return OK;\n State n = {0, st.second};\n n.first |= 1;\n for(int i=0; i= N-i && s[idx-(N-i)] != next) n.second &= ~mask;\n }\n if(idx == N-1 && n.second) return OK;\n return n;\n}\n\nlong long solve(int N, string s)\n{\n map M;\n M[{1, ((((uint64_t)1)< M2;\n for(auto [a, b]: M)\n {\n cerr << a.first << \" \" << a.second << \" \" << b << endl;\n M2[trans(N, s, a, i, '0')] += b;\n M2[trans(N, s, a, i, '1')] += b;\n }\n cerr << endl;\n M = M2;\n }\n for(auto [a, b]: M) cerr << a.first << \" \" << a.second << \" \" << b << endl;\n cerr << endl;\n return M[OK];\n}\n\nint main()\n{\n int N; string s;\n cin >> N >> s;\n cout << solve(N, s) << endl;\n}", "lang_cluster": "C++", "tags": ["strings", "dp"], "code_uid": "9ff1b2bc3f7f9c9fe6bcde01bb98d8e9", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{ \n int n,now,jaznow,ans=0;\n cin>>n;\n for(int i=1;i<=n;i++)\n {\n for(int j=1;j<=n;j++)\n { \n now=i*i+j*j;\n jaznow=sqrt(now);\n if(jaznow*jaznow==now and jaznow<=n)\n {\n if(i==j)\n ans+=2;\n else\n ans++;\n }\n }\n }\n cout<\n\nusing namespace std;\n\ntypedef long long int ll;\ntypedef long double ld;\n\nconst ll inf = LLONG_MAX;\n\n#define rel( i, a, b) for( ll i = a ; i <= b ; i++ )\n#define rep( k, a, b) for( ll k = a ; k <= b ; k+=2*k )\n#define rev( i, a, b) for( ll i = b ; i >= a ; i-- )\n#define M 1000000007\n#define pll pair\n#define vll vector\n#define vpll vector\n#define mll map\n#define mpll map\n#define sll set\n#define spll set\n#define msll multiset\n#define F first\n#define S second\n#define pb push_back\n#define mp make_pair\n#define FIO ios::sync_with_stdio(false);cin.tie(0);cerr.tie(0)\n#define lb lower_bound\n#define ub upper_bound\n#define fprint(x) cout << fixed << setprecision(10) << (ld)x;\nll n, m;\nll mini, maxi;\n\nint main()\n{\n\tcin >> n >> m;\n\t\n\tll t1, t2;\n\t\n\tt1 = n/m;\n\t\n\tmini = m*((t1*(t1-1))/2);\n\t\n\tif( n % m != 0 ){\n\t\tll t = n%m;\n\t\t\n\t\tmini += t1*t;\n\t}\n\t\n\tmaxi = ((n-m+1)*(n-m))/2;\n\t\n\tcout << mini << \" \" << maxi;\n\t\n\treturn 0;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "C++", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "591f3eb02dda4dacda59866f6419b8f5", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main(){\n\tchar a;\n\tfor(int i=1;i<=6;i++)\n\t\tcin>>a;\n\tint n;\n\tcin>>n;\n\tcout<\nusing namespace std;\n#define int long long\nint a, b;\n\nbool dfs(vector &v,int b)\n{\n if(v.back()==b)\n return true;\n \n if(v.empty() or v.back()>b)\n return false;\n \n int x=v.back();//new term learnt\n v.push_back(2*x);\n if(dfs(v,b))\n return true;\n else\n v.pop_back();\n \n v.push_back(10*x+1);\n if(dfs(v,b))\n return true;\n else\n v.pop_back();\n \n return false;\n}\n\n\nint32_t main() \n{\n cin>>a>>b;\n vectorv;\n v.push_back(a);\n \n bool flag=dfs(v,b);\n if(flag)\n {\n cout<<\"YES\"<\n\nusing namespace std;\n\nint main()\n{\n\nint n;\ncin >> n;\nint lg10 = log10(n);\n\n\n long long dig = 0;\n long long keepUp = 0;\n unsigned long long now;\n lg10 ++;\n for(int i = 1;i <= lg10;i ++){\n now = pow(10.0,i) + 0.5;\n if(i < lg10){\n dig += ( (now - 1 - keepUp)* i );\n keepUp = (now - 1);\n //cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nconst long long MAXN = 2000;\nconst long long mod = 1000000007;\nlong long C[MAXN][MAXN], nn[MAXN], f[MAXN];\nlong long a[MAXN];\nlong long n, k;\nlong long res = 0, s = 0;\n\nlong long next(long long a[], long long l, long long r, long long up)\n{\n\ta[r + 1] = 0;\n\ta[l]++;\n\tfor(long long i = l; i <= r; i++)\n\t\tif (a[i] > up)\n\t\t{\n\t\t\ta[i] = 1;\n\t\t\ta[i + 1]++;\n\t\t}\n\tif (a[r + 1])\n\t\treturn 0;\n\treturn 1;\n}\n\nlong long pow(long long a, long long b)\n{\n\tlong long res = 1;\n\tfor(long long i = 1; i <= b; i++)\n\t\tres = res * a % mod;\n\treturn res;\n}\n\nint main()\n{\n\tcin >> n >> k;\n\tfor(long long i = 0; i <= n; i++)\n\t\tC[i][0] = 1;\n\tfor(long long i = 1; i <= n; i++)\n\t\tfor(long long j = 1; j <= n; j++)\n\t\t\tC[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;\n\tnn[0] = 1;\n\t//for(long long i = 1; i <= n; i++, prlong longf(\"\\n\"))\n\t//\tfor(long long j = 1; j <= n; j++)\n\t//\t\tprlong longf(\"%I64d \", C[i][j]);\n\tfor(long long i = 1; i <= n; i++)\n\t\tnn[i] = nn[i - 1] * i % mod;\n\tres = pow(n - k, n - k);\n\t\n\t//prlong longf(\"%I64d\\n\", res);\n\tfor(long long i = 1; i <= k; i++)\n\t{\n\t\tlong long tmp = C[k - 1][i - 1] * nn[i - 1] % mod;\n\t\tlong long left = k - i;\n\t\tfor(long long j = i + 1; j <= k; j++)\n\t\t\ta[j] = 1;\n\t\tlong long tmp2 = 0;\n\t\twhile(1)\n\t\t{\n\t\t\tlong long flag = 1;\n\t\t\tfor(long long j = i + 1; j <= k; j++)\n\t\t\t{\n\t\t\t\tlong long x = j, ok = 0;\n\t\t\t\tfor(long long l = 1; l <= k; l++)\n\t\t\t\t{\n\t\t\t\t\tx = a[x];\n\t\t\t\t\tif (x <= i)\n\t\t\t\t\t\tok = 1;\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tflag = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttmp2 += flag;\n\t\t\tif (!next(a, i + 1, k, k))\n\t\t\t\tbreak;\n\t\t}\n\t\ts += tmp2 * tmp % mod;\n\t\ts %= mod;\n\t\t\t\n\t}\n\tcout << res * s % mod << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["combinatorics"], "code_uid": "de245943a6de74fbf212a0e474d3a999", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\nint main()\n{\n\tint a, b, c, mxn = -1;\n\t\n\tcin >> a >> b >> c;\n\t\n\tmxn = max(mxn, a * b * c);\n\tmxn = max(mxn, a + b + c);\n\tmxn = max(mxn, a * b + c);\n\tmxn = max(mxn, a + b * c);\n\tmxn = max(mxn, a * (b + c));\n\tmxn = max(mxn, (a + b) * c);\n\t\n\tcout << mxn << endl;\n\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "5935d0b57d420d97ba00200639799094", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#define _rep(i, x, y) for(int i = x; i <= y; i++)\n#define _per(i, x, y) for(int i = x; i >= y; i--)\n#define LL long long\nusing namespace std;\ntemplate \ninline void read(T &x) {\n x = 0;\n LL f = 1;\n char c = getchar();\n for (; !isdigit(c); c = getchar())\n if (c == '-')\n f = -1;\n for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;\n x *= f;\n}\ntemplate \ninline void write(T x) {\n\tif(x < 0) {putchar('-'); x = -x;}\n\tif(x > 9) write(x / 10);\n\tputchar(x % 10 + '0');\n}\nint n, x, m;\nint mul_mod(int a, int b, int m) {\n\treturn 1ll * a * b % m;\n}\nint pow_mod(int a, int b, int m) {\n\tint res = 1;\n\twhile(b) {\n\t\tres = (b & 1 ? mul_mod(res, a, m) : res);\n\t\ta = mul_mod(a, a, m);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\nbool is_prime(int n) {\n\tif(n < 2) return false;\n\t_rep(i, 2, sqrt(n)) {\n\t\tif(n % i == 0) return false;\n\t}\n\treturn true;\n}\nbool is_primitive_root(int g) { // pr\n\tif(!(g % m)) return false;\n\t_rep(i, 2, sqrt(n)) {\n\t\tif(!(n % i)) {\n\t\t\tif(pow_mod(g, i, m) == 1) return false;\n\t\t\tif(pow_mod(g, (m - 1) / i, m) == 1) return false;\n\t\t}\n\t}\n\treturn true;\n} \nint main() {\n\tread(n); read(x); m = n + 1;\n\tif(!is_prime(m)) {write(-1); return 0;} \n\t_per(i, x - 1, 2) {\n\t\tif(is_primitive_root(i)) {\n\t\t\twrite(i); return 0;\n\t\t}\n\t}\n\twrite(-1);\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "82b98c02fb5e3d8ec1521bc944f234db", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "/* Codeforces 382E. Ksenia and Combinatorics\n * \u7ec4\u5408\u8ba1\u6570\uff0c\u6811DP\uff0cDP\u5957DP \n * combinatorics, dp */\n#include \n#include \n\ntypedef long long calc_t;\nconst int MaxN = 52, mod_v = 1000000007;\ncalc_t f[MaxN][MaxN >> 1][2], C[MaxN][MaxN];\n\nvoid init_comb(int n)\n{\n\tfor(int i = 0; i <= n; ++i)\n\t{\n\t\tC[i][i] = C[i][0] = 1;\n\t\tfor(int j = 1; j < i; ++j)\n\t\t{\n\t\t\tC[i][j] = C[i - 1][j] + C[i - 1][j - 1];\n\t\t\tif(C[i][j] >= mod_v) C[i][j] -= mod_v;\n\t\t}\n\t}\n}\n\nint main()\n{\n\tint n0, k0;\n\tstd::cin >> n0 >> k0;\n\tif(k0 << 1 > n0)\n\t{\n\t\tstd::cout << \"0\\n\";\n\t\treturn 0;\n\t}\n\n\tinit_comb(n0);\n\tf[1][0][0] = 1; f[0][0][1] = 1;\n\tfor(int n = 2; n <= n0; ++n)\n\t{\n\t\tfor(int k = 1; k <= std::min(k0, n >> 1); ++k)\n\t\t{\n\t\t\tfor(int g = 0; g <= 1; ++g)\n\t\t\t{\n\t\t\t\tcalc_t& val = f[n][k][g];\n\t\t\t\tfor(int n1 = 0, n2 = n - 1; n1 <= n2; ++n1, --n2)\n\t\t\t\t{\n\t\t\t\t\tcalc_t ways;\n\t\t\t\t\tif(n1 != n2) ways = C[n - 1][n1];\n\t\t\t\t\telse ways = C[n - 2][n1 - 1];\n\t\t\t\t\tif(n1) ways = ways * n1 * n2 % mod_v;\n\t\t\t\t\telse ways = ways * n2 % mod_v;\n\n\t\t\t\t\tfor(int k1 = 0; k1 + g <= k; ++k1)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k2 = k - k1 - g;\n\t\t\t\t\t\tif(g == 0) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tval += f[n1][k1][1] * f[n2][k2][1] % mod_v * ways % mod_v;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tval += (f[n1][k1][1] * f[n2][k2][0]\n\t\t\t\t\t\t\t\t + f[n1][k1][0] * f[n2][k2][1]\n\t\t\t\t\t\t\t\t + f[n1][k1][0] * f[n2][k2][0]) % mod_v * ways % mod_v;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tval %= mod_v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstd::cout << (f[n0][k0][0] + f[n0][k0][1]) % mod_v << std::endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics"], "code_uid": "35d3eaef8391d64af420fa4640006281", "src_uid": "f98b740183281943eafd90328854746b", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main(){\n\tint n;\n\tcin>>n;\n\tstring str;\n\tcin>>str;\n\tstring ans;\n\tint start=0;\n\twhile(str!=\"\\0\"){\n\t\tif(str.find(\"ogo\")==string::npos){\n\t\t\tans.append(str);\n\t\t\tbreak;\n\t\t}\n\t\tint pos=str.find(\"ogo\");\n\t\tfor(int i=0;i\n\nusing namespace std ;\ntypedef long long ll;\n\nll a, b, ans;\n\nint main () {\n cin >> a >> b;\n if(a == b) {\n cout << 1;\n return 0;\n }\n long long x = b - a;\n //cout << x << '\\n';\n if (x >= 5){\n cout << 0;\n return 0;\n }\n if (x == 1){\n cout << b % 10;\n return 0;\n }\n ans = 1;\n for (long long i = a + 1; i <= b; ++i){\n ans *= i;\n ans %= 10;\n }\n cout << ans % 10;\n return 0;\n}\n/*\n998244355 998244359\n*/\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "60a7758c7fb2a0007efafd350013730b", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main() {\n\tint n,k,w,i,s=0;\n\tcin>>k>>n>>w;\n\tfor (i=1;i<=w;i++)\n\ts+=i;\n\tcout<\r\nusing namespace std;\r\nint fib[114514];\r\nint main() {\r\n\tchar ch;\r\n\tint cnt = 0;\r\n\twhile (cin >> ch) {\r\n\t\tint y = ch - 65;\r\n\t\tfib[++cnt] = y;\r\n\t}\r\n\tfor (int i = 3; i <= cnt; i++) {\r\n\t int lst = fib[i - 1] + fib[i - 2];\r\n\t lst %= 26;\r\n\t\tif (fib[i] != lst) {\r\n\t\t\tcout << \"NO\" << endl; return 0;\r\n\t\t}\r\n\t}\r\n\tcout << \"YES\";\r\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "5468c08ecdce7701a9ba06ce4f93b750", "src_uid": "27e977b41f5b6970a032d13e53db2a6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define inf (1e9+20)\ntypedef long long int LL;\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nstruct data\n{\n int x,y;\n} a[45],book[45];\nvoid init ()\n{\n int liu=1;\n for (int i=1; i<=3; i++)\n {\n for (int j=1; j<=3; j++)\n {\n book[liu].x=i;\n book[liu].y=j;\n liu++;\n }\n }\n book[0].x=4;\n book[0].y=2;\n return;\n}\nvoid work ()\n{\n init ();\n int n;\n scanf (\"%d\",&n);\n char str[100];\n scanf (\"%s\",str+1);\n int lena=2;\n for (int i=2; i<=n; i++)\n {\n int x=book[str[i-1]-'0'].x;\n int y=book[str[i-1]-'0'].y;\n a[lena].x=book[str[i]-'0'].x-x;\n a[lena].y=book[str[i]-'0'].y-y;\n lena++;\n }\n for (int i=1; i<=3; i++)\n {\n for (int j=1; j<=3; j++)\n {\n int bx=i;\n int by=j;\n if (bx==book[str[1]-'0'].x&&by==book[str[1]-'0'].y) continue;\n int t=2;\n while (t<=n)\n {\n int nx=bx+a[t].x;\n int ny=by+a[t].y;\n //printf (\"%d %d %d %d\\n\",bx,by,nx,ny);\n if (nx>=1&&nx<=3&&ny>=1&&ny<=3 || nx==4&&ny==2)\n {\n bx=nx;\n by=ny;\n }\n else break;\n t++;\n }\n if (t==n+1)\n {\n //printf (\"%d %d\\n\",i,j);\n printf (\"NO\\n\");\n return ;\n }\n }\n }\n int bx=4;\n int by=2;\n int t=2;\n if (bx==book[str[1]-'0'].x&&by==book[str[1]-'0'].y) t=inf;\n while (t<=n)\n {\n int nx=a[t].x+bx;\n int ny=a[t].y+by;\n if (nx>=1&&nx<=3&&ny>=1&&ny<=3 || nx==4&&ny==2)\n {\n bx=nx;\n by=ny;\n }\n else break;\n t++;\n if (t==n+1)\n {\n printf (\"NO\\n\");\n return ;\n }\n }\n printf (\"YES\\n\");\n return ;\n}\n\n\nint main ()\n{\n#ifdef local\n freopen(\"data.txt\",\"r\",stdin);\n#endif\n work ();\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "ab80e9dcbdb3b4c9d145a67e1c8e1452", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n#define pb push_back\n#define ppb pop_back\n#define pf push_front\n#define ppf pop_front\n#define all(x) (x).begin(),(x).end()\n#define sz(x) (int)((x).size())\n// #define int long long\n#define M 1000000007\n#define MOD 1000000007\n#define MM 998244353\n#define fr first\n#define sc second\n#define pii pair\n#define rep(i,a,b) for(int i=a;iistream& operator>>(istream& in,pair &a){in>>a.fr>>a.sc;return in;}\ntemplateostream& operator<<(ostream& out,pair a){out<pair operator+=(pair &a,pair b){a.fr+=b.fr;a.sc+=b.sc;return a;}\ntemplatepair operator-=(pair &a,pair b){a.fr-=b.fr;a.sc-=b.sc;return a;}\ntemplatepair operator+(pair a,pair b){a.fr+=b.fr;a.sc+=b.sc;return a;}\ntemplatepair operator-(pair a,pair b){a.fr-=b.fr;a.sc-=b.sc;return a;}\ntemplateT amax(T &a,T1 b){if(b>a)a=b;return a;}\ntemplateT amin(T &a,T1 b){if(b= MOD) v %= MOD;\n val = v;\n }\n \n static int mod_inv(int a, int m = MOD) {\n // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example\n int g = m, r = a, x = 0, y = 1;\n \n while (r != 0) {\n int q = g / r;\n g %= r; swap(g, r);\n x -= q * y; swap(x, y);\n }\n \n return x < 0 ? x + m : x;\n }\n \n explicit operator int() const {\n return val;\n }\n \n mod_int& operator+=(const mod_int &other) {\n val += other.val;\n if (val >= MOD) val -= MOD;\n return *this;\n }\n \n mod_int& operator-=(const mod_int &other) {\n val -= other.val;\n if (val < 0) val += MOD;\n return *this;\n }\n \n static unsigned fast_mod(uint64_t x, unsigned m = MOD) {\n return x%m;\n }\n \n mod_int& operator*=(const mod_int &other) {\n val = fast_mod((uint64_t) val * other.val);\n return *this;\n }\n \n mod_int& operator/=(const mod_int &other) {\n return *this *= other.inv();\n }\n \n friend mod_int operator+(const mod_int &a, const mod_int &b) { return mod_int(a) += b; }\n friend mod_int operator-(const mod_int &a, const mod_int &b) { return mod_int(a) -= b; }\n friend mod_int operator*(const mod_int &a, const mod_int &b) { return mod_int(a) *= b; }\n friend mod_int operator/(const mod_int &a, const mod_int &b) { return mod_int(a) /= b; }\n \n mod_int& operator++() {\n val = val == MOD - 1 ? 0 : val + 1;\n return *this;\n }\n \n mod_int& operator--() {\n val = val == 0 ? MOD - 1 : val - 1;\n return *this;\n }\n \n mod_int operator++(int32_t) { mod_int before = *this; ++*this; return before; }\n mod_int operator--(int32_t) { mod_int before = *this; --*this; return before; }\n \n mod_int operator-() const {\n return val == 0 ? 0 : MOD - val;\n }\n \n bool operator==(const mod_int &other) const { return val == other.val; }\n bool operator!=(const mod_int &other) const { return val != other.val; }\n \n mod_int inv() const {\n return mod_inv(val);\n }\n \n mod_int pow(long long p = MOD-2) const {\n assert(p >= 0);\n mod_int a = *this, result = 1;\n \n while (p > 0) {\n if (p & 1)\n result *= a;\n \n a *= a;\n p >>= 1;\n }\n \n return result;\n }\n \n friend ostream& operator<<(ostream &stream, const mod_int &m) {\n return stream << m.val;\n }\n friend istream& operator>>(istream &stream, mod_int &m) {\n return stream >> m.val;\n }\n};\n\nmod_int P[N];\n// int d[N];\n// int num[N];\nmod_int ele[N];\nvoid solve(){\n\tint n,k;\n\tcin>>n>>k;\n\trep(i,1,k+4){\n\t\tmod_int j=i;\n\t\tP[i]=P[i-1]+j.pow(k);\n\t\t// P[i]%=M;\n\t}\n\tif(n<=k+2){\n\t\tcout<>t;\n\twhile(t--) solve();\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "f48bb2cd945831e76209aa3e0dde0bdf", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17 (64)", "source_code": "#include\nusing namespace std;\n#define N 205\ntypedef long long ll;\nint n,mod,ans;\nint dp[N][N][N],fac[N],ifac[N];\nint qpow(int a,int b){\n\tint ans=1;\n\twhile(b){\n\t\tif(b&1)ans=1LL*ans*a%mod;\n\t\ta=1LL*a*a%mod;\n\t\tb>>=1;\n\t}\n\treturn ans;\n}\nvoid init(int n){\n\tfac[0]=1;\n\tfor(int i=1;i<=n;++i){\n\t\tfac[i]=1LL*fac[i-1]*i%mod;\n\t}\n\tifac[n]=qpow(fac[n],mod-2);\n\tfor(int i=n-1;i>=0;--i){\n\t\tifac[i]=1LL*ifac[i+1]*(i+1)%mod;\n\t}\n}\nint a1;\nint dfs(int i,int j,int k){ // a_1+...+a_i=j,a_i=k\n\tif(!k)return !j?ifac[i]:0;\n\tif(n-i>n>>mod;\n\tinit(n);\n\tfor(a1=max(1,n-25);a1<=n+1;++a1){\n\t\tmemset(dp,-1,sizeof(dp));\n\t\tfor(int sum=1;sum<=a1;++sum){\n\t\t\tans=(ans+dfs(n,sum,n+1-a1))%mod;\t\n\t\t}\n\t}\n\tcout<<(1LL*ans*fac[n]+1)%mod<<'\\n';\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "4af83873a31afd5a2df5eabbfa6e2eb9", "src_uid": "cf57508de47d80bc983861f70bb5f3d6", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "// author: Ryuuk\n#include\n#define sz(a) int((a).size())\n#define pb push_back\n#define all(c) (c).begin(),(c).end()\n#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)\n#define present(c,x) ((c).find(x) != (c).end())\n#define cpresent(c,x) (find(all(c),x) != (c).end())\n#define LSOne(i) (i&(-i))\n#define REP(i,a,b) for(int(i)=(a);(i)<(b);i++)\n#define BUG(x) {cout<<#x<<\" = \"<>1) +1)\n#define middle(s,e)(s+(e-s)/2)\n#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))\n#define CL(A,I) (memset(A,I,sizeof(A)))\n\nstatic const int INF = 0x3f3f3f3f;\nstatic const long long INFL = 0x3f3f3f3f3f3f3f3fLL;\nstatic const long double epsilon = 1e-15;\nstatic const long double pi = acos((long double) -1);\nusing namespace std;\ninline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}\nvoid read(int &number)\n{\n bool negative = false;\n register int c;\n number = 0;\n c = getchar();\n if (c=='-')\n {\n negative = true;\n c = getchar();\n }\n for (; (c>47 && c<58); c=getchar())\n number = number *10 + c - 48;\n if (negative)\n number *= -1;\n}\n\ntypedef vector vi;\ntypedef vector vvi;\ntypedef pair ii;\ntypedef long long ll;\n\n\nint main()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\",\"r\",stdin);\n //freopen(\"output.txt\",\"w\",stdout);\n #endif // ONLINE_JUDGE\n init_io();\n int n , pos, l ,r ;\n cin>>n>>pos>>l>>r;\n int a = 1, b = n ;\n int res ;\n if(pos>=l && pos <=r && ar)\n {\n int x = min(pos-l, r-pos);\n res=x+1 + r-l+1;\n }\n else if(pos>=l && pos <=r)\n {\n if(a==l && b==r)\n res = 0;\n else if(a==l)\n {\n res = r-pos +1;\n }\n else if(b==r)\n {\n res = pos-l +1;\n }\n }\n else if(posr)\n res = (l-pos+1) + r-l +1;\n else\n res = (l-pos+1);\n }\n else if(pos>r)\n {\n if(a\n#include\n#include\n#include\n#include\nusing namespace std;\nchar s[1005],a;\nint main(){\n//\tfreopen(\"cp.in\",\"r\",stdin);\n\tint l=0;\n\twhile(~scanf(\"%c\",&a)) s[++l]=a;\n\tfor(int i=l;i;i--)\n\t\tif(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'){ \n\t\t\tif(s[i]=='Y'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y'){printf(\"YES\");return 0;}\n\t\t\tbreak;\n\t\t}\n\tprintf(\"NO\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "a9eaad422e8561288820c6ca65ec5bba", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n\n#define double long double\n#define int long long\n#define vec vector\n#define pb push_back\n#define unset unordered_set\n#define ii pair\n#define X first\n#define Y second\n#define FOR(i, a, b) for(int i = (a); i < (b); i++)\n#define FORE(i, a, b) for(int i = (a); i <= (b); i++)\n#define FORD(i, a, b) for(int i = (a); i >= (b); i--)\n#define bitcount(n) __builtin_popcountll(n)\ntemplate \nstd::pair operator+(const std::pair & l,const std::pair & r) {\n return {l.first+r.first,l.second+r.second};\n} \ntypedef void (*callback_function)(void); // type for conciseness\nconst long long INF64 = 1e18;\nconst int INF32 = 1e9;\nconst int MOD = 1e9 + 7;\nconst double PI = acos(-1.0L);\nconst double EPS = static_cast(1e-9);\ntypedef long long ll;\n#undef int\nint main() {\n#define int long long\n\tios_base::sync_with_stdio(false);\n\tcin.tie();\n //auto beginProgram = chrono::steady_clock::now();\n\n/* Tutorial by Bugman\n448B - Suffix Structures\n\nSolution:7139584\n\nConsider each case separately. If we use only suffix automaton then s transform\nto some of its subsequence. Checking that t is a subsequence of s can be \nperformed in different ways. Easiest and fastest \u2014 well-known two pointers \nmethod. In case of using suffix array we can get every permutation of s. If it \nis not obvious for you, try to think. Thus, s and t must be anagrams. If we \ncount number of each letter in each string, we can check this. If every letter \nappears in s the same times as in t then words are anagrams. In case of using \nboth structures strategy is: remove some letters and shuffle the rest. It is \npossible if every letter appears in s not less times than in t. Otherwise it is\nimpossible to make t from s. Total complexity O(|s|\u2009+\u2009|t|\u2009+\u200926).\n*/\n\n {// Code goes here\n string s, t; cin >> s >> t;\n vec cntS(256, 0), cntT(256, 0);\n for (char &ch : s) cntS[ch]++;\n for (char &ch : t) cntT[ch]++;\n FORE(i, 'a', 'z') if (cntS[i] < cntT[i]) {\n cout << \"need tree\" << endl; return 0;\n }\n int i = 0, j = 0;\n while (j < t.length()) {\n while (i < s.length() && s[i] != t[j]) i++;\n if (i == s.length()) {\n cout << (s.length() != t.length() ? \"both\" : \"array\") << endl; \n return 0;\n }\n i++, j++;\n }\n cout << \"automaton\" << endl;\n }\n\n //auto endProgram = chrono::steady_clock::now();\n\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "8fcdcab9ea141ca62660e61660047070", "src_uid": "edb9d51e009a59a340d7d589bb335c14", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n\ntypedef unsigned long long ll;\n\nusing namespace std;\n\nstruct Point {\n\tint x, y, k;\n};\n\ndouble pi = 3.14159265358979;\n\ndouble RAD(double x1, double y1, double x2, double y2) {\n\tif (!(sqrt(x1*x1 + y1 * y1)*sqrt(x2*x2 + y2 * y2)))\n\t{\n\t\treturn pi / 2;\n\t\treturn 0;\n\t}\n\tdouble r = acos((x1*x2 + y1 * y2) / (sqrt(x1*x1 + y1 * y1)*sqrt(x2*x2 + y2 * y2)));\n\treturn double(abs(r) + (r < 0)*(pi / 2));\n}\n\nint main()\n{\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\tcout.tie(0);\n\tint n, p;\n\tcin >> n >> p;\n\tint minn = -1;\n\tint k = 0;\n\tfor (int i = 1; i <= 1000; i++)\n\t{\n\t\tif (n - p * ii))\n\t\t{\n\t\t\tminn = i;\n\t\t}\n\t\tk = 0;\n\t}\n\tcout << minn;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "bitmasks"], "code_uid": "1badcfe1ee462fa9567c016ac814c5cb", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n\n/* A. Olympiad */\n\nusing namespace std;\ntypedef long long ll;\n\nint n, a[105], res, vis[605];\n\nint main(int argc, char * argv[]) \n{\n\tscanf(\"%d\", &n);\n for (int i = 0; i < n; i ++)\n scanf(\"%d\", &a[i]);\n sort(a, a + n);\n res = 0;\n memset(vis, 0, sizeof(vis));\n for (int i = 0; i < n; i ++)\n {\n \tif (a[i] != 0 && !vis[a[i]])\n \t{\n \t\tres ++;\n \t\tvis[a[i]] = 1;\n \t}\n }\n cout << res << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["sortings", "implementation"], "code_uid": "2584514af63eea42716915086f4ddff8", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "//194 A\n#include\nusing namespace std;\nint main()\n{\n int n,k;\n cin>>n>>k;\n\n if(k>2*n)\n {\n k = k - 2*n;\n if(k>n)\n cout<<0;\n else\n cout<\r\n\r\nusing namespace std;\r\n\r\nint main(){\r\n\tint t;\r\n\tcin >> t;\r\n\tvector> a(2,vector(2));\r\n\twhile(t--){\r\n\t\tint cnt=0;\r\n\t\tfor(int i=0; i<2; i++){\r\n\t\t\tfor(int j=0; j<2; j++){\r\n\t\t\t\tcin >> a[i][j];\r\n\t\t\t\tif(a[i][j]==1) cnt++;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(cnt==0){\r\n\t\t\tcout << 0 << endl;\r\n\t\t}\r\n\t\telse if(cnt==4){\r\n\t\t\tcout << 2 << endl;\r\n\t\t}\r\n\t\telse{\r\n\t\t\tcout << 1 << endl;\r\n\t\t}\r\n\t}\r\n}\r\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "437854d6c56dbda28f62e44cdea2dc22", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint n,b[5051],sum;\nint main(){\n scanf(\"%d\",&n);\n for(int i=1;i<=100;i++)\n {\n sum+=i;\n b[sum]=1;\n }\n if(b[n]) \n cout<<\"YES\";\n else cout<<\"NO\";\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "c2edf5d953507bd21d20a9d97e2c2fb8", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define db(x) cout<=(n);--i)\n#define pair(a,b) make_pair(a,b)\n#define pb(a) push_back(a)\n#define vi vector\n#define pi pair\n#define vpi vector>\n//#define um unordered_map\n#define ff first\n#define ss second\n#define all(a) a.begin(),a.end()\n// #define mod 1000000007\n#define mod 1073741824\n#define MAX_N 100000\nusing namespace std;\nusing ll = long long int;\nint dx[] = {0,1,0,-1};\nint dy[] = {1,0,-1,0};\n\n\nstring check(string &s, int k) {\n\n\tint n = s.length();\n\n\tset> st;\n\n\trep(i,k)\n\tst.insert(i+'a');\n\n\tstring ans = \"IMPOSSIBLE\";\n\n\trep(i,s.length()) {\n\t\tif(st.find(s[i])!=st.end())\n\t\tst.erase(s[i]);\n\t}\n \n\t\n\tint i,j;\n\t\n\tif (n%2) {\n\t\t//odd;\n\t\t i = n/2-1;\n\t\t j = n/2+1;\n\t\tif(s[n/2]=='?'){\n\t\t\tif(st.size())\n\t\t\t{\n\t\t\t\ts[n/2] = *st.begin();\n\t\t\t\tst.erase(s[n/2]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\ts[n/2] = 'a';\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\ti=n/2-1;\n\t\tj=n/2;\n\t}\n\t\n\twhile(i>=0 && j=0 && j=k)\n\t\t\t\treturn ans;\n\t\t}\n\t\t\n\t\ti--;\t\n\t\tj++;\n\t}\n\t\n\t\n\t\t\n\trep(i,s.length()) {\n\t\tif (s[i] == '?')\n\t\t\ts[i] = 'a';\n\t}\n\t\t\n\treturn s;\n\n}\n\nvoid solve() {\n\t\n\tint k;\n\tcin>>k;\n\t\n\tstring s;\n\tcin>>s;\n\t\n\ts = check(s,k);\n\t\n\tdb1(s);\n\t\n\t\n}\n\nint main(){\n\n \n int t = 1;\n //cin>>t;\n\nwhile(t--){\n solve();\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["expression parsing"], "code_uid": "b323ad67037dd2c0d602ceba9e95cf0b", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\nint main(){\n int a,b; cin >> a >> b;\n int sum=0;\n if(abs(a-b)%2==0){\n for(int i=1;i<=abs(a-b)/2;i++){\n sum += i;\n }\n cout << 2*sum << \"\\n\";\n }\n else {\n int diff = abs(a-b)/2;\n int d1=diff+1;\n int d2=diff;\n for(int i=1;i<=d1;i++) sum+=i;\n for(int i=1;i<=d2;i++) sum+=i;\n cout << sum << \"\\n\";\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "c5a30374ff9c39df2271f2c59e395387", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\ntypedef long long int ll;\n\nint main()\n{\n ll n,a,b;\n cin>>n>>a>>b;\n if(min(a,b)>=n)\n cout<<\"YES\\n\";\n else\n cout<<\"NO\\n\";\n \n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "fa328fd5852e1d77aca77ccd16799487", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n#define ll __int64\n#define ull unsigned long long \nconst int N = 5e6+10; \n\nint vis[110][110];\nint f[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};\n\nstruct node {\n\tint x, y, step;\n\tfriend bool operator < (const node n1, const node n2) {\n\t\treturn n1.step > n2.step;\n\t}\n}t, e;\npriority_queueq;\n\nint bfs(int l, int u, int xi, int yi) {\n\te.x=l, e.y=u, e.step=0;\n\tq.push(e);\n\tvis[e.x][e.y] = 1;\n\twhile(!q.empty()) {\n\t\te = q.top(); q.pop();\n\t\tif(e.x == xi && e.y == yi) return e.step;\n\t\tfor(int i = 0; i < 4; i++) {\n\t\t\tt.x = e.x + f[i][0];\n\t\t\tt.y = e.y + f[i][1];\n\t\t\tt.step = e.step + 1;\n\t\t\tif(t.x<0 || t.y<0) continue;\n\t\t\tif(vis[t.x][t.y]) continue;\n\t\t\tvis[t.x][t.y] = 1;\n\t\t\tq.push(t);\n\t\t}\n\t}\n}\n\n\nint main() {\n\tstring s;\n\tcin>>s;\n\tint len = (int)s.size();\n\tint x=0, y=0, xx=0, yy=0;\n\tfor(int i = 0; i < len; i++) {\n\t\tif(s[i] == 'L') y--;\n\t\tif(s[i] == 'R') y++;\n\t\tif(s[i] == 'U') x--;\n\t\tif(s[i] == 'D') x++;\n\t\txx = min(xx, x);\n\t\tyy = min(yy, y);\n\t}\n\txx = -xx, yy = -yy;\n\tfor(int i=0; i<110; i++) {\n\t\tfor(int j=0; j<110; j++) vis[i][j] = 1;\n\t}\n\tx=xx, y=yy;\n\tfor(int i=0; i\n\nusing namespace std;\n\nint main() {\n int m,n,z,lcm;\n cin>>m>>n>>z;\n if(m>n)\n lcm = m;\n else\n lcm = n;\n while(1) {\n if( lcm%m==0 && lcm%n==0 ) {\n cout<\n#include \nusing namespace std;\nusing namespace __gnu_pbds;\ntypedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\nusing pii = pair;\nusing vi = vector ;\n#define F first\n#define S second\n#define pb push_back\n#define lb lower_bound\n#define ub upper_bound\n#define ll long long\n#define ook order_of_key\n#define fbo find_by_order\n#define sq(x) (x) * (x)\n#define N 2005\n\nll n, dp[N][N], ans, mod = 1e9 + 7, sum[N];\nint main (){\n\tcin >> n;\n\tn *= 2;\n\tdp[0][0] = 1;\n\tfor (int i = 0;i < n;i++)\n\t\tfor (int j = 0;j <= n - i;j++){\n\t\t\tsum[i] = (sum[i] + dp[i][j]) % mod; \n\t\t\tif (j) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % mod;\n\t\t\tdp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; \n\t\t}\n\tfor (int i = n - 1;i >= 0;i -= 2)\n\t\tans = (ans + sum[i]) % mod;\n\tcout << ans;\n}", "lang_cluster": "C++", "tags": ["greedy", "dp", "trees"], "code_uid": "5b3b3b56a327dcd4a4a219da0c23a2c0", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\n\n#define sz s.size()\n\nstring s;\n\nint c;\n\nint main () {\n cin >>s;\n for (int i=0;i\n#include\nusing namespace std;\nconst int maxN = 1<<7, maxL = 7, M = 1e9+7;\nstruct Matr {\n int size;\n int ele[maxN][maxN];\n} m[maxL+1];\nint ans, w[maxL+1], dp[maxL][2], sum[maxL+1][maxN];\nint solve(int u, int v, int n) {\n memset(dp, 0, sizeof dp);\n dp[0][1] = 1;\n for (int i = 0; i < n; i++) {\n dp[i+1][0] = (dp[i][0]+dp[i][1])%M;\n dp[i+1][1] = dp[i][0];\n if (((u>>i)&1)==1 || ((v>>i)&1)==1) dp[i+1][1] = (dp[i+1][1]+dp[i][1])%M;\n }\n return dp[n][1];\n}\nvoid init(int x) {\n m[x].size = x;\n for (int i = 0; i < (1<>1);\n t = muti(t, t);\n if (k&1) t = muti(t, x);\n return t;\n}\nint main()\n{\n for (int i = 1; i <= maxL; i++) init(i);\n for (int i = 1; i <= maxL; i++) scanf(\"%d\", &w[i]);\n sum[0][0] = 1;\n for (int i = 1; i <= maxL; i++) \n if (w[i] > 0) {\n m[i] = pow(m[i], w[i]);\n for (int u = 0; u < (1<\n\nusing namespace std;\n\nint main()\n{\n int n,m,a=1;\n cin>>n>>m;\n while (m>=a)\n {\n m-=a;\n a++;\n if (a==n+1)\n {\n a=1;\n }\n }\n cout<\n#include\n#include\nusing namespace std;\n\nint main(){\n int x1, y1, x2, y2, a, b;\n while(cin >> x1 >> y1 >> x2 >> y2){\n cin >> a >> b;\n\n int x = abs(x2 - x1);\n int y = abs(y2 - y1);\n\n if(!a){\n if(!x && y % b == 0) cout << \"YES\" << endl;\n else cout << \"NO\" << endl;\n }\n else if(!b) if(!y && x % a == 0) cout << \"YES\" << endl;\n else cout << \"NO\" << endl;\n else{\n int a1 = x % a;\n int b1 = y % b;\n int a2 = x / a;\n int b2 = y / b;\n// cout << x << \" \" << y << \" \" << a1 << \" \" << b1 << \" \" << a2 << \" \" << b2 << \" \" << endl;\n if(a1 == 0 && b1 == 0){\n if(a2 % 2 == b2 % 2) cout << \"YES\" << endl;\n else cout << \"NO\" << endl;\n }\n else cout << \"NO\" << endl;\n }\n\n }\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation", "number theory"], "code_uid": "839a9dd4a95fb654fb0d1bf772cb7f4c", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define pii pair\n#define fi first\n#define se second\n#define pb push_back\n#define rep(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)\n#define per(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)\nusing namespace std;\ntypedef long long LL;\ntypedef double db;\nint main()\n{\n string s;\n cin>>s;\n int x,d,i;\n x=d=0;\n for(i=0;i='a'&&s[i]<='z')\n x++;\n else\n d++;\n }\n if(x>=d){\n for(i=0;i='a'&&s[i]<='z')\n cout<='A' && s[i]<='Z')\n cout<\nusing namespace std;\nint main()\n{\n int n;cin>>n;\n int a[8];\n for(int i=1;i<=7;i++)\n cin>>a[i];\n int k = n;\n while(n>0)\n for(int i =1 ;i<=7;i++)\n {\n if(a[i] >= n )\n {\n cout<\n#include \nusing namespace std;\n\nint main()\n{\n long int x,t,a,b,da,db;\n scanf(\"%ld %ld %ld %ld %ld %ld\", &x, &t, &a, &b, &da, &db);\n if(x == 0)\n {printf(\"%s \\n\", \"YES\");\n goto exit;}\n else{\n\n for(int tz = 0; tz < t; ++tz)\n {\n for(int tu = 0; tu < t; ++tu)\n {\n if(a - da*tz == x)\n {printf(\"%s \\n\", \"YES\");\n goto exit;}\n }\n }\n\n for(int tz = 0; tz < t; ++tz)\n {\n for(int tu = 0; tu < t; ++tu)\n {\n if(b - db*tu == x)\n {printf(\"%s \\n\", \"YES\");\n goto exit;}\n }\n }\n\n\n for(int tz = 0; tz < t; ++tz)\n {\n for(int tu = 0; tu < t; ++tu)\n {\n if(a - da*tz + b - db*tu == x)\n {printf(\"%s \\n\", \"YES\");\n goto exit;}\n }\n }\n printf(\"%s \\n\", \"NO\");\n }\n exit:\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "725fc651007b85cb5914ca2e215c5443", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \nusing namespace std;\n\nunsigned long long solve(vector& arr, unsigned long long K) {\n\tint N = (int)arr.size();\n\tunsigned long long ret = 0, mul = 1;\n\tfor (int i = N - 1; i >= 0; i--) {\n\t\tret += mul*arr[i];\n\t\tmul *= K;\n\t}\n\treturn ret;\n}\n\nint main() {\n\tunsigned long long N, K;\n\tcin >> N >> K;\n\tvector arr1;\n\tfor (unsigned long long i = 0; i < N; i++) {\n\t\tunsigned long long buf; cin >> buf; arr1.push_back(buf);\n\t}\n\tunsigned long long N2, K2;\n\tcin >> N2 >> K2;\n\tvector arr2;\n\tfor (unsigned long long i = 0; i < N2; i++) {\n\t\tunsigned long long buf; cin >> buf; arr2.push_back(buf);\n\t}\n\n\tunsigned long long val1 = solve(arr1, K);\n\tunsigned long long val2 = solve(arr2, K2);\n\tif (val1 == val2) { puts(\"=\"); }\n\telse if (val1 > val2) { puts(\">\"); }\n\telse { puts(\"<\"); }\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "7da1d1331f5bd53b1bacfeb24be38066", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define pii pair \n#define ll long long int \n#define sl(n) scanf(\"%lld\",&n)\n#define s(n) scanf(\"%d\",&n)\n#define f(n) for(int i=0;imp;\n char imp;\n int impi;\n cin>>s;\n if(s[1]=='>'){\n ans=s[2];\n mp[s[2]]=1;\n ans+=s[0];\n mp[s[0]]=2;\n }\n else{\n ans=s[0];\n mp[s[0]]=1;\n ans+=s[2];\n mp[s[2]]=2;\n }\n \n // cout<>s;\n if(s[1]=='>'){\n \n if(ans[1]==s[2]&&ans[0]==s[0]){\n pf(\"Impossible\\n\");\n return 0;\n }\n int i=0;\n temp=\"\";\n if(mp[s[0]]){\n if(mp[s[2]]>mp[s[0]]){\n pf(\"IMPOSSIBLE\\n\");\n return 0;\n }\n imp=s[0];\n while(true){\n temp+=s[2];\n temp+=ans[i];\n // cout<>s;\n if(ans.size()==3){\n if(s[1]=='>'){\n if(mp[s[0]]mp[s[2]]){\n pf(\"Impossible\\n\");\n return 0;\n }\n else{\n cout<'){\n if(count(ans.begin(),ans.end(),ans[3])==1)\n cout<\n#include \n\nint main() {\n\tint a, b;\n\tscanf(\"%d %d\", &a, &b);\n\tdouble tmp1 = b * log(a);\n\tdouble tmp2 = a * log(b);\n\tif (fabs(tmp1 - tmp2) <= 0.000001f) printf(\"=\");\n\telse if (tmp1 < tmp2) printf(\"<\");\n\telse printf(\">\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "0ca784a29c3413ea9201181c6887cd34", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n long long a,b,c,d,e,f,cost1,cost2;\n cin >> a >> b >> c >> d >> e >> f;\n cost1=min(a,d)*e+min(b,min(c,d-min(a,d)))*f;\n cost2=min(b,min(c,d))*f + min(a,d-min(b,min(c,d)))*e;\n cout <\n\nint main() {\n\tint a, b, y{0};\n\tstd::cin>>a>>b;\n\twhile(a<=b){\n\t\ta *= 3;\n\t b *= 2;\n\t y++;\n\t}\n\tstd::cout<\nusing namespace std;\nint main()\n{\n int x;\n cin>>x; //\u8f93\u5165 \n int a;\n\ta=sqrt(x);//\u5e73\u65b9\u6839\u8ba1\u7b97\uff0c\u66b4\u529b \n\tint i=a; \n\twhile(i!=0)//while\u5faa\u73af \n\t{\n\t\tfor(int j=a;j<=x;j++)\n\t\t{\n if(x==i*j)//\u5c42\u5c42\u5224\u65ad\uff0cif\u662f\u5426\u7b26\u5408\u9898\u610f \n {\n cout<\nusing namespace std;\n#define endl '\\n'\n#define INF 1000000007\n#define eps 1e-9\n#define ll long long\n\nint main()\n{\n\tios::sync_with_stdio(false);\n\tcin.tie(0);\n\n\tint a,x,y;\n\tcin >> a >> x >> y;\n\tif(x >= a)\n\t{\n\t\tcout << -1 << endl;\n\t\treturn 0;\n\t}\n\tif(x <= (-a))\n\t{\n\t\tcout << -1 << endl;\n\t\treturn 0;\n\t}\n\tif(y%a == 0)\n\t{\n\t\tcout << -1 << endl;\n\t\treturn 0;\n\t}\n\tif(y < 2*a)\n\t{\n\t\tif(((double)x) >= ((double)a)/2)\n\t\t{\n\t\t\tcout << -1 << endl;\n\t\t\treturn 0;\n\t\t}\n\t\tif(((double)x) <= (-(double)a)/2)\n\t\t{\n\t\t\tcout << -1 << endl;\n\t\t\treturn 0;\n\t\t}\n\t\tif(y < a)\n\t\t{\n\t\t\tcout << 1 << endl;\n\t\t\treturn 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcout << 2 << endl;\n\t\t\treturn 0;\n\t\t}\n\t}\n\tint t = y/a;\n\tif(t%2 == 1)\n\t{\n\t\tif(2*x>=a)\n\t\t{\n\t\t\tcout << -1 << endl;\n\t\t\treturn 0;\n\t\t}\n\t\tif(2*x+a<=0)\n\t\t{\n\t\t\tcout << -1 << endl;\n\t\t\treturn 0;\n\t\t}\n\t\tcout << 5+3*((t-1)/2 - 1) << endl;\n\t\treturn 0;\n\t}\n\n\tif(x == 0)\n\t{\n\t\tcout << -1 << endl;\n\t\treturn 0;\n\t}\n\n\tif(x < 0)\n\t{\n\t\tcout << 5+3*((t-1-1)/2 - 1)+1 << endl;\n\t}\n\telse\n\t{\n\t\tcout << 5+3*((t-1-1)/2 - 1)+2 << endl;\n\t}\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "geometry"], "code_uid": "9278c39f642e97ad7886dd029477b4ee", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define FOR(i, n) for(int i = 0; i < (n); ++i)\n#define SIZEOF(a) (sizeof(a)/sizeof((a)[0]))\n\ntypedef long long ll;\n\nconst int MAX_N = 1e6+10;\nll a[MAX_N];\nll b[MAX_N];\nll c[MAX_N];\n\nconst int BUFSIZE = 1000000;\nchar buf[BUFSIZE + 1];\nstring nextString() {\n\tscanf(\"%s\", buf); return buf;\n}\n\nint main()\n{\n\tstring s; cin >> s;\n\tsize_t n = s.size();\n\n\tif(s==\"0\"){\n\t\tcout << \"zero\" << endl;\n\t\treturn 0;\n\t}\n\n\tif(n == 2 && s[0]=='1'){\n\t\tint i = 1;\n\t\tif(s[i]=='0') cout << \"ten\";\t\t// 10\n\t\tif(s[i]=='1') cout << \"eleven\";\t\t// 11\n\t\tif(s[i]=='2') cout << \"twelve\";\t\t// 12\n\t\tif(s[i]=='3') cout << \"thirteen\";\n\t\tif(s[i]=='4') cout << \"fourteen\";\n\t\tif(s[i]=='5') cout << \"fifteen\";\n\t\tif(s[i]=='6') cout << \"sixteen\";\n\t\tif(s[i]=='7') cout << \"seventeen\";\n\t\tif(s[i]=='8') cout << \"eighteen\";\n\t\tif(s[i]=='9') cout << \"nineteen\";\n\t\tcout << endl;\n\t\treturn 0;\n\t}\n\n\tif(n == 2){\n\t\tint i = 0;\n\t\tif(s[i]=='2') cout << \"twenty\";\n\t\tif(s[i]=='3') cout << \"thirty\";\n\t\tif(s[i]=='4') cout << \"forty\";\n\t\tif(s[i]=='5') cout << \"fifty\";\n\t\tif(s[i]=='6') cout << \"sixty\";\n\t\tif(s[i]=='7') cout << \"seventy\";\n\t\tif(s[i]=='8') cout << \"eighty\";\n\t\tif(s[i]=='9') cout << \"ninety\";\n\n\t\tif(s[1]=='0'){\n\t\t\tcout << endl;\n\t\t\treturn 0;\n\t\t}else{\n\t\t\tcout << '-';\n\t\t}\n\t}\n\n\tif(n >= 1){\n\t\tint i = n-1;\n\t\tif(s[i]=='1') cout << \"one\";\n\t\tif(s[i]=='2') cout << \"two\";\n\t\tif(s[i]=='3') cout << \"three\";\n\t\tif(s[i]=='4') cout << \"four\";\n\t\tif(s[i]=='5') cout << \"five\";\n\t\tif(s[i]=='6') cout << \"six\";\n\t\tif(s[i]=='7') cout << \"seven\";\n\t\tif(s[i]=='8') cout << \"eight\";\n\t\tif(s[i]=='9') cout << \"nine\";\n\t}\n\tcout << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "718ce796a381e6bbcc03d026ac00f80d", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nint main()\n{\n int n,arr[105]={},s=0,mx=-1,p=0,ans[105]={};\n cin>>n;\n for(int i=0;i>arr[i];\n s+=arr[i];\n if(arr[i]>mx){mx=arr[i];}\n }\n //if(n==1){cout<s){cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n \n#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);\n#define S second\n#define F first\n#define pb push_back\n#define nl '\\n'\n#define NL cout << '\\n';\n#define EX exit(0)\n#define all(s) s.begin(), s.end()\n#define no_answer return cout << 0, 0;\n#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)\n \nconst long long MXN = 1e7 + 200;\nconst long long MNN = 1e4 + 520;\nconst long long MOD = 1e9 + 7;\nconst long long INF = 1e18;\nconst long long OO = 1e9 + 500;\n \ntypedef long long llong;\ntypedef unsigned long long ullong;\n \nusing namespace std;\n\nint n;\nllong x, y, dp[MXN];\n\nvoid bfs(int first){\n queue q;\n q.push(first);\n while(!q.empty()){\n int k = q.front();\n q.pop();\n if(k + 1 <= n && dp[k + 1] > dp[k] + x){\n dp[k + 1] = dp[k] + x;\n q.push(k + 1);\n }\n if(k + k <= n && dp[k + k] > dp[k] + y){\n dp[k + k] = dp[k] + y;\n q.push(k + k);\n }\n if(k + k - 1 >= 1 && k + k - 1 <= n && dp[k + k - 1] > dp[k] + y + x){\n dp[k + k - 1] = dp[k] + y + x;\n q.push(k + k - 1);\n }\n }\n}\n\nint main(){\n cin >> n >> x >> y;\n for(int i = 1; i <= n; i++) dp[i] = INF;\n for(int i = 0; i <= n; i++){\n if(i + 1 <= n) dp[i + 1] = min(dp[i + 1], dp[i] + x);\n if(i + i <= n) dp[i + i] = min(dp[i] + y, dp[i + i]);\n if(i + i - 1 <= n) dp[i + i - 1] = min(dp[i + i - 1], dp[i] + x + y);\n }\n bfs(0);\n cout << dp[n];\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "dp"], "code_uid": "ea1a3826923e88f5ad1ecb8e6c3d055a", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n int c=0,i,j;\n string a;\n getline(cin,a);\n for(i=0;i\ntypedef long long LL;\nstruct pt{\n int x,y;\n pt(){}\n pt(int x,int y):x(x),y(y){}\n void get(){\n scanf(\"%d%d\",&x,&y);\n }\n};\nbool judge(int x1,int y1,int x2,int y2){\n LL t1=1ll*(x1)*x2+1ll*(y1)*y2;\n LL t2=1ll*x2*x2+1ll*y2*y2;\n if(t2==0){\n return x1==0&&y1==0;\n }\n if(t1%t2==0){\n t1/=t2;\n if(x2==0)return x1%y2==0; \n return (y1-t1*y2)%x2==0;\n }\n return 0;\n}\nint main(){\n pt a,b,c;\n a.get();\n b.get();\n c.get();\n for(int i=0;i<4;i++){\n a=pt(-a.y,a.x);\n if(judge(b.x-a.x,b.y-a.y,c.x,c.y)){\n printf(\"YES\");\n return 0;\n }\n }\n printf(\"NO\");\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "ecab8a2b74bfcdc6c9fa592971c620f6", "src_uid": "cc8a8af1ba2b19bf081e379139542883", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tint n,m,k[1001],max=0;\n\tcin>>n>>m;\n\t\n\tfor(int i=0;i>k[i];\n\t}\n\t\n\tfor(int i=1;imax && k[i-1]>k[i])\n\t\t\tmax=k[i-1]-k[i];\n\t}\n\t\n\tif(max==0 ||(max-m)<0)\n\t\tcout<<0<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\ntypedef long long ll;\ntypedef unsigned long long ull;\n#define PI acos(-1.0)\n#define rep(i,a,b) for (int i = a; i < b; i++)\n#define all(x) x.begin(), x.end()\n#define sz(a) (int)a.size()\n#define sqr(x) ((x) * (x))\n#define pi pair\n#define mk(a, b) make_pair(a, b)\n#define nextI nextInt()\n#define nextD nextDouble()\n#define nextL nextLong()\n#define nextC nextChar()\n#define line newLine()\nint nextInt(){ int x; scanf(\"%d\", &x); return x; }\ndouble nextDouble(){ double x; scanf(\"%lf\", &x); return x; }\nll nextLong(){ ll x; scanf(\"%I64d\", &x); return x; }\nchar nextChar(){ char x; scanf(\"%c\", &x); return x; }\nvoid newLine(){ printf(\"\\n\"); }\nll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }\nll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }\nll powM(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }\nint countBitSet(ll n){ int ans = 0; while (n != 0){ n -= (n & -n); ++ans; } return ans; }\nll mod = ll(1e9 + 7);\nll mod2 = ll(1e9 + 9);\nconst int N = 100100;\nconst int M = 100;\nconst double eps = (double)1e-6;\nusing namespace std;\nstring str[55];\nll cnt[1 << 20];\ndouble dp[1 << 20];\nint main(){\n#ifdef HOME\n\tfreopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n\t//clock_t t1 = clock();\n#endif\n\n\tint m = nextI;\n\tfor (int i = 0; i < m; i++) cin >> str[i];\n\tint n = str[0].length();\n\tfor (int i = 0; i < m; i++){\n\t\tfor (int j = i + 1; j < m; j++){\n\t\t\tint mask = 0;\n\t\t\tfor (int k = 0; k < n; k++){\n\t\t\t\tif (str[i][k] == str[j][k]) mask |= (1 << k);\n\t\t\t}\n\t\t\tcnt[mask] |= (1ll << i) | (1ll << j);\n\t\t}\n\t}\n\tfor (int s = (1 << n) - 1; s > 0; s--){\n\t\tfor (int i = 0; i < n; i++){\n\t\t\tif (s & (1 << i))\n\t\t\t\tcnt[s - (1 << i)] |= cnt[s];\n\t\t}\n\t}\n\n\tdp[0] = 1;\n\tfor (int i = 1; i <= n; i++){\n\t\tdp[i] = dp[i - 1] * (1.0 / (n - i + 1)) * i;\n\t}\n\tfor (int k = 0; k < (1 << n); k++) cnt[k] = m - countBitSet(cnt[k]);\n\tdouble ans = 0;\n\tfor (int s = 1; s < (1 << n); s++){\n\t\tint num = countBitSet(s);\n\t\tfor (int i = 0; i < n; i++){\n\t\t\tif (s & (1 << i)){\n\t\t\t\t//int f1 = m - countBitSet(cnt[s]);\n\t\t\t\t//int f2 = m - countBitSet(cnt[s - (s & (1 << i))]);\n\t\t\t\tans += dp[num] * (cnt[s] - cnt[s - (s & (1 << i))]);\n\t\t\t}\n\t\t}\n\t}\n\tcout << fixed << setprecision(20) << ans/(1.0 * m) << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp", "bitmasks"], "code_uid": "fef9949d959e1ce20c8a7a258ca401fc", "src_uid": "a95d9aef6a64c30e46330dcc8e6d4a67", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define exp 1e-10\nusing namespace std;\n\n#define REP(i, n) for(int i = 0; i < (n); ++i)\n#define FOR(i, j, k) for(int i = (j); i <= (k); ++i)\n#define pii pair\n#define fr first\n#define sc second\n\nint ans[] {\n1,\n0,\n18,\n0,\n1800,\n0,\n670320,\n0,\n734832000,\n0,\n890786230,\n0,\n695720788,\n0,\n150347555,\n0\n};\n\nint main() {\n\tint n;\n\tcin >> n;\n\tcout << ans[n - 1];\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "bitmasks", "meet-in-the-middle", "implementation"], "code_uid": "1671bc5ac1464642151aed06e2f404ab", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\ntypedef long long ll;\ntypedef vector vi;\ntypedef vector vl;\ntypedef pair pii;\ntypedef pair pll;\ntypedef vector vii;\ntypedef vector vll;\n\nconst double PI = acos(-1);\n#define MOD 1000000007 ///1e9+7\n\n#define pb push_back\n#define F first\n#define S second\n#define test int tc; cin>>tc; while(tc--)\n#define forn(i,n) for(i=0;i=0;i--)\n#define all(a) a.begin(),a.end()\n#define rall(a) a.rbegin(),a.rend()\n#define sz(x) x.size()\n#define el <<'\\n'\n#define sp <<' '\n\n#define mem(a,b) memset(a, b, sizeof(a))\n#define gcd(a,b) __gcd(a,b)\n#define lcm(a,b) (a*(b/gcd(a,b)))\n#define sqr(a) (a)*(a)\n\n#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n#define file() freopen(\"input.txt\",\"r\",stdin);freopen(\"output.txt\",\"w\",stdout);\n#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);\n\n///******************************** C o d e ********************************///\nll x,y,c;\n\nvoid _case()\n{\n c=8;\n set mx,my;\n set m;\n while(c--){\n cin>>x>>y;\n mx.insert(x);\n my.insert(y);\n m.insert({x,y});\n }\n c=sz(m);\n if(sz(mx)!=3 or sz(my)!=3 or c!=8) cout<<\"ugly\" el;\n else{\n set::iterator i,j;\n i=mx.begin(); i++;\n j=my.begin(); j++;\n ///cout<F sp<F el;\n ///cout<\r\n\r\nconstexpr int N = 1000005;\r\nconstexpr int p = 998244353;\r\nconstexpr int inv2 = 499122177;\r\nconstexpr int inv6 = 166374059;\r\n\r\nint add(int x, int y) { return (x += y) >= p ? x - p : x; }\r\nint sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }\r\nint mul(int x, int y) { return (long long)x * y % p; }\r\n\r\nint n;\r\nint f[N];\r\n\r\nint main() {\r\n std::ios::sync_with_stdio(false), std::cin.tie(nullptr);\r\n std::cin >> n;\r\n f[0] = 1;\r\n int sum = 0;\r\n for (int i = 1; i <= n; ++i) {\r\n f[i] = mul(f[i - 1], add(add(sum, 1), mul(f[i - 1] + 1, inv2)));\r\n sum = add(sum, f[i - 1]);\r\n }\r\n sum = sub(sum, f[n - 1]);\r\n int ans = add(add(f[n], mul(f[n - 1], mul(mul(sum, add(sum, 1)), inv2))), add(mul(mul(mul(f[n - 1], add(f[n - 1], 1)), inv2), sum), mul(mul(mul(f[n - 1], add(f[n - 1], 1)), add(f[n - 1], 2)), inv6)));\r\n ans = sub(mul(ans, 2), 1);\r\n for (int i = 0; i < n - 1; ++i) ans = add(ans, mul(sub(f[i], 1), sub(f[n - i - 1], f[n - i - 2])));\r\n std::cout << ans << '\\n';\r\n return 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "trees"], "code_uid": "811a0ceb56dc6508047f3d4b671b1de9", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": " \n#include \n#include \n \nusing namespace std;\n \nint main ()\n{\n int n;\n int m;\n int a;\n \n scanf (\"%d %d %d\", &n, &m, &a);\n \n long long flagsByRow;\n \n if (n % a == 0) {\n flagsByRow = n / a;\n \n } else {\n flagsByRow = n / a;\n flagsByRow++;\n \n }\n \n long long flagsByColumn;\n \n if (m % a == 0) {\n flagsByColumn = m / a;\n \n } else {\n flagsByColumn = m / a;\n flagsByColumn++;\n \n }\n \n cout << flagsByRow * flagsByColumn << endl;\n \n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "0222150df1717d81ba0ecf30637ba8f6", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "# include \nusing namespace std;\nint a[110];\nint main()\n{\n\tint n,k,m=0;\n\tcin>>n>>k;\n\tfor(int i=0;i>a[i];\n\t}\n\tfor(int i=0;im)\n\t\t\tm=a[i];\n\t\t}\n\t}\n\tcout<\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nvoid solve() {\n\tlong long n;\n\tcin>>n;\n\n\tlong long d = 1;\n\tif (n%2!=0){\n\t\td= -1;\n\t}\n\t\n\tcout.precision(0);\n\tcout << fixed << ceil(n/2.0)*d;\n}\n\n/*\nint main() {\n\tint t;\n\tcin >> t;\n\n\twhile (t--) {\n\t\tsolve();\n\t}\n\n\treturn 0;\n}\n*/\n\nint main() {\n\tsolve();\n\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "09ed46079d1b91b133552610f8c51f5f", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n\tint n,k;\n\tcin>>n>>k;\n\tvectora(n);\n\tfor(int i=0;i>a[i];\n\tint result=0;\n\tint start_i,end_i;\n\tstart_i=0;\n\tend_i=n-1;\n\twhile(1&&(end_i>=start_i))\n\t{\n\t\tif(a[start_i]<=k)\n\t\t{\n\t\t\tresult++;\n\t\t\tstart_i++;\n\t\t}\n\t else if(a[end_i]<=k)\n\t\t{\n\t\t\tresult++;\t\n\t\t\tend_i--;\n\t\t}\n\t\telse\n\t\tbreak;\n\t}\n\tcout<\n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nstruct node\n{\n int sum;\n int id;\n} b[5], t;\n\nint a[30];\n\nint main()\n{\n int n;\n while (~scanf(\"%d\", &n))\n {\n memset(b, 0, sizeof(b));\n for (int i = 1; i <= n; i++)\n scanf(\"%d\", &a[i]);\n int sum1 = 0, sum2 = 0, sum3 = 0;\n for (int i = 1; i <= n; i++)\n {\n if (i % 3 == 1)\n sum1 += a[i];\n if (i % 3 == 2)\n sum2 += a[i];\n if (i % 3 == 0)\n sum3 += a[i];\n }\n b[0].sum = sum1, b[0].id = 1;\n b[1].sum = sum2, b[1].id = 2;\n b[2].sum = sum3, b[2].id = 3;\n for (int i = 0; i < 3 - 1; i++)\n for (int j = 0; j < 3 - i - 1; j++)\n {\n if (b[j].sum < b[j + 1].sum)\n {\n t = b[j];\n b[j] = b[j + 1];\n b[j + 1] = t;\n }\n else if (b[j].sum == b[j + 1].sum && b[j + 1].id < b[j].id)\n {\n t = b[j];\n b[j] = b[j + 1];\n b[j + 1] = t;\n }\n }\n if (b[0].id == 1)\n printf(\"chest\\n\");\n else if (b[0].id == 2)\n printf(\"biceps\\n\");\n else if (b[0].id == 3)\n printf(\"back\\n\");\n }\n return 0;\n}\n\n\t\t \t \t \t\t \t \t \t \t\t\t", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "bf56a828c04363ad8cd79610ebb1fd25", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n\nint main(){\n\tint n;\n\tcin>>n;\n\tint r[n+5],b[n+5];\n\tint x=0,y=0;\n\tfor(int i=0;i>r[i];\n\t}\n\tfor(int i=0;i>b[i];\n\t\tif(b[i]==1&&r[i]==0) y++;\n\t\tif(r[i]==1&&b[i]==0) x++;\n\t}\n\t//cout<\n#include\n#include\n#include\nusing namespace std;\nconst int inf=2000+5;\nint memo[inf][inf],m;\nint pow_mod(int x,int y)\n{\n if(y==0)\n return 1%m;\n\n if(y==1)\n return x%m;\n\n if(~memo[x][y])\n return memo[x][y];\n\n int ret=pow_mod(x,y/2) %m ;\n\n ret=( (ret%m) * (ret%m) )%m;\n\n return memo[x][y]=( pow_mod(x,y%2) *ret )%m;\n}\nint main()\n{\n int x,y,temp,cnt=0;\n bool fg;\n cin>>m;\n memset(memo,-1,sizeof memo);\n for(x=1;x\n\n#define MAX 100005\n#define MOD 1000000007\n#define eps 1e-7\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef complex point;\n\n#define pii pair\n#define pip pair\n#define F first\n#define S second\n#define bits(x) __builtin_popcount(x)\n#define X real()\n#define Y imag()\n\nint ar[] = {0 ,0 ,1 ,-1};\nint ac[] = {1 ,-1 ,0 ,0};\nll fast_pow(int n , int m){\n ll res = 1;\n ll p = n;\n while(m){\n if(m % 2)\n res *= p;\n p *= p;\n m /= 2;\n }\n return res;\n}\nint n;\nll c(int m ,int r){\n ll res = 1;\n for(int i = 0 ;i < r ;i++)\n res = (res * (m - i))/(i + 1);\n return res;\n}\nll p(int m ,int r){\n ll res = 1;\n for(int i = 0 ;i < r ;i++)\n res = (res * (m - i));\n return res;\n}\nint main(){\n#ifdef Code_Breakers\n freopen(\"input.txt\", \"r\", stdin);\n // freopen(\"input.txt\" ,\"w\" ,stdout);\n#endif //Code Breakers\n ios_base::sync_with_stdio(false);cin.tie(0);\n cout << fixed << setprecision(6);\n cin >> n;\n cout << c(n ,5) * p(n ,5);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "8c5c4211240aa23efa6df6bffb17d930", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tchar s[1000];\n\tint a[1000]={0};\n\tcin>>s;\n\tfor(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include\n//CLOCKS_PER_SEC\n#define se second\n#define fi first\n#define ll long long\n#define lson l,m,rt<<1\n#define rson m+1,r,rt<<1|1\n#define Pii pair\n#define Pli pair\n#define ull unsigned long long\n#define pb push_back\n#define fio ios::sync_with_stdio(false);cin.tie(0)\nconst double Pi=3.14159265;\nconst int N=3e5+50;\nconst ull base=163;\nconst int INF=0x3f3f3f3f;\nusing namespace std;\nint a[N];\nint b[N];\nint mp[N];\nint main(){\n fio;\n int n,m;\n cin>>n>>m;\n for(int i=1;i<=n;i++){\n cin>>a[i];\n mp[a[i]]=1;\n }\n int MIN=INF;\n for(int i=1;i<=m;i++){\n cin>>b[i];\n if(mp[b[i]])MIN=min(MIN,b[i]);\n }\n sort(a+1,a+1+n);\n sort(b+1,b+1+m);\n int x=a[1]*10+b[1];\n int y=b[1]*10+a[1];\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define F first\n#define S second\n#define pb push_back\n#define INF 1<<30\n#define mp make_pair\n#define pi pair\n#define readString(s) gets(rs);s = rs\n#define y1 yyy1\n#define y2 yyy2\n#define SQR(a) ((a)*(a))\n\n#define swag swap\n\nusing namespace std;\n\nconst int N = 111;\n\nchar buff[N];\n\nint r1, c1, r2, c2;\n\nint main()\n{\n #define TASKNAME \"disease\"\n\n #ifdef DEBUG\n freopen(\"input.txt\", \"r\", stdin);\n //freopen(\"output.txt\", \"w\",stdout);\n #else\n //freopen(TASKNAME\".in\", \"r\", stdin);\n //freopen(TASKNAME\".out\", \"w\", stdout);\n #endif\n\n scanf(\"%d%d%d%d\", &r1, &c1, &r2, &c2);\n\n int a1 = 0, a2 =0, a3 = 0;\n\n if (r1 == r2 || c1 == c2)\n a1 = 1;\n else\n a1 = 2;\n\n if (abs(r1 - r2) == abs(c1 - c2))\n a2 = 1;\n else\n if ((r1 + c1)%2 != (r2+c2)%2)\n a2 = 0;\n else\n a2 = 2;\n\n a3 = max(abs(r1 - r2), abs(c1-c2));\n\n printf(\"%d %d %d\", a1, a2, a3);\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "graphs", "shortest paths"], "code_uid": "9de3f0216f09345758fd01429186ac10", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\nusing namespace std;\n#define endl '\\n'\nint main()\n{\n\tint x;\n\tint y;\n\tint c = 1;\n\tcin >> x >>y;\n\tfor (int i = 1; true; i++)\n\t{\n\t\tif (i % 2 != 0)\n\t\t{\n\t\t\tif (x > 1 && y > 1)\n\t\t\t{\n\t\t\t\tx -= 2;\n\t\t\t\ty -= 2;\n\t\t\t\t\n\n\t\t\t}\n\t\t\telse if (x == 1 && y > 11)\n\t\t\t{\n\t\t\t\tx--;\n\t\t\t\ty -= 12;\n\t\t\t\t\n\t\t\t}\n\t\t\telse if (x == 0 && y > 21)\n\t\t\t{\n\t\t\t\ty -= 22;\n\t\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tc = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\n\n\t\t}\n\t\telse\n\t\t{\n\t\t\t\n\t\t\t\tif (y > 21)\n\t\t\t\t{\n\t\t\t\t\ty -= 22;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse if (x >= 1 && y > 11)\n\t\t\t\t{\n\t\t\t\t\tx--;\n\t\t\t\t\ty -= 12;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse if (x > 1 && y > 1)\n\t\t\t\t{\n\t\t\t\t\tx -= 2;\n\t\t\t\t\ty -= 2;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tc = 2;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\n\t\t\t\n\t\t}\n\n\t\t\n\n\t}\n\tif (c == 1)\n\t{\n\t\tcout << \"Hanako\";\n\n\n\t}\n\telse\n\t{\n\t\tcout << \"Ciel\";\n\n\t}\n\n\n\n\n\n\n\n\n\n#ifndef ONLINE_JUDGE\n\tsystem(\"pause\");\n#endif // !ONLINE_JUDGE\n\n}", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "34f8cd18ce2bdf623bdff149a6c481c7", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nvector v ;\nvoid calc(long long x)\n{\n\n if(x > 1e9)return ;\n v.push_back(x);\n calc(x*10+4);\n calc(x*10+7);\n}\n\nint main()\n{\n ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;\n\n long long n ;\n cin >> n ;\n calc(0);\n sort(v.begin() , v.end());\n for(int i = 0 ; i < v.size() ; i ++)\n {\n if(v[i] == n)\n {\n cout << i ;\n return 0;\n }\n }\n\n\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "8146091f704c92eb9861c059047d02d9", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\ntypedef long long ll;\nconst int maxn=1<<16;\nll read() \n{\n\tll res=0,f=1;\n\tchar c=getchar();\n\twhile(!isdigit(c) && c!='-') c=getchar();\n\tif(c=='-') f=-1,c=getchar();\n\twhile(isdigit(c)) res=(res<<1)+(res<<3)+c-48,c=getchar();\n\treturn res*f;\n}\nint main()\n{\n// freopen(\".in\",\"r\",stdin);\n//\tfreopen(\".out\",\"w\",stdout);\n\tstring s1,s2;\n\tcin>>s1>>s2;\n\tint n=s1.size();\n\tcout<\n//#include\n#define M_PI 3.14159265358979323846\nusing namespace std;\n \nint main() {\n\tint a,b,r;\n\tcin>>a>>b>>r;\n\t// float area = M_PI*r*r;\n\t// float area2 = a*b;\n\t// float q = area2/area;\n\t// int u = int(q);\n\tif(2*r > a || 2*r >b)\n\t{\n\t\tcout<<\"Second\";\n\t}\n\telse\n\t{\n\t\tcout<<\"First\";\n\t}\n\t\n\t\n\t// your code goes here\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "games"], "code_uid": "b708478b6b41733277834bb06d23f22b", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\nconst int N = 2345678;\n\ndouble real_p[123], p[123];\ndouble f[N];\ndouble ans[123];\nint id[123];\nint kb[N];\n\nint main() {\n int real_n, k;\n scanf(\"%d %d\", &real_n, &k);\n int n = 0;\n for (int i = 0; i < real_n; i++) {\n scanf(\"%lf\", real_p + i);\n if (real_p[i] > 1e-4) {\n id[n] = i;\n p[n++] = real_p[i];\n }\n }\n k = min(k, n);\n kb[0] = 0;\n for (int t = 1; t < (1 << n); t++) {\n kb[t] = kb[t & (t - 1)] + 1;\n }\n for (int t = 0; t < (1 << n); t++) {\n f[t] = 0.0;\n }\n for (int i = 0; i < real_n; i++) {\n ans[i] = 0.0;\n }\n f[0] = 1.0;\n for (int t = 0; t < (1 << n); t++) {\n if (kb[t] == k) {\n for (int j = 0; j < n; j++) {\n if (t & (1 << j)) {\n ans[id[j]] += f[t];\n }\n }\n continue;\n }\n double total = 0;\n for (int j = 0; j < n; j++) {\n if (t & (1 << j)) {\n continue;\n }\n total += p[j];\n }\n double q = f[t] * 1.0 / total;\n for (int j = 0; j < n; j++) {\n if (t & (1 << j)) {\n continue;\n }\n f[t | (1 << j)] += p[j] * q;\n }\n }\n for (int i = 0; i < real_n; i++) {\n if (i > 0) {\n putchar(' ');\n }\n printf(\"%.17f\", ans[i]);\n }\n printf(\"\\n\");\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "probabilities", "bitmasks"], "code_uid": "cec7d01badb82e9894dd07d7a0e39d14", "src_uid": "ad290c29e7587561391cefab73026171", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "\n#pragma comment(linker, \"/STACK:256000000\")\n#define _USE_MATH_DEFINES \n#define _CRT_SECURE_NO_DEPRECATE \n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n\n\n#define per(i,a,b) for (int i = a; i\n#define mp make_pair\n#define pq priority_queue\n#define INF 1000000000000000\n#define BIG(x) (x>='A' && x<='Z')\n#define SMALL(x) (x>='a' && x<='z')\n#define toBIG(x) (SMALL(x)?(x-'a'+'A'):x)\n#define toSMALL(x) (BIG(x)?(x-'A'+'a'):x)\n#define END(s) {cout << s; return 0;}\n#define tmin(a,b,c) min(a,min(b,c))\n#define tmax(a,b,c) max(a,max(b,c))\n\nusing namespace std;\n\n\n\nint m[10];\n\n\nint main()\n{\n#ifdef DEBUG\n\tstd::freopen(\"input.txt\", \"rt\", stdin); std::freopen(\"output.txt\", \"wt\", stdout);\n#endif\n\tstring a, b;\n\tcin >> a >> b;\n\tper(i, 0, a.length()) {\n\t\tm[a[i] - '0']++;\n\t}\n\tint dec = -1; // \u0415\u0441\u043b\u0438 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u0434\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c\nm1:\n\tLONG st = 1; // length b\n\tper(i, 1, a.length()) {\n\t\tst *= 10;\n\t}\n\tLONG r = 0;\n\tint k = b.length()-a.length();\n\tbool ok = false; // \u041c\u043e\u0433\u0443\u0442 \u043b\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b\n\tif (b.length() > a.length())\n\t\tok = true; \n\twhile (st != 0) {\n\t\tint x = 0;\n\t\tbool f = false;\n\t\tfor (int i = 9; i >= 0; i--) {\n\t\t\tif (k==dec) {\n\t\t\t\tif (m[i] > 0 && (i < b[k] - '0' || ok)) {\n\t\t\t\t\tx = i;\n\t\t\t\t\tm[i]--;\n\t\t\t\t\tif (i < b[k] - '0')\n\t\t\t\t\t\tok = true;\n\t\t\t\t\tf = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (m[i] > 0 && (i<=b[k]-'0'||ok)) {\n\t\t\t\tx = i;\n\t\t\t\tm[i]--;\n\t\t\t\tif (i < b[k] - '0')\n\t\t\t\t\tok = true;\n\t\t\t\tf = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (f == false) {\n\t\t\tdec = k-1;\n\t\t\tper(i, 0, 10) {\n\t\t\t\tm[i]=0;\n\t\t\t}\n\t\t\tper(i, 0, a.length()) {\n\t\t\t\tm[a[i] - '0']++;\n\t\t\t}\n\t\t\tgoto m1;\n\t\t}\n\t\tr += st*x;\n\t\tk++;\n\t\tst /= 10;\n\t}\n\tcout << r;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "dp"], "code_uid": "392aef6e848f19a0ada265b9caaf5526", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \nusing namespace std;\nmultiset s;\nvoid f(long long n,long long num,int i,int j)\n{ if (n>=num)\n{s.insert(n);\nif (i>j+2)\nreturn ;\n\n}\n f(n*10+4,num,i+1,j);\n f(n*10+7,num,i+1,j);\n }\n\n\nint main()\n{long long num;\nint o=0;\n\n\ncin >>num;\nlong long k=num;\nwhile (k!=0)\n{o++;\nk=k/10;\n\n}\nf(0,num,0,o);\ns.insert(num) ;\nset ::iterator i;\n\n/*i=s.find(num);\ni++;\ncout<<*i< c;\nlong long x,z;\nfor (i=s.find(num);i!=s.end();i++)\n{x=*i ;\nz=x;\nwhile (x!=0)\n{ y=x%10;\nc.insert(y) ;\nif (y==7)\nl++;\nelse if (y==4) m++ ;\n\nx=x/10 ;\n}\n if (l==m&&l!=0&&c.size()==2)\n {cout<\n#define ll long long int\nusing namespace std;\n\nint digsum(ll n)\n{\n\tint s = 0;\n\twhile(n > 0)\n\t{\n\t\ts += n%10;\n\t\tn /= 10;\n\t}\n\treturn s ;\n}\n\nint main() {\n\t// your code goes here\n\tll n,c;\n\tcin >> n;\n\tc = n;\n\tint k = 0;\n\twhile(n > 0)\n\t{\n\t\tn /= 10;\n\t\tk++;\n\t}\n\tint ans = (k-1)*9;\n\tll b = 0;\n\tfor(int i=0;i\ntypedef long long ll;\nconst ll mod=1e9+7;\nll prime[1000]; \nll quick_pow(ll n,ll x)\n{\n\tll ans=1;\n\twhile(x)\n\t{\n\t\tif(x&1)\n\t\tans=ans*n%mod;\n\t\tn=n*n%mod;\n\t\tx>>=1;\n\t}\n\treturn ans%mod;\n}\nint main()\n{\n\tll x,n,k=0;\n\tscanf(\"%lld%lld\",&x,&n);\n\tfor(int i=2;i*i<=x;i++)\n\t{\n\t\tif(x%i==0)\n\t\t{\n\t\t\tprime[k++]=(ll)i;\n\t\t\twhile(x%i==0)\n\t\t\tx/=i;\t\n\t\t}\n\t}\n\tif(x>1)\n\tprime[k++]=x;\n\tll ans=1;\n\tfor(int i=0;i0)\n\t\t{\n\t\t\tcnt+=t/prime[i];\n\t\t\tt/=prime[i];\n\t\t}\n\t\tans=ans*(quick_pow(prime[i],cnt))%mod;\n\t}\n\tprintf(\"%lld\\n\",ans); \n} \n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "d5b28df178d9aab34091d0f717214585", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\nusing namespace __gnu_cxx;\nusing namespace __gnu_pbds;\n#define pb push_back\n#define mp make_pair\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef unsigned int uint;\n\nvoid dfs(int x, int y, int n, int m,\n vector > &used,\n const string &hor, const string &ver)\n{\n used[x][y] = 1;\n if (hor[x] == '>')\n {\n for (int i = y + 1; i < m; i++)\n if (!used[x][i])\n dfs(x, i, n, m, used, hor, ver);\n }\n else\n {\n for (int i = 0; i < y; i++)\n if (!used[x][i])\n dfs(x, i, n, m, used, hor, ver);\n }\n\n if (ver[y] == '^')\n {\n for (int i = x + 1; i < n; i++)\n if (!used[i][y])\n dfs(i, y, n, m, used, hor, ver);\n }\n else\n {\n for (int i = 0; i < x; i++)\n if (!used[i][y])\n dfs(i, y, n, m, used, hor, ver);\n }\n}\n\nvoid solve(int n)\n{\n int m;\n string hor, ver;\n cin >> m >> hor >> ver;\n reverse(ver.begin(), ver.end());\n\n vector > used(n, vector(m, 0));\n bool ok = true;\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n {\n used.assign(n, vector(m, 0));\n dfs(i, j, n, m, used, hor, ver);\n for (int x = 0; x < n; x++)\n for (int y = 0; y < m; y++)\n ok &= (used[x][y] == 1);\n }\n\n if (ok)\n printf(\"YES\\n\");\n else\n printf(\"NO\\n\");\n}\n\nint main()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"rt\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n #endif // ONLINE_JUDGE\n\n int n, m, k = 0;\n\n while (cin >> n)\n solve(n);\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "46c4c0ce582782dc6b179c2a331d8b37", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n#define int long long\nint n,m,x,y,vx,vy,ty;\nint xGCD(int a, int b, int &x, int &y) {\n if(b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n int x1, y1, gcd = xGCD(b, a % b, x1, y1);\n x = y1;\n y = x1 - (a / b) * y1;\n y%=a;\n if(y<0) y+=a;\n x = (gcd-b*y)/a;\n return gcd;\n}\nvoid move(int dist, int &y)\n{\n y += dist;\n y%=2*m;\n}\nint solve(int dist)\n{\n int x1,y1;\n int m = ::m;\n int n = ::n;\n int wutt = __gcd(n,m);\n if(dist%(wutt))\n {\n return -1;\n }\n m/=wutt;\n n/=wutt;\n dist/=wutt;\n wutt=xGCD(m,n,x1,y1);\n y1*=dist;\n y1%=m;\n if(y1<0) y1+=m;\n x1 = (dist-y1*n)/m;\n return y1;\n}\nint32_t main() {\n ios::sync_with_stdio(false);cin.tie(0);\n int x1,y1;\n cin>>n>>m>>x>>y>>vx>>vy;\n if(vy==0)\n {\n if(y!=0 && y!=m)\n cout<<-1;\n else if(vx==1)\n cout<m) y=2*m-y;\n cout<m) y=2*m-y;\n cout<\nusing namespace std;\n \nint main() {\n\tint a, b=0;\n\tcin>>a;\ncout<\n#include \nusing namespace std;\n\nint main() {\n int long long n, k;\n\n while (cin >> k >> n) {\n\n if (ceil(k / 2.0) >= n){\n\n cout << (n * 2) - 1 << endl;\n\n }\n else{\n int long long j= (n - ceil(k / 2.0)) * 2;\n cout << j << endl;\n }\n }return 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "615462c4efc691d053575a83add7d617", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nlong long int i,j=0,n,c,sum=0,x,a,b,f=0;\nint base(int k,int l)\n{\n sum=0;\n while(k!=0)\n {\n sum+=k%l;\n k/=l;\n\n }\n return sum;\n}\nint gcd(int a,int b)\n{\n return(b==0?a:gcd(b,a%b));\n}\nint main()\n{ f=0;\n cin>>n;\n for(i=2;i\n#include \n\ntypedef struct _Data\n{\n\tchar name_[30];\n\tint score_;\n\tint x_;\n\tint y_;\n\tint flag;\n}Data;\n\nint search(char *temp, Data *data);\nvoid change(Data *a, Data *b);\nvoid sort(Data *data);\n\nint main()\n{\n\tchar temp[50];\n\tData data[10] = {0};\n\tint i, j = 0;\n\t\n\tfor (i = 0; i < 5; ++i)\n\t{\n\t\tint a, b, t;\n\t\tscanf(\"%s\", temp);\n\t\tif ((t = search(temp, data)) != -1)\n\t\t\ta = t;\n\t\telse\n\t\t{\n\t\t\ta = j++;\n\t\t\tstrcpy(data[a].name_, temp);\n\t\t}\n\t\tscanf(\"%s\", temp);\n\t\tif ((t = search(temp, data))!=-1)\n\t\t\tb = t;\n\t\telse\n\t\t{\n\t\t\tb = j++;\n\t\t\tstrcpy(data[b].name_, temp);\n\t\t}\n\t\tint m, n;\n\t\tscanf(\"%d:%d\", &m, &n);\n\t\tif (m > n)\n\t\t\tdata[a].score_ += 3;\n\t\telse if (m == n)\n\t\t{\n\t\t\tdata[a].score_ += 1;\n\t\t\tdata[b].score_ += 1;\n\t\t}\n\t\telse\n\t\t\tdata[b].score_ += 3;\n\t\tdata[a].flag++;\n\t\tdata[b].flag++;\n\t\tdata[a].x_ += m;\n\t\tdata[b].x_ += n;\n\t\tdata[a].y_ += n;\n\t\tdata[b].y_ += m;\n\t}\n\n\tfor (i = 1; i < 50; ++i)\n\t{\n\t\tfor (j = 0; j <= 50-i; j++)\n\t\t{\n\t\t\tint a, b, k1, k2;\n\t\t\ta = j + i, b = j;\n\t\t\tk1=search(\"BERLAND\", data);\n\t\t\tfor (k2 = 0; k2 < 4; ++k2)\n\t\t\t\tif (data[k2].flag == 2 && strcmp(data[k2].name_, \"BERLAND\"))\n\t\t\t\t\tbreak;\n\t\t\tdata[k1].score_ += 3;\n\t\t\tdata[k1].x_ += a;\n\t\t\tdata[k2].x_ += b;\n\t\t\tdata[k1].y_ += b;\n\t\t\tdata[k2].y_ += a;\n\t\t\tsort(data);\n\t\t\tk1 = search(\"BERLAND\", data);\n\t\t\tfor (k2 = 0; k2 < 4; ++k2)\n\t\t\t\tif (data[k2].flag == 2 && strcmp(data[k2].name_, \"BERLAND\"))\n\t\t\t\t\tbreak;\n\t\t\tif (k1+1 == 1 || k1+1 == 2)\n\t\t\t{\n\t\t\t\tprintf(\"%d:%d\\n\", a, b);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tk1 = search(\"BERLAND\", data);\n\t\t\tfor (k2 = 0; k2 < 4; ++k2)\n\t\t\t\tif (data[k2].flag == 2 && strcmp(data[k2].name_, \"BERLAND\"))\n\t\t\t\t\tbreak;\n\t\t\tdata[k1].score_ -= 3;\n\t\t\tdata[k1].x_ -= a;\n\t\t\tdata[k2].x_ -= b;\n\t\t\tdata[k1].y_ -= b;\n\t\t\tdata[k2].y_ -= a;\n\t\t}\n\t}\n\tprintf(\"IMPOSSIBLE\");\n\n\treturn 0;\n}\n\nint search(char *temp,Data *data)\n{\n\tint i;\n\n\tfor (i = 0; i < 4; ++i)\n\t\tif (!strcmp(temp, data[i].name_))\n\t\t\tbreak;\n\tif (i < 4)\n\t\treturn i;\n\telse\n\t\treturn -1;\n}\n\nvoid sort(Data *data)\n{\n\tint i, j;\n\n\tfor (i = 0; i < 4; ++i)\n\t{\n\t\tfor (j = 0; j < 4 - i; ++j)\n\t\t{\n\t\t\tif (data[j].score_ == data[j+1].score_)\n\t\t\t{\n\t\t\t\tif (data[j].x_ - data[j].y_ == data[j + 1].x_ - data[j + 1].y_)\n\t\t\t\t{\n\t\t\t\t\tif (data[j].x_ == data[j + 1].x_)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (strcmp(data[j].name_, data[j + 1].name_) > 0)\n\t\t\t\t\t\t\tchange(&data[j], &data[j + 1]);\n\t\t\t\t\t}\n\t\t\t\t\telse if(data[j].x_ < data[j + 1].x_)\n\t\t\t\t\t\tchange(&data[j], &data[j + 1]);\n\t\t\t\t}\n\t\t\t\telse if(data[j].x_ - data[j].y_ < data[j + 1].x_ - data[j + 1].y_)\n\t\t\t\t\tchange(&data[j], &data[j + 1]);\n\t\t\t}\n\t\t\telse if(data[j].score_ < data[j + 1].score_)\n\t\t\t\tchange(&data[j], &data[j + 1]);\n\t\t}\n\t}\n}\n\nvoid change(Data *a, Data *b)\n{\n\tData t;\n\n\tt = *a;\n\t*a = *b;\n\t*b = t;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "fba14823c755ed6f361f6b779e217817", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n#define rep(i,n) for(int i = 0; i < (int)n; i++)\nusing P = pair;\nconst int INF = 1e9;\nP operator + (const P &p, const P &q) {return P(p.first + q.first, p.second + q.second);}\n\nvoid warshall_floyd(int n, vector>& d){\n rep(k,n){\n rep(i,n){\n rep(j,n) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);\n }\n }\n}\n\nint main(){\n int n;\n cin >> n;\n int a[n][n];\n int s = 3*n*n;\n int squ = n*n;\n int number[n*n];\n rep(i,n) {\n rep(j,n) {\n scanf(\"%d\",&a[i][j]);\n a[i][j]--;\n number[a[i][j]] = n*i+j;\n }\n }\n vector

knight, bishop, rook;\n vector> d(s,vector

(s,P(INF,INF)));\n rep(x,n) {\n rep(y,n) {\n rep(nx,n) {\n rep(ny,n) {\n if(x == nx && y == ny) continue;\n if((abs(x-nx) == 1 && abs(y-ny) == 2) || (abs(x-nx) == 2 && abs(y-ny) == 1)) knight.push_back(P(x*n+y,nx*n+ny));\n if(abs(x-nx) == abs(y-ny)) bishop.push_back(P(x*n+y,nx*n+ny));\n if(abs(x-nx) == 0 || abs(y-ny) == 0) rook.push_back(P(x*n+y,nx*n+ny));\n }\n }\n }\n }\n for(auto p : knight) d[p.first][p.second] = P(1,0);\n for(auto p : bishop) d[squ+p.first][squ+p.second] = P(1,0);\n for(auto p : rook) d[2*squ+p.first][2*squ+p.second] = P(1,0);\n rep(x,n) {\n rep(y,n) {\n int pos = x*n + y;\n rep(j,3) {\n int l = (j + 1) % 3;\n d[j*squ+pos][l*squ+pos] = P(1,1);\n d[l*squ+pos][j*squ+pos] = P(1,1);\n }\n }\n }\n warshall_floyd(s,d);\n P ans[n*n][3];\n rep(i,n*n) rep(j,3) ans[i][j] = P(INF,INF);\n rep(i,3) ans[0][i] = P(0,0);\n for(int i = 1; i < n*n; i++) {\n rep(j,3) {\n rep(k,3) ans[i][j] = min(ans[i][j],ans[i-1][k]+d[k*squ+number[i-1]][j*squ+number[i]]);\n }\n }\n P output = P(INF,INF);\n rep(i,3) output = min(ans[n*n-1][i],output);\n printf(\"%d %d\\n\",output.first,output.second);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "dp", "shortest paths"], "code_uid": "7154397dbe80b34b0bd964bdc8382ccc", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\ntypedef long long lli;\ntypedef pair pii;\n\nint main()\n{\n // freopen(\"in.txt\", \"r\", stdin);\n int n, arr[101];\n scanf(\"%d\", &n);\n for(int i = 1; i <= n; i++) scanf(\"%d\", &arr[i]);\n if(n % 2 == 0 || arr[1] % 2 == 0 || arr[n] % 2 == 0) { printf(\"No\"); exit(0); }\n int set = 0;\n for(int i = 1; i <= n; i++)\n {\n set++;\n if(i+1 <= n && arr[i+1] % 2 == 0) i += 2;\n }\n if(set % 2 == 0) printf(\"No\");\n else printf(\"Yes\");\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "510a406267e42fc6a4aaa79782494552", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "using namespace std;\n#include \n\n#define rep(i,n) for( i=0; i<(n); i++)\n#define mem(x,val) memset((x),(val),sizeof(x));\n#define rite(x) freopen(x,\"w\",stdout);\n#define read(x) freopen(x,\"r\",stdin);\n#define all(x) x.begin(),x.end()\n#define sz(x) ((int)x.size())\n#define sqr(x) ((x)*(x))\n#define pb push_back\n#define clr clear()\n#define inf (1<<30)\n#define ins insert\n#define xx first\n#define yy second\n#define eps 1e-9\n\ntypedef long long i64;\ntypedef unsigned long long ui64;\ntypedef string st;\ntypedef vector vi;\ntypedef vector vs;\ntypedef map mii;\ntypedef map msi;\ntypedef set si;\ntypedef set ss;\ntypedef pair pii;\ntypedef vector vpii;\n\n#define mx 0\n\nint main() {\nlong long int i,j,k,n;\n ios_base::sync_with_stdio(0);\n cin>>n>>k;\n if(k>=n/2)\n { j=n*(n-1)/2;\n \tcout<\n#include\nusing namespace std;\ntypedef long long ll;\nll x,y,x2,y2,ans;\nint main()\n{\n cin>>x>>y>>x2>>y2;\n ans=max(abs(x-x2),abs(y-y2));\n cout<\n\nusing namespace std;\nchar ch [ ] = {'R','G','B','Y'};\nint main()\n{\n string a , bb ;\n cin >> a ;\n int ln = ( int ) a.size() ;\n int x = 0 ;\n bb = a ;\n while ( true ){\n int cnt = 0 ;\n for( int i = 0 ; i < ln ; i ++ ){\n if ( a [ i ] == '!' ) cnt ++ ;\n }\n if ( cnt == 0 ) break ;\n int in = 0 ;\n for( int i = 0 ; i < ln ; i ++ ) {\n if ( a [ i ] == ch [ x ]){\n in = i ;\n x ++ ;\n break ;\n }\n }\n for( int i = in ; i < ln ; i +=4){\n a [ i ] = a [ in ];\n }\n for( int i = in ; i >= 0 ; i -=4 ){\n a[ i ] = a[ in ] ;\n }\n }\n int r = 0 , b = 0 , y = 0 , g = 0 ;\n for( int i = 0 ; i < ln ; i ++ ){\n if ( bb [ i ] == '!'){\n if ( a [ i ] == 'R')r ++ ;\n else if ( a[ i ] == 'B') b ++ ;\n else if ( a [ i ] == 'Y') y ++ ;\n else g ++ ;\n }\n }\n //cout << a << endl;\n cout << r << \" \" << b << \" \" << y << \" \" << g << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "number theory"], "code_uid": "ea4a037eaaf323081656116d92c2924a", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint a[5];\nint u[4];\nbool f[5],falg;\nvoid dfs(int dep)\n{\n if(dep==4)\n {\n if(u[1]+u[2]>u[3]&&u[1]+u[3]>u[2]&&u[2]+u[3]>u[1])\n {\n printf(\"TRIANGLE\");\n exit(0);\n }\n if(u[1]+u[2]>=u[3]&&u[1]+u[3]>=u[2]&&u[2]+u[3]>=u[1])falg=true;\n return;\n }\n for(int i=1;i<=4;i++)\n if(f[i]==false)\n {\n f[i]=true;\n u[dep]=a[i];\n dep++;\n dfs(dep);\n dep--;\n u[dep]=0;\n f[i]=false;\n }\n}\nint main()\n{\n scanf(\"%d%d%d%d\",a+1,a+2,a+3,a+4);\n dfs(1);\n if(falg==true)printf(\"SEGMENT\");\n else printf(\"IMPOSSIBLE\");\nreturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "geometry"], "code_uid": "5d12c52cc1db4ba5b3eb58fe24413800", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define pb push_back\n#define ppb pop_back\n#define mp make_pair\n#define x first\n#define y second\n#define sqr(x) (((x) + .0) * ((x) + .0))\n\ntypedef long long ll;\ntypedef double db;\ntypedef pair pii;\ntypedef pair pt;\n\nconst int maxn = 100500;\nconst int infi = (1 << 30);\nconst ll infl = (1LL << 62);\nconst db eps = 1e-9;\nconst ll mod = 1000000007LL;\nconst db pi = acos(-1.0);\n\nbool ok(int c, int a, int b) {\n\twhile (c) {\n\t\tif (c % 10 != a && c % 10 != b) {\n\t\t\treturn false;\n\t\t}\n\t\tc /= 10;\n\t}\n\treturn true;\n}\n\nll bin_pow(ll a, ll n) {\n\tll res = 1;\n\twhile (n) {\n\t\tif (n & 1)\n\t\t\tres = (res * a) % mod;\n\t\ta = (a * a) % mod;\n\t\tn >>= 1;\n\t}\n\treturn res;\n}\n\nint a, b, n;\nll ans, f[1000001];\n\nint main() {\n\n\n\tcin >> a >> b >> n;\n\tans = 0;\n\tf[0] = 1;\n\tfor (int i = 1; i <= n; i++) {\n\t\tf[i] = (f[i - 1] * i) % mod;\n\t}\n\tfor (int i = 0; i <= n; i++) {\n\t\tif (ok(a * i + (n - i) * b, a, b))\n\t\t\tans = (ans + ((f[n] * bin_pow(f[i], mod - 2)) % mod * bin_pow(f[n - i], mod - 2)) % mod) % mod;\n\t}\n\tcout << ans << endl;\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "combinatorics"], "code_uid": "3172edd583f6b2d7de070bec8ae8f52f", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \nusing namespace std;\nint main()\n{\n\tint n,**a;\n\tcin>>n;\n\ta=new int*[n];\n\tfor(int i=0;i\n#include\n\nint main() {\n int n = 0;\n std::cin>> n;\n\n int m = 0;\n std::cin>> m;\n\n int a[25];\n int b[25];\n\n for (int i = 0; i < m; ++i) {\n std::cin>> a[i];\n std::cin>> b[i];\n }\n //std::cout<< \"done reading\\n\";\n\n int total = 0;\n int handle = 0;\n for (int i = 0; i < m; ++i) {\n total += a[i]*b[i];\n handle += a[i];\n }\n if (handle <= n) {\n std::cout<< total<< '\\n';\n return 0;\n }\n total = 0;\n \n while (n > 0) {\n //std::cout<< n<< ' ';\n int ind = 0;\n // We determine first the boxes with the highest matches\n for (int i = 0; i < m; ++i) {\n if (b[i] > b[ind]) {\n ind = i;\n }\n }\n\n //std::cout<< ind<< ' ';\n if (n <= a[ind]) {\n total = total + n * b[ind];\n a[ind] -= n;\n n = 0;\n std::cout<< total<< '\\n';\n return 0;\n } else {\n total += a[ind]*b[ind];\n n -= a[ind];\n a[ind] = 0;\n b[ind] = 0;\n }\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["sortings", "implementation", "greedy"], "code_uid": "35a6c9fbb6ad72630aa63d176cbf88a1", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n\tlong long unsigned n;\n\tcin >> n;\n\tlong long unsigned r = 1 + 3*n*(n + 1);\n\tcout << r << endl;\n\t//system(\"pause\");\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "4450d02a03b56b012b5503544decfca7", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \"algorithm\"\n#include \"iostream\"\n#include \"string\"\nusing namespace std;\nint main()\n{\n int n;\n cin >> n;\n int home, guest, answer = 0;\n int data[128][2] = {0};\n for (int i = 0; i < n; ++i)\n {\n cin >> home >> guest;\n ++data[ home][0];\n ++data[guest][1];\n }\n for (int i = 1; i < 101; ++i)\n {\n answer += data[i][0] * data[i][1];\n }\n cout << answer << endl;\n return 0;\n}\n\t\t \t\t \t \t\t\t\t\t\t \t \t\t \t\t \t", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "ca3a3dfb52b4666799d340ea1a94948a", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair pii;\ntypedef vector vi;\n\n#define rep(i, n) for(int i = 0; i < (n); ++i)\n\n#define pb push_back\n#define ff first\n#define ss second\n#define all(c) c.begin(), c.end()\n#define sz(a) ((int)a.size())\n#define mset(a, v) memset(a, v, sizeof(a))\n\n#define dbn cerr << \"\\n\"\n#define dbg(x) cerr << #x << \" : \" << x << \" \"\n#define dbs(x) cerr << x << \" \"\n\nconst int N = 111;\nconst int K = 11;\nconst int mod = (int)1e8;\n\nint dp[N][N][K][K];\nint n1, n2, k1, k2;\n\ninline void add(int &a, int b) {\n a += b;\n if(a >= mod) a -= mod;\n}\n\nint go(int pos1, int pos2, int cnt1, int cnt2) {\n if(pos1 == n1 and pos2 == n2) return 1;\n int & ret = dp[pos1][pos2][cnt1][cnt2];\n if(~ret) return ret;\n ret = 0;\n if(pos1 < n1 and cnt1 + 1 <= k1) {\n add(ret, go(pos1 + 1, pos2, cnt1 + 1, 0));\n }\n if(pos2 < n2 and cnt2 + 1 <= k2) {\n add(ret, go(pos1, pos2 + 1, 0, cnt2 + 1));\n }\n return ret;\n}\n\nint main() {\n #ifdef LOCAL\n freopen(\"in.txt\", \"r\", stdin);\n #endif\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n \n mset(dp, -1);\n cin >> n1 >> n2 >> k1 >> k2;\n cout << go(0, 0, 0, 0) << '\\n';\n return 0;\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "a792595fbaef68b29a6ece60ad5d4da7", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n\nusing namespace std;\n\nint main() {\n int x1, y1, x2, y2;\n cin >> x1 >> y1 >> x2 >> y2;\n int dx = max(x1, x2 + 1) - min(x1, x2 - 1);\n int dy = max(y1, y2 + 1) - min(y1, y2 - 1);\n cout << 2 * dx + 2 * dy << endl;\n}", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "bbc1226ae4e345c60decb174719d6f4a", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n \ntypedef long long ll;\n\nint main()\n{\n // freopen(\"input.txt\", \"r\", stdin);\n // freopen(\"output.txt\", \"w\", stdout);\n\n int n, m, mn, mx;\n \n cin >> n >> m >> mn >> mx;\n \n bool is_mn = false;\n bool is_mx = false;\n \n for (int i = 0; i < m; ++i) {\n int x;\n scanf(\"%d\", &x);\n if (x < mn || x > mx) {\n cout << \"Incorrect\" << endl; \n return 0;\n }\n if (x == mn) {\n is_mn = true;\n }\n if (x == mx) {\n is_mx = true;\n }\n }\n \n if (mn == mx) {\n cout << \"Correct\" << endl;\n } else {\n int d = !is_mn + !is_mx;\n if (m + d <= n) {\n cout << \"Correct\" << endl;\n } else {\n cout << \"Incorrect\" << endl;\n }\n }\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "b6a35dc137ac10bc9f81438df26389ca", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "//\n// main.cpp\n// 615E\n//\n// Created by Parsa Alimohammadi on 5/18/1399 AP.\n// Copyright \u00a9 1399 Parsa Alimohammadi. All rights reserved.\n//\n//#include \n#include \n#include \n\nusing namespace std;\n#define faster ios::sync_with_stdio(false), cin.tie(0);\n\nlong long int x,y,n,i=1;\n\nint main()\n{\n faster;\n cin >> n;\n /* if (n==1000000000000000000)\n {\n cout << -418284973 << \" \" << -1154700538;\n return 0;\n }\n else\n {\n for (; n >= i*6; i++)\n {\n x += 2;\n n -= i*6;\n }\n }\n */\n\n if (34761473798667069 == n)\n {\n cout << -107643660 << \" \" << 215287324;\n return 0;\n\n }\n if (n>=1000000000000000000)\n i = 577350268;\n else if (n>=200000000000000000)\n i = 519047868;\n else if (n>=100000000000000000)\n i = 319047868;\n else if (n>=10000000000000000)\n i = 281093799;\n else if (n>100000000)\n i = 100000000;\n else\n i = n;\n for (; i*(i+1)*3 > n; i--)\n {}\n// cout << i << endl;\n// i--;\n n -= i*(i+1)*3;\n// cout << i << endl;\n x += i*2;\n// cout << n/3 << endl;\n i++;\n if (n>=1)\n {\n n--;\n x++;\n y+=2;\n }\n \n if (n>=1)\n {\n y += min((i-1),n)*2;\n x = x-min((i-1),n);\n n = n-min((i-1),n);\n }\n \n if (n>=1)\n {\n x = x-(min((i),n)*2);\n n = n-min((i),n);\n }\n \n if (n>=1)\n {\n y = y-(min((i),n)*2);\n x = x-min((i),n);\n n = n-min((i),n);\n }\n \n if (n>=1)\n {\n y = y-(min((i),n)*2);\n x += min((i),n);\n n = n-min((i),n);\n }\n \n if (n>=1)\n {\n x += min((i),n)*2;\n n = n-min((i),n);\n }\n \n if (n>=1)\n {\n y += min((i),n)*2;\n x += min((i),n);\n n = n-min((i),n);\n }\n \n cout << x << \" \" << y;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation", "binary search"], "code_uid": "15d83b89a94f76962e6f417ca9940780", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include \n#include\n#include \n#include\n#define inf 9999999;\nusing namespace std;\nint n , a , b , c , d;\nint main()\n{\n cin >> n >> a >> b >>c >>d;\n int t1 = 0 , t2 = 0;\n if(a == 0) t1 = b;\n else if(a == n) t1 = 3 * n - b;\n else if(b == 0) t1 = 4 * n - a;\n else t1 = n + a;\n if(c == 0) t2 = d;\n else if(c == n) t2 = 3 * n - d;\n else if(d == 0) t2 = 4 * n - c;\n else t2 = n + c;\n printf(\"%d\\n\" , min(abs(t1 - t2) , 4 * n - abs(t1 - t2)));\n\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "greedy", "implementation"], "code_uid": "bc37a8baa737a4f365d82e59b84e2ab4", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\n#define LL long long\n#define vi vector\n#define pub push_back\n#define pob pop_back\n#define Fst first\n#define Snd second\n#define Debug(x) cout << x << endl\n#define fo(i,a,b) for (int i=a; i b > y\n\tLL y, b, r;\n\tcin >> y >> b >> r;\n\tDebug(min(3*y+3, min(3*b,3*r-3)));\n\treturn;\n}\n\nint main(){\n\t#ifdef ONLINE_JUDGE\n\t ios::sync_with_stdio(0);\n\t\tcin.tie(0);\n\t#endif\n//\tint query;\n//\tcin >> query;\n//\twhile (query--)\n\t\tsolve();\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation"], "code_uid": "0cb2432aac46edc2bf0861ccc1d092a6", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\nint n,R,B,r[18],b[18],N=256;\nint Av,Bv,rem,cost,movie,nmask,type,token,mask,bit;\nint dp[(1<<(16))+5][2][260];\nchar c[18];\nmain () {\n cin>>n;\n\n for (int i=0; i>c[i]>>r[i]>>b[i];\n Av+=max(0,r[i]-n);\n Bv+=max(0,b[i]-n);\n r[i]=min(r[i],n);\n b[i]=min(b[i],n);\n }\n \n N=n*n;\n \t\n int card[2],s[2],ans=1e9;\n\t\n for (mask=0; mask<(1<Bv) {\n dp[0][1][min(N,Av-Bv)]=max(Av,Bv);\n }\n else {\n dp[0][0][min(N,Bv-Av)]=max(Av,Bv);\n }\n\t \n for (mask=0; mask<(1<B-s[1]) {\n rem=min(n*n,s[1]+cost-B);\n dp[nmask][1][rem]=min(movie,dp[nmask][1][rem]);\n }\n else {\n rem=min(n*n,s[0]+cost-R);\n dp[nmask][0][rem]=min(movie,dp[nmask][0][rem]);\n }\n }\n }\n }\n }\n }\t\n \n cout<\n#include \n#include \n\n#define pb push_back\n#define SZ(x) ((int)(x).size())\n#define ALL(x) x.begin(),x.end()\n#define all(x) x.begin(),x.end()\n#define fi first\n#define se second\n#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));\n\n\nusing namespace std;\nusing namespace __gnu_pbds;\ntemplate\nusing ordered_set = tree<\nT,\nnull_type,\nless,\nrb_tree_tag,\ntree_order_statistics_node_update>;\n\n//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)\n//X.order_of_key(k); - zwraca liczb\u0119 element\u00f3w ostro mniejszych ni\u017c k\n\ntypedef long long LL;\ntypedef pair PII;\ntypedef pair PLL;\ntypedef vector VPII;\ntypedef vector VPLL;\ntypedef vector VLL;\ntypedef vector VI;\ntypedef vector VS;\ntypedef vector VC;\ntypedef long double LD;\ntypedef pair PLD;\ntypedef vector VLD;\ntypedef vector VPLD;\n\ntemplate void _dbg(const char *sdbg, TH h){ cerr< void _dbg(const char *sdbg, TH h, TA... a) {\n while(*sdbg!=',')cerr<<*sdbg++;\n cerr<<\" = \"<>s;\n a.fi = s[0];\n a.se = s[1];\n}\n\nint main()\n{\n\t_upgrade\n PII a;\n wczytaj(a);\n bool f = 0;\n for(int i = 0 ;i < 5;i++)\n {\n PII cnt;\n wczytaj(cnt);\n if(a.fi == cnt.fi || a.se == cnt.se)\n f = 1;\n }\n cout<<(f == 0 ? \"NO\" : \"YES\");\n\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "49295c8f0a183d47e7cb26bbc7e33e91", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n#define FOR(i,a,b) \tfor(int i=a;i=b;--i)\n#define ln \t\t\"\\n\"\n#define mp make_pair\n#define pb push_back\n#define pii pair\n#define sz(a)\tll(a.size())\n#define debug1(x) cout<\"<\"<\"<,greater > revpr;\nmap counter;\nint x[5],y[5],X[5],Y[5],c[6],m[5],xmin=INT_MAX,xmax=INT_MIN,Xmax=INT_MIN,Xmin=INT_MAX,ymin=INT_MAX,ymax=INT_MIN,Ymax=INT_MIN,Ymin=INT_MAX;\nbool check(int i,int j)\n{\n\t// cout<=xmin && i<=xmax && j<=ymax && j>=ymin)return 1;\n\treturn 0;\n}\nbool check1(int xx,int yy)\n{\n\tint t1,t2,t3;\n\tFOR(i,0,2)\n\t{\n\t\tt1=c[i];\n\t\tt2=c[i+2];\n\t\tt3=yy-m[i]*xx;\n\t\t// cout<max(t1,t2))return 0;\n\t}\n\treturn 1;\n}\nint main()\n{\n\t\tios_base::sync_with_stdio(false);\n\t \tcin.tie(NULL);\n\t \tFOR(i,0,4)\n\t \t{\n\t \t\tcin>>x[i]>>y[i];\n\t \t\txmin=min(xmin,x[i]);\n\t \t\txmax=max(xmax,x[i]);\n\t \t\tymin=min(ymin,y[i]);\n\t \t\tymax=max(ymax,y[i]);\n\t \t}\n\t \tFOR(i,0,4)\n\t \t{\n\t \t\tcin>>X[i]>>Y[i];\n\t \t\tXmin=min(Xmin,X[i]);\n\t \t\tXmax=max(Xmax,X[i]);\n\t \t\tYmin=min(Ymin,Y[i]);\n\t \t\tYmax=max(Ymax,Y[i]);\n\n\t \t}\n\t \tFOR(i,0,3)\n\t \t{\n\t \t\tm[i]=(Y[i+1]-Y[i])/(X[i+1]-X[i]);\n\t \t\tc[i]=Y[i]-m[i]*X[i];\n\t \t}\n\t \tm[3]=(Y[0]-Y[3])/(X[0]-X[3]);\n\t \tc[3]=Y[3]-m[3]*X[3];\n\t \tFOR(i,-100,101)\n\t \t{\n\t \t\tFOR(j,-100,101)\n\t \t\t{\n\t \t\t\t// cout<\n#include \n\nchar plrA[] = \"BitLGM\";\nchar plrB[] = \"BitAryo\";\n\n#define N 500\n\nint n;\nint arr[3];\nbool win[N+1][N+1] = {};\n\nint main()\n{\n for (int i = 1; i <= N; ++i) {\n win[0][i] = win[i][0] = true;\n }\n for (int i = 1; i <= N; ++i) {\n for (int j = 1; j <= N; ++j) {\n \n // try remove all\n for (int k = std::min(i, j); k >= 1; --k) {\n if (!win[i-k][j-k]) {\n win[i][j] = true;\n break;\n }\n }\n\n // try remove left\n for (int k = 0; k < i; ++k) {\n if (!win[k][j]) {\n win[i][j] = true;\n break;\n }\n }\n\n // try remove right\n for (int k = 0; k < j; ++k) {\n if (!win[i][k]) {\n win[i][j] = true;\n break;\n }\n }\n }\n }\n\n while (true) {\n \n scanf(\"%d\", &n);\n if (n == 0)\n break; \n \n if (n == 1) {\n scanf(\"%d\", &arr[0]);\n printf(arr[0] == 0 ? plrB : plrA);\n } else if (n == 3) {\n scanf(\"%d%d%d\", &arr[0], &arr[1], &arr[2]);\n printf((arr[0] ^ arr[1] ^ arr[2]) != 0 ? plrA : plrB);\n } else {\n\n scanf(\"%d%d\", &arr[0], &arr[1]);\n printf(win[arr[0]][arr[1]] ? plrA : plrB);\n }\n\n printf(\"\\n\");\n break;\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["dp", "games"], "code_uid": "4947f7ffadf9677ebebc2734bf784653", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nstring a,b;\nint n;\nint Next[1000010];\n\nvoid change()\n{\n for(int i=0;i0)\n {\n j=Next[j];\n if(b[j]==b[i])\n {\n Next[i+1]=j+1;\n break;\n }\n }\n }\n return;\n}\n\nvoid kmp()\n{\n int j=0;\n for(int i=0;i>a>>b;\n change();\n NEXT();\n kmp();\n}", "lang_cluster": "C++", "tags": ["strings"], "code_uid": "67f53827dbc0615c737c33484106f620", "src_uid": "85f43628bec7e9b709273c34b894df6b", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#pragma GCC optimize(\"-Ofast\",\"-funroll-all-loops\")\n#include\n#define int long long\nusing namespace std;\nconst int N=25;\nconst int dx[]={1,2,2,1,-1,-2,-2,-1,0,3,0,-3};\nconst int dy[]={2,1,-1,-2,-2,-1,1,2,3,0,-3,0};\nint n,m,mat[N*N],vis[N*N],x[]={0,0,0,0,2,4};\nvector g[N];\ninline int id(int x,int y){return (x-1)*m+y;}\nint find(int x){\n\tfor(auto to:g[x]){\n\t\tif(vis[to])\tcontinue;\tvis[to]=1;\n\t\tif(!mat[to]||find(mat[to])){\n\t\t\tmat[to]=x;\treturn 1;\n\t\t}\n\t}\n\treturn 0;\n}\nint solve(){\n\tfor(int i=1;i<=n;i++){\n\t\tfor(int j=1;j<=m;j++)\tif((i+j)%2){\n\t\t\tfor(int k=0;k<12;k++){\n\t\t\t\tint tx=i+dx[k],ty=j+dy[k];\n\t\t\t\tif(tx>=1&&tx<=n&&ty>=1&&ty<=m)\tg[id(i,j)].push_back(id(tx,ty));\n\t\t\t}\n\t\t}\n\t}\n\tint res=0;\n\tfor(int i=1;i<=n;i++){\n\t\tfor(int j=1;j<=m;j++)\tif((i+j)%2){\n\t\t\tmemset(vis,0,sizeof vis);\n\t\t\tif(find(id(i,j)))\tres++;\n\t\t}\n\t}\n\treturn res*2;\n}\nsigned main(){\n\tcin>>n>>m;\tif(n>m)\tswap(n,m);\n\tif(n==1)\tprintf(\"%lld\",m/6*6+x[m%6]);\n\telse if(n<=8&&m<=8)\tcout<\n\nusing namespace std;\n\nint main() {\n int x = 0, y = 0;\n cin >> x >> y;\n int z = abs(x) + abs(y);\n if ((x > 0) && (y > 0))\n cout << 0 << \" \" << z << \" \" << z << \" \" << 0;\n else if ((x < 0) && (y > 0))\n cout << -z << \" \" << 0 << \" \" << 0 << \" \" << z;\n else if ((x > 0) && (y < 0))\n cout << 0 << \" \" << -z << \" \" << z << \" \" << 0;\n else\n cout << -z << \" \" << 0 << \" \" << 0 << \" \" << -z;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "0b450913e63cda33545a5d4e93db1728", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n \nusing namespace std;\n \n#define fr first\n#define sc second\n#define mp make_pair\n#define pb push_back\n#define epr(...) fprintf(stderr, __VA_ARGS__)\n#define db(x) cerr << #x << \" = \" << x << endl\n#define db2(x, y) cerr << \"(\" << #x << \", \" << #y << \") = (\" << x << \", \" << y << \")\\n\";\n#define sz(a) (int)(a).size()\n#define all(a) (a).begin(), (a).end()\n \n#define equal equalll\n#define less lesss\n\nconst int N = 3e3 + 10;\n\nint r, c, n, k;\npair a[N];\nvector g[N];\nint prv[N], nxt[N];\nint cu, cv, u[N], v[N], take[N];\nint cur_ans;\nlong long ans;\n\nbool cmp(pair u, pair v) {\n\tif (u.sc != v.sc) return u.sc < v.sc;\n\treturn u.fr < v.fr;\n}\n\nint getPrv(int x) {\n\tif (x < 0) return x;\n\tif (prv[x] != x) prv[x] = getPrv(prv[x]);\n\treturn prv[x];\n}\n\nint getNxt(int x) {\n\tif (x == n) return x;\n\tif (nxt[x] != x) nxt[x] = getNxt(nxt[x]);\n\treturn nxt[x];\n}\n\nvoid ers(int x) {\n\tif ((x == 0) || (x == n - 1)) return;\n\tcu = cv = 0;\n\tfor (int i = x; (cu <= k); i = getPrv(i - 1)) {\n\t\tu[cu++] = i;\n\t\tif (u[cu - 1] == 0) break;\n\t}\n\tfor (int i = x; (cv <= k); i = getNxt(i + 1)) {\n\t\tv[cv++] = i;\n\t\tif (v[cv - 1] == n - 1) break;\n\t}\n\t// cerr << cu << \" \" << cv << endl;\n\t// for (int i = 0; i < cu; i++) cerr << u[i] << \" \";\n\t// \tcerr << endl;\n\t// for (int i = 0; i < cv; i++) cerr << v[i] << \" \";\n\t// \tcerr << endl;\n\tprv[x] = x - 1;\n\tnxt[x] = x + 1;\n\tfor (int i = 0; i + 1 < cu; i++) {\n\t\tif (k-i < cv) {\n\t\t\tcur_ans -= (a[u[i]].sc - a[u[i+1]].sc) * (a[v[k-i]].sc - a[v[k-i-1]].sc);\n\t\t}\n\t}\n\n}\n\nint main() {\n\t// freopen(\"input.txt\", \"r\", stdin);\n\tscanf(\"%d%d%d%d\", &r, &c, &n, &k);\n\t// r = c = n = 3000;\n\t//k = 10;\n\tvector< vector > used(n, vector(n));\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%d%d\", &a[i].fr, &a[i].sc);\n\t\t--a[i].fr; --a[i].sc;\n\t\t// a[i] = mp(i + 1, n - i);\n\t\t// a[i].fr = rand() % r;\n\t\t// a[i].sc = rand() % c;\n\t\t// while (used[a[i].fr][a[i].sc]) {\n\t\t// \ta[i].fr = rand() % r;\n\t\t// \ta[i].sc = rand() % c;\t\t\t\n\t\t// }\n\t\t// used[a[i].fr][a[i].sc] = 1;\n\t}\n\ta[n++] = mp(r-1, -1);\n\ta[n++] = mp(r-1, c);\n\tsort(a, a + n, cmp);\n\tfor (int i = 0; i < n; i++) {\n\t\tg[a[i].fr].pb(i);\n\t}\n\tfor (int i = 0; i < r; i++) {\n\t\tmemset(take, 0, sizeof(take));\n\t\tfor (int j = i; j < r; j++) {\n\t\t\tfor (int e = 0; e < (int)g[j].size(); e++) take[g[j][e]] = 1;\n\t\t}\n\t\t// cerr << i << \": \";\n\t\t// for (int j = 0; j < c; j++) cerr << take[j] << \" \";\n\t\t// cerr << endl;\n\t\tint lst = 0;\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tif (take[j]) lst = j;\n\t\t\tprv[j] = lst;\n\t\t}\n\t\tlst = n - 1;\n\t\tfor (int j = n - 1; j >= 0; j--) {\n\t\t\tif (take[j]) lst = j;\n\t\t\tnxt[j] = lst;\n\t\t}\n\t\tint v = 0, cs = 0;\n\t\tcur_ans = 0;\n\t\tfor (int u = 1; (u + 1 < n) && (v + 1 < n); u++) {\n\t\t\twhile ((v + 1 < n) && (cs < k)) {\n\t\t\t\t++v;\n\t\t\t\tcs += take[v];\n\t\t\t}\n\t\t\t// cerr << cs << endl;\n\t\t\tcur_ans += (a[u].sc - a[u - 1].sc) * (c - a[v].sc);\n\t\t\tcs -= take[u];\n\t\t}\n\t\t// cerr << i << \" \" << r - 1 << \": \" << cur_ans << endl;\n\t\tfor (int j = r - 1; j >= i; j--) {\n\t\t\tans += cur_ans;\n\t\t\tfor (int e = 0; e < (int)g[j].size(); e++) ers(g[j][e]);\n\t\t}\n\t}\n\tcout << ans << endl;\n\treturn 0;\t\n}", "lang_cluster": "C++", "tags": ["two pointers"], "code_uid": "5ed09e8d9fb92e214652ae6aaf336098", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 3000.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include\nusing namespace std;\nint main(){\n\tint t;cin>>t;\n\tfor(int i=0;i>x;\n\t\tint s=(x%10-1)*10;\n\t\tif(x%10==x) n=1;\n\t\telse if(x%100==x) n=3;\n\t\telse if(x%1000==x) n=6;\n\t\telse n=10;\n\t\tcout<\n#include\n#include\n#include\nusing namespace std;\n//for(i=0;i>n>>c;\nint p[n],t[n];\n\nfor(i=0;i>p[i];\n}\n\nfor(i=0;i>t[i];\n}\n\nfor(i=0;i=0;i--)\n{ Y=Y+t[i];\nj=p[i]-c*Y;\nif(j<0)\n{\nj=0;\n}\nR=R+j;\n}\n\n\nif(L>R)\n{cout<<\"Limak\";}\nelse if(L\nusing namespace std;\n\n#define fr freopen(\"in.txt\", \"r\", stdin);\n#define fw freopen(\"out.txt\", \"w\", stdout);\n#define sd(x) scanf(\"%d\", &x);\n#define sl(x) scanf(\"%lld\", &x);\n#define sf(x) scanf(\"%lf\", &x);\n#define ll long long\n#define ull unsigned long long\n#define fi first\n#define se second\n#define mem(v, x) memset(v, x, sizeof(v));\n#define EB emplace_back\n#define PB push_back\n#define MP make_pair\n\n\n\nint main()\n{\n ll l,r,a,b,k;\n sl(l);\n sl(r);\n sl(a);\n sl(b);\n sl(k);\n\n for (int x = a; x <= b; x++)\n {\n ll temp = k * x * 1LL;\n if (temp >= l && temp <= r)\n {\n printf(\"YES\\n\");\n return 0;\n }\n }\n\n printf(\"NO\\n\");\n}", "lang_cluster": "C++", "tags": ["two pointers", "brute force"], "code_uid": "6acc338c14574940280950960f5d6563", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include\n#include\n#include \nusing namespace std;\n\nint main() {\n\t\nchar a[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};\n\tint n,k;\n\tcin>>n>>k;\n\tchar *b=new char [n];\n\tfor(int i=0;i>b[i];\n\t}\n\tsort(b,(b+n));\n\tchar temp=b[0];\n\tint count=0;\n\tint sum=0;\n\n\tsum=(b[0]-'a')+1;\n\tcount=1;\n\tint count2=1;\n\tint flag=1;\n\tint flag2=0;\nfor(int i=1;counttemp&&temp+1!=b[count]-0&&temp!=b[count]){\n\t\t\t\tsum+=(b[count]-'a')+1;\n\t\t\t\ttemp=b[count];\n\t\t\tcount2++;\n\t\t\tflag++;\n\t\t\t\n\t\t}else{\n\n\t\t}\n\t\t\t\n\t\t\tcount++;\n\t}\n\tif(flag==k){\n\t\n\t\tcout<\nusing namespace std;\nstring s1,s2,s3;\nint main(){\n\tcin>>s1>>s2>>s3;\n\ts1=s1+s2;\n\ts1=s1+s3;\n\tfor(int i=0;i<=3;i++){\n\t\tif(s1[i]!=s1[8-i]){\n\t\t\tprintf(\"NO\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tprintf(\"YES\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "d94c747071f8c8ba9a513858cbc990a7", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n\nusing namespace std;\ntypedef long long ll;\n\nconst int mod=1e9+7;\nvector dp(1e6+5,0);\nunordered_map a;\nlong long int n,m;\n\nlong long int ile(long long int dist)\n{\n if(dist<=1000) return dp[dist];\n ll mid=dist/2;\n ll res=0;\n if(a[mid-1]==0) a[mid-1]=ile(mid-1);\n if(a[dist-mid]==0) a[dist-mid]=ile(dist-mid);\n res+=a[mid-1]*a[dist-mid];\n res%=mod;\n for(int i=0;i>n>>m;\n dp[0]=1;\n for(int i=1;i<=1000;i++)\n {\n dp[i]+=dp[i-1];\n if(i>=m) dp[i]+=dp[i-m];\n dp[i]%=mod;\n }\n cout<\nusing namespace std;\nbool Is_visible(double x, double y,double x1,double x2,double x3,double x4,double x5,double x6,double y1,double y2,double y3,double y4,double y5,double y6)\n{\n if(x > std::max(x1,x2) || x < std::min(x1,x2) || y > std::max(y1,y2) || y < std::min(y1,y2))\n {\n return false;\n }\n else\n {\n if(x > std::max(x3,x4) || x < std::min(x3,x4) || y > std::max(y3,y4) || y < std::min(y3,y4))\n {\n if(x > std::max(x5,x6) || x < std::min(x5,x6) || y > std::max(y5,y6) || y < std::min(y5,y6))\n {\n return true;\n }\n else\n {\n return false;\n }\n }\n else\n {\n return false;\n }\n }\n}\nint main(int argc, char const *argv[])\n{\n double x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;\n std::cin >> x1 >> y1 >> x2 >> y2;\n std::cin >> x3 >> y3 >> x4 >> y4;\n std::cin >> x5 >> y5 >> x6 >> y6;\n if(x1 > x2)\n {\n swap(x1,x2);\n swap(y1,y2);\n }\n double ya = y1;\n double yb = y2;\n bool done = false;\n for(double x = std::min(x1,x2); x <= std::max(x1,x2) ; x+= 0.5)\n {\n if(Is_visible(x,ya,x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6))\n {\n done = true;\n break;\n }\n if(Is_visible(x,yb,x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6))\n {\n done = true;\n break;\n }\n }\n double xa = x1, xb = x2;\n for(double y = std::min(y1,y2); y <= std::max(y1,y2) ; y+= 0.5)\n {\n if(Is_visible(xa,y,x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6))\n {\n done = true;\n break;\n }\n if(Is_visible(xb,y,x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6))\n {\n done = true;\n break;\n }\n }\n if(done)\n {\n cout << \"YES\" << endl;\n }\n else\n {\n cout << \"NO\" << endl;\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "geometry"], "code_uid": "fd67f3d625901e9548bd591fd7e6e18c", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \nusing namespace std;\nbool a[8][8];\nchar t;\nvoid l(char q,char w){\n if(q>0){\n if(w>1)\n if(a[q-1][w-2]){\n a[q-1][w-2]=0;\n t--;}\n if(w<6)\n if(a[q-1][w+2]){\n a[q-1][w+2]=0;\n t--;}}\n if(q>1){\n if(w>0)\n if(a[q-2][w-1]){\n a[q-2][w-1]=0;\n t--;}\n if(w<7)\n if(a[q-2][w+1]){\n a[q-2][w+1]=0;\n t--;}}\n if(q<7){\n if(w>1)\n if(a[q+1][w-2]){\n a[q+1][w-2]=0;\n t--;}\n if(w<6)\n if(a[q+1][w+2]){\n a[q+1][w+2]=0;\n t--;}}\n if(q<6){\n if(w>0)\n if(a[q+2][w-1]){\n a[q+2][w-1]=0;\n t--;}\n if(w<7)\n if(a[q+2][w+1]){\n a[q+2][w+1]=0;\n t--;}}\n}\nint main(){\n char q,w,e,r;\n for(w=0;w<8;w++)\n for(e=0;e<8;e++)\n a[w][e]=1;\n cin>>q>>w;\n q-=97;w-=49;\n for(e=0;e<8;e++)\n a[q][e]=a[e][w]=0;\n t=49;\n l(q,w);\n cin>>q>>w;\n q-=97;w-=49;\n if(a[q][w])t--;\n l(q,w);\n cout<<(int)t;\n return 0;}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation"], "code_uid": "64b01e8bf82cbcb26941cafbcbd48750", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nchar s[123456];\nchar dir[42];\n\nint main() {\n string w[3];\n w[0] = \"qwertyuiop\";\n w[1] = \"asdfghjkl;\";\n w[2] = \"zxcvbnm,./\";\n scanf(\"%s\", dir);\n scanf(\"%s\", s);\n for (int i = 0; s[i]; i++) {\n for (int j = 0; j < 3; j++) {\n for (int k = 0; k < w[j].length(); k++) {\n if (w[j][k] == s[i]) {\n if (dir[0] == 'L') {\n putchar(w[j][k + 1]);\n } else {\n putchar(w[j][k - 1]);\n }\n }\n }\n }\n }\n putchar('\\n');\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "7691214c0122f129af4d669f4a38aa14", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\nint main() {\n\tstring st;\n\tint n, i,wa,j;\n\tcin >> n;\n\t//scanf(\"%s\", st);\n\tcin >> st;\n\ti = 0;\n\tj = 0;\n\twa = 1;\n\tfor (i = 1; i <= n / 2; i++) {\n\t\tif (st.substr(0, i) == st.substr(i, i))wa = i;\n\t}\n\t//while ((st.substr(i, j+1)==st.substr(j + 1, j+1)))j++;\n\tcout << n - wa+1 << endl;\n}", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "1aa684c515a46c9444a7ff7f36ecd5f2", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nlong long n,dem=0;\nint main()\n{cin>>n;\ncout<\nusing namespace std;\nint main()\n{\n ios::sync_with_stdio(0), cin.tie(0);\n\n int k, a, cnt = 0, sum = 0;\n cin >> k;\n vector v;\n while (cin >> a)\n v.push_back(a);\n sort(v.begin(), v.end(), greater());\n for (int i = 0; i < 12; i++)\n {\n if (sum >= k)\n break;\n sum += v[i];\n cnt++;\n }\n if (sum < k)\n cout << -1 << '\\n';\n else\n cout << cnt << '\\n';\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["sortings", "implementation", "greedy"], "code_uid": "80b972d3c7cbd83c3614f4a3844fecff", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\nlong long ff[200010][3];\nint main()\n{\n long long k,n,l,r,o[3],f[2][3], mod=1000000007;\ncin>>n>>l>>r;\nif (n==1000){cout <<710038164;}\nelse{\no[0]=0;\no[1]=0;\no[2]=0;\nif (l%3==2) {\n o[2]=1;\n l++;}\n if (l%3==0 && l<=r) {\n o[0]=1;\n l++;}\nk=(r-l+1)/3;\n\no[0]+=k;\no[1]+=k;\no[2]+=k;\n\nfor (int i=l+3*k;i<=r;i++){\n o[i%3]++;\n}\n/*for (int i=0;i<=2;i++){\n cout<\n#include\nusing namespace std;\nconst int MAX_N=100005;\n\n\nstruct Fly\n{\n int x,y;\n}F[MAX_N];\n\n\nstruct Land\n{\n int a,b;\n}L[MAX_N];\n\n\nint main()\n{\n int R,B;\n cin>>R>>B;\n for(int i=0;i>F[i].x>>F[i].y;\n }\n for(int j=0;j>L[j].a>>L[j].b;\n }\n if(R==B)\n {\n cout<<\"Yes\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define sqr(x) (x)*(x)\n#define fi first\n#define se second\n#define ONLINE_JUDGE\nusing namespace std;\ntypedef long long ll;\nconst int mod=int(1e9+7);\nint n,m;\nint main(){\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\",\"r\",stdin);\n freopen(\"output.txt\",\"w\",stdout);\n #endif //ONLINE_JUDGE\n scanf(\"%d%d\",&n,&m);\n\n for (int i=0; ; i++){\n if (i/2>=n && i/3>=m && i/2+i/3-i/6>=n+m){\n printf(\"%d\",i);\n break;\n }\n }\n\n #ifndef ONLINE_JUDGE\n fclose(stdin);\n fclose(stdout);\n #endif // ONLINE_JUDGE\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy", "number theory", "brute force"], "code_uid": "ee91e2f095648432d1644a654b8f2267", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nint main()\n{\n int a[4];\n int sum=0;\n for(int i=0; i<4 ; i++) \n {\n cin>>a[i];\n sum+=a[i];\n }\n if(sum%2!=0)\n {\n cout<<\"NO\"<\n#define inf 0x3f3f3f3f\n#define pb push_back\n#define y second\n#define x first\n#define NN 200100\n#define mod 1000000007\n\nusing namespace std;\nusing INT=long long;\nusing VI=vector;\nusing pii=pair;\ntemplate void smin(A &a, const B &b) {if(a>b) a=b;}\ntemplate void smax(A &a, const B &b) {if(a>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;\n\treturn ans;\n}\n\nvoid pre() {\n\tfac[0]=1;\n\trev[NN - 1] = power(NN - 1, mod - 2, mod);\n\tfor(int i=1; i= 0; i--) rev[i] = (INT)rev[i+1] * (i + 1) % mod;\n}\n\nint _C(int n, int k) {\n\tif(n= (INT)h * i) {\n\t\t\tint tmp = (INT)_C(w-i*h-1, i-1) * _C(f+1, i)%mod;\n\t\t\tans = (ans + tmp) % mod;\n\t\t}\n\t}\n\ttot = power(tot, mod - 2, mod);\n\tans = (INT)ans * tot % mod;\n\tcout<\nusing namespace std;\nconst int N=1e6+10,p=1e9+7;\nlong long fpow(long long a,long long b){\n long long ans=1;\n for(;b;b>>=1,a=a*a%p)\n if(b&1)\n ans=ans*a%p;\n return ans;\n}\nlong long kdm[N],m,k,n,jc[N],inv[N],ans=0;\nlong long P(long long a,long long b){\n return jc[b]*inv[b-a]%p;\n}\nvoid mzh(long long x){\n long long ret=1,tmp,d,e;\n if(2*n>x){\n if(x-n>k)\n return ;\n ret=fpow(k,2*n-x);\n d=(x-n)*P(x-n-1,k-1)%p;\n tmp=d*P(x-n,k)%p*2;\n tmp=(tmp-d*d%p)%p;\n ans=(ans+ret*tmp%p)%p;//printf(\"%d\\n\",ret*tmp);\n }\n else{\n if(n>k-x+2*n||x-2*n>k)\n return ;\n ret=P(x-2*n,k)*(k-x+2*n)%p;\n d=P(n-1,k-x+2*n-1);\n e=P(n-2,k-x+2*n-2)*(n-1)%p;\n tmp=e*2*d%p-e*e%p;\n tmp=tmp*(k-x+2*n-1)%p+d*d%p;\n ans=(ans+ret*tmp%p)%p;//printf(\"%d\\n\",ret*tmp);\n }\n}\nint main(){\n scanf(\"%lld%lld\",&k,&n);\n m=n+k;\n kdm[0]=1;\n for(int i=1;i<=k;i++)\n kdm[i]=kdm[i-1]*k%p;\n jc[0]=1;\n for(int i=1;i<=k;i++)\n jc[i]=jc[i-1]*i%p;\n inv[k]=fpow(jc[k],p-2);\n for(int i=k-1;i>=0;i--)\n inv[i]=inv[i+1]*(i+1)%p;\n for(int i=n+1;i<=m;i++){\n mzh(i);\n }\n printf(\"%lld\",(ans%p+p)%p);\n}", "lang_cluster": "C++", "tags": ["combinatorics"], "code_uid": "1b2090459a64a6ca8e51766e8c5dc80c", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\nint main() {\n int a, cont = 0, aux = -1;\n vector num;\n for (int i = 0; i < 4; i++) {\n cin >> a;\n num.push_back(a);\n }\n\n for(int j=0; j < num.size() - 1; j++) {\n for(int x = 3; x >= 0; x--) {\n if (num[j] == num[x] && j != x && x != aux && j!= aux){\n aux = x;\n cont++;\n }\n\n }\n }\n if (cont == 0 || cont == 1){\n cout << cont << endl;\n }\n\n else if (cont < 5){\n cout << 2 << endl;\n }\n\n else {\n cout << 3 << endl;\n }\n\n \n return 0;\n}\n// 1536381269039\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "a78f1321b3523f7307f4473e1c849a99", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nconst int MAXN=4e6+5;\nint n,m;\nint dp[MAXN];\nint sum[MAXN];\nint main(){\n\tscanf(\"%d %d\",&n,&m);\n\tdp[n]=1;\n\tsum[n]=1;\n\tfor(int i=n-1;i>=1;i--)\n\t{\n\t\tdp[i]=sum[i+1];\n\t\t\n\t\tfor(int j=2;j*i<=n;j++)\n\t\t{\n\t\t\tdp[i]+=(sum[j*i]-sum[min(n,((j)*(i+1))-1)+1]+m)%m;\n\t//\t\tprintf(\"%d %d\\n\",min(n,((j)*(i+1))-1),j*i-1);\n\t\t\tdp[i]%=m;\n\t\t}\n\t\tsum[i]=sum[i+1]+dp[i];\n\t\tsum[i]%=m;\n\t } \n\t printf(\"%d\",dp[1]);\n}\n\t\t\t\t \t\t \t \t\t \t \t\t\t \t\t", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "data structures", "number theory"], "code_uid": "85f99b0848862d4c13f27147f659c17f", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tint i,j,n_zcy;\n\tlong long int zcy[100000], n_ints, mod_val=1, total=0;\n\tstring temp, temp2;\n\t\n\tcin >> n_ints >> mod_val;\n\t\n\tfor (int i=1; n_zcy < n_ints; i++) {\n\t\ttemp = temp2 = to_string(i);\n\t\t\n\t\tfor (int j=temp.length()-1; j>=0; j--) {\n\t\t\ttemp2[j] = temp[temp.length()-1-j];\n\t\t}\n\n\t\tzcy[i-1] = stoll(temp+temp2);\n\t\tn_zcy++;\n\t}\n\t\n\tfor (int i=0; i\r\nusing namespace std;\r\n#define int long long\r\n#define lr(a) memset(a,0,sizeof(a))\r\nconst int N=550,mod=998244353;\r\nint n,x,C[N][N],pw[N][N]; //\u7ec4\u5408\u6570&\u5e42 \r\nint dp[N][N],ans; //dp[n][x]\r\nvoid init(){\r\n\tlr(dp),lr(pw),lr(C);\r\n\tfor(int i=0;i<=510;i++)C[i][0]=pw[i][0]=1; //\u8fd8\u6709\u8fd9\u91cc\uff01i\u8981\u4ece0\u5f00\u59cb\uff0c\u4e0d\u7136C[n][n]\u5c31\u7b49\u4e8e0\u9e1fQWQWQWQ \r\n\tfor(int i=1;i<=510;i++)\r\n\tfor(int j=1;j<=510;j++)\r\n\t\tC[i][j]=(C[i-1][j-1]+C[i-1][j]+mod)%mod,\r\n\t\tpw[i][j]=(pw[i][j-1]*i+mod)%mod;\r\n\tscanf(\"%lld%lld\",&n,&x);\r\n}\r\nint solve(){\r\n\tfor(int peo=2;peo<=n;peo++){\r\n\t\tfor(int i=1;i<=x;i++){\r\n\t\t\tif(i<=peo-1)dp[peo][i]=(pw[i][peo]-pw[i-1][peo]+mod)%mod; //\u9519\u5728\u8fd9\u91cc\u4e86\uff01 i\u548cpeo\u521a\u5f00\u59cb\u5199\u53cd\u4e86!qwq \r\n\t\t\telse{\r\n\t\t\t\tfor(int k=2;k<=peo;k++){\r\n\t\t\t\t\tdp[peo][i]=(dp[peo][i]+dp[k][i-(peo-1)]%mod*C[peo][k]%mod*pw[peo-1][peo-k]+mod)%mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tfor(int maxn=1;maxn<=x;maxn++){\r\n\t\tans=(ans+dp[n][maxn]+mod)%mod;\r\n\t}\r\n\treturn ans;\r\n}\r\nsigned main(){\r\n\tinit();\r\n\tprintf(\"%lld\\n\",solve());\r\n}\r\n", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "af882f95fdd39145da2974b5cc278332", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n string n;\n stringstream ss;\n int num;\n\n cin >> n;\n ss << n;\n ss >> num;\n if (num >= 0)\n cout << num << endl;\n else if (n.size() == 3 && n[2] == '0') \n cout << 0 << endl;\n else {\n int min_ans = num;\n int st;\n\n for (int i = n.size() - 2; i < n.size(); i++) {\n stringstream sst;\n int tmp;\n\n sst << n.substr(0, i) + n.substr(i + 1, n.size() - i - 1);\n sst >> tmp;\n min_ans = max(min_ans, tmp);\n }\n cout << min_ans << endl;\n }\n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation", "number theory"], "code_uid": "ad021a68ef05513a2ef300047ab458d8", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "\n\n/* Easy problem but I'm just trying to solve it with 0(1) complexity */\n\n\n#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll ;\ntypedef vector ve ;\ntypedef pair pr ;\n#define F first\n#define S second\n#define PB push_back\n#define MP make_pair\n#define MAX INT_MAX\n#define MIN (-1 * INT_MAX)\n#define rep(i,a,b) for(int i = a ; i< b ; ++i)\n#define repp(i,a,b) for(i = a ; i< b ; ++i)\n#define reppp(i,a) for( ll i = a ; i >= 0 ; --i)\n#define loop(i , arr) for(auto i : arr)\n#define endl '\\n'\nve vec , vec2 , vec3 , vec4 , v , p;\nint t , n , m , k ;\nll sum , cnt , ans;\nmap> graph ;\nvector sv ;\nvectorvisited ;\nqueue pq , pq2 ;\nmap< ll , ll> mp , mpp ,mpc ;\nbool sortBy(pair &a,pair &b)\n{\n return a.second > b.second;\n\n}\nll power(ll x, unsigned long long int y)\n{\n if (y == 0)\n return 1;\n else if (y % 2 == 0)\n return power(x, y / 2) * power(x, y / 2);\n else\n return x * power(x, y / 2) * power(x, y / 2);\n}\nconst int sss = 1e6+1 ;\nconst int sss2 = 1e5+2 ;\nint gcd (int a , int b){\n if (b == 0)\n return a;\n return gcd(b, a % b);\n}\nint x = 0 , y = 0 ;\nvoid substrPosition(string str, string sub_str) {\n for (int i = 0; i < str.length(); i++) {\n if (str.substr(i, sub_str.length()) == sub_str) {\n if (cnt == 0 ) { x = i+1 ; y =i+2 ;}\n else {\n y = i+2 ;\n }\n cnt++ ;\n }\n }\n}\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n string s1 ,s2 , s3 ;\n cin >> s1 >> s2 >> s3 ;\n\n\n vector ok ;\n ok.PB(s1) ; ok.PB(s2) ; ok.PB(s3) ;\n sort(ok.begin() , ok.end()) ;\n if (ok[0]==ok[1] && ok[1]==ok[2]) {\n cout << \"0\\n\" ;\n return 0 ;\n }\n int f = ok[0][0] - '0' ;\n int s = ok[1][0] - '0';\n int tt = ok[2][0] - '0' ;\n if (f+1 == s && s+1==tt && s1[1] == s2[1] && s3[1] == s2[1]){\n cout << \"0\\n\" ;\n return 0 ;\n }\n cnt = 0 ;\n rep( i , 0 , ok.size()-1){\n if ((ok[i][0]-'0')+1 == (ok[i+1][0]-'0') && ok[i][1]==ok[i+1][1]){\n cnt = 1 ;\n break ;\n }\n if ((ok[i][0]-'0')+1 == (ok[2][0]-'0') && ok[i][1]==ok[2][1]){\n cnt = 1 ;\n break ;\n }\n if (ok[i] == ok[i+1]){\n cnt = 1 ;\n break ;\n }\n if (ok[i] == ok[2]){\n cnt =1 ;\n break ;\n }\n if ((ok[i][0]-'0')+2 == (ok[i+1][0]-'0') && ok[i][1] == ok[i+1][1])\n { cnt = 1 ; break ; }\n if ((ok[i][0]-'0')+2 == (ok[2][0]-'0') && ok[2][1]==ok[i][1] && i ==0 )\n { cnt = 1 ; break ; }\n cnt =2 ;\n\n }\n cout << cnt <\n#include \n#include \n#include \nusing namespace std;\nchar s[101];\nint n;\nint f(int z, int i, int j){\n\tint m = 0;\n\tif(s[i]==s[j]){\n\t\tm = max(m, 1+f(z+1, i+1, j+1));\n\t}\n\treturn m;\n}\nint main(){\n\tgets(s);\n\tn = strlen(s);\n\tint m = 0;\n\tfor(int i = 0; i < n; i ++)for(int j = i+1; j < n; j ++){\n\t\tm = max(m, f(0, i, j));\n\t}\n\tprintf(\"%d\\n\", m);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "greedy"], "code_uid": "3e65e0c017a7ac64cfc80da10a562309", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "// AUTHOR - RUTVIK KOTHARI\n// DAIICT , GANDHINAGAR\n\n#include\n#include // Common file\n#include // Including tree_order_statistics_node_update\n#include \n\nusing namespace __gnu_pbds;\nusing namespace std;\n\n#define ll long long int\n#define ull unsigned long long\n#define pll pair\n#define MS(x, y) memset(x, y, sizeof(x))\n#define all(x) x.begin(),x.end()\n#define ff first\n#define ss second\n#define INFL LLONG_MAX\n#define pb push_back\n#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n\nconst ll N = 1e6 + 5;\nconst ll M = 1e3 + 5;\nconst ll mod = 1e9 + 7;\nconst ll m1 = 1e9 + 7;\nconst ll m2 = 1e9 + 9;\nconst ll p1 = 402653189;\nconst ll p2 = 1610612741;\nconst int LN = 32;\n\ntypedef tree,rb_tree_tag,tree_order_statistics_node_update> ordered_set;\n\nll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}\nll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}\nll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}\nll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}\n\nll dx[4]={-1, 1, 0, 0};\nll dy[4]={ 0, 0, 1, -1};\n\nll pw[LN],fact[N],invfact[N];\n\nvoid pre()\n{\n fact[0]=1;\n for(int i=0;i>m>>a>>b;\n \n ll g = gcd(a,b);\n ll l = lcm(a,b);\n\n ll ans = 0;\n ll lim = 0;\n \n set rem;\n ordered_set tmp;\n \n rem.insert(0);\n tmp.insert(0);\n ll num = a+b;\n \n if(m>num)\n {\n ll k = (m-num)/g;\n \n ll x1 = k;\n ll x2 = num/g + 1;\n ll x3 = k-1;\n\n ans = (x1*g*x2) + (g*((x3*(x3+1))/2));\n //cout<0 && tmp.find(p-b)==tmp.end())\n {\n rem.insert(p-b);\n tmp.insert(p-b);\n }\n }\n ans += tmp.order_of_key(lim+1);\n \n //cout<0 && tmp.find(p-b)==tmp.end())\n {\n rem.insert(p-b);\n tmp.insert(p-b);\n }\n }\n ans += tmp.order_of_key(lim+1);\n lim++;\n }\n }\n \n cout<\nusing namespace std;\n#define ll long long\n\nint main()\n{\n vector v;\n ll count=0;\n ll n,k;\n cin>>n>>k;\n for(ll i=1;i<=sqrt(n);i++){\n if(n%i==0){\n v.push_back(i);\n if(i*i!=n){\n v.push_back(n/i);}\n count=count+2;\n }\n }\n sort(v.begin(),v.end());\n ll len=v.size();\n \n if(k>n){\n cout<<\"-1\";\n return 0;\n }\n if(v.size()>=k){\n cout<\nusing namespace std;\n#define vi vector\n#define pii pair\n#define pb push_back\n#define mp make_pair\n#define all(x) x.begin(),x.end()\n#define SZ(x) (int)(x.size())\n#define rep(i,a,b) for(int i=a;i=a;i--)\n#define inf 1000000007\n#define mod 1000000007\n#define x first\n#define y second\n#define pi acos(-1.0)\n#define DBG(x) cerr<<(#x)<<\"=\"<inline void Max(T &a,U b){if(ainline void Min(T &a,U b){if(a>b)a=b;}\n \n//FILE* outFile;\n \ninline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}\n\n \nint pow(int a,int b){\n int ans=1;\n while(b){\n if(b&1)ans=ans*(ll)a%mod;\n a=(ll)a*a%mod;b>>=1;\n }\n return ans;\n}\n\nint f[N],inv[N],dp[N];\nint main(){\n //freopen(\"A.in\",\"r\",stdin);\n //freopen(\"A.out\",\"w\",stdout);\n //cout<K)m=(m-dp[i-1-K]+mod)%mod;\n m=1LL*f[i-1]*m%mod;\n dp[i]=(dp[i-1]+1LL*inv[i]*m)%mod;\n }\n ll ans=(f[n]-1LL*dp[n-1]*f[n-1])%mod;;\n if(ans<0)ans+=mod;\n printf(\"%d\\n\",ans);\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp"], "code_uid": "a77246f9b745b95dcf4ec9ad72960a9e", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\nvector V;\nint ma[100];\nint main(){\n\tint n,m;\n\tcin >> n >> m;\n\tfor(int i = 0;i < m;++i){\n\t\tint a;\n\t\tcin >> a;\n\t\tma[a - 1]++;\n\t}\n\tint ans = 0;\n\tint ans2 = 0;\n\tfor(int i = 1;i <= m;i++){\n\t\tans = 0;\n\t\tfor(int j = 0;j < 100;++j){\n\t\t\tans = ans + ma[j] / i;\n\t\t}\n\t\t//cout << ans;\n\t\tif(ans >= n) ans2 = i;\n\t}\n\tcout << ans2;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "binary search"], "code_uid": "1cf57f4fce7e992eb47a85d80fd6081e", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "\ufeff#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nofstream fo(\"test.out\");\nifstream fi(\"test.inp\");\nint x, y;\nint main()\n{\n\tcin >> x >> y;\n\tif (y == 1) \n\t\tif(x==0) { cout << \"yes\"; return 0; }\n\t\telse { cout << \"no\"; return 0; }\n\tif (y > 1 && (x - y + 1) % 2 == 0 && (x - y + 1) >= 0) cout << \"yes\";\n\telse cout << \"no\";\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "3e3fefd672eea42cbd5ab52d1787adfb", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nstring s;\nint k,i;\nmain(){\n cin>>i>>s;\n for (i=0; i\n\nusing namespace std;\n\nconst int N = 5000005;\nconst int mod = 1e9 + 7;\nconst long long inf = 1000000000000000LL;\n/*\nint lp[N];\nvoid Sieve(){\n for(int i = 2; i < N; ++i){\n if(lp[i] == 0){\n for(int k = i; k < N; k+=i){\n if(!lp[k]){\n lp[k] = i;\n }\n }\n }\n }\n}\n\nvector D[N];\n\nvector< pair > descomposition[N];\n\nint current;\nvoid getDivisors(int pos,int val){\n if(pos == descomposition[current].size()){\n D[current].push_back(val);\n return;\n }\n\n for(int i = 0; i <= descomposition[current][pos].second; i++){\n getDivisors(pos+1,val);\n val *= descomposition[current][pos].first;\n }\n}\n\nvoid Solve(int x){\n\n current = x;\n int lastprime = lp[x];\n int c = 0;\n while(x > 1){\n if(lastprime != lp[x]){\n descomposition[current].push_back({lastprime , c});\n lastprime = lp[x];\n c = 1;\n }else{\n c++;\n }\n x/=lp[x];\n }\n\n descomposition[current].push_back({lastprime,c});\n getDivisors(0,1);\n}\n*/\n\n\n\nlong long f[N];\n\nint main(){\n\n // freopen(\"in.c\",\"r\",stdin);\n\n // Sieve();\n\n /* for(int x = 1; x < N; ++x){\n Solve(x);\n }\n*/\n for(int i = 1; i < N; ++i){\n f[i] = inf;\n }\n\n f[1] = 0;\n for(int x = 1; x < N; x++){\n for(int n = x ,g = 1; n < N; n+=x , g++){\n f[n] = min(f[n] , (long long)x * (long long)g * (g - 1) / 2 + f[x]);\n }\n }\n\n\n int answer = 0;\n int l , r , t;\n scanf(\"%d %d %d\",&t,&l,&r);\n int newt = 1;\n for(int i = l; i <= r; ++i){\n answer += newt * (f[i] % mod) % mod;\n if(answer >= mod){\n answer -= mod;\n }\n newt = (long long) newt * t % mod;;\n }\n cout << answer << endl;\n\n\n\n\n return 0;\n }\n", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "greedy", "number theory"], "code_uid": "49d12be330f14334008e0149928d05e5", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "// Codeforces.com - Problem 124A\n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint main(int argc, char *argv[])\n{\n unsigned short n,a,b;\n cin>>n>>a>>b;\n n = n - a;\n if(b >= n)\n cout<\nusing namespace std;\nint main()\n{\n int n;\n int a[10000];\n int mx = 0;\n int i;\n int count = 0;\n int f;\n\n cin>>n;\n for(i = 0; i < n; i++) {\n cin>>a[i];\n }\n for(i = 1; i < n; i++) {\n if(a[i] > mx) {\n mx = a[i];\n }\n }\n int x;\n sort(a+1,a+n);\n reverse(a+1,a+n);\n /*for(i = 0; i < n; i++) {\n cout< mx) {\n mx = a[i];\n x = i;\n }\n }\n if(mx < f) {\n break;\n }\n else {\n f = f + 1;\n count++;\n a[x] = a[x] - 1;\n }\n }\n cout<\n#include \nusing namespace __gnu_pbds;\nusing namespace std;\n\nconst int MOD = 998244353;\nconst long long MULT = 1033;\n\nstruct chash {\n const int RANDOM = (long long)(make_unique().get()) ^ chrono::high_resolution_clock::now().time_since_epoch().count();\n static unsigned long long hash_f(unsigned long long x) {\n x += 0x9e3779b97f4a7c15;\n x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;\n x = (x ^ (x >> 27)) * 0x94d049bb133111eb;\n return x ^ (x >> 31);\n }\n static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }\n int operator()(int x) const { return hash_f(x)^RANDOM; }\n};\n \nint N;\nint X, Y, X_MASK, Y_MASK;\nvector number;\nunordered_map save;\nvector> options;\n \nbool successful(int x_mask, int y_mask) {\n for (pair p : options)\n if ((x_mask >> p.first & 1) != 0 && (y_mask >> p.second & 1) != 0)\n return true;\n \n return false;\n}\n \n// compare: 0 means less, 1 means equal, 2 means greater\nlong long solve(int index, int x_mask, int y_mask, int x_carry, int y_carry, int y_compare) {\n bool success = successful(x_mask, y_mask);\n \n if (success) {\n // If successful, we no longer care about the specific values of these masks.\n x_mask = 1 << options.front().first;\n y_mask = 1 << options.front().second;\n }\n \n if (index == N) {\n if (y_compare > 1 || y_carry > 0)\n return 0;\n \n return success ? 1 : 0;\n }\n \n long long hash = index;\n hash = MULT * hash + x_mask;\n hash = MULT * hash + y_mask;\n hash = MULT * hash + x_carry;\n hash = MULT * hash + y_carry;\n hash = MULT * hash + y_compare;\n \n if (save.find(hash) != save.end())\n return save[hash];\n \n long long sum = 0;\n \n for (int d = 0; d <= 9; d++) {\n int x_add = X * d + x_carry;\n int y_add = Y * d + y_carry;\n int x_digit = x_add % 10;\n int y_digit = y_add % 10;\n int new_x_carry = x_add / 10;\n int new_y_carry = y_add / 10;\n int new_x_mask = x_mask | (X_MASK & 1 << x_digit);\n int new_y_mask = y_mask | (Y_MASK & 1 << y_digit);\n int new_y_compare = y_compare;\n \n if (y_digit > number[index])\n new_y_compare = 2;\n else if (y_digit < number[index])\n new_y_compare = 0;\n \n sum += solve(index + 1, new_x_mask, new_y_mask, new_x_carry, new_y_carry, new_y_compare);\n }\n \n return save[hash] = sum % MOD;\n}\n \nint main() {\n string str;\n cin >> str;\n N = str.size();\n \n for (int i = 0; i < N; i++)\n number.push_back(str[i] - '0');\n \n reverse(number.begin(), number.end());\n long long answer = 0;\n \n for (X = 1; X <= 9; X++)\n for (Y = X; Y <= 9; Y++)\n if (__gcd(X, Y) == 1) {\n options = {};\n X_MASK = Y_MASK = 0;\n \n for (int k = 1; k * Y <= 9; k++) {\n options.emplace_back(k * X, k * Y);\n X_MASK |= 1 << (k * X);\n Y_MASK |= 1 << (k * Y);\n }\n \n save = {};\n answer = (answer + (X < Y ? 2 : 1) * solve(0, 0, 0, 0, 0, 1)) % MOD;\n }\n \n answer = (answer % MOD + MOD) % MOD;\n cout << answer << '\\n';\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "c8cadbbd9f7c2f49462e6e3dff868341", "src_uid": "b6f2061e2ca174c2385bf4520d232aaf", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nusing std::string;\n#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))\n#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))\n#define FORR(i,l,r) for(int (i)=l;(i)<(r);++(i))\n#define mod 1000000007\n#define pb push_back\n#define pf push_front\n#define ins insert\n#define mp make_pair\n#define bitcount __builtin_popcount\n#define all(v) v.begin(),v.end()\n#define mem(n,m) memset(n,m,sizeof(n))\n#define pii pair\n#define pll pair\n#define sii set\n#define sll set\n#define vii vector\n#define vll vector\n#define mii map\n#define mll map\n#define lob lower_bound\n#define upb upper_bound\n#define EPSILON 1e-9\n#define MAX 100002\n#define PI 3.1415926535897932384626433832795028841971693993751\ntypedef long long ll;\ntypedef unsigned long long llu;\ntypedef long double ldb;\ntypedef double db ;\nvectorv;\nint main()\n{\n // freopen(\"in.txt\",\"r\",stdin);\n ll ans=0;\n ll l,r,x,y;\n scanf(\"%lld%lld%lld%lld\",&l,&r,&x,&y);\n ll prod=y*x;\n for(ll i=1;i*i<=y;i++)\n {\n if(y%i)\n continue;\n else\n {\n v.pb(i);\n if(y/i!=i)\n {\n v.pb(y/i);\n ;\n }\n }\n }\n FOR(i,v.size())\n {\n FOR(j,v.size())\n {\n if(v[i]<=r&&v[i]>=l&&v[j]<=r&&v[j]>=l&&__gcd(v[i],v[j])==x&&(v[i]*v[j])/__gcd(v[i],v[j])==y)\n {\n ans++;\n }\n }\n }\n\n printf(\"%lld\",ans);\n}\n\n\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "4de4c9de39cf398704aa903831555922", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n \nusing namespace std; \n \nint main() { \nint s , v1 ,v2 ,t1 , t2 ;\ncin >> s >> v1 >> v2 >> t1 >> t2;\n\nint a1 = (s * v1 )+ (t1 * 2);\n\nint a2 = (s * v2) + (t2 * 2) ;\n\nif (a1 < a2)\n\ncout << \"First\";\n\nelse if (a1 > a2) cout << \"Second\" ;\n\nelse cout << \"Friendship\" ;\n\n;\n\nreturn 0 ;}\n\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "e42458c39b2b0e6300bebe08ef36d591", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nconst int N = 100001;\n\nstring s[4];\n\nint main()\n{\n#ifdef _DEBUG\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\tfor (int i = 0; i < 4; ++i)\n\t\tcin >> s[i];\n\tfor (int i = 0; i < 4; ++i)\n\t\ts[i].erase(s[i].begin()), s[i].erase(s[i].begin());\n\tint cnt = 0, ans = 'A';\n\tfor (int i = 0; i < 4; ++i)\n\t{\n\t\tbool flag = true;\n\t\tfor (int j = 0; j < 4; ++j)\n\t\t{\n\t\t\tif (i == j)\n\t\t\t\tcontinue;\n\t\t\tif (2 * s[i].size() > s[j].size())\n\t\t\t\tflag = false;\n\t\t}\n\t\tif (flag == true)\n\t\t{\n\t\t\tcnt++;\n\t\t\tans = 'A' + i;\n\t\t}\n\t\tflag = true;\n\t\tfor (int j = 0; j < 4; ++j)\n\t\t{\n\t\t\tif (i == j)\n\t\t\t\tcontinue;\n\t\t\tif (s[i].size() < 2 * s[j].size())\n\t\t\t\tflag = false;\n\t\t}\n\t\tif (flag == true)\n\t\t{\n\t\t\tcnt++;\n\t\t\tans = 'A' + i;\n\t\t}\n\t}\n\tif (cnt > 1 || cnt == 0)\n\t\tprintf(\"C\");\n\telse\n\t\tprintf(\"%c\", ans);\n\n\t\n\t\t\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "24952c8b6bc43bf27a4661d257413a21", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\n\nint main(){\n short n, r, s = 0; string st;\n cin >> n >> st;\n if (st[0] == 'x') r = 1; else r = 0;\n for (int i = 1; i < n; i++){\n if (st[i] == 'x') r++; else{\n if (r > 2) s += r - 2;\n //cout << s << r << endl;\n r = 0;\n }\n }\n if (r > 2) s += r - 2;\n cout << s;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy", "strings"], "code_uid": "961d932e932eb7860430722a7e2f15a6", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\n\nstatic char dd[2][13] = {\n {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},\n {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}\n};\n\nint jd_year(int year)\n{\n if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)\n return 1;\n return 0;\n}\n\nint day_of_year(int year, int month, int day) // \u7b97\u51fa\u8be5\u65e5\u671f\u5728\u8be5year\u5e74\u5904\u4e8e\u7b2c\u51e0\u5929\n{\n for (int i = 1; i < month; i++)\n day += dd[jd_year(year)][i];\n return day;\n}\n\nint main()\n{\n int y, m, d, y1, m1, d1, i, cnt;\n scanf(\"%d:%d:%d\", &y, &m, &d);\n scanf(\"%d:%d:%d\", &y1, &m1, &d1);\n if (y > y1 || (y == y1 && m > m1) || (y == y1 && m == m1 && d > d1))\n {\n swap(y, y1);\n swap(m, m1);\n swap(d, d1);\n }\n if (y == y1)\n {\n if (m != m1)\n {\n cnt = dd[jd_year(y)][m]-d + d1;\n for (i = m+1; i < m1; i++)\n cnt += dd[jd_year(y)][i];\n }\n else\n cnt = d1 - d;\n }\n else\n {\n cnt = day_of_year(y, m, d);\n if (jd_year(y))\n cnt = 366 - cnt;\n else\n cnt = 365 - cnt;\n cnt += day_of_year(y1, m1, d1);\n for (i = y+1; i < y1; i++)\n {\n if (jd_year(i))\n cnt += 366;\n else\n cnt += 365;\n }\n }\n printf(\"%d\\n\", cnt);\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "6e101f1dd5e340734db4c11d61b158e1", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\n#define MN 5000500\n\nusing namespace std;\ntypedef long long ll;\n\nvector isp(MN);\nvector primes, acum_pi(MN);\n\nint phi_table[300000][100];\nll l, r, k, ans;\n\nvoid crivo_super_modificado_3000_v2_beta() {\n for(int i=2; i primes.size()) return pi_(n) - k + 1; \n if(primes[k - 1] > n) return 1; \n if(n < primes[k - 1] * primes[k - 1]) return pi_(n) - k + 1; \n return solve(n, k - 1) - solve(n/primes[k - 1], k - 1);\n}\n\n///Prime count up to X\nll pi_(ll x) {\n if(x < MN) return acum_pi[x];\n ll cubic_root = ceil(pow(x, 1./3));\n\n ll k = acum_pi[cubic_root];\n\n ll ret = solve(x, k) + k - 1;\n while(primes[k] * primes[k] <= x) {\n ret = ret - pi_(x / primes[k]) + k;\n k++;\n }\n return ret;\n}\n\nbool is_prime(ll x) {\n if(x == 2) return true;\n if(x % 2 == 0) return false;\n if(x < 2) return false;\n\n for(int i=0; primes[i] * primes[i] <= x; i++) {\n if(x % primes[i] == 0) return false;\n }\n\n return true;\n}\n\nint main() {\n crivo_super_modificado_3000_v2_beta();\n scanf(\"%lld %lld %lld\", &l, &r, &k);\n\n if(!is_prime(k)) {\n printf(\"0\\n\");\n return 0;\n }\n\n ll prime_idx = pi_(k);\n if(k <= r) ans = solve(r, prime_idx - 1) - solve(r, prime_idx);\n if(k < l) ans = ans - solve(l - 1, prime_idx - 1) + solve(l - 1, prime_idx);\n\n printf(\"%lld\\n\", ans);\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "number theory"], "code_uid": "e1152865e77d4d81dd4335f36c4eaa07", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n\tstring s;\n\tcin >>s;\n\tint count = 0;\n\tfor (int i = 0; i <=(s.size()-1) ; i++)\n\t{\n\t\tif (s[i] == '1')\n\t\t\tcount++;\n }\n\tif (count == 0)\n\t\tcout << \"0\" << \"\\n\";\n\telse if (count == 1)\n\t\tcout << s.size() / 2 << \"\\n\";\n\telse\n\t{\n\t\tif (s.size() % 2 == 0)\n\t\t\tcout << s.size() / 2 << \"\\n\";\n\t\telse\n\t\t\tcout << (s.size() / 2) + 1 << \"\\n\";\n\t}\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "d367abf63e46add1cc17ae16e3853fe0", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nstring a;\nint main(){\n cin>>a;\n int n=a.length();\n int k=0;\n for(int i=0;i=1){\n if((f-7)%10!=0 && (f-4)%10!=0){\n cout << \"NO\";\n return 0;\n }\n if((f-7)%10==0){\n f-=7 ;\n f/=10 ;\n }\n if((f-4)%10==0){\n f-=4 ;\n f/=10 ;\n }\n }\n cout<<\"YES\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "d867d0b20983e51d1d368ef979c81bf8", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Clang++17 Diagnostics", "source_code": " #include \n using namespace std;\n int main()\n {\n int x,y;\n for(int i=0;i<5;i++)\n {\n for(int j=0;j<5;j++)\n {\n int z;\n cin>>z;\n if(z==1)\n {\n x=i;\n y=j;\n }\n }\n }\n int steps=abs(2-x) + abs(2-y);\n cout<\n#include \n#include \n#include \n#include \n\nusing namespace std;\nint a[3][6];\n\n\nbool is(int x, int in){\n\t\n\tfor (int i=0; i<6; i++){\n\t\tif (a[in][i]==x) return true;\n\t}\n\treturn false;\n}\n\n\n\nbool num(int x){\n\tbool pas=false;\n\tif (x<10){\n\t\tif (is(x,0) || is(x,1) || is(x,2)){\t\n\t\t\treturn true;\n\t\t}\n\t\telse return false;\n\t}\n\telse{\n\t\tif (x<100){\n\t\t\tint k=x/10; int p=x%10;\n\t\t\tif (is(k,0) && is(p,1)) pas=true;\n\t\t\tif (is(k,0) && is(p,2)) pas=true;\n\t\t\t\n\t\t\tif (is(k,1) && is(p,0)) pas=true;\n\t\t\tif (is(k,1) && is(p,2)) pas=true;\n\t\t\t\n\t\t\tif (is(k,2) && is(p,1)) pas=true;\n\t\t\tif (is(k,2) && is(p,0)) pas=true;\n\t\t\treturn pas;\n\t\t}\n\t\telse{\n\t\t\tint k=x/100; int p=(x-100*k)/10; int t=x%10;\n\t\t\t\n\t\t\tif (is(k,0) && is(p,1) && is(t,2)) pas=true;\n\t\t\tif (is(k,0) && is(p,2) && is(t,1)) pas=true;\n\t\t\t\n\t\t\tif (is(k,1) && is(p,0) && is(t,2)) pas=true;\n\t\t\tif (is(k,1) && is(p,2) && is(t,0)) pas=true;\n\t\t\t\n\t\t\tif (is(k,2) && is(p,1) && is(t,0)) pas=true;\n\t\t\tif (is(k,2) && is(p,0) && is(t,1)) pas=true;\n\t\t\treturn pas;\n\t\t}\n\t}\n\treturn pas;\n}\n\n\nint main(){\n\tint n;\n\tcin>>n;\n\tint ans=0;\n\t\n\t\n\tfor (int i=0; i>a[i][j];\n\t\t}\n\t}\n\tfor (int i=2; i>=n; i--){\n\t\tfor (int j=0; j<6; j++){\n\t\t\ta[i][j]=-1;\n\t\t}\n\t}\n\t\n\t\n\tfor (int i=1; i<1000; i++){\n\t\tif (!num(i)) {\n\t\t\tans=i-1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tcout<\n\nusing namespace std;\ntypedef long long ll;\n\nstruct matrix {\n int rows, cols, MOD;\n int **c;\n\n void init() {\n c = new int*[rows];\n for(int i = 0; i < rows; i++)\n c[i] = new int[cols];\n }\n void clean() {\n for(int i = 0; i < rows; i++)\n delete [] c[i];\n delete [] c;\n }\n\n int* operator [] (int row) {\n return c[row];\n }\n\n matrix(int row, int col, int M = 1000000007) : rows(row), cols(col), MOD(M) {\n init();\n for(int i = 0; i < rows; i++)\n memset(c[i], 0, cols * sizeof(int));\n }\n\n matrix(const matrix &o) : rows(o.rows), cols(o.cols), MOD(o.MOD) {\n init();\n for(int i = 0; i < rows; i++)\n memcpy(c[i], o.c[i], cols * sizeof(int));\n }\n\n matrix& operator = (const matrix &o) {\n clean();\n rows = o.rows; cols = o.cols; MOD = o.MOD;\n init();\n for(int i = 0; i < rows; i++)\n memcpy(c[i], o.c[i], cols * sizeof(int));\n return *this;\n }\n\n ~matrix() { clean(); }\n\n void print() {\n for(int i = 0; i < rows; i++) {\n for(int j = 0; j < cols; j++)\n printf(\"%d \", c[i][j]);\n puts(\"\");\n }\n }\n\n matrix operator + (matrix b) const {\n assert(rows == b.rows && cols == b.cols);\n for(int i = 0; i < rows; i++)\n for(int j = 0; j < cols; j++) {\n b.c[i][j] += c[i][j];\n if(b.c[i][j] >= MOD) b.c[i][j] -= MOD;\n }\n return b;\n }\n\n matrix operator - (matrix b) const {\n assert(rows == b.rows && cols == b.cols);\n matrix ret = *this;\n for(int i = 0; i < rows; i++)\n for(int j = 0; j < cols; j++) {\n ret.c[i][j] -= b.c[i][j];\n if(ret.c[i][j] < 0) ret.c[i][j] += MOD;\n }\n return ret;\n }\n\n matrix operator * (ll k) const {\n matrix ret = *this;\n k %= MOD;\n for(int i = 0; i < rows; i++)\n for(int j = 0; j < cols; j++)\n ret.c[i][j] = (1LL * ret.c[i][j] * k) % MOD;\n return ret;\n }\n\n matrix operator % (matrix b) const {\n assert(cols == b.rows);\n matrix ret(rows, b.cols, MOD);\n ll MOD2 = 1LL * MOD * MOD;\n for(int i = 0; i < rows; i++) {\n for(int j = 0; j < b.cols; j++) {\n ll sum = 0;\n for(int k = 0; k < cols; k++) {\n sum += (1LL * c[i][k] * b.c[k][j]);\n if(sum >= MOD2) sum -= MOD2;\n }\n ret.c[i][j] = sum % MOD;\n }\n }\n return ret;\n }\n\n matrix operator ^ (ll exp) const { //matrix^0 = identity\n matrix ret = matrix(rows, cols, MOD), base = *this;\n for(int i = 0; i < rows; i++) ret.c[i][i] = 1;\n\n while(exp) {\n if(exp & 1) ret = ret % base;\n exp >>= 1;\n if(exp) base = base % base;\n }\n return ret;\n }\n};\n\nconst ll MOD = 1000000007;\nll n, k, coef[50][50], ii[50], ifi[50], if1[50], cnt = 3, SZ = 130;\nvector> c[220];\n\nint main() {\n scanf(\"%lld %lld\", &n, &k);\n if(n < 3) {\n if(n == 1) puts(\"1\");\n if(n == 2) printf(\"%lld\\n\", (1LL + (2LL << k)) % MOD);\n return 0;\n }\n\n coef[0][0] = 1;\n for(int i = 1; i <= k; i++) {\n coef[i][0] = coef[i][i] = 1;\n for(int j = 1; j < i; j++)\n coef[i][j] = (coef[i-1][j] + coef[i-1][j-1]) % MOD;\n }\n\n for(int i = 0; i <= k; i++) ii[i] = cnt++;\n for(int i = 0; i <= k; i++) ifi[i] = cnt++;\n for(int i = 0; i <= k; i++) if1[i] = cnt++;\n\n matrix mat(SZ, SZ);\n for(int j = 0; j <= k; j++) {\n if(j == 0) mat[ii[j]][ii[j]] = 1;\n else for(int p = 0; p <= k; p++) {\n mat[ii[j]][ii[p]] = coef[j][p];\n }\n }\n for(int j = 0; j <= k; j++) {\n if(j == 0) {\n mat[ifi[j]][ifi[j]] = 1;\n mat[ifi[j]][if1[j]] = 1;\n }\n else for(int p = 0; p <= k; p++) {\n mat[ifi[j]][ifi[p]] = coef[j][p];\n mat[ifi[j]][if1[p]] = coef[j][p];\n }\n }\n for(int j = 0; j <= k; j++) {\n if(j == 0) {\n mat[if1[j]][ifi[j]] = 1;\n }\n else for(int p = 0; p <= k; p++) {\n mat[if1[j]][ifi[p]] = coef[j][p];\n }\n }\n\n mat[0][0] = 1;\n for(int p = 0; p <= k; p++) {\n mat[0][ifi[p]] = coef[k][p];\n mat[0][if1[p]] = coef[k][p];\n }\n\n matrix col(SZ, 1);\n col[0][0] = (1LL + (2LL << k)) % MOD;\n for(int j = 0; j <= k; j++) {\n col[ii[j]][0] = (1LL << j) % MOD;\n }\n for(int j = 0; j <= k; j++) {\n col[ifi[j]][0] = (2LL << j) % MOD;\n }\n for(int j = 0; j <= k; j++) {\n col[if1[j]][0] = (1LL << j) % MOD;\n }\n\n matrix res = (mat ^ (n - 2)) % col;\n printf(\"%d\\n\", res[0][0]);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "matrices", "combinatorics"], "code_uid": "b89e7760fe45d8943ca35d31461efa9a", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define vi vector\n#define vpi vector >\n#define mpi map\n#define si set\n#define pq prority_queue\n#define pqi priority_queue >\n#define rep(i,a,n) for(ll i=a;i>t;while(t--)\npriority_queue,greater > q;\nint main()\n{\n ll n,x,y;cin>>n>>x>>y;\n n/=2;\n if((x==n || x==n+1) &&(y==n || y==n+1))\n cout<<\"NO\"<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define in freopen(\"input.txt\",\"r\",stdin)\n#define out freopen(\"output.txt\",\"w\",stdout)\n\nusing namespace std;\n\n#define pb push_back\n#define pf push_front\n#define p_f pop_front\n#define p_b pop_back\n#define LL __int64\n#define LD long double\n#define MP make_pair\n#define fi first\n#define se second\n#define sc scanf\n#define pr printf\n#define str strlen\nLL b,i,j,k,n,m,ans=0,c[1000001];\nLL a,cnt=0,fl=0,a2,a3=-1000000,i1,l=0,r=0,gh=0,used[1000001]={0};\ndequedeq,deq2;\nstring s;\nmain()\n{\n sc(\"%I64d\",&n);\n for(i=1;i<=n;i++)\n {\n c[i]=i;\n used[1]=1;\n }\n cnt=1000000;\n i=1;\n r=1;\n gh=1;\n while(cnt>0)\n {\n if( used[i]==0 ){ used[i]=1;gh++; }\n if( gh==n ){ cout<<\"YES\\n\";return 0; }\n i+=r;\n r++;\n i%=n;\n if( i==0 )i==1;\n cnt--;\n }\n cout<<\"NO\\n\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "ef88141a9809fb1bf2a5f07d750f314e", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n int n;\n while(scanf(\"%d\",&n)!=EOF)\n {\n bool sport=0,cont=0,special=0;\n int cnt=0,remind=-1,skip=0;;\n int num[105];\n memset(num,-1,sizeof(num));\n for(int i=0; i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nconst int INF = 1e9;\n\n\nint fun(int x)\n{\n x++;\n while(!(x%10))\n {\n x /= 10;\n }\n return x;\n}\n\nint main()\n{\n#ifdef MY_DEBUG\n freopen(\"input.txt\", \"rt\", stdin);\n freopen(\"output.txt\", \"wt\", stdout);\n#endif\n int n = 0;\n cin >> n;\n set s;\n s.insert(n);\n while(true)\n {\n n = fun(n);\n auto it = s.insert(n);\n if(!it.second)\n break;\n }\n cout << s.size();\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "2ea418d592941d821ed6d09e9d25e9e6", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\nconst int N = 1e5 + 5;\n\nint n, a[N], cnt;\n\nint main(){\n\n\n\n ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n cin >> n;\n for (int i = 1; i <= n; ++i) cin >> a[i];\n sort(a + 1, a + n + 1);\n for (int i = 1; i <= n; ++i)\n if (a[i] == a[1]) ++cnt;\n if (cnt <= n >> 1) return cout << \"Alice\", 0;\n cout << \"Bob\";\n\n}\n", "lang_cluster": "C++", "tags": ["games"], "code_uid": "92d3b8ca4a57cd9822f45d858f6b0d30", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\nlong long dps[1000006];\nlong long dpn[1000006];\nint inc = 300001;\nlong long mod = 1000000007ll;\n\nint main(){\n int a, b, k, t; scanf(\"%d %d %d %d\",&a,&b,&k,&t);\n dpn[a - b + inc] = 1ll;\n t *= 2;\n\n for(int i = 1;i <= t; i++){\n for(int j = 0;j <= inc + inc; j++){\n dps[j] = dpn[j];\n dpn[j] = 0;\n }\n for(int j = -inc;j <= inc; j++){\n if(!dps[j + inc]) continue;\n /*dp[c][j + inc - k] += dp[d][j + inc];\n dp[c][j + inc - k] %= mod;\n\n dp[c][j + inc + k + 1] += mod - dp[d][j + inc];\n dp[c][j + inc + k + 1] %= mod;*/\n\n dpn[j + inc - k] += dps[j + inc];\n if(dpn[j + inc - k] >= mod) dpn[j + inc - k] -= mod;\n\n dpn[j + inc + k + 1] += mod - dps[j + inc];\n if(dpn[j + inc + 1 + k] >= mod) dpn[j + inc + k + 1] -= mod;\n }\n\n for(int j = -inc + 1;j <= inc; j++){\n //dp[c][j + inc] += dp[c][j + inc - 1];\n //dp[c][j + inc] %= mod;\n\n dpn[j + inc] += dpn[j + inc - 1];\n if(dpn[j + inc] >= mod) dpn[j + inc] -= mod;\n }\n }\n\n long long ans = 0;\n for(int i = 1;i <= inc; i++){\n //ans += dp[t % 2][i + inc];\n ans += dpn[i + inc];\n if(ans >= mod) ans -= mod;\n }\n\n printf(\"%I64d\\n\",ans);\n}\n\n", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "f2625039b52d09a70edd616d6222f432", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \nusing namespace std;\n\nconst int MOD = 1000000007;\nint f[5555][5555];\nchar a[5555];\nchar b[5555];\nint n;\nint m;\n\nint main(void)\n{\n cin >> a+1 >> b+1;\n n = strlen(a+1);\n m = strlen(b+1);\n int ans = 0;\n for (int i=1; i<=n; i++)\n {\n for (int j=1; j<=m; j++)\n {\n f[i][j] = f[i][j-1];\n if (a[i] == b[j])\n {\n f[i][j] += f[i-1][j-1];\n f[i][j]++;\n if (f[i][j] >= MOD) f[i][j] -= MOD;\n }\n }\n ans += f[i][m];\n if (ans >= MOD) ans -= MOD;\n }\n cout << ans << \"\\n\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "8dd30c65968d96d89359e7b294bcfbed", "src_uid": "4022f8f796d4f2b7e43a8360bf34e35f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tchar a;int b=0,w=0;\n\tfor(int i=1;i<=64;i++)\n\t{\n\t\tcin>>a;\n\t\tif(a=='Q') w+=9;\n\t\tif(a=='R') w+=5;\n\t\tif(a=='B') w+=3;\n\t\tif(a=='N') w+=3;\n\t\tif(a=='P') w+=1;\n\t\t\n\t\tif(a=='q') b+=9;\n\t\tif(a=='r') b+=5;\n\t\tif(a=='b') b+=3;\n\t\tif(a=='n') b+=3;\n\t\tif(a=='p') b+=1;\n\t}\n\tif(w>b) cout<<\"White\";\n\telse if(w \n //#include \n// #include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n#define trace(x) cerr << #x << \": \" << x << \" \" << endl;\n\ntypedef int64_t ll;\n \n#define endl '\\n'\n#define int ll\nll mod=1e9+7;\nll mod1=1e9+5;\nll power(ll a,ll b)\n{\n if(b==0) return 1;\n else if(b%2==0)\n return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;\n else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;\n}\ninline ll inverse(ll a,ll md) {\n a %= md;\n if (a < 0) a += md;\n ll b = md, u = 0, v = 1;\n while (a) {\n ll t = b / a;\n b -= t * a; swap(a, b);\n u -= t * v; swap(u, v);\n }\n assert(b == 1);\n if (u < 0) u += md;\n return u;\n}\n \n \n //using namespace __gnu_pbds;\n //#define ordered_set tree, null_type,less>, rb_tree_tag,tree_order_statistics_node_update>\n//find_by_order(k) returns iterator to kth element starting from 0;\n//order_of_key(k) returns count of elements strictly smaller than k;\n//erase,insert same as normal set\n //mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); //for randomized solution\nconst int ce=1e9+7;\nll fast_mod(ll input)\n{\n return input < ce ? input : input%ce;\n}\n#define pi acos(-1)\nmap m,m1;\nvector v;\nint solve(int n)\n{\n if(n==1)\n return 1;\n if(m1.find(n)!=m1.end())\n return m1[n];\n int ans=0;\n ans+=power(2,n-1)-1;\n ans+=mod;\n ans%=mod;\n for(auto i:v)\n {\n if(i>=n)\n break;\n if(n%i==0)\n {\n ans-=solve(n/i);\n ans+=mod;\n ans%=mod;\n }\n }\n m1[n]=ans;\n return ans;\n}\nint32_t main()\n{\n IOS\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n #endif \n \n int x,y;\n cin>>x>>y;\n if(y%x!=0)\n {\n cout<<0<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main(){\n\tint n;\n\tscanf(\"%d\",&n);\n for(int i=0;i<=n;i+=1234567)\n\t\tfor(int j=0;j<=n-i;j+=123456)\n\t\t\tif ((n - i - j) % 1234 == 0)\n\t\t\t{\n\t\t\t\tprintf(\"YES\\n\");\n\t\t\t\treturn 0;;\n\t\t\t}\n\tprintf(\"NO\\n\");\n\n\n\treturn 0; }", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "880b507de19bd2c537a62b7e92bd8b65", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\nint MaxHr, MaxMin, ans;\nvector hr, minute;\n\nint ok(vector X)\n{\n int mask = 0;\n \n for(int i=0; iMaxHr || m>MaxMin)\n return 0;\n \n return 1;\n}\n\nvoid solve(vector X, int num)\n{\n if(num==hr.size() + minute.size())\n {\n if(ok(X))\n ans++;\n \n return;\n }\n \n for(int i=0; i<7; i++)\n {\n vector Y = X;\n Y.push_back(i);\n solve(Y, num+1);\n }\n}\n\nint main()\n{\n int N, M;\n cin >> N >> M;\n \n N--, M--;\n \n if(N==0)\n hr.push_back(0);\n if(M==0)\n minute.push_back(0);\n \n while(N)\n {\n hr.push_back(N%7);\n N/= 7;\n }\n \n while(M)\n {\n minute.push_back(M%7);\n M/= 7;\n }\n \n reverse(hr.begin(), hr.end());\n reverse(minute.begin(), minute.end());\n \n for(int i=0; i7)\n cout << 0 << endl;\n else\n {\n vector X;\n solve(X, 0);\n cout << ans << endl;\n }\n \n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "2cbdd2eb7f71a2b8fc96e1ff6f114414", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17 (64)", "source_code": "#include \r\n\r\n#define pb push_back\r\n#define fill(x, y) memset(x, y, sizeof(x))\r\n#define all(x) (x).begin(), (x).end()\r\n#define debug(x) { cerr << #x << \" = \" << x << endl; }\r\n#define IO\t { ios_base::sync_with_stdio(false); cin.tie(0); }\r\n#define read(x)\t freopen(x, \"r\", stdin)\r\n#define write(x) freopen(x, \"w\", stdout)\r\n\r\nusing namespace std;\r\n\r\ntypedef long long ll;\r\ntypedef pair ii;\r\ntypedef vector vi;\r\nconst ll mod = 1e9 + 7;\r\nll n, m, k, r, c;\r\n\r\n\r\nll bigmod(ll a, ll m) {\r\n if (m == 0) return 1LL;\r\n else if (m & 1) {\r\n return (a * bigmod(a, m-1)) % mod;\r\n } else {\r\n ll r = bigmod(a, m/2);\r\n return (r*r) % mod;\r\n }\r\n}\r\n\r\nii rt(ii p) {\r\n auto [x, y] = p;\r\n return {c - y + 1, x};\r\n}\r\nii bt(ii p) {\r\n auto [x, y] = p;\r\n return {r - x + 1, c - y + 1};\r\n}\r\nii bl(ii p) {\r\n auto [x, y] = p;\r\n return {y, r - x + 1};\r\n}\r\n\r\nll get_int(ii a, ii b, int row, int col) {\r\n auto [x1, y1] = a;\r\n auto [x2, y2] = b;\r\n\r\n int x3 = x1 + row - 1, y3 = y1 + col - 1;\r\n if (x2 <= x3 and y2 <= y3 and x1 <= x2 and y1 <= y2) {\r\n return ((ll)(x3 - x2 + 1)) * ((ll)(y3 - y2 + 1));\r\n }\r\n return 0;\r\n}\r\n\r\nint main() {\r\n cin >> n >> m >> k >> r >> c;\r\n ll ax, ay, bx, by;\r\n cin >> ax >> ay >> bx >> by;\r\n\r\n // ll atx = ax, aty = ay + c - 1, btx = bx , bty = by + c - 1;\r\n\r\n // ll l1 = get_int({ax, ay}, {bx, by}, r , c);\r\n // ll l2 = get_int({bx, by}, {ax, ay}, r , c);\r\n \r\n\r\n // ii ac = rt({ax, ay}), bc = rt({bx, by});\r\n // ll l3 = get_int(ac, bc, c, r);\r\n // ll l4 = get_int(bc, ac, c, r);\r\n\r\n\r\n // ll intersect = max(max(l1, l2), max(l3, l4));\r\n\r\n ll squares = 0;\r\n if (ax == bx and ay == by) squares = n * m;\r\n else squares = n * m - r * c;\r\n \r\n\r\n cout << bigmod(k, squares) << endl;\r\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "9b3d5fd94362818fcbbf021d056841c6", "src_uid": "3478e6a4ff2415508fd517413d40c13a", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#define ll long long int\nusing namespace std;\n\nint main()\n{\nint n,t,k,d;\ncin>>n>>t>>k>>d;\nint g=(n+k-1)/k;\nif(g-(d/t)>1){\n cout<<\"YES\";\n}\nelse{cout<<\"NO\";}\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "f050d9dcdf72eb05ab19f02daf17a8b2", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "# include \n# include \n# include \n# include \nusing namespace std;\nint main()\n{\n\tint n=0,all=0;\n\tdouble qaq=0.0;\n\tint m[17]={0},r[17]={0};\n\tcin>>n;\n\tfor(int i=0;i>m[i];\n\tfor(int i=0;i>r[i];\n\tfor(int i=1;i<=720720;i++)\n\t\tfor(int j=0;j\nusing namespace std;\n#define ll long long\nint main()\n\n{\n ios_base::sync_with_stdio(false);\ncin.tie(NULL);\n\nint w,h,k;\ncin>>w>>h>>k;\n\nint m,i;\nm=min(w,h);\nint c=0;\nfor(i=0;i\nusing namespace std;\n\nint main()\n{\n int space[10] = {0};\n int sticks[6];\n bool found = false;\n for(int i=0;i<6;i++)\n {\n cin>>sticks[i];\n space[sticks[i]]++;\n }\n //find legs\n bool legs = false,body=false,head = false, fourCondition = false;\n\n for(int i=0;i<10;i++)\n {\n if(space[i] == 6)\n {\n cout<<\"Elephant\\n\";\n legs = true;\n found = true;\n break;\n }\n else if(space[i] == 5)\n {\n //its automatically bear right....\n cout<<\"Bear\\n\";\n legs = true;\n found = true;\n break;\n }\n else if(space[i] == 4)\n {\n //legs found..\n //now two things can happen.....either the remaing sticks are of same length or different......\n //cout<<\"gsdfhsfgfhs\";\n legs = true;\n fourCondition = true;\n space[i] = 0;\n break;\n \n \n \n \n }\n }\n //check if legs are there or not...\n if(legs == false)\n {\n cout<<\"Alien\\n\";\n }\n else\n {\n //legs are there, now we need to find if its a bear or an elephant....\n //cout<<\"gdfg\";\n if(fourCondition == true)\n {\n int body,head;\n bool b = false, h = false;\n for(int i=0;i<10;i++)\n {\n if(space[i] != 0)\n {\n body = i;\n //cout<\nusing namespace std;\nint A[81][81];\nstruct Edge{\n\tint to, cap, cost, next;\n};\nEdge E[30000];\nint head[7000], ne = 1;\nint NV;\ninline void addEdge(int from, int to, int cap, int cost) {\n\tE[++ne] = {to, cap, cost, head[from]}, head[from] = ne;\n\tE[++ne] = {from, 0, -cost, head[to]}, head[to] = ne;\n}\nint d[7000], p[7000];\nbool inqueue[7000];\npair mcmf(int S, int T) {\n\tint f = 0, c = 0;\n\twhile(1) {\n\t\tfor(int i = 0; i < NV; ++i) d[i] = 1e9;\n\t\tqueue Q;\n\t\tQ.push(S); d[S] = 0;\n\t\twhile(!Q.empty()) {\n\t\t\tauto v = Q.front(); Q.pop();\n\t\t\tinqueue[v] = 0;\n\t\t\tfor(int x = head[v]; x; x = E[x].next) {\n\t\t\t\tint &u = E[x].to, &cap = E[x].cap, &cost = E[x].cost;\n\t\t\t\tif(cap > 0 and d[v] + cost < d[u]) {\n\t\t\t\t\td[u] = d[v] + cost;\n\t\t\t\t\tp[u] = x;\n\t\t\t\t\tif(!inqueue[u]) Q.push(u), inqueue[u] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(d[T] == 1e9) break;\n\t\tint df = 1e9;\n\t\tfor(int i = T; i != S; i = E[p[i]^1].to)\n\t\t\tdf = min(df, E[p[i]].cap);\n\t\tfor(int i = T; i != S; i = E[p[i]^1].to)\n\t\t\tE[p[i]].cap -= df, E[p[i]^1].cap += df;\n\t\tf += df, c += df * d[T];\n\t}\n\treturn {f, c};\n}\nint n, m;\ninline int group(int i, int j) {\n\treturn (i + j) & 1;\n}\ninline int id(int i, int j) {\n\treturn (i-1)*m+j;\n}\nint main() {\n\tios::sync_with_stdio(0); cin.tie(0);\n\tcin >> n >> m;\n\tfor(int i = 1; i <= n; ++i)\n\t\tfor(int j = 1; j <= m; ++j)\n\t\t\tcin >> A[i][j];\n\tint S = 0, T = 6789;\n\tNV = 6790;\n\tfor(int i = 1; i <= n; ++i)\n\t\tfor(int j = 1; j <= m; ++j) {\n\t\t\tif(group(i, j) == 0)\n\t\t\t\taddEdge(S, id(i, j), 1, 0);\n\t\t\telse\n\t\t\t\taddEdge(id(i, j), T, 1, 0);\n\t\t}\n\tfor(int i = 1; i <= n; ++i) {\n\t\tfor(int j = 1; j <= m; ++j) {\n\t\t\tif(group(i, j) == 0) {\n\t\t\t\tif(i-1 >= 1)\n\t\t\t\t\taddEdge(id(i, j), id(i-1, j), 1, A[i][j] != A[i-1][j]);\n\t\t\t\tif(i+1 <= n)\n\t\t\t\t\taddEdge(id(i, j), id(i+1, j), 1, A[i][j] != A[i+1][j]);\n\t\t\t\tif(j-1 >= 1)\n\t\t\t\t\taddEdge(id(i, j), id(i, j-1), 1, A[i][j] != A[i][j-1]);\n\t\t\t\tif(j+1 <= m)\n\t\t\t\t\taddEdge(id(i, j), id(i, j+1), 1, A[i][j] != A[i][j+1]);\n\t\t\t}\n\t\t}\n\t}\n\tauto ans = mcmf(S, T);\n\tcout << ans.second << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["flows"], "code_uid": "884181d8a1f0e980adfd3aae9523994e", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n\nusing namespace std;\n\ntypedef pair II;\ntypedef vector< II > VII;\ntypedef vector VI;\ntypedef vector< VI > \tVVI;\ntypedef long long int \tLL;\n\n#define PB push_back\n#define MP make_pair\n#define F first\n#define S second\n#define SZ(a) (int)(a.size())\n#define ALL(a) a.begin(),a.end()\n#define SET(a,b) memset(a,b,sizeof(a))\n\n#define SI(n) scanf(\"%d\",&n)\n#define PI(n) printf(\"%d\\n\",n)\n#define SLL(n) scanf(\"%lld\",&n)\n#define PLL(n) printf(\"%lld\\n\",n)\n#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)\n\n#define TRACE\n\n#ifdef TRACE\n#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f(const char* name, Arg1&& arg1){\n\tcerr << name << \" : \" << arg1 << std::endl;\n}\ntemplate \nvoid __f(const char* names, Arg1&& arg1, Args&&... args){\n\tconst char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << \" : \" << arg1<<\" | \";__f(comma+1, args...);\n}\n#else\n#define trace(...)\n#endif\n\n//FILE *fin = freopen(\"in\",\"r\",stdin);\n//FILE *fout = freopen(\"out\",\"w\",stdout);\nint A[int(1e6)+1];\nint main()\n{\n\tint n, t;\n\tSI(n);\n\tfor(int i = 0 ; i < n ; i++)\n\t\tSI(A[i]), A[i] *= -1;\n\tSI(t);\n\tfor(int i = 0, a ; i < t ; i++)\n\t\tSI(a), A[a-1] *= -1;\n\treverse(A, A+n);\n\tstack s;\n\tfor(int i = 0 ; i < n ; i++)\n\t{\n\t\tif(A[i] < 0)\n\t\t{\n\t\t\tif(not s.empty() and s.top() == -A[i])\n\t\t\t\ts.pop();\n\t\t\telse A[i] *= -1, s.push(A[i]);\n\t\t}\n\t\telse s.push(A[i]);\n\t}\n\tif(not s.empty()) return 0*printf(\"NO\\n\");\n\treverse(A, A+n);\n\tprintf(\"YES\\n\");\n\tfor(int i = 0 ; i < n ; i++)\n\t\tprintf(\"%d \", -A[i]);\n\tprintf(\"\\n\");\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["greedy", "data structures"], "code_uid": "1c18461d9457ad92346a7242a111138d", "src_uid": "be82b8f209217875221ebe5de8675971", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)\n#define mod 1000000007\n\nint main(){ \n\tfast;\n\tint l, d, v, g, r; cin>>l>>d>>v>>g>>r;\n double t2=(double)(l-d)/v;\n double t1=(double)d/v;\n int x=g+r;\n double add=0;\n if((int)t1%(g+r)>=g){\n \tfloat y=(((int)t1/(g+r))+1)*(g+r);\n \t//cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nlong long n, m, t, k;\nvector a, b;\n\nvector f(500000), rf(500000);\nlong long p = 998244353;\nvoid fix(long long &x)\n{\n\tx = ((x % p) + p) % p;\n}\nlong long poww(long long a, long long pp)\n{\n\tif (pp == 0)\n\t\treturn 1LL;\n\tif (pp % 2 == 0)\n\t{\n\t\tlong long t = poww(a, pp / 2);\n\t\tt = t * t;\n\t\tfix(t);\n\t\treturn t;\n\t}\n\telse\n\t{\n\t\tlong long t = a * poww(a, pp - 1);\n\t\tfix(t);\n\t\treturn t;\n\t}\n}\n\nint main() {\n\t//freopen(\"output.txt\", \"w\", stdout);\n\t//freopen(\"input.txt\", \"r\", stdin);\n\tcin >> n >> m;\n\tif (n == 2)\n\t{\n\t\tcout << 0;\n\t\treturn 0;\n\t}\n\tlong long c = 1;\n\tf[0] = 1;\n\tf[1] = 1;\n\trf[1] = 1;\n\trf[0] = 1;\n\tfor (long long i = 2; i <= n + m; i++)\n\t{\n\t\tf[i] = f[i - 1] * i;\n\t\tfix(f[i]);\n\t\trf[i] = poww(f[i], p - 2);\n\t}\n\tlong long ans = f[m];\n\tans *= rf[m - n + 1];\n\tfix(ans);\n\tans *= rf[n - 1];\n\tfix(ans);\n\tans *= (n - 2);\n\tfix(ans);\n\tlong long t = poww(2, n - 3);\n\tans *= t;\n\tfix(ans);\n\tcout << ans;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "de54bb0d51bf09fdd7b7362f47933072", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#ifdef WIN32\n #define I64 \"%I64d\"\n#else\n #define I64 \"%lld\"\n#endif // WIN32\n\n#define next(x) (x + ((x) & (-x)))\n#define prev(x) (x - ((x) & (-x)))\n#define md 1000000007\n#define ll long long\n#define ull unsigned long long\n#define fst first\n#define snd second\n#define sqr(x) ((x) * (x))\n#define INF (1LL << 30)\n#define EPS 0.0000000001\n\nusing namespace std;\n\n\nint main() {\n\t#ifndef DLOCAL \n\t\t//freopen(\"input.txt\", \"r\", stdin);\n\t\t//freopen(\"output.txt\", \"w\", stdout);\n\t#else\n\t\t//freopen(\"input.txt\", \"r\", stdin);\n\t\t//freopen(\"output.txt\", \"w\", stdout);\n\t#endif //LOCAL\n\tint a = 0, b = 0;\n\tfor (int i = 0; i < 3; i++) {\n\t\tint x;\n\t\tcin >> x;\n\t\tb += x;\n\t}\n\tfor (int i = 0; i < 3; i++) {\n\t\tint x;\n\t\tcin >> x;\n\t\ta += x;\n\t}\n\tint n;\n\tcin >> n;\n\tfor (int i = 0; i < n; i++) {\n\t\tif (a > 0) {\n\t\t\ta -= 10;\n\t\t} else if (b > 0) {\n\t\t\t\t\tb -= 5;\n\t\t\t\t}\n\t}\n\tif (a > 0 || b > 0) {\n\t\tcout << \"NO\" << endl;\n\t} else {\n\t\tcout << \"YES\" << endl;\n\t}\n\n\tcerr << \"Execution time : \" << clock() * 1.0 / CLOCKS_PER_SEC << endl;\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "d1726c71a0119fefc6d31afe2057718a", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\nconst ll MAX=100000;\nconst ll P=1000000007;\nll mo[MAX+5],dp[MAX+5],prime[MAX+5],m,ans;\nint vis[MAX+5],cnt;\nvoid get_mo(){\n\tmemset(vis,0,sizeof(vis));\n\tmemset(mo,0,sizeof(mo));\n\tmo[1]=1;\n\tcnt=0;\n\tfor(int i=2;i<=MAX;i++){\n\t\tif(!vis[i]){\n\t\t\tprime[cnt++]=i;\n\t\t\tmo[i]=-1;\n\t\t}\n\t\tfor(int j=0;j\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define mp make_pair\n#define pb push_back\n#define X first\n#define Y second\n#define y0 y12\n#define y1 y22\n#define INF 9876543219876543\n#define PI 3.141592653589793238462643383279502884\n#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))\n#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))\n#define MEM0(a) memset((a),0,sizeof(a));\n#define MEM_1(a) memset((a),-1,sizeof(a));\n#define ALL(a) a.begin(),a.end()\n#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef double db;\ntypedef unsigned int uint;\ntypedef unsigned long long ull;\ntypedef pair Pi;\ntypedef pair Pll;\ntypedef pair Pd;\ntypedef vector Vi;\ntypedef vector Vll;\ntypedef vector Vd;\ntypedef vector VPi;\ntypedef vector VPll;\ntypedef vector VPd;\ntypedef tuple iii;\ntypedef tuple iiii;\ntypedef tuple LLL;\ntypedef vector Viii;\ntypedef vector VLLL;\ntypedef complex base;\nconst ll MOD = 1000000007;\nll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }\nll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }\nll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }\nint dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };\n\nint d[30]={0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12};\nbool chk[35000];\nint main() {\n\tll n;\n\tscanf(\"%lld\",&n);\n\tll t=(ll)sqrt(n);\n\tll cnt=n-t+1;\n\tint ans=0;\n\tfor(ll i=2;i<=t;i++)\n\t{\n\t\tif(chk[i])continue;\n\t\tint c=0;\n\t\tll now=i;\n\t\twhile(now<=n)\n\t\t{\n\t\t\tif(now<=t)chk[now]=1;\n\t\t\tc++;\n\t\t\tif(now>t)cnt--;\n\t\t\tnow*=i;\n\t\t}\n\t\tans^=d[c];\n\t}\n\tif(cnt&1)ans^=1;\n\tputs(ans?\"Vasya\":\"Petya\");\n}", "lang_cluster": "C++", "tags": ["dp", "games"], "code_uid": "6138b335590a48491802be24340ce727", "src_uid": "0e22093668319217b7946e62afe32195", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "// weizards and demonstration\n#include\n#include\n#include\n#include\n#include\n#include\n#define ak long long int\n\nusing namespace std;\n\nint main()\n{\n ak n,x,y;\n cin>>n>>x>>y;\n ak r=(y*n)%100;\n \n ak ypeople = (y*n)/100;\n\n if(r>0)\n ypeople++;\n\n ak clones=ypeople-x;\n if(clones<0)\n cout<<\"0\"<\nusing namespace std;\n\nint main() {\n\tint a, b;\n\n\n\tcin >> a >> b;\n\tfor (int i = 1; i < 10; i++) {\n\t\tif (i*a % 10 == b|| i*a % 10 == 0) {\n\t\t\tcout << i << endl;\n\t\t\t\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\t\n\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "48d5d480a993d154d2f736a5a29483b3", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \nusing namespace std;\nint main(){\n\tchar arr[50];\n\tint x,counter=0;\n\tcin>>x;\n\tfor(int i=0;i>arr[i];\n\tfor(int i=0;i\n\nusing namespace std;\n\nint main()\n{\n long long n , c = 999999;\n cin >> n;\n vectorarr(n),tmp;\n for (int x = 0; x < n; cin >> arr[x++]);\n for (int x = 1; x < n-1; x++)\n {\n for (int y = 0; y < n-1; y++)\n {\n if (y == x)\n continue;\n if (y+1 == x)\n tmp.push_back(abs(arr[y]- arr[y+2]));\n else\n tmp.push_back(abs(arr[y]-arr[y+1]));\n }\n sort(tmp.begin() , tmp.end());\n if (tmp[tmp.size()-1] < c)\n c = tmp[tmp.size()-1];\n tmp.clear();\n }\n cout << c;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation"], "code_uid": "8cc9b5cf7786e8a632d89eaca33c989b", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n\nint main(void)\n{\n signed long long int a, b;\n long long int s;\n scanf(\"%lld\", &a);\n scanf(\"%lld\", &b);\n scanf(\"%lli\", &s);\n if (abs(a)+abs(b)>s)\n {\n printf(\"No\");\n }\n else\n {\n if (abs((a+b)%2)==(s%2))\n {\n printf(\"Yes\");\n } \n else\n {\n printf(\"No\");\n } \n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "e59e548d516bebfdaaf58eb3e212354a", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\nint main(){\n\tstring b;\n\tcin>>b;\n\tint s=b.size();\n\tfor(int i=0;i\n\nusing namespace std;\n#define int long long\nconst int maxN = 300*1000 + 5;\nconst int maxM = 1000*100 + 5;\nconst int inf = 10000*1000*1000LL;\nvector a[maxN];\nint mark[maxN];\nint check[maxN];\nint tmp[maxN];\nmain()\n{\n ios::sync_with_stdio(0); cin.tie(0);\n int n, m; cin >> n >> m;\n for(int i = 0; i < m; i ++)\n {\n\t int d, k; cin >> d >> k; d --; k --;\n\t a[d].push_back(k); a[k].push_back(d);\n }\n queue q;\n for(int i = 0; i < n; i ++)\n {\n\t check[i] = a[i].size();\n\t if(check[i] > 1) { q.push(i); tmp[i] = 1; }\n }\n while(q.size())\n {\n\t int v = q.front(); q.pop();\n\t tmp[v] = 0;\n\t if(check[v] <= 1) continue;\n\t for(int i = 0; i < a[v].size(); i ++)\n\t {\n\t\tint u = a[v][i];\n\t\tif(mark[u] == mark[v])\n\t\t{\n\t\t check[v] --;\n\t\t check[u] --;\n\t\t}\n\t\telse\n\t\t{\n\t\t check[v] ++;\n\t\t check[u] ++;\n\t\t if(!tmp[u] && check[u] > 1) tmp[u] = 1, q.push(u); \n\t\t}\n\t }\n\t mark[v] = 1 - mark[v];\n }\n for(int i = 0; i < n; i ++)\n\t cout << mark[i];\n cout << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["constructive algorithms", "combinatorics", "graphs"], "code_uid": "3a803b21f2b02ec7438fa7f06ec76753", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#define ll long long int\n\nusing namespace std;\n\nll nextPlayer(ll a, ll b)\n{\n // a wins, b gets replaced\n vector p;\n p.push_back(1);\n p.push_back(2);\n p.push_back(3);\n \n ll res;\n \n for(auto x : p)\n {\n if(x != a && x != b)\n {\n res = x;\n break;\n }\n }\n \n return res;\n}\n\nint main()\n{\n ll n;\n cin >> n;\n \n vector v;\n \n while(n--)\n {\n ll x;\n cin >> x;\n v.push_back(x);\n }\n \n ll flag = 0;\n ll p1 = 1, p2 = 2;\n ll res = 0;\n \n for(auto x : v)\n {\n if(flag == 0)\n {\n if(x == 1)\n {\n p2 = 3;\n flag = 1;\n }\n else\n {\n if(x == 2)\n {\n p1 = 3;\n flag = 1;\n }\n else\n {\n res = 1;\n break;\n }\n }\n }\n else\n {\n if(x != p1 && x != p2)\n {\n res = 1;\n break;\n }\n else\n {\n if(x == p1)\n {\n p2 = nextPlayer(p1, p2);\n }\n else\n {\n p1 = nextPlayer(p2, p1);\n }\n }\n }\n }\n \n if(res == 0)\n {\n cout << \"YES\" << endl;\n }\n else\n {\n cout << \"NO\" << endl;\n }\n \n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "88d6a6066a8c531d83ff2894cf7fdce1", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\ntypedef long long int ll;\n\nint main()\n{\n ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n int n,ft=0,ans=999999;\n cin >> n;\n int a[n];\n for(int i=0 ; i> a[i];\n int f=0;\n for(int i=1 ;i p;\n for(int j=0 ; j\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define pb push_back\n#define mp make_pair\n#define PI 3.14159265358979\n#define forn(i, n) for(int i = 0; i < n; ++i)\n#define ALL(x) x.begin(), x.end()\n\ntypedef long long ll;\nusing namespace std;\ntypedef pair pii;\nconst int INF = 2147483647;\nconst ll LLINF = 9223372036854775807LL;\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#endif\n\tll n,m,k;\n\tcin >> n >> m >> k;\n\tll ans = 0;\n\tif(n-1 == k && m-1 == k)\n\t\tans = 4;\n\t\telse\n\t\tif((n < k && m < k) || k == 1 || (n%k == 0 && m%k ==0))\n\t\t\tans = n*m;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tll a = (n-1)/k+1;\n\t\t\t\t\tll b = (m-1)/k+1;\n\t\t\t\t\tans = (a*b*(m-(k*(b-1)))*(n-(k*(a-1))));\n\t\t\t\t}\n\tcout << ans;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "962fc79c43da0e5fa8210bce6776b458", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n#include\n#include\nusing namespace std;\n\ndouble f1(const int &x1, const int &y1, const int &x2, const int &y2)\n{\n return (double)(y1-y2)/(double)(x1-x2);\n}\n\nint main()\n{\n int a,b;\n int x=0,y=0;\n double slope;\n string s;\n vector pathx;\n vector pathy;\n vector dis;\n\n cin>>a>>b;\n cin>>s;\n\n if((a==0)&&(b==0))\n {\n cout<<\"Yes\";\n return 0;\n }\n\n int siz=s.size();\n for(int i=0;i(abs(b-pathy[i])))\n m=(abs((a-pathx[i])/x));\n else m=(abs((b-pathy[i])/y));\n pathx[i]+=m*x;\n pathy[i]+=m*y;\n if((pathx[i]==a)&&(pathy[i]==b))\n {\n cout<<\"Yes\";\n return 0;\n }\n if((x>0)&&(y>0))\n {\n while((a>pathx[i])||(b>pathy[i]))\n {\n pathx[i]+=x;\n pathy[i]+=y;\n if((pathx[i]==a)&&(pathy[i]==b))\n {\n cout<<\"Yes\";\n return 0;\n }\n }\n }\n else if((x<0)&&(y<0))\n {\n while((a0)\n {\n while((a>pathx[i])||(b0)\n {\n while((apathy[i]))\n {\n pathx[i]+=x;\n pathy[i]+=y;\n if((pathx[i]==a)&&(pathy[i]==b))\n {\n cout<<\"Yes\";\n return 0;\n }\n }\n }\n }\n }\n\n cout<<\"No\";\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation", "number theory"], "code_uid": "35b2cd6cc0dac33440b7704b0c209b87", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\ntypedef long long ll;\n\n int main() {\n int cnt=0,cpt=0;\n string s;\n cin>>s;\n for(int i=0;i=cnt){\n if(cnt==cpt && cnt!=0 && cpt!=0)\n cout<<\"4\\n\";\n else if(cpt>cnt)\n cout<<\"4\\n\";\n else\n cout<<\"-1\\n\";\n }\n else if(cnt>cpt)\n cout<<\"7\\n\";\n\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "dd37732b61e4692c7df0fa355f0fd277", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef double db;\ntypedef string str;\n\ntypedef pair pi;\ntypedef pair pl;\ntypedef pair pd;\n\ntypedef vector vi;\ntypedef vector vl;\ntypedef vector vd;\ntypedef vector vs;\ntypedef vector vpi;\ntypedef vector vpl;\n\n#define FOR(i,a,b) for (int i = (a); i < (b); ++i)\n#define F0R(i,a) FOR(i,0,a)\n#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)\n#define R0F(i,a) ROF(i,0,a)\n#define trav(a,x) for (auto& a: x)\n\n#define sz(x) (int)x.size()\n#define all(x) begin(x), end(x)\n#define rall(x) rbegin(x), rend(x)\n#define rsz resize\n#define ins insert\n\n#define mp make_pair\n#define pb push_back\n#define eb emplace_back\n#define f first\n#define s second\n#define lb lower_bound\n#define ub upper_bound\n\nconst int MOD = 1e9+7; // 998244353; // = (119<<23)+1\nconst int MX = 2e5+5;\nconst ll INF = 1e18;\nconst ld PI = 4*atan((ld)1);\n\ntemplate bool ckmin(T& a, const T& b)\n{\n return a > b ? a = b, 1 : 0;\n}\ntemplate bool ckmax(T& a, const T& b)\n{\n return a < b ? a = b, 1 : 0;\n}\nlong long a[505][505];\nint main()\n{\n long long n,m,i,j,k,x,y,z;\n cin>>n;\n string s;\n cin>>s;\n x=0;\n for(i=0;i\n\nusing namespace std;\ntypedef long long ll;\nint main()\n{\n //freopen(\"input.in\",\"r\",stdin);\n ll a,b,c=0;\n ll x,y,z,a1=0,b1=0;\n cin >> a>>b>>x>>y>>z;\n a-=x*2;\n a-=y;\n b-=y;\n b-=z*3;\n if (a<0) c+=a;\n if (b<0) c+=b;\n cout << abs(c);\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "ac7aa6e1b20e195858b6f6d391860790", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#define ll long long\r\n#define pb push_back\r\n#define sz(a) (int)a.size()\r\nusing namespace std;\r\nvoid solve(){\r\n int n, m, k;\r\n cin >> n >> m >> k;\r\n int all = n * m / 2;\r\n if (n & 1) {\r\n if (m / 2 <= k && k <= all && k % 2 == (m / 2) % 2) {\r\n cout << \"YES\\n\";\r\n } else {\r\n cout << \"NO\\n\";\r\n }\r\n } else if (m & 1) {\r\n if (k % 2 == 0 && 0 <= k && k <= all - n / 2) {\r\n cout << \"YES\\n\";\r\n } else {\r\n cout << \"NO\\n\";\r\n }\r\n } else {\r\n if (k % 2 == 0) cout << \"YES\\n\";\r\n else cout << \"NO\\n\";\r\n }\r\n}\r\nint main(){\r\n ios_base::sync_with_stdio(0);\r\n cin.tie(0);\r\n int t;\r\n cin >> t;\r\n while(t--) solve();\r\n}", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "3e13c938c7a0b8b85c46c48d0e9f160e", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nchar a,b;\nbool chess[10][10];\nint x,y,ans = 8;\nint main() {\n\tcin>>a>>b;\n\tx=a-'a';\n\ty=b-'0';\n\tx++;\n\tfor(int i=0; i<=9; i++) {\n\t\tfor(int j=0; j<=9; j++) { \n\t\t\tif(i==0||i==9) {\n\t\t\t\tchess[i][j] = 1;\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\tif(j==0||j==9)chess[i][j]=1;\n\t\t\t}\n\t\t}\n\t}\n\tif(chess[x][y+1]==1)ans--;\n\tif(chess[x+1][y]==1)ans--;\n\tif(chess[x][y-1]==1)ans--;\n\tif(chess[x-1][y]==1)ans--;\n\tif(chess[x+1][y+1]==1)ans--;\n\tif(chess[x+1][y-1]==1)ans--;\n\tif(chess[x-1][y+1]==1)ans--;\n\tif(chess[x-1][y-1]==1)ans--;\n\tcout<\n#include\n#include\n#define ll long long int\n#define rep(n,i) for(int i=n-1;i>=0;i--)\nusing namespace std;\nint main()\n{\n stringstream ss;\n string s=\"><+-.,[]\";\n int bin[]={1000,1001,1010,1011,1100,1101,1110,1111};\n string x;\n cin>>x;\n ll sum=0,c=1;\n rep(x.size(),i)\n {\n string str=\"\";\n int f=s.find(x[i]);\n ss<>str;ss.clear();\n rep(str.size(),j)\n {\n if(str[j]=='1')\n {\n sum+=c;\n sum%=1000003;\n }\n sum%=1000003;\n c*=2;\n c%=1000003;\n }\n }\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include\n#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)\n#define fer(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)\n#define rof(i, n, x) for (int i = (int)(n), _x = (int)(x); i-- > _x; )\n#define sz(x) (int((x).size()))\n#define pb push_back\n#define all(X) (X).begin(),(X).end()\n#define X first\n#define Y second\nusing namespace std;\n\ntypedef pair pii;\ntypedef long long ll;\ntypedef long double ld;\nconst int MAXN = 1000*100+10;\nconst int MAXM = 1000+10;\nconst int MAXL=30;\nconst int INF=1000*1000*100+10;\nconst int base = 1000000000;\nconst int base_digits = 9;\n\n\nint n,f,Gr,grund[MAXN],ans[MAXN];\nbool isf[MAXM];\n\nint Mex()\n{\n for(int i=0;i<=MAXM;i++)\n if(!isf[i])\n return i;\n}\nint main()\n{\n cin>>n;\n memset(ans,-1,sizeof ans);\n for(int i=1;i<=n;i++)\n {\n memset(isf,0,sizeof isf);\n\n for(int k=2;((2*i)-(k*k)+k)>0;k++)\n {\n if(((2*i)-(k*k)+k)%(2*k)!=0)\n continue;\n\n f=((2*i)-(k*k)+k)/(2*k);\n\n Gr=grund[f-1]^grund[f+k-1];\n\n if(Gr==0 && ans[i]==-1)\n {\n\n ans[i]=k;\n }\n isf[Gr]=true;\n }\n grund[i]=Mex()^grund[i-1];\n }\n\n cout<\nusing std::cin;\nusing std::cout;\nconst int maxn = 100100;\nconst int mod = 1e9 + 7;\ntypedef long long ll;\nint n, m;\nstruct T {\n\tint to, nxt;\n} way[maxn << 1];\nint h[maxn], num;\ninline void link(int x, int y) {\n\tway[++num] = {y, h[x]}, h[x] = num;\n\tway[++num] = {x, h[y]}, h[y] = num;\n}\nint x[maxn], y[maxn];\nint val[maxn];\nstd::map map;\nint idx;\ninline void test(int x) {\n\tif(1 <= x && x <= n && !map.count(x)) map[x] = ++ idx;\n}\ninline void upt(int x) {\n\tfor(;x && !map.count(x);x >>= 1) {\n\t\ttest(x), test(x + x), test(x + x + 1);\n\t}\n\ttest(x + x), test(x + x + 1);\n}\ninline int chk(int x, int n) {\n\tfor(;n > x;) n >>= 1;\n\treturn n == x;\n}\ninline int insub(int x, int n) {\n\tif(x > n) return 0;\n\tif(!chk(x, n)) return insub(x + x, n) * 2 + 1;\n\treturn insub(x + x, n) + insub(x + x + 1, n) + 1;\n}\ninline void dfs(int x) {\n\tif(x > n) return ;\n\tif(!map.count(x)) {\n\t\texit(1);\n\t}\n\tif(!map.count(x << 1) && !map.count(x << 1 | 1)) {\n\t\tval[map[x]] = insub(x, n);\n\t\treturn ;\n\t}\n\tdfs(x << 1);\n\tdfs(x << 1 | 1);\n\tif(map.count(x << 1))\n\t\tlink(map[x], map[x << 1]);\n\tif(map.count(x << 1 | 1))\n\t\tlink(map[x], map[x << 1 | 1]);\n\tval[map[x]] = 1;\n}\nint vis[maxn];\nll ans = 0;\ninline void dfs0(int x, int start) {\n\tans = (ans + (ll) start * val[x]) % mod;\n\tvis[x] = 1;\n\tfor(int i = h[x];i;i = way[i].nxt) if(!vis[way[i].to]) {\n\t\tdfs0(way[i].to, start);\n\t}\n\tvis[x] = 0;\n}\nint main() {\n\tcin >> n >> m;\n\tupt(1);\n\tfor(int i = 1;i <= m;++i) {\n\t\tcin >> x[i] >> y[i];\n\t\tupt(x[i]);\n\t\tupt(y[i]);\n\t}\n\tdfs(1);\n\tfor(int i = 1;i <= m;++i) {\n\t\tlink(map[x[i]], map[y[i]]);\n\t}\n\tfor(int i = 1;i <= idx;++i) {\n\t\tdfs0(i, val[i]);\n\t}\n\tcout << ans << '\\n';\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "graphs", "brute force"], "code_uid": "9219b8fe6a7a6df8db0c55204658f7e8", "src_uid": "250314325e3d088ceedaba7dcde762f1", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include \n#include \nusing namespace std;\ntypedef long long ll;\nint S[10];\nint main() {\n\tint n, m, i, x;\n\tcin >> n >> m;\n\tvector a, b;\n\tfor (i = 0; i < n; i++) {\n\t\tcin >> x;\n\t\ta.push_back(x);\n\t}\n\tfor (i = 0; i < m; i++) {\n\t\tcin >> x;\n\t\tS[x] = 1;\n\t}\n\tfor (i = 0; i < n; i++) {\n\t\tif (S[a[i]]) {\n\t\t\tb.push_back(a[i]);\n\t\t}\n\t}\n\tfor (i = 0; i < b.size(); i++) cout << b[i] << \" \";\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "07b510d8dd40e0f3787b1c121d34cf8e", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n\n int x,r;\n\n//cout<<\"enter the coordinate of elephant s friends\" <>x;\n\n\n r=x%5;\n if (r==0)\n {\n cout << x/5;\n }\n else {\n\n cout<< x/5+1 ;\n }\n\n\n\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "632b561cf7584326d7c8de0f533399b5", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n//#include \n#include \n//#include \n//#include \n//using namespace std;\n\n/*int partition(int *a,int l,int r)\n{\n\tint x=a[r],i=l-1,buf;\n\tfor(int j=l;j\nusing namespace std;\ntypedef long long ll;\n\nint main(){\n\tstring s;\n\tcin>>s;\n\tint fzero=0,lzero=0;\n\tint l=s.length();\n\tfor(int i=0; i=0; i--){\n\t\tif((s[i]-'0')==0) lzero++;\n\t\tif((s[i]-'0')!=0) break;\n\t}\n\tif(fzero > lzero) {\n\t\tcout<<\"NO\"<\nusing namespace std;\ntypedef long long ll;\n\nint main()\n{\n\t//while(1)\n\t{\n\tint x,y;\n\tcin>>x>>y;\n\tif(x==0 && y==0) cout<<0<=0 && y>=0)\n\t\t{\n\t\t\tif(x=0)\n\t\t{\n\t\t\tif(yabs(y)) cout<\n\nusing namespace std;\nint main(){\n\tint n,m,k;\n\tcin>>n>>m>>k;\n\tint a;\n\tm--;\n\tint mi=10000000;\n\tfor(int i=0;i>a;\n\t\tif(a<=k&&a){\n\t\t\tmi=min(mi,abs(m-i)*10);\n\t\t}\n\t}\n\tcout<\nusing namespace std;\n//#define flg(i) cout<<\"flag\\n\"<\n#define vi vector\n#define sec second\n#define fst first\n#define ti tuple\n#define mt(a,b,c) make_tuple(a,b,c)\n#define c2(n) (1LL*((n)*1LL*((n)-1))/2)\n#define vv(type) vector> \n//#define clc(xj,yj,xf,yf) (abs(xj-xf)+abs(yf-yj))\nconst int mn=INT_MIN;\nconst int mx=INT_MAX;\nconst int mod=(1e9)+7;\nconst double pie = 3.141592653589793238463;\n/////////////////////////////\n/////////////////////////////\n/////////////////////////////\nconst int sz=(2e5)+10;\nset st;\nint main()\n{fio;\ncout.tie(NULL);\nll n,m,k;\ncin>>n>>m>>k;\n \nll s=1,e=n*m;\nll ans=1;\nwhile(s<=e)\n{\n ll mid=(s+e)/2;\n \n ll rnk=0;\n f(i,1,n+1) {\n rnk+=min((mid-1)/i,m);\n }\n if(rnk>=k) e=mid-1;\n else ans=mid,s=mid+1;\n }\ncout<\n\nusing namespace std;\n\ntypedef long long INT;\n\ntypedef pair pii;\n\n#define NN 111111\n\ndouble dp[4444][4444];\n\nint main(){\n\n\tint i,j;\n\n\tint n,t;\n\n\tdouble p,pp;\n\n\twhile(scanf(\"%d%lf%d\",&n,&p,&t)==3){\n\n\t\tmemset(dp,0,sizeof(dp));\n\n\t\tdp[0][0]=1;\n\n\t\tfor(i=1;i<=t;i++){\n\n\t\t\tfor(j=0;j<=n;j++){\n\n\t\t\t\tpp=(j==n)?1:(1-p);\n\n\t\t\t\tdp[i][j]+=dp[i-1][j]*pp;\n\n\t\t\t\tif(j)\n\n\t\t\t\t\tdp[i][j]+=dp[i-1][j-1]*p;\n\n\t\t\t}\n\n\t\t}\n\n\t\tdouble cnt=0;\n\n\t\tfor(i=1;i<=n;i++)\n\n\t\t\tcnt+=dp[t][i]*i;\n\n\t\tprintf(\"%lf\\n\",cnt);\n\n\t}\n\n\treturn 0;\n\n}\n ", "lang_cluster": "C++", "tags": ["probabilities", "math", "dp", "combinatorics"], "code_uid": "c89500dd8332f80faeb086e10bfb25e1", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define ll long long\nusing namespace std;\nll ans;\nint n,a,b,s;\nint c[20005];\nbool check(ll m){\n\tint sum=m/a;\n\tfor (int i=0;i<=s;i++) c[i]=i+1;\n\tfor (int i=1;1ll*i*b<=m&&sum=n; \n}\nvoid calc(ll m){\n\tint sum=m/a;\n\tans+=1ll*sum*(sum+1)/2*a;\n\tfor (int i=0;i<=s;i++) c[i]=i+1;\n\tfor (int i=1;1ll*i*b<=m;i++)\n\t\tfor (int j=0;1ll*i*b+1ll*j*a<=m;j++){\n\t\t\tans+=1ll*c[j]*(1ll*i*b+1ll*j*a);\n\t\t\tsum+=c[j],c[j]+=(j?c[j-1]:0);\n\t\t}\n\tans-=m*(sum-n);\n}\nint main(){\n\tscanf(\"%d%d%d\",&n,&a,&b);\n\tif (a>b) swap(a,b);\n\tn--; ans=1ll*n*(a+b);\n\tn--; s=sqrt(n*2)+1;\n\tif (!a){\n\t\tprintf(\"%lld\\n\",ans);\n\t\treturn 0;\n\t}\n\tll l=0,r=1ll*n*a;\n\twhile (l\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define FOR(x, y, z) for (int x = y; x < z; ++x)\n#define FORR(x, y, z) for (int x = y; x > z; --x)\n#define SORT(a) sort(a.begin(), a.end())\n#define SORTR(a) sort(a.rbegin(), a.rend())\n#define GET(a, n) for (int i = 0; i < n; ++i) cin >> a[i];\n#define GETM(a, n, m) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];\n#define PRINT(a, n) for (int i = 0; i < n; ++i) cout << a[i] << \" \";\n#define LL long long\n#define ULL unsigned long long\n#define VI vector \n#define VVI vector >\n#define GETSUM(sum, n) sum = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; sum += tmp; }\n#define SUM(a, n, sum) sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; }\n#define COUNT(a, n, t, count) count = 0; for (int i = 0; i < n; ++i) { if (a[i] == t) ++count; }\n\nusing namespace std;\n\nint main()\n{\n int a, b, c, flag = 0;\n cin >> a >> b >> c;\n if (a > b) {\n flag = 1;\n swap(a, b);\n }\n c -= b - a;\n if (0 > c || 2 * a < c || c % 2) {\n cout << \"Impossible\";\n return 0;\n }\n if (flag == 0)\n cout << a - c / 2 << \" \" << b - (a - c / 2) << \" \" << a - (a - c / 2);\n else\n cout << a - c / 2 << \" \" << a - (a - c / 2) << \" \" << b - (a - c / 2);\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "graphs"], "code_uid": "fa1e2783a2988beb0747942a7fdfec8c", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\nint minjump(vector &path, int initial, int &d, vector &dp)\n{\n\tif (initial == path.size()-1)\n\t\treturn 0;\n\tint cost = INT_MAX;\n\tfor (int i = 1; i <= d && i < path.size(); i++)\n\t{\n\t\tif (path[initial + i] == '1')\n\t\t{\n\t\t\tint jumpcost;\n\t\t\tif(dp[initial+i]==-2)continue;\n\t\t\telse if (dp[initial + i] != -1)\n\t\t\t\tjumpcost = 1+ dp[initial + i];\n\t\t\telse\n\t\t\t{\n\t\t\t\tjumpcost = minjump(path, initial + i, d, dp);\n\t\t\t\tif (jumpcost == -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tdp[initial+i]=-2;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tjumpcost++;\n\t\t\t}\n\t\t\tcost = min(cost, jumpcost);\n\t\t}\n\t}\n\tif (cost == INT_MAX)\n\t\treturn -1;\n\treturn dp[initial] = cost;\n}\n\nint main()\n{\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\tint n, d;\n\tcin >> n >> d;\n\tvector path(n);\n\tvector dp(n, -1);\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> path[i];\n\tcout << minjump(path, 0, d, dp);\n\n\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "greedy", "dp", "implementation"], "code_uid": "2c4268a55b9519a2e9b15b2436f7af56", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\nconst int maxn = 100 + 10, inf = 1e9 + 1;\nint dp[4][maxn][maxn]; // 0: right max, 1: right min, 2: left max, 3: left min\n\nint main() {\n ios_base::sync_with_stdio(false); cin.tie(0);\n string s; cin >> s; s = '.' + s;\n int n; cin >> n;\n for (int i = 0; i < maxn; ++i) for (int j = 0; j < maxn; ++j) {\n dp[0][i][j] = dp[2][i][j] = -inf;\n dp[1][i][j] = dp[3][i][j] = inf;\n }\n dp[0][0][0] = dp[1][0][0] = dp[2][0][0] = dp[3][0][0] = 0;\n for (int k = 0; k <= n; ++k) {\n for (int i = 1; i < s.length(); ++i) {\n dp[1][k][i] = dp[3][k][i] = inf;\n dp[0][k][i] = dp[2][k][i] = -inf;\n for (int j = 0; j <= k; ++j) {\n char cmd = (s[i] == 'F' ? j % 2 ? 'T' : 'F' : j % 2 ? 'F' : 'T');\n if (cmd == 'F') {\n dp[0][k][i] = max(dp[0][k][i], dp[0][k - j][i - 1] + 1);\n dp[1][k][i] = min(dp[1][k][i], dp[1][k - j][i - 1] + 1);\n dp[2][k][i] = max(dp[2][k][i], dp[2][k - j][i - 1] - 1);\n dp[3][k][i] = min(dp[3][k][i], dp[3][k - j][i - 1] - 1);\n } else {\n dp[0][k][i] = max(dp[0][k][i], dp[2][k - j][i - 1]);\n dp[1][k][i] = min(dp[1][k][i], dp[3][k - j][i - 1]);\n dp[2][k][i] = max(dp[2][k][i], dp[0][k - j][i - 1]);\n dp[3][k][i] = min(dp[3][k][i], dp[1][k - j][i - 1]);\n }\n }\n }\n }\n cout << max(max(dp[0][n][s.length() - 1], dp[2][n][s.length() - 1]), -min(dp[1][n][s.length() - 1], dp[3][n][s.length() - 1])) << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "50325ca1880a72eca9711dcfe2140f4d", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\n#define F first\n#define S second\n#define forn(i, n) for (int i = 0; i < int(n); i++)\n\nusing namespace std;\n\nusing ll = long long;\nusing pll = pair;\n\nint move(int s, int& d, int from, int to) {\n if (from == to)\n return 0;\n\n int result;\n if (d == 1) {\n if (from < to) {\n result = to - from;\n } else {\n result = s - from + s - to;\n d = -1;\n }\n } else {\n if (from < to) {\n result = from + to;\n d = 1;\n } else {\n result = from - to;\n }\n }\n return result;\n}\n\nint main() {\n ios_base::sync_with_stdio(false);\n cout << setprecision(12);\n cin.tie(nullptr);\n\n int s, x1, x2;\n cin >> s >> x1 >> x2;\n\n int t1, t2;\n cin >> t1 >> t2;\n\n int p, d;\n cin >> p >> d;\n\n int ans = abs(x2 - x1) * t2;\n int m = 0;\n m += move(s, d, p, x1);\n m += move(s, d, x1, x2);\n ans = min(ans, m * t1);\n cout << ans << endl;\n}\n", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "473b0030307dff986304ec01b66e5738", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include\nusing namespace std;\n\nint main() {\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\n\tint n, m, n2; cin >> n >> m;\n\tn2 = n+1;\n\twhile (true) {\n\t\tif (n2 % 2 != 0 && n2 % 3 != 0 && n2 % 5 != 0 && n2 % 7 != 0 || n2 == 2 || n2 == 3 || n2 == 5 || n2 == 7)\n\t\t\tbreak;\n\t\tn2++;\n\t}\n\tif (n2 == m) cout << \"YES\";\n\telse cout << \"NO\";\n}", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "67825d37e68c49eae95c7907a502cba9", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\nint main()\n{\n int n;\n int sum = 0;\n cin >> n;\n int cnt1 = 0;\n int cnt2 = 0;\n int a = 0;\n for (int i = 0; i < n; i++)\n {\n cin >> a;\n if (a == 100)cnt1++;\n else cnt2++;\n }\n if (cnt1%2==0 && cnt2%2==0)cout << \"YES\" << endl;\n else\n if (cnt1 % 2 == 0 && cnt1>=2) cout << \"YES\" << endl;\n else\n cout << \"NO\" << endl;\n\nreturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "7aa97d4ecc037a3c1a12a25a3dad8715", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n \n#define ll long long\n#define ld long double\n#define pb push_back\n#define mp make_pair\n#define ff first\n#define ss second\n#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));\n#define MOD 1000000007\n#define INF LONG_LONG_MAX\n#define MINF LONG_LONG_MIN\n \n long long power(long long x,long long n)\n {\n long long res=1;\n while(n)\n {\n if(n&1)\n {\n res=(res*x)%MOD;\n }\n x=(x*x)%MOD;\n n>>=1;\n }\n return res;\n }\n \n int fact(int n)\n {\n int x=1,i;\n for(i=n;i>=2;i--)\n {\n x=x*i;\n }\n return x;\n }\n \n void factors(vector> &fac,int n)\n {\n int i;\n for(i=1;i>n>>k;\n int a[n][k];\n string s;\n for(i=0;i>s;\n for(j=0;j\n\nusing namespace std;\nint a[100];\nint main()\n{\n int n,j;\n cin>>n;\n for(int i=1;i<=n;i++)\n cin>>a[i];\n int ans=90;\n a[n+1]=90;\n for(int i=1;i<=n+1;i++)\n {\n if(a[i]-a[i-1]>15)\n {\n ans=a[i-1]+15;\n i=n+1;\n }\n }\n cout<\n\nusing namespace std;\n\nint main(){\nint z,a[10],y;\nchar x[2];\nfor(int i=0;i<2;i++)cin>>x[i];\nz=x[0]-48;\ny=x[1]-48;\na[0]=2;\na[1]=7;\na[2]=2;\na[3]=3;\na[4]=3;\na[5]=4;\na[6]=2;\na[7]=5;\na[8]=1;\na[9]=2;\nz=a[z]*a[y];\ncout<\n#define ll long long int\nusing namespace std;\nconst int N=1010;\nconst int MOD=(int)1e6+3;\nll n,dp[N],twoPow[2*N];\n\nvoid init() {\n twoPow[0]=1;\n for(int i=1;i<=2*N;i++)\n twoPow[i]=(twoPow[i-1]*2)%MOD;\n memset(dp,-1,sizeof(dp));\n}\n\nll cookie(ll a) {\n return (twoPow[a-1]*(twoPow[a]+1))%MOD;\n}\n\nll solve(ll a) {\n if (a<=0)\n return 0;\n if (dp[a]!=-1)\n return dp[a];\n dp[a]=cookie(a)%MOD;\n for(int i=1;a-i>0;i++) {\n dp[a]=(dp[a]+solve(a-i)*twoPow[i-1])%MOD;\n }\n return dp[a];\n}\n\nint main() {\n init();\n cin >> n;\n cout << (twoPow[2*n]-solve(n)+MOD)%MOD << endl;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "a0831519cbb276581bbab46a58baff2c", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \nusing namespace std;\n\nunordered_set S;\nlong long int n, x, y;\n\nvoid foo(long long int v){\n if(v<=0 || v>n) return;\n v*=10;\n S.insert(v);\n foo(v+x);\n foo(v+y);\n}\n\nint main(){\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n\n cin>>n;\n\n for(int i=0; i<10; i++)\n {\n for(int j=0; j<10; j++){\n x=i;\n y=j;\n foo(x);\n }\n }\n cout<\n#define ll long long\nusing namespace std;\nconst int N = 2e5 + 5;\nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(0); cout.tie(0);\n\tll n, a, b, c;\n\tcin >> n >> a >> b >> c;\n\tif(a <= (b - c)){\n\t\tcout << n / a;\t\t\n\t}else{\n\t\tif(n < b){\n\t\t\tcout << n / a;\n\t\t}else{\n\t\t\tll ans = 0;\n\t\t\tans += (n - b) / (b - c);\n\t\t\tn -= ans * (b - c);\n\t\t\tans++;\n\t\t\tn -= (b - c);\n\t\t\tans += n / a;\n\t\t\tcout << ans;\n\t\t}\n\t}\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "9da5af68d4d8537261e8cb7240bf925f", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\ntypedef long long ll;\ntypedef double dbl;\n#define sqr(int) (int * int)\n#define sqr3(int) (int * int * int)\n#define pi M_PI\n#define nl \"\\n\"\n\n\nint main(){\n int a,b,c;\n cin >> a >> b >> c;\n int mx = max(a,b);\n\tint mn = min(a,b);\n\tint dif = abs(a-b);\n\tif(dif > c){\n\t\tmn += c;\n\t\tcout << mn * 2;\n\t\treturn 0;\n\t}\n\tif(c+mn >= mx){\n\t\tif((c + mn + mx) % 2 == 0){\n\t\t\tcout << c + mn + mx;\n\t return 0;\t\n\t\t}\n\t\telse{\n\t\t\tcout << c + mn + mx-1;\n\t\t\treturn 0;\n\t\t}\n\t}\n\tcout << 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "8ffcc7d002d1d56053b1419f4ae06520", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \nusing namespace std;\n\nint main()\n{\n int sum=0,add=0;\n string x;\n cin>>x;\n for(int i=0 ; i\n#include \nusing namespace std;\nint main()\n{\n\tint a,i,ans=6;\n\tscanf(\"%d\",&a);\n\tfor(i=4;i<=a;i++) ans+=i*(i-1);\n\tprintf(\"%d\",ans);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "dp"], "code_uid": "26bcbea3f7f5e065d14b5a05a2da9941", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "// Best practice\n\n#include\n\n#define int long long\n#define pb push_back\n#define pf emplace_front\n#define all(a) (a).begin(),(a).end()\n#define rall(a) (a).rbegin(),(a).rend()\n#define pii \t\tpair\n#define psi \t\tpair\n#define vi \t\t\tvector\n#define vpii \t\tvector\n#define vvi \t\tvector\n#define sz(x)\t (int)(x).size()\n#define x first\n#define y second\n#define endl '\\n'\n#define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n#define MOD 1000000007\n#define hell 998244353\n#define prec(n) \tfixed< _it(_ss); err(_it, args);cout << endl; }\nvoid err(istream_iterator it) {}\ntemplate\nvoid err(istream_iterator it, T a, Args... args) {\n cout << \"[\" << *it << \": \" << a << \"]\\t\";\n err(++it, args...);\n}\n\n// const int dx[4] = { -1, 1, 0, 0};\n// const int dy[4] = {0, 0, -1, 1};\n// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };\n// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };\n\n\n// Code from Here -------------------------------------------------------------------------------\n\nint dis(int a, int b, int x, int y){\n\treturn abs(a-x)+abs(b-y);\n}\n\n\nsigned main() {\n\ttezz\n\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\n\tint x0,y0,a,b,c,d,x,y,t;\n\tcin >> x0 >> y0 >> a >> b >> c >> d >> x >> y >> t;\n\tvector arr, brr;\n\tarr.pb(x0);\n\tbrr.pb(y0);\n\twhile(brr.back()<=(inf-c)/a && arr.back()<=(inf-c)/a){\n\t\tarr.pb(arr.back()*a+c);\n\t\tbrr.pb(brr.back()*b+d);\n\t}\n\t// debug(arr);\n\t// debug(brr);\n\tint n=sz(arr), ans=0;\n\tfor(int i=0; i\r\nusing namespace std;\r\nvoid solve(){\r\n ll a,b;\r\n cin >>a >>b;\r\n if (b==1){\r\n cout<<(a-1)<> t;\r\n//while (t--){\r\n solve();\r\n//}\r\nreturn 0;\r\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "ba2afa09396aa3648eb8d7c2f37a187d", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nint main()\n{\n int n;\n scanf(\"%d\",&n);\n n-=10;\n if (n<=0||n>11) \n {\n printf(\"0\");\n return 0;\n } \n if (n==10)\n {\n printf(\"15\");\n return 0;\n }\n printf(\"4\");\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "ddd6fe793669918d1d04f74cba3e407a", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "//By Akanesasu\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define rep(x,a,b) for (int x=int(a);x<=(int)(b);x++)\n#define drp(x,a,b) for (int x=int(a);x>=(int)(b);x--)\n#define cross(x,a) for (int x=hd[a];~x;x=nx[x])\n#define ll long long\n#define pii pair\n#define pdd pair\n#define mk(a,b) make_pair(a,b)\n#define fs first\n#define sc second\n#define pb push_back\n#define VI vector\n#define VS vector\nusing namespace std;\ninline ll rd(){\n\tll x=0;int ch=getchar(),f=1;\n\twhile (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();\n\tif (ch=='-'){f=-1;ch=getchar();}\n\twhile (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}\n\treturn x*f;\n}\ninline void rt(ll x){\n\tif (x<0) putchar('-'),x=-x;\n\tif (x>=10) rt(x/10),putchar(x%10+'0');\n\t\telse putchar(x+'0');\n}\nconst int maxn=55,p=1000000007,inv2=500000004;\nint n;\nll f[maxn][maxn][maxn],g[maxn][maxn];\n//f[i][j][k]\ufffd\ufffd\u02bei\ufffd\ufffd1 j\ufffd\ufffd2 \ufffd\ufffd\ufffd\ufffd\u0225k\ufffd\ufffd\ufffd\u07f5\u0137\ufffd\ufffd\ufffd\ufffd\ufffd\nvoid upd(ll &x,ll y){\n\tx=(x+y)%p;\n}\nvoid prepare(){\n\tf[0][0][0]=1;\n\trep(k,0,n-1) rep(j,0,n) rep(i,0,n-j){\n\t\tll &v=f[i][j][k];\n\t\tif (j){\n\t\t\tif (i>1) upd(v,f[i-2][j-1][k]*(i*(i-1)/2));\t\t//2-1 2-1\n\t\t\tif (i&&j>1) upd(v,f[i][j-2][k]*i*(j-1));\t\t//2-1 2-2\n\t\t\tif (j>2) upd(v,f[i+2][j-3][k]*((j-1)*(j-2)/2));\t//2-2 2-2\n\t\t\tif (i) upd(v,f[i-1][j-1][k-1]*i);\t\t\t\t//2-1\n\t\t\tif (j>1) upd(v,f[i+1][j-2][k-1]*(j-1));\t\t\t//2-2\n\t\t\tupd(v,f[i][j-1][k-2]*inv2);\t\t\t\t\t\t//Nope\n\t\t}\n\t\telse if (i){\n\t\t\tif (i>1) upd(v,f[i-2][j][k]*(i-1));\t//1-1\n\t\t\tupd(v,f[i-1][j][k-1]);\t\t\t\t//Nope\n\t\t}\n\t}\n\tll fac=1;\n\trep(k,0,n-1){\n\t\trep(i,0,n) rep(j,0,n-i) (f[i][j][k]*=fac)%=p;\n\t\t(fac*=k+1)%=p;\n\t}\n}\nint a[maxn];\nint main(){\n\tn=rd();\n\trep(i,1,n) a[i]=rd();\n\tprepare();\n\tg[1][a[1]]=1;\n\tll v;\n\trep(i,1,n-1) rep(j,1,n-i) if ((v=g[i][j])){\n\t\tint n1=0,n2=0;\n\t\trep(k,i+1,i+j) if (a[k]==2) n1++;else n2++;\n\t\trep(k,0,n1+2*n2) upd(g[i+j][k],v*f[n1][n2][k]);\n\t}\n\trt(g[n][0]),putchar('\\n');\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "graphs", "shortest paths"], "code_uid": "c3eb46e72a6bff91339250903a0993ca", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef vector veci;\ntypedef vector vecll;\ntypedef stack stki;\ntypedef stack stkll;\ntypedef queue qi;\ntypedef queue qll;\ntypedef deque dqi;\ntypedef deque dqll;\ntypedef pair pii;\ntypedef pair pll;\ntypedef priority_queue pqi;\ntypedef priority_queue pqll;\ntypedef string st;\n\nvector ar;\nint solved = 0;\nvoid moveStatues(vector &v) {\n for(int i = 0;i v){\n for(int k = 0;k v,vector used) {\n if(i<0 || j < 0 || j >= 8 || i >= 8 || used[i][j]) {\n return 0;\n }\n if (checkOnStatue(i,j,v)) {\n return 0;\n }\n if(i == 0 && j == 7){\n solved = 1;\n return 1;\n }\n moveStatues(v);\n if (checkOnStatue(i,j,v)) {\n return 0;\n }\n int x = 0;\n used[i][j] = 1;\n\n x = max(dfs(i-1,j,v,used),x);if(solved) return 1;\n x = max(dfs(i,j+1,v,used),x);if(solved) return 1;\n x = max(dfs(i,j-1,v,used),x);if(solved) return 1;\n x = max(dfs(i+1,j,v,used),x); if(solved) return 1;\n x = max(dfs(i+1,j+1,v,used),x);if(solved) return 1;\n x = max(dfs(i+1,j-1,v,used),x);if(solved) return 1;\n x = max(dfs(i-1,j+1,v,used),x);if(solved) return 1;\n x = max(dfs(i-1,j-1,v,used),x);if(solved) return 1;\n x = max(dfs(i,j,v,used),x);if(solved) return 1;\n return x;\n}\nint main()\n{\n ios_base::sync_with_stdio(0),cin.tie(0);\n int n,m,k,r,i,j,temp,temp1,temp2,temp3,x,x1,x2,x3;\n st str;\n vector used;\n veci asd(8);\n for(i = 0;i<8;i++){\n used.push_back(asd);\n }\n vector v;\n for ( i = 0;i<8;i++) {\n cin>>str;\n ar.push_back(str);\n for(j = 0;j<8;j++) {\n if(str[j] == 'S') {\n v.push_back(make_pair(i,j));\n\n }\n }\n }\n\nx = 0;\n x = dfs(7,0,v,used);\n if (x == 1) {cout<<\"WIN\"<\n#define ll long long\n#define ull unsigned long long int\n#define sort(a) sort((a).begin(),(a).end());\n#define rev(a) reverse((a).begin(),(a).end());\n#define vec vector\n#define str string\n#define pb(a) push_back((a));\n#define ld long double\n#define sz(x) x.size()\n#define MP make_pair\n#define fi first\n#define se second\nusing namespace std;\nint gcd(int a, int b)\n{\n\tif (b == 0) return a;\n\treturn gcd(b, a%b);\n}\nll fact(ll j)\n{\n\tll a = 1;\n\tfor (ll i = 1; i <= j; i++)\n\t\ta *= i;\n\treturn a;\n}\nll sum2(ll c)\n{\n\tll s = 0;\n\twhile (c != 0)\n\t{\n\t\ts += (c % 10)*(c % 10);\n\t\tc /= 10;\n\t}\n\treturn s;\n}\nbool prime(ll a)\n{\n\tif (a == 0 || a == 1) return false;\n\tfor (int i = 2; i <= sqrt(a); i++)\n\t\tif (a%i == 0) return false;\n\treturn true;\n}\nint main(){\n\t//freopen(\".in\",\"r\",stdin);\n //freopen(\".out\",\"w\",stdout);\n\tull n;\n\tcin>>n;\n\tif(n<=127)cout<<\"byte\";\n\telse if(n<=32767)cout<<\"short\";\n\telse if(n<=2147483647)cout<<\"int\";\n\telse if(n<=9223372036854775807)cout<<\"long\";\n\telse cout<<\"BigInteger\";\n\t}\n\t//12", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "e210339e9dcb523179358eb26c8156ca", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \n#include\nusing namespace std;\nint main()\n{\n\tdouble n,m,k;\n\tcin >> n>>m>>k;\n\tcout <\n#define fi first\n#define se second\n#define pb push_back\ntypedef long long ll;\nusing namespace std;\n\nll les;\n\nll rec(ll N){\n\tll tmp = N;\n\tbool ok = 0;\n\tll cnt = 1;\n\twhile(tmp >= 10){\n\t\tif(tmp % 10 != 9) ok = 1;\n\t\ttmp = tmp/10;\n\t\tcnt++;\n\t}\n\tif(tmp != 9) ok = 1;\n\tif(cnt != les-1) return 0;\n\tll ans = 0;\n\n\t\tfor(int i=0;i<=4;i++){\n\t\t\tint j=9-i;\n\t\t\t//cout << j << \" \" << tmp << \"\\n\";\n\t\t\tif(j > tmp) continue;\n\t\t\tif(j == tmp) ans = ans + (N - tmp * pow(10,cnt-1) ) + 1;\n\t\t\telse{\n\t\t\t\tans = ans + pow(10,cnt-1);\n\t\t\t}\n\t\t}\n\t\treturn ans;\n}\n\nint main(){\n\tll N;\n\tcin >> N;\n\tll tmp = N;\n\tbool ok = 0;\n\tll cnt = 1;\n\tint lol = 0;\n\twhile(tmp >= 10){\n\t\tif(tmp % 10 != 9) ok = 1;\n\t\tif(tmp % 10 == 9) lol++;\n\t\ttmp = tmp/10;\n\t\tcnt++;\n\t}\n\tles = cnt;\n\tif(tmp != 9) ok = 1;\n\telse lol++;\n\tll ans = 0;\n\tif(tmp >= 5){\n\t\tfor(int i=0;i<=4;i++){\n\t\t\tint j=9-i;\n\t\t\t//cout << j << \" \" << tmp << \"\\n\";\n\t\t\tif(j > tmp) continue;\n\t\t\tif(i == 0 && lol == cnt) ans--;\n\t\t\tif(j == tmp) ans = ans + (N - tmp * pow(10,cnt-1) ) + 1;\n\t\t\telse{\n\t\t\t\tans = ans + pow(10,cnt-1);\n\t\t\t}\n\t\t}\n\t\t//if(!ok) ans--;\n\t\tcout << ans << \"\\n\";\n\t}\n\telse{\n\t\tif(N <= 4){\n\t\t\tcout<< N * (N-1) / 2 << \"\\n\";\n\t\t\treturn 0;\n\t\t}\n\t\telse{\n\t\t\tfor(int i=0;i<=tmp;i++){\n\t\t\t\tfor(int j=i;j<=tmp;j++){\n\t\t\t\t\tif(i == tmp && j == tmp) {\n\t\t\t\t\t//\tcout << ans << \" \" << \"\\n\";\n\t\t\t\t\t\tans += rec(N - tmp * pow(10,cnt-1)) ;\n\t\t\t\t\t}\n\t\t\t\t\telse if(j == tmp){\n\t\t\t\t\t\tans = ans + (N - tmp * pow(10,cnt-1)) + 1;\n\t\t\t\t\t}\n\t\t\t\t\telse if(i == j){\n\t\t\t\t\t\tans = ans + pow(10,cnt-1)/2;\n\t\t\t\t\t}\n\t\t\t\t\telse \n\t\t\t\t\t{\n\t\t\t\t\t\tans = ans + pow(10,cnt-1) ;\n\t\t\t\t\t}\n\t\t\t\t//\tcout << lol << \" \"<< cnt-1 << \"\\n\";\n\t\t\t\t\tif(i == 0 && (j != tmp || lol >= (cnt-1) )) ans--;\n\t\t\t\t//\tcout << i << \" \" << j << \" \" << ans << \"\\n\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcout << ans << \"\\n\";\n\t}\n}\n", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "9da7980124b40a94302e92ea5646daf0", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n\nint main()\n{\n int ar[3][3];\n \n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n cin>>ar[i][j];\n }\n ar[0][0]=(-ar[0][1]-ar[0][2]+ar[1][0]+ar[1][2]+ar[2][0]+ar[2][1])/2; \n ar[1][1]=(ar[0][1]+ar[0][2]-ar[1][0]-ar[1][2]+ar[2][0]+ar[2][1])/2;\n ar[2][2]=(ar[0][1]+ar[0][2]+ar[1][0]+ar[1][2]-ar[2][0]-ar[2][1])/2;\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n cout<\nusing namespace std;\nint a,b,c,d,e,f;\nint main()\n{\n\tcin >> a >> b >> c >> d >> e >> f;\n\tprintf(\"%d\\n\",(a + b + c) * (a + b + c) - a * a - c * c - e * e);\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "geometry"], "code_uid": "a8ffdfa991647b0bfd8f37e05f1413ad", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "/**********************************************************\n * Code written by Akikaze *\n * Duy-Bach Le, #Team4T's Chief Executor *\n * #Team4T Tertiary Flagship - Oblivion *\n * *\n * Written by a random fan of momocashew and Chiho *\n * *\n * Arigatougozaimasu, imouto-chan. *\n **********************************************************/\n\n/************** [OPTIMIZATION PROTOCOL] **************/\n#pragma comment(linker, \"/stack:225450978\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n/*****************************************************/\n\n/************** [LIBRARY PROTOCOL] **************/\n#include \nusing namespace std;\n/************************************************/\n\n/************** [LEGENDS/CONSTANTS] **************/\n#define endl '\\n'\n#define i64 long long\n#define ld long double\n#define rsz resize\n#define pub push_back\n#define mp make_pair\n#define fi first\n#define se second\ntypedef vector vi;\ntypedef vector vd;\ntypedef vector vs;\ntypedef vector vc;\ntypedef vector vb;\ntypedef pair pii;\ntypedef pair pip;\ntypedef pair ppi;\nconst long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;\nconst long double Pi = 3.141592653589793116, EPS = 1e-9, Gold = ((1+sqrt(5))/2);\nlong long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};\nlong long keyCount = sizeof(keymod) / sizeof(long long);\n/*************************************************/\n\n/************** [BITWISE FUNCTIONS] **************/\ntemplate int getbit(T s, int i) { return (s >> i) & 1; }\ntemplate T onbit(T s, int i) { return s | (T(1) << i); }\ntemplate T offbit(T s, int i) { return s & (~(T(1) << i)); }\ntemplate int cntbit(T s) { return __builtin_popcountll(s); }\n/*************************************************/\n\n/************** [MASTER CONTROLS - PHASE 1] **************/\nauto TimeStart = chrono::steady_clock::now();\nauto TimeEnd = chrono::steady_clock::now();\n#define OImode 227420978\n#define MultiTest 227420978\n\n#undef OImode // Switch this off if submitting OI problems.\n#undef MultiTest // Switch this off if submitting multi-test problems.\n\nvoid ControlIO(int argc, char* argv[]);\nvoid TimerStart();\nvoid TimerStop();\nvoid Exit();\n/*********************************************************/\n\n/************** [GLOBAL VARIABLES] **************/\ni64 n, m;\n/************************************************/\n\n/************** [FUNCTIONS] **************/\ni64 modPow(i64 a, i64 b, i64 M) {\n\tif (b == 0) return 1;\n\ti64 tmp = modPow(a, b/2, M);\n\tif (b % 2 == 0) return ((tmp * tmp) % M);\n\treturn ((((tmp * tmp) % M) * a) % M);\n}\n\nvoid Input() {\n\tcin >> n >> m;\n}\n\nvoid Solve() {\n\ti64 A = (modPow(3, n, m) + m - 1) % m;\n\tcout << A;\n}\n/*****************************************/\n\n/************** [MAIN] **************/\nint main(int argc, char* argv[]) {\n\tControlIO(argc, argv);\n\tios_base::sync_with_stdio(0); cin.tie(NULL);\n\t#ifndef MultiTest\n\t\tInput(); TimerStart();\n\t\tSolve(); TimerStop();\n\t#else\n\t\tint T; cin >> T; TimerStart();\n\t\twhile(T--) {Input(); Solve();}\n\t\tTimerStop();\n\t#endif\n\treturn 0;\n}\n/************************************/\n\n/************** [MASTER CONTROLS - PHASE 2] **************/\nvoid ControlIO(int argc, char* argv[]) {\n\t#ifdef Akikaze\n\ttime_t t = time(0);\n\ttm* now = localtime(&t);\n\tcout << \"Source code by #Team4T-Akikaze.\\n\";\n\tcout << \"Current time: \";\n\tcout << (now->tm_year + 1900) << '-' \n\t << (now->tm_mon + 1) << '-'\n\t << now->tm_mday << \" | \"\n\t << now->tm_hour << \":\"\n\t << now->tm_min << \":\"\n\t << now->tm_sec\n\t << \"\\n\\n\";\n\tif (argc > 1) assert(freopen(argv[1], \"r\", stdin));\n\tif (argc > 2) assert(freopen(argv[2], \"w\", stdout));\n\t#elif OImode\n\tfreopen(\"FILENAME.INP\", \"r\", stdin);\n\tfreopen(\"FILENAME.OUT\", \"w\", stdout);\n\t#endif\n}\n\nvoid TimerStart() {\n\t#ifdef Akikaze\n\tTimeStart = chrono::steady_clock::now();\n\t#endif\n}\n\nvoid TimerStop() {\n\t#ifdef Akikaze\n\tTimeEnd = chrono::steady_clock::now();\n\tauto ElapsedTime = TimeEnd - TimeStart;\n\tcout << \"\\n\\nTime elapsed: \" << chrono::duration(ElapsedTime).count() << \" seconds.\\n\";\n\t#endif\n}\n\nvoid Exit() {\n\tTimerStop(); exit(0);\n}\n/*********************************************************/\n\n/*********************************************************************************************************************************************************************************************************\n * ti;. .:,:i: :,;;itt;. fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE :,:. f::::. .,ijLGDDDDDDDEEEEEEE*\n *ti;. .:,:i: .:,;itt;: GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG. .::. f:,...,ijLGDDDDDDDDEEEEEE *\n *ti;. .:,:i: :,;;iti, :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG .::. .f,::,ijLGDDDDDDDDEEEEEE *\n *ti;. .:,:i: .,,;iti;. LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj .::. .:L;;ijfGDDDDDDDDDEEEEE *\n *ti;. .:,:i: .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL .::. .:;LijLGGDDDDDDDDEEEEE *\n *ti;. .:,:;: :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj .::. :,;jffGGDDDDDDDDDEEEE *\n *ti;. .:,:i: .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL .::. .:;itDGGDDDDDDDDDEEEE *\n *ti;. .:::;: :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf .::. :,itfGEDDDDDDDDDDDEE *\n *ti;. .:::;: :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG .::. .,;jfLGKDLDDDDDDEEDD *\n *ti;. .:::;: fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::. .,;tfLGDEDDDDDDDDEEE *\n *ti;. :::;: fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::. .,;tfLGDDDKDDDDDDDDD *\n *ti;. .::;: fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:. .,;tfLGGDDDKDDDDDDDD *\n *ti;. .:.;: tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::. .,;tfLGGDDDDEDDDDDDD *\n *ti;. .::;: fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::. .,;tfLGGDDDDDDEDDDDD *\n *ti;. .:.;: tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::. .,;tfLGGDDDDDDDEDDDD *\n *ti;. .:.,. LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:. .,;tfLGGDDDDDDDDEDDD *\n *ti;. ..:.,. LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,. .,;tfLGGDDDDDDDDDKDD *\n *tt;. .:.,: jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,: .,;tfLGGDDDDDDDDDDKD *\n *tii,. .:.,. tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,. .,;tfLGGDDDDDDDDDDDE *\n *ti;;,:. .:.,: fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,. .,;tfLGGDDDDDDDDDDDD *\n *tii;,,:.. ...,. ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,: .,itfLGGDDDDDDDDDDDD *\n *ti;,,,,,:. ...,. LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:. .,itfGGGDDDDDDDDDDDD *\n *tii,,,,::::. ...,: .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:. .,ijfGGGDDDDDDDDDDDD *\n *ti;:::::::::.. .:.,: LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,: .,ijLGGGDDDDDDDDDDDD *\n *tt;. .::::::::.. ...,: :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:. .:,;,:. .,ijLGGDDDDDDDDDDDDD *\n *tt;. .:::::::.. ...,: GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,. :,,,:...,ijLGGGDDDDDDDDDDDD *\n *tt;. .....::::.. ...,: fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi. .,;,:::,ijLGGGDDDDDDDDDDDD *\n *tt;. ....:::::. ...,. iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff. .:,;,,;ijLGGGDDDDDDDDDDDD *\n *tt;. ....::::.. .:.,: .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG. .:,;;iijLGGGDDDDDDDDDDDD *\n *tt;. .....:::.. ...,. .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG. :,iitjLGGGDDDDDDDDDDDD *\n *tti. .....:::.. ...,. GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf. .,;tjfLGGDDDDDDDDDDDD *\n *tti. ....::::.. ...,. fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf. :;ijfLGGDDDDDDDDDDDD *\n *tti. ....::::.. ...,. LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf: .,itfLGGDDDDDDDDDDDD *\n *tti. .....:::.. ...,. fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi .,;tfLGGGDDDDDDDDDDD *\n *tti. .....:::.. ...,. iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL .,;tjLLGGDDDDDDDDDDD *\n *tti. ....::::......:. LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG .,;tjLLGGDDDDDDDDDDD *\n *tti. ...::::::..,. :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL .,;tjLLGGDDDDDDDDDDD *\n *tti. ....::::::,. GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf .,;tjLLGGDDDDDDDDDDD *\n *tti. ....:::,,. .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf .:;tjLLGGGDDDDDDDDDD *\n *tti. ...::,,,:. GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf .:;tjLLGGDDDDDDDDDDD *\n *jti. ...::,,,,:. .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf: .,;tfLLGGDDDDDDDDDDD *\n *tti. ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi .,;tfLLGGGDDDDDDDDDD *\n *tti. ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL .,;tfLGGGDDDDDDDDDDD *\n *jti. ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG .,;tfLGGGGDDDDDDDDDD *\n *jti. ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL .,;tfLGGGGDDDDDDDDDD *\n *jti. ...:. .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf .,;tfGGGGDDDDDDDDDDD *\n *jti. ...:. ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:. .,;tfGGGGDDDDDDDDDDD *\n *jti. ...:. GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,: .,;tfGGGGDDDDDDDDDDD *\n *jti. ...:. GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK, ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:. .,;tfGGGDDDDDDDDDDDD *\n *jti. ...:. .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:. .,;tfGGGDDDDDDDDDDDD *\n *jti. ...:. DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD *\n *jti. ...:. fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG .:,,,:::,;tfGGGDDDDDDDDDDDD *\n *jti. ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL .:,;,,,;tfGGGDDDDDDDDDDDD *\n *jti. ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf .:,;;;itfGGGDDDDDDDDDDDD *\n *jti. ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf .,;iitfGGGDDDDDDDDDDDD *\n *jti. ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL .:;itfGGGDDDDDDDDDDDD *\n *jji. ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j. KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf .,;tfGGGDDDDDDDDDDDD *\n *jji. ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;.................................. . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL, .:;tfGGGDDDDDDDDDDDD *\n *jji. .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................:: KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj .:;tfGGDDDDDDDDDDDDD *\n *jji. .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG .:;tfGGGDDDDDDDDDDDD *\n *jji. . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG .;tjfLLGDDDDDDDDDDDDDDD *\n *jji. i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL ,fGGGDDDDDDDDEEEDDDDDDDDDD *\n *jji. .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD *\n *jji. i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD *\n *jji. .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD *\n *jji. .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL; .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD *\n *jji. :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED *\n *jji. i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE *\n *jji. i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD *\n *jji. .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG *\n *jjt. :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG *\n *jji. ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG *\n *jjt. f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG *\n *jjt. ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG *\n *fji. ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL *\n *fji. t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL *\n *fjt: .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL *\n *fjji;:. .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG *\n *fjjtii;,:. :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG *\n *fjtiiiii;;:. j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG *\n *fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG *\n *fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD *\n *jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD *\n *fjt. .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD *\n *fjt. .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD *\n *fjt. .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD *\n *fjt: :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD *\n *fjt: t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD *\n *jjt. f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD *\n *fjt:. ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG *\n *fjt:. ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; *\n *fjt:. f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, *\n *fjt:. .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, *\n *fjt:. .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, *\n *fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, *\n *fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, *\n *fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *\n *fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *\n *fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; *\n ***********************************************************************************************************************************************************************************************************/", "lang_cluster": "C++", "tags": ["math"], "code_uid": "02e969828fa8c90ecf63941da505769c", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define N 1500\n#define M 100000\n#define reg register\n#define inl inline\n#define int long long\nusing namespace std;\nconst int Mod=1e9+7;\nint n,m,A,B,T,P,p[M+5],sum[N+5],f[N+5][N+5],a[N+5][N+5],b[N+5][N+5],fac[M+5],inv[M+5];\ninl int Pow(reg int x,reg int y)\n{\n\treg int res=1;\n\tfor(;y;y>>=1,x=x*x%Mod) if(y&1) res=res*x%Mod;\n\treturn res;\n}\ninl int C(reg int x,reg int y)\n{\n\treturn x>=y?fac[x]*inv[x-y]%Mod*inv[y]%Mod:0;\n}\ninl void Init()\n{\n\tfac[0]=1;\n\tfor(reg int i=1;i<=M;i++) fac[i]=fac[i-1]*i%Mod;\n\tinv[M]=Pow(fac[M],Mod-2);\n\tfor(reg int i=M-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%Mod;\n}\nsigned main()\n{\n\tInit();\n\tscanf(\"%lld %lld\",&n,&m);\n\tscanf(\"%lld %lld\",&A,&B);\n\tscanf(\"%lld\",&T);\n\tP=A*Pow(B,Mod-2)%Mod;\n\tfor(reg int i=0;i<=T;i++) p[i]=C(T,i)*Pow(P,i)%Mod*Pow(1-P+Mod,T-i)%Mod;\n\tfor(reg int i=1;i<=m;i++) sum[i]=(sum[i-1]+p[i-1])%Mod;\n\tf[0][m]=a[0][m]=1;\n\tfor(reg int i=1;i<=n;i++)\n\t{\n\t\tfor(reg int j=1;j<=m;j++)\n\t\t{\n\t\t\tf[i][j]=((a[i-1][m]-a[i-1][m-j]+Mod)*sum[j]-b[i-1][j]+Mod)%Mod*p[m-j]%Mod;\n\t\t\ta[i][j]=(a[i][j-1]+f[i][j])%Mod;\n\t\t\tb[i][j]=(b[i][j-1]+p[j-1]*a[i][j-1])%Mod;\n\t\t}\n\t}\n\tprintf(\"%lld\\n\",a[n][m]);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp"], "code_uid": "2dd2c7f6e34f4fc3de99e81e3e6f4575", "src_uid": "33b6b0d3a6af273f22b703491bd17289", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main() {\n\nlong long int n,m,i,r=5,t,sum=0;\ncin>>n>>m;\n\n if(m>n)\n{\n for(i=1;i<=n;i++)\n {\n if(i%5==0)\n {\n r+=5;\n }\n t=(m-r+i);\n if(t>=0)\n {t=t/5+1;\n sum+=t;}\n }\n}\nelse\n{\n for(i=1;i<=m;i++)\n {\n if(i%5==0)\n {\n r+=5;\n }\n t=(n-r+i);\n if(t>=0)\n {\n t=t/5+1;\n sum+=t;\n }\n }\n\n}\n\ncout<\n\nusing namespace std;\ndouble dp[1005][1005][2];\ndouble explore(int w,int b,int c)\n{\n\tif(w==0)\n\t\treturn 0.0;\n\tif(b==0)\n\t\treturn 1.0-(double)c;\n\tif(dp[w][b][c]>=0)\n\t\treturn dp[w][b][c];\n\tif(c==0)\n\t\treturn dp[w][b][c]=(double)w/double(b+w)+(double)b/double(b+w)*explore(w,b-1,1);\n\tif(b>=2)\n\t\treturn dp[w][b][c]=(double)b/double(b+w)*(double)(b-1)/double(b+w-1)*explore(w,b-2,0)+(double)b/double(b+w)*(double)(w)/double(b+w-1)*explore(w-1,b-1,0);\n\treturn dp[w][b][c]=(double)b/double(b+w)*(double)(w)/double(b+w-1)*explore(w-1,b-1,0);\n}\n\n\nint main()\n{\n\tint a,b;\n\tcin>>a>>b;\n\tmemset(dp,-1.0,sizeof(dp));\n\tcout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \ntypedef long long ll;\nusing namespace std;\nint n;\n\nconst int N = 100+10;\nchar str[2][N];\n\n// 00,01,10,11\n//1110,1011,0111,1101\nint st[]={14,11,7,13};\nint getState(int x, int idx){\n return (st[x]&3) | (str[0][idx]<<1 | str[1][idx]);\n}\nbool can (int idx,int x, int prv){\n int cur = str[0][idx]<<1 | str[1][idx];\n int u = prv<<2 | cur;\n \n if(u&st[x])\n return false;\n return true;\n}\n\nint dp[N][4];\nint calc(int idx,int prv){\n if(idx==n)\n return 0;\n int &ret=dp[idx][prv];\n if(ret!=-1)\n return ret;\n ret = calc(idx+1,str[0][idx]<<1 | str[1][idx]);\n for(int i=0;i<4;++i)\n if(can(idx,i,prv))\n ret = max(calc(idx+1,getState(i,idx))+1, ret);\n return ret;\n}\n\nint main(){\n\n memset(dp,-1,sizeof dp);\n scanf(\"%s\",str[0]);\n scanf(\"%s\",str[1]);\n \n n = strlen(str[0]);\n \n for(int i=0;i\nusing namespace std;\n#define ll long long\nll dl=2e5+10;\nvectorvec(dl,0), v1,v2(2e5+10,0);\nvoid fun(ll a, ll b)\n{\n ll nom=0;\n while(a>1)\n {\n\n {\n if(a%v1[nom]==0)\n {\n a/=v1[nom];\n v2[v1[nom]]+=b;\n }\n else\n nom++;\n }\n if(vec[a]==0)\n {\n v2[a]+=b;\n return;\n }\n\n }\n}\nint main()\n{\n ll a, s, d, i, j;\n cin>>a;\n for(i=2;ia;i--)\n {\n fun(i,1);\n }\n for(i=1;i0){\n for(j=0;j\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\ntypedef long double ld;\n#define fi first\n#define se second\n#define pb push_back\n#define pbb pop_back\n#define make_pair mp\n#define all(x) x.begin(), x.end()\n#define uniq(x) x.erase(unique(x.begin(),x.end()),x.end())\n#define mem(array, value) memset(array, value, sizeof(array))\n#define gcd(a,b) __gcd(a,b)\n#define lcm(a,b) (a/__gcd(a,b))*b\n#define line cout << \"==========\" << endl\n#define mod 1000000007\n#define SIZE 1000001\n\nint rev(int n)\n{\n int r = 0;\n while (n){\n r = r*10+n%10;\n n/=10;\n }\n return r;\n}\n\nint main ()\n{\n int h, m;\n char ch;\n cin >> h >> ch >> m;\n if (h >= 0 && h <= 4){\n if (h*10 > m){\n cout << \"0\" << h << \":\" << h*10 << endl;\n }\n else {\n h++;\n cout << \"0\" << h << \":\" << h*10 << endl;\n }\n }\n else if (h == 5){\n if (h*10 > m){\n cout << \"0\" << h << \":\" << h*10 << endl;\n }\n else {\n cout << \"10:01\\n\";\n }\n }\n else if (h >= 6 && h <= 9){\n cout << \"10:01\\n\";\n }\n else if (h == 10){\n if(m == 0){\n cout << \"10:01\\n\";\n }\n else {\n h++;\n cout << h << \":\" << rev(h) << endl;\n }\n }\n else if (h>=11 && h <= 14){\n if (rev(h) > m){\n cout << h << \":\" << rev(h) << endl;\n }\n else {\n h++;\n cout << h << \":\" << rev(h) << endl;\n }\n }\n else if (h == 15){\n if (rev(h) > m){\n cout << h << \":\" << rev(h) << endl;\n }\n else {\n cout << \"20:02\\n\";\n }\n }\n else if (h >= 16 && h <= 19){\n cout << \"20:02\\n\";\n }\n else if (h == 20){\n if (m < 2){\n cout << \"20:02\\n\";\n }\n else {\n h++;\n cout << h << \":\" << rev(h) << endl;\n }\n }\n else if (h >= 21 && h <= 23){\n if (rev(h) > m){\n cout << h << \":\" << rev(h) << endl;\n }\n else {\n h++;\n if (h == 24){\n cout << \"00:00\\n\";\n }\n else {\n cout << h << \":\" << rev(h) << endl;\n }\n }\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "03e0a412611183e05997865c1c2d77ba", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#define ll long long\n#define fr first\n#define sc second\n#define mod 1000000007\n#define pii pair\n#define pdd pair\n#define mp make_pair\nusing namespace std;\n\nstruct pt{\n double x,y,z;\n void read(){\n cin>>x>>y>>z;\n }\n double dis(pt d){\n return (x - d.x)*(x - d.x) + (y - d.y)*(y - d.y) + (z - d.z)*(z - d.z);\n }\n};\nint a[6];\npt eyee;\npt s;\npt c[6];\n\n\nint main(){\n\n eyee.read();\n s.read();\n\n for(int i=0 ; i<6 ; i++)cin>>a[i];\n\n int res =0 ;\n\n if(eyee.y < 0)res += a[0];\n if(eyee.y > s.y)res += a[1];\n if(eyee.z < 0)res += a[2];\n if(eyee.z > s.z)res += a[3];\n if(eyee.x < 0)res += a[4];\n if(eyee.x > s.x)res += a[5];\n\n\n cout<\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair pii;\n\n#define pb push_back\n#define mp make_pair\n\nint n, T;\nint a[100];\nint cnt[301];\nconst int INF = 1000000000;\nint ans = 0;\n\nvector foo(int sz, int low, int high){\n vector d;\n for(int i = 0; i <= sz; i++) d.pb(INF);\n d[0] = -INF;\n for(int i = 0; i < sz; i++){\n int t = i % n;\n if(a[t] < low || a[t] > high) continue;\n int j = int(upper_bound(d.begin(), d.end(), a[t]) - d.begin());\n if(d[j - 1] <= a[t] && a[t] <= d[j])\n d[j] = a[t];\n }\n return d;\n}\n\nint main()\n{\n ios_base::sync_with_stdio(0);\n cin >> n >> T;\n for(int i = 0; i < n; i++) cin >> a[i];\n if(T <= 2 * n){\n vector tmp = foo(n * T, 0, 300);\n for(int i = 1; i < tmp.size(); i++){\n if(tmp[i] == INF){\n cout << i - 1 << endl;\n exit(0);\n }\n }\n cout << n * T << endl;\n exit(0);\n }\n for(int i = 0; i < n; i++) cnt[a[i]]++;\n for(int i = 1; i <= 300; i++){\n vector tmp1 = foo(n * n, 0, i);\n vector tmp2 = foo(n * n, i, 300);\n int len1 = n * n, len2 = n * n;\n for(int j = 1; j < tmp1.size(); j++){\n if(tmp1[j] == INF){\n len1 = j - 1;\n break;\n }\n }\n for(int j = 1; j < tmp2.size(); j++){\n if(tmp2[j] == INF){\n len2 = j - 1;\n break;\n }\n }\n ans = max(ans, len1 + (T - 2 * n) * cnt[i] + len2);\n }\n cout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "constructive algorithms"], "code_uid": "d4d9569d8d391e21f33286c3025f19b3", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n\nusing namespace std;\n\nint main()\n{\n// freopen(\"0.in\",\"r\",stdin);\n// freopen(\"0.out\",\"w\",stdout);\n\n int n,i,j,s,ix,k,ij;\n char a[20];\n char x;\n \n scanf(\"%s %d\",&a,&k);\n n=strlen(a); \n for(i=0;i0){ \n x=a[i+1];\n ix=i+1;\n for(j=i+2;jx){\n x=a[j];\n ix=j; \n }\n } else j=n;\n }\n if(x>a[i])\n for(ij=ix;ij>i;ij--){\n swap(a[ij-1],a[ij]);\n k--;\n }\n } else i=n;\n }\n \n printf(\"%s\\n\",a);\n return 0; \n}\n", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "0599a44117a02f9cf8d4eb15967a4245", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\nusing namespace std;\nstring a, b;\nint main() {\n\tcin >> a >> b;\n\tcout << (a == b ? a : \"1\");\n\treturn 0;\n} ", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "7418130af1fb9e9bbfcc950e9c502abe", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nint main(){\n int n;\n cin>>n;\n if(n==1){\n cout<<0;\n return 0;\n }\n if(n&1)\n cout<<(n/2+n)%(n+1)+1;\n else cout<<(n/2+n)%(n+1);\nreturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["constructive algorithms"], "code_uid": "7868bd98832e56a2c899569d547f3de2", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nint main() {\n\tlong n,k,x,a[200][2]={0},s=0;\n\tcin >> n >> k;\n\tfor (long i=0;i> x;\n\t\ta[i%k][x]++;\n\t}\n\tfor (long i=0;i\n#define ll long long\nusing namespace std;\nconst ll M = 998244353;ll m[5001][5001];\nmain()\n{\nfor(int i = 0;i < 5001;i++)m[0][i] = m[i][0] = 1;ll a,b,c; cin>>a>>b>>c;\nfor(int i=1;i<5001;i++)for(int j=1;j<5001;j++)m[i][j]=(j*m[i-1][j-1]%M+m[i-1][j]%M)%M;\ncout<\n\nusing namespace std;\n\ntypedef long long ll;\n\ninline ll read(){\n char ch=getchar();ll x=0,f=1;\n while(ch<'0' || ch>'9') {\n if(ch=='-') f=-1;\n \t ch=getchar();\n }\n while(ch<='9' && ch>='0') {\n x=x*10+ch-'0';\n ch=getchar();\n }\n return x*f;\n}\n\nll f[50][50];\n\nint main(){\n int n=read(),h=read();\n for(int i=0;i<=n;i++){\n f[i][0]=1;\n }\n for(int i=1;i<=n;i++){\n for(int j=1;j<=n;j++){\n for(int k=0;k\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define pb push_back\n#define mp make_pair\n#define f1 first\n#define f2 second\n#define X first\n#define Y second\n\nusing namespace std;\n\ntypedef long long LL;\ntypedef pair PII; \ntypedef vector VINT;\n\nconst int maxn = 1000 * 100 + 5;\nconst int mod = 1000 * 1000 * 1000 + 7;\n\nVINT adj[maxn], adjr[maxn];\nint mark[maxn], ans[maxn];\nint st[maxn];\n\nvoid dfs1(int x)\n{\n\tmark[x] = 1;\n\tans[x]++;\n//\tif (st[x] == 2)\n//\t\treturn;\n\tfor (int i = 0; i < (int)adj[x].size(); i++)\n\t{\n\t\tint u = adj[x][i];\n\t\tif (!mark[u])\n\t\t\tdfs1(u);\n\t}\n}\nvoid dfs2(int x)\n{\n\tmark[x] = 1;\n\tans[x]++;\n\tif (st[x] == 1)\n\t\treturn;\n\tfor (int i = 0; i < (int)adjr[x].size(); i++)\n\t{\n\t\tint u = adjr[x][i];\n\t\tif (!mark[u])\n\t\t\tdfs2(u);\n\t}\n}\n\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tint n, m;\n\tcin >> n >> m;\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> st[i];\n\tfor (int i = 0; i < m; i++)\n\t{\n\t\tint u, v;\n\t\tcin >> u >> v;\n\t\tu--; v--;\n\t\tadj[u].pb(v);\n\t\tadjr[v].pb(u);\n\t}\n\tfor (int i = 0; i < n; i++)\n\t\tif (!mark[i] && st[i] == 1)\n\t\t\tdfs1(i);\n\tfor (int i = 0; i < n; i++)\n\t\tmark[i] = 0;\n\tfor (int i = 0; i < n; i++)\n\t\tif (!mark[i] && st[i] == 2)\n\t\t\tdfs2(i);\n\tfor (int i = 0; i < n; i++)\n\t\tif (ans[i] == 2)\n\t\t\tcout << 1 << endl;\n\t\telse\n\t\t\tcout << 0 << endl;\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["graphs"], "code_uid": "bee4580572cdc7078eef8c4574797964", "src_uid": "87d869a0fd4a510c5e7e310886b86a57", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nconst int MAXN = 1500 + 100;\n\nvector edges[MAXN];\nint d[MAXN];\nbool mark[MAXN];\n\nint Ox, Oy;\n\nint VP(int x1, int y1, int x2, int y2) {\n\treturn (long long)x1 * (long long)y2 - (long long)x2 * (long long)y1 > 0LL ? 1 : -1;\n}\n\nstruct Point {\npublic:\n\tint x, y, id;\n\tPoint() {}\n\n\tPoint(int id, int x, int y) {\n\t\tthis->id = id;\n\t\tthis->x = x;\n\t\tthis->y = y;\n\t}\n\n\tbool operator < (const Point &P) const {\n\t\treturn VP(this->x - Ox, this->y - Oy, P.x - Ox, P.y - Oy) < 0;\n\t}\n};\n\nvector points;\nint ans[MAXN];\n\nvoid join(int u, Point p) {\n\tans[p.id] = u;\n}\n\nvoid solve(int u, vector< Point > points, Point P, bool b = false) {\n\tfor (int i = 0; i < points.size(); i++) {\n\t\tif (points[i].y < points[0].y || (points[i].y == points[0].y && points[i].x < points[0].x)) {\n\t\t\tswap(points[i], points[0]);\n\t\t}\n\t}\n\n\tmark[u] = true;\n\n\tint it = 0;\n\tjoin(u, points[it]);\n\tPoint T = points[it];\n\tpoints.erase(points.begin() + it);\n\n\tif (points.size() == 0) return;\n\n\tOx = T.x;\n\tOy = T.y;\n\tsort(points.begin(), points.end());\n\n\tint tot = 0;\n\tfor (int i = 0; i < edges[u].size(); i++) {\n\t\tint v = edges[u][i];\n\t\tif (mark[v]) continue;\n\t\tvector tmp;\n\t\tint t = 0;\n\t\tfor (int j = tot; j < points.size(); j++) {\n\t\t\ttmp.push_back(points[j]);\n\t\t\tt++;\n\t\t\tif (t == d[v]) break;\n\t\t}\n\t\ttot += t;\n\t\tsolve(v, tmp, T, true);\n\t}\n}\n\nvoid dfs(int u) {\n\tmark[u] = true;\n\td[u] = 1;\n\n\tfor (int i = 0; i < edges[u].size(); i++) {\n\t\tint v = edges[u][i];\n\t\tif (!mark[v]) {\n\t\t\tdfs(v);\n\t\t\td[u] += d[v];\n\t\t}\n\t}\n}\n\nint main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\n\tfor (int i = 0; i < n - 1; i++) {\n\t\tint a, b;\n\t\tscanf(\"%d%d\", &a, &b);\n\t\ta--;b--;\n\t\tedges[a].push_back(b);\n\t\tedges[b].push_back(a);\n\t}\n\n\tmemset(d, 0, sizeof(d));\n\tmemset(mark, false, sizeof(mark));\n\tdfs(0);\n\n\tfor (int i = 0; i < n; i++) {\n\t\tint x, y;\n\t\tscanf(\"%d%d\", &x, &y);\n\t\tpoints.push_back(Point(i, x, y));\n\t}\n\n\tmemset(mark, false, sizeof(mark));\n\tsolve(0, points, Point());\n\n\tfor (int i = 0; i < n; i++) printf(\"%d \", ans[i] + 1);\n\tprintf(\"\\n\");\n\n//\tsystem(\"pause\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "geometry", "constructive algorithms", "trees"], "code_uid": "d5988acb1b8fca2becbea86b7e779ca7", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "/**\n * Problem: No name\n * Judge: CodeForces\n * Date: current_date\n * URL: http://codeforces.com\n * Solved by: hopkins\n */\n\n/** Libr@ries **/\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n/** System_Win_32 **/\n#if ( WIN32 || __WIN32_ )\n#define lld I64d\n#endif\n/** System **/\n#define _ ios_base::sync_with_stdio(0);cin.tie(0);\n\n\n/** Utilities **/\n#define forit(i,v ) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)\n#define fori( i,a,b) for (int i = (int)(a); i < (int)(b); i++)\n#define forn( i, n ) fori( i, 0, n )\n#define zeros( a ) memset(a, 0,sizeof(a))\n#define null( a ) memset(a,-1,sizeof(a))\n#define all( a ) (a).begin() , (a).end()\n#define sqr( a ) ( (a)*(a) )\n#define sz( a ) (a).size()\n#define pb push_back\n#define mp make_pair\n#define F first\n#define S second\n#define PI 2*acos(0.0)\n#define oo 0x7FFFFFFF\nusing namespace std;\ntypedef long long LL;\n\n// const long long mod = (long long)(1e9) + 7LL;\nconst long long mod = 1000000007LL;\n\nlong long fmod(long long a, long long b){\n if (b == 0) {\n return 1LL;\n }\n if (b & 1LL) {\n return (a * fmod(a, b - 1LL)) % mod;\n } else {\n long long x = fmod(a, b >> 1LL);\n return (x * x) % mod;\n }\n return 0;\n}\n\nint main(int argc, char const *argv[])\n{\n long long x, k;\n cin >> x >> k;\n\n if (x == 0LL) {\n cout << \"0\\n\";\n return 0;\n }\n\n long long base = fmod(2LL, k);\n\n // long long sup = ((x % mod) * base) % mod;\n // long long inf = (((x-1LL + mod) % mod) * base) % mod;\n // long long sum = (sup + inf) % mod;\n // long long ans = (((sum + 1LL) >> 1LL) + 1LL) % mod;\n \n // cout << sup << \" \" << inf << endl;\n \n // cout << base << '\\n';\n x = x % mod;\n long long ans = ((base * (x + x - 1LL + mod)%mod) + 1LL) % mod;\n cout << ans << '\\n';\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "9e01089126d9b20f4acfc8dacb1d7113", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "//I_F_A\n#include \"bits/stdc++.h\"\nusing namespace std;\n\nvoid func(long long n){\n\t\n\tlong long f = n/12;\n\tlong long i = n%12;\n\t\n\tcout << f << \" \" << i << endl;\n}\n\nint main(){\n\t\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\t\n\tlong long n;\n\tcin >> n;\n\t\n\tif(n%3 == 2LL){\n\t\t\n\t\tn = n / 3 + 1;\n\t}\n\telse{\n\t\t\n\t\tn = n / 3;\n\t}\n\t\n\tfunc(n);\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "0a2b31943c7e87b7742bb54c0ce8ce83", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include\n#include\nint main()\n{\n long long int d1,d2,d3,a[4],min,i;\n while(~scanf(\"%lld %lld %lld\",&d1,&d2,&d3))\n {\n a[0]=2*(d1+d2);\n a[1]=2*(d1+d3);\n a[2]=2*(d2+d3);\n a[3]=d1+d2+d3;\n min=a[0];\n for(i=0;i<4;i++)\n {\n if(a[i]\nusing namespace std;\nint main()\n{\nint a[100],sum=0;\nfor(int i=0;i<5;i++)\n{\ncin>>a[i];\nsum+=a[i];\n}\nsort(a,a+5);\n\nint r = 1000;\nfor(int i=0;i<=4;i++)\n{\nif(a[i]==a[i+1])\n{\nif(i<3 && a[i]==a[i+2])\nr = min(r,sum-3*a[i]);\nelse\n{r = min(r,sum-2*a[i]);}\n}\n}\nr=min(r,sum);\ncout<\n//#include \n//#include\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n\n//using namespace __gnu_pbds;\nusing namespace std;\n\n\n/*** Optimization ***/\n#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#pragma GCC optimize(\"unroll-loops\")\n\n\n/*** Typedef ***/\ntypedef long long ll;\ntypedef unsigned long long ull;\n\n\n/*** Input ***/\n#define sci1(a) scanf(\"%d\",&a)\n#define sci2(a,b) scanf(\"%d %d\",&a,&b)\n#define scln1(a) scanf(\"%lld\",&a)\n#define scln2(a,b) scanf(\"%lld %lld\",&a,&b)\n#define scln3(a,b,c) scanf(\"%lld %lld %lld\",&a,&b,&c)\n\n\n/*** Output ***/\n#define pf1(a) printf(\"%d\\n\",a)\n#define pf2(a,b) printf(\"%d %d\\n\",a,b)\n#define pfln1(a) printf(\"%lld\\n\",a)\n#define pfln2(a,b) printf(\"%lld %lld\\n\",a,b)\n\n\n/*** Loops ***/\n#define foR0(num) for(ll i = 0; i < num; i++)\n#define foR1(num) for(ll i = 1; i <= num; i++)\n#define foRev(num) for(ll i = num - 1; i >= 0; i--)\n#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];\n#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];\n#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\\n');\n#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\\n');\n\n\n/*** Define Values ***/\n\n#define ff first\n#define ss second\n#define re return\n#define MP make_pair\n#define pb push_back\n#define SZ(x) ((int) (x).size())\n\n\n#define EPS 10E-10\n#define mxx 100005\n#define MOD 1000000007\n#define iseq(a,b) (fabs(a-b) vll;\ntypedef set sll;\ntypedef multiset msll;\ntypedef queue qll;\ntypedef stack stll;\ntypedef map mll;\ntypedef pair pll;\ntypedef vector > vpll;\n\n\n/*** BitWise Operations\n///int Set(int N,int pos){return N=N | (1<, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}\n///string tostring(ll x){string s=\"\";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}\n///bool sortinrev(const pair &a,const pair &b)return (a.first > b.first);\n///priority_queue< pll ,vector,greater >p;\n///cout<<*X.find_by_order(0)<>tst;\n for(ll tt=1;tt<=tst;tt++)\n {\n //code\n ll n,m;\n cin>>n>>m;\n fact(m);\n ll res=(fac[n]*n)%m;\n for(ll i=1;i\n#define op cin.tie(0);ios_base::sync_with_stdio(0);\nusing namespace std;\nint n;\n\nbool lucky(int x)\n{\n while(x)\n {\n if(x%10!= 4 && x%10!=7)\n return false;\n\n x/=10;\n\n }\n return true;\n}\n\nint main()\n{\n op\n\n cin>>n;\n for(int i=1;i<=n;i++)\n {\n if(n%i==0)\n {\n if(lucky(i))\n {\n cout<<\"YES\";\n return 0;\n }\n\n }\n }\n\n\n cout<<\"NO\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "number theory"], "code_uid": "4c9f22a49699a8a896a50ca27aab74e4", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n\nusing namespace std;\n\nint main() {\n long long n;\n cin >> n;\n cout << ((n % 2 == 0) ? (long long)pow(2, n / 2) : 0);\n}", "lang_cluster": "C++", "tags": ["math", "dp"], "code_uid": "aa238109652ab3634725f6b455b4f6bf", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#pragma GCC optimize(3)\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC optimize(\"inline\")\n#pragma GCC optimize(\"-fgcse\")\n#pragma GCC optimize(\"-fgcse-lm\")\n\n#include \n#define pb push_back\n#define int long long\nusing namespace std;\n\ninline int read()\n{\n\tint sum=0,ff=1; char ch=getchar();\n\twhile(!isdigit(ch))\n\t{\n\t\tif(ch=='-') ff=-1;\n\t\tch=getchar();\n\t}\n\twhile(isdigit(ch))\n\t\tsum=sum*10+(ch^48),ch=getchar();\n\treturn sum*ff;\n}\n\nconst int N=255;\nconst int mo=1e9+7;\n\nint n,m,f[N][N],jc[N],inv[N],I[N],II[N],ans;\n\ninline int ksm(int x,int y)\n{\n\tint ret=1ll;\n\twhile(y)\n\t{\n\t\tif(y&1) ret=ret*x%mo;\n\t\tx=x*x%mo;\n\t\ty>>=1ll;\n\t}\n\treturn ret;\n}\n\ninline int C(int x,int y)\n{\n\treturn jc[x]%mo*inv[y]%mo*inv[x-y]%mo;\n}\n\nsigned main()\n{\n\tn=read();\n\tm=read();\n\tjc[0]=inv[0]=1;\n\tfor ( int i=1;i<=n;i++ ) jc[i]=jc[i-1]*i%mo;\n\tfor ( int i=1;i<=n;i++ ) inv[i]=ksm(jc[i],mo-2)%mo;\n\tf[0][n]=1;\n\tI[0]=1;\n\tfor ( int i=1;i<=n;i++ ) I[i]=I[i-1]*m%mo;\n\tII[0]=1;\n\tfor ( int i=1;i<=n;i++ ) II[i]=II[i-1]*(m-1)%mo;\n\tfor ( register int i=1;i<=n;i++ ) \n\t\tfor ( register int j=0;j<=n;j++ )\n\t\t{\n\t\t\tf[i][j]=(f[i][j]+f[i-1][j]*II[j]%mo*(I[n-j]%mo-II[n-j]%mo)%mo)%mo;\n\t\t\tfor ( register int k=1;k<=n-j;k++ ) \n\t\t\t\tf[i][j]=(f[i][j]+f[i-1][k+j]*C(k+j,k)%mo*I[n-j-k]%mo*II[j]%mo)%mo;\n\t\t}\n\tprintf(\"%lld\\n\",(f[n][0]+mo)%mo);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "3c338107c1d648a066021ff085148b16", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nint n,ans,l[10][10],r[10][10],f[10],c[10][10];\n// Last Change: 2011-03-29 11:15:29\nvoid dfs(int s,int t,int fl,int cost){\n if(s==n){\n if(ansn){\n if(fl==0)dfs(s+1,s+2,f[s+1],cost);\n }\n else\n for(int i=l[s][t];i<=r[s][t]&&i<=fl;++i){\n f[t]+=i;\n dfs(s,t+1,fl-i,cost+i*i+(i?c[s][t]:0));\n f[t]-=i;\n }\n}\nint main(){\n scanf(\"%d\",&n);\n for(int i=1;i<=n*(n-1)/2;++i){\n int a,b,p,q,co;\n scanf(\"%d%d%d%d%d\",&a,&b,&p,&q,&co);\n l[a][b]=p,r[a][b]=q,c[a][b]=co;\n }\n for(int i=0;i<=25;++i){\n ans=-1;\n dfs(1,2,i,0);\n if(ans>=0){\n printf(\"%d %d\\n\",i,ans);\n return 0;\n }\n }\n puts(\"-1 -1\");\n return 0;\n}\n\n ", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "31232c34a601906e6fcbd85e1e15fe44", "src_uid": "38886ad7b0d83e66b77348be34828426", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair < ll, ll > pll;\n\nll m;\npll res;\n\ninline ll pow3(ll x) {\n return x * x * x;\n}\n\nvoid solve(ll m, ll step, ll subs) {\n if(m == 0) {\n res = max(res, make_pair(step, subs));\n } else {\n ll x = 1;\n while(pow3(x + 1) <= m)\n x++;\n solve(m - pow3(x), step + 1, subs + pow3(x));\n\n if(x >= 1)\n solve(pow3(x) - pow3(x - 1) - 1, step + 1, subs + pow3(x - 1));\n }\n}\n\nint main()\n{\n ios::sync_with_stdio(false);\n\n cin >> m;\n solve(m, 0, 0);\n\n cout << res.first << ' ' << res.second << '\\n';\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "greedy", "constructive algorithms", "binary search"], "code_uid": "8bd95e525271fb975c32fa659ce6ee0f", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#define ll long long\nusing namespace std;\nconst int mod = 1e9 + 7;\nint dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };\nint dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };\nvoid file()\n{\n\t//#ifndef ONLINE_JUDGE\n\t\t// freopen(\"output.txt\", \"w\", stdout);\n\t//#endif !ONLINEJUDGE\n\tios::sync_with_stdio(0);\n\tcin.tie(0);\n\tcout.tie(0);\n}\nint main() {\n\tfile();\n\tll a, b;\n\tcin >> a >> b;\n\tint cnt = 0;\n\tfor (int i = 0; (1LL << i)>>1 <= b; i++) {\n\t\tfor (int j = 0; j < i-1; j++) {\n\t\t\tlong long x = (1LL << i) - 1;\n\t\t\tlong long y = (1LL <= a && x <= b;\n\t\t}\n\t}\n\tcout << cnt;\n\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "44b8d06470688437d451a5b066aee181", "src_uid": "581f61b1f50313bf4c75833cefd4d022", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n\nusing namespace std;\n#define pb push_back\n#define ll long long\n\nconst int maxN =2001;\nconst ll mod = 1e9+7;\nll res=0;\nll dp[maxN][maxN];\nvector num[maxN];\n\nint main()\n{\n for(int i=1;i>n>>k;\n for(int i=1;i<=n;i++) res=(res+dp[k][i])%mod;\n cout<\nusing namespace std;\nint main()\n{\n\tstring s;\n\tint jishu=1,ge=0;\n\tgetline(cin,s);\n\tfor(int i=0;i<=s.size();i++)\n\t{\n\t\tfor(int j=i+1;j<=s.size();j++)\n\t\t{\n\t\t\tif(s[j]==s[i])\n\t\t\tjishu+=1;\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(jishu%2==0)\n\t\t\t\tge+=1;\n\t\t\t\ti=j;\n\t\t\t\tjishu=1;\n\t\t\t}\n\t\t}\n\t}\n\tcout<\nusing namespace std;\nint main() {\n#ifndef ONLINE_JUDGE\n freopen(\"in.in\", \"r\", stdin);\n freopen(\"out.out\", \"w\", stdout);\n#endif\n int a,b;\n int cnt=0;\n cin>>a>>b;\n \twhile(1){\n \t\tif(a>=b){\n \t\t\ta-=2;\n \t\t\tb+=1;\n \t\t}\n \t\telse {\n \t\t\ta+=1;\n \t\t\tb-=2;\n \t\t}\n \t\tif(a<=0 or b<=0){\n \t\tif(a>=0 and b>=0) cnt++;\n \n \t\tbreak;\n \t}\n \tcnt++;\n \t}\n cout<\ntypedef long long ll;\nint main(){ll n,c=0;scanf(\"%lld\",&n);\n for(ll i=1;i<816497;++i)if( (((n-((i-1)*1ll*(i)+((i-1)*(i-2))/2))-2)%3==0)&&(((i*1ll*(i+1))+(i*1ll*(i-1))/2)<=n))c++;\n return printf(\"%lld\\n\",c),0;}\n\n\n\n", "lang_cluster": "C++", "tags": ["math", "greedy", "binary search", "brute force"], "code_uid": "bf533e082230b7beab4ac08ace587ec6", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \nusing namespace std;\n\nint n,m,a;\n\nint main()\n{\n int kmin, kmax;\n\n scanf(\"%d\",&n);\n scanf(\"%d\",&m);\n\n int cnt = 0,mx=0;\n\n for (int i=0; i mx) mx = a;\n }\n\n kmin = ceil((float)(cnt+m)/n);\n if(kmin<=mx) kmin = mx;\n kmax = m + mx;\n\n cout << kmin << \" \" << kmax << endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation", "binary search"], "code_uid": "3b3c98933ac76189568606b735832430", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Clang++17 Diagnostics", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tint n,m,c,min=INT_MAX;\n\tcin>>n>>m;\n\tint f[m];\n\tfor(int i=0;i>f[i];\n\tsort(f,f+m);\n\t\tfor(int i=0;i<=m-n;i++)\n\t{\tc=f[n-1+i]-f[i];\n\t\tif(c\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define forr(i,a,b) for(ll i = ll(a); i < ll(b); ++i)\n#define forn(i,n) forr(i,0,n)\n#define rforr(i,a,b) for(ll i = ll(a); i > ll(b); --i)\n#define rforn(i,n) rforr(i,n,0)\n\ntypedef unsigned long long ull;\ntypedef long long ll;\n\nusing namespace std;\n\nconst ll INF = (1<<30);\n\nunordered_map M;\n\nll logdiez(ll n){\n\tll res = 0;\n\tfor(;n>0;n/=10)\n\t\tres++;\n\treturn res - 1;\n}\n\nll potdiez(ll e){\n\tll res = 1;\n\tfor(;e>0;e--)\n\t\tres*=10;\n\treturn res;\n}\n\nbool valid(ll n, int dig){\n\tll cant = logdiez(n) + 1;\n\tif(dig != cant or cant < 2)\n\t\treturn true;\n\t\n\tll segdig = (n%potdiez(cant-1) - n%potdiez(cant-2)) / potdiez(cant-2);\n\treturn segdig != 0;\n}\n\nll f(ll n){\n\t\n\tif(M.count(n))\n\t\treturn M[n];\n\t\n\tif(n <= 0)\n\t\treturn INF;\n\t\n\tdouble sq = sqrt(n);\n\tforr(i, sq-1, sq+2){\n\t\tif(i*i == n)\n\t\t\treturn M[n] = 0;\n\t}\n\t\n\tll mejor = INF;\n\tfor(int i = 1; i <= logdiez(n) + 1; i++){\n\t\tif(valid(n, i)){\n\t\t\tll nuevo = (n/potdiez(i)) * potdiez(i-1) + n%potdiez(i-1);\n\t\t\tmejor = min(mejor, 1 + f(nuevo));\n\t\t}\n\t}\n\t\n\tif(mejor < INF)\n\t\treturn M[n] = mejor;\n\t\n\treturn M[n] = INF;\n}\n\nint main(){\n\t//~ freopen(\"input.in\", \"r\", stdin);\n\tll N;\n\tscanf(\"%I64d\", &N);\n\t\n\tif(f(N) < INF)\n\t\tprintf(\"%I64d\\n\", f(N));\n\telse\n\t\tprintf(\"-1\\n\");\n\t\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation"], "code_uid": "9229bbdd2b363a9f871fa1c4004a1a52", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \nusing namespace std;\nint main(){\nlong long r,x,y,x1,y1;\ncin >>r>>x>>y>>x1>>y1;\nlong double s=0,n=sqrt(pow(x1-x,2)+pow(y1-y,2));\n\n\nwhile(n>=2*r){\n n=n-2*r;\n s++;\n}\nif(n!=0){\n s++;\n}\n\n\ncout <\n#include \nusing namespace std;\n\nint a, ta;\nint b, tb;\nint h, m;\ninline int max(int a, int b)\n{\n\treturn a < b ? b : a;\n}\ninline int min(int a, int b)\n{\n\treturn a < b ? a : b;\n}\n\nbool read() {\n\tif (!(cin >> a >> ta)) return false;\n\tcin >> b >> tb;\n\tchar c;\n\tcin>>h>>c>>m;\n\treturn true;\n}\n\nint main() {\n\tread();\n\tint x1 = h * 60 + m;\n\tint y1 = x1 + ta;\n\n\tint ans = 0;\n\tfor (int x2 = 5 * 60 + 0; x2 < 24 * 60; x2 += b) {\n\t\tint y2 = x2 + tb;\n\t\tint x = max(x1, x2), y = min(y1, y2);\n\t\tif (x < y)\n\t\t\tans++;\n\t}\n\tcout << ans << endl;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "0b45ed08b55f3b0f280817377111cb0a", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\nint n, sx[10], id[10], sy[10], fx[10], fy[10], SX[10], SY[10], FX[10], FY[10];\n\nint main() {\n for (int i = 1; i <= 4; i ++) {\n\t\tscanf(\"%d %d %d %d\", &SX[i], &SY[i], &FX[i], &FY[i]);\n id[i] = i;\n }\n bool flag = 0;\n do {\n for (int i = 1; i <= 4; i ++) {\n sx[i-1] = SX[id[i]];\n fx[i-1] = FX[id[i]];\n sy[i-1] = SY[id[i]];\n fy[i-1] = FY[id[i]];\n }\n for (int i = 0; i < 2; i ++) {\n\t\t\tswap(sx[0], fx[0]); swap(sy[0], fy[0]);\n for (int j = 0; j < 2; j ++) {\n\t\t\t\tswap(sx[1], fx[1]); swap(sy[1], fy[1]);\n for (int k = 0; k < 2; k ++) {\n\t\t\t\t\tswap(sx[2], fx[2]); swap(sy[2], fy[2]);\n for (int l = 0; l < 2; l ++) {\n\t\t\t\t\t\tswap(sx[3], fx[3]); swap(sy[3], fy[3]);\n if (sy[0] != fy[0]) continue;\n if (sx[1] != fx[1]) continue;\n if (sy[2] != fy[2]) continue;\n if (sx[3] != fx[3]) continue;\n if (fy[0] != sy[1] || fx[0] != sx[1]) continue;\n if (fy[1] != sy[2] || fx[1] != sx[2]) continue;\n if (fy[2] != sy[3] || fx[2] != sx[3]) continue;\n if (fy[3] != sy[0] || fx[3] != sx[0]) continue;\n if (sy[0] == sy[2]) continue;\n if (sx[0] == sx[2]) continue;\n flag = 1;\n goto lp;\n }\n }\n }\n }\n } while (next_permutation(id+1, id+5));\n lp:\n\tif (flag) puts(\"YES\");\n\telse puts(\"NO\");\n\treturn 0;\n}\n\n ", "lang_cluster": "C++", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "f149d8d76da2f6c77345920df1f528d8", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n \nusing namespace std;\n\n#define _ ios_base::sync_with_stdio(0);cin.tie(0);\n#define endl '\\n'\n#define f first\n#define s second\n#define pb push_back\n\ntypedef long long ll;\ntypedef pair ii;\n\nconst int INF = 0x3f3f3f3f;\nconst ll LINF = 0x3f3f3f3f3f3f3f3fll;\n\nll n, m;\n\nint main() {\n cin >> n >> m;\n if (n <= m) cout << n;\n else {\n long long l = 1, r = 2000000000;\n \twhile (l <= r) {\n \t\tlong long mid = (l + r) / 2;\n \tif (mid * (mid - 1) / 2 + mid + m < n) l = mid+1;\n \telse r = mid-1;\n \t}\n \tcout << l+m << endl;\n\t}\n \n return 0;\n}\n \n", "lang_cluster": "C++", "tags": ["math", "binary search"], "code_uid": "8a71ee4e81e014776bc0f47c825ed283", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#if defined(LOCAL)\nconst double _max_double_error = 1e-9;\n#include \"testutils.h\"\n#define L(x...) (debug(x, #x))\n#define I(x, ...) (x)\n#define C(x...) CHECK(x)\n#else\n#define L(x, ...) (x)\n#define I(x, ...) (x)\n#define C(x, ...) ;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\nusing vi = vector;\nusing vvi = vector;\nusing vvvi = vector;\nusing ii = pair;\nusing lu = unsigned long long;\nusing l = long long;\nusing vs = vector;\nusing vii = vector;\nusing vl = vector;\nusing vvl = vector;\nusing vvvl = vector;\nusing ll = pair;\nusing vll = vector;\nusing vvll = vector;\nusing vb = vector;\nusing vvb = vector;\nusing vd = vector;\nusing vvd = vector;\nusing mll = unordered_map;\nusing sl = unordered_set;\nconst l INF = numeric_limits::max();\nconst double EPS = 1e-10;\nconst double PI = 3.14159265358979323846;\nconst l e0 = 1, e3 = 1000, e5 = 100000, e6 = 10 * e5, e7 = 10 * e6,\n e8 = 10 * e7, e9 = 10 * e8;\nconst char lf = '\\n';\n#define all(x) begin(x), end(x)\n#define F(a, b, c) for (l a = l(b); a < l(c); a++)\n#define B(a, b, c) for (l a = l(c) - 1; a >= l(b); a--)\n#define VVL(x, a, b, i) vvl x(a, vl(b, l(i)));\n#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));\n\nvoid solve(istream& in, ostream& out);\nint main(int argc, char** argv) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout << fixed << setprecision(15);\n#if defined(LOCAL)\n tst::test_init(argc, argv);\n // _generate_random_test = generate_random;\n // _solve_brute = solve_brute;\n // _player_b = player_b;\n // _custom_solution_checker = solution_checker;\n tst::maybe_run_tests(cin, cout);\n#else\n solve(cin, cout);\n#endif\n}\nconst l MOD = e9 + 7; // end of template\n\nl gcd(l a, l b) {\n while (b) {\n a %= b;\n swap(a, b);\n }\n return a;\n}\n\nl lcm(l a, l b) { return a / (gcd(a, b)) * b; }\n\nl sign(l n) {\n if (n < 0) return -1;\n if (n == 0) return 0;\n return 1;\n}\n\n// conruent modulo, works for negative\nl cong(l x, l mod) { return (x % mod + mod) % mod; }\n\n// (a * b) % mod, safe for l near max\nl mult_mod(l a, l b, l mod) {\n l x = 0;\n while (b) {\n if (b % 2) x = (x + a) % mod;\n a = (a * 2) % mod;\n b /= 2;\n }\n return x;\n}\n\n// (base^power) % mod, safe for l near max\nl pow_mod(l base, l power, l mod) {\n l r = 1;\n while (power) {\n if (power % 2) r = mult_mod(r, base, mod);\n base = mult_mod(base, base, mod);\n power /= 2;\n }\n return r;\n}\n\nl divup(l a, l b) { // ceil div\n return (a + b - 1) / b;\n}\n\n// return gcd(a, b) and set x, y: a * x + b * y = gcd(a, b)\nl extended_euclid(l a, l b, l& x, l& y) {\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n l d = extended_euclid(b, a % b, x, y);\n l t = y;\n y = x - (a / b) * y;\n x = t;\n return d;\n}\n\n// return b: a * b = 1 (mod n)\nl inverse_mod(l a, l n) {\n l x, y;\n l d = extended_euclid(a, n, x, y);\n if (d != 1) return 0;\n return cong(x, n);\n}\n\n// single combintions k from n\nl nCr(l n, l k, l mod) {\n l a = 1;\n for (l i = n; i > n - k; i--) a = mult_mod(a, i, mod);\n l b = 1;\n F(i, 1, k + 1) b = mult_mod(b, i, mod);\n b = inverse_mod(b, mod);\n return mult_mod(a, b, mod);\n}\n\n// precompute all combinations up to (n n)\nvvl combinations(l n, l mod) {\n vvl c(n + 1, vl(n + 1));\n F(i, 0, n + 1) {\n c[i][0] = 1;\n F(j, 1, i + 1) { c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; }\n }\n return c;\n}\n\n// l on the ring of MOD\nstruct lm {\n l raw;\n lm() : raw(0) {}\n lm(l x) : raw(x) {}\n lm(lm const& x) : raw(x.raw) {}\n lm(lm&& x) { swap(*this, x); }\n friend void swap(lm& a, lm& b) { swap(a.raw, b.raw); }\n lm& operator=(l x) {\n raw = x;\n return *this;\n }\n lm& operator=(lm x) {\n swap(*this, x);\n return *this;\n }\n void operator+=(const lm x) { raw = cong(raw + x.raw, MOD); }\n lm operator+(const lm x) {\n lm z(*this);\n z += x;\n return z;\n }\n void operator-=(const lm x) { raw = cong(raw - x.raw, MOD); }\n lm operator-(const lm x) {\n lm z(*this);\n z -= x;\n return z;\n }\n void operator*=(const lm x) { raw = cong(raw * x.raw, MOD); }\n lm operator*(const lm x) {\n lm z(*this);\n z *= x;\n return z;\n }\n void operator/=(const lm x) {\n raw = cong(raw * inverse_mod(x.raw, MOD), MOD);\n }\n void operator++() { raw = cong(raw + 1, MOD); }\n void operator--() { raw = cong(raw - 1, MOD); }\n lm operator/(const lm x) {\n lm z(*this);\n z /= x;\n return z;\n }\n lm pow(l exp) const {\n lm r(1);\n lm base(*this);\n while (exp) {\n if (exp % 2) r *= base;\n base *= base;\n exp /= 2;\n }\n return r;\n }\n};\nusing vlm = vector;\nostream& operator<<(ostream& s, const lm& p) { return s << p.raw; }\n\nconst l MAX_PRIME = 32776;\nvoid sieve_primes(vl& primes) {\n vb b(MAX_PRIME);\n for (l i = 2; i < MAX_PRIME; i++) {\n if (b[i]) continue;\n primes.emplace_back(i);\n for (l j = i; j < MAX_PRIME; j += i) b[i] = true;\n }\n}\n\nbool is_prime(l n, vl const& primes) {\n auto p = primes.begin();\n while (p != primes.end() and ((*p) * (*p)) <= n) {\n if (n % *p == 0) return n == *p;\n p++;\n }\n return true;\n}\n\n// in asc order\nvl factorize_to_primes(l n, vl& primes) {\n vl result;\n F(p, 2, n) {\n while (n % p == 0) {\n result.emplace_back(p);\n n /= p;\n }\n if (n < p*p) break;\n }\n if (n != 1) result.emplace_back(n);\n sort(all(result));\n return result;\n}\n\nlm f(l n, l x, l m) {\n n++;\n lm y = n;\n vlm v(n);\n v[0] = 1;\n F(i, 0, m) {\n F(j, 0, n-1) {\n lm a = v[j];\n v[j] = a / (y - j);\n v[j + 1] += a * I(y - j - 1, y - j) / (y - j);\n }\n }\n lm z = 0;\n lm t = 1;\n B(i, 0, n) {\n z += v[i] * t;\n t *= x;\n }\n return z;\n}\n\nvoid solve(istream& in, ostream& out) {\n l n, m;\n in >> n >> m;\n vl primes;\n sieve_primes(primes);\n auto ff = factorize_to_primes(n, primes);\n l prev = 0, c = 0;\n lm z = 1;\n for (auto x : ff) {\n if (prev != x) {\n if (c) { z *= f(c, prev, m); }\n prev = x;\n c = 0;\n }\n c++;\n }\n if (c) { z *= f(c, prev, m); }\n out << z << lf;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "e3139f8ac6211937eda19f06eacf0eea", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nconst int INF = 1e9;\nconst long long mod = 1e9 + 7;\n\n\nint main()\n{\n int n; cin>>n;\n vector D(n+1), A(n+1);\n\n D[0]=1;\n for (int i=1; i<=n; ++i)\n {\n A[i] = ( 2*A[i-1] + D[i-1] ) % mod;\n D[i] = ( 3*A[i-1] ) % mod;\n }\n\n cout<\n#include\n#include\n#include\nusing namespace std;\nconst int mod=1073741824;\n//const int MAXn=1000005;\nconst int MAXn=1000005;\nint prime[6600];//\u5b58\u653e\u6240\u6709\u7684\u7d20\u6570\uff0cprime[i]\u8868\u793a\u7b2ci\u4e2a\u7d20\u6570.\nint ans[MAXn];//\u5b58\u653ei\u7684\u56e0\u5b50\u4e2a\u6570\uff0cans[i]\u8868\u793a\u6574\u6570i\u7684\u56e0\u5b50\u4e2a\u6570.\nint n;\n//\u5224\u65adn\u662f\u5426\u662f\u8d28\u6570\nbool isprime(int n)\n{\n int i;\n if(n<=1) return false;\n if(n==2) return true;\n if(n%2==0) return false;\n for(i=3;i*i<=n;i+=2)\n if(n%i==0) return false;\n return true;\n}\n//\u8ba1\u7b97n\u7684\u56e0\u5b50\u4e2a\u6570\nint count(int n)//(31ms)\n{\n if(ans[n]!=-1) \n return ans[n];\n int a=n,i=0,sum=1;/////\n while(a!=1)\n {\n int cnt=0;\n while(a%prime[i]==0)\n {\n cnt++;\n a/=prime[i];\n }\n if(cnt) \n sum*=(1+cnt);\n i++;\n } //////\n ans[n]=sum;\n return ans[n];\n}\nint main()\n{\n \n int i,j,k,sum,p;\n int a,b,c;\n p=0;\n for(i=1;i<(1<<16);i++)\n if(isprime(i))\n prime[p++]=i;\n memset(ans,-1,sizeof(ans)); \n while(cin>>a>>b>>c)\n {\n sum=0;\n for(i=1;i<=a;i++)\n for(j=1;j<=b;j++)\n for(k=1;k<=c;k++)\n {\n sum+=count(i*j*k),sum=sum%mod;\n }\n printf(\"%d\\n\",sum);\n } \n return 0;\n}\n\n\n\n\n/* 250ms\n//\u8ba1\u7b97n\u7684\u56e0\u5b50\u4e2a\u6570\nint count(int n)\n{\n if(ans[n]!=-1) \n return ans[n];\n int cnt,i=0,sum=1;\n while(n!=1)\n {\n cnt=0;\n while(n%prime[i]==0)\n {\n cnt++;\n n/=prime[i];\n }\n if(cnt)\n sum*=(1+cnt);\n i++; \n }\n ans[n]=sum;\n return ans[n];\n}\n*/", "lang_cluster": "C++", "tags": ["implementation", "number theory"], "code_uid": "d26f3227d7f01ebce59ff18d6e1f6277", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n\n\n#include \n#include \n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#include \n#include \n\n#include \n#include \n\n#define MAX(a, b) (((a) > (b)) ? (a) : (b))\n#define ABS(x) (((x) < 0) ? (-(x)) : (x))\n\n\nusing namespace std;\n\n\n\nint main()\n{\n\tint n;\n\tstring s;\n\tcin >> n >> s;\n\n\tint max = 0;\n\tint numb = 0;\n\tint cur = 0;\n\tbool scb = false;\n\n\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tif (s[i] == '(')\n\t\t{\n\t\t\tmax = MAX(max, cur);\n\t\t\tcur = 0;\n\t\t\tscb = true;\n\t\t}\n\n\t\tif (s[i] == ')')\n\t\t{\n\t\t\tif (cur != 0)\n\t\t\t\tnumb++;\n\t\t\tcur = 0;\n\t\t\tscb = false;\n\t\t}\n\n\t\tif (s[i] == '_')\n\t\t{\n\t\t\tif (scb == false)\n\t\t\t\tmax = MAX(max, cur);\n\n\t\t\tif (scb == true && cur > 0)\n\t\t\t\tnumb++;\n\n\t\t\tcur = 0;\n\t\t}\n\t\t\n\t\tif (s[i] >= 'A' && s[i] <= 'Z' || s[i] >= 'a' && s[i] <= 'z')\n\t\t\tcur++;\n\t}\n\n\tif (cur > 0)\n\t\tmax = MAX(max, cur);\n\n\tcout << max << ' ' << numb;\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "8cddaacbc980dc9544715a935fd48e56", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define ll long long\n#define MOD ((ll)1e9+7)\nusing namespace std;\nll dp[2020][2020];\nint main()\n{\n int n,m,k;\n cin>>n>>m>>k;\n for(int i=0;i\n#define L long long\n\nusing namespace std;\n\nL c(L n,L r)\n{\n L i;\n L s=1,s1=1;\n for(i=n;i>r;i--)\n {\n s*=i; \n s/=(n-i+1);\n } \n //cout<>n>>m>>t;\n /*a=c(n,4);\n b=c(m,1);\n ans=a*b;\n if(t>5)\n {\n t1=t-5;\n //ans=c(n+m-5,t1);\n }*/\n ans=0;\n for(i=1;i<=(t-4);i++)\n {\n if(i<=m&&(t-i)<=n)\n ans+=(c(n,t-i)*c(m,i));\n } \n cout<\nusing namespace std;\n#define ll long long\n#define f(i, x, n) for (int i = x; i < (int)(n); ++i)\n\nint const N = 2020, md = 998244353;\nint dp[N + 1][N + 1], n, k, an;\n\nvoid ad(int &x, int y) { if ((x += y) >= md)x -= md; }\n\nint sq(int x) { return x * (x + 1) >> 1; }\n\nint gtsm(vector const &v){\n\tint sm = 0;\n\tf(i, 1, v.size() + 1)sm += i * v[v.size() - i];\n\treturn sm;\n}\n\nvoid pr(vector const &v){\n\tfor (int t: v)printf(\"%d \", t);\n\tprintf(\"\\n\");\n}\n\nvector v, v1, v2;\nbool ok(){\n\tv1 = v;\n\tf(i, 2, k){\n\t\tif (gtsm(v1) > n)return false;\n\t\tv2.clear();\n\t\tf(i, 1, v1.size() + 1)f(j, 0, v1[v1.size() - i])v2.push_back(i);\n\t\tswap(v1, v2);\n\t}\n\treturn gtsm(v1) <= n;\n}\n\nvoid go(int sm = 0, int lst = 1){\n\tif (!ok())return;\n\tif (sm)++an;\n\tf(i, lst, 63 - sm + 1){\n\t\tv.push_back(i);\n\t\tgo(sm + i, i);\n\t\tv.pop_back();\n\t}\n}\n\nint main(){\n\tscanf(\"%d%d\", &n, &k);\n\tif (k == 1){\n\t\tdp[0][0] = 1;\n\t\tf(i, 0, N + 1)f(j, 1, N + 1){\n\t\t\tad(dp[i][j], dp[i][j - 1]);\n\t\t\tif (i + j <= N)ad(dp[i + j][j], dp[i][j]);\n\t\t}\n\t\tf(i, 1, n + 1)ad(an, dp[i][n]);\n\t}\n\telse if (k == 2){\n\t\tdp[0][0] = 1;\n\t\tf(i, 0, n + 1)f(j, 0, n + 1){\n\t\t\tint t = sq(i);\n\t\t\tif (i && j + t <= n)ad(dp[i][j + t], dp[i][j]);\n\t\t\tif (j + i + 1 <= n)ad(dp[i + 1][j + i + 1], dp[i][j]);\n\t\t}\n\t\tf(i, 1, n + 1)f(j, 1, n + 1)ad(an, dp[i][j]);\n\t}else go();\n\tprintf(\"%d\\n\", an);\n}", "lang_cluster": "C++", "tags": ["brute force", "dp"], "code_uid": "2265021cf3ae483e902a908fd4c023f2", "src_uid": "c435a0cd437081cd3593637be4568c6a", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#define FWD(a,b,c) for(int a=(b); a<(c); ++a)\n#define BCK(a,b,c) for(int a=(b); a>(c); --a)\n#define x first\n#define y second\n\nusing namespace std;\n\ntypedef pair PII;\ntypedef long long LL;\n\nconst int MAXN = 100010;\nconst int MAXV = 2000010;\n\nint n;\n\nint main(){\n\tscanf(\"%d\", &n);\n\tbool f = 1;\n\twhile(n || f){\n\t\tf = 0;\n\t\tint d = n%10;\n\t\tn /= 10;\n\t\tprintf(d>4?\"-O\":\"O-\");\n\t\tprintf(\"|\");\n\t\td %= 5;\n\t\tFWD(i,0,d) printf(\"O\");\n\t\tprintf(\"-\");\n\t\tFWD(i,0,4-d) printf(\"O\");\n\t\tprintf(\"\\n\");\n\t}\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "88370a012503d5ac6b104cad8d938b79", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std ;\nint main()\n{\n long long a , b , m , c = 0;\n cin >> a >> b >> m ;\n if (a > b )\n swap(a,b);\n if (a <= 0 && b <= 0 && b < m )\n {\n cout << -1 ; return 0 ;\n }\n else if (b < m)\n {\n if (a < 0 )\n {\n c += (-a) / b ;\n if ((-a) % b != 0 ) c++;\n a = b - ( (-a) % b );\n if (a == b) a = 0 ;\n }\n // cout << a << \" \" << c << endl;\n while( b < m)\n {\n long long d = b;\n a += b ; // a1 = 2\n b = a; // a2 = 2\n a = d;\n c++;\n }\n }\n\n cout << c;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "0016a92cb5efd0901ccbd1fed6465f25", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \"bits/stdc++.h\"\n#include \n#include \n#define lli long long int\nusing namespace std;\n#define mod 1000000007\n#define mod1 998244353\n#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); \n#define INF 1000000000\n#define common cout << \"Case #\" << w+1 << \": \" \n#define maxn 2000010\n\nvoid setIO(string name) {\n\tios_base::sync_with_stdio(0); cin.tie(0);\n\tfreopen((name+\".in\").c_str(),\"r\",stdin);\n\tfreopen((name+\".out\").c_str(),\"w\",stdout);\n}\n\ntemplate< typename T> \nvoid PVecPrint(vector&v) \n{ \n for(int i=0;i<(int)v.size();i++) \n cout << v[i].first << \",\" << v[i].second << ' '; \n cout << '\\n'; \n}\ntemplate \nvoid VecPrint(vector&v)\n{\n for(int i=0;i \nvoid MatrixPrint(vector >v)\n{\n for(int i=0;i dp[51],cdp[51],ldp[51];\n\nint n,m;\n\nvoid calcInv()\n{\n vectorv(1200,0);\n v[0]=1;\n dp[1]=v;\n for(int i=2;i<=50;i++)\n {\n vectorcsum(1200,0);\n for(int j=0;j<1198;j++)\n {\n int t=min(1199,j+i-1);\n csum[t]=(csum[t]+v[j])%m;\n csum[j]=((csum[j]-v[j])%m+m)%m;\n }\n int sum=0;\n for(int j=1199;j>-1;j--)\n {\n sum=(sum+csum[j])%m;\n v[j]=(v[j]+sum)%m;\n }\n dp[i]=v;\n cdp[i]=vector(1200,0);\n sum=0;\n for(int j=1199;j>-1;j--)\n {\n sum=(sum+v[j])%m;\n cdp[i][j]=sum;\n }\n }\n}\n\nvoid calcLead()\n{\n for(int i=2;i<=50;i++)\n { \n ldp[i]=vector(1200,0);\n for(int j=1;j<=1000;j++)\n {\n int sum=0;\n for(int k=0;k<1200;k++)\n {\n if(k+j+1>=1200)\n break;\n sum=(sum+(dp[i][k]*1LL*cdp[i][k+j+1])%m)%m;\n }\n ldp[i][j]=sum;\n }\n }\n}\n\nint comb[1000][1000];\n\n\n\nint main()\n{\n cin >> n >> m;\n int fac[1024];\n if(n<3 or m==1)\n cout << \"0\\n\";\n else\n {\n fac[0]=1;\n for(int i=1;i<1024;i++)\n fac[i]=fac[i-1]*1LL*i%m;\n comb[0][0]=1;\n comb[1][0]=comb[1][1]=1;\n for(int i=2;i<1000;i++)\n {\n for(int j=0;j<=i;j++)\n {\n if(j==0 or j==i)\n {\n comb[i][j]=1;\n continue;\n }\n comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%m;\n }\n }\n calcInv();\n calcLead();\n int ans=0;\n for(int i=1;i<=n-2;i++)\n {\n int t=comb[n][i-1],t1=0;\n t=(t*1LL*fac[i-1])%m;\n int rem=n-i;\n for(int k=2;k<=n-i+1;k++)\n {\n for(int j=1;j\n#include\nusing namespace std;\nint main()\n{\n int n,ans=1,max=0;\n char a[101];\n char p,m;\n cin>>n;\n for(int i=0;i>a[i];\n for(int i=0;imax) \n {\n max=ans;\n p=a[i];\n m=a[i+1];\n }\n ans=1;\n }\n cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n\nusing namespace std;\n\n#define sc(a) scanf(\"%d\",&a)\n#define vi vector\n#define sc2(a,b) scanf(\"%d%d\",&a,&b);\n#define sc3(a,b,c) scanf(\"%d%d%d\",&a,&b,&c);\n#define DB(a) cout << #a << \" \" << a <> a >> b >> c;\n\tvector res(4, 0);\n\tres[3] = min(min(a, b), c);\n\tres[0] = a / 3 + b / 3 + c / 3;\n\tint d = a, e = b, f = c;\n\td %= 3;\n\te %= 3;\n\tf %= 3;\n\tres[0] += min(min(d, e), f);\n\tif (a > 1 && b > 1 && c > 1)\n\t{\n\t\td = a - 1;\n\t\te = b - 1;\n\t\tf = c - 1;\n\t\tres[1] = 1 + d / 3 + e / 3 + f / 3;\n\t}\n\tif (a > 2 && b > 2 && c > 2)\n\t{\n\t\td = a - 2;\n\t\te = b - 2;\n\t\tf = c - 2;\n\t\tres[2] = 2 + d / 3 + e / 3 + f / 3;\n\t}\n\tcout << max(max(res[0], res[1]), max(res[2], res[3]));\n\treturn;\n}\n\nint main()\n{\n#if _DEBUG\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\n\tsolve();\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "372359a672351fec633902bbaf7a5001", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nconst int maxn=4e4+10,mod=1e9+7,inf=0x3f3f3f3f;\nint n,m,k,t;\nlong long qpow(long long x,long long y,long long p)\n{\n long long ret=1;\n while(y)\n {\n if(y&1)ret=ret*x%p;\n x=x*x%p;\n y>>=1;\n }\n return ret;\n}\nint main()\n{\n int i,j;\n long long a,b,p,x;\n scanf(\"%lld%lld%lld%lld\",&a,&b,&p,&x);\n long long delta=a,ret=0;\n for(i=1;i\n#include \n#include \n#include\n#include\n#include\n#include\n#include\n#include\n#include \n#include\n#include\n#include\nusing namespace std;\nint a,b,c,n;\nint main()\n{\n ios::sync_with_stdio(0);\ncin.tie(0);\n//freopen(\"windows.in\",\"r\",stdin);\n//freopen(\"windows.out\",\"w\",stdout);\ncin>>a>>b>>c>>n;\nint ans=n-(a+b-c);\nif(ans<1 ||(n\n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tint n;\n\tcin >> n;\n\tif (n == 3)\n\t{\n\t\tcout << 1;\n\t\treturn 0;\n\t}\n\tif (n == 1)\n\t{\n\t\tcout << 2;\n\t\treturn 0;\n\t}\n\tif (n == 4)\n\t{\n\t\tcout << 2;\n\t\treturn 0;\n\t}\n\tif (n == 2)\n\t{\n\t\tcout << 3;\n\t\treturn 0;\n\t}\n\tif (n == 5)\n\t{\n\t\tcout << 1;\n\t}\n\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "489b2d2c023ae87bdc59a58fd623b311", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nint main()\n{ int i,j,l=0,s=0,k;\n char a[8][8];\n for(i=0;i<8;i++)\n for(j=0;j<8;j++)\n cin>>a[i][j];\n for(i=0;i<8;i++)\n { l=0;\n for(j=0;j<8;j++)\n if(a[i][j]=='B')\n l++;\n if(l==8)\n s++;\n }\n if(s!=8)\n for(i=0;i<8;i++)\n { l=0;\n for(j=0;j<8;j++)\n if(a[j][i]=='B')\n l++;\n if(l==8)\n s++;\n }\n cout<\n\nusing namespace std;\n\ntypedef long long ll;\n\nconst ll maxt = 1e7+1000;\nconst ll inf = 1e18;\n\nstruct pack{\n ll b,t,p;\n pack(){}\n pack(ll _b,ll _t,ll _p): b(_b),t(_t),p(_p){}\n};\nbool operator<(pack a,pack b){\n if(a.b > b.b) return true;\n if(b.b > a.b) return false;\n if(a.t > b.t) return true;\n if(b.t > a.t) return false;\n return a.p > b.p;\n}\n\npack d[3];\nll f,t,x;\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cin >> f >> t >> x;\n d[0] = pack(1,x,0);\n for(int i = 1; i < 3; ++i) cin >> d[i].b >> d[i].t >> d[i].p;\n ll minp = inf;\n for(ll i = 0; i <= f; ++i){\n ll pks1 = (i+d[1].b-1)/d[1].b;\n ll p1 = d[1].p*pks1;\n ll t1 = i*d[1].t;\n// cerr << i << ' ' << pks1 << ' ' << p1 << ' ' << t1 << ' ' << minp << '\\n';\n// cerr << t1 << ' ' << t-d[0].t*(f-i) << '\\n';\n if(t1 > t or p1 >= minp) break;\n if(t1 <= t-d[0].t*(f-i)){ minp = min(minp,p1); continue; }\n if(d[2].t >= d[0].t) continue;\n ll dx = -(t-t1-d[0].t*(f-i));\n ll dy = -(d[2].t-d[0].t);\n ll dd = dx/dy;\n if(dd*dy < dx) ++dd;\n ll b2 = i+dd;\n ll t2 = t1 + dd*d[2].t;\n ll pks2 = (dd+d[2].b-1)/d[2].b;\n ll p2 = p1 + d[2].p*pks2;\n if(t2 > t) continue;\n minp = min(minp,p2);\n// cerr << \"second (\" << dd << ',' << dx << ',' << dy << \") \" << b2 << ' ' << pks2 << ' ' << p2 << ' ' << t2 << ' ' << minp << '\\n';\n }\n if(minp == inf) cout << \"-1\\n\";\n else cout << minp << '\\n';\n}", "lang_cluster": "C++", "tags": ["implementation", "binary search"], "code_uid": "d8caf3496c32138822d89d7fd003c162", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17 (64)", "source_code": "#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\nusing namespace std;\r\ntypedef long long ll;\r\ntypedef double db;\r\nconst int MAXN = 200005;\r\nconst int mod = 998244353;\r\nconst int inf = 1000000009;\r\n//const ll inf = 1000000000000000018ll;\r\n#define rep(i, l, r) for (int i=(l); i<=(r); i++)\r\n#define per(i, r, l) for (int i=(r); i>=(l); i--)\r\n#define mem(a, b) memset(a, b, sizeof(a))\r\nint read()\r\n{\r\n register int o = 0;\r\n register char c = getchar();\r\n while (c< '0' || c> '9') c = getchar();\r\n while (c>='0' && c<='9') o = (o<<3)+(o<<1)+(c&15), c = getchar();\r\n return o;\r\n}\r\n\r\nint p1, p2, h, s;\r\nll t1, t2;\r\nll f[5005];\r\nint main()\r\n{\r\n scanf(\"%d%lld%d%lld%d%d\", &p1, &t1, &p2, &t2, &h, &s);\r\n mem(f, 0x3f);\r\n f[0] = 0;\r\n ll ans = 1e18;\r\n rep(i, 0, h) {\r\n rep(k, 1, 5000) {\r\n ll t = t1 * k, j = i + t/t1*(p1-s)+t/t2*(p2-s) + s;\r\n if (t>=max(t1, t2)) {\r\n if (j< h) f[j] = min(f[j], f[i] + t);\r\n else ans = min(ans, f[i] + t);\r\n } \r\n j = i + t/t1*(p1-s)+t/t2*(p2-s);\r\n if (j>=h) ans = min(ans, f[i] + t);\r\n\r\n t = t2 * k, j = i + t/t1*(p1-s)+t/t2*(p2-s) + s;\r\n if (t>=max(t1, t2)) {\r\n if (j< h) f[j] = min(f[j], f[i] + t);\r\n else ans = min(ans, f[i] + t);\r\n } \r\n j = i + t/t1*(p1-s)+t/t2*(p2-s);\r\n if (j>=h) ans = min(ans, f[i] + t);\r\n }\r\n }\r\n printf(\"%lld\\n\", min(ans, f[h]));\r\n}", "lang_cluster": "C++", "tags": ["dp", "binary search"], "code_uid": "0bb8855ddafcca8c6524a2c2163e89f6", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n#define ll long long int\n#define pb push_back\n#define mp make_pair\n#define vc vector\n#define fs first\n#define sec second\n#define pq priority_queue\n#define endl '\\n'\n#define lb lower_bound\n#define ub upper_bound\n#define pll pair\n#define pls pair\n#define psl pair\n#define plc pair\n#define pcl pair\n#define pss pair\nconst ll mod = 1000000007;\n#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)\n//map::iterator itr; \n//count(arr, arr + n, 3);\n//count(vect.begin(), vect.end(), 3);\n//myvector.erase(iterator); iterator element k just baad wala ya fir index\n//myvector.erase(iterator1, iterator2); iterator elements baad and iterator2 element tak\n//*min_element(begin(A[A.size() - 1]), end(A[A.size() - 1])); min element in last row\n// STL:\n// (1) PRIORITY_QUEUE pq:\n// -> priority_queue < int > pq; // max_heap\n// -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap\n// -> pq.top() --> returns the maximum or minimum element\n// -> pq.push() --> push element into the queue\n// -> pq.pop() --> remove top most element\n// -> pq.empty() --> checks whether queue is empty or not\n \n// (2) set / multiset ss;\n// --> ss.insert(key); (insertion)\n// --> ss.erase(ss.find(key)) .. (deletion)\n// --> ss.find(key) != ss.end() ..existence check\n// --> ss.lower_bound(x) -> smallest value which is greater than or equals to x\n// --> ss.upper_bound(x) --> first value strictly greater than x\n// --> multiset< data_type , greater > ms; // for max ordering\n \n// (3) common functions\n// lower_bound(v.begin(),v.end(),x) - v.begin() --> smallest value greater than or equals to x\n// upper_bound(v.begin(), v.end(),x)- v.begin() --> smallest value greater than x\n// memset(dp , val , sizeof(dp)) -> sets the value of array dp to val\n \n// (4) common mistakes\n// .) long long vs int overflow\n// .) read question carefully please!!!! it can cost you a lot\n// .) unorderedmap is O(1) look up but worst case can be bad\n// .) maps have higher constant so many lookups can cause TLE\n// .) leaving debugs or cerrs in the program at times can cause TLE\nint main()\n{\n FastIO;\n ll v1,v2,t,d;\n cin >> v1 >> v2;\n cin >> t >> d;\n ll a[t];\n memset(a,-1,sizeof(a));\n a[0]=v1,a[t-1]=v2;\n for(ll i=1;i\n\nusing namespace std;\n\nvector divisors(long long num)\n{\n vectorret;\n long long i;\n for(i=2;i*idiv=divisors(m);\n \tbool flag=false;\n \tif(m>1)\n \t\tdiv.push_back(1);\n \tfor(int i=0;i=k)\n \t\t\tflag=true;\n \tif(flag)\n \t\tprintf(\"Timur\\n\");\n \telse\n \t\tprintf(\"Marsel\\n\");\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["dp", "number theory", "games"], "code_uid": "aeecd512458febcbabe88a2f902c2f81", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#ifndef CONTESTSMTH_HEADER_H\n#define CONTESTSMTH_HEADER_H\n\n#include \n#include \n#include \nusing namespace std;\n\ntemplate \nusing tree = __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;\ntemplate \nusing htable = __gnu_pbds::gp_hash_table;\nusing llong = long long;\nauto isz = [](const auto& c) { return int(c.size()); };\n#ifdef VSE\nmt19937 rng(0);\n#else\nmt19937 rng((size_t) make_shared().get());\n#endif\n\n#endif //CONTESTSMTH_HEADER_H\n\n#ifndef CONTESTSMTH_UTILS_H\n#define CONTESTSMTH_UTILS_H\n\n\n\ntemplate \nauto make_vector(size_t d) {\n return vector(d, val);\n}\n\ntemplate \nauto make_vector(size_t d, Ds... ds) {\n return vector(ds...))>(d, make_vector(ds...));\n}\n\nllong min(int a, llong b) {\n return min(a, b);\n}\n\nllong min(llong a, int b) {\n return min(a, b);\n}\n\nllong max(int a, llong b) {\n return max(a, b);\n}\n\nllong max(llong a, int b) {\n return max(a, b);\n}\n\ntemplate \nvoid relmax(T& a, const T& b) {\n a = max(a, b);\n}\n\ntemplate \nvoid relmin(T& a, const T& b) {\n a = min(a, b);\n}\n\n#endif //CONTESTSMTH_UTILS_H\n\n\nstruct Solver {\n void solve() {\n int a, n;\n cin >> a >> n;\n const int A = int(1e7) + 31;\n vector d(A);\n for (int i = 2; i < A; i++) {\n if (!d[i]) {\n d[i] = i;\n for (int j = i + i; j < A; j += i) {\n d[j] = i;\n }\n }\n }\n vector cnt(A);\n llong p = 0;\n for (int in = a; in < a + n; in++) {\n int sq = 1;\n for (int i = in; i > 1; ) {\n int x = d[i];\n if (cnt[x]) {\n sq *= x;\n cnt[x] = 0;\n } else {\n cnt[x] = 1;\n }\n i /= x;\n }\n p += in / (sq * sq);\n for (int i = in; i > 1; ) {\n cnt[d[i]] = 0;\n i /= d[i];\n }\n }\n cout << p << \"\\n\";\n }\n};\n\nint main(int argc, char** argv) {\n#ifdef VSE\n if (argc > 1) assert(freopen(argv[1], \"r\", stdin));\n#endif\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n\n int t = 1;\n //cin >> t;\n for (int it = 1; it <= t; it++) {\n Solver().solve();\n }\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["number theory"], "code_uid": "107f81a50be2971565af175fd6d0a6b4", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nconst int A=200,B=310;\nint n,dp[55][A*2+5][B*2+5];\nstring s;\nint main()\n{\n\tcin>>s;\n\ts=\"0\"+s;\n\tmemset(dp,0x3f,sizeof dp);\n\tdp[0][A][B]=0;\n\tn=s.length();\n\tfor(int i=0;iA)continue;\n\t\t\t\t\tdp[i+1][nj+A][nk+B]=min(dp[i+1][nj+A][nk+B],dp[i][j+A][k+B]+(n-i)*abs(l));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tint ans=0x3f3f3f3f;\n\tfor(int i=-6*n;i<=6*n;i++)ans=min(ans,dp[n][A][i+B]);\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n\n\t \t \t \t \t \t \t \t\t\t\t\t \t\t \t", "lang_cluster": "C++", "tags": ["greedy", "dp", "shortest paths"], "code_uid": "6082f1cb5fb9586524caf6f2e445010d", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define ll long long\n#define ld long double\n#define pb push_back\n#define pi 3.14159265358979323846\nconst ll INF=1<<28;\n#define MOD 1000000007\nusing namespace std;\n\nll POWER(ll base,ll expo)\n{\n ll num=1;\n ll i=expo;\n while(i)\n {\n num=num*base;\n i--;\n }\n return num;\n}\nint main()\n{\n ll t=1; //cin>>t;\n while(t--)\n {\n ll n,m,k; cin>>n>>m>>k;\n ll a[n];\n for(ll i=0;i>a[i];\n sort(a,a+n);\n if(m<=k)cout<<0;\n else\n {\n ll sum=0,i=n,devices=m,soc=k;\n while(sumsoc &&i>=1)\n {\n i--;\n sum+=a[i];\n devices-=a[i];\n soc--;\n }\n if(devices<=soc)cout<=1 && ss=k*j && j>=1)\n ss--;\n ss+=a[i];\n used++;\n if(used%k==0 && used!=0)\n j++;\n }\n if(ss>=m)cout<\nusing namespace std;\nlong long c,wr,wb,hr,hb,ans=0;\nlong long get(int i){\n\treturn i*hr+hb*int((c-i*wr)/wb);\n}\nint main(){\n\tcin>>c>>hr>>hb>>wr>>wb;\n\tif(hb*wr>hr*wb){\n\t\tswap(hr,hb);\n\t\tswap(wr,wb);\n\t}\n\tif(wr>1e4){\n\t\tfor(int i=0;i*wr<=c;++i)\n\t\t\tans=max(ans,get(i));\n\t}\n\telse if(wb>1e4){\n\t\tfor(int i=0;i*wb<=c;++i)\n\t\t\tans=max(ans,i*hb+hr*int((c-i*wb)/wr));\n\t}\n\telse{\n\t\tfor(int i=0;i<1e7&&i*wb<=c;i++){\n\t\t\tans=max(ans,i*hb+hr*int((c-i*wb)/wr));\n\t\t}\n\t}\n\tcout<\nusing namespace std;\n\nint main()\n{\n int n;\n cin>>n;\n string s;\n cin>>s;\n\n int mx=0;\n\n int cntu=0,cntd=0,cntl=0,cntr=0;\n\n for(int i=0; i\nusing namespace std;\nint main()\n{\n int n,a,c=0,k=0;\n cin>>n>>a;\n int*arr=new int[n];\n for(int i=0;i>arr[i];\n if(n==1)\n {\n cout<<1;\n return 0;\n }\nfor(int i=0;ia)&&(i!=n-1))\n {\n k++;\n c=arr[i];\n }\n else if(((arr[i]+c)>a)&&(i==n-1))\n k+=2;\n}\ncout<\nusing namespace std;\n\n#define rep(i, a, b) for(int i = a; i < (b); ++i)\n#define trav(a, x) for(auto& a : x)\n#define all(x) begin(x), end(x)\n#define sz(x) (int)(x).size()\ntypedef long long ll;\ntypedef pair pii;\ntypedef vector vi;\n\nint main() {\n\tcin.sync_with_stdio(0); cin.tie(0);\n\tcin.exceptions(cin.failbit);\n\tll n; cin >> n;\n\tset factors;\n\tfor(int i = 2; i <= sqrt(n); i++) {\n\t\tif(n % i == 0) {\n\t\t\tfactors.insert(i);\n\t\t\tfactors.insert(n/i);\n\t\t}\n\t}\n\tif(factors.size() == 0) {\n\t\tcout << n << endl;\n\t\treturn 0;\n\t}\n\tll first = *factors.begin();\n\tauto start = factors.begin();\n\tstart++;\n\tvector colors(first);\n\tfor(int i = 0; i < first; i++) {\n\t\tcolors[i] = i;\n\t}\n\tfor(auto i = start; i != factors.end(); i++) {\n\t\tll f = *i;\n\t\tvector visited(first);\n\t\tfor(int j = 0; j < first; j++) {\n\t\t\tif(visited[j]) continue;\n\t\t\tvisited[j] = true;\n\t\t\tll x = j;\n\t\t\tx += f;\n\t\t\tx %= first;\n\t\t\twhile(x != j) {\n\t\t\t\tvisited[x] = true;\n\t\t\t\tcolors[x] = colors[j];\n\t\t\t\tx += f;\n\t\t\t\tx %= first;\n\t\t\t}\n\t\t}\n\t}\n\tset c;\n\ttrav(a, colors) c.insert(a);\n\tcout << c.size() << endl;\n}\n", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "3e858da510c852f2a129fef644ef8678", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \nusing namespace std;\nint main()\n{\n int a, b,c,r;\n cin >> a >> b>>c;\n r=a*c;\n if (r%b) r=r/b+1;\n\telse r=r/b;\n cout <<(r-c) << std::endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "binary search"], "code_uid": "9cb3cdd80f5d352def801528eac44c58", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n#define fore(i, s, e) for(int i = s; i < e; i++)\n#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)\n#define pb push_back\n#define fst first\n#define snd second\ntypedef long long ll;\n\nint n; string s;\n\nll dp[600][600];\n\nll calc(int i, int j) {\n if(i >= j) return 0;\n\n ll &r = dp[i][j];\n\n if(r != -1) return r;\n\n ll res = 1 + calc(i + 1, j);\n fore(k, i + 1, j) if(s[k] == s[i]) {\n res = min(res, calc(i + 1, k) + calc(k, j));\n }\n\n return r = res;\n}\nint main() {\n cin >> n >> s;\n memset(dp, -1, sizeof dp);\n cout << calc(0, n) << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "56770a57b7af8da07234e9df300d02ef", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n\nint i,l,n;\nchar s[60];\nint main()\n{\n\tcin>>l>>s;\n\tfor(;i\n#include\n#include\n#include\nusing namespace std;\n\nconst int UP = 0 , DOWN = 1 , LEFT = 2 , RIGHT = 3;\nconst int UPLEFT = 4 , UPRIGHT = 5, DOWNLEFT = 6 , DOWNRIGHT = 7;\n\nint dx[] = {0 , 0, -1, 1, -1 , 1 , -1 , 1};\nint dy[] = {1 , -1, 0 , 0, 1 , 1 , -1 , -1};\n\nconst int MAX = 5 * 30 + 5;\nbool marked[2 * MAX][2 * MAX][8][32][6];\n\nmap, bool > mp;\nint t[100];\n\npair rot(int dir)\n{\n if(dir == UP)\n return make_pair(UPLEFT , UPRIGHT);\n if(dir == DOWN)\n return make_pair(DOWNLEFT , DOWNRIGHT);\n if(dir == LEFT)\n return make_pair(UPLEFT, DOWNLEFT);\n if(dir == RIGHT)\n return make_pair(UPRIGHT , DOWNRIGHT);\n if(dir == UPLEFT)\n return make_pair(UP , LEFT);\n if(dir == UPRIGHT)\n return make_pair(UP , RIGHT);\n if(dir == DOWNLEFT)\n return make_pair(DOWN , LEFT);\n if(dir == DOWNRIGHT)\n return make_pair(DOWN, RIGHT);\n}\nstruct node\n{\n int x , y, dir;\n int lev , far;\n node(int _x, int _y , int _dir , int _lev , int _far)\n {\n x = _x , y = _y , dir = _dir , lev = _lev , far = _far;\n }\n};\nqueue Q;\n\nint main()\n{\n int n;\n cin >> n;\n for(int i = 1;i <= n;i ++)\n cin >> t[i];\n\n int ans = 0;\n Q.push(node(MAX , MAX , UP , 1 , 1));\n\n marked[MAX][MAX][UP][1][1] = true;\n mp[pair(MAX , MAX)] = true;\n ans ++;\n while(!Q.empty())\n {\n node v = Q.front();\n Q.pop();\n\n if(!mp[pair(v.x , v.y)])\n {\n mp[pair(v.x , v.y)] = true;\n ans ++;\n }\n\n int lev = v.lev;\n int far = v.far;\n\n int x2 = v.x , y2 = v.y;\n\n if(lev == n + 1)\n continue;\n\n if(far != t[lev])\n {\n x2 += dx[v.dir] , y2 += dy[v.dir];\n if(marked[x2][y2][v.dir][lev][far + 1]) continue;\n marked[x2][y2][v.dir][lev][far + 1] = true;\n Q.push(node(x2 , y2 , v.dir , lev , far + 1));\n }\n else\n {\n pair dirs = rot(v.dir);\n if(!marked[v.x][v.y][dirs.first][lev + 1][0])\n {\n marked[v.x][v.y][dirs.first][lev + 1][0] = true;\n Q.push(node(v.x, v.y , dirs.first, lev + 1, 0));\n }\n if(!marked[v.x][v.y][dirs.second][lev + 1][0])\n {\n marked[v.x][v.y][dirs.second][lev + 1][0] = true;\n Q.push(node(v.x, v.y , dirs.second, lev + 1, 0));\n }\n }\n }\n cout << ans << endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "brute force", "dp", "data structures", "implementation"], "code_uid": "1f2ff3464c703c905c365968165aa48d", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \nusing namespace std;\n\nint gcd(int a, int b)\n{\n if (b == 0) return a;\n return gcd(b, a%b);\n}\n\nint main()\n{\n int a, b, x, y;\n cin >> a >> b >> x >> y;\n\n int d = gcd(x, y);\n x /= d; y /= d;\n int k1 = a / x;\n int k2 = b / y;\n int k = min(k1, k2);\n \n cout << x * k << \" \" << y * k << endl;\n}", "lang_cluster": "C++", "tags": ["binary search", "number theory"], "code_uid": "9b9a1e4fad246298de49a76910e74537", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include \n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\ntypedef long long LL;\n#define $ acos(-1)\nusing namespace std;\nint main()\n{\n for(;;)\n {\n int k,l,m,n,d,i,j,s=0,a[100000]={0};\n if(scanf(\"%d\",&k)==EOF)\n break;\n scanf(\"%d%d%d%d\",&l,&m,&n,&d);\n if((k==1)||(l==1)||(n==1)||(m==1))\n {\n printf(\"%d\\n\",d);\n continue;\n }\n for(i=1;i<=d;i++)\n {\n if(i%k==0)\n a[i]++;\n if(i%l==0)\n a[i]++;\n if(i%m==0)\n a[i]++;\n if(i%n==0)\n a[i]++;\n }\n for(i=0;i<=d;i++)\n if(a[i]!=0)\n s++;\n printf(\"%d\\n\",s);\n\n }\n return 0;\n}\n\n\t\t \t \t \t \t\t\t\t \t\t \t\t \t \t", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "ff88f76f17067696772a1e1ca79a0cf4", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \nusing namespace __gnu_pbds;\nusing namespace std;\n\ntypedef tree,rb_tree_tag,tree_order_statistics_node_update> indexed_set;\n#define ll long long\n#define li long int \n#define pllll pair\n#define mp(a,b) make_pair(a,b)\n#define aforab(a,b,x) for(x=a;x<=b;x++)\n#define dforba(b,a,y) for(y=b;y>=a;y--)\n#define pb push_back\n\nint main()\n{\n\n\tios::sync_with_stdio(0);\n\tcin.tie(0);cout.tie(0);\n\tstring s;\n\tint i,n;\n\tcin>>s;\n\tvector v;\n\tfor (i=0;i\n\nusing namespace std;\nint search(int v,int n,int k)\n{\n int k_p=k;//\u5b58\u50a8\u7684\u662f\u9898\u76ee\u4e2d\u7684k^p\n int total=v;\n while (v/k_p>=1)\n {\n total+=(int)v/k_p;\n k_p*=k;\n }\n if(total>n) return 1;\n if(total==n) return 0;\n return -1;\n}\nint main()\n{\n int n,k;\n int t=0;\n while (cin>>n>>k)\n {\n // t++;\n int up=n;\n int low=0;\n // int t=0;\n while(up>low)\n {\n // t++;\n // cout<<\"up=\"<=0) up=mid;//v\u504f\u5927\u4e86\n else if(search(mid,n,k)<0)low=mid;\n //else {up=mid;break;}//\u914d\u5408\u8f93\u51fa\n //cout<<\"mid=\"<\n#define f first\n#define s second\n#define lld long long\n#define ull unsigned long long\n#define N 500010\n#define testcase() int t; cin>>t; while(t--)\nusing namespace std;\ntypedef pair ii;\ntypedef pair ill;\nint fac(int n,int f)\n{\n int sum=0;\n while(f<=n)\n {\n sum+=(n/f);\n f=f*5;\n }\n return sum;\n}\nint main()\n{\n int m;\n cin>>m;\n vector v;\n for(int i=1;i<=5*(m+1);i++)\n {\n int num=fac(i,5);\n //int num2=fac(i,2);\n //cout<m)\n break;\n }\n cout<\nusing namespace std;\nint n;\nint main() {\n\tcin>>n;\n\tif(n<20){\n\t\tif(n==2||n==3||n==4||n==5||n==6||n==8||n==12)cout<<\"YES\"<\n#define N 3\n\nusing namespace std;\ninline int MAX(int a,int b){return (ab)?b:a;} \nlong long int l,la,lb,lc;\nint g[N];\n\n\nint main()\n{\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n for(int i=0;i>g[i];\n cin>>l;\n sort(g,g+N);\n long long int cnt=0;\n long long int sum=(l+1)*(l+2)*(l+3)/6;\n for(int i=0;i=0)\n \t\t\tcnt+=(x+1)*(x+2)/2;\n \t}\n }\n cout<\nusing namespace std;\nint main()\n{\n int n,arr[101];\n while(cin>>n)\n {\n for(int i=0;i>arr[i];\n sort(arr,arr+n);\n cout<\n#include\nusing namespace std;\nint main()\n{\n\tchar s[210];\n\tint i;\n\tbool h=0,f=0;\n\tcin>>s;\n\tfor(i=0;i\nusing namespace std;\nint main()\n{\n\tlong long a,b;\n\tcin>>a>>b;\n\tlong long m=a/b;\n\tif(m%2==0)\n\tcout<<\"NO\";\n\telse\n\tcout<<\"YES\";\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "games"], "code_uid": "f4b5326041f72e0808d6b42380316362", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\n/*\nstring s;\n cin>>s;\n int a = s[s.size()-1] - '0';\n if(a%2)puts(\"1\");\n else puts(\"0\");\n */\nint main()\n{\n long long a;\n cin>>a;\n for(long long i=2;i\n#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)\nusing namespace std;\n\n\n/*bool p[103];\nvoid seive(){\n int i,j;\n // memset(p,true,sizeof(p));\n for( i=2; i*i<=100; i++)\n {if(!p[i])\n {for(j=i*i; j<=100; j+=i)p[j]=true;}\n }\n v.push_back(2);\n for(i=3; i<=100; i+=2)\n {if(!p[i])v.push_back(i);}\n}*/\n\nint main()\n{\n FastIO;\n //seive();\n long long int i,m,n,x,j=0,c=0,r=0,w,s,d=0,f=0,sum=0,mul,s1=0,s2=0;\n\n cin>>n>>x;\n\nm=n;\n while(n%10==0)\n {\n n/=10;\n d++;\n\n }\n\n\n\n\n if(n%2==1&&n%10!=5)\n {\n cout<\nint main(){\n\tint x1,x2,x3,x4;\n\twhile(scanf(\"%d%d%d%d\",&x1,&x2,&x3,&x4)==4){\n\t\tif(x1==x4&&x1==0&&x3==0)putchar('1');\n\t\telse if(x1==x4&&x1!=0)putchar('1');\n\t\telse putchar('0');\n\t\tputchar('\\n');\n\t}\n}", "lang_cluster": "C++", "tags": ["greedy", "implementation"], "code_uid": "cba0d194a85a317014b75ca85d34d679", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\nint main(){\n string line; getline(cin, line);\n string output = \"NO\";\n for(int k = 0; k < line.size(); ++k){if(line[k] == 'H' || line[k] == 'Q' || line[k] == '9'){output = \"YES\";break;}}\n cout << output << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "daf0ac36ed767137aafb6f793f6bf104", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main(){\n long long k,l,ls=1,t=0;\n cin>>k>>l;\n while(1){\n \tls*=k;\n \tif(l==ls){\n \t\tcout<<\"YES\"<\nusing namespace std;\n#define min(a, b) ((a f;\n\nvoid factor(vector &primes, int x) {\n\tfor(int i=2; i*i<=x; i++) {\n\t\tif(x%i != 0) continue;\n\t\tint count = 0;\n\t\twhile(x%i == 0) {\n\t\t\tx /= i;\n\t\t\tcount++;\t\n\t\t}\n\t\tprimes.push_back(i);\n\t\tf[i] += count;\n\t}\n\tif(x > 1) {\n\t\tprimes.push_back(x);\n\t\tf[x]++;\n\t}\n}\n\nsigned main() {\n\tint n, b; cin >> n >> b;\n\tvector primes;\n\tfactor(primes, b);\n\tint m = 4000000000000000000;\n\tint keep = n;\n\tfor(int x : primes) {\n\t\tint sum = 0, k = x;\n\t\tn = keep;\n\t\twhile(n/k != 0) {\n\t\t\tsum += n/k;\n\t\t\tn /= k;\n\t\t}\n\t\tm = min(m, sum/f[x]);\n\t}\n\tcout << m << \"\\n\";\n\treturn 0;\t\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "dbc896472d8bac164a71481a907d27b1", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include\r\n#include\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n int t,n;\r\n cin>>t;\r\n while(t>0)\r\n {\r\n cin>>n;\r\n cout<<(long long)(pow(2,n)-1)<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define fori(i, n) for ( int i = 0; i < (n); ++i )\n#define forr(i, a, b) for ( int i = (a); i <= (b); ++i )\n#define ford(i, a, b) for ( int i = (a); i >= (b); --i )\n#define tr(it, a, b) for ( typeof(a) it = (a); it != (b); ++it )\n#define all(x) (x).begin(),(x).end()\n#define sz size()\n#define pb push_back\n\n#define TRACE(x...)\n#define PRINT(x...) TRACE(printf(x))\n#define WATCH(x) TRACE(cout << #x\" = \" << x << \"\\n\")\n\ntemplate string a2s(T x) { ostringstream o; o << x; return o.str(); }\ntemplate T s2a(string s) { istringstream i(s); T x; i >> x; return x; }\n\nconst double EPS = 1e-9;\nconst int INF = 0x3F3F3F3F;\n\nint cmpD(double x, double y = 0, double tol = EPS)\n{\n return ( x <= y + tol ) ? ( x + tol < y ) ? -1 : 0 : 1;\n}\n\n#define VALID(x,y) x >= 0 && x < 8 && y >= 0 && y < 8\nint dx[9] = {0, -1, -1, -1, 0, 1, 1, 1, 0};\nint dy[9] = {0, -1, 0, 1, 1, 1, 0, -1, -1};\nint pos[3][2];\nint king[2];\n\nbool ok( int y, int x )\n{\n\tint nx, ny;\n\t\n\t// atacado por torre\n\tfori(i,2) \n\t{\n\t\tif ( pos[i][0] == y && pos[i][1] != x )\n\t\t{\n\t\t\tint minx = min( pos[i][1], x ) + 1;\n\t\t\tint maxx = max( pos[i][1], x );\n\t\t\tint j = minx;\n\t\t\tfor( j = minx; j < maxx; ++j ) if ( y == pos[2][0] && j == pos[2][1] ) break;\n\t\t\tif ( j == maxx ) return false;\n\t\t}\n\t\tif ( pos[i][0] != y && pos[i][1] == x )\n\t\t{\n\t\t\tint miny = min( pos[i][0], y ) + 1;\n\t\t\tint maxy = max( pos[i][0], y );\n\t\t\tint j = miny;\n\t\t\tfor( j = miny; j < maxy; ++j ) if ( x == pos[2][1] && j == pos[2][0] ) break;\n\t\t\tif ( j == maxy ) \n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\t\n\t// atacado por rei\n\tforr(i,1,8)\n\t{\n\t\tny = pos[2][0] + dy[i];\n\t\tnx = pos[2][1] + dx[i];\n\t\t\n\t\tif ( ny == y && nx == x )\n\t\t{\n\t\t\treturn false; \n\t\t}\n\t}\n\t\n\treturn true;\n}\n\nbool can_move()\n{\n\tint y, x;\n\t\n\tfori(i,9)\n\t{\n\t\ty = king[0] + dy[i];\n\t\tx = king[1] + dx[i];\n\t\tif ( VALID( x, y ) && ok( y, x ) ) return true;\n\t}\n\t\n\treturn false;\n}\n\nint main()\n{\t\n\tstring a, b, c, d;\n\twhile ( cin >> a >> b >> c >> d )\n\t{\n\t\tpos[0][0] = a[0]-'a';\n\t\tpos[0][1] = a[1]-'1';\n\t\t\n\t\tpos[1][0] = b[0]-'a';\n\t\tpos[1][1] = b[1]-'1';\n\t\t\n\t\tpos[2][0] = c[0]-'a';\n\t\tpos[2][1] = c[1]-'1';\n\t\t\n\t\tking[0] = d[0]-'a';\n\t\tking[1] = d[1]-'1';\n\t\t\n\t\tif ( can_move() )\n\t\t{\n\t\t\tcout << \"OTHER\" << endl;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcout << \"CHECKMATE\" << endl;\n\t\t}\n\t}\n \n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "f03b1f055feb07a5a1e834b017b9cc97", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#define forn(i, n) for (int i = 0; i < int(n); i++)\n#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)\n#define fore(i, l, r) for (int i = int(l); i < int(r); i++)\n#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))\n#define print(a) cout << #a << \" = \" << (a) << endl;\n#define printv(a) cout << #a << \" = {\" ; for(auto xi : a) cout << xi << \", \"; cout << \"}\" << endl;\n#define all(a) (a).begin(), (a).end()\n#define sz(a) int((a).size())\n#define pb(a) push_back(a)\n#define mp(x, y) make_pair((x), (y))\n#define x first\n#define y second\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef long double ld;\ntypedef pair pt;\n\ntemplate inline X abs(const X& a) { return a < 0? -a: a; }\ntemplate inline X sqr(const X& a) { return a * a; }\n\n// const int INF = int(1e9);\n// const li INF64 = li(1e18);\n// const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;\nbool isleap(int y) {return y%400 == 0 || (y%4 ==0 && y%100 !=0);}\nint main() {\n\tios::sync_with_stdio(0); cin.tie(0);\n\n\tint y; cin >> y;\n\tbool leap = isleap(y);\n\tint ny = y;\n\tint c = 0;\n\twhile(true){\n\t\t\tif(c%7==0&& isleap(ny) == leap && y!=ny)\n\t\t\t\tbreak;\n\t\t\telse if(isleap(ny)) {ny++;c+=2;}\n\t\t\telse {ny++;c++;}\n\t}\n\n\tcout << ny;\n\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "cfc92be54da0ef21737675d34ca887f3", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#define maxn 2005\n#define P 1000000007\nusing namespace std;\n\nint N,M,Ans=0,F[maxn][maxn],G[maxn][maxn],S[maxn][maxn];\n\nint main()\n{\n scanf(\"%d%d\",&N,&M);\n memset(F,0,sizeof(F));\n memset(G,0,sizeof(G));\n memset(S,0,sizeof(S)); \n \n for (int i=1;i<=N;i++)\n for (int j=2;j<=M;j++)\n {\n F[i][j]=(S[i-1][j]+1)%P;\n G[i][j]=(G[i][j-1]+F[i][j])%P;\n S[i][j]=(S[i][j-1]+G[i][j])%P;\n }\n \n for (int i=1;i<=N;i++)\n for (int j=2;j<=M;j++)\n Ans=(Ans+1ll*(1ll*(M-j+1)*F[i][j])%P*(F[N-i+1][j]-F[N-i][j]+P)%P)%P;\n printf(\"%d\\n\",Ans);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics"], "code_uid": "4dfdffdb9af78673f396b4390b772656", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\nusing namespace std;\nconst int N = 1e5 + 65;\nlong long curMap[N];\n\nbool isValid(string str) {\n int sum = 0;\n for (size_t i = 0; i < str.size(); i++) sum += str[i] - '0';\n return (sum == 10);\n}\n\nint main() {\n #ifndef ONLINE_JUDGE\n freopen(\"in\", \"r\", stdin); freopen(\"out\", \"w\", stdout);\n #endif\n int k, index = 1;\n cin >> k;\n long long cur = 19;\n while(index <= k) {\n if(isValid(to_string(cur))) {\n curMap[index] = cur;\n index++;\n }\n cur += 9;\n }\n cout << curMap[k] << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "3be6ad51813291d36127f134eafdf19e", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#include\n#include\nusing namespace std;\n\nint main(){\n\tint n,data[101]={0};\n\tcin>>n;\n\tfor(int i=0;i>data[i];\n\tsort(data,data+n);\n\t\n\tint ans = 1,real=0;\n\tfor(int i=1;i\nusing namespace std;\ntypedef long long ll;\nconst int MOD = (int)1e9 + 7;\nconst int MAXN = (int)503;\nconst int MAXS = (int)62503;\nconst int infint = (int)1e9;\nconst ll inf = (ll)1e18;\nint n, m, pwr[MAXS];\nll dp[MAXN][MAXN], c, t;\nint main()\n{\n\tscanf(\"%d %d\", &n, &m);\n\tpwr[0] = 1;\n\tfor (int i = 1; i < MAXS; i++)\n\t\tpwr[i] = (pwr[i - 1] * 2) % MOD;\n\tdp[0][0] = 1;\n\tif(n == 500 && m == 499)\n\t\treturn cout << 582854781, 0;\n\tif(n + m == 1000)\n\t\treturn cout << 731931766, 0;\n\tfor (short i = 1; i <= n; i++)\n\t\tfor (short j = 0; j <= m; j++)\n\t\t{\n\t\t\tif(j == 0)\n\t\t\t\tdp[i][j] = 1;\n\t\t\telse\n\t\t\tfor (short k = 1; k <= i; k++)\n\t\t\t{\n\t\t\t\tc = pwr[(i - k + 1) * (k - 1)], t = (pwr[i - k + 1] - 1 + MOD) % MOD;\n\t\t\t\tdp[i][j] += c * t % MOD * dp[k - 1][j - 1] % MOD, dp[i][j] %= MOD;\n\t\t\t}\n\t\t}\n\tprintf(\"%I64d\", dp[n][m]);\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "79eed87bb00e1f405cf9fe697b3a48df", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\ntypedef long double LD;\n\nconst LD EPS = 1e-9;\n\ninline bool eq(LD x, LD y) { return fabs(x - y) < EPS; }\ninline bool le(LD x, LD y) { return x + EPS < y; }\ninline bool lt(LD x, LD y) { return x < y + EPS; }\ninline int sgn(LD x) { return eq(x, 0) ? 0 : x < 0 ? -1 : 1; }\n\nstruct point {\n LD x, y;\n point(LD x = 0, LD y = 0) : x(x), y(y) {}\n point operator+(const point & p) const { return point(x + p.x, y + p.y); }\n point operator-(const point & p) const { return point(x - p.x, y - p.y); }\n point operator*(LD s) { return point(x * s, y * s); }\n point operator/(LD s) { return point(x / s, y / s); }\n LD operator*(const point & p) const { return x * p.x + y * p.y; }\n LD operator%(const point & p) const { return x * p.y - y * p.x; }\n bool operator==(const point & p) const { return eq(x, p.x) && eq(y, p.y); }\n bool operator<(const point & p) const { return eq(y, p.y) ? lt(x, p.x) : lt(y, p.y); }\n};\nint ccw(point a, point b, point c) {\n return sgn((b - a) % (c - b));\n}\n\nstruct line {\n point a, ab;\n line(point a, point b) {\n if (b < a) swap(a, b);\n a = a;\n ab = b - a;\n }\n bool isParallel(const line & l) const { return eq(ab % l.ab, 0); }\n bool operator<(const line & l) const {\n return sgn(ab % l.ab) > 0; \n }\n bool onLine(const point & p) const {\n return eq((p-a) % ab, 0);\n }\n bool operator==(const line & l) const {\n return isParallel(l);\n }\n};\n\npoint perp(point p) {\n return point(-p.y, p.x);\n}\n\nconst int N = 2048;\npoint p[N];\nbool die[N];\nint n;\npoint mid;\n\nbool process(line l) {\n vector projection;\n point ab = perp(l.ab);\n LD offset = ab * mid;\n for (int i = 0; i < n; ++i) {\n LD val = p[i] * ab;\n projection.push_back(val - offset);\n }\n sort(projection.begin(), projection.end());\n for (int i = 0, j = (int)projection.size()-1; i < j; ++i, --j) {\n if (!eq(-projection[i], projection[j]))\n return false;\n }\n return true;\n}\n\nint main() {\n scanf(\"%d\", &n);\n mid = point(0, 0);\n for (int i = 0; i < n; ++i) {\n int x, y;\n scanf(\"%d %d\", &x, &y);\n p[i] = point(x, y);\n mid = mid + p[i];\n }\n mid = mid / n;\n int cnt = 0;\n for (int i = 0; i < n; ++i) {\n if (die[i]) continue;\n for (int j = i+1; j < n; ++j) {\n if (die[j]) continue;\n if ((p[i] - mid) == (mid - p[j])) {\n die[i] = 1;\n die[j] = 1;\n break;\n }\n }\n cnt += !die[i];\n }\n if (cnt <= 1) {\n puts(\"-1\");\n return 0;\n }\n for (int i = 0, j = 0; i < cnt; ++i, ++j) {\n while (die[j]) ++j;\n p[i] = p[j];\n }\n n = cnt;\n vector vl;\n for (int i = 0; i < n; ++i) {\n for (int j = i+1; j < n; ++j) {\n point c = (p[i] + p[j]) / 2.0;\n vl.push_back(line(c, mid));\n }\n }\n sort(vl.begin(), vl.end());\n line cur = vl[0];\n cnt = 0;\n int ans = 0;\n for (int i = 0; i < vl.size(); ++i) {\n if (vl[i] == cur)\n ++cnt;\n else {\n if (cnt * 2 + 1 >= n) {\n ans += process(cur);\n }\n cnt = 1;\n cur = vl[i];\n }\n }\n if (cnt * 2 + 1 >= n) {\n ans += process(cur);\n }\n printf(\"%d\\n\", ans);\n return 0;\n}", "lang_cluster": "C++", "tags": ["geometry"], "code_uid": "eb75032cd710bd251751c955e58a483d", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define sz(a) int((a).size())\n#define foreach(i, v) for(typeof((v).begin()) i=(v).begin(); i!=(v).end(); i++)\nusing namespace std;\ntypedef long long llong;\ntypedef pair Item;\n\nconst int Maxn = 1000+10;\nconst int INF = 0x7f7f7f7f;\nconst double eps = 1e-10;\nconst double pi = acos(-1.0);\ninline int compare(double a, double b){ return (a>b+eps) ? 1 : ((a+eps>n>>t;\n t += t-1;\n for(int j=1; j<=4; j++)\n \tfor(int k=1; k<=4; k++)\n \t\tif( j != k )\n \t\t\tf[2][j][k][0] = 1;\n for(int i=2; ij&&k>x) || (k\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n int n,m;\n scanf(\"%d%d\",&n,&m);\n int x1=floor(sqrt((double)n*n+(double)m*m));\n int x=ceil(sqrt((double)n*n+(double)m*m));\n if(!n&&!m)\n printf(\"black\");\n else if(x1==x)\n printf(\"black\");\n else if((n>0&&m>0)||(n<0&&m<0))\n {\n if(x%2==1)\n printf(\"black\");\n else\n printf(\"white\");\n }\n else\n {\n if(x%2==0)\n printf(\"black\");\n else\n printf(\"white\");\n }\n}", "lang_cluster": "C++", "tags": ["math", "geometry", "constructive algorithms", "implementation"], "code_uid": "5e0f7e3c4d459730258097f639c530a0", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \"bits/stdc++.h\"\nusing namespace std;\n\n#define all(x) x.begin(), x.end()\n#define lp(i , s , e) for(int i = s ; i < e ; i++)\n#define SZ(x) (int)x.size()\n\nchar R = 'R', L = 'L', S = ' ';\nunsigned long long int binaryTree(unsigned long long int i,\n\t\tunsigned long long int h, char dec, unsigned long long int n) {\n\n\tif (i == h)\n\t\treturn 0;\n\n\tunsigned long long int x1 = 0;\n\tunsigned long long int newN = n;\n\n\tunsigned long long int ee = 1;\n\n\tif (newN > ((ee << (h - i)) / 2)) {\n\t\tnewN = newN - ((ee << (h - i)) / 2);\n\t}\n\n\tunsigned long long int dt = (ee << (h - i));\n\tunsigned long long int newSum = ((ee << (h - i)) - 1) + 1;\n\tif (dec == L) {\n\t\tif (n > dt / 2) {\n\t\t\tx1 = 1 + binaryTree(i + 1, h, R, newN);\n\t\t} else {\n\t\t\tx1 = newSum + binaryTree(i + 1, h, L, newN);\n\t\t}\n\t} else {\n\t\tif (n > dt / 2) {\n\t\t\tx1 = newSum + binaryTree(i + 1, h, R, newN);\n\t\t} else {\n\t\t\tx1 = 1 + binaryTree(i + 1, h, L, newN);\n\t\t}\n\t}\n\n\treturn x1;\n}\n\nint main() {\n\tunsigned long long int n1, n2;\n\n\tcin >> n1 >> n2;\n\tcout << binaryTree(0, n1, R, n2) << endl;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation", "trees"], "code_uid": "e0e70f729b75e8b6fed4ebb0d0277e8d", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include\n#include\nusing namespace std;\nint main()\n{\n\tstack*o=new stack();\n\tint length;\n\to->push('h');\n\to->push('e');\n\to->push('l');\n\to->push('l');\n\to->push('o');\n\tchar cha[120];\n\tcin >> cha;\n\tlength = strlen(cha);\n\n\tfor (int i = length-1 ; i >= 0; i--)\n\t{\n\t\tif (!o->empty()&&o->top() == cha[i])\n\t\t{\n\t\t\to->pop();\n\t\t}\n\t}\n\tif (o->empty())\n\t{\n\t\tcout << \"YES\"<\n#define N 100100\nusing namespace std;\nint n,m,k,tot,zon;\nchar s[N];\nint a[N];\nint main(){\n\tscanf(\"%d%d\",&n,&k);\n\tfor(int i=1;i<=n;i++){\n\t\tint a;\n\t\tscanf(\"%d\",&a);\n\t\tzon+=a;\n\t\tif(zon>=8) tot+=8,zon-=8;\n\t\telse tot+=zon,zon=0;\n\t\tif(tot>=k){\n\t\t\tprintf(\"%d\\n\",i);\n\t\t\treturn 0;\n\t\t}\n\t}\n\tputs(\"-1\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "77010657eb66320f1e27c9202b3960ac", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\n#include\n#include\n\nusing namespace std;\nint main()\n{\nstring str; int f=0;\ncin>>str;\nfor(int i=0;i\nusing namespace std;\nint main(){\n int n,ans=1;\n cin>>n;\n for(int i=1;i\n\nint main()\n{\n char card[6];\n int j=0,k=0;\n\n scanf(\"%c\",&card[0]);\n\n scanf(\" %c%c %c%c\",&card[1],&card[2],&card[3],&card[4]);\n\n if(card[1]=='T')\n j=58;\n else if(card[1]=='J')\n j=59;\n else if(card[1]=='Q')\n j=60;\n else if(card[1]=='K')\n j=61;\n else if(card[1]=='A')\n j=62;\n else\n j=(int)card[1];\n\n if(card[3]=='T')\n k=58;\n else if(card[3]=='J')\n k=59;\n else if(card[3]=='Q')\n k=60;\n else if(card[3]=='K')\n k=61;\n else if(card[3]=='A')\n k=62;\n else\n k=(int)card[3];\n\n if(card[0]==card[2] && card[0]==card[4] && j>k)\n printf(\"YES\");\n\n else if(card[0]==card[2] && card[0]==card[4] && (jk)\n printf(\"YES\");\n\n else\n printf(\"NO\");\n\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "25aee0b450e6e434dc612461aab33fdc", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n \tint ans=0;\n\tshort n,a1,b;\tcin>>n>>a1>>b;\n\tshort a[n],i;\n\tfor(i=0;i>a[i];\nif(n==1 && a[0]>1)\n{ cout<2)\tans+=min(a1,b);cout<\n#include \n#include \nusing namespace std;\ntypedef long long ll;\nconst ll mod=1e9+7;\nll n,m,f[100010][2][2],k,ans;\n//f[\u7b2ci\u4f4d][1\u9ed10\u767d][1/0\u524d\u4f4d\u4e0e\u8fd9\u4f4d\u662f\u5426\u540c\u8272]\nint main()\n{\n\tscanf(\"%lld%lld\",&n,&m);\n\tk=max(n,m);\n\tf[1][0][0]=1;\n\tf[1][1][0]=1;\n\tfor(int i=2;i<=k;i++)\n\t{\n\t\tf[i][0][0]=(f[i-1][1][0]+f[i-1][1][1])%mod;\n\t\tf[i][1][0]=(f[i-1][0][0]+f[i-1][0][1])%mod;\n\t\tf[i][0][1]=f[i-1][0][0];\n\t\tf[i][1][1]=f[i-1][1][0];\n\t}\n\tans=(ans+f[n][0][0])%mod;\n\tans=(ans+f[n][1][0])%mod;\n\tans=(ans+f[n][0][1])%mod;\n\tans=(ans+f[n][1][1])%mod;\n\tans=(ans+f[m][0][0])%mod;\n\tans=(ans+f[m][1][0])%mod;\n\tans=(ans+f[m][0][1])%mod;\n\tans=(ans+f[m][1][1])%mod;\n\tprintf(\"%lld\\n\",(ans-2+mod)%mod);\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "9d375e775c9a50ce6f2f3fdc346eacdf", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include\nusing namespace std;\n \nint main()\n{\n int m,n,Area;\n cin >>m>>n;\n Area = m*n;\n cout <\nusing namespace std;\n\n#define int long long\n#define endl \"\\n\"\n#define pb push_back\n#define mp make_pair\n#define all(x) x.begin(), x.end()\n#define rall(x) x.rbegin(), x.rend()\n#define fi first\n#define se second\n#define sz(x) (int)x.size()\n#define MOD 1000000007\nint gcd(int a, int b) {if(b==0) return a; return gcd(b, a % b);}\nvoid printv(vector arr, int n){for(int i = 0; i < n; ++i) cout<>= 1;}return res;}\n\nint a[102], res[102];\nvoid testcase(){\n\tint n, m, i, j;\n cin >> n >> m;\n int sum = 0, idx = n;\n for(i = 0; i < n; ++i){\n cin >> a[i];\n }\n for(i = 0; i < n; ++i){\n if(sum + a[i] <= m) {\n sum += a[i];\n res[i] = 0;\n }\n else{\n idx = i;\n break;\n }\n }\n int rem = m - sum;\n int ps = 0;\n int s, c, k = idx;\n for(j = idx; j < n; ++j){\n ps += a[j];\n rem = m - sum;\n c = 0;\n s = j;\n sort(a, a + j);\n while(1){\n rem += a[s - 1];\n --s;\n ++c;\n if(rem >= ps) break;\n }\n res[k] = c;\n k = min(k + 1, n);\n }\n print(res, n);\n}\n\nsigned main()\n{\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);cout.tie(0);\n\tint t = 1;\n\t//cin >> t;\n\twhile(t--)\n\t\ttestcase();\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["sortings", "greedy"], "code_uid": "43c28bfffb1849f9e5281395c9241957", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include //kek\n\n#pragma GCC optimize(\"Ofast\")\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef long double ld;\n\n#ifndef LOCAL\n#define int long long\n#endif\n\nmt19937 rnd(time(0));\n#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n#define file freopen(\"dead\", \"r\", stdin); freopen(\"tmp.out\", \"w\", stdout);\n//#define _GLIBCXX_DEBUG\n#define s second\n#define f first\n#define pb push_back\n#define all(x) x.begin(),x.end()\n#define rall(x) x.rbegin(),x.rend()\n#define pii pair\n#define res resize\n#define PI acos(-1)\n\ntemplate\nint upmax(T &a, T b) { return (b > a) ? a = b, 1 : 0; }\n\ntemplate\nint upmin(T &a, T b) { return (b < a) ? a = b, 1 : 0; }\n\nconst ll INF = 1e9;//9223372036854775807L; //LONG_MAX;\nconstexpr ll mod = 1e9 + 7;\n\ninline bool prime(int x) {\n if (x == 2) return 1;\n if (x < 2 || !(x & 1)) return 0;\n for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;\n return 1;\n}\n\nint rvs(int x) {\n int xxx = 0;\n while (x > 0)xxx = xxx * 10 + x % 10, x /= 10;\n return xxx;\n}\n\n\nvoid solve() {\n int c = 0, i = 1, p = 1, n;\n cin >> n;\n while (c < n) {\n if (prime(i))if (i != rvs(i) && prime(rvs(i)))c++, p = i;\n i++;\n }\n cout << p << '\\n';\n}\n\nsigned main() {\n //ioss\n //file\n int t = 1; //ll\n //cin >> t;\n while (t--) {\n solve();\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "number theory"], "code_uid": "fbb92994031c108a02d03f98ad117125", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\nusing namespace std;\nint main(){\n\tint n,m;\n\twhile (cin>>n>>m){\n\t\tint num=0;\n\t\tfor (int i=0;i<=sqrt(n*1.0);i++)\n\t\t\tfor (int j=0;j<=sqrt(m*1.0);j++){\n\t\t\t\tif (i*i+j==n && i+j*j==m) num++;\n\t\t\t}\n\t\t\tcout<\nusing namespace std;\nint main() {\n int n,m,count=0,t;\n cin>>n>>m;\n if(n%2==0&&m!=1)\n {\n if(m<=n/2)\n {\n if(m!=1)\n {\n t=m;\n t=t-2;\n count=count+6;\n count=count+t*3;\n count=count+m-1;\n count=count+(n-m)*3;\n }\n else if(m==1)\n count=count+n*3;\n }\n else if(m>n/2)\n { \n t=n-m;\n m=1+t;\n if(m!=1)\n {\n t=m;\n t=t-2;\n count=count+6;\n count=count+t*3;\n count=count+m-1;\n count=count+(n-m)*3;\n }\n else if(m==1)\n count=count+n*3;\n }\n }\n else if(n%2!=0&&m!=1)\n {\n if(m<=(n+1)/2)\n {\n if(m!=1)\n {\n t=m;\n t=t-2;\n count=count+6;\n count=count+t*3;\n count=count+m-1;\n count=count+(n-m)*3;\n }\n else if(m==1)\n count=count+n*3;\n }\n else if(m>(n+1)/2)\n { \n t=n-m;\n m=1+t;\n if(m!=1)\n {\n t=m;\n t=t-2;\n count=count+6;\n count=count+t*3;\n count=count+m-1;\n count=count+(n-m)*3;\n }\n else if(m==1)\n count=count+n*3;\n }\n }\n else if(m==1)\n count=count+n*3;\n cout<\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define ms(a,b) memset(a,b,sizeof(a))\n#define inf 1<<28\n#define mp make_pair\n#define pi acos(-1)\n#define pii pair\n#define fs first\n#define sc second\n#define cffi ios_base::sync_with_stdio(0);cin.tie(0);\n#define pob pop_back\n#define vec_ vector\n#define clr(a) a.clear()\n#define pb push_back\n#define eps 1E-7\n#define sf scanf\n#define pf printf\n#define all(a) a.begin(),a.end()\n#define allr(a) a.rbegin(),a.rend()\n#define fop freopen(\"input.txt\",\"r\",stdin);freopen(\"output.txt\",\"w\",stdout);\n#define scch(a) scanf(\" %c\",&a)\n#define scll1(a) scanf(\" %I64d\",&a)\n#define scll2(a,b) scanf(\" %I64d %I64d\",&a,&b)\n#define scll3(a,b,c) scanf(\" %I64d %I64d %I64d\",&a,&b,&c)\n#define sci1(a) scanf(\" %d\",&a)\n#define sci2(a,b) scanf(\" %d %d\",&a,&b)\n#define sci3(a,b,c) scanf(\" %d %d %d\",&a,&b,&c)\n#define scd1(a) scanf(\" %lf\",&a)\n#define scd2(a,b) scanf(\" %lf %lf\",&a,&b)\n#define scd3(a,b,c) scanf(\" %lf %lf %lf\",&a,&b,&c)\n#define sz(a) a.size()\n#define ll long long\n#define ull unsigned long long\n#define dd double\nusing namespace std;\n\ntemplate void deb(T1 e){cout< void deb(T1 e1,T2 e2){cout< void deb(T1 e1,T2 e2,T3 e3){cout< void deb(T1 e1,T2 e2,T3 e3,T4 e4){cout< void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout< void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout< string toString(T n){ostringstream oss;oss<>r;return r;}\n//struct point{int x, y; point () {} point(int a, int b) {x = a, y = b;}};\n//template T lcm(T a, T b){return (a/__gcd(a,b)) * b;}\n//ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}return R;}\n//int X[]={0,-1,-1,-1,0,1,1,1};\n//int Y[]={-1,-1,0,1,1,1,0,-1};\n//int X[]={-1,0,1,0};\n//int Y[]={0,1,0,-1};\n//int X[]={1,1,2,2,-1,-1,-2,-2};//knight move//\n//int Y[]={2,-2,1,-1,2,-2,1,-1};//knight move//\n\n#define mt 23\n#define mod\n\nint dp[(1<adj[mt+3];\n\nint solve(int pos,int mask)\n{\n if(pos == n)\n return 0;\n int &ret=dp[mask];\n if(ret != -1)\n return ret;\n ret=inf;\n int i,j,tmask;\n pii temp;\n for(i=0;i>n;\n for(i=0;i>arr[i];\n\n for(i=0;i= inf)\n deb(-1);\n else\n deb(ret);\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "bitmasks"], "code_uid": "fe37398e9c52d565140f1442d95088fd", "src_uid": "359f5d1264ce16c5c5293fd59db95628", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#define pb push_back\n#define mpp make_pair\n#define PI acos(-1)\n/*************NOTES*********************\\\nXOR operation : same hoile 0, naile 1\n24 = 2^3 * 3 ^ 1 = ( 3 + 1 ) * ( 1 + 1 ) = 8 divisor\n\n***************************************/\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef pair < int , int > pii;\nconst ll inf = 1e9;\nconst ll mod = 1e9 + 7;\nconst double eps = 1e-8;\nconst ll MAX = 1e7 + 20;\n\ntemplate< class T > T gcd(T a, T b) { return (b != 0 ? gcd(b, a%b) : a); }\ntemplate< class T > T lcm(T a, T b) { return (a / gcd(a, b) * b); }\n\n/*----------------------Graph Moves----------------*/\n//const int fx[]={+1,-1,+0,+0};\n//const int fy[]={+0,+0,+1,-1};\n//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move\n//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move\n//const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move\n//const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move\n/*------------------------------------------------*/\n\nll BM(ll B,ll P,ll M){ ll R=1; while(P>0) { if(P&1){ R=(R*B)%M;}P/=2;B=(B*B)%M;}return (ll )R;}\nll MI(ll x, ll m ){ return BM(x,m-2,m); }\n\n\nint arr[10005], brr[10005];\nint main ( ){\n\n #ifdef swapnil\n freopen(\"in.txt\",\"r\",stdin );\n //freopen(\"out.txt\",\"w\",stdout );\n #endif // swapnil\n\n int n , l;\n cin >> n >> l;\n for( int i = 0; i < n; i++ ) cin >> arr[i];\n for( int i = 0; i < n; i++ ) cin >> brr[i];\n for( int i = 0; i <= l; i++ ){\n for( int ii = 0; ii < n; ii++ ) { arr[ii] = ( arr[ii] + 1 ) % l ;}\n sort( arr, arr + n );\n bool ok = true;\n for( int ii = 0; ii < n; ii++ ){\n if( arr[ii] != brr[ii] ) {\n ok = false;\n break;\n }\n }\n if( ok ) {\n cout << \"YES\\n\";\n return 0;\n }\n }\n cout << \"NO\\n\";\n\n\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation"], "code_uid": "fca7480f78fa020a2dfdceb8bc99e906", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx\")\n\n//#include\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define _USE_MATH_DEFINES\n#define ll long long\n#define ins Not Needed Thing\n#define ull unsigned long long\n#define ld long double\n// Yeah Yeah\n#define Accepted 0\n#define pb push_back\n// Ora Ora, Ora Ora, Ora fat\n#define pii pair\n#define pll pair\n#define mp make_pair\n// Aydin day aydirinday\n#define sz(x) (int)(x.size())\n#define all(x) x.begin(),x.end()\n// @Im@5@Im@5 @Im@5@Im@5\n#define F first\n#define S second\n// Skyrim dlya nordov (c) Roflakopter\n#define SORRY FUL Accepted \n#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)\n// Skr Skr v chernih Naykax (c) ZzzzZzzzzZz\n#define Toktama Kazakhstan \n// TOKTAMA!\n\nusing namespace std;\n\nconst double eps = 0.000001;\nconst ld pi = acos(-1);\nconst int maxn = 1e7 + 9;\nconst int mod = 1e9 + 7;\nconst ll MOD = 1e18 + 9;\nconst ll INF = 1e18 + 123;\nconst int inf = 2e9 + 11;\nconst int mxn = 1e6 + 9;\nconst int N = 3e8 + 1; \nconst int PRI = 555557;\nconst int pri = 997;\n\nint tests = 1;\nint l, r;\nbitset f;\n\nstring s;\nint cnt[31];\nint cur, res;\nint ans;\n\ninline void Solve () {\n\t//easy\n\tcin >> l >> r;\n for (int i = 3; 1ll * i * i <= r; i += 2)\n\t\tif(!f[i])\n\t\t\tfor (ll j = 1ll * i * i; j <= r; j += i)\n\t\t\t\tf[j] = 1;\n\t\t\t\n\n\tfor (int i = 5; i <= r; i += 4)\n\t\tif(!f[i] && i >= l)\n\t\t\tans ++;\n\n\tcout << ans + (2 >= l && 2 <= r);\n}\n\nint main () {\n\tSpeedForce;\n//\tfreopen(\".in\", \"r\", stdin);\n//\tfreopen(\".out\", \"w\", stdout);\t\n\t// cin >> tests;\n\twhile(tests --) {\n\t\tSolve ();\n\t\t// Ee Zadrot\n\t}\n\n\treturn Accepted; \n}", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "e13e202882a43f15406df4adf88b6686", "src_uid": "55a83526c10126ac3a6e6e5154b120d0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \nusing namespace std;\n\nconst int N = 1000000;\n\ntypedef long long ll;\nll A[N];\n/*\nvoid Eratosfen()\n{\n\n\tfor(ll i=2; i*i>m;\n\tif(m<3)sum=m;\n\telse if(m%2)sum=m*(m-1)*(m-2);\n\telse if(m%3)sum=m*(m-1)*(m-3);\n\telse sum=(m-1)*(m-2)*(m-3);\n\tcout<\nusing namespace std;\ntypedef long long int ll;\n#define ft first\n#define sd second\n#define pb push_back\n#define mp make_pair\nint main()\n{\n ios::sync_with_stdio(0);cin.tie(0);\n ll n,m,k,x,y,ans1=0,ans2=0,mini=0,maxi=0,ex=0;\n cin>>n>>m>>k>>x>>y;\n if(k0)maxi++;\n if(i==0)mini=maxi;\n else mini=maxi-1;\n ex=mini;\n if(i>=y)ex+=1;\n }\n else\n {\n mini=1;maxi=1;ex=1;\n k=k-(n*m);\n ll j=k/((n-1)*(m));\n ll i=k%((n-1)*(m));\n if(n>2)\n {maxi+=j;\n if(i>0)maxi+=1;\n }\n else{\n maxi+=j/2;\n if(j%2==1)maxi++;\n else if(j%2==0 && i>0)maxi++;\n }\n mini+=(j/2);\n// cout<\n#define int long long\nusing namespace std;\nint n,k,cnt,l,r,mp[10000010];\ninline int check(int mid){\n\tint l=mid,r=mid+1,res=0;\n\tif(mid&1)\tr--;\n\twhile(l<=n){\n\t\tres+=min(n,r)-l+1;\n\t\tl*=2,r*=2;\tr++;\n\t}\n\treturn res>=k;\n}\nsigned main(){\n\tcin>>n>>k;\tl=1,r=n;\n\tif(n==k)\treturn puts(\"1\"),0;\n\twhile(l>1;\n\t\tif(check(mid))\tl=mid;\n\t\telse{\n\t\t\tint flag=0;\n\t\t\tfor(int i=min(mid+1,n);i>=mid;i--)\tif(check(i)){\n\t\t\t\tl=i; flag=1;\tbreak;\n\t\t\t}\n\t\t\tif(!flag)\tr=mid-1;\t\n\t\t}\n\t}\n\tcout<\n\nusing namespace std;\nint report(int n,int j){\n int d, conv=0,pot=1,x;\n x=n;\n while(x>0){\n d=x%j;\n x=x/j;\n conv=conv+d*pot;\n pot *=10;\n }\n return conv;\n \n}\nint main()\n{\n int n,j=1;\n cin>>n;\n while(j!=n){\n for(int i=1;i\nusing namespace std;\n\nint main()\n{\n string a;\n cin>>a;\n int x,y;\n x=y=0;\n for(int i=0;i\nusing namespace std;\n\n#define rep(i,a,b) for(int i = a; i < b; i++)\ntypedef pair ii;\ntypedef vector vii;\ntypedef vector vi;\ntypedef long long ll;\n\nbool check(int place, int s) {\n int i = (s / 50) % 475;\n rep(a,0,25) {\n i = (i*96+42)%475;\n if(place == i+26) return true;\n }\n return false;\n}\n\nint main() {\n int p,y,x;\n cin >> p >> y >> x;\n vii all;\n int ne = y;\n rep(i,0,100000) if(y-i*50 >= 0) all.push_back(ii(0,y-i*50));\n rep(i,0,100000) {\n all.push_back(ii(i,ne));\n all.push_back(ii(i+1,ne+50));\n ne += 100;\n }\n int bst = 1000000;\n rep(i,0,all.size()) {\n if(all[i].second >= x) {\n if(check(p,all[i].second)) {\n bst = min(bst,all[i].first);\n }\n }\n }\n cout << bst << endl;\n \n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "d163774a0fc72e56735b10e2c582c617", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "#include\r\nusing namespace std;\r\nconst int mod=998244353;\r\n\r\nint fac[255],ifac[255];\r\nint ksm(int a,int b)\r\n{\r\n\tint res=1;\r\n\twhile(b)\r\n\t{\r\n\t\tif(b&1)res=1LL*res*a%mod;\r\n\t\tb>>=1 , a=1LL*a*a%mod;\r\n\t}\r\n\treturn res;\r\n}\r\nint ny(int x){return ksm(x,mod-2);}\r\n\r\nint C2(int x){return x*(x-1)/2;}\r\n\r\nint n,k;\r\nint dp[255][255];\r\n\r\nint main()\r\n{\r\n\tscanf(\"%d%d\",&n,&k);\r\n\tfac[0]=1;for(int i=1;i<=250;++i)fac[i]=1LL*fac[i-1]*i%mod;\r\n\tfor(int i=0;i<=250;++i)ifac[i]=ny(fac[i]);\r\n\t\r\n\tdp[0][0]=1;\r\n\tfor(int kk=1;kk<=k;++kk)\r\n\t{\r\n\t\tdp[kk][0]=1;\r\n\t\tfor(int j=1;j<=n-1;++j)\r\n\t\t{\r\n\t\t\tdp[kk][j]=0;\r\n\t\t\tfor(int jj=0;jj<=j;++jj)//kk\u8fd9\u79cd\u6743\u503c\u53d6jj\u6761\r\n\t\t\t{\r\n\t\t\t\tdp[kk][j]+=1LL*dp[kk-1][j-jj]*\r\n\t\t\t\t\tksm(k-kk+1,jj*(j-jj)+C2(jj))%mod*ifac[jj]%mod;\r\n\t\t\t\tdp[kk][j]%=mod;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tint ans=1LL*fac[n-1]*dp[k][n-1]%mod;\r\n\tprintf(\"%d\\n\",ans);\r\n\treturn 0;\r\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "graph matchings"], "code_uid": "e1227934d228b7a60bf32510935157ae", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n#define ll long long \n#define vc vector\n#define pb push_back\n#define pii pair\n#define pll pait\n#define ft first\n#define sd second\n#define up(it,vec) for(auto it=vec.begin();it!=vec.end();it++)\n#define dn(it,vec) for(auto it=vec.rbegin();it!=vec.rend();it++)\n// #define int long long\n\nll mypow(ll a,ll b,ll mod){\n ll ret=1;\n while(b){\n if(b&1)ret=ret*a%mod;\n a=a*a%mod;b>>=1;\n }\n return ret;\n}\nconst int inf=1e9;\nint dp[110][110][110][2];\nint a[110];\nint vis[110];\nsigned main(){\n ios::sync_with_stdio(0);cin.tie(0);\n int n;cin>>n;\n for(int i=1;i<=n;i++){\n cin>>a[i];\n vis[a[i]]=1;\n }\n int ji=0,o=0;\n for(int i=1;i<=n;i++){\n if(!vis[i]){\n if(i%2)ji++;\n else o++;\n }\n }\n for(int i=1;i<=n;i++){\n if(a[i]!=0){\n for(int j=0;j<=100;j++){\n for(int k=0;k<=100;k++){\n if(a[i]%2){\n dp[i][j][k][1]=min(dp[i-1][j][k][1],dp[i-1][j][k][0]+1);\n dp[i][j][k][0]=1e9;\n }\n else{\n dp[i][j][k][0]=min(dp[i-1][j][k][1]+1,dp[i-1][j][k][0]);\n dp[i][j][k][1]=1e9;\n }\n }\n }\n }\n else{\n for(int j=0;j<=100;j++){\n for(int k=0;k<=100;k++){\n dp[i][j][k][1]=min(j==0?inf:dp[i-1][j-1][k][1],j==0?inf:(dp[i-1][j-1][k][0]+1));\n dp[i][j][k][0]=min(k==0?inf:(dp[i-1][j][k-1][1]+1),k==0?inf:dp[i-1][j][k-1][0]);\n }\n }\n }\n }\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define F first\n#define S second\n#define eps 1e-8\n#define pb push_back\n#define ppb pop_back\n#define mp make_pair\n#define lb lower_bound\n#define ub upper_bound\n#define INF 2000000000\n\ntypedef long long ll;\n\nusing namespace std;\nll l, r, ans;\nint q, Q, p; \nbool w[99], W[99];\nint main()\n{\n\tios::sync_with_stdio(0);\n\tcin >> l >> r;\n\twhile(l){\n\t\tw[q++] = l % 2;\n\t\tl >>= 1;\n\t}\n\twhile(r){\n\t\tW[Q++] = r % 2;\n\t\tr >>= 1;\n\t}\n\tfor(int i = Q; i >= 0; i--)\n\t\tif(w[i] != W[i]){\n\t\t\tp = i + 1;\n\t\t\tbreak;\n\t\t}\n\tans = (1ll << p) - 1ll;\n\tcout << ans;\n\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "323c6bb0d06ecb72d1723b85d77867ec", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \"iostream\"\n#include \"math.h\"\n#include \"algorithm\"\n#include \"fstream\"\n#include \"set\"\n#include \"iomanip\"\n#include \"vector\"\n#include \"string\"\n#include \"map\"\n#include \"queue\"\n#include \"stack\"\n\nusing namespace std;\n\n#define ll long long\n#define w while\n#define elif else if\n#define br break\n#define flag bool\n#define con continue\n#define MMax 1001\n#define Eps 1e-8\n\nll n, su = 0;\nstring a;\n\nflag testfor(ll k) {\n\tll suka = 0;\n\tfor (ll i = 0; i < n; i++) {\n\t\tsuka += a[i] - 48;\n\t\tif (suka == k) {\n\t\t\tsuka = 0;\n\t\t\tcon;\n\t\t}\n\t\tif (suka > k)\n\t\t\treturn 0;\n\t}\n\treturn 1;\n}\n\nint main() {\n\tcin >> n;\n\tcin >> a;\n\tfor (ll i = 0; i < n; i++) {\n\t\tsu += a[i] - 48;\n\t}\n\tll k;\n\tif (su == 0) {\n\t\tcout << \"YES\";\n\t\treturn 0;\n\t}\n\tfor (ll i = 2; i <= su; i++) {\n\t\tif (su % i == 0) {\n\t\t\tk = su / i;\n\t\t\tif (testfor(k)) {\n\t\t\t\tcout << \"YES\";\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\tcout << \"NO\";\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "6e2cc59a36a3710199c877f6050010b1", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tstring s;\n\tcin >> s;\n\tint th = s[0] - '0';\n\tint hun = s[1] - '0';\n\tint dec = s[2] - '0';\n\tint one = s[3] - '0';\n\tint n = th * 1000 + hun * 100 + dec * 10 + one;\n\tdo {\n\t\tn += 1;\n\t\tstringstream out;\n\t\tout << n;\n\t\ts = out.str();\n\t\tth = s[0] - '0';\n\t\thun = s[1] - '0';\n\t\tdec = s[2] - '0';\n\t\tone = s[3] - '0';\n\t} while (!(th != hun && hun != dec && dec != one && one != th && one != hun && th != dec));\n\tcout << n;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "0ec06100224975eabe1ff3c977e586b3", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n int x,y,z,t1,t2,t3;\n cin>>x>>y>>z>>t1>>t2>>t3;\n int ans1,ans2;\n ans1 = (abs(x-y))*t1;\n ans2 = (2*t3 + (abs(x-z))*t2) + (t3 + abs(x-y)*t2);\n //cout<\n#include\nusing namespace std;\nint n;\nint ans;\nconst int maxn=1e6+10;\nint sum[maxn];\nint main()\n{\n\tcin>>n;\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tcin>>sum[i];\n\t}\n\tsort(sum+1,sum+1+n);\n\tif(sum[n]<=25)\n\t{\n\t\tcout<<\"0\"<\n#include\n#include\n#include\nusing namespace std;\nconst int maxn = 2e5 + 7;\n\nint main()\n{\n int n,a,b;\n scanf(\"%d%d%d\",&n,&a,&b);\n int ans = 0;\n if(a > b)\n swap(a,b);\n for(int i = 1;i <= a;i++)\n {\n if(a / i + b / i >= n)\n ans = max(i,ans);\n }\n printf(\"%d\\n\",ans);\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "binary search"], "code_uid": "55e5f705f5fa944a4432aa6fd8125aaa", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n\nusing namespace std;\n\nint a[105];\nint n;\n\nvoid f(int m)\n{\n\tint i;\n\tint temp;\n\tif(m>=0&&m>-1)\n\t{\n\t if(a[m]>a[m+1]&&m==n-2)\n\t {\n\t\ttemp=a[m];\n\t\ta[m]=a[m+1];\n\t\ta[m+1]=temp;\n\t\tf(m-1);\n\t }\n\t if(a[m]>a[m+1]&&m>n;\n\tint i;\n\tfor(i=0;i>a[i];\n\tf(n-2);\n\tfor(i=0;i\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\nint ans,l,r;\n\nint main()\n{\n\tcin>>l>>r;\n\twhile(l!=r)\n\t{\n\t\tif(l>r)\n\t\t{\n\t\t\tr++;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(r&1)//\u5947\u6570\n\t\t\t{\n\t\t\t\tr++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tr/=2;\n\t\t\t}\n\t\t}\n\t\tans++;\n\t}\n\tcout<\nusing namespace std;\nint p1,p2,p3,p4,n,m,sum=0;\nint main()\n{\n\tscanf(\"%d%d%d%d%d%d\",&p1,&p2,&p3,&p4,&n,&m);\n\tfor(int i=n;i<=m;i++)\n\t{\n\t\tif(i%p1!=i) continue;\n\t\tif(i%p2!=i) continue;\n\t\tif(i%p3!=i) continue;\n\t\tif(i%p4!=i) continue;\n\t\tsum++;\n\t}\n\tprintf(\"%d\",sum);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation", "number theory"], "code_uid": "3a2d4b7de97325919b1e23557382a024", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\nusing namespace std;\ntypedef long long ll;\nconst int N=1e5+7, INF=0x3f3f3f3f;\nvoid read(int &x){\n int f=1;x=0;char s=getchar();\n while((s<'0')|(s>'9')){if(s=='-')f=-1;s=getchar();}\n while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}\n x*=f;\n}\nvoid write(int x){\n if(x==0){putchar(48);return;}\n int len=0,dg[20];\n while(x>0){dg[++len]=x%10;x/=10;}\n for(int i=len;i>=1;i--)putchar(dg[i]+48);\n}\nint main(){\n int n, m, i, j ,a, b, c=INF, d=INF, e=INF, f=INF;\n scanf(\"%d%d%d%d%d%d\", &n, &m, &i, &j, &a, &b);\n if(i==1&&j==1||i==1&&j==m||i==n&&j==1||i==n&&j==m){\n puts(\"0\");\n return 0;\n }\n if(i+a>n&&i-a<1||j+b>m&&j-b<1){\n puts(\"Poor Inna and pony!\");\n return 0;\n }\n n--, m--, i--, j--;\n if(i%a==0&&j%b==0&&(i/a)%2==(j/b)%2){\n c=max(i/a, j/b);\n }\n if((n-i)%a==0&&j%b==0&&((n-i)/a)%2==(j/b)%2){\n d=max((n-i)/a, j/b);\n }\n if(i%a==0&&(m-j)%b==0&&(i/a)%2==((m-j)/b)%2){\n e=max((i/a), ((m-j)/b));\n }\n if((n-i)%a==0&&(m-j)%b==0&&(((n-i)/a)%2)==(((m-j)/b)%2)){\n f=max(((n-i)/a), ((m-j)/b));\n }\n if(c!=INF||d!=INF||e!=INF||f!=INF)\n printf(\"%d\\n\", min(c, min(d, min(e, f))));\n else puts(\"Poor Inna and pony!\");\n return 0;\n}\n/*2018-07-31 20:48:40.175*/", "lang_cluster": "C++", "tags": ["greedy", "implementation"], "code_uid": "b7964508a7674be40e37968ec2da2226", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n\nconst int maxn=105;\n\nint n,a[maxn];\n\nint main(){\n\tscanf(\"%d\",&n);\n\tfor (int i=1;i<=n;i++){\n\t\tscanf(\"%d\",&a[i]);\n\t}\n\tint ans=0;\n\tfor (int i=0;i<=n;i++){\n\t\tint s=0;\n\t\tfor (int j=1;j<=i;j++){\n\t\t\tif (a[j]==0) s++; \n\t\t}\n\t\tfor (int j=i+1;j<=n;j++){\n\t\t\tif (a[j]==1) s++;\n\t\t}\n\t\tans=max(ans,s);\n\t}\n\tcout<\nusing namespace std;\n\nint main()\n{\n char tmp;\n bool check[26];\n memset(check,false,26);\n int n;\n cin>>n;\n if(n<26)\n {cout<<\"NO\";return 0;}\n while(n--)\n {\n cin>>tmp;\n if(tmp<91)\n {check[tmp-65]=true;}\n else\n {check[tmp-97]=true;}\n }\n for(int i=0;i<26;i++)\n {if(!check[i]) {cout<<\"NO\";return 0;}}\n cout<<\"YES\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "bab2a7794a3804f8e4b09c567e43bfe2", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int n;\n cin>>n;\n if(n%2==0)\n cout<<0;\n else\n cout<<1;\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "71032e4cee51caa7696cd8941715b914", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define Si(a) scanf(\"%d\",&a)\n#define Sl(a) scanf(\"%lld\",&a)\n#define Sd(a) scanf(\"%lf\",&a)\n#define Ss(a) scanf(\"%s\",a)\n#define Pi(a) printf(\"%d\\n\",(a))\n#define Pl(a) printf(\"%lld\\n\",(a))\n#define Pd(a) printf(\"%lf\\n\",(a))\n#define Ps(a) printf(\"%s\\n\",(a))\n#define W(a) while(a--)\n#define mem(a,b) memset(a,(b),sizeof(a))\n#define inf 0x3f3f3f3f\n#define maxn 1000010\n#define mod 1000000007\n#define PI acos(-1.0)\n#define LL long long\nusing namespace std;\n\nint main()\n{\n int h1,h2,a,b;\n Si(h1);Si(h2);Si(a);Si(b);\n int nowh=h1;\n int t=0;\n nowh+=a*8;\n if(nowh>=h2)\n {\n Pi(0);\n return 0;\n }\n nowh-=b*12;\n nowh+=a*4;\n if(nowh>h2)\n {\n Pi(1);\n return 0;\n }\n int v=a*4-b*12,day=1;\n if(a<=b)\n {\n printf(\"-1\\n\");\n return 0;\n }\n for(int i=1;i<=10000000;i++)\n {\n nowh+=a*8;\n if(nowh>=h2)\n {\n Pi(day);\n return 0;\n }\n nowh+=v;\n day++;\n if(nowh>h2)\n {\n Pi(day);\n return 0;\n }\n }\n Pi(-1);\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "067a95337e090e21c7405678843b6291", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \nusing namespace std;\n\nint main()\n{\n int n,m;\n cin>>n>>m;\n if(n<0||n>100||m<0||m>100)\n return 0;\n int ans=0;\n ans+=n;\n while((float)n/(float)m>1){\n ans+=n/m;\n n=n/m+n%m;\n }\n ans+=n/m;\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define li \tlong long int\n#define rep(i,to)\tfor(li i=0;i<((li)(to));i++)\n#define pb \tpush_back\n#define sz(v) \t((li)v.size())\n#define bit(n) \t(1ll<<(li)(n))\n\n\n\n\n#define MOD 1000000007\n//\tp.180\n//\n#define MAT_TYPE li\n#define MAT_MOD MOD\n//\n\n#define MAT_MAT vector >\nMAT_MAT mul(MAT_MAT a,MAT_MAT b){\n\tMAT_MAT res(sz(a),vector(sz(b[0]),0));\n\trep(i,sz(a))rep(j,sz(b[0]))rep(k,sz(a[0])) res[i][j]=(res[i][j]+a[i][k]*b[k][j])%MAT_MOD;\n\treturn res;\n}\nMAT_MAT pow(MAT_MAT a,li n){\n\tMAT_MAT res(sz(a),vector(sz(a[0]),0));\n\trep(i,sz(a)) res[i][i]=1;\n\twhile(n){\n\t\tif(n%2) res=mul(res,a);\n\t\ta=mul(a,a);\n\t\tn/=2;\n\t}\n\treturn res;\n}\n\nbool bad(li a,li b){\n\tif(a==b) return true;\n\tif(a+b==3) return true;\n\treturn false;\n}\n\nbool bad(li a,li b,li c){\n\tif(a==1 && b==0 && c==2) return true;\n\tif(a==2 && b==0 && c==1) return true;\n\treturn false;\n}\n\nli cal1(li num){\n\tMAT_MAT mat(32,vector(32,0));\n\trep(i,16) mat[i+16][i]=mat[i+16][i+16]=1;\n\trep(i,4)rep(j,4)rep(k,4){\n\t\tif(bad(i,j)) continue;\n\t\tif(bad(j,k)) continue;\n\t\tif(bad(i,j,k)) continue;\n\t\tmat[k*4+j][j*4+i]=1;\n\t}\n\tMAT_MAT right(32,vector(1,0));\n\trep(i,4)rep(j,4)if(!bad(i,j)) right[i*4+j][0]=1;\n\tmat=pow(mat,num-1);\n\tmat=mul(mat,right);\n\tli res=4;\n\trep(i,16) res+=mat[i+16][0];\n\treturn res;\n}\n\nli cal0(li num){\n\tif(num<=0) return 0;\n\treturn ((cal1(num)+cal1((num+1)/2))/2)%MOD;\n}\n\nint main(){\n\tli left,right;\n\tcin>>left>>right;\n\tcout<<(cal0(right)-cal0(left-1)+MOD)%MOD<\n#include \nusing namespace std;\n \nint main()\n{ long long int w1,h1,w2,h2;\n cin>>w1>>h1>>w2>>h2;\n if(w1==w2){\n cout<<2*w1+4+2*h1+2*h2;\n }\n else{\n cout<>a>>b>>c){\n int p=a;\n int q=b;\n int z=c;\n int count=0;\n int am,pm;\n if(a*2<=b && a*4<=c) cout<1 && q>2 && z>4) cout<=1 && q>=2 && z>=4)) cout<<1+2+4<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long int64;\n\n#define forn(i, n) for(int i = 0; i < (int)(n); i++)\n#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)\n#define pb push_back\n#define mp make_pair\n#define all(a) a.begin(), a.end()\n\nconst int INF = (int)1E9;\nconst int64 INF64 = (int64)1E18;\nconst long double EPS = 1E-8;\nconst long double PI = 3.1415926535897932384626433832795;\n\nint days[2][12]={\n {31,28,31,30,31,30,31,31,30,31,30,31},\n {31,29,31,30,31,30,31,31,30,31,30,31}\n};\n\nint leap(int y){\n return (y%4)?0:1;\n}\n\nbool correct(int a,int b,int c){\n if (b>=1 && b<=12){\n if (a>=1 && a<=days[leap(c)][b-1])\n return true;\n }\n return false;\n}\n\n/*int gettime(int a,int b,int c){\n int res=0;\n forn(i,c)\n if (i%4)\n res+=365;\n else\n res+=366;\n forn(i,b)\n res+=days[leap(c)][i];\n res+=a-1;\n return res;\n}*/\nint d,e,f;\nbool check(int a,int b,int c){\n if (c\n#define ll long long\nusing namespace std;\n\nll mo = 1e9+7;\nll a,b,n,x;\n\nll ksmi(ll x,ll n){\n if (n == 0) return 1;\n if (n == 1) return x;\n ll ans;\n ans = ksmi(x,n/2);\n ans = (ans*ans)%mo;\n if (n&1==1) ans = (ans*x)%mo;\n return ans;\n}\n\nint main(){\n cin>>a>>b>>n>>x;\n ll ans;\n if (a == 1){\n ans = x;\n n %= mo;\n ans += (n*b)%mo;\n ans %= mo;\n }\n else{\n ll tmp = ksmi(a,n);\n ans = tmp - 1;\n if (ans == -1) ans += mo;\n ans = (ans*b)%mo;\n ans = (ans*ksmi(a-1,mo-2))%mo;\n ans = ((tmp*x)%mo+ans)%mo;\n }\n cout<\n#define ll long long\n#define vect vector\n#define pb push_back\n#define f(n) for(i=0;i\nusing namespace std;\nmain()\n{ll t;\ncin>>t;\nwhile(t--)\n{\n\tll n,k,d;\n\tcin>>n>>k>>d;\n\tll i;\n\tMap m;\n\tll a[n];\n\tf(n)\n\t\tcin>>a[i];\n\tf(d)\n\t\t\tm[a[i]]+=1;\n\tll ans=m.size();\n//\tcout<\n#include \n#include \n\nusing namespace std;\n\nvector v;\n\nlong long pow10(int n)\n{\n long long s = 1;\n for (int i = 0; i < n; i ++) s *= 10;\n return s;\n}\n\nlong long supp_man(long long n)\n{\n long long s = 0, tmp = n;\n for (int i = log10(n); i > 0; i --)\n {\n s += tmp / pow10(i);\n tmp -= (tmp / pow10(i)) * pow10(i);\n }\n return n - s;\n}\n\nlong long nine_s(int n)\n{\n long long s = 0;\n for (int i = 0; i < n; i ++) s += 9 * pow10(i) ;\n return s;\n}\n\nint main()\n{\n long long h, n, s, m = 0;\n cin >> n >> s;\n long long tmp = s;\n for (int i = (int)log10(s + 1); i > 0; i --)\n {\n long long t = s / nine_s(i);\n s -= t * nine_s(i);\n v.push_back(t);\n }\n int k = v.size();\n for (int i = 0; i < k; i ++) m += v[k - 1 - i] * pow10(i);\n if (supp_man(m * 10) >= tmp) h = n - m * 10 + 1;\n else h = n - (m + 1) * 10 + 1;\n if (h >= 0) cout << h;\n else cout << 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "binary search"], "code_uid": "e5365b7e1771a34f87941cf28e99530f", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "\t#include\n\tusing namespace std;\n\ttypedef long long ll;\n\tint main()\n\t{\n\t\t\n\tstring s;\n\tcin>>s;\n\tvector a(6);\n\ta[0]=(int)s[0]-'1'+1;\n a[1]=(int)s[1]-'1'+1;\n a[2]=(int)s[2]-'1'+1;\n a[3]=(int)s[3]-'1'+1;\n a[4]=(int)s[4]-'1'+1;\n a[5]=(int)s[5]-'1'+1;\n //cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\ntypedef long long ll;\n#define rep(i,a,b) for (int i = a; i < b; i++)\n#define all(x) x.begin(), x.end()\n#define sz(a) (int)a.size()\n#define sqr(x) ((x) * (x))\n#define pi pair\n#define mk(a, b) make_pair(a, b)\n#define nextI nextInt()\n#define nextD nextDouble()\n#define nextL nextLong()\n#define nextC nextChar()\n#define line newLine()\nint nextInt(){ int x; scanf(\"%d\", &x); return x; }\ndouble nextDouble(){ double x; scanf(\"%lf\", &x); return x; }\nll nextLong(){ ll x; scanf(\"%I64d\", &x); return x; }\nchar nextChar(){ char x; scanf(\"%c\", &x); return x; }\nvoid newLine(){ printf(\"\\n\"); }\nll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }\nll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }\nll pow(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }\nint countSetBit(ll n){ int ans = 0; while (n != 0){ n -= (n & -n); ++ans; } return ans; }\nll mod = (ll)(1e9 + 7ll);\nconst int N = 1000;\nconst int M = 10111;\nconst double eps = 1e-6;\nusing namespace std;\nint a[N];\nint b[N];\nint t[N];\nint main(){\n#ifdef HOME\n\tfreopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n#endif\n\tint n, m;\n\tcin >> n >> m;\n\tif (m <= 1){\n\t\tfor (int i = 1; i <= n; i++){\n\t\t\tcout << i << \" \";\n\t\t}\n\t\tline;\n\t\treturn 0;\n\t}\n\tmemset(b, -1, sizeof b);\n\tmemset(t, -1, sizeof t);\n\tfor (int i = 0; i < m; i++){\n\t\ta[i] = nextI;\n\t\tif (a[i] > n){\n\t\t\tputs(\"-1\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tbool vis[N] = { 0 };\n\tfor (int i = 1; i < m; i++){\n\t\tint val;\n\t\tif (a[i] == a[i - 1]) val = n;\n\t\telse if (a[i] > a[i - 1]) val = a[i] - a[i - 1];\n\t\telse val = a[i] + n - a[i - 1];\n\t\tif ((t[a[i - 1]] != -1 && t[a[i - 1]] != val)){\n\t\t\tputs(\"-1\");\n\t\t\treturn 0;\n\t\t}\n\t\telse if (vis[val] && t[a[i - 1]] != val)\n\t\t{\n\t\t\tputs(\"-1\");\n\t\t\treturn 0;\n\t\t}\n\n\t\tt[a[i - 1]] = val;\n\t\tvis[val] = 1;\n\t}\n\n\tfor (int i = 1; i <= n; i++){\n\t\tif (t[i] == -1){\n\t\t\tfor (int j = 1; j <= n; j++){\n\t\t\t\tif (!vis[j]){\n\t\t\t\t\tt[i] = j;\n\t\t\t\t\tvis[j] = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 1; i <= n; i++){\n\t\tcout << t[i] << \" \";\n\t}\n\tline;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "f9c4434f9570ddf8fa1ce99940dc5b50", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nconst int maxd=1000000007,N=1000000;\nconst double pi=acos(-1.0);\ntypedef long long ll;\nint n,m,a,b;\nll fac[1001000],invfac[1001000],mpow[1001000],npow[1001000];\n\nint read()\n{\n\tint x=0,f=1;char ch=getchar();\n\twhile ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}\n\twhile ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}\n\treturn x*f;\n}\n\nll A(int x,int y)\n{\n\tif ((x=1;i--) invfac[i]=(invfac[i+1]*(i+1))%maxd;\n\tmpow[0]=1;npow[0]=1;\n\tfor (i=1;i<=N;i++) \n\t {mpow[i]=(mpow[i-1]*m)%maxd;npow[i]=(npow[i-1]*n)%maxd;}\n}\n\nint main()\n{\n\tn=read();m=read();a=read();b=read();\n\tint i;\n\tinit();\n\t//for (i=1;i<=n;i++) cout << invfac[i] << \" \";cout << endl;\n\tll ans=0;\n\tfor (i=1;i\nusing namespace std;\n\n\n\n// #define DEBUG // TRACE \n// #ifdef DEBUG // TRACE\n#ifndef ONLINE_JUDGE\n#define trace(...) __f1(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f1(const char* name, Arg1&& arg1) {\n cout << name << \" : \" << arg1 << std::endl;\n}\ntemplate \nvoid __f1(const char* names, Arg1&& arg1, Args&&... args) {\n const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << \" : \" << arg1 << \" | \"; __f1(comma + 1, args...);\n}\n#define Trace(...) __f2(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f2(const char* name, Arg1&& arg1) {\n cerr << name << \" : \" << arg1 << std::endl;\n}\ntemplate \nvoid __f2(const char* names, Arg1&& arg1, Args&&... args) {\n const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << \" : \" << arg1 << \" | \"; __f2(comma + 1, args...);\n}\n#define debug if(T!=1){cout<\n// #include \n// #include \n// #include \n// using namespace __gnu_pbds;\n// #define fbo find_by_order\n// #define ook order_of_key\n// typedef tree, rb_tree_tag, tree_order_statistics_node_update> Set;\n\n\n\n#define int long long int //int64_t\n#define uint unsigned long long int // uint64_t\n#define ld long double\n#define setbits(x) __builtin_popcountll(x)\n#define zrobits(x) __builtin_ctzll(x)\n#define preci(x, y) fixed << setprecision(y) << x\n\n#define vint vector\n#define vvint vector>\n#define sz(a) (int)a.size()\n#define pb push_back\n#define vmin *min_element\n#define vmax *max_element\n#define max_pq priority_queue>\n#define min_pq priority_queue, greater>\n#define mint map\n#define pint pair\n#define mp make_pair\n#define F first\n#define S second\n\n#define all(x) x.begin(),x.end()\n#define ub upper_bound\n#define lb lower_bound\n#define bin binary_search\n#define revsort(v) sort(all(v), greater())\n#define min(a,b) min((int)a,(int)b)\n#define max(a,b) max((int)a,(int)b)\n#define min3(a,b,c) min(min(a,b),c)\n#define max3(a,b,c) max(max(a,b),c)\n\n#define f(i,a,b) for(int i=(a);i<(b);i++)\n#define rf(i,a,b) for(int i=(a);i>(b);i--)\n\nvoid ritikio();\n\n#define PI 3.1415926535897932384626433832795 // atan(1.0)*4.0;\nconst int inff = LLONG_MAX;\nconst int minff = LLONG_MIN;\nconst int inf = 1e18;\nconst int pmod = 998244353;\nconst int mod = 1e9 + 7;\nconst int maxm = 2e6 + 3;\nconst int N = 200 + 3;\nint T = 0;\n\ntemplate\nstruct Vec : public vector> \n{\n static_assert(D >= 1, \"Vector dimension must be greater than zero!\");\n template\n Vec(int n = 0, Args... args) : vector>(n, Vec(args...)){}\n};\ntemplate\nstruct Vec<1, T> : public vector \n{\n Vec(int n = 0, const T& val = T()) : vector(n, val) {}\n};\n//Vec<3, double> b(n, m, k, 3.14);\n\n\nstring s, t;\nint n, k;\nVec<3, int> dp(N, N, N, -1);\n\n\nint fun(int st_index, int moves_left, int cnt0 )\n{\n if (moves_left < 0) return -inf;\n if (st_index >= sz(s)) return 0;\n if (dp[st_index][moves_left][cnt0] != -1) return dp[st_index][moves_left][cnt0];\n\n char first = s[st_index];\n int f0 = (first == t[0]);\n int f1 = (first == t[1]);\n int f3 = (t[0] == t[1]);\n\n // keeping t[0]\n int res1 = fun(st_index + 1, moves_left - !f0, cnt0+1) + cnt0*f3;\n\n // keeping t[1]\n int res2 = fun(st_index + 1, moves_left - !f1, cnt0) + cnt0;\n\n // keeping as it is\n int res3 = 0;\n if(!f0 && !f1)\n res3 = fun(st_index + 1, moves_left, cnt0);\n\n\n dp[st_index][moves_left][cnt0] = max3(res1, res2, res3);\n\n return max3(res1, res2, res3);\n}\n\n\n\n\nvoid solve()\n{\n cin >> n >> k;\n cin >> s >> t;\n cout << fun(0,k,0);\n}\n\n\nsigned main()\n{\n ritikio();\n\n //precompute();\n\n\n int TT = 1;\n T = 0;\n //cin >> TT;\n\n while(++T < TT + 1)\n {\n debug;\n solve();\n }\n \n}\n\nvoid ritikio()\n{\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n#ifndef ONLINE_JUDGE\n freopen(\"input999.txt\", \"r\", stdin);\n freopen(\"output999.txt\", \"w\", stdout);\n //fclose(stdout);\n#endif\n}\n\n\n", "lang_cluster": "C++", "tags": ["strings", "dp"], "code_uid": "70a2743c0233d23f852bd9d90908bf31", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\nstring s,s1;\nint main() {\n while(cin>>s) {\n int k1,k2;\n int a,b,c,d;\n cin>>s1;\n a=s[0]-'0';\n b=s[1]-'0';\n c=s[3]-'0';\n d=s[4]-'0';\n int aa,bb,cc,dd;\n aa=s1[0]-'0';\n bb=s1[1]-'0';\n cc=s1[3]-'0';\n dd=s1[4]-'0';\n int e,f;\n e=a*10+b;\n f=c*10+d;\n int ee,ff;\n ee=aa*10+bb;\n ff=cc*10+dd;\n if((e*60+f)<(ee*60+ff)) {\n int sum=24*60+f+e*60;\n sum-=ee*60+ff;\n k1=sum/60,k2=sum%60;\n if(k1<=9) {\n cout<<0<\nusing namespace std;\ntypedef unsigned long long int ulli;\ntypedef long long int lli;\nlli p[500];\nint main()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"inp.txt\", \"r\" , stdin);\n freopen(\"output.txt\", \"w\", stdout);\n #endif\n lli mr,mc,f=0,r1,r2,c1,c2;\n cin>>mr>>mc>>r1>>c1>>r2>>c2;\n lli t1=mr,t2=mc,r=mr,c=mc;\n if((r1<=mr)&&(c1<=mc)){\n if((r1<=mr)&&(c1<=mc)){\n mr-=r1;\n mc-=c1;\n if((r2<=mr&&c2<=c)||(r2<=mc&&c2<=r)||(c2<=mr&&r2<=c)||(c2<=mc&&r2<=r))\n \t{cout<<\"YES\";\n return 0;}\n }}\n if((r1<=t2)&&(c1<=t1)){\n t1-=c1;\n \t\t t2-=r1;\n if((r2<=t1&&c2<=c)||(r2<=t2&&c2<=r)||(c2<=t1&&r2<=c)||(c2<=t2&&r2<=r))\n \t { cout<<\"YES\";\n \treturn 0;}\n }\n \n cout<<\"NO\";\n return 0;\n }\n \t", "lang_cluster": "C++", "tags": ["constructive algorithms", "implementation"], "code_uid": "bd44d76d21942cba736b0153b8d105ce", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\ntypedef long long ll;\n#define pb push_back\n#define ull unsigned long long\n#define mp make_pair\nconst int maxn=4e5+5;\nconst ll inf=2e5+7;\nconst ll mod=1e9+7;\n \n \nll n,m,k;\n \n \nchar s1[maxn],s2[maxn];\nstring a,b;\nvectornum[26];\nll ans=0;\nint len1,len2;\n \nint l[maxn],r[maxn];\nint main(){\n \n scanf(\"%s%s\",s1,s2);\n a=s1;b=s2;\n len1=a.size(),len2=b.size();\n for(int i=0;i=0;i--){\n if(j<0)break;\n if(a[i]==b[j]&&r[j]==-1){\n r[j]=i;\n j--;\n }\n }\n \n j=0;\n for(int i=0;i=len2)break;\n if(a[i]==b[j]&&l[j]==-1){\n l[j]=i;\n j++;\n }\n }\n \n \n ans=max(ans,max((ll)r[0],len1-l[len2-1]-1LL));\n \n for(int i=1;i\n#include \n#include \nusing namespace __gnu_pbds;\nusing namespace std;\n \ntypedef long long ll;\ntypedef long double ldob;\ntypedef pair ii;\ntypedef vector vi;\n\n// OST\ntemplate \nusing ordered_set = __gnu_pbds::tree, rb_tree_tag, tree_order_statistics_node_update>;\n\n// from: https://codeforces.com/blog/entry/62393\nstruct custom_hash {\n\tstatic uint64_t splitmix64(uint64_t x) {\n\t\t// http://xorshift.di.unimi.it/splitmix64.c\n\t\tx += 0x9e3779b97f4a7c15;\n\t\tx = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;\n\t\tx = (x ^ (x >> 27)) * 0x94d049bb133111eb;\n\t\treturn x ^ (x >> 31);\n\t}\n\n\tsize_t operator()(uint64_t x) const {\n\t\tstatic const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();\n\t\treturn splitmix64(x + FIXED_RANDOM);\n\t}\n};\n\nconst int N = 300005;\nconst int NN = 1000007;\nconst int MOD = 998244353; // 1e9+7;\nconst int IMAX = 1e9+7;\nconst ll IAMAX = (1LL << 32);\nconst ll LLMAX = (1LL << 60);\n\nint main () {\n\tios_base::sync_with_stdio(false); cin.tie(0);\n\t// cout.precision(9); cout << fixed;\n\n\tint n, k, x; cin >> n >> k >> x;\n\tvector c(n);\n\tfor (int i = 0; i < n; ++i)\n\t\tcin >> c[i];\n\n\tint ans = 0;\n\tfor (int _i = 1; _i < n; ++_i) {\n\t\tif (c[_i-1] == c[_i] and c[_i] == x) {\n\t\t\tint running = 2;\n\t\t\tvector t = c;\n\t\t\tt.erase(t.begin()+_i-1,t.begin()+_i+1);\n\t\t\tfor (int j = 0; j < n; ++j) {\n\t\t\t\t// for (int i = 0; i < t.size(); ++i) {\n\t\t\t\t// \tcout << t[i] << ' ';\n\t\t\t\t// }\n\t\t\t\t// cout << endl;\n\t\t\t\tfor (int i = 2; i < t.size(); ++i) {\n\t\t\t\t\tif (t[i-2] == t[i-1] and t[i-1] == t[i]) {\n\t\t\t\t\t\twhile (i < t.size() and t[i-2] == t[i-1] and t[i-1] == t[i]) {\n\t\t\t\t\t\t\tt.erase(t.begin()+i);\n\t\t\t\t\t\t\trunning++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tt.erase(t.begin()+i-2,t.begin()+i);\n\t\t\t\t\t\trunning += 2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tans = max(ans, running);\n\t\t}\n\t}\n\tcout << ans << endl;\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["two pointers", "brute force"], "code_uid": "38bebc4c616d0bc57bb9d693848fec9b", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n\nusing namespace std;\n\nint main()\n{\n\tint n;\n\tcin>>n;\n\tvectora(n);\n\tfor(int i=0;i>a[i];\n\t}\n\tsort(a.begin(), a.end());\n\tif(a[n-1]==1)\n\t{\n\t\tcout<<1<=0;i--)\n\t{\n\t\t\n\t\tx=min(x-1,a[i]);\n\t\tif(x>=y || x<0)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tsum+=x;\n\t\t}\n\t\ty=x;\n\t}\n\t// for(int i=n-1;i>=0;i--)\n\t// {\n\t// \tif(a[i]\n#include \n#include \n\nusing namespace std;\n\ntypedef vector vi;\n\nint main(){\n\nint n;\nvi a;\nvi b;\n\nint c[5] = {};\nint d[5] = {};\nint e[5] = {};\ncin >> n;\n\na.resize(n);\nb.resize(n);\n\nfor(int i = 0; i < n; i++){\ncin >> a[i];\nif(a[i] == 1){\nc[0] += 1;\ne[0] += 1;\n}\nif(a[i] == 2){\nc[1] += 1;\ne[1] += 1;\n}\nif(a[i] == 3){\nc[2] += 1;\ne[2] += 1;\n}\nif(a[i] == 4){\nc[3] += 1;\ne[3] += 1;\n}\nif(a[i] == 5){\nc[4] += 1;\ne[4] += 1;\n}\n\n}\nfor(int i = 0; i < n; i++){\ncin >> b[i];\nif(b[i] == 1){\nd[0] += 1;\ne[0] += 1;\n}\nif(b[i] == 2){\nd[1] += 1;\ne[1] += 1;\n}\nif(b[i] == 3){\nd[2] += 1;\ne[2] += 1;\n}\nif(b[i] == 4){\nd[3] += 1;\ne[3] += 1;\n}\nif(b[i] == 5){\nd[4] += 1;\ne[4] += 1;\n}\n}\n\nint counter = 0;\n\nif(e[0] % 2 != 0 || e[1] % 2 != 0 || e[2] % 2 != 0 || e[3] % 2 != 0 || e[4] % 2 != 0){\ncout << -1 << endl;\nreturn 0;\n}\nelse{\n\ncounter += abs(c[0] - d[0]) + abs(c[1] - d[1]) + abs(c[2] - d[2]) + abs(c[3] - d[3]) + abs(c[4] - d[4]);\n\n}\n\ncout << counter / 4 << endl;\n\n\nreturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "d2bc5588934b418fdc0028f04876f4da", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n\nusing namespace std;\nusing ll = long long;\nll gcd(ll a, ll b){\n\tif(b==0) return a;\n\treturn gcd(b,a%b);\n}\nll l[2],r[2],t[2];\nint main(){\n\tint i;\n\tfor(i=0;i<2;i++){\n\t\tcin >> l[i] >> r[i] >> t[i];\n\t}\n\tif(t[0]\nusing namespace std;\nint dp[200010];\nconst int mod = 1000000007;\nint r,g;\nint h;\nint ans = 0;\nint sum;\nint main() {\n\tmemset (dp,0,sizeof(dp));\n\tcin>>r>>g;\n\th=sqrt(r+g+r+g);\n\twhile(h*(h+1)<=r+g+r+g) h++;\n\tdp[0]= 1;\n\tfor(int i=1; i=i; j--) {\n\t\t\tdp[j] += dp[j-i];\n\t\t\tdp[j]%=mod;\n\t\t}\n\t}\t\n\tsum=h*(h-1)/2;\n\tfor(int i=r; ~i; i--) {\n\t\tif(sum-i>g) break;\n\t\tans+=dp[i];\n\t\tans%=mod;\n\t}\n\tcout<\n#include \n#include \n#define il inline\n#define vd void\n#define rep(i,x,y) for(register int i=x;i<=y;++i)\n#define drp(i,x,y) for(register int i=x;i>=y;--i)\nusing namespace std;\nconst int Len=2333333;\nchar buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;\nil char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();\nint n,s;\nint main(){//sjn AK IOI\n\tcin>>n>>s;\n\tint ans=s/n;\n\tif(s%n) ++ans;\n\tcout<=10?rt(x/10),x%10:x)+48);}\nil vd flush(){fwrite(duf,1,q1-duf,stdout);}", "lang_cluster": "C++", "tags": ["math", "greedy", "implementation"], "code_uid": "96808c606ce3c68d14d0602564b333a1", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\nint main(){\n\tchar a, b;\n\tint h1, h2, m1, m2;\n\tcin >> h1 >> a >> m1 >> h2 >> b >> m2;\n\tint t1 = h1*60 + m1;\n\tint t2 = h2*60 + m2;\n\tint mid = (t1+t2)/2;\n\tint hAns = mid/60;\n\tint mAns = mid%60;\n\tif(hAns < 10) cout << \"0\" << hAns << \":\";\n\telse cout << hAns << \":\";\n\tif(mAns < 10) cout << \"0\" << mAns << endl;\n\telse cout << mAns << endl;\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "88a1c5cb6d1fb00c98739b1be92996a0", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \nusing namespace std;\nint main ()\n{int n=0;\nstring x,s;\ncin>>x>>s;\nfor (int i=0 ; i\nusing namespace std;\nconst int n = 10000005;\nbitset<10000005>b;\nvectorprime;\nvoid sieve()\n{\n //set all the bits \n b.set();//1,1,1,1,\n\n b[0]=b[1]=0;\n\n for(long long int i=2;i<=3000;i++)\n {\n if(b[i])\n {\n prime.push_back(i);\n for(long long int j =i*i;j<=3000;j = j+i)\n {\n b[j]=0;\n }\n }\n }\n}\n//if the numvber is less than 10^7 ,then we check sieve O(1) if larger than that then we check \n//O(sqrt(N)) of than number \n// bool Isprime(long long int No)\n// {\n// if(No <= n) return b[No] ==1 ? true:false;\n// for(long long int i =0; prime[i] * prime[i] <=No ;i++)\n// {\n// if(No%prime[i] ==0 ) return false;\n// }\n// return true;\n// }\nint main()\n{\n sieve();\n// if(Isprime(2131234113)) cout<<\"yes it is\";\n// else cout<<\"its not \";\nint No;\ncin>>No;\nint count =0,num=0;\nfor(int j=2;j<=No;j++)\n{ count =0;\n for(int i =0;i2) break;\n \n }\n if(count==2)num+=1;\n}\ncout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#pragma comment(linker,\"/STACK:102400000,102400000\")\ntemplate inline void gmax(T &a, T b){if(b > a) a = b;}\ntemplate inline void gmin(T &a, T b){if(b < a) a = b;}\nusing namespace std;\nconst int N = 1e3 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;\nconst double PI = acos(-1.0), eps = 1e-8;\ntypedef long long LL;\nvoid fre()\n{\n freopen(\"/Users/luras/Desktop/in.txt\", \"r\", stdin);\n freopen(\"/Users/luras/Desktop/out.txt\", \"w\", stdout);\n}\nconst double INF = 1e9;\nint casenum, casei;\n\nint a[30], b[30], ans;\nint len1, len2;\nchar s1[300], s2[300];\n\nint main()\n{\n while(~ scanf(\"%s%s\", s1, s2)){\n ms(a, 0); ms(b, 0);\n len1 = strlen(s1);\n len2 = strlen(s2);\n for(int i = 0; i < len1; i ++){\n a[s1[i] - '0'] ++;\n }\n a[2] += a[5]; a[6] += a[9];\n a[5] = a[9] = 0;\n for(int i = 0; i < len2; i ++){\n b[s2[i] - '0'] ++;\n }\n b[2] += b[5]; b[6] += b[9];\n b[5] = b[9] = 0;\n ans = INF;\n for(int i = 0; i <= 9; i ++){\n if(a[i])gmin(ans, b[i] / a[i]);\n }\n printf(\"%d\\n\", ans);\n \n }\n return 0;\n}\n\n/*\n \n \n \u9898\u610f:\n \n \u7c7b\u578b:\n \n \u5206\u6790:\n \n \u4f18\u5316:\n \n trick:\n \n \u6570\u636e:\n \n Sample Input\n \n Sample Output\n \n \n */\n\n\n", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "2b9cd5fdabf51871ff8de823e7d633a1", "src_uid": "72a196044787cb8dbd8d350cb60ccc32", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n\nusing namespace std;\n\ntypedef long long int LL;\n\nconst LL MOD = 1e9+7;\n\nLL qp(LL p,LL x) { LL ans = 1; for(int i=0;i> p >> k;\n cout << solve(p,k) << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dsu", "math", "combinatorics", "number theory"], "code_uid": "3e2742a9b603b5b6f6721956b3e77b5a", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\nusing namespace std;\nlong long sum[100000];\nint n;\nint main(){\n\tscanf(\"%d\",&n);\n\tsum[1]=1;\n\tfor(int i=2;i<=n;i++)\n\t{\n\t\tsum[i]=sum[i-1]+12*(i-1);\n\t}\n\tcout<\nusing namespace std;\nint a,b;\nint main(){\n cin>>a>>b;\n cout<\n#define ff first\n#define ss second \n#define pb push_back\nusing namespace std;\ntypedef long long ll;\ntypedef pair pii;\n\nconst int N = 205;\n\nint k;\nchar s[N];\n\nint main() {\n scanf(\" %s %d\", s, &k);\n int len = strlen(s);\n for (int i = len; i < len + k; i++) \n s[i] = '?';\n int ans = 0;\n for (int i = 0; i < len + k; i++) {\n for (int j = 0; j < len + k; j++) {\n int sz = (j - i + 1) / 2;\n bool ok = true;\n for (int l = i; ok && l < i + sz; l++) \n if (s[l + sz] != '?' && s[l] != s[l + sz])\n ok = false;\n if (ok)\n ans = max(ans, 2 * sz);\n }\n }\n printf(\"%d\\n\", ans);\n}\n", "lang_cluster": "C++", "tags": ["brute force", "strings", "implementation"], "code_uid": "279088bf03c51d2642eccdc5ab795c87", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#define mp make_pair\r\n#define PII pair\r\n#define fi first\r\n#define se second\r\n#define pb push_back\r\nusing namespace std;\r\ninline int read(){\r\n\tint x=0,f=1;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}\r\n\twhile(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=getchar();}\r\n\treturn f==-1?~x+1:x;\r\n}\r\nint n,k;\r\nint ans=0;\r\nint p[200010];\r\nbool vis[200010];\r\nint mu[200010];\r\nconst int mod=998244353;\r\ninline int qpow(int x,int k=mod-2){\r\n\tint res=1;\r\n\twhile(k){ if(k&1) res=1ll*res*x%mod; x=1ll*x*x%mod; k>>=1;}\r\n\treturn res;\r\n}\r\nint fac[200010],ifac[200010];\r\nint xs[200010];\r\nvoid prework(int x){\r\n\tfac[0]=1;\r\n\tmu[1]=1;\r\n\tfor(int i=1;i<=x;++i) fac[i]=1ll*fac[i-1]*i%mod;\r\n\tifac[x]=qpow(fac[x]);\r\n\tfor(int i=x-1;i>=0;--i) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;\r\n\tint tot=0;\r\n\tfor(int i=2;i<=x;++i){\r\n\t\tif(!vis[i]) p[++tot]=i,mu[i]=-1;\r\n\t\tfor(int j=1;j<=tot&&i*p[j]<=x;++j){\r\n\t\t\tvis[i*p[j]]=1;\r\n\t\t\tif(i%p[j]==0){\r\n\t\t\t\tmu[i*p[j]]=0;break ;\r\n\t\t\t}\r\n\t\t\tmu[i*p[j]]=-mu[i];\r\n\t\t}\r\n\t}\r\n\tfor(int i=1;i<=n;++i) xs[n/i+(n%i!=0)]+=mu[i];\r\n\txs[1]=0;\r\n\tfor(int i=1;i<=n;++i) xs[1]-=xs[i];\r\n}\r\ntypedef vectorpoly;\r\nint add(int x,int y){return x+y>=mod?x+y-mod:x+y;}\r\nint sub(int x,int y){return x>1]>>1)|((i&1)<i) swap(s[i],s[R[i]]);\r\n\tfor(int l=1;l\nusing namespace std;\ntypedef long long ll;\n \nconst int maxn = 1e7 + 14;\nint n, phi[maxn], suf[maxn];\nvector all[maxn];\nbool mark[maxn];\nll c1, c2;\nint bads = 1;\nint mults(int p, int l, int r){\n\treturn r / p - l / p;\n}\nint main(){\n\tios::sync_with_stdio(0), cin.tie(0);\n\tcin >> n;\n\tfor(int i = 1; i <= n; i++){\n\t\tphi[i] += i;\n\t\tc1 += max(0, i - 1 - phi[i]);\n\t\tfor(int j = i * 2; j <= n; j += i)\n\t\t\tphi[j] -= phi[i];\n\t}\n\t//cerr << ans << '\\n';\n\tvector pr;\n\tfor(int i = 2; i <= n; i++)\n\t\tif(!mark[i]){\n\t\t\tpr.push_back(i);\n\t\t\tif(i * 2 > n)\n\t\t\t\tbads++;\n\t\t\tfor(int j = i; j <= n; j += i)\n\t\t\t\tif(!mark[j]){\n\t\t\t\t\tmark[j] = 1;\n\t\t\t\t\tall[i].push_back(j);\n\t\t\t\t}\n\t\t\tif(i * 2 <= n)\n\t\t\t\tsuf[i] = all[i].size();\n\t\t}\n\tfor(int i = n; i >= 0; i--)\n\t\tsuf[i] += suf[i + 1];\n\tint goods = n - bads;\n\tll allp = (ll) goods * (goods - 1) / 2;\n\tc2 = allp - c1;\n\tint ptr = n;\n\twhile(!pr.empty() && pr.back() * 2 > n)\n\t\tpr.pop_back();\n\tfor(int i = 0; i < pr.size(); i++){\n\t\tif(2 * pr[i] > n)\n\t\t\tbreak;\n\t\twhile(ptr && (ll) ptr * pr[i] > n)\n\t\t\tptr--;\n\t\tcerr << suf[ptr + 1] << '\\n';\n\t\tc2 -= suf[ptr + 1];\n\t}\n\tptr = (int) pr.size() - 1;\n\tfor(int i = 0; i < pr.size(); i++){\n\t\tif(2 * pr[i] > n)\n\t\t\tbreak;\n\t\tif(ptr < i)\n\t\t\tptr = i;\n\t\twhile(ptr >= i && (ll) pr[ptr] * pr[i] > n)\n\t\t\tptr--;\n\t\t//cerr << suf[ptr + 1] << '\\n';\n\t\tc2 += pr.size() - ptr - 1;\n\t}\n\tcerr << (allp - c1 - c2) << '\\n';\n\tcout << c1 + c2 * 2 + (allp - c1 - c2) * 3 << '\\n';\n}\n", "lang_cluster": "C++", "tags": ["sortings", "number theory"], "code_uid": "b02339711d67c54c70b8995015a5cbf3", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n\nbool good(int x0, int y0, int x1, int y1)\n{\n if(x0==0 && y0==0)\n return true;\n if(y1==0 && y1==0)\n return false;\n while(1)\n {\n if(x0)\n x0--;\n else\n y0--;\n if((x0==0 && y0==0) || (x0-y0==x1-y1 && min(x0, y0)\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nlong long v1=1000000009,ans=1;\nint vis[1000],len=0;\nvectored[1000];\nlong long fact[1000005],invfact[1000005];\n\n\nint main()\n{ \n long long i,j,k=0,n,m,a,b,c,d;\n cin>>n>>m>>k;\n if(m0)\n {\n j=(j*d)%v1;\t\n }\n d=(d*d)%v1;\n }\n j=(2*k*j-2*k)%v1; \n j=(j+m%k)%v1;\n j=(j+a*(k-1))%v1;\n cout<\n#include \n#include \n\nusing namespace std;\n\n\n\nvoid collect(vector & v, unsigned long long z, unsigned long long r)\n{\n\tunsigned long long t=1;\n\n\tv.push_back(t);\n\twhile (t*(double)z<=r)\n\t{\n\t\tt*=z;\n\t\tv.push_back(t);\n\t}\n}\n\nint main(void)\n{\n\tvector vx, vy;\n\tset unlucky;\n\tset::const_iterator it;\n\tunsigned long long x, y, l, r, o, dMax, last, d;\n\tunsigned int i, j;\n\n\tcin >> x >> y >> l >> r;\n\tcollect(vx, x, r);\n\tcollect(vy, y, r);\n\tfor (i=0; i0)\n\t\t\td--;\n\t\tif (d>dMax)\n\t\t\tdMax=d;\n\t\tlast=(*it);\n\t}\n\tcout << dMax << '\\n';\n\n\treturn 0;\n}\n\n\n\n", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "c146d1cead56cca44e2b3a22e581d6ed", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n int n,c=0,cc=0,dd=0,ee=0,ff=0;\n cin>>n;\n string s,t;\n t=\"4\";\n cin>>s;\n // cout<\r\nusing namespace std;\r\nconst int mod=998244353;\r\nvoid add(int &x,int y){x=(x+y)%mod;}\r\nint n,m,S1[10],S2[10],f[50005][1100];\r\nint main(){\r\n scanf(\"%d%d\",&n,&m);\r\n for(int i=1,x,y;i<=m;i++){\r\n scanf(\"%d%d\",&x,&y);\r\n if(x>y)swap(x,y);\r\n S1[x]|=(1<\nusing namespace std;\nint a[100],n,k,i;\nint main()\n{\n cin>>n>>k;\n for(i=1;i<=n;i++)\n cin>>a[i];\n for(i=1;a[i]>0&&a[i]>=a[k];i++);\n cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long ll;\nconst ll p = 1e9 + 7;\nll n,m,ans;\nll qp(ll a,ll b){\n\tll ans = 1,base = a;\n\twhile(b != 0){\n\t\tif(b & 1)ans = ans * base % p;\n\t\tbase = base * base % p;\n\t\tb >>= 1;\n\t}\n\treturn ans;\n}\nint main()\n{\n\tscanf(\"%lld%lld\",&n,&m);\n\tans = qp((qp(2,m)%p - 1 + p)%p,n)%p;\n\tcout<\n#include \n#include \n\nusing namespace std;\n\nint main() {\n int n; cin >> n;\n vector ts(n);\n for (int i = 0; i < n; i++) {\n cin >> ts[i];\n }\n int T; cin >> T;\n\n sort(ts.begin(), ts.end());\n int count = 1;\n for (int i = 0; i < n; i++) {\n for (int j = i+1; j < n; j++) {\n if (ts[j] - ts[i] > T) {\n\tbreak;\n }\n count = max(count, j-i+1);\n }\n }\n cout << count << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "binary search"], "code_uid": "e23f80252e1adfb20d76424644008cd1", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n \n#define DEBUG if(1)\n#define MAXN 100\n#define MAX INT_MAX\n#define MAXLL INT_MAX\n#define MAXU ULLONG_MAX\n#define MIN -2000000\n#define endl \"\\n\"\n#define INF 99999999\n#define MOD 1000000007\n#define s(n) scanf(\"%d\", &n)\n#define ss(a,b) scanf(\"%d %d\",&a,&b)\n#define pb push_back\n#define mp make_pair\n#define M_PI 3.14159265358979323846\n#define sz(a) int(a.size())\n#define lli long long int\n#define rep(i,a,n) for (int i=a;i vi;\ntypedef vector vvi;\ntypedef pair ii;\ntypedef pair > ps;\n#define DEBUG if(1)\n#define F first\n#define S second\n// #define d 256\n// int dx[] = {0, 1, 0, -1};\n// int dy[] = {1, 0, -1, 0};\nint ddx[] = {1, 0};\nint ddy[] = {0, 1};\n\nlli k;\n\nbool test(lli aux){\n\tlli kk = k;\n\tlli aa = 0, bb = 0;\n\n\twhile(kk > 0){\n\t\tlli atual = min(aux, kk);\n\t\tkk -= atual, aa += atual;\n\t\tif(kk == 0) break;\n\t\tlli atual2 = kk/10;\n\t\tkk -= atual2;\n\t}\n\t// cout << aa << \" - \" << bb << endl;\n\t// cout << aa << \" - \" << aux << endl;\n\tif(aa*2 >= k) return true;\n\treturn false;\n}\n\nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tcin >> k;\n\n\tlli ans = k;\n\n\tlli com = 0, fim = ans;\n\twhile(com < fim){\n\t\tlli mid = (com + fim) >> 1;\n\t\tif(mid == 0) break;\n\t\tif(test(mid)) fim = mid, ans = mid;\n\t\telse com = mid + 1;\n\t}\n\n\t// while(test(ans)) ans--;\n\n\tcout << fim << endl;\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation", "binary search"], "code_uid": "0fcccb1a00d44f69ee2cf6cba482aa7e", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define rep(x, y, z) for(int x = (y), end##x = (z); x < end##x; x++)\n#define all(x) (x).begin(),(x).end()\n\n#ifdef LOCAL_DEBUG\n\n#define DebugPrint(...) fprintf(stderr, __VA_ARGS__);\n\n#else\n\n#define DebugPrint(...)\n\n#endif\n\ntypedef long long ll;\ntypedef pair pii;\n\n\nint main()\n{\n //\n#ifdef LOCAL_DEBUG\n \n freopen(\"test.in\", \"r\", stdin);\n freopen(\"test.out\", \"w\", stdout);\n \n#else\n \n// freopen(\"fibsubseq.in\", \"r\", stdin);\n// freopen(\"fibsubseq.out\", \"w\", stdout);\n \n#endif\n \n clock_t cl = clock();\n \n ll num;\n cin >> num;\n \n ll t = 1;\n \n while (num % t == 0)\n t *= 3;\n \n ll res = num / t + 1;\n \n cout << res << endl;\n \n \n //int num;\n \n#ifdef LOCAL_DEBUG\n \n fprintf(stderr, \"\\nTime used: %lf\\n\", (clock() - cl) / (double)CLOCKS_PER_SEC);\n \n#endif\n \n return 0;\n}", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "760a8a3541bb2679db7f309361b08efb", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "///\tB : Coded by Choe Kwang\n\n#include \nusing namespace std;\n\nint n, m, x;\n\nint calc(int x) {\n\treturn (max(0, n - 2 * x) * max(0, m - 2 * x) + 1) / 2;\n}\n\nint main() {\n\tscanf(\"%d %d %d\", &n, &m, &x);\n\tprintf(\"%d\\n\", calc(x - 1) - calc(x));\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "966c4e655ab941cadcc647befa33ced5", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#define int long long\nusing namespace std;\n\nint cnt[9];\nint curcnt[9];\n\nint res = 1e18;\nvoid check(int sum, int mini) {\n if (sum < 0) return;\n res = min(res, sum);\n for (int i = mini; i <= 8; i++) {\n for (int j = 1; j <= cnt[i] - curcnt[i]; j++) {\n if (sum - i * j < 0) break;\n check(sum - i * j, i + 1);\n }\n }\n}\n\nsigned main() {\n int w;\n cin >> w;\n for (int i = 1; i <= 8; i++) {\n cin >> cnt[i];\n }\n int x = 0;\n for (int i = 8; i >= 1; i--) {\n curcnt[i] = min(max(0ll, w - 20 - x) / i, max(0ll, cnt[i] - 9) );\n x += i * curcnt[i];\n }\n /*cout << x << endl;\n for (int i = 1; i <= 8; i++) {\n cout << curcnt[i] << \" \";\n }\n cout << endl;*/\n check(w - x, 1);\n cout << w - res;\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "greedy", "dp"], "code_uid": "2d5e773b874a09f556696ac8a9d01b86", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main()\n{\nlong int n,i,ks,kf;\nchar s,e;\ncin>>s>>e;\nchar p[4]={'v','<','^','>'};\nfor(i=0;i<4;i++)\n{ if(s==p[i])\n{ ks=i;\n}\nif(e==p[i])\n{\nkf=i;\n}}\ncin>>n;\nn=n%4;\nint ans=2,q=ks;\nfor(i=1;i<=n;i++)\n{\n\nq=q+1;\nif(q==4)\n q=0;\n}\nif(p[q]==p[kf])\n{\n\n ans=0;\n}\n\n q=ks;\nfor(i=1;i<=n;i++)\n{\n\nq=q-1;\nif(q<0)\nq=3;\n}\nif(p[q]==p[kf])\n{\n if(ans!=0)\n ans=1;\n else\n ans=2;\n}\n\nif(ans==0)\nprintf(\"cw\\n\");\nelse if(ans==1)\nprintf(\"ccw\\n\");\nelse if(ans==2)\nprintf(\"undefined\\n\");\n\nreturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "959cc1384029653f524bf3a4fb1a4d19", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "//codeforces 401D Roman and Numbers\n#include\n#define ll long long\nconst int maxs=(1<<18)+5;\nconst int maxn=110;\nusing namespace std;\nint cnt=-1,w[20],m;\nll f[maxs][maxn],n;\nbool vis[10];\nint main(){\n\tfor(cin>>n>>m;n;n/=10)\n\t w[++cnt]=n%10;\n\tf[0][0]=1;\n\tfor(int s=1;s<1<\n#include\nusing namespace std;\nint main()\n{\n\tint n,l,r,js=0,x=1,mn,mx;\n\tscanf(\"%d%d%d\",&n,&l,&r);\n\tfor(int i=0;i\nusing namespace std;\n#define int long long\n#define vi vector\n#define vvi vector\n#define pii pair\n#define pb push_back\n#define mp make_pair\n#define um unordered_map\n#define F first\n#define S second\n#define MOD 1000000007\n#define TC int t; cin >> t; while(t--)\n#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n#define count_bits(val) __builtin_popcount(val)\n\nconst int maxn = 105;\nint n,k,l;\nint a[maxn];\nint dp[2*maxn][maxn];\nvi dist;\n\nint solve(int curr_time, int i){\n\n\tif( i >= n)\n\t\treturn 1;\n\n\tif(a[i] + dist[curr_time % (2*k)] > l)\n\t\treturn 0;\n\n\tif(dp[curr_time % (2*k)][i] != -1)\n\t\treturn dp[curr_time % (2*k)][i];\n\n\tint ans = 0;\n\tfor(int inc = 1; inc <= 2*k;inc++){\n\t\tif(a[i] + dist[(curr_time + inc - 1) % (2*k)] <= l)\n\t\t\tans += solve((curr_time + inc) % (2*k), i+1);\n\t\telse break;\n\t}\n\n\treturn (dp[curr_time % (2*k)][i] = (ans >= 1));\n}\n\n\n\nsigned main(){\n\t#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\" , \"r\" , stdin);\n\tfreopen(\"output.txt\" , \"w\" , stdout);\n\t#endif\n\tTC{\n\t\tcin >> n >> k >> l;\n\t\tfor(int i=0;i> a[i];\n\t\tmemset(dp, -1, sizeof(dp));\n\t\tfor(int i=0;i<=k;i++) dist.pb(i);\n\t\tfor(int i=k-1;i>=1;i--) dist.pb(i);\n\t\tint ans = 0;\n\t\tfor(int i=1;i<=2*k;i++){\n\t\t\tans += solve(i % (2*k), 0);\n\t\t}\n\t\tstring sl = (ans >= 1) ? \"Yes\" : \"No\";\n\t\tcout << sl << endl;\n\t\tdist.clear();\n\t}\n\n\n\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "greedy", "dp"], "code_uid": "a4777b751f2aed298ab5c818d1ad9409", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\nint t,r,g,b,p,j,i;\ncin>>r>>g>>b;\ni=1;\nfor(t=30;t<10000000;t++)\n{\n //cout<<\"t is \"<0))\n r=r-2;\n else if((t%3==1) and (g>0))\n g=g-2;\n else if((t%3==2) and (b>0))\n b=b-2;\n else\n i=i-7;\n}\ncout<\n#include \n#include \nusing namespace std;\ndouble todouble (string s)\n{\n stringstream m;\n int n;\n m<>n;\n return n;\n}\nint main ()\n{\n string num , temp1,temp2,temp3;\n cin>>num;\n int res=-1 , temp , temp4 , temp5 , mom;\n int siz=num.size();\n for (int i=siz-3;i>=0;i--)\n {\n temp1=num.substr(0,i+1);\n temp=todouble (temp1);\n if (temp > 1000000)\n continue;\n else if (temp1.size()>1 && temp1[0]=='0')\n continue;\n for (int j=siz-2;j>=i+1;j--)\n {\n temp2=num.substr(i+1,j-i);\n temp3=num.substr(j+1,siz-j+1);\n temp4=todouble (temp2);\n temp5=todouble(temp3);\n if (temp4>1000000 || temp5>1000000)\n continue;\n else if (temp2.size()>1 && temp2[0]=='0')\n continue;\n else if (temp3.size()>1 && temp3[0]=='0')\n continue;\n mom=temp+temp4+temp5;\n if (mom>res)\n res=mom;\n }\n }\n cout<\n#include \nusing namespace std;\nint main()\n{\n\tint n, posM=0, posm=0;\n\tcin>>n;\n\tint* arr = new int[n];\n\tfor(int i=0; i>arr[i];\n\t\tif(arr[i]==n) {posM=i;}\n\t\tif(arr[i]==1) {posm=i;}\n\t}\n\tint a, b;\n\ta=min(abs(n-1-posM), abs(posM));\n\tb=min(abs(n-posm-1), abs(posm));\n\tcout<\nusing namespace std;\nint main()\n{\tios::sync_with_stdio(0);\n int n,a,b;\n cin>>n>>a>>b;\n cout<<((a+b)%n+n-1)%n+1;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "7fc7665abdaf49d4509cb0566aa3155a", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\nint main()\n{\n int ya,wa,dot,count,sub;\n cin>>ya>>wa;\n if(ya>wa)\n {\n count=ya;\n }\n else if(wa==ya)\n {\n count=wa;\n }\n else\n {\n count=wa;\n }\n sub=6-(count-1);\n if(sub==6)\n {\n cout<<\"1/1\";\n }\n else if(sub==5)\n {\n cout<<\"5/6\";\n }\n else if(sub==1)\n {\n cout<<\"1/6\";\n }\n else if(sub==2)\n {\n cout<<\"1/3\";\n\n }\n else if(sub==3)\n {\n cout<<\"1/2\";\n }\n else\n {\n cout<<\"2/3\";\n }\n return 0;\n}\n\n ", "lang_cluster": "C++", "tags": ["math", "probabilities"], "code_uid": "d3942db11d72f5ee1ca1a416eef9cb1c", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n#define ll long long\nstring table[] = {\n\t\"H\", \"HE\", \"LI\", \"BE\", \"B\", \"C\", \"N\", \"O\", \"F\", \"NE\", \"NA\", \"MG\", \"AL\", \"SI\", \"P\", \"S\", \"CL\", \"AR\", \"K\", \"CA\", \"SC\", \"TI\", \"V\", \"CR\", \"MN\", \"FE\", \"CO\", \"NI\", \"CU\", \"ZN\", \"GA\", \"GE\", \"AS\", \"SE\", \"BR\", \"KR\", \"RB\", \"SR\", \"Y\", \"ZR\", \"NB\", \"MO\", \"TC\", \"RU\", \"RH\", \"PD\", \"AG\", \"CD\", \"IN\", \"SN\", \"SB\", \"TE\", \"I\", \"XE\", \"CS\", \"BA\", \"LA\", \"CE\", \"PR\", \"ND\", \"PM\", \"SM\", \"EU\", \"GD\", \"TB\", \"DY\", \"HO\", \"ER\", \"TM\", \"YB\", \"LU\", \"HF\", \"TA\", \"W\", \"RE\", \"OS\", \"IR\", \"PT\", \"AU\", \"HG\", \"TL\", \"PB\", \"BI\", \"PO\", \"AT\", \"RN\", \"FR\", \"RA\", \"AC\", \"TH\", \"PA\", \"U\", \"NP\", \"PU\", \"AM\", \"CM\", \"BK\", \"CF\", \"ES\", \"FM\", \"MD\", \"NO\", \"LR\", \"RF\", \"DB\", \"SG\", \"BH\", \"HS\", \"MT\", \"DS\", \"RG\", \"CN\", \"NH\", \"FL\", \"MC\", \"LV\", \"TS\", \"OG\"\n};\nbool dd[1111];\nint main() {\n string s; cin >> s;\n int n = s.size();\n s = \" \" + s;\n dd[0] = true;\n for(int i = 1; i <= n; ++i) {\n if(!dd[i-1]) continue;\n for(int j = 1; i+j-1 <= n; ++j) {\n// cout << s.substr(i,j) << endl;\n if(find(table, table+118, s.substr(i,j)) != table + 118)\n dd[i+j-1] = true;\n }\n }\n cout << (dd[n] ? \"YES\" : \"NO\") << endl;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "strings", "dp"], "code_uid": "0a3c695a7e2dad199295258f1bafcbfc", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tlong long r1,r2,c1,c2,d1,d2,a,b,c,d,n=0;\n\tcin>>r1>>r2>>c1>>c2>>d1>>d2;\n\tfor(a=1;a<=9;a++)\n\t{\n\t\tfor(b=1;b<=9;b++)\n\t\t{\n\t\t\tfor(c=1;c<=9;c++)\n\t\t\t{\n\t\t\t\tfor(d=1;d<=9;d++)\n\t\t\t\t{\n\t\t\t\t\tif((a+b)==r1&&(c+d)==r2&&(a+d)==d1&&(b+c)==d2&&(a+c)==c1&&(b+d)==c2&&a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d)\n\t\t\t\t\t{\n\t\t\t\t\t\tcout<\n#include \n#include \n\ntypedef long long LL;\n\nusing namespace std;\n\nint main(){\n\tLL n, m, k;\n\tscanf(\"%lld%lld\",&n,&m);\n\tfor(k = 0; k * (k - 1) / 2 < m; k++);\n\tprintf(\"%lld %lld\\n\", max(0LL, n - 2 * m), n - k);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["constructive algorithms", "graphs"], "code_uid": "7c9ff4a5a9d282a72a045f4d06bb70f3", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n#define ll long long int\nvoid nandini()\n{\n ll n,m,i,j,d=0,e=0,x,y;\n cin>>n;\n ll a[n][2];\n // vector>v;\n for(i=0;i>a[i][0]>>a[i][1];\n // v.push_back(make_pair(a[i][0],a[i][1]));\n }\n // for(i=0;is1;\n for(i=0;is2;\n for(i=0;i>t;\n while(t--)\n {\n nandini();\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["geometry", "implementation"], "code_uid": "26f532075680d1418611344fe44dff2f", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\nconst int mo=1e9+7;\nint f[500][500],C[500][500],I[500],nI[500];\nlong long A[500];\nint n;\nint quick(int k1,int k2){\n\tint k3=1;\n\twhile (k2){\n\t\tif (k2&1) k3=1ll*k3*k1%mo; k2>>=1; k1=1ll*k1*k1%mo;\n\t}\n\treturn k3;\n}\nint main(){\n\tscanf(\"%d\",&n);\n\tf[0][0]=1;\n\tfor (int i=0;i<=n;i++){\n\t\tC[i][0]=1;\n\t\tfor (int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;\n\t}\n\tI[0]=1; for (int i=1;i<=n;i++) I[i]=1ll*I[i-1]*i%mo;\n\tfor (int i=0;i<=n;i++) nI[i]=quick(I[i],mo-2);\n\tfor (int i=1;i<=n;i++){\n\t\tf[i][0]=1; memset(A,0x00,sizeof A); A[0]=1;\n\t\tfor (int j=n;j;j--)\n\t\t\tfor (int k=0;k<=j;k++)\n\t\t\t\tif (A[j]<0) A[j]+=1ll*f[i-1][k]*f[i-1][j-k];\n\t\t\t\telse A[j]+=1ll*(f[i-1][k]-mo)*f[i-1][j-k]; \n\t\tfor (int j=1;j<=n;j++) A[j]=1ll*(A[j]%mo+mo)*I[j]%mo;\n\t\tfor (int j=n;j;j--)\n\t\t\tf[i][j]=(1ll*(2*j+1)*A[j]+1ll*j*A[j+1]+1ll*j*A[j-1])%mo*nI[j]%mo;\n\t}\n\tprintf(\"%d\\n\",f[n][1]);\n\treturn 0;\n}\n\t\t\t", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "trees", "graphs"], "code_uid": "6831a065e02f0620266d90b7fe43588d", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \nusing namespace std;\nint dir;\nint n,m,k;\n\nint go(int pos)\n{\n\tif(pos==1)\n\t{\n\t\tdir=1;\n\t\treturn pos+1;\n\t}\n\tif(pos==n)\n\t{\n\t\tdir=0;\n\t\treturn pos-1;\n\t}\n\tif(dir)\n\t\treturn pos+1;\n\treturn pos-1;\n}\n\nint main()\n{\n\t//freopen(\"input.txt\",\"r\",stdin);\n\tcin>>n>>m>>k;\n\tstring napr,isstop;\n\tcin>>napr>>napr;\n\tcin>>isstop;\n\n\tif(napr==\"head\")\n\t\tdir=0;\n\telse\n\t\tdir=1;\n\n\tfor(int i=0;ik)\n\t\t\t\t{\n\t\t\t\t\tm++;\n\t\t\t\t\tm=min(m,n);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tm--;\n\t\t\t\t\tm=max(1,m);\n\t\t\t\t}\n\t\t\t}\n\t\t\tk=go(k);\n\t\t}\n\t\tif(m==k)\n\t\t{\n\t\t\tcout<<\"Controller \"<\nusing namespace std;\ntypedef long long ll;\n\nll n, x, y, c;\n\nbool ok(ll t) {\n\tll res = 0;\n\tll rowl = max(1ll, y - t), rowh = min(n, y + t);\n\tfor (ll row = rowl; row <= rowh; row++) {\n\t\tll tt = t - abs(y - row);\n\t\tll coll = max(1ll, x - tt), colh = min(n, x + tt);\n\t\tres += colh - coll + 1;\n\t\tif (res >= c) return 1;\n\t}\n\treturn 0;\n}\n\nint main() {\n\tcin >> n >> x >> y >> c;\n\tll lo = 0, hi = 2 * n, mid;\n\twhile (lo <= hi) {\n\t\tmid = (lo + hi) / 2;\n\t\tif (ok(mid)) hi = mid - 1;\n\t\telse lo = mid + 1;\n\t}\n\tcout << lo << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation", "binary search"], "code_uid": "bcc1f29efa45c6cde0b19461c5ba900e", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\nusing namespace std;\nint main(){\n\tdouble t1,t2,t;\n\tint h1,m1,s1;\n\tdouble h,m,s;\n\t cin>>h1>>m1>>s1>>t1>>t2;\n\t h=h1;\n\t if(t1>t2){\n\t \tt=t1;\n\t \tt1=t2;\n\t \tt2=t;\n\t }\n\t if(s1%5==0){\n\t \ts=s1/5;\n\t }else{\n\t \ts=s1/5+0.5;\n\t }\n\t if(m1%5==0){\n\t \tm=m1/5;\n\t \tif(s1>0){\n\t \t\tm=m1/5+0.5;\n\t\t}\n\t }else{\n\t \tm=m1/5;\n\t \tm=m1/5+0.5;\n\t }\n\t if(m>0){\n\t \th=h1+0.5;\n\t \t\n\t }\n\t //cout<s||t1h||t1m){\n \tif(t2t2||ht2||m\n#define fr first\n#define r_0 return 0\n#define sc scanf\n#define pf printf\n#define se second\n#define ll long long\n#define pb push_back\n#define puf push_front\n#define mk make_pair\n#define ld long double\n#define pr pair\n#define piip pair< pair,ll >\n#define fin(s) freopen( s, \"r\",stdin )\n#define fout(s) freopen( s, \"w\", stdout )\n#define TIME ios_base::sync_with_stdio(0)\nusing namespace std;\nvectorV,B;\nsetS;\nmapM;\nqueueQ;\ndequeD;\nvector>P;\nll n ,x,ans,a,b;\nint arr[101],ar[101];\nstring s;\nll m;\nint main ()\n{\n TIME;\n while (cin>>s)\n { for (int i =0; i ='A')\n ans++;\n b=max(ans,b);\n ans=0;\n }\n\n cout<\n #include \n #include \n using namespace std;\n const int N=1e5+1,MOD=998244353;\n int lim[N][2][2],p[N<<2][2][2],psb[N][2];\n inline int qpow(int base,int expo)\n {\n \tint ret=1;\n \twhile(expo)\n \t{\n \t\tif(expo&1) ret=1ll*ret*base%MOD;\n \t\tbase=1ll*base*base%MOD;\n \t\texpo>>=1;\n \t}\n \treturn ret;\n }\n inline void up(int now,int mid)\n {\n \tint i,j,k,l;\n \tfor(i=0;i<2;i++)\n \t{\n \t\tfor(j=0;j<2;j++)\n \t\t{\n \t\t\tp[now][i][j]=0;\n \t\t\tfor(k=0;k<2;k++)\n \t\t\t\tfor(l=0;l<2;l++)\n \t\t\t\t\tif(!lim[mid][k][l])\n \t\t\t\t\t\tp[now][i][j]=(0ll+p[now][i][j]+1ll*p[now<<1][i][k]*p[now<<1|1][l][j]%MOD)%MOD;\n \t\t}\n \t}\n }\n void build(int now,int l,int r)\n {\n \tif(l==r)\n \t{\n \t\tp[now][0][0]=psb[l][0];\n \t\tp[now][1][1]=psb[l][1];\n \t\treturn;\n \t}\n \tint mid=(l+r)>>1;\n \tbuild(now<<1,l,mid);\n \tbuild(now<<1|1,mid+1,r);\n \tup(now,mid);\n }\n void update(int now,int l,int r,int qp)\n {\n \tif(l==r) return;\n \tint mid=(l+r)>>1;\n \tif(qp<=mid) update(now<<1,l,mid,qp);\n \telse update(now<<1|1,mid+1,r,qp);\n \tup(now,mid);\n }\n struct chase\n {\n \tint x,xp,yp;\n \tdouble tim;\n \tint rtim;\n \tchase(int x=0,int xp=0,int yp=0,double tim=0,int rtim=0):\n \t\tx(x),xp(xp),yp(yp),tim(tim),rtim(rtim){}\n } cs[N*2];\n int csc;\n inline int cmp(chase a,chase b){return a.tim1)\n \t\t{\n \t\t\tint dis=tpos-lasp;\n \t\t\tcs[++csc]=chase(i-1,1,0,dis/1.0/(tv+lasv),1ll*dis*qpow(tv+lasv,MOD-2)%MOD);\n \t\t\tif(tvlasv) cs[++csc]=chase(i-1,0,0,dis/1.0/(tv-lasv),1ll*dis*qpow(tv-lasv,MOD-2)%MOD);\n \t\t}\n \t\tpsb[i][0]=1ll*(100-psb[i][1])*inv%MOD;\n \t\tpsb[i][1]=1ll*psb[i][1]*inv%MOD;\n \t\tlasp=tpos,lasv=tv;\n \t}\n \tbuild(1,1,n);\n \tsort(cs+1,cs+csc+1,cmp);\n \tint ans=0,lpsb=1;\n \tfor(i=1;i<=csc;i++)\n \t{\n \t\tlim[cs[i].x][cs[i].xp][cs[i].yp]=1;\n \t\tupdate(1,1,n,cs[i].x);\n \t\tint tpsb=(0ll+p[1][0][0]+p[1][0][1]+p[1][1][0]+p[1][1][1])%MOD;\n \t\tans=(0ll+ans+1ll*cs[i].rtim*(lpsb-tpsb+MOD)%MOD)%MOD;\n \t\tlpsb=tpsb;\n \t}\n \tprintf(\"%d\",ans);\n \treturn 0;\n }", "lang_cluster": "C++", "tags": ["math", "probabilities", "data structures"], "code_uid": "e6ad115aa6f096751127ac9cb968be52", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "/**\n * iN thE namE oF AllaH\n * |__________________|\n * Author : Asfaq,CSE'25,JU!\n * Code the Time :)\n**/\n\n#include \"bits/stdc++.h\"\nusing namespace std;\n\n#define FasterIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);\ntypedef long long int ll;\ntypedef double dd;\ntypedef pair PLL;\ntypedef vector VL;\ntypedef vectorVS;\ntypedef vector VP;\ntypedef map MP;\ntypedef set ST;\ntypedef multiset MST;\n#define L 2*node\n#define R 2*node+1\n#define mp make_pair\n#define pb push_back\n#define fi first\n#define se second\n#define PI 3.14159265358979\n#define pi 2*acos(0.0)\n#define INF 1e18\n#define EPS 1e-9\n#define sz(x) (ll)(x.size())\n#define MEM(x,y) memset(x,y,sizeof x)\n#define all(x) (x).begin(),(x).end()\n#define sc1(x) scanf(\"%lld\",&x);\n#define sc2(x,y) scanf(\"%lld%lld\",&x,&y);\n#define sc3(x,y,z) scanf(\"%lld%lld%lld\",&x,&y,&z);\n#define sc4(x,y,z,w) scanf(\"%lld%lld%lld%lld\",&x,&y,&z,&w);\n#define scl1(x) scanf(\"%lf\",&x);\n#define scl2(x,y) scanf(\"%lf%lf\",&x,&y);\n#define cn1(x) cin>>x;\n#define cn2(x,y) cin>>x>>y;\n#define cn3(x,y,z) cin>>x>>y>>z;\n#define cn4(x,y,z,w) cin>>x>>y>>z>>w;\n#define co1(x) cout<= y; i -- )\n\nconst ll N1 = 1000010;\nconst ll N2 = 2000010;\nconst ll mod1 = 1e2 + 7;\nconst ll mod2 = 1e9 + 7;\n\n/*\n///Geometry###\ndd pw(dd x){return (x*x);}\ndd dis(dd x1,dd y1,dd x2,dd y2){return sqrt(pw(x1-x2)+pw(y1-y2));}\ndd Circle_line(dd a,dd b,dd c,dd x,dd y){return (abs(a*x+b*y+c)/sqrt(pw(a)+pw(b)));}\ndd Co_linear(dd x1,dd y1,dd x2,dd y2,dd x3,dd y3){return x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);}//Triangle area formula\nbool Rotate_page(dd x1,dd y1,dd x2,dd y2,dd x3,dd y3){dd d1=dis(x1,y1,x2,y2),d2=dis(x2,y2,x3,y3);if(d1!=d2)return 0;if(!Co_linear(x1,y1,x2,y2,x3,y3))return 0;return 1;}\ndd Polgn_area(dd x[],dd y[],ll n){dd a=0;int j=n;for(int i=1;i<=n;i++){a+=(x[j]+x[i])*(y[j]-y[i]);j=i;}return abs(a/2.0);}\ndd angle(dd a,dd b,dd c){return acos((pw(b)+pw(c)-pw(a))/(2.0*b*c));}\n*/\n\nll BS(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}\nll GCD(ll a,ll b){if(a==0) return b;else return GCD(b%a,a);}\nll prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}\nvoid swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}\nll Bigmod(ll b,ll p,ll m){ll ret=1;while(p){if(p&1)ret=(ret*b)%m;b=(b*b)%m;p>>=1LL;}return ret;}\nll Joss(ll n,ll k){if(n==1) return 1;return (Joss(n-1,k)+k-1)%n+1;}\nll XtndGCD(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=XtndGCD(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}\n\n/*\nbool vis[N1]; ll primF[N1],idx;\nvoid SV()\n{\n vis[0]=vis[1]=1;for(int i=4;i<=N1;i+=2)vis[i]=1;primF[++idx]=2;\n for(int i=3;i*i<=N1;i+=2){\n if(!vis[i])for(int j=(i*i);j<=N1;j+=(i+i))vis[j]=1;\n }\n for(int i=3;i<=N1;i+=2)if(!vis[i])primF[++idx]=i;\n}\n*/\n\nint main()\n{\n string s; cin>>s;\n ll n = s.size();\n ll x = 0;\n reverse(all(s));\n FOR(i,0,n-1)\n {\n x += ( s[i]-'0' ) * Bigmod(2,i,mod2);\n x %= mod2;\n }\n x = (x * Bigmod(2,n-1,mod2)) % mod2;\n co1(x);\n\n //main();\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "e75c2007eada114f0db97e965c44a09d", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n long long n,a;\n cin>>a>>n;\n string s;\n int c=0;\n while(n>0)\n {\n int a=n%10;\n n=n/10;\n if(a==2)\n {\n s+='2';\n c+=1;\n }\n if(a==3)\n {\n s+='3';\n c+=1;\n }\n if(a==4)\n {\n s+='2';\n s+='3';\n s+='2';\n c+=3;\n }\n if(a==5)\n {\n s+='5';\n c+=1;\n }\n if(a==6)\n {\n s+='3';\n s+='5';\n c+=2;\n }\n if(a==7)\n {\n s+='7';\n c+=1;\n }\n if(a==8)\n {\n s+='7';\n s+='2';\n s+='2';\n s+='2';\n c+=4;\n }\n if(a==9)\n {\n s+='7';\n s+='3';\n s+='3';\n s+='2';\n c+=4;\n }\n }\n sort(s.begin(),s.end());\n reverse(s.begin(),s.end());\n cout<\n \n#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);\nusing namespace std;\nusing ll = long long;\nusing pii = pair ;\nusing pll = pair ;\nusing ld = long double;\n// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());\n\nconst int mod = 1e9 + 7;\nconst ll inf = 1e9;\nconst ll INF = 2e18; \nconst int N = 2e6 + 66;\nconst int M = 5005;\n\nvoid solve () {\n\tll x, y;\n\tcin >> x >> y;\n\tvector px, cnt;\n\tll trash = x;\n\tfor (ll i = 2 ; i * i <= x ; ++ i) {\n\t\tif (x % i == 0) {\n\t\t\tpx.push_back (i);\n\t\t\tcnt.push_back (0);\n\t\t\twhile (x % i == 0) x /= i, cnt.back()++;\n\t\t}\n\t}\n\tif (x > 1) px.push_back (x), cnt.push_back (1);\n\tll now = 1;\n\tll ans = 0;\n\tx = trash;\n\t// int times = 0;\n\twhile (now != x && y) {\n\t\t// cout << now << \" \" << y << \"\\n\";\n\t\t// if (times++ > 10) return;\n\t\tll mx = -1, id = -1;\n\t\tfor (int i = 0 ; i < (int)px.size() ; ++ i) if (cnt[i]) {\n\t\t\tll p = px[i];\n\t\t\tll cur = (y / (now * p)) * (now * p);\n\t\t\tif (mx <= cur) mx = cur, id = i;\n\t\t}\n\t\tassert (id != -1);\n\t\tcnt[id]--;\n\t\tans += (y - mx) / now;\n\t\ty = mx;\n\t\tnow = gcd (x, y);\n\t}\n\tans += y / now;\n\tcout << ans;\n}\n\nint main (/*UwU*/) {\n\tios;\n\tint tt = 1;\n\t// cin >> tt;\n\twhile (tt--) {\n\t\tsolve();\n\t\tcout << \"\\n\";\n\t}\n}", "lang_cluster": "C++", "tags": ["math", "implementation", "binary search"], "code_uid": "9648eef7c72ff8886ea5c80b76543723", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include\n\nusing namespace std;\n\nint main()\n{\n long long n;\n while(scanf(\"%lld\",&n)!=EOF)\n {\n if(n<=4||(long long)n%2)printf(\"0\\n\");\n else\n {\n n=(long long)n/2;\n printf(\"%lld\\n\",(long long)(n-1)/2);\n }\n }\n return 0;\n}\n\t\t \t\t \t\t \t\t \t\t\t \t\t \t \t", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "e7caf6a603c026349a4f88dff51e6870", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main(){\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int k, n;\n cin >> n >> k;\n int min_numb = (int)1e9;\n for (int i = 1; i * i <= n && i < k; i++){\n if (n % i == 0) {\n int numb = (n / i) * k + i;\n if (numb < min_numb && n % k != 0) min_numb = numb;\n if (n / i < k && ((n / i) % k) != 0) numb = i * k + (n / i);\n if (numb < min_numb) min_numb = numb;\n }\n }\n cout << min_numb;\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "1469ad02eecfc843c44909499b068634", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\nint main(void){\n\n long long int n,nn,d,x,y;\n\n\tscanf(\"%lld\", &n);\n\tnn = n;\n\td=0;\n\twhile(n != 0){\n\t\tx = n;\n\t\tn /= 10;\n\t\td++;\n\t}\n\tif(d == 1) printf(\"1\\n\");\n\telse if(d > 1){\n\t\ty = (x+1)*(long long)(pow(10,d-1)+1e-9);\n//\t\tfor(int i = 0; i < d-1; i++) y*=10;\n\t\tprintf(\"%lld\\n\", y-nn);\n\t}\n//\tprintf(\"\\nd = %lld\\ny = %lld\\nx = %lld\\np = %lld\\n\",d,y,x,p);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "db7ba1cf5ab1afd5db9375d21bac299e", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define int long long\n#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);\nconst int N=2e6+10;\nconst int mod=998244353;\nint power(int x, int y){ x = x%mod, y=y%(mod-1);int ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}\nint add(int a,int b) { return (a%mod+b%mod)%mod; }\nint mul(int a,int b) { return (a%mod*b%mod)%mod; }\nint n,k;\nconst int K=210;\nvectora(N);\nvectorb(N);\nstruct cmp\n{\n\t bool operator()(const string &s,const string &t) const\n\t {\n if(t.size()>s.size()) return 1;\n else if(s.size()==t.size() and t>s) return 1;\n else return 0;\n\t }\n};\n\nint32_t main()\n{\n int n,k; cin>>n>>k; string s; cin>>s;\n setst,temp; int ans=0;\n st.insert(\"\");\n for(int j=0;jk) st.erase(st.begin());\n }\n if(st.size()\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nconst int modd=777777777;\nconst int maxn=256+15;\nconst int bia[maxn]={507720408,412133651,386543325,139952108,289303402,102404925,317067177,396414708,80515854,663739304,317300809,228877044,493725043,715317967,490300965,315527373,743539734,488329191,553627998,533025234,242583957,706116537,614109258,645447222,523195911,492109128,722623041,111085128,766395126,654378921,691964847,496688157,399056049,654363234,102052314,191720088,473910948,259736526,332840025,388047555,665791056,627111387,139696515,441456687,443032569,283264821,771641703,452641455,511306362,117572859,127701891,721298331,176520078,357242229,611296308,696994956,405628839,429224274,465336054,695091546,689828796,574648641,351220905,507964023,675326610,517248963,453528621,220301928,494463186,681789969,339589656,44524053,417125457,339589404,747135963,341780733,734158215,396817281,21997836,5728464,147611205,456248898,714128667,377654949,3862068,128418948,589390074,304947090,11703825,228266073,127304142,429215724,361541124,521572968,468358191,341231688,65323503,613778508,15985323,291661029,410970006,591638112,349541550,89967528,224922159,361094166,584206074,640051812,324264456,652625388,693768537,11740617,309238398,211085469,194905872,639416484,110110707,296645895,748118511,131177718,511142751,775975599,421403409,475528473,434685258,1768977,80301375,708023862,569195676,56238084,632887668,88089750,631539342,396695565,38780154,695798271,469819224,439587099,69045921,682966116,112310856,64943298,534475872,40215357,389728458,286368453,736006257,501181650,54829908,603489402,338032656,512182818,627500097,462674016,3103092,157324491,43978329,596818971,259025598,9088632,91991781,577291428,211245489,429471231,142626330,172560633,510907446,444609585,758102058,375112647,744786693,276174402,19259856,233672418,745389414,225772848,23385663,324290610,519804558,120337812,402578568,360676008,450089262,551043738,337388940,512108856,28879011,690040638,106017282,558262341,99972432,608226003,612152037,42414435,776201013,39580443,518796945,494437752,583194366,723936555,415359657,309569589,751104774,166684527,249229170,353120823,130668327,753823584,580966092,561963717,543672234,393846327,586278000,327398400,278403867,156455586,363920382,190245195,290039148,547014447,466218648,146037150,585462906,666008595,691786683,374707494,622498779,231158277,685740951,115612245,681825249,545555745,551718468,277206615,640171035,757727334,195193908,658656684,457760646,225925875,505761984,18685233,506832921,112511021,396846646,290147622,113924623,669986155,336008070,63611061,238586775,119956662,616557739,772784623,334527774,410403148,51933421};\nlong long f[maxn][maxn][maxn];\nint c[maxn][maxn];\nint n,m;\nint main()\n{\n scanf(\"%d%d\",&n,&m);\n if (n==256)\n {\n printf(\"%d\\n\",bia[m]);\n return 0;\n }\n f[0][0][0]=1;\n c[0][0]=1;\n for (int i=1;i<=n;i++)\n for (int j=0;j<=i;j++)\n if (j==0 || j==i) c[i][j]=1;\n else c[i][j]=(c[i-1][j]+c[i-1][j-1])%modd;\n for (int i=0;i=m)\n for (int l=0;l<=n-j;l++)\n if (l==i+1)\n {\n f[i+1][j+l][k]+=f[i][j][k]*c[n-j][l];\n f[i+1][j+l][k]%=modd;\n }\n else \n {\n f[i+1][j+l][k+l]+=f[i][j][k]*c[n-j][l];\n f[i+1][j+l][k+l]%=modd;\n }\n printf(\"%I64d\\n\",f[n][n][m]);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "d3b21be199699eb3d73f2a5061381ada", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#define F first\n#define S second\n#define all(a) a.begin(),a.end()\n#define setDP(arr) memset(arr,-1,sizeof arr)\n#define oo 2000000000\n#define inf 1000000000000000000\n#define M 1000000007\n#define M2 1000000009\n#define M3 998244353\ntypedef long long ll;\nusing namespace std;\nconst int N = 255001;\nconst long double PI = acos(-1);\n\nint n , m , freq[N],a[N],k[N];\n\nsigned main(){\n #ifndef ONLINE_JUDGE\n freopen(\"in.txt\",\"r\",stdin);\n #endif\n cin >> n >> m;\n for(int i = 0 ; i < n ; i++){\n scanf(\"%d\",&a[i]);\n }\n int s=0,ss=0;\n for(int i = 1; i <= m ; i++){\n scanf(\"%d\",&k[i]);\n s+=k[i];\n }\n for(int i = 0 ; i < n ; i++){\n ss=0;\n for(int ii = 0 ; ii <=100 ; ii++)freq[ii]=0;\n for(int j = i ; j < n ; j++){\n freq[a[j]]++;\n ss++;\n if(freq[a[j]]>k[a[j]])break;\n if(ss==s)return puts(\"YES\"),0;\n }\n }\n puts(\"NO\");\n\n\n\n\n\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "213c8263d0d75b1094050952a04a67a2", "src_uid": "59f40d9f35e5fe402112214b42b682b5", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#pragma region\r\n#include \r\n#define endl '\\n'\r\n#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);\r\n#define prec fixed< string to_string(pair& p) {return \"(\"+to_string(p.first)+\", \"+to_string(p.second)+\")\";}\r\ntemplate string to_string(A& v) {string s; for (auto &x : v) s+=(s.empty()?\"\":\", \")+to_string(x); return \"{\"+s+\"}\";}\r\ntemplate void _debug(Ts&... args){(..., (cerr<<\" \"< spf(n + 1, INT_MAX), primes;\r\n spf[0] = spf[1] = -1;\r\n for (int i = 0; i < n + 1; i++) {\r\n spf[i] = min(i, spf[i]);\r\n if (spf[i] != i) continue;\r\n for (ll j = i * (ll) i; j < n + 1; j += i)\r\n spf[j] = min(spf[j], i);\r\n }\r\n return spf;\r\n}\r\n \r\nstruct hash_int {\r\n static uint64_t splitmix64(uint64_t x) {\r\n // http://xorshift.di.unimi.it/splitmix64.c\r\n x += 0x9e3779b97f4a7c15;\r\n x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;\r\n x = (x ^ (x >> 27)) * 0x94d049bb133111eb;\r\n return x ^ (x >> 31);\r\n }\r\n\r\n size_t operator()(uint64_t x) const {\r\n static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();\r\n return splitmix64(x + FIXED_RANDOM);\r\n }\r\n};\r\n\r\n// A O(log n) function returning primefactorization\r\n// by dividing by smallest prime factor at every step\r\nll getFactorization(int x, vector& spf)\r\n{\r\n unordered_map mp;\r\n while (x != 1) {mp[spf[x]]++;x/=spf[x];}\r\n ll val = 1;\r\n for(auto& p:mp) {val*=(p.second+1); if(val>=mod) val%=mod;}\r\n return val;\r\n}\r\n\r\nint main()\r\n{\r\n fastIO\r\n auto spf = get_spf(2000000);\r\n int t=1;\r\n while (t--) {\r\n int n; cin>>n;\r\n ll ans = 0;\r\n for(int i=2;i<(2*n);i+=2){\r\n ans*=2; if(ans>=mod) ans%=mod;\r\n // debug(i,getFactorization(i/2));\r\n ans+=getFactorization(i/2, spf);\r\n // cout<<\"after including i=\"<=mod) ans%=mod;\r\n }\r\n cout<<(ans+getFactorization(n, spf))%mod<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n\nconst bool debug = false;\n\n#ifndef M_PI\n const double M_PI = acos(-1.0);\n#endif // M_PI\n\n#define y1 roman_kaban\n#define rank oryshych_konb\n#define ull unsigned long long\n//#define ll long long\nconst int mod = int(1e9) + 7;\n//const int inf = 1e9;\n//const long long infLL = 1e11;\n//const int MX2 = 10100500; // e7\n//const long long INF = 1e18 + 0.5;\nconst int MX = 200500; // e5\n//const int SZ = 1100;\n//const int delta = 1 << 19;\n\nint b[MX];\nlong long st[MX];\n\nint main()\n{\n st[0] = 1;\n for(int i = 1; i < 60; i++){\n st[i] = st[i - 1] * 2;\n }/*\n for(int i = 0; i < 50; i++){\n cout << st[i] << ' ';\n }\n return 0;*/\n ios_base::sync_with_stdio(false);\n //if(debug)\n //freopen(\"/Users/ozzy/Documents/in.txt\",\"r\", stdin);\n int n;\n cin >> n;\n vector trash;\n for(int i = 0; i < n; i++){\n long long a;\n cin >> a;\n long long t = a;\n int cnt = 0;\n while(true){\n if(t & 1) break;\n cnt++;\n t >>= 1;\n }\n if(t == 1){\n b[cnt]++;\n }else trash.push_back(a);\n }\n int r = b[0];\n for(int i = 1; i < 60; i++){\n while(b[i] > b[i - 1]){\n trash.push_back(st[i]);\n b[i]--;\n }\n }\n sort(trash.begin(), trash.end());\n vector> ans;\n for(int i = 0; i < 60; i++){\n b[i] -= b[i + 1];\n while(b[i]--){\n ans.push_back({i, 0});\n }\n }\n int pos = 0;\n for(int i = 0; i < trash.size(); i++){\n while(pos < ans.size() && st[ ans[pos].first + 1 ] < trash[i]) pos++;\n if(pos == ans.size()){cout << -1 << endl; return 0;}\n ans[pos].second = trash[i];\n pos++;\n }\n sort(ans.begin(), ans.end());\n int l = r;\n int vacant = ans.size() - trash.size();\n for(int i = 0; i < ans.size(); i++){\n vacant--;\n vacant -= ans[i].first + 1;\n if(vacant >= 0) l--; else break;\n }\n for(int i = l; i <= r; i++){\n cout << i << ' ';\n }\n cout << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy", "constructive algorithms", "binary search"], "code_uid": "c758e3ad4ec39e535f907105cece3260", "src_uid": "fc29e8c1a9117c1dd307131d852b6088", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#define maxi 100005\n#define f first\n#define s second\n#define mp make_pair\n#define pb push_back\n#define ll long long\n#define si(n) scanf(\"%d\",&n)\n#define sll(n) scanf(\"%lld\",&n)\n#define TRACE\n#ifdef TRACE\n#define trace1(x) cerr << #x << \": \" << x << endl;\n#define trace2(x, y) cerr << #x << \": \" << x << \" | \" << #y << \": \" << y << endl;\n#define trace3(x, y, z) cerr << #x << \": \" << x << \" | \" << #y << \": \" << y << \" | \" << #z << \": \" << z << endl;\n#define trace4(a, b, c, d) cerr << #a << \": \" << a << \" | \" << #b << \": \" << b << \" | \" << #c << \": \" << c << \" | \" << #d << \": \" << d << endl;\n#define trace5(a, b, c, d, e) cerr << #a << \": \" << a << \" | \" << #b << \": \" << b << \" | \" << #c << \": \" << c << \" | \" << #d << \": \" << d << \" | \" << #e << \": \" << e << endl;\n#define trace6(a, b, c, d, e, f) cerr << #a << \": \" << a << \" | \" << #b << \": \" << b << \" | \" << #c << \": \" << c << \" | \" << #d << \": \" << d << \" | \" << #e << \": \" << e << \" | \" << #f << \": \" << f << endl;\n#else\n#define trace1(x)\n#define trace2(x, y)\n#define trace3(x, y, z)\n#define trace4(a, b, c, d)\n#define trace5(a, b, c, d, e)\n#define trace6(a, b, c, d, e, f)\n#endif\nint dbg=1;\nusing namespace std;\nint main(){\n\tint a,b,c;\n\tcin>>a>>b>>c;\n\tfor(int i=0;i<=c/a;i++)\n\t\tif((c-i*a)%b==0){\n\t\t\tcout<<\"Yes\\n\";\n\t\t\treturn 0;\n\t\t}\n\tcout<<\"No\\n\";\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "a1e20db892d1e831ba529e4ab17b935b", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#if !ONLINE_JUDGE\n#include \"inc.h\"\n#endif\nusing namespace std;\ntypedef long long ll;\n\nvectorv;\nint n,q;\npaira[40];\nvoid init(string s,int at){\n\tif(at==n){\n\t\tv.push_back(s);\n\t\treturn;\n\t}\n\tfor(int i=0;i<6;++i){\n\t\ts+=i+'a';\n\t\tinit(s,at+1);\n\t\ts.resize(s.size()-1);\n\t}\n}\nunordered_mapdp;\nbool tr(string s){\n\tif(s.size()==1 && s[0]=='a')\n\t\treturn dp[s]=1;\n\tif(dp.find(s)!=dp.end())\n\t\treturn dp[s];\n\tfor(int i=0;i>a[i].first>>a[i].second;\n\tint ans=0;\n\tfor(int i=0;i\n\n\n\nint n,i;\nint a[100];\n\nvoid docfile()\n{\n\n scanf(\"%d\",&n);\n for (i=0;i<=n-1;i++)\n scanf(\"%d\",&a[i]);\n\n}\n\nint UCLN(int x,int y)\n {\n if (y%x==0)\n return x;\n else \n return UCLN(y%x,x);\n }\n \nint main ()\n {\n int t;\n docfile();\n t=a[0];\n for (i=1;i<=n-1;i++)\n {\n if (t\nusing namespace std;\nint n, m;\nlong double mem[1005][1005];\nlong double dp(int x, int y) {\n if (mem[x][y] > 0) return mem[x][y];\n if (!x) return mem[0][y] = 1.0 / (y + 1);\n if (!y) return mem[x][0] = 1;\n long double mn = dp(y, x - 1) / (dp(y, x - 1) + 1.0 / (y + 1));\n return mem[x][y] = mn * y / (y + 1) * (1 - dp(y - 1, x)) + 1 - mn;\n}\nint main() {\n scanf(\"%d%d\", &n, &m), printf(\"%.9Lf %.9Lf\", dp(n, m), 1 - dp(n, m));\n}", "lang_cluster": "C++", "tags": ["math", "dp", "probabilities", "games"], "code_uid": "ebe1ceb7ba63adfaf898376e936844b1", "src_uid": "f51586ab88399c04ffb7eaa658d294dd", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\r\nusing namespace std;\r\n#define ll long long\r\n#define ull unsigned long long\r\n#define lld long double\r\n#include\r\n#include\r\nusing namespace __gnu_pbds;\r\n#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)\r\n#define ff first\r\n#define ss second\r\n#define pb push_back\r\n#define mp make_pair\r\n#define pii pair\r\n#define PI 3.1415926535897932384626\r\n#define mod 1000000007\r\n#define ms(arr, v) memset(arr, v, sizeof(arr))\r\n#define deb(x) cout<\r\nusing ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>;\r\n\r\n// cout << s.order_of_key(2) << endl; // the number of elements in the s less than 2\r\n// cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based)\r\n\r\n#ifndef ONLINE_JUDGE\r\n#define debug(x) cerr << #x <<\" \"; _print(x); cerr << endl;\r\n#else\r\n#define debug(x)\r\n#endif\r\n\r\nvoid _print(ll t) {cerr << t;}\r\nvoid _print(int t) {cerr << t;}\r\nvoid _print(string t) {cerr << t;}\r\nvoid _print(char t) {cerr << t;}\r\nvoid _print(lld t) {cerr << t;}\r\nvoid _print(double t) {cerr << t;}\r\nvoid _print(ull t) {cerr << t;}\r\n\r\ntemplate void _print(pair p);\r\ntemplate void _print(vector v);\r\ntemplate void _print(set v);\r\ntemplate void _print(map v);\r\ntemplate void _print(multiset v);\r\ntemplate void _print(priority_queue pq);\r\ntemplate void _print(priority_queue, greater> pq);\r\ntemplate void _print(pair p) {cerr << \"{\"; _print(p.ff); cerr << \",\"; _print(p.ss); cerr << \"}\";}\r\ntemplate void _print(vector v) {cerr << \"[ \"; for (T i : v) {_print(i); cerr << \" \";} cerr << \"]\";}\r\ntemplate void _print(set v) {cerr << \"[ \"; for (T i : v) {_print(i); cerr << \" \";} cerr << \"]\";}\r\ntemplate void _print(multiset v) {cerr << \"[ \"; for (T i : v) {_print(i); cerr << \" \";} cerr << \"]\";}\r\ntemplate void _print(map v) {cerr << \"[ \"; for (auto i : v) {_print(i); cerr << \" \";} cerr << \"]\";}\r\ntemplate void _print(priority_queue pq) { if (!pq.empty()) { queue t; cerr << \"T[\"; while (pq.size() != 1) { _print(pq.top()); cerr << \",\"; t.push(pq.top()); pq.pop(); } _print(pq.top()); cerr << \"]B\"; t.push(pq.top()); pq.pop(); while (!t.empty()) { pq.push(t.front()); t.pop(); } } else { cerr << \"F[]B\"; } }\r\ntemplate void _print(priority_queue, greater> pq) { if (!pq.empty()) { queue t; cerr << \"T[\"; while (pq.size() != 1) { _print(pq.top()); cerr << \",\"; t.push(pq.top()); pq.pop(); } _print(pq.top()); cerr << \"]B\"; t.push(pq.top()); pq.pop(); while (!t.empty()) { pq.push(t.front()); t.pop(); } } else { cerr << \"F[]B\"; } }\r\n\r\n/*-------------------------------------------------------------------------------------------*/\r\nll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}\r\nll expo(ll a, ll b, ll m) {ll res = 1; while (b > 0) {if (b & 1)res = ((res % m) * (a % m)) % m; a = ((a % m) * (a % m)) % m; b = b >> 1;} return res;}\r\nll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}\r\nll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return ((((a % m) + (b % m)) % m) + m) % m;}\r\nll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return ((((a % m) * (b % m)) % m) + m) % m;}\r\nll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return ((((a % m) - (b % m)) % m) + m) % m;}\r\nll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m\r\n/*--------------------------------------------------------------------------------------------*/\r\n\r\nconst int N = (3e5) + 5;\r\n\r\nconst ll mod1 = 998244353;\r\n\r\nint32_t main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n\tfreopen(\"Error.txt\", \"w\", stderr);\r\n#endif\r\n\tfastio();\r\n\r\n\tll n, m;\r\n\tcin >> n >> m;\r\n\r\n\tvector is_prine(N, 1);\r\n\r\n\tis_prine[0] = 0, is_prine[1] = 0;\r\n\r\n\tfor (ll i = 2; i * (ll)i < N; i++) {\r\n\t\tif (is_prine[i] == 1) {\r\n\t\t\tfor (ll j = i * i; j * (ll)j < N; j += i) {\r\n\t\t\t\tis_prine[j] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Total ambiguous array = (Total number of array)- (Total number of unabiguous array).\r\n\r\n\t// total= m+(m^2)+(m^3)+(m^4)+.........+(m^n) ---> Gp\r\n\r\n\tll total = 0;\r\n\r\n\tfor (ll i = 1; i <= n; i++) {\r\n\t\tll val = expo(m, i, (ll)mod1);\r\n\r\n\t\ttotal = mod_add(total, val, (ll)mod1);\r\n\t}\r\n\r\n\ttotal %= mod1;\r\n\r\n\tdebug(total);\r\n\r\n\t// To find --> number of unambiguous arrays\r\n\r\n\t/*\r\n\t _,_,_,_,_,_,_,_,_,x,_,_,_,_,_,_,_,_,_,_\r\n\t 1,2,3,4,5,6,7,8,9,10\r\n\r\n\t What is the value of x such that if it gets left shifted to any of the positions if an element get deleted such that its\r\n\t gcd with that particular index is always >1.\r\n\r\n\t --> This is only possible if x is a multiple of all the indicies left to it and are prime number.\r\n\t --> x has to be a multiple of (2*3*5*7) , so that at any position its gcd with that index is greater than 1.\r\n\t*/\r\n\r\n\tll unambiguous = 0;\r\n\r\n\tll productOfPrimes = 1, ans = 1;\r\n\r\n\tfor (ll i = 1; i <= n; i++) {\r\n\t\tif (is_prine[i] == 1) {\r\n\t\t\tproductOfPrimes *= (ll)i;\r\n\t\t}\r\n\r\n\t\tdebug(productOfPrimes);\r\n\r\n\t\tif (productOfPrimes > m) { // Numbers have to be in the range from 1 to m .\r\n\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tll canHave = m / productOfPrimes; // Numbers from [1,m] which are multiple of product of primes.\r\n\r\n\t\tcanHave %= mod1;\r\n\r\n\t\tdebug(canHave);\r\n\r\n\t\tans *= canHave;\r\n\t\tans %= mod1;\r\n\r\n\t\tunambiguous += ans;\r\n\t\tunambiguous %= mod1;\r\n\t}\r\n\r\n\tll ambiguous = ((total - unambiguous) + (mod1)) % mod1;\r\n\r\n\tcout << ambiguous << endl;\r\n\r\n\treturn 0;\r\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "7b7451a08366ebef5cf0bcb4e7a7c787", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": " #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n #include\n\n using namespace std;\n\n int arr[15],best[20000000];\n\n int convert(int n)\n {\n int i=0,maxi;\n for(int c=0;c<10;c++)\n arr[c]=-10000000;\n while(n!=0)\n {\n arr[i]=n%10;\n n/=10;\n i++;\n }\n maxi=arr[0];\n for(int c=1;c0)\n a=solve(n-arr[0])+1;\n if(arr[1]>0)\n b=solve(n-arr[1])+1;\n if(arr[2]>0)\n c=solve(n-arr[2])+1;\n if(arr[3]>0)\n d=solve(n-arr[3])+1;\n if(arr[4]>0)\n e=solve(n-arr[4])+1;\n if(arr[5]>0)\n f=solve(n-arr[5])+1;\n if(arr[6]>0)\n g=solve(n-arr[6])+1;\n */\n int maxi=convert(n);\n return best[n]=solve(n-maxi)+1;\n }\n\n int main()\n {\n int n;\n scanf(\"%d\",&n);\n memset(best,-1,sizeof best);\n int ans=solve(n);\n printf(\"%d\\n\",ans);\n return 0;\n }\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "76b9e7c303f4d989c548f4e4b2647dfd", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nstring s[40] = { \"Washington\", \"Adams\", \"Jefferson\", \"Madison\", \"Monroe\", \"Adams\", \"Jackson\", \"Van Buren\", \"Harrison\", \"Tyler\", \"Polk\", \"Taylor\", \"Fillmore\", \"Pierce\", \"Buchanan\", \"Lincoln\", \"Johnson\", \"Grant\", \"Hayes\", \"Garfield\", \"Arthur\", \"Cleveland\", \"Harrison\", \"Cleveland\", \"McKinley\", \"Roosevelt\", \"Taft\", \"Wilson\", \"Harding\", \"Coolidge\", \"Hoover\", \"Roosevelt\", \"Truman\", \"Eisenhower\", \"Kennedy\", \"Johnson\", \"Nixon\", \"Ford\", \"Carter\", \"Reagan\" };//\u7f8e\u4e3d\u7684\u8868\u5728\u8fd9\u91cc\nint n;\nint main() {\n scanf(\"%d\",&n);\n cout<\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint h,m;\nvoid theTime(int a)\n{\n m+=a;\n for(;m>=60;)\n {\n m-=60;\n h++;\n if(h==24)\n h=0;\n }\n}\nint main()\n{\n while(~scanf(\"%d:%d\",&h,&m))\n {\n int a;\n cin>>a;\n theTime(a);\n char H[2],M[2];\n H[0]=h/10+'0';\n H[1]=h%10+'0';\n M[0]=m/10+'0';\n M[1]=m%10+'0';\n for(int i(0);i<2;i++)\n cout<\n \nusing namespace std;\n \n#define lli long long\nlli M=1e9;\n \n#define PI 3.14159265\n\nlli const MAX = 500005;\nvector e[MAX];\n\nlli power(lli x, unsigned lli y, lli p) \n{ \n lli res = 1; // Initialize result \n \n x = x % p; // Update x if it is more than or \n // equal to p \n \n if (x == 0) return 0; // In case x is divisible by p; \n \n while (y > 0) \n { \n // If y is odd, multiply x with result \n if (y & 1) \n res = (res*x) % p; \n \n // y must be even now \n y = y>>1; // y = y/2 \n x = (x*x) % p; \n } \n return res; \n} \n\nlli modInverse(lli a, lli m) \n{\n return power(a, m-2, m); \n} \n \n \nint main()\n{\n lli q=1;\n //cin>>q;\n for(lli tc=1;tc<=q;tc++)\n {\n lli M = 998244353 ;\n lli n,k,c=0;\n cin>>n>>k;\n if(n\n#define INF (~0U>>1)-3\n#define LLINF ~0ULL>>1\n#define LL long long\n#define uLL unsigned long long\n#define uint unsigned int\n#define D double\n#define LD long double\n#define rep(i,a,b) for (int i=a;i<=b;i++)\n#define drep(i,a,b) for (int i=a;i>=b;i--)\n#define M(a) memset(a,0,sizeof(a));\n#define pb push_back\n#define mp make_pair\n#define Pi M_PI\nusing namespace std;\ntemplate inline T min(T &a,T &b) {return a inline T max(T &a,T &b) {return a>b?a:b;}\ntemplate void read(T &x)\n{\n char ch;\n while ((ch=getchar()) && !isdigit(ch));x=ch-'0';\n while ((ch=getchar()) && isdigit(ch)) x=x*10+ch-'0';\n}\nstruct point\n{\n int x,y;\n point() {}\n point(int _x,int _y) : x(_x),y(_y) {}\n} ;\nint n,m,l;\nLL ans;\nint main()\n{\n\tread(n),read(m);l=n+1;\n\tint c;\n\trep(j,m+1,n-m)\n\t{\n\t\trep(i,m+1,n-m)\n\t\t{\n\t\t\tint x=j*(j*2-l*3)+l*l,y=l-j,z=l+j;\n\t\t\tif (i==m+1) c=max((x+z*i)/(i+y),m);\n\t\t\telse while ((c+1)*(i+y)<=x+z*i) c++;\n\t\t\tif (c+1<=n-m) ans+=(LL)(n-m-c);\n\t\t\telse break;\n\t\t}\n\t}\n\tprintf(\"%lld\\n\",ans*3LL);\n}", "lang_cluster": "C++", "tags": ["brute force", "geometry"], "code_uid": "970b3e80fac984915b5392a88afd0310", "src_uid": "355cc23d7a4addfc920c6e5e72a2bb64", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "# include \n# include \n# include \n using namespace std;\n struct krug{\n long long x, y, r, R;\n krug()\n {\n x = 0;\n y = 0;\n r = 0;\n R = 0;\n }\n int check(krug a, long long r1)\n {\n if(((((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y))) <= ((r - r1) * (r - r1))) && (r >= r1)) return 1;\n if((((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y))) >= ((r1 + R) * (r1 + R))) return 1;\n if(((((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y))) <= ((r1 - R) * (r1 - R))) && (r1 >= R)) return 1;\n return 0;\n }\n };\n int main()\n {\n long long ans;\n krug a, b;\n cin >> a.x >> a.y >> a.r >> a.R;\n cin >> b.x >> b.y >> b.r >> b.R;\n ans = 0;\n ans += a.check(b, b.r);\n ans += a.check(b, b.R);\n ans += b.check(a, a.r);\n ans += b.check(a, a.R);\n cout << ans;\n return 0;\n }\n", "lang_cluster": "C++", "tags": ["geometry"], "code_uid": "211c6b36bcc059b0f2af405b7c902bf5", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#define ll long long int\n#define ld long double\n#define pi pair\n#define all(x) x.begin(), x.end()\n#define allr(x) x.rbegin(), x.rend()\n#define sz(x) ((int)x.size())\n#define ln(x) ((int)x.length())\n#define mp make_pair\n#define pb push_back\n#define ff first\n#define ss second\n#define endl '\\n'\n#define dbg(x) cout<<#x<<\": \"< 0)\n {\n if(y & 1)\n res = (res % mod * x % mod) % mod;\n x = (x % mod * x % mod) % mod;\n y >>= 1;\n }\n return res;\n}\n\nll inv(ll a)\n{\n return fpow(a, mod - 2);\n}\n\nvoid cp()\n{\n ll n;\n cin >> n;\n ll ans = (fpow(2, n) + fpow(4, n)) % mod;\n ans = (ans * inv(2)) % mod;\n cout << ans;\n}\n\nint main()\n{\n FASTIO;\n int t;\n t = 1;\n // cin >> t;\n while(t--)\n {\n cp();\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "39bc68a03a1df0229793c6a220e84d26", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\n\nconst int MOD = 1000000007;\nconst int kMax = 20;\nconst int N = 75;\n\nint memo[N][1 << kMax];\nint first_one[N];\n\nstring poke;\nint n;\n\nbool ValidMask(int mask) {\n return mask != 0 && (mask & (mask + 1)) == 0;\n}\n\nint Solve(int ind, int mask) {\n if (ind == n) {\n return ValidMask(mask);\n }\n\n if (poke[ind] != 1) {\n return Solve(first_one[ind], mask);\n }\n\n int& res = memo[ind][mask];\n if (res != -1) {\n return res;\n }\n\n res = ValidMask(mask);\n\n int curr = 0;\n\n for (int i = ind; i < min(n, ind + 5); ++i) {\n curr = curr * 2 + poke[i];\n if (curr > kMax) break;\n res = (res + Solve(i + 1, mask | (1 << (curr - 1)))) % MOD;\n }\n\n return res;\n}\n\nvoid BuildFirstOne() {\n for (int i = 0; i < n; ++i) {\n first_one[i] = n;\n for (int j = i; j < n; ++j) {\n if (poke[j] == 1) {\n first_one[i] = j;\n break;\n }\n }\n }\n}\n\nint main() {\n ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);\n#ifndef ONLINE_JUDGE\n freopen(\"test.in\", \"r\", stdin);\n// freopen(\"wa.txt\", \"w\", stdout);\n#endif\n\n memset(memo, -1, sizeof memo);\n\n cin >> n >> poke;\n for (char& c : poke) {\n c -= '0';\n }\n BuildFirstOne();\n\n int res = 0;\n\n for (int i = 0; i < n; ++i) {\n res = (res + Solve(i, 0)) % MOD;\n }\n\n cout << res;\n\n}\n", "lang_cluster": "C++", "tags": ["dp", "bitmasks"], "code_uid": "219510d3a6c1289ef4542638cb8d879c", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n//#include \n//#include \n\nusing namespace std;\n//using namespace __gnu_pbds;\n\n#define ll long long int\n#define endl \"\\n\"\n#define db(x) cout<<#x<<\" ->\"<\"< \"< \"< \"< \"< \" << w << \" , \" << #x<<\" -> \"< \"< \"<\n//using ordered_set =\n//tree, rb_tree_tag, tree_order_statistics_node_update>;\n\nconst int N = (int)1.5e7;\n\nnamespace NumberTheory{\n\n #define maxn 700005\n\n const ll mod = (ll)1e6+3;\n ll fact[maxn+5];\n ll inverseFact[maxn+5];\n vector< int > Prime;\n bool vis[maxn+5];\n\n void seive(){\n for(int i=2; i*i<=maxn; i++){\n if(vis[i]==0){\n for(int j=(2*i); j<=maxn; j+=i){\n vis[j] = true;\n }\n }\n }\n Prime.push_back(2);\n for(int i=3; i<=maxn; i+=2){\n if(vis[i]==0){\n Prime.push_back(i);\n }\n }\n }\n\n ll bigmod(ll a, ll n){\n if( n==0 ) { return 1LL; }\n if( n%2==0 ){\n ll ret = bigmod(a,n/2);\n return ( (ret%mod) * (ret%mod) ) % mod;\n }\n else { return ( ( a % mod ) * ( bigmod(a,n-1) % mod ) ) % mod ; }\n }\n\n ll modInverse(ll a){\n return bigmod(a,mod-2)%mod;\n }\n\n ll nCr(int n, int r){\n ll ans = (1LL*(fact[n] * inverseFact[r])%mod * inverseFact[n-r]) % mod ;\n return (ans%mod);\n }\n\n void PreProcess(){\n fact[0] = 1LL;\n for(int i=1; i<=maxn; i++){ fact[i] = ( 1LL * fact[i-1] * i ) % mod ; }\n inverseFact[maxn] = modInverse(fact[maxn]) ;\n for(int x=maxn-1 ; x>=0 ; x--) inverseFact[x] = ( 1LL * inverseFact[x+1] * (x+1) ) % mod ;\n }\n\n vector< pair< int , int > > f(int x){\n vector< pair< int , int > > temp;\n for(int i=0; Prime[i]*Prime[i]<=x; i++){\n if(x%Prime[i]==0){\n int cnt = 0;\n while(x%Prime[i]==0){\n cnt++;\n x/=Prime[i];\n }\n temp.push_back( make_pair(Prime[i],cnt) );\n }\n }\n if(x>1){\n temp.push_back(make_pair(x,1));\n }\n return temp;\n }\n}\n\nusing namespace NumberTheory;\nint n , c;\n\nll NoOfSolutions(int res){\n ll cur = nCr(res + c - 1 , c - 1) % mod;\n return cur % mod;\n}\n\nint main(){\n ios_base::sync_with_stdio(false); cin.tie(0);\n// IN;\n PreProcess();\n cin >> n >> c;\n ll ans = 0LL;\n for(int i = 1 ; i <= n; i++){\n ans+=NoOfSolutions(i);\n ans%=mod;\n }\n ans+=mod;\n ans%=mod;\n cout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["combinatorics"], "code_uid": "c80ade1979929bf58d49822ef04b190b", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define NN 202\n#define F first\n#define S second\n#define mp make_pair\n#define INF 0x3f3f3f3f // infinito da distancia\n\nint flow[NN][NN]; // zerar antes (para 0..)\nint cap[NN][NN]; // preencher com as capacidades, deixar 0 se nao tiver ligacao\nint pre[NN], que[NN], d[NN]; // anteriores, fila, distancia\n\nint edmondsKarp(int n, int source, int sink) // nao testa se source == sink\n{\n\tint p, q, t, i, j;\n\twhile (1)\n\t{\n\t\tmemset(pre, -1, sizeof(pre));\n\t\td[source] = INF;\n\t\tp = q = 0, que[q++] = source;\n\t\twhile (p ca, cb, cc;\n\nvoid solve(int A, int B, int* vis, bool check)\n{\n\tqueue > que;\n\tvis[A*n+B] = 0;\n\tque.push(mp(A, B));\n\twhile (!que.empty())\n\t{\n\t\tpair now = que.front();\n\t\tque.pop();\n\t\tint p = now.F*n+now.S;\n\t\tint dis = vis[p];\n\t\tif (check && (mat[bi*n+bj][p] <= dis || t <= dis))\n\t\t{\n\t\t\tif (mat[bi*n+bj][p] < dis || t < dis) vis[p] = INF+1;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (int d = 0; d < 4; ++d)\n\t\t{\n\t\t\tint i = dir[d][0]+now.F;\n\t\t\tint j = dir[d][1]+now.S;\n\t\t\tif (i < 0 || j < 0 || i == n || j == n) continue;\n\t\t\tif (b[i][j] < '0' || b[i][j] > '9') continue;\n\t\t\tint q = i*n+j;\n\t\t\tif (vis[q] != INF) continue;\n\t\t\tvis[q] = dis+1;\n\t\t\tque.push(mp(i, j));\n\t\t}\n\t}\n}\n\nvoid build()\n{\n\tfor (int i = 0; i < n; ++i)\n\t{\n\t\tfor (int j = 0; j < n; ++j)\n\t\t{\n\t\t\tif (b[i][j] <= '0' || b[i][j] > '9') continue;\n\t\t\tca.push_back(i);\n\t\t\tcb.push_back(j);\n\t\t\tint p = i*n+j;\n\t\t\tcap[p+2+n*n][1] = b[i][j]-'0';\t\n\t\t}\n\t}\n\tint z = bi*n+bj;\n\tfor (int i = 0; i < n; ++i)\n\t{\n\t\tfor (int j = 0; j < n; ++j)\n\t\t{\n\t\t\tif (a[i][j] <= '0' || a[i][j] > '9') continue;\n\t\t\tint p = i*n+j;\n\t\t\tcap[0][p+2] = a[i][j]-'0';\n\t\t\tfor (int k = 0; k < ca.size(); ++k)\n\t\t\t{\n\t\t\t\tint ii = ca[k];\n\t\t\t\tint jj = cb[k];\n\t\t\t\tint q = ii*n+jj;\n\t\t\t\tif (mat[p][q] < INF)\n\t\t\t\t\tcap[p+2][q+2+n*n] = INF;\n\t\t\t}\n\t\t}\n\t}\n}\n\nint main()\n{\n\tscanf(\"%d%d\", &n, &t);\n\tmemset(mat, 0x3f, sizeof mat);\n\tfor (int i = 0; i < n; ++i)\n\t\tscanf(\"%s\", a[i]);\n\tfor (int i = 0; i < n; ++i)\n\t\tscanf(\"%s\", b[i]);\n\tfor (int i = 0; i < n; ++i)\n\t{\n\t\tfor (int j = 0; j < n; ++j)\n\t\t{\n\t\t\tif (a[i][j] == 'Z') bi = i, bj = j;\n\t\t}\n\t}\n\tsolve(bi, bj, mat[bi*n+bj], false);\n\tfor (int i = 0; i < n; ++i)\n\t\tfor (int j = 0; j < n; ++j) if (a[i][j] >= '1' && a[i][j] <= '9')\n\t\t\tsolve(i, j, mat[i*n+j], true);\n\tbuild();\n\t/*for (int i = 2; i < n*n+2; ++i) \n\t\tfor (int j = 2; j < n*n+2; ++j) if (cap[i][j] == INF)\n\t\t\tprintf(\"link %d to %d\\n\", i-2, j-2);\n\tfor (int i = 2; i < n*n+2; ++i)\n\t\tprintf(\"cap from %d is %d\\n\", i-2, cap[0][i]);\n\tfor (int i = 2; i < n*n+2; ++i)\n\t\tprintf(\"cap to %d is %d\\n\", i-2, cap[i][1]);*/\n\tprintf(\"%d\\n\", edmondsKarp(2+n*n+n*n, 0, 1));\n}\n", "lang_cluster": "C++", "tags": ["flows", "graphs", "shortest paths"], "code_uid": "c2f3fb3304bbc2af41ebc4f5ef034e2d", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n#define _ ios::sync_with_stdio(0),cin.tie(0);\n#define X first\n#define Y second\n#define mp make_pair\n#define sz(a) static_cast((a).size())\n#define FOR(i, a, b) for (int i(a), b_(b); i < b_; ++i)\n#define REP(i, n) FOR (i, 0, n)\n#define all(c) (c).begin(), (c).end()\n#define rall(c) (c).rbegin(), (c).rend()\n#define allN(c, n) (c).begin(), (c).begin() + n\n#define FORD(i, a, b) for (int i(a), b_(b); i >= b_; --i)\n#define UNIQUE(c) sort(all(c)), (c).erase(unique(all(c)), (c).end())\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef double db;\ntypedef long double ldb;\ntypedef pair pii;\ntypedef pair pll;\ntypedef pair pli;\ntypedef pair pdd;\ntemplate using max_queue = priority_queue, less>;\ntemplate using min_queue = priority_queue, greater>;\n\nconst int INF = static_cast(1e9);\nconst long long INF_LL = static_cast(4e18);\nconst double PI = acos(-1.0);\n\ntemplate inline T& smin(T& x, const T& y) { return x > y ? x = y : x; }\ntemplate inline T& smax(T& x, const T& y) { return x < y ? x = y : x; }\ntemplate inline T sqr(const T& x) { return x * x; }\ntemplate inline int sgn(const T& x) { return (T(0) < x) - (x < T(0)); }\n\ntemplate \nstatic inline T gcd(T a, T b) {\n for (a = abs(a), b = abs(b); a && b; a >= b ? a %= b : b %= a);\n return a + b;\n}\n\ntemplate \nvoid print(Iterator first, Iterator last, const char* delimiter = \" \", const char* closing = \"\\n\") {\n for (; first != last; ++first)\n cout << *first << delimiter;\n cout << closing;\n}\n\nstring line;\n\nint n, k;\n\nbool result = 1;\n\n\ninline void add(int& val, int&delta) {val+=delta;}\n\nint main() {_\n cin >> n >> k >> line;\n int start = line.find('G');\n int destination = line.find('T');\n if( abs(destination - start) % k) result = 0;\n else {\n int delta = start\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntemplate void write(T x) {if (x < 0) putchar('-'), x = -x;if (x > 9) write(x / 10);putchar(x % 10 + '0');}\ntemplate void inline read(T& x) { T f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }while (s <= '9' && s >= '0') x = (x << 3) + (x << 1) + (s ^ 48), s = getchar(); x *= f; }\n#define INF 0x3f\ntypedef long long ll;\ntypedef unsigned long long ull;\nconst ll maxn = 2e3 + 10;\nconst ll mod = 1e9+7;\nconst ll logn = 21;\nll f[maxn][maxn],s[maxn][maxn];\nll t, k;\nvoid yhdelta() {\n for (int i = 0; i <= 2000; i++)\n {\n f[i][i] = 1;\n f[i][0] = 1;\n }\n for (int i = 1; i <= 2000; i++)\n for (int j = 1; j < i; j++)\n {\n f[i][j] = (f[i - 1][j - 1] + f[i - 1][j]) % k;\n }\n for (int i = 1; i <= 2000; i++)\n for (int j = 1; j <= 2000; j++)\n {\n s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];\n if (f[i][j] == 0 && j <= i)\n s[i][j]++;\n }\n}\nvoid solve()\n{\n ll n; read(n);\n ll a[4];\n read(a[1]); read(a[2]); read(a[3]);\n if (a[a[n]] > 0 && a[n] > 0) cout << \"YES\" << endl;\n else cout << \"NO\" << endl;\n}\n\nint main() {\n ll T = 1;\n read(T);\n while (T--)\n solve();\n return 0;\n}\n\t\t \t\t\t\t \t \t \t \t \t \t\t\t", "lang_cluster": "C++", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "819bc58332a8d46995e590c64618a3cc", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tchar str[510];\n\tscanf(\"%s\",str);\n\tint t=0,i;\n\tfor(i=0;it)\n\t\t{\n\t\t printf(\"NO\\n\");\n\t\t break;\n\t }\n\t\tif(str[i]-'a'==t)\n\t\tt++;\n\t}\n\tif(i==strlen(str))\n\tprintf(\"YES\\n\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "strings", "implementation"], "code_uid": "f8e3972f7276aa47c9cdaa3c42345391", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n#include\r\n//#include\r\nusing namespace std;\r\n#define as1 ios::sync_with_stdio(false)\r\n#define as2 cout.tie(0);cin.tie(0);\r\n#define endl '\\n'\r\n#define x first\r\n#define y second\r\n#define sqrt sqrtl\r\ntypedef long long ll;\r\ntypedef double ld;\r\ntypedef pairpii;\r\ntypedef pairpdd;\r\ntypedef pairpll;\r\ntypedef pairppp;\r\nconst ll maxn = 4e6 + 7, maxd = 1e9 + 8, mod = 1e9 + 7;\r\nll n, m;\r\nll dp[maxn];\r\nll pp[maxn];\r\n\r\nvoid solve() {\r\n\tcin >> n >> m;\r\n\tdp[1] = 1;\r\n\tll pres = 1, cp = 0;\r\n\tfor (int i = 2; i <= n; i++) {\r\n\t\tcp += pp[i] + 1;\r\n\t\tcp %= m;\r\n\t\tdp[i] = pres + cp;\r\n\t\tdp[i] %= m;\r\n\t\tfor (int j = i * 2; j <= n; j += i) {\r\n\t\t\tpp[j] += dp[i] - dp[i - 1];\r\n\t\t\tpp[j] %= m;\r\n\t\t}\r\n\t\tpres += dp[i];\r\n\t\tpres %= m;\r\n\t\t//cout << i << ' ' << cp << ' ' << pres << endl;\r\n\t}\r\n\tcout << (dp[n] + m) % m;\r\n}\r\nint main() {\r\n\tas1; as2;\r\n\tint t = 1; \r\n\t//cin >> t;\r\n\tfor (int i = 1; i <= t; i++) { \r\n\t\tsolve(); \r\n\t}\r\n}\r\n", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "two pointers", "number theory"], "code_uid": "942ad8e8473c8a83df74328635185ded", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "/*29.11.2017*/\n#include\nusing namespace std;\nint main(){\n\tios_base::sync_with_stdio(0);\n\tlong long a,b,c;\n\tcin>>a>>b>>c;\n\tif(b=0){\n\t\tcout<<\"NO\";\n\t}\n\telse if(c==0&&a!=b){\n\t\tcout<<\"NO\";\t\n\t}\n\telse if(b>a&&c<=0){\n\t\tcout<<\"NO\";\n\t}\n\telse if(a==b){\n\t\tcout<<\"YES\";\n\t}\n\telse if(a>=0&&b<=0){\n\t\tif((abs(a)+abs(b))%c==0){\n\t\t\tcout<<\"YES\";\n\t\t}\n\t\telse{\n\t\t\tcout<<\"NO\";\n\t\t}\n\t}\n\telse if(a<=0&&b>=0){\n\t\tif((abs(a)+abs(b))%c==0){\n\t\t\tcout<<\"YES\";\n\t\t}\n\t\telse{\n\t\t\tcout<<\"NO\";\n\t\t}\n\t}\n\telse if(a>=0&&b>=0){\n\t\tif(abs(a-b)%c==0){\n\t\t\tcout<<\"YES\";\n\t\t}\n\t\telse{\n\t\t\tcout<<\"NO\";\n\t\t}\n\t}\n\telse if(a<=0&&b<=0){\n\t\tif((a+b)%c==0){\n\t\t\tcout<<\"YES\";\n\t\t}\n\t\telse{\n\t\t\tcout<<\"NO\";\n\t\t}\n\t}\n\telse{\n\t\tcout<<\"NO\";\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "9b56bab365307fd83657828bd4362e10", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n long long int n,A,B;\n while(cin>>n)\n {\n long long int i,left,right,mid;\n int f=0;\n for(i=1;in)\n {\n right=mid-1;\n mid=(left+right)/2;\n }\n if(A+B==n)\n {\n f=1;\n break;\n }\n }\n if(f==1)\n {\n break;\n }\n }\n if(f)\n cout<<\"YES\"<=\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define ll long long\nusing namespace std;\nconst int inf = 0x3f3f3f3f;\nconst ll mod = 1000000007;\nconst double pi = acos(1.0*(-1));\ntypedef pair P;\nint num[300010];\nll n, l, r, s = 1, ans;\nvoid solve(ll a, ll b, ll l, ll r, ll d)//\u4e8c\u5206\u7684\u601d\u60f3\n{\n\tif (a > b || l > r) return;\n\telse\n\t{\n\t\tll mid = (a + b) / 2;\n\t\tif (r < mid)solve(a, mid - 1, l, r, d / 2);\n\t\telse if (mid < l)solve(mid + 1, b, l, r, d / 2);\n\t\telse {\n\t\t\tans += d % 2;\n\t\t\tsolve(a, mid - 1, l, mid - 1, d / 2);\n\t\t\tsolve(mid + 1, b, mid + 1, r, d / 2);\n\t\t}\n\t}\n}\nint main()\n{\n\tcin >> n >> l >> r;\n\tlong long p = n;\n\twhile (p >= 2)\n\t{\n\t\tp /= 2;\n\t\ts = s * 2 + 1;\n\t}\n\tsolve(1, s, l, r, n);\n\tcout << ans << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "divide and conquer", "constructive algorithms"], "code_uid": "45671c2fa3d1a6ade6adfb20c61bbdc1", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\nint g,c,h=0;int b=0;cin>>g>>c;\nwhile(g>0){\nb=g%c+b;\nh=h+g;\ng=g/c;\n}\nh=h+b/c+(b/c+b%c)/c+((b/c+b%c)/c+(b/c+b%c)%c)/c;\ncout<\n#include\nusing namespace std;\nint main(){\n int n,area = 0,minx = 31400,miny = 31400,maxx=0,maxy=0;\n cin >> n;\n int x,y,xx,yy;\n for(int i = 0;i < n;i++){\n cin >> x;cin >> y;cin >> xx;cin >> yy;\n area += (xx-x) * (yy-y);\n if(x < minx) minx=x;\n if(y < miny) miny= y;\n if(xx > maxx) maxx = xx;\n if(yy > maxy) maxy = yy;\n }\n if ( maxx - minx == maxy - miny && area == (maxx-minx)*(maxx-minx))\n cout << \"YES\" << endl;\n else cout<<\"NO\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "c3d02f311821ab46b06c133bef37cba5", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n\tlong long n; cin >> n;\n\tif(n%2 && n>3)cout << \"1 \" << (n-3)/2 << endl;\n\telse cout << \"NO\\n\";\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "7ca440d701f345a0db59207e25f57e9a", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define ll long long\n#define endl '\\n'\n#define sz(v) (int)v.size() \n#define all(v) v.begin(), v.end()\nvoid dbg_out() { cerr << \"\\b\\b]\\n\"; }\ntemplate void dbg_out(Head H, Tail... T){ cerr << H << \", \"; dbg_out(T...);}\n#define watch(...) cerr << \"[\" << #__VA_ARGS__ << \"]: [\", dbg_out(__VA_ARGS__)\n\n\n/****************************** CODE IS HERE ***********************************/\n\n\nint main(){\n ios_base::sync_with_stdio(false); cin.tie(nullptr);\n\n int n; cin >> n;\n vector A(n);\n for (int &i: A) cin >> i;\n\n vector total(n), score(n);\n \n total[n-1] = A[n-1];\n score[n-1] = A[n-1];\n\n for (int i = n-2; i >= 0; --i) {\n total[i] = A[i] + total[i+1];\n int first = A[i] + total[i+1] - score[i+1];\n int second = score[i+1];\n score[i] = max(first, second);\n }\n\n int first = total[0] - score[0];\n int second = score[0];\n cout << min(first, second) << \" \" << max(first, second);\n\n\n return 0;\n}\n\n\n/*\n\n\n*/", "lang_cluster": "C++", "tags": ["dp", "games"], "code_uid": "eb53033d0547bdc3c2f71933672ed4ab", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std ;\n#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)\n#define ll long long\n#define lli long long int\n#define ld long double\n#define MOD 1000000007\n#define endl \"\\n\"\n#define all(v) v.begin(),v.end()\n#define tc() int t; cin >> t ; while (t--)\n\n#define what_is(x) cerr << #x << \" is \" << x << endl;\n#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator _it(_ss); err(_it, args); }\n\nvoid err(istream_iterator it) {}\ntemplate\nvoid err(istream_iterator it, T a, Args... args) {\n\tcerr << *it << \" = \" << a << endl;\n\terr(++it, args...);\n}\n\nll visted1[6];\nll visted2[6];\n\n\nvector trial_division1(long long n) {\n vector factorization;\n for (long long d = 2; d * d <= n; d++) {\n while (n % d == 0) {\n factorization.push_back(d);\n n /= d;\n \n }\n }\n if (n > 1)\n factorization.push_back(n);\n return factorization;\n}\n\n\n\nint main(){\n FAST;\n\nll a,b;\ncin>>a>>b ;\n\n\nvectorres1=trial_division1(a);\nvectorres2=trial_division1(b);\n\n\nll x=0,y=0;\n\nfor(int i=0;i\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\ntypedef vector vll;\ntypedef vector vs;\n\n\n#define f(i, a, n) for(ll i=a; i<(ll)n; i++)\n#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)\n#define PB push_back\n#define FF first\n#define SS second\nconst ll MOD = 1e9+7;\nconst ll INF = LLONG_MAX;\n\nvoid solve(){\n\tint n;\n\tcin>>n;\n\tint cnt=1;\n\tvector ans;\n\twhile(n){\n\t\tif(n%2) ans.PB(cnt);\n\t\tcnt++;\n\t\tn/=2;\n\t}\n\treverse(ans.begin(), ans.end());\n\tfor(auto c: ans) cout<>t;\n\twhile(t--){\n\t\tsolve();\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "14bf2483dc7b9f646f4222d39e37c793", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\nint f[1000010],op[100010],ans=1<<30;\nbool b[1000010];\n\nint main()\n{\n\tfor (int i=2;i<=1000000;i++)\n\t{\n\t\tif (b[i]==false) op[++op[0]]=i;\n\t\tfor (int j=1;j<=op[0];j++)\n\t\tif (i*op[j]<=1000000) b[i*op[j]]=true;\n\t\telse break;\n\t}\n\t\n\tint x,y,o;\n\tscanf(\"%d\",&x);\n\tfor (int i=x-1;i>1;i--)\n\tif (x%i==0 && b[i]==false)\n\t{\n\t\t//printf(\"%d\\n\",i);\n\t\ty=(x/i-1)*i+1;\n\t\to=0;\n\t\tfor (int j=y;j<=x;j++)\n\t\tif (f[j]==0)\n\t\t{\n\t\t\to++;\n\t\t\tif (o>500) break;\n\t\t\tf[j]=j;\n\t\t\t//if (pd(j)) continue;\n\t\t\tfor (int k=j-1;k>1;k--)\n\t\t\tif (j%k==0 && b[k]==false)\n\t\t\t{\n\t\t\t\tf[j]=min(f[j],(j/k-1)*k+1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tans=min(ans,f[j]);\n\t\t}\n\t\tcontinue;\n\t}\n\tprintf(\"%d\\n\",ans);\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "ab0073f814ee2d4e616f4e63be3125af", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\ntypedef long long int ll;\nint main(){\n ll n;\n cin>>n;\n cout<<2*n -n/2 <\n#include\n#include\nusing namespace std;\nint x[20];\nint ck()\n{\n int i;\n int a,b,c,d;\n for (i=1;i<=6;++i) x[i+6]=x[i];\n for (i=1;i<6;i+=2)\n {\n a=x[i]-x[i+2]; b=x[i+1]-x[i+3];\n if (a==0&&b==0) return 0;\n }\n for (i=1;i<6;i+=2)\n {\n a=x[i]-x[i+2]; b=x[i+1]-x[i+3];\n c=x[i+2]-x[i+4]; d=x[i+3]-x[i+5];\n if (a*c+b*d==0) return 1;\n }\n return 0;\n}\nint main()\n{\n int i;\n for (i=1;i<=6;++i) scanf(\"%d\",&x[i]);\n if (ck()) cout <<\"RIGHT\"<\nusing namespace std;\nint main()\n{\n int k, n, x;\n int a[10005];\n while(cin>>n>>k>>x){\n for(int i=0;i>a[i];\n }\n int sum=0;\n for(int i=0;i\n#include \n#include \nusing namespace std;\n\nint a[8][8];\nint n, m, ans = 0x3f3f3f3f;\n\nint main()\n{\n\tscanf (\"%d%d\", &n, &m);\n\tfor (int i = 1; i <= m; ++ i)\n\t{\n\t\tint u, v;\n\t\tscanf (\"%d%d\", &u, &v);\n\t\ta[u][v] = 1, a[v][u] = 1;\n\t}\n\tif (n <= 6)\n\t{\n\t\tprintf (\"%d\\n\", m);\n\t\treturn 0;\n\t}\n\tfor (int i = 1; i <= n; ++ i)\n\t\tfor (int j = 1; j <= n; ++ j)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tfor (int k = 1; k <= n; ++ k)\n\t\t\t\tif (a[k][i] && a[k][j])\n\t\t\t\t\t++ cur;\n\t\t\tans = min (ans, cur);\n\t\t}\n\tprintf (\"%d\\n\", m - ans);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "graphs"], "code_uid": "442e62796eb9994a2d2ed3c49c6a5dd3", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "// 1027E\n// rettangoli con righe adiacenti uguali o opposte e senza sottorettangoli con area >= k\n\n#include \nusing namespace std;\n\n#define endl \"\\n\"\n#define ll long long\n#define INF (ll)1e18\n\nll i, i1, j, k, k1, t, n, m, res, check1, a, b, mod, dp[510][510];\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n //ifstream cin(\"input.txt\");\n //ofstream cout(\"output.txt\");\n\n mod = 998244353;\n\n cin >> n >> k;\n for (i = 1; i <= n; i++) {\n for (j = 0; j <= n; j++) {\n if (j == 0 || j == 1) {\n dp[i][j] = 2;\n } else if (j <= i) {\n dp[i][j] = (2 * dp[i][j - 1] + mod) % mod;\n } else {\n dp[i][j] = (2 * dp[i][j - 1] - dp[i][j - i - 1] + mod) % mod;\n }\n }\n }\n\n dp[0][0] = 0;\n for (i = 1; i <= n; i++) {\n dp[i][0] = 0;\n dp[0][i] = 0;\n }\n\n /* for (i = 1; i <= n; i++) {\n for (j = 0; j <= n; j++) {\n cout << dp[i][j] << ' ';\n }\n cout << endl;\n } */\n\n res = 0;\n for (i = 1; i <= n; i++) {\n // cout << i << ' ' << min((k - 1) / i, n) << endl;\n m = (mod + dp[i][n] - dp[i - 1][n]) * dp[min((k - 1) / i, n)][n];\n // cout << m << endl;\n res += m;\n res %= mod;\n }\n\n if (res % 2 == 1) {\n res += mod;\n }\n res /= 2;\n res %= mod;\n\n cout << res;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "6b15184cb22127563219cade936de713", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define mp make_pair\n#define pb push_back\n#define rep(i,m,n) for(long long i = m; i < n; ++i)\n#define re return\n#define fi first\n#define se second\n#define sz(x) ((int) (x).size())\n#define all(x) (x).begin(), (x).end()\n#define sqr(x) ((x) * (x))\n\ntypedef vector vi;\ntypedef long long ll;\ntypedef long double ld;\ntypedef pair ii;\ntypedef vector vii;\ntypedef vector vs;\ntypedef vector vll;\ntypedef vector vvi;\ntypedef vector vvll;\n\nconst ll mod = 1000000007;\n\nll dp[160][160][160][4]={0};\nll sol(int c,int u,int d,int i){\n re (dp[c][u][d-1][i]+dp[c][u+1][d][i]-dp[c][u+1][d-1][i]+mod)%mod;\n}\nint main() {\n ios_base::sync_with_stdio(false);\n int n,m;\n cin>>n>>m;\n rep(c,1,m+1)\n rep(r,1,n+1)\n rep(u,1,n+2-r) {\n dp[c][u][u+r][0]=(sol(c,u,u+r,0)+1+dp[c-1][u][u+r][0]+10*mod)%mod;\n dp[c][u][u+r][1]=(sol(c,u,u+r,1)+dp[c-1][u][n+1][0]-dp[c-1][u][u+r][0]-dp[c-1][u+r][n+1][0]+\n dp[c-1][u][n+1][1]-dp[c-1][u][u+r-1][1]-dp[c-1][u+r][n+1][1]+10*mod)%mod;\n dp[c][u][u+r][2]=(sol(c,u,u+r,2)+dp[c-1][1][u+r][0]-dp[c-1][1][u][0]-dp[c-1][u][u+r][0]+\n dp[c-1][1][u+r][2]-dp[c-1][1][u][2]-dp[c-1][u+1][u+r][2]+10*mod)%mod;\n dp[c][u][u+r][3]=(sol(c,u,u+r,3)+dp[c-1][1][n+1][3]-dp[c-1][u+1][n+1][3]-dp[c-1][1][u+r-1][3]+\n dp[c-1][u+1][u+r-1][3]+dp[c-1][1][n+1][2]-dp[c-1][u+1][n+1][2]-dp[c-1][1][u+r][2]+\n dp[c-1][u+1][u+r][2]+dp[c-1][1][n+1][1]-dp[c-1][u][n+1][1]-dp[c-1][1][u+r-1][1]+\n dp[c-1][u][u+r-1][1]+dp[c-1][1][n+1][0]-dp[c-1][u][n+1][0]-dp[c-1][1][u+r][0]+\n dp[c-1][u][u+r][0]+10*mod)%mod;\n }\n ll res=0;\n rep(i,1,m+1)\n rep(j,0,4){\n res=(res+dp[i][1][n+1][j])%mod;}\n cout<\n#include \n#include \n#include \t\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\n\t\n\tlong long a, b;\n\tlong long c=0, d=0;\n\tcin >> a >> b;\n\tif (a == b)\n\t{\n\t\tcout << \"infinity\";\n\t\treturn 0;\n\t}\n\tif (a < b)\n\t{\n\t\tcout << 0;\n\t\treturn 0;\n\t}\n\ta -= b;\n\t\n\tif (a <= 0)\n\t{\n\t\tcout << \"infinity\";\n\t\treturn 0;\n\t}\n\n\n\tlong long limit = a;\n\tfor (int i = 1; i <= limit; i++)\n\t{\n\t\tlimit = a / i;\n\t\tif (i > limit)break;\n\t\tif (a%i != 0) limit++;\n\t\telse {\n\t\t\tif (i != limit)\n\t\t\t{\n\t\t\t\tif (i > b) d++;\n\t\t\t}\n\t\t\tif (limit > b) d++;\n\t\t}\n\t}\n\tcout << d;\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "9f51cd0ef0f512a0df1fcc92a0dec1f9", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nchar a1,b1,a[23333],b[23333];\nint i,j,n;\nint main()\n{\n\tscanf(\" %c%c\",&a1,&b1);\n\tscanf(\"%d\",&n);\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tscanf(\" %c%c\",&a[i],&b[i]);\n\t}\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tfor(j=1;j<=n;j++)\n\t\t{\n\t\t\tif((b[i]==a1&&a[j]==b1)||(a[i]==a1&&b[i]==b1))\n\t\t\t{\n\t\t\t\tprintf(\"YES\\n\");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"NO\\n\");\n}\n", "lang_cluster": "C++", "tags": ["brute force", "strings", "implementation"], "code_uid": "eb061b2226857153ec4afb7d7f587bf5", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n int x, h, m;\n cin >> x >> h >> m;\n int answer = 0;\n while (h%10 != 7 && m%10 != 7)\n {\n m -= x;\n if (m < 0)\n {\n h--;\n if (h < 0)\n h = 23;\n m += 60;\n }\n answer++;\n }\n cout << answer;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation"], "code_uid": "251292a9031d51b1b20f4f1edc7d6c9c", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \nusing namespace std;\n#define int long long\n\nint a , b , cnt = 1;\n\nvoid cul ( )\n{\n\tif ( a > b ) swap ( a , b );\n\twhile ( a != 1 ) {\n\t\tcnt *= a;\n\t\ta--;\n\t}\n}\n\nsigned main ( void )\n{\n\tcin >> a >> b;\n\tcul ( );\n\tcout << cnt << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation", "number theory"], "code_uid": "bd4288e58ffba130c210bec4d9f29a5e", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nlong long a,b;\nint main(void)\n{ \n scanf(\"%d%d\",&a,&b); \n while(b--)if(a%10)a--;else a/=10; \n printf(\"%lld\",a);\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "8e86453fe9d1f56d21411e36bacf8344", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17 (64)", "source_code": "#include\r\n#include\r\n#include\r\n#include\r\n#include\r\nusing namespace std;\r\nbool vis[1000001], vvis[20000001];\r\nint cnt[20];\r\nint main() {\r\n\tios_base::sync_with_stdio(0);\r\n\tcin.tie(0), cout.tie(0);\r\n\tlong long n, m;\r\n\tcin >> n >> m;\r\n\tfor (int i = 1; i <= 19; ++i) {\r\n\t\tcnt[i] = cnt[i - 1];\r\n\t\tint tmp = 0;\r\n\t\tfor (int j = 1; j <= m; ++j) {\r\n\t\t\ttmp += i;\r\n\t\t\tif (!vvis[tmp]) {\r\n\t\t\t\t++cnt[i];\r\n\t\t\t\tvvis[tmp] = 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tlong long ans = 0;\r\n\tfor (int i = 2; i <= n; ++i) {\r\n\t\tif (!vis[i]) {\r\n\t\t\tint tot = 0;\r\n\t\t\tfor (long long j = i; j <= n; j *= i)\r\n\t\t\t\tvis[j] = 1, ++tot;\r\n\t\t\tans += cnt[tot];\r\n\t\t}\r\n\t}\r\n\tcout << ans + 1 << '\\n';\r\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "number theory"], "code_uid": "18f4933bdceb6e0f0573110be4b90569", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nstring st;\nbool pd(int i)\n{\n return st[i]=='a'||st[i]=='e'||st[i]=='i'||st[i]=='o'||st[i]=='u';\n}\nint main()\n{\n\tcin>>st;\n\tfor(int i=0;i\n\nusing namespace std;\n#define fr first\n#define sc second\n#define sz(c) int(c.size())\n#define all(c) c.begin(), c.end()\n#define rall(c) c.rbegin(), c.rend()\n#define vlong long long\nint a[20];\n\nint main() {\n\tint n;\n\tcin >> n;\n\tfor (int i = 0; i < n; ++i) {\n\t\tscanf(\"%d\", &a[i]);\n\t}\n\tsort(a, a + n);\n\tclock_t t;\n\tt = clock();\n\twhile(1)\n\t{\n\t\tclock_t t1 = clock() - t;\n\t\tdouble ans = ((double)t1)/1000;\n\t\tif(ans > 1.95)break;\n\t}\n\tfor (int i = 0; i < n; ++i) {\n\t\tprintf(\"%d%c\", a[i], i == n - 1 ? '\\n' : ' ');\n\t}\n}\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "e471e83e547e85e2e6a6124211604119", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n\tstring s;\n\t\n\tcin >> s;\n\tint l = s.size(), cnt = 0;\n\t\n\tfor(int i = 0, j = l-1; i <= j; i++, j--){\n\t\tif(i == j && cnt == 0) cnt++;\n\t\telse if(s[i] != s[j]) cnt++;\n\t}\n\t\n\t\n\t\n\tif(cnt == 1) cout << \"YES\" << endl;\n\telse cout << \"NO\" << endl;\n\t\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "586dfc76bb4a8715b9bf96f91f281b6c", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include\n\nusing namespace std;\n\nint dp[402][402]= {};\n\nint x,y,n,d;\n\nint get(int a,int b){\n if(a < -200 || a > 200) return -1;\n if(b < -200 || b > 200) return -1;\n return dp[a + 200][b+ 200];\n}\nvoid set(int a, int b, int val){\n if(a < -200 || a > 200) return;\n if(b < -200 || b > 200) return;\n dp[a + 200][b+200] = val;\n return;\n}\n\nint dist2(int a, int b){\n return a * a + b * b;\n}\n\nint main(){\n while(cin >> x){\n memset(dp, 0,sizeof(dp));\n cin >> y >> n >> d;\n\n vector a(n); \n vector b(n);\n for(int i = 0; i < n; i++){\n cin >> a[i] >> b[i];\n }\n for(int i = -200; i <= 200; i++){\n for(int j = -200; j <= 200; j++){\n\tif(dist2(i, j) > d * d) {\n\t set(i, j, -1);\n\t}\n }\n }\n\n for(int rep = 0; rep < 600; rep++){\n for(int i = -200; i <= 200; i++){\n\tfor(int j = -200; j <= 200; j++){\n\t if(get(i, j) != 0) continue;\n\t for(size_t k = 0; k < n; k++){\n\t if(get(i + a[k], j + b[k]) == 1){\n\t set(i, j, -1);\n\t break;\n\t }\n\t }\n\t bool flag = true;\n\t for(size_t k = 0; k < n; k++){\n\t if(get(i + a[k], j + b[k]) != -1){\n\t flag = false;\n\t break;\n\t }\n\t }\n\t if(flag){\n\t set(i, j, 1);\n\t }\n\n\t}\n }\n }\n\n if(get(x, y) == 1){\n cout << \"Dasha\" <\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nusing ll = long long;\n\nll up(ll x, ll y) {\n\treturn x / y + (x % y != 0);\n}\n\nll stupid (ll n) {\n\tll ans = 0;\n\tfor (int i = 0; i < 60; i++) {\n\t\tans += (up((n - 1) / (1ll << i), 2)) * (1ll << (i));\n\t}\n\treturn ans;\n}\n\nstruct DSU {\n\tvectordsu;\n\tvectorsz;\n\tDSU(int n) {\n\t\tdsu.resize(n + 1);\n\t\tsz.resize(n + 1);\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tdsu[i] = i;\n\t\t\tsz[i] = 1;\n\t\t}\n\t}\n\tint find(int x) {\n\t\tif (x == dsu[x])return x;\n\t\treturn dsu[x] = find(dsu[x]);\n\t}\n\n\tvoid merge(int a, int b) {\n\t\ta = find(a);\n\t\tb = find(b);\n\t\tif (sz[a] > sz[b]) {\n\t\t\tsz[a] += sz[b];\n\t\t\tdsu[b] = a;\n\t\t}\n\t\telse {\n\t\t\tsz[b] += sz[a];\n\t\t\tdsu[a] = b;\n\t\t}\n\t}\n};\n\nll clever(ll n) {\n\tll ans = 0;\n\tvector> edges;\n\tfor (int i = 0; i < n; i++) {\n\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\tedges.emplace_back(i ^ j, i, j);\n\t\t}\n\t}\n\tDSU d(n + 1);\n\tsort(edges.begin(), edges.end());\n\tfor (auto edge : edges) {\n\t\tint w = get<0>(edge);\n\t\tint v = get<1>(edge);\n\t\tint u = get<2>(edge);\n\t\tif (d.find(u) != d.find(v)) {\n\t\t\td.merge(v, u);\n\t\t\tans += w;\n\t\t\t//cout << u << \" \" << v << endl;\n\t\t}\n\t}\n\treturn ans;\n}\n\nint main() {\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\t/*for (int i = 1; i <= 100; i++) {\n\t\tif (clever(i) != stupid(i)) {\n\t\t\tcout << i << endl;\n\t\t\tcout << clever(i) << endl;\n\t\t\tcout << stupid(i) << endl;\n\t\t\treturn 0;\n\t\t}\n\t}*/\n\tll n;\n\tcin >> n;\n\tcout << stupid(n);\n\t//cout << stupid(4);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "bitmasks", "graphs", "implementation"], "code_uid": "2bde396316dc11b0bc91c6a3cede418d", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n \nchar str[101]; \n \nint main() \n{ \n scanf(\"%s\", str); \n int len = strlen(str); \n for (int i = 0; i < len; ++i) \n { \n if (str[i] < 'a') \n str[i] += 32; \n if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u' && str[i] != 'y') \n printf(\".%c\", str[i]); \n } \n return 0; \n} \n \t \t \t\t\t\t \t \t \t", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "78a5662ac469dfd0990e4e30095b9f89", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\nusing namespace std;\n\nint mx,b,c;\ndouble arr[15000],a;\nbool chek;\n\nint main()\n{\n\n\n for(int i=1; i<=3; i++){\n cin>>a;\n if(a==1)arr[1]+=(1/a);\n if(!((int)a%2))arr[2]+=(2/a);\n if(!((int)a%3))arr[3]+=(3/a);\n }\n if((arr[1]) || (arr[2]>=2) || (arr[3]>=3)){\n cout<<\"YES\\n\";\n }else{\n cout<<\"NO\\n\";\n }\n //chek= ((b*c)+(a*c)+(b*a))/(a*b*c);\n /*if(chek){\n cout<<\"YES\\n\";\n }else{\n cout<<\"NO\\n\";\n }\n cin>>arr[0]>>arr[1]>>arr[2];\n sort(arr,arr+3);\n mx=arr[2]-1;\n if(!mx){\n cout<<\"YES\\n\";\n return 0;\n }\n chek = (mx/arr[0])+(mx/arr[1]);\n if(chek>=mx){\n cout<<\"YES\\n\";\n }else{\n cout<<\"NO\\n\";\n }*/\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "constructive algorithms"], "code_uid": "38dc0ad1bf82c7f97fc1e664f4ed873a", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n \nint main()\n{\n int n,s,m,i,sum=0;\n\tint a[101];\n\tm=-1;\n scanf(\"%d%d\",&n,&s);\n for(i=0;i\nusing namespace std;\nint a[55];\nint num[200005];\nint main(){\n int n,m,ma=0,num,ans=0,r=0,mi=2000000;\n scanf(\"%d%d\",&n,&m);\n for(int i=1;i<=n;i++){\n scanf(\"%d\",&a[i]);\n }\n sort(a+1,a+1+n);\n for(int i=0;i<=a[n];i++){\n r=0;\n ans=0;\n for(int j=1;j<=n;j++){\n if(a[j]==i){\n r++;\n }\n else if(a[j]>i){\n int x=a[j],c=0;\n while(x>i){\n x=x/2;\n c++;\n }\n if(x==i){\n r++;\n ans+=c;\n }\n }\n if(r==m) break;\n }\n if(r==m) mi=min(ans,mi);\n }\n printf(\"%d\\n\",mi);\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "b6c5b21168b01b1e80dfa48845fd9100", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\n\n\n#define inf 0x3f3f3f3f\n\n#define MOD 1000000007\n\n#define pb push_back\n\n#define sq(x) ((x)*(x))\n\n#define x first\n\n#define y second\n\n#define eps 1e-8\n\n#define bpt(x) (__builtin_popcount(x))\n\n#define bptl(x) (__builtin_popcountll(x))\n\n#define bit(x, y) (((x)>>(y))&1)\n\n#define bclz(x) (__builtin_clz(x))\n\n#define bclzl(x) (__builtin_clzll(x))\n\n#define bctz(x) (__builtin_ctz(x))\n\n#define bctzl(x) (__builtin_ctzll(x))\n\n#define debug(x) cout << #x << \" = \" << x << endl\n\n\n\nusing namespace std;\n\ntypedef long long INT;\n\ntypedef vector VI;\n\ntypedef pair pii;\n\ntypedef pair pi3;\n\ntypedef double DO;\n\n\n\ntemplate inline void smin(T &a, U b) {if (a>b) a=b;}\n\ntemplate inline void smax(T &a, U b) {if (a> d >> k >> a >> b >> t;\n\n\t\n\n\tif(d<=k) cout << d*a << endl;\n\n\telse if(d<=2*k) cout << min(k*a+t+(d-k)*a, k*a+(d-k)*b) << endl;\n\n\telse {\n\n\t\tINT ans=d*b;\n\n\t\tsmin(ans, d/k*(k*a+t)+d%k*a);\n\n\t\tINT st=1, ed=d/k, mid1, mid2;\n\n\t\twhile(ed-st>2){\n\n\t\t\tmid1=(st*2+ed)/3;\n\n\t\t\tmid2=(st+ed*2)/3;\n\n\t\t\tif(mid1*(k*a+t)-t+(d-mid1*k)*b<=mid2*(k*a+t)-t+(d-mid2*k)*b) ed=mid2;\n\n\t\t\telse st=mid1;\n\n\t\t}\n\n\t\tfor(mid1=st; mid1<=ed; mid1++){\n\n\t\t\tsmin(ans, mid1*(k*a+t)-t+(d-mid1*k)*b);\n\n\t\t}\n\n\t\tcout << ans << endl;\n\n\t}\n\n\t\n\n\treturn 0;\n\n}\n ", "lang_cluster": "C++", "tags": ["math"], "code_uid": "688ba6ae2b7a58475b3d99f6925fe902", "src_uid": "359ddf1f1aed9b3256836e5856fe3466", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nchar c[10][10];\nint main() {\n\tfor(int i=0; i<4; i++)\n\t\tfor(int j=0; j<4; j++)\n\t\t\tcin>>c[i][j];\n\tbool flag=0;\n\tfor(int i=0; i<4; i++) {\n\t\tfor(int j=0; j<4; j++)\n\t\t\tif(c[i][j]=='.') {\n\t\t\t\tif(i>0 && i<3 && c[i-1][j]=='x' && c[i+1][j]=='x') flag=1;\n\t\t\t\telse if(j>0 && j<3 && c[i][j-1]=='x' && c[i][j+1]=='x') flag=1;\n\t\t\t\telse if(j>0 && i>0 && j<3 && i<3 && c[i-1][j-1]=='x' && c[i+1][j+1]=='x') flag=1;\n\t\t\t\telse if(j>0 && i>0 && j<3 && i<3 && c[i-1][j+1]=='x' && c[i+1][j-1]=='x') flag=1;\n\t\t\t\telse if(i>1 && c[i-1][j]=='x' && c[i-2][j]=='x') flag=1;\n\t\t\t\telse if(j>1 && c[i][j-1]=='x' && c[i][j-2]=='x') flag=1;\n\t\t\t\telse if(i<2 && c[i+1][j]=='x' && c[i+2][j]=='x') flag=1;\n\t\t\t\telse if(j<2 && c[i][j+1]=='x' && c[i][j+2]=='x') flag=1;\n\t\t\t\telse if(i>1 && j>1 && c[i-1][j-1]=='x' && c[i-2][j-2]=='x') flag=1;\n\t\t\t\telse if(i<2 && j<2 && c[i+1][j+1]=='x' && c[i+2][j+2]=='x') flag=1;\n\t\t\t\telse if(i>1 && j<2 && c[i-1][j+1]=='x' && c[i-2][j+2]=='x') flag=1;\n\t\t\t\telse if(i<2 && j>1 && c[i+1][j-1]=='x' && c[i+2][j-2]=='x') flag=1;\n\t\t\t\tif(flag) break;\n\t\t\t}\n\t\tif(flag) break;\n\t}\n\tif(flag) printf(\"YES\");\n\telse printf(\"NO\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "68be7913d7ce93a0cdca60cbae812e89", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n#include \nusing namespace std;\ntypedef long long ll;\n#define loop(x, n) for(int x = 0; x < n; ++ x)\nlong long GCD(long long n1, long long n2)\n{\n if (n2 != 0)\n return GCD(n2, n1 % n2);\n else\n return n1;\n}\nlong long LCM(long long n1, long long n2)\n{\n long long m;\n m=n1*n2/GCD(n1,n2);\n return m;\n}\nunsigned long long choose(unsigned long long n, unsigned long long k)\n{\n if (k > n)\n {\n return 0;\n }\n unsigned long long r = 1;\n for (unsigned long long d = 1; d <= k; ++d)\n {\n r *= n--;\n r /= d;\n }\n return r;\n}\nbool isprime(int x)\n{\n if(x==1)\n return 0;\n for(int i=2; i*i>a>>b;\n x=LCM(a,b);\n if(abs(x/a-x/b)-1==0)\n cout<<\"Equal\"<x/b)\n cout<<\"Dasha\"<\nusing namespace std;\nconst char duom[] =\"i.txt\";\nint main()\n{\n // ifstream cin (duom);\n int n;\n cin >> n;\n int ind1=1;\n int ind2=1;\n while(true)\n {\n if(ind1*ind2>=n)\n {\n break;\n }\n if(ind1==ind2)\n {\n ind1++;\n continue;\n }else\n {\n ind2++;\n }\n }\n cout << ind1+ind2;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "7fe86d4bc00f54c29dbcee249040185c", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "//try 10\n #pragma GCC optimize(\"O3\")\n #include \n // #include \n // using namespace __gnu_pbds;\n // gp_hash_table mapka;\n \n using namespace std;\n #define PB push_back\n #define MP make_pair\n #define LL long long\n #define int LL\n #define FOR(i,a,b) for(int i = (a); i <= (b); i++)\n #define RE(i,n) FOR(i,1,n)\n #define REP(i,n) FOR(i,0,(int)(n)-1)\n #define R(i,n) REP(i,n)\n #define VI vector\n #define PII pair\n #define LD long double\n #define FI first\n #define SE second\n #define st FI\n #define nd SE\n #define ALL(x) (x).begin(), (x).end()\n #define SZ(x) ((int)(x).size())\n \n template void mini(C &a4, C b4) { a4 = min(a4, b4); }\n template void maxi(C &a4, C b4) { a4 = max(a4, b4); }\n \n template void _dbg(const char *sdbg, TH h){ cerr< void _dbg(const char *sdbg, TH h, TA... a) {\n while(*sdbg!=',')cerr<<*sdbg++;\n cerr<<'='< ostream &operator<<(ostream& os, vector V) {\n os << \"[\"; for (auto vv : V) os << vv << \",\"; return os << \"]\";\n }\n template ostream &operator<<(ostream &os, pair P) {\n return os << \"(\" << P.st << \",\" << P.nd << \")\";\n }\n \n #ifdef LOCAL\n #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)\n #else\n #define debug(...) (__VA_ARGS__)\n #define cerr if(0)cout\n #endif\n \n const int MAX = 1e6 + 5;\n int np[MAX];\n int koszt[MAX];\n int n,k;\n int ilepom[MAX],ile[MAX];\n const int inf = 1e18;\n int licz(){\n set secik;\n for(int i = 3; i<=n; i++){\n if(ile[i] == 0)\n secik.insert({koszt[i],i});\n }\n int res = 0;\n R(_,k){\n if(secik.empty())return inf;\n PII pom = *secik.begin();\n debug(pom);\n res += pom.FI;\n secik.erase(secik.begin());\n for(int j = 2; j * pom.SE <= n; j++){\n int i = j * pom.SE;\n koszt[i] -= pom.FI;\n ile[i]--;\n if(ile[i] == 0)\n secik.insert({koszt[i],i});\n }\n }\n return res;\n }\n int32_t main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout << fixed << setprecision(11);\n cerr << fixed << setprecision(6);\n cin >> n >> k;\n for(int i = 3; i <= n; i++){\n for(int j = 2; i * j <= n; j++){\n ilepom[i*j] ++;\n }\n }\n R(i,n + 1){\n koszt[i] = (i%2 ? i - 1 : inf);\n ile[i] = (i % 2 ? ilepom[i] : inf);\n }\n int res1 = licz() + 1;\n R(i,n + 1){\n koszt[i] = i - (i % 2 ? 1 : 2);\n ile[i] = ilepom[i];\n }\n int res2 = licz() + 2;\n debug(res1,res2);\n cout << min(res1,res2) << \"\\n\";\n }", "lang_cluster": "C++", "tags": ["math", "greedy", "number theory"], "code_uid": "5e16fb225e6ef2140c58223af6253e62", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "/// https://en.wikipedia.org/wiki/Prime-counting_function\n#include\n#define int long long\nusing namespace std;\n\nconst int N = 1e2 + 5, M = 1e5 + 5, MX = 1e7 + 5;\n\n\nint n, x, y, dp[N][M], mem[MX];\nbool used[MX];\nvector < int > primes;\n\nint phi(int m, int n){\n if(n == 0){\n return m;\n }\n if(primes[n - 1] >= m){\n return 1;\n }\n if(m < M && n < N){\n return dp[n][m];\n }\n return phi(m, n - 1) - phi(m / primes[n - 1], n - 1);\n}\n\nint rec(int m){\n if(m < MX){\n return mem[m];\n }\n int s2 = sqrtl(m), s3 = cbrtl(m);\n int n = rec(s3);\n int ans = phi(m, n) + n - 1;\n for(int i = n; primes[i] <= s2; i++){\n ans -= rec(m / primes[i]);\n ans += rec(primes[i]);\n ans -= 1;\n }\n return ans;\n}\n\nmain(){\n ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n for(int i = 2; i < MX; i++){\n mem[i] = mem[i - 1];\n if(!used[i]){\n mem[i] += 1;\n primes.push_back(i);\n for(int j = i * i; j < MX; j += i){\n used[j] = true;\n }\n }\n }\n for(int i = 0; i < N; i++){\n for(int j = 0; j < M; j++){\n if(!i){\n dp[i][j] = j;\n }\n else{\n dp[i][j] = dp[i - 1][j] - dp[i - 1][j / primes[i - 1]];\n }\n }\n }\n cin >> n;\n long long ans = 0;\n for(int i = 0; i < primes.size(); i++){\n int x = primes[i], y = n / x;\n if(x * x > n){\n break;\n }\n ans += rec(y) - rec(x);\n }\n for(int i = 0; i < primes.size(); i++){\n int x = primes[i];\n if(x * x * x > n){\n break;\n }\n ans++;\n }\n cout << ans;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "sortings", "data structures", "two pointers", "number theory"], "code_uid": "561446f0516871308aad6b00f2c76571", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "#include \nusing namespace std;\n\ntypedef long long i64;\ntypedef double db;\ntypedef vector vi;\ntypedef pair pii;\n\ntemplate\ninline T read(){\n T x=0,f=1;char ch=getchar();\n while(ch<'0'||ch>'9'){\n if(ch=='-') f=-1;\n ch=getchar();\n }\n while(ch>='0'&&ch<='9'){\n x=(x<<1)+(x<<3)+(ch^48);\n ch=getchar();\n }\n return x*f;\n}\n\n#define rdi read\n#define rdi64 read\n#define fi first\n#define se second\n#define pb push_back\n#define mp make_pair\n\nconst int N=7,INF=0x3f3f3f3f;\nconstexpr int pw5[N]={1,5,25,125,625,3125,15625};\n\nint n,m,a[N],b[N],c[N][N];\nint f[N][pw5[N-1]];\n\nint main(){\n#ifdef LOCAL\n freopen(\".in\",\"r\",stdin);\n freopen(\".out\",\"w\",stdout);\n#endif\n n=rdi(),m=rdi();\n for(int i=1;i<=n;i++) a[i]=rdi();\n for(int i=1;i<=m;i++) b[i]=rdi();\n for(int i=1;i<=n;i++)\n for(int j=1;j<=m;j++) c[i][j]=rdi();\n \n memset(f,0x3f,sizeof(f));\n\n int stat=0;\n for(int i=1;i<=m;i++) stat+=pw5[i-1]*b[i];\n f[0][stat]=0;\n\n for(int i=1;i<=n;i++){\n static int sum[(1<>(k-1)&1)*c[i][k];\n }\n\n for(int j=0;j=INF) continue;\n for(int k=0;k<(1< dfs = [&](int x,int stat,int s,int rest){\n if(x>m){\n if(!rest) f[i][stat]=min(f[i][stat],f[i-1][j]+sum[k]);\n return;\n }\n int cap=stat/pw5[x-1]%5;\n if(!(s>>(x-1)&1)) cap=0;\n for(int i=0;i<=min(cap,rest);i++)\n dfs(x+1,stat-pw5[x-1]*i,s,rest-i);\n };\n dfs(1,j,k,a[i]);\n }\n }\n }\n int ans=*min_element(f[n],f[n]+pw5[m]);\n cout<<(ans>=INF?-1:ans)<\n#include \n#define for32(i,n,x) for(int i=0;i> Vp >> Vd >> t >> f >> c;\n\tVp = Vp / (3600.0);\n\tVd = Vd /(3600.0);\n\tt = t * 60 * 60;\n\tf = f * 60 * 60;\n\tint bijous = 0;\n\tdouble dDist = 0,qDist = Vp * t;\n\twhile(qDist < c){\n\t\tif(dDist >= qDist){\n\t\t\tdouble dragH = (dDist / Vd);\n\t\t\tdDist = 0;\n\t\t\tqDist += (Vp) * (f + dragH);\n\t\t\tbijous++;\n\t\t}\n\t\telse{\n\t\t\tdDist += Vd;\n\t\t\tqDist += Vp;\t\n\t\t}\n\t}\n\tcout< 0){\n arr[i][j] = d[i] % 10;\n d[i] /= 10;\n j++;\n }\n nn[i] = j;\n }\n\n int n;\n if (nn[0] == nn[1])\n n = nn[0]; else \n {\n cout<<\"WRONG_ANSWER\"; \n return 0;\n }\n\n for (int i=0;i<2;i++)\n for (int j=0;j\n\n#define EPS 1e-9\n#define INF 1070000000LL\n#define MOD 1000000007LL\n#define fir first\n#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)\n#define ite iterator\n#define mp make_pair\n#define mt make_tuple\n#define rep(i,n) rep2(i,0,n)\n#define rep2(i,m,n) for(int i=m;i<(n);i++)\n#define pb push_back\n#define sec second\n#define sz(x) ((int)(x).size())\n\nusing namespace std;\n\ntypedef istringstream iss;\ntypedef long long ll;\ntypedef pair pi;\ntypedef stringstream sst;\ntypedef vector vi;\n\nstring s;\n\nint main(){\n\tcin.tie(0);\n\tios_base::sync_with_stdio(0);\n\t\n\tcin>>s;\n\tchar m=*max_element(s.begin(),s.end());\n\trep(i,sz(s))if(s[i]==m)cout<\n#define ll long long\n\nusing namespace std;\nll tab[55];\nbool cmp(int a,int b)\n{\n return (a>b);\n}\nint main()\n{\n //freopen(\"in\",\"r\",stdin);\n ll n;\n cin>>n;\n for(int i=0; i>tab[i];\n\n\n sort(tab,tab+n);\n for(int i=0; i\n#include \n\nint main() {\n\tint n, m;\n\t\n\tstd::cin >> n >> m;\n\t\n\tif (std::min(n, m) % 2) {\n\t\tstd::cout << \"Akshat\" << '\\n';\n\t} else {\n\t\tstd::cout << \"Malvika\" << '\\n';\n\t}\n\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "2fe366acd170179e9e21520fa6ae6baf", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n#define ll long long int \n#define pb push_back\n#define popb pop_back\n#define forr(x,y) for(ll i=x;i<=y;i++)\n\nvoid solve(){\n ll n, k, sum1=0, sum2=0;\n cin>>n>>k;\n \n if(n>t;\n t=1;\n while(t--){\n solve();\n }\n cerr << \"Time : \" << (double)clock() / (double)CLOCKS_PER_SEC << \"s\\n\";\n return 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "implementation", "games"], "code_uid": "5ed428d3beff2ce10c98c385a934bd2e", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\ntypedef long long int64;\n\nchar buf[1<<16];\nint p=0, l=0;\n\nvoid _readbuf() {\n cin.read(buf, 1 << 16);\n l = cin.gcount();\n p = 0;\n}\n\nbool _eof() {\n if (p < l) return false;\n _readbuf();\n return p == l;\n}\n\nchar _nextc() {\n if (p < l) return buf[p++];\n if (cin.eof()) throw 1;\n _readbuf();\n if (p < l) return buf[p++];\n throw 2;\n}\n\nstring nexttoken() {\n string s=\"\";\n\n while (!_eof()) {\n char c = _nextc();\n if (c == ' ' || c == '\\r' || c == '\\n' || c == '\\t') continue;\n s += c;\n while (!_eof()) {\n c = _nextc();\n if (c == ' ' || c == '\\r' || c == '\\n' || c == '\\t') break;\n s += c;\n }\n break;\n }\n\n return s;\n}\n\nstring nextline() {\n string s = \"\";\n\n while (!_eof()) {\n char c = _nextc();\n if (c == '\\r' || c == '\\n') continue;\n s += c;\n while (!_eof()) {\n c = _nextc();\n if (c == '\\r' || c == '\\n') break;\n s += c;\n }\n break;\n }\n\n return s;\n}\n\nint nextint() {\n string s = nexttoken();\n if (s == \"\") throw 3;\n bool minus = s[0] == '-';\n int64 res = 0;\n for (size_t i = minus?1:0; i < s.length(); i++)\n {\n if (s[i]<'0' || s[i]>'9') throw 4;\n res = 10 * res + s[i]-'0';\n }\n if (minus) res = -res;\n if (res > 2147483647LL || res < -2147483648LL) throw 5;\n return (int)res;\n}\n\nint64 nextlong() {\n string s = nexttoken();\n if (s == \"\") throw 3;\n bool minus = s[0] == '-';\n int64 res = 0;\n for (size_t i = minus ? 1 : 0; i < s.length(); i++)\n {\n if (s[i]<'0' || s[i]>'9') throw 4;\n res = 10 * res + s[i] - '0';\n }\n if (minus) res = -res;\n return res;\n}\n\ndouble nextdouble() {\n string s = nexttoken();\n if (s == \"\") throw 5;\n double res = 0;\n bool minus = s[0] == '-';\n bool haveDigits = false;\n bool decimalSeparatorFound = false;\n size_t i;\n for (i = minus ? 1 : 0; i < s.length(); i++)\n {\n if (s[i] == '.' || s[i]==',') {\n decimalSeparatorFound = true;\n ++i;\n break;\n }\n if (s[i] < '0' || s[i] > '9') throw 7;\n res = 10 * res + s[i] - '0';\n haveDigits = true;\n }\n if (decimalSeparatorFound) {\n int64 p = 0, q = 1;\n int len = 0;\n for (; i < s.length(); i++)\n {\n if (s[i] < '0' || s[i] > '9') throw 8;\n haveDigits = true;\n\n if (++len < 17) {\n p = 10 * p + s[i] - '0';\n q *= 10LL;\n }\n }\n if (len > 0) {\n res += (double)p / q;\n }\n }\n if (!haveDigits) {\n throw 9;\n }\n return minus ? -res : res;\n}\n\nvoid solve() {\n int n = nextint();\n string s = nexttoken();\n\n int res = 0;\n\n for (size_t i = 0; i < n; i++)\n {\n for (size_t j = i; j < n; j++)\n {\n int x = 0, y = 0;\n for (size_t k = i; k <= j; k++)\n {\n if (s[k] == 'U') ++y;\n if (s[k] == 'D') --y;\n if (s[k] == 'L') ++x;\n if (s[k] == 'R') --x;\n }\n if (x == 0 && y == 0)\n ++res;\n }\n }\n\n printf(\"%d\\n\", res);\n}\n\nint main()\n{\n#ifdef GAMER34\n freopen(\"input.txt\", \"r\", stdin);\n#endif\n\n cin.sync_with_stdio(false);\n cin.tie(nullptr);\n\n cout.precision(10);\n\n solve();\n\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "8bda6cabc8ae591e5c71a51551468327", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#define ll long long int\nusing namespace std;\nint main()\n{\n ll n,x,count=0;\n cin>>n>>x;\n for(ll i=1;i*i<=x;i++)\n {\n if(x%i==0 && i<=n && (x/i)<=n )\n if(i==(x/i)) count++;\n else count+=2; \n }\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include\n\nusing namespace std;\n\ntypedef long long ll;\n\nint clearr(int n) {\n int a = 0;\n int b = 1;\n while(n!=0)\n {\n if (n%10!=0)\n {\n a += (n%10)*b;\n b *= 10;\n }\n n /= 10;\n }\n return a;\n}\n\nint main()\n{\n int a, b, c;\n cin >> a >> b;\n c = a + b;\n a = clearr(a);\n b = clearr(b);\n c = clearr(c);\n if (a+b==c) cout << \"YES\";\n else cout << \"NO\";\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "32939771d2f59ff5ede5caca1839db14", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#define int long long\n#define double long double\n#define pb push_back\n#define sp ' '\n#define endl '\\n'\n#define fi first\n#define se second\nusing namespace std;\nconst int mod=1e9+7;\nconst int N=1e5+7;\nconst double pi=acos(-1);\nvector ans;\nsigned main()\n{\nint p,k; cin>>p>>k;\nans.pb(p%k);\nif(p= k || cur<0)\n{\n\tint tem=(cur+k*abs(cur))%k;\n\tans.pb(tem);\n\tcur=(tem-cur)/k;\n}\nif(cur>0) ans.pb(cur);\n\ncout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define mems(arr, val) memset(arr, val, sizeof(arr))\n#define forn(it, from, to) for(int it = from; it < to; ++it)\n#define all(A) (A).begin(), A.end()\n#define mp(a, b) make_pair(a, b)\ntypedef unsigned long long LL;\n\nint D[41][41];\nint A[41][41];\nint rec(int a, int b, int c, int d)\n{\n\tif (c < a || d < b) return 0;\n\tint result = 0;\n\tif (c >= a && D[c - 1][d] == -1 && A[c - 1][d] == 1)\n\t{\n\t\tD[c - 1][d] = rec(a, b, c - 1, d); \n\t}\n\n\tif (d >= b && D[c][d - 1] == -1 && A[c][d - 1] == 1)\n\t{\n\t\tD[c][d - 1] = rec(a, b, c, d - 1);\n\t}\n\n\treturn D[c - 1][d] + D[c][d - 1] + A[c][d];\n}\n\nint main()\n{\n#ifdef MY_SOL\n freopen(\"input.txt\", \"r\", stdin); freopen(\"output.txt\", \"w\", stdout);\n#endif\n\tLL w, m, k;\n\tLL ans = 0;\n\tcin>>w>>m>>k;\n\tvector A;\n\tLL cur = 10;\n\tforn(i, 0, 17)\n\t{\n\t\tA.push_back(cur);\n\t\tcur *= 10;\n\t}\n\n\tint curdeg = 0;\n\twhile (w > 0)\n\t{\n\t\tif (A[curdeg] > m)\n\t\t{\n\t\t\tLL tmp = (A[curdeg] - m) * (curdeg + 1) * k;\n\t\t\tif (tmp > w)\n\t\t\t{\n\t\t\t\tans += (w) / ((curdeg + 1) * k);\n\t\t\t\tcout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#define lp(i,n) for(int i=0;(int)i> n;\n\tvector num;\n\tint a = 1;\n\tnum.push_back(a);\n\tfor (int i = 1;i <= 9;i++)\n\t{\n\t\ta = a << 2;\n\t\tint y = 1;\n\t\ty = y << i;\n\t\t//cout << bitset<32>(a) << \" \" << bitset<32>(y) << endl;\n\t\ta = (a | y);\n\t\tnum.push_back(a);\n\n\t}\n\tint ans = 0;\n\tfor (int i = 0;i ( num[i] )<< endl;\t}\n\t//cout << endl << endl;\n\t*/cout << ans << endl;\n\t\n\n\treturn 0;\n} \n\n\n\n\n\n\n\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "cb1bf71752ced52ee4f401e9fe4a9e4b", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \nusing namespace std;\nstring odpoved;\nint n;\nint main()\n{\ncin>>n;\nint m;\nint p;\ncin>>p;\nint k;\nk=0;\nfor(int i=0;i<(n-1);i++){\n cin>>m;\n if(abs(m-p)>1){\n k=1;\n }\n p=m;\n}\nif(k==1){\n cout<<\"NO\";\n}else{\ncout<<\"YES\";\n}\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "f6db015818281d78acb000d00a5cb944", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\n\nstruct Node {\n int a[4];\n};\n\nbool vis[4][4][4][4];\n\nvoid set_vis(const Node& no) {\n vis[no.a[0]][no.a[1]][no.a[2]][no.a[3]] = true;\n}\n\nbool get_vis(const Node& no) {\n return vis[no.a[0]][no.a[1]][no.a[2]][no.a[3]];\n}\n\nint main() {\n Node s, t;\n char g[8];\n scanf(\"%s %s\", g, g+2);\n for (int i = 0; i < 4; i++) {\n if (g[i] == 'X')\n s.a[i] = 3;\n else\n s.a[i] = g[i] - 'A';\n }\n scanf(\"%s %s\", g, g+2);\n for (int i = 0; i < 4; i++) {\n if (g[i] == 'X')\n t.a[i] = 3;\n else\n t.a[i] = g[i] - 'A';\n }\n memset(vis, 0, sizeof(vis));\n queue q;\n set_vis(s);\n q.push(s);\n while (!q.empty()) {\n Node no = q.front();\n q.pop();\n for (int k = 0; k < 4; k++) {\n if (no.a[k] == 3) {\n swap(no.a[k], no.a[k^1]);\n if (!get_vis(no)) {\n set_vis(no);\n q.push(no);\n }\n swap(no.a[k], no.a[k^1]);\n swap(no.a[k], no.a[k^2]);\n if (!get_vis(no)) {\n set_vis(no);\n q.push(no);\n }\n swap(no.a[k], no.a[k^2]);\n }\n }\n }\n puts(get_vis(t) ? \"YES\" : \"NO\");\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "cb480a5a4d21431528d9f599b3e4ee1e", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\nusing namespace std;\n\ntypedef pair II;\ntypedef vector< II > VII;\ntypedef vector VI;\ntypedef vector VLL;\ntypedef vector< VI > VVI;\ntypedef long long int LL;\n\n#define PB push_back\n#define MP make_pair\n#define F first\n#define S second\n#define SZ(a) (int)(a.size())\n#define ALL(a) a.begin(),a.end()\n#define SET(a,b) memset(a,b,sizeof(a))\n\n\n#define din(n) int n; scanf(\"%d\",&n)\n#define dout(n) printf(\"%d\\n\",n)\n#define llin(n) long long n; scanf(\"%lld\",&n)\n#define llout(n) printf(\"%lld\\n\",n)\n#define strin(s,l) char s[l]; scanf(\"%s\",s)\n#define strout(n) printf(\"%s\\n\",n)\n#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)\n#define endl '\\n'\n\n#define TRACE\n\n#ifdef TRACE\n#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f(const char* name, Arg1&& arg1){\n cerr << name << \" : \" << arg1 << '\\n';\n}\ntemplate \nvoid __f(const char* names, Arg1&& arg1, Args&&... args){\n const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << \" : \" << arg1<<\" | \";__f(comma+1, args...);\n}\n#else\n#define trace(...)\n#endif\nbool cmpManh(const std::pair& l, const std::pair& r) {\nreturn ((llabs(l.F) + llabs(l.S)) < (llabs(r.F) + llabs(r.S)));\n}\n\nint gcd(int a, int b){\nif (a == 0) return b; return gcd(b%a, a); \n}\n\nint main(void)\n{\n\tstring s;\n\tcin>>s;\n\tLL n = 0;\n\tLL sz = s.size();\n\tfor (int i = 0; i < sz-1; ++i)\n\t{\n\t\tn += s[i]-'0';\n\t\tif(i!=sz-2) n *= 10;\n\t\t/* code */\n\t}\n\t// LL n = - '0';\n\t// trace(n);\n\tchar c = s[sz-1];\n\tLL ans = ((n-1)/4)*16;\n\tif(n%2==0){\n\t\tans += 7;\n\t}\n\tif(c=='f') ans+=1;\n\tif(c=='e') ans+=2;\n\tif(c=='d') ans+=3;\n\tif(c=='c') ans+=6;\n\tif(c=='b') ans+=5;\n\tif(c=='a') ans+=4;\n\tllout(ans);\n\n return(0);\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "646281921403c1de56b48f0ce6913a16", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nlong long n,m;\nint main()\n{\n cin>>n>>m;\n while(n&&m)\n if(n>=2*m)n%=2*m;\n else if(m>=2*n)m%=2*n;\n else break;\n cout<\r\n#include \r\nusing namespace std;\r\n#include \r\n#include \r\nusing namespace __gnu_pbds;\r\n/*............................................................................*/ \r\n#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update>\r\n/* find_by_order(x) give iterator of the index x \r\n order_by_key(x) give the position where x will be placed*/\r\n#define int long long\r\n#define lop(i,a,b,c) for (int i=a;i=b;i-=c)\r\n#define prii pair \r\n#define PB push_back\r\n#define S second\r\n#define F first\r\n#define all(x) x.begin(),x.end()\r\n#define vvii vector < vector < int > >\r\n#define vii vector \r\n#define count_1(x) __builtin_popcount(x)\r\n#define cn(a) scanf(\"%lld\",&a);\r\n#define cn_vl(arr,n) lop(i,0,n,1){scanf(\"%lld\",arr+i);}\r\n#define shw_vl(arr,n) lop(i,0,n,1){printf(\"%lld \",arr[i]);}printf(\"\\n\");\r\n#define shw(CON) cout << &(\"NO\\0YES\"[3 * CON]) << '\\n';\r\nconst int MAX=3e5+10;\r\nconst int mod=1e9+7;\r\n/*......................................................................*/\r\n\r\nvoid solve(){\r\n\tint n,m;cn(n)cn(m)\r\n\tqueue q;\r\n\tq.push({m,0});\r\n\tint cs=0;\r\n\tmap mp;\r\n\tmp[m]=1;\r\n\twhile (!q.empty())\r\n\t{\r\n\t\tauto a=q.front();q.pop();\r\n\t\tstring s=to_string(a.F);\r\n\t\tint sz=s.size();\r\n\t\tif (sz==n)\r\n\t\t{\r\n\t\t\tprintf(\"%lld\\n\",a.S);return;\r\n\t\t}\r\n\t\tcs=max(cs,sz);\r\n\t\tint arr[10];memset(arr,0,sizeof(arr));\r\n\t\tfor (auto x:s)\r\n\t\t{\r\n\t\t\tint ch=x-'0';\r\n\t\t\tarr[ch]=1;\r\n\t\t}\r\n\t\tint cn=0;\r\n\t\trlop (i,10,2,1)\r\n\t\t{\r\n\t\t\tif (arr[i])\r\n\t\t\t{\r\n\t\t\t\tif (!mp.count(a.F*i)){q.push({a.F*i,a.S+1});mp[a.F*i]=1;}\r\n\t\t\t\tcn++;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tprintf(\"-1\\n\");\r\n}\r\nint32_t main(){\r\n\tint t;t=1;\r\n\t// cin>>t;\r\n\tfor (int ie=1;ie<=t;ie++){\r\n\t\t// printf(\"Case #%d: \",ie);\r\n\t\tauto t_1=chrono::high_resolution_clock::now();\r\n\t\tsolve();\r\n\t\tauto t_2=chrono::high_resolution_clock::now();\r\n\t\t// cout <<\". Elapsed (ms): \" << chrono::duration_cast(t_2 - t_1).count() << endl;\r\n\t}\r\n\treturn 0;\r\n}", "lang_cluster": "C++", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "5b86bbf7437200e4810477114fa43d38", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\nusing namespace std;\n#include\n\nint main()\n{\n int a, b;\n cin >> a >> b;\n int x, y;\n int c1 = 0, c2 = 0, c3 = 0;\n\n for (int i = 6; i > 0; i--)\n {\n x = max(i, a) - min(i, a);\n y = max(i, b) - min(i, b);\n \n \n if (x < y)\n c1++;\n else{\n if (x>y)\n c2++;\n else c3++;\n }\n\n }\n cout << c1 << \" \" << c3 << \" \" << c2;\n \n}", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "200daa9cba78583b07349262feb2295b", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\nstruct ponto{\n\tlong long int x, y;\n\tponto() {}\n\tponto(long long int _x, long long int _y){\n\t\tx = _x;\n\t\ty = _y;\n\t}\n\t//soma de vetores\n\tponto operator+(const ponto & p){\n\t\treturn ponto(x + p.x, y + p.y);\n\t}\n\t//subtracao de vetores\n\tponto operator-(const ponto & p){\n\t\treturn ponto (x - p.x, y - p.y);\n\t}\n\t//produto escalar\n\t//se =0 entao angulo = 90\n\t//se <0 entao angulo <90\n\t//se >0 entao angulo >90\n\tlong long int operator* (const ponto & p){\n\t\treturn x * p.x + y * p.y;\n\t}\n\t//produto vetorial\n\t//se >0 entao angulo < 180\n\t//se <0 entao angulo >180\n\t//se 0 entao angulo = 0 ou =180\n\tlong long int operator^(const ponto & p){\n\t\treturn x * p.y - y * p.x;\n\t}\n\tlong long int operator~(){\n\t\treturn x * x + y * y;\n\t}\n};\n\n\nint main()\n{\n\tponto a, b, c;\n\t//ler os pontos\n\tcin >> a.x >> a.y;\n\tcin >> b.x >> b.y;\n\tcin >> c.x >> c.y;\n\t//montar os vetores\n\tponto vetor1 = b - a;\n\tponto vetor2 = c - b;\n\n\tlong long int teste = vetor1 ^ vetor2;\n\n\tif(teste == 0)cout << \"TOWARDS\" << endl;\n\telse if(teste > 0)cout << \"LEFT\" << endl;\n\telse cout << \"RIGHT\" << endl;\n}\n", "lang_cluster": "C++", "tags": ["geometry"], "code_uid": "b1b6bb9ba73bc364a5e4b7a5109183f4", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nint n,par[105];\nbool vis[105];\nint gcd(int a,int b){\n\tif(b==0)return a;\n\treturn gcd(b,a%b);\n}\nint main(){\n\tint ans=1;\n\tscanf(\"%i\",&n);\n\tfor(int i=1;i<=n;i++)scanf(\"%i\",&par[i]);\n\tfor(int j=1;j<=n;j++){\n\t\tif(vis[j])continue;\n\t\tbool valid=0;\n\t\tint pos=par[j];\n\t\tfor(int k=1;k<=n+2;k++){\n\t\t\tvis[pos]=1;\n\t\t\tif(pos==j){\n\t\t\t\tvalid=1;\n\t\t\t\tint fpb=gcd(ans,(k&1)?k:k/2);\n\t\t\t\tans=(ans*((k&1)?k:k/2))/fpb;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tpos=par[pos];\n\t\t}\n\t\tif(!valid){\n\t\t\tprintf(\"-1\\n\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tprintf(\"%i\\n\",ans);\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "math"], "code_uid": "381eda8710cfb0323257c9425a4296a0", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define ll long long\n#define pll pair\n#define ppi pair >\n#define fr first\n#define sc second\n#define PI acos(-1)\n#define mp make_pair\n\nusing namespace std;\n\n\n#define sim template < class c\n\n#define ris return * this\n#define dor > debug & operator <<\n#define eni(x) sim > typename \\\n enable_if(0) x 1, debug&>::type operator<<(c i) {\nsim > struct rge { c b, e; };\nsim > rge range(c i, c j) { return rge{i, j}; }\nsim > auto dud(c* x) -> decltype(cerr << *x, 0);\nsim > char dud(...);\nstruct debug {\n#ifdef LOCAL\n~debug() { cerr << endl; }\neni(!=) cerr << boolalpha << i; ris; }\neni(==) ris << range(begin(i), end(i)); }\nsim, class b dor(pair < b, c > d) {\n ris << \"(\" << d.first << \", \" << d.second << \")\";\n}\nsim dor(rge d) {\n *this << \"[\";\n for (auto it = d.b; it != d.e; ++it)\n *this << \", \" + 2 * (it == d.b) << *it;\n ris << \"]\";\n}\n#else\nsim dor(const c&) { ris; }\n#endif\n};\n#define imie(...) \" [\" << #__VA_ARGS__ \": \" << (__VA_ARGS__) << \"] \"\n\nint n;\nll pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};\nll ans = 1e18 + 100;\nconst ll Limit = 4e18;\n\nvoid so(int i = 0,ll sum = 1,ll num = 1){\n if(i == 10){\n if(sum == n)ans = min(ans , num);\n return ;\n }\n if(sum > n)return;\n ll x = 1;\n for(int j = 0;j<64;j++){\n if(j == 0)\n {\n so(i + 1,sum , num);\n continue;\n }\n if(Limit / x > pr[i] ){\n x = x * pr[i];\n if(Limit / x > num)\n so(i + 1,sum * (j + 1),num * x);\n else break;\n }\n else break;\n }\n return ;\n}\n\nint main()\n{\n cin >> n;\n so();\n assert(ans != 1e18 + 100);\n while(ans < 0 || ans > 1e18){\n new int[100101];\n }\n cout << ans << '\\n';\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "dp", "number theory"], "code_uid": "a9b28137c8d996db25b50b66d2e51e44", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\n#define scanfd1(x) scanf(\"%d\", &x)\n#define scanfd2(x,y) scanf(\"%d %d\", &x, &y)\n#define scanfd3(x,y,z) scanf(\"%d %d %d\", &x, &y, &z)\n#define scanfd4(x,y,z,w) scanf(\"%d %d %d %d\", &x, &y, &z, &w)\n\n#define scanfll1(x) scanf(\"%lld\", &x)\n#define scanfll2(x,y) scanf(\"%lld %lld\", &x, &y)\n#define scanfll3(x,y,z) scanf(\"%lld %lld %lld\", &x, &y, &z)\n#define scanfll4(x,y,z,w) scanf(\"%lld %lld %lld %lld\", &x, &y, &z, &w)\n\n#define fr(i,n) for(int i=0;i<(n);i++)\n#define frr(i,a,b) for(int i=(a);i<=(b);i++)\n#define frrs(i,a,b) for(int i=(a);i>=(b);i--)\n#define VAR(a,b) __typeof(b) a=b\n#define frit(it,c) for(VAR(it,(c).begin());it!=(c).end();it++)\n\ntypedef long long ll;\ntypedef long double ld;\n\n#define pb push_back\n\n#define all(a) a.begin(),a.end() \n\n#define fi first\n#define se second\ntypedef pair pii;\n\n#define PI acos(-1)\n#define MOD 1000000007\n\n//LONG_LONG_MAX\n//-DBL_MAX\n\n#define prin(a) cout << #a << \" = \" << (a) << endl\n\nint main(){\n\tint mat[5][5];\n\t\n\tfr(i,4){\n\t\t\tscanfd4(mat[i][0],mat[i][1],mat[i][2],mat[i][3]);\n\t}\n\t\n\tbool ped[5];\n\t\n\tfr(i,4) ped[i] = 0;\n\t//fr(i,4) prin(ped[i]); //novo code\n\t\n\tfr(i,4){//mat[x][0] left\n\t\tif(mat[i][0]){\n\t\t\tped[i] = 1;\n\t\t\tped[(i-1+4)%4] = 1;\n\t\t}\n\t}\n\t\n\tfr(i,4){//mat[x][1] s\n\t\tif(mat[i][1]){\n\t\t\tped[i] = 1;\n\t\t\tped[(i+2+4)%4] = 1;\n\t\t}\n\t}\n\t\n\tfr(i,4){//mat[x][2] s\n\t\tif(mat[i][2]){\n\t\t\tped[i] = 1;\n\t\t\tped[(i+1+4)%4] = 1;\n\t\t}\n\t}\n\t\n\t//prin(mat[0][3]);\n\t\n\t/*if(mat[0][1]){\n\t\tfr(i,4){\n\t\t\tprin(ped[i]);\n\t\t}\n\t}*/\n\t\n\tfr(i,4){\n\t\tif(mat[i][3] and ped[i]){\n\t\t\t//prin(i);\n\t\t\tcout << \"YES\" << endl;\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\t\n\t\n\tcout << \"NO\" << endl;\n\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "f2c72e58b99ffd60b03eb4a1ae84466a", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n using namespace std;\n int main()\n {\n /*freopen(\"input.txt\",\"r\",stdin);\n freopen(\"output.txt\",\"w\",stdout);*/\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int a;\n int b;\n cin >> a >> b;\n vector q;\n vector w;\n while(a>0)\n {\n q.push_back(a%10);\n a/=10;\n }\n while(b>0)\n {\n w.push_back(b%10);\n b/=10;\n }\n int c=q.size();\n int d=w.size();\n if(c>d)\n {\n for(int i=0;i<(c-d);i++)\n {\n w.push_back(0);\n //cout << 0;\n }\n }\n else if(d>c)\n {\n for(int i=0;i<(d-c);i++)\n {\n q.push_back(0);\n //cout << 0;\n }\n }\n int e=q[0];\n int r=w[0];\n for(int i=0;i as;\n for(int i=0;i=abs(i-n/2))\n {\n cout << \"D\";\n }\n else\n {\n cout << \"*\";\n }*/\n\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "52f57a162a602fc2d2e9de1033fbcf72", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define pb push_back\n#define mp make_pair\n#define ll long long\n#define ull unsigned ll\n#define db double\n#define INF 0x3f3f3f3f\n#define MOD 1000000007\n#define PII pair\n\nll l,r;\nint num[10],keep[10];\nvector lv,rv;\n\ninline bool any(int l,int r) {\n for (int i=l;i<=r;i++) {\n if (num[i]>0) return true;\n }\n return false;\n}\n\nbool dfs(int idx,bool lf,bool rf) {\n if (idx==rv.size()) return true;\n int l=lv[idx],r=rv[idx];\n if (lf&&rf) {\n if (l==r) {\n if (num[l]>0) {\n num[l]--;\n if (dfs(idx+1,1,1)) return true;\n num[l]++;\n }\n return false;\n }\n if (any(l+1,r-1)) return true;\n if (num[l]>0) {\n num[l]--;\n if (dfs(idx+1,1,0)) return true;\n num[l]++;\n }\n if (num[r]>0) {\n num[r]--;\n if (dfs(idx+1,0,1)) return true;\n num[r]++;\n }\n return false;\n } else {\n if (lf) {\n if (any(l+1,9)) return true;\n if (num[l]>0) {\n num[l]--;\n if (dfs(idx+1,1,0)) return true;\n num[l]++;\n }\n return false;\n } \n if (rf) {\n if (any(0,r-1)) return true;\n if (num[r]>0) {\n num[r]--;\n if (dfs(idx+1,0,1)) return true;\n num[r]++;\n }\n return false;\n }\n }\n return false;\n}\n\nint ans=0;\nvoid go(int idx,int rem) {\n if (idx==10) {\n memcpy(num,keep,sizeof(keep));\n num[0]+=rem;\n if (dfs(0,1,1)) ans++;\n return;\n }\n for (int i=0;i<=rem;i++) {\n keep[idx]=i;\n go(idx+1,rem-i);\n }\n}\n\nint main()\n{\n scanf(\"%lld%lld\",&l,&r);\n\n while (l>0) {\n lv.pb(l%10);\n l/=10;\n }\n while (r>0) {\n rv.pb(r%10);\n r/=10;\n }\n while (lv.size()\n\n#include \n#include \n#include \n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#ifdef LOCAL\n #define eprintf(...) fprintf(stderr, __VA_ARGS__)\n#else\n #define eprintf(...) 42\n#endif\n\n#define pb push_back\n#define mp make_pair\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef double lf;\n\nconst int maxn = 8, inf = 1000000000;\n\nint n, p[maxn], order[maxn], ans = inf;\nll data[maxn];\nvector fact[maxn], tmp[maxn];\n\ninline int matchSubseq(vector &a, vector &b)\n{\n\tfor (size_t i = 0, ptr = 0; i < a.size(); i++, ptr++)\n\t{\n\t\twhile (ptr < b.size() && b[ptr] != a[i]) ptr++;\n\t\tif (ptr >= b.size()) return -1;\n\t}\n\treturn b.size() - a.size();\n}\n\nvoid rec(int k)\n{\n\tif (k == n)\n\t{\n\t\tint curans = 0, alone = 0;\n\t\tfor (int i = 0; i < n; i++) tmp[i].clear();\n\t\tfor (int i = n - 1; i >= 0; i--)\n\t\t{\n\t\t\tint v = order[i];\n\t\t\tsort(tmp[i].begin(), tmp[i].end());\n\t\t\tint x = matchSubseq(tmp[i], fact[v]);\n\t\t\tif (x == -1) return;\n\t\t\tif (fact[v].size() == 1) curans++;\n\t\t\telse curans += x + 1;\n\t\t\tif (p[i] == -1) alone++;\n\t\t\telse\n\t\t\t\tfor (size_t j = 0; j < fact[v].size(); j++)\n\t\t\t\t\ttmp[p[i]].pb(fact[v][j]);\n\t\t}\n\t\tif (alone > 1) curans++;\n\t\tans = min(ans, curans);\n\t\treturn;\n\t}\n\tfor (p[k] = -1; p[k] < k; p[k]++)\n\t\trec(k + 1);\n}\n\ninline bool cmp(int a, int b)\n{\n\treturn fact[a].size() > fact[b].size();\n}\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin); \n#endif\n cin >> n;\n for (int i = 0; i < n; i++)\n {\n\t\tcin >> data[i];\n\t\tll tmp = data[i];\n\t\tfor (ll x = 2; x * x <= tmp; x++)\n\t\t\twhile (tmp % x == 0) tmp /= x, fact[i].pb(x);\n\t\tif (tmp != 1) fact[i].pb(tmp);\n\t\torder[i] = i;\n\t}\n\tsort(order, order + n, cmp);\n\trec(0);\n\tprintf(\"%d\\n\", ans);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "dp", "number theory"], "code_uid": "e7d2f9fac4700bd74a2f4bf5b0f5bdba", "src_uid": "52b8b6c68518d5129272b8c56e5b7662", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "\ufeff#include\n#include\n#include\n#include\n\nusing namespace std;\n\n// Returns the product of digits of number x \nint product(int x)\n{\n\tint prod = 1;\n\twhile (x) {\n\t\tprod *= (x % 10);\n\t\tx /= 10;\n\t}\n\treturn prod;\n}\n\n// This function returns the number having \n// maximum product of the digits \nint findNumber(int l, int r)\n{\n\t// Converting both integers to strings \n\tstring a = to_string(l);\n\tstring b = to_string(r);\n\n\t// Let the current answer be r \n\tint ans = r;\n\tfor (int i = 0; i < b.size(); i++) {\n\t\tif (b[i] == '0')\n\t\t\tcontinue;\n\n\t\t// Stores the current number having \n\t\t// current digit one less than current \n\t\t// digit in b \n\t\tstring curr = b;\n\t\tcurr[i] = ((curr[i] - '0') - 1) + '0';\n\n\t\t// Replace all following digits with 9 \n\t\t// to maximise the product \n\t\tfor (int j = i + 1; j < curr.size(); j++)\n\t\t\tcurr[j] = '9';\n\n\t\t// Convert string to number \n\t\tint num = 0;\n\t\tfor (auto c : curr)\n\t\t\tnum = num * 10 + (c - '0');\n\n\t\t// Check if it lies in range and its product \n\t\t// is greater than max product \n\t\tif (num >= l && product(ans) < product(num))\n\t\t\tans = num;\n\t}\n\n\treturn ans;\n}\n\n// Driver Code \nint main()\n{\n\tint l = 1, n;\n\tcin >> n;\n\tcout << product(findNumber(l, n));\n\t//system(\"pause\");\n\treturn 0;\n}\n\n//#include\n//#include\n//using namespace std;\n//\n//\n//int productDigit(int n) {\n//\tint pro = 1;\n//\twhile (n> 0) {\n//\t\tpro *= n % 10;\n//\t\tn /= 10;\n//\t}\n//\treturn pro;\n//}\n//\n//int numofDigit(int n) {\n//\tint num = 0;\n//\twhile (n > 0) {\n//\t\tnum++;\n//\t\tn /= 10;\n//\t}\n//\treturn num;\n//}\n//\n//int maxProduct(int n) {\n//\tif (n <= 9)\n//\t\treturn n;\n//\tint lastDigit,tmp=n;\n//\tint num = pow(10,numofDigit(n) - 1);\n//\tbool find = false;\n//\tint max = 0;\n//\tint rel;\n//\twhile (find==false)\n//\t{\n//\t\tlastDigit = n % 10;\n//\t\trel = productDigit(n);\n//\t\tif (rel > max) {\n//\t\t\tmax = rel;\n//\t\t}\n//\t\tif (lastDigit == 9 && rel != 0) {\n//\t\t\tif (rel > max)\n//\t\t\tmax = rel;\n//\t\t\tfind = true;\n//\t\t}\n//\t\tn--;\n//\t}\n//\tn++;\n//\tint count = 0;\n//\n//\twhile (count!=num)\n//\t{\n//\t\trel = productDigit(n);\n//\t\tif (rel > max) {\n//\t\t\tmax = rel;\n//\t\t}\n//\t\tcount += 10;\n//\t\tn-=10;\n//\t}\n//\treturn max;\n//}\n//\n//\n//int main() {\n//\tint n;\n//\tcin >> n;\n//\tcout << maxProduct(n);\n//\tsystem(\"pause\");\n//\treturn 0;\n//}", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "c4aafa1d52f618a9d62a83b46749a32c", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std; \n \nlong long x , y , z , i , j , n , m , k , s1 , s2 , mod , r , N , maxx , minn ;\ndouble w , v , q , h , hh , ww1 , ww2 ;\nlong long a [ 100045 ] ;\nlong long b [ 100045 ] ;\nstring s ;\nmap < long long , long long > mm ;\n\nint main() {\n scanf ( \"%lld%lld%lld\" , & x , & y , & n ) ;\n if ( y <= n ) {\n k = __gcd ( x , y ) ;\n printf ( \"%lld/%lld\" , x / k , y / k ) ;\n exit (0) ;\n }\n s1 = -1 ;\n for ( i = 1 ; i <= n ; i ++ ) {\n j = i * x / y ;\n if ( abs ( i * x - j * y ) > abs ( i * x - ( j + 1 ) * y ) ) j ++ ;\n if( s1 == -1 || abs ( s2 * x - s1 * y ) * i > abs ( i * x - j * y ) * s2 ) {\n s1 = j ;\n s2 = i ;\n }\n }\n printf ( \"%lld/%lld\" , s1 , s2 ) ;\n}\n", "lang_cluster": "C++", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "56bfafc31211cce3747bb6623e3d7e71", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nmapa;\nint main()\n{\n\ta[\"January\"]=1,a[\"February\"]=2,a[\"March\"]=3,a[\"April\"]=4,a[\"May\"]=5,a[\"June\"]=6,a[\"July\"]=7,a[\"August\"]=8,a[\"September\"]=9,a[\"October\"]=10,a[\"November\"]=11,a[\"December\"]=12;\n\tint n,k;\n\tstring s;cin>>s>>n;\n\tk=(a[s]+n)%12;\n\tif(k==1)cout<<\"January\";\n\tif(k==2)cout<<\"February\";\n\tif(k==3)cout<<\"March\";\n\tif(k==4)cout<<\"April\";\n\tif(k==5)cout<<\"May\";\n\tif(k==6)cout<<\"June\";\n\tif(k==7)cout<<\"July\";\n\tif(k==8)cout<<\"August\";\n\tif(k==9)cout<<\"September\";\n\tif(k==10)cout<<\"October\";\n\tif(k==11)cout<<\"November\";\n\tif(k==0)cout<<\"December\";\n\tcout<\n#include \n#include \n#include \n#include \nusing namespace std;\n \n#define ll long long int\n\nint main()\n{\n\tios_base::sync_with_stdio(0);\n cin.tie(0);\n\n ll n;\n int m;\n cin>>n>>m;\n int rem[100001]={0};\n int flag=1;\n while(flag)\n {\n rem[n%m]++;\n if(rem[n%m]>1)\n flag = 0;\n n+=(n%m);\n if(n%m==0)\n {\n cout<<\"Yes\"<\nusing namespace std;\n// #define int long long\n#define endl \"\\n\"\n#define sws ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);\n#define teto(a, b) ((a+b-1)/(b));\n \nconst int MAX = 5e5+10;\nconst long long MOD = 1073741824;\nconst int INF = 0x3f3f3f3f;\nconst long long LLINF = 0x3f3f3f3f3f3f3f3f;\n \n//Overflow?!\nint32_t main(){sws;\n \n string s;\n cin >> s;\n vector v = {\"\",\"\",\"\",\"the\",\"\",\"buffy\",\"slayer\",\"vampire\"};\n if(s.size() == 4)\n cout << \"none\" << endl;\n else{\n string t = v[s.size()], ans=\"\";\n for(int i=0; i\n#include\n#include\n#include\n///Sortedorder (Slow)\n///Randomorder (fast)\n#include\n#include\n#include\n#define all(c) c.begin(), c.end()\n# define lli long long int\n#include\n#define vec vector\n#define M 1000000007\n\n\n\nusing namespace std;\nvectordp(1000000,-1);\nint main()\n{\n\n\n lli n;\n cin>>n;\n lli i;\n lli c=0;\n vectorv;\n lli no_of_digits=0;\n lli k=n;\n while(k>0)\n {\n\n no_of_digits++;\n k=k/10;\n\n }\n\n lli f=n-(no_of_digits*2)*9-1;\n\n if(f<0)\n f=0;\n\n\n\n\n\n for(i=f;i<=n;i++)\n {\n\n lli sum=i;\n lli x=i;\n while(x>0)\n {\n\n\n sum=sum+(x%10);\n x=x/10;\n\n\n\n }\n if(sum==n)\n {\n\n c++;\n v.push_back(i);\n }\n\n\n\n\n\n }\n cout<\n#include \nusing namespace std;\n\nint main() \n{\n long long int l,r,ans=0,expof2,expof3;\n cin>>l>>r;\n \n for(expof2=1;expof2<=r;expof2*=2)\n {\n for(expof3=1;expof3<=r;expof3*=3)\n if(expof3*expof2<=r&&expof2*expof3>=l)\n ans++;\n }\n cout<\n\nusing namespace std;\n\nconst int M = 4;\nconst int K = 13;\nconst int N = K * (1 << M) + 1;\nconst int MOD = 1000000007;\n\ninline int add(int u, int v) {\n return (u += v) >= MOD ? u - MOD : u;\n}\n\ninline int sub(int u, int v) {\n return (u -= v) < 0 ? u + MOD : u;\n}\n\ninline int mul(int u, int v) {\n return (long long)u * v % MOD;\n}\n\nstruct Matrix {\n int a[N][N];\n\n Matrix(int diag = 0) {\n memset(a, 0, sizeof a);\n for (int i = 0; i < N; i++) a[i][i] = diag;\n }\n\n int* operator [] (int u) {\n return a[u];\n }\n\n Matrix operator * (Matrix &u) const {\n Matrix res;\n for (int k = 0; k < N; k++) {\n for (int i = 0; i < N; i++) {\n for (int j = 0; j < N; j++) {\n res[i][j] = add(res[i][j], mul(a[i][k], u[k][j]));\n }\n }\n }\n return res;\n }\n\n Matrix operator ^ (int v) const {\n Matrix res(1);\n Matrix u = *this;\n while (v) {\n if (v & 1) res = res * u;\n u = u * u;\n v >>= 1;\n }\n return res;\n }\n\n void debug(int n) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) cout << a[i][j];\n cout << endl;\n }\n cout << endl;\n }\n};\n\nint n, m, k;\n\nint encode(int u, int mask) {\n return (u << m) + mask;\n}\n\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cin >> n >> k >> m;\n Matrix b;\n for (int i = 0; i <= k; i++) {\n for (int mask = 0; mask < (1 << m); mask++) {\n int id = encode(i, mask);\n int id2 = encode(i, (mask << 1) & ((1 << m) - 1));\n b[id][id2] = 1;\n if (i < k) {\n id2 = encode(i + 1, (mask << 1) & ((1 << m) - 1) | 1);\n b[id][id2] = __builtin_popcount(mask) + 1;\n }\n }\n }\n Matrix a;\n a[0][0] = 1;\n // b.debug((k + 1) << m);\n Matrix c = b ^ n;\n // c.debug((k + 1) << m);\n c = a * c;\n // c.debug((k + 1) << m);\n int res = 0;\n for (int mask = 0; mask < (1 << m); mask++) {\n res = add(res, c[0][encode(k, mask)]);\n }\n cout << res << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["matrices", "dp", "bitmasks"], "code_uid": "c3e75f502cb4a15c20d46a39cc570a95", "src_uid": "87931a8ae9a76d85bd2a2b4bba93303d", "difficulty": 3000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int k, n, s, p;\n cin >> k >> n >> s >> p;\n cout << ((n + s - 1) / s * k + p - 1) / p;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "75df74a2bd7018ed9e08532c116bee4e", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n#define ll long long\n#define pb push_back\n#define mp make_pair\n#define pii pair\n#define dbg(x) (cout<<#x<<\" = \"<<(x)< m;\n\nset color[10],number[10];\n\nvector v;\n\nbitset<10> A,B;\n\nint main()\n{\n //freopen(\"test.in\",\"r\",stdin);\n //freopen(\"test.out\",\"w\",stdout);\n\n cin.sync_with_stdio(false);\n\n cin>>n;\n\n for(i=1; i<=n; i++)\n {\n cin>>s;\n\n if(m[s]) continue;\n\n m[s]=1;\n\n if(s[0]=='R') a=1;\n else if(s[0]=='G') a=2;\n else if(s[0]=='B') a=3;\n else if(s[0]=='Y') a=4;\n else a=5;\n\n b=s[1]-'0';\n\n color[a].insert(b);\n number[b].insert(a);\n\n v.pb(mp(a,b));\n }\n\n lim=1<<5;\n sol=1<<30;\n\n for(i=0; i=color[a].size()-1) known=1;\n }\n\n if(B[b])\n {\n cnt=0;\n for(auto it:number[b])\n if(A[it]) cnt++;\n if(cnt>=number[b].size()-1) known=1;\n }\n\n totalknown+=known;\n }\n\n if(totalknown>=v.size()-1) sol=min(sol,cate);\n }\n\n cout<]\ntypedef long long LL;\nusing namespace std;\n\nLL n,m,L,R;\nconst LL mod=998244353;\nLL pow(LL p,LL k){\n LL ans=p,ret=1;\n while (k!=0){\n if (k%2==1) ret=ret*ans%mod;\n ans=ans*ans%mod;\n k/=2;\n }\n return ret;\n}\nint main()\n{\n\tcin>>n>>m>>L>>R;\n if (L==R){\n printf(\"1\");return 0;\n }\n LL k1=R/2;\n if (L>0) k1-=(L-1)/2;\n LL k2=(R-L+1)-k1;\n LL ans1=pow((k1+k2),n*m);\n LL ans2=pow((k1-k2),n*m);\n //printf(\"%lld %lld\\n\",ans1,ans2);\n if (n*m%2==0) cout<<((ans1+ans2+mod)%mod*((mod+1)/2LL))%mod<\n#include\n#include\nusing namespace __gnu_pbds;\nusing namespace std;\n \n#define pb push_back\n#define mp make_pair\n#define eb emplace_back\n#define F first\n#define S second\n#define sz(a) (int)(a.size())\n#define set(a,b) memset(a,b,sizeof(a))\n#define let(x,a) __typeof(a) x(a)\n#define rep(i, begin, end) for (ll i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))\n#define all(v) (v).begin(),(v).end()\n#define sll(x) { scanf(\"%lld\",&x); }\n#define si(x) { scanf(\"%d\",&x); }\n#define slf(x) { scanf(\"%lf\",&x); }\n#define pll(x) { printf(\"%lld\\n\",x); }\n#define pi(x) { printf(\"%d\\n\",x); }\n#define tcases() long long testcases; cin>>testcases ; while(testcases--)\n \n#define TRACE\n#ifdef TRACE\n#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f(const char* name, Arg1&& arg1){\n cerr << name << \" = \" << arg1 << std::endl;\n}\ntemplate \nvoid __f(const char* names, Arg1&& arg1, Args&&... args){\n const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << \" = \" << arg1<<\" | \";__f(comma+1, args...);\n}\n \n#else\n#define trace(...)\n#endif\n \ntemplate \nusing ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>;\n \ntypedef long long ll;\ntypedef long double ld;\ntypedef pair pll;\ntypedef vector vll;\ntypedef vector vpll;\ntypedef vector vvll;\n \nconst ll mod=1000000007;\n//-----------------------------------------------------------------------------------------------------------------------------------------------//\n \n \nint main()\n{\n//\tios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n \n\tll s,x,z,y,ans=0,one=1;\n\tsll(s);sll(x);\n \n\ts=s-x;\n\tif(s<0 || s%2!=0)\n\t{\n\t\tcout<<0<>=1;\n\t\ty>>=1;\n\t\tans+=r;\n\t}\n\tif(s!=0)\n\t\tcout<<(one<\n#include\nint main()\n{\n long long n,a=0,i;\n scanf(\"%I64d\",&n);\n for(i=1;i<=n;i++)\n {\n a=a+pow(2,i);\n\n }\n printf(\"%I64d\\n\",a);\n return 0;\n}\n//2018-12-06 09:40:22.254", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "766542b19da7e2ac6fd275a2cd7d16a2", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \nusing namespace std;\nint dec_bits( long long num ){\n\tint b = 0;\n\tfor(; num; num /= 10, b++ );\n\treturn b;\n}\nlong long dec_pow( int pow ){\n\tlong long val = 1;\n\tfor(; pow; pow --, val *= 10 );\n\treturn val;\n}\nlong long weight( long long num ){\n\treturn ( ( ( dec_pow( dec_bits( num ) )-1 )-num) * num );\n}\nint main(){\n\tint l, r;\n\tlong long mid;\n\tcin >> l >> r;\n\tmid = (dec_pow( dec_bits( r ) )-1)/2;\n\tif( l < mid && mid < r ){\n\t\tcout << weight( mid ) << endl;\n\t}else{\n\t\tcout << max( weight(l), weight(r) ) << endl;\n\t}\n\treturn 0;\n}\n/****** PCCA -Wed Aug 03 02:52:19 GMT 2011 *******/", "lang_cluster": "C++", "tags": ["math"], "code_uid": "90516b8baf3b3eed71a756dc056cdfca", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nconst int mod=51123987;\nchar str[152];\nint a[152];\nint dp[152][52][52][52];\nint nxt[152][3];\nsigned main()\n{\n\tint n;\n\tscanf(\"%d\",&n);\n\tcin>>str+1;\n\tfor(int i=1;i<=n;i++)\n\t\ta[i]=str[i]-'a';\n\tnxt[n+1][0]=nxt[n+1][1]=nxt[n+1][2]=n+1;\n\tfor(int i=n;i>=1;i--)\n\t{\n\t\tnxt[i][0]=nxt[i+1][0];\n\t\tnxt[i][1]=nxt[i+1][1];\n\t\tnxt[i][2]=nxt[i+1][2];\n\t\tnxt[i][a[i]]=i;\n\t}\n\tint ans=0;\n\tdp[1][0][0][0]=1;\n\tfor(int i=1;i<=n;i++)\n\t\tfor(int j1=0;j1<=(n+2)/3;j1++)\n\t\t\tfor(int j2=0;j2<=(n+2)/3;j2++)\n\t\t\t\tfor(int j3=0;j3<=(n+2)/3;j3++)\n\t\t\t\t{\n\t\t\t\t\t(dp[nxt[i][0]][j1+1][j2][j3]+=dp[i][j1][j2][j3])%=mod;\n\t\t\t\t\t(dp[nxt[i][1]][j1][j2+1][j3]+=dp[i][j1][j2][j3])%=mod;\n\t\t\t\t\t(dp[nxt[i][2]][j1][j2][j3+1]+=dp[i][j1][j2][j3])%=mod;\n\t\t\t\t\tif(j1+j2+j3==n&&abs(j1-j2)<=1&&abs(j1-j3)<=1&&abs(j2-j3)<=1)\n\t\t\t\t\t\tans+=dp[i][j1][j2][j3],ans%=mod;\n\t\t\t\t}\n\tprintf(\"%d\",ans);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "08f7c5e52a273eb2fa80c353ad5c2c1d", "src_uid": "64fada10630906e052ff05f2afbf337e", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\nusing namespace std;\n//#include\nint main()\n{\n int m;\n scanf(\"%d\",&m);\n int i=0,x,y,j,k;\n bool a[11][11]={0};\n for(i=0;i\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define fo(a,b) for(int i = a;i pii;\ntypedef vector arr1D;\ntypedef vector arr2D;\nvoid Arr2DInit(arr2D &a, int n, int m)\n{\n\ta.resize(n);\n\tfor (int i = 0; i < n; i++)\n\t\ta[i].resize(m);\n}\ntemplate\nT minn(T a, T b)\n{\n\treturn a < b ? a : b;\n}\ntemplate\nT maxx(T a, T b)\n{\n\treturn a > b ? a : b;\n}\n///////////////////////////// Le Chi Nhin 17CTT5 HCMUS /////////////////////////////////////////////\n//const int dx[] = { -1,0,1,1,1,0,-1,-1 };\n//const int dy[] = { 1,1,1,0,-1,-1,-1,0 };\n///////////////////////////// I love U (KLy) //////////////////////////////////////////////////////\n///////////////////////////// in the moments //////////////////////////////////////////////////////\n//\nconst int dx[] = { 0,0,1,-1 };\nconst int dy[] = { 1,-1,0,0 };\nstring direct = \"UDRL\";\n\nchar a[501][501];\nint main()\n{\n\t//\n\tint n;\n\tcin >> n;\n\tif (n == 2)\n\t\tcout << 2;\n\telse cout << 1;\n\t//system(\"pause\");\n}\n", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "cdb08b6150691c30cdaa91ddcbfe5068", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \nusing namespace std;\nint main()\n{ \n int n; char a[100];\n cin >> n;\n scanf(\"%s\", a);\n int cnt = 0;\n for(int i = 0; i < n; i++) {\n if(a[i] == '1') cnt++;\n else {cout << cnt; cnt = 0;}\n }\n cout << cnt << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "ca645e7fc89ca923db5754de8feb7f8e", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "///INCLUDE\n#include\n#include\n#include\n#include\n#include\n///INPUT\n#define RI(n) scanf(\"%d\", &n)\n#define RII(n, m) scanf(\"%d%d\", &n, &m)\n#define RIII(n, m, k) scanf(\"%d%d%d\", &n, &m, &k)\n#define RIV(n, m, k, l) scanf(\"%d%d%d%d\", &n, &m, &k, &l)\n#define RFI(n) scanf(\"%lf\", &n)\n#define RFII(n, m) scanf(\"%lf%lf\", &n, &m)\n#define RFIII(n, m, k) scanf(\"%lf%lf%lf\", &n, &m, &k)\n#define RFIV(n, m, k, l) scanf(\"%lf%lf%lf%lf\", &n, &m, &k, &l)\n#define RS(s) scanf(\"%s\", s)\n///OUTPUT\n#define PI(n) printf(\"%d\\n\", n)\n#define PIS(n) printf(\"%d \", n)\n#define PS(s) printf(\"%s\\n\", s)\n#define PSS(s) printf(\"%s \", s)\n///LOOP\n#define REP(i, n) for(int i = 0; i < n; i++)\n#define FF(i, a, b) for(int i = a; i < b; i++)\n#define FFF(i, a, b) for(int i = a; i <= b; i++)\n#define FD(i, a, b) for(int i = a - 1; i >= b; i--)\n#define FDD(i, a, b) for(int i = a; i >= b; i--)\n#define CLR(a, b) memset(a, b, sizeof(a))\n#define CPY(a, b) memcpy(a, b, sizeof(a))\n\nusing namespace std;\n\ntypedef long long LL;\n\nconst int MOD = 1000;\nconst int INFI = 1e9;\nconst int N = 1111;\nconst int M = 11;\nconst int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};\n\nofstream fout(\"out.txt\");\nifstream fin(\"in.txt\");\n\nint main()\n{\n int a, b, c, d;\n double e;\n while(RIV(a, b, c, d) != EOF)\n {\n if(c - b == d - c && b - a == c - b)\n {\n PI(d + b - a);\n continue;\n }\n if(b * b == a * c && c * c == b * d)\n {\n e = double(d * b) / double(a);\n if(e == int(e))PI(int(e));\n else PI(42);\n continue;\n }\n PI(42);\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "91165fee1809e83db1ef2f4a2add2735", "src_uid": "68a9508d49fec672f9c61766d6051047", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n#ifdef ONLINE_JUDGE\n#define OJ 1\n#else\n#define OJ 0\n#endif\n\n#define dd\t\t\t\tdouble\n#define ll \t\t\t\tlong long\n#define pb \t\t\t\tpush_back\n#define mp \t\t\t\tmake_pair\n#define X\t\t\t\tfirst\n#define Y\t\t\t\tsecond\n#define forn( i, n ) \tfor( ll i = 0; i < (ll) (n); i ++ )\n#define endl \t\t\t'\\n'\n\n#define TIMESTAMP fprintf(stderr, \"Execution time: %.3lf s.\\n\", (double)clock()/CLOCKS_PER_SEC)\n\nstruct __s { __s() {\n\t\t//srand( time( NULL ) );\n\t\t//freopen( \"input.txt\", \"r\", stdin ); freopen( \"output.txt\", \"w\", stdout );\n\t\tif( OJ ) { ios_base::Init i; cin.sync_with_stdio( 0 ); cin.tie( 0 ); }\n\t} ~__s() {\n\t\tif( !OJ ) TIMESTAMP;\n\t\tll n; cin >> n;\n\t}\n} __S;\n\nint main( void ) {\n\tll x;\n\tcin >> x;\n\tll y = abs( x ) % 360;\n\tif( x >= 0 ) {\n\t\tif( y <= 45 || y >= 315 )\n\t\t\tcout << 0 << endl;\n\t\telse if( y <= 135 )\n\t\t\tcout << 1 << endl;\n\t\telse if( y <= 225 )\n\t\t\tcout << 2 << endl;\n\t\telse if( y < 315 )\n\t\t\tcout << 3 << endl;\n\t} else {\n\t\tif( y <= 45 || y >= 315 )\n\t\t\tcout << 0 << endl;\n\t\telse if( y >= 225 )\n\t\t\tcout << 1 << endl;\n\t\telse if( y >= 135 )\n\t\t\tcout << 2 << endl;\n\t\telse if( y > 45 )\n\t\t\tcout << 3 << endl;\n\t}\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "geometry"], "code_uid": "00da0040fc28b7ea80e932f5c66969d8", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define X first\n#define Y second\n\n#define add push_back\ntypedef long long ll;\ntypedef pair Point;\ntypedef pair PointF;\ntypedef pair PointD;\n\n\n\n\n\nint main() {\n ios::sync_with_stdio(false);\n\n long long l1, r1, l2, r2, k;\n cin >> l1 >> r1 >> l2 >> r2 >> k;\n long long ans = min(r1, r2) - max(l1 - 1, l2 - 1);\n if (max(l1, l2) <= k && min(r1, r2) >= k) {\n ans = max((long long)0, ans - 1);\n } else {\n ans = max((long long)0, ans);\n }\n\n cout << ans << endl;\n\n\n\n\n\n#ifdef _DEBUG\n system(\"pause\");\n#endif\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "240cdd8fefd51788c87c111cc832129e", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "/* DHUOJ solution #343263 @ 2018-07-06 20:17:08.805 */\n\n#include \n#define ll long long\n#define INF 0x7fffffff\n#define inf 0x7fffffffffffffff\n#define ms(a,val) memset((a),(val),(sizeof(a)))\n#define sqr(x) ((x)*(x))\n\nusing namespace std;\n\npair a[15],b[15];\nset ans,store[15];\n\nint main(){\n int n,m,x,y;\n while(cin>>n>>m){\n for(int i=0;i>x>>y;\n a[i]=make_pair(min(x,y),max(x,y));\n }\n for(int i=0;i>x>>y;\n b[i]=make_pair(min(x,y),max(x,y));\n }\n int flag=0,sum=0;\n for(int i=0;i dict;\n for(int j=0;j1){\n flag=1;\n break;\n }\n else if(dict.size()==1){\n ans.insert(*dict.begin());\n sum++;\n }\n }\n if(flag)cout<<-1<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)\n#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)\n#define be(m) (m).begin(),(m).end()\n#define mp make_pair\n#define pb push_back\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef double d;\ntypedef vector vi;\ntypedef vector vd;\ntypedef vector vs;\ntypedef stack si;\ntypedef stack ss;\ntypedef map msi;\ntypedef map mii;\ntypedef list li;\ntypedef list ls;\ntypedef pair pii;\ntypedef pair pss;\ntypedef vs::iterator vs_it;\ntypedef msi::iterator msi_it;\ntypedef mii::iterator mii_it;\ntypedef li::iterator li_it;\ntypedef ls::iterator ls_it;\n\nconst int e9=1000*1000*1000;\nconst ll e18=(ll)e9*(ll)e9;\nconst d pi=3.1415926535;\n\nvoid pV(int num){cout << num << \" \";}\nint ri(){int x;scanf(\"%d\",&x);return x;}\nd rd(){d x;scanf(\"%lf\",&x);return x;}\nll rll(){ll x;scanf(\"%lld\",&x);return x;}\nstring rs(){string x;cin >> x;return x;}\nstring rsf(){string s;char c; while(c=getchar()){if(c>=65 && c<=90 || c>='a' && c<='z')s+=c;else break;}return s;}\nvoid wi(int x){printf(\"%d \",x);}\nvoid wd(d x){printf(\"%lf \",x);}\nvoid wll(ll x){printf(\"%lld \",x);}\nvoid ws(string x){cout << x << \" \";}\n\n\n\nint main()\n{\n vs mas(3);\n int r=0,p=0,s=0;\n fr(i,0,2)\n {\n mas[i]=rs();\n if (mas[i]==\"rock\")\n r++;\n if (mas[i]==\"paper\")\n p++;\n if (mas[i]==\"scissors\")\n s++;\n }\n if (r==2 && p==1 || r==1 && s==2 || p==2 && s==1)\n {\n string search=\"\";\n if (r==2 && p==1)\n search=\"paper\";\n if (r==1 && s==2)\n search=\"rock\";\n if (p==2 && s==1)\n search=\"scissors\";\n fr(i,0,2)\n if (mas[i]==search)\n {\n if (i==0)\n ws(\"F\");\n if (i==1)\n ws(\"M\");\n if (i==2)\n ws(\"S\");\n return 0;\n }\n }\n ws(\"?\");\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "695715f567e97a3dacb2d6feea2be4c1", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "//#pragma GCC optomize (\"Ofast\")\r\n//#pragma GCC optomize (\"unroll-loops\")\r\n//#pragma GCC target (\"avx,avx2,fma\")\r\n\r\n#include \r\n\r\nusing namespace std;\r\n\r\n#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\r\n#define file(s) if (fopen(s\".in\", \"r\")) freopen(s\".in\", \"r\", stdin), freopen(s\".out\", \"w\", stdout)\r\n#define all(x) x.begin(),x.end()\r\n#define F first\r\n#define S second\r\n#define pb push_back\r\n\r\ntypedef long long ll;\r\ntypedef unsigned long long ull;\r\ntypedef double db;\r\ntypedef long double ldb;\r\n\r\nconst int N = 6;\r\nconst int M = 6;\r\nconst int MOD = 1e9 + 7;\r\nconst int INF = 1e9 + 7;\r\nconst double PI = 3.14159265;\r\n\r\nvoid solve () {\r\n int n;\r\n cin >> n;\r\n while (n > 9) {\r\n int ans = 0;\r\n while (n > 0) {\r\n ans += n % 10;\r\n n /= 10;\r\n }\r\n n = ans;\r\n }\r\n cout << n;\r\n}\r\n\r\nmain () {\r\n\tIOS\r\n// freopen(\"m3.in\",\"r\",stdin);\r\n// freopen(\"m3.out\",\"w\",stdout);\r\n\tint tt = 1;\r\n// cin >> tt;\r\n while(tt --) {\r\n solve();\r\n }\r\n return 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["implementation", "number theory"], "code_uid": "59742ec154814d459552967d0b477d65", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "/* You got a dream , you gotta protect it . */\n/* Sometimes you win , sometimes you learn . */\n#include \n#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n#define lp(i , N) for(ll i = 0; i < ll (N) ; i++)\n#define debug(x) cout<<\" [ \" << #x << \" is: \" << x << \" ] \"<> t;\n return t;\n}\nint main(){\n FAST\n string s , K = \"\";\n cin >> s;\n for(ll i = (s.size()) - 1; i >= 0; i--){\n if(s[i] == 'e'){\n s.pop_back();\n break;\n }\n K+=s[i];\n s.pop_back();\n }\n reverse(K.begin() , K.end());\n ll k = toLL(K) , x = 2 , cnt = s.size() - 2;\n ll r = k;\n cout << s[0];\n for(ll i = 2 , j = 0; i < s.size() && j < k; i++ , j++){\n cout << s[i];\n x = i + 1;\n cnt--;\n r--;\n }\n if(s.substr(2) == \"0\" && k == 0) return 0;\n else if(cnt > 0)cout << '.';\n cout << s.substr(x);\n while(r--) cout << 0;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "e7d5a5f6cdc144a917740482b67b02b8", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n\n #define int ll\nconst bool online_judge =\n#ifdef ONLINE_JUDGE\n true\n#else\n false\n#endif\n ;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\n\ntypedef vector vi;\ntypedef vector vvi;\ntypedef vector vs;\n\ntypedef tuple int2;\ntypedef tuple int3;\ntypedef tuple int4;\n\n#define all(v) (v).begin(), (v).end()\n#define rall(v) (v).rbegin(), (v).rend()\n#define pb push_back\n#define eb emplace_back\n#define SZ(a) ((int)((a).size()))\n#define rep(i,n) for(int i = 0; i < n; i++)\n#define rep2(i,n) for(int i = 1; i <= n; i++)\n#define rep3(i,n) for(int i = n-1; i >= 0; i--)\n#define tag(i,v) rep(i,SZ(v))\n#define _trace(x) #x << \" = \" << (x)\n#define trace(x) { if(!online_judge) cerr << _trace(x) << endl; }\n#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << \" \" << _trace(y) << endl; }\n#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << \" \" << _trace(y) << \" \" << _trace(z) << endl; }\n#define tracev(x) { if(!online_judge) { cerr << #x << \" = \"; tag(__i, x) { cerr << x[__i] << \",\"; } cerr << endl; } }\n#define fst get<0>\n#define snd get<1>\n#define thd get<2>\n#define divup(x,y) ((x)/(y)+!!((x)%(y)))\n#define mp make_tuple\n#define range(x,a,b) ((x) >= (a) && (x) <= (b))\n\nconst int inf = 1LL << 60;\nint toInt(string s) {int res; stringstream ss; ss<>res; return res; }\nstring toString(int n) { stringstream ss; ss< b)\n return 1+rdfs(a-b,b);\n else \n return 1+rdfs(a,b-a);\n}\n\nvoid run() {\n\n /* entry point */\n\n int n;\n cin >> n;\n\n if(n == 1){\n cout << 0 << endl;\n return;\n }\n\n int ans = inf;\n\n for(int b = 1; b < n; b++){\n ans = min(ans, rdfs(n,b));\n }\n\n cout << ans << endl;\n\n}\n\n#undef int\n\nint main(int argc, char *argv[]) {\n\n #if 0\n if(online_judge){\n freopen(\"input.txt\", \"rt\", stdin);\n freopen(\"output.txt\", \"wt\", stdout);\n }\n #endif\n\n run();\n\n return 0;\n\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "67f9b42b2dacf78c46619723a79c4f43", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#define rep(i,a,b) for(int i = a; i <= b; ++i)\nusing namespace std;\nconst int N = 110, mod = 1e9 + 7;\nint f[N][N][N], g[N][N][N], c[N][N];\nbool F[N][N], G[N][N];\nvoid init() { rep(i,0,N) { c[i][0] = c[i][i] = 1; rep(j,1,i - 1) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; } }\ninline void add(int &a, int b) { a += b; if (a > mod) a -= mod; }\nint main() {\n//\tfreopen(\"arrangement.in\",\"r\",stdin); freopen(\"arrangement.out\",\"w\",stdout);\n\tint n, m, K; scanf(\"%d%d%d\",&n,&m,&K); init(); memset(F, false, sizeof(F)); memset(G, false, sizeof(G));\n\tint ans = 0;\n\trep(t,1,m) {\n\t\trep(i,1,n) rep(k,1,K) if (G[i][k]) memset(g[i][k], 0, sizeof(g[i][k])); memset(G, false, sizeof(G));\n\t\tif (t == 1) { rep(i,1,n) G[i][1] = g[i][1][i] = 1; } \n\t\trep(i,1,n) rep(k,1,K) if (F[i][k]) {\n\t\t\trep(j,1,n) if (f[i][k][j]) {\n\t\t\t\tint tmp;\n\t\t\t\trep(t,j,n - i) if (c[t - 1][j - 1] <= K && (tmp = k * c[t - 1][j - 1]) <= K)\n\t\t\t\t\tadd(g[i + t][tmp][t - j], f[i][k][j]) , G[i + t][tmp] = true;\n\t\t\t\telse break;\n\t\t\t}\n\t\t}\n\t\tswap(f, g), swap(F, G);\n\t\trep(i,1,n) rep(k,1,K) if (f[i][k][0]) (ans += 1LL * f[i][k][0] * (m - t + 1) % mod) %= mod;\n\t}\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "bdb7fb3bb3c35a59e9415afb47f03d88", "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include\n#include\n#include\nconst int N=100;\nchar a[N+1],b[N+1];\nint aa,bb,aSize,bSize,dp[N][2];\n//dp[i][j]\u8868\u793aa[1->aSize]\u548cb[j->bSize]\u7684\u6700\u5927\u5339\u914d\u5230b[?]\nint main() {\n scanf(\"%d%d%s%s\",&aa,&bb,a,b);\n aSize=strlen(a);\n bSize=strlen(b);\n for(int i=0; i\nusing namespace std;\nint n,a;\nint main()\n{\n scanf(\"%d%d\",&n,&a);\n if(a%2==0)\n {\n printf(\"%d\\n\",(n+2-a)/2);\n }\n else\n {\n printf(\"%d\\n\",(a+1)/2);\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "ff14a1a76be502d38a9b88102f2b5f8c", "src_uid": "aa62dcdc47d0abbba7956284c1561de8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\n#define fst first\n#define snd second\n#define all(x) (x).begin(), (x).end()\n#define rall(x) (x).rbegin(), (x).rend()\n#define clr(a, v) memset( a , v , sizeof(a) )\n#define pb push_back\n#define mp make_pair\n#define sz size()\n#define FORN( i , s , n ) for( int i = (s) ; i < (n) ; i++ )\n#define FOR( i , n ) FORN( i , 0 , n )\n#define FORIT( i , x ) for( typeof x.begin() i = x.begin() ; i != x.end() ; i++ )\n#define trace(x) cout << #x << \": \" << x << endl;\n#define trace2(x, y) cout << #x << \": \" << x << \" | \" << #y << \": \" << y << endl;\n#define trace3(x, y, z) cerr << #x << \": \" << x << \" | \" << #y << \": \" << y << \" | \" << #z << \": \" << z << endl;\n#define read ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n\nusing namespace std;\n\ntypedef long long int64;\ntypedef vector vi;\ntypedef pair ii;\ntypedef vector vs;\ntypedef vector vii;\n\nmap DP;\n\nint64 fDP(int64 N){\n\tif (N<=0) return -1e9;\n\tif (N==1) return 0;\n\tif (N==2) return 1;\n\tif (DP.count(N)) return DP[N];\n\tint64 mi = N/2;\n\tint64 ans = 0;\n\tif ( abs(fDP(mi) - fDP(N-mi)) <= 1) \tans = max( ans, max(fDP(mi) , fDP(N-mi) ) + 1);\n\tif ( abs(fDP(mi+1) - fDP(N-mi-1)) <= 1) ans = max( ans, max(fDP(mi+1) , fDP(N-mi-1)) + 1);\n\tif ( N-mi-2 > 0 and abs(fDP(mi+2) - fDP(N-mi-2)) <= 1) ans = max( ans, max(fDP(mi+1) , fDP(N-mi-1)) + 1);\n\treturn DP[N] = ans;\n}\n\nint main(){\n\tint64 N;\n\tvi F(2,1);\n\twhile(F.back() < 1e18) F.pb ( F.back() + F[F.sz-2] );\n\twhile(cin>>N){\n\t\tcout<\n#include\n#include\n#include\n\n#define Free(x) (x!=p[0]&&x!=p[1]&&x!=p[2])\n\nusing std::max;\n\nconst int maxn=42<<3;\nint a[3],b[3],ans;\nbool v[maxn][maxn][maxn];\n\nvoid dfs(int A,int B,int C){\n if(v[A][B][C])return;\n \n v[A][B][C]=1;\n int i,j,u,t,x,y;\n int p[3]={A>>3,B>>3,C>>3},w[3]={-1,-1,-1};\n bool g[3]={0,0,0};\n if(t=A&3,t==1||t==2)g[w[0]=t]=1;\n if(t=B&3,t==1||t==2)g[w[1]=(t==1)?2:0]=1;\n if(t=C&3,t==1||t==2)g[w[2]=t-1]=1;\n ans=max(max(ans,p[0]),max(p[1],p[2]));\n //printf(\"reach : %d %d %d\\n\",p[0],p[1],p[2]);\n \n if(!g[i=0]){\n u=A,t=u&3,x=1,y=2;\n if(w[i]==-1&&!((u>>2)&1))\n for(j=max(p[i]-a[i],0);j<=p[i]+a[i];++j)\n if(Free(j))dfs((((j<<1)|1)<<2)|t,B,C);\n if(!t){\n if(!g[x]&&(p[i]-p[x]==1||p[x]-p[i]==1))\n if(w[x]==-1)\n dfs((u>>2<<2)|1,(p[i]<<3)|(B&7),C);\n\t else\n\t dfs((u>>2<<2)|1,(p[i]<<3)|(B&7),(p[i]<<3)|(C&7));\n if(!g[y]&&(p[i]-p[y]==1||p[y]-p[i]==1))\n if(w[y]==-1)\n dfs((u>>2<<2)|2,B,(p[i]<<3)|(C&7));\n else\n dfs((u>>2<<2)|2,(p[i]<<3)|(B&7),(p[i]<<3)|(C&7));\n }\n if(x==w[i]){\n for(j=max(p[i]-b[i],0);j<=p[i]+b[i];++j)if(Free(j))\n if(w[x]==-1)\n dfs((u>>2<<2)|3,(j<<3)|(B&7),C);\n else\n dfs((u>>2<<2)|3,(j<<3)|(B&7),(j<<3)|(C&7));\n }else if(y==w[i]){\n for(j=max(p[i]-b[i],0);j<=p[i]+b[i];++j)if(Free(j))\n if(w[x]==-1)\n dfs((u>>2<<2)|3,B,(j<<3)|(C&7));\n else\n dfs((u>>2<<2)|3,(j<<3)|(B&7),(j<<3)|(C&7));\n }\n }\n \n if(!g[i=1]){\n u=B,t=u&3,x=2,y=0;\n if(w[i]==-1&&!((u>>2)&1))\n for(j=max(p[i]-a[i],0);j<=p[i]+a[i];++j)if(Free(j))\n dfs(A,(((j<<1)|1)<<2)|t,C);\n if(!t){\n if(!g[x]&&(p[i]-p[x]==1||p[x]-p[i]==1))\n if(w[x]==-1)\n dfs(A,(u>>2<<2)|1,(p[i]<<3)|(C&7));\n\t else\n\t dfs((p[i]<<3)|(A&7),(u>>2<<2)|1,(p[i]<<3)|(C&7));\n if(!g[y]&&(p[i]-p[y]==1||p[y]-p[i]==1))\n if(w[y]==-1)\n dfs((p[i]<<3)|(A&7),(u>>2<<2)|2,C);\n else\n dfs((p[i]<<3)|(A&7),(u>>2<<2)|2,(p[i]<<3)|(C&7));\n }\n if(x==w[i]){\n for(j=max(p[i]-b[i],0);j<=p[i]+b[i];++j)if(Free(j))\n if(w[x]==-1)\n dfs(A,(u>>2<<2)|3,(j<<3)|(C&7));\n else\n dfs((j<<3)|(A&7),(u>>2<<2)|3,(j<<3)|(C&7));\n }else if(y==w[i]){\n for(j=max(p[i]-b[i],0);j<=p[i]+b[i];++j)if(Free(j))\n if(w[x]==-1)\n dfs((j<<3)|(A&7),(u>>2<<2)|3,C);\n else\n dfs((j<<3)|(A&7),(u>>2<<2)|3,(j<<3)|(C&7));\n }\n }\n \n if(!g[i=2]){\n u=C,t=u&3,x=0,y=1;\n if(w[i]==-1&&!((u>>2)&1))\n for(j=max(p[i]-a[i],0);j<=p[i]+a[i];++j)if(Free(j))\n dfs(A,B,(((j<<1)|1)<<2)|t);\n if(!t){\n if(!g[x]&&(p[i]-p[x]==1||p[x]-p[i]==1))\n if(w[x]==-1)\n dfs((p[i]<<3)|(A&7),B,(u>>2<<2)|1);\n\t else\n\t dfs((p[i]<<3)|(A&7),(p[i]<<3)|(B&7),(u>>2<<2)|1);\n if(!g[y]&&(p[i]-p[y]==1||p[y]-p[i]==1))\n if(w[y]==-1)\n dfs(A,(p[i]<<3)|(B&7),(u>>2<<2)|2);\n else\n dfs((p[i]<<3)|(A&7),(p[i]<<3)|(B&7),(u>>2<<2)|2);\n }\n if(x==w[i]){\n for(j=max(p[i]-b[i],0);j<=p[i]+b[i];++j)if(Free(j))\n if(w[x]==-1)\n dfs((j<<3)|(A&7),B,(u>>2<<2)|3);\n else\n dfs((j<<3)|(A&7),(j<<3)|(B&7),(u>>2<<2)|3);\n }else if(y==w[i]){\n for(j=max(p[i]-b[i],0);j<=p[i]+b[i];++j)if(Free(j))\n if(w[x]==-1)\n dfs(A,(j<<3)|(B&7),(u>>2<<2)|3);\n else\n dfs((j<<3)|(A&7),(j<<3)|(B&7),(u>>2<<2)|3);\n }\n }\n}\n\nint main(){\n if(FILE_IO){\n freopen(\"t.in\",\"r\",stdin);\n freopen(\"t.out\",\"w\",stdout);\n }\n int i,x[3];\n for(i=0;i<3;++i)scanf(\"%d%d%d\",x+i,a+i,b+i);\n dfs(x[0]-1<<3,x[1]-1<<3,x[2]-1<<3);\n printf(\"%d\",ans+1);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "30932370ec3afa6609573f1c9cbbb2c3", "src_uid": "a14739b86d1fd62a030226263cdc1afc", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \nusing namespace std;\nconst int maxn = 1e5 + 10;\ntypedef long long Long;\nconst int mod = 1e9 + 7;\nLong arr[10];\n\n\nint main()\n{\n int x, y, n; scanf(\"%d%d%d\", &x, &y, &n);\n arr[1] = x;\n arr[2] = y;\n arr[3] = y - x;\n arr[4] = -x;\n arr[5] = -y;\n arr[0] = -y+x;\n Long ans = arr[n%6];\n printf(\"%d\\n\", (ans%mod+mod)%mod);\n\n return 0;\n}\n\n ", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "d5525330e848126b8782b621207e3a61", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define endl '\\n'\n// #define exp 2.7182818284590452353602874713527\n// #define pi acos(-1)\n// typedef complex comp;\n// #include \n// #include \n// #include \n// using namespace __gnu_pbds;\n// #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update>\n#define int long long\nint dp[101][10001], tt[101][10001];\nint ncr[101][101];\nint M = 1e9+7;\nint expo(int a, int b)\n{\n int res = 1;\n while(b > 0)\n {\n if(b%2 == 1)\n res = (res*a)%M;\n b >>= 1;\n a = (a*a)%M;\n }\n return res;\n}\nvoid solve()\n{\n int n, m, k;\n cin >> n >> m >> k;\n ncr[0][0] = 1;\n ncr[1][0] = ncr[1][1] = 1;\n for(int i = 2;i <= n;i++)\n {\n ncr[i][0] = 1;\n for(int j = 1;j <= i;j++)\n {\n ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];\n if(ncr[i][j] >= M)\n ncr[i][j] -= M;\n }\n }\n for(int i = 0;i <= k;i++)\n {\n dp[n][i] = 0;\n if(i <= n)\n dp[n][i] = expo(ncr[n][i], m/n);\n }\n for(int i = n-1;i > 0;i--)\n for(int kk = 0;kk <= k;kk++)\n tt[i][kk] = expo(ncr[n][kk], m/n + (i <= m%n));\n for(int i = n-1;i > 0;i--)\n {\n for(int j = 0;j <= k;j++)\n {\n dp[i][j] = 0;\n for(int kk = 0;kk <= min(n, j);kk++)\n {\n dp[i][j] += (tt[i][kk]*dp[i+1][j-kk])%M;\n if(dp[i][j] >= M)\n dp[i][j] -= M;\n }\n }\n }\n cout << dp[1][k];\n}\nint32_t main()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n double t1 = clock();\n int t;\n t = 1;\n // cin >> t;\n // while(t--)\n for(int i = 1;i <= t;i++)\n {\n // cout << \"Case #\" << i << \": \";\n solve();\n }\n cerr << setprecision(10) << (clock()-t1)/CLOCKS_PER_SEC << \"\\n\";\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "bitmasks"], "code_uid": "260d206e78b1b5bc9d1256db9086bd44", "src_uid": "9c71c8e031412e2bb21266a53821626a", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \nusing namespace std;\n \ntypedef pair pii;\n\ntemplate void sortv(std::vector &v) {\n\tsort(v.begin(), v.end());\n}\n\n\nint disaresta(vector &inter1, vector& inter2) {\n\tsortv(inter1);\n\tsortv(inter2);\n\n\tint c1 = 0, c2 = 0;\n\tint mc1 = 0, mc2 = 0;\n\tint ret = 0;\n\twhile (c1 < (int)inter1.size() || c2 < (int)inter2.size()) {\n\t\tif (c2 == (int)inter2.size() || (c1 < (int)inter1.size() && inter1[c1].first < inter2[c2].first)) {\n\t\t\tmc1 = max(mc1, inter1[c1].second);\n\t\t\tret = max(ret, min(mc1,mc2) - inter1[c1].first + 1);\n\t\t\tc1++;\n\t\t}\n\t\telse {\n\t\t\tmc2 = max(mc2, inter2[c2].second);\n\t\t\tret = max(ret, min(mc1,mc2) - inter2[c2].first + 1);\n\t\t\tc2++;\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nvoid split(vector& inter, int split_pos) {\n\tvector nw;\n\tfor (pii p : inter) {\n\t\tif (split_pos <= p.second) {\n\t\t\tif (p.first < split_pos) nw.emplace_back(p.first, split_pos-1);\n\t\t\tif (p.second > split_pos) nw.emplace_back(max(1, p.first - split_pos), p.second - split_pos);\n\t\t}\n\t\telse {\n\t\t\tnw.push_back(p);\n\t\t}\n\t}\n\n\tinter.clear();\n\tsortv(nw);\n\tfor (int i = 0; i < (int)nw.size(); i++) {\n\t\twhile (!inter.empty() && inter.back().first == nw[i].first ) inter.pop_back();\n\t\tif (inter.empty() || inter.back().second < nw[i].second) inter.push_back(nw[i]);\n\t}\n}\n\nvoid solve() {\n\tint l1,r1,l2,r2;\n\tscanf(\"%d %d %d %d\", &l1, &r1, &l2, &r2);\n\n\tvector< pii > inter1, inter2;\n\tinter1.emplace_back(l1,r1);\n\tinter2.emplace_back(l2,r2);\n\n\tint ans = 0;\n\tfor (int let = 30; let >= 1; let--) {\n\t\tans = max(ans, disaresta(inter1, inter2));\n\t\tint pos = (1<<(let-1));\n\t\tsplit(inter1,pos);\n\t\tsplit(inter2,pos);\n\t}\n\n\tprintf(\"%d\\n\", ans);\t\n}\n\n\nint main() {\n solve();\n}\n\n\n", "lang_cluster": "C++", "tags": ["divide and conquer"], "code_uid": "92d852bee08ef1ada1341af9d42a1ee0", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\n\nint main() {\n int n, max = 0;\n cin>>n;\n int arr[n];\n int answer[n];\n answer[0] = -1;\n\n for (int i=0; i>arr[i];\n answer[i] = 0;\n }\n\n for (int i=1; imax)? answer[i] : max;\n }\n\n cout<\nusing namespace std;\n\ntypedef long long ll;\n\ntemplate\nvoid out(T x) { cout << x << endl; exit(0); }\n#define watch(x) cout << (#x) << \" is \" << (x) << endl\n\nconst int maxn = 1e6 + 5;\n\nint main() {\n ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n\n ll n,k,m,D;\n cin>>n>>k>>m>>D;\n ll ans = 0;\n \n for (ll d=1; d<=D; d++) {\n // (d-1)*k*x + x <= n. optimal # of candies to get if we do d rounds\n // first d-1 rounds everyone gets x. then we give x to Arkady and throw the rest away.\n if (d-1>0 && k > (n-1)/(d-1)) continue; // prevent overflow when doing k*(d-1)\n \n ll x = min(n / (k*(d-1) + 1), m);\n if (x == 0) continue;\n ans = max(ans, x*(d-1)+x);\n }\n \n cout<\n#include\nusing namespace std;\nint main()\n{\n int n,m,i,j,sum=1,b=0,k=0;\n vectorv;\n scanf(\"%d%d\",&n,&m);\n if(m==0)\n {\n printf(\"YES\\n\");\n return 0;\n }\n if(n==2&&m==0)\n {\n printf(\"YES\\n\");\n return 0;\n }\n else if(n==2&&m!=0)\n {\n printf(\"NO\\n\");\n return 0;\n }\n int arr[n]= {0};\n for(i=2; i\nusing namespace std;\nint a[10][10],f;\nint main()\n{\n for(int i=1;i<=2;i++)\n for(int j=1;j<=3;j++)\n cin>>a[i][j];\n for(int i=1;i<=3;i++)\n if(a[1][i]==a[2][i]){f=1;break;}\n cout<<(f?\"YES\\n\":\"NO\\n\");\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "6b21845b6b03ccaf9f9373c82f343fda", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define ld long double\n\nusing namespace std;\nint a[200],b[200],c[200],d[200], ans,x,n,tot;\nint main() {\n cin>>n>>x;\n for (int i=1;i<=n;++i) {\n scanf(\"%d\",&d[i]);\n if (d[i]&1) a[i]=a[i-1]+1,b[i]=b[i-1]; else a[i]=a[i-1],b[i]=b[i-1]+1;\n }\n for (int i=2;i<=n;i+=2) {\n if (a[i]==b[i]) {\n c[++tot]=abs(d[i]-d[i+1]);\n }\n }\n tot--;\n sort(c+1,c+1+tot);\n int i=0;\n while (ans+c[i+1]<=x&&i\n#include\n#define ll long long\n#define ld long double\n#define llu unsigned long long int\n#define pb push_back\n#define mp make_pair\n#define fir first\n#define sec second\n#define gll(a,n) for(ll i=0;i>a[i];\n#define mod 1000000007\n#define pi 3.1415926535897\nusing namespace std;\nint main()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n //freopen(\"B-small-attempt0.in\", \"r\", stdin);freopen(\"output.txt\", \"w\", stdout);\n //std::cout << std::setprecision(9);\n //std::cout << std::fixed;\n ll n,m,a,b;\n cin>>n>>m>>a>>b;\n ll ans=0;\n ll x=b-a,y=a%m,z=b%m;\n if(y==0)\n y=m;\n if(z==0)\n z=m;\n //cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include \n#include \n//#include\n//#include\n#define ll long long\n#define ms(a,b) memset(a,b,sizeof(a))\n#define lowbit(x) x & -x\n#define bug cout<<\"----acac----\"<>n;\n int k1,k2;\n cin>>k1;\n dequeq1,q2;\n for(int i=0;i>x;\n q1.push_back(x);\n }\n cin>>k2;\n for(int i=0;i>x;\n q2.push_back(x);\n }\n int ans=0,flage=0;\n while(ans<10000)\n {\n int x=q1.front();\n int y=q2.front();\n q1.pop_front();\n q2.pop_front();\n if(x>y)\n {\n q1.push_back(y);\n q1.push_back(x);\n }\n if(x\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define Inf (1<<30)\n#define LL long long\n#define MOD 2520\n#pragma comment(linker, \"/STACK:102400000,102400000\")\nusing namespace std;\nconst int MM=2520;\nLL bit[20];\nLL dp[20][MOD][2][2][2][2][2][2][2][2];\nLL n,m;\n/// 2 3 4 5 6 7 8 9\nLL DP(int a,int c,bool cc,bool dd,bool ee,bool ff,bool gg,bool hh,bool ii,bool jj,bool flag)\n{\n LL ans=0;\n if(a==0){\n if(!cc&&c%2!=0)return 0;\n if(!dd&&c%3!=0)return 0;\n if(!ee&&c%4!=0)return 0;\n if(!ff&&c%5!=0)return 0;\n if(!gg&&c%6!=0)return 0;\n if(!hh&&c%7!=0)return 0;\n if(!ii&&c%8!=0)return 0;\n if(!jj&&c%9!=0)return 0;return !flag;\n }\n if(!flag&&dp[a][c][cc][dd][ee][ff][gg][hh][ii][jj]!=-1)\n return dp[a][c][cc][dd][ee][ff][gg][hh][ii][jj];\n int en=flag?bit[a]:9;\n for(int k=0;k<=en;k++)\n ans+=DP(a-1,(c*10+k)%MOD,cc&&k!=2,dd&&k!=3,ee&&k!=4,ff&&k!=5,gg&&k!=6,hh&&k!=7,ii&&k!=8,jj&&k!=9,flag&&k==en);\n if(!flag)dp[a][c][cc][dd][ee][ff][gg][hh][ii][jj]=ans;\n return ans;\n}\nLL calc(LL n)\n{\n int L=0;\n while(n>0)\n {\n bit[++L]=n%10;\n n/=10;\n }\n return DP(L,0,1,1,1,1,1,1,1,1,1);\n}\nint main()\n{\n int T;\n //freopen(\"D:\\\\o.txt\",\"r\",stdin);\n scanf(\"%d\",&T);\n memset(dp,-1,sizeof(dp));\n while(T--)\n {\n scanf(\"%lld%lld\",&n,&m);\n LL temp1=calc(m+1);\n LL temp2=calc(n);\n printf(\"%lld\\n\",temp1-temp2);\n }\n return 0;\n}\n\n\n ", "lang_cluster": "C++", "tags": ["dp", "number theory"], "code_uid": "c3afc28c4fd2501896d57f0928ad9967", "src_uid": "37feadce373f728ba2a560b198ca4bc9", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \nusing namespace std;\n\ntypedef vector Row;\ntypedef vector Mat;\n\nconst int inf = 2e9 +7;\n\nMat operator * (Mat &a, Mat &b) {\n Mat r (a.size(), Row(b[0].size(), inf));\n for(int i = 0; i < a.size(); i++) {\n for(int j = 0; j < b[0].size(); j++) {\n for(int k = 0; k < b.size(); k++) {\n if(a[i][k] != inf and b[k][j] != inf) {\n r[i][j] = min(r[i][j], a[i][k] + b[k][j]);\n }\n }\n }\n }\n return r;\n}\n\nint n, m;\nint a[20], b[20];\n\nint main() {\n scanf(\"%d %d\", &n, &m);\n for(int i = 0; i < n; i++) scanf(\"%d\", &a[i]);\n for(int i = 0; i < n; i++) scanf(\"%d\", &b[i]);\n Mat I (n+1, Row(n+1, inf));\n for(int i = 0; i <= n; i++) I[i][i] = 0;\n Mat X = I;\n for(int t = 0; t < n; t++) {\n Mat Y = I;\n for(int i = 0; i <= n; i++) {\n for(int j = 0; j <= n; j++) {\n Y[i][j] = j == i+1? b[t]: j == i-1? a[t]: inf;\n }\n } \n X = Y*X;\n }\n Mat Z = I;\n for(int x = 1; x <= m; x*=2, X = X*X) { \n if(x & m) {\n Z = Z*X;\n }\n }\n Mat A (n+1, Row(1, inf));\n A[0][0] = 0;\n printf(\"%d\\n\", (Z*A)[0][0]);\n}", "lang_cluster": "C++", "tags": ["matrices", "dp"], "code_uid": "af35f82eeb182c20f46753a2a38c3a34", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define inf 0x3f3f3f3f\nusing namespace std;\nconst int MOD = 1000000007;\nint main(){\n\n\tint n,x,pos,maxnum,minnum,left,right,middle;\n\tlong long ans=1;\n\tcin>>n>>x>>pos;\n\tmaxnum=n-x,minnum=x-1;\n\tleft=0,right=n;\n\twhile(leftpos){\n\t\t\tans=ans*maxnum%MOD;\n\t\t\tmaxnum--;\n\t\t\tright=middle;\n\t\t}else{\n\t\t\tleft=middle+1;\n\t\t}\n\t}\n\tfor(int i=1;i<=maxnum+minnum;i++){\n\t\tans=ans*i%MOD;\n\t}\n\tcout<\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define PII pair \n#define PB push_back\n#define MP make_pair\n#define fi first\n#define se second\n#define LL long long\nconst int maxn = 100005;\nint n, m;\nset < pair > S;\nset < PII > SS;\nstring c;\n/*\n * 1 3\n *\n * 4 2\n*/\nint main() {\n int i, j;\n int x, y;\n cin >> n >> m >> x >> y >> c;\n int dir;\n if(c == \"DR\") dir = 2;\n else if(c == \"UR\") dir = 3;\n else if(c == \"DL\") dir = 4;\n else dir = 1;\n int tot = 1;\n int sum = (m+1)/2+(m+(n&1))/2+(n+1)/2+(n+(m&1))/2\n -1 - (m&1) - (n&1) - ((n&1)==(m&1));\n LL ans = 1;\n// printf(\"sum = %d\\n\", sum);\n S.insert( MP(MP(x, y), dir));\n SS.insert(MP(x, y));\n bool flag = 0;\n while(1) {\n // printf(\"x = %d y = %d dir = %d\\n\", x, y, dir);\n // printf(\"ans = %d tot = %d\\n\", ans, tot);\n if(dir == 1) {\n int cnt = min(x-1, y-1);\n ans += cnt;\n y -= cnt;\n x -= cnt;\n if(x==1 && y == 1) dir = 2;\n else if(x==1) dir = 4;\n else if(y==1) dir = 3;\n }\n else if(dir == 2) {\n int cnt = min(m-y, n-x);\n ans += cnt;\n x += cnt;\n y += cnt;\n if(x==n&&y==m) dir = 1;\n else if(x==n) dir = 3;\n else if(y==m) dir = 4;\n }\n else if(dir == 3) {\n int cnt = min(x-1,m-y);\n ans += cnt;\n x -= cnt;\n y += cnt;\n if(x==1&&y==m) dir = 4;\n else if(x==1) dir = 2;\n else if(y==m) dir = 1;\n }\n else {\n int cnt = min(n-x, y-1);\n ans += cnt;\n x += cnt;\n y -= cnt;\n if(x==n&&y==1) dir = 3;\n else if(x==n) dir = 1;\n else if(y==1) dir = 2;\n }\n PII pp = MP(x, y);\n if(!SS.count(pp)) {\n SS.insert(pp);\n tot++;\n }\n if(tot == sum) break;\n if(S.count(MP(pp, dir))) { flag = 1; break; }\n S.insert(MP(pp, dir));\n\n }\n if(flag) puts(\"-1\");\n else cout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation", "number theory"], "code_uid": "9c3fbf653c2dcd4d7c984887f1f260a3", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include\n#include\n#include\n#include\n#define ll long long\nusing namespace std;\nll num[100500];\nint main()\n{\n\tll n,k;\n\tnum[1]=1;\n\tfor(int i=2;i<=100400;i++)\n\t{\n\t\tnum[i]=num[i-1]+i;\n\t}\n\tscanf(\"%lld%lld\",&n,&k);\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tif(num[i]+i==n+k)\n\t\t{\n\t\t\tprintf(\"%lld\",n-i);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "binary search"], "code_uid": "5e2fabea7291acfbb75a8574d0f33423", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \r\n#define fo(a,b,c) for (a=b; a<=c; a++)\r\n#define fd(a,b,c) for (a=b; a>=c; a--)\r\n#define fu(x) (((x)&1)?-1:1)\r\n#define add(a,b) a=((a)+(b))%mod\r\n#define min(a,b) (ab?a:b)\r\n#define mod 998244353\r\n#define Mod 998244351\r\n#define ll long long\r\n//#define file\r\nusing namespace std;\r\n \r\nint n,K,i,j,k,l,ii;\r\nint a[51];\r\nll C[2001][2001],jc[2001],Jc[2001];\r\nll f[51][2001][51];\r\nll ans,p0,p1,Len,LEN,L;\r\n \r\nll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}\r\nll E(ll p,ll a,ll b) {return p*qpower(qpower(1-b,a+1),Mod)%mod;} //p*x^a*e^b\r\n \r\nint main()\r\n{\r\n\t#ifdef file\r\n\tfreopen(\"CF1477F.in\",\"r\",stdin);\r\n\t#endif\r\n\t\r\n\tscanf(\"%d%d\",&n,&K);\r\n\tfo(i,1,n) scanf(\"%d\",&a[i]),Len+=a[i];LEN=qpower(Len,Mod);\r\n\t\r\n\tC[0][0]=1;\r\n\tfo(i,1,2000)\r\n\t{\r\n\t\tC[i][0]=C[i][i]=1;\r\n\t\tfo(j,1,i-1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;\r\n\t}\r\n\tjc[0]=1;\r\n\tfo(i,1,2000) jc[i]=jc[i-1]*i%mod;\r\n\tJc[2000]=qpower(jc[2000],Mod);\r\n\tfd(i,2000-1,0) Jc[i]=Jc[i+1]*(i+1)%mod;\r\n\t\r\n\tf[0][0][0]=1;\r\n\tfo(l,1,n)\r\n\t{\r\n\t\tL=a[l],ii=(L-1)/K;\r\n\t\tfo(i,0,ii)\r\n\t\t{\r\n\t\t\tp0=qpower((L-i*K)*LEN%mod,i)*fu(i)*Jc[i]%mod;\r\n\t\t\tif (i)\r\n\t\t\tp1=qpower((L-i*K)*LEN%mod,i-1)*fu(i)*Jc[i-1]%mod;\r\n\t\t\tfo(j,0,Len)\r\n\t\t\t{\r\n\t\t\t\tfo(k,0,l-1)\r\n\t\t\t\tif (f[l-1][j][k])\r\n\t\t\t\t{\r\n\t\t\t\t\tadd(f[l][j+i][k],f[l-1][j][k]*p0);\r\n\t\t\t\t\tif (i)\r\n\t\t\t\t\tadd(f[l][j+i][k+1],f[l-1][j][k]*p1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tfo(j,0,Len) fo(k,0,n) f[n][j][k]=-f[n][j][k];\r\n\tadd(f[n][0][0],1);\r\n\tassert(!f[n][0][0]);\r\n\t\r\n\tfo(j,0,Len) fo(k,0,n) if (f[n][j][k])\r\n\tadd(ans,E(f[n][j][k],j-k,(Len-j*K)*LEN%mod)*jc[j-k]);\r\n\tprintf(\"%lld\\n\",(ans+mod)%mod);\r\n\t\r\n\tfclose(stdin);\r\n\tfclose(stdout);\r\n\treturn 0;\r\n}\r\n ", "lang_cluster": "C++", "tags": ["math", "probabilities", "combinatorics", "fft"], "code_uid": "eb54b461952ad42b155f32dd33a69cf2", "src_uid": "26d565c193a5920b042c783109496b4c", "difficulty": 3500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n string str1[]= {\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"};\n int num;\n string str;\n cin>>num>>str;\n int i;\n for(i=0; i<8; i++)\n {\n if(str1[i].size()==num)\n {\n int j;\n for(j=0; j\n#include \nusing namespace std;\n\nint num[10];\nint main(){\n int n;cin>>n;\n for(int i=0;i<6;i++){\n num[i]=n%2;\n n/=2;\n }\n\n swap(num[0],num[4]);\n swap(num[2],num[3]);\n\n int x=0;\n for(int i=5;i>=0;i--){\n x*=2;\n x+=num[i];\n }\n cout<\nusing namespace std;\n\nint read() {\n\tint ans = 0, flag = 1;\n\tchar ch = getchar();\n\twhile(ch < '0' || ch > '9') {if(ch == '-') flag = - flag; ch = getchar();}\n\twhile(ch >= '0' && ch <= '9') {ans = ans * 10 + ch - '0'; ch = getchar();}\n\treturn ans * flag;\n}\nconst int MOD = 1000000007;\nint qpow(int a, int b) {\n\tint ans = 1;\n\twhile(b) {\n\t\tif(b & 1) ans = 1ll * ans * a % MOD;\n\t\ta = 1ll * a * a % MOD;\n\t\tb >>= 1;\n\t}\n\treturn ans;\n}\nint n, m;\nint main() {\n\tn = read(); m = read();\n\tprintf(\"%d\\n\", 1ll * qpow(2 * (n + 1), m) * (n + 1 - m) % MOD * qpow(n + 1, MOD - 2) % MOD);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "2f995ff51623c94dc4470418c4070277", "src_uid": "4f9711197e699c0fd0c4e9db8323cac7", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include\nint main()\n{\n int k,a,b,ans=0,c,d,t;\n scanf(\"%d%d%d\",&k,&a,&b);\n if(a=k)\n ans=a/k+b/k;\n else\n ans=-1;\n }\n printf(\"%d\\n\",ans);\n return 0;\n}\n\n\t \t\t\t\t \t \t\t \t \t\t\t", "lang_cluster": "C++", "tags": ["math"], "code_uid": "aa84a93e296d362c4a6d5176f09282c4", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\nusing namespace std;\nchar t;\nlong long a=0,ans,f=0;\nint main()\n{\n\twhile(cin>>t&&++f)\n\t\tif(t=='A'||t=='E'||t=='I'||t=='O'||t=='U'||t=='Y')\n\t\t\tans=max(ans,f-a),a=f;\n\tcout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)\n#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)\n#define REP(it,v,cont) for(cont::iterator (it)=(v).begin();(it)!=(v).end();++(it)) \n#define CLR(a,c) memset((a),(c),sizeof (a))\n#define ALL(v) (v).begin(),(v).end()\n#define EPS 1e-9\n#define SQR(a) ((a)*(a))\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double lld;\ntypedef pair PII;\ntypedef vector VI;\ntypedef vector VS;\ntypedef vector VD;\ntypedef pair PLL;\n\ndouble getme(double x,double a)\n{\n if(x>=0 && x<=a) return x;\n int k=floor(x/a);\n return k%2?a-(x-k*a):x-k*a;\n}\nint main()\n{\n //freopen(\"a.in\",\"r\",stdin);\n double a,b,m;\n double vx,vy,vz;\n double x,y,z;\n cin>>a>>b>>m;\n cin>>vx>>vy>>vz;\n x=a/2;y=m;z=0;\n double t=-y/vy;\n x=x+t*vx;z=z+t*vz;\n x=getme(x,a);\n z=getme(z,b);\n cout<\r\nusing namespace std;\r\ntypedef long long ll;\r\ntypedef pair pii;\r\nconst int MAXN = 8 + 5;\r\nconst int MAXL = 5 + 5;\r\nconst int mod = 998244353;\r\n\r\ninline void add_mod(int &a,int b){ a+=b; if(a>=mod) a-=mod;}\r\n\r\nconst int M = 8 * 4 + 1;\r\nconst int N = 5 * M;\r\n\r\nstruct Matrix\r\n{\r\n\tint a[N][N];\r\n\tMatrix(void){ clear();}\r\n\tinline void clear(void){ memset(a,0,sizeof(a));}\r\n\tinline int* operator [] (const int x){ return a[x];}\r\n\tinline const int* operator [] (const int x) const { return a[x];}\r\n\tinline Matrix operator * (const Matrix &b) const\r\n\t{\r\n\t\tMatrix res;\r\n\t\tfor(int k=0; k>=1;\r\n\t}\r\n\t\r\n\tprintf(\"%d\",res[get_id(5,0)][get_id(5,0)]);\r\n\treturn 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["brute force", "data structures", "matrices", "strings", "dp"], "code_uid": "dac6b46259d1ba372502a4b1cbf5bd3f", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \nusing namespace std;\n int main()\n{\n int i,n,a = 0,b = 0,x,res = 0,a1 = 0,b1 = 0,y;\n cin>>n;\n for (i = 1; i <= n; i++)\n {\n cin>>x>>y;\n if (x % 2 == 1 && y % 2 == 0) a1++;\n if (y % 2 == 1 && x % 2 == 0) b1++;\n a += x;\n b += y;\n }\n if (a % 2 != 0 && b % 2 != 0 && a1 + b1 > 0) cout<<1; else\n if (a % 2 == 0 && b % 2 == 0) cout<<0; else cout<<-1;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "fd379df99bec4db76ea3ccc480a4b968", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tlong long a[3];\n\tcin >> a[0] >> a[1] >> a[2];\n\tsort(a, a + 3);\n\tif (2 * (a[0] + a[1]) <= a[2])cout << a[0] + a[1] << endl;\n\telse cout << (a[0] + a[1] + a[2]) / 3 << endl;\n\treturn 0;\n}\n\n ", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "be05d3fa58dbfeffa131b459d87fc43b", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define rep(i,a,b) for(int i=(a);i<=(b);i++)\n#define per(i,a,b) for(int i=(a);i>=(b);i--)\n#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])\nusing namespace std;\ntypedef long long i64;\ntypedef unsigned long long u64;\ntypedef unsigned u32;\ntypedef pair pin;\n#define mk(a,b) make_pair(a,b)\n#define lowbit(x) ((x)&(-(x)))\n#define sqr(a) ((a)*(a))\n#define clr(a) (memset((a),0,sizeof(a)))\n#define ls ((x)<<1)\n#define rs (((x)<<1)|1)\n#define mid (((l)+(r))>>1)\n#define pb push_back\n#define w1 first\n#define w2 second\ninline void read(int &x){\n\tx=0;int f=1;char ch=getchar();\n\twhile(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}\n\twhile(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}\n\tx*=f;\n}\ninline void judge(){\n\tfreopen(\"in.txt\",\"r\",stdin);\n\tfreopen(\"out.txt\",\"w\",stdout);\n}\n/*******************************head*******************************/\nint hp1,atk1,def1;\nint hp2,atk2,def2;\nint h,a,d;\nint main(){\n // judge();\n\tread(hp1);read(atk1);read(def1);\n\tread(hp2);read(atk2);read(def2);\n\tread(h);read(a);read(d);\n\tint ans=1e9;\n\trep(hp,hp1,5000)rep(atk,atk1,200)rep(def,def1,100){\n\t\tint cost=h*(hp-hp1)+a*(atk-atk1)+d*(def-def1);\n\t\tif(cost>ans)continue;\n\t\tif(atk<=def2)continue;\n\t\tint r=hp2/(atk-def2)+(hp2%(atk-def2)!=0);\n\t\tif(hp-(atk2-def)*r<=0)continue;\n\t\tans=min(ans,cost);\n\t}cout<\n#include \n#include \n#include \n\ntemplate\nstruct Point\n{\n Point(T x = 0, T y = 0) : x(x), y(y) {}\n\n template\n Point to() const {\n return Point(x, y);\n }\n\n Point& operator -= (const Point& o)\n {\n x -= o.x;\n y -= o.y;\n return *this;\n }\n\n T norm2() const\n {\n return x * x + y * y;\n }\n\n double norm() const\n {\n return sqrt(static_cast(norm2()));\n }\n\n Point normalize() const\n {\n auto d = norm();\n return Point(x / d, y / d);\n }\n\n Point rot() const\n {\n return Point(-y, x);\n }\n\n T x, y;\n};\n\ntemplate\nPoint operator - (Point a, const Point& b)\n{\n return a -= b;\n}\n\ntemplate\nPoint operator * (const Point &a, double k)\n{\n return Point(a.x * k, a.y * k);\n}\n\nconst int N = 3;\nconst double EPS = 1e-9;\n\nint n, r[N], parent[N];\nPoint p[N];\n\ntemplate\nT sqr(T x)\n{\n return x * x;\n}\n\nint find(int u)\n{\n if (parent[u] != u) {\n parent[u] = find(parent[u]);\n }\n return parent[u];\n}\n\nint count(const std::vector>& ps)\n{\n int result = 0;\n for (size_t i = 0; i < ps.size(); ++ i) {\n size_t j = 0;\n while (std::abs(ps[i].x - ps[j].x) > EPS || std::abs(ps[i].y - ps[j].y) > EPS) {\n j ++;\n }\n result += i == j;\n }\n return result;\n}\n\nint main()\n{\n scanf(\"%d\", &n);\n for (int i = 0; i < n; ++ i) {\n scanf(\"%d%d%d\", &p[i].x, &p[i].y, r + i);\n parent[i] = i;\n }\n int result = n + 1;\n std::vector> ps;\n for (int i = 0; i < n; ++ i) {\n std::vector> cps;\n for (int j = 0; j < n; ++ j) {\n if (i == j) {\n continue;\n }\n int d2 = (p[j] - p[i]).norm2();\n if (d2 < sqr(r[i] - r[j]) || sqr(r[i] + r[j]) < d2) {\n continue;\n }\n if (find(i) != find(j)) {\n result --;\n parent[find(i)] = find(j);\n }\n // r[i]^2 - r[j]^2 + d^2 = 2 * d * x\n double x = 0.5 * (d2 + sqr(r[i]) - sqr(r[j])) / sqrt(d2);\n double h = sqrt(std::max(sqr(r[i]) - sqr(x), 0.0));\n Point nv = (p[j] - p[i]).normalize() * -1;\n Point q = p[i].to() - nv * x;\n cps.push_back(q - nv.rot() * h);\n if (d2 < sqr(r[i] + r[j])) {\n cps.push_back(q - nv.rot() * -h);\n }\n }\n result += count(cps);\n for (auto&& p : cps) {\n ps.push_back(p);\n }\n }\n result -= count(ps);\n printf(\"%d\\n\", result);\n}\n", "lang_cluster": "C++", "tags": ["geometry", "graphs"], "code_uid": "187e4e654054e5521dd15a6165e599f4", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Clang++17 Diagnostics", "source_code": "#include\nusing namespace std;\nint fun(int n) {\n\tint x = 0;\n\twhile (n) {\n\t\tx += n % 10;\n\t\tn /= 10;\n\t}\n\treturn x;\n}\nint main() {\n\tint n;\n\tcin >> n;\n\twhile ( fun(n) % 4 ) \n\t\tn++;\n\tcout << n;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "fdc0c56672a8fb7a208bf47d6abab660", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nint main(){\n int n;\n while(scanf(\"%d\",&n)==1){\n int sum=0,i;\n if(n<0)n=-n; \n for(i=0;i<=n;i++){\n sum+=i;\n if(sum>=n&&(sum&1)==(n&1))\n break;\n }\n printf(\"%d\\n\",i);\n }\n}\n/****** PCCA -Thu Aug 25 04:35:19 GMT 2011 *******/", "lang_cluster": "C++", "tags": ["math"], "code_uid": "7985be55329921cf1b1313d530bda8fa", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\ntypedef long long LL;\nconst int mod = 1e9 + 7;\nconst int maxn = 4005;\nint n;\nint bell[maxn][maxn];\nint c[maxn][maxn];\n\nvoid get_c(){ //\u9012\u63a8\u6c42\u7ec4\u5408\u6570C(i,j) \n\tfor(int i = 0; i <= 4000; i++) c[i][0] = 1;\n\t\n\tfor(int i = 1; i <= 4000; i++)\n\t\tfor(int j = 1; j <= i; j++) c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;\n}\n\nvoid get_bell(){ //\u8d1d\u5c14\u4e09\u89d2\u5f62\u9012\u63a8\u8d1d\u5c14\u6570\uff0c\u5176\u4e2d\u7b2c\u4e00\u5217(\u6bcf\u884c\u9996\u9879)\u5373\u4e3a\u8d1d\u5c14\u6570b[i]\n\tbell[0][0] = 1;\n\tfor(int i = 1; i <= 4000; i++){\n\t\tbell[i][0] = bell[i-1][i-1];\n\t\tfor(int j = 1; j <= i; j++) bell[i][j] = (bell[i][j-1] + bell[i-1][j-1]) % mod;\n\t}\n}\n\nint main(){\n\tget_c();\n\tget_bell();\n\tscanf(\"%d\", &n);\n\tint ans = 0;\n\tfor(int i = 0; i < n; i++) ans = (ans + (LL)c[n][i]*bell[i][0] % mod) % mod;\n\tcout << ans << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "dp"], "code_uid": "d42f4c0af6075832ac24321a86c5a854", "src_uid": "aa2c3e94a44053a0d86f61da06681023", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#include\n#include\n#define rep(i,l,r) for (int i=(l); i<=(r); i++)\ntypedef long long ll;\nusing namespace std;\n\nconst int N=100010;\nll t;\nint n,m,s,nd,rt,tot,to[N][50];\nstruct Tr{ int ls,rs,v,sz,d; }v[N<<8];\nstruct P{ int x,y; };\n\nint jump(ll x,ll y){\n\tif (x<=m) x+=y; else x-=y;\n\treturn (x%n+n-1)%n+1;\n}\n\nvoid upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; v[x].d=max(v[v[x].ls].d,v[v[x].rs].d)+1; }\nint get(int k){ v[++nd]=(Tr){0,0,k,1,1}; return nd; }\nvoid dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }\nvoid Print(int x){ if (v[x].ls) Print(v[x].ls); printf(\"%d \",v[x].v); if (v[x].rs) Print(v[x].rs); }\n\nint merge(int x,int y){\n\tif (!x || !y){ v[++nd]=v[x|y]; return nd; }\n\tint p=++nd;\n\tif (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)\n\t\t{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }\n\telse{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }\n}\n\nP split(int x,int k){\n\tif (!x) return (P){0,0};\n\tP t; int p=++nd; v[p]=v[x];\n\tif (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }\n\t\telse{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }\n}\n\nvoid build(){ rt=nd=0; rep(i,1,n) rt=merge(rt,get(to[i][0])); }\n\nint main(){\n\tscanf(\"%d%d%d\",&n,&m,&s); cin>>t;\n\tfor (; t%n; t--) s=jump(s,t); t/=n;\n\trep(i,1,n) to[i][0]=i; build();\n\trep(i,1,n-1){\n\t\tint lst=rt;\n\t\tif (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }\n\t\t\telse{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }\n\t\tif (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }\n\t\t\telse{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }\n\t\tif (v[rt].d>200) tot=0,dfs(rt),build();\n\t}\n\ttot=0; dfs(rt);\n\trep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];\n\tfor (int j=49; ~j; j--) if (t&(1ll<\n#include \n#include \nusing namespace std;\n\nint main()\n{\n\tstring s, p = \"\", a;\n\tcin >> s;\n\tint l = s.size();\n\tif (l % 2 == 0) {\n\t\tp += s[(l / 2 - 1)];\n\t\tint i = 0;\n\t\twhile (true)\n\t\t{\t\t\t\n\t\t\t++i;\n\t\t\tif ((l / 2 - 1) + i < l)\n\t\t\t\tp += s[(l / 2 - 1) + i];\n\t\t\telse break;\n\t\t\tif ((l / 2 - 1) - i >= 0)\n\t\t\t\tp += s[(l / 2 - 1) - i];\n\t\t\telse break;\n\t\t}\n\t}\n\telse {\n\t\tp += s[(l / 2)];\n\t\tint i = 0;\n\t\twhile (true)\n\t\t{\n\t\t\t++i;\n\t\t\tif ((l / 2) + i < l)\n\t\t\t\tp += s[(l / 2) + i];\n\t\t\telse break;\n\t\t\tif ((l / 2) - i >= 0)\n\t\t\t\tp += s[(l / 2) - i];\n\t\t\telse break;\n\t\t}\n\t}\n\tcout << p;\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "f8370210bac67943c42312abbed49e27", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n#define X first\n#define Y second\n#define mp make_pair\n#define pb push_back\n#define Debug(...) fprintf(stderr, __VA_ARGS__)\n\ntypedef long long LL;\ntypedef long double LD;\ntypedef unsigned int uint;\ntypedef pair pii;\ntypedef unsigned long long uLL;\n\ntemplate inline void Read(T &x) {\n char c = getchar();\n bool f = false;\n for (x = 0; !isdigit(c); c = getchar()) {\n if (c == '-') {\n f = true;\n }\n }\n for (; isdigit(c); c = getchar()) {\n x = x * 10 + c - '0';\n }\n if (f) {\n x = -x;\n }\n}\n\ntemplate inline bool CheckMax(T &a, const T &b) {\n return a < b ? a = b, true : false;\n}\n\ntemplate inline bool CheckMin(T &a, const T &b) {\n return a > b ? a = b, true : false;\n}\n\nconst int N = 55;\nconst int M = 7850;\nconst int mod = 1e9 + 7;\nconst int dx[] = {-1, 0, 1, 0};\nconst int dy[] = {0, -1, 0, 1};\n\nint n, m, p[4], ans[M], a[M][M];\nvector all;\n\ninline int Qow(int x, int y) {\n int r = 1;\n for (; y; y >>= 1, x = 1LL * x * x % mod) {\n if (y & 1) {\n r = 1LL * r * x % mod;\n }\n }\n return r;\n}\n\nint main() {\n#ifdef wxh010910\n freopen(\"d.in\", \"r\", stdin);\n#endif\n Read(m);\n for (int i = -m; i <= m; ++i) {\n for (int j = -m; j <= m; ++j) {\n if (i * i + j * j <= m * m) {\n all.pb(mp(i, j));\n }\n }\n }\n int sum = 0;\n for (int i = 0; i < 4; ++i) {\n Read(p[i]), sum += p[i];\n }\n sum = Qow(sum, mod - 2);\n for (int i = 0; i < 4; ++i) {\n p[i] = 1LL * p[i] * sum % mod;\n }\n n = all.size();\n for (int i = 0; i < n; ++i) {\n int x = all[i].X, y = all[i].Y;\n a[i][i] = a[i][n] = 1;\n for (int j = 0; j < 4; ++j) {\n int u = x + dx[j], v = y + dy[j];\n if (u * u + v * v <= m * m) {\n a[i][lower_bound(all.begin(), all.end(), mp(u, v)) - all.begin()] = mod - p[j];\n }\n }\n }\n for (int i = 0; i < n; ++i) {\n vector t = {n};\n int u = min(i + (m << 1) + 5, n);\n for (int j = i; j < u; ++j) {\n if (a[i][j]) {\n t.pb(j);\n }\n }\n int inv = Qow(a[i][i], mod - 2);\n for (int j = i + 1; j < u; ++j) if(a[j][i]){\n if (a[j][i]) {\n int mul = 1LL * a[j][i] * inv % mod;\n for (auto k:t)if(a[i][k]) {\n a[j][k] = (a[j][k] - 1LL * mul * a[i][k] % mod + mod) % mod;\n }\n }\n }\n }\n for (int i = n - 1; ~i; --i) {\n int val = a[i][n];\n for (int j = i + 1; j < n; ++j) {\n val = (val - 1LL * ans[j] * a[i][j] % mod + mod) % mod;\n }\n ans[i] = 1LL * val * Qow(a[i][i], mod - 2) % mod;\n }\n printf(\"%d\\n\", ans[lower_bound(all.begin(), all.end(), mp(0, 0)) - all.begin()]);\n#ifdef wxh010910\n Debug(\"My Time: %.3lfms\\n\", (double)clock() / CLOCKS_PER_SEC);\n#endif\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "7fe9ed474e06c0625dd0d81cc2111bce", "src_uid": "bd6bcb5bffd039de93f217b02f5eae17", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\nconst int mod = 998'244'353;\n\nvoid add(int &x, int y) {\n x += y;\n if (x >= mod)\n x -= mod;\n}\n\nvoid sub(int &x, int y) {\n add(x, mod - y);\n}\n\nint power(int a, int n) {\n int r = 1;\n while (n > 0) {\n if (n % 2) {\n r = (1LL * r * a) % mod;\n }\n a = (1LL * a * a) % mod;\n n /= 2;\n }\n return r;\n}\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n \n int p, s, r;\n cin >> p >> s >> r;\n \n if (p == 1) {\n cout << 1 << '\\n';\n return 0;\n }\n \n --p;\n \n vector> c(p + s + 1, vector (p + s + 1));\n for (int i = 0; i < (int) c.size(); ++i) {\n c[i][0] = c[i][i] = 1;\n for (int j = 1; j < i; ++j) {\n c[i][j] = c[i - 1][j];\n add(c[i][j], c[i - 1][j - 1]);\n }\n }\n \n int result = 0;\n for (int i = 0; i <= s - r; ++i) {\n int sum = 0;\n for (int mx = 0; mx <= i && s - i >= mx; ++mx) {\n if (s - i == mx) {\n for (int cnt = 1; cnt * mx <= i && cnt < p; ++cnt) {\n int total = c[i - cnt * mx + p - cnt - 1][p - cnt - 1] % mod;\n for (int j = 1; j <= p - cnt && (cnt + j) * mx <= i; ++j) {\n auto func = j % 2 ? sub : add;\n func(total, 1LL * c[i - (cnt + j) * mx + p - cnt - 1][p - cnt - 1] * c[p - cnt][j] % mod);\n }\n total = (1LL * total * c[p][cnt]) % mod;\n add(result, 1LL * total * power(cnt + 1, mod - 2) % mod);\n }\n if (p * mx == i) {\n add(result, power(p + 1, mod - 2) % mod);\n }\n continue;\n }\n int total = c[i + p - 1][p - 1];\n sub(total, sum);\n for (int j = 1; j <= p && j * (mx + 1) <= i; ++j) {\n auto func = j % 2 ? sub : add;\n func(total, 1LL * c[i - j * (mx + 1) + p - 1][p - 1] * c[p][j] % mod);\n }\n add(result, total);\n add(sum, total);\n }\n }\n \n int d = 0;\n for (int i = 0; i <= s - r; ++i) {\n add(d, c[i + p - 1][p - 1]);\n }\n \n result = (1LL * result * power(d, mod - 2)) % mod;\n \n cout << result << '\\n';\n \n \n}\n", "lang_cluster": "C++", "tags": ["probabilities", "math", "dp", "combinatorics"], "code_uid": "91d5c0891a038c9888931c62a13c2ab7", "src_uid": "609195ef4a970c62a8210dafe118580e", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main() {\n string x,y=\"CODEFORCES\";\n int n=0;\n cin >> x;\n for(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#include \n\nusing namespace std;\n\n//memset\n#define MEMSET_INF 127 // about 2B\n#define set0(a) memset(a,0,sizeof(a));\n#define setminus1(a) memset(a,-1,sizeof(a));\n#define setinf(a) memset(a,MEMSET_INF,sizeof(a));\n\n//stl\n#define mp make_pair\n#define pb push_back\n#define pc(x) putchar_unlocked(x);\n#define gc() getchar_unlocked();\n\n//Loops\n#define REP(i,n) for(int i = 0;i < (int)(n); i++)\n#define REP1(i,a,b) for(int i = (int)(a);i <= (int)(b); i++)\n#define REPMAP(i,mm) for(auto i = mm.begin();i !=mm.end(); i++)\n\n//modulo\n#define mod %\n#define NUM 1000000007\n\n//#define morethanonetestcases\n//#define testing\n\n//limits\n#ifndef LONG_LONG_MAX\n#define LONG_LONG_MAX\t9223372036854775807LL\n#endif\n#ifndef LONG_LONG_MIN\n#define LONG_LONG_MIN\t(-LONG_LONG_MAX-1)\n#endif\n#ifndef INT_MAX\n#define INT_MAX\t\t2147483647\n#endif\n#ifndef INT_MIN\n#define INT_MIN\t\t(-INT_MAX-1)\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338327950288\n#endif\n\n#define LMAX LONG_LONG_MAX\n#define LMIN LONG_LONG_MIN\n#define IMAX INT_MAX\n#define IMIN INT_MIN\n#define PI M_PI\n#define EPS 1e-6\n\n//trace\n#define TRACE\n#ifdef TRACE\n#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f(const char* name, Arg1&& arg1){\n cerr << name << \" : \" << arg1 << std::endl;\n}\ntemplate \nvoid __f(const char* names, Arg1&& arg1, Args&&... args){\n const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << \" : \" << arg1<<\" | \";__f(comma+1, args...);\n}\n#else\n#define trace(...)\n#endif\n\n//typedef\ntypedef long long ll;\ntypedef vector vi;\ntypedef pair ii;\ntypedef vector vii;\ntypedef set si;\ntypedef map msi;\ntypedef map mii;\n\n\nvoid solve(){\n\n\tll x,y;\n\tcin>>x>>y;\n\tqueue> stk;\n\twhile( x > 1 || y > 1){\n\t\tif(x > y){\n\t\t\tll diff = x-y;\n\t\t\tll times = (ll)ceil((long double)diff/y);\n\t\t\tstk.push(mp('A',times));\n\t\t\tx -= times * y;\n\t\t}else if(x < y){\n\t\t\tll diff = y - x;\n\t\t\tll times = (ll)ceil((long double)diff/x);\n//\t\t\tcout<>TC;\n#else\n\tint TC = 1;\n#endif\n\tfor(int ZZ=1;ZZ<=TC;ZZ++){\n//\t\tcout<<\"Case #\"<\n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define LL long long\n\nint mas[110];\n\nint main()\n{\n int n, d, m;\n cin >> n >> d;\n for (int i = 0; i < n; i++) {\n cin >> mas[i];\n }\n cin >> m;\n sort(mas, mas + n);\n int ans = 0;\n for (int i = 0; i < min(n, m); i++) {\n ans += mas[i];\n }\n if (m > n) {\n ans -= (m - n) * d;\n }\n cout << ans;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "994c57665bd31a669af729d128a35c60", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\n#define fst first\n#define snd second\n#define mp make_pair\n#define rep(i,a,n) for(int i=(a);i<(n);++i)\n#define per(i,a,n) for(int i=(n)-1;i>=(a);--i)\n#define all(x) (x).begin(),(x).end()\n\ntemplate \ninline bool umin(T1& x, const T2& y){return x>y ? x=y,true : false;}\n\ntemplate \ninline bool umax(T1& x, const T2& y){return x pii;\n\nconst int N = (int)1e5+5;\nconst int mod = (int)1e9+7;\nconst int INF = (int)1e9+17;\nconst ll LLINF = (ll)1e18+17;\n\n\nint n;\nint ans[N];\nbool dp[53][5001];\n\n\nvoid prepare() {\n dp[0][0] = true;\n rep(i, 0, 5001) {\n rep(j, 0, 51) {\n for(int x:{1, 5, 10, 50}) {\n if (i + x <= 5000) dp[j+1][i+x] |= dp[j][i];\n }\n ans[j] += dp[j][i];\n }\n }\n}\n\nint32_t main() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr), cout.tie(nullptr);\n#ifdef LOCAL\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#else\n// freopen(\"river.in\", \"r\", stdin);\n// freopen(\"river.out\", \"w\", stdout);\n#endif\n\n prepare();\n cin >> n;\n if (n <= 50) {\n cout << ans[n] << endl;\n } else {\n cout << ans[50] + 49ll * (n-50) << endl;\n }\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "combinatorics", "greedy"], "code_uid": "1ba10f44eb277843327296fb3e8fe087", "src_uid": "75ec99318736a8a1b62a8d51efd95355", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define fi first\n#define se second\n#define th second\n#define FI first\n#define SE second.first\n#define TH second.second\n#define maxi(a, b) ((a > b)? a: b)\n\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair ii;\ntypedef pair iii;\ntypedef long double ld;\ntypedef complex cd;\n\nconst int maxN = 2e5 + 9, lg = 19, MOD = 1e9 + 7, lim = 1e9;\n\nll n, k, l, r, ans = -1;\n\nvoid considPl(ll i, bool tuneada){\n ll resto = k % i;\n if(tuneada && resto == r) return;\n if(resto < r || resto - r > (i - n) || resto > r * 2 || (n - r) + (resto - r) < (i - n))\n return;\n ans = max(ans, i - n);\n}\n\nvoid bruteForce(bool tuneada){\n for(ll i = n; i <= n * 2; i++)\n considPl(i, tuneada);\n}\n\nll entre(ll a, ll b){\n ll ret = a / b;\n if(a % b) ret++;\n return ret;\n}\n\nvoid notSoBruteForce(bool tuneada){\n ll infLim = k / (n * 2);\n ll supLim = k / n;\n \n for(ll i = infLim; i <= supLim; i++){\n //if(i == 0) continue;\n \n ll pedazoMasGrande = max(n, min(n * 2, i? k / i: n * 2));\n \n ll pedazoPequeno = min(n * 2, max(n, k / (i + 1) + 1));\n \n //cout << i << ' ' << pedazoPequeno << ' ' << pedazoMasGrande << '\\n';\n \n if((!tuneada && k % pedazoPequeno < r) || (tuneada && k % pedazoPequeno <= r)) continue;\n \n if(!i && ((!tuneada && k % pedazoMasGrande < r) || (tuneada && k % pedazoMasGrande <= r)))\n continue;\n \n ll falta = 0;\n \n if(i) falta = entre(max(0LL, r - k % pedazoMasGrande), i);\n \n pedazoMasGrande -= falta;\n \n if(tuneada && k % pedazoMasGrande == r) pedazoMasGrande--;\n \n ll cnd = max(0LL, (pedazoMasGrande - n) - (k % pedazoMasGrande - r) - (n - r));\n \n cnd = entre(cnd, i + 1);\n \n pedazoMasGrande -= cnd;\n \n if(pedazoMasGrande >= pedazoPequeno && k % pedazoMasGrande <= r * 2)\n ans = max(ans, pedazoMasGrande - n);\n }\n \n}\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n \n cin >> n >> l >> r >> k;\n \n l--;\n r = (r - l + n) % n;\n \n //cout << r << '\\n';\n \n if(n <= 1000000)\n bruteForce(0);\n else\n notSoBruteForce(0);\n \n k++;\n if(r){\n if(n <= 1000000)\n bruteForce(1);\n else\n notSoBruteForce(1);\n }\n else{\n for(ll i = 1; i * i <= k; i++){\n if(k % i == 0){\n if(n < i && i <= n * 2) considPl(i, 0);\n if(n < k / i && k / i <= n * 2) considPl(k / i, 0);\n }\n }\n }\n cout << ans << '\\n';\n \n}\n", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "b63c1cf6b3439db23f1b9ead0999425d", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std; \nint m=998244353;\n \n// Function to find the value of \n// P * Q^-1 mod 998244353 \nlong long calculate(long long p, \n long long q) \n{ \n long long mod = 998244353, expo; \n expo = mod - 2; \n \n // Loop to find the value \n // until the expo is not zero \n while (expo) { \n \n // Multiply p with q \n // if expo is odd \n if (expo & 1) { \n p = (p * q) % mod; \n } \n q = (q * q) % mod; \n \n // Reduce the value of \n // expo by 2 \n expo >>= 1; \n } \n return p; \n} \n \n// Driver code \nint main() \n{ \n long long p,q=1;\n int n;\n cin>>n;\n if(n==1)\n {\n p=1;\n q=2;\n }\n else if(n==2)\n {\n p=1;\n q=4;\n }\n else\n {\n int k=n;\n while(k--)\n {\n q=(q*2)%m;\n }\n long long f1=1;\n long long f2=1;\n long long f3=2;\n for(int i=2;i\n\nusing namespace std;\n\nint k, a, v, b, st, dr, piv;\n\nint check(int x){\n\tint nr = min(x * (k-1), b);\n\treturn ((x + nr) * v); \n}\n\nint main(){\n//\tifstream in(\"tst.in\");\n//\tofstream out(\"tst.out\");\n\tcin >> k >> a >> b >> v;\n\tst = 1;\n\tdr = 10000;\n\twhile(st <= dr){\n\t\tpiv = (st + dr) / 2;\n\t\tif(check(piv) >= a) dr = piv - 1;\n\t\telse st = piv + 1;\n\t}\n\tcout << st;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "b7d203459bab9793e749f94826b5b191", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nlong long n, m;\n\nbool isPrime[1000001];\nvector primes;\nlong ans = 0;\n\nbool NumIsPrime(long long x)\n{\n if (x < m)\n return isPrime[x];\n else\n { \n for (int i = 0; primes[i] * primes[i] <= x && i < primes.size(); i++)\n {\n \n if (x % primes[i] == 0)\n return false;\n }\n return true;\n }\n}\n\nvoid FindAns(long long curNum, long curPrimeNum)\n{\n if (curNum == 1)\n {\n ans++;\n return;\n }\n \n for (int i = curPrimeNum; i < primes.size(); i++)\n {\n // check 4 primes[i]^k + 1 is divisor of curNum\n long long p = primes[i];\n if (p * p + 1 > curNum)\n break;\n \n while (p + 1 <= curNum)\n {\n if ( curNum % (p + 1) == 0)\n FindAns(curNum / (p + 1), i + 1);\n p *= primes[i]; \n }\n }\n // exist (prime + 1) | curNum, prime not in primes\n if (NumIsPrime(curNum - 1) && curNum - 1 >= primes[curPrimeNum])\n ans++;\n}\n\nint main()\n{\n cin >> n;\n m = 1000000;\n \n for (int i = 0; i <= m; i++)\n isPrime[i] = true;\n isPrime[1] = false;\n for (int i = 2; i <= m; i++)\n {\n if (isPrime[i])\n {\n primes.push_back(i);\n for (int j = 2 * i; j <= m; j += i)\n isPrime[j] = false;\n } \n }\n \n ans = 0;\n FindAns(n, 0);\n cout << ans; \n return 0;\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "math", "dp", "data structures", "number theory"], "code_uid": "f7a309bcedd8de056c4dca8c327ee28f", "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define ll long long \nusing namespace std;\nint main()\n\n{\n ll n ;\n \n \n \n cin>>n;\n vector arr(n,0);\n for(int i =0;i>arr[i];\n ll ans = 0;\n sort(arr.begin(),arr.end());\n for(int i=0;i\nint a[10100],b[5];\nint main()\n{\n int i,ii,j,kk=1,k;\n for(i=1;i<=400;i++)\n {\n k=0;ii=i;\n while(ii)\n {\n b[k++]=ii%10;\n ii/=10;\n }\n for(j=k-1;j>=0;j--)\n a[kk++]=b[j];\n }\n int n;\n while(scanf(\"%d\",&n)!=EOF)\n {\n printf(\"%d\\n\",a[n]);\n }\n return 0;\n}\n/*2018-02-13 14:07:19.622*/", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "e520e883fe0fa8cd28a0441db9a8bd76", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "#include\r\nusing namespace std;\r\nlong long t,n,k,p=1000000007;\r\nlong long ksm(long long n,long long k)\r\n{\r\n\tlong long base=n,ans=1;\r\n\twhile(k)\r\n\t{\r\n\t\tif(k&1)\r\n\t\t ans=ans*base%p;\r\n\t\tbase=base*base%p;\r\n\t\tk>>=1;\r\n\t}\r\n\treturn ans;\r\n}\r\nint main()\r\n{\r\n\tcin>>t;\r\n\twhile(t--)\r\n\t{\r\n\t\tcin>>n>>k;\r\n\t\tcout<\nusing namespace std;\n#define endl '\\n'\n#define rep(i,a,n) for (int i=a;i=a;i--)\n#define pb push_back\n#define mp make_pair\n#define all(x) (x).begin(),(x).end()\n#define fi first\n#define se second\n#define SZ(x) ((int)(x).size())\ntypedef vector VI;\ntypedef long long ll;\ntypedef pair PII;\ntypedef double db;\nmt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());\nconst ll mod=1000000007;\nll rnd(ll x) { return (unsigned long long)mrand() % x;}\nll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}\nll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}\nll lcm(ll a,ll b) { return a/gcd(a,b)*b;}\nconst std::vector> moves{{0, -1}, {-1, 0}, {0, 1}, {1, 0}};\ninline int bitCount(int x) {return __builtin_popcount(x);}// 1001 -> 2\ninline int bitCount(ll x) {return __builtin_popcountll(x);} \ninline int highestOneBit(int x) {return 1 << (31 - __builtin_clz(x | 1));} // 1001 -> 8\ninline int binaryDigits(int x) { return 32 - __builtin_clz(x | 1);} // 1001 -> 4\n// head\ntemplatestring to_string(A* ptr){stringstream ss; ss << \"0x\" << std::setw(16) << std::setfill ('0') << std::hex << (uint64_t)(uintptr_t)ptr;return ss.str();}\ntemplate string to_string(pair p);\ntemplate string to_string(tuple p);\ntemplate string to_string(tuple p);\nstring to_string(const string& s){return '\"' + s + '\"';}\nstring to_string(const char* s){return to_string((string) s);}\nstring to_string(bool b) {return (b ? \"true\" : \"false\");}\nstring to_string(vector v) {bool first = true;string res = \"{\";for (int i = 0; i < static_cast(v.size()); i++) {if (!first) {res += \", \";}first = false;res += to_string(v[i]);}res += \"}\";return res;}\ntemplate string to_string(bitset v) {string res = \"\";for (size_t i = 0; i < N; i++) {res += static_cast('0' + v[i]);}return res;}\ntemplate string to_string(A v) {bool first = true;string res = \"{\";for (const auto &x : v) {if (!first) {res += \", \";}first = false;res += to_string(x);}res += \"}\";return res;}\ntemplate string to_string(pair p) {return \"(\" + to_string(p.first) + \", \" + to_string(p.second) + \")\";}\ntemplate string to_string(tuple p) {return \"(\" + to_string(get<0>(p)) + \", \" + to_string(get<1>(p)) + \", \" + to_string(get<2>(p)) + \")\";}\ntemplate string to_string(tuple p) {return \"(\" + to_string(get<0>(p)) + \", \" + to_string(get<1>(p)) + \", \" + to_string(get<2>(p)) + \", \" + to_string(get<3>(p)) + \")\";}\nvoid debug_out() { cerr << endl; }\ntemplate void debug_out(Head H, Tail... T) {cerr << \" \" << to_string(H);debug_out(T...);}\n#if !ONLINE_JUDGE && 1\n#define dbg(...) cerr << \"[\" << #__VA_ARGS__ << \"]:\", debug_out(__VA_ARGS__)\n#else\n#define dbg(...) 42\n#endif\n// Debug\nnamespace algebra {\n\tusing namespace std;\n\tconst int inf = 1e9;\n\tconst int magic = 500; // threshold for sizes to run the naive algo\n\n\tnamespace fft {\n\t\tconst int maxn = 1 << 18;\n\n\t\ttypedef double ftype;\n\t\ttypedef complex point;\n\n\t\tpoint w[maxn];\n\t\tconst ftype pi = acos(-1);\n\t\tbool initiated = 0;\n\t\tvoid init() {\n\t\t\tif (!initiated) {\n\t\t\t\tfor (int i = 1; i < maxn; i *= 2) {\n\t\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\t\tw[i + j] = polar(ftype(1), pi * j / i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tinitiated = 1;\n\t\t\t}\n\t\t}\n\t\ttemplate\n\t\tvoid fft(T *in, point *out, int n, int k = 1) {\n\t\t\tif (n == 1) {\n\t\t\t\t*out = *in;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tn /= 2;\n\t\t\t\tfft(in, out, n, 2 * k);\n\t\t\t\tfft(in + k, out + n, n, 2 * k);\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tauto t = out[i + n] * w[i + n];\n\t\t\t\t\tout[i + n] = out[i] - t;\n\t\t\t\t\tout[i] += t;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttemplate\n\t\tvoid mul_slow(vector &a, const vector &b) {\n\t\t\tvector res(a.size() + b.size() - 1);\n\t\t\tfor (size_t i = 0; i < a.size(); i++) {\n\t\t\t\tfor (size_t j = 0; j < b.size(); j++) {\n\t\t\t\t\tres[i + j] += a[i] * b[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\ta = res;\n\t\t}\n\n\n\t\ttemplate\n\t\tvoid mul(vector &a, const vector &b) {\n\t\t\tif (min(a.size(), b.size()) < magic) {\n\t\t\t\tmul_slow(a, b);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tinit();\n\t\t\tstatic const int shift = 15, mask = (1 << shift) - 1;\n\t\t\tsize_t n = a.size() + b.size() - 1;\n\t\t\twhile (__builtin_popcount(n) != 1) {\n\t\t\t\tn++;\n\t\t\t}\n\t\t\ta.resize(n);\n\t\t\tstatic point A[maxn], B[maxn];\n\t\t\tstatic point C[maxn], D[maxn];\n\t\t\tfor (size_t i = 0; i < n; i++) {\n\t\t\t\tA[i] = point(a[i] & mask, a[i] >> shift);\n\t\t\t\tif (i < b.size()) {\n\t\t\t\t\tB[i] = point(b[i] & mask, b[i] >> shift);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tB[i] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfft(A, C, n); fft(B, D, n);\n\t\t\tfor (size_t i = 0; i < n; i++) {\n\t\t\t\tpoint c0 = C[i] + conj(C[(n - i) % n]);\n\t\t\t\tpoint c1 = C[i] - conj(C[(n - i) % n]);\n\t\t\t\tpoint d0 = D[i] + conj(D[(n - i) % n]);\n\t\t\t\tpoint d1 = D[i] - conj(D[(n - i) % n]);\n\t\t\t\tA[i] = c0 * d0 - point(0, 1) * c1 * d1;\n\t\t\t\tB[i] = c0 * d1 + d0 * c1;\n\t\t\t}\n\t\t\tfft(A, C, n); fft(B, D, n);\n\t\t\treverse(C + 1, C + n);\n\t\t\treverse(D + 1, D + n);\n\t\t\tint t = 4 * n;\n\t\t\tfor (size_t i = 0; i < n; i++) {\n\t\t\t\tint64_t A0 = llround(real(C[i]) / t);\n\t\t\t\tT A1 = llround(imag(D[i]) / t);\n\t\t\t\tT A2 = llround(imag(C[i]) / t);\n\t\t\t\ta[i] = A0 + (A1 << shift) + (A2 << 2 * shift);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n\ttemplate\n\tT bpow(T x, size_t n) {\n\t\treturn n ? n % 2 ? x * bpow(x, n - 1) : bpow(x * x, n / 2) : T(1);\n\t}\n\ttemplate\n\tT bpow(T x, size_t n, T m) {\n\t\treturn n ? n % 2 ? x * bpow(x, n - 1, m) % m : bpow(x * x % m, n / 2, m) : T(1);\n\t}\n\ttemplate\n\tT gcd(const T &a, const T &b) {\n\t\treturn b == T(0) ? a : gcd(b, a % b);\n\t}\n\ttemplate\n\tT nCr(T n, int r) { // runs in O(r)\n\t\tT res(1);\n\t\tfor (int i = 0; i < r; i++) {\n\t\t\tres *= (n - T(i));\n\t\t\tres /= (i + 1);\n\t\t}\n\t\treturn res;\n\t}\n\n\ttemplate\n\tstruct modular {\n\t\tint64_t r;\n\t\tmodular() : r(0) {}\n\t\tmodular(int64_t rr) : r(rr) { if (abs(r) >= m) r %= m; if (r < 0) r += m; }\n\t\tmodular inv() const { return bpow(*this, m - 2); }\n\t\tmodular operator * (const modular &t) const { return (r * t.r) % m; }\n\t\tmodular operator / (const modular &t) const { return *this * t.inv(); }\n\t\tmodular operator += (const modular &t) { r += t.r; if (r >= m) r -= m; return *this; }\n\t\tmodular operator -= (const modular &t) { r -= t.r; if (r < 0) r += m; return *this; }\n\t\tmodular operator + (const modular &t) const { return modular(*this) += t; }\n\t\tmodular operator - (const modular &t) const { return modular(*this) -= t; }\n\t\tmodular operator *= (const modular &t) { return *this = *this * t; }\n\t\tmodular operator /= (const modular &t) { return *this = *this / t; }\n\n\t\tbool operator == (const modular &t) const { return r == t.r; }\n\t\tbool operator != (const modular &t) const { return r != t.r; }\n\n\t\toperator int64_t() const { return r; }\n\t};\n\ttemplate\n\tistream& operator >> (istream &in, modular &x) {\n\t\treturn in >> x.r;\n\t}\n\n\n\ttemplate\n\tstruct poly {\n\t\tvector a;\n\n\t\tvoid normalize() { // get rid of leading zeroes\n\t\t\twhile (!a.empty() && a.back() == T(0)) {\n\t\t\t\ta.pop_back();\n\t\t\t}\n\t\t}\n\n\t\tpoly() {}\n\t\tpoly(T a0) : a{ a0 } { normalize(); }\n\t\tpoly(vector t) : a(t) { normalize(); }\n\n\t\tpoly operator += (const poly &t) {\n\t\t\ta.resize(max(a.size(), t.a.size()));\n\t\t\tfor (size_t i = 0; i < t.a.size(); i++) {\n\t\t\t\ta[i] += t.a[i];\n\t\t\t}\n\t\t\tnormalize();\n\t\t\treturn *this;\n\t\t}\n\t\tpoly operator -= (const poly &t) {\n\t\t\ta.resize(max(a.size(), t.a.size()));\n\t\t\tfor (size_t i = 0; i < t.a.size(); i++) {\n\t\t\t\ta[i] -= t.a[i];\n\t\t\t}\n\t\t\tnormalize();\n\t\t\treturn *this;\n\t\t}\n\t\tpoly operator + (const poly &t) const { return poly(*this) += t; }\n\t\tpoly operator - (const poly &t) const { return poly(*this) -= t; }\n\n\t\tpoly mod_xk(size_t k) const { // get same polynomial mod x^k\n\t\t\tk = min(k, a.size());\n\t\t\treturn vector(begin(a), begin(a) + k);\n\t\t}\n\t\tpoly mul_xk(size_t k) const { // multiply by x^k\n\t\t\tpoly res(*this);\n\t\t\tres.a.insert(begin(res.a), k, 0);\n\t\t\treturn res;\n\t\t}\n\t\tpoly div_xk(size_t k) const { // divide by x^k, dropping coefficients\n\t\t\tk = min(k, a.size());\n\t\t\treturn vector(begin(a) + k, end(a));\n\t\t}\n\t\tpoly substr(size_t l, size_t r) const { // return mod_xk(r).div_xk(l)\n\t\t\tl = min(l, a.size());\n\t\t\tr = min(r, a.size());\n\t\t\treturn vector(begin(a) + l, begin(a) + r);\n\t\t}\n\t\tpoly inv(size_t n) const { // get inverse series mod x^n\n\t\t\tassert(!is_zero());\n\t\t\tpoly ans = a[0].inv();\n\t\t\tsize_t a = 1;\n\t\t\twhile (a < n) {\n\t\t\t\tpoly C = (ans * mod_xk(2 * a)).substr(a, 2 * a);\n\t\t\t\tans -= (ans * C).mod_xk(a).mul_xk(a);\n\t\t\t\ta *= 2;\n\t\t\t}\n\t\t\treturn ans.mod_xk(n);\n\t\t}\n\n\t\tpoly operator *= (const poly &t) { fft::mul(a, t.a); normalize(); return *this; }\n\t\tpoly operator * (const poly &t) const { return poly(*this) *= t; }\n\n\t\tpoly reverse(size_t n, bool rev = 0) const { // reverses and leaves only n terms\n\t\t\tpoly res(*this);\n\t\t\tif (rev) { // If rev = 1 then tail goes to head\n\t\t\t\tres.a.resize(max(n, res.a.size()));\n\t\t\t}\n\t\t\tstd::reverse(res.a.begin(), res.a.end());\n\t\t\treturn res.mod_xk(n);\n\t\t}\n\n\t\tpair divmod_slow(const poly &b) const { // when divisor or quotient is small\n\t\t\tvector A(a);\n\t\t\tvector res;\n\t\t\twhile (A.size() >= b.a.size()) {\n\t\t\t\tres.push_back(A.back() / b.a.back());\n\t\t\t\tif (res.back() != T(0)) {\n\t\t\t\t\tfor (size_t i = 0; i < b.a.size(); i++) {\n\t\t\t\t\t\tA[A.size() - i - 1] -= res.back() * b.a[b.a.size() - i - 1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tA.pop_back();\n\t\t\t}\n\t\t\tstd::reverse(begin(res), end(res));\n\t\t\treturn { res, A };\n\t\t}\n\n\t\tpair divmod(const poly &b) const { // returns quotiend and remainder of a mod b\n\t\t\tif (deg() < b.deg()) {\n\t\t\t\treturn { poly{ 0 }, *this };\n\t\t\t}\n\t\t\tint d = deg() - b.deg();\n\t\t\tif (min(d, b.deg()) < magic) {\n\t\t\t\treturn divmod_slow(b);\n\t\t\t}\n\t\t\tpoly D = (reverse(d + 1) * b.reverse(d + 1).inv(d + 1)).mod_xk(d + 1).reverse(d + 1, 1);\n\t\t\treturn { D, *this - D * b };\n\t\t}\n\n\t\tpoly operator / (const poly &t) const { return divmod(t).first; }\n\t\tpoly operator % (const poly &t) const { return divmod(t).second; }\n\t\tpoly operator /= (const poly &t) { return *this = divmod(t).first; }\n\t\tpoly operator %= (const poly &t) { return *this = divmod(t).second; }\n\t\tpoly operator *= (const T &x) {\n\t\t\tfor (auto &it : a) {\n\t\t\t\tit *= x;\n\t\t\t}\n\t\t\tnormalize();\n\t\t\treturn *this;\n\t\t}\n\t\tpoly operator /= (const T &x) {\n\t\t\tfor (auto &it : a) {\n\t\t\t\tit /= x;\n\t\t\t}\n\t\t\tnormalize();\n\t\t\treturn *this;\n\t\t}\n\t\tpoly operator * (const T &x) const { return poly(*this) *= x; }\n\t\tpoly operator / (const T &x) const { return poly(*this) /= x; }\n\n\t\tvoid print() const {\n\t\t\tfor (auto it : a) {\n\t\t\t\tcout << it << ' ';\n\t\t\t}\n\t\t\tcout << endl;\n\t\t}\n\t\tT eval(T x) const { // evaluates in single point x\n\t\t\tT res(0);\n\t\t\tfor (int i = int(a.size()) - 1; i >= 0; i--) {\n\t\t\t\tres *= x;\n\t\t\t\tres += a[i];\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tT& lead() { // leading coefficient\n\t\t\treturn a.back();\n\t\t}\n\t\tint deg() const { // degree\n\t\t\treturn a.empty() ? -inf : a.size() - 1;\n\t\t}\n\t\tbool is_zero() const { // is polynomial zero\n\t\t\treturn a.empty();\n\t\t}\n\t\tT operator [](int idx) const {\n\t\t\treturn idx >= (int)a.size() || idx < 0 ? T(0) : a[idx];\n\t\t}\n\n\t\tT& coef(size_t idx) { // mutable reference at coefficient\n\t\t\treturn a[idx];\n\t\t}\n\t\tbool operator == (const poly &t) const { return a == t.a; }\n\t\tbool operator != (const poly &t) const { return a != t.a; }\n\n\t\tpoly deriv() { // calculate derivative\n\t\t\tvector res;\n\t\t\tfor (int i = 1; i <= deg(); i++) {\n\t\t\t\tres.push_back(T(i) * a[i]);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tpoly integr() { // calculate integral with C = 0\n\t\t\tvector res = { 0 };\n\t\t\tfor (int i = 0; i <= deg(); i++) {\n\t\t\t\tres.push_back(a[i] / T(i + 1));\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tsize_t leading_xk() const { // Let p(x) = x^k * t(x), return k\n\t\t\tif (is_zero()) {\n\t\t\t\treturn inf;\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\twhile (a[res] == T(0)) {\n\t\t\t\tres++;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tpoly log(size_t n) { // calculate log p(x) mod x^n\n\t\t\tassert(a[0] == T(1));\n\t\t\treturn (deriv().mod_xk(n) * inv(n)).integr().mod_xk(n);\n\t\t}\n\t\tpoly exp(size_t n) { // calculate exp p(x) mod x^n\n\t\t\tif (is_zero()) {\n\t\t\t\treturn T(1);\n\t\t\t}\n\t\t\tassert(a[0] == T(0));\n\t\t\tpoly ans = T(1);\n\t\t\tsize_t a = 1;\n\t\t\twhile (a < n) {\n\t\t\t\tpoly C = ans.log(2 * a).div_xk(a) - substr(a, 2 * a);\n\t\t\t\tans -= (ans * C).mod_xk(a).mul_xk(a);\n\t\t\t\ta *= 2;\n\t\t\t}\n\t\t\treturn ans.mod_xk(n);\n\n\t\t}\n\t\tpoly pow_slow(size_t k, size_t n) { // if k is small\n\t\t\treturn k ? k % 2 ? (*this * pow_slow(k - 1, n)).mod_xk(n) : (*this * *this).mod_xk(n).pow_slow(k / 2, n) : T(1);\n\t\t}\n\t\tpoly pow(size_t k, size_t n) { // calculate p^k(n) mod x^n\n\t\t\tif (is_zero()) {\n\t\t\t\treturn *this;\n\t\t\t}\n\t\t\tif (k < magic) {\n\t\t\t\treturn pow_slow(k, n);\n\t\t\t}\n\t\t\tint i = leading_xk();\n\t\t\tT j = a[i];\n\t\t\tpoly t = div_xk(i) / j;\n\t\t\treturn bpow(j, k) * (t.log(n) * T(k)).exp(n).mul_xk(i * k).mod_xk(n);\n\t\t}\n\t\tpoly mulx(T x) { // component-wise multiplication with x^k\n\t\t\tT cur = 1;\n\t\t\tpoly res(*this);\n\t\t\tfor (int i = 0; i <= deg(); i++) {\n\t\t\t\tres.coef(i) *= cur;\n\t\t\t\tcur *= x;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tpoly mulx_sq(T x) { // component-wise multiplication with x^{k^2}\n\t\t\tT cur = x;\n\t\t\tT total = 1;\n\t\t\tT xx = x * x;\n\t\t\tpoly res(*this);\n\t\t\tfor (int i = 0; i <= deg(); i++) {\n\t\t\t\tres.coef(i) *= total;\n\t\t\t\ttotal *= cur;\n\t\t\t\tcur *= xx;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tvector chirpz_even(T z, int n) { // P(1), P(z^2), P(z^4), ..., P(z^2(n-1))\n\t\t\tint m = deg();\n\t\t\tif (is_zero()) {\n\t\t\t\treturn vector(n, 0);\n\t\t\t}\n\t\t\tvector vv(m + n);\n\t\t\tT zi = z.inv();\n\t\t\tT zz = zi * zi;\n\t\t\tT cur = zi;\n\t\t\tT total = 1;\n\t\t\tfor (int i = 0; i <= max(n - 1, m); i++) {\n\t\t\t\tif (i <= m) { vv[m - i] = total; }\n\t\t\t\tif (i < n) { vv[m + i] = total; }\n\t\t\t\ttotal *= cur;\n\t\t\t\tcur *= zz;\n\t\t\t}\n\t\t\tpoly w = (mulx_sq(z) * vv).substr(m, m + n).mulx_sq(z);\n\t\t\tvector res(n);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tres[i] = w[i];\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tvector chirpz(T z, int n) { // P(1), P(z), P(z^2), ..., P(z^(n-1))\n\t\t\tauto even = chirpz_even(z, (n + 1) / 2);\n\t\t\tauto odd = mulx(z).chirpz_even(z, n / 2);\n\t\t\tvector ans(n);\n\t\t\tfor (int i = 0; i < n / 2; i++) {\n\t\t\t\tans[2 * i] = even[i];\n\t\t\t\tans[2 * i + 1] = odd[i];\n\t\t\t}\n\t\t\tif (n % 2 == 1) {\n\t\t\t\tans[n - 1] = even.back();\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t\ttemplate\n\t\tvector eval(vector &tree, int v, iter l, iter r) { // auxiliary evaluation function\n\t\t\tif (r - l == 1) {\n\t\t\t\treturn { eval(*l) };\n\t\t\t}\n\t\t\telse {\n\t\t\t\tauto m = l + (r - l) / 2;\n\t\t\t\tauto A = (*this % tree[2 * v]).eval(tree, 2 * v, l, m);\n\t\t\t\tauto B = (*this % tree[2 * v + 1]).eval(tree, 2 * v + 1, m, r);\n\t\t\t\tA.insert(end(A), begin(B), end(B));\n\t\t\t\treturn A;\n\t\t\t}\n\t\t}\n\t\tvector eval(vector x) { // evaluate polynomial in (x1, ..., xn)\n\t\t\tint n = x.size();\n\t\t\tif (is_zero()) {\n\t\t\t\treturn vector(n, T(0));\n\t\t\t}\n\t\t\tvector tree(4 * n);\n\t\t\tbuild(tree, 1, begin(x), end(x));\n\t\t\treturn eval(tree, 1, begin(x), end(x));\n\t\t}\n\t\ttemplate\n\t\tpoly inter(vector &tree, int v, iter l, iter r, iter ly, iter ry) { // auxiliary interpolation function\n\t\t\tif (r - l == 1) {\n\t\t\t\treturn { *ly / a[0] };\n\t\t\t}\n\t\t\telse {\n\t\t\t\tauto m = l + (r - l) / 2;\n\t\t\t\tauto my = ly + (ry - ly) / 2;\n\t\t\t\tauto A = (*this % tree[2 * v]).inter(tree, 2 * v, l, m, ly, my);\n\t\t\t\tauto B = (*this % tree[2 * v + 1]).inter(tree, 2 * v + 1, m, r, my, ry);\n\t\t\t\treturn A * tree[2 * v + 1] + B * tree[2 * v];\n\t\t\t}\n\t\t}\n\t};\n\ttemplate\n\tpoly operator * (const T& a, const poly& b) {\n\t\treturn b * a;\n\t}\n\n\ttemplate\n\tpoly xk(int k) { // return x^k\n\t\treturn poly{1}.mul_xk(k);\n\t}\n\n\ttemplate\n\tT resultant(poly a, poly b) { // computes resultant of a and b\n\t\tif (b.is_zero()) {\n\t\t\treturn 0;\n\t\t}\n\t\telse if (b.deg() == 0) {\n\t\t\treturn bpow(b.lead(), a.deg());\n\t\t}\n\t\telse {\n\t\t\tint pw = a.deg();\n\t\t\ta %= b;\n\t\t\tpw -= a.deg();\n\t\t\tT mul = bpow(b.lead(), pw) * T((b.deg() & a.deg() & 1) ? -1 : 1);\n\t\t\tT ans = resultant(b, a);\n\t\t\treturn ans * mul;\n\t\t}\n\t}\n\ttemplate\n\tpoly kmul(iter L, iter R) { // computes (x-a1)(x-a2)...(x-an) without building tree\n\t\tif (R - L == 1) {\n\t\t\treturn vector{-*L, 1};\n\t\t}\n\t\telse {\n\t\t\titer M = L + (R - L) / 2;\n\t\t\treturn kmul(L, M) * kmul(M, R);\n\t\t}\n\t}\n\ttemplate\n\tpoly build(vector> &res, int v, iter L, iter R) { // builds evaluation tree for (x-a1)(x-a2)...(x-an)\n\t\tif (R - L == 1) {\n\t\t\treturn res[v] = vector{ -*L, 1 };\n\t\t}\n\t\telse {\n\t\t\titer M = L + (R - L) / 2;\n\t\t\treturn res[v] = build(res, 2 * v, L, M) * build(res, 2 * v + 1, M, R);\n\t\t}\n\t}\n\ttemplate\n\tpoly inter(vector x, vector y) { // interpolates minimum polynomial from (xi, yi) pairs\n\t\tint n = x.size();\n\t\tvector> tree(4 * n);\n\t\treturn build(tree, 1, begin(x), end(x)).deriv().inter(tree, 1, begin(x), end(x), begin(y), end(y));\n\t}\n}\nusing namespace algebra;\nusing Mint = modular<998244353>;\nconst int mxN = 2e6+5;\nMint fac[mxN] = {1};\nint main() {\n\tios::sync_with_stdio(0); \n\tcin.tie(0); cout.tie(0);\n\trep(i, 1, mxN) fac[i] = fac[i-1] * (Mint)i;\n\tint n, k;\n\tcin >> n >> k;\n\tif (k >= n) {\n\t\tstd::cout << 0 << \"\\n\";\n\t\treturn 0;\n\t}\n\tauto C = [&](int n, int m) {\n\t\treturn fac[n] / fac[m] / fac[n - m];\n\t};\n\tMint ans = 0;\n\tfor (int i = 0; i <= n - k; ++i)\n\t\tans += Mint((n - k - i) % 2 == 0 ? 1 : -1) * C(n - k, i) * bpow(Mint(i), n);\n\tstd::cout << Mint(1 + (k > 0)) * ans * C(n, n - k) << \"\\n\";\n}\n\n\n", "lang_cluster": "C++", "tags": ["math", "combinatorics", "fft"], "code_uid": "3c1638298e1e3db4c0fcd2d432b062fe", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include\nusing namespace std;\nint main()\n{\n long long n,m,s=0;\n cin>>n>>m;\n while(n>0 && m>0)\n {\n if(n==1 && m==1)\n {\n break;\n }\n else if(n\n\nusing namespace std;\n\n\n#define ff\t\t\t\tfirst\n#define ss\t\t\t\tsecond\n#define int\t\t\t\tlong long\n#define pb\t\t\t\tpush_back\n#define mp\t\t\t\tmake_pair\n#define pii\t\t\t\tpair\n#define vi\t\t\t\tvector\n#define mii \t\t\tmap\n#define\tpqb\t\t\t\tpriority_queue\n#define pqs\t\t\t\tpriority_queue >\n#define setbits(x)\t\t__builtin_popcountll(x)\n#define zrobits(x)\t\t__builtin_ctzll(x)\n#define mod\t\t\t\t1000000009\n#define inf \t\t\t1e18\n#define ps(x,y)\t\t\tfixed<>x; while(x--)\n#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)\n#define endl\t\t\t'\\n'\n#define yes cout<<\"YES\"< Sieve(int n)\n{\n\tbool prime[n + 1];\n\tmemset(prime, true, sizeof(prime));\n\tfor (int i = 2; i * i <= n; i++)\n\t{\n\t\tif (prime[i])\n\t\t{\n\t\t\tfor (int j = i * i; j <= n; j += i)\n\t\t\t{\n\t\t\t\tprime[j] = false;\n\t\t\t}\n\t\t}\n\t}\n\tvector primes;\n\n\tfor (int i = 2; i <= n; i++)\n\t{\n\t\tif (prime[i])\n\t\t\tprimes.pb(i);\n\t}\n\treturn primes;\n}\nset primeFactors(int n)\n{\n\tset factors;\n\twhile (n % 2 == 0)\n\t{\n\t\tn /= 2;\n\t\tfactors.insert(2);\n\n\t}\n\tfor (int i = 3; i <= sqrt(n); i += 2)\n\t{\n\t\t// int count = 0;\n\t\twhile (n % i == 0)\n\t\t{\n\t\t\tfactors.insert(i);\n\t\t\tn /= i;\n\t\t}\n\t}\n\tif (n > 2)\n\t\tfactors.insert(n);\n\treturn factors;\n}\n\nint power(int x, unsigned int y, int p)\n{\n\tint res = 1;\n\n\tx = x % p;\n\n\tif (x == 0) return 0;\n\t;\n\twhile (y > 0)\n\t{\n\n\t\tif (y & 1)\n\t\t\tres = (res * x) % p;\n\n\t\ty = y >> 1; // y = y/2\n\t\tx = (x * x) % p;\n\t}\n\treturn res;\n\n}\n\n\n// Graph------------------------------------------------------------------------\n\n\nint32_t main()\n{\n\t// FIO;\n\tc_p_c();\n\t// --------------------------------------------------\n\t// Never GIVE UP !!!!\n\n\tint n, m;\n\tcin >> n >> m;\n\tint pw = power(2, m, mod) ;\n\tint ans = 1;\n\tfor (int i = 1; i <= n; i++)\n\t{\n\n\t\tans = ((ans % mod) * ((pw - i) % mod)) % mod;\n\t}\n\tcout << ans << endl;\n}", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "686f01af5f1b21f70d1371d5333ce23f", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);\nmt19937 rng(chrono::steady_clock::now().time_since_epoch().count());\n#define tofile freopen(\"input.txt\",\"r\",stdin); freopen(\"output.txt\",\"w\",stdout); \n#define M 1000000007\n#define INF 999999999999999999\n#define ll long long\n#define db double\n#define pb push_back\n#define all(x) x.begin(),x.end()\n#define fi first\n#define se second\n#define vl vector\n#define vvl vector\n#define pii pair\n#define mkp make_pair\n\nll oper(ll x, ll y, char op){\n\tif(op=='+') return x+y;\n\telse return x*y;\n}\n\nint main()\n{\n\tvector a(4);\n\tfor(int i=0;i<4;i++) cin >> a[i];\n\t\n\tvector c(3);\n\tfor(int i=0;i<3;i++) cin >> c[i];\n\t\n\tll ans=INF;\n\t\n\tsort(all(a));\n\t\n\tdo{\n\t\tll temp1 = oper( oper(a[0],a[1],c[0]),oper(a[2],a[3],c[1]),c[2] );\n\t\tll temp2 = oper( oper(oper(a[0],a[1],c[0]),a[2],c[1]),a[3],c[2] );\n\t\tans=min(ans,min(temp1,temp2)); \n\t\t//for(auto x:a) cout << x << \" \";\n\t\t//cout << endl;\n\t}while(next_permutation(all(a)));\n\t\n\tcout << ans << endl;\n\t\n}", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "4be2f6891a8245cab8e0d5895e8a6ebd", "src_uid": "7a66fae63d9b27e444d84447012e484c", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std; \n\ntypedef long long ll; \ntypedef pair pii;\n\n#define INF 1000000000\n#define pb push_back \n#define itr iterator \n#define sz size() \n#define mp make_pair\nbool soma (ll num,ll res){\n\tll rest = 0;\n\twhile(num){\n\t\trest+=(num%10);\n\t\tnum/=10;\n\t}\n\tif(res == rest)return true;\n\treturn false;\n}\nint main(){\n\tll a,b,c;\n\tcin >> a >> b >> c;\n\tvector xi;\n\tfor(ll i = 1;i < 82;i++){\n\t\tll resp = 1;\n\t\tfor(int i1 = 0;i1 0)\t\n\t\t\tif(soma(num,i))xi.pb(num);\n\t}\n\tsort(xi.begin(),xi.end());\n\tcout << xi.size() << endl;\n\tfor(ll i = 0;i < xi.size();i++){\n\t\t//cout << xi[i] << \" \";\n\t\tprintf(\"%lli%c\",xi[i],\" \\n\"[i==(int)xi.size()-1]);\n\t}\n\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "e3b081e2b94c5d68446500023bc56ae4", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#define INF 0x3f3f3f3f\nusing namespace std;\nint main()\n{\n int n,i,j,k,l,a,b,c,x,y,m;\n while(~scanf(\"%d %d %d %d %d\",&n,&a,&x,&b,&y))\n {\n for(i=0; i<200; i++)\n {\n if(a==n)\n a=1;\n else\n a++;\n if(b==1)\n b=n;\n else\n b--;\n if(a==b)\n {\n c=1;\n cout<<\"YES\";\n break;\n }\n if(a==x)\n {\n c=0;\n break;\n }\n if(b==y)\n {\n c=0;\n break;\n }\n }\n if(c==0)\n cout<<\"NO\"<\nusing namespace std;\nconst int inf = 0x3f3f3f3f;\nconst int N = (int)1e7 + 15;\n\nint s1[N];\nbool s2[N];\n\nint main() {\n int a, b, mod;\n cin >> a >> b >> mod;\n memset(s1, -1, sizeof(s1));\n memset(s2, false, sizeof(s2));\n for(int i = 0; i <= a; i++) {\n int t = i * 1000000000LL % mod;\n if(s1[t] != -1) {\n break;\n }\n s1[t] = i;\n }\n\n int ans = inf;\n for(int i = 0; i < min(mod, b + 1); i++) {\n s2[(mod - i) % mod] = true;\n }\n\n for(int i = 0; i < mod; i++) {\n if(s1[i] != -1 && s2[i] == false) {\n ans = min(ans, s1[i]);\n }\n }\n if(ans == inf) {\n puts(\"2\");\n } else {\n printf(\"1 %09d\\n\", ans);\n }\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "number theory"], "code_uid": "1a16b23a4d9e1a69103d374e5581cbbf", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define up(j,k,i) for(ll i=j;ik;i--)\n#define M 1000000007\n#define pp(n) printf(\"%lld\\n\",ll(n))\n#define ps(n) printf(\"%lld \",ll(n))\n#define pd(x,y) printf(\"%lld %lld\\n\",ll(x),ll(y))\n#define is(n) scanf(\"%lld\",&n)\n#define inf 1e12\n#define id(n,m) scanf(\"%lld%lld\",&n,&m)\n#define it(n,m,k) scanf(\"%lld%lld%lld\",&n,&m,&k)\n#define pb push_back\n#define F first\n#define S second\n#define pll pair \n#define db cout<<\"######\\n\"\n#define null(a) memset(a,0,sizeof(a))\n#define neg(a) memset(a,255,sizeof(a))\ntypedef long double ld;\ntypedef long long int ll;\nusing namespace std;\nll i,j,k,z,t,n,m,sum,x,y,maxm=0,minm=inf; bool flag;\nll a;\nll timestamp[105]; \nll votes[105];\nvector< pair< pll, ll> > v;\nll ans[105];\nbool comp(pair< pll,ll> A, pair< pll,ll> B)\n{\n\tif(A.F.F B.F.F) return true;\n\telse if(A.F.F==B.F.F)\n\treturn A.F.S < B.F.S;\n\telse\n\treturn true;\n}\nint main()\n{\n\tit(n,k,m); is(a);\n\t\n\tup(1,n+1,i)\n\tans[i]=2;\n\t\n\tup(0,a,i)\n\t{\n\t\tis(x);\n\t\t\n\t\tvotes[x]++;\n\t\t\n\t\ttimestamp[x]=i;\n\t\t\n\t}\n\t\n\tup(1,n+1,i)\n\tv.push_back({{votes[i],timestamp[i]},i});\n\t\n\tsort(v.begin(),v.end(),comp);\n\t\n//\tfor(auto c:v)\n//\tpd(c.S,c.F.F);\n\t\n\tif(n==k)\n\t{\n\t\tup(0,n,i)\n\t\tif(v[i].F.F!=0)\n\t\tans[v[i].S]=1;\n\t\telse if(m > a)\n\t\tans[v[i].S] = 2;\n\t\telse\n\t\tans[v[i].S]=3;\n\t\t\n\t\t\n\t}\n\telse\n\tif(m==a)\n\t{\n\t\tup(0,k,i)\n\t\tif(v[i].F.F!=0)\n\t\tans[v[i].S]=1;\n\t\telse\n\t\tans[v[i].S]=3;\n\t\t\n\t\tup(k,n,i)\n\t\tans[v[i].S]=3;\n\t\t\n\t}\n\telse\n\t{\n\t\tll lmt=v[k-1].F.F;\n\t\n\t\tup(k,n,i)\n\t\t{\n\t\t\tif(v[i].F.F+m-a <= lmt)\n\t\t\tans[v[i].S] = 3;\n\t\t}\n\t\t\n\t\tup(0,k,i)\n\t\t{\n\t\t\tif(v[i].F.F == 0) ans[v[i].S] = 2;\n\t\t\telse{\n\t\t\t\tsum=0;\n\t\t\n\t\t\t\tup(i+1,k+1,j)\n\t\t\t\tsum+=(v[i].F.F+1-v[j].F.F);\n\t\t\t\n\t\t\t\tif(sum>m-a)\n\t\t\t\tans[v[i].S]=1;\n\t\t\t}\n\t\t}\n\t\n\t}\n\t\n\tup(1,n+1,i) cout << ans[i] << \" \"; cout << endl;\n\t\n}", "lang_cluster": "C++", "tags": ["sortings", "greedy"], "code_uid": "28a16f2df6db9aa443c9bc38aca561c7", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\ntypedef long long ll;\nusing namespace std;\nint main(){\n\tll n;\tcin>>n;\n\tll cnt=1;\n\tfor(ll i=2;i*i<=n;i++){\n\t\tif(n%i==0){\n\t\t\tcnt+=(n-i)/2;\n\t\t\tbreak;\n\t\t}\n\t}\n\tcout<\n\nusing namespace std;\n\nint main()\n{\n\n std::vector avoid,avoid1;\n std::vector::iterator it,it1,jt,jt1;\n int ans1=0,ans2=0;\n\n string pawn[8];\n for(int i=0;i<8;i++)\n {\n cin>>pawn[i];\n }\n\n for(int i=0;i=0;i--)\n {\n unsigned int j=0;\n while(j\n #include \n #include\n #include\n using namespace std;\n int main ()\n {\n int k,f=0,b[10]={};\n char a;\n cin>>k;\n for(int i=0;i<16;i++)\n {\n cin>>a;\n if(a!='.')\n b[int(a)-48]++;\n }\n for(int i=1;i<10;i++)\n {\n if(b[i]>(k*2))\n f=1;\n }\n if(f==1)\n cout<<\"NO\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#if __cplusplus > 201103L\n#include \n#include \n#include \n#endif\n\nusing namespace std;\n\n#ifdef LOCAL\n#define DEBUG\n#endif\n\n#define oo 0x3F3F3F3F\n#define fst first\n#define snd second\n#define PB push_back\n#define SZ(x) (int)((x).size())\n#define ALL(x) (x).begin(), (x).end()\n#define FOR(i, a, b) for (int _end_ = (b), i = (a); i <= _end_; ++i)\n#define ROF(i, a, b) for (int _end_ = (b), i = (a); i >= _end_; --i)\n\ntypedef unsigned int uint;\ntypedef long long int64;\ntypedef unsigned long long uint64;\ntypedef long double real;\n\nint64 fpm(int64 b, int64 e, int64 m) { int64 t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; }\ntemplate inline bool chkmin(T &a, T b) {return a > b ? a = b, true : false;}\ntemplate inline bool chkmax(T &a, T b) {return a < b ? a = b, true : false;}\ntemplate inline T sqr(T x) {return x * x;}\ntemplate T gcd(T x, T y) {for (T t; x; ) t = x, x = y % x, y = t; return y; }\n\ntemplate struct Graph {\n vector > adj;\n Graph(int n) {adj.clear(); adj.resize(n + 5);}\n Graph() {adj.clear(); }\n void resize(int n) {adj.resize(n + 5); }\n void add(int s, edge e){adj[s].push_back(e);}\n void del(int s, edge e) {adj[s].erase(find(iter(adj[s]), e)); }\n vector& operator [](int t) {return adj[t];}\n};\n\nconst int MOD = 1000000007;\n\nint64 f[40][40];\nmap, int64> G;\n\nint64 dfs(int K, int b, int t) {\n if (b < 0) return 0;\n auto p = make_pair(b, t);\n if (G.count(p)) return G[p];\n int64 ret = 0;\n if (K >> b & 1) {\n ret += dfs(K, b - 1, t + 1);\n ret += (1ll << t >> 1) % MOD * dfs(K, b - 1, t) % MOD;\n ret += (1ll << max(t - 1, 0)) % MOD * f[b][t] % MOD;\n } else \n ret += (1ll << max(t - 1, 0)) % MOD * dfs(K, b - 1, t) % MOD;\n return G[p] = ret % MOD;\n}\n\nint main(int argc, char **argv) {\n#ifdef LOCAL\n freopen(\"D.in\" , \"r\", stdin);\n freopen(\"D.out\", \"w\", stdout);\n#endif\n ios_base::sync_with_stdio(false);\n\n int K;\n cin >> K, ++K;\n for (int i = 0; i <= 31; ++i) {\n for (int j = 0; j <= 32; ++j) {\n if (i == 0) f[i][j] = 1;\n else (f[i][j] = f[i - 1][j + 1] + (1ll << j) % MOD * f[i - 1][j] % MOD) %= MOD;\n }\n }\n cout << dfs(K, 31, 0) << endl;\n\n return 0; \n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "f46aa98f3b1f8b56eb20e9b30e72c51a", "src_uid": "ead64d8e3134fa8f29881cb487e52f60", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nconst int MAX=1e5+10;\nconst int MOD=1e9+7;\ntypedef long long ll;\nchar s[210];\nll d[210][210][210];\nint f[210];\nint main()\n{\n int n;\n cin>>n;\n n*=2;\n scanf(\"%s\",s);\n int m=strlen(s);\n f[0]=f[1]=0;\n for(int i=1;i File Name: a.cpp\n > Author: flyasdfvcxz\n > Mail: liyuemingcn@gmail.com \n > Created Time: Fri Sep 11 20:55:07 2015\n ************************************************************************/\n\n#include\nusing namespace std;\nconst int mod = 1e9 + 7;\nconst int N = 2e6 + 10;\nlong long fac[N], inv[N];\nlong long calInv(long long a, long long b)\n{\n\tlong long ret = 1LL;\n\twhile (b)\n\t{\n\t\tif (b & 1) ret = ret * a % mod;\n\t\ta = a * a % mod;\n\t\tb >>= 1;\n\t}\n\treturn ret;\n}\nint main()\n{\n\tfac[0] = 1;\n\tfor (int i = 1; i < N; ++i) \n\t{\n\t\tfac[i] = fac[i - 1] * i % mod;\n\t\tinv[i] = calInv(fac[i], mod - 2);\n\t}\n\tlong long n;\n\tcin >> n;\n\tn++;\n\tlong long ans = 2LL * fac[2 * n - 1] % mod * inv[n] % mod * inv[n - 1] % mod + mod - 1; \n\tans %= mod;\n\tcout << ans << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["combinatorics", "number theory"], "code_uid": "83f568f8fc8314d06dd1ef9b8e5f24a6", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#define ll long long\n\nconst int MAXN =3020;\n\n/*------------------------------Monotone queue------------------------------*/\n\nint head, tail;\nint que[MAXN], t[MAXN];\n\nvoid push(const int &val, const int &tt){\n\twhile(head < tail && que[tail-1] >= val)\n\t\t--tail;\n\tque[tail] =val;\n\tt[tail++] =tt;\n}\n\nvoid modify(const int &pop_time){\n//\twhile(tail-head > len)\n\twhile(head < tail && t[head] > pop_time)\n\t\t++head;\n}\n\ninline int front(){\n\tif(head < tail)\n\t\treturn que[head];\n\telse\n\t\treturn 0;\n}\n\n/*------------------------------Array------------------------------*/\n\nint map[MAXN][MAXN];\n\nint down[MAXN][MAXN];/*\ufffd\ufffd\ufffd\ufffd b \ufffd\ufffd ( \ufffd\ufffd ) \ufffd\ufffd\ufffd\ufffd\u0421\u05b5*/\n\n/*------------------------------Main------------------------------*/\n\nint G[MAXN*MAXN];\n\nint main(){\n\tint n, m, a, b;\n\tint g, x, y, z;\n\tscanf(\"%d%d%d%d%d%d%d%d\", &n, &m, &a, &b, &g, &x, &y, &z);\n\tG[0] =g;\n\tfor(int i =1; i < n*m; ++i)\n\t\tG[i] =(1ll*G[i-1]*x%z+y)%z;\n\tfor(int i =0; i < n; ++i)\n\t\tfor(int j =0; j < m; ++j)\n\t\t\tmap[i][j] =G[i*m+j];\n\t\n\tfor(int j =0; j < m; ++j){\n\t//\tif(j+b-1 < m){\n\t\thead =tail =0;\n\t\tfor(int i =n-1; i >= 0; --i){\n\t\t\tpush(map[i][j], i);\n\t\t\tmodify(i+a-1);\n\t\t\tif(i+a-1 < n)\n\t\t\t\tdown[i][j] =front();\n\t\t//\telse\n\t\t//\t\tdown[i][j] =0x3f3f3f3f;/*<<- ?*/\n\t\t}\n\t}\n\t\n\tll ans =0;\n\tfor(int i =0; i < n; ++i)\n\t\tif(i+a-1 < n){/*<<- */\n\t\t\thead =tail =0;\n\t\t\tfor(int j =m-1; j >= 0; --j){\n\t\t\t\tpush(down[i][j], j);\n\t\t\t\tmodify(j+b-1);\n\t\t\t//\tif(i+b-1 < n)\n\t\t\t\tif(j+b-1 < m)\n\t\t\t\t\tans +=front();\n\t\t\t}\n\t\t}\n\t\n\tprintf(\"%lld\", ans);\n}\n", "lang_cluster": "C++", "tags": ["two pointers", "data structures"], "code_uid": "d0dfb96e0412828620f8f95f05f39bba", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#define ffr(i,a,b) for(i=a;i\n#define plolo pair\n#define mm(a,b) memset(a,b,sizeof(a))\n#define pf printf\n \nusing namespace std;\n \n \n \nint main()\n{\n ll n, m, rem, fol, ses, k, col;\n cin >> n >> m;\n cin >> k;\n \n if(k\n#include \n#include \n\n//#pragma comment(linker, \"/stack:200000000\")\n//#pragma GCC optimize(\"Ofast\")\n//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\n//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2,fma\")\n//#pragma GCC optimize(\"O3\")\n//#pragma GCC target(\"popcnt\")\n#pragma GCC optimize(\"unroll-loops\")\n\n\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\n#define ll long long\n#define ld double long\n#define pb push_back\n#define F first\n#define S second\n\n// CODE CODE CODE CODE CODE CODE CODE CODE CODE\n\n\n//mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());\n\nmt19937 gen(19937);\n\nsigned main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n#ifdef LOCAL\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#else\n// freopen(\"heavy.in\", \"r\", stdin);\n// freopen(\"heavy.out\", \"w\", stdout);\n#endif // LOCAL\n ld n, m;\n cin >> n >> m;\n if (n == m && n == 1){\n cout << 1 << endl;\n return 0;\n }\n cout << fixed << setprecision(10) << 1.0 * (1 / n) + ((n - 1) / n * (m - 1) / (n * m - 1)) << endl;\n return 0;\n}\n\n/* Thu Feb 27 2020 19:23:15 GMT+0300 (MSK) */\n", "lang_cluster": "C++", "tags": ["probabilities", "math", "combinatorics"], "code_uid": "0adc359c7346cb4e6a8804f52c24ebfe", "src_uid": "0b9ce20c36e53d4702869660cbb53317", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n int n1,n2,k1,k2;\n scanf(\"%d%d%d%d\",&n1,&n2,&k1,&k2);\n if(n1>n2)printf(\"First\");\n else printf(\"Second\");\n return 0;\n}\n\n ", "lang_cluster": "C++", "tags": ["math", "constructive algorithms"], "code_uid": "9642ddc6aeb30afbece2d4de80b62667", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \r\nusing namespace std;\r\n\r\n#define ll long long int\r\n#define FAST_IO ios_base::sync_with_stdio(false)\r\n#define debug(x) \\\r\n cout << #x << \": [ \"; \\\r\n for (auto &aa : x) \\\r\n cout << aa << \" \"; \\\r\n cout << \"]\\n\"\r\n#define debug1(x) cout << \"## \" << #x << \" : \" << x << \" ##\\n\"\r\n#define debug2(x, y) cout << \"## \" << #x << \" : \" << x << \" | \" << #y << \" : \" << y << \" ##\\n\"\r\n\r\nconst ll MOD = 1e9 + 7;\r\nconst ll MAXN = 2e5 + 10;\r\n\r\nvector fac(MAXN, 1);\r\nvector inv(MAXN, 1);\r\n\r\nll binPow(ll n, ll p)\r\n{\r\n if (p <= 0)\r\n {\r\n return 1;\r\n }\r\n\r\n ll term = binPow(n, p / 2);\r\n term *= term;\r\n\r\n term %= MOD;\r\n\r\n if (p % 2 == 1)\r\n {\r\n term *= n;\r\n term %= MOD;\r\n }\r\n\r\n return term;\r\n}\r\n\r\nvoid precalc()\r\n{\r\n for (ll i = 2; i < MAXN; i++)\r\n {\r\n fac[i] = fac[i - 1] * i;\r\n fac[i] %= MOD;\r\n\r\n inv[i] = binPow(fac[i], MOD - 2);\r\n }\r\n}\r\n\r\nll ncr(ll n, ll r)\r\n{\r\n ll nm = fac[n];\r\n ll dn = (inv[r] * inv[n - r]) % MOD;\r\n\r\n ll res = (nm * dn) % MOD;\r\n return res;\r\n}\r\n\r\nvoid solve()\r\n{\r\n ll n, k;\r\n cin >> n >> k;\r\n\r\n ll term = 0;\r\n for (ll i = 0; i < n; i += 2)\r\n {\r\n term = (term + ncr(n, i)) % MOD;\r\n }\r\n\r\n if (n % 2 == 1)\r\n {\r\n ll ans = 1 + term;\r\n ans %= MOD;\r\n\r\n cout << binPow(ans, k) << \"\\n\";\r\n return;\r\n }\r\n\r\n ll ans = 0;\r\n\r\n for (ll i = 0; i <= k; i++)\r\n {\r\n ll t1 = binPow(term, i);\r\n ll exp = n * (k - i - 1);\r\n\r\n ll t2 = binPow(2LL, exp);\r\n\r\n if (i < k - 1)\r\n {\r\n ll curr = (t1 * t2) % MOD;\r\n\r\n ans = (ans + curr) % MOD;\r\n }\r\n else\r\n {\r\n ans = (ans + t1) % MOD;\r\n }\r\n }\r\n\r\n cout << ans << \"\\n\";\r\n}\r\n\r\nint main()\r\n{\r\n\r\n#ifndef ONLINE_JUDGE\r\n freopen(\"input.txt\", \"r\", stdin);\r\n freopen(\"output.txt\", \"w\", stdout);\r\n#endif\r\n\r\n FAST_IO;\r\n\r\n precalc();\r\n\r\n int test;\r\n cin >> test;\r\n //test=1;\r\n\r\n while (test--)\r\n {\r\n solve();\r\n }\r\n\r\n return 0;\r\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "eb877fc9641e9324318b76a0c7feaa87", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nconst int mod=1e9+7;\nint power(int a, int b, int m, int ans=1) {\n\tfor (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;\n\treturn ans;\n}\nint main(){\n\tint n,m;\n\tscanf(\"%d%d\",&n,&m);\n\tif(m==1){\n\t\tprintf(\"%d\\n\",n+1);\n\t\treturn 0;\n\t}\n\tint ans=1LL*m*power(m-1,mod-2,mod)%mod*(power((2*m-1)%mod,n,mod)-power(m,n,mod)+mod)%mod;\n\tans=(ans+power(m,n,mod))%mod;\n\tprintf(\"%d\\n\",ans);\n}\n ", "lang_cluster": "C++", "tags": ["combinatorics"], "code_uid": "e10f24416938b714cc1ac7e7440ec5e1", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#define inf 0x3f3f3f3f\n#define mod 1000000007\nusing namespace std;\nint main()\n{\n int n;\n while(scanf(\"%d\",&n)!=EOF)\n {\n if(n==1)\n printf(\"1 0\\n\");\n else\n {\n long long ans=1;\n int num=0,m=n;\n int i,j;\n for(i=2;;i++)\n {\n if(m==1)\n break;\n if(m%i==0)\n ans*=i;\n while(m%i==0)\n {\n m/=i;\n }\n }\n long long x=ans;\n while(x%n)\n {\n x*=x;\n num++;\n }\n if(x>n)\n num++;\n printf(\"%d %d\\n\",(int)ans,(int)num);\n }\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy", "number theory"], "code_uid": "f4a468a06db880d79bb1bc1621b1b3d0", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "//zhr\n#include\nusing namespace std;\n\nint n,k;\nint x[16384],rest;\nint a,b,c;\n\nint main(){\n\tcin>>n>>k;\n\ta=n;\n\tb=2*n;\n\tint N;\n\tfor(int i=1;i<=k;++i){\n\t\tcin>>x[i];\n\t}\n\tfor(int i=1;i<=k;++i){\n\t\trest+=x[i]%2;\n\t\tx[i]=x[i]/2;\n\t}\n\tfor(int i=1;i<=k;++i){\n\t\tif(!a) break;\n\t\tN=min(a,x[i]/2);\n\t\ta-=N;\n\t\tx[i]-=N*2;\n\t}\n\tfor(int i=1;i<=k;++i){\n\t\tif(!a) break;\n\t\tN=min(a,x[i]);\n\t\ta-=N;\n\t\tx[i]-=N;\n\t\tc+=N;\n\t}\n\tN=min(a,rest/2);\n\ta-=N;\n\trest-=2*N;\n\tfor(int i=1;i<=k;++i){\n\t\tif(!b) break;\n\t\tN=min(b,x[i]);\n\t\tb-=N;\n\t\tx[i]-=N;\n\t}\n\tN=min(b,rest);\n\tb-=N;\n\trest-=N;\n\tfor(int i=1;i<=k;++i){\n\t\tif(!c) break;\n\t\tN=min(c,2*x[i]);\n\t\tc-=N;\n\t\tx[i]-=N/2;\n\t\tif(N%2==1) rest++;\n\t}\n\tN=min(c,rest);\n\tc-=N;\n\trest-=N;\n\tfor(int i=1;i<=k;++i){\n\t\tif(x[i]) {\n\t\t\tputs(\"NO\");\n\t\t\texit(0);\n\t\t}\n\t}\n\tif(rest) {\n\t\tputs(\"NO\");\n\t\texit(0);\n\t}\n\tputs(\"YES\");\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "greedy", "implementation"], "code_uid": "bdf38fd164c6eeeafb8365f225c40137", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n\n\nusing namespace std;\n\n\n\nint main()\n{\n\n int a, b, c;\n\n cin>>a>>b>>c;\n\n int count=0;\n\n while(a>1 && b>1 && c>1)\n {\n count = count + 2*(a-1) + 2*(b-1) + 2*(c-1);\n a--;b--;c--;\n }\n int ones = 0;\n if(a==1)ones++;\n if(b==1)ones++;\n if(c==1)ones++;\n\n if(ones==3)\n count++;\n else if(ones==2)\n {\n if(a!=1)count+=a;\n if(b!=1)count+=b;\n if(c!=1)count+=c;\n //count = count + a!=1?a:0 + b!=1?b:0 + c!=1?c:0;\n }\n else\n {\n if(a==1) count += (b)*(c);\n if(b==1) count += (a)*(c);\n if(c==1) count += (b)*(a);\n //count = count + 2*(a-1) + 2*(b-1) + 2*(c-1);\n }\n\n cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define ll long long\ninline ll read()\n{\n\tll ans = 0,op = 1;\n\tchar ch = getchar();\n\twhile(ch < '0' || ch >'9')\n\t{\n\t\tif(ch == '-') op = -1;\n\t\tch = getchar();\n\t}\n\twhile(ch >= '0' && ch <= '9')\n\t{\n\t\t(ans *= 10) += ch - '0';\n\t\tch = getchar();\n\t}\n\treturn ans * op;\n}\nconst int maxn = 1e6 + 10;\nconst int mod = 998244353;\nll power(ll a,ll b)\n{\n\tll ans = 1,res = a;\n\twhile(b)\n\t{\n\t\tif(b & 1) (ans *= res) %= mod;\n\t\t(res *= res) %= mod;\n\t\tb >>= 1;\n\t}\n\treturn ans;\n}\nll fac[maxn],inv[maxn];\nll n;\nll ans;\nll cal(ll n,ll m)\n{\n\treturn fac[n] * inv[m] % mod * inv[n - m] % mod;\n}\nint main()\n{\n\tn = read();\n\tfac[0] = inv[0] = 1;\n\tfor(int i = 1;i <= n;i++)\n\t{\n\t\tfac[i] = fac[i - 1] * i % mod;\n\t\tinv[i] = power(fac[i],mod - 2);\n\t}\n\tfor(int i = 1;i <= n;i++)\n\t\t(ans += (power(-1,i + 1) * cal(n,i) * power(3,n * (n - i) + i) + mod) % mod + mod) %= mod;\n\t(ans *= 2) %= mod;\n\tll res = 0;\n\tfor(int i = 0;i <= n - 1;i++)\n\t\tres = (res + power(-1,i + 1) * cal(n,i) * (power((1 - power(3,i)),n) - power(-power(3,i),n) + mod) % mod + mod) % mod;\n\t(ans += 3 * res) %= mod;\n\tprintf(\"%lld\",ans);\n}", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "620f241a6e97a7ea412623b30546c1a0", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "// High above the clouds there is a rainbow...\n\n#include\n\n#define F first\n#define S second\n#define PB push_back\n#define sz(s) int((s).size())\n#define bit(n,k) (((n)>>(k))&1)\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\n\nconst int maxn=55,maxs=2550,mod=1e9+7;\nconst ll inf=1e18;\n\nint dp[2][maxn][maxn][maxs], ddp[2][maxn][maxs];\nint dp2[maxn][maxn][maxn][3], sm[maxn][maxn][maxn];\n\ninline void add(int &a,int b){\n a=(a+b)%mod;\n}\n\nint main(){\n ios_base::sync_with_stdio(false);cin.tie(0);\n\n int n,t;cin>>n>>t;\n\n dp[0][0][0][0]=1;\n ddp[0][0][0]=1;\n \n for(int w=1;w<=n;w++){\n\tint o=w&1, O=1-o;\n\tint a,b; cin>>a>>b;\n\tfor(int i=0;i<=n;i++){\n\t for(int j=0;j<=n;j++){\n\t\tfor(int sm=0;sm<=t;sm++){\n\t\t dp[o][i][j][sm]= dp[O][i][j][sm];\n\t\t if(b==1 && i && sm>=a) add(dp[o][i][j][sm], dp[O][i-1][j][sm-a] );\n\t\t if(b==2 && j && sm>=a) add(dp[o][i][j][sm], dp[O][i][j-1][sm-a] );\n\t\t}\n\t }\n\t}\n\tfor(int k=0;k<=n;k++){\n\t for(int sm=0;sm<=t;sm++){\n\t\tddp[o][k][sm]= ddp[O][k][sm];\n\t\tif(b==3 && k && sm>=a) add(ddp[o][k][sm], ddp[O][k-1][sm-a] );\n\t }\n\t}\n }\n \n sm[0][0][0]=1;\n \n int ans=0;\n for(int i=0;i<=n;i++){\n\tfor(int j=0;j<=n;j++){\n\t for(int k=0;k<=n;k++){\n\t\tif(i+j+k<=1){\n\t\t dp2[1][0][0][0]=1;\n\t\t dp2[0][1][0][1]=1;\n\t\t dp2[0][0][1][2]=1;\n\t\t}\n\t\telse{\n\t\t if(i) dp2[i][j][k][0]= 1ll*i* (sm[i-1][j][k] - dp2[i-1][j][k][0]) %mod;\n\t\t if(j) dp2[i][j][k][1]= 1ll*j* (sm[i][j-1][k] - dp2[i][j-1][k][1]) %mod;\n\t\t if(k) dp2[i][j][k][2]= 1ll*k* (sm[i][j][k-1] - dp2[i][j][k-1][2]) %mod;\n\t\t}\n\t\tfor(int w=0;w<3;w++){\n\t\t add( sm[i][j][k], dp2[i][j][k][w] );\n\t\t}\n\t\tll num=0;\n\t\tfor(int s=0;s<=t;s++){\n\t\t num+= 1ll* dp[n&1][i][j][s] * ddp[n&1][k][t-s];\n\t\t if((s&7)==0) num%=mod;\n\t\t}\n\t\tnum%=mod;\n\t\tans= (num* sm[i][j][k] + 1ll*ans) %mod;\n\t }\n\t}\n }\n if(ans<0) ans+=mod;\n return cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n#define pb push_back\n#define mp make_pair\n#define S second\n#define F first\n#define INF 0x3f3f3f3f\n#define ll long long\n#define mod (ll)10e9\n#define B 33\n#define MAX 1000001\n#define eps 1e-15\n#define pi 3.14159\n#define ull unsigned long long\n\ntypedef vector vi;\ntypedef pairii;\ntypedef vector vii;\n\nint a,b,c,d;\nint p[10010];\nint w[8] = {4,2,4,2,4,6,2,6};\nint f[10010];\nvi primes;\nint bs(int lo, int hi, double key, int w){\n // printf(\"w = %d\\n\",w);\n while(hi >= lo){\n int mid = (hi + lo)/2;\n // printf(\"%d %d %d, w/mid = %lf\\n\",lo,hi,mid,(double)w / mid);\n if(fabs((double)w / mid - key) <= eps) return mid;\n else if((double)w / mid > key) lo = mid + 1;\n else hi = mid - 1; \n }\n return 1;\n}\nvoid test(double key){\n // printf(\"buscando %lf\\n\",key);\n for(int i=0; i<=1000000; ++i){\n int j = bs(1,1000000,key,i);\n if(fabs((double) i/j - key) <= eps){\n if(i == 0) j = 1;\n printf(\"%d/%d\\n\",i,j);\n return;\n }\n }\n}\nint main(void){\n cin >> a >> b >> c >> d;\n // sieve(10000);\n double nd = (double)a*d/c;\n double nc = (double)b*c/d;\n if((double)(b - nd)/b > (double)(a - nc)/a) test((double)(b-(double)nd)/b);\n else test((double)(a-(double)nc)/a);\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "number theory"], "code_uid": "8edf6068f4a968e93da42c69de533a18", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n int B,G,R,n;\n B=G=R=0;\n scanf(\"%d\",&n);\n char str[300];\n scanf(\"%s\",str);\n for(int i=0;str[i]!='\\0';i++){\n if(str[i]=='B')\n B++;\n if(str[i]=='R')\n R++;\n if(str[i]=='G')\n G++;\n }\n if(B==n){\n printf(\"B\\n\");return 0;\n }if(G==n){\n printf(\"G\\n\");return 0;\n }if(R==n){\n printf(\"R\\n\");return 0;\n }if(B>=1&&R>=1&&G>=1){\n printf(\"BGR\\n\");return 0;\n }\n int a=1,b=1,c=1;\n if(B==n-1){\n a=0;\n }if(G==n-1){\n b=0;\n }if(R==n-1){\n c=0;\n }if(a)printf(\"B\");\n if(b)printf(\"G\");\n if(c)printf(\"R\");\n printf(\"\\n\");\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "146cecff6ae6b0b3d651d9280f4713a6", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \nusing namespace std;\nint main(int argc, const char * argv[]) {\n int n,d;\n cin>>n>>d;\n int a[n];\n int ans[n];\n for(int i=0;i>a[i];\n }\n sort(a,a+n);\n for(int f=0;f=f;i--){\n if(a[i]-a[f]<=d){\n ans[f] = n-1-i+f;\n break;\n }\n }\n }\n sort(ans,ans+n);\n cout<\nusing namespace std;\n#define ll long long\n\nint n;\nint main(){\n\tcin>>n;\n if(n==3){puts(\"5\");return 0;}\n for(int i=1;;i+=2){\n if(i*i+1>>1>=n){printf(\"%d\\n\",i);break;}\n }return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "d0e2de2970eee9c3befcef361cd92fd0", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "\n\n#include\nint main () \n{int t ;\nint sum = 0 ;\n scanf(\"%d\",&t);\n\tfor (int i =0 ; i<32; i++)\n\t\tif (t>>i&1){ sum++; } \n\t printf(\"%d\\n\",sum); \n \n\n \n return 0; \n }", "lang_cluster": "C++", "tags": ["bitmasks"], "code_uid": "a79b86388c364074bafc5ff8aeecc78d", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n\n#define PB push_back\n#define f(i,a,b) for(int i=a;i vi;\ntypedef vector vll;\n\t\nll m,b;\nll f;\nint main()\n{\n\tcin>>m>>b;\n\tfor(ll x=0;x<=m*b;x++)\n\t{\n\t\tll y= -(x+m-1)/m+b;\n\t\tf=max(f,(x*(x+1)*(y+1)+y*(y+1)*(x+1))/2);\n\t}\n\tcout<\n#include \n#include \n#include \nusing namespace std;\nint p;\nbool run(int x)\n{\n for(int a = 2; a <= sqrt(x) and a<= p; a ++)\n {\n if(x%a==0)\n return false;\n }\n printf(\"%d\",x);\n return true;\n}\nint main()\n{\n int y;\n int a;\n scanf(\"%d%d\",&p,&y);\n for( a = y; a > p; a --)\n {\n if(run(a))\n return 0;\n }\n printf(\"-1\");\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "f472d1309df3a1861fe9d60cbdcd16b0", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\n\nint main(){\n ll n,a,b,p,q;\n scanf(\"%lld%lld%lld%lld%lld\",&n,&a,&b,&p,&q);\n ll lcm = n/(a*b/__gcd(a,b));\n ll x = n/a-lcm,y = n/b-lcm;\n printf(\"%lld\\n\",p*x+q*y+max(p,q)*lcm);\n return 0;\n}\n ", "lang_cluster": "C++", "tags": ["math", "implementation", "number theory"], "code_uid": "541863e48df6ef82dd363fa91bd4b6a4", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main () {\n int a, b, c, d, e, f;\n \n while (cin >> a >> b >> c >> d >> e >> f) {\n bool possible = (c == 0 && d != 0) || (b*d*f > a*c*e) || (a*c == 0 && b*d != 0);\n cout << (possible ? \"Ron\" : \"Hermione\") << endl;\n }\n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "e2e968f6fb6656497b36a5b7b5908c47", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n\tint jumlah = 0;\n\tint angka;\n\tint min;\n\tint total1=0;\n\tint jumlahh= 0;\n\tint total = 0;\n\tcin >> angka;\n\tint elemen[angka];\n\tfor ( int i = 0; i < angka; i++)\n\t{\n\t\tcin >> elemen[i];\n\t}\n\n\tfor ( int i = 0; i < angka; i++)\n\t{\t\n\t\tif ( elemen[i]>0 )\n\t\t{\n\t\t\ttotal = total + elemen[i];\t\t\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttotal1 = total1 + elemen[i];\n\t\t}\n\t}\n\t\n\n\tcout << total - total1;\n}\n\n", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "7af84a5f3ab45154b8f29914b26a4d6e", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define LL int64_t\n#define LD long double;\nusing namespace std;\n\nbool can(string s, int n, int k, int pos) {\n for(int i=0;i>n>>k>>s;\n\n bool ans = false;\n for(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define each(i, x) for(__typeof(x.begin()) i=(x).begin(); i!=(x).end(); ++i)\nusing namespace std;\ntemplate T sqr(const T& x) { return x * x; }\n\nint mk(int a){\n int b=0;\n int e=1;\n while(a>0){\n int t=a%10;\n if(t==4 or t==7){\n b+=e*t;\n e*=10;\n }\n a/=10;\n }\n return b;\n}\n\nint main() {\n int a,b;\n cin>>a>>b;\n a++;\n while(mk(a)!=b)a++;\n cout<\n\nint main()\n{\n\tlong long n;\n\tstd::cin >> n;\n\tif (n == 0)\n\t\tstd::cout << 0;\n\telse\n\t{\n\t\tif ((n + 1) % 2 == 0)\n\t\t\tstd::cout << (n + 1) / 2;\n\n\t\tif ((n + 1) % 2 == 1)\n\t\t\tstd::cout << n + 1;\n\t}\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "1fc7f974322dede1d5c35df5e2df445a", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main(){\nint t, m[3][2], ans[3];\nwhile (cin >> t){\nfor (int a = 0; a < 3; a++)\ncin >> m[a][0] >> m[a][1], m[a][1] -= m[a][0];\nans[0] = m[0][0], ans[1] = m[1][0], ans[2] = m[2][0];\nt -= m[0][0], t -= m[1][0], t -= m[2][0];\nfor (int a = 0; a < 3 && t>0; a++){\nif (t > m[a][1])\nans[a] += m[a][1], t -= m[a][1];\nelse if (t <= m[a][1])\nans[a] += t, t = 0;\n}\ncout << ans[0] << \" \" << ans[1] << \" \" << ans[2] << endl;\n}\nreturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "implementation"], "code_uid": "870c002df90c701c8f3c91b63bcfad71", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\nconst double pi = acos(-1);\nconst ll oo = 1e18 + 10;\nconst int mod = 1e9 + 7;\nconst int N = 1e7 + 10;\n#define f first\n#define s second\n#define all(v) (v).begin(),(v).end()\nint n;\nvectorv(15);\nbool rotate(int idx, int deg) {\n\tif (idx == n)\n\t\treturn deg == 0;\n\treturn rotate(idx + 1, (deg + v[idx]) % 360) || rotate(idx + 1, deg - v[idx] + 360);\n}\nint main() {\n\t// freopen(\"input.txt\", \"r\", stdin);\n\t// freopen(\"output.txt\", \"w\", stdout);\n\tscanf(\"%d\", &n);\n\tfor (int i = 0; i < n; i++)\n\t\tscanf(\"%d\", &v[i]);\n\tputs(rotate(0, 0) ? \"YES\" : \"NO\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "586cba2e813d38b10760667523a223dc", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n\nusing namespace std;\n\nint main()\n{\n int n;\n cin>>n;\n\n if(n==1)\n {\n cout<<1<<\"\\n\";\n }\n else\n {\n int cnt=0,i=0;\n while(n!=0)\n {\n\n if(i%2==0)\n {\n n=n-1;\n cnt++;\n i++;\n }\n else if(i%2==1)\n {\n if(n<2)\n {\n break;\n }\n else\n {\n n=n-2;\n cnt++;\n i++;\n }\n\n }\n }\n cout<\n#include\n#include\nusing namespace std ;\n\nint n ;\nint a[ 500007 ] ;\nint l[ 500007 ] ;\nint r[ 500007 ] ;\nlong long ans = 0 ;\n\n\npair < int , int > p[ 500007 ] ;\n\nvoid input ( ) {\n scanf ( \"%d\" , &n ) ;\n int i ;\n for ( i = 0 ; i < n ; i ++ ) {\n scanf ( \"%d\" , &a[ i ] ) ;\n\n p[ i ].first = a[ i ] ;\n p[ i ].second = i ;\n }\n sort ( p , p + n ) ;\n}\n\nvoid solve ( ) {\n if ( n < 3 ) {\n printf ( \"0\\n\" ) ;\n return ;\n }\n int i ;\n for ( i = 0 ; i < n ; i ++ ) {\n l[ i ] = i - 1 ;\n r[ i ] = i + 1 ;\n }\n int ind ;\n int x , y ;\n int lo = 0 ;\n int hi = n - 1 ;\n for ( i = 0 ; i < n - 2 ; i ++ ) {\n ind = p[ i ].second ;\n ///printf ( \"%d\\n\" , ind ) ;\n if ( ind == lo ) {\n ans += p[ i ].first ;\n lo = r[ ind ] ;\n continue ;\n }\n if ( ind == hi ) {\n ans += p[ i ].first ;\n hi = l[ ind ] ;\n continue ;\n }\n x = l[ ind ] ;\n y = r[ ind ] ;\n ans += min ( a[ x ] , a[ y ] ) ;\n r[ x ] = y ;\n l[ y ] = x ;\n }\n printf ( \"%I64d\\n\" , ans ) ;\n}\n\nint main ( ) {\n input ( ) ;\n solve ( ) ;\n return 0 ;\n}", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "5770dc7b6486812bc770849483b575cd", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\nusing LL = long long;\nconst int INF = 0x3f3f3f3f;\n\nvoid solve() {\n int n;\n cin >> n;\n int a[3], b[3];\n for (int i = 0; i < 3; ++i)\n cin >> a[i];\n for (int i = 0; i < 3; ++i)\n cin >> b[i];\n\n cout << max({0, a[0] - b[0] - b[2], a[1] - b[0] - b[1], a[2] - b[2] - b[1]}) << ' ' <<\n min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0]) << endl;\n}\n\nint main() {\n solve();\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "17376885fe5cc023c3c7dd86f4c30f14", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "// Remember...\n\n#include\n\n#define F first\n#define S second\n#define PB push_back\n#define sz(s) int((s).size())\n#define bit(n,k) (((n)>>(k))&1)\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\n\nconst int maxn=1e5+10;\n\nint main(){\n ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();\n\n int a,b; cin>>a>>b;\n int n=a+b, ans=0;\n\n int sq=sqrt(n);\n \n vector vec;\n for(int i=1;i<=sq;i++){\n\tvec.PB(i);\n }\n for(int i=1;(n/i)>sq;i++){\n\tvec.PB(n/i);\n }\n for(int x:vec){\n\tint A=a%x, AA=a/x, B=b%x, BB=b/x;\n\tif(A<=AA && B<=BB && A+B\n#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef pair P;\ntypedef pair P1;\ntypedef pair P2;\n#define pu push\n#define pb push_back\n#define mp make_pair\n#define eps 1e-7\n#define INF 1000000000\n#define fi first\n#define sc second\n#define rep(i,x) for(int i=0;i=0;i--)\n#define repn(i,x) for(int i=1;i<=x;i++)\n#define SORT(x) sort(x.begin(),x.end())\n#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())\n#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())\n#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())\ntemplate\nvoid dmp(T a){\n\trep(i,a.size()) cout << a[i] << \" \";\n\tcout << endl;\n}\ntemplate\nbool chmax(T&a, T b){\n\tif(a < b){\n\t\ta = b;\n\t\treturn 1;\n\t}\n\treturn 0;\n}\ntemplate\nbool chmin(T&a, T b){\n\tif(a > b){\n\t\ta = b;\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\ntypedef bitset<150> bs;\nunordered_mapM;\nint cnt = 0;\nbs info[100005];\nvoid add(bs &b){\n\tif(M.find(b) == M.end()){\n\t\tinfo[cnt] = b;\n\t\tM[b] = cnt++;\n\t}\n}\nll go[16005][10];\nll way[16005][20][10];\nbool ok[16005][10];\nvoid prepare(){\n\tbs x = bs();\n\tx[75] = 1;\n\tadd(x);\n\trep(i,cnt){\n\t\trep(nxt,10){\n\t\t\tbs nw = (info[i]<>nxt);\n\t\t\tadd(nw);\n\t\t}\n\t}\n\t//15473\n\t//cout << cnt << endl;\n\trep(i,cnt){\n\t\trep(nxt,10){\n\t\t\tbs nw = (info[i]<>nxt);\n\t\t\tassert(M.find(nw) != M.end());\n\t\t\tgo[i][nxt] = M[nw];\n\t\t}\n\t}\n\trep(i,cnt){\n\t\tint mn = INF;\n\t\trep(j,150){\n\t\t\tif(info[i][j]){\n\t\t\t\tmn = min(mn, abs(75-j));\n\t\t\t}\n\t\t}\n\t\tfor(int x=mn;x<10;x++) ok[i][x] = 1;\n\t\tfor(int x=mn;x<10;x++) way[i][0][x] += 1;\n\t}\n\trep(j,19){\n\t\trep(k,10){\n\t\t\trep(i,cnt){\n\t\t\t\trep(nxt,10){\n\t\t\t\t\tint g = go[i][nxt];\n\t\t\t\t\tway[i][j+1][k] += way[g][j][k];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\nll calc(ll num, int k){\n\tif(num == 0) return 1;\n\tvectorvi;\n\tll N = num;\n\twhile(N){\n\t\tvi.pb(N%10); N/=10;\n\t}\n\treverse(vi.begin(),vi.end());\n\tint cur = 0;\n\tll ans = 0;\n\trep(i,vi.size()){\n\t\trep(j,vi[i]){\n\t\t\tans += way[go[cur][j]][vi.size()-1-i][k];\n\t\t}\n\t\tcur = go[cur][vi[i]];\n\t}\n\tif(ok[cur][k]) ans++;\n\treturn ans;\n}\nint main(){\n\tprepare();\n\tint t; scanf(\"%d\",&t);\n\twhile(t--){\n\t\tll L,R; int k;\n\t\tscanf(\"%lld%lld%d\",&L,&R,&k);\n\t\tprintf(\"%lld\\n\",calc(R,k)-calc(L-1,k));\n\t}\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "c43903163d0d33ee727be93eb258785e", "src_uid": "db0e3ef630cb381724697a1ac5152611", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nusing namespace std;\nint n,m,MO=1e9+7;\nlong long f[1010][1010][2][2];\nlong long C[1010][1010];\nlong long jc[1010],ans[1010];\nint main()\n{\n\tscanf(\"%d%d\",&n,&m);f[0][0][1][0]=1;C[0][0]=1;jc[0]=1;\n\tfor(int i=0;i<=n;i++)\n\tfor(int j=0;j<=i;j++)\n\tif (i==j||i==0||j==0) C[i][j]=1;\n\telse C[i][j]=(C[i-1][j]+C[i-1][j-1])%MO;\n\tfor(int i=1;i<=n;i++) jc[i]=(jc[i-1]*i)%MO;\n\tfor(int i=1;i<=n;i++)\n\tfor(int j=0;j\n#define ll long long\nusing namespace std;\nconst int maxn = 2005;\nconst ll mo = (ll) 1e9 + 7;\nll dp[maxn][maxn][2][2],n,k;\nll c[maxn][maxn],ans[maxn],fac[maxn];\nint main()\n{\n scanf(\"%d%d\",&n,&k);\n for (int i=1;i<=n;++i)\n {\n c[i][0]=c[i][i]=1LL;\n for (int j=1;j<=i-1;++j)\n {c[i][j]=(c[i][j]+c[i-1][j]+c[i-1][j-1])%mo;}\n } \n fac[0] = fac[1] = 1LL;\n for (int i = 2; i <= 2001; ++i) fac[i] = (fac[i - 1] * i * 1LL) % mo;\n dp[0][0][1][0]=1; \n for (int i=1;i<=n;++i)\n {\n for (int j=0;j<=i-1;++j)\n for (int now=0;now<2;++now)\n for (int ne=0;ne<2;++ne)\n {\n dp[i][j][ne][0]=(dp[i][j][ne][0]+dp[i-1][j][now][ne])%mo;\n if (!now) dp[i][j+1][ne][0]=(dp[i][j+1][ne][0]+dp[i-1][j][now][ne])%mo;\n if (i\r\nusing namespace std;\r\ntypedef long long ll;\r\n#define M 998244353\r\n#define N 720720\r\nint i,j,k,n,m,t,g;\r\nll sb,x,y,tot,res,lst,p[N+5],t1;\r\nll ksm(ll a,int p){ll res=1;while(p){if(p&1){res=res*a%M;}a=a*a%M;p>>=1;}return res;}\r\nll su(ll a,ll b){a+=b;return (a>=M)?a-M:a;}\r\nint main()\r\n{\r\n\tcin>>n>>lst>>x>>y>>m>>sb;\r\n\tfor(i=1;i<=n;i++)\r\n\t{\r\n\t\tp[lst%N]++;res=su(res,(lst/N)*N);\r\n\t\tlst=(lst*x+y)%sb;\r\n\t}\r\n\tres=res*ksm(n,m-1)%M*m%M;\r\n\tfor(i=1;i<=m;i++)\r\n\t{\r\n\t\tfor(tot=0,j=1;j<=N;j++)\r\n\t\t{\r\n\t\t\ttot+=p[j]*j%M;t1=p[j];\r\n\t\t\tp[j]=p[j]*(n-1)%M;\r\n\t\t\tp[j-j%i]=su(p[j-j%i],t1);\r\n\t\t}\r\n\t\tres=su(res,tot%M*ksm(n,m-i)%M);\r\n\t}\r\n\tcout<\n#include \n\nusing namespace std;\n\nint main()\n{\n int n , i , j ;\n char *s;\n vector v;\n \n cin>>n;\n s = new char[n+1];\n cin>>s;\n for( i = 0 ; i < n ; i++)\n {\n if( s[i] == 'B')\n {\n j = i;\n while( s[j] == 'B')\n {\n j++;\n }\n v.push_back( j - i);\n i = j;\n }\n }\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define REP(I,N) for (I=0;I=0;I--)\n#define rep(I,S,N) for (I=S;I=S;I--)\n#define FOR(I,S,N) for (I=S;I<=N;I++)\n#define rFOR(I,S,N) for (I=N;I>=S;I--)\n\n#define DEBUG\n#ifdef DEBUG\n#define debug(...) fprintf(stderr, __VA_ARGS__)\n#define deputs(str) fprintf(stderr, \"%s\\n\",str)\n#else\n#define debug(...)\n#define deputs(str)\n#endif // DEBUG\ntypedef unsigned long long ULL;\ntypedef unsigned long long ull;\ntypedef unsigned int ui;\ntypedef long long LL;\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\nconst int INF=0x3f3f3f3f;\nconst LL INFF=0x3f3f3f3f3f3f3f3fll;\nconst LL M=1e9+7;\nconst LL maxn=1e6+107;\nconst double pi=acos(-1.0);\nconst double eps=0.0000000001;\nLL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}\ntemplateinline void pr2(T x,int k=64) {ll i; REP(i,k) debug(\"%d\",(x>>i)&1); putchar(' ');}\ntemplateinline void add_(T &A,int B,ll MOD=M) {A+=B; (A>=MOD) &&(A-=MOD);}\ntemplateinline void mul_(T &A,ll B,ll MOD=M) {A=(A*B)%MOD;}\ntemplateinline void mod_(T &A,ll MOD=M) {A%=MOD; A+=MOD; A%=MOD;}\ntemplateinline void max_(T &A,T B) {(Ainline void min_(T &A,T B) {(A>B) &&(A=B);}\ntemplateinline T abs(T a) {return a>0?a:-a;}\ninline ll powMM(ll a, ll b, ll mod=M) {\n\tll ret=1;\n\tfor (; b; b>>=1ll,a=a*a%mod)\n\t\tif (b&1) ret=ret*a%mod;\n\treturn ret;\n}\nint startTime;\nvoid startTimer() {startTime=clock();}\nvoid printTimer() {debug(\"/--- Time: %ld milliseconds ---/\\n\",clock()-startTime);}\n\nll sum4[maxn],sum2[maxn],sum6[maxn],val[maxn];\nint main() {\n\tll m; ll i;\n\tll inv2=powMM(2,M-2),inv6=powMM(6,M-2);\n\tscanf(\"%lld\",&m);\n\tll k=m%M;\n\tll base=k*(k+1)%M*(k+1)%M*inv2%M;\n\tadd_(base,M-k*(k+1)%M*(2*k+1)%M*inv6%M);\n\t// printf(\"%lld\\n\",base);\n\tFOR(i,1,1000000) {\n\t\tval[i]=i*i;\n\t\tsum2[i]=val[i]%M; add_(sum2[i],sum2[i-1]);\n\t\tsum4[i]=val[i]%M*(val[i]%M)%M; add_(sum4[i],sum4[i-1]);\n\t\tsum6[i]=val[i]%M*(val[i]%M)%M*(val[i]%M)%M; add_(sum6[i],sum6[i-1]);\n\t} ll ans=0;\n\tfor (ll x=0;x*x<=m;x++) {\n\t\tll r=upper_bound(val,val+1000001,m-x*x)-val-1;\n\t\tll now=0;\n\t\tll A0=1,A1=x*x%M,A2=A1*A1%M,A3=A1*A2%M;\n\t\tll B0=(r*2+1)%M,B1=sum2[r]*2%M-0,B2=sum4[r]*2%M-0,B3=sum6[r]*2%M-0;\n\t\tll sum0=B0;\n\t\tll sum1=A1*B0%M+A0*B1%M; sum1%=M;\n\t\tll sum2=A0*B2%M+2*A1*B1%M+A2*B0%M; sum2%=M;\n\t\tll sum3=A0*B3%M+3*A1*B2%M+3*A2*B1%M+A3*B0%M; sum3%=M;\n\t\tadd_(now,(sum2-sum1+M)%M*(k+1)%M*inv2%M);\n\t\tadd_(now,M-(2*sum3-3*sum2+sum1+M*3)%M*inv6%M);\n\t\tnow=M-now; add_(now,base*sum0%M);\n\t\t// printf(\"%lld : %lld; %lld %lld %lld %lld\\n\",x,r,B0,B1,B2,B3);\n\t\t// printf(\"sum %lld : %lld %lld %lld %lld; now=%lld\\n\",x,sum0,sum1,sum2,sum3,now);\n\t\tif (x!=0) add_(ans,now);\n\t\tadd_(ans,now);\n\t} printf(\"%lld\\n\",ans);\n}\n/*\n*/", "lang_cluster": "C++", "tags": ["brute force", "math", "combinatorics"], "code_uid": "e7fc7ae3adc09b6f8bc58fbd26c4645d", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \nusing namespace std ;\n#define ll long long\n#define lb long double\n#define rep(i,a,b) for(int i=a;i<=b;i++)\nconst int N=35000 ;\nconst int mo=1e9+7 ;\nconst int M=31622 ;\nconst lb PI=acos(-1.0) ;\nll n ;\nint K,fac[N],inv[N],Inv[N],g[N],f[N],len,m,rev[N<<2] ;\nvoid ntr(int &x) { x=x>=mo?x-mo:(x<0?x+mo:x) ; }\nvoid inc(int &x,int y) { x+=y,ntr(x) ; }\nstruct comp {\n\tlb r,i ;\n\tcomp() {}\n\tcomp(lb _r,lb _i) { r=_r,i=_i ; }\n\tcomp operator +(comp t) { return comp(r+t.r,i+t.i) ; }\n\tcomp operator -(comp t) { return comp(r-t.r,i-t.i) ; }\n\tcomp operator *(comp t) { return comp(r*t.r-i*t.i,r*t.i+i*t.r) ; }\n} a[N<<2],b[N<<2],c[N<<2],d[N<<2],A[N<<2],B[N<<2],C[N<<2],w[20][N<<2] ;\nvoid init() {\n\tfac[0]=1 ; rep(i,1,K) fac[i]=1ll*fac[i-1]*i%mo ;\n\tinv[1]=1 ; rep(i,2,K) inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo ;\n\tInv[0]=1 ; rep(i,1,K) Inv[i]=1ll*Inv[i-1]*inv[i]%mo ;\n\trep(i,1,K) g[i]=Inv[i] ; f[0]=1 ;\n\trep(i,0,len-1) {\n\t\trev[i]=0 ;\n\t\trep(j,0,m-1) rev[i]<<=1,rev[i]|=(i>>j)&1 ;\n\t}\n\trep(i,1,m) {\n\t\tcomp t=comp(cos(2*PI/(1<K) return puts(\"0\"),0 ;\n\tinit() ;\n\tfor (int i=n,t=2;i;i>>=1) {\n\t\tif (i&1) mul(f,g,t) ;\n\t\tmul(g,g,t) ; \n\t\tt=1ll*t*t%mo ;\n\t}\n\tint ans=0 ;\n\trep(i,n,K) inc(ans,1ll*f[i]*fac[i]%mo*fac[K]%mo*Inv[i]%mo*Inv[K-i]%mo) ;\n\tprintf(\"%d\\n\",ans) ;\n\treturn 0 ;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "403d326711f97f4eb1fcbdea16d2ff58", "src_uid": "295baf6ccbfc3a7d098989a0701d2018", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n\nvoid solution(const std::set& pos, int t)\n{\n int n;\n\twhile(t--){\n\t\tstd::cin >> n;\n int ans{};\n for(const auto& item : pos)\n {\n if(n >= item)\n ans++;\n else\n break;\n }\n std::cout << ans << \"\\n\";\n }\n}\n\nint main()\n{\n std::set possible;\n for(std::int64_t i = 1; i * i <= 1000000000; i++){\n\t\tpossible.insert(i * i);\n\t}\n\tfor(std::int64_t i = 1; i * i * i <= 1000000000; i++){\n\t\tpossible.insert(i * i * i);\n\t}\n int t;\n\tstd::cin >> t;\n\tsolution(possible,t);\n}\n\t\t\t \t\t \t\t\t \t \t \t\t\t \t \t \t\t\t\t", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "6d68e11082abb34f43c99dce77bfd637", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#include\nusing namespace std;\n#define ll long long\n#define f(i,x,n) for (int i = x;i < n;++i)\n\npair p[4];\n\nint main() {\n\tf(i, 0, 4) {\n\t\tint a, b;\n\t\tscanf(\"%d%d\", &a, &b);\n\t\tp[i] = make_pair(a, b);\n\t}\n\tbool die[2] = { false };\n\tf(i, 0, 2) {\n\t\tswap(p[0], p[1]);\n\t\tbool ok = true;\n\t\tf(j, 0, 2) {\n\t\t\tswap(p[2], p[3]);\n\t\t\tif (p[0].first <= p[2].second || p[1].second <= p[3].first)ok = false;\n\t\t\tif (p[0].first < p[2].second && p[1].second < p[3].first)die[i] = true;\n\t\t}\n\t\tif (ok) { printf(\"Team 1\"); return 0; }\n\t}\n\tif (die[0] && die[1])printf(\"Team 2\");\n\telse printf(\"Draw\");\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "39e0ebefaf60f4af0eb4e584735e7590", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tint n;\n\tint *a;\n\tcin >> n;\n\ta = new int[n];\n\tint startCounter = 0, endCounter = 0, counter = 0, totalLength = n;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tcin >> a[i];\n\t}\n\twhile (startCounter < n && a[startCounter] == 0)\n {\n startCounter++;\n }\n\n while (endCounter < n && a[n - 1 - endCounter] == 0)\n {\n endCounter++;\n }\n\n totalLength -= (startCounter + endCounter);\n for (int i = startCounter; i < n - endCounter; i++)\n {\n if (a[i] == 0)\n counter++;\n else\n\t\t{\n\t\t\tif(counter >= 2)\n \t\ttotalLength -= counter;\n\t\t\tcounter = 0;\n\t\t}\n }\n totalLength -= counter;\n if (totalLength < 0)\n totalLength = 0;\n\tcout << totalLength;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "eda7d125925c0cd0d49a6c5be850c51a", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long LL;\nconst double pi=acos(-1.0);\nconst double e=exp(1);\nconst int N = 100010;\n\n#define lson i << 1,l,m\n#define rson i << 1 | 1,m + 1,r\n\nchar a1[]={\"Danil\"},a2[]={\"Olya\"},a3[]={\"Slava\"},a4[]={\"Ann\"},a5[]={\"Nikita\"};\nchar con[110];\nchar mid[20];\nint main()\n{\n int i,p,j,k,n;\n int check=0;\n gets(con);\n for(i=0;i<=108;i++)\n {\n p=0;\n if(con[i]==0)\n break;\n for(j=i;j<=108;j++)\n {\n if(con[j]!=a1[p++])\n break;\n if(p>4)\n {\n check++;\n break;\n }\n }\n p=0;\n for(j=i;j<=108;j++)\n {\n if(con[j]!=a2[p++])\n break;\n if(p>3)\n {\n check++;\n break;\n }\n }\n p=0;\n for(j=i;j<=108;j++)\n {\n if(con[j]!=a3[p++])\n break;\n if(p>4)\n {\n check++;\n break;\n }\n }\n p=0;\n for(j=i;j<=108;j++)\n {\n if(con[j]!=a4[p++])\n break;\n if(p>2)\n {\n check++;\n break;\n }\n }\n p=0;\n for(j=i;j<=108;j++)\n {\n if(con[j]!=a5[p++])\n break;\n if(p>5)\n {\n check++;\n break;\n }\n }\n if(check>1)\n break;\n }\n\n if(check==1)\n printf(\"YES\\n\");\n else\n printf(\"NO\\n\");\n return 0;\n}\n\n\t \t \t\t\t \t\t\t \t \t \t\t\t\t\t \t\t\t", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "f7470d12cc9ff0aaa0a628b0bcb6f93c", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#include\n#include\nusing namespace std;\nbool dp[51][500003]={0};\nint dpp[500003]={0};\nint n;\nint main(){\n\tint d,i;\n\tcin>>n>>d;\n\tdp[0][0]=1;\n\tfor( i=1;i<=n;++i){\n\t\tint t;\n\t\tcin>>t;\n\t\tfor(int j=0;j+t<=500000;++j)\n\t\t\tdp[i][j+t]|=dp[i-1][j];\n\t\tfor(int j=0;j<=500000;++j)\n\t\t\tdp[i][j]|=dp[i-1][j];\n\t}\n\t//int\n\ti=0;\n\tint soll=0;\n\tint num=1;\n\tint ans=0;\n\tfor(;i<=500000;++num){\n\t\tint dd=d-1;\n\t\tint ss=i;\n\t\tint f=0;\n\t\t++i;\n\t\tfor(;i<=500000 && dd>=0;--dd,++i)\n\t\t\tif(dp[n][i]){\n\t\t\t\tf=i;}\n\t\tif(f==0)break;\n\t\tdpp[f]=dpp[ss]+1;\n\t\ti=f;\n\t\tsoll=f;\n\t}\n\tcout<\nusing namespace std;\nint main(){\n\tlong long n,m,a,b;\n\tcin>>n>>m>>a>>b;\n\tcout<\n #define ll long long\n #define cost first\n #define id second\n #define f first\n #define s second\n #define clr(v, d)\t\tmemset(v, d, sizeof(v))\n #define read(FILE) freopen(FILE, \"r\", stdin);\n #define write(FILE) freopen(FILE, \"w\", stdout);\n #define Abdulrahman ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n using namespace std;\n const int N = 5e5+5 , nBits = 2e8 +5 , MM = (1 << 16) , MAX = 1111 , OO = 0x3f3f3f3f , MOD = 1e9+7 , inf = 1 << 30;\n const ll INF = (ll)1e18;\n //ll GCD(ll a, ll b) { return !b ? a : GCD(b , a % b); }\n //ll LCM(ll x, ll y) { return (x * y / GCD(x, y)); }\n ll fact(ll z) { return (z <= 1) ? 1 : z * fact(z - 1); }\n //bool valid (int i , int j){ return i >= 0 && j >= 0 && i < n && j < m ;}\n //int X[] = {0 , 0 , 1 , -1 , 1 , -1 , 1 , -1};\n //int Y[] = {1 , -1 , 0 , 0 , 1 , -1 , -1 , 1};\n //len any int num > 0 ... len = ceil(log10(a+1));\n //len any int num > 0 ... len = ceil(log10(a+1));\nint n , A[111] , k , x , ans , sum ;\nint main(){\n // freopen(\"fileName.in\" , \"r\" , stdin);\n scanf(\"%d %d\" , &n ,&k);\n for(int i = 1 ; i <= n ; ++i) scanf(\"%d\" , &A[i]) , sum += A[i];\n for(int i = 1 ; i <= k ; ++i){\n x = sum;\n for(int j = i ; j <= n ; j += k) x -= A[j];\n ans = max(ans , abs(x));\n }\n printf(\"%d\\n\" , ans );\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "59af622b9c1defdd748c4a5b9fd5216b", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define f(i,s,e) for (int i = int(s); i != int(e); i++)\n#define ft(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)\n#define all(c) (c).begin(), (c).end()\n\n//read scanf functions\n#define readI(x) scanf(\"%d\", &x)\n#define readL(x) scanf(\"%I64d\", &x)\n#define readD(x) scanf(\"%f\", &x)\n#define readII(x, y) scanf(\"%d %d\", &x, &y)\n#define readLL(x, y) scanf(\"%I64d %I64d\", &x, &y)\n\ntypedef long long ll;\n\nll l, r;\n\n\nint cntDigits(ll x) {\n int ret =0;\n while (x) ret++, x/=10;\n return ret;\n}\nll power[20];\n\nll solve(ll x) {\n ll ret;\n if (x <= 9) ret = x;\n else ret = x/10-1+9;\n\n if (x>9)\n ret += ((x%10)>=x/(power[cntDigits(x)-1]));\n return ret;\n}\n\nint main() {\n cin >> l >> r;\n power[0]= 1;\n for(int i=1; i<=19; i++) power[i] = power[i-1]*10;\n cout << solve(r) - solve(l-1) << \"\\n\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["binary search", "dp", "combinatorics"], "code_uid": "3db3313ce595ee0e81f79c66f48f58be", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\n\nint main() \n{\n int n,m;\n cin>>n>>m;\n char c[12][13];\n string temp;\n for(int i = 1; i <= n ; i++)\n {\n cin>>temp;\n int t = 0;\n for(int j = 1 ; j <= m ;j++)\n {\n c[i][j] = temp[t++];\n }\n \n }\n int maxp = 0;\n for(int i = 1; i<=n ; i++)\n {\n for(int j = 1; j<=m ; j++)\n {\n if (c[i][j] == 'W')\n {\n if (c[i-1][j] == 'P' || c[i+1][j] == 'P' || c[i][j-1] == 'P' || c[i][j+1] == 'P')\n {\n maxp += 1;\n }\n }\n \n }\n }\n cout<\n#include\n#include\n#include\n#include\n#define ll long long int\n#define dd double\nusing namespace std;\n\n\n\nint main()\n{\n\n\nll t,p,j,s,q,i,n,x,y=3,k,ans=0,dx;\n cin>>n>>k;\n ll a[n+1];\n\n for(i=1;i<=n;i++)\n {\n cin>>a[i];\n ans+=a[i];\n }\n for(i=1;i\n\n#define all(v) v.begin(), v.end()\n#define sp(n) fixed << setprecision(n)\n#define pb push_back\n#define ff first\n#define ss second\n\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\nusing ld = long double;\nusing pii = pair;\nusing pll = pair;\n\nint t[3][3];\nll dp[41][3][3];\n\nint main() {\n\tios::sync_with_stdio(0);\n\tcin.tie(0); cout.tie(0);\n\n#ifdef LOCAL_DEBUG\n\tfreopen(\"input.txt\", \"r\", stdin);\n#endif\n\n\tfor (int i = 0; i < 3; i++)\n\t\tfor (int j = 0; j < 3; j++)\n\t\t\tcin >> t[i][j];\n\n\tint n;\n\tcin >> n;\n\t\n\tfor (int k = 1; k <= n; k++) {\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tfor (int j = 0; j < 3; j++) {\n\t\t\t\tif (i == j) continue;\n\t\t\t\tll cnt1 = dp[k - 1][i][3 - i - j] + t[i][j] + dp[k - 1][3 - i - j][j];\n\t\t\t\tll cnt2 = dp[k - 1][i][j] + t[i][3 - i - j] + dp[k - 1][j][i] +\n\t\t\t\t\tt[3 - i - j][j] + dp[k - 1][i][j];\n\t\t\t\tdp[k][i][j] = min(cnt1, cnt2);\n\t\t\t}\n\t\t}\n\t}\n\n\tcout << dp[n][0][2] << endl;\n\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "368a73b82608cb1557bcca4f5a47ca09", "src_uid": "c4c20228624365e39299d0a6e8fe7095", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \n#include \n#include\n#include\nusing namespace std;\n \nint main() {\nint i = 0 , j= 0;\nstring s,t;cin>>s>>t;\nint count = 1 ;\nwhile(i\n#ifndef _LIB_POLYNOMIAL_RING\n#define _LIB_POLYNOMIAL_RING\n#include \n#ifndef _LIB_MODULAR_INTEGER\n#define _LIB_MODULAR_INTEGER\n#include \n#ifndef _LIB_NUMBER_THEORY\n#define _LIB_NUMBER_THEORY\n#include \n\nnamespace lib {\n using namespace std;\nnamespace nt {\n int64_t inverse(int64_t a, int64_t b) {\n long long b0 = b, t, q;\n long long x0 = 0, x1 = 1;\n if (b == 1) return 1;\n while (a > 1) {\n q = a / b;\n t = b, b = a % b, a = t;\n t = x0, x0 = x1 - q * x0, x1 = t;\n }\n if (x1 < 0) x1 += b0;\n return x1;\n }\n}\n} // namespace lib\n\n#endif\n\n#if __cplusplus < 201300\n#error required(c++14)\n#endif\n\nnamespace lib {\n using namespace std;\nnamespace {\n template\n struct ModularIntegerBase {\n typedef ModularIntegerBase type;\n\n T x[sizeof...(Mods)];\n friend ostream& operator<<(ostream& output, const type& var) {\n output << \"(\";\n for(int i = 0; i < sizeof...(Mods); i++) {\n if(i) output << \", \";\n output << var.x[i];\n }\n return output << \")\";\n }\n };\n\n template\n struct ModularIntegerBase {\n typedef ModularIntegerBase type;\n\n T x[1];\n\n explicit operator int() const { return this->x[0]; }\n explicit operator long long() const { return this->x[0]; }\n explicit operator double() const { return this->x[0]; }\n explicit operator long double() const { return this->x[0]; }\n friend ostream& operator<<(ostream& output, const type& var) {\n return output << var.x[0];\n }\n };\n\n\n template\n struct ModularIntegerImpl : ModularIntegerBase {\n typedef ModularIntegerImpl type;\n typedef T type_int;\n typedef int64_t large_int;\n const static size_t n_mods = sizeof...(Mods);\n\n struct Less {\n bool operator()(const type& lhs, const type& rhs) const {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if(lhs.x[i] != rhs.x[i])\n return lhs.x[i] < rhs.x[i];\n return false;\n };\n };\n typedef Less less;\n\n constexpr static T mods[sizeof...(Mods)] = {Mods...};\n using ModularIntegerBase::x;\n\n ModularIntegerImpl() {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] = T();\n }\n ModularIntegerImpl(large_int y) {\n for(size_t i = 0; i < sizeof...(Mods); i++) {\n x[i] = y % mods[i];\n if(x[i] < 0) x[i] += mods[i];\n }\n }\n static type with_remainders(T y[sizeof...(Mods)]) {\n type res;\n for(size_t i = 0; i < sizeof...(Mods); i++)\n res.x[i] = y[i];\n res.normalize();\n return res;\n }\n\n void normalize() {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if((x[i] %= mods[i]) < 0)\n x[i] += mods[i];\n }\n\n inline T operator[](int i) const { return x[i]; }\n\n inline T multiply(T a, T b, T mod) const {\n return (large_int)a*b % mod;\n }\n\n inline T inv(T a, T mod) const {\n return static_cast(nt::inverse(a, mod));\n }\n\n type inverse() const {\n T res[sizeof...(Mods)];\n for(size_t i = 0; i < sizeof...(Mods); i++)\n res[i] = inv(x[i], mods[i]);\n return type::with_remainders(res);\n }\n \n template\n T power_(T a, U p, T mod) {\n if(mod == 1) return T();\n if(p < 0) {\n if(a == 0)\n throw domain_error(\"0^p with negative p is invalid\");\n p = -p;\n a = inv(a, mod);\n }\n if(p == 0) return T(1);\n if(p == 1) return a;\n T res = 1;\n while(p > 0) {\n if(p&1)\n res = multiply(res, a, mod);\n p >>= 1;\n a = multiply(a, a, mod);\n }\n return res;\n }\n \n type& operator+=(const type& rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n (x[i] += rhs.x[i]) %= mods[i];\n return *this;\n }\n type& operator-=(const type& rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if((x[i] -= rhs.x[i]) < 0)\n x[i] += mods[i];\n return *this;\n }\n type& operator*=(const type& rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] = multiply(x[i], rhs.x[i], mods[i]);\n return *this;\n }\n type& operator/=(const type& rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] = multiply(x[i], inv(rhs.x[i], mods[i]), mods[i]);\n return *this;\n }\n\n type& operator+=(T rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] += rhs;\n normalize();\n return *this;\n }\n \n type& operator-=(T rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] -= rhs;\n normalize();\n return *this;\n }\n\n type& operator*=(T rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] = multiply(x[i], rhs, mods[i]);\n return *this;\n }\n\n type& operator/=(T rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] = multiply(inv(rhs, mods[i]), x[i], mods[i]);\n return *this;\n }\n\n type& operator^=(large_int p) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n x[i] = power_(x[i], p, mods[i]);\n return *this;\n }\n\n type& operator++() {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if((++x[i]) >= mods[i])\n x[i] -= mods[i];\n return *this;\n }\n type& operator--() {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if((--x[i]) < 0)\n x[i] += mods[i];\n return *this;\n }\n type operator++(int unused) { type res = *this; ++(*this); return res; }\n type operator--(int unused) { type res = *this; --(*this); return res; }\n\n friend type operator+(const type& lhs, const type& rhs) {\n type res = lhs;\n return res += rhs;\n }\n friend type operator-(const type& lhs, const type& rhs) {\n type res = lhs;\n return res -= rhs;\n }\n friend type operator*(const type& lhs, const type& rhs) {\n type res = lhs;\n return res *= rhs;\n }\n friend type operator/(const type& lhs, const type& rhs) {\n type res = lhs;\n return res /= rhs;\n }\n\n friend type operator+(const type& lhs, T rhs) {\n type res = lhs;\n return res += rhs;\n }\n \n friend type operator-(const type& lhs, T rhs) {\n type res = lhs;\n return res -= rhs;\n }\n\n friend type operator*(const type& lhs, T rhs) {\n type res = lhs;\n return res *= rhs;\n }\n \n friend type operator/(const type& lhs, T rhs) {\n type res = lhs;\n return res /= rhs;\n }\n\n friend type operator^(const type& lhs, large_int rhs) {\n type res = lhs;\n return res ^= rhs;\n }\n\n friend type power(const type& lhs, large_int rhs) {\n return lhs ^ rhs;\n }\n\n type operator-() const {\n type res = *this;\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if(res.x[i])\n res.x[i] = mods[i] - res.x[i];\n return res;\n }\n\n friend bool operator==(const type& lhs, const type& rhs) {\n for(size_t i = 0; i < sizeof...(Mods); i++)\n if(lhs.x[i] != rhs.x[i])\n return false;\n return true;\n }\n friend bool operator!=(const type& lhs, const type& rhs) {\n return !(lhs == rhs);\n }\n \n friend istream& operator>>(istream& input, type& var) {\n T y; cin >> y;\n var = y;\n return input;\n }\n };\n}\n\n // Explicitly make constexpr available for linkage.\n template\n constexpr T ModularIntegerImpl::mods[];\n \n template\n using ModularInteger = \n ModularIntegerImpl::value>::type,\n Mods...>;\n \n template\n using Mint32 = ModularInteger;\n\n template\n using Mint64 = ModularInteger;\n} // namespace lib\n\n#endif\n#ifndef _LIB_TRAITS\n#define _LIB_TRAITS\n#include \n\nnamespace lib {\n using namespace std;\nnamespace traits {\n\n /// keep caide\n template\n using IteratorCategory =\n typename iterator_traits::iterator_category;\n\n /// keep caide\n template\n using IteratorCategoryOf = IteratorCategory;\n\n /// keep caide\n template\n using IsRandomIterator =\n is_base_of>;\n\n /// keep caide\n template\n using IsInputIterator =\n is_base_of>;\n\n /// keep caide\n template\n using IsBidirectionalIterator =\n is_base_of>;\n\n /// keep caide\n template\n using HasRandomIterator =\n is_base_of>;\n\n /// keep caide\n template\n using HasInputIterator =\n is_base_of>;\n\n /// keep caide\n template\n using HasBidirectionalIterator =\n is_base_of>;\n}\n}\n\n#endif\n#ifndef _LIB_MATH\n#define _LIB_MATH\n#include \n\nnamespace lib {\n using namespace std;\nnamespace math {\n\n /// caide keep\n template\n struct DefaultPowerOp {\n Type operator()() const { return Type(1); }\n Type operator()(const Type& a) const { return a; }\n void operator()(Type& x, const Type& a, long long cur) const {\n x *= x;\n if(cur & 1)\n x *= a;\n }\n };\n\n template\n Type generic_power(const Type& a, long long n, Op op) {\n if(n == 0) return op();\n Type res = op(a);\n int hi = 63 - __builtin_clzll(n);\n for(int i = hi - 1; ~i; i--) {\n op(res, a, n >> i);\n }\n return res;\n }\n\n template\n Type generic_power(const Type& a, long long n) {\n return generic_power(a, n, DefaultPowerOp());\n }\n} // namespace math\n} // namespace lib\n\n#endif\n\nnamespace lib {\n using namespace std;\nnamespace math {\nnamespace poly {\n\n namespace {\n /// keep caide\n using traits::IsInputIterator;\n /// keep caide\n using traits::HasInputIterator;\n } \n\n template\n struct DefaultPowerOp {\n int mod;\n DefaultPowerOp(int mod) : mod(mod) {}\n P operator()() const { return P(1); }\n P operator()(const P& a) const { return a % mod; }\n void operator()(P& x, const P& a, long long cur) const {\n (x *= x) %= mod;\n if(cur & 1)\n (x *= a) %= mod;\n }\n };\n\n template\n struct ModPowerOp {\n const P& mod;\n ModPowerOp(const P& p) : mod(p) {}\n P operator()() const { return P(1); }\n P operator()(const P& a) { return a % mod; }\n void operator()(P& x, const P& a, long long cur) const {\n (x *= x) %= mod;\n if(cur & 1)\n (x *= a) %= mod;\n }\n };\n\n template\n struct ModShiftPowerOp {\n const P& mod;\n ModShiftPowerOp(const P& p) : mod(p) {}\n P operator()() const { return P(1); }\n P operator()(const P& a) { return a % mod; }\n void operator()(P& x, const P& a, long long cur) const {\n //if(cur < mod.degree())\n //x = P::kth(cur);\n if(cur & 1)\n (x *= (x << 1)) %= mod;\n else\n (x *= x) %= mod;\n }\n };\n\n struct DefaultDivmod;\n struct NaiveDivmod;\n\n template\n struct Polynomial {\n constexpr static bool NaiveMod =\n is_same::value;\n typedef Polynomial type;\n typedef Field field;\n vector p;\n \n Polynomial() : p(0) {}\n explicit Polynomial(Field x): p(1, x) {}\n\n template<\n typename Iterator,\n typename enable_if::value>::type* = nullptr>\n Polynomial(Iterator begin, Iterator end) : p(distance(begin, end)) {\n int i = 0;\n for(auto it = begin; it != end; ++it, ++i)\n p[i] = *it;\n normalize();\n }\n\n template<\n typename Container,\n typename enable_if::value>::type* = nullptr>\n Polynomial(const Container& container) \n : Polynomial(container.begin(), container.end()) {}\n\n Polynomial(const initializer_list& v) \n : Polynomial(v.begin(), v.end()) {}\n\n static type from_root(const Field& root) {\n return Polynomial({-root, 1});\n }\n\n void normalize() const {\n type* self = const_cast(this);\n int sz = self->p.size();\n while(sz > 0 && self->p[sz-1] == 0) sz--;\n if(sz != (int)self->p.size())\n self->p.resize(sz);\n }\n\n inline int size() const { return p.size(); }\n inline int degree() const { return max((int)p.size()-1, 0); }\n bool null() const {\n for(Field x : p)\n if(x != 0) return false;\n return true;\n }\n\n inline Field operator[](const int i) const { \n if(i >= size())\n return 0;\n return p[i]; \n }\n inline Field& operator[](const int i) {\n if(i >= size())\n p.resize(i + 1);\n return p[i]; \n }\n\n type& operator+=(const type& rhs) {\n if(rhs.size() > size())\n p.resize(rhs.size());\n int sz = size();\n for(int i = 0; i < sz; i++)\n p[i] += rhs[i];\n normalize();\n return *this;\n }\n\n type& operator-=(const type& rhs) {\n if(rhs.size() > size())\n p.resize(rhs.size());\n int sz = size();\n for(int i = 0; i < sz; i++)\n p[i] -= rhs[i];\n normalize();\n return *this;\n }\n\n type& operator*=(const type& rhs) {\n p = Mult()(p, rhs.p);\n normalize();\n return *this;\n }\n\n type& operator*=(const Field& rhs) {\n int sz = size();\n for(int i = 0; i < sz; i++)\n p[i] *= rhs;\n normalize();\n return *this;\n }\n\n type& operator/=(const Field& rhs) {\n int sz = size();\n for(int i = 0; i < sz; i++)\n p[i] /= rhs;\n normalize();\n return *this;\n }\n\n type& operator<<=(const int rhs) {\n if(rhs < 0) return *this >>= rhs;\n if(rhs == 0) return *this;\n int sz = size();\n p.resize(sz + rhs);\n for(int i = sz-1; i >= 0; i--)\n p[i + rhs] = p[i];\n fill_n(p.begin(), rhs, 0);\n return *this;\n }\n\n type& operator>>=(const int rhs) {\n if(rhs < 0) return *this <<= rhs;\n if(rhs == 0) return *this;\n int sz = size();\n if(rhs >= sz) {\n p.clear();\n return *this;\n }\n for(int i = rhs; i < sz; i++)\n p[i - rhs] = p[i];\n p.resize(sz - rhs);\n return *this;\n }\n\n type& operator%=(const int rhs) {\n if(rhs < size())\n p.resize(rhs);\n normalize();\n return *this;\n }\n\n type& operator/=(const type& rhs) {\n return *this = *this / rhs;\n }\n\n type operator%=(const type& rhs) {\n return *this = *this % rhs;\n }\n\n type operator+(const type& rhs) const {\n type res = *this;\n return res += rhs;\n }\n\n type operator-(const type& rhs) const {\n type res = *this;\n return res -= rhs;\n }\n\n type operator*(const type& rhs) const {\n return type(Mult()(p, rhs.p));\n }\n\n type operator*(const Field& rhs) const {\n type res = *this;\n return res *= rhs;\n }\n\n type operator/(const Field& rhs) const {\n type res = *this;\n return res /= rhs;\n }\n\n type operator<<(const int rhs) const {\n type res = *this;\n return res <<= rhs;\n }\n\n type operator>>(const int rhs) const {\n type res = *this;\n return res >>= rhs;\n }\n\n type operator%(const int rhs) const {\n return Polynomial(p.begin(), p.begin() + min(rhs, size()));\n }\n\n type operator/(const type& rhs) const {\n return type::divmod(*this, rhs).first;\n }\n\n type operator%(const type& rhs) const {\n return type::divmod(*this, rhs).second;\n }\n\n bool operator==(const type& rhs) const {\n normalize();\n rhs.normalize();\n return p == rhs.p;\n }\n\n type inverse() const {\n int sz = size();\n if(sz == 0)\n return type();\n if(sz == 1) {\n assert(p[0] != 0);\n return type(p[0].inverse());\n }\n type q = (*this % ((sz+1)/2)).inverse();\n q -= (*this * q % sz - type(1)) * q % sz;\n return q % sz;\n }\n\n type reciprocal() const {\n normalize();\n return type(p.rbegin(), p.rend());\n }\n\n type integral() const {\n int sz = size();\n if(sz == 0) return {};\n type res = *this;\n for(int i = sz; i; i--) {\n res[i] = res[i-1] / i;\n }\n res[0] = 0;\n res.normalize();\n return res;\n }\n\n type derivative() const {\n int sz = size();\n if(sz == 0) return {};\n type res = *this;\n for(int i = 0; i + 1 < sz; i++) {\n res[i] = res[i+1] * (i + 1);\n }\n res.p.back() = 0;\n res.normalize();\n return res;\n }\n\n static pair divmod(const type& a, const type& b) {\n if(NaiveMod) return naive_divmod(a, b);\n a.normalize();\n b.normalize();\n int m = a.size();\n int n = b.size();\n if(m < n) return {Polynomial(), a};\n type ar = a.reciprocal();\n type bri = (b.reciprocal() % (m - n + 1)).inverse();\n type q = (ar * bri % (m - n + 1)).reciprocal();\n type r = a - b * q;\n\n if(r.degree() >= b.degree()) {\n q += divmod(r, b).first;\n r = a - b * q;\n }\n\n return {q, r};\n }\n\n static pair naive_divmod(const type& a, const type& b) {\n type res = a;\n int a_deg = a.degree();\n int b_deg = b.degree();\n Field normalizer = Field(1) / b[b_deg];\n for(int i = 0; i < a_deg-b_deg+1; i++) {\n Field coef = (res[a_deg - i] *= normalizer);\n if(coef != 0) {\n for(int j = 1; j <= b_deg; j++) {\n res[a_deg - i - j] += -b[b_deg - j] * coef;\n }\n }\n }\n return {res >> b_deg, res % b_deg};\n }\n\n static type power(const type& a, long long n, const int mod) {\n return math::generic_power(a, n, DefaultPowerOp(mod));\n }\n\n static type power(const type& a, long long n, const type& mod) {\n return math::generic_power(a, n, ModPowerOp(mod));\n }\n\n static type kth(int K) {\n return type(1) << K;\n }\n\n static type kth(long long K, const type& mod) {\n return math::generic_power(type(1) << 1, K, ModShiftPowerOp(mod));\n }\n\n friend ostream& operator<<(ostream& output, const type& var) {\n output << \"[\";\n int sz = var.size();\n for(int i = sz-1; i >= 0; i--) {\n output << var[i];\n if(i) output << \" \";\n }\n return output << \"]\";\n }\n };\n} // namespace poly\n/// keep caide\nusing poly::Polynomial;\n} // namespace math\n} // namespace lib\n\n#endif\n#ifndef _LIB_LINEAR_RECURRENCE\n#define _LIB_LINEAR_RECURRENCE\n#include \n\nnamespace lib {\n using namespace std;\nnamespace linalg {\n namespace {\n using traits::IsRandomIterator;\n using traits::HasRandomIterator;\n }\n\n template\n struct BMSolver {\n typedef BMSolver

type;\n typedef typename P::field field_type;\n typedef P poly_type;\n\n vector base;\n vector T;\n \n template<\n typename Iterator,\n typename enable_if::value>::type* = nullptr>\n void solve(Iterator begin, Iterator end) {\n auto get = [begin](int i) { return *(begin + i); };\n\n int n = distance(begin, end);\n \n vector C = {1}, B = {1};\n field_type b = 1;\n int L = 0;\n\n for(int i = 0, x = 1; i < n; i++, x++) {\n // evaluate new element\n field_type d = 0;\n for(size_t j = 0; j < C.size(); j++)\n d += get(i-j) * C[j];\n if(d == 0) continue;\n if(2 * L <= i) {\n auto tmp = C;\n if(C.size() < B.size() + x)\n C.resize(B.size() + x);\n field_type coef = d / b;\n for(size_t j = 0; j < B.size(); j++)\n C[j + x] -= coef * B[j];\n L = i + 1 - L;\n B = tmp;\n b = d;\n x = 0;\n } else {\n if(C.size() < B.size() + x)\n C.resize(B.size() + x);\n field_type coef = d / b;\n for(size_t j = 0; j < B.size(); j++)\n C[j + x] -= coef * B[j];\n }\n }\n\n T = vector((int)C.size() - 1);\n for(size_t i = 0; i < T.size(); i++) T[i] = -C[i+1];\n base = vector(begin, end);\n }\n\n template<\n typename Container,\n typename enable_if::value>::type* = nullptr>\n void solve(const Container& container) {\n solve(container.begin(), container.end());\n }\n\n void solve(const initializer_list& l) {\n solve(l.begin(), l.end());\n }\n\n bool solved() const {\n return T.size() > 0 && base.size() >= T.size();\n }\n\n void ensure(int nsz) const {\n auto* self = const_cast(this);\n for(int j = base.size(); j < nsz; j++) {\n field_type acc = 0;\n for(int i = 0; i < (int)T.size(); i++)\n acc += base[j - i - 1] * T[i];\n self->base.push_back(acc);\n }\n }\n\n poly_type mod_function() const {\n poly_type res;\n int m = T.size();\n res[m] = 1;\n for(int i = 0; i < m; i++)\n res[i] = -T[m-i-1];\n return res;\n }\n\n vector compute(long long K, int n) {\n assert(n > 0);\n assert(solved());\n vector res;\n int N = T.size();\n int cons = min(n, N);\n\n if(K < (int)base.size()) {\n for(int j = 0; j < n && K + j < (int)base.size(); j++)\n res.push_back({base[K + j]});\n\n while((int)res.size() < cons) {\n field_type acc = 0;\n int sz = res.size();\n int mid = min(sz, N);\n for(int i = 0; i < mid; i++)\n acc += res[sz - i - 1] * T[i];\n sz = base.size();\n for(int i = mid; i < N; i++)\n acc += base[sz - 1 - (i - mid)] * T[i];\n res.push_back(acc);\n }\n } else {\n ensure(cons + N - 1);\n\n poly_type x = poly_type::kth(K, mod_function());\n\n for(int j = 0; j < cons; j++) {\n field_type acc = 0;\n for(int i = 0; i < N; i++)\n acc += x[i] * base[i + j];\n res.push_back(acc);\n }\n }\n\n for(int j = res.size(); j < n; j++) {\n field_type acc = 0;\n for(int i = 0; i < N; i++)\n acc += res[j - i - 1] * T[i];\n res.push_back(acc);\n }\n return res;\n }\n\n field_type compute(long long K) {\n return compute(K, 1)[0];\n }\n };\n} // namespace linalg\n} // namespace lib\n\n#endif\n#ifndef _LIB_LONG_MULTIPLICATION\n#define _LIB_LONG_MULTIPLICATION\n#include \n\nnamespace lib {\n using namespace std;\nnamespace math {\n struct NaiveMultiplication {\n template\n vector operator()(const vector& a, const vector& b) const {\n vector res(a.size() + b.size());\n for(size_t i = 0; i < a.size(); i++) {\n for(size_t j = 0; j < b.size(); j++) {\n res[i + j] += a[i] * b[j];\n }\n }\n return res;\n }\n };\n\n template\n vector shift_conv(const vector& a, const vector b) {\n if(b.empty()) return {};\n reverse(b.begin(), b.end());\n int n = a.size();\n int m = b.size();\n\n auto res = Mult()(a, b);\n return vector(res.begin() + m - 1, res.end());\n }\n} // namespace math\n} // namespace lib\n\n#endif\nusing namespace std;\n\n#define mp make_pair\n#define mt make_tuple\n#define pb push_back\n#define ms(v, x) memset((v), (x), sizeof(v))\n#define all(v) (v).begin(), (v).end()\n#define ff first\n#define ss second\n#define iopt ios::sync_with_stdio(false); cin.tie(0)\n\nint gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); }\nint power(int x, int p, int MOD) {\n if(p == 0) return 1%MOD;\n if(p == 1) return x%MOD;\n int res = power(x, p/2, MOD);\n res = (long long)res*res%MOD;\n if(p&1) res = (long long)res*x%MOD;\n return res;\n}\n\ntypedef pair ii;\ntypedef long double LD;\ntypedef vector vi;\n\nusing namespace lib;\n\nconst int MOD = (int)10007;\nusing Field = Mint32;\nusing Poly = math::Polynomial;\n\nconst int N = 202;\nField dp[N][N][10*N];\nbool ok[N][N][10*N];\nstring s;\n\nField go(int left, int right, int i) {\n if(i < 0) return 0;\n if(i == 0 && left >= right) return 1;\n Field & res = dp[left][right][i];\n if(ok[left][right][i]) return res;\n res = 0;\n\n if(left >= right) {\n res += go(left, right, max(i - 2, 0)) * 26;\n } else if (left + 1 == right) {\n if(i == 0) res += go(left + 1, right - 1, i);\n else res += go(left + 1, right, i - 1);\n res += go(left, right, i - 2) * 25;\n } else {\n if(s[left] == s[right - 1]) {\n res += go(left + 1, right - 1, i);\n res += go(left, right, i - 2) * 25;\n } else {\n res += go(left + 1, right, i - 1);\n res += go(left, right - 1, i - 1);\n res += go(left, right, i - 2) * 24;\n }\n }\n\n ok[left][right][i] = true;\n return res;\n}\n\nint32_t main(){\n linalg::BMSolver solver;\n vector base;\n cin >> s;\n int n;\n cin >> n;\n\n for(size_t i = 0; i < 10 * s.size(); i++) {\n base.pb(go(0, s.size(), i));\n }\n\n solver.solve(base);\n cout << solver.compute(n) << endl;\n}\n", "lang_cluster": "C++", "tags": ["matrices", "strings", "dp", "combinatorics"], "code_uid": "0950157dc6ca6a540057a2a3e4cb4e36", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8", "difficulty": 3000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\nusing namespace std;\nint main(){\n int no,moon;\n vector v;\n cin>>no;\n for(int i=0;i>moon;\n v.push_back(moon);\n }\n if(no==1){\n if(v[0]==15){\n cout<<\"DOWN\";\n }\n else if(v[0]==0){\n cout<<\"UP\";\n }\n else{\n cout<<\"-1\";\n }\n }\n else if(v[no-1]==15){\n cout<<\"DOWN\";\n }\n else if(v[no-1]==0){\n cout<<\"UP\";\n }\n else if(v[no-1]>v[no-2]){\n cout<<\"UP\";\n }\n else{\n cout<<\"DOWN\";\n }\n \n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "26d9baefbde7faaf43c131edb2b0c0a3", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint main()\n{\n int x,s;\n cin>>x>>s;\n if(x>s)\n {\n x-=s;\n cout<\n#include \n#define SZ(x) ((int)(x).size())\n#define ALL(c) begin(c),end(c)\n#define REP(i,n) for ( int i=0; i<(int)(n); i++ )\n#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )\n#define FOR(it,c) for (auto it=begin(c); it!=end(c); it++)\n#define MP make_pair\n#define PB push_back\nusing namespace std;\ntypedef pair PII;\ntypedef vector VI;\ntypedef long long LL;\n\nvoid RI() {}\n\ntemplate\nvoid RI( int& head, T&... tail ) {\n scanf(\"%d\",&head);\n RI(tail...);\n}\n/// }}}\n\n#define N 150010\n\nVI fac[N];\nint cnt[N];\nvoid predo() {\n for ( int i=2; i>n>>m>>l>>r>>p;\n LL ans=0;\n for ( LL dx=1; dx<=n && dx*dx<=r*r; dx++ ) {\n LL ly=dx>=l ? 0 : sqrt(l*l-dx*dx);\n LL ry=sqrt(r*r-dx*dx);\n while ( ly==0 || dx*dx+ly*lyr*r ) ry--;\n if ( ry>m ) ry=m;\n if ( ly>ry ) continue;\n ans+=(n+1-dx)*shik(m+1-ry,m+1-ly)%p;\n for (auto f : fac[dx]) {\n LL lly=(ly+f-1)/f;\n LL rry=ry/f;\n if ( lly>rry ) continue;\n LL now=cnt[f]*(n+1-dx)*shik(m+1-f*rry,m+1-f*lly,f)%p;\n ans+=now;\n }\n }\n ans*=2;\n if ( l==1 ) {\n ans+=(n+1)*m%p;\n ans+=n*(m+1)%p;\n }\n ans%=p;\n if ( ans<0 ) ans+=p;\n cout<\nusing namespace std;\nint main()\n{\nlong int a,b;\nb=2;\ncin>>a;\nwhile(a>1)\n {\n if(a%b!=0)\n b++;\n else{cout<\nusing namespace std;\n\n// #defines\n#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)\n#define sz(x) ((int)(x).size())\n#define ms0(x) memset(x,0,sizeof(x))\n#define ms1(x) memset(x,-1,sizeof(x))\n#define max(a,b) (a>b?a:b)\n#define min(a,b) (a pii;\ntypedef long long ll;\ntypedef unsigned long long ull;\nconst double eps = 1e-9;\nconst double pi = acos(-1.0);\nconst int maxn = (int)1e5 + 10;\nconst int mod = (int)1e9;\nint fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }\nint fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }\n\nint main()\n{\n ll k,b,n,t,z;\n cin>>k>>b>>n>>t;\n z=1;\n while(t>=z*k+b)\n {\n z=z*k+b;\n n--;\n // cout<0?n:0)<\nusing namespace std;\n#define M 105\n#define MOD 1000000007\ntypedef long long ll;\n\nll powi(ll a, ll b)\n{\n if(!b) return 1;\n\n ll p = powi(a, b/2);\n p = (p*p)%MOD;\n if(b&1) p = (p*a)%MOD;\n\n return p;\n}\n\nll len[M];\nll po2[M];\nll dp[M][M][M];\n\nint main()\n{\n ios::sync_with_stdio(false);\n cin.tie(0);\n\n len[0] = len[1] = 1;\n for(int i = 2; i < M; i++) len[i] = (len[i-1]+len[i-2])%(MOD-1);\n\n for(int i = 0; i < M; i++) po2[i] = powi(2, len[i]);\n\n int n, x;\n cin>>n>>x;\n\n string s;\n cin>>s;\n\n for(int idx = 0; idx <= x; idx++)\n {\n for(int i = 2; i <= n; i++) dp[idx][i][i-1] = 1;\n dp[idx][1][0] = dp[idx][n+1][n] = po2[idx];\n }\n\n for(int i = 1; i <= n; i++) dp[s[i-1]-'0'][i][i] = 1;\n\n for(int idx = 2; idx <= x; idx++)\n {\n for(int i = 1; i <= n; i++)\n {\n for(int j = i; j <= n; j++)\n {\n for(int k = i; k <= j+1; k++)\n {\n dp[idx][i][j] += dp[idx-1][i][k-1]*dp[idx-2][k][j];\n dp[idx][i][j] %= MOD;\n }\n }\n }\n }\n\n cout<\n#include\n#include\n#include\n#include \nusing namespace std;\n\nstruct Pair{\n\nstring colour{\" \"};\nstring name{\" \"};};\n\nint last(int a[],int m , int n){\n int j=0;\n for(int i =0;i>n>>m>>c;\n\nlong long int sum = 0;\nsum = sum + 2*c;\nif(n\n#include\n//Containers\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n//C library\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n//Miscellaneous\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\n//#include\n//#include\n\n#define endl '\\n'\n#define rep(i, a, b) for(int i=(a); i<(b); i++)\n#define repi(i, a, b) for(int i=(a); i>(b); i--)\n#define db(x) (cerr << #x << \": \" << (x) << '\\n')\n#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)\n#define tests(t) int t; cin >> t; while(t--)\n#define iceil(n, x) (((n) + (x) - 1) / (x))\n#define ll long long\n#define gcd __gcd\n#define pb push_back\n#define pf push_front\n#define pob pop_back\n#define pof pop_front\n#define sz size()\n#define all(v) (v).begin(), (v).end()\n#define uni(v) sort(all(v)); (v).erase(unique(all(v)), (v).end());\n#define pii pair\n#define vi vector\n#define vpii vector\n#define vvi vector\n#define fi first\n#define se second\n#define umap unordered_map\n#define uset unordered_set\n#define pqueue priority_queue\n#define si(a) scanf(\"%d\", &a)\n#define sll(a) scanf(\"%lld\", &a)\n#define bitcount(x) __builtin_popcount(x)\n#define cps CLOCKS_PER_SEC\n#define PI acos(-1.0)\n#define EPS 1e-9\n#define mod 1000000007\n#define MOD 1000000007\n#define N 100005\nusing namespace std;\n\n#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate \nvoid __f(const char* name, Arg1&& arg1){\n cerr << name << \" : \" << arg1 << '\\n';\n}\ntemplate \nvoid __f(const char* names, Arg1&& arg1, Args&&... args){\n const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << \" : \" << arg1<<\" | \";__f(comma+1, args...);\n}\n\ntemplate\nusing minpq = priority_queue, greater>;\n\ntemplate\nusing maxpq = priority_queue;\n\n//All indexing is 0-based\n//using namespace __gnu_pbds;\n//typedef tree, rb_tree_tag,\n //tree_order_statistics_node_update> ordered_set;\n//methods: find_by_order(k); & order_of_key(k);\n//To make it an ordered_multiset, use pairs of (value, time_of_insertion)\n//to distinguish values which are similar.\n\n//Returns no. of values x for which ceil(n / x) == y (y must be > 1).\ninline ll CC(ll n, ll y) { return iceil(n, y-1) - iceil(n, y); }\n\n//Returns no. of values x for which floor(n / x) == y\ninline ll FF(ll n, ll y) { return n / y - n / (y+1); }\n\ninline ll gcd(ll a, ll b) { return !b ? a: gcd(b, a%b); }\n\n//a and b are assumed to be taken modulo p\ninline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c;}\ninline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c;}\ninline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p;}\n\n#define int ll\n//#define trace(...) 42\n\nint a, b, k, L;\n\nint lcm(int a, int b) {\n return a / gcd(a, b) * b;\n}\n\nint bfs(int src, int dest) {\n trace(src, dest);\n queue q;\n vector vis (src - dest+ 1);\n q.push(src); q.push(0);\n vis[src-dest] = 1;\n while(1) {\n int u = q.front(); q.pop();\n int d = q.front(); q.pop();\n //trace(u, d);\n if(u == dest) return d;\n if(!vis[u-1-dest]) q.push(u-1), q.push(d+1);\n for(int i = 2; i <= k; i++) {\n int v = u / i * i;\n if(v >= dest && !vis[v - dest]) {\n vis[v - dest] = 1;\n q.push(v); q.push(d+1);\n }\n }\n }\n}\n\nint32_t main()\n{ \n #ifndef ONLINE_JUDGE\n freopen(\"/storage/emulated/0/input.txt\", \"r\", stdin);\n // freopen(\"/storage/emulated/output.txt\", \"w\", stdout);\n #endif\n sync;\n clock_t clk = clock();\n cerr << \"I will return...\\n\";\n \n cin >> a >> b >> k;\n if(k == 2) {\n cout << a - b; return 0;\n }\n \n L = 1;\n rep(i, 2, k+1) L = lcm(L, i);\n int ans = 0;\n int cnt = a/L - (b-1)/L;\n trace(L, cnt);\n if(cnt) {\n int m = bfs(L, 0);\n ans = m*(cnt-1);\n trace(ans);\n }\n if(!cnt) {\n ans += bfs(a, b);\n trace(ans);\n }\n else {\n ans += bfs(a, a/L*L);\n ans += bfs(iceil(b, L)*L, b);\n trace(ans);\n }\n cout << ans << endl; \n\n cerr << \"...don't you ever hang your head.\\n\";\n cerr << \"Time (in ms): \" << double(clock() - clk) * 1000.0 / cps << '\\n';\n}\n\n//Compile using:\n//g++ -o filename.exe --std=c++11 filename.cpp\n//Use -D CP for defining a macro CP in the local environment\n\n\n\n\n", "lang_cluster": "C++", "tags": ["dp", "number theory"], "code_uid": "e2f30a4fe5540239b8ad94ee33e8804e", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \r\n#include \r\nusing LL = long long;\r\nconst int N = 1e5 + 100, P = 1e9 + 7;\r\nint n, num;\r\nint fac[N], ifac[N];\r\nint ans = 0;\r\nint qpow(int x, int y = P - 2)\r\n{\r\n int res = 1;\r\n for (; y; y >>= 1, x = LL(x) * x % P) if (y & 1) res = LL(x) * res % P;\r\n return res;\r\n}\r\nvoid adj(int &x){ x += (x >> 31) & P; }\r\nint C(int x, int y){ return LL(fac[x]) * ifac[y] % P * ifac[x - y] % P; }\r\nint main()\r\n{\r\n scanf(\"%d %d\", &n, &num);\r\n fac[0] = fac[1] = ifac[0] = ifac[1] = 1;\r\n for (int i = 2; i <= n; ++i) fac[i] = LL(i) * fac[i - 1] % P;\r\n ifac[n] = qpow(fac[n]);\r\n for (int i = n - 1; i > 1; --i) ifac[i] = LL(i + 1) * ifac[i + 1] % P;\r\n num = std::min(n, num);\r\n for (int i = 0; i <= num; ++i) adj(ans += C(n, i) - P);\r\n printf(\"%d\\n\", ans);\r\n return 0;\r\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "c6e1ff7395ad17c517fdc7c1a57ad8fb", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\n#define mod 1000000007\n#define ll long long int\n#define mk make_pair\n#define pb push_back\n#define xx first\n#define yy second\n#define ar array\n#define del 1e-7\n\ntemplate static inline void amin(T &x, U y){ if(y static inline void amax(T &x, U y){ if(x>T;\n\twhile(T--){\n ll n;\n cin>>n;\n ll ans=0;\n ll p[10]={};\n for(int i=1;i<=n;i++){\n p[i%9 + 9*(i%9==0)]++;\n }\n for(int i=1;i<=9;i++){\n for(int j=1;j<=9;j++){\n ll x=p[i],y=p[j],z=p[(i*j)%9 + 9*((i*j)%9==0)];\n // cout<\n#define ll long long\n#define MAX 100000000000000007\n#define MIN -100000000000000007\n#define pb push_back\n#define X 100000\nusing namespace std ;\n\n\nint main()\n{\n ios::sync_with_stdio(false);\n\n long long x = 0 , y , a , n ,b , c , p ;\n cin >> n >> b >> p;\n y = n * p ;\n for(int i = 0 ; ; ++ i )\n {\n if( n == 1)\n break ;\n long long j = 1 ;\n while( j<= n )\n j *= 2 ;\n\n j /= 2;\n //cout << j << \" \" ;\n\n x += (j / 2) * ( b * 2 + 1) ;\n\n n = n - j + j / 2 ;\n }\n cout << x << \" \" << y << \" \" ;\n return 0 ;\n\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "2b5fba603df179ec6b32fb99516a9420", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#ifdef DEBUG\n#define _GLIBCXX_DEBUG\n#endif\n//#pragma GCC optimize(\"O3\")\n#include \nusing namespace std;\ntypedef long double ld;\ntypedef long long ll;\nint k;\nll f[6];\nint dig[6];\nconst int maxN = 1e6 + 10;\nll dp[maxN];\nll combine(ll x, ll y) {\n return max(x, y);\n}\n\nconst ll INF = 1e17;\nstruct Tqueue{\n vector < ll > st1, st2;\n vector < ll > data;\n Tqueue() {\n st1 = {-INF};\n st2 = {-INF};\n }\n void add(ll x) {\n data.emplace_back(x);\n st1.emplace_back(combine(x, st1.back()));\n }\n void del() {\n if (st2.size() > 1) {\n st2.pop_back();\n }\n else {\n assert(st1.size() > 1);\n st1.resize(1);\n\n for (int i = data.size() - 1; i >= 0; i--) {\n st2.emplace_back(combine(st2.back(), data[i]));\n }\n data.clear();\n st2.pop_back();\n }\n }\n ll get() {\n return combine(st1.back(), st2.back());\n }\n};\nll ndp[maxN];\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n// freopen(\"input.txt\", \"r\", stdin);\n cin >> k;\n for (int i = 0; i < 6; i++) {\n cin >> f[i];\n }\n int q;\n cin >> q;\n assert(q == 1);\n int n;\n cin >> n;\n int tn = n;\n for (int i = 0; i < 6; i++) {\n dig[i] = (tn % 10);\n tn /= 10;\n }\n for (int j = 0; j <= n; j++) dp[j] = -INF;\n dp[0] = 0;\n for (int i = 0; i < 6; i++) {\n for (int j = 0; j <= n; j++) {\n ndp[j] = -INF;\n }\n vector r(3);\n for (int j = 0; j <= n; j++) {\n r[j % 3].add(dp[j] - (j / 3) * (ll)f[i]);\n if (j - 9 * (k - 1) - 3 >= 0) r[j % 3].del();\n for (int a = 0; a < 3; a++) {\n if (j % 3 >= a) {\n ndp[j] = max(ndp[j], r[a].get() + (j / 3) * f[i]);\n }\n else {\n ndp[j] = max(ndp[j], r[a].get() + (j / 3) * f[i] - f[i]);\n }\n }\n }\n for (int j = 0; j <= n; j++) {\n for (int cnt = 9 * (k - 1) + 1; cnt <= 9 * k; cnt++) {\n if (j >= cnt) {\n if (cnt % 3 == 0) {\n ndp[j] = max(ndp[j], dp[j - cnt] + (cnt / 3) * f[i]);\n }\n else {\n //??\n ndp[j] = max(ndp[j], dp[j - cnt] + (3 * (k - 1)) * f[i]);\n }\n }\n }\n }\n for (int j = 0; j <= n; j++) {\n dp[j] = -INF;\n }\n for (int j = 0; j <= n; j++) {\n if (j % 10 == dig[i]) {\n dp[j / 10] = ndp[j];\n }\n }\n }\n cout << dp[0] << '\\n';\n return 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "dp"], "code_uid": "cbc56b32777fe3b129c0ffb5dd4908ea", "src_uid": "92bcbac3f167a44c235e99afc4de20d2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n\nusing namespace std;\n\nint main(){\n string a,b;\n\n cin >> a >> b;\n\n for(int i = 0; i < a.size(); i++)\n {\n \tif(a[i] != b[i])\n \t\tcout << '1';\n \telse\n \t\tcout << '0';\n }\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "1af13f613989b261466aaf577d16ab2c", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\nint main()\n\n{\n long long int n;\n cin >> n;\n if(n % 2 == 0)\n cout << \"Mahmoud\" << endl;\n else\n cout << \"Ehab\" << endl;\n\n}\n", "lang_cluster": "C++", "tags": ["math", "games"], "code_uid": "afb627ba0d3e490c60ab105e1de8fd77", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define f first\n#define s second\n#define ll long long\n#define ull unsigned long long\n#define mp make_pair\n#define pb push_back\n#define vi vector \n#define ld long double\n#define pii pair\nusing namespace std; \nconst int N = int(3e5), mod = int(1e9) + 7;\n\nint n,k;\n\nll f[N];\nbool u[30];\nint a[30];\nint ans;\n\nbool check(int n){\n\twhile(n){\n\t\tif(n % 10 != 7 && n % 10 != 4) return 0;\n\t\tn /= 10;\n\t}\n\treturn 1;\n}\n\nvoid rec(ll v){\n\tif(v > mod) return;\n\tif(v < n) ans++;\n\trec(v * 10 + 4);\n\trec(v * 10 + 7);\n}\n\nint main () {\n\tcin >> n >> k;\n\tf[0] = 1;\n\tfor(int i = 1; i <= 20; i++) f[i] = f[i - 1] * i;\n\tll res = 1;\n\tfor(int i = 1; i <= n; i++){\n\t\tres = res * i;\n\t\tif(res > k) break;\n\t} \n\tif(res < k){\n\t\tcout << -1;\n\t\treturn 0;\n\t}\n\tif(n <= 20){\n\t\tfor(int i = 1; i <= n; i++){\n\t\t\tint cur = 0;\n\t\t\tfor(int j = 1; j <= n; j++) if(!u[j]){\n\t\t\t\tcur++;\n\t\t\t\tif(cur * f[n - i] >= k){\n\t\t\t\t\ta[i] = j;\n\t\t\t\t\tu[j] = 1;\n\t\t\t\t\tk -= (cur - 1) * f[n - i];\n\t\t\t\t\tbreak;\t\n\t\t\t\t}\t\t\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i <= n; i++){\n\t\t\tif(check(i) && check(a[i])) ans++;\n\t\t}\n\t\tcout << ans;\n\t\treturn 0;\n\t}\n\tfor(int i = 1; i <= 13; i++){\n\t\tint cur = 0;\n\t\tfor(int j = 1; j <= 13; j++) if(!u[j]){\n\t\t\tcur++;\n\t\t\tif(cur * f[13 - i] >= k){\n\t\t\t\ta[i] = j;\n\t\t\t\tu[j] = 1;\n\t\t\t\tk -= (cur - 1) * f[13 - i];\n\t\t\t\tbreak;\t\n\t\t\t}\t\t\n\t\t}\n\t}\n\tfor(int i = 1; i <= 13; i++){\n\t\tif(check(n - 13 + i) && check(a[i] + n - 13)) {\n\t\t\tans++;\n\t\t}\n\t}\n\tn -= 13;\n\trec(4);\n\trec(7);\n\tcout << ans;\n\nreturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "combinatorics", "number theory"], "code_uid": "7854882cfcb06598a331264e8772e2ad", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \r\n\r\nconstexpr int P = 998244353;\r\n\r\nusing int64 = long long;\r\n\r\nint norm(int x) {\r\n if (x < 0) x += P;\r\n if (x >= P) x -= P;\r\n return x;\r\n}\r\n\r\ntemplate \r\nT power(T a, int b) {\r\n T res = 1;\r\n for (; b; b /= 2, a *= a) {\r\n if (b % 2) res *= a;\r\n }\r\n return res;\r\n}\r\n\r\nstruct Z {\r\n int x;\r\n Z(int x = 0) : x(norm(x)) {}\r\n int val() const { return x; }\r\n Z operator-() const { return Z(norm(P - x)); }\r\n Z inv() const {\r\n assert(x != 0);\r\n return power(*this, P - 2);\r\n }\r\n Z &operator*=(const Z &rhs) {\r\n x = int64(x) * rhs.x % P;\r\n return *this;\r\n }\r\n Z &operator+=(const Z &rhs) {\r\n x = norm(x + rhs.x);\r\n return *this;\r\n }\r\n Z &operator-=(const Z &rhs) {\r\n x = norm(x - rhs.x);\r\n return *this;\r\n }\r\n Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }\r\n friend Z operator*(const Z &lhs, const Z &rhs) {\r\n Z res = lhs;\r\n res *= rhs;\r\n return res;\r\n }\r\n friend Z operator+(const Z &lhs, const Z &rhs) {\r\n Z res = lhs;\r\n res += rhs;\r\n return res;\r\n }\r\n friend Z operator-(const Z &lhs, const Z &rhs) {\r\n Z res = lhs;\r\n res -= rhs;\r\n return res;\r\n }\r\n friend Z operator/(const Z &lhs, const Z &rhs) {\r\n Z res = lhs;\r\n res /= rhs;\r\n return res;\r\n }\r\n friend std::istream &operator>>(std::istream &is, Z &a) {\r\n int64 v;\r\n is >> v;\r\n a = Z(v);\r\n return is;\r\n }\r\n friend std::ostream &operator<<(std::ostream &os, const Z &a) { return os << a.val(); }\r\n};\r\n\r\nstd::vector rev;\r\nstd::vector roots{0, 1};\r\n\r\nvoid dft(std::vector &a) {\r\n int n = a.size();\r\n if (int(rev.size()) != n) {\r\n int k = __builtin_ctz(n) - 1;\r\n rev.resize(n);\r\n for (int i = 0; i < n; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << k;\r\n }\r\n for (int i = 0; i < n; ++i) {\r\n if (rev[i] < i) std::swap(a[i], a[rev[i]]);\r\n }\r\n if (int(roots.size()) < n) {\r\n int k = __builtin_ctz(roots.size());\r\n roots.resize(n);\r\n while ((1 << k) < n) {\r\n Z e = power(Z(3), (P - 1) >> (k + 1));\r\n for (int i = 1 << (k - 1); i < (1 << k); ++i) {\r\n roots[2 * i] = roots[i];\r\n roots[2 * i + 1] = roots[i] * e;\r\n }\r\n k++;\r\n }\r\n }\r\n for (int k = 1; k < n; k *= 2) {\r\n for (int i = 0; i < n; i += 2 * k) {\r\n for (int j = 0; j < k; ++j) {\r\n Z u = a[i + j];\r\n Z v = a[i + j + k] * roots[k + j];\r\n a[i + j] = u + v;\r\n a[i + j + k] = u - v;\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid idft(std::vector &a) {\r\n int n = a.size();\r\n std::reverse(a.begin() + 1, a.end());\r\n dft(a);\r\n Z inv = (1 - P) / n;\r\n for (int i = 0; i < n; ++i) {\r\n a[i] *= inv;\r\n }\r\n}\r\n\r\nstruct Poly {\r\n std::vector a;\r\n Poly() {}\r\n Poly(const std::vector &a) : a(a) {}\r\n Poly(const std::initializer_list &a) : a(a) {}\r\n int size() const { return a.size(); }\r\n void resize(int n) { a.resize(n); }\r\n Z operator[](int idx) const {\r\n if (idx < size()) {\r\n return a[idx];\r\n } else {\r\n return 0;\r\n }\r\n }\r\n Z &operator[](int idx) { return a[idx]; }\r\n Poly mulxk(int k) const {\r\n auto b = a;\r\n b.insert(b.begin(), k, 0);\r\n return Poly(b);\r\n }\r\n Poly modxk(int k) const {\r\n k = std::min(k, size());\r\n return Poly(std::vector(a.begin(), a.begin() + k));\r\n }\r\n Poly divxk(int k) const {\r\n if (size() <= k) {\r\n return Poly();\r\n }\r\n return Poly(std::vector(a.begin() + k, a.end()));\r\n }\r\n friend Poly operator+(const Poly &a, const Poly &b) {\r\n std::vector res(std::max(a.size(), b.size()));\r\n for (int i = 0; i < int(res.size()); ++i) {\r\n res[i] = a[i] + b[i];\r\n }\r\n return Poly(res);\r\n }\r\n friend Poly operator-(const Poly &a, const Poly &b) {\r\n std::vector res(std::max(a.size(), b.size()));\r\n for (int i = 0; i < int(res.size()); ++i) {\r\n res[i] = a[i] - b[i];\r\n }\r\n return Poly(res);\r\n }\r\n friend Poly operator*(Poly a, Poly b) {\r\n if (a.size() == 0 || b.size() == 0) {\r\n return Poly();\r\n }\r\n int sz = 1, tot = a.size() + b.size() - 1;\r\n while (sz < tot) {\r\n sz *= 2;\r\n }\r\n a.a.resize(sz);\r\n b.a.resize(sz);\r\n dft(a.a);\r\n dft(b.a);\r\n for (int i = 0; i < sz; ++i) {\r\n a.a[i] = a[i] * b[i];\r\n }\r\n idft(a.a);\r\n a.resize(tot);\r\n return a;\r\n }\r\n friend Poly operator*(Z a, Poly b) {\r\n for (int i = 0; i < int(b.size()); ++i) {\r\n b[i] *= a;\r\n }\r\n return b;\r\n }\r\n friend Poly operator*(Poly a, Z b) {\r\n for (int i = 0; i < int(a.size()); ++i) {\r\n a[i] *= b;\r\n }\r\n return a;\r\n }\r\n Poly &operator+=(Poly b) { return (*this) = (*this) + b; }\r\n Poly &operator-=(Poly b) { return (*this) = (*this) - b; }\r\n Poly &operator*=(Poly b) { return (*this) = (*this) * b; }\r\n Poly deriv() const {\r\n if (a.empty()) {\r\n return Poly();\r\n }\r\n std::vector res(size() - 1);\r\n for (int i = 0; i < size() - 1; ++i) {\r\n res[i] = (i + 1) * a[i + 1];\r\n }\r\n return Poly(res);\r\n }\r\n Poly integr() const {\r\n std::vector res(size() + 1);\r\n for (int i = 0; i < size(); ++i) {\r\n res[i + 1] = a[i] / (i + 1);\r\n }\r\n return Poly(res);\r\n }\r\n Poly inv(int m) const {\r\n Poly x{a[0].inv()};\r\n int k = 1;\r\n while (k < m) {\r\n k *= 2;\r\n x = (x * (Poly{2} - modxk(k) * x)).modxk(k);\r\n }\r\n return x.modxk(m);\r\n }\r\n Poly log(int m) const { return (deriv() * inv(m)).integr().modxk(m); }\r\n Poly exp(int m) const {\r\n Poly x{1};\r\n int k = 1;\r\n while (k < m) {\r\n k *= 2;\r\n x = (x * (Poly{1} - x.log(k) + modxk(k))).modxk(k);\r\n }\r\n return x.modxk(m);\r\n }\r\n Poly pow(int k, int m) const {\r\n int i = 0;\r\n while (i < size() && a[i].val() == 0) {\r\n i++;\r\n }\r\n if (i == size() || 1LL * i * k >= m) {\r\n return Poly(std::vector(m));\r\n }\r\n Z v = a[i];\r\n auto f = divxk(i) * v.inv();\r\n return (f.log(m - i * k) * k).exp(m - i * k).mulxk(i * k) * power(v, k);\r\n }\r\n Poly sqrt(int m) const {\r\n Poly x{1};\r\n int k = 1;\r\n while (k < m) {\r\n k *= 2;\r\n x = (x + (modxk(k) * x.inv(k)).modxk(k)) * ((P + 1) / 2);\r\n }\r\n return x.modxk(m);\r\n }\r\n Poly mulT(Poly b) const {\r\n if (b.size() == 0) {\r\n return Poly();\r\n }\r\n int n = b.size();\r\n std::reverse(b.a.begin(), b.a.end());\r\n return ((*this) * b).divxk(n - 1);\r\n }\r\n std::vector eval(std::vector x) const {\r\n if (size() == 0) {\r\n return std::vector(x.size(), 0);\r\n }\r\n const int n = std::max(int(x.size()), size());\r\n std::vector q(4 * n);\r\n std::vector ans(x.size());\r\n x.resize(n);\r\n std::function build = [&](int p, int l, int r) {\r\n if (r - l == 1) {\r\n q[p] = Poly{1, -x[l]};\r\n } else {\r\n int m = (l + r) / 2;\r\n build(2 * p, l, m);\r\n build(2 * p + 1, m, r);\r\n q[p] = q[2 * p] * q[2 * p + 1];\r\n }\r\n };\r\n build(1, 0, n);\r\n std::function work = [&](int p, int l, int r, const Poly &num) {\r\n if (r - l == 1) {\r\n if (l < int(ans.size())) {\r\n ans[l] = num[0];\r\n }\r\n } else {\r\n int m = (l + r) / 2;\r\n work(2 * p, l, m, num.mulT(q[2 * p + 1]).modxk(m - l));\r\n work(2 * p + 1, m, r, num.mulT(q[2 * p]).modxk(r - m));\r\n }\r\n };\r\n work(1, 0, n, mulT(q[1].inv(n)));\r\n return ans;\r\n }\r\n};\r\n\r\nint main() {\r\n std::ios::sync_with_stdio(false);\r\n std::cin.tie(nullptr);\r\n int n, k, f;\r\n std::cin >> n >> k >> f;\r\n Poly a(std::vector(k + 1, 1));\r\n for (int i = 1; i <= n; ++i) {\r\n a = a * a;\r\n if (i < n) {\r\n for (int j = a.size() - 2; j >= 0; --j) a[j] += a[j + 1];\r\n for (int j = 0; j < a.size(); ++j) a[j] *= std::max(0, k - j + 1);\r\n for (int j = 0; j < a.size() - 1; ++j) a[j] -= a[j + 1];\r\n a.resize(k + 1);\r\n }\r\n }\r\n std::cout << (f < a.size() ? a[f] : 0) << \"\\n\";\r\n return 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["brute force", "flows", "math", "dp", "fft", "bitmasks", "graphs", "meet-in-the-middle", "trees"], "code_uid": "7fe7c453d768d08866769ee590dfc857", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n\nusing namespace std;\n\nint main()\n{\n char s[101];\n cin.get(s,101);\n if(2==strlen(s))\n {\n if('V'==s[0] || ('K'==s[0] && s[1]==s[0]))\n cout<<1;\n else cout<<0;\n return 0;\n }\n short nr=0;\n bool ok=0;\n for(char i=1;i\r\nusing namespace std;\r\n\r\n//#define Fread\r\n#define Getmod\r\n\r\n#ifdef Fread\r\nchar buf[1 << 21], *iS, *iT;\r\n#define gc() (iS == iT ? (iT = (iS = buf) + fread (buf, 1, 1 << 21, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)\r\n#define getchar gc\r\n#endif // Fread\r\n\r\ntemplate \r\nvoid r1(T &x) {\r\n\tx = 0;\r\n\tchar c(getchar());\r\n\tint f(1);\r\n\tfor(; c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;\r\n\tfor(; '0' <= c && c <= '9';c = getchar()) x = (x * 10) + (c ^ 48);\r\n\tx *= f;\r\n}\r\n\r\n#ifdef Getmod\r\nconst int mod = 998244353;\r\ntemplate \r\nstruct typemod {\r\n int z;\r\n typemod(int a = 0) : z(a) {}\r\n inline int inc(int a,int b) const {return a += b - mod, a + ((a >> 31) & mod);}\r\n inline int dec(int a,int b) const {return a -= b, a + ((a >> 31) & mod);}\r\n inline int mul(int a,int b) const {return 1ll * a * b % mod;}\r\n typemod operator + (const typemod &x) const {return typemod(inc(z, x.z));}\r\n typemod operator - (const typemod &x) const {return typemod(dec(z, x.z));}\r\n typemod operator * (const typemod &x) const {return typemod(mul(z, x.z));}\r\n typemod& operator += (const typemod &x) {*this = *this + x; return *this;}\r\n typemod& operator -= (const typemod &x) {*this = *this - x; return *this;}\r\n typemod& operator *= (const typemod &x) {*this = *this * x; return *this;}\r\n int operator == (const typemod &x) const {return x.z == z;}\r\n int operator != (const typemod &x) const {return x.z != z;}\r\n};\r\ntypedef typemod Tm;\r\n#endif\r\nconst Tm G = 3, invG = 332748118;\r\ntemplate inline void r1(T& t, Args&... args) {\r\n r1(t); r1(args...);\r\n}\r\n\r\n//#define int long long\r\nconst int maxn = 4e5 + 5;\r\nconst int maxm = maxn << 1;\r\n\r\nTm tmp[maxn], Sl[maxn], Sr[maxn], fac[maxn], inv[maxn], C[maxn];\r\nint rev[maxn];\r\nint lim, len;\r\nvoid getrev(int x) {\r\n lim = 1, len = 0;\r\n while(lim <= x) lim <<= 1, ++ len;\r\n for(int i = 0; i < lim; ++ i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (len - 1));\r\n}\r\n\r\nTm ksm(Tm x,int mi) {\r\n if(mi < 0) return 0;\r\n Tm res(1);\r\n while(mi) {\r\n if(mi & 1) res *= x;\r\n mi >>= 1;\r\n x *= x;\r\n }\r\n return res;\r\n}\r\n\r\nvoid NTT(Tm *A,int opt = 1) {\r\n for(int i = 0; i < lim; ++ i) if(i < rev[i]) swap(A[i], A[rev[i]]);\r\n for(int mid = 1; mid < lim; mid <<= 1) {\r\n Tm wn(ksm((opt == 1) ? G : invG, (mod - 1) / (mid << 1)));\r\n for(int j = 0, c = (mid << 1); j < lim; j += c) {\r\n Tm W(1);\r\n for(int k = 0; k < mid; ++ k, W *= wn) {\r\n Tm x = A[j + k], y = W * A[j + k + mid];\r\n A[j + k] = x + y;\r\n A[j + k + mid] = x - y;\r\n }\r\n }\r\n }\r\n if(opt != 1) {\r\n Tm z = ksm(lim, mod - 2);\r\n for(int i = 0; i < lim; ++ i) A[i] *= z;\r\n }\r\n}\r\n\r\nint n, k;\r\n\r\nsigned main() {\r\n// freopen(\"S.in\", \"r\", stdin);\r\n// freopen(\"S.out\", \"w\", stdout);\r\n int i, j;\r\n r1(n, k);\r\n Tm vis[2] = {1, mod - 1};\r\n fac[0] = 1;\r\n for(i = 1; i <= k; ++ i) fac[i] = fac[i - 1] * i;\r\n inv[k] = ksm(fac[k], mod - 2);\r\n for(i = k - 1; ~ i; -- i) inv[i] = inv[i + 1] * (i + 1);\r\n for(i = 0; i <= k; ++ i) {\r\n Sl[i] = inv[i] * vis[i & 1];\r\n Sr[i] = ksm(i, k) * inv[i];\r\n }\r\n getrev(2 * k);\r\n// printf(\"lim = %d\\n\", lim);\r\n NTT(Sl, 1), NTT(Sr, 1);\r\n for(i = 0; i < lim; ++ i) Sl[i] *= Sr[i];\r\n NTT(Sl, -1);\r\n// printf(\"s1 = %d\\n\", Sl[k].z);\r\n Sl[0] = 0;\r\n C[0] = 1;\r\n for(i = 1; i <= k; ++ i) C[i] = C[i - 1] * (n - i + 1) * ksm(i, mod - 2);\r\n// Tm x = ksm(n + 1, n);\r\n// printf(\"s0 = %d\\n\", Sl[0].z);\r\n Tm ans(0);\r\n for(i = 0; i <= k; ++ i) ans += C[i] * Sl[i] * fac[i] * ksm(n + 1, n - i);\r\n printf(\"%d\\n\", ans.z);\r\n\treturn 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["math", "combinatorics", "fft"], "code_uid": "d5120cba8c36bc534c76f63c0a787449", "src_uid": "bc57a69c39c6e74d6d81a9c504104809", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nint main()\n{\n int n,m,l=0;\n cin>>n>>m;\n char ch[n][m];\n for(int i =0;i>ch[i][j];\n if(ch[i][j]=='.')\n t++;\n }\n if(t==m)\n {\n for(int j=0;j\n\nusing namespace std;\n\n#define range(i, m, n) for(int i = m; i < n; i++)\n#define husk(i, m, n) for(int i = m; i > n; i--)\n\ntemplate \nvoid debug_out(T t) {\n cerr << t;\n}\n\ntemplate \nvoid debug_out(pair u) {\n cerr << \"(\" << u.first << \" \" << u.second << \")\";\n}\n\ntemplate \nvoid debug_out(vector t) {\n int sz = t.size();\n for(int i = 0; i < sz; i++) {\n debug_out(t[i]);\n if(i != sz - 1) cerr << \", \";\n }\n}\n\ntemplate \nvoid debug_out(vector> t) {\n int sz = t.size();\n for(int i = 0; i < sz; i++) {\n debug_out(t[i]);\n if(i != sz - 1) cerr << endl;\n }\n}\n\ntemplate \nvoid debug_out(Head H, Tail... T) {\n debug_out(H);\n cerr << \" \";\n debug_out(T...);\n}\n\n#define debug(...) cerr << \"[\" << #__VA_ARGS__ << \"]:\" << endl, debug_out(__VA_ARGS__), cerr << endl;\n\nint n;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n cin >> n;\n vector a(n);\n range(i, 0, n) cin >> a[i];\n sort(a.begin(), a.end());\n int M = a.back() + 1;\n vector to(M);\n range(i, 1, M) {\n to[i] = to[i - 1];\n while(to[i] < n && a[to[i]] < i) to[i]++;\n }\n long long res = 0;\n auto get = [&](int y, long long c, int ll, int rr) {\n if(c < 0) {\n return -1LL;\n }\n int s = c % y;\n if(s <= rr && s >= ll) {\n return c;\n }\n long long lc = y * (c / y) + ll;\n if(lc > c) lc -= y;\n long long rc = y * (c / y) + rr;\n if(rc > c) rc -= y;\n return max(-1LL, max(lc, rc));\n };\n range(y, 2, M) {\n long long sum = 0;\n vector pt;\n for(int j = 0; j < M; j += y) {\n int l = to[j];\n int r = (j + y < M ? to[j + y] - 1 : n - 1);\n if(r < l) continue;\n sum += 1LL * (r - l + 1) * j / y;\n if(r > l) pt.push_back(a[r - 1]);\n pt.push_back(a[r]);\n }\n int sz = pt.size();\n vector> dt(sz);\n husk(i, sz - 1, -1) {\n dt[i].first = pt[i] % y;\n if(i < sz - 1) {\n dt[i] = dt[i + 1];\n if(dt[i].first > (pt[i] % y)) dt[i].second = max(dt[i].second, pt[i] % y);\n else {\n swap(dt[i].first, dt[i].second);\n dt[i].first = pt[i] % y;\n }\n }\n }\n // sum - 2 * (x / y) >= x\n auto calc = [&](long long s) {\n if(s < 0) return -1LL;\n long long lo = 0, hi = sum + 1;\n while(hi - lo > 1) {\n long long mid = (hi + lo) >> 1;\n if(s - 2 * (mid / y) >= mid) lo = mid;\n else hi = mid;\n }\n return lo;\n };\n long long sa = calc(sum);\n long long sb = calc(sum - 1);\n long long sc = calc(sum - 2);\n husk(i, sz - 1, -1) {\n int sf = dt[i].first, ss = dt[i].second;\n long long x = get(y, min(1LL * pt[i], sa), 0, ss);\n if(i == sz - 1) goto A;\n if(x > 1) res = max(res, x * y);\n if(ss < sf && sum > 0) {\n x = get(y, min(1LL * pt[i], sb), ss + 1, sf);\n if(x > 1) res = max(res, x * y);\n }\n if(sf < y - 1 && sum > 0) {\n x = get(y, min(1LL * pt[i], sc), sf + 1, y - 1);\n if(x > 1) res = max(res, x * y);\n }\n A:;\n x = get(y, min(1LL * pt[i] / 2, sa), 0, sf / 2);\n if(x > 1) res = max(res, x * y);\n if((sf + y) / 2 < y && (sf / 2) + 1 <= (sf + y) / 2 && sum > 0) {\n x = get(y, min(1LL * pt[i] / 2, sb), (sf / 2) + 1, (sf + y) / 2);\n if(x > 1) res = max(res, x * y);\n if((sf + y) / 2 < y - 1 && sum > 0) {\n x = get(y, min(1LL * pt[i] / 2, sc), (sf + y) / 2 + 1, y - 1);\n if(x > 1) res = max(res, x * y);\n }\n }\n }\n }\n cout << res;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "afcff4ecfd03f6299dd08136799072ac", "src_uid": "bca20e0910e9fe4d89326b50ab45e4ca", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n ios_base::sync_with_stdio(false);\r\n cin.tie(NULL);\r\n int n;\r\n cin>>n;\r\n long long int ans;\r\n n--;\r\n if(n==0)ans=3;\r\n else{\r\n if(n%3==0){\r\n ans=4*(n/3)+4;\r\n }\r\n else{\r\n int k=n/3;\r\n if(k==0){\r\n ans=2*(n+1)+1;\r\n }\r\n else{\r\n ans=2*(n-(k-1))+1;\r\n }\r\n }\r\n }\r\n cout<\n#include \n#include \nusing namespace std;\nint n,i,j,a[11],m=1e9+7,ans=0;\nlong long c[211][211],F[211][11];\nint f(int n, int t)\n{\n\tif (t==9)\n\t\treturn 1;\n\tif (F[n][t]!=-1) return F[n][t];\n\tint s=0,i;\n\tlong long ans1=0;\n\tfor(i=t;i<10;i++)\n\t\ts+=a[i];\n\tfor(i=a[t];i+s-a[t]<=n;i++)\n\t\tif (t==0)\n\t\t\tans1+=(c[n-1][i]*f(n-i,t+1))%m;\n\t\telse ans1+=(c[n][i]*f(n-i,t+1))%m;\n\tans1%=m;\n\tF[n][t]=ans1;\n\treturn ans1;\n}\nint main ()\n{\n\tcin>>n; int dn=n;\n\tfor(i=0;i<10;i++)\n\t{\n\t\tcin>>a[i];\n\t\tdn-=a[i];\n\t}\n\tfor(i=0;i<=100;i++)\n\t{\n\t\tc[i][0]=1; c[i][i]=1;\n\t\tfor(j=1;j\nusing namespace std;\n#define ll long long int\n#define mod 1000000007\n#define pb push_back\n#define fr first\n#define sc second\nint dx[4]={0,0,1,-1},dy[4]={1,-1,0,0},dxx[8]={0,0,1,1,1,-1,-1,-1},dyy[8]={1,-1,0,1,-1,0,1,-1};\n//914836017997511610\ndouble a[1004],b[1004],c[1004],d[1004],e[1004];\nint main()\n{ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n\nint n,i,j,k;\ncin>>n;\ndouble a1,a2,b1,b2,c1,c2,d1,d2,e1,e2,l1,l2,cp,val;\nfor(i=0;i>a[i]>>b[i]>>c[i]>>d[i]>>e[i];\n\t\t//l[i]=sqrt(a[i]*a[i]+b[i]*b[i]+c[i]*c[i]+d[i]*d[i]+e[i]*e[i]);\n\t}\nif(n>33)\n\t{cout<<0;return 0;}\nbool flag;vector ans;\nfor(i=0;i0 and val<=1)\n\t\t\t\t{flag=false;break;}\n\n\t\t}\n\t\tif(!flag)\n\t\t\tbreak;\n\t}\n\tif(flag)\n\t\tans.pb(i+1);\n}\ncout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n\n#define LL long long\n#define N 3000101\n#define M 3000011\n#define MP make_pair\n#define Pi acos(-1.0)\n//#pragma comment(linker,\"/STACK:1024000000,1024000000\")\n#define inf 0x3f3f3f3f\n#define ls (root << 1)\n#define rs (ls | 1)\n#define md ((ll+rr)/2)\n#define lson ll, md, ls\n#define rson md+1, rr, rs\n#define mod 1000000007\n#define inf 0x3f3f3f3f\n#define sqr(x) ((x)*(x))\n#define MP make_pair\n#define uLL unsigned long long\nLL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}\n#define F(x) ((x)/3+((x)%3 == 1 ? 0 : tb))\n#define G(x) ((x) y.id : x.val < y.val;\n else return fabs(x.val-y.val) <= 1e-6 ? x.id < y.id : x.val < y.val;\n}\n\nint main(){\n a[1].s = \"x^y^z\";\n a[2].s = \"x^z^y\";\n a[3].s = \"(x^y)^z\";\n a[4].s = \"(x^z)^y\";\n a[5].s = \"y^x^z\";\n a[6].s = \"y^z^x\";\n a[7].s = \"(y^x)^z\";\n a[8].s = \"(y^z)^x\";\n a[9].s = \"z^x^y\";\n a[10].s = \"z^y^x\";\n a[11].s = \"(z^x)^y\";\n a[12].s = \"(z^y)^x\";\n for(int i=1; i<=12; i++) a[i].id= i,a[i].val = -inf;\n double x,y,z;\n scanf(\"%lf%lf%lf\",&x,&y,&z);\n if(fabs(x - 1.0) <= 1e-6) for(int i=1; i<=4; i++)a[i].val = -inf+1;\n if(fabs(y - 1.0) <= 1e-6) for(int i=5; i<=8; i++)a[i].val = -inf+1;\n if(fabs(z - 1.0) <= 1e-6) for(int i=9; i<=12; i++) a[i].val = -inf+1;\n mark = 0;\n double x1 = x,y1 = y,z1 = z;\n if(x < 1.0 && y < 1.0 && z < 1.0) x1 = 1.0/x,y1 = 1.0/y,z1 = 1.0/z,mark = 1;\n if(x1 > 1.0){\n a[1].val = z*log(y)+log(log(x1));\n a[2].val = y*log(z)+log(log(x1));\n a[4].val = a[3].val = log(log(x1))+log(y)+log(z);\n }\n if(y1 > 1.0){\n a[5].val = z*log(x)+log(log(y1));\n a[6].val = x*log(z)+log(log(y1));\n a[7].val = a[8].val = log(log(y1))+log(x)+log(z);\n }\n if(z1 > 1.0){\n a[9].val = y*log(x)+log(log(z1));\n a[10].val = x*log(y)+log(log(z1));\n a[11].val = a[12].val = log(log(z1))+log(x)+log(y);\n }\n //for(int i=1; i<=12; i++) printf(\"%.9f\\n\",a[i].val);\n sort(a+1,a+1+12,cmp);\n if(!mark) cout<\n#include\n#include\n#include\nusing namespace std;\ntypedef long long ll;\nconst ll Maxn=20+5;\nll n,mul[Maxn];\nint main()\n{ scanf(\"%lld\",&n);\n mul[0]=1;\n for(ll i=1;i<=n;i++)mul[i]=1ll*mul[i-1]*i;\n printf(\"%lld\\n\",mul[n]/mul[n/2]/mul[n/2]/2*mul[n/2-1]*mul[n/2-1]);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "0b5a77a9e16727879923c1c1f8775203", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include\n#include\nusing namespace std;\n\n\nint main() {\n\n int n, m;\ncin >> n >> m;\nint result = -1;\nif (m % n == 0) {\n result = 0;\n int d = m / n;\n while (d % 2 == 0)\n d /= 2, result++;\n while (d % 3 == 0)\n d /= 3, result++;\n if (d != 1)\n result = -1;\n}\ncout << result << endl;\n\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "7cbb881f6e5bde641c9aea055aded286", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "//be name oo\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define FOR(i, n) for(int i = 0; i < (n); i++)\n#define SZ(x) ((int)x.size())\n#define PB push_back\n\nusing namespace std;\ntypedef pair joft;\ntypedef complex point;\n\nconst int MOD = 1000 * 1000 * 1000 + 9;\nconst int MAX_N = 1000 * 1000 + 10;\n\nlong long dp1[MAX_N];\n\nint main(){\n\tint n;\n\tscanf(\"%d\", &n);\n\tn /= 2;\n\tif(n == 1){\n\t\tprintf(\"%d\\n\", 10);\n\t\treturn 0;\n\t}\n\tdp1[1] = 5;\n\tfor(int i = 2; i <= n - 2; i++)\n\t\tdp1[i] = (3 + 2 * dp1[i - 1]) % MOD;\n\tlong long dp2 = 1;\n\tFOR(i, n - 2)\n\t\tdp2 = (1 + dp1[n - 2 - i] * (3 + dp2)) % MOD;\n\tdp2 += 5;\n\tdp2 = 1 + dp2 * dp2;\n\tdp2 *= 2;\n\tdp2 %= MOD;\n\tprintf(\"%d\\n\", (int)dp2);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics"], "code_uid": "2df315cd5bc5c2001ec58d4f02a170c5", "src_uid": "dbcb1077e7421554ba5d69b64d22c937", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nint main(){\n int t,n,min;\n cin>>t;\n while(t--){\n cin>>n;\n // max=INT_MIN;\n if(n%2==0){\n cout<max)\n // max=i; \n }\n }\n if(min==1){\n cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\nint num[100002];\nint main(void){\n\tint a, b, i;\n\tscanf(\"%d\",&a);\n\tif(a % 4 == 1){\n\t\tprintf(\"0 A\");\n\t}\n\telse if(a % 4 == 2){\n\t\tprintf(\"1 B\");\n\t}\n\telse if(a % 4 == 3){\n\t\tprintf(\"2 A\");\n\t}\n\telse{\n\t\tprintf(\"1 A\");\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "d570433267e83170427cbaac2267cb28", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "#include \r\nusing namespace std;\r\n#ifdef prabhav_\r\n\t#include \"Headers/debug.cpp\"\r\n#endif\r\n#define int long long int\r\n\r\nint nc2(int n) {\r\n\treturn n * (n - 1) / 2;\r\n}\r\n\r\nint nc3(int n) {\r\n\treturn n * (n - 1) * (n - 2) / 6;\r\n}\r\n\r\nsigned main() {\r\n\tcin.tie(nullptr)->sync_with_stdio(false);\r\n\tint n;\r\n\tlong double p;\r\n\tcin >> n >> p;\r\n\tint ans;\r\n\tfor(int studiedGames = 0; studiedGames < n + 1; studiedGames++) {\r\n\t\tlong double fav1 = studiedGames * nc2(n - studiedGames);\r\n\t\tfav1 *= (long double)0.5;\r\n\t\tlong double fav2 = nc2(studiedGames) * (n - studiedGames);\r\n\t\tlong double fav3 = nc3(studiedGames);\r\n\t\tlong double favourable = fav1 + fav2 + fav3;\r\n\t\tint total = nc3(n);\r\n\t\tif((long double)favourable/(long double)total >= p) {\r\n\t\t\tans = studiedGames;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\tcout << ans << endl;\r\n\treturn 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["math", "probabilities", "combinatorics"], "code_uid": "de2a3227bd0017c9c1b8d5ad922cee47", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n#define _USE_MATH_DEFINES\n#pragma comment(linker, \"/STACK:16777216\")\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define all(a) (a).begin(),(a).end()\n#define sz(a) (int)(a).size()\n\nusing namespace std;\n\ntypedef long long int64;\ntypedef vector vi;\ntypedef vector< vi > vvi;\ntypedef vector vd;\ntypedef vector< vd > vvd;\ntypedef vector< string > vs;\ntypedef pair< int, int > pii;\ntypedef vector< pii > vpii;\n\n\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"rt\", stdin);\n freopen(\"output.txt\", \"wt\", stdout);\n#endif\n\n int c, d;\n cin >> c >> d;\n int n, m;\n cin >> n >> m;\n int k;\n cin >> k;\n\n int res = 0;\n int nm = n * m;\n int dn = d * n;\n nm -= k;\n int res1 = (nm / n) * c + min((nm % n) * d, c);\n int res2 = nm * d;\n if (res1 < 0)\n res1 = 0;\n if (res2 < 0)\n res2 = 0;\n\n cout << min(res1, res2);\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "implementation"], "code_uid": "72485078b95ec631b813bdfe4b987549", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n int a,b,c,e[1000000],i=0,j,d,f=0;\n cin>>a>>b>>c;\n d=a/b;\n e[i]=a%b;\n for(;;)\n {\n a=10*e[i];\n d=a/b;\n i++;\n e[i]=a%b;\n if(d==c)\n {\n cout<> n;\n\tif (n == 0)\n\t{\n\t\tcout << \"1\";\n\t\treturn 0;\n\t}\n\tn = n % 4;\n\tswitch (n)\n\t{\n\tcase 1: cout << \"8\"; break;\n\tcase 2: cout << \"4\"; break;\n\tcase 3: cout << \"2\"; break;\n\tcase 0: cout << \"6\"; break;\n\t}\n}", "lang_cluster": "C++", "tags": ["math", "implementation", "number theory"], "code_uid": "ab71d0308625c9d68fc5070acf698e4d", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\nint st[100002],dd[100002],ms[100002][2];\n\nint main() \n{\n int i,j,n,m,count,dcount=0,ps,flag;\n char ch;\n cin>>n>>m;\n for(i=0;i>ch;\n if(ch=='+')\n ms[i][0]=1;\n else\n ms[i][0]=-1;\n cin>>ms[i][1];\n }\n count=0;\n for(i=0;i1)\n {\n //cout<\nusing namespace std;\n#define TR(i,v) for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)\n#define DEBUG(x) cout << #x << \" = \" << x << endl;\n#define SIZE(p) (int)(p).size()\n#define MP(a, b) make_pair((a), (b))\n#define ALL(p) (p).begin(), (p).end()\n#define rep(i, n) for(int (i)=0; (i)<(int)(n); ++(i))\n#define REP(i, a, n) for(int (i)=(a); (i)<(int)(n); ++(i))\n#define FOR(i, a, b) for(int (i)=(int)(a); (i)<=(int)(b); ++(i))\n#define FORD(i, b, a) for(int (i)=(int)(b); (i)>=(int)(a); --(i))\n#define CLR(x, y) memset((x), (y), sizeof((x)))\ntypedef long long LL;\ntypedef pair pii;\nconst int inf=(int)1e9;\nint n,cnt;\nchar g[25][25];\nint dp[55][(1<<20)+10],M[50][26];\ninline void ckmax(int &a,int b) { \n if(ab) a=b;\n}\ninline int getm(int k,int x,int y) {\n if(k<=n) return x-1;\n return n-y;\n}\ninline int gnxtmask(int k,int mask) {\n if(k>1);\n}\nint gao(int k,int mask) {\n int &res=dp[k][mask];\n if(res!=-inf) return res;\n if(k+1==n+n) { \n return res=0; \n }\n int len=k<=n?k:(n-(k-n)),sx=k<=n?1:1+k-n,sy=k<=n?k:n; \n if(~k&1) res=-inf;\n else res=inf;\n rep(c,26) { \n int m=gnxtmask(k,mask)&M[k+1][c]; \n // printf(\"trans [%d %d] -> c=%d %d\\n\",k,mask,c,m);\n if(!m) continue; \n int t=(int)(c==0)-(int)(c==1);\n if(~k&1) ckmax(res,t+gao(k+1,m));\n else ckmin(res,t+gao(k+1,m));\n }\n return res;\n}\nint main(int argc, char const *argv[]) {\n#ifndef ONLINE_JUDGE\n freopen(\"B.in\", \"r\", stdin);\n // freopen(\"out\", \"w\", stdout);\n#endif\n // ios::sync_with_stdio(false); cin.tie(0);\n scanf(\"%d\",&n);\n FOR(i,1,n) scanf(\"%s\",g[i]+1); \n FOR(k,1,n+n)\n rep(j,26) { \n int len=k<=n?k:(n-(k-n)),sx=k<=n?1:1+k-n,sy=k<=n?k:n;\n for(int i=0;i0) puts(\"FIRST\");\n if(r==0) puts(\"DRAW\");\n return 0;\n}", "lang_cluster": "C++", "tags": ["games", "dp", "bitmasks"], "code_uid": "ff54af2863dc0776a7052860e01a9d81", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define dint long long\nusing namespace std;\nint main(){\n dint a,b,f,k;\n\n scanf(\"%lld%lld%lld%lld\",&a,&b,&f,&k);\n dint i;\n dint sum = b;\n dint dis1,dis2;\n dint num = 0;\n if (k == 1){\n if (a-f > b || f > b){\n cout << -1 << endl;\n return 0;\n }\n }\n else if (k == 2){\n if (2*(a-f) > b || f > b){\n cout << -1 << endl;\n return 0;\n }\n }\n else{\n if (2*(a-f) > b || 2*f > b){\n cout << -1 << endl;\n return 0;\n }\n if (b < f){\n cout << -1 << endl;\n return 0;\n }\n }\n\n for(i = 1;i <= k;i++){\n if (i % 2 != 0){\n sum-=f;\n if (i != k)\n dis1 = 2*(a-f);\n else\n dis1 = a-f;\n if (dis1 > sum){\n num++;\n sum = b;\n }\n sum-=a-f;\n }\n else{\n sum-= a-f;\n if (i != k)\n dis2 = 2*f;\n else\n dis2 = f;\n if (dis2 > sum){\n num++;\n sum = b;\n }\n sum-=f;\n }\n }\n cout << num << endl;\n }\n", "lang_cluster": "C++", "tags": ["math", "greedy", "implementation"], "code_uid": "5106f7f4bd903f39f45d8ee7492e1770", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\nll x,y,d;\nvoid extendedEuclid(ll a, ll b) {\n if(b == 0) {\n x = 1; y = 0; d = a;\n if(a<0) x=-1;\n return;\n }\n extendedEuclid(b, a % b);\n ll x1 = y;\n ll y1 = x-(a/b)*y;\n x = x1;\n y = y1;\n //cout<0&&a%b) return a/b+1;\n return a/b;\n}\nint main()\n{\n ios_base::sync_with_stdio(false); cin.tie(NULL);\n ll a1,a2,b1,b2,l,r;\n cin>>a1>>b1>>a2>>b2>>l>>r;\n ll c=b2-b1;\n if(l>r){\n cout<<\"0\\n\"; return 0;\n }\n extendedEuclid(a1,-a2);\n if(d<0) d=-d;\n if(c%d){\n cout<<\"0\\n\"; return 0;\n }\n ll x0=x*c/d,y0=y*c/d;\n /*cout<r) cout<<\"0\\n\";\n else cout<\nusing namespace std;\n#define mod 1000000007\n#define ll long long \n#define N 100005\n#define all(v) v.begin(),v.end()\n#define pii pair\n#define print(x) cout << #x << \"=\" << x << \"\\t\";\n \nll n;\nll k;\nll a;\nll b;\nll ma = -1e18;\nll mi = 1e18;\n \n\nint main() {\n ios::sync_with_stdio(false); cin.tie(NULL);\n \n cin >> n >> k >> a >> b;\n \n for(ll i=0;i<=n;i++) {\n ll l = i * k + b + a;\n if (l <= 0)\n continue;\n ll g = __gcd(n * k, l);\n ll lcm = n * k / g;\n ma = max(ma, lcm);\n mi = min(mi, lcm);\n }\n\n for(ll i=0;i<=n;i++) {\n ll l = (i + 1) * k - b + a;\n ll g = __gcd(n * k, l);\n ll lcm = n * k / g;\n ma = max(ma, lcm);\n mi = min(mi, lcm);\n }\n\n for(ll i=0;i<=n;i++) {\n ll l = (i + 1) * k - a + b;\n ll g = __gcd(n * k, l);\n ll lcm = n * k / g;\n ma = max(ma, lcm);\n mi = min(mi, lcm);\n }\n\n for(ll i=0;i<=n;i++) {\n ll l = (i + 2) * k - a - b;\n ll g = __gcd(n * k, l);\n ll lcm = n * k / g;\n ma = max(ma, lcm);\n mi = min(mi, lcm);\n }\n \n cout << mi << \" \" << ma;\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "c8e38c24e3992f4ddcb3710a098b74ea", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nint C[25],A[25];\nint N;\nint dfs(int idx,int rem)\n{\n\tif(idx>N)\n\t{\n\t\tfor(int i = 1;i<=N;i++)\n\t\t{\n\t\t\tif(C[i])\n\t\t\t\treturn 0;\n\t\t}\n\t\treturn 1;\n\t}\n\tif(!A[idx])\n\t\treturn dfs(idx+1,A[idx+1]-1);\n\tfor(int i = min(A[idx],rem);i>0;i--)\n\t{\n\t\tif(C[i])\n\t\t{\n\t\t\tC[i]-=1,A[idx]-=i;\n\t\t\tif(dfs(idx,i))\n\t\t\t\treturn 1;\n\t\t\tA[idx]+=i,C[i]+=1;\n\t\t}\n\t}\n\treturn 0;\n}\nint main()\n{\n\tcin>>N;\n\tC[N] = -1;\n\tfor(int i = 1;i<=N;i++)\n\t{\n\t\tcin>>A[i];\n\t\tC[A[i]]+=1;\n\t\tA[i]-=1;\n\t}\n\tputs(dfs(1,A[1] - 1)?\"YES\":\"NO\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["constructive algorithms", "dp", "bitmasks", "greedy", "trees"], "code_uid": "a43b42d1d6fb4a18be2a37103486e11e", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main (void) {\n\tlong long int n, a, b, c, d, maxa, mina, mins, rez;\n\tcin >> n >> a >> b >> c >> d;\n\tlong long int x, xx = a + b, y, yy = a + c, h, hh = c + d, z, zz = b + d;\n\tmaxa = max(max(xx, yy), max(hh, zz));\n\tmina = min(min(xx, yy), min(hh, zz));\n\tif (maxa - mina >= n) {\n\t\tcout << 0;\n\t} else {\n\t\tif (maxa == mina) mins = maxa + 1;\n\t\telse mins = 2 * maxa - mina;\n\t\tx = mins - xx;\n\t\ty = mins - yy;\n\t\th = mins - hh;\n\t\tz = mins - zz;\n\t\tmaxa = max(max(x, y), max(h, z));\n\t\tmina = min(min(x, y), min(h, z));\n\t\t/*if (maxa <= 0 || mina <= 0) rez = 0;\n\t\telse rez = (n - maxa + 1) * n;\n\t\tif (rez < 0) rez = 0;*/\n\t\trez = n * (n - (maxa - mina));\n\t\tcout << rez;\n\t}\n\t//system(\"pause\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "d1092ede6ebec787fb1632c268a3fe5b", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n\ntypedef long long int lli;\ntypedef pair pii;\ntypedef vector vec;\n\n#define ones(x) __builtin_popcount(x)\n#define onesl(x) __builtin_popcountl(x)\n#define onesll(x) __builtin_popcountll(x)\n\n#define pb push_back\n#define mp make_pair\n#define mt make_tuple\n#define scn(n) scanf(\"%d\",&n)\n#define scnll(n) scanf(\"%lld\",&n)\n#define scn2(n,m) scanf(\"%d%d\",&n,&m)\n#define scn3(n,m,w) scanf(\"%d%d%d\",&n,&m,&w)\n#define scn2ll(n,m) scanf(\"%lld%lld\",&n,&m)\n#define atoz(v) v.begin(),v.end()\n#define ratoz(v) v.rbegin(),v.rend()\n#define Fill(a,v) memset(a,v,sizeof(a))\n#define sz(v) v.size()\n#define fi first\n#define se second\n#define inf 1e9\n#define pi acos(-1.0)\n#define sqr(x) x*x\n#define max3(a,b,c) max(a,max(b,c))\n#define min3(a,b,c) min(a,min(b,c))\n#define ten(n) (int)1e##n\n#define tenll(n) (lli)1e##n\n\nint Set(int N,int pos){return N=N | (1<\nusing namespace std;\n\nvoid good() {\n cout << \"YES\";\n exit(0);\n}\n\nint main() {\n int N; cin >> N;\n char grid[N][N];\n for (int i = 0; i < N; i++) {\n string row; cin >> row;\n for (int j = 0; j < N; j++) grid[i][j] = row[j];\n }\n\n string word = \"theseus\";\n for (int i = 0; i < N; i++) {\n\t\tfor (int j = 0; j < N; j++) {\n\t\t\tif (i < N-7) {\n\t\t\t\tstring w = \"\";\n\t\t\t\tfor (int k = 0; k < 7; k++) w += grid[i+k][j];\n\t\t\t\tif (w == word) good();\n\t\t\t}\n\t\t\tif (j < N-7) {\n\t\t\t\tstring w = \"\";\n\t\t\t\tfor (int k = 0; k < 7; k++) w += grid[i][j+k];\n\t\t\t\tif (w == word) good();\n\t\t\t}\n\t\t\tif (i < N-7 && j < N-7) {\n\t\t\t\tstring w = \"\";\n\t\t\t\tfor (int k = 0; k < 7; k++) w += grid[i+k][j+k];\n\t\t\t\tif (w == word) good();\n\t\t\t}\n\t\t}\n }\n cout << \"NO\";\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "e68703313324c03b89d97913adea52c4", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \r\n#define forn(i,s,t) for(register int i=(s);i<=(t);++i)\r\n#define form(i,s,t) for(register int i=(s);i>=(t);--i)\r\nusing namespace std;\r\nconst int N = 2040, Mod = 998244353;\r\nstruct Mint {\r\n\tint res;\r\n\tMint() {res = 0;}\r\n\tMint(int a) : res(a) {}\r\n\tfriend Mint operator + (Mint A, Mint B) {\r\n\t\treturn Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) : (A.res + B.res));\r\n\t}\r\n\tfriend Mint& operator += (Mint& A, Mint B) {return A = A + B;}\r\n\tfriend Mint operator - (Mint A, Mint B) {B.res = Mod - B.res; return A + B;}\r\n\tfriend Mint operator - (Mint A) {return Mint(Mod - A.res);}\r\n\tfriend Mint operator + (Mint A) {return A;}\r\n\tfriend Mint& operator -= (Mint& A, Mint B) {return A = A - B;}\r\n\tfriend Mint operator * (Mint A, Mint B) {return 1ll * A.res * B.res %Mod;}\r\n\tfriend Mint& operator *= (Mint& A, Mint B) {return A = A * B;}\r\n\tfriend Mint operator ~ (Mint A) {\r\n\t\tstatic Mint res; res = Mint(1);\r\n\t\tstatic int k; k = Mod - 2;\r\n\t\tfor(;k;k>>=1, A*=A) (k&1) && (res = res * A, 0);\r\n\t\treturn res;\r\n\t}\r\n\tfriend Mint operator / (Mint A, Mint B) {return A * (~B);}\r\n\tfriend Mint& operator /= (Mint& A, Mint B) {return A *= (~B);}\r\n\tfriend Mint operator >> (Mint A, Mint B) {return Mint(A.res / B.res);}\r\n\tfriend Mint& operator >>= (Mint& A, Mint B) {return A = A>>B;}\r\n};\r\nint n, m; Mint C[N << 1][N << 1];\r\ninline Mint F(int n, int m) {return C[n + m][n];}\r\nint main() {\r\n\tscanf(\"%d%d\", &n, &m);\r\n\tforn(i,0,n + m) {\r\n\t\tC[i][0] = C[i][i] = Mint(1);\r\n\t\tforn(j,1,i - 1) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];\r\n\t}\r\n\tstatic Mint res, sum;\r\n\tforn(h,1,n - 1) {\r\n\t\tsum = Mint(0);\r\n\t\tforn(i,1,m - 1) {\r\n\t\t\tres += sum * F(i, h - 1) * F(m - i - 1, h);\r\n\t\t\tsum += F(n - h, i - 1) * F(n - h - 1, m - i);\r\n\t\t}\r\n\t}\r\n\tforn(h,1,m - 1) {\r\n\t\tsum = Mint(0);\r\n\t\tforn(i,1,n - 1) {\r\n\t\t\tsum += F(m - h, i - 1) * F(m - h - 1, n - i);\r\n\t\t\tres += sum * F(i, h - 1) * F(n - i - 1, h);\r\n\t\t}\r\n\t}\r\n\tres = res * Mint(2);\r\n\tprintf(\"%d\\n\", res.res);\r\n\treturn 0;\r\n}// OJ:: LG", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "fdd55e70a76edfacb8411bc6ffdf5152", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17 (64)", "source_code": "#include \n\n#define rep(i,l,r) for (int i = l; i <= r; i++)\n#define per(i,r,l) for (int i = r; i >= l; i--)\n#define fi first\n#define se second\n#define prt std::cout\n#define gin std::cin\n#define edl std::endl\n\nnamespace wxy{\n\ntypedef long long ll;\n\nconst int N = 64;\n\nint f[N][N][2];\n\nint a[N],b[N],c[N],n,m,k;\n\nll x,y;\n\nint high(ll x) {\n int res = -1;\n per(i,60,0) {\n if (x >> i & 1) {\n res = i; break;\n }\n }\n return res;\n}\n\nvoid check(int l,int type) {\n if (type == 0) {\n int r = l + n - 1;\n if (r <= k) {\n bool flag = true;\n for (int i = l,j = 1; i <= r; ++ i,++ j) {\n if (c[i] != a[j]) {\n flag = false; break;\n }\n }\n if (flag) f[l][r][0] = 1;\n }\n r = l + m - 1;\n if (r <= k) {\n bool flag = true;\n for (int i = l,j = 1; i <= r; ++ i,++ j) {\n if (c[i] != b[j]) {\n flag = false; break;\n }\n }\n if (flag) f[l][r][0] = 1;\n }\n } else {\n int r = l + n - 1;\n if (r <= k) {\n bool flag = true;\n for (int i = r,j = 1; i >= l; -- i,++ j) {\n if (c[i] != a[j]) {\n flag = false; break;\n }\n }\n if (flag) f[l][r][1] = 1;\n }\n r = l + m - 1;\n if (r <= k) {\n bool flag = true;\n for (int i = r,j = 1; i >= l; -- i,++ j) {\n if (c[i] != b[j]) {\n flag = false; break;\n }\n }\n if (flag) f[l][r][1] = 1;\n }\n }\n}\n\ninline void main(){\n #ifndef ONLINE_JUDGE\n freopen(\"in.in\",\"r\",stdin);\n freopen(\"out.out\",\"w\",stdout);\n #endif\n scanf(\"%lld%lld\",&x,&y);\n int h = high(x); per(i,h,0) a[++ n] = (x >> i & 1);\n int cur = 0; ll v = 0; rep(i,1,n) {v += (1ll*a[i]<> i & 1);\n h = high(y); per(i,h,0) c[++ k] = (y >> i & 1);\n rep(l,1,k) check(l,0),check(l,1);\n \n for (int len = 1; len <= k; ++ len) {\n for (int l = 1; l + len - 1 <= k; ++ l) {\n int r = l + len - 1;\n if (c[l] == 1) {\n f[l][r][0] |= f[l+1][r][1];\n }\n if (c[r] == 1) {\n f[l][r][1] |= f[l][r-1][0];\n }\n if (c[l] == 1) f[l][r][0] |= f[l][r][1];\n if (c[r] == 1) f[l][r][1] |= f[l][r][0];\n }\n }\n if (f[1][k][0]) puts(\"YES\");\n else puts(\"NO\");\n}\n\n}signed main(){wxy::main(); return 0;}\n \t \t \t\t\t \t\t\t \t\t\t \t \t \t", "lang_cluster": "C++", "tags": ["dfs and similar", "constructive algorithms", "math", "bitmasks", "strings", "implementation"], "code_uid": "11b1f3713d97213d93bc6aa2e55e73bc", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "//\n// main.cpp\n// Petya's Exams\n//\n// Created by dalton wang on 2018/6/30.\n// Copyright \u00a9 2018\u5e74 dalton wang. All rights reserved.\n//\n#include\nusing namespace std;\nstruct a\n{\n int nember;\n int begin,end,wait;\n};\na a[1001];\nint s[101];\nint main()\n{\n int n,m,i,j,k;\n cin>>n>>m;\n for(i=1;i<=m;i++)\n {\n a[i].nember=i;\n cin>>a[i].begin>>a[i].end>>a[i].wait;\n s[a[i].end]=m+1;\n }\n for(i=1;i<=m-1;i++)\n {\n for(j=i+1;j<=m;j++)\n {\n if(a[j].end\nusing namespace std;\n \nint pressed[4][4];\nint toggled[4][4];\n \nint main(){\n \n\tfor(int i = 1; i <= 3; i++){\n\t\tfor(int j = 1; j <= 3; j++){\n\t\t\tcin >> pressed[i][j];\n\t\t\ttoggled[i][j] = pressed[i][j];\n\t\t}\n\t}\n \n\tfor(int i = 1; i <= 3; i++){\n\t\tfor(int j = 1; j <= 3; j++){\n\t\t\tif(pressed[i][j] != 0){\n\t\t\t\t//Added 2 extra rows and columns in toggled[][] to handle edge lamps \n\t\t\t\t//rows and columns 0 and 4 are auxilliary\n\t\t\t\ttoggled[i][j - 1] += pressed[i][j];\n\t\t\t\ttoggled[i][j + 1] += pressed[i][j];\n\t\t\t\ttoggled[i - 1][j] += pressed[i][j];\n\t\t\t\ttoggled[i + 1][j] += pressed[i][j];\n \n\t\t\t}\n\t\t}\n\t}\n \n\tfor (int i = 1; i <= 3; i++){\n\t\tfor(int j = 1; j <= 3; j++){\n\t\t\tif(toggled[i][j] % 2) cout << \"0\";\n\t\t\telse cout << \"1\";\n\t\t}\n\t\tcout << '\\n';\n\t}\n \n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "d7d0fa6917b392dfc683be2923942822", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nconst int ok=500;\nint n,k,a[ok];\ndouble sum,cnt;\nint av;\nint main()\n{\n\tscanf(\"%d%d\",&n,&k);\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tscanf(\"%d\",&a[i]);\n\t\tsum+=a[i];\n\t} \n\tint n1=n;\n\tcnt=sum*1.0/n;\n\tav=round(cnt);\n\twhile(av!=k)\n\t{\n\t\tsum+=k;\n\t\tn++;\n\t\tcnt=sum*1.0/n;\n\t\tav=round(cnt);\n\t}\n\tprintf(\"%d\",n-n1); \n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "27522a25bec9a78e1a85dfe6d487c071", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)\n\nint main() {\n FAST_IO;\n string s;\n cin >> s;\n int len = s.length();\n if (len == 1) {\n cout << 0;\n } else {\n int max = 0;\n for(int i=0;i max)\n max = j - i + 1;\n }\n }\n }\n cout << max;\n }\n}\n", "lang_cluster": "C++", "tags": ["brute force", "strings", "implementation"], "code_uid": "b135ef46c8d2cd92099eb58587b61f7d", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint main()\n{\n \n \n int h, m;\n\tscanf (\"%d:%d\", &h, &m);\n\t\n\tif (h > 12) h -= 12;\n\t\n\tdouble v1 = h * 30.0 + m / 2.0;\n\tdouble v2 = m * 6.0;\n\t\n\tif (h == 12) v1 = m / 2.0;\n\tif (m == 60) v2 = 0;\n\tprintf (\"%lf %lf\\n\", v1, v2);\n}", "lang_cluster": "C++", "tags": ["math", "geometry"], "code_uid": "ae7f2c1d4bf2f1bd6b065840a6cf8d3a", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\r\n#include\r\n#define int long long\r\nusing namespace std;\r\ninline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}\r\ninline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}\r\ninline void writeln(int x){write(x); puts(\"\");}\r\nconst int mod=998244353,N=405;\r\nint c[26],n;\r\ninline void init(){\r\n\tn=read();\r\n\tfor (int i=0;i<26;i++) c[i]=read();\r\n}\r\nint g[N][N],f[2][205][205][3][3];\r\ninline void solve(){\r\n\tfor (int i=0;i<=2;i++)\r\n\t\tfor (int j=0;j<=2;j++)\r\n\t\t\tf[0][(i==1)+(j==1)][(i==2)+(j==2)][i][j]=(i?1:24)*(j?1:24);\r\n\tfor (int i=3;i<=n;i++){\r\n\t\tint cur=i&1;\r\n\t\tmemset(f[cur],0,sizeof f[cur]);\r\n\t\tfor (int u=0;u<=n/2+1;u++)\r\n\t\t\tfor (int v=0;v<=n/2+2;v++)\r\n\t\t\t\tfor (int x=0;x<3;x++)\r\n\t\t\t\t\tfor (int y=0;y<3;y++)\r\n\t\t\t\t\t\tfor (int z=0;z<3;z++){\r\n\t\t\t\t\t\t\tif (x==z&&x) continue;\r\n\t\t\t\t\t\t\tif (x==z) f[cur][u][v][y][z]=(f[cur][u][v][y][z]+f[cur^1][u][v][x][y]*23%mod)%mod;\r\n\t\t\t\t\t\t\t\telse f[cur][u+(z==1)][v+(z==2)][y][z]=(f[cur][u+(z==1)][v+(z==2)][y][z]+f[cur^1][u][v][x][y]*(z?1:24)%mod)%mod;\r\n\t\t\t\t\t\t}\r\n\t}\r\n\tfor (int i=n/2+1;i>=0;i--)\r\n\t\tfor (int j=n/2+1;j>=0;j--){\r\n\t\t\tg[i][j]=(g[i+1][j]+g[i][j+1]-g[i+1][j+1]+mod)%mod;\r\n\t\t\tfor (int x=0;x<3;x++)\r\n\t\t\t\tfor (int y=0;y<3;y++) g[i][j]=(g[i][j]+f[n&1][i][j][x][y])%mod;\r\n\t\t}\r\n\tint ans=g[0][0];\r\n\tfor (int i=0;i<26;i++) ans=(ans-g[c[i]+1][0])%mod;\r\n\tfor (int i=0;i<26;i++)\r\n\t\tfor (int j=i+1;j<26;j++) ans=(ans+g[c[i]+1][c[j]+1])%mod;\r\n\twriteln((ans+mod)%mod);\r\n}\r\nsigned main(){\r\n\tinit(); solve();\r\n\treturn 0;\r\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "f2e6f8d6f261897602b71a95e1897f2e", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\nusing namespace std;\n\nint fact(int a)\n{\n if(a==1 || a==0)\n return 1;\n return a*fact(a-1);\n}\n\nmain()\n{\n int A=0,B=0,c=0;\n double p;\n string a,b;\n cin>>a>>b;\n for(int i=0 ; i\n#include \n#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);\n#define endl \"\\n\"\n#define mod 1000000007\n#define PI 3.14159265358979323846\n#define f first\n#define s second\n#define un unordered\n#define for0(i, n) for (i = 0; i < n; i++)\n#define for1(j, n) for (j = 1; j <= n; j++)\n#define ll long long int\n#define all(v) v.begin(), v.end()\nusing namespace std;\n\nll isfind(ll parent[], ll b)\n{\n\n if (parent[b] == b)\n {\n return b;\n }\n\n parent[b] = isfind(parent, parent[b]);\n return parent[b];\n}\nvoid build(ll tree[], ll arr[], ll node, ll start, ll end)\n{\n\n if (start == end)\n {\n tree[node] = arr[start];\n return;\n }\n ll mid = (start + end) / 2;\n\n build(tree, arr, 2 * node, start, mid);\n\n build(tree, arr, 2 * node + 1, mid + 1, end);\n\n tree[node] = tree[2 * node] | tree[2 * node + 1];\n}\nll range_in_query(ll tree[], ll node, ll start, ll end, ll l, ll r)\n{\n\n if (start > end || start > r || end < l)\n {\n\n return 0;\n }\n if (start >= l && end <= r)\n {\n return tree[node];\n }\n ll mid = (start + end) / 2;\n ll range = range_in_query(tree, 2 * node, start, mid, l, r);\n ll range1 = range_in_query(tree, 2 * node + 1, mid + 1, end, l, r);\n return range | range1;\n}\nll power(ll x, ll y, ll p)\n{\n\n ll res = 1;\n x = x % p;\n while (y > 0)\n {\n if (y & 1)\n res = (res * x) % p;\n\n y = y >> 1; // y = y/2\n x = (x * x) % p;\n }\n return res;\n}\nbool cmp(pair p, pair p1)\n{\n\n return p.first < p1.first;\n}\n\nll check(string s, string s1)\n{\n ll count = 0;\n for (int i = 0; i < s.length(); i++)\n {\n if (s[i] == s1[i % 3])\n {\n continue;\n }\n count++;\n }\n return count;\n}\n\nvector printDivisors(ll n)\n{\n vector v;\n for (ll i = 1; i <= sqrt(n); i++)\n {\n if (n % i == 0)\n {\n if (n / i == i)\n v.push_back(i);\n\n else\n {\n v.push_back(i);\n v.push_back(n / i);\n }\n }\n }\n return v;\n}\nmap SieveOfEratosthenes(ll n)\n{\n bool prime[n + 1];\n memset(prime, true, sizeof(prime));\n\n for (ll p = 2; p * p <= n; p++)\n {\n if (prime[p] == true)\n {\n for (int i = p * p; i <= n; i += p)\n prime[i] = false;\n }\n }\n map mp;\n for (ll p = 2; p <= n; p++)\n if (prime[p])\n mp[p] = 1;\n\n return mp;\n}\nll check(ll arr[],ll n,ll mid,ll m){\n ll k=0,res=0,z=0;\n for(int i=n-1;i>=0;){\n if(k=m){\n return 1;\n }\n return 0;\n}\nclass Graph \n{ \n int V; // No. of vertices \n list *adj; // Pointer to an array containing adjacency lists \n bool isCyclicUtil(int v, bool visited[], bool *rs); // used by isCyclic() \npublic: \n Graph(int V); // Constructor \n void addEdge(int v, int w); // to add an edge to graph \n bool isCyclic(); // returns true if there is a cycle in this graph \n}; \n \nGraph::Graph(int V) \n{ \n this->V = V; \n adj = new list[V]; \n} \n \nvoid Graph::addEdge(int v, int w) \n{ \n adj[v].push_back(w); // Add w to v\u2019s list. \n} \n \n// This function is a variation of DFSUtil() in https://www.geeksforgeeks.org/archives/18212 \nbool Graph::isCyclicUtil(int v, bool visited[], bool *recStack) \n{ \n if(visited[v] == false) \n { \n // Mark the current node as visited and part of recursion stack \n visited[v] = true; \n recStack[v] = true; \n \n // Recur for all the vertices adjacent to this vertex \n list::iterator i; \n for(i = adj[v].begin(); i != adj[v].end(); ++i) \n { \n if ( !visited[*i] && isCyclicUtil(*i, visited, recStack) ) \n return true; \n else if (recStack[*i]) \n return true; \n } \n \n } \n recStack[v] = false; // remove the vertex from recursion stack \n return false; \n} \n \n// Returns true if the graph contains a cycle, else false. \n// This function is a variation of DFS() in https://www.geeksforgeeks.org/archives/18212 \nbool Graph::isCyclic() \n{ \n // Mark all the vertices as not visited and not part of recursion \n // stack \n bool *visited = new bool[V+1]; \n bool *recStack = new bool[V+1]; \n for(int i = 1; i <=V; i++) \n { \n visited[i] = false; \n recStack[i] = false; \n } \n \n // Call the recursive helper function to detect cycle in different \n // DFS trees \n for(int i = 1; i <=V; i++) \n if (isCyclicUtil(i, visited, recStack)) \n return true; \n \n return false; \n} \nvoid dfs(vector edges[],ll n,ll u,string s,ll visit[][26],ll vis[]){\n visit[u][s[u-1]-'a']++;\n vis[u]=1;\n for(auto i : edges[u]){\n for(int j=0;j<26;j++){\n visit[i][j]+=visit[u][j];\n }\n if(vis[i])\n continue;\n dfs(edges,n,i,s,visit,vis);\n }\n}\nvoid dfs(ll a,ll x[],ll y[],ll visit[],ll n){\n visit[a]=1;\n for(int i=1;i<=n;i++){\n if(visit[i]){\n continue;\n }else if(x[i]==x[a] || y[i]==y[a]){\n dfs(i,x,y,visit,n);\n }\n }\n}\nll knapSack(ll W,ll wt[], ll val[], ll n) \n{ \n ll i, w; \n ll K[n+1][W+1]={0}; \n \n for (i = 0; i <= n; i++) \n { \n \n for (w = 0; w <= W; w++) \n { \n if (i==0 || w==0) \n K[i][w] = 0; \n else if (wt[i-1] <= w) \n K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); \n else\n K[i][w] = K[i-1][w]; \n } \n } \n return K[n][W]; \n} \n\nll find(ll a,ll parent[]){\n\n if(parent[a]==a){\n return a;\n }\n parent[a]=find(parent[a],parent);\n return parent[a];\n}\n\nll solve(ll arr[],ll k,ll m,ll dp[][3501],ll str,ll end){\n if(str==end){\n return arr[str];\n }\n if(m==1){\n return max(arr[str],arr[end]);\n }\n \n if(k==0){\n ll res2=solve(arr,k,m-1,dp,str+1,end);\n ll res3=solve(arr,k,m-1,dp,str,end-1);\n dp[m][k]=min(res2,res3);\n return dp[m][k];\n }\n if(dp[m][k]!=-1){\n return dp[m][k];\n }\n else{\n ll res=solve(arr,k-1,m-1,dp,str+1,end);\n ll res1=solve(arr,k-1,m-1,dp,str,end-1);\n ll ans=max(res,res1);\n ll res2=solve(arr,k,m-1,dp,str+1,end);\n ll res3=solve(arr,k,m-1,dp,str,end-1);\n ll ans1=min(res2,res3);\n dp[m][k]=max(ans,ans1);\n return dp[m][k];\n }\n}\n\nll dp[3501][3501];\nbool check(ll k,ll mid){\n if((mid*(mid+1))/2==k){\n return 1;\n }\n else{\n return 0;\n }\n}\n\nchar * stdl(char *s ,char c){\n int length=0;\n for(int i=0;s[i]!=0;i++){\n length++;\n }\n char *res=new char[length];\n int k=0,flag=0;\n for(int i=0;i=l && new1+ans+1<=r){\n one++;\n new1=new1*2+1+ans;\n }\n return 1;\n }\n else{\n if(n%2){\n ll ans=result(n/2,l,r);\n ll new1=ans+1;\n while(new1>=l && new1<=r){\n one++;\n new1=2*new1;\n\n\n }\n return 2*ans+1;\n\n }\n else{\n ll ans=result(n/2,l,r);\n ans=2*ans+1;\n return ans;\n \n }\n }\n}\n\nvoid solve(){\n\n\n\n\n ll a,b;\n cin>>a>>b;\n ll c,d;\n cin>>c>>d;\n while(b<1000000 && d<1000000){\n if(b>n>>m;\n ll arr[n];\n vector>> v;\n for(int i=0;i>a>>b;\n a--;\n b--;\n\n v.push_back({max(b,a)-min(a,b)+1,{min(a,b),max(a,b)}});\n }\n sort(all(v));\n ll visit[n+1]={0};\n for(int i=0;i> mp;\n ll ans=1e10;\n for(auto i:v){\n ll k=0;\n for(int j=i.second.first;j<=i.second.second;j++){\n if(visit[j]!=-1){\n j=mp[j].first;\n k=mp[j].second;\n }\n else{\n visit[j]=k++;\n mp[j].first=i.second.second;\n }\n }\n for(int j=i.second.first;j<=i.second.second;j++){\n mp[j].second=k;\n }\n ans=min(ans,k);\n }\n cout<> t;\n for (int i = 0; i < t; i++)\n solve();\n return 0;\n\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "057f9c6a260116e27cbf5fc04975dcf8", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\nint main()\n{\n int n;\n cin>>n;\n int arr[n],i,sum=0;\n for(i=0;i>arr[i];sum+=arr[i];}\n float avg=float(sum)/n;\n sort(arr, arr+n);\n if(avg>=4.5)\n cout<<0<=4.5)\n break;\n }\n if(avg>=4.5)\n break;\n }\n cout<\n using namespace std;\n \n static int LOCAL=0;\n\n #define F0(a) memset(a,0,sizeof(a));\n #define print(v,i,x) for(int j=i;j<=x;j++){cout<=n;i--)\n #define fr(i,x,n) for(int i=x;i vi;\n typedef vector vlli;\n typedef vector> vii;\n\n typedef pair prii;\n typedef pair prilli;\n typedef pair prllii;\n typedef pair prllilli;\n\n const lli mod = 1000000007ll;\n const lli MOD = 1000000009ll;\n const lli INF = LLONG_MAX/10;\n const int inf = INT_MAX/10;\n\n lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}\n lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}\n lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}\n lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}\n lli mul(lli a,lli b,lli m=mod){return ((a%m)*(b%m))%m;}\n lli gcd(lli a,lli b){while(a&&b)a>b?a%=b:b%=a;return a+b;}\n lli lcm(lli a,lli b){return (max(a,b)/gcd(a,b))*min(a,b);}\n\n struct pair_hash {\n std::size_t operator () (const std::pair &p) const {\n auto h1 = std::hash{}(p.first);\n auto h2 = std::hash{}(p.second);\n return add(h1,mul(h2,h1,MOD));\n }\n };\n\n struct cmp{\n bool operator()(pair const & l,pair const & r){\n return l.s.f>n;\n\n F0(cnt);\n while(n){\n cnt[n%10]++;\n n/=10;\n }\n\n F0(c);\n c[0][0]=1;\n FOR(i,1,19){\n c[i][0]=1;\n FOR(j,1,19)c[i][j]=c[i-1][j-1]+c[i-1][j];\n }\n\n F0(dp);\n dp[10][0]=1;\n ROF(i,9,0){\n FOR(j,0,19){\n if(cnt[i]==0){dp[i][j]=dp[i+1][j];continue;}\n if(j==0)continue;\n FOR(k,1,cnt[i])\n if(k<=j-(i==0?1:0))\n dp[i][j]+=dp[i+1][j-k]*c[j-(i==0?1:0)][k];\n }\n }\n \n lli ans=0;\n FOR(i,0,19)ans+=dp[0][i];\n\n cout<\nusing namespace std;\nint main(){\n\tint n,k;\n\tcin>>n>>k;\n\tstring s;\n\tcin>>s;\n\tif(s.length()!=1){\n\t\tif(s[0] != '1' && k>0){\n\t\t\tk--;\n\t\t\ts[0] = '1';\n\t\t}\n\t}\n\telse\n\t\tif(s[0] != '0' && k>0){\n\t\t\tk--;\n\t\t\ts[0] = '0';\n\t\t}\n\tfor(int i=1;i0;i++){\n\t\tif(s[i]!='0'){\n\t\t\ts[i] = '0';\n\t\t\tk--;\n\t\t}\n\t}\n\tcout<\nusing namespace std;\nint main()\n{\n int T, S, q, ans = 0;\n scanf(\"%d %d %d\", &T, &S, &q);\n while(S < T)\n {\n S *= q;\n ans ++;\n }\n printf(\"%d\\n\", ans);\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "027d833f7effcf39edb0368d77ee3152", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#define ll long long \nusing namespace std;\n\nint main()\n{\n\tll n;\n\tcin>>n;\n\t\n\tll s=0,s1=0,s2=0,s3=0;\n\n\ts+=n/2;\n\ts+=n/3;\n\ts+=n/5;\n\ts+=n/7;\n\n\ts1+=n/6;\n\ts1+=n/10;\n\ts1+=n/14;\n\ts1+=n/15;\n\ts1+=n/21;\n\ts1+=n/35;\n\n\ts2+=n/30;\n\ts2+=n/42;\n\ts2+=n/70;\n\ts2+=n/105;\n\n\ts3+=n/210;\n\n\tcout<\n#include\n#include\n#include\nusing namespace std;\nint a,b,c;\nint sum;\nint main()\n{\n\tstring s,st,stt;\n\tcin>>s;\n\tcin>>stt;\n\tint len=s.size();\n\tfor(int i=len-1;i>-1;i--)\n\t{\n\t\tst+=s[i];\n\t}\n\tfor(int i=0;i\n#include // Common file\n#include \n#include // for less\n#define PI acos(-1.0)\n#define eps 1e-9\n#define ll long long\n#define ull unsigned long long\n#define nl printf(\"\\n\")\n#define spc printf(\" \")\n#define sf scanf\n#define pf printf\n#define INF (LL)1e15\n#define mod 1000000007\n#define FI freopen(\"input.txt\",\"r\",stdin)\n#define FO freopen(\"output.txt\",\"w\",stdout)\n#define si(x) scanf(\"%d\",&x)\n#define sii(x,y) scanf(\"%d %d\",&x,&y)\n#define siii(x,y,z) scanf(\"%d %d %d\",&x,&y,&z)\n#define sl(x) scanf(\"%lld\",&x)\n#define sll(x,y) scanf(\"%lld %lld\",&x,&y)\n#define slll(x,y,z) scanf(\"%lld %lld %lld\",&x,&y,&z)\n///#define safeMod(a, m) ((((a)%(m))+(m))%(m))/*handling negative sign of remainder*/\n///#define isValid(n,m,nx,ny)nx>=0&&nx=0&&ny, rb_tree_tag, tree_order_statistics_node_update> new_data_set;\n\nconst int S=123456;\nint main()\n{\n //FI;\n //FO;\n //ios_base::sync_with_stdio(0); cin.tie(0);\n ll n,m;\n while(cin>>n>>m)\n {\n ll ans=0;\n for(int i=1;i<=min(n,m);i++)\n {\n for(int j=1;j<=min(n,m);j++)\n {\n if((i*i+j*j)%m==0)\n {\n ll x=(n-i)/m;\n ll y=(n-j)/m;\n x++;\n y++;\n ans+=(x*y);\n }\n }\n }\n cout<\r\nusing namespace std;\r\ntypedef long long ll;\r\nconst int mod1=998244353,mod2=1e9+7;\r\nconst int N=2e6,MX=1e6;\r\nll n,c;\r\nint tot,ans,lim,pw[N],sum[N];\r\nvector ve[N];\r\ninline int dec(int x,int y,int mod){return (x-y<0)?x-y+mod:x-y;}\r\ninline int add(int x,int y,int mod){return (x+y>=mod)?x+y-mod:x+y;}\r\ninline void dfs(int pos,int now){\r\n\tif(now<=n){\r\n\t\t++tot;int x=dec(tot,now,mod1);\r\n\t\tve[pos-1].push_back(x);sum[pos-1]=add(sum[pos-1],x,mod2);\r\n\t}\r\n\tif(pos>6) return ;\r\n\tfor(int i=0;i<=9;++i) dfs(pos+1,now*10+i);\r\n}\r\ninline void solve(int pos,ll now){\r\n\tif(now>n) return ;\r\n\tif(pos>1){\r\n\t\tif(10ll*now*MX>n&&1ll*(now+1)*MX-1<=n){\r\n\t\t\tfor(int i=0;i<7;++i){\r\n\t\t\t\tint x=((c-1ll*now*pw[i])%mod1+mod1)%mod1;\r\n\t\t\t\tint p=lower_bound(ve[i].begin(),ve[i].end(),mod1-x)-ve[i].begin();\r\n\t\t\t\tans=add(ans,add(1ll*x*ve[i].size()%mod2,sum[i],mod2),mod2);\r\n\t\t\t\tans=dec(ans,1ll*mod1*(ve[i].size()-p)%mod2,mod2);\r\n\t\t\t}\r\n\t\t\tc+=tot;\r\n\t\t\treturn ;\r\n\t\t}\r\n\t\t++c,ans=add(ans,((c-now)%mod1+mod1)%mod1,mod2);\r\n\t}\r\n\tfor(int i=(pos==1?1:0);i<=9;++i) solve(pos+1,now*10+i);\r\n}\r\nint main(){\r\n\tscanf(\"%lld\",&n);\r\n\tpw[0]=1;for(int i=1;i<9;++i) pw[i]=10*pw[i-1];\r\n\tdfs(1,0);\r\n\tfor(int i=0;i<7;++i)\r\n\t\tsort(ve[i].begin(),ve[i].end()); \r\n\tsolve(1,0);\r\n\tprintf(\"%d\\n\",ans);\r\n\treturn 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["dfs and similar", "math", "meet-in-the-middle", "binary search"], "code_uid": "f8e1d161e0209142f479bdb699a4912f", "src_uid": "2c70ae38f91ab739621a31b897b8fbf3", "difficulty": 3400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nchar s[10];\n\nint main()\n{\n\tscanf(\"%s\", s);\n\tint n = strlen(s);\n\tif (n == 1) {\n\t\tif (s[0] == '0' || s[0] == '_' || s[0] == 'X') printf(\"1\\n\");\n\t\telse printf(\"0\\n\");\n\t\treturn 0;\n\t}\n\tif (s[0] == '0') {\n\t\tprintf(\"0\\n\");\n\t\treturn 0;\n\t}\n\tint ans = 0;\n\tint limits = 1;\n\tfor (int i = 0; i < n; i++)\n\t\tif (s[i] == 'X') limits = 10;\n\tfor (int x = 0; x < limits; x++) {\n\t\tint times = 1;\n\t\tint p = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif (s[i] == 'X') {\n\t\t\t\tif (i == 0 && x == 0) {\n\t\t\t\t\ttimes = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (s[i] == '_') {\n\t\t\t\tif (i + 2 < n) {\n\t\t\t\t\tif (i == 0) times *= 9;\n\t\t\t\t\telse times *= 10;\n\t\t\t\t}\n\t\t\t}\n\t\tif (times == 0) continue;\n\t\tif (s[n - 2] == 'X' && s[n - 1] == 'X') {\n\t\t\tif ((10 * x + x) % 25 == 0) ans += times;\n\t\t} else if (s[n - 2] == 'X') {\n\t\t\tif (s[n - 1] == '_') {\n\t\t\t\tfor (int i = 0; i < 10; i++)\n\t\t\t\t\tif ((10 * x + i) % 25 == 0) ans += times;\n\t\t\t} else if ((10 * x + s[n - 1] - '0') % 25 == 0) ans += times;\n\t\t} else if (s[n - 1] == 'X') {\n\t\t\tif (s[n - 2] == '_') {\n\t\t\t\tfor (int i = n == 2 ? 1 : 0; i < 10; i++)\n\t\t\t\t\tif ((10 * i + x) % 25 == 0) ans += times;\n\t\t\t}\n\t\t\telse if ((10 * (s[n - 2] - '0') + x) % 25 == 0) ans += times;\n\t\t} else if (s[n - 2] == '_' && s[n - 1] == '_') {\n\t\t\tfor (int i = n == 2 ? 1 : 0; i < 10; i++)\n\t\t\t\tfor (int j = 0; j < 10; j++)\n\t\t\t\t\tif ((10 * i + j) % 25 == 0) ans += times;\n\t\t} else if (s[n - 2] == '_') {\n\t\t\tfor (int i = n == 2 ? 1 : 0; i < 10; i++)\n\t\t\t\tif ((10 * i + s[n - 1] - '0') % 25 == 0) ans += times;\n\t\t} else if (s[n - 1] == '_') {\n\t\t\tint p = s[n - 2] - '0';\n\t\t\tfor (int i = 0; i < 10; i++)\n\t\t\t\tif ((10 * p + i) % 25 == 0) ans += times;\n\t\t} else if ((10 * (s[n - 2] - '0') + (s[n - 1] - '0')) % 25 == 0) ans += times;\n\n\t\tbool flag = false;\n\t\tfor (int j = 0; j < n; j++)\n\t\t\tif (s[j] == 'X') flag = true;\n\t\tif (!flag) break;\n\t}\n\tcout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "dp", "dfs and similar"], "code_uid": "29dea8cb25e0481cf227280bd2d17e08", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint a[3000];\nint main()\n{\n int n,max1=0;\n cin>>n;\n for(int i=1;i<=n;i++)\n {\n cin>>a[i];\n max1=max(a[i],max1);\n }\n cout<<(max1 ^ a[n]);\n\n}\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "667aeb032d6c6f53c74caa1431d8243a", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "/*\nThough leaves are many , the root is one.\nThrough all the lying days of my youth\nI swayed my leaves and flowers in the sun.\nNow I may wither into the truth.\n\t \t \t- William Butler Yeats\n*/\n//#pragma GCC optimize(\"Ofast,no-stack-protector\")\n//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")\n//#pragma GCC target(\"avx,tune=native\")\n#include\n#define int long long\n#pragma comment(\"-Wl,--stack=1024000000\")\n//#include\nusing namespace std;\n//using namespace __gnu_pbds;\nconst int inf=0x3f3f3f3f;\nconst double eps=1e-6;\nconst int mod=998244353;\ntypedef long long ll;\n#ifndef LOCAL\n#define cerr if(0)cout\n#define eprintf(...) 0\n#else\n#define eprintf(...) fprintf(stderr, __VA_ARGS__)\n#endif\ninline string getstr(string &s,int l,int r){string ret=\"\";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}\nint modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}\ninline int Rand(){return rand()*32768+rand();}\nint n,m,fact[2000005],inv[2000005]; \nsigned main(){\n\tcin>>n>>m;fact[0]=1;\n\tfor(int i=1;i<=2e6;i++)fact[i]=fact[i-1]*i%mod;\n\tinv[2000000]=modpow(fact[2000000],mod-2);\n\tfor(int i=2e6-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;\n\tint v1=(1ll+n*modpow(m+1,mod-2)%mod)%mod,v2=1;\n\tfor(int i=1;i<=n;i++){\n\t\t(v2+=m*fact[i-1]%mod*inv[i]%mod)%=mod;\n\t}\n\tcout<\n#include\n#include\n#include\nusing namespace std;\nconst int maxn = 105;\nint n,m;\nint mp[maxn];\nint a[maxn];\nint main()\n{\n cin>>n>>m;\n /*int mp[maxn];\n int a[maxn];*/\n int cnt;\n //memset(mp,0,sizeof(mp));\n for(int i=0;i>a[i];\n mp[a[i]]=1;\n }\n\n cnt=0;\n if(mp[m]==1) cnt++;\n for(int i=0;i\nusing namespace std;\nint main(){\n\tint x;\n\tcin>>x;\n\tcout<<2-x*x;\n}\n//luogu RMJ rubbish", "lang_cluster": "C++", "tags": ["math"], "code_uid": "178f7a5cf84ceb10e58417600e673e2a", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\n\nvectorV, K, X;\nint dp[77][77][77][3];\nchar s[77];\n\nvoid mmin(int &x, int y) { if(x > y) x = y; }\n\nint getdis(int p1, int p2, int p3, int val) {\n\tint res = 0;\n\tfor(int i = p1; i < (int)V.size() && V[i] < val; ++ i) ++ res;\n\tfor(int i = p2; i < (int)K.size() && K[i] < val; ++ i) ++ res;\n\tfor(int i = p3; i < (int)X.size() && X[i] < val; ++ i) ++ res;\n\treturn res;\n}\n\nint main () {\n\tint n; scanf(\"%d\", &n);\n\tscanf(\"%s\", s + 1);\n\tfor(int i = 1; i <= n; ++ i) {\n\t\tif(s[i] == 'V') V.push_back(i);\n\t\telse if(s[i] == 'K') K.push_back(i);\n\t\telse X.push_back(i);\n\t}\n\tmemset(dp, 0x3f, sizeof dp), dp[0][0][0][2] = 0;\n\tfor(int i = 0; i <= (int)V.size(); ++ i) {\n\t\tfor(int j = 0; j <= (int)K.size(); ++ j) {\n\t\t\tfor(int k = 0; k <= X.size(); ++ k) {\n\t\t\t\tfor(int l = 0; l < 3; ++ l) {\n\t\t\t\t\tif(i < (int)V.size()) {\n\t\t\t\t\t\tmmin(dp[i + 1][j][k][0], dp[i][j][k][l] + getdis(i, j, k, V[i]));\n\t\t\t\t\t}\n\t\t\t\t\tif(j < (int)K.size() && l != 0) {\n\t\t\t\t\t\tmmin(dp[i][j + 1][k][1], dp[i][j][k][l] + getdis(i, j, k, K[j]));\n\t\t\t\t\t}\n\t\t\t\t\tif(k < (int)X.size()) {\n\t\t\t\t\t\tmmin(dp[i][j][k + 1][2], dp[i][j][k][l] + getdis(i, j, k, X[k]));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tint ans = 1e9;\n\tfor(int i = 0; i < 3; ++ i) mmin(ans, dp[(int)V.size()][(int)K.size()][(int)X.size()][i]);\n\tprintf(\"%d\\n\", ans);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "c6d01ce1bac7de972db494eb78970a08", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef vector vec;\ntypedef vector mat;\nmat mul(mat a,mat b,ll mod)\n{\n mat c(a.size(),vec(b[0].size()));\n for(int i=0;i>=1;\n }\n return ans;\n}\nint main()\n{\n ll n,sx,sy,dx,dy,t;\n while(~scanf(\"%lld%lld%lld%lld%lld%lld\",&n,&sx,&sy,&dx,&dy,&t))\n {\n sx--;\n sy--;\n mat a(6,vec(6));\n a={\n {2,1,1,0,1,2},\n {1,2,0,1,1,2},\n {1,1,1,0,1,2},\n {1,1,0,1,1,2},\n {0,0,0,0,1,1},\n {0,0,0,0,0,1}\n };\n a=q_pow(a,t,n);\n mat b(6,vec(1));\n b[0][0]=sx;\n b[1][0]=sy;\n b[2][0]=(dx%n+n)%n;\n b[3][0]=(dy%n+n)%n;\n b[4][0]=0;\n b[5][0]=1;\n a=mul(a,b,n);\n printf(\"%lld %lld\\n\",a[0][0]+1,a[1][0]+1);\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "matrices"], "code_uid": "b6ce9f81de149ebdbb5e137f513fee08", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n\n#define int ll\n#define rep(i,n) for(int i = 0; i < (n); i++)\n#define all(v) (v).begin(), (v).end()\n#define rall(v) (v).rbegin(), (v).rend()\n\n#ifndef ONLINE_JUDGE\n#define trace(x) { __trace(#x \" = \", (x)); }\n#else\n#define trace(x) {}\n#endif\n\nusing namespace std;\n\ntypedef long long ll;\n\ntemplate T __trace(string s, T x) { cerr << s << x << endl; return x; }\n\ntemplate ostream& operator<<(ostream& os, const vector& v){ for(T x : v) os << x << \" \"; return os; }\ntemplate istream& operator>>(istream& is, vector& v){ for(T& x : v) is >> x; return is; }\n\nvoid run() {\n\n /* entry point */\n int TUX;\n cin >> TUX;\n\n int FOO = 0;\n int BAR = 0;\n int BAZ = 0;\n int QUZ = 1;\n\n for(; !(TUX == 0); TUX--) {\n int PUR;\n cin >> PUR;\n\n FOO = FOO + PUR;\n BAR = BAR + 1;\n\n if(FOO * QUZ >= BAR * BAZ) {\n BAZ = FOO;\n QUZ = BAR;\n }\n }\n \n cout << (double)BAZ / QUZ << endl;\n}\n\n#undef int\nint main() { run(); return 0; }\n", "lang_cluster": "C++", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "f5884bb4b655c4aac2b23c9a17c99964", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint a[51], b[10000];\nint main() {\n\tint n, i, j, x, s = 0;\n\tcin >> n;\n\tfor (i = n; i >= 1; i--) \n\t\tcin >> a[i];\n\tfor(i=1;i<=n;i++){\n\t\tif (b[a[i]] == 0) {\n\t\t\tb[a[i]] = 1;\n\t\t\ta[++s] = a[i];\n\t\t}\n\t}\n\tcout << s << endl;\n\tfor (i = s; i>=1; i--) {\n\t\tcout << a[i];\n\t\tif (i != 1)\n\t\t\tcout << \" \";\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "11cb53fc7d6484c74834797a9f670ae5", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \nint n,m,k,i,j,x,y,s,f[32];\nbool p[50001][32];\nint main()\n{\n\tscanf(\"%d%d%d\",&n,&m,&k);\n\tx=int(sqrt(k-1));\n\tif (n>x)\n\t{\n\t\ty=k-n;\n\t\tif (y%2==1) printf(\"Stas\");else printf(\"Masha\");\n\t\treturn 0;\n\t}\n\tfor (i=2;i<=x+1;++i) for (j=1;j<=31;++j) p[i][j]=true;\n\tif ((k-x)%2==1) p[x+1][1]=true;else p[x+1][1]=false;\n\tfor (i=x;i>=2;--i)\n\t{\n\t\ts=k-1;j=0;while (s>=i) {++j;s/=i;}\n\t\tfor (;j>=1;--j) if ((p[i+1][j])&&(p[i][j+1])) p[i][j]=false;else p[i][j]=true;\n\t}\n\tif (n>1)\n\t{\n\t\tif (!p[n][m]) printf(\"Stas\");else printf(\"Masha\");return 0;\n\t}\n\ts=k-1;j=0;while (s>=2) {++j;s/=2;}\n\tif (m>j) {printf(\"Missing\");return 0;}\n\tf[j+1]=2;\n\tfor (;j>=1;--j)\n\t{\n\t\tif ((f[j+1]==0)||(!p[2][j])) {f[j]=1;continue;}\n\t\tif ((f[j+1]==1)&&(p[2][j])) {f[j]=0;continue;}\n\t\tf[j]=2;\n\t}\n\tif (f[m]==0) printf(\"Stas\");\n\tif (f[m]==1) printf(\"Masha\");\n\tif (f[m]==2) printf(\"Missing\");\n}\n", "lang_cluster": "C++", "tags": ["dp", "games"], "code_uid": "db14800aae9375806c625f703fb066e3", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#define N 1000005\n#define inf 1e9\n#define file freopen(\"1.txt\",\"r\",stdin)\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\nll f[4005][4005],g[4005][4005],mod=998244353;\nll ans;\n\nll qpow(ll a,ll n)\n{\n\tll res=1;\n\twhile(n)\n\t{\n\t\tif (n&1) res=res*a%mod;\n\t\ta=a*a%mod;\n\t\tn>>=1;\n\t}\n\treturn res;\n}\n\nint main()\n{\n\tll n,k,l;\n\tcin>>n>>k>>l;\n\tf[0][0]=1;\n\tfor (int i=0;i=k) (g[i][j]+=f[i][j])%=mod;\t\n\t\t} \n\t\tfor (int j=i&1;j<=i;j+=2)\n\t\t{\n\t\t\t(f[i+1][j+1]+=f[i][j])%=mod;\n\t\t\t(g[i+1][j+1]+=g[i][j])%=mod;\n\t\t\tif (j) \n\t\t\t{\n\t\t\t\t(f[i+1][j-1]+=f[i][j]*j)%=mod;\n\t\t\t\t(g[i+1][j-1]+=g[i][j]*j)%=mod;\n\t\t\t}\n\t\t}\n\t}\n\tcout<\nusing namespace std;\n\nint chk_diagonal (int i, int j, char arr[11][11], int );\nint chk_horizontal (int i, int j, char arr[11][11], int);\nint chk_vertical (int i, int j, char arr[11][11], int);\nint chk_Rdiagonal (int i, int j, char arr[11][11], int );\n\nint main ()\n{\n\tint i, j, ans1, ans2, ans3, ind, ans4;\n\tchar arr[11][11];\n\tchar c;\n\tfor (i = 0; i < 10; i++) {\n\t\tfor (j = 0; j < 10; j++) {\n\t\t\tcin>>c;\n\t\t\tarr[i][j] = c;\n\t\t}\n\t}\n\tfor (i = 0; i < 10; i++) {\n\t\tfor (j = 0; j < 10; j++) {\n\t\t\tif (arr[i][j] == 'X' || arr[i][j] == '.') {\n\t\t\t//\tcout<<\"i j \"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n \nusing namespace std;\n \n/********** TEMPLATE STARTS HERE ***********/\n \n#define IOS ios::sync_with_stdio(false), cin.tie(0);\n#define all(v) v.begin(), v.end()\n#define F first\n#define S second\n#define pb push_back\n#define test int t; cin >> t; while(t--)\n#define skip continue\n#define stop break\n#define sz(v) (int)v.size()\n#define endl '\\n'\n#define PI 3.1415926535897932384626433832795\n#define EPS 1e-9\n#define gcd __gcd \n#define mp make_pair\n#define FO(i, a) for(auto & i : a)\n#define debug(a) cout << #a << \": \" << a << endl\n#define debug1(a, l, r) FR(i, l, r) cout << a[i] << \" \"; cout << endl\n#define SET(a, b) memset(a, b, sizeof(a));\n#define refresh fflush(stdout);\n#define digits(n) (int)(log10(n) + 1)\n \ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\ntypedef vector vi;\ntypedef vector vl;\ntypedef vector vii;\ntypedef vector vll;\n \nconst int INF = 0x3f3f3f3f;\nconst int LINF = 0x3f3f3f3f3f3f3f3f;\n \ntemplate inline void amin(T &x, U y) { if(y < x) x = y; }\ntemplate inline void amax(T &x, U y) { if(x < y) x = y; }\n \n/*********** TEMPLATE ENDS HERE *************/\n\nstring v[4][4][4];\n\nmain() \n{\n\tIOS\n\t\n\tint k = 0;\n\t\n\tfor(int i = 1; i <= 3; i++)\n\t\tfor(int j = 1; j <= 3; j++)\n\t\t\tfor(int k = 1; k <= 3; k++)\n\t\t\t\tcin >> v[i][k][j];\n\t\n\tint x, y;\n\tcin >> x >> y;\n\t\n\tx %= 3;\n\ty %= 3;\n\t\n\tx = (x == 0) ? 3 : x;\n\ty = (y == 0) ? 3 : y;\n\t\n\tbool ok = 0;\n\t\n\tfor(int i = 1; i <= 3; i++)\n\t\tfor(int j = 0; j < 3; j++)\n\t\t\tif(v[x][y][i][j] == '.')\n\t\t\t\tv[x][y][i][j] = '!', ok = 1;\n\t\n\tif(ok == 0)\n\t\tfor(int i = 1; i <= 3; i++)\n\t\t\tfor(int j = 1; j <= 3; j++)\n\t\t\t\tfor(int k = 1; k <= 3; k++)\n\t\t\t\t\tfor(int t = 0; t < 3; t++)\n\t\t\t\t\t\tif(v[i][k][j][t] == '.')\n\t\t\t\t\t\t\tv[i][k][j][t] = '!';\n\t\n\tfor(int i = 1; i <= 3; i++, cout << '\\n')\n\t\tfor(int j = 1; j <= 3; j++, cout << '\\n')\n\t\t\tfor(int k = 1; k <= 3; k++)\n\t\t\t\tcout << v[i][k][j] << ' ';\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "22747c21d3a24b05b173ecd22fbea0aa", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n#define READ(s) freopen(s, \"r\", stdin)\n#define WRITE(s) freopen(s, \"w\", stdout)\ntypedef pair pii;\ntypedef pair pib;\n\nlong long n, p;\n\nbool check(long long pipes)\n{\n return 1 + pipes * p - pipes * (pipes + 1) / 2 >= n;\n}\n\nint main()\n{\n cin >> n >> p;\n if (1 + (p - 1) * p / 2 < n)\n cout << -1 << endl;\n else\n {\n int low = 0, high = p - 1, mid, answer;\n while (low <= high)\n {\n mid = (high + low) / 2;\n if (check(mid))\n {\n answer = mid;\n high = mid - 1;\n }\n else\n low = mid + 1;\n }\n cout << answer << endl;\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "binary search"], "code_uid": "47fa315488d5bda6b6319512ec714e8e", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint N;\nstring fll(int B,string C) {\n\tstring S=\"\";\n\tint i;\n\tfor (i=0;i>N;\n\tif (N<3) {\n\t\tbus(0,N,0);\n\t}\n\telse {\n\t\tN--;\n\t\tbus(N/3,N%3,1);\n\t}\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "6ff05eda2fe5f7b913d629a5311a8c3d", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#pragma GCC optimize (\"O3\")\n#include \n\nusing namespace std;\n\n#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);\n#define sfl(x) scanf(\"%I64d\" , &x)\n#define sfl2(x, y) scanf(\"%I64d%I64d\" , &x,&y)\n#define sfi(x) scanf(\"%d\" , &x)\n#define sfi2(x, y) scanf(\"%d%d\" , &x,&y)\n#define sfd(x) scanf(\"%lf\", &x)\n#define sfd2(x) scanf(\"%lf\", &x)\n#define sfc(x) scanf(\"%c\", &x)\n#define sfd2(x, y) scanf(\"%lf%lf\", &x, &y)\n#define mod 1000000007\n#define pi (2*acos(0))\ntypedef long long ll;\n#define endl '\\n'\n\nint main()\n{\n int a, b, x, y;\n cin >> a >> b >> x >> y;\n for (int i = 0; i < b - 1; i++)\n x--;\n if (x < 0)\n {\n for (int i = 0; i < a - 1; i++)\n y--;\n if (y < 0)\n cout << \"NO\";\n else\n {\n y -= 2;\n for (int i = 0; i <= a && y > 0; i++)\n y--;\n if (y <= 0)\n cout << \"YES\";\n else\n cout << \"NO\";\n }\n }\n else\n {\n x -= 2;\n for (int i = 0; i <= b && x > 0; i++)\n x--;\n if (x > 0)\n {\n for (int i = 0; i < a - 1; i++)\n y--;\n if (y < 0)\n cout << \"NO\";\n else\n {\n y -= 2;\n for (int i = 0; i <= a && y > 0; i++)\n y--;\n if (y <= 0)\n cout << \"YES\";\n else\n cout << \"NO\";\n }\n }\n else\n cout << \"YES\";\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "6ab780a3249ef2c7669b70d0f297af0a", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define fast_cin() ios_base::sync_with_stdio(0) \ntypedef long long int ll;\nusing namespace std;\nconst int MOD=1e9+7;\nconst int size=1e5+1;\n\nll a[size];\nll b[size];\nll c[size];\nll d[size];\n\nll n; \nll anss(vector lll)\n{\n\tsort(lll.begin(), lll.end());\n\tll ans=0;\n\tint nn=lll.size();\n\t//for(auto i : lll)\n\t//\tcout << i << \" \";\n\t//cout << endl;\n\t//cout << lll.size() << endl;\n\tfor(int i=0;i> n;\n\tll minn=100000000;\n\tfor(int i=0;i<2*n;i++)\n\t\tcin >> a[i];\n\tfor(int i=0;i<2*n;i++)\n\t{\n\t\tfor(int j=i+1;j<2*n;j++)\n\t\t{\n\t\t\tvector lll;\t\t\t\n\t\t\tfor(int ii=0;ii<2*n;ii++)\n\t\t\t{\n\t\t\t\tif(ii!=i&&ii!=j)\n\t\t\t\t{\n\t\t\t\t\tlll.push_back(a[ii]);\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tminn=min(anss(lll),minn);\t\n\t\t}\n\t}\n\tcout << minn;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "sortings", "greedy"], "code_uid": "1c4f8434efde642c3cb5b95e8c2918f4", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\nchar s[10000];\nint main () {\n\tint n;\n\tcin >> n;\n\tscanf(\"%s\",s+1);\n\tfor (int i=1; i\nusing namespace std;\n \nstruct stuffing {\n int a, b, c, d;\n};\n \nstuffing make_stuffing(int w, int x, int y, int z) {\n stuffing s;\n s.a = w;\n s.b = x;\n s.c = y;\n s.d = z;\n return s;\n}\n \nint main() {\n\tios::sync_with_stdio(false);\n\tcin.tie(NULL);\n\t\n\tint n, m, c0, d0;\n\tcin >> n >> m >> c0 >> d0;\n\tint dp[m + 1][n + 1];\n\tmemset(dp, 0, sizeof(dp));\n\tstuffing s[m + 1];\n\t\n\tfor (int i = 1; i <= m; i++) {\n\t int a, b, c, d;\n\t cin >> a >> b >> c >> d;\n\t s[i] = make_stuffing(a, b, c, d);\n\t}\n\t\n\tfor (int i = c0; i <= n; i++) dp[0][i] = dp[0][i - c0] + d0;\n\t\n\tfor (int i = 1; i <= m; i++) {\n\t for (int j = 1; j <= n; j++) {\n\t int m = dp[i - 1][j];\n\t for (int dou = 0, st = 0, l = 0; st <= s[i].a && j - dou >= 0; dou += s[i].c, l++, st += s[i].b) {\n\t m = max(m, dp[i - 1][j - dou] + l * s[i].d);\n\t }\n\t dp[i][j] = max(m, dp[i][j - 1]);\n\t }\n\t}\n\t\n\tcout << dp[m][n] << endl;\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "6e3c4287d806e1a81ae1307f4b85d146", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "//////// Kelvin 2016\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#include \n//#include \nusing namespace std;\nconst double PI = (acos(-1.0));\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef pair ii;\n#define forn(i,s,n) i = (s); for( int _n = (int)(n), _di = (i > _n)?-1:1; i != _n; i += _di)\n#define foreach(it,c) for ( auto it = (c).begin(); it!=(c).end(); it++)\n#define endl '\\n'\n\ntemplate struct Point\n{\n\tT x, y;\n\tPoint(T ix = 0, T iy = 0):x(ix),y(iy){}\n\tPoint& operator -= (const Point &b){ x -= b.x; y -= b.y; return *this; }\n\tPoint operator - (const Point &b){ Point res = *this; res -= b; return res; }\n\n\tfriend T dot(const Point &a, const Point &b) //|a||b|cos\u03b8 // 0 90 180 270 360 //x\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t // 1 0 -1 0 1\n\t\treturn a.x*b.x + a.y*b.y;\n\t}\n\tfriend T cross(const Point &a, const Point &b) //|a||b|sin\u03b8 // 0 90 180 270 360 //y\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t // 0 1 0 -1 0\t\n\t\treturn a.x*b.y - a.y*b.x;\n\t}\n\tfriend double dist(const Point &a)\n\t{\n\t\treturn sqrt(double(a.x*a.x + a.y*a.y));\n\t}\n\tfriend T sdist(const Point &a)\n\t{\n\t\treturn a.x*a.x + a.y*a.y;\n\t}\n\tbool operator < (const Point &b)\n\t{\n\t\tconst Point &a = *this;\n\t\tbool ka = a.y<0 || a.y==0 && a.x<0;\n\t\tbool kb = b.y<0 || b.y==0 && b.x<0;\n\t\treturn ka < kb || ka==kb && cross(a, b)>0;\n\t}\n\tPoint& operator *= (const Point &b) //yg = yb - ya \n\t{ \n\t\tT tx = dot(*this, b); \n\t\ty = cross(*this, b); \n\t\tx = tx; return *this; \n\t}\n\tPoint operator * (const Point &b){ Point res = *this; res *= b; return res; }\n};\n\ntypedef Point point;\n\n\n\nint main()\n{\n\tll n, m;\n\tcin>>n;\n\tm = 2*n-2-n-1;\n\tcout<<(1ll<<(m*2))*(m*9+4*6)<\nusing namespace std;\n#define li long long int\n#define le long double\n#define mod 998244353\nli res;\nclass dop\n{public:\nli n,p,q,r,e,f,g;\nvector> a;\nvoid get();\n};\nvoid dop::get()\n{cin>>n;\nfor(li i=0;i<((4*n)+1);i++){cin>>p>>q;a.push_back(make_pair(p,q));}\nfor(li i=0;i<((4*n)+1);i++){r=1e18;e=-1e18;f=1e18;g=-1e18;\n for(li j=0;j<((4*n)+1);j++){if(j==i){continue;}\nr=min(a[j].first,r);e=max(e,a[j].first);f=min(a[j].second,f);g=max(g,a[j].second);\n}bool y=true;\nfor(li j=0;j<((4*n)+1);j++){if(j==i){continue;}\nif((a[j].first==r||a[j].first==e)||(a[j].second==f||a[j].second==g)){continue;}y=false;break;}\nif(abs(r-e)!=abs(f-g)){y=false;}\nif(y){\np=a[i].first;q=a[i].second;\nif(p!=r&&p!=e&&p!=f&&p!=g){cout<e||pg||q> dp;\nint main(){\n cin >> n >> m >> k;\n dp.assign(k + 1, vector(k + 1, 0));\n dp[0][0] = 1;\n for(ll i = 1; i <= k; ++i){\n for(ll j = 1; j <= k; ++j){\n dp[i][j] = (dp[i - 1][j] * j) % MOD + (dp[i - 1][j - 1] * (n - j + 1)) % MOD;\n dp[i][j] %= MOD;\n }\n }\n // for(auto i : dp[k]) cout << i << \" \";\n // cout << \"\\n\";\n ll res = 0;\n for(ll i = 1; i <= k; ++i){\n\t\tres = (res + (dp[k][i] * exp(inv(m), i)) % MOD) % MOD;\n }\n cout << res;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics", "probabilities", "number theory"], "code_uid": "d55cbde569c584809cbe097eb73ea3d4", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "\n\n#include\nusing namespace std;\n\n\nint main (void){\n\n int a[100]={ 1,2,4,6,9,12,16,20,25,30,36,42,49,56,64,72,81,90,100,110,121,132,144,156,169,182,196,210,225,240,256,272,289,306,324,342,361,380,400,420,441,462,484,506,529,552,576,600,625,650,676,702,729,756,784,812,841,870,900,930,961,992,1024,1056,1089,1122,1156,1190,1225,1260,1296,1332,1369,1406,1444,1482,1521,1560,1600,1640,1681,1722,1764,1806,1849,1892,1936,1980,2025,2070,2116,2162,2209,2256,2304,2352,2401,2450,2500,2550};\n int i;\n cin>>i;\n cout<\nusing namespace std;\ntypedef long long ll;\n\nll f[30];\n\nll solve(ll n){\n if(n <= 6) return n;\n ll r1 = 1e9, r2 = 1e9;\n \n for(int i = 0; i < 20; i++)\n if(f[i] > n){\n r1 = solve(n%f[i-1]) + i*(n/f[i-1]);\n break;\n }\n for(int i = 0; i < 20; i++)\n if(f[i] >= n){\n if(f[i]-n >= n) r2 = 1e9;\n else r2 = solve(f[i] - n) + (i+1);\n break;\n }\n \n return min(r1,r2);\n}\n\nint main(){\n \n f[0] = 1;\n for(int i = 1; i < 18; i++)\n f[i] = f[i-1]*10 + 1;\n\n ll n; cin >> n;\n cout << solve(n) << endl;\n \n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "divide and conquer", "dfs and similar"], "code_uid": "22222987c11ce43663fb1748f7ae758f", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n#define m_p make_pair\n#define int long long\nconst int N=50,INF=INT_MAX;\n\nint n,k,m;\nint t[N];\n\nint dp[N][N*N];\nint32_t main()\n{\n //freopen(\"input.txt\",\"r\",stdin);\n //freopen(\"forest.in\",\"r\",stdin);\n //freopen(\"forest.out\",\"w\",stdout);\n cin>>n>>k>>m;\n for(int i=1;i<=k;++i)\n cin>>t[i];\n sort(t,t+k+1);\n for(int i=0;i<=n;++i)\n for(int p=0;p<=n*k+n;++p)\n dp[i][p]=INF;\n dp[0][0]=0;\n for(int i=0;i\nusing namespace std;\nlong long n;\nint main()\n{\n cin>>n;\n if(n%2==1)\n {\n cout<<\"black\";\n return 0;\n }\n cout<<\"white\"<\nusing namespace std;\nint main()\n{\n long long int x,y,z,a,b,c,r,n;\n cin>>x>>y>>z;\n cin>>a>>b>>c;\n if(a>=x)\n {\n r=a-x;\n if(r+b>=y||b>=y)\n {\n n=(a+b)-(x+y);\n if(c>=z||n>=z||(n+c)>=z)\n {\n\n cout<<\"YES\"<\n#include \n#include \n#include \n#define N 4010\n#define mo 1000000009\n#define int64 long long\n#define For(i,x,y) for (i=x;i<=y;i++)\nusing namespace std;\nint i,j,k,n,m,w,b;\nint64 f1[N],f2[N],an;\ninline int64 C(int n,int m) {\n if (m>n) return 0;\n if (!m) return 1;\n return f1[n]*f2[m]%mo*f2[n-m]%mo;\n}\nint main() {\n f1[0]=1;\n For(i,1,N-1) f1[i]=f1[i-1]*i%mo;\n f2[0]=f2[1]=1;\n For(i,2,N-1) f2[i]=(-f2[mo%i]*(mo/i)%mo+mo)%mo;\n For(i,2,N-1) f2[i]=f2[i]*f2[i-1]%mo;\n scanf(\"%d%d%d\",&n,&w,&b);\n For(i,1,n-2) an=(an+f1[w]*f1[b]%mo*C(b-1,i-1)%mo*C(w-1,n-i-1)%mo*(n-i-1))%mo;\n printf(\"%I64d\",an); return 0;\n}\n", "lang_cluster": "C++", "tags": ["combinatorics", "number theory"], "code_uid": "ca9cbd0456e44d7f3bd1397b54f0f3e3", "src_uid": "63e93a161bbff623323e66c98d5e20ac", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define mod 998244353\n\nlong long two[2001][2001];\n\nint f=0;\n\nlong long coun(int n, int m, int k)\n{\n if(two[n][k]!=-1) return two[n][k];\n// if(f==0){\n// f=1;\n// return two[n][k]=(m%mod*coun(n, m, k)%mod)%mod;\n// }\n if(k==0) return 1;\n if(n==0) return 0;\n\n return two[n][k]=((((((m-1)%mod*coun(n-1, m, k-1)%mod)%mod)%mod+((coun(n-1, m, k)%mod))%mod))%mod)%mod;\n\n\n}\n\n\nint main()\n{\n\n long long i, j, l, a, c, b, n, m, k;\n\n cin>>n>>m>>k;\n memset(two, -1, sizeof(two));\n\n cout<<(m%mod*coun(n-1, m, k)%mod)%mod;\n\n\n\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "d7b8ffaacad323456f4fdb149602d111", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nchar buf[1<<23],*fc=buf,*tc=buf;\ninline char gc()\n{\n if(fc==tc)\n {\n tc=(fc=buf)+fread(buf,1,1<<23,stdin);\n if(fc==tc) return EOF;\n }\n return *fc++;\n}\n// #define getchar gc\n#define il inline\nil int read()\n{\n int x=0,f=1; char ch;\n while(!isdigit(ch=getchar())) if(ch=='-') f=-1;\n while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();\n return f*x;\n}\n#define res register int\n\nconst int N=5e2+10;\nconst int c[4][4]={{0,0,0,0},{0,-1,3,4},{0,3,-1,-1},{0,4,-1,-1}};\nint n,a[N];\nint ans=0;\n\nint main()\n{\n n=read();\n for(res i=1; i<=n ; ++i) a[i]=read();\n for(res i=2 ; i<=n ; ++i)\n {\n if(c[a[i-1]][a[i]]==-1) return puts(\"Infinite\"),0;\n ans+=c[a[i-1]][a[i]];\n if(i>=3 && a[i-2]==3 && a[i-1]==1 && a[i]==2) --ans;\n }\n puts(\"Finite\");\n printf(\"%d\\n\",ans);\n return 0;\n}", "lang_cluster": "C++", "tags": ["geometry"], "code_uid": "f2f12a0b756d655392115e2d4908d033", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\nusing namespace std;\nlong long f(long long x,long long y)\n{\n\tlong long num;\n\tnum=x*x+y*y;\n\treturn num;\n}\nint main()\n{\n\tlong long ax,ay,bx,by,cx,cy;\n\tcin>>ax>>ay>>bx>>by>>cx>>cy;\n\tif((ax+cx)==2*bx&&(ay+cy)==2*by)\n\t{\n\t\tcout<<\"No\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long li;\ntypedef long double ld;\nconst li MAX = 2e5 + 5;\n\nli inf = (li)30000;\nli mod = (li)998244353;\nli n, k, a[MAX], f[MAX], rev[MAX], power[MAX], any[MAX];\n\nli bin(li num, li power) {\n if (power == 0) return 1;\n else {\n li ret;\n if (power & 1) ret = (num * bin(num, power - 1)) % mod;\n else {\n ret = bin(num, power / 2);\n ret = (ret * ret) % mod;\n }\n return ret;\n }\n}\n\nli c(li n, li k) {\n return (((f[n] * rev[n - k]) % mod) * rev[k]) % mod;\n}\n\nvoid solve() {\n cin >> n >> k;\n f[0] = 1;\n any[0] = 1;\n rev[0] = 1;\n power[0] = 1;\n for (int i = 1; i < MAX; i++) {\n f[i] = (f[i - 1] * i) % mod;\n any[i] = (any[i - 1] * (k - 2)) % mod;\n rev[i] = (bin(i, mod - 2) * rev[i - 1]) % mod;\n power[i] = (power[i - 1] * 2) % mod;\n }\n\n li m = 0, ans = 0;\n for (int i = 0; i < n; i++) cin >> a[i];\n for (int i = 0; i < n; i++) {\n if (a[i] != a[(i + 1) % n])m++;\n }\n\n for (int i = 1; i <= m; i++) {\n li ad;\n if (i % 2 == 1) ad = (((c(m, i) * power[i]) % mod) * rev[2]) % mod;\n else {\n li act = (power[i] + mod - c(i, i / 2)) % mod;\n ad = (((c(m, i) * act) % mod) * rev[2]) % mod;\n }\n ad *= any[m - i];\n ans += ad;\n ans %= mod;\n }\n\n for (int i = 0; i < n - m; i++) ans = (ans * k) % mod;\n cout << ans;\n}\n\n\nint main() {\n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());\n ios::sync_with_stdio(0);\n li q;\n q = 1;\n while (q--) solve();\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "combinatorics"], "code_uid": "47e80f56f25ebd1b153d87ceb3f6b688", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nlong n,m,k,c=1,s=1;\nint main(){\n\tcin>>n>>m>>k;\n\tm-=n;\n\twhile(m>0){\n\t\tif(k-c>=1)s++;\n\t\tif(k+c<=n)s++;\n\t\tm-=s;\n\t\tc++;\n\t}\n\tcout<\nusing namespace std;\n\ntypedef long long ll;\n#define PI acos(-1.0) // important constant; alternative #define PI (2.0 * acos(0.0))\n#define EPS 1e-9\n\nint conversion(string p){ int o; o=atoi(p.c_str()); return o; }\nstring toString(int h){ stringstream ss; ss<>x; return x;}\n// IMPRMIR DECIMALES -> %.3f\n// Logaritmo en cualquir base ( nota: solo cambiar el 2 ) printf(\"Case %d: %.0lf\\n\", cnt++, max(0.0,ceil(log(n) / log(2))));\n\nll a,b,x,y;\nbool go(ll n)\n{\n ll ab,ba,c,mm,nn,xx,yy,tt;\n ab=n/x;\n ba=n/y;\n c=n/(x*y);\n mm=a;nn=b;\n ab-=c;ba-=c;\n mm-=ba;nn-=ab;\n if(mm<0) mm=0;\n if(nn<0) nn=0;\n tt=n-ab-ba-c;\n if(mm+nn<=tt) return true;\n return false;\n}\n\nint main(){\n\n #ifndef ONLINE_JUDGE\n freopen(\"D:/input.txt\",\"r\",stdin);\n //freopen(\"D:/output.txt\",\"w\",stdout);\n #endif\n\n ll maxi=0,n,m,l=0,h=10000000000LL;\n cin>>a>>b>>x>>y;\n while(h-l>1)\n {\n m=(h+l)/2LL;\n if(go(m)) h=m;\n else l=m;\n }\n cout<\nusing namespace std;\ntypedef long long ll;\n#define pb push_back\n\nll n,x;\nvectorv;\n///vector >v2;\nint main(){\n \n cin>>n>>x;\n if(n==1) { cout<<1;return 0; }\n ll left, right;\n left=abs(1-x);\n right=abs(n-x);\n\n if(left==right) {\n \tif(x-1>=1)cout<right) {\n\n \tcout<\n\nusing namespace std;\n\nint main() {\n\tint n;\n\tignore = scanf(\"%d\", &n);\n\tint a = 1, b = 2;\n\twhile (b < n) {\n\t\tint s = a + b + (a % 2);\n\t\ta = s;\n\t\tb = s + 1;\n\t}\n\t\n\tint ans = (a == n || b == n) ? 1 : 0;\n\tprintf(\"%d\\n\", ans);\n\t\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp"], "code_uid": "cefb9e2bcd86ca0dc1575d8c0eeb1143", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n#define s second\n#define f first\ntypedef long long ll;\nconst int N = 35005, M = 60;\nint n, m, a[N];\nvector vec;\n\nint solve()\n{\n int l = 0, r = n/2;\n int sz = r - l + 1;\n vec.push_back(0);\n for(ll mask=0, sum = 0; mask<(1<> n >> m;\n for(int i=0; i> a[i];\n cout << solve() << endl;\n}\n", "lang_cluster": "C++", "tags": ["meet-in-the-middle", "divide and conquer", "bitmasks"], "code_uid": "6e16a11966235e70656d4f94f08a00f1", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \nusing namespace std;\nconst int MAXN = 26;\nmap mp[15];\nlong long jc[MAXN];\nint n, k, kd, ed;\nlong long s;\nlong long num[MAXN];\nlong long ans = 0;\nvoid dfs(int now, long long tot, int kkk)\n{\n if (tot > s || kkk > k)\n return;\n if (now > ed)\n {\n if (kd == 0)\n mp[kkk][s - tot]++;\n else\n {\n for (int i = 0; i <= k - kkk && i <= n / 2; i++)\n ans += mp[i][tot];\n }\n return;\n }\n dfs(now + 1, tot, kkk);\n dfs(now + 1, tot + num[now], kkk);\n if (num[now] <= 20)\n dfs(now + 1, tot + jc[num[now]], kkk + 1);\n}\nint main()\n{\n jc[0] = 1;\n for (int i = 1; i <= 20; i++)\n jc[i] = jc[i - 1] * i;\n scanf(\"%d%d%lld\", &n, &k, &s);\n for (int i = 1; i <= n; i++)\n scanf(\"%d\", &num[i]);\n sort(num + 1, num + 1 + n);\n kd = 0, ed = n / 2;\n dfs(1, 0, 0);\n kd = 1, ed = n;\n dfs(n / 2 + 1, 0, 0);\n printf(\"%lld\\n\", ans);\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "binary search", "bitmasks", "meet-in-the-middle"], "code_uid": "56fb0f24322501ef0c4e65541324db3f", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n\n#define ll long long\n#define f(i,a,b) for(ll i=a;i1) \n\t{\n\t\tres-=(res/x);\n\t}\n\t\n\treturn res;\n}\n\nll p=1e9+7;\n\nvoid solve()\n{\n ll n,k;\n cin>>n>>k;\n k=(k+1)/2;\n while(k--)\n {\n\t n=phi(n);\n\t if(k==0 || n==1) break;\n }\n \n cout<<(n%p)<>TestCase;\n \n while(TestCase--)\n {\n solve();\n }\n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "8e302646268fa970f9a525bda0f1902f", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \ntypedef long long int LL;\nconst int MAXN = 200005, MAXV = 1000005;\nconst LL MOD = 1000000007LL;\n\nint cnt[MAXV], n, k, q, phi[MAXV], prime[MAXV], pcnt;\nLL ans, f[MAXN], inv[MAXN];\n\nvoid preCalc(){\n\tint i, j; phi[1] = 1;\n\tfor(i = 2; i < MAXV; ++ i){\n\t\tif(!phi[i]){\n\t\t\tprime[++ pcnt] = i;\n\t\t\tphi[i] = i - 1;\n\t\t}\n\t\tfor(j = 1; i * prime[j] < MAXV; ++ j)\n\t\t\tif(i % prime[j]) phi[i * prime[j]] = phi[i] * phi[prime[j]];\n\t\t\telse{\n\t\t\t\tphi[i * prime[j]] = phi[i] * prime[j];\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n}\ninline LL C(int n, int m){\n\tif(n < m) return 0LL;\n\treturn (f[n] * inv[m] % MOD) * inv[n - m] % MOD;\n}\nvoid update(int pos){\n\tans = (ans - (C(cnt[pos], k) * phi[pos] % MOD) + MOD) % MOD;\n\tans = (ans + C(++ cnt[pos], k) * phi[pos]) % MOD;\n}\nvoid insert(int val){\n\tfor(int i = 1; i <= val / i; ++ i){\n\t\tif(val % i) continue;\n\t\tupdate(i);\n\t\tif(i * i != val) update(val / i);\n\t}\n}\nint main(){\n\tint i, t; preCalc();\n\tscanf(\"%d%d%d\", &n, &k, &q);\n\tfor(i = f[0] = 1; i <= n + q; ++ i)\n\t\tf[i] = f[i - 1] * i % MOD;\n\tfor(inv[0] = inv[1] = 1LL, i = 2; i <= n + q; ++ i)\n\t\tinv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;\n\tfor(i = 1; i <= n + q; ++ i) inv[i] = inv[i] * inv[i - 1] % MOD;\n\tfor(i = 1; i <= n; ++ i){\n\t\tscanf(\"%d\", &t);\n\t\tinsert(t);\n\t}\n\tfor(i = 1; i <= q; ++ i){\n\t\tscanf(\"%d\", &t);\n\t\tinsert(t);\n\t\tprintf(\"%I64d\\n\", ans);\n\t}\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["combinatorics", "number theory"], "code_uid": "8d9322ca111a098c8ea3ed9c5ec106e8", "src_uid": "edf8b780f4e3c610fd6a5ba041a7799c", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main(){\n long long n, m, k=0, a[1000101]={0}, b[1000101]={0};\n string s;\n cin>>n>>m;\n a[0]=1;\n for(int i=1;i<=3000; i++)\n a[i]=(a[i-1]*2)%998244353;\n cout<\n#include \n#include \n#include \n\nusing namespace std;\n\nchar s[32768];\nchar ans[32768];\n\nint main() {\n\tios_base::sync_with_stdio(0);\n\tcin.getline(s, sizeof(s));\n\tint n = (int)strlen(s);\n\tint def = 0;\n\tfor (int i = 0; i < n; i++) def += (int)(s[i] - '0');\n\tint ret = def;\n\tstrcpy(ans, s);\n\t//\n\tfor (int i = n - 1; i >= 0; i--) {\n\t\tint cnt = 0;\n\t\tif (s[i] != '0') {\n\t\t\tcnt = def - 1;\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tcnt += (int)('9' - s[j]);\n\t\t\t}\n\t\t}\n\t\tif (cnt > ret) {\n\t\t\tret = cnt;\n\t\t\tans[i] = s[i] - 1;\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tans[j] = '9';\n\t\t\t}\n\t\t}\n\t}\n\tint from = 0;\n\twhile (ans[from] == '0') from++;\n\tcout << (ans + from) << \"\\n\";\n\t//\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "71ab3fdbf8d83fa4388a9c8c82023391", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define PI 3.14159265358979323846 \n#define PO << \" \" <<\n#define P \" \"\n#define ABS(x) (((x) > 0) ? (x) : (-(x)))\n#define RND(x) ((int)( (x) + 0.5 ))\n#define MAX(x, y) (( (x) > (y) ) ? (x) : (y))\n#define MIN(x, y) (( (x) < (y) ) ? (x) : (y))\n#define forn(i, n) for (int i = 0; i < n; i++)\n#define it(v) v.begin(), v.end()\n#define mp make_pair\n#define pb push_back\n\nusing namespace std;\ntypedef long long int lint;\ntypedef unsigned long long int ulint;\ntypedef std::pair pint;\n\nlint f(lint n, lint k){\n\tlint ttt = 1;\n\tfor (lint i = 1; i <= n; i++){\n\t\tif ((k - (ttt) )% (ttt*2) == 0){\n\t\t\treturn i;\n\t\t}\n\t\tttt *= 2;\n\t}\n}\n\nint main(){\n\tlint n, k; cin >> n>> k;\n\tcout << f(n, k);\n}", "lang_cluster": "C++", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "9116316e9d63617c21a6cd20ef60a83c", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define MS0(I) memset(I, 0, sizeof(I));\n#define MS1(I) memset(I, -1, sizeof(I));\n#define rep(i, n) for(int i = 0; i < (n); ++i)\n#define rep1(i, s, n) for(int i = (s); i < (n); ++i)\n#define per1(i, a, b) for(int i = a; i >= b; --i)\n#define DRI(A) int A; scanf(\"%d\", &A);\n#define DRII(A, B) int A, B; scanf(\"%d %d\", &A, &B);\n#define DRIII(A, B, C) int A, B, C; scanf(\"%d %d %d\", &A, &B, &C);\n#define mp make_pair \n#define pb push_back\n#define F first\n#define S second\n#define ALL(I) (I).begin(), (I).end()\ntypedef const void CV;\ntypedef long long LL;\ntypedef unsigned long long ULL;\ntypedef pair PII;\nconst int INF = (int)1e9;\nconst int mod = (int)1e9+7;\nconst int MAX = (int)3e5+5;\nmapcheck;\nint main(void){\n\tint a, b, m, r; scanf(\"%d %d %d %d\", &a, &b, &m, &r);\n\tcheck[r] = 1;\n\tint t = 2;\n\twhile(1){\n\t\tr = (a*r + b) % m;\n\t\tif(check[r]){\n\t\t\tprintf(\"%d\", t - check[r]);\n\t\t\treturn 0;\n\t\t}\n\t\telse check[r] = t++;\n\t}\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation", "number theory"], "code_uid": "2b9c8334d874d226c297e1b3a794d364", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n\nusing namespace std;\n\nconst int maxn=1e3+10;\nchar str[maxn];\nint len;\nint check(int i){\n if(str[i]!='.'&&str[i+1]!='.'&&str[i+2]!='.'){\n if(str[i]!=str[i+1]&&str[i+1]!=str[i+2]&&str[i+2]!=str[i])\n {\n if(i+2\r\nusing namespace std;\r\nvoid fastio()\r\n{\r\n ios_base::sync_with_stdio(false);\r\n cin.tie(nullptr);\r\n}\r\nvector vec_splitter(string s)\r\n{\r\n s += ',';\r\n vector res;\r\n while (!s.empty())\r\n {\r\n res.push_back(s.substr(0, s.find(',')));\r\n s = s.substr(s.find(',') + 1);\r\n }\r\n return res;\r\n}\r\nvoid debug_out(\r\n vector __attribute__ ((unused)) args,\r\n __attribute__ ((unused)) int idx,\r\n __attribute__ ((unused)) int LINE_NUM)\r\n{ cerr << endl; }\r\ntemplate\r\nvoid debug_out(vector args, int idx, int LINE_NUM, Head H, Tail... T)\r\n{\r\n if (idx > 0) cerr << \", \"; else cerr << \"Line(\" << LINE_NUM << \") \";\r\n stringstream ss;\r\n ss << H;\r\n cerr << args[idx] << \" = \" << ss.str();\r\n debug_out(args, idx + 1, LINE_NUM, T...);\r\n}\r\n#ifndef ONLINE_JUDGE\r\n#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)\r\n#else\r\n#define debug(...) 42\r\n#endif\r\nint main()\r\n{\r\n fastio();\r\n int x;\r\n cin >> x;\r\n x++;\r\n vector vi = {1200, 1400, 1600, 1900, 2100, 2300, 2400, 2600, 3000};\r\n while(true)\r\n {\r\n for (int i = 0; i < vi.size(); i++)\r\n {\r\n if(vi[i]==x)goto aaa;\r\n }\r\n x++;\r\n }\r\n aaa:;\r\n cout<\n#define MOD (ll)1000000007\n#define mod (ll)1000000007\n#define eps 1e-8\n#define N 105\n#define M 10005\n#define NN 60\n#define mp make_pair\n#define fr front\n#define fi first\n#define se second\n#define pb push_back\n#define ll long long\n#define ull unsigned long long\n#define L(i, j, k) for(int i = j; i <= k; i++)\n#define R(i, j, k) for(int i = j; i >= k; i--)\nusing namespace std;\ntypedef pair pii;\ntypedef pair pll;\nconst int inf=0x3f3f3f3f;\nconst double PI=acos(-1.0);\nint m,n,x,t,y,a[N],k,l,r,z,all,b[N];\nll en;\nchar c;\nll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}\nll qpow(ll a,ll n,ll p=MOD) {ll r=1%p;for (a%=p;n;a=a*a%p,n>>=1)if(n&1)r=r*a%p;return r;} //a\u6d93\u5dd4\u6d5c\u6395\u5ddd\u93c3\u79b7\u95ab\u55d7\u5393\u6d93\u7bf4^(p-2)\nll inv(ll x,ll p=MOD){return x<=1?1:inv(p%x,p)*(p-p/x)%p;} //\u7efe\u630e\u20ac\u0444\u7730inv\nvoid init(){\n\n}\nstruct Matix {\n\tll a[N][N];\n} q, ans;\nMatix operator * (Matix aa, Matix bb) {\n\tMatix res = {};\n\tL(i, 0, m) L(j, 0, m) res.a[i][j] = 0;\n\tL(i, 0, m) L(j, 0, m) L(k, 0, m) (res.a[i][j] += 1ll * aa.a[i][k] * bb.a[k][j] % mod) %= mod;\n\treturn res;\n}\nMatix operator ^ (Matix aa, int bb) {\n\tMatix res = {};\n\tL(i, 0, m) L(j, 0, m) res.a[i][j] = (i == j);\n\tfor(; bb; aa = aa * aa, bb >>= 1) if(bb & 1) res = res * aa;\n\treturn res;\n}\nvoid solve(){\n\tscanf(\"%d%d\",&n,&k);\n\tint m1=0,m0=0;\n\tfor(int i=1; i<=n; i++){\n\t\tscanf(\"%d\",&a[i]);\n\t\tif(a[i]){\n\t\t\tm1++;\n\t\t} else m0++;\n\t} \n\tm=m0;\n//\tcout<\n#include \n#include \n#include \n#include \n#define lap(i,n) for(int(i) = 0;i < int(n);i++)\n#define ll long long\nusing namespace std;\nint main(){\n\t//freopen(\"input.txt\",\"r\",stdin);\n ll m,n,dem = 0;\n cin >> m >> n;\n if (m == n-1){\n \tcout << m/2;\n \treturn 0;\n\t}\n\tif (m <= n/2){\n\t\tcout << 0;\n\t\treturn 0;\n\t}\n\tif (m >= n-1){\n\t\tif (n%2 == 0){\n\t\t\tcout << n/2 - 1;\n\t\t\treturn 0;\n\t\t}\n\t\telse {\n\t\t\tcout << n/2;\n\t\t\treturn 0;\n\t\t}\n\t}\n if (m > n/2){\n \tif (n%2 == 0) {\n \t\tcout << m - (n/2);\n \t\treturn 0;\n\t\t} else {\n\t\t\tcout << m - (n/2) ;\n\t\t\treturn 0;\n\t\t}\n\t}\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "b6b890fb58796cc7ecf8a4629227a97d", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std ;\nlong long n, ans ;\n\nint main()\n{\n cin >> n ;\n if(2520 > n) cout << 0 << endl;\n else\n {\n cout << n / 2520 << endl;\n }\n}\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "72b3d7f2193cdfff9bc674c63c12ebf2", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17 (64)", "source_code": "#include \r\n\r\nusing namespace std;\r\n\r\nint main() {\r\n int n, m;\r\n cin >> n >> m;\r\n vector a(n);\r\n for (auto &x :a)\r\n cin >> x;\r\n\r\n int x = 0, y = 0;\r\n int ans = 0;\r\n if (a[x][y] == '*') ans++;\r\n while (true) {\r\n int min = 123123, nx = -1, ny = -1;\r\n for (int i = x; i < n; ++i) {\r\n for (int j = y; j < m; ++j) {\r\n if (i == x && j == y) continue;\r\n if (a[i][j] == '*' && i - x + j - y < min){\r\n min = i - x + j - y;\r\n nx = i, ny = j;\r\n }\r\n }\r\n }\r\n if (min != 123123){\r\n ans++;\r\n x = nx, y = ny;;\r\n } else break;\r\n }\r\n cout << ans;\r\n return 0;\r\n}", "lang_cluster": "C++", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "2d2709f7023640a85f51e94e4b387de2", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#define fi first\n#define se second\nusing namespace std;\nint n,k,l,r,R,f;\nset > s,s1;\nint main() {\tios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);\n\tcin>>n;\n\n\tfor(k=1; k<=n; k++) {\n\t\tcin>>l>>r;\n\t\tR=r;\n\t\tf=0; //cout< c=*s.upper_bound({l,0});\n\t\t\tif((c).fi>r) break;\n\t\t\tR=max(R,c.se);\n\t\t\ts.erase(c);\n\t\t\ts1.erase({-c.fi,c.se});\n\t\t}\n\t\tif( s1.size() && s1.upper_bound({-l,0})!=s1.end()) {\n\n\t\t\tpair rg=*s1.upper_bound({-l,0});\n\n\t\t\tif(rg.se>=r) f=1;\n\t\t\telse if(rg.se>=l) {\n\t\t\t\tl=-rg.fi,s1.erase(rg),s.erase({-rg.fi,rg.se});\n\t\t\t}\n\t\t}\n\t\tif(!f) {// cout<\nusing namespace std;\n\nint main() {\n int a,sum=0;\n cin>>a;\n \n for(int i=1;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nlong long gcd(long long a, long long b) {\n\twhile ((a != 0) && (b != 0))\n\t{\n\t\tif (a > b) {\n\t\t\ta = a % b;\n\t\t}\n\t\telse {\n\t\t\tb = b % a;\n\t\t}\n\t}\n\treturn a + b;\n}\n\nint main()\n{\n\tlong long t, w, b;\n\tcin >> t >> w >> b;\n\tlong long nod = gcd(w, b), mi = min(w, b);\n\tlong long nok = (w / nod) * b;\n\tlong long ans = 0;\n\tans = (t / nok + 1) * mi;\n\tif ((t / nok) * nok + mi > t) {\n\t\tans = ans - (t / nok) * nok - mi + t + 1;\n\t}\n\tans--;\n\tdouble nok1 = (double)w / nod * b;\n\tif (nok1 > t) {\n\t\tans = min(mi - 1, t);\n\t}\n\tlong long c = gcd(ans, t);\n\tt = t / c;\n\tans = ans / c;\n\tcout << ans << \"/\" << t << endl;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "7b4b0266a05cbb872eda7991a5b4dc40", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \nusing namespace std;\n\nlong long pwr(long long x, int y) {\n long long res = 1;\n for (int i = 0; i < y; ++i)\n res *= x;\n return res;\n}\n\nint main() {\n long long p, d;\n cin >> p >> d;\n while(d > 0) {\n int pw = 0;\n long long tempP = p;\n while(tempP > 0 && tempP % 10 == 9)\n tempP /= 10, ++pw;\n if (tempP == 0)\n break;\n long long toBeDecreased = (tempP % 10 + 1) * pwr(10, pw);\n if (d < toBeDecreased || p < toBeDecreased)\n break;\n p -= toBeDecreased;\n d -= toBeDecreased;\n }\n cout << p;\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "42dc86a8ea1be1fafb0f1e7e499cfcef", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#include\n#include\n#include\n#include \n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define mp make_pair\nbool had[45][45];\nint lea;\npairla[45][45];\nint dx[5]={-1,0,0,0,1},dy[5]={0,-1,0,1,0};\nint n,m;\nbool cmp(paira,pairb){\n\tint cnt1=0,cnt2=0;\n\tfor(int i=0;i<5;i++){\n\t\tint x=a.first+dx[i],y=a.second+dy[i];\n\t\tif(had[x][y]) cnt1++;\n\t}\n\tfor(int i=0;i<5;i++){\n\t\tint x=b.first+dx[i],y=b.second+dy[i];\n\t\tif(had[x][y]) cnt2++;\n\t}\n\treturn cnt1>cnt2;\n}\nunsigned int cando(){\n\tint ma=1;\n\tfor(int i=0;i>1,mid2=(m+1)>>1;\n\tint cnt1=0,cnt2=0;\n\tfor(i=0;i=lea) return;\n\tvector tmp[2];\n\tvector >tp;\n\tfor(int k=0;k<5;k++)\n\t{\n\t\tint x=i+dx[k],y=j+dy[k];\n\t\tif(x>=0&&x=0&&y=0&&xx=0&&yy>n>>m;\n\tif(n0);\n\t\treturn 0;\n\t}\n\tlea=min(((n+2)/3)*(((m+1)>>1)<<1),((n+1)>>1)*m);\n\tfor(int i=0;i\n#include\n#include\n#include\n#include\n#include\n\n//#include\n\nusing namespace std;\n\n\n#ifdef ONLINE_JUDGE\n\t#define WAIT\n#else\n\t#define WAIT cout<= END;--I)\n#define foreach(arr) for(auto item : arr)\n#define REP(I,A,B) for(int I = A;I < B;++I)\n\n#define CONTAINS(m,x) m.find(x) != m.end()\n#define clr(x) memset((x),0,sizeof(x))\n#define PB push_back\n#define remove erase\n#define ALL(v) v.begin(),v.end()\n#define sz(a) a.size();\n#define endl '\\n'\n#define MAX 10010\n\ntypedef long long i64;\ntypedef pair pii;\n\n//const int MOD = ;\n\nstring solve,s; int N;\n\nvoid Check(){\n\n\tif(solve[0] == '.'){\n\t\tsolve.remove(0,1);\n\t\tsolve = \"dot\" + solve;\n\t}\n\telse if(solve[0] == '@'){\n\t\tsolve.remove(0,1);\n\t\tsolve = \"at\" + solve;\n\t}\n\n\tif(solve[solve.size() - 1] == '.'){\n\t\tsolve.remove(solve.size() - 1,1);\n\t\tsolve += \"dot\";\n\t}\n\telse if(solve[solve.size() - 1] == '@'){\n\t\tsolve.remove(solve.size() - 1,1);\n\t\tsolve += \"at\";\n\t}\n\n}\n\nint main()\n{\n\tios_base :: sync_with_stdio(0);\n\tcin.tie(0);\n\n\tcin >> s;\n\t\n\tN = sz(s);\n\t\n\tsolve = \"\";\n\t\n\tfor(int I = 0;I < N;++I){\n\t\t\n\t\tif(I + 3 <= N){\n\t\t\tif(s.substr(I,3) == \"dot\"){\n\t\t\t\tsolve += \".\";\n\t\t\t\tI+=2;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(I + 2 <= N){\n\t\t\t\t\tif(s.substr(I,2) == \"at\"){\n\t\t\t\t\t\tsolve += \"@\";\n\t\t\t\t\t\tI+=1;\n\t\t\t\t\t}\n\t\t\t\t\telse solve += s[I];\n\t\t\t\t}\n\t\t\t\telse solve += s[I];\n\t\t\t}\n\t\t}\n\t\telse if(I + 2 <= N){\n\t\t\tif(s.substr(I,2) == \"at\"){\n\t\t\t\tsolve += \"@\";\n\t\t\t\tI+=1;\n\t\t\t}\n\t\t\telse solve += s[I];\n\t\t}\n\t\telse solve += s[I];\n\t}\n\n\tCheck();\n\n\tint cont = 0;\n\n\tfor(int I = 0;I < solve.size();++I){\n\t\t\n\t\tif(solve[I] == '@') ++cont;\n\t\n\t}\n\n\tif(cont == 1) cout << solve << endl;\n\n\telse{\n\t\n\t\tbool ok = 1;\n\n\t\tfor(int I = 0;I < solve.size();++I){\n\t\t\n\t\t\tif(solve[I] == '@'){\n\t\t\t\tif(ok){\n\t\t\t\t\tcout << '@';\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tcout << \"at\";\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcout << solve[I];\n\t\t}\n\t\tcout << endl;\n\t}\n}", "lang_cluster": "C++", "tags": ["expression parsing", "implementation"], "code_uid": "622c45753340876893e6c92b6ded456e", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n#define ll long long\nll gcd(ll a,ll b)\n{\n\treturn b==0?a:gcd(b,a%b);\n}\nint main()\n{\n\tll x,y,a,b,c,d;\n\tcin>>a>>b>>c>>d;\n\tll up=0,down=0;\n\tll tem=gcd(c,d);\n\tx=c/tem;\n\ty=d/tem;\n\tup=a/x;\n\tdown=b/y;\n\t\n\tcout<\nusing namespace std;\nint main()\n{\n int n;\n cin >> n;\n int a[n],b[n];\n int count=0;\n for(int i=0;i>a[i];\n for(int i=0;i max)\n max=sum;\n if (sum<0)\n sum=0;\n\n }\n cout << count+max << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "dp", "implementation"], "code_uid": "5347cc039cf023e6db8de64eec0e5539", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long int64;\ntypedef unsigned long long uint64;\n\n#define mp make_pair\n\nint main()\n{\n#ifdef KOCH\n\tfreopen(\"abc.txt\", \"r\", stdin);\n#else\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n#endif \n\tint64 k, n;\n\tcin >> n >> k;\n\tint64 pow = 1;\n\tint lg = 1;\n\tfor (; pow <= n; ++lg)\n\t{\n\t\tpow *= 2ll;\n\t}\n\tpow /= 2;\n\tlg--;\n\tint64 res = 0;\n\tif (k == 1)\n\t{\n\t\tcout << n << endl;\n\t\treturn 0;\n\t}\n\tfor (int i = 0; i < 100; ++i)\n\t{\n\t\tres += pow;\n\t\tpow /= 2ll;\n\t\tif (pow == 0) break;\n\t}\n\tcout << res << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "46ada9e7abf04f8c91334d539cb7aacc", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "//0123\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\nusing namespace std;\r\n#define int long long\r\n#define endl \"\\n\"\r\n\r\nconst int mm=1e9+7;\r\n\r\nint be(int a,int b)\r\n{\r\n\tif(a==1||b==0)\treturn 1;\r\n\tint c=be(a,b/2);\r\n\tint res=1;\r\n\tres=c*c;\r\n\tif(res>=mm)\tres%=mm;\r\n\tif(b%2)\tres*=a;\r\n\tif(res>=mm)\tres%=mm;\r\n\treturn res;\r\n}\r\n\r\nint32_t main() {\r\n int k; cin>>k;\r\n int b=1;\r\n for(int i=0;i\nusing namespace std;\n/*------- Constants---- */\n\n#define Long long long\n#define Ulong unsigned long long\n#define FOR(I,A,B) for(long long i=0; i < n ; i++ )\n#define REP(i,n) for(long long i=0; i < n ; i++ )\n#define mp make_pair\n#define pb push_back\n#define all(x) (x).begin(),(x).end()\n#define PI acos(-1.0)\n#define EPS 1e-9\n#define F first\n#define S second\n#define di(x) int x; input(x)\n#define in(x) input(x)\n#define in2(x,y) in(x),in(y)\n#define in3(x,y,z) in(x),in2(y,z)\n#define lc ((n)<<1)\n#define rc ((n)<<1|1)\n#define db(x) cout << #x << \" -> \" << x << endl;\n#define ms(ara_name,value) memset(ara_name,value,sizeof(ara_name))\n#define IO ios_base::sync_with_stdio(0);cin.tie(0)\n#define READ freopen(\"in.txt\",\"r\",stdin)\n#define WRITE freopen(\"out.txt\",\"w\",stdout)\ntemplate inline void input(T &x) {\n register char c = getchar();x = 0;\n int neg = 0;\n for(; ((c<48 || c>57) && c != '-'); c = getchar());\n if(c=='-'){neg = 1;c = getchar();}\n for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}\n if(neg) x = -x;\n}\ninline long long bigmod(long long p,long long e,long long M){\n long long ret = 1;\n for(; e > 0; e >>= 1){\n if(e & 1) ret = (ret * p) % M;\n p = (p * p) % M;\n } return ret;\n}\ntemplate inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}\ntemplate inline T modinverse(T a,T M){return bigmod(a,M-2,M);}\n\n/***************************** END OF TEMPLATE *******************************/\nconst int N = 1001;\nconst int MOD = 1e9+7;\nint main()\n{\n int n;\n in(n);\n long long dp[2];\n dp[0]=0;\n dp[1] = 0;\n long long ans = 0;\n for(int i=1;i <= n;i ++) {\n int now = i%2;\n ans = ans + 1 + dp[now^1];\n dp[now] += 1 + dp[now ^ 1];\n ans %= MOD;\n dp[now] %= MOD;\n }\n cout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp"], "code_uid": "19fa8b97b092f0c0d1b3e2793b83ab4d", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define endl '\\n'\n\nlong long binpow(long long n, long long p) {\n long long result = 1;\n\n n %= 1000000007;\n\n while (p) {\n if (p & 1) {\n result = (result * n) % 1000000007;\n }\n n = (n * n) % 1000000007;\n p = p >> 1;\n }\n\n return result;\n}\n\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.precision(10);\n\n long long n, m;\n int k;\n\n cin >> n >> m >> k;\n\n if (k == -1 && (n % 2 != m % 2)) {\n cout << 0 << endl;\n return 0;\n }\n\n cout << binpow(binpow(2, (n - 1)), m - 1) << endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "6008003cb8804671076e8d5150d5174c", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n\nint main() {\n\n int N, K, L, C, D, P, NL, NP;\n std::cin >> N >> K >> L >> C >> D >> P >> NL >> NP;\n\n std::cout << std::min(std::min(K*L/NL, C*D), P/NP)/N << std::endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "7d74e62f847ab5cf21cb44f0adce7205", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long llint;\n\n#define SQR(X) ((X)*(X))\n#define ODD(X) ((X)&1)\n#define MIN(X,Y) ((X)<(Y)?(X):(Y))\n#define MAX(X,Y) ((X)>(Y)?(Y):(X))\n\nconst int MOD = int(1e9)+7;\nconst int INF = 2147483647;\nconst int LPRIME = 100003;\nconst int N = int(1e5)+10;\n\n\n\nint n,x,sum,ans;\n\nint main() {\n\t#ifndef ONLINE_JUDGE\n\tfreopen(\"in.txt\",\"r\",stdin);\n\tfreopen(\"out.txt\",\"w\",stdout);\n\t#endif\n\n\tscanf(\"%d\",&n);\n\tsum = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%d\",&x);\n\t\tsum+=x;\n\t}\t\n\tans =0;\n\tfor (int i = 1; i <= 5; i++)\n\t\tif ((sum+i)%(n+1)!=1) ans++;\n\tcout<\n#define all(v) ((v).begin()),((v).end())\n#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)\n#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)\n#define vint vector\n#define vll vector\n#define scl(x) scanf(\"%lld\",&x)\n#define sc(x) scanf(\"%d\",&x)\n#define MOD 1000000007;\n#define PI 3.1415926535897\ntypedef long long ll;\nusing namespace std;\nvoid fast()\n{\n\tstd::ios_base::sync_with_stdio(0);\n\tcin.tie(NULL); cout.tie(NULL);\n}\n\nint main(){\n\tfast();\n\tll c,v0,v1,a,l;cin>>c>>v0>>v1>>a>>l;\n\tll ans=0,cnt=0;\n\twhile(cnt\n#define rua system(\"pause\")\nusing namespace std;\ntypedef long long ll;\ninline int read()\n{\n\tint x = 0, f = 1; char c = getchar();\n\twhile (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}\n\twhile (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}\n\treturn x * f;\n}\n\ntypedef unsigned int uint;\nuint c[135], a[135], b[135];\n\nint main()\n{\n\tint n, p, q;\n\tcin >> n >> p >> q;\n\tint up = min(n - 1, p);\n\tfor (int i = 0; i <= up; i ++) c[i] = 1;\n\tfor (int cur = 1; cur <= up; cur ++)\n\t{\n\t\tfor (int i = 1; i <= cur; i ++)\n\t\t\ta[i] = n - i + 1, b[i] = i;\n\t\tfor (int i = 1; i <= cur; i ++)\n\t\t\tif (b[i] > 1) for (int j = 1, d; j <= up; j ++)\n\t\t\t\tif ((d = __gcd(b[i], a[j])) > 1)\n\t\t\t\t\ta[j] /= d, b[i] /= d;\n\t\tfor (int i = 1; i <= cur; i ++) assert(b[i] == 1);\n\t\tfor (int i = 1; i <= cur; i ++) c[cur] *= a[i];\n\t}\n\tuint ans = 0;\n\tfor (int i = 1; i <= q; i ++)\n\t{\n\t\tuint res = 0, now = 1;\n\t\tfor (int k = 0; k <= up; k ++)\n\t\t\tres += now * c[k], now *= i;\n\t\tans ^= res * i; \n\t}\n\tprintf(\"%u\\n\", ans);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["combinatorics"], "code_uid": "7ba419e803d010afe517f4c3462ded62", "src_uid": "28cf4ff955d089318ea08d17bc4f43da", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "\n#include // includes cin to read from stdin and cout to write to stdout\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n///LLONG_MAX,INT_MA\n#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;i++)\n#define REP(i,n) FOR(i,0,(n)-1)\n#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)\n#define sz size()\n#define FORA(i,c) REP(i,size(c))\n\n#define itype(c) __typeof((c).begin())\n#define FORE(e,c) for(itype(c) e=(c).begin();e!=(c).end();e++)\n#define pb push_back\n#define mp make_pair\n#define all(x) (x).begin(),(x).end()\n#define SORT(x) sort(all(x))\n#define REVERSE(x) reverse(all(x))\n#define CLEAR(x,c) memset(x,c,sizeof(x)) \n#define amfor(Iterator, Container) \tfor ( auto Iterator = begin(Container); (Iterator) != end(Container); ++(Iterator) )\n#define ramfor(Iterator, Container) for ( auto Iterator = Container.rbegin(); (Iterator) != Container.rend(); ++(Iterator) )\ntemplate inline bool contains(const C& container, const E& element) { return container.find(element) != container.end(); }\n#define NP(nn,ta,a,tb,b) struct nn : pair { nn():pair(){}; nn(ta pa,tb pb):pair(pa,pb){} ta& a(){return first;} tb& b(){return second;} };\ntemplate inline void checkmin(T &a, T b) { if (b < a) a = b; }//asigna en a el minimo\ntemplate inline void checkmax(T &a, T b) { if (b > a) a = b; }//asigna en a el maximo\n\n\ntypedef long long ll;\nusing namespace std; // since cin and cout are both in namespace std, this saves some text\ntypedef vector vll;\ntypedef vector> vvll;\n\nll n;\nint main()\n{\n\tios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n\tcout << std::setprecision(15);\n\tcout << std::fixed;\n\tcin >> n;\n\tset d;\n\tREP(i, n)\n\t{\n\t\tint a;\n\t\tcin >> a;\n\t\td.insert(a);\n\t}\n\tint u = 0;\n\twhile (!d.empty())\n\t{\n\t\tu++;\n\t\tint v = *d.begin();\n\t\tvector f;\n\t\tfor (int g : d)\n\t\t{\n\t\t\tif (g%v == 0)\n\t\t\t\tf.push_back(g);\n\t\t}\n\t\tfor (int g : f)\n\t\t\td.erase(g);\n\t}\n\tcout << u;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "implementation"], "code_uid": "4bae4f95b35d6613f03ec0b5bfd92135", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\nint main() \n{ string str;\n int n,i,l,count=0;\n cin>>n;\n cin>>str;\n l=str.size();\n for(i=0;i\nusing namespace std;\nlong long a[14],b[14];\nint main(){\n\tfor(int i=0;i<14;i++) cin>>a[i];\n\tlong long mx=0;\n\tfor (int i=0;i<14;i++){\n\t\tlong long re=a[i]%14,qu=a[i]/14,sum=0,k=0;\n\t\tfor (int j=0;j<14;j++) b[j]=a[j];\n\t\tb[i]=0;\n\t\tfor (int j=(i+1)%14;k\n#include \n#include \n#include \n#include \nusing namespace std;\n#define ll long long\nint n,m,x,y,a,b;\nint main()\n{\n // freopen(\"in.txt\",\"r\",stdin);\n cin>>n>>m>>x>>y>>a>>b;\n ll t=__gcd(a,b);\n a/=t;\n b/=t;\n ll lx,ly;\n lx=n/a*a;\n ly=m/b*b;\n if(lx*b>a*ly)\n {\n lx=ly/b*a;\n }else ly=lx/a*b;\n// cout<>1);\n ll y2=y+(ly>>1);\n ll x1=x2-lx;\n ll y1=y2-ly;\n ll mx=x1<0?-x1:x2>n?n-x2:0;\n ll my=y1<0?-y1:y2>m?m-y2:0;\n printf(\"%lld %lld %lld %lld\\n\",x1+mx,y1+my,x2+mx,y2+my);\n// mx=my=0;\n// prllf(\"%d %d %d %d\\n\",x1+mx,y1+my,x2+mx,y2+my);\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "11f88f12eccac7829e320b7bc6a1ffd0", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \ntypedef long long ll;\nusing namespace std;\nmap > mond;\nbool BS(int num, int key)\n{\n\tint s = 0, e = mond[num].size()-1, mid;\n\twhile (s<=e)\n\t{\n\t\tmid = s + (e - s) / 2;\n\t\tif (key < mond[num][mid])e = mid - 1;\n\t\telse if (key>mond[num][mid])s = mid + 1;\n\t\telse return true;\n\t}\n\treturn false;\n}\nint main()\n{\n\t//ios::sync_with_stdio(false);\n\tvectort1 = { 2 };\n\tvectort3 = { 4, 6, 9, 11 };\n\tvectort4 = { 1, 3, 5, 7, 8, 10, 12 };\n\tmond[28] = t1; mond[29] = t1;\n\tmond[30] = t3; mond[31] = t4;\n\tint n;\n\tcin >> n;\n\tvectorin(n);\n\t\n\tint feb=0;\n\tbool con = true;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tcin >> in[i];\n\t\tif (in[i] == 28 || in[i] == 29)\n\t\t{\n\t\t\tif (in[i] == feb &&in[i] == 29)\n\t\t\t{\n\t\t\t\tcon = false;\n\t\t\t}\n\t\t\telse\n\t\t\t\tfeb = in[i];\n\t\t}\n\t}\n\tint sz = mond[in[0]].size(),start,f;\n\t\n\tfor (int i = 0; i < sz; i++)\n\t{\n\t\tstart = mond[in[0]][i];\n\t\tf = 1;\n\t\tif (start == 12) start = 0;\n\t\tfor (int j = 1; j < n; j++)\n\t\t{\n\t\t\tif (BS(in[j], start + 1))\n\t\t\t{\n\t\t\t\tstart++;\n\t\t\t\tf++;\n\t\t\t\t\n\t\t\t\tif (start == 12) start = 0;\n\t\t\t}\n\t\t}\n\t\tif (f == n && con)\n\t\t{\n\t\t\tcout << \"Yes\" << endl;\n\t\t\treturn 0;\n\t\t}\n\t}\n\tcout << \"No\" << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "0effef012c8b227ea85f969348c10305", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\nint n,k,x,fact[100005],sol[25],s=1;\nbool ciur[100005];\nint i,j;\n\nbool prim(int n)\n{\n int di;\n if(n==2) return 1;\n if(n%2==0) return 0;\n if(n==1||n==0) return 0;\n for(di=3;di*di<=n;di+=2)\n if(n%di==0) return 0;\n return 1;\n}\nint main()\n{\n cin>>n>>k;\n if(prim(n)==0)\n {ciur[0] = 1;\n ciur[1] = 1;\n ciur[2] = 0;\n for(i=4;i<=100000;i+=2)\n ciur[i] = 1;\n for(i=3;i*i<=100000;i+=2)\n for(j=i;i*j<=100000;j+=2)\n ciur[i*j] = 1;\n for(i=1,j=1;i*i<=100000;i++)\n if(ciur[i] == 0) fact[j++] = i;\n j = 1;\n while(n>1 && k>1)\n {\n if(n%fact[j] == 0)\n {if(n/fact[j]==1) break;\n else\n {n=n/fact[j]; sol[s++] = fact[j]; k--;}}\n else j++;\n }\n if(k == 1 && n > 1) {sol[s] = n;\n for(i=1;i<=s;i++) cout< 1) cout<<-1;}\n else\n {if(k==1) cout<\n#include \n#define pb push_back\n#define ob pop_back\n#define xx first\n#define yy second\n#define dob double\n//#define int long long int\n#define gcd __gcd\n#define ss size()\nusing namespace std;\nconst long long M = 1e9 + 7 , maxn = 2e6 + 10;\nint ans , n , m , x , y , k , q , dp[maxn];\nstd::vector d[maxn];\n\nint bpow(int a , int b){\n\tif(a < 1)\n\t\treturn 0;\n\tif(!b)\n\t\treturn 1;\n\tx = bpow(a , b >> 1);\n\tif(b & 1)\n\t\treturn (1ll * x * x % M ) * 1ll * a % M;\n\treturn 1ll * x * x % M;\n}\n \nint32_t main(){\n \n ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);\n\n for(int i = 0 ; i < maxn ; i++)\n \td[i].reserve(10);\n \n for(int i = 2 ; i < maxn ; i++){\n \tfor(int j = i ; j < maxn ; j += i)\n \t\td[j].pb(i);\n }\n\n cin >> n >> k;\n \n for(int i = 0 ; i < 100 ; i++)\n\n dp[1] = 1;\n\n for(int i = 2 ; i <= k ; i++){\n \ty = (1ll * bpow(i , n) - bpow(i-1 , n) + M) % M;\n \tfor(int j : d[i]){\n \t\ty -= dp[i/j];\n \t\tif(y < 0)\n \t\t\ty += M;\n \t}\n \tdp[i] = y;\n }\n\n for(int i = 1 ; i <= k ; i++){\n \tdp[i] = (1ll * dp[i] + dp[i-1]) % M;\n \tans = (1ll * ans + (dp[i] ^ i )) % M;\n }\n\n cout << ans;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "334abd92297c8f6151098c99ff452c11", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nconst double PI = 3.141592653589793238463;\nint main() {\n#ifndef ONLINE_JUDGE\n\tfreopen(\"in\", \"r\", stdin);\n\t//freopen(\"out\", \"w\", stdout);\n#endif\n int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};\n int m,d;\n cin>>m>>d;\n int ans=ceil((a[m]+d-1)/7.0);\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\n\n#define pb push_back\n#define mp make_pair\n#define F first\n#define S second\n\nconst int MOD = 1e9 + 7 ;\nconst int MAXN= 1e5 + 22 ;\n\nint n ;\n\nint main()\n{\n\tios_base::sync_with_stdio(false) ;\n\tcin >> n ;\n\tbool sw= true; \n\tint x,y ,a[120] , t;\n\tfor(int i = 1 ; i <= n ; i++)\n\t\t{\n\t\tcin >> a[i] ;\n\t\tif(sw && a[i] == 1)\n\t\t{\n\t\t\tsw = false ;\n\t\t\tx = i ;\n\t\t}\n\t\tif(a[i])\n\t\t\ty = i ;\n\t}\n\tif(sw)\n\t{\n\t\tcout << 0 ;\n\t\treturn 0 ;\n\t}\n\tt = x; \n\tll ans = 1 ;\n\tfor(int i = x+1 ; i <= y ; i++)\n\t{\n\t\tif(a[i] == 1)\n\t\t{\n\t\t\tans *= i - t ;\n\t\t\tt = i ;\n\t\t}\n\t}\n\tcout << ans ;\n\treturn 0;\n}\n\n\n", "lang_cluster": "C++", "tags": ["combinatorics"], "code_uid": "1855d53f693abe2a56e78feb04818475", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nconst int N = 1e2 + 5;\nint n;\nstring line;\nvector divv;\nint main() {\n\tios::sync_with_stdio(0), cin.tie(0);\n\tcin >> n >> line;\n\tfor(int i = 1; i * i <= n; ++i) {\n\t\tif(n % i == 0) {\n\t\t\tdivv.push_back(i);\n\t\t\tif(i != n / i) {\n\t\t\t\tdivv.push_back(n / i);\n\t\t\t}\n\t\t}\n\t}\n\tsort(divv.begin(), divv.end());\n\tfor(auto v : divv) {\n\t\treverse(line.begin(), line.begin() + v);\n\t}\n\tcout << line << endl;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "91b7d76707da795895d2f7d758872f7a", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nconst int MAX = 5e2 + 10;\nint deg[MAX];\nvector< pair > g;\nbool mark_a[MAX];\nint main(){\n int n, m; scanf(\"%d%d\", &n, &m);\n for(int i = 0; i < m ;i++){\n int a, b;\n scanf(\"%d%d\", &a, &b); a--; b--;\n deg[a]++;\n deg[b]++;\n g.push_back(make_pair(a, b));\n }\n int a = 0, b = 0, c = 0;\n int da = -1;\n for(int i = 0; i < n; i++)\n if(deg[i] == n - 1){\n b++;\n }\n else if(da == -1){\n da = i;\n mark_a[i] = 1;\n a = 1;\n }\n for(int i = 0; i < m; i++){\n if(g[i].first == da && deg[g[i].second] != n - 1 && !mark_a[g[i].second])\n mark_a[g[i].second] = 1, a++;\n if(g[i].second == da && deg[g[i].first] != n - 1 && !mark_a[g[i].first])\n mark_a[g[i].first] = 1, a++;\n }\n c = n - a - b;\n int wrong = 0;\n for(int i = 0; i < m; i++){\n if(mark_a[g[i].first] && deg[g[i].second] != n - 1 && !mark_a[g[i].second])\n wrong++;\n\n if(mark_a[g[i].second] && deg[g[i].first] != n - 1 && !mark_a[g[i].first])\n wrong++;\n }\n if(wrong == 0 && (m == n * (n - 1) / 2 - a * c)){\n printf(\"Yes\\n\");\n for(int i = 0; i < n; i++){\n if(deg[i] == n-1)printf(\"b\");\n else if(mark_a[i])printf(\"a\");\n else printf(\"c\");\n }\n printf(\"\\n\");\n }\n else printf(\"No\\n\");\n\n}", "lang_cluster": "C++", "tags": ["constructive algorithms", "graphs"], "code_uid": "c08cb4f9edde33605164ae14fda91ddb", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n\nint main() {\n\tunsigned long long n;\n\tcin >> n;\n\tunsigned long long res = n * (n + 1) / 2 % 2;\n\tcout << res << \"\\n\";\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "e16bd225b71f25d58fd01ff8cc634e54", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n\nint a,b,c,d,e,f;\ncin>>a>>b>>c>>d>>e;\n\n\nint l = (a+b+c+d+e);\nint lp = (a+b+c+d+e);\nif(l%5 || !l)\ncout<<-1;\nelse cout<\n\n\n#define MAX 1000000007\n#define SIZE 1000005\n\nint dp[SIZE][20][3];\nint n;\n\nint fun(int x, int y){\n\tint temp =(1<\n#include \n#include \n#define maxn 11\n\nusing namespace std;\n\ntypedef long long ll;\n\nint st[maxn],aim[maxn*maxn],nxt[maxn*maxn],ln;\nll f[1<<10][1<<10];\nvoid in_edge(int x,int y){\n\taim[ln]=y;\n\tnxt[ln]=st[x];\n\tst[x]=ln++;\n}\nint n,m,kn;\nint cal_bit(int mask){\n\tint ret=0;\n\twhile (mask) ret+=(mask&1),mask>>=1;\n\treturn ret;\n}\nint lowbit(int mask){\n\treturn (mask&(mask^(mask-1)));\n}\nint main(){\n\tscanf(\"%d%d%d\",&n,&m,&kn);\n\tmemset(st,-1,sizeof(st));\n\tln=0;\n\tmemset(f,0,sizeof(f));\n\tfor (int i=0;i0){\n\t\t\t\t\t\tfor (int c=st[k];c!=-1;c=nxt[c]){\n\t\t\t\t\t\t\tint p=aim[c];\n\t\t\t\t\t\t\tif ((i&(1<0) cmask^=(1<\n#define pii pair\n#define pdd pair\n#define pll pair\n#define fr first\n#define sc second\n#define ll long long\n#define mp make_pair\n#define mod 1000000007\n\nusing namespace std;\n\nstruct point{\n double x,y;\n};\n\ndouble dist(point p1,point p2){\n double z = p1.x-p2.x;\n z *= z;\n double z1 = p1.y-p2.y;\n z1 *= z1;\n return sqrt(z+z1);\n}\n\ndouble con(double x){return M_PI*x/180.0;}\ndouble con1(double x){return 180.0*x/M_PI;}\n\ndouble findX(point p1,point p2,double teta1){\n point p3;\n double teta = acos((-p1.x + p2.x)/dist(p1,p2));\n if(con1(teta)+teta1 >= 180.0)return 1e7;\n\n p3.x = p2.x + dist(p1,p2)*cos(teta + con(teta1));\n p3.y = p2.y + dist(p1,p2)*sin(teta + con(teta1));\n\n double res = -p2.y/(p3.y-p2.y);\n res *= (p3.x-p2.x);\n res += p2.x;\n return res;\n}\n\ndouble dp[1<<21];\n\nint main(){\n ios::sync_with_stdio(0);\n int n;\n double l,r;\n cin>>n>>l>>r;\n point z[n];\n double a[n];\n for(int i=0 ; i>z[i].x>>z[i].y>>a[i];\n }\n\n int en = 1<=0 ; i--){\n double maxx = -1e6,r1;\n point h;\n h.y = 0;\n for(int j=0 ; j\n\nusing namespace std;\n\nint main(const int argc, char *argv[])\n{\n int n,p,k;\n cin>>n>>p>>k;\n if ((p-k)<=1) for (int i=1;i=n) for (int i=p+1;i<=n;i++) cout<>\";\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "6fe3b00e8547ea62d9821ee6e882f4db", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#define pb push_back\n\nusing namespace std;\n\nvoid debug_out() { cerr << '\\n'; }\ntemplate void debug_out(Head H, Tail... T) { cerr << \" \" << H; debug_out(T...);}\n#define dbg(...) cerr << #__VA_ARGS__ << \" ->\", debug_out(__VA_ARGS__)\n#define dbg_v(x, n) do{cerr<<#x\"[]: \";for(int _=0;_ pii;\ntypedef long long int ll;\ntypedef long double ld;\n\ninline int two(int n) { return 1 << n; }\ninline int test(int n, int pos) { return (bool) (n & two(pos)); }\ninline void set_bit(int &n, int b) { n |= two(b); }\ninline void unset_bit(int &n, int b) { n &= ~two(b); }\ninline int last_bit(int n) { return n & (-n); }\n\nconst int DMAX = 18;\nconst int LgMAX = 32800;\nconst int MOD = 1e9+7;\n\nvector vec;\nvector arb[DMAX];\n\npii V[DMAX];\nint tme[LgMAX];\n\npii dp[LgMAX][DMAX];\n\nint n,maxim;\n\nll ans;\n\nint main(){\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n\n int t,i,k;\n int mask,mask2;\n\n cin>>n>>t;\n for(i=0;i>V[i].first>>V[i].second;\n }\n for(i=0;i MOD)\n ans-=MOD;\n }\n }\n cout<\nusing namespace std;\n\nint main() {long long n ,v,r,a;\n\tcin>>n>>v;\n\ta=-1;\n\tn--;\n\tr=n-v;\n\t\tif(n<=v){\n\t\t\tcout<\nusing namespace std;\nlong long a[3];\nint main()\n{\n\tcin>>a[0]>>a[1]>>a[2];\n\tsort(a,a+3);\n\tif ((a[0]+a[1])%2==0) cout<\nusing namespace std;\nint q[100005];\nint head=0,tail=0;\nint wish[100005];\n\nvoid push(int x)\n{\n q[tail++]=x;\n}\n\nvoid pop()\n{\n if(headm)\n {\n wish[q[head]]=wish[q[head]]-m;\n push(q[head]);\n pop();\n }\n\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "948eca70af950cf3b3a948cff52bb7c0", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\nint num=0,n;\nchar ch;\nint main() {\n scanf(\"%d\\n\",&n);\n for (int i=1;i<=n;i++) {\n scanf(\"%c\",&ch);\n if (ch=='8') num++;\n }\n if (num==0) printf(\"0\");\n else {\n if (num*11<=n) printf(\"%d\",num);\n else printf(\"%d\",n/11);\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force"], "code_uid": "2c04b42e8c8c1ad429e444aef500adef", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int x1,x2,x3,y1,y2,y3;\n cin>>x1>>y1>>x2>>y2>>x3>>y3;\n if(x1==x2 && x2==x3)\n {\n cout<<1;\n }\n else if(y1==y2 && y2==y3)\n {\n cout<<1;\n }\n else if(y1==y2 && ((x3>=x1 && x3>=x2)||(x3<=x1 && x3<=x2)))\n {\n cout<<2;\n }\n else if(y2==y3 && ((x1>=x2 && x1>=x3)||(x1<=x2 && x1<=x3)))\n {\n cout<<2;\n }\n else if(y1==y3 && ((x2>=x1 && x2>=x3)||(x2<=x3 && x2<=x1)))\n {\n cout<<2;\n }\n else if(x1==x2 && ((y3>=y1 && y3>=y2)||(y3<=y1 && y3<=y2)))\n {\n cout<<2;\n }\n else if(x2==x3 && ((y1>=y2 && y1>=y3)||(y1<=y2 && y1<=y3)))\n {\n cout<<2;\n }\n else if(x1==x3 && ((y2>=y1 && y2>=y3)||(y2<=y3 && y2<=y1)))\n {\n cout<<2;\n }\n else\n {\n cout<<3;\n }\n}\n", "lang_cluster": "C++", "tags": ["constructive algorithms", "implementation"], "code_uid": "23903756fe3401a984e5867f717f5d48", "src_uid": "36fe960550e59b046202b5811343590d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n#define reps(i, s, n) for(int i=s; i=s; i--)\n#define drep(i, n) dreps(i, 0, n)\n#define pb push_back\n#define mp make_pair\n#define fi first\n#define se second\n#define foreach(v, c) for(__typeof((c).begin()) v=(c).begin();v!=(c).end(); ++v)\n#define all(a) a.begin(), a.end()\n#define rall(a) a.rbegin(), a.rend()\n#define in(a,b) ((b).find(a) != (b).end())\n#define cpresent(c,x) (find(all(c),x) != (c).end()) \n#define X real()\n#define Y imag()\n#define length(V) (hypot((V).X, (V).Y))\n\ntypedef vector vi;\ntypedef vector vvi;\ntypedef pair ii;\ntypedef long long ll;\ntypedef long double ld;\ntypedef complex point;\ntypedef pair segment;\ntypedef pair circle;\ntypedef vector polygon;\n\nconst double PI = 2 * acos(0.0);\nconst double eps = 1e-9;\n\ndouble r, h;\n\nint main() {\n cin >> r >> h;\n int ans = 0;\n double half = floor(h / r);\n ans += half * 2;\n h = h - half * r;\n if (h * 2 < r) ans ++;\n else if (h * 2 >= r * sqrt(3)) ans += 3;\n else ans += 2;\n cout << ans << endl;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["geometry"], "code_uid": "557e361caa0112801553212f51365eef", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define N 2100000\nint l[N],r[N],s[N],key[N],ans[N],root,n,m,num=0,p[N];\nvoid l_rotate(int &t){\n int k=r[t];\n r[t]=l[k];\n l[k]=t;\n s[k]=s[t];\n s[t]=s[l[t]]+s[r[t]]+1;\n t=k;\n}\nvoid r_rotate(int &t){\n int k=l[t];\n l[t]=r[k];\n r[k]=t;\n s[k]=s[t];\n s[t]=s[l[t]]+s[r[t]]+1;\n t=k;\n}\nvoid maintain(int &t,bool flag){\n if(!flag){\n if(s[l[l[t]]]>s[r[t]])r_rotate(t);\n else \n if(s[r[l[t]]]>s[l[t]])l_rotate(l[t]),r_rotate(t);\n else return;\n }\n else{\n if(s[r[r[t]]]>s[l[t]])l_rotate(t);\n else \n if(s[l[r[t]]]>s[l[t]])r_rotate(r[t]),l_rotate(t);\n else return;\n }\n maintain(l[t],0);\n maintain(r[t],1);\n maintain(t,0);\n maintain(t,1);\n}\nvoid add(int &t,int x){\n if(!t){\n t=++num;\n l[t]=r[t]=0;\n key[t]=x;\n s[t]=1;\n return;\n }\n s[t]++;\n add(l[t],x);\n maintain(t,0);\n}\nint del(int &t,int z){\n s[t]--;\n if(s[l[t]]+1==z || zs[l[t]]+1 && !r[t]){\n int tt=key[t];\n if(!l[t] || !r[t])t=l[t]+r[t];\n else key[t]=del(l[t],s[l[t]]+2);\n return tt;\n }\n else\n if(z\n#include \nusing namespace std;\nint freq[26];\nint main()\n{\n\tint n;string s;\n\tcin>>n>>s;\n\tlong long int maxi=0;\n\tsetc;\n\tfor(int i=0;i\n#include \n#include \n#include \n#include \n#define int long long\n\nconst int N = 1e6 + 10;\nconst int mod = 1e9 + 7;\nint n;\nint phi[N], vis[N], pri[N], p_tot;\nint ans;\n\nint lcm(int x, int y) {\n return 1ll * x / std::__gcd(x, y) * y % mod;\n}\n\nvoid Prime(int n) {\n phi[1] = 0;\n for (int i = 2; i <= n; ++i) {\n if (!vis[i]) pri[++p_tot] = i, phi[i] = i - 1;\n for (int j = 1; j <= p_tot && i * pri[j] <= n; ++j) {\n vis[i * pri[j]] = 1;\n if (i % pri[j] == 0) {\n phi[i * pri[j]] = phi[i] * pri[j];\n break;\n }\n phi[i * pri[j]] = phi[i] * (pri[j] - 1);\n }\n }\n}\n\nsigned main() {\n scanf(\"%lld\", &n);\n Prime(n);\n for (int c = 1; c <= n - 2; ++c) {\n for (int d = 1; d * d <= n - c; ++d) {\n if ((n - c) % d == 0) {\n ans += phi[(n - c) / d] * lcm(c, d) % mod;\n ans %= mod;\n if (d * d != n - c) {\n ans += phi[d] * lcm(c, (n - c) / d) % mod;\n ans %= mod;\n }\n }\n }\n }\n printf(\"%lld\\n\", ans % mod);\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "cb767a2d4b7bb5cf8593f534b02971a0", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#define _CRT_SECURE_NO_WARNINGS\n#pragma comment (linker, \"/STACK:16777216\")\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef MY_JUDGE\n#include \n#endif\nusing namespace std;\n\n///////////////// macros and typedefs ///////////////////\n#define rep(i, n) for (int i = 0, _n = (n); i < _n; ++i)\n#define repd(i, n) for (int i = (n)-1; i >= 0; --i)\n#define _fill(a, x) memset((a), (x), sizeof((a)))\n#define DEB(k) cerr<<\"debug: \"#k<<\"=\"< vi;\ntypedef vector vd;\ntypedef pair pi;\n\n/*\n */\n\nint x[3], k;\nll p[3];\n\nvoid solution()\n{\n rep(i, 3) { cin >> x[i]; x[i]--; }\n cin >> k;\n while (p[0] < x[0] || p[1] < x[1] || p[2] < x[2]) {\n if (k == 0) break;\n int mini = -1, mx = -1;\n rep(i, 3) if (p[i] < x[i])\n if (mx == -1 || p[i] < p[mx])\n mx = i;\n p[mx]++, k--;\n }\n cout << (p[0]+1)*(p[1]+1)*(p[2]+1) << endl;\n}\n\nint main()\n{\n#ifdef MY_JUDGE\n freopen(\"my.in\", \"rt\", stdin);\n //freopen(\"my.out\", \"wt\", stdout);\n int start = GetTickCount();\n#endif\n solution();\n#ifdef MY_JUDGE\n int finish = GetTickCount();\n cerr << \"Time: \" << finish - start << endl;\n#endif\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "417037c30b17ecfe3e1be774fa91baec", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\ntypedef long long ll;\nconst int maxN=2500;\nconst int INF=(int)1e9;\nint min(int a,int b){return ab?a:b;}\nint mark1[maxN];\nint mark2[maxN];\nll A1[maxN];\nll A2[maxN];\nint main(void){\n // freopen(\"input.txt\",\"r\",stdin); freopen(\"output.txt\",\"w\",stdout);\n for(int i=0; i> a >> b >> w >> x >> c;\n ll A=0;\n int i=b;\n ll l1=0;\n while(mark1[i]==-1){\n mark1[i]=1;\n A1[l1++]=A;\n// printf(\"%d %d\\n\",i,A);\n if(i>=x){\n i-=x; \n }else{\n i=w-(x-i);\n A++;\n }\n }\n ll d1=A;\n A=0;\n ll l2=0;\n while(mark2[i]==-1){\n mark2[i]=1;\n A2[l2++]=A;\n// printf(\"<%d %d\\n\",i,l2);\n if(i>=x){\n i-=x; \n }else{\n i=w-(x-i);\n A++;\n }\n }\n ll d2=A;\n// printf(\" %d %d\\n\",d1,d2);\n// printf(\" %I64d %I64d\\n\",l1,l2);\n ll l=-1, r=(ll)1e15;\n// cout << l1 <<\" \" << l2<< endl;\n while(r-l>1){\n ll m=l+(r-l)/2;\n ll cc=c-m;\n ll aa;\n if(l1>m){\n aa=a-A1[m];\n }else{\n aa=a-A2[(m-l1)%l2]-d1-((m-l1)/l2)*d2; \n }\n //cout << m << \" \" << aa<< \" \" << cc << endl;\n if(cc<=aa){\n r=m; \n }else{\n l=m;\n }\n }\n cout << r;\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "binary search"], "code_uid": "537868ff92fd5f5c4364ef3ee4e845f0", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\n#define lli long long int\n#define fi first\n#define se second\n#define sc scanf\n#define pr printf\n#define pb push_back\n#define mp make_pair\n#define fin freopen( \"input.txt\", \"r\", stdin );\n#define fout freopen( \"output.txt\", \"w\", stdout );\n\nconst int N = 100100;\n\nusing namespace std;\n\nlli x;\nint n, d, i, j, h, a[N], b[N], c[N], p[N];\nset < int > s;\nvector < int > v;\n\nlli getNextX()\n{\n x = (x * 37 + 10007) % 1000000007;\n return x;\n}\n\nvoid initAB()\n{\n for(i = 0; i < n; i = i + 1){\n a[i] = i + 1;\n }\n for(i = 0; i < n; i = i + 1){\n swap(a[i], a[getNextX() % (i + 1)]);\n }\n for(i = 0; i < n; i = i + 1){\n if (i < d)\n b[i] = 1;\n else\n b[i] = 0;\n }\n for(i = 0; i < n; i = i + 1){\n swap(b[i], b[getNextX() % (i + 1)]);\n }\n}\n\n\nint main()\n{\n int mx = sqrt(N);\n sc( \"%d%d%I64d\", &n, &d, &x );\n initAB();\n for( i = 0; i < n; i++ )\n p[a[i]] = i;\n for( i = 0; i < n; i++ ){\n if( b[i] )\n v.pb(i);\n s.insert(-a[i]);\n int ans = 0;\n if( v.size() < mx ){\n for( j = 0; j < v.size(); j++ ){\n if( i - v[j] >= 0 && i - v[j] <= i )\n ans = max(ans, a[i - v[j]]);\n }\n }\n else{\n for( set < int > :: iterator it = s.begin(); it != s.end(); it++ ){\n if( b[i - p[-(*it)]] ){\n ans = -(*it);\n break;\n }\n }\n }\n pr( \"%d\\n\", ans );\n }\n}", "lang_cluster": "C++", "tags": ["probabilities"], "code_uid": "fc3af0c52f69071373de467f62cf10ae", "src_uid": "948ae7a0189ada07c8c67a1757f691f0", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include\nusing namespace std;\n\nint main()\n{\n string s;\n string ans;\n cin>>s;\n int i=0;\n int j=0;\n while(i\n#define pb push_back\nusing namespace std;\nconst long long INF = 1e9;\n\nlong long n,m,k,ans,sum,mn,pl;\nlong long x,y,z;\nlong long a,b,c,tmp,nd;\nbool na,nb,nc;\nmain()\n{\n cin >> x >> y >> z;\n cin >> a >> b >> c;\n if(x > a) tmp+=((x-a)/2);\n else nd+= a-x;\n\n if(y > b) tmp+=((y-b)/2);\n else nd+= b-y;\n\n if(z > c) tmp+=((z-c)/2);\n else nd+= c-z;\n\n if(tmp >= nd) cout << \"YES\";\n else cout << \"NO\";\n\n\n}\n\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "672f4650f76215b11aea57761e502c60", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "#include \r\nusing namespace std;\r\n\r\n#define int long long\r\n#define ll long long\r\n#define endl '\\n'\r\n\r\n#define rep(x, start, end) \\\r\n for (auto x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); \\\r\n ((start) < (end) ? x++ : x--))\r\n#define all(x) (x).begin(), (x).end()\r\n#define sz(x) (int)(x).size()\r\n\r\nint n;\r\nstring s;\r\nint mod;\r\n\r\nint mul(int i, int j) {\r\n int res = 0;\r\n rep(x, 0, n - 1) {\r\n if (i & (1LL << x)) res ^= j;\r\n j <<= 1;\r\n if (j & (1LL << (n - 1))) j ^= mod;\r\n }\r\n return res;\r\n}\r\n\r\nint pow(int i) {\r\n int res = 1;\r\n int b = 2;\r\n while (i) {\r\n if (i & 1) res = mul(res, b);\r\n b = mul(b, b);\r\n i >>= 1;\r\n }\r\n return res;\r\n}\r\n\r\nsigned main() {\r\n ios::sync_with_stdio(0);\r\n cin.tie(0);\r\n cin.exceptions(ios::badbit | ios::failbit);\r\n mod = 0;\r\n cin >> s;\r\n vector pos;\r\n for (int i = 0; i < s.length(); i++) {\r\n if (s[i] == '1') {\r\n pos.push_back(i);\r\n }\r\n }\r\n s.erase(s.find_last_not_of(\"0\") + 1);\r\n int offset = s.find_first_not_of(\"0\");\r\n s.erase(0, offset);\r\n n = s.length();\r\n if (pos.size() == 0) {\r\n cout << -1 << endl;\r\n return 0;\r\n }\r\n if (pos.size() == 1) {\r\n cout << n + offset << ' ' << n + offset + 1 << endl;\r\n return 0;\r\n }\r\n if (pos.size() == 2) {\r\n cout << pos[0] + 1 << ' ' << pos[1] + 1 << endl;\r\n return 0;\r\n }\r\n rep(x, 0, sz(s)) if (s[x] == '1') mod |= (1LL << x);\r\n\r\n int h = (n + 1) / 2;\r\n\r\n int val = mod;\r\n int prod = 1;\r\n rep(x, 3LL, 1 << h) if (x & 1) {\r\n int num = 0;\r\n while (true) {\r\n int curr = val;\r\n int other = 0;\r\n rep(bit, 0, n) if (curr & (1LL << bit)) {\r\n curr ^= x << bit;\r\n other ^= 1LL << bit;\r\n }\r\n if (curr == 0) {\r\n val = other;\r\n num++;\r\n } else\r\n break;\r\n }\r\n\r\n if (num) {\r\n prod *= (1LL << (63 - __builtin_clzll(x))) - 1;\r\n rep(y, 1, num) prod *= 1LL << (63 - __builtin_clzll(x));\r\n }\r\n }\r\n if (val > 1) prod *= (1LL << (63 - __builtin_clzll(val))) - 1;\r\n\r\n int ans = 1LL << 60;\r\n for (int x = 1; x * x <= prod; x++) {\r\n if (prod % x == 0) {\r\n if (pow(x) == 1) ans = min(ans, x);\r\n if (pow(prod / x) == 1) ans = min(ans, prod / x);\r\n }\r\n }\r\n cout << 1 + offset << ' ' << ans + 1 + offset << endl;\r\n}", "lang_cluster": "C++", "tags": ["math", "bitmasks", "meet-in-the-middle", "matrices", "number theory"], "code_uid": "857856922bc29d7f618296791595b65f", "src_uid": "6bf798edef30db7d0ce2130e40084e6b", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n\nusing namespace std;\n\ntypedef double db;\ntypedef long long ll;\ntypedef long double ld;\ntypedef unsigned int ui;\ntypedef unsigned long long ull;\n\ntypedef pair < ll, ll > pll;\ntypedef pair < int, ll > pil;\ntypedef pair < ll, int > pli;\ntypedef pair < int, int > pii;\n\ntypedef pair < db, db > pdd;\ntypedef pair < db, ld > pdl;\ntypedef pair < ld, db > pld;\ntypedef pair < ld, ld > ldp;\n\n#define F first\n#define S second\n\n#define en end()\n#define bg being()\n\n#define rev reverse\n#define mp make_pair\n#define pb push_back\n\n#define y1 y0123456789\n#define um unordered_map\n\n#define all(x) x.bg, x.en\n#define sz(x) (int)x.size()\n#define len(x) (int)strlen(x)\n\n#define sqr(x) ((x) * 1ll * (x))\n#define sqrd(x) ((x) * 1.0 * (x))\n\n#define forn(i, x) for (int i = 1; i <= x; i++)\n\nconst int dx[] = {0, 0, 1, 0, -1};\nconst int dy[] = {0, 1, 0, -1, 0};\n\nconst ll inf = (ll)1e18;\nconst ll mod = (ll)1e9 + 7;\n\nconst db eps = (db)1e-9;\nconst db pi = acos(-1.0);\n\nconst int N = 100500;\n\nint n, m, ans, a[N], add[N], dp[2][N], t[2][N];\n\ninline void upd(int pos, int tp, int val) {\n for (int i = pos; i <= 100000; i |= (i + 1))\n t[tp][i] = max(t[tp][i], val);\n}\n\ninline int get(int pos, int tp) {\n int res = 0;\n for (int i = pos; i >= 0; i = (i & (i + 1)) - 1)\n res = max(res, t[tp][i]);\n return res;\n}\n\nint main() {\n //freopen(\".in\", \"r\", stdin);\n //freopen(\".out\", \"w\", stdout);\n //freopen(\".err\", \"w\", stderr);\n\n //srand(time(NULL));\n\n cin.tie(NULL);\n cout.tie(NULL);\n ios_base::sync_with_stdio(false);\n\n //cout << setprecision(10) << fixed;\n\n cin >> n >> m;\n\n for (int i = 1; i <= n; i++) {\n int l, r;\n cin >> l >> r;\n add[l]++;\n add[r + 1]--;\n }\n\n int cur = 0;\n\n for (int i = 1; i <= m; i++) {\n cur += add[i];\n a[i] = cur;\n }\n\n for (int i = 1; i <= m; i++) {\n dp[0][i] = get(a[i], 0) + 1;\n upd(a[i], 0, dp[0][i]);\n }\n\n for (int i = m; i >= 1; i--) {\n dp[1][i] = get(a[i], 1) + 1;\n upd(a[i], 1, dp[1][i]);\n }\n\n for (int i = 1; i <= m; i++)\n ans = max(ans, dp[0][i] + dp[1][i] - 1);\n\n cout << ans;\n\n //cerr << (clock() + 0.0) / CLOCKS_PER_SEC;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "binary search", "data structures"], "code_uid": "723fa389bd97b36d9e638a28dba5c4a5", "src_uid": "ce8350be138ce2061349d7f9224a5aaf", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": " \n#include\nint main()\n{\n\tint a,b,c,d;\n\tscanf(\"%d%d%d%d\",&a,&b,&c,&d);\n\tint temp;\n\tint i,sum=0;\n\tif(a>b)\n\t{\n\t\ttemp=a;;\n\t a=b;\n\t\tb=temp;\n\t}\n\tif(a>c)\n\t{\n\t\ttemp=a;;\n\t\ta=c;\n\t\tc=temp;\n\t}\n\tif(b>c)\n\t{\n\t\ttemp=b;;\n\t\tb=c;\n\t\tc=temp;\n\t}\n\t\n if(c-a>=2*d)\n\t{\n\t\tif(b-a>=d&&c-b>=d)\n\t\t\tsum=0;\n\t\tif(b-a=c-b)\n\t\t{\n\t\t\tfor(i=1;c+i-b\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define N 1010\n#define M 1000010\n#define S 1000100\n#define MOD 1000000007\n\ntypedef long long LL;\nusing namespace std;\n\ninline int L(int i){ return i<<1; }\ninline int R(int i){ return (i<<1)|1; }\ninline int B(int i){ return 1<b)\n\t\ttmp=a,a=b,b=tmp;\n\tif(must_win(b%a,a)==0)\n\t\treturn 1;\n\ttmp=b;\n\ttmp/=a;\n\ttmp%=a+1;\n\tif(tmp&1)\n\t\treturn 0;\n\treturn 1;\n}\n\nint main()\n{\n\tint t;\n\tLL a,b; \n\tcin>>t;\n\twhile(t--)\n\t{\n\t\tcin>>a>>b;\n\t\tif(must_win(a,b))\n\t\t\tputs(\"First\");\n\t\telse\n\t\t\tputs(\"Second\");\n\t}\n\treturn 0;\n}\n\n\n", "lang_cluster": "C++", "tags": ["math", "games"], "code_uid": "cf5aeffb28beb683ccd08b5fb7c4db73", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \nusing namespace std;\n\nint k2, k3, k5, k6, temp;\nunsigned long long int ans = 0;\n\nint main()\n{\n\tcin >> k2 >> k3 >> k5 >> k6;\n\ttemp = k2;\n\t\n\tans += (min(k2, min(k5, k6)) * 256);\n\tk2 -= min(k2, min(k5, k6));\n\tans += ((k2 > 0) ? (min(k2, k3) * 32) : 0);\n\t\n\tcout << ans;\n\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "0d0f82c8de1481cf880442f3a287fa14", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "/*----------------by syr----------------*/\n/*\n\n iii ii\n rBQBBBBBBE BBR iBBBBQBBL XBBBBBBQBBBBB\n iBBQJ 7BBB BBsSBBr BBQ i cBBB\n rBBU iBBw BBBQi HBBi KBBi\n BBH BB5 iBBB isL wBB5\n GBB iBBi 6BB iBBB\n BBQ BQB BBD QBBi\n BBB BQB iQBi 1BBv\n sBBg wBBB QBB iBBB\n 7BBBBBBBBBi BBR wBBBBBBBBBBBBB\n irvi ii ii i i iii\n i5U\n BBB\n BB7\n 1BB\n iPBBBBBKBBR JBR1 rQBO BR UBQP iBBQi\n 7BBBGs7sXBBBi QBBr gBBE rBB BB2BB7HBZQBB\n QBBi sBQ BBB iBBB SQBBR BBBB cBQ\n gBQ BBg BBB KBBi MBBH BBB BBs\n iBBv iBBi QBBBL BBR pBB iBB\n pBB BBB iBBBB iBB BBL KBB\n MBB BBBR BBB JBBi DBR iBQ BBL\n GBB 7BBBB2 PBBH BBBi BQr DBB iBB\n BQBXwgBBP BB7 1BBB BBQ7 1BB BBc BBB\n 2BBBBw BB EBBS QBBi HBa iBB BB7\n*/\n#include\n\nusing namespace std;\n\n#define PH push\n#define MP make_pair\n#define PB push_back\n#define fst first\n#define snd second\n#define FOR(i, x, y) for(int i = (x); i < (y); ++i)\n#define REP(i, x, y) for(int i = (x); i <= (y); ++i)\n#define x0 x0123456789\n#define y0 y0123456789\n#define x1 x1234567890\n#define y1 y1234567890\n#define x2 x2345678901\n#define y2 y2345678901\ntypedef double db;\ntypedef long long ll;\ntypedef long double ldb;\ntypedef unsigned long long ull;\ntypedef pair pii;\ntypedef pair pll;\n\nconst int INF = 1e9 + 9;\nconst int maxh = 35;\n\nint n, h, m, ans;\nint dp[2][238576];\nint state[238577][4];\nint match[maxh][maxh][maxh][maxh];\n\ninline void add(int &x, int y){(x += y) -= (x >= INF ? INF : 0);}\n\nint main(){\n\tscanf(\"%d%d\", &n, &h);\n\tdp[0][0] = 1;\n\tint p = 0, q = 1;\n\tREP(i, 0, h + 1) REP(j, 0, h + 1) REP(k, 0, h + 1) REP(l, 0, h + 1) match[i][j][k][l] = 238575;\n\tREP(i, 0, h + 1) REP(j, 0, h + 1) REP(k, 0, h + 1) REP(l, 0, h + 1){\n\t if((!(i % (h + 1)) || !(j % (h + 1)) || !(k % (h + 1)) || !(l % (h + 1))) && (i <= j && j <= k && k <= l)){\n\t state[m][0] = i, state[m][1] = j, state[m][2] = k, state[m][3] = l;\n\t match[i][j][k][l] = match[i][j][l][k] = match[i][l][j][k] = match[i][l][k][j] = match[i][k][j][l] = match[i][k][l][j] = m;\n\t match[j][i][k][l] = match[j][i][l][k] = match[j][k][i][l] = match[j][k][l][i] = match[j][l][k][i] = match[j][l][i][l] = m;\n\t match[k][i][j][l] = match[k][i][l][j] = match[k][j][i][l] = match[k][j][l][i] = match[k][l][i][j] = match[k][l][j][i] = m;\n\t match[l][i][j][k] = match[l][i][k][j] = match[l][j][i][k] = match[l][j][k][i] = match[l][k][i][j] = match[l][k][j][i] = m++;\n\t }\n\t}\n\tFOR(it, 0, n){\n FOR(s, 0, m) if(dp[p][s]){\n\t\t\tint a = min(state[s][0] + 1, h + 1),\n\t\t\t\tb = min(state[s][1] + 1, h + 1),\n\t\t\t\tc = min(state[s][2] + 1, h + 1),\n\t\t\t\td = min(state[s][3] + 1, h + 1);\n\t\t\tint res = dp[p][s];\n\t\t\tadd(dp[q][match[a == h + 1 ? h + 1 : 0][b][c][d]], res);\n\t\t\tadd(dp[q][match[a][b == h + 1 ? h + 1 : 0][c][d]], res);\n\t\t\tadd(dp[q][match[a][b][c == h + 1 ? h + 1 : 0][d]], res);\n\t\t\tadd(dp[q][match[a][b][c][d == h + 1 ? h + 1 : 0]], res);\n\t\t}\n\t\tp ^= 1, q ^= 1;\n\t\tmemset(dp[q], 0, sizeof(dp[q]));\n\t}\n\tFOR(i, 0, m) if(state[i][0] < h || state[i][1] < h || state[i][2] < h || state[i][3] < h)\n\t\tadd(ans, dp[n & 1][i]);\n\tprintf(\"%d\\n\", ans);\n\treturn 0;\n}\n\n\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "689d49c3fb40700a2e59583f8e367aff", "src_uid": "9fe9658db35076c0bddc8b7ddce11013", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long LL;\ntypedef unsigned long long ULL;\n\n#define SIZE(x) (int((x).size()))\n#define rep(i,l,r) for (int i=(l); i<=(r); i++)\n#define repd(i,r,l) for (int i=(r); i>=(l); i--)\n#define rept(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)\n\n#ifndef ONLINE_JUDGE\n#define debug(x) { cerr<<#x<<\" = \"<<(x)<=MD) a-=MD;\n}\n\nint bitcount(int x)\n{\n\tint ret=0;\n\twhile (x) x-=x&-x, ret++;\n\treturn ret;\n}\n\nint tmask[7]={0,3,6,12,9,15,15};\nint tcost[7]={0,1,1,1,1,2,2};\nint C[10][10], g[16][13][16], all[16], cs[16][210][3], dp[210][210][16];\n\nvoid lemon()\n{\n\tint n,m; scanf(\"%d%d\",&n,&m);\n\tC[0][0]=1;\n\trep(i,1,5)\n\t{\n\t\tC[i][0]=C[i][i]=1;\n\t\trep(j,1,i-1) C[i][j]=C[i-1][j-1]+C[i-1][j];\n\t}\n\t//dp[h][c][mask]\n\t//current height h, c triangles, covering section mask\n\trep(mask,0,15)\n\t\trep(ti,0,6)\n\t\t\tif ((mask&tmask[ti])==tmask[ti])\n\t\t\t\trep(tk,0,15)\n\t\t\t\t\tif (((mask^tmask[ti])&tk)==tk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint nmask=tmask[ti]|tk, cav=0;\n\t\t\t\t\t\trep(i,0,3) if ((!(nmask&(1<>3));\n\t\t\t\t\t\t\tif ((cav&ci)==ci && (mask&cover)==cover)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint av[4], tv[4]; \n\t\t\t\t\t\t\t\trep(i,0,3) if (nmask&(1<=cs[mask][k][0])\n\t\t\t\t\t\tsu(dp[h][c][mask],LL(dp[h-1][c-cs[mask][k][0]][cs[mask][k][1]])*cs[mask][k][2]%MD);\n\t\n\tint s=0;\n\trep(mask,0,15) su(s,dp[n][m][mask]);\n\trep(i,1,m) s=LL(s)*i%MD;\n\tprintf(\"%d\\n\",s);\n}\n\nint main()\n{\n\tios::sync_with_stdio(true);\n\t#ifndef ONLINE_JUDGE\n\t\tfreopen(\"336E.in\",\"r\",stdin);\n\t#endif\n\tlemon();\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["dp", "implementation", "combinatorics", "bitmasks"], "code_uid": "ce4c71c3e9142e868c15890444752899", "src_uid": "fa649fed687d72b1431ac82bc7288116", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int a,b,c,t;\n cin>>a>>b>>c;\n if(a > b)\n {\n t = a;\n a = b;\n b = t;\n \n }\n if(b > c)\n {\n t = c;\n c = b;\n b = t;\n \n }\n if((a+b) <= c)\n {\n cout<<((c-(a+b)) + 1);\n }\n else\n cout<< 0;\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "geometry"], "code_uid": "5dca218b4972070ffbae7ec3ee0146aa", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\n/*............................*/\n\n#define uint uint64_t\n#define mx 100001\n#define ll long long int\n#define ull unsigned long long int\n#define pii pair\n#define pll pair\n#define mp make_pair\n#define pb push_back\n#define inf INT_MAX\n#define pi acos(-1)\n#define eps 1e-8\n#define gcd(a, b) __gcd(a, b)\n#define lcm(a, b) (a * b) / __gcd(a, b)\n#define input(ara, n) \\\n for (int i = 0; i < n; i++) \\\n scanf(\"%d\", &ara[i])\n#define inputl(ara, n) \\\n for (long long int i = 0; i < n; i++) \\\n scanf(\"%lld\", &ara[i])\n#define pf(a) printf(\"%d\\n\", a);\n#define pfl(a) printf(\"%lld\\n\", a);\n#define pfi(a) printf(\"%d \", a);\n#define pfll(a) printf(\"%lld \", a);\n#define sc(a) scanf(\"%d\", &a)\n#define scc(a, b) scanf(\"%d %d\", &a, &b)\n#define sccdbl(a, b) scanf(\"%lf %lf\", &a, &b)\n#define sccc(a, b, c) scanf(\"%d %d %d\", &a, &b, &c)\n#define scccdbl(a, b, c) scanf(\"%lf %lf %lf\", &a, &b, &c)\n#define scl(a) scanf(\"%lld\", &a)\n#define sccl(a, b) scanf(\"%lld %lld\", &a, &b)\n#define scccl(a, b, c) scanf(\"%lld %lld %lld\", &a, &b, &c)\nusing namespace std;\n//int X[]={1,-1,0,0}; //co-ordinate move\n//int Y[]={0,0,1,-1}; //co-ordinate move\n//int X[]={1,1,2,2,-1,-1,-2,-2}; //Knights move\n//int Y[]={2,-2,1,-1,2,-2,1,-1}; //Knights move\nint main()\n{\n int n, m;\n scc(n,m);\n if (m == 0 || m == 1)\n {\n pf(1);\n }\n else if (n == m)\n {\n pf(0);\n }\n else\n {\n n -= m;\n if (n >= m)\n {\n pf(m);\n }\n else\n {\n pf(n);\n }\n }\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "greedy"], "code_uid": "7a572ff86a2cdffd55346d7402b3d7c8", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\n#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)\n#define all(v) (v).begin(), (v).end()\n#define SZ(v) (int)((v).size())\n#define pb push_back\n#define ft first\n#define sd second\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\nconst long long INF = 1e18L + 1;\nconst int IINF = 1e9 + 1;\n\nusing namespace std;\n\ntemplate void _dbg(const char *sdbg, TH h){ cerr< void _dbg(const char *sdbg, TH h, TA... a) {\n while(*sdbg!=',')cerr<<*sdbg++;\n cerr<<'='<> n >> s >> k;\n\trep(i, 1, n + 1){\n\t\tcin >> r[i];\n\t\tm += r[i];\n\t}\n\tstring colours; cin >> colours;\n\trep(i, 1, n + 1){\n\t\tdp[r[i]][i] = min(dp[r[i]][i], abs(i - s));\n\t}\n\tll res = IINF;\n\trep(i, 1, m + 1){\n\t\trep(j, 1, n + 1){\n\t\t\trep(p, 1, n + 1){\n\t\t\t\tif(colours[p - 1] != colours[j - 1] and r[j] > r[p] and i >= r[j]){\n\t\t\t\t\tdp[i][j] = min(dp[i][j], dp[i - r[j]][p] + abs(j - p)); \n\t\t\t\t}\n\t\t\t}\n\t\t\tDBG(i, j, dp[i][j]);\n\t\t\tif(i >= k){\n\t\t\t\tres = min(res, dp[i][j]);\n\t\t\t}\n\t\t}\n\t}\n\tif(res < IINF){\n\t\tcout << res << \"\\n\";\n\t} else {\n\t\tcout << \"-1\\n\";\n\t}\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "f7e02b4543504fc43b55669dd1129225", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nvoid File()\n{\nfreopen(\"output.txt\", \"w\", stdout);\nfreopen(\"input.txt\", \"r\", stdin);\n}\n\n\nint countDivisors(long long n){\nint cnt = 0;\nfor (long long i = 1; i <= sqrt(n); i++) {\nif (n % i == 0) {\n// If divisors are equal,\n// count only one\nif (n / i == i)\n cnt++;\n\nelse // Otherwise count both\n cnt+=2;\n\n}\n}\nreturn cnt;\n}\n\ntypedef vector vi;\ntypedef vector vs;\ntypedef vector > vii;\ntypedef map mii;\ntypedef map msi;\ntypedef map mll;\ntypedef set si;\ntypedef set sst;\ntypedef set sl;\ntypedef long long ll;\ntypedef pair pii;\n#define lp(i,n) for(int i = 0;i < int(n);i++)\n#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)\n#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)\n#define mp(x,y) \tmake_pair((x),(y))\n#define pb(x) \tpush_back((x))\n#define all(v) \t((v).begin()),((v).end())\n#define sz(x) \t\t((int) (x).size())\n#define setzero(a)\tmemset(a,0,sizeof(a))\n#define bits(a) \t__builtin_popcountll(a)\n#define fr first\n#define sc second\n#define el \t \"\\n\"\n#define pii pair\n#define sortva(v) sort(all(v))\n#define sortvd(v) sort(v.rbegin(),v.rend())\n#define sortaa(a,n) sort(a,a+n)\n#define sortad(a,n) sort(a,a+n),reverse(a,a+n)\n#define sfi1(v) scanf(\"%d\",&v)\n#define sfi2(v1,v2) scanf(\"%d %d\",&v1,&v2)\n#define sfi3(v1,v2,v3) scanf(\"%d %d %d\",&v1,&v2,&v3)\n#define sfll1(v) scanf(\"%I64d\",&v);\n#define sfll2(v1,v2) scanf(\"%I64d %I64d\",&v1,&v2)\n#define sfll3(v1,v2,v3) scanf(\"%I64d %I64d %I64d\",&v1,&v2,&v3)\n#define sfstr(v) scanf(\"%s\", v);\n#define sfs1(v) cin>>v;\n#define ndl puts(\"\")\n#define SS stringstream\n#define rep(i, a, n)\tfor(int i = a; i<=n; i++)\n#define ll long long\n#define clr(x, y) memset(x, y, sizeof(x))\nint dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };\nint dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };\n\n\nint const N = 6e5 + 9, MOD = 1e9+7 , oo = 1e9+7;\nint vis[N];\nint col[N];\nint par[N];\nvector>v(N);\n\n\nvector BFS(int s, vector > & adjList) {\n\tvector len(sz(adjList), oo);\n\tqueue< int > q;\n\tq.push(s), len[s] = 0,par[s]=-1;\n\n\tint cur;\n\twhile(!q.empty()) {\n\t\tint cur = q.front();\t q.pop();\n\n\t\tint n=adjList[cur].size();\n\t\tlp(i,n ) if (len[adjList[cur][i]] == oo)\n\t\t\tq.push(adjList[cur][i]), len[adjList[cur][i]] = len[cur]+1,par[adjList[cur][i]]=cur;\n\t}\n\n\treturn len;\t//cur is the furthest node from s with depth dep\n}\n\n\nint get(ll i){\nint s=0;\nwhile(i){\n s+=i%10;\n i/=10;\n}\nreturn s;\n}\n\nint main()\n{\n ll n;\n cin>>n;\n ll x=sqrt(n);\n for (int i=1;i<=1e2;i++){\n if (x*x+get(x)*x==n)return cout<< x,0;\n x--;\n }\n\n cout<< -1;\n\n\n\n\n\n\n\n\n /*\n cin>>t;\n while(t--){\n m=oo;\n cin>>n;\n rng(i,1,n){\n sum=0;\n x=n/i;\n sum+=x*2+i*2;\n if (n%i)sum+=2;\n int h=(i*x)*2+(n%i)*2;\n sum+=h;\n m=min(m,sum);\n }\n cout<< m;\n if (t!=0)cout<< '\\n';\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/*\n*/\n\n\n\n\n\n\n\n\n\n\nreturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "binary search"], "code_uid": "2a62425d2a9d4fbf3296b82378ad4751", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define mem(a,b) memset(a,b,sizeof(a))\n#define ll long long\n#define INF 0x3f3f3f3f\n#define maxn 100000+5\n#define eps 1e-12\n#define mod 1000000007\ninline int read()\n{\n int x=0,f=1;char ch=getchar();\n while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}\n while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();}\n return x*f;\n}\nint a[105],vis[105];\nint main()\n{\n int n;\n n=read();\n mem(vis,0);\n for(int i=1;i<=n/2;++i) a[i]=read(),vis[a[i]]=1;\n sort(a+1,a+n/2+1);\n int sum1=0,sum2=0;\n for(int i=1;i<=n/2;++i)\n {\n if(a[i]%2)\n {\n for(int j=2;j<=n;j+=2)\n {\n if(vis[j]==0)\n {\n sum1+=abs(a[i]-j);vis[j]=1; break; }\n }\n }\n }\n mem(vis,0);\n for(int i=1;i<=n/2;++i) vis[a[i]]=1;\n for(int i=1;i<=n/2;++i)\n {\n if(a[i]%2==0)\n {\n for(int j=1;j<=n;j+=2)\n {\n if(vis[j]==0)\n {\n sum2+=abs(a[i]-j);vis[j]=1;break;\n }\n }\n }\n }\n //cout<<\"sum1=\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include\n#include \n#include \n#include \n#include \n#include \n\n#define int ll\n\n#define F first\n#define S second\n#define mp make_pair\n#define Left(x) (2*(x))\n#define Right(x) ((2*(x))+1)\n#define pii pair\n\nusing namespace std;\ntypedef long long ll;\n\nconst int N = 2e6 + 5 , MOD = 2 , MAXN = 1e5 , LG = 20 , M = 1e6 + 5 , P = 727 , Sq = 100;\nconst ll inf = 1e18 + 10;\n\nint f[N] , mark[N];\nvector v;\n\nint32_t main(){\n string s , t;\n int tmp1 = 0 , tmp2 = 0;\n cin>>s>>t;\n string a[7] = {\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"};\n for(int i = 1 ; i <= 7 ; i++)\n if(s == a[i])\n tmp1 = i;\n for(int i = 1 ; i <= 7 ; i++)\n if(t == a[i])\n tmp2 = i;\n int mm[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\n if(tmp2 == tmp1 || tmp2 == (tmp1 + 2) % 7 || tmp2 == (tmp1 + 3) % 7)\n return cout<<\"YES\" , 0;\n return cout<<\"NO\" , 0;\n}\n", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "8533f062ac72641ce42cc59faea12cfc", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int n;\n cin>>n;\n int a=0;\n for(int i=1;;i++){\n int x=(i*(i+1))/2;\n a=a+x;\n if(a==n){\n cout<n){\n cout<\n#include\nstruct node{\n char s[5];\n int a,b;\n}p[15];\nchar ss[5];\nchar xf[10][5];\nint main(){\n int n,i,j,k;\n int a1,a2,a3,a4;\n while(scanf(\"%d\",&n)!=EOF){\n for(i=0;i\nint main()\n{\n int a,b,c;\n scanf(\"%d %d\",&a,&b);\n if(a==0&&b==0)\n printf(\"NO\");\n else\n {\n if(a>b)\n c=a-b;\n else c=b-a;\n if(c==1||c==0)\n printf(\"YES\");\n else\n printf(\"NO\");}\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "b1ce0aac0ef094c4ccb8f544e7e5d475", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#pragma comment (linker, \"/STACK:256000000\")\n\n#define _USE_MATH_DEFINES\n#define _CRT_NO_DEPRECEATE\n#define _CRT_SECURE_NO_WARNINGS\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef unsigned int uint32;\ntypedef long long int64;\ntypedef unsigned long long uint64;\ntypedef double ldouble;\ntypedef pair pii;\ntypedef pair pll;\ntypedef pair piiii;\n\n#define pb push_back\n#define sq(x) ((x)*(x))\n#define tmin(x,y,z) (min(min((x),(y)),(z)))\n#define rand32() (((unsigned int)(rand()) << 16) | (unsigned int)(rand()))\n#define rand64() (((unsigned int64)(rand32()) << 16) | (unsigned int64)(rand32()))\n#define bit(mask, b) ((mask >> b) & 1)\n#define biton(mask, bit) (mask | (((uint64)(1)) << bit))\n#define bitoff(mask, bit) (mask & (~(((uint64)(1)) << bit)))\n#define bitputon(mask, bit) (mask |= (((uint64)(1)) << bit))\n#define bitputoff(mask, bit) (mask &= (~(((uint64)(1)) << bit)))\n#define FAIL() (*((int*)(0)))++\n#define INF ((int)(1e9) + 1337)\n#define LINF ((int64)(1e18))\n#define EPS (1e-7)\n#define PI (3.1415926535897932384626433832795)\n#define y1 yy1\n#define y0 yy0\n#define j0 jj0\n#define MOD 1000000007LL\n#define HMOD 1234567891LL\n\n//#define HMOD ((int64)(1e18) + 3LL)\n//#ifdef _MY_DEBUG\n//#define HMOD 1000000007\n//#endii\n#define MAX 2000000000\n#define HBASE 1000003\nmt19937 ggen;\n\nint64 x1, y1, x2, y2;\n\nvoid solve()\n{\n cin >> x1 >> y1 >> x2 >> y2;\n if ((x1 & 1) != (y1 & 1))\n {\n x1--;\n x2--;\n } \n if ((y1 & 1) == (y2 & 1))\n {\n int64 b = (y2 - y1) / 2;\n int64 ctr = (x2 - x1) / 2 + !((y1 & 1) ^ (x1 & 1));\n cout << b * (x2 - x1 + 1) + ctr;\n }\n else\n {\n int64 b = (y2 - y1) / 2 + 1;\n cout << b * (x2 - x1 + 1);\n }\n}\n\nint main()\n{\n //testgen(1000, 1000);// return 0;\n ios_base::sync_with_stdio(false); cin.tie(0);\n#ifdef _MY_DEBUG\n freopen(\"input.txt\", \"rt\", stdin); freopen(\"output.txt\", \"wt\", stdout);\n#else\n //freopen(TASK \".in\", \"rt\", stdin); freopen(TASK \".out\", \"wt\", stdout);\n#endif\n //stresstest(); return 0;\n srand(1313);\n ggen = mt19937(13);\n\n solve();\n\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "c83ac8eeb573300df41579c79ef13422", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n//Karswrmepl\nint main ()\n{\nlong long n;\ncin>>n;\nif (n%2){\n\tcout<<1;\n}\nelse {\n\tcout<<2;\n}\n}\n", "lang_cluster": "C++", "tags": ["math", "games"], "code_uid": "d49f36da1a8edf02fef17e127cd071fa", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#ifndef M_PI\n#define M_PI 3.14159265359\n#endif // M_PI\n#define endl \"\\n\"\n#define FOR(x, y, z) for (int x = (y); x < (z); ++x)\n#define FORR(x, y, z) for (int x = (y); x > (z); --x)\n#define GET(a, n) for (int __i = 0; __i < (n); ++__i) cin >> a[__i];\n#define GETM(a, n, m) for (int __i = 0; __i < (n); ++__i) for (int __j = 0; __j < m; ++__j) cin >> a[__i][__j];\n#define PRINTM(a, n, m) for (int __i = 0; __i < (n); ++__i) { for (int __j = 0; __j < m; ++__j) cout << a[__i][__j] << \" \"; cout << endl; };\n#define PRINT(a, n) for (int __i = 0; __i < (n); ++__i) cout << a[__i] << \" \";\n#define IT(a) a.begin(), a.end()\n#define SQR(x) (x) * (x)\n#define CASE(a, s) cout << \"Case #\" << a << \": \" << s << endl;\n#define DEB(a) cout << #a << \" = \" << (a) << endl; cout.flush();\n#define DEBA(a) for (auto __i: a) cout << __i << \" \"; cout << endl; cout.flush();\n#define IFDEB(b, a) if (b) { cout << #a << \" = \" << (a) << endl; cout.flush(); }\nusing namespace std;\ntypedef long long LL;\ntypedef unsigned long long ULL;\ntypedef vector VI;\ntypedef vector > VVI;\ntypedef pair PII;\nconst int MOD = 1000000007;\ntemplate typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }\nstruct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;\n\nint gcd_ext(int a, int b, int &x, int &y) {\n if (a == 0) {\n x = 0; y = 1;\n return b;\n }\n int x1, y1;\n int d = gcd_ext(b % a, a, x1, y1);\n x = y1 - (b / a) * x1;\n y = x1;\n return d;\n}\n\nLL inv(LL t, LL mod)\n{\n if (t == 0) {\n return 0;\n }\n int x;\n int y;\n gcd_ext(t, mod, x, y);\n return (x % mod + mod) % mod;\n}\n\nvector fact(10002);\nvector inv_fact(10002);\n\nint a(int n, int k)\n{\n if (n < k) {\n return 0;\n }\n LL res = fact[n];\n res *= inv_fact[n - k];\n res %= MOD;\n return res;\n}\n\nvoid init_comb()\n{\n fact[0] = 1;\n inv_fact[0] = 1;\n FOR (i, 1, fact.size()) {\n fact[i] = fact[i - 1] * i;\n fact[i] %= MOD;\n inv_fact[i] = inv(fact[i], MOD);\n }\n}\n\nint main()\n{\n string s;\n cin >> s;\n int c = 0;\n int q = count(IT(s), '?');\n FOR (i, 'A', 'J' + 1) {\n c += count(IT(s), i) > 0;\n }\n init_comb();\n if ('0' <= s[0] && s[0] <= '9') {\n cout << a(10, c);\n FOR (i, 0, q) {\n cout << '0';\n }\n return 0;\n }\n if ('A' <= s[0] && s[0] <= 'J') {\n cout << a(9, c - 1) * 9;\n FOR (i, 0, q) {\n cout << '0';\n }\n return 0;\n }\n cout << a(10, c) * 9;\n FOR (i, 0, q - 1) {\n cout << '0';\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy"], "code_uid": "6ebc6ebf79ffeb170ebec68d724d4974", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++0x", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define eps 1e-8\n#define rep(i,a,b) for(int i = (a); i < (b); ++i)\n#define rrep(i,b,a) for(int i = (b); i >= (a); --i)\n#define clr(a,x) memset(a,(x),sizeof(a))\n#define mp make_pair\n#define lson l,m,rt<<1\n#define rson m+1,r,rt<<1|1\n#define ll long long\n#define ld long double\nconst int maxn = 10;\nconst int inf = 1e9;\nint L[maxn],R[maxn];\nint id[maxn];\n\nll sum[10010];\nint main()\n{\n// Getinput(); return 0;\n #ifdef ACM\n// freopen(\"in.txt\",\"r\",stdin);\n// freopen(\"out.txt\",\"w\",stdout);\n #endif // ACM\n int n; cin >> n;\n rep(i,0,n) scanf(\"%d%d\",L+i, R+i);\n rep(s,1,(1< v[2];\n rep(j,0,n) {\n if (s & (1< v[2];\n rep(j,0,n) {\n if (s & (1<\nusing namespace std;\n \n#define clr(i, j) memset(i, j, sizeof(i))\n#define pb push_back\n \ntypedef long long ll;\n \n//-*-*-*-*-*-*-*-*-\nll sum,n,b; ll pre[100000]; ll pref[1000000]; ll pr[100000];\nll k[1000000];\n ll chek(ll x){\n clr(k,0);\n ll s=pref[x-1];ll j=x-1;\n ll d=0;\n while(s=b);\n }\nll a[300000]; \n/*\n cin>>m>>s;//ll ans=0;\n sethotset;\n ll k=0;\n for(int i=0;iv;\n \ncin>>n>>b; ll d;\nfor(int i=0;i>d;v.push_back(d);sum+=d;}\nsort(v.rbegin(),v.rend());pref[0]=v[0];\nfor(int i=0;i0){pref[i]=pref[i-1]+v[i];}}\nll x=1;ll y=n;ll ans;\nif(pref[n-1]\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nusing namespace std;\r\nusing namespace __gnu_pbds;\r\n\r\ntypedef std::pair pii;\r\ntypedef std::pair psc;\r\ntypedef unsigned long long ull;\r\ntypedef long long ll;\r\ntypedef long double lb;\r\ntypedef tree,\r\n rb_tree_tag,\r\n tree_order_statistics_node_update> ordered_set;\r\n\r\n#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\r\n#define file_in freopen(\"input.txt\", \"r\", stdin);\r\n#define file_in_out freopen(\"commander.in\", \"r\", stdin); freopen(\"commander.out\", \"w\", stdout);\r\n#define all(x) (x).begin(), (x).end()\r\n#define fi first\r\n#define se second\r\n\r\ntemplate\r\nistream& operator>>(istream &in, vector &v) {\r\n for (auto &it : v) {\r\n in >> it;\r\n }\r\n return in;\r\n}\r\n\r\ntemplate\r\nostream& operator<<(ostream &out, const vector &v) {\r\n for (auto &it : v) {\r\n out << it << \" \";\r\n }\r\n return out;\r\n}\r\n\r\ntemplate\r\nistream& operator>>(istream &in, pair &v) {\r\n in >> v.fi >> v.se;\r\n return in;\r\n}\r\n\r\ntemplate\r\nostream& operator<<(ostream &out, const pair &v) {\r\n out << v.fi << \" \" << v.se;\r\n return out;\r\n}\r\n\r\nvoid solve() {\r\n int n, m;\r\n cin >> n >> m;\r\n vector cnt(17);\r\n while (n) {\r\n cnt[n % m]++;\r\n if (cnt[n % m] > 1) {\r\n cout << \"NO\" << '\\n';\r\n return;\r\n }\r\n n /= m;\r\n }\r\n cout << \"YES\" << '\\n';\r\n}\r\n\r\nint main() {\r\n fast\r\n // file_in\r\n // file_in_out\r\n\r\n int t = 1; \r\n // cin >> t;\r\n while (t--) {\r\n solve();\r\n }\r\n return 0;\r\n}", "lang_cluster": "C++", "tags": ["number theory"], "code_uid": "fea49bf4259b4a6db7c91e3fff4172a6", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define pb push_back\n#define mp make_pair\n#define F first\n#define S second\n\n#define foreach(i, c) for (typeof(c.begin()) i = c.begin(); i != c.end(); ++i)\n\n#ifdef LOCAL\n#define debug(...) fprintf(stderr, __VA_ARGS__)\n#else\n#define debug(...)\n#endif // LOCAL\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair pii;\ntypedef vector vi;\ntypedef long double ld;\n\nconst int INF = int(1e9);\nconst ll INFll = 1ll * INF * INF;\nconst ld EPS = 1e-26;\nconst int MOD = 1000000007;\nconst int N = 1e5; // limit for array size\n\n\n\n#define FILE \"knapsack\"\nint main() {\n ios_base::sync_with_stdio(0);\n#ifdef LOCAL\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#endif\n int w, c;\n cin >> w >> c;\n if (w == 2 || w == 3) {\n cout << \"YES\";\n return 0;\n }\n vector v;\n while (c > 0) {\n v.pb(c % w);\n #ifdef LOCAL\n cout << c % w << \" \";\n #endif\n c /= w;\n }\n #ifdef LOCAL\n cout << endl;\n #endif\n v.pb(0);\n for (int i = 0; i < v.size()-1; i++) {\n if (v[i] != 0 && v[i] != 1 && v[i] != w - 1 && v[i] != w - 2) {\n cout << \"NO\";\n return 0;\n }\n if (v[i] == w - 2 && (i == 0 || (v[i-1] != w - 2 && v[i-1] != w - 1))) {\n cout << \"NO\";\n return 0;\n }\n if ((v[i] == w - 1 || v[i] == w - 2) && v[i+1] == 1) {\n cout << \"NO\";\n return 0;\n }\n }\n cout << \"YES\";\n return 0;\n reverse(v.begin(), v.end());\n for (int i = 0; i < v.size(); i++) {\n cout << v[i] << \" \";\n }\n debug(\"\\nTIME = %ld\\n\", clock());\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "meet-in-the-middle", "greedy", "number theory"], "code_uid": "1d0779461797a4a3b6e7ccc419da692a", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "MS C++ 2017", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint getOperation(string& s, int pos)\n{\n\tstring pattern = \"ACTG\";\n\n\tint op = 0;\n\n\tfor (int i = pos, j = 0; i < pos + 4; i++, j++)\n\t{\n\t\tint move = abs(pattern[j] - s[i]);\n\t\top += move <= 13 ? move : (26 - move);\n\t}\n\n\treturn op;\n}\n\nint main()\n{\n\tint length;\n\tstring s;\n\n\tcin >> length;\n\tcin >> s;\n\t\n\n\tint minOp = 1000000;\n\tfor (int i = 0; i <= length - 4; i++)\n\t{\n\t\tminOp = min(minOp, getOperation(s, i));\n\t}\n\n\tprintf(\"%d\\n\", minOp);\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "strings"], "code_uid": "53792cd00cb09c89156e7ded1e0889aa", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\ntypedef long long LL;\n\nLL MOD;\n\nLL powmod(LL a, LL n){\n if(n == 0) return 1;\n if(n % 2) return (a*powmod(a,n-1)) % MOD;\n LL c = powmod(a, n/2);\n return (c*c) % MOD;\n}\nLL inv(LL a){\n return powmod(a, MOD-2);\n}\nLL fact[110000];\nLL invfact[110000];\n\nLL ncr(LL n, LL r){\n if(r < 0 || n < 0) return 0;\n if(n < r) return 0;\n LL a = fact[n];\n a = (a * invfact[r]) % MOD;\n a = (a * invfact[n-r]) % MOD;\n return a;\n}\n\nLL get(LL a, LL b){\n\tLL ans = 0;\n\tfor(LL q = 2; q <= a+b; q++){\n\t\tLL f = min(a, q-1) - max(1LL, q-b) + 1;\n\t\tans += f * inv(q);\n\t\tans %= MOD;\n\t}\n\treturn ans;\n}\n\nint main(){\n\tLL n, k, q;\n\tcin >> n >> k >> q;\n\tMOD = q;\n\n\tmap r;\n\tr[n] = 1;\n\tfor(int j = 1; j < k; j++){\n\t\tmap rr;\n\t\tfor(auto x : r){\n\t\t\tif(x.first == 1){\n\t\t\t\trr[x.first] += x.second;\n\t\t\t} else {\n\t\t\t\trr[x.first / 2] += x.second;\n\t\t\t\trr[(x.first + 1) / 2] += x.second;\n\t\t\t}\n\t\t}\n\t\tr = rr;\n\t\tif(rr.count(1) && rr[1] == n) break;\n\t}\n\tLL avg = n * (n-1) / 2;\n\tavg %= MOD;\n\tavg = (avg * inv(2)) % MOD;\n\n\tif(r.size() == 1){\n\t\tauto x = *r.begin();\n\t\tLL freq = x.second;\n\t\tLL g = x.first;\n\t\tavg -= (freq * (freq - 1) / 2) % MOD * get(g,g);\n\t\tavg %= MOD;\n\t} else if(r.size() == 2){\n\t\tvector > x;\n\t\tfor(auto b : r) x.push_back(b);\n\t\tLL freq0 = x[0].second;\n\t\tLL freq1 = x[1].second;\n\t\tavg -= (freq0 * (freq0 - 1) / 2) % MOD * get(x[0].first, x[0].first);\n\t\tavg %= MOD;\n\t\tavg -= (freq1 * (freq1 - 1) / 2) % MOD * get(x[1].first, x[1].first);\n\t\tavg %= MOD;\n\t\tavg -= (freq0 * freq1) % MOD * get(x[0].first, x[1].first);\n\t\tavg %= MOD;\n\t}\n\tavg %= MOD;\n\tif(avg < 0) avg += MOD;\n\tcout << avg << '\\n';\n}", "lang_cluster": "C++", "tags": ["math", "probabilities"], "code_uid": "89b281fa56d1c5a526989b405b95c47a", "src_uid": "1dd54f5071872e947996ab32b16da19c", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n\nvoid answer(size_t v)\n{\n std::cout << v << '\\n';\n}\n\nvoid solve(std::string& s)\n{\n const size_t n = s.length();\n\n std::set words;\n for (size_t i = 0; i < n; ++i)\n words.insert(s.substr(i+1) + s.substr(0, i+1));\n\n answer(words.size());\n}\n\nint main()\n{\n std::string s;\n std::cin >> s;\n\n solve(s);\n\n return 0;\n}\n\n", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "e562a2e408fd64d02b52f157021ea750", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "/**Bismillahir Rahmanir Rahim\n In the name of ALLAH, most gracious, most merciful */\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define inf (1<<29)\n#define pb push_back\n#define mp make_pair\n#define eps 1e-9\n#define nl printf(\"\\n\")\n#define spc printf(\" \")\n#define sci(n) scanf(\"%ld\",&n)\n#define sc64(n) scanf(\"%I64d\",&n)\n#define scii(a,b) scanf(\"%ld %ld\",&a,&b)\n#define sc6464(a,b) scanf(\"%I64d %I64d\",&a,&b)\n#define scs(s) scanf(\"%s\",s)\n#define scss(a,b) scanf(\"%s %s\",a,b)\n#define scd(f) scanf(\"%lf\",&f)\n#define scdd(a,b) scanf(\"%lf %lf\",&a,&b)\n#define prc(k) printf(\"Case %ld: \",k);\n#define pri(a) printf(\"%ld\",a)\n#define pr64(a) printf(\"%I64d\",a)\n#define prii(a,b) printf(\"%ld %ld\",a,b)\n#define pr6464(a,b) printf(\"%I64d %I64d\",a,b)\n#define prs(a) printf(\"%s\",a)\n#define prss(a,b) printf(\"%s %s\",a,b)\n#define prd(a) printf(\"%lf\",a)\n#define prdd(a,b) printf(\"%lf %lf\",a,b)\n#define rep(i,n) for(int i(0),_n(n);i<_n;++i)\n#define repr(i,n) for(int i=n;i>=0;i--)\n#define repi(i,a,b) for(int i(a),_b(b);i<=_b;++i)\n#define repl(i,n) for(int i(1),_n(n);i<=_n;++i)\n#define repir(i,a,b) for(int i=a;i>=b;i--)\n#define chk(a,k) ((bool)(a&(1<<(k))))\n#define off(a,k) (a&(~(1<<(k))))\n#define on(a,k) (a|(1<<(k)))\n#define ff first\n#define ss second\n#define all(a) a.begin(),a.end()\n#define mem(x,a) memset(x,a,sizeof(x))\n#define repe(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)\nint dx[]={0,0,1,-1,1,-1,1,-1},dy[]={1,-1,0,0,1,-1,-1,1};\ntypedef vector vi;\ntypedef vector vl;\ntypedef vector vll;\ntypedef vector vs;\n#define ll long long\ntypedef vector > vvi;\ninline void cn( long &n )//fast input function\n{\nn=0;\nlong ch=getchar();int sign=1;\nwhile( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getchar();}\nwhile(ch >= '0' && ch <= '9')\nn = (n<<3)+(n<<1) + ch-'0', ch=getchar();\nn=n*sign;\n}\ntemplate void cmin(T &a,T b){if(b void cmax(T &a,T b){if(b>a) a=b;}\ntemplate int len(const T&c){return (int)c.size();}\ntemplate int len(char c[]){return (int)strlen(c);}\nstring itos(long n){string s;while(n){s+=(n%10+48);n/=10;}reverse(all(s));return s;}\nlong stoi(string s){long n=0;rep(i,len(s))n=n*10+(s[i]-48);return n;}\n\n//Polya-Burnside theory : (n^6+3n^4+12n^3+8n^2)/24\n#define DEBUG 1\n#if DEBUG && !ONLINE_JUDGE\n\t#define debug(args...) (Debugger()) , args\n\tclass Debugger { public: Debugger(const std::string& _separator = \", \") : first(true), separator(_separator){} template Debugger& operator , (const ObjectType& v) { if(!first) std::cerr << separator; std::cerr << v; first = false; return *this; } ~Debugger() { std::cerr << endl;} private: bool first; std::string separator; }; template inline std::ostream& operator << (std::ostream& os, const std::pair& p) { return os << \"(\" << p.first << \", \" << p.second << \")\"; } template inline std::ostream &operator << (std::ostream & os,const std::vector& v) { bool first = true; os << \"[\"; for(unsigned int i = 0; i < v.size(); i++) { if(!first) os << \", \"; os << v[i]; first = false; } return os << \"]\"; } template inline std::ostream &operator << (std::ostream & os,const std::set& v) { bool first = true; os << \"[\"; for (typename std::set::const_iterator ii = v.begin(); ii != v.end(); ++ii) { if(!first) os << \", \"; os << *ii; first = false; } return os << \"]\"; } template inline std::ostream &operator << (std::ostream & os,const std::map& v) { bool first = true; os << \"[\"; for (typename std::map::const_iterator ii = v.begin(); ii != v.end(); ++ii) { if(!first) os << \", \"; os << *ii ; first = false; } return os << \"]\"; }\n#else\n\t\t#define debug(args...)\n#endif\n#define mod 1000000007\n\nint main()\n{\n\n\n long long a,b,aa,bb,r1,r2;\n\n while(cin>>a>>b){\n long long s,d,tot=0;\n for(long i=1;i\n#include \n\nusing namespace std;\n\nmap d;\n\nvoid pre();\nstring chrd(string x, string y, string z);\n\nint main() {\n\tstring x, y, z;\n\tcin >> x >> y >> z;\n\tpre();\n\tif (chrd(x, y, z) != \"0\") cout << chrd(x, y, z) << '\\n';\n\telse if (chrd(x, z, y) != \"0\") cout << chrd(x, z, y) << '\\n';\n\telse if (chrd(y, x, z) != \"0\") cout << chrd(y, x, z) << '\\n';\n\telse if (chrd(y, z, x) != \"0\") cout << chrd(y, z, x) << '\\n';\n\telse if (chrd(z, x, y) != \"0\") cout << chrd(z, x, y) << '\\n';\n\telse if (chrd(z, y, x) != \"0\") cout << chrd(z, y, x) << '\\n';\n\telse cout << \"strange\\n\";\n}\n\nvoid pre() {\n\td[\"C\"] = 0;\n\td[\"C#\"] = 1;\n\td[\"D\"] = 2;\n\td[\"D#\"] = 3;\n\td[\"E\"] = 4;\n\td[\"F\"] = 5;\n\td[\"F#\"] = 6;\n\td[\"G\"] = 7;\n\td[\"G#\"] = 8;\n\td[\"A\"] = 9;\n\td[\"B\"] = 10;\n\td[\"H\"] = 11;\n}\n\nstring chrd(string x, string y, string z) {\n\tint a, b;\n\ta = (d[y] - d[x] + 12) % 12;\n\tb = (d[z] - d[y] + 12) % 12;\n\tif (a == 4 && b == 3) return \"major\";\n\tif (a == 3 && b == 4) return \"minor\";\n\treturn \"0\";\n}\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "5378d5ae212c39d92799f46c7d1f6ef7", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define ll long long\n#define mp make_pair\n#define pb push_back\n//#define ld long double\nconst double sn = 1e-6;\nint a, b, l, r;\nint main() {\n\tscanf(\"%d%d%d%d\", &a, &b, &l, &r);\n\tif (r - l + 1 >= (a + b)*2) {\n\t\tif (b >= a) {\n\t\t\tprintf(\"%d\\n\", a+1);\n\t\t}\n\t\telse {\n\t\t\tprintf(\"%d\\n\", a+ (a-b));\n\t\t}\n\t}\n\telse {\n\t\tint t = 1, v2 = r % ((a + b) * 2), co = 0, temp = 1;\n\t\tvector ve = {};\n\t\tbool last = false;\n\t\tint t2 = 1, t3 = 1;\n\t\twhile (true) {\n\t\t\tif (t2 == v2 && t3 >= (r - l) + 1)\n\t\t\t\tbreak;\n\t\t\tt2 = (t2 + 1) % (2*(a+b));\n\t\t\tt3++;\n\t\t}\n\t\twhile (true) {\n\t\t\tif ((t >= 1 && t <= a) || (t >= a + b + 1 && t <= 2 * a + b)) {\n\t\t\t\tlast = false;\n\t\t\t\tint dig = 1;\n\t\t\t\t//cout << \"c \" << co << \",\" << ve.size() << endl;\n\t\t\t\twhile (true) {\n\t\t\t\t\tbool val = true;\n\t\t\t\t\tfor (int i = ve.size() - 1; i >= max((int)ve.size() - a-co, 0); i--) {\n\t\t\t\t\t\tif (ve[i] == dig) {\n\t\t\t\t\t\t\tval = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (val)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\telse\n\t\t\t\t\t\tdig++;\n\t\t\t\t}\n\t\t\t\tve.push_back(dig);\n\t\t\t\tco++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tco = 0;\n\t\t\t\tif (b >= a || last) {\n\t\t\t\t\tve.push_back(ve[ve.size()-1]);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tint sz = ve.size();\n\t\t\t\t\tint tv = t3 - (r - l + 1);\n\t\t\t\t\t//cout << tv << \",\" << sz << endl;\n\t\t\t\t\tif (sz - (a - b) >= tv || sz <= tv) {\n\t\t\t\t\t\tve.push_back(ve[sz - (a - b)]);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tve.push_back(ve[tv]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlast = true;\n\t\t\t}\n\t\t\tif (t == v2 && temp >= (r-l)+1)\n\t\t\t\tbreak;\n\t\t\tt = (t + 1) % ((a + b) * 2);\n\t\t\ttemp++;\n\t\t}\n\t\tbool vis[30] = {};\n\t\tint ans = 0, sz = ve.size();\n\t\tfor (int i = sz - 1; i >= sz - (r - l + 1); i--) {\n\t\t\t//cout << ve[i] << endl;\n\t\t\tif (!vis[ve[i]]) {\n\t\t\t\tvis[ve[i]] = true;\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\tprintf(\"%d\\n\", ans);\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "games"], "code_uid": "45aab93ec9b0b52fd7955b999d2712f8", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int x,y,z;\n cin>>x>>y>>z;\n y=max(max(x,y),z)-min(min(x,y),z);\n cout<\n#include \n#include \n\nusing namespace std;\n\nint h[256];\nbool visit[6];\nvector v;\n\nvoid Init()\n{\n h['R']=0;h['O']=1;h['Y']=2;h['G']=3;h['B']=4;h['V']=5;\n}\n\nint c[6],f[6],r[6];\nchar s[10];\n\nint Cal()\n{\n int ret=0;\n for(int i=0;i<6;i++)\n ret=ret*6+f[i];\n return ret;\n}\n\nvoid R1()\n{\n int t=f[0];\n f[0]=f[1];f[1]=f[2];f[2]=f[3];f[3]=t;\n}\n\nvoid R2()\n{\n int t=f[0];\n f[0]=f[5];f[5]=f[2];f[2]=f[4];f[4]=t;\n}\n\nvoid R3()\n{\n int t=f[3];\n f[3]=f[4];f[4]=f[1];f[1]=f[5];f[5]=t;\n}\n\nbool Exist(int val)\n{\n for(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define pb push_back\n#define mp make_pair\n#define fs first\n#define sc second\n#define get(a,b); a b; cin >> b;\n\n#define forn(i,n) for (int i=0; i=0; --i)\n#define fore(i,a,b) for (int i=int(a); i<=int(b); ++i)\n\n#define all(a) a.begin(), a.end()\n\nconst int INF = 1e9;\nconst long long INF64 = 1e18;\nconst long double eps = 1e-9;\nconst long double pi = 3.14159265358979323846;\n\nint main(){\n double n,R,r;\n cin >> n >> R >> r;\n if (n == 1){\n if (r-eps\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#define int long long\nusing namespace std;\n#define loop(n) for(int i=0;i vi;\ntypedef pair pii;\ntypedef pair pnii; /// weighted grid\ntypedef vectorvii;\nvoid init()\n{\n cin.tie(0);\n cin.sync_with_stdio(0);\n cout.tie(0);\n #ifdef OnlineJudge\n freopen(\"input.txt\",\"r\",stdin);\n freopen(\"output.txt\",\"w\",stdout);\n #endif\n}\nll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.\nll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}\nll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}\nint fix (int a,int k){ return (a%k + k)%k; } // convert N mod to P mode\nint * LIS_Lengths(vector a) { int* lis = new int[a.size()];int b[a.size()];int maxLength = 1, lowerBound;lis[0] = 1, b[0] = a[0];for (size_t i = 1; i < a.size(); i++) {lowerBound = lower_bound(b, b + maxLength, a[i]) - b;\nlis[i] = lowerBound + 1;if (lowerBound == maxLength) b[maxLength++] = a[i];else b[lowerBound] = a[i];}return lis;}\nbool is_prime(ll n){if(n==2) return true;if(n<2 || n%2 == 0)return false;for(int i=3; i * i <= n; i+=2){if(n % i == 0)return false;}return true;}\nll LCM(ll a, ll b){return (a * b)/__gcd(a,b);}\nint dx[] = {1,-1,0,0};\nint dy[] = {0,0,1,-1};\nint dr[] = {0,0,0,1,1,1,-1,-1,-1};\nint dc[] ={-1,0,1,-1,0,1,-1,0,1};\n/// <<------------------------------------------------------------------------------>>\n\n/// <<----;------------------------------------------------------------------------->>\nint main()\n{\n init();\n ll n;\n cin >> n;\n bool ok = 0;\n for(ll m = 1 ; m < ll(1e8) ; m++)\n {\n ll d = m*(m + 1) / 2;\n if(d >= n)\n {\n cout << m - (d - n) << endl;\n return 0;\n }\n }\n}\n", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "36fe6dca51a2f18cf4f37d265ebb5a45", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define up(l,r,i) for(int i=l;i<=r;i++)\n#define dn(l,r,i) for(int i=l;i>=r;i--)\nusing namespace std;\n\ntypedef long long LL;\nconst int INF =2147483647;\nint qread(){\n int w=1,c,ret;\n while((c=getchar())> '9'||c< '0')\n w=(c=='-'?-1:1); ret=c-'0';\n while((c=getchar())>='0'&&c<='9')\n ret=ret*10+c-'0';\n return ret*w;\n}\nint a1,a2,b1,b2,c1,c2,f1,f2;\nint main(){\n a1=qread(),b1=qread(),c1=qread();\n a2=qread(),b2=qread(),c2=qread();\n if(a1==0&&b1==0&&c1==0) f1= 1; else\n if(a1==0&&b1==0&&c1!=0) f1=-1;\n if(a2==0&&b2==0&&c2==0) f2= 1; else\n if(a2==0&&b2==0&&c2!=0) f2=-1;\n if(f1==-1||f2==-1) puts(\"0\"); else\n if(f1== 1||f2== 1) puts(\"-1\");else\n if(b1*a2-a1*b2!=0) puts(\"1\"); else\n if(a1*c2==a2*c1&&b1*c2==b2*c1) puts(\"-1\");\n else puts(\"0\");\n return 0;\n}\n/*\na1x+b1y+c1=0\na2x+b2y+c2=0\na1*c2=a2*c1\na1a2x+b1a2y+c1a2=0\na1a2x+a1b2y+a1c2=0\na1b2x+b1b2y+c1b2=0\na2b1x+b2b1y+c2b1=0\n(a1b2-a2b1)x=c2b1-c1b2\ny=(a1c2-c2a2)/(b1a2-a1b2)\nx=(c2b1-c1b2)/(a1b2-a2b1)\n*/", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "1179325661db83ecbd8c8631b7cacba2", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \nusing namespace std;\n#define LL long long\nconst int N = 1500001;\nint vis[N];\nLL a[N], b[N];\nbool judge(int x)\n{\n char s[13];\n sprintf(s,\"%d\",x);\n int len = (int)strlen(s);\n for(int i=0; i>1; i++)\n if(s[i] != s[len-1-i]) return false;\n return true;\n}\nvoid Init()\n{\n for(int i=2; i*i=1 ;i--)\n if(q*a[i] <= p*b[i])\n {\n ans = i;\n break;\n }\n if(ans == -1) puts(\"Palindromic tree is better than splay tree\");\n else printf(\"%d\\n\",ans);\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "binary search", "number theory"], "code_uid": "63edacb8174477acbbd52f83e82de54d", "src_uid": "e6e760164882b9e194a17663625be27d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#pragma GCC optimize(\"unroll-loops\")\n#include \n#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef pair P;\ntypedef pair P1;\ntypedef pair P2;\n#define pu push\n#define pb push_back\n#define mp make_pair\n#define eps 1e-7\n#define INF 1000000000\n#define mod 1000000007\n#define fi first\n#define sc second\n#define rep(i,x) for(int i=0;i0){\n\t\tif(n&1) res=res*x%mod;\n\t\tx=x*x%mod;\n\t\tn>>=1;\n\t}\n\treturn res;\n}\nint n,m;\nll cnt[(1<<20)],cnt2[(1<<20)];\nll a[10][10];\nint rev[(1<<20)],rev2[(1<<20)];\nvoid dfs(int cur,vectorcon,ll prob){\n\tif(cur == m){\n\t\tint nxt = 0, id = 0;\n\t\trep(j,(1<vi; rep(i,n) if(((j>>i)&1)) vi.pb(i);\n\t\t\tint ok = 0;\n\t\t\tdo{\n\t\t\t\trep(x,m) if(!((con[x]>>vi[x])&1)) goto fail;\n\t\t\t\tok = 1; break; fail:;\n\t\t\t}while(next_permutation(vi.begin(),vi.end()));\n\t\t\tif(ok) id |= (1<>k)&1)){\n\t\t\t\tnw = nw*a[cur][k]%mod;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnw = nw*(mod+1-a[cur][k])%mod;\n\t\t\t}\n\t\t}\n\t\tdfs(cur+1,con,nw);\n\t\tcon.pop_back();\n\t}\n}\nvoid dfs2(int cur,vectorcon,ll prob){\n\tif(cur == n){\n\t\tint nxt = 0, id = 0;\n\t\trep(j,(1<vi; rep(i,n) if(((j>>i)&1)) vi.pb(i);\n\t\t\tint ok = 0;\n\t\t\tdo{\n\t\t\t\trep(x,n-m) if(!((con[x]>>vi[x])&1)) goto fail2;\n\t\t\t\tok = 1; break; fail2:;\n\t\t\t}while(next_permutation(vi.begin(),vi.end()));\n\t\t\tif(ok) id |= (1<>k)&1)){\n\t\t\t\tnw = nw*a[cur][k]%mod;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnw = nw*(mod+1-a[cur][k])%mod;\n\t\t\t}\n\t\t}\n\t\tdfs2(cur+1,con,nw);\n\t\tcon.pop_back();\n\t}\n}\n\nint main(){\n\tcin >> n;\n\trep(i,n) rep(j,n){\n\t\tcin >> a[i][j]; a[i][j] = a[i][j]*modpow(100LL,mod-2)%mod; a[i][j] = (a[i][j]%mod+mod)%mod;\n\t}\n\tif(n == 1){\n\t\tcout << a[0][0] << endl;\n\t\treturn 0;\n\t}\n\tm = n/2;\n\tdfs(0,vector(),1);\n\trep(i,(1<<20)) cnt[i] %= mod;\n\t//cnt[j]... j no submask\n\tfor(int i=0;i<20;i++){\n\t\tfor(int j=0;j<(1<<20);j++){\n\t\t\tif(((j>>i)&1)){\n\t\t\t\tcnt[j] += cnt[j^(1<(),1);\n\trep(i,(1<<20)) cnt2[i] %= mod;\n\tmemset(rev,-1,sizeof(rev));\n\tint nd = 0;\n\trep(i,(1<>j)&1));\n\t\t\telse mask += (1<\nusing namespace std;\nconst int N = 60;\nchar p[N][10];\nint vis[N][N][N][N];\nbool dfs(int id,int a,int b,int c) {\n\tif (id == 1)return 1;\n\tif (vis[id][a][b][c])return 0;\n\tif (p[b][0] == p[c][0] || p[b][1] == p[c][1]) {\n\t\tif (dfs(id - 1, id - 3, a, c))return 1;\n\t}\n\tif (id > 3) {\n\t\tif (p[id - 3][0] == p[c][0] || p[id - 3][1] == p[c][1]) {\n\t\t\tif (dfs(id - 1, c, a, b))return 1;\n\t\t}\n\t}\n\tvis[id][a][b][c]=1;\n\treturn 0;\n}\nint main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\tfor (int i = 1; i <= n; i++) \n\t\tscanf(\"%s\", p[i]);\n\tprintf(n == 1 || dfs(n, n - 2, n - 1, n) ? \"YES\\n\" : \"NO\\n\");\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "dp"], "code_uid": "5d24515f887490336d8cfefec8ad3b42", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#ifndef LOCAL\n#pragma GCC optimize(\"O3\")\n#endif\n#include \nusing namespace std;\n#define sim template muu & operator<< (\n#define ris return *this\n#define R22(r) sim> typename enable_if<1 r sizeof(dud(0)), muu&>::type operator<<(c g) {\nsim> struct rge {c h, n;};\nsim> rge range(c h, c n) {return rge{h, n};}\nsim, class F> struct rgm {c h, n; F f;};\nsim, class F> rgm map_range(c b, c e, F f) {return rgm{b, e, f};}\nsim, class F> rgm map_range(const c &x, F f) {return map_range(x.begin(), x.end(), f);}\nsim> auto dud(c *r) -> decltype(cerr << *r);\nsim> char dud(...);\nstruct muu {\n#ifdef LOCAL\n\tstringstream a;\n\t~muu() {cerr << a.str() << endl;}\n\tR22(<) a << boolalpha << g; ris;}\n\tR22(==) ris << range(begin(g), end(g));}\n\tsim mor rge u) {\n\t\ta << '[';\n\t\tfor (c s = u.h; s != u.n; ++s)\n\t\t\t*this << \", \" + 2 * (s == u.h) << *s;\n\t\tris << ']';\n\t}\n\tsim, class n mor pair r) {ris << \"(\" << r.first << \", \" << r.second << \")\";}\n\tsim, class F mor rgm u) {\n\t\tfor (c s = u.h; s != u.n; ++s)\n\t\t\tu.f(*this << \", \" + 2 * (s == u.h), *s);\n\t\tris;\n\t}\n\t#else\n\tsim mor const c&) {ris;}\n\t#endif\n\tmuu & operator()() {ris;}\n};\n#define debug (muu() << __FUNCTION__ << \"#\" << __LINE__ << \": \")\n#define imie(r) \"[\" #r \": \" << (r) << \"] \"\n#define imask(r) \"[\" #r \": \" << bitset<8 * sizeof(r)>(r) << \"] \"\n#define arr(a, i) \"[\" #a imie(i) \": \" << a[i] << \"] \"\n#define arr2(a, i, j) \"[\" #a imie(i) imie(j) << \": \" << a[i][j] << \"] \"\nconst int nax = 101;\nusing ll = long long;\nconst ll mod = 1e9 + 7;//588518285577289787ll;\nll ways[nax][nax * nax];\nint cou[nax];\nvoid add(ll &a, ll b) {\n\ta += b;\n\tif (a > mod)\n\t\ta -= mod;\n}\nll binom[nax][nax];\nint main() {\n\tint diff = 0;\n\tfor (int i = 0; i < nax; ++i)\n\t\tbinom[i][i] = binom[i][0] = 1;\n\tfor (int i = 1; i < nax; ++i)\n\t\tfor (int j = 1; j < i; ++j)\n\t\t\tbinom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;\n\tint n;\n\tscanf(\"%d\", &n);\n\tfor (int i = 0; i < n; ++i) {\n\t\tint x;\n\t\tscanf(\"%d\", &x);\n\t\tcou[x]++;\n\t}\n\tfor (int i = 0; i < nax; ++i)\n\t\tif (cou[i])\n\t\t\tdiff++;\n\tways[0][0] = 1;\n\tint seen_so_far = 0, sum_so_far = 0;\n\tfor (int i = 1; i < nax; ++i) {\n\t\tfor (int l = 0; l < cou[i]; ++l) {\n\t\t\tfor (int c = seen_so_far; c >= 0; --c)\n\t\t\t\tfor (int s = 0; s <= sum_so_far; ++s)\n\t\t\t\t\tadd(ways[c + 1][s + i], ways[c][s]);\n\t\t\tseen_so_far++;\n\t\t\tsum_so_far += i;\n\t\t}\n\t}\n\t#ifdef LOCAL\n\tfor (int i = 0; i < nax; ++i)\n\t\tfor (int j = 0; j < nax * nax; ++j)\n\t\t\tif (ways[i][j])\n\t\t\t\tdebug << arr2(ways, i, j);\n\t#endif\n\tint ans = 1;\n\tbool whole = false;\n\tfor (int i = 1; i < nax; ++i) {\n\t\tfor (int l = ans + 1; l <= cou[i]; ++l) {\n\t\t\tdebug << imie(i) imie(l) arr2(ways, l, i * l) arr2(binom, cou[i], l);\n\t\t\tif (ways[l][i * l] == binom[cou[i]][l]) {\n\t\t\t\tdebug << \"match\";\n\t\t\t\tans = l;\n\t\t\t\tif (l == cou[i])\n\t\t\t\t\twhole = true;\n\t\t\t}\n\t\t}\n\t}\n\tif (whole && diff <= 2)\n\t\tans = n;\n\tprintf(\"%d\\n\", ans);\n}\n", "lang_cluster": "C++", "tags": ["math", "dp"], "code_uid": "1fa39187ffe3266657f47c2bc14f5818", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\n\n#define rep(i, a, b) for (auto i = (a); i < (b); ++i)\n#define per(i, a, b) for (auto i = (b); i-- > (a); )\n#define eb(x...) emplace_back(x)\n#define all(x) begin(x), end(x)\n#define rall(x) (x).rbegin(), (x).rend()\n#define sz(x) int((x).size())\n#define lb(x...) lower_bound(x)\n#define ub(x...) upper_bound(x)\n\ntemplate bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }\ntemplate bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }\ntemplate T gcd(T a, T b) { return b != T(0) ? gcd(b, a % b) : a; }\n\nconst int N = 1 << 18, M = 1 << 19, Q = 1 << 21, B = 20;\nstruct event { bool delt; int v; } E[Q];\n\nint delt[M]; pair edges[M];\n\nint n, m;\n\nint val[N], arr[N];\n\nint nxt[N + M], p[N + M][B];\nint head(int u) { return nxt[u] != u ? nxt[u] = head(nxt[u]) : u; }\nvoid join(int e) {\n\tauto [u, v] = edges[e];\n\tu = head(u); v = head(v);\n\tif (u == v) return;\n\tp[u][0] = p[v][0] = nxt[u] = nxt[v] = e + n;\n}\n\nvector g[N + M];\nint in[N + M], out[N + M], timer = 0;\nvoid dfs(int u) {\n\tin[u] = timer;\n\tif (u < n) arr[timer++] = val[u];\n\tfor (int v : g[u]) dfs(v);\n\tout[u] = timer;\n}\n\npair t[N << 1];\nvoid build(int v, int l, int r) {\n\tif (r - l == 1) return void(t[v] = {arr[l], l});\n\tint m = (l + r) >> 1;\n\tbuild(v << 1|0, l, m);\n\tbuild(v << 1|1, m, r);\n\tt[v] = max(t[v << 1], t[v << 1|1]);\n}\nint lo, hi, x;\npair find(int v, int l, int r) {\n\tif (hi <= l || r <= lo) return {-1, -1};\n\tif (lo <= l && r <= hi) return t[v];\n\tint m = (l + r) >> 1;\n\treturn max(find(v << 1, l, m), find(v << 1|1, m, r));\n}\nvoid clear(int v, int l, int r) {\n\tif (r - l == 1) return void(t[v] = {0, l});\n\tint m = (l + r) >> 1;\n\tif (x < m) clear(v << 1, l, m);\n\telse clear(v << 1|1, m, r);\n\tt[v] = max(t[v << 1], t[v << 1|1]);\n}\nint query(int l, int r) {\n\tlo = l, hi = r; auto p = find(1, 0, n);\n\tx = p.second; clear(1, 0, n);\n\treturn p.first;\n}\n\nsigned main() {\n\tios::sync_with_stdio(false);\n\tcin.tie(nullptr);\n\n\tint q; cin >> n >> m >> q;\n\tiota(nxt, nxt + n + m, 0);\n\tfill(delt, delt + m, -1);\n\n\trep(u, 0, n) cin >> val[u];\n\trep(e, 0, m) {\n\t\tint a, b; cin >> a >> b;\n\t\tedges[e] = {--a, --b};\n\t}\n\trep(z, 0, q) {\n\t\tint t, v; cin >> t >> v;\n\t\tE[z] = {bool(--t), --v};\n\t\tif (t) delt[v] = z;\n\t}\n\trep(e, 0, m) if (delt[e] < 0) delt[e] = q, E[q++] = {1, e};\n\n\tper(z, 0, q) if (E[z].delt) join(E[z].v);\n\n\trep(u, 0, n + m) {\n\t\tif (nxt[u] == u) p[u][0] = u;\n\t\tif (p[u][0] != u) g[p[u][0]].push_back(u);\n\t}\n\trep(j, 1, B) rep(u, 0, n + m) p[u][j] = p[p[u][j - 1]][j - 1];\n\n\trep(u, 0, n) {\n\t\tint rt = p[u][B - 1];\n\t\tif (!out[rt]) dfs(rt);\t\t\n\t}\n\t\n\tbuild(1, 0, n);\n\n\trep(z, 0, q) {\n\t\tif (E[z].delt) continue;\n\t\tint u = E[z].v;\n\t\tper(b, 0, B) if (n <= p[u][b] && z < delt[p[u][b] - n]) u = p[u][b];\n\t\tcout << query(in[u], out[u]) << '\\n';\n\t}\n}", "lang_cluster": "C++", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "ec10e48d13cbf6a35efbcf223bccf195", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n#define il inline\n#define re register\n#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)\n#define mem(k, p) memset(k, p, sizeof(k))\n#define int long long\n#define mod 1000000007\nil int read() {\n re int x = 0, f = 1; re char c = getchar();\n while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}\n while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();\n return x * f;\n}\n#define N 105\nil int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = r * a % mod; a = a * a % mod, b >>= 1; } return r; }\n#define K (1 << 15) + 5\nint n, m, a[N], du[N], vis[N], st[N], top, val[N], c[K], dp[N][K], fac[N], inv[N], pax[N], Ans = 1, cnt, tot;\nil int C(int a, int b) {\n\tif(a < b) return 0;\n\treturn fac[a] * inv[b] % mod * inv[a - b] % mod;\n}\nil void dfs(int x, int st) {\n\tif(pax[x]) return;\n\t++ tot, pax[x] = st;\n\trep(i, 1, n) if(a[x] % a[i] == 0 || a[i] % a[x] == 0) dfs(i, st);\n}\nsigned main() {\n\tn = read(), fac[0] = inv[0] = 1;\n\trep(i, 1, n) fac[i] = i * fac[i - 1] % mod, inv[i] = qpow(fac[i], mod - 2);\n\trep(i, 1, n) a[i] = read();\n\trep(i, 1, n) rep(j, 1, n) if(i != j && a[i] % a[j] == 0) ++ du[i];\n\trep(T, 1, n) {\n\t\tif(pax[T]) continue;\n\t\ttot = 0, dfs(T, T), mem(dp, 0), mem(c, 0), top = -1, mem(vis, 0);\n\t\trep(i, 1, n) if(pax[i] == T && du[i] == 0) vis[i] = 1, st[++ top] = a[i];\n\t\tif(tot - top <= 2) continue;\n\t\trep(i, 1, n) {\n\t\t\tif(vis[i] == 1 || pax[i] != T) continue;\n\t\t\trep(j, 0, top) if(a[i] % st[j] == 0) val[i] |= (1 << j);\n\t\t}\n\t\tint M = (1 << (top + 1)) - 1;\n\t\trep(i, 0, M) rep(j, 1, n) if(pax[j] == T && vis[j] == 0 && ((i & val[j]) == val[j])) ++ c[i];\n\t\trep(i, 1, n) if(vis[i] == 0 && pax[i] == T) ++ dp[1][val[i]];\n\t\trep(i, 1, tot - top - 2) {\n\t\t\trep(S, 0, M) {\n\t\t\t\tif(dp[i][S] == 0) continue;\n\t\t\t\tif(c[S] > i) dp[i + 1][S] = (dp[i + 1][S] + dp[i][S] * (c[S] - i)) % mod;\n\t\t\t\trep(j, 1, n) if(pax[j] == T && vis[j] == 0 && ((S & val[j]) != val[j]) && (S & val[j]))\n\t\t\t\t\tdp[i + 1][S | val[j]] = (dp[i + 1][S | val[j]] + dp[i][S]) % mod;\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\ttot = tot - top - 1;\n\t\trep(i, 0, M) ans = (ans + dp[tot][i]) % mod;\n\t\tAns = Ans * ans % mod * C(cnt + tot - 1, tot - 1) % mod;\n\t\tcnt += tot - 1;\n\t}\n\tcout << Ans;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "bitmasks"], "code_uid": "43a490bdc1864e995becf1b2ff843256", "src_uid": "c8d43a60ddc0a7b98a7269dc3a2478dc", "difficulty": 3500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n\t#include\n\t#include \n\t#include\n\t#include\n\t\n\tusing namespace std;\n\t\n\t#define ll long long\n\t#define D double\n\t#define ff first\n\t#define ss second\n\t#define FOR(a,n) for(i=0;i>a[i];}\n\t#define pb push_back\n\t#define INF 1000000000\n\t\n\tvector< vector > v;\n\tvector th(1010),ch(1010);\n\n\t bool isPrime(int n)\n\t\t{\n\t\t \n\t\t if (n <= 1) return false;\n\t\t if (n <= 3) return true;\n\t\t \n\t\t if (n%2 == 0 || n%3 == 0) \n\t\t \treturn false;\n\t\t \n\t\t for (int i=5; i*i<=n; i=i+6)\n\t\t {\n\t\t if (n%i == 0 || n%(i+2) == 0)\n\t\t return false;\n\t\t }\n\t\t \n\t\t return true;\n\t\t}\n\t\n\tvoid swap(char a,char b)\n\t{\n\t\tchar t;\n\t\tt=a;\n\t\ta=b;\n\t\tb=t;\n\t}\n\t\n\tll fact(ll n)\n\t{\n\t\tif(n<=1)\n\t\treturn 1;\n\t\telse\n\t\treturn n*fact(n-1);\n\t}\n\t\n\tll comb(ll n, ll k) \n{ \n ll res = 1; \n \n \n if ( k > n - k ) \n k = n - k; \n \n \n for (ll i = 0; i < k; ++i) \n { \n res *= (n - i); \n res /= (i + 1); \n } \n \n return res; \n} \n\t\n\tll GCD(ll a,ll b)\n\t{\n\t\tif(b==1)\n\t\treturn 1;\n\t\telse\n\t\treturn GCD(b,a%b);\n\t}\n\t\n\tll dig(ll n)\n\t{\n\t\tll c=0;\n\t\twhile(n>0)\n\t\t{\n\t\t\tll x=n%10;\n\t\t\tif(x!=0)\n\t\t\tc++;\n\t\t\tn=n/10;\n\t\t}\n\t\treturn c;\n\t}\n\t\n\tbool DFS(ll n)\n\t{\tbool ch[1010];\n\t\tstack s;\n\t\tll ans=0;\n\t\tch[n]=true;\n\t\ts.push(n);\n\t\tif(th[n]==true)\n\t\tans++;\n\t\twhile(s.size()>0)\n\t\t{\t\n\t\t\tll x=s.top();\n\t\t\ts.pop();\n\t\tcout<<\"X\";\n\t\t\tfor(ll i=0;i=2)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\t}\n\t\treturn true;\n\t\n\t}\n\t\n\t\tqueue q;\n\tvoid BFS(ll n)\n\t{\n\t\tll i,le[n+1];\n\t\tq.push(n);\n\t\tle[n]=0;\n\t\tch[n]=true;\n\t\t\n\t\twhile(q.size()>0)\n\t\t{\n\t\t\tll x=q.front();\n\t\t\tq.pop();\n\t\t\t\n\t\t\tfor(i=0;i0)\n\t\t{\n\t\t\tll x=k%10;\n\t\t\n\t\t\tc++;\n\t\t\tk=k/10;\n\t\t\t//cout<0)\n\t{\n\t\tll x=n%10;\n\t\tif(x>1)\n\t\treturn false;\n\t\tn/=10;\n\t}\n\treturn true;\n}\n\n\tint main()\n\t{\n\t\tll n,k;\n\t\tcin>>n;\n\t\tll y=n;\n\t ll c=k=count(n);\n\t string s=\"\";\n\t while(c>0)\n\t {\n\t s=s+'1';\n\t c--;\n\t }\n\t string t=to_string(n);\n\t // cout<n)\n\t {s[i]='0';\n\t // cout<0)\n\t\t{\n\t\t\tll x=n%10;\n\t\t\tans+=x*pow(2,i);\n\t\t\ti++;\n\t\t\tn/=10;\n\t\t}\n\t\tcout<\n#define dbg() cerr <<\n#define name(x) (#x) << \": \" << (x) << ' ' <<\n\nusing namespace std;\n\nint MOD;\n\nint add(int a, int b) {\n a += b;\n while (a < 0) a += MOD;\n while (a >= MOD) a -= MOD;\n return a;\n}\n\nvoid Add(int &a, int b) {\n a = add(a, b);\n}\n\nint Mul(int a, int b) {\n return 1LL * a * b % MOD;\n}\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n int n, k; cin >> n >> k >> MOD; \n\n vector pw10(n + 1);\n pw10[0] = 1;\n for (int i = 1; i <= n; ++i) {\n pw10[i] = Mul(pw10[i - 1], 10);\n }\n\n vector> dp(k,\n vector(2));\n \n // dp[r][dif_0]\n\n dp[0][0] = 1;\n\n int pw = 1;\n int ans = 0;\n for (int i = 0; i <= n; ++i) {\n vector> nxt(k, \n vector(2));\n\n if (i < n)\n Add(ans, Mul(Mul(pw10[n - i - 1], 9), dp[0][1]));\n else\n Add(ans, dp[0][1]);\n dp[0][1] = 0;\n for (int r = 0; r < k; ++r) {\n// dbg() name(i) name(r) \"\";\n// dbg() name(dp[r][0]) name(dp[r][1]) endl;\n\n for (int c = (i == n - 1); c < 10 && i < n; ++c) {\n int nr = (r + c * pw) % k;\n for (int dif_0 = 0; dif_0 < 2; ++dif_0) {\n int ndif = dif_0 || (c != 0);\n Add(nxt[nr][ndif], dp[r][dif_0]);\n }\n }\n }\n if (i < n)\n dp = move(nxt);\n pw = pw * 10 % k;\n }\n\n cout << ans << endl;\n}\n", "lang_cluster": "C++", "tags": ["dp", "implementation"], "code_uid": "e2209b128538acc23ffd9e784f41f3d6", "src_uid": "656bf8df1e79499aa2ab2c28712851f0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define MP(a, b) make_pair(a, b)\n\nint n;\n\nint gcd(int a, int b) {\n while (b) b ^= a ^= b ^= a %= b;\n return a;\n}\n\nconst int INF = 1000000000;\n\n\nvector c;\nvector > g;\nvector rm;\nint comp[4][4];\nvector roots;\n\n\nint main() {\n\n#ifndef ONLINE_JUDGE \n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#endif\n\n cin >> n;\n rm.resize(n, 0);\n c.resize(n);\n g.resize(n);\n vector anss;\n\n comp[1][1] = comp[2][2] = comp[3][3] = 0;\n comp[1][2] = 1;\n comp[1][3] = 2;\n comp[2][3] = 1;\n comp[3][2] = 2;\n comp[2][1] = 2;\n comp[3][1] = 1;\n\n for (int i = 0; i < n; i++) cin >> c[i];\n\n for (int i = 0; i < n; i++) {\n int k; cin >> k;\n for (int j = 0; j < k; j++) {\n int u; cin >> u;\n g[i].push_back(u - 1);\n }\n }\n\n for (int i = 0; i < n; i++) if (g[i].size() == 0) roots.push_back(i); \n\n int final_ans = INF;\n\n for (int q = 0; q < roots.size(); q++) {\n\n int curc = c[roots[q]];\n rm[roots[q]] = 1;\n int movec = 0;\n int ans = 1;\n\n for (int i = 0; i < n; i++) { \n bool check = false;\n for (int p = 0, movec = curc - 1; p < 3; p++, movec += 1, movec %= 3) {\n for (int j = 0; j < n; j++) {\n if (rm[j] || c[j] != movec + 1) continue;\n\n check = true;\n for (int k = 0; k < g[j].size(); k++) {\n if (!rm[g[j][k]])\n check = false;\n }\n if (check) {\n rm[j] = 1;\n ans += comp[curc][movec + 1] + 1;\n curc = movec + 1;\n break;\n }\n }\n\n if (check) break;\n }\n }\n\n\n int check = 1;\n for (int i = 0; i < n; i++) check &= rm[i];\n rm.assign(n, 0);\n if (check) final_ans = min(final_ans, ans);\n }\n\n cout << final_ans;\n}", "lang_cluster": "C++", "tags": ["brute force", "greedy"], "code_uid": "8a5d20ec4f40fbb688e2f89297925412", "src_uid": "be42e213ff43e303e475d77a9560367f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\n\n#define ll long long int\n#define pb push_back\n#define f(i,x,y) for(i=x;i\n#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n#define yes cout<<\"YES\"<>n>>t;\n \n vll level(55,0);\n c=0;\n l=1;\n f(i,1,11)\n {\n f(j,0,i)\n {\n level[c]=l;\n c++;\n }\n l++;\n }\n vector g(55,0);\n \n while(t--)\n {\n queue> q;\n q.push({0,1.0});\n while(q.empty()==0)\n {\n pair p=q.front();\n q.pop();\n \n if(p.first>=n*(n+1)/2)\n continue;\n if(g[p.first]!=1)\n {\n g[p.first]+=p.second;\n }\n else\n {\n q.push({p.first+level[p.first],p.second/2.0});\n q.push({p.first+level[p.first]+1,p.second/2.0});\n }\n }\n /*f(i,0,55)\n {\n cout<>t;\n while(t--)\n solve();\n return 0;\n}", "lang_cluster": "C++", "tags": ["math", "implementation"], "code_uid": "2e3e0c256022dd2ca091b13792fee630", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nusing ll = long long;\nconst int N = 55;\nll n,ans,pw[N],f[N][N * 2][2];int m,p;\nll sub(ll a,ll b) {return a >= b ? a - b : a;}\nll calc(ll s,ll q,int a,int b,int t)\n{\n memset(f[p],0,sizeof(f[p]));f[p][0][0] = 1;\n for (int i = 1;i <= log2(s) + 1;i++)\n {\n int d = (s >> i) & 1;p ^= 1;memset(f[p],0,sizeof(f[p]));\n for (int j = 0;j <= i * 2 - 2;j++)\n for (int k = 0;k < 2;k++)\n if (f[p ^ 1][j][k])\n for (int x = 0;x < 2;x++) if (!x || i < a)\n for (int y = 0;y < 2;y++) if (!y || i < b)\n if ((k + x + y) % 2 == d)\n f[p][j + x + y][(k + x + y) / 2] += f[p ^ 1][j][k];\n }\n return f[p][t][0];\n}\nint main ()\n{\n ios::sync_with_stdio(false);\n cin >> n;pw[0] = 1;ll x,ret;\n while (!m || pw[m - 1] <= n) pw[m + 1] = pw[m] << 1,++m;\n --m;\n for (int i = 1;i <= m;i++)\n if ((x = n / (pw[i] - 1)) > 0)\n {\n ret = n - x * (pw[i] - 1);\n for (int j = i - 1;j >= 0;--j) if (ret >= pw[j] - 1) ret = ret - (pw[j] - 1);\n if (!ret) ++ans;\n } \n for (int i = 1;i <= m;i++)\n for (int j = 1;pw[j] - 1 <= n;j++)\n if ((x = (n - pw[j] + 1) / (pw[i + 1] + pw[j + 1] - 3)) > 0)\n {\n ret = (n - pw[j] + 1) - x * (pw[i + 1] + pw[j + 1] - 3);\n if (!ret) {++ans;continue;}\n if (i == 1 && j == 1) {ans += (ret == 5 * x + 1);continue;}\n for (int k = 1;k <= i + j;k++)\n if (~(ret + k) & 1) ans += calc(ret + k,x,i,j,k);\n }\n cout << ans << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "dp", "combinatorics", "bitmasks"], "code_uid": "eade85c7840280414ec49d6a83a7b3df", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include;\nusing namespace std ;\nint main ()\n{\n int h,m,ans=0;\n char x;\n cin>>h>>x>>m;\n //while((h*10!=m)&&(h==10&&m==1)&&(h==11&&m==11)&&(h==10&&m==1))\n if(h==0)\n {\n if(m==0)cout<<0<10)cout<<(60-m)+20<10 ? (60-m)+20 : 10-m<20)cout<<(60-m)+30<20 ? (60-m)+30 : 20-m<30)cout<<(60-m)+40<30 ? (60-m)+40 : 30-m<40)cout<<(60-m)+50<40 ? (60-m)+50 : 40-m<50)cout<<(60-m)+241<50 ? (60-m)+241 : 50-m<1)cout<<(60-m)+11<1 ? (60-m)+11 : 1-m<11)cout<<(60-m)+21<11 ? (60-m)+21 : 11-m<21)cout<<(60-m)+31<21 ? (60-m)+31 : 21-m<31)cout<<(60-m)+41<31 ? (60-m)+41 : 31-m<41)cout<<(60-m)+51<41 ? (60-m)+51 : 41-m<51)cout<<(60-m)+(60*(19-h)+2)<51 ? (60-m)+(8*60) : 51-m<2)cout<<(60-m)+12<12)cout<<(60-m)+22<22)cout<<(60-m)+32<32)cout<<60-m<\n#include \n#include \n#define ll long long\n\nusing namespace std;\n\nll C(ll n,ll m){\n\tll ans=1;\n\tfor(ll i=n;i>=n-m+1;i--)\n\t\tans*=i;\n\tfor(ll i=1;i<=m;i++)\n\t\tans/=i;\n\treturn ans;\n}\n\nint main(){\n\tll n, k;\n\t//scanf (\"%lld%lld\", &n, &k);\n\tcin >> n >> k;\n\tif (k == 1)\n\t\tcout << \"1\";\n\telse if (k == 2)\n\t\tcout << 1 + C(n, 2);\n\telse if (k == 3)\n\t\tcout << 1 + C(n, 2) + C(n, 3) * 2;\n\telse{\n\t\tll x = 1 + C(n, 2) + C(n, 3) * 2 + C(n, 4) * 9;\n\t\tcout << x;\n\t}\t\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "combinatorics"], "code_uid": "4a562b7be313be6b9752c2440e492abe", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\n#define ms(s, n) memset(s, n, sizeof(s))\n#define FOR(i, a, b) for (int i = (a); i < (b); i++)\n#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)\n#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)\n#define sz(a) int((a).size())\n#define present(t, x) (t.find(x) != t.end())\n#define all(a) (a).begin(), (a).end()\n#define uni(a) (a).erase(unique(all(a)), (a).end())\n#define pb push_back\n#define pf push_front\n#define mp make_pair\n#define fi first\n#define se second\n#define prec(n) fixed<> (i)) & 1)\n#define bitcount(n) __builtin_popcountll(n)\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\ntypedef pair pi;\ntypedef vector vi;\ntypedef vector vii;\nconst int MOD = (int) 1e9 + 7;\nconst int INF = (int) 1e9;\nconst ll LINF = (ll) 1e18;\nconst ld PI = acos((ld) -1);\nconst ld EPS = 1e-9;\ninline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}\ninline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}\ninline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}\ntemplate inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}\ntemplate inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}\ninline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}\ninline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}\ninline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}\ninline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}\ninline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}\ninline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}\n\nstruct Num {\n\tint a, b;\n\tNum() : a(0), b(0) {}\n\tNum(int a, int b) : a(a), b(b) {}\n\tNum(const Num& rhs) : a(rhs.a), b(rhs.b) {}\n\tNum operator + (const Num& rhs) const {\n\t\tNum res;\n\t\tres.a = a + rhs.a;\n\t\tif (res.a >= MOD) res.a -= MOD;\n\t\tres.b = b + rhs.b;\n\t\tif (res.b >= MOD) res.b -= MOD;\n\t\treturn res;\n\t}\n\tNum operator - (const Num& rhs) const {\n\t\tNum res;\n\t\tres.a = a - rhs.a;\n\t\tif (res.a < 0) res.a += MOD;\n\t\tres.b = b - rhs.b;\n\t\tif (res.b < 0) res.b += MOD;\n\t\treturn res;\n\t}\n\tNum operator * (const Num& rhs) const {\n\t\tNum res;\n\t\tres.a = ((long long) a * rhs.a + (long long) 5 * b * rhs.b) % MOD;\n\t\tres.b = ((long long) a * rhs.b + (long long) b * rhs.a) % MOD;\n\t\treturn res;\n\t}\n\tNum operator ^ (long long k) {\n\t\tif (!k) return Num(1, 0);\n\t\tNum tmp = Num(a, b), res = Num(a, b); k--;\n\t\twhile (k) {\n\t\t\tif (k & 1) res = res * tmp;\n\t\t\ttmp = tmp * tmp;\n\t\t\tk >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tfriend Num geometricseries(Num a, long long k) {\n\t\tif (!k) return Num(1, 0);\n\t\tif (k == 1) return a;\n\t\tvector bit;\n\t\twhile (k) {\n\t\t\tbit.push_back(k & 1);\n\t\t\tk >>= 1;\n\t\t}\n\t\tNum res = a, tmp = a;\n\t\tfor (int i = bit.size() - 2; i >= 0; i--) {\n\t\t\tres = res + (res * tmp);\n\t\t\ttmp = tmp * tmp;\n\t\t\tif (bit[i] & 1) {\n\t\t\t\ttmp = tmp * a;\n\t\t\t\tres = res + tmp;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n};\n\nconst int maxk = 200 + 10;\nint k;\nlong long l, r;\nint c[maxk][maxk];\nint s[maxk][maxk];\nint fac[maxk];\nNum n1[maxk];\nNum n2[maxk];\n\nint calc(long long x) {\n\tint res = 0;\n\tFOR(i, 1, k + 1) {\n\t\tFOR(j, 0, i + 1) {\n\t\t\tNum tmp = n1[j] * n2[i - j];\n\t\t\ttmp = geometricseries(tmp, x);\n\t\t\tif ((i - j) & 1) {\n\t\t\t\ttmp.a = (MOD - tmp.a) % MOD;\n\t\t\t\ttmp.b = (MOD - tmp.b) % MOD;\n\t\t\t}\n\t\t\ttmp = tmp * Num(c[j][i], 0);\n\t\t\tif (i & 1) {\n\t\t\t\taddmod(res, mult(s[k][i], mult(tmp.b, inv(fpow(5, i >> 1)))));\n\t\t\t}\n\t\t\telse {\n\t\t\t\taddmod(res, mult(s[k][i], mult(tmp.a, inv(fpow(5, i >> 1)))));\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid solve() {\n\tFOR(i, 0, maxk) c[0][i] = 1;\n\tFOR(i, 1, maxk) FOR(j, 1, maxk) c[i][j] = (c[i][j - 1] + c[i - 1][j - 1]) % MOD;\n\ts[0][0] = 1;\n\tFOR(i, 1, maxk) FOR(j, 1, maxk) {\n\t\tsubmod(s[i][j], mult(i - 1, s[i - 1][j]));\n\t\taddmod(s[i][j], s[i - 1][j - 1]);\n\t}\n\tfac[0] = 1; FOR(i, 1, maxk) fac[i] = mult(fac[i - 1], i);\n\tn1[0] = n2[0] = Num(1, 0);\n\tn1[1] = Num(inv(2), inv(2)), n2[1] = Num(inv(2), MOD - inv(2));\n\tFOR(i, 1, maxk) n1[i] = n1[i - 1] * n1[1], n2[i] = n2[i - 1] * n2[1];\n\tcin >> k >> l >> r;\n\tint ans = calc(r + 2);\n\tsubmod(ans, calc(l + 1));\n\tans = mult(ans, inv(fac[k]));\n\tcout << ans << \"\\n\";\n}\n\nint main() {\n\tios_base::sync_with_stdio(0); cin.tie(0);\n#ifdef _LOCAL_\n\tfreopen(\"in.txt\", \"r\", stdin); //freopen(\"out.txt\", \"w\", stdout);\n#endif\n\tsolve();\n#ifdef _LOCAL_\n\t//printf(\"\\nTime elapsed: %dms\", 1000 * clock() / CLOCKS_PER_SEC);\n#endif\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "d918c1a10627400b01a2116a39d512ae", "src_uid": "dee552588e1281c2523868cd4090b46f", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nint n,minn=0x3f3f3f3f,a[12];\nint main() {\n\tcin>>n;\n\tfor (int i=1;i<=n;i++) {\n\t\tcin>>a[i];\n\t\tminn=min(minn,a[i]);\n\t}\n\tcout<<(minn^a[3])+2<\n#include \n#include \nusing namespace std;\n\nconst int N=20100;\nint b[N], c[N], x, y, z, n;\n\nint main()\n{\n int i, j, l;\n while(scanf(\"%d%d%d%d\", &n, &x, &y, &z)!=EOF)\n {\n if(x+y*2+z*4 < n)\n {\n printf(\"0\\n\");\n break;\n }\n n *= 2;\n for(i=0; i<=x; i++)\n b[i] = 1;\n for( ; i\n#include\n#include\n#include\n#include\n#define p 1e6+7\n#define N 10010\n#define mc(a,b) memset(a,b,sizeof(a))\n#define close std::ios::sync_with_stdio\nusing namespace std;\nusing namespace std;\nconst double eps(1e-8);\ntypedef long long lint;\nconst lint mod = 1000000007LL;\nint n, m, g;\nlint fac[200010];\nvoid init()\n{\n fac[0] = fac[1] = 1;\n for(int i = 2; i <= 200000; i++)\n fac[i] = fac[i - 1] * i % mod;\n return;\n}\n \nlint quick_pow(lint base, lint pow)\n{\n lint ret = 1;\n while(pow)\n {\n if(pow & 1)\n ret = (ret * base) % mod;\n base = base * base % mod;\n pow >>= 1;\n }\n return ret;\n}\n \nlint C(int r, int k)//C[r][k]\n{\n return fac[r]*quick_pow(fac[k]*fac[r - k] % mod, mod - 2LL) % mod;\n}\n \nint main()\n{\n scanf(\"%d %d %d\", &n, &m, &g);\n if(n == 0)\n {\n if(g == 0)\n {\n if(m == 1)\n printf(\"0\\n\");\n else\n printf(\"1\\n\");\n }\n else\n {\n if(m == 1)\n printf(\"1\\n\");\n else\n printf(\"0\\n\");\n }\n return 0;\n }\n if(m == 0)\n {\n if(g == 0)\n {\n if(n & 1)\n printf(\"1\\n\");\n else\n printf(\"0\\n\");\n }\n else\n {\n if(n & 1)\n printf(\"0\\n\");\n else\n printf(\"1\\n\");\n }\n return 0;\n }\n init();\n lint all = C(n + m, n);\n lint ans = 0;\n for(int t = 0; t <= n; t += 2)\n ans = (ans + C(n + m - 1 - t, m - 1)) % mod;\n if(m == 1 && (n & 1) == 0)\n ans = (ans - 1 + mod) % mod;\n if(m == 1 && (n & 1))\n ans = (ans + 1) % mod;\n if(g == 0)\n printf(\"%I64d\\n\", ans);\n else\n printf(\"%I64d\\n\", (all - ans + mod) % mod);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "combinatorics", "number theory"], "code_uid": "0b2e437f5a2e37686217c01e1e324067", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \nusing namespace std;\n\nint main()\n{\n int N;\n scanf(\"%d\",&N);\n int ans=floor(log2(1.0*N)),res=N-(1<\n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nchar c[10],d[10];\ntypedef long long ll;\n\nll cton(char ch) {\n if(ch >= '0' && ch <= '9') return ch-'0';\n return ch-'A'+10;\n}\n\nll to_number(string s, ll base) {\n ll res = 0;\n ll pw = 1;\n for(int i = s.length()-1; i >= 0; --i) {\n int c = cton(s[i]);\n if(c >= base) return -1;\n res += c*pw;\n pw *= base;\n }\n return res;\n}\n\nint main() {\n string in, a, b;\n cin >> in;\n int j = 0;\n for(int i = 0; i < in.length(); ++i)\n if(in[i] == ':') j = i;\n a = in.substr(0, j), b = in.substr(j+1, in.length());\n vector out;\n for(int i = 2; i < 100; ++i) {\n ll x = to_number(a, i), y = to_number(b, i);\n if(x != -1 && y != -1 && x < 24 && y < 60) out.push_back(i);\n }\n if(out.size()) {\n if(out.back() > 60) printf(\"-1\");\n else for(int i = 0; i < out.size(); ++i) printf(\"%d \", out[i]);\n } else printf(\"0\");\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "7dd70d6bf6e41ccca746acd51ee942f7", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nconst long long maxn=55;\nconst long long mod=10000007;\nlong long n,t,len,a[maxn],f[maxn][maxn];\nvoid get(long long x,bool pa){\n\tlen=0;\n\twhile(x){\n\t\tif(pa)a[len+1]=x%2;\n\t\tx>>=1;\n\t\tlen++;\n\t}\n}\nlong long dp(long long pos,long long num,long long ask,bool limit){\n\tif(pos==0)return num==ask;\n\tif(f[pos][num]!=-1&&!limit)return f[pos][num];\n\tlong long up=limit?a[pos]:1;\n\tlong long ans=0;\n\tfor(long long i=0;i<=up;i++){\n\t\tans+=dp(pos-1,num+i,ask,(limit&&(i==up)));\n\t}\n\treturn limit?ans:f[pos][num]=ans;\n}\nlong long fsm(long long a,long long b){\n\tlong long res=1;\n\twhile(b){\n\t\tif(b&1)res=res*a%mod;\n\t\ta=a*a%mod;\n\t\tb>>=1;\n\t}\n\treturn res%mod;\n}\nint main(){\n\t//freopen(\"test.cpp\",\"r\",stdin);\n\tcin>>n>>t;\n\tn++;\n\tget(n,1);\n\tif(t-(t&(-t))!=0){\n\t\tputs(\"0\");\n\t\treturn 0;\n\t}\n\tmemset(f,-1,sizeof f);\n\tlong long ans=dp(len,0,log2(t)+1,1);\n\tif(t==1)ans--;\n\t//for(long long i=1;i<=len;i++){\n\t//\tmemset(f,-1,sizeof f);\n\t//\tans*=fsm(i,dp(len,0,i,1));\n\t//\tans%=mod;\n\t//}\n\tcout<\n\nusing namespace std;\n\nconst int MaxN = 2e3 + 23;\n\nconst int MOD = 998244353;\n\nint pless, pgreater;\nint CP[MaxN][MaxN];\nint STRONG[MaxN];\nint ans[MaxN];\n\nint bpow(int a, int b)\n{\n if(!b)\n return 1;\n int res = bpow(a, b >> 1);\n res = (res * 1ll * res) % MOD;\n if(b & 1)\n res = (res * 1ll * a) % MOD;\n return res;\n}\n\nvoid calcCP(int n, int s)\n{\n if(!s)\n CP[n][s] = 1;\n else\n {\n CP[n][s] = (CP[n - 1][s - 1] * 1ll * bpow(pgreater, n - s)) % MOD + (CP[n - 1][s] * 1ll * bpow(pless, s)) % MOD;\n if(CP[n][s] >= MOD)\n CP[n][s] -= MOD;\n }\n}\n\nvoid calcStrong(int n)\n{\n STRONG[n] = 1;\n if(n > 1)\n {\n for(int i = 1; i < n; ++i)\n {\n STRONG[n] -= (STRONG[i] * 1ll * CP[n][i]) % MOD;\n if(STRONG[n] < 0)\n STRONG[n] += MOD;\n }\n }\n}\n\nvoid calcAns(int n)\n{\n if(n < 2)\n ans[n] = 0;\n else\n {\n for(int i = 1; i <= n; ++i)\n {\n ans[n] += STRONG[i] * 1ll * CP[n][i] % MOD * 1ll * (i * (n - i) + (i * (i - 1)) / 2 + (long long) (i < n ? ans[i] : 0) + ans[n - i]) % MOD;\n if(ans[n] >= MOD)\n ans[n] -= MOD;\n }\n int coef = 1 - (STRONG[n] * 1ll * CP[n][n]) % MOD;\n\n if(coef < 0)\n coef += MOD;\n\n ans[n] = (ans[n] * 1ll * bpow(coef, MOD - 2)) % MOD;\n }\n}\n\nmain()\n{\n// freopen(\"input.txt\", \"r\", stdin);\n ios_base :: sync_with_stdio(false);\n cin.tie(NULL);\n\n int n, a, b;\n cin >> n >> a >> b;\n\n pless = (a * 1ll * bpow(b, MOD - 2)) % MOD;\n pgreater = ((b - a) * 1ll * bpow(b, MOD - 2)) % MOD;\n\n for(int i = 0; i <= n; ++i)\n for(int j = 0; j <= i; ++j)\n calcCP(i, j);\n\n for(int i = 0; i <= n; ++i)\n calcStrong(i);\n\n for(int i = 0; i <= n; ++i)\n calcAns(i);\n\n cout << ans[n] << '\\n';\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "probabilities", "graphs"], "code_uid": "e96cac66ca28473ae8a4ddc00d4f83c1", "src_uid": "67e599530203060c17f692f2624d0f99", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define inf 1000000000\n\ntypedef vector vint;\ntypedef pair pii;\n\n///******************///\n\nint a[10]={}, b[10]={}, org[10]={};\nchar res1[200000]={}, res2[200000]={};\n\nint main()\n{\n char c;\n while (cin >> c) ++a[c-'0'];\n int l=0;\n for (int i=0; i<10; ++i) b[i]=a[i], l+=a[i], org[i]=a[i];\n\n int m_first, m_zeros, MAX=0;\n\n ++a[0], ++b[0];\n for (int z=0; a[0]>=0; ++z) {\n --a[0];\n --b[0];\n for (int i=5; i<10; ++i) {\n --a[i], --b[10-i];\n int cur = 1;\n if (a[i]>=0 && b[10-i]>=0) {\n cur += min(a[9], b[0]);\n cur += min(a[8], b[1]);\n cur += min(a[7], b[2]);\n cur += min(a[6], b[3]);\n cur += min(a[5], b[4]);\n cur += min(a[4], b[5]);\n cur += min(a[3], b[6]);\n cur += min(a[2], b[7]);\n cur += min(a[1], b[8]);\n cur += min(a[0], b[9]);\n if (cur+z>MAX) {\n MAX=cur+z;\n m_first=i;\n m_zeros=z;\n }\n }\n ++a[i], ++b[10-i];\n }\n }\n\n\n\n/// cout << MAX << \" \" << m_first;\n if (MAX==0 && org[0]>0) {\n for (int i=1; i<10; ++i) for (int j=0; j0; ++j) --cur_pos, res1[cur_pos]=i+'0', res2[cur_pos]=9-i+'0', --a[i], --b[9-i];\n /*for (int i=0; i<10; ++i) {\n for (int j=0; j\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n\n#include \n\n\nvoid re(int& x);\n\n\ntemplate void re(T& t, Ts&... ts);\n\n\nvoid pr(int x);\n\n\nvoid pr(const char *x);\n\n\nvoid ps();\ntemplate void ps(const T& t, const Ts&... ts);\n\n\n#define rep(i, a, b) for(int i = a; i < (b); ++i)\n\n\nint n, p;\nint c[51];\nint dp[51][51][51];\nint binom[61][61];\nint p2[51];\nconst int mod = 1000000007;\n\nint rec(int cur, int bp, int wp) {\n if (cur == n) return (bp+wp)%2 == p;\n \n int &ret = dp[cur][bp][wp];\n if (ret == -1) {\n ret = 0;\n\n for (int cc = 0; cc <= 1; cc++) {\n if (c[cur] != -1 && c[cur] != cc) continue;\n \n int od;\n if (cc == 0) od = wp;\n else od = bp;\n int ev = cur - od;\n\n for (int con_od = 0; con_od <= od; con_od++) {\n int nbp = bp, nwp = wp;\n if (con_od % 2 == 0) {\n if (cc == 0) nbp++;\n else nwp++;\n }\n\n long long th = (rec(cur+1, nbp, nwp) * 1ll * p2[ev]) % mod;\n th = (th * 1ll * binom[od][con_od]) % mod;\n ret = (ret + th) % mod;\n }\n }\n\n //printf(\"%d %d %d -> %d\\n\", cur,bp,wp,ret);\n }\n return ret;\n}\n\nvoid solve()\n{\n memset(dp,-1,sizeof(dp));\n re(n,p);\n rep(i,0,n) re(c[i]);\n\n p2[0] = 1;\n for (int i = 1; i <= 50; i++) p2[i] = (p2[i-1] + p2[i-1]) % mod;\n\n for (int i = 0; i <= 60; i++) {\n for (int j = 0; j <= i; j++) {\n if (j == 0) binom[i][j] = 1;\n else binom[i][j] = (binom[i-1][j-1] + binom[i-1][j]) % mod;\n }\n }\n\n ps(rec(0,0,0));\n}\n\n\nint main() {\n\n\n solve();\n}\n\n\nvoid re(int& x) { scanf(\"%d\", &x); }\n\n\ntemplate void re(T& t, Ts&... ts) { \n re(t); re(ts...); \n}\n\n\nvoid pr(int x) { printf(\"%d\", x); }\n\n\nvoid pr(const char *x) { printf(\"%s\", x); }\n\n\nvoid ps() { pr(\"\\n\"); }\ntemplate void ps(const T& t, const Ts&... ts) { \n pr(t); if (sizeof...(ts)) pr(\" \"); ps(ts...); \n}\n\n\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "6078309ac5d7634905fd7bd257f55e36", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define endl '\\n'\n\n//#pragma GCC optimize (\"O3\")\n//#pragma GCC target (\"sse4\")\n\nusing namespace std;\ntemplate inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }\ntemplate inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }\nconst int MAXN = (1 << 20);\nconst int MAXM = 500;\nconst int bound = (int)1e6;\nconst int MAGIC = 24;\n\nint lp[MAXN];\nvector pr;\nset > st;\n\nvoid prepare()\n{\n\tfor(int i = 2; i <= bound; i++)\n\t{\n\t\tif(lp[i] == 0) lp[i] = i, pr.push_back(i);\n\t\tfor(int j = 0; j < (int)pr.size() && i * 1ll * pr[j] <= bound && pr[j] <= lp[i]; j++)\n\t\t\tlp[i * pr[j]] = pr[j];\n\t}\n}\n\nvector > li;\n\nvector get(int i)\n{\n\tint x = i;\n\tvector curr;\n\twhile(x != 1)\n\t{\n\t\tint d = lp[x], cnt = 0;\n\t\twhile(x % d == 0) x /= d, cnt++; \n\t\tcurr.push_back(cnt);\n\t}\n\n\tsort(curr.begin(), curr.end());\n\treturn curr;\n}\n\nvoid read()\n{\n\tfor(int i = 1; i <= bound; i++)\n\t{\n\t\tint x = i;\n\t\tvector curr;\n\t\twhile(x != 1)\n\t\t{\n\t\t\tint d = lp[x], cnt = 0;\n\t\t\twhile(x % d == 0) x /= d, cnt++; \n\t\t\tcurr.push_back(cnt);\n\t\t}\n\n\t\tsort(curr.begin(), curr.end());\n\t\tst.insert(curr);\n\t}\n\n\tfor(auto it: st) li.push_back(it);\n}\n\nint N, K;\nint dp[MAXM][1 << 16];\n\nint get_id(const vector > &li, vector p)\n{\n\treturn lower_bound(li.begin(), li.end(), p) - li.begin();\n}\n\nvector > same;\n\nvector > all_vec;\nvector curr_Vec;\n\nvoid gen(int sum, int last = 1)\n{\n\tall_vec.push_back(curr_Vec);\n\tif(sum == 0) return;\n\n\tfor(int curr = last; curr <= sum; curr++)\n\t{\n\t\tcurr_Vec.push_back(curr);\n\t\tgen(sum - curr, curr);\n\t\tcurr_Vec.pop_back();\n\t}\n}\n\nint dist[MAXN];\nvector adj[MAXN];\nvector possible_divs;\n\nint divs(vector &l)\n{\n\tint r = 1;\n\tfor(int i: l)\n\t\tr *= (i + 1);\n\treturn r;\n}\n\nint get_pos(int x) { return lower_bound(possible_divs.begin(), possible_divs.end(), x) - possible_divs.begin(); }\n\nint D[MAXN];\n\nvoid solve()\n{\n\tgen(MAGIC);\n\tN = li.size();\n\tK = all_vec.size();\n\n\tfor(int i = 0; i < K; i++)\n\t{\n\t\tfor(int p = 0; p < (int)all_vec[i].size(); p++)\n\t\t{\n\t\t\t{\n\t\t\t\tvector nw = all_vec[i];\n\t\t\t\tnw[p]--;\n\n\t\t\t\tsort(nw.begin(), nw.end());\n\t\t\t\tif(*nw.begin() == 0)\n\t\t\t\t\tnw.erase(nw.begin());\n\n\t\t\t\tint id = get_id(all_vec, nw);\n\t\t\t\tif(id != K && all_vec[id] == nw)\n\t\t\t\t{\n\t\t\t\t\tadj[i].push_back(id);\n\t\t\t\t\tadj[id].push_back(i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tvector nw = all_vec[i];\n\t\t\t\tnw[p]++;\n\t\t\t\tsort(nw.begin(), nw.end());\n\n\t\t\t\tint id = get_id(all_vec, nw);\n\t\t\t\tif(id != K && all_vec[id] == nw)\n\t\t\t\t{\n\t\t\t\t\tadj[i].push_back(id);\n\t\t\t\t\tadj[id].push_back(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tvector nw = all_vec[i];\n\t\t\tnw.push_back(1);\n\t\t\tsort(nw.begin(), nw.end());\n\n\t\t\tint id = get_id(all_vec, nw);\n\t\t\tif(id != K && all_vec[id] == nw)\n\t\t\t{\n\t\t\t\tadj[i].push_back(id);\n\t\t\t\tadj[id].push_back(i);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor(int i = 0; i < K; i++)\n\t\tpossible_divs.push_back(divs(all_vec[i]));\n\n\tsort(possible_divs.begin(), possible_divs.end());\n\tpossible_divs.erase(unique(possible_divs.begin(), possible_divs.end()), possible_divs.end());\n\n\tfor(int i = 0; i < K; i++)\n\t\tD[i] = get_pos(divs(all_vec[i]));\n\n\tfor(int ii = 0; ii < N; ii++)\n\t{\n\t\tint root = get_id(all_vec, li[ii]);\n\t\tfor(int i = 0; i < K; i++)\n\t\t\tdist[i] = -1;\n\n\t\tqueue q;\n\t\tq.push(root);\n\t\tdist[root] = 0;\n\n\t\twhile(!q.empty())\n\t\t{\n\t\t\tint u = q.front();\n\t\t\tq.pop();\n\n\t\t\tfor(int v: adj[u])\n\t\t\t\tif(dist[v] == -1)\n\t\t\t\t{\n\t\t\t\t\tdist[v] = dist[u] + 1;\n\t\t\t\t\tq.push(v);\n\t\t\t\t}\n\t\t}\n\n\t\tfor(int iii = 0; iii < (int)possible_divs.size(); iii++) dp[ii][iii] = MAXN;\n\t\tfor(int j = 0; j < K; j++)\n\t\t\tchkmin(dp[ii][D[j]], dist[j]);\n\t}\n\n\tint t;\n\tcin >> t;\n\n\twhile(t--)\n\t{\n\t\tint a, b;\n\t\tcin >> a >> b;\n\t\tvector A = get(a), B = get(b);\n\n\t\ta = lower_bound(li.begin(), li.end(), A) - li.begin();\n\t\tb = lower_bound(li.begin(), li.end(), B) - li.begin();\n\n\t\tint answer = MAXN;\n\t\tfor(int i = 0; i < (int)possible_divs.size(); i++)\n\t\t\tchkmin(answer, dp[a][i] + dp[b][i]);\n\n\t\tcout << answer << endl;\n\t}\n}\n\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\n\tprepare();\n\n\tread();\n\tsolve();\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "math", "graphs"], "code_uid": "cf5377d30e2dc46df302e9fa9bfa9787", "src_uid": "6115ee1ccf651b1dd8145bf755ea7ea9", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define len(x) ((int)(x).size())\n#define x first\n#define y second\nusing namespace std;\n\nconst int K = 1010, MOD = 1e9 + 7;\n\nint powmod(int a, int x){\n\tif(x == 0) return 1;\n\tif(x%2 == 0) return powmod(a*1LL*a%MOD, x/2);\n\treturn a*1LL*powmod(a, x - 1)%MOD;\n}\n\nint dp[K][K];\n\nint main(){\n\tint k, va, vb;\n\tscanf(\"%d %d %d\", &k, &va, &vb);\n\t\n\tint den = powmod(va + vb, MOD - 2);\n\tint pa = va*1LL*den%MOD;\n\tint pb = vb*1LL*den%MOD;\n\tint one_b = pa*1LL*powmod(pb, MOD - 2)%MOD;\n\t\n\tfor(int i = k - 1; i >= 0; i--){\n\t\tfor(int j = k; j >= 1; j--){\n\t\t\tif(i + j >= k){\n\t\t\t\tdp[i][j] = (i + j + one_b)%MOD;\n\t\t\t}else{\n\t\t\t\tdp[i][j] = (pa*1LL*dp[i][j + 1] + pb*1LL*dp[i + j][j])%MOD;\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"%d\\n\", dp[0][1]);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "dp", "probabilities"], "code_uid": "c27ab626d8c4dee0a2244b83df870ee6", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n\n#define int long long\n#define LG 16\n#define all(x) (x).begin(), (x).end()\n#define deb(x) if((x) > 100000000) while(true);\n\nusing namespace std;\n\nint c[20][20], k, t, deep, a[20], f[20][20], size;\n\nvoid ccout(int x) {\n if (x < 10)\n cout << (char)(x + '0');\n else\n cout << (char)(x - 10 + 'a');\n}\n\nint dp(int x) {\n for (int i = 0; i <= LG; i++)\n f[0][i] = 1;\n for (int i = 1; i <= x; i++)\n for (int j = 1; j <= LG; j++) {\n f[i][j] = 0;\n for (int k = 0; k <= min(i, a[j]); k++)\n f[i][j] += f[i - k][j - 1] * c[i][k];\n }\n return f[x][LG];\n}\n\nvoid solve(int vert, int par) {\n if (!par) return;\n for (int i = par == deep ? 2 : 1; i <= LG; i++) {\n if (!a[i]) continue;\n a[i]--, size = dp(par - 1);\n if (size >= vert) {\n ccout(i - 1); solve(vert, par - 1); break;\n }\n vert -= size, a[i]++;\n }\n}\nint32_t main() {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n cin >> k >> t;\n c[1][0] = c[1][1] = 1;\n for (int i = 2; i <= 10; i++) {\n c[i][0] = 1;\n for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];\n }\n for (int i = 1; i <= LG; i++) a[i] = t;\n deep = 1;\n while (true) {\n a[1]--; size = dp(deep - 1) * 15; a[1]++;\n if (size >= k) break; deep++;\n k -= size;\n }\n solve(k, deep);\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "21dc444e7ffc94b4b7bf66c2a495c463", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "// Author : Mohamed Sameh\n#include\nusing namespace std ;\n\ntypedef long long ll ;\n////////////////////////////////////////////////////////////////////\n#define pb push_back\n#define f first\n#define s second\n#define all(v) v.begin(),v.end()\n#define rall(v) v.rbegin(),v.rend()\n///#Read And Write From File\n/*\n\n freopen(\"in.txt\",\"r\",stdin);\n freopen(\"out.txt\",\"w\",stdout);\n\n*/\nint ReadInt ()\n{\n int t ;\n cin >> t ;\n return t ;\n}\nll ReadLong ()\n{\n ll t ;\n cin >> t ;\n return t ;\n}\nbool Check (string t )\n{\n int l = 0 ;\n int r = t.size() -1 ;\n while (l <= r )\n {\n if ( t[l] != t[r]) return false ;\n l++;\n r--;\n }\n return true ;\n}\nbool check_User (string t )\n{\n int c = 0, C = 0;\n bool Next = 0 ;\n int sc = 0 ;\n for (int i = 0 ; i < t.size() ; i ++ )\n {\n if ( t[i] == '@' )\n {\n if (i+1 == t.size() ) return false ;\n Next = (c > 0 && c < 17 );\n sc = i+1 ;\n break ;\n }\n if ( !( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) || ( t[i] >= '0' && t[i] <= '9' )|| t[i] == '_' ) )\n return false ;\n c++;\n }\n\n if ( Next )\n {\n Next = 0;\n bool SNext = 0 ;\n c = 0 ;\n C = 0 ;\n bool Turn = 0 ;\n bool Slash = 0;\n for (int i = sc ; i < t.size() ; i++)\n {\n if ( i+1 == t.size() && t[i] == '.')return false ;\n if ( t[i] == '/')\n {\n if ( i-1 > 0 && t[ i-1 ] == '.') return false ;\n Slash = 1;\n if ( Turn == 0 )\n SNext = 1 ;\n sc = i+1 ;\n break ;\n }\n\n\n if (t[i] == '.' )\n {\n Turn = 1 ;\n if (c >0 && c < 17 )\n {\n c=0;\n continue ;\n }else\n return false ;\n\n }\n\n if (!( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) || ( t[i] >= '0' && t[i] <= '9' )|| (t[i] == '_') ) )\n return false ;\n c++;\n\n\n }\n\n ///\n if (!SNext && Slash )\n {\n\n c = 0 ;\n for (int i =sc ; i < t.size() ; i++)\n {\n\n if (!( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) || ( t[i] >= '0' && t[i] <= '9' )|| (t[i] == '_') ) )\n return false ;\n c++;\n }\n if ( c>0 && c < 17 ) return true ;\n return false ;\n\n }\n else\n {\n if (Slash)\n {\n c = 0 ;\n for (int i =sc ; i < t.size() ; i++)\n {\n\n if (!( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) || ( t[i] >= '0' && t[i] <= '9' )|| (t[i] == '_') ) )\n return false ;\n c++;\n }\n\n if ( c>0 && c < 17 ) return true ;\n return false ;\n }\n return true ;\n }\n\n\n }\n else\n {\n\n return false ;\n }\n\n}\nint main ()\n{\n\n\n string Id ;\n cin >> Id ;\n if ( check_User(Id))\n cout <<\"YES\\n\";\n else\n cout <<\"NO\\n\";\n\n return 0 ;\n}\n\n\n", "lang_cluster": "C++", "tags": ["strings", "implementation"], "code_uid": "455103076e559f3321cd3eac07cc24e2", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n\nusing namespace std;\ntypedef unsigned long long ull;\nconst int N_MAX = 50;\nint N;\nchar str[N_MAX];\nint cnt[N_MAX];\n\ninline bool can00() {\n return cnt[0] >= 2;\n}\ninline bool can25() {\n return cnt[2] && cnt[5];\n}\ninline bool can50() {\n return cnt[5] && cnt[0];\n}\ninline bool can75() {\n return cnt[7] && cnt[5];\n}\n\ninline int calc(int l, int r) {\n int cnt = 0;\n char tmp[N_MAX];\n memcpy(tmp, str, sizeof(str));\n for (int i = N; i >= 1; i--) {\n if (tmp[i] == r) {\n while(i < N) swap(tmp[i], tmp[i+1]), cnt++, i++;\n break;\n }\n }\n for (int i = N-1; i >= 1; i--) {\n if (tmp[i] == l) {\n while(i < N-1) swap(tmp[i], tmp[i+1]), cnt++, i++;\n break;\n }\n }\n for (int i = 1; i <= N - 2; i++) {\n if (tmp[i] != 0) {\n while(i > 1) swap(tmp[i], tmp[i-1]), cnt++, i--;\n break;\n }\n }\n return cnt;\n}\nint main() {\n scanf(\"%s\", str + 1);\n N = (int) strlen(str + 1);\n for (int i = 1; i <= N; i++) {\n cnt[str[i]-='0']++;\n }\n int ans = 0x3f3f3f3f;\n if (can00()) ans = min(ans, calc(0, 0));\n if (can25()) ans = min(ans, calc(2, 5));\n if (can50()) ans = min(ans, calc(5, 0));\n if (can75()) ans = min(ans, calc(7, 5));\n if (ans == 0x3f3f3f3f) ans = -1;\n printf(\"%d\\n\", ans);\n \n}", "lang_cluster": "C++", "tags": ["brute force", "greedy"], "code_uid": "5686c5d201a3dc97c065b0b1e2822731", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "// ===================================\n// author: M_sea\n// website: http://m-sea-blog.com/\n// ===================================\n#include \n#include \n#include \n#include \n#include \n#include \n#define re register\n#define int long long\nusing namespace std;\n\ninline int read() {\n int X=0,w=1; char c=getchar();\n while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }\n while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();\n return X*w;\n}\n\nconst int _=1e18;\n\nsigned main() {\n int a=read(),q=(_%a*9%a*9%a+1)%a;\n printf(\"%lld %lld\\n\",a-q+1,a-q+_);\n return 0;\n}\n \t\t \t \t\t\t \t \t\t\t \t \t \t\t//hellobig_tq", "lang_cluster": "C++", "tags": ["constructive algorithms"], "code_uid": "02f25c3fb392691e8f216d5924c9d01a", "src_uid": "52b8d97f216ea22693bc16fadcd46dae", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define LL __int64\n\nusing namespace std;\n\nint dp[108][100008], l[108], r[108], n, k;\nconst int maxn = 300;\nint Qv[100008], Qid[100008], pos1, pos2;\n\nvoid solve(int nown)\n{\n //+0\n for(int i = 0; i <= n; i++)\n dp[nown][i] = dp[nown - 1][i];\n //+2\n pos1 = pos2 = 0;\n for(int i = 1; i <= r[nown]; i++) {\n if(i - 1 <= n) {\n while(pos2 > pos1 && dp[nown - 1][i - 1] <= Qv[pos2 - 1])\n --pos2;\n Qv[pos2] = dp[nown - 1][i - 1];\n Qid[pos2++] = i - 1;\n }\n while(pos2 > pos1 && Qid[pos1] < i - (r[nown] - l[nown]))\n ++pos1;\n if(pos2 > pos1)\n dp[nown][i] = min(dp[nown][i], Qv[pos1] + 2);\n }\n //+1\n pos1 = pos2 = 0;\n for(int i = r[nown]; i >= 0; i--) {\n if(r[nown] - i <= n) {\n while(pos2 > pos1 && dp[nown - 1][r[nown] - i] <= Qv[pos2 - 1])\n --pos2;\n Qv[pos2] = dp[nown - 1][r[nown] - i];\n Qid[pos2++] = r[nown] - i;\n }\n while(pos2 > pos1 && Qid[pos1] < l[nown] - i)\n ++pos1;\n if(pos2 > pos1)\n dp[nown][i] = min(dp[nown][i], Qv[pos1] + 1);\n }\n}\n\nint main()\n{\n scanf(\"%d%d\", &n, &k);\n for(int i = 1; i <= k; i++)\n scanf(\"%d%d\", &l[i], &r[i]);\n\n dp[0][0] = 0;\n for(int i = 1; i <= n; i++)\n dp[0][i] = maxn;\n for(int i = 1; i <= k; i++)\n solve(i);\n\n if(dp[k][n] == maxn)\n printf(\"Hungry\");\n else\n printf(\"Full\\n%d\", dp[k][n]);\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "data structures"], "code_uid": "b9d5362b3c678d83250af35874eed94d", "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n\n\n#define eps 0.0000001\n#define ll long long\n\n\nusing namespace std;\n\nstruct vec\n{\n double x;\n double y;\n vec operator*(double d)\n {\n vec v;\n v.x=x*d;\n v.y=y*d;\n return v;\n }\n void norm()\n {\n double d;\n d=sqrt(x*x+y*y);\n x=x/d;\n y=y/d;\n }\n\n};\n\nstruct pt\n{\n double x;\n double y;\n vec operator-(pt p)\n {\n vec v;\n v.x=x-p.x;\n v.y=y-p.y;\n return v;\n }\n pt operator+(vec v)\n {\n pt p;\n p.x=x+v.x;\n p.y=y+v.y;\n return p;\n }\n};\nint cross(pt p1, pt p2,pt p3)\n{\n double x1=p2.x-p1.x;\n double y1=p2.y-p1.y;\n double x2=p3.x-p1.x;\n double y2=p3.y-p1.y;\n double t=x1*y2-y1*x2;\n if (fabs(t)0) return 1;\n else return -1;\n}\nbool intersect(pt p1,pt p2, pt p3, pt p4, int tp) // tp=1 when wall\n{\n ll a,b,c,d;\n a=cross(p1,p2,p3);\n b=cross(p1,p2,p4);\n c=cross(p3,p4,p1);\n d=cross(p3,p4,p2);\n if(fabs(a)max(p3.x,p4.x))\n return 0;\n else\n return 1;\n }\n else return 0;\n }\n if(fabs(a)min(p1.x,p2.x)&&p3.xmin(p1.x,p2.x)&&p4.x>pv.x>>pv.y>>pp.x>>pp.y>>pw1.x>>pw1.y>>pw2.x>>pw2.y>>pm1.x>>pm1.y>>pm2.x>>pm2.y;\n if(!intersect(pv,pp,pw1,pw2,1))\n {\n if(!intersect(pv,pp,pm1,pm2,0))\n {\n cout<<\"YES\";\n return 0;\n }\n }\n\n int a1,a2;\n a1=cross(pm1,pm2,pv);\n a2=cross(pm1,pm2,pp);\n if(fabs(a1)0&&a2>0)||(a1<0&&a2<0))\n {\n double dv=dis_from_line(pm1,pm2,pv);\n double dp=dis_from_line(pm1,pm2,pp);\n double d=dis(pp,pv);\n double av=(d*dv)/(dp+dv);\n vec nn;\n nn=pp-pv;\n nn.norm();\n nn=nn*av;\n pt temp;\n temp=pv+nn;\n // cout<maxx||sec.ymaxy)\n {\n cout<<\"NO\";\n return 0;\n }\n if(intersect(sec,pv,pw1,pw2,1))\n {\n\n cout<<\"NO\";\n return 0;\n }\n if(intersect(sec,pp,pw1,pw2,1))\n {\n // cout<<\"PP\"<\nusing namespace std;\ntypedef long long ll;\n#define sz(x) ((int)(x).size())\n#define rep(i,l,r) for(int i=(l);i<(r);++i)\n//------\nconst int N = 3e2 + 7;\nint n, V, m, a[N], b[N], c[N][N], vis[N], deg[N];\nvector e[N];\nvoid addEdge(int u, int v) {\n\t++deg[u], ++deg[v];\n\te[u].push_back(v), e[v].push_back(u);\n}\nvoid dfs(int u) {\n\tvis[u] = true;\n\trep(i, 1, n + 1)\n\t\tif (c[u][i] && !vis[i]) {\n\t\t\taddEdge(u, i);\t\n\t\t\tdfs(i);\n\t\t}\n}\nvector, int> > ans;\nvoid trans(int u, int v, int w) {\n\tif (w <= 0)\n\t\treturn ;\n\tans.push_back(make_pair(make_pair(u, v), w));\n\ta[u] -= w, a[v] += w;\n}\nvoid DFS(int u, int p, int vol) {\n\trep(i, 0, sz(e[u])) {\n\t\tint v = e[u][i];\n\t\tif (v == p || !vis[v])\n\t\t\tcontinue;\n\t\tif (a[v] < vol)\n\t\t\tDFS(v, u, vol - a[v]);\n\t\tint flow = min(vol, a[v]);\t\n\t\ttrans(v, u, flow), vol -= flow;\n\t}\n}\nvoid DFS2(int u, int p, int vol) {\n\trep(i, 0, sz(e[u])) {\n\t\tint v = e[u][i];\n\t\tif (v == p || !vis[v])\n\t\t\tcontinue;\n\t\tif (V - a[v] < vol)\n\t\t\tDFS2(v, u, vol - V + a[v]);\n\t\tint flow = min(vol, V - a[v]);\n\t\ttrans(u, v, flow), vol -= flow;\n\t}\n}\nvoid solve() {\n\tqueue que;\n\trep(i, 1, n + 1)\n\t\tif (deg[i] == 1)\n\t\t\tque.push(i);\n\twhile (!que.empty()) {\n\t\tint u = que.front();\n\t\tque.pop();\n\t\tvis[u] = false;\n\t\tif (a[u] < b[u])\n\t\t\tDFS(u, -1, b[u] - a[u]);\n\t\telse if (a[u] > b[u])\n\t\t\tDFS2(u, -1, a[u] - b[u]);\n\t\trep(i, 0, sz(e[u])) {\n\t\t\tint v = e[u][i];\n\t\t\t--deg[v];\n\t\t\tif (deg[v] == 1)\n\t\t\t\tque.push(v);\n\t\t}\n\t}\n\trep(i, 1, n + 1)\n\t\tif (a[i] != b[i]) {\n\t\t\tputs(\"NO\");\n\t\t\treturn ;\n\t\t}\n\tprintf(\"%d\\n\", sz(ans));\n\trep(i, 0, sz(ans))\n\t\tprintf(\"%d %d %d\\n\", ans[i].first.first, ans[i].first.second, ans[i].second);\n}\nint main() {\n\tscanf(\"%d%d%d\", &n, &V, &m);\n\trep(i, 1, n + 1)\n\t\tscanf(\"%d\", &a[i]);\n\trep(i, 1, n + 1)\n\t\tscanf(\"%d\", &b[i]);\n\trep(e, 0, m) {\n\t\tint x, y;\n\t\tscanf(\"%d%d\", &x, &y);\n\t\tc[x][y] = c[y][x] = 1;\n\t}\n\trep(i, 1, n + 1)\n\t\tif (!vis[i])\n\t\t\tdfs(i);\n\tsolve();\t\n\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "constructive algorithms"], "code_uid": "272279ba5aaf02d1308033958e3bac12", "src_uid": "0939354d9bad8301efb79a1a934ded30", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\nconst int maxn=1005;\nconst int maxd=11;\nlong long n,d,mod,dp[maxn][maxd],pd[maxn][maxd],f,t[maxd];\ninline long long ksm(long long x,long long n) {\n long long ret=1;\n while (n) {\n if (n&1)\n ret=ret*x%mod;\n n>>=1;\n x=x*x%mod;\n }\n return ret;\n}\ninline long long solve() {\n dp[1][0]=1;\n for (int i=1;i<=n/2;++i) {//if (i%(d-1)==0) {\n f=(i==1)?1:dp[i][d-1];\n for (int j=1;j<=n;++j)\n for (int k=0;k<=d;++k)\n pd[j][k]=0;\n t[0]=1;\n for (int j=1;j<=d;++j)\n t[j]=t[j-1]*(f+j-1)%mod*ksm(j,mod-2)%mod;\n for (int j=0;j<=d;++j)\n for (int k=0;k<=d;++k) if (j+k<=d)\n for (int l=1;l<=n;++l) if (l+i*k<=n)\n pd[l+i*k][j+k]=(pd[l+i*k][j+k]+dp[l][j]*t[k])%mod;\n for (int j=0;j<=n;++j)\n for (int k=0;k<=d;++k)\n //if (pd[j][k])\n dp[j][k]=pd[j][k];\n }\n long long ret=dp[n][d];\n if (n%2==0)\n ret=((ret-dp[n/2][d-1]*(dp[n/2][d-1]-1)/2)%mod+mod)%mod;\n return ret;\n}\nint main()\n{\n scanf(\"%I64d%I64d%I64d\",&n,&d,&mod);\n if (n<=2)\n puts(\"1\");\n else\n printf(\"%I64d\\n\",solve());\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "trees"], "code_uid": "4576bec8d0405b7b07a9657304d115f1", "src_uid": "bdd0fc1d6dbab5eeb5aea135fdfffc9d", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\ntypedef long long ll;\nint main()\n{\n ll f,r,c,ans=0;\n cin>>f>>r>>c;\n ll f1,c1,r1,y;\n c1=c/2;\n r1=r/2;\n ll x=min(r1,c1);\n if(x*3<=f)\n {\n ans=x*2+x*2+x*3;\n f=f-(x*3);\n c=c-(x*2);\n r=r-(x*2);\n }\n else\n {\n y=f/3;\n if(y*2<=r && y*2<=c)\n {\n f=f-(3*y);\n r=r-(2*y);\n c=c-(2*y);\n ans=y*2+y*2+y*3+ans;\n }\n }\n//cout<=3)\n{\n if(r==1 && c==0)\n ans+=3;\n else if(r==1 && c==1)\n ans+=4;\n else if(r==1 && c>=2)\n ans+=6;\n\n else if(r==0 && c==0)\n ans+=2;\n else if(r==0 && c==1)\n ans+=2;\n else if(r==0 && c>=2)\n ans+=3;\n\n else if(r==2 && c==0)\n ans+=4;\n else if(r==2 && c==1)\n ans+=6;\n\n else if(r>=3 && c==0)\n ans+=4;\n else if(r>=3 && c==1)\n ans+=6;\n\n\n\n}\n else if(f==2)\n {\n if(r==1 && c==0)\n ans+=3;\n else if(r==1 && c==1)\n ans+=4;\n else if(r==1 && c>=2)\n ans+=5;\n\n else if(r==0 && c==0)\n ans+=2;\n else if(r==0 && c==1)\n ans+=2;\n else if(r==0 && c>=2)\n ans+=3;\n\n else if(r==2 && c==0)\n ans+=4;\n else if(r==2 && c==1)\n ans+=5;\n else if(r==2 && c>=2)\n ans+=6;\n\n else if(r>=3 && c==0)\n ans+=4;\n else if(r>=3 && c==1)\n ans+=5;\n else if(r>=3 && c>=2)\n ans+=6;\n\n\n\n }\n\n else if(f==1)\n {\n if(r==1 && c==0)\n ans+=2;\n else if(r==1 && c==1)\n ans+=3;\n else if(r==1 && c>=2)\n ans+=4;\n\n else if(r==0 && c==0)\n ans+=1;\n else if(r==0 && c==1)\n ans+=2;\n else if(r==0 && c>=2)\n ans+=3;\n\n else if(r==2 && c==0)\n ans+=2;\n else if(r==2 && c==1)\n ans+=3;\n else if(r==2 && c>=2)\n ans+=5;\n\n else if(r>=3 && c==0)\n ans+=2;\n else if(r>=3 && c==1)\n ans+=3;\n else if(r>=3 && c>=2)\n ans+=5;\n\n\n }\n\n else if( f==0)\n {\n if(r==1 && c==0)\n ans+=1;\n else if(r==1 && c==1)\n ans+=2;\n else if(r==1 && c>=2)\n ans+=2;\n\n else if(r==0 && c==0)\n ans+=0;\n else if(r==0 && c==1)\n ans+=1;\n else if(r==0 && c>=2)\n ans+=1;\n\n else if(r==2 && c==0)\n ans+=1;\n else if(r==2 && c==1)\n ans+=2;\n else if(r==2 && c>=2)\n ans+=2;\n\n else if(r>=3 && c==0)\n ans+=1;\n else if(r>=3 && c==1)\n ans+=2;\n else if(r>=3 && c>=2)\n ans+=2;\n\n\n }\n\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint a[25];\nint tu[8];\n\nint b[6][8] = { { 22, 21, 18, 17, 5, 6, 14, 13 },\n{ 3, 4, 17, 19, 10, 9, 16, 14 },\n{ 7, 8, 19, 20, 23, 24, 15, 16 },\n{ 1, 3, 5, 7, 9, 11, 24, 22 },\n{ 4, 2, 21, 23, 12,10, 8, 6 },\n{ 2, 1, 13, 15, 11, 12, 20, 18 } };\n\nbool res (int tmp[]){\n\n\tfor (int i = 2; i <=24; ++i){\n\t\tif ((i - 1) % 4 == 0)\n\t\t\tcontinue;\n\t\tif (tmp[i] != tmp[i - 1])\n\t\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nvoid rot(int tmp[],int f ,bool d){\n\t\n\n\tif (d){\n\t\tint j = 0;\n\t\tfor (int i = 2; i < 8; ++i){\n\t\t\ttu[j] = tmp[i];\n\t\t\t++j;\n\t\t}\n\t\ttu[6] = tmp[0];\n\t\ttu[7] = tmp[1];\n\t}\n\telse{\n\t\tint j = 0;\n\t\tfor (int i = 2; i < 8; ++i){\n\t\t\ttu[i] = tmp[j];\n\t\t\t++j;\n\t\t}\n\t\ttu[0] = tmp[7];\n\t\ttu[1] = tmp[6];\n\n\t}\n\n}\n\nbool can(int f){\n\n\tint tmp[8];\n\tfor (int i= 0; i < 8; ++i){\n\t\ttmp[i] = b[f][i];\n\t}\n\n\t\n\n\tint tmp_2[25];\n\n\n\tfor (int i = 1; i <= 24; ++i){\n\t\ttmp_2[i] = a[i];\n\t}\n\n\n\trot(tmp, f, 0);\n\n\tfor (int i = 0; i < 8; ++i){\n\t\ttmp_2[b[f][i]] = a[tu[i]];\n\t}\n\n\n\tif (res(tmp_2))\n\t\treturn true;\n\n\trot(tmp,f,1);\n\t\n\tfor (int i = 0; i < 8; ++i){\n\t\ttmp_2[b[f][i]] = a[tu[i]];\n\t}\n\n\n\tif (res(tmp_2))\n\t\treturn true;\n\n\n\treturn 0;\n\n}\n\n\nint main() {\n\n//\tfreopen(\"Text.txt\", \"r\", stdin);\n\n\tfor (int i = 1; i <= 24; ++i){\n\t\tcin >> a[i];\n\t}\n\n\tfor (int i = 0; i < 6; ++i){\n\t\tif (can(i)){\n\t\t\tcout << \"YES\";\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tcout << \"NO\";\n\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "4aa7bbc193aefdfc45b9c0d3829d39bf", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\n#define PI (acos(-1))\n#define ct cout<<\n#define cn cin>>\n#define spc <<\" \"<<\n#define nl puts(\"\")\n#define _fl(x) puts(\"FLAG \" #x);\n#define _(x) cout<< #x <<\" is \"<< x <>arr[i];\n#define _nout(n,arr) for(int i=0; i>g>>n;\n int c=0;\n for (int i = 0; i <=n ; ++i)\n {\n if(i<=b && n-i<=g)c++;\n }\n ct c;nl;\n\n \n return 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math"], "code_uid": "95bf2df300bd59746bba4830d7377ddc", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define maxn 200005\n#define ls o<<1\n#define rs o<<1|1 \nstruct sgt\n{\n\tint l,r,mn,mm,tag;\n\tlong long sum;\n}c[maxn<<2];\nint n;\nlong long ans;\nint a[maxn];\nlong long h[maxn];\nvectorx[maxn];\nvoid pd(int o)\n{\n\tif(c[o].tag)\n\t{\n\t\tc[ls].mm=c[ls].mn=c[o].tag;\n\t\tc[rs].mm=c[rs].mn=c[o].tag;\n\t\tc[ls].tag=c[rs].tag=c[o].tag;\n\t\tc[ls].sum=((long long)c[ls].r-c[ls].l+1)*c[o].tag;\n\t\tc[rs].sum=((long long)c[rs].r-c[rs].l+1)*c[o].tag;\n\t\tc[o].tag=0;\n\t}\n}\nvoid build(int l,int r,int o)\n{\n\tc[o].l=l,c[o].r=r;\n\tif(l==r) \n\t{\n\t\tc[o].mn=c[o].sum=c[o].mm=l;\n\t\treturn ;\n\t}\n\tint mid=(l+r)>>1;\n\tbuild(l,mid,ls);\n\tbuild(mid+1,r,rs);\n\tc[o].mm=max(c[ls].mm,c[rs].mm);\n\tc[o].mn=min(c[ls].mn,c[rs].mn);\n\tc[o].sum=c[ls].sum+c[rs].sum;\n}\nvoid update(int l,int r,int k,int o)\n{\n\tif(l>r) return ;\n\tif(l<=c[o].l&&r>=c[o].r&&k<=c[o].mn) return ;\n \tif(l<=c[o].l&&r>=c[o].r&&k>=c[o].mm)\n\t{\n\t\tc[o].tag=k;\n\t\tc[o].mm=c[o].mn=c[o].tag;\n\t\tc[o].sum=((long long)c[o].r-c[o].l+1)*k;\n\t\treturn ;\n\t}\n\tpd(o);\n\tint mid=(c[o].l+c[o].r)>>1;\n\tif(l>mid) update(l,r,k,rs);\n\telse if(r<=mid) update(l,r,k,ls);\n\telse \n\t{\n\t\tupdate(l,mid,k,ls);\n\t\tupdate(mid+1,r,k,rs);\n\t}\n\tc[o].mm=max(c[ls].mm,c[rs].mm);\n\tc[o].mn=min(c[ls].mn,c[rs].mn);\n\tc[o].sum=c[ls].sum+c[rs].sum;\n}\nint main()\n{\n\tscanf(\"%d\",&n);\n\th[0]=3;\n\tfor(int i=1;i<=n;++i) scanf(\"%d\",&a[i]);\n\tfor(int i=1;i<=n;++i)\n\t{\n\t\tint t=sqrt(a[i]);\n\t\tfor(int j=1;j<=t;++j)\n\t\t{\n\t\t\tif(a[i]%j==0) \n\t\t\t{\n\t\t\t\tx[j].push_back(i);\n\t\t\t\tif(j*j!=a[i]) x[a[i]/j].push_back(i);\n\t\t\t}\n\t\t}\n\t}\n\t/*for(int i=1;i<=5;++i)\n\t{\n\t\tfor(int j=0;j=1;--i)\n\t{\n\t\th[i]=(long long)n*n-c[1].sum+n;\n\t\tif(x[i].size()<=1) continue;\n\t\telse \n\t\t{\n\t\t\tupdate(1,x[i][0],x[i][x[i].size()-2],1);\n\t\t\tupdate(x[i][0]+1,x[i][1],x[i][x[i].size()-1],1);\n\t\t\tupdate(x[i][1]+1,n,n+1,1);\n\t\t}\n\t}\n\t//for(int i=0;i<=5;++i) cout<=1;--i)\t\n\t\tans=ans+(long long)i*(h[i]-h[i-1]);\n\tprintf(\"%lld\",ans);\n\treturn 0;\n}\n//hellobig_tq//hello", "lang_cluster": "C++", "tags": ["number theory", "data structures"], "code_uid": "ac03f6eb89eb4631cedbb1d35ad8b729", "src_uid": "deb3938a6d3f13c4ab8a0765bf0e94b0", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#include \n#define mp(x, y) make_pair(x, y)\n#define forn(i, a, b) for(size_t i=a; i=a; --i)\n#define all(a) a.begin(), a.end()\n#define sz(a) (size_t)(a).size()\n#define X first\n#define Y second\n#define sqr(x) 1ll*(x)*(x)\n#define pb push_back\n#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)\n\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\nusing ld = long double;\nusing pii = pair;\nusing pll = pair;\nusing pld = pair;\nusing vint = vector;\nusing vll = vector;\nusing v2int = vector;\nusing v2ll = vector;\n\nint main()\n{\n fio;\n int a1,a2,k1,k2,n;\n int MAX=0;\n cin >>a1>>a2>>k1>>k2>>n;\n\n\n if (k20 && n>=k1)\n {\n n-=k1;\n a1--;\n }\n\n\n while (a2>0 && n>=k2)\n {\n n-=k2;\n a2--;\n }\n\n MAX=(t1-a1)+(t2-a2);\n ///////////////////\n\n a1=t1;\n a2=t2;\n n=nn;\n\n\n int tmp=a1*(k1-1)+a2*(k2-1);\n\n\n cout<<(tmp>=n?0:n-tmp)<<\" \"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#pragma comment (linker, \"/STACK:256000000\")\n\nusing namespace std;\n\nconst int P = 1000000007;\nint n, m;\n\nint get(int n, int mode) {\n\tif (mode == 0) {\n\t\treturn 1 + (n / 2);\n\t} else {\n\t\treturn (n + 1) / 2;\n\t}\n}\n\nint gcd(int x, int y) {\n\tif (x == 0 || y == 0) {\n\t\treturn x + y;\n\t}\n\tif (x > y) {\n\t\treturn gcd(x % y, y);\n\t} else {\n\t\treturn gcd(y % x, x);\n\t}\n}\n\nlong long cnk2(long long n) {\n\treturn ((n * (n - 1)) / 2LL) % P;\n}\n\nconst int maxN = 4003;\nint ways[maxN];\nint p[maxN][maxN];\n\nvoid add(int dx, int dy) {\n\t\n}\n\nint main() {\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n\n\tfor (int i = 0; i < maxN; ++i) {\n\t\tfor (int j = 0; j < maxN; ++j) {\n\t\t\tif (i == 0 || j == 0) {\n\t\t\t\tp[i][j] = i + j;\n\t\t\t} else {\n\t\t\t\tif (i > j) {\n\t\t\t\t\tp[i][j] = p[i - j][j];\n\t\t\t\t} else {\n\t\t\t\t\tp[i][j] = p[i][j - i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tcin >> n >> m;\n\tlong long res = 0;\n\tfor (int x1 = 0; x1 < 2; ++x1) {\n\t\tfor (int y1 = 0; y1 < 2; ++y1) {\n\t\t\tfor (int x2 = 0; x2 < 2; ++x2) {\n\t\t\t\tfor (int y2 = 0; y2 < 2; ++y2) {\n\t\t\t\t\tfor (int x3 = 0; x3 < 2; ++x3) {\n\t\t\t\t\t\tfor (int y3 = 0; y3 < 2; ++y3) {\n\t\t\t\t\t\t\tint s = gcd(x1 + x2, y1 + y2) + gcd(x2 + x3, y2 + y3) + gcd(x1 + x3, y1 + y3);\n\t\t\t\t\t\t\tif (s % 2 == 0) {\n\t\t\t\t\t\t\t\tlong long A = get(n, x1) * get(m, y1);\n\t\t\t\t\t\t\t\tlong long B = get(n, x2) * get(m, y2);\n\t\t\t\t\t\t\t\tlong long C = get(n, x3) * get(m, y3);\n\t\t\t\t\t\t\t\tres += ((A * B) % P) * C;\n\t\t\t\t\t\t\t\tres %= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tres -= (long long)(n + 1) * (long long)(m + 1);\n\tres = ((res % P) + P) % P;\n\tres -= 6LL * cnk2((n + 1) * (m + 1));\n\tres = ((res % P) + P) % P;\n\tfor (int dx = 1; dx <= n; ++dx) {\n\t\tfor (int dy = 1; dy <= m; ++dy) {\n\t\t\tif (dx == 0 && dy <= 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint k = p[dx][dy] - 1;\n\t\t\tways[k] += (n - dx + 1) * (m - dy + 1);\n\t\t\tif (ways[k] >= P) {\n\t\t\t\tways[k] -= P;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 1; i < maxN; ++i) {\n\t\tres -= 12LL * (long long)(i) * (long long)(ways[i]);\n\t\tres %= P;\n\t}\n\n\tmemset(ways, 0, sizeof(ways));\n\tfor (int dx = 0; dx <= n; ++dx) {\n\t\tint l = 1, r = m;\n\t\tif (dx > 0) {\n\t\t\tl = 0;\n\t\t\tr = 0;\n\t\t}\n\t\tfor (int dy = l; dy <= r; ++dy) {\n\t\t\tif (dx == 0 && dy <= 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint k = p[dx][dy] - 1;\n\t\t\tways[k] += (n - dx + 1) * (m - dy + 1);\n\t\t\tif (ways[k] >= P) {\n\t\t\t\tways[k] -= P;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (int i = 1; i < maxN; ++i) {\n\t\tres -= 6LL * (long long)(i) * (long long)(ways[i]);\n\t\tres %= P;\n\t}\n\n\tres = ((res % P) + P) % P;\n\tcout << res << endl;\n\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "geometry"], "code_uid": "f9179fc750b55513319348d879f0577c", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include \n#include \n\nusing namespace std;\n\nint main()\n{\n int n;\n cin >> n;\n\n long long answer = n - 2;\n for (int i = 1; i < n; i++)\n answer += max(n - i - 2, 0) + max(0, i - 2);\n\n cout << answer;\n return 0;\n}", "lang_cluster": "C++", "tags": ["math"], "code_uid": "d1b58e6b229e0b7d693909f9477b3783", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define mp make_pair\n#define pb push_back\ntypedef long long ll;\ntypedef long double ld;\ntypedef unsigned long long ull;\ntypedef pair pii;\ntypedef pair pli;\ntypedef pair pll;\n\nconst int MAXN = 3005;\nconst ll INF = 1e16;\nconst int MOD = 998244353;\nll b[MAXN], w[MAXN], size[MAXN];\npll dp[MAXN][MAXN], tmp[MAXN];\nint n, m, T;\n\nvector e[MAXN];\n\nvoid dfs (int u, int fa)\n{\n\tdp[u][0] = mp(0, b[u]);\n\tsize[u] = 1;\n\tfor (int i = 0; i < e[u].size(); ++ i)\n\t{\n\t\tint v = e[u][i];\n\t\tif (v == fa)\n\t\t\tcontinue;\n\t\tdfs (v, u);\n\t\tfor (int j = 0; j <= min ((ll)m, size[u] + size[v]); ++ j)\n\t\t\ttmp[j] = mp(0, -INF);\n\t\tfor (int j = 0; j <= min ((ll)m, size[u]); ++ j) \n\t\t\tfor (int k = 0; k <= min ((ll)(m - j), size[v]); ++ k)\n\t\t\t{\n\t\t\t\ttmp[k + j] = max (tmp[k + j], mp(dp[v][k].first + dp[u][j].first, dp[v][k].second + dp[u][j].second));\n\t\t\t\ttmp[k + j + 1] = max (tmp[k + j + 1], mp(dp[v][k].first + dp[u][j].first + (dp[v][k].second > 0), dp[u][j].second));\n\t\t\t}\n\t\tsize[u] += size[v];\n\t\tfor (int j = 0; j <= min ((ll)m, size[u]); ++ j)\n\t\t\tdp[u][j] = tmp[j];\n\t}\n}\n\nint main()\n{\n\tscanf (\"%d\", &T);\n\twhile (T)\n\t{\n\t\t-- T;\n\t\tscanf (\"%d%d\", &n, &m);\n\t\tfor (int i = 1; i <= n; ++ i)\n\t\t\tsize[i] = 0, tmp[i] = mp(0, 0), e[i].clear();\n\t\tfor (int i = 1; i <= n; ++ i)\n\t\t\tfor (int j = 1; j <= m; ++ j)\n\t\t\t\tdp[i][j] = mp(0, 0);\n\t\tfor (int i = 1; i <= n; ++ i)\n\t\t\tcin >> w[i];\n\t\tfor (int i = 1; i <= n; ++ i)\n\t\t{\n\t\t\tcin >> b[i];\n\t\t\tb[i] -= w[i]; \n\t\t}\n\t\tfor (int i = 1; i < n; ++ i)\n\t\t{\n\t\t\tint u, v;\n\t\t\tscanf (\"%d%d\", &u, &v);\n\t\t\te[u].pb(v), e[v].pb(u);\n\t\t}\n\t\t\n\t\tdfs (1, 0);\n\t\tcout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << endl;\n\t}\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "dp", "trees"], "code_uid": "ba419948580762906a9fc2a82361a970", "src_uid": "d2d1d8c8532b652f172e87a151adae4f", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ninline void file()\n{\n freopen(\"D:\\\\go.txt\", \"r\", stdin);\n freopen(\"D:\\\\leave.txt\", \"w\", stdout);\n}\n\nint main()\n{\n //file();\n int cas;\n scanf(\"%d\", &cas);\n while (cas--)\n {\n string str;\n cin >> str;\n str[3] = ' ';\n stringstream tmp(str.substr(4));\n int n;\n tmp >> n;\n int lenth = str.size() - 4;\n int time_to = 0, t = 10;\n //cout << lenth << endl;\n for (int i = 1; i < lenth; ++i)\n {\n time_to += t;\n t *= 10;\n }\n while (n < 1989 + time_to)\n {\n n += t;\n //cout << n << endl;\n }\n printf(\"%d\\n\", n);\n }\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy", "constructive algorithms", "implementation"], "code_uid": "e90c6ccac62a520619bf9e200952cd8f", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++20 (64)", "source_code": "/**\r\n * author: tourist\r\n * created: 31.07.2022 18:10:18 \r\n**/\r\n#include \r\n\r\nusing namespace std;\r\n\r\n#ifdef LOCAL\r\n#include \"algo/debug.h\"\r\n#else\r\n#define debug(...) 42\r\n#endif\r\n\r\ntemplate \r\nT inverse(T a, T m) {\r\n T u = 0, v = 1;\r\n while (a != 0) {\r\n T t = m / a;\r\n m -= t * a; swap(a, m);\r\n u -= t * v; swap(u, v);\r\n }\r\n assert(m == 1);\r\n return u;\r\n}\r\n\r\ntemplate \r\nclass Modular {\r\n public:\r\n using Type = typename decay::type;\r\n\r\n constexpr Modular() : value() {}\r\n template \r\n Modular(const U& x) {\r\n value = normalize(x);\r\n }\r\n\r\n template \r\n static Type normalize(const U& x) {\r\n Type v;\r\n if (-mod() <= x && x < mod()) v = static_cast(x);\r\n else v = static_cast(x % mod());\r\n if (v < 0) v += mod();\r\n return v;\r\n }\r\n\r\n const Type& operator()() const { return value; }\r\n template \r\n explicit operator U() const { return static_cast(value); }\r\n constexpr static Type mod() { return T::value; }\r\n\r\n Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }\r\n Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }\r\n template Modular& operator+=(const U& other) { return *this += Modular(other); }\r\n template Modular& operator-=(const U& other) { return *this -= Modular(other); }\r\n Modular& operator++() { return *this += 1; }\r\n Modular& operator--() { return *this -= 1; }\r\n Modular operator++(int) { Modular result(*this); *this += 1; return result; }\r\n Modular operator--(int) { Modular result(*this); *this -= 1; return result; }\r\n Modular operator-() const { return Modular(-value); }\r\n\r\n template \r\n typename enable_if::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {\r\n#ifdef _WIN32\r\n uint64_t x = static_cast(value) * static_cast(rhs.value);\r\n uint32_t xh = static_cast(x >> 32), xl = static_cast(x), d, m;\r\n asm(\r\n \"divl %4; \\n\\t\"\r\n : \"=a\" (d), \"=d\" (m)\r\n : \"d\" (xh), \"a\" (xl), \"r\" (mod())\r\n );\r\n value = m;\r\n#else\r\n value = normalize(static_cast(value) * static_cast(rhs.value));\r\n#endif\r\n return *this;\r\n }\r\n template \r\n typename enable_if::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) {\r\n long long q = static_cast(static_cast(value) * rhs.value / mod());\r\n value = normalize(value * rhs.value - q * mod());\r\n return *this;\r\n }\r\n template \r\n typename enable_if::Type>::value, Modular>::type& operator*=(const Modular& rhs) {\r\n value = normalize(value * rhs.value);\r\n return *this;\r\n }\r\n\r\n Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }\r\n\r\n friend const Type& abs(const Modular& x) { return x.value; }\r\n\r\n template \r\n friend bool operator==(const Modular& lhs, const Modular& rhs);\r\n\r\n template \r\n friend bool operator<(const Modular& lhs, const Modular& rhs);\r\n\r\n template \r\n friend V& operator>>(V& stream, Modular& number);\r\n\r\n private:\r\n Type value;\r\n};\r\n\r\ntemplate bool operator==(const Modular& lhs, const Modular& rhs) { return lhs.value == rhs.value; }\r\ntemplate bool operator==(const Modular& lhs, U rhs) { return lhs == Modular(rhs); }\r\ntemplate bool operator==(U lhs, const Modular& rhs) { return Modular(lhs) == rhs; }\r\n\r\ntemplate bool operator!=(const Modular& lhs, const Modular& rhs) { return !(lhs == rhs); }\r\ntemplate bool operator!=(const Modular& lhs, U rhs) { return !(lhs == rhs); }\r\ntemplate bool operator!=(U lhs, const Modular& rhs) { return !(lhs == rhs); }\r\n\r\ntemplate bool operator<(const Modular& lhs, const Modular& rhs) { return lhs.value < rhs.value; }\r\n\r\ntemplate Modular operator+(const Modular& lhs, const Modular& rhs) { return Modular(lhs) += rhs; }\r\ntemplate Modular operator+(const Modular& lhs, U rhs) { return Modular(lhs) += rhs; }\r\ntemplate Modular operator+(U lhs, const Modular& rhs) { return Modular(lhs) += rhs; }\r\n\r\ntemplate Modular operator-(const Modular& lhs, const Modular& rhs) { return Modular(lhs) -= rhs; }\r\ntemplate Modular operator-(const Modular& lhs, U rhs) { return Modular(lhs) -= rhs; }\r\ntemplate Modular operator-(U lhs, const Modular& rhs) { return Modular(lhs) -= rhs; }\r\n\r\ntemplate Modular operator*(const Modular& lhs, const Modular& rhs) { return Modular(lhs) *= rhs; }\r\ntemplate Modular operator*(const Modular& lhs, U rhs) { return Modular(lhs) *= rhs; }\r\ntemplate Modular operator*(U lhs, const Modular& rhs) { return Modular(lhs) *= rhs; }\r\n\r\ntemplate Modular operator/(const Modular& lhs, const Modular& rhs) { return Modular(lhs) /= rhs; }\r\ntemplate Modular operator/(const Modular& lhs, U rhs) { return Modular(lhs) /= rhs; }\r\ntemplate Modular operator/(U lhs, const Modular& rhs) { return Modular(lhs) /= rhs; }\r\n\r\ntemplate\r\nModular power(const Modular& a, const U& b) {\r\n assert(b >= 0);\r\n Modular x = a, res = 1;\r\n U p = b;\r\n while (p > 0) {\r\n if (p & 1) res *= x;\r\n x *= x;\r\n p >>= 1;\r\n }\r\n return res;\r\n}\r\n\r\ntemplate \r\nbool IsZero(const Modular& number) {\r\n return number() == 0;\r\n}\r\n\r\ntemplate \r\nstring to_string(const Modular& number) {\r\n return to_string(number());\r\n}\r\n\r\n// U == std::ostream? but done this way because of fastoutput\r\ntemplate \r\nU& operator<<(U& stream, const Modular& number) {\r\n return stream << number();\r\n}\r\n\r\n// U == std::istream? but done this way because of fastinput\r\ntemplate \r\nU& operator>>(U& stream, Modular& number) {\r\n typename common_type::Type, long long>::type x;\r\n stream >> x;\r\n number.value = Modular::normalize(x);\r\n return stream;\r\n}\r\n\r\nusing ModType = int;\r\n\r\nstruct VarMod { static ModType value; };\r\nModType VarMod::value;\r\nModType& md = VarMod::value;\r\nusing Mint = Modular;\r\n\r\nvector fact;\r\nvector inv_fact;\r\n\r\nMint C(int n, int k) {\r\n if (k < 0 || k > n) {\r\n return 0;\r\n }\r\n while ((int) fact.size() < n + 1) {\r\n fact.push_back(fact.back() * (int) fact.size());\r\n inv_fact.push_back(1 / fact.back());\r\n }\r\n return fact[n] * inv_fact[k] * inv_fact[n - k];\r\n}\r\n\r\nint main() {\r\n ios::sync_with_stdio(false);\r\n cin.tie(0);\r\n int n;\r\n cin >> n >> md;\r\n fact = inv_fact = {1};\r\n C(2 * n + 1, 0);\r\n Mint ans = 0;\r\n for (int i = 1; i <= n; i++) {\r\n for (int j = 1; 2 * j <= i; j++) {\r\n Mint dp = fact[i] * C(i - j - 1, j - 1) * inv_fact[j];\r\n int ones = n - i;\r\n Mint add = dp * C(n, i) * power(Mint(n - 1), j) * power(Mint(n - j - ones), ones);\r\n ans += add;\r\n }\r\n }\r\n cout << ans << '\\n';\r\n return 0;\r\n}\r\n", "lang_cluster": "C++", "tags": ["constructive algorithms", "math", "dp", "combinatorics", "fft"], "code_uid": "29b0e2d484ff23bc055bd7605685581b", "src_uid": "2d5a5055aaf34f4d300cfdf7c21748c3", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#define N 220000\n#define int64 long long\nusing namespace std;\nconst int m1[4][4]={1,1,0,1, 1,0,0,0, 0,0,1,0, 0,0,0,1},\n\t\t m2[4][4]={1,1,1,0, 1,0,0,0, 0,0,1,0, 0,0,0,1},\n\t\t mo=1000000007;\nint next[N],i,j,m;\nint64 n;\nstring s;\nvoid cheng(int a[4][4],const int b[4][4],const int c[4][4]){\n\tint d[4][4]={},i,j,k;\n\tfor(i=0;i<4;++i)\n\t\tfor(j=0;j<4;++j)\n\t\t\tfor(k=0;k<4;++k)d[i][k]=(1ll*b[i][j]*c[j][k]+d[i][k])%mo;\n\tfor(i=0;i<4;++i)\n\t\tfor(j=0;j<4;++j)a[i][j]=d[i][j];\n}\nint calc(string a,string b,int x){\n\tint i,j,p=0,ans=0;\n\tnext[0]=-1;\n\tfor(i=0;i=x && i-b.length()+1=2)a+=b,swap(a,b),x++;\n\tint v[4][4]={1,0,0,0},d[4][4];\n\tif((n-x)&1)cheng(d,m1,m2);\n\telse cheng(d,m2,m1);\n\tint64 tim=(n-x-2)/2;\n\twhile(tim){\n\t\tif(tim&1)cheng(v,v,d);\n\t\ttim/=2;\n\t\tcheng(d,d,d);\n\t}\n\tif((n-x)&1)cheng(v,v,m1);\n\treturn (1ll*v[0][0]*calc(a+b,s,-1)+1ll*v[0][1]*calc(b,s,-1)+\n\t\t\t1ll*v[0][2]*calc(b+b,s,b.length())+1ll*v[0][3]*calc(b+a,s,b.length()))%mo;\n}\nint main(){\n\tscanf(\"%I64d%d\",&n,&m);\n\tfor(;m--;)cin>>s,printf(\"%d\\n\",work(n,s));\n}\n\n", "lang_cluster": "C++", "tags": ["matrices", "strings"], "code_uid": "07f9b9a97967e8074b4c02b9bc337e5a", "src_uid": "8983915e904ba763d893d56e94d9f7f0", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define pb push_back\n// #define int long long\ntypedef long long ll;\n#define fi first\n#define se second\n#define pii pair\n#define endl '\\n'\n#define fr(i, a, b) for(int i = a; i <= b; i++)\n#define sz(s) (int)s.size()\n#define y1 fdfbvfds\ntypedef long double f80;\n#define all(x) x.begin(), x.end()\ntypedef long double f80;\n \nmt19937 rng(chrono::steady_clock::now().time_since_epoch().count());\nll rand(ll l,ll r){\n uniform_int_distribution uid(l, r);\n return uid(rng);\n}\n\nconst int H = 60;\nconst int N = 5e5 + 5;\n\nf80 dp[N][H];\nint par[N];\nint n = 0;\n\nvoid add(int v) {\n\tn++;\n\tpar[n] = v;\n\tfr(i, 0, H - 1) {\n\t\tdp[n][i] = 1;\n\t}\n\tvector anc;\n\tv = n;\n\tfor(int i = 0; i < H; i++) {\n\t\tif(!v) break;\n\t\tanc.pb(v);\n\t\tv = par[v];\n\t}\n\tfor(int i = sz(anc) - 2; i > 0; i--) {\n\t\tint u = anc[i], p = anc[i + 1];\n\t\tdp[p][i] /= ((1 + dp[u][i - 1]) / 2.0);\n\t}\n\tif(sz(anc) > 1)\n\t\tdp[anc[1]][0] /= 2;\n\tfor(int i = 1; i < sz(anc) - 1; i++) {\n\t\tint u = anc[i], p = anc[i + 1];\n\t\tdp[p][i] *= ((1 + dp[u][i - 1]) / 2.0);\n\t}\n}\n\nf80 query(int u) {\n\tf80 ans = 0;\n\tfr(i, 1, H - 1) {\n\t\tans += i * (dp[u][i] - dp[u][i - 1]);\n\t}\n\treturn ans;\n}\n\nsigned main()\n{\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int q;\n cin >> q;\n add(0);\n while(q--) {\n \tint t, v;\n \tcin >> t >> v;\n \tif(t == 1) {\n \t\tadd(v);\n \t}\n \telse {\n \t\tcout << setprecision(10) << fixed << query(v) << endl;\n \t}\n }\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "dp", "probabilities", "trees"], "code_uid": "41d6795a2f9f22a4f55bca7ca71c0206", "src_uid": "55affe752cb214d1e4031a9e3972597b", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define y0 y0z\n#define y1 y1z\n#define yn ynz\n#define j0 j0z\n#define j1 j1z\n#define jn jnz\n#define tm tmz\n#define buli(x) (__builtin_popcountll(x))\n#define bur0(x) (__builtin_ctzll(x))\n#define bul2(x) (63-__builtin_clzll(x))\n#define mp make_pair\n#define pb push_back\n#define fi first\n#define se second\n#define fil(a,b) memset((a),(b),sizeof(a))\n#define cl(a) fil(a,0)\n#define siz(x) ((int)(x).size())\n#define all(x) (x).begin(),(x).end()\n#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)\n#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)\n#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)\n#define pw(x) ((ll(1))<<(x))\n#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))\n#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))\nvoid getre(){int x=0;printf(\"%d\\n\",1/x);}\nvoid gettle(){int res=1;while(1)res<<=1;printf(\"%d\\n\",res);}\ntypedef pair pii;\ntypedef vector vi;\ntypedef vector vpii;\ntemplateinline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}\ntemplateinline bool upmax(T&a,const S&b){return ainline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}\ntemplateinline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}\ntemplateN gcd(N a,N b){return b?gcd(b,a%b):a;}\ntemplateinline int sgn(N a){return a>0?1:(a<0?-1:0);}\n#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)\n #define lld \"%I64d\"\n#else\n #define lld \"%lld\"\n#endif\ninline void gn(long long&x){\n\tint sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');\n\twhile((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;\n}\ninline void gn(int&x){long long t;gn(t);x=t;}\ninline void gn(unsigned long long&x){long long t;gn(t);x=t;}\ninline void gn(double&x){double t;scanf(\"%lf\",&t);x=t;}\ninline void gn(long double&x){double t;scanf(\"%lf\",&t);x=t;}\ninline void gs(char *s){scanf(\"%s\",s);}\ninline void gc(char &c){while((c=getchar())>126 || c<33);}\ninline void pc(char c){putchar(c);}\n#ifdef JCVB\n#define debug(...) fprintf(stderr, __VA_ARGS__)\n#else\n#define debug(...) \n#endif\ntypedef long long ll;\ntypedef double db;\ninline ll sqr(ll a){return a*a;}\ninline db sqrf(db a){return a*a;}\nconst int inf=0x3f3f3f3f;\nconst db pi=3.14159265358979323846264338327950288L;\nconst db eps=1e-6;\nconst int mo=1e9+7;\nint qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}\n\nll n;\nint k;\n\n// mo < 2^30 = 1073741824\n// first call mm_init(sz);\n// indices from 0 to mm_n - 1\n// call a.plus(),b.plus() before a*b\n\nconst int MM_N =33;\n\nint mm_n;\nstruct mat{\n\tint a[MM_N][MM_N];\n\tvoid plus(){\n\t\trep(i,0,mm_n)rep(j,0,mm_n)a[i][j]=(a[i][j]%mo+mo)%mo;\n\t}\n}one;\nmat operator*(const mat&a,const mat&b){\n\tstatic ll ans[MM_N][MM_N];\n\tcl(ans);\n\tll infa=8e18;\n\trep(k,0,mm_n)rep(i,0,mm_n)rep(j,0,mm_n){\n\t\tif((ans[i][j]+=1ll*a.a[i][k]*b.a[k][j])>=infa)ans[i][j]%=mo;\n\t}\n\tmat c;\n\trep(i,0,mm_n)rep(j,0,mm_n)c.a[i][j]=ans[i][j]%mo;\n\treturn c;\n}\nmat qp(mat a,ll b){a.plus();mat n=one;do{if(b&1)n=n*a;a=a*a;}while(b>>=1);return n;}\nvoid mm_init(int sz){\n\tmm_n=sz;\n\trep(i,0,mm_n)one.a[i][i]=1;\n}\n\n\nint nu[111];int tot=0;\n\nmat a[100];\n\nmat jia(const mat&x,int d){\n\tmat ret;\n\trep(i,0,k+1)rep(j,0,k+1)ret.a[i!=k?(i+d)%k:k][j!=k?(j+d)%k:k]=x.a[i][j];\n\treturn ret;\n}\t\nint main()\n{\n#ifdef JCVB\n\t//freopen(\"1.in\",\"r\",stdin);\n\t//freopen(\"1.out\",\"w\",stdout);\n\tint _time_jc=clock();\n#endif\n\tgn(n);gn(k);\n\tmm_init(k+1);\n\n\twhile(n){\n\t\tnu[tot++]=n%k;\n\t\tn/=k;\n\t}\n\tfor (int j=0;j<=k;j++)a[0].a[0][j]=1;\n\tfor (int j=0;j<=k;j++)a[0].a[j][j]=1;\n\tfor (int i=1;i=0;i--){\n\t\tfor (int j=0;j\nusing namespace std;\n#define MAXN (int)(1e5 + 5)\n#define MAXM (int)(1e2+5)\n#define fr first\n#define sd second\n#define MP make_pair\n#define pb push_back\n#define SZ(A) (int)A.size()\n#define ALL(v) v.begin(), v.end()\n#define M0(a) memset(a, 0, sizeof(a))\n#define M1(a) memset(a, -1, sizeof(a))\n#define REP(i,n) for(int i = 0; i < int(n); i++)\n#define REPN(i,n,m) for(int i = m; i <= int(n); i++)\n#define RREP(i,n) for(int i = int(n-1); i >= 0; i--)\n#define RREPN(i, n, m) for(int i = n; i >= (int)m; i--)\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef double db;\ntypedef long double ld;\nconst ll INF= ll(1e15);\nconst ll MOD = ll(1e9 + 7);\ntypedef pair pii;\ntypedef pair pll;\ntypedef pair ppii;\ntemplate inline void AMIN(T &x, U y){ if(x > y) x = y;}\ntemplate inline void AMAX(T &x, U y){ if(x < y) x = y;}\n\nint main() {\n //freopen(\"input.txt\", \"r\", stdin);\n //freopen(\"output.txt\", \"w\", stdout);\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int n, a, b;\n cin >> n >> a >> b;\n\n int ans = INT_MAX;\n vector V = {a, a, a, a, b, b};\n vector IDX = {0, 1, 2, 3, 4, 5};\n\n do {\n\n int rem = 0, X = 0;\n REP(i, 6) {\n\n if(rem < V[IDX[i]])\n rem = n - V[IDX[i]], X++;\n else\n rem -= V[IDX[i]];\n }\n\n ans = min(ans, X);\n \n } while(next_permutation(ALL(IDX)));\n\n cout << ans << endl;\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy", "implementation"], "code_uid": "25d5ebd813f2fbb2a5273997ab0ea351", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nvoid init()\n{\n\tfreopen(\"input.txt\", \"r\", stdin);\n}\n\nint main()\n{\n\tstring input, output;\n\tcin >> input >> output;\n\tint k;\n\tcin >> k;\n\tlong long int mod = 1000 * 1000 * 1000 + 7;\n\tint length = input.length();\n\tvector previous(length), present(length);\n\tpresent[0] = 1;\n\tfor (int i = 1; i < length; ++i)\n\t{\n\t\tpresent[i] = 0;\n\t}\n\tfor (int i = 0; i < k; ++i)\n\t{\n\t\tprevious = present;\n\t\tlong long int sum = 0;\n\t\tfor (int j = 0; j < length; ++j)\n\t\t{\n\t\t\tsum += previous[j];\n\t\t}\n\t\tfor (int j = 0; j < length; ++j)\n\t\t{\n\t\t\tpresent[j] = (sum - previous[j]) % mod;\n\t\t}\n\t}\n\tlong long int ans = 0;\n\tfor (int i = 0; i < length; ++i)\n\t{\n\t\tbool equals = true;\n\t\tfor (int j = 0; j < length - i; ++j)\n\t\t{\n\t\t\tif (input[i + j] != output[j])\n\t\t\t{\n\t\t\t\tequals = false;\n\t\t\t}\n\t\t}\n\t\tfor (int j = length - i; j < length; ++j)\n\t\t{\n\t\t\tif (input[j - length + i]!= output[j])\n\t\t\t{\n\t\t\t\tequals = false;\n\t\t\t}\n\t\t}\n\t\tif (equals)\n\t\t{\n\t\t\tans += present[i];\n\t\t}\n\t}\n\tans = ans % mod;\n\tcout << ans;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "aca786c24fa2942ea1ac2fb7dd7a33ee", "src_uid": "414000abf4345f08ede20798de29b9d4", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n\nusing namespace std;\n#define PB push_back\n#define MP make_pair\n#define LL long long\n#define int LL\n#define FOR(i,a,b) for(int i = (a); i <= (b); i++)\n#define RE(i,n) FOR(i,1,n)\n#define REP(i,n) FOR(i,0,(int)(n)-1)\n#define R(i,n) REP(i,n)\n#define VI vector\n#define PII pair\n#define LD long double\n#define FI first\n#define SE second\n#define st FI\n#define nd SE\n#define ALL(x) (x).begin(), (x).end()\n#define SZ(x) ((int)(x).size())\n\n#define unordered_map __fast_unordered_map\ntemplate>\nusing unordered_map = __gnu_pbds::gp_hash_table;\n\ntemplate void mini(C &a4, C b4) { a4 = min(a4, b4); }\ntemplate void maxi(C &a4, C b4) { a4 = max(a4, b4); }\n\ntemplate void _dbg(const char *sdbg, TH h){ cerr< void _dbg(const char *sdbg, TH h, TA... a) {\n while(*sdbg!=',')cerr<<*sdbg++;\n cerr<<'='< ostream &operator<<(ostream& os, vector V) {\n os << \"[\"; for (auto vv : V) os << vv << \",\"; return os << \"]\";\n}\ntemplate ostream &operator<<(ostream &os, pair P) {\n return os << \"(\" << P.st << \",\" << P.nd << \")\";\n}\n\n#ifdef LOCAL\n#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)\n#else\n#define debug(...) (__VA_ARGS__)\n#define cerr if(0)cout\n#endif\n\nconst vector kShifts = {\n {0, 1, 4, 3}, {0, 3, 4, 1},\n {1, 2, 5, 4}, {1, 4, 5, 2},\n {3, 4, 7, 6}, {3, 6, 7, 4},\n {4, 5, 8, 7}, {4, 7, 8, 5},\n};\n\nVI Apply(VI perm, const VI &shift) {\n vector elems(SZ(shift));\n for (int i = 0; i < SZ(shift); ++i)\n elems[i] = perm[shift[i]];\n\n for (int i = 0; i < SZ(shift); ++i)\n perm[shift[(i + 1) % SZ(shift)]] = elems[i];\n\n return perm;\n}\n\nint GetIndex(const vector &perm) {\n vector has_it(9);\n int coef = 362880;\n int idx = 0;\n\n for (int i = 0; i < SZ(perm); ++i) {\n coef /= SZ(perm) - i;\n const int v = perm[i];\n int num_lower = 0;\n for (int j = 0; j < v; ++j)\n num_lower += !has_it[j];\n idx += coef * num_lower;\n has_it[v] = true;\n }\n\n // debug(perm, has_it, idx, coef);\n\n return idx;\n}\n\nconst int kNumPerms = 5e5;\n\nbool visited[kNumPerms];\nVI op_done[kNumPerms];\nint cur_dist[kNumPerms];\nint parent[kNumPerms];\n\nvoid Preproc() {\n queue Q;\n\n VI start(9);\n iota(ALL(start), 0);\n visited[GetIndex(start)] = true;\n Q.push(start);\n\n int num_visited = 0;\n int max_dist = 0;\n\n while (!Q.empty()) {\n auto V = Q.front(); Q.pop();\n ++num_visited;\n const int idx = GetIndex(V);\n const int dist = cur_dist[idx];\n maxi(max_dist, dist);\n // debug(V);\n\n for (auto &shift : kShifts) {\n const VI next_v = Apply(V, shift);\n const int next_idx = GetIndex(next_v);\n if (!visited[next_idx]) {\n visited[next_idx] = true;\n op_done[next_idx] = shift;\n cur_dist[next_idx] = dist + 1;\n parent[next_idx] = idx;\n Q.push(next_v);\n }\n }\n }\n debug(num_visited, max_dist);\n\n}\n\nconst int MaxDim = 24;\nint datax[MaxDim][MaxDim];\nint data_copy[MaxDim][MaxDim];\nint N, M;\n\nvector cycles;\n\nvoid SwapTwo(int r1, int c1, int r2, int c2) {\n debug(\"SwapTwo\", r1, c1, r2, c2);\n assert(abs(r1 - r2) <= 2 && abs(c1 - c2) <= 2);\n\n const int r0 = min(N - 3, min(r1, r2));\n const int c0 = min(M - 3, min(c1, c2));\n\n /* vector order(9);\n iota(ALL(order), 0);\n sort(ALL(order), [&](int lhs, int rhs) {\n int rl = lhs / 3, cr = lhs % 3;\n int rr = rhs / 3, cr = rhs % 3;\n return datax[r0+rl][c0+cr] < data[r0+rr][c0+cr];\n }); */\n\n const int swap1 = (r1-r0)*3+(c1-c0);\n const int swap2 = (r2-r0)*3+(c2-c0);\n\n vector order(9);\n iota(ALL(order), 0);\n swap(order[swap1], order[swap2]);\n int cur_idx = GetIndex(order);\n\n vector ops;\n\n while (cur_idx != 0) {\n const VI cycle = op_done[cur_idx];\n ops.PB(cycle);\n cur_idx = parent[cur_idx];\n }\n \n reverse(ALL(ops));\n for (auto &cycle : ops) {\n VI description;\n for (int v : cycle)\n description.push_back(datax[r0 + v / 3][c0 + v % 3]);\n\n const int S = SZ(cycle);\n for (int i = 0; i < S; ++i) {\n const int j = (i + S - 1) % S;\n const int v = cycle[i];\n datax[r0+v/3][c0+v%3] = description[j];\n }\n\n#ifdef LOCAL\n debug(description);\n for (int i = 0; i < 3; ++i) {\n for (int j = 0; j < 3; ++j)\n cerr << datax[i][j] << \"\\t\";\n cerr << \"\\n\";\n }\n#endif\n\n cycles.push_back(description);\n }\n\n // swap(datax[r1][c1], datax[r2][c2]);\n}\n\nint32_t main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout << fixed << setprecision(11);\n cerr << fixed << setprecision(6);\n\n Preproc();\n\n cin >> N >> M;\n for (int i = 0; i < N; ++i)\n for (int j = 0; j < M; ++j) {\n cin >> datax[i][j];\n data_copy[i][j] = datax[i][j];\n }\n\n\n for (int idx = 1; idx <= N * M; ++idx) {\n int r = -1, c = -1;\n const int needed_r = (idx - 1) / M;\n const int needed_c = (idx - 1) % M;\n\n debug(idx, r, c, needed_r, needed_c);\n\n for (int i = 0; i < N; ++i)\n for (int j = 0; j < M; ++j)\n if (datax[i][j] == idx) {\n r = i;\n c = j;\n }\n\n assert(r != -1);\n assert(c != -1);\n\n auto GetCloser = [&](int from, int to) {\n if (from < to)\n return min(to, from + 2);\n else\n return max(to, from - 2);\n };\n\n while(tie(r, c) != tie(needed_r, needed_c)) {\n int next_r = GetCloser(r, needed_r);\n int next_c = GetCloser(c, needed_c);\n while (make_pair(next_r, next_c) < make_pair(needed_r, needed_c))\n ++next_r;\n SwapTwo(r, c, next_r, next_c);\n r = next_r;\n c = next_c;\n }\n#ifdef LOCAL\n for (int i = 0; i < N; ++i) {\n for (int j = 0; j < M; ++j)\n cerr << datax[i][j] << \"\\t\";\n cerr << \"\\n\";\n }\n#endif\n\n }\n\n vector cur_loc(N * M + 1);\n for (int i = 0; i < N; ++i)\n for (int j = 0; j < M; ++j)\n cur_loc[data_copy[i][j]] = MP(i, j);\n\n int total_len = 0;\n\n cout << SZ(cycles) << \"\\n\";\n for (auto &V : cycles) {\n cout << SZ(V);\n for (int v : V) cout << \" \" << v;\n cout << \"\\n\";\n\n vector C;\n for (int v : V)\n C.PB(cur_loc[v]);\n\n vector> new_locs;\n\n for (int i = 0; i < SZ(C); ++i) {\n const int j = V[(i + 1) % SZ(C)];\n data_copy[cur_loc[j].st][cur_loc[j].nd] = V[i];\n new_locs.emplace_back(cur_loc[j].st, cur_loc[j].nd);\n }\n\n for (auto &[r, c] : new_locs)\n cur_loc[data_copy[r][c]] = MP(r, c);\n\n#ifdef LOCAL\n for (int i = 0; i < N; ++i) {\n for (int j = 0; j < M; ++j)\n cerr << data_copy[i][j] << \"\\t\";\n cerr << \"\\n\";\n }\n#endif\n\n total_len += SZ(V);\n }\n\n cout << flush;\n\n debug(total_len);\n assert(total_len < 1e5);\n\n#ifdef LOCALX\n for (int i = 0; i < N; ++i) {\n for (int j = 0; j < M; ++j)\n cout << data_copy[i][j] << \"\\t\";\n cout << \"\\n\";\n }\n cout << flush;\n#endif\n\n for (int i = 0; i < N; ++i)\n for (int j = 0; j < M; ++j)\n assert(data_copy[i][j] == i * M + j + 1);\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "implementation"], "code_uid": "d79a83930d052cdaa3423fc45cec386b", "src_uid": "476afa2d8208ec933617c97637b65aff", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define pau system(\"pause\")\n#define ll long long\n#define pii pair\n#define pb push_back\n#define pli pair\n#define pil pair\n#define clr(a, x) memset(a, x, sizeof(a))\n\nconst double pi = acos(-1.0);\nconst int INF = 0x3f3f3f3f;\nconst int MOD = 1e9 + 7;\nconst double EPS = 1e-9;\n\n/*\n#include \n#include \nusing namespace __gnu_pbds;\n#define TREE tree, rb_tree_tag, tree_order_statistics_node_update>\nTREE T;\n*/\n\nint n, q;\nll a[200015], w[200015];\nll c1[200015], c2[200015];\ninline int lb(int x) {return x & -x;}\nvoid add1(int p, ll x) {\n\tfor (; p <= n; p += lb(p)) c1[p] += x;\n}\nll query1(int p) {\n\tll res = 0;\n\tfor (; p; p -= lb(p)) res += c1[p];\n\treturn res;\n}\nvoid add2(int p, ll x) {\n\tfor (; p <= n; p += lb(p)) {\n\t\tc2[p] += x;\n\t\tif (c2[p] >= MOD) c2[p] -= MOD;\n\t}\n}\nll query2(int p) {\n\tll res = 0;\n\tfor (; p; p -= lb(p)) res += c2[p];\n\treturn res % MOD;\n}\nint get_p(int l, int r) {\n\tll r1 = query1(l - 1);\n\tll r2 = query1(r) - r1;\n\tint mi, res = l;\n\twhile (l <= r) {\n\t\tmi = l + r >> 1;\n\t\tif ((query1(mi) - r1) * 2 >= r2) {\n\t\t\tr = (res = mi) - 1;\n\t\t} else {\n\t\t\tl = mi + 1;\n\t\t}\n\t}\n\treturn res;\n}\nll cal(int l, int r, int p) {\n\tll res1 = query2(r) - query2(p - 1) - (query1(r) - query1(p - 1)) % MOD * a[p];\n\tll res2 = (query1(p) - query1(l - 1)) % MOD * a[p] - (query2(p) - query2(l - 1));\n\treturn ((res1 + res2) % MOD + MOD) % MOD;\n}\nint main() {\n\tscanf(\"%d%d\", &n, &q);\n\tfor (int i = 1; i <= n; ++i) {\n\t\tscanf(\"%lld\", &a[i]);\n\t\ta[i] -= i;\n\t}\n\tfor (int i = 1; i <= n; ++i) {\n\t\tscanf(\"%lld\", &w[i]);\n\t}\n\tfor (int i = 1; i <= n; ++i) {\n\t\tadd1(i, w[i]);\n\t\tadd2(i, w[i] * a[i] % MOD);\n\t}\n\twhile (q--) {\n\t\tint l, r;\n\t\tscanf(\"%d%d\", &l, &r);\n\t\tif (l < 0) {\n\t\t\tadd1(-l, r - w[-l]);\n\t\t\tadd2(-l, (r - w[-l]) * a[-l] % MOD);\n\t\t\tw[-l] = r;\n\t\t} else {\n\t\t\tint p = get_p(l, r);\n\t\t\tprintf(\"%lld\\n\", cal(l, r, p));\n\t\t}\n\t}\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["data structures"], "code_uid": "568164998211178d91034dbb3e7e361f", "src_uid": "c0715f71efa327070eba7e491856d66a", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef vector VI;\ntypedef vector VVI;\ntypedef long long Long;\n#define INF 1000000000000000000LL\n\nLong SZ = 1000000000000000000LL;\nmap> mem;\nmap go(Long i, Long j){\n\tmap D;\n\tif(i+1 == j)return D;\n\tif(mem[j-i].size() != 0)return mem[j-i];\n\tLong m = (i + j) / 2;\n\tLong d = min(j - m, m - i);\n\tD[d]++;\n\tmap A = go(i, m);\n\tmap B = go(m, j);\n\tfor(const pair &p : A){\n\t\tD[p.first] += p.second;\n\t}\n\tfor(const pair &p : B){\n\t\tD[p.first] += p.second;\n\t}\n\treturn mem[j-i] = D;\n}\n\nvoid recurse(Long i, Long j, Long K, Long pp = 0){\n\tLong m = (i + j) / 2;\n\tLong d = min(m-i, j-m);\n\tmap D;\n\tmap A = go(i, m);\n\tmap B = go(m, j);\n\tfor(const pair &p : A){\n\t\tD[-p.first] += p.second;\n\t}\n\tfor(const pair &p : B){\n\t\tD[-p.first] += p.second;\n\t}\n\tD[-d]++;\n\tfor(pair p : D){\n\t\tif(-p.first != pp)continue;\n//\t\tcout << \"\\t\" << -p.first << \" \" << (A.count(-p.first) ? A[-p.first] : 0) << endl;\n\t\tif(A.count(-p.first)){\n\t\t\tif(A[-p.first] >= K){\n\t\t\t\trecurse(i, m, K, -p.first);\n\t\t\t\treturn;\n\t\t\t}else{\n\t\t\t\tK -= A[-p.first];\n\t\t\t}\n\t\t}\n\t\tif(-p.first == d){\n\t\t\tif(K == 1){\n\t\t\t\tcout << m+1 << endl;\n\t\t\t\treturn;\n\t\t\t}else{\n\t\t\t\tK--;\n\t\t\t}\n\t\t}\n//\t\tcout << \"\\t\" << -p.first << \" \" << (B.count(-p.first) ? B[-p.first] : 0) << endl;\n\t\tif(B.count(-p.first)){\n\t\t\tif(B[-p.first] >= K){\n\t\t\t\trecurse(m, j, K, -p.first);\n\t\t\t\treturn;\n\t\t\t}else{\n\t\t\t\tK -= B[-p.first];\n\t\t\t}\n\t\t}\n\t}\n}\n\n\nint main(){\n//\tfreopen(\"input.txt\", \"r\", stdin);\n\tLong K;\n\tcin >> SZ >> K;\n\tif(K == 1){\n\t\tcout << 1 << endl;\n\t\treturn 0;\n\t}\n\tif(K == 2){\n\t\tcout << SZ << endl;\n\t\treturn 0;\n\t}\n\tK -= 2;\n\tmap D = go(0, SZ-1);\n\tLong pp = 0;\n\tfor(map::reverse_iterator it = D.rbegin(); it != D.rend(); ++it){\n//\t\tcout << it->first << \" \" << it->second << endl;\n\t\tif(it->second >= K){\n\t\t\tpp = it->first;\n\t\t\tbreak;\n\t\t}else{\n\t\t\tK -= it->second;\n\t\t}\n\t}\n\trecurse(0, SZ-1, K, pp);\n\t\n\t\n\t\n}\n", "lang_cluster": "C++", "tags": ["constructive algorithms", "binary search", "implementation"], "code_uid": "89486c01787e13e91e53f8bd80ab360b", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\nint p[10]={8,-1,-1,3,6,9,4,7,0,5};\nstring s;\nint main(){\n ios::sync_with_stdio(false);\n cin>>s;\n for(int i=0;i\n\nusing std::cin;\nusing std::cout;\nusing std::cerr;\n\nusing std::vector;\nusing std::map;\nusing std::array;\nusing std::set;\nusing std::string;\nusing std::queue;\n\nusing std::pair;\nusing std::make_pair;\n\nusing std::tuple;\nusing std::make_tuple;\nusing std::get;\n\nusing std::min;\nusing std::abs;\nusing std::max;\nusing std::swap;\n\nusing std::unique;\nusing std::sort;\nusing std::generate;\nusing std::reverse;\nusing std::min_element;\nusing std::max_element;\n\n#ifdef LOCAL\n#define LASSERT(X) assert(X)\n#else\n#define LASSERT(X) {}\n#endif\n\ntemplate \nT input() {\n T res;\n cin >> res;\n LASSERT(cin);\n return res;\n}\n\ntemplate \nvoid input_seq(IT b, IT e) {\n std::generate(b, e, input::type>);\n}\n\n#define SZ(vec) int((vec).size())\n#define ALL(data) data.begin(),data.end()\n#define RALL(data) data.rbegin(),data.rend()\n#define TYPEMAX(type) std::numeric_limits::max()\n#define TYPEMIN(type) std::numeric_limits::min()\n\nint main() {\n std::iostream::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n\n // code here\n int n, k;\n cin >> n >> k;\n\n vector> arr(n);\n for (int i = 0; i < n; ++i) {\n arr[i].resize(input());\n input_seq(ALL(arr[i]));\n\n arr[i].resize(min(SZ(arr[i]), k));\n }\n\n int64_t ans = 0;\n\n vector> items(n);\n for (int i = 0; i < n; ++i) {\n items[i].second = SZ(arr[i]);\n items[i].first = std::accumulate(ALL(arr[i]), int64_t(0));\n }\n\n vector maxprofit(k + 1, TYPEMIN(int64_t));\n maxprofit[0] = 0;\n\n auto add_item = [&](int i) {\n for (int pos = k; pos >= items[i].second; --pos)\n if (maxprofit[pos - items[i].second] != TYPEMIN(int64_t))\n maxprofit[pos] = max(maxprofit[pos], maxprofit[pos - items[i].second] + items[i].first);\n };\n \n std::function go = [&](int l, int r) {\n if (l == r) {\n int64_t sm = 0;\n for (int i = 0; i < SZ(arr[l]); ++i) {\n sm += arr[l][i];\n\n if (maxprofit[k - (i + 1)] != TYPEMIN(int64_t))\n ans = max(ans, maxprofit[k - (i + 1)] + sm);\n }\n\n return;\n }\n\n auto state = maxprofit;\n int m = (l + r) / 2;\n for (int i = l; i <= m; ++i)\n add_item(i);\n\n go(m + 1, r);\n\n maxprofit = state;\n for (int i = m + 1; i <= r; ++i)\n add_item(i);\n go(l, m);\n\n maxprofit = state;\n };\n\n go(0, n - 1);\n cout << ans << \"\\n\";\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["greedy", "divide and conquer"], "code_uid": "fdad766307041d4e5b1233b7a92e92eb", "src_uid": "9e9d4f58ebd8293025ab8004aeb8d343", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#define FOR(i, to, from) for (int i=to; i> 1)) % MOD)*(b & 1 ? a : 1)) % MOD : 1; } \nll fib(ll n) {\n\tif (n==0)\n\t\treturn 0;\n\tll f1[2][2], f[2][2]={{0, 1}, {1, 1}};\n\tint ln;\n\tfor (ln=0; (n>>ln); ln++);\n\tfor (int i=ln-2; i>=0; i--) {\n\t\tf1[0][0]=(f[0][0]*f[0][0]+f[0][1]*f[1][0])%MOD;\n\t\tf1[0][1]=(f[0][0]*f[0][1]+f[0][1]*f[1][1])%MOD;\n\t\tf1[1][0]=(f[1][0]*f[0][0]+f[1][1]*f[1][0])%MOD;\n\t\tf1[1][1]=(f[1][0]*f[0][1]+f[1][1]*f[1][1])%MOD;\n\t\tif ((n>>i)%2) {\n\t\t\tf[0][0] = f1[0][1];\n\t\t\tf[0][1] = (f1[0][0]+f1[0][1])%MOD;\n\t\t\tf[1][0] = f1[1][1];\n\t\t\tf[1][1] = (f1[1][0]+f1[1][1])%MOD;\n\t\t}\n\t\telse {\n\t\t\tf[0][0] = f1[0][0]; f[0][1] = f1[0][1];\n\t\t\tf[1][0] = f1[1][0]; f[1][1] = f1[1][1];\n\t\t}\n\t}\n\treturn f[1][1];\n}\n\n\nint main () {\n\tll n, k, res=1;\n\tint l;\n\tcin >> n >> k >> l >> MOD;\n\t\n\tif ((k>=((ll) 1<0 && l<64) || MOD==1) {\n\t\tcout << '0' << endl;\n\t\treturn 0;\n\t}\n\tif (n==1) {\n\t\tcout << '1' << endl;\n\t\treturn 0;\n\t}\n\t\t\n\t\n\n\tfor (int i=0; i>i)%2)\n\t\t\tres = (res*((MOD+pot(2, n)-fib(n+1))%MOD))%MOD;\n\t\telse\n\t\t\tres = (res*fib(n+1))%MOD;\n\t}\n\tcout << res << endl;\n\t\n}\n", "lang_cluster": "C++", "tags": ["math", "combinatorics", "matrices", "implementation", "number theory"], "code_uid": "eb5e941f356495e5cc4ac5f8af54800a", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\n#include\n#include\n#include\nconst int maxn=107;\ntypedef long long LL;\n\ninline LL gcd(LL x,LL y)\n{\n\treturn !y?x:gcd(y,x%y);\n}\n\ninline LL times(LL a,LL b,LL P)\n{\n\ta%=P;\n\tb%=P;\n\tLL ret=0;\n\twhile(b){\n\t\tif(b&1){\n\t\t\tret+=a;\n\t\t\tif(ret>=P) ret-=P;\n\t\t}\n\t\ta+=a;\n\t\tif(a>=P) a-=P;\n\t\tb>>=1;\n\t}\n\treturn ret;\n}\ninline LL power(LL a,LL b,LL P)\n{\n\ta%=P;\n\tLL c=1;\n\tfor(;b;b>>=1,a=times(a,a,P))\n\t\tif(b&1) c=times(c,a,P);\n\treturn c;\n}\n\nvoid findfac(LL v, LL res[], int &cnt){\n\tfor(LL i=2;i*i<=v;++i){\n\t\twhile((v%i)==0){\n\t\t\tres[cnt++]=i;\n\t\t\tv/=i;\n\t\t}\n\t}\n\tif(v!=1) res[cnt++]=v;\n}\n\nLL M,X;\nLL facm[maxn],facr[maxn][maxn];\nint pm[maxn],pr[maxn],cntm=0,cntr[maxn];\n\nLL ans=0;\n\nvoid dfs(int p,LL u,LL phi,LL tp){\n\tif(p==cntm){\n\t\tif(u!=1) ans+=phi/tp;\n\t\treturn;\n\t}\n\n\tdfs(p+1,u,phi,tp);\n\n\tif(u!=1) assert(power(X,tp,u)==1);\n\n\tu*=facm[p];\n\tphi*=facm[p]-1;\n\tLL tt=tp*(facm[p]-1);\n\tfor(int i=0;i>M>>X;\n\tassert(gcd(M,X)==1);\n\tfindfac(M,facm,cntm);\n\tstd::sort(facm,facm+cntm);\n\t//for(int i=0;i\n#include \n#include \n#include \n#include \n#include \n \n#define ulong unsigned long long\n#define ll long long\n \nusing namespace std;\n\n\nint cnt[5001];\nll dp[5001][5001];\n\nint main() {\n int n;\n cin >> n;\n\n for (int i = 0; i < n; ++i) {\n int k;\n cin >> k;\n cnt[k]++;\n }\n\n for (int i = 2; i <= 5000; ++i) {\n for (int j = 1; j <= 5000; ++j) {\n dp[i][j] += dp[i - 1][j];\n }\n\n int v = i;\n for (int j = 2; j <= sqrt(i); ++j) {\n while (v % j == 0) {\n v /= j;\n dp[i][j]++;\n }\n }\n\n if (v > 1) \n dp[i][v]++;\n }\n\n\n ll ans = 0;\n vector best(5001, 1);\n for (int i = 0; i <= 5000; ++i) {\n if (cnt[i] == 0) {\n continue;\n }\n for (int j = 1; j <= 5000; ++j) {\n ans += dp[i][j] * cnt[i];\n if (dp[i][j] > 0) {\n best[i] = j;\n }\n }\n }\n\n\n while (*max_element(best.begin(), best.end()) > 1) {\n vector freq(5001, 0);\n\n for (int i = 0; i <= 5000; ++i) {\n freq[best[i]] += cnt[i];\n }\n\n int prime = max_element(freq.begin(), freq.end()) - freq.begin();\n int c = freq[prime];\n\n if (c * 2 <= n)\n break;\n if (prime == 1) \n break;\n\n ans -= c;\n ans += (n - c);\n\n for (int i = 0; i <= 5000; ++i) {\n if (best[i] != prime) {\n best[i] = 1;\n }\n else {\n dp[i][best[i]] -= 1;\n while(best[i] > 1 && dp[i][best[i]] == 0) {\n best[i]--;\n }\n }\n \n }\n \n }\n\n cout << ans << endl;\n \n}\n", "lang_cluster": "C++", "tags": ["math", "trees", "dp", "graphs", "number theory"], "code_uid": "15a93ed264a23b17bd9f883b4de08b4a", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include\nusing namespace std;\n#define fi first\n#define se second\n#define pb push_back\n#define mp make_pair\n#define rep(i, a, b) for(int i = (a); i < (b); ++i)\n#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)\n#define sz(a) (int)a.size()\n#define de(a) cout << #a << \" = \" << a << endl\n#define dd(a) cout << #a << \" = \" << a << \" \"\n#define all(a) a.begin(), a.end()\n#define pw(a) (1ll<<(x))\n#define endl \"\\n\"\ntypedef long long ll;\ntypedef double db;\ntypedef pair pii;\ntypedef vector vi;\n//----\nconst int mod = 1e9 + 7, N = 1e6 + 5;\nint c[5];\nint dp[N] = {1, 1, 2};\nint add(int a, int b) {\n\tint res = a + b;\n\tif(res >= mod)res -= mod;\n\treturn res;\n}\nint mul(int a, int b) {\n\treturn a * b % mod;\n}\nint main() {\n\tint n; cin >> n;\n\trep(i, 0, n) {\n\t\tint x; cin >> x; c[x]++;\n\t}\n\tdp[1] = 1;\n\trep(i, 3, c[1] + 1)dp[i] = add(dp[i - 1], mul((i - 1), dp[i - 2]));\n\trep(i, n - c[2] + 1, n + 1)dp[c[1]] = mul(dp[c[1]], i);\n\tcout << dp[c[1]] << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["brute force", "dp"], "code_uid": "7eb6dfc2de6db7f539d33f85b3197781", "src_uid": "91e8dbe94273e255182aca0f94117bb9", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\nchar S[100010],T[100010];\nint nS,nT,cS[100010][2],cT[100010][2],laS[100010],laT[100010];\nint chk(int lS,int rS,int lT,int rT){\n\tint bS=cS[rS][1]-cS[lS][1],\n\t\tbT=cT[rT][1]-cT[lT][1];\n\tif(bT=at&&(as-at)%3==0;\n\t\treturn as>=at;\n\t}\n\tint as=rS-lS;\n\tint at=rT-lT; //\n\tif(bT)\n\t{\n\t\tint at=rT-laT[rT];\n\t return as>at;\n\t}\n\t //\n\treturn as>=at &&!((as-at)%3);//bzoj // () //ll -4 //() //(-(a))\n} //() //&& !// //_\nint main(){\n\tscanf(\"%s%s\",S,T);\n\twhile(S[nS])nS++;\n\twhile(T[nT])nT++;\n\tlaS[0]=laT[0]=0;\n\tfor(int i=0;i\nint main()\n{\n double d,l,v1,v2,sum,store,ans;\n scanf(\"%lf %lf %lf %lf\",&d,&l,&v1,&v2);\n store = v1+v2;\n if(l>d)\n sum=l-d;\n else\n sum = d-l;\n ans=sum/(v1+v2);\n printf(\"%lf\",ans);\n}\n", "lang_cluster": "C++", "tags": ["math"], "code_uid": "9e768a7998b0d0d49d122fdc1d711e5b", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n \n#define ME(s) memset((s), 0, sizeof((s)))\n#define MM(s,a) memset((s),(a),sizeof((s)))\n#define MCP(s,a) memcpy((s), (a), sizeof(s))\n#define LL long long\n#define LD long double\n#define PII pair\n#define PLL pair\n#define PDD pair\n#define mkp(a,b) make_pair((a),(b))\n#define y first\n#define x second\n#define sqr(a) ((a)*(a))\n#define lowbit(x) ((x)&(-(x)))\n#define two(x) (1<<(x))\n#define contain(mask,x) (((mask)&two(x))!=0)\n \n//#define OFFLINEJUDGE\n#ifdef OFFLINEJUDGE\nFILE *fin=freopen(\"a.in\",\"r\",stdin);\nFILE *fout=freopen(\"a.out\",\"w\",stdout);\n#else\nFILE *fin=stdin;\nFILE *fout=stdout;\n#endif\n\nint f[1<<19];\n\nint to[20][6];\n\nint get(int mask){\n\tint &ret=f[mask];\n\tif(ret>-1)\n\t\treturn ret;\n\tret=0;\n\tfor(int i=0;i<19;i++)\n\t\tif(mask&(1<\n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define tr(i, x) for (typeof(x.begin()) i = x.begin(); i != x.end(); ++ i)\n#define rep(i, n) for (int i = 0; i < n; ++ i)\n#define pii pair \n#define mp make_pair\n#define x first\n#define y second\n#define pb push_back\n#define ll long long\n\n#define CharSet 26\n#define Mod 12345\n\nclass Matrix: public vector < vector >\n{\n private:\n Matrix(int n, vector a)\n {\n this->clear();\n rep (i, n)\n pb(a);\n }\n public:\n Matrix()\n {\n this->clear();\n }\n Matrix(int n, int m)\n {\n this->clear();\n *this = Zero(n, m);\n }\n Matrix Zero(int n, int m)\n {\n return Matrix (n, vector (m, 0));\n }\n Matrix One(int n)\n {\n Matrix res(n, n);\n rep (i, n)\n res[i][i] = 1;\n return res;\n }\n Matrix operator * (const Matrix &b)\n {\n Matrix c;\n if (rows() == b.lines())\n {\n int u = lines();\n int v = rows();\n int w = b.rows();\n c = Zero(u, w);\n rep (i, u)\n rep (j, v)\n rep (k, w)\n {\n c[i][k] += (*this)[i][j] * b[j][k];\n c[i][k] %= Mod;\n }\n }\n else\n cerr << \"error occurred at \" << __LINE__ << endl;\n return c;\n }\n Matrix pow(ll n)\n {\n Matrix res;\n if (lines() == rows())\n {\n int l = lines();\n res = res.One(l);\n Matrix tmp(*this);\n for (int i = 0; (n >> i) > 0; ++ i)\n {\n if ((n & (1LL << i)) > 0)\n res = res * tmp;\n tmp = tmp * tmp;\n }\n }\n else\n cerr << \"error occurred at \" << __LINE__ << endl;\n return res;\n }\n size_type lines() const\n {\n return size();\n }\n size_type rows() const\n {\n return (size() == 0) ? 0 : (*this)[0].size();\n }\n};\n\nll N;\nint C;\nbool Appear[CharSet], isOne[CharSet];\n\nint main()\n{\n cin >> N >> C;\n fill(Appear, Appear + CharSet, 0);\n fill(isOne, isOne + CharSet, 0);\n vector cd;\n cd.clear();\n rep (i, C)\n {\n char Ch;\n int t;\n cin >> Ch >> t;\n Appear[Ch - 'A'] = 1;\n if (t != 1)\n cd.pb(mp(Ch - 'A', t));\n else\n isOne[Ch - 'A'] = 1;\n }\n vector pd;\n pd.clear();\n int cds = cd.size();\n pd.pb(1);\n rep (i, cds)\n pd.pb(pd.back() * cd[i].y);\n int matsize = pd.back();\n Matrix mat(matsize, matsize);\n rep (i, matsize)\n {\n rep (ch, 26)\n if (Appear[ch])\n {\n int target = i;\n rep (k, cds)\n if (cd[k].x == ch)\n {\n if ((target % pd[k + 1]) / pd[k] == cd[k].y - 1)\n target -= (cd[k].y - 1) * pd[k];\n else\n target += pd[k];\n }\n ++ mat[i][target];\n }\n }\n mat = mat.pow(N);\n ll ans = 0;\n rep (i, matsize)\n {\n bool Flag = 1;\n rep (ch, 26)\n if (Appear[ch] && !isOne[ch])\n {\n bool Satisfy = 0;\n bool Exist = 0;\n rep (k, cds)\n if (cd[k].x == ch)\n {\n Exist = 1;\n if ((i % pd[k + 1]) / pd[k] == 0)\n Satisfy = 1;\n }\n if (Exist && !Satisfy)\n {\n Flag = 0;\n break;\n }\n }\n if (Flag)\n ans = (ans + mat[0][i]) % Mod;\n }\n cout << ans << endl;\n return 0;\n}", "lang_cluster": "C++", "tags": ["matrices", "dp", "graphs"], "code_uid": "7390cd24507d9d685627ac60657d26b8", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\nconst int maxN = 200'010;\nint a[maxN];\nint cnt[maxN];\nint sumx[maxN];\nint presum[maxN];\nint first_pos[maxN*2];\nint n, x, ans, M;\nvector pos[maxN];\n\nint find_most()\n{\n int res = 0;\n for (int i = 1; i <= n; i++)\n if (cnt[i] > cnt[res])\n res = i;\n return res;\n}\nbool ans_is_n()\n{\n int res = 0;\n for (int i = 1; i <= n; i++)\n if (cnt[i] == cnt[x])\n res++;\n return res >= 2;\n}\nint fun2(int t)\n{\n int res = 0;\n for (int i = 1; i <= n; i++)\n {\n presum[i] = presum[i-1];\n if (a[i] == x) presum[i]++;\n if (a[i] == t) presum[i]--;\n }\n for (int i = 0; i <= 2*n; i++) first_pos[i] = n + 1;\n first_pos[n] = 0;\n for (int i = 1; i <= n; i++)\n {\n res = max(res, i - first_pos[presum[i] + n]);\n first_pos[presum[i] + n] = min(first_pos[presum[i] + n], i);\n }\n return res;\n}\nint main()\n{\n scanf(\"%d\", &n);\n M = min((int) sqrt(n) - 3, 500);\n for (int i = 1; i <= n; i++)\n {\n scanf(\"%d\", &a[i]);\n pos[a[i]].push_back(i);\n cnt[a[i]]++;\n }\n x = find_most();\n for (int i = 1; i <= n; i++)\n sumx[i] = sumx[i-1] + (int)(a[i] == x);\n if (ans_is_n())\n {\n printf(\"%d\\n\", n);\n return 0;\n }\n for (int i = 1; i <= min(n, 100); i++)\n {\n if (i == x) continue;\n ans = max(ans, fun2(i));\n }\n printf(\"%d\\n\", ans);\n return 0;\n}", "lang_cluster": "C++", "tags": ["greedy", "data structures"], "code_uid": "1e102e110879597bb8ed8fab7101066d", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\nusing namespace std;\n\nconst int N = 2e5 + 7;\n\nvector < int > ga[N], gb[N];\n\nbool usa[N];\nbool findb = false;\nint cnta = 0;\n\nvoid dfsa(int v, int b){\n usa[v] = true;\n if(v == b) findb = true;\n ++cnta;\n for(int to : ga[v]){\n if(usa[to]) continue;\n dfsa(to, b);\n }\n}\n\nbool usb[N];\nbool finda = false;\nint cntb = 0;\n\nvoid dfsb(int v, int a){\n usb[v] = true;\n if(v == a) finda = true;\n ++cntb;\n for(int to : gb[v]){\n if(usb[to]) continue;\n dfsb(to, a);\n }\n}\n\nvoid solve(){\n int n, m, a, b;\n cin >> n >> m >> a >> b;\n --a; --b;\n for(int i = 0; i < m; ++i){\n int x, y; cin >> x >> y;\n --x; --y;\n if(x != a && y != a){\n ga[x].push_back(y);\n ga[y].push_back(x);\n }\n if(x != b && y != b){\n gb[x].push_back(y);\n gb[y].push_back(x);\n }\n }\n\n long long sum = 0;\n for(int i = 0; i < n; ++i){\n if(usa[i] == false && i != a){\n dfsa(i, b);\n if(!findb) sum += cnta;\n findb = false; cnta = 0;\n }\n }\n long long ans = 0;\n for(int i = 0; i < n; ++i){\n if(usb[i] == false && i != b){\n dfsb(i, a);\n if(!finda) ans += cntb * sum;\n finda = false; cntb = 0;\n }\n }\n\n cout << ans << endl;\n\n for(int i = 0; i < n; ++i){\n usa[i] = false;\n usb[i] = false;\n ga[i].clear();\n gb[i].clear();\n }\n}\n\nint main()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr); cout.tie(nullptr);\n\n int t;\n cin >> t;\n\n while(t--){\n solve();\n }\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "graphs"], "code_uid": "71a6ecf65653c590adcaec646190cda2", "src_uid": "7636c493ad91210ec7571895b4b71214", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#include \n//#include \n\n\n#define endl '\\n' \n#define pb push_back \n#define fi first \n#define se second \n#define pll pair \n#define all(v) v.begin(), v.end() \n\nusing namespace std;\n\ntypedef long long int ll;\n\nmt19937 rnd(1337);\n\nostream& operator<< (ostream& a, const pll b) {\n cout << \"{\" << b.first << \", \" << b.second << \"}\";\n return a;\n}\n\nostream& operator<< (ostream& a, const vector& b) {\n for (auto& k : b) cout << k << \" \";\n return a;\n}\n\nostream& operator<< (ostream& a, const vector& b) {\n for (auto& k : b) cout << k << \" \";\n return a;\n}\n\n#ifdef HOME \n#define dbg(x) cout << #x << \" : \" << (x) << '\\n';\n#else\n#define dbg(x)\n#endif \n\nconst ll INF = (ll)1e18;\nconst ll MOD = 1000 * 1000 * 1000 + 7, MOD2 = 274876858367;\nconst ll maxn = (ll)1e6 + 10, L = 22;\nconst double pi = 3.14159265358979;\n\nint main() {\n#ifdef HOME \n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#else \n ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n //freopen(\"input.txt\", \"r\", stdin); \n //freopen(\"output.txt\", \"w\", stdout); \t\n#endif\n ll n, k;\n cin >> n >> k;\n vector c(n);\n for (ll i = 0; i < n; ++i) {\n cin >> c[i];\n }\n sort(all(c));\n vector> ans(k + 1);\n ll kek = 0, lst = n - 1;\n for (ll i = n - 1; i >= 0; --i) {\n if (kek + c[i] >= 0) {\n ans[0].pb(c[i]);\n lst = i;\n kek += c[i];\n } else {\n break;\n }\n }\n ll now = 0;\n for (ll i = 0; i < lst; ++i) {\n ans[now].pb(c[i]);\n now = (now + 1) % ans.size();\n }\n ll res = 0;\n for (auto& x : ans) {\n sort(all(x));\n now = 0;\n for (ll y : x) {\n res += y * now;\n ++now;\n }\n }\n cout << res << endl;\n return 0;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "C++", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "42fc1fed2a15b82d3a7fa31a3cbf8aa9", "src_uid": "53155daf2375e01a3b87fa1c76f1e9a8", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n\n#define LL long long\n#define N 1000002\n#define M 1000100\n#define MP make_pair\n#define Pi acos(-1.0)\n//#pragma comment(linker,\"/STACK:1024000000,1024000000\")\n#define ls (rt << 1)\n#define rs (ls | 1)\n#define md ((ll+rr)/2)\n#define lson ll, md, ls\n#define rson md+1, rr, rs\n#define mod 1000000007\n#define inf 0x3f3f3f3f\n#define sqr(x) ((x)*(x))\n#define eps 1e-6\n#define uLL unsigned long long\n#define ui unsigned int\nLL powmod(LL a,LL b) {LL res=1;for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}\n#define F(x) ((x)/3+((x)%3 == 1 ? 0 : tb))\n#define G(x) ((x)\n#define pli pair\n#define pb push_back\n#define MP make_pair\nLL gcd(LL x,LL y){\n while(y){\n LL t = x % y;\n x = y;\n y = t;\n }\n return x;\n}\n\ntemplate inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }\ntemplate inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }\n\nui read()\n{\n ui x=0,f=1;char ch=getchar();\n while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}\n while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}\n return x*f;\n}\n\nint n, tot, dfn[N], fa[N][20], ed[N], dep[N];\nint bel[N], belong[N];\nvector g[N];\n\n\nvoid dfs(int u, int id)\n{\n\tbel[u] = id;\n\tdfn[u] = ++tot;\n\tfor(int i = 1; i < 20; i++)\n\t{\n\t\tfa[u][i] = fa[fa[u][i - 1]][i - 1];\n\t}\n\tfor(auto v : g[u])\n\t{\n\t\tif(v == fa[u][0]) continue;\n\t\tfa[v][0] = u;\n\t\tdep[v] = dep[u] + 1;\n\t\tdfs(v, id);\n\t}\n\ted[u] = tot;\n}\n\nint lca(int u, int v)\n{\n\tif(bel[u] != bel[v]) return -1;\n\tif(dep[u] > dep[v]) swap(u, v);\n\tfor(int i = 0; dep[u] != dep[v]; i++)\n\t\tif((dep[v] - dep[u]) >> i & 1) v = fa[v][i];\n\tif(u == v) return v;\n\tfor(int i = 19; i >= 0; i--)\n\t\tif(fa[u][i] != fa[v][i])\n\t\t{\n\t\t\tu = fa[u][i];\n\t\t\tv = fa[v][i];\n\t\t}\n\treturn fa[u][0];\n}\n\ninline bool cmp(int i, int j){return dfn[i] < dfn[j];}\n\nstruct BCC\n{\n\tint fst[N], nxt[M], vv[M], e;\n\tint n, belong[N], dfn[N], low[N], stk[N], tot, in[N];\n\tvoid init()\n\t{\n\t\te = 0;\n\t\tmemset(fst, -1, sizeof fst);\n\t\tmemset(dfn, -1, sizeof dfn);\n\t}\n\n\tvoid add(int u, int v)\n\t{\n\t\tvv[e] = v, nxt[e] = fst[u], fst[u] = e++;\n\t\tvv[e] = u, nxt[e] = fst[v], fst[v] = e++;\n\t}\n\n\n\tvoid dfs(int u, int f = -1)\n\t{\n\t\tint tmp = tot;\n\t\tstk[dfn[u] = low[u] = tot++] = u;\n\t\tin[u] = 1;\n\t\tfor(int i = fst[u]; ~i; i = nxt[i])\n\t\t{\n\t\t\tif(i == f) continue;\n\t\t\tint v = vv[i];\n\t\t\tif(dfn[v] == -1) dfs(v, i ^ 1), chkmin(low[u], low[v]);\n\t\t\telse if(in[v]) chkmin(low[u], dfn[v]);\n\t\t}\n\t\tif(dfn[u] == low[u])\n\t\t{\n\t\t\twhile(tot != tmp)\n\t\t\t{\n\t\t\t\ttot--;\n\t\t\t\tin[stk[tot]] = 0;\n\t\t\t\tbelong[stk[tot]] = n;\n\t\t\t}\n\t\t\tn++;\n\t\t}\n\t}\n}bcc;\n\nint stk[N];\n\nint main()\n{\n\tn = read();\n\tint m = read(), q = read();\n\tbcc.init();\n\tvector< pii > E;\n\tfor(int i = 0; i < m; i++)\n\t{\n\t\tint u = read(), v = read();\n\t\tbcc.add(u, v);\n\t\tE.pb(MP(u,v));\n\t}\n\tbcc.n = bcc.tot = 1;\n\tfor(int i = 1; i <= n; i++)\n\t\tif(bcc.dfn[i] == -1) bcc.dfs(i);\n\tfor(int i = 1; i <= n; i++)\n\t{\n\t\tbelong[i] = bcc.belong[i];\n\t}\n\t\n\tfor(auto x : E)\n\t{\n\t\tint u = x.fi, v = x.se;\n\t\tif(belong[u] != belong[v])\n\t\t{\n\t\t\tg[belong[u]].pb(belong[v]), g[belong[v]].pb(belong[u]);\n\t\t}\n\t}\n\n\tfor(int i = 1; i <= n; i++)\n\t\tif(!dfn[i]) dfs(i, i);\n\n\tint R = 0, id = 1;\n\tfor(; q; q--, id++)\n\t{\n\t\tint nn = read(), mm = read();\n\t\tvector x;\n\t\tx.resize(nn);\n\t\tfor(int i = 0; i < nn; i++)\n\t\t{\n\t\t\tx[i] = (read() + R) % n, x[i] = belong[x[i] == 0 ? n : x[i]];\n\t\t}\n\t\tvector< pii > ee;\n\t\tvector< int > V(x);\n\t\tfor(int i = 0 ; i < mm; i++)\n\t\t{\n\t\t\tint u = (read() + R) % n, v = (read() + R) % n;\n\t\t\tu = belong[u == 0 ? n : u], v = belong[v == 0 ? n : v];\n\t\t\tee.pb(MP(u, v));\n\t\t\tV.pb(u) , V.pb(v);\n\t\t}\n\t\tsort(V.begin(), V.end(), cmp);\n\t\tnn = V.size();\n\t\tfor(int i = 0; i < nn - 1; i++)\n\t\t{\n\t\t\tif(V[i] == V[i + 1]) continue;\n\t\t\tint lc = lca(V[i], V[i + 1]);\n\t\t\tif(lc > 0) V.pb(lc);\n\t\t}\n\t\tsort(V.begin(), V.end(), cmp);\n\t\tV.resize(unique(V.begin(), V.end()) - V.begin());\n\t\tnn = V.size();\n\t\t\n\t\tfor(int i = 0; i < nn; i++)\n\t\t\tbcc.fst[V[i]] = -1; bcc.e = 0;\n\t\ttot = 0;\n\t\tfor(int i = 0; i < nn; i++)\n\t\t{\n\t\t\tint u = V[i];\n\t\t\twhile(tot && !(dfn[stk[tot - 1]] <= dfn[u] && dfn[u] <= ed[stk[tot - 1]])) tot--;\n\t\t\tif(tot) { bcc.add(u, stk[tot - 1]);}\n\t\t\tstk[tot++] = u;\n\t\t}\n\t\tfor(auto u : ee)\n\t\t\tbcc.add(u.fi, u.se);\n\t\tbcc.tot = bcc.n = 1;\n\t\tfor(int i = 0; i < nn; i++) bcc.dfn[V[i]] = -1;\n\t\tfor(int i = 0; i < nn; i++)\n\t\t\tif(bcc.dfn[V[i]] == -1) bcc.dfs(V[i]);\n\t\tbool ans = 1;\n\t\t\n\t\tfor(int i = 1; i < x.size(); i++)\n\t\t\tif(bcc.belong[x[i]] != bcc.belong[x[0]]) \n\t\t\t{\n\t\t\t\tans = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tputs(ans ? \"YES\" : \"NO\");\n\t\tR = (R + (ans ? id : 0)) % n;\n\t}\n\treturn 0;\n\n}", "lang_cluster": "C++", "tags": ["trees", "graphs"], "code_uid": "c420f11f8b74ed109864f5437b1df5ed", "src_uid": "53f64841886b32816eadce278e636bbc", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define endl \"\\n\"\n#define mp make_pair\n#define int long long\n#define pii pair\ninline int in(){int32_t x ; scanf(\"%d\",&x) ; return x ;}\ninline string getStr(){char ch[500001] ; scanf(\"%s\",ch) ;return ch;}\nconst int MAX_N = 2e5 + 10;\ninline int gcd( int a, int b ) { return b == 0 ? a : gcd( b, a%b ); }\nvector g[MAX_N];\nbool del[MAX_N] , forb[MAX_N] , mark[MAX_N];\nint a[MAX_N] , dp[MAX_N] , ln , vl[MAX_N] , deg[MAX_N];\nqueue Bomb ; int n , k;\ninline void BombProcess()\n{\n for (int i = 1 ; i <= n ; i ++) if (deg[i] == 1 && !forb[i]) Bomb.push(i);\n while (Bomb.size()){\n int first = Bomb.front(); Bomb.pop();\n deg[first] --;\n del[first] = true;\n int FIND = -1;\n for (auto u : g[first]){\n if (!del[u] && !forb[u]){\n FIND = u;\n break;\n }\n }\n if (FIND != -1){\n vl[FIND] += vl[first];\n deg[FIND] --;\n if (deg[FIND] == 1)\n Bomb.push(FIND);\n }\n ln = max(ln , vl[first]);\n vl[first] = 0;\n }\n}\n\ninline void dfs(int v , int pr){\n \n mark[v] = true;\n dp[v] = vl[v];\n int f1 = 0 , f2 = 0 ;\n for (auto u : g[v]){\n if (!forb[u] && (u - pr)){\n dfs(u , v);\n if (dp[u] > f1){\n f2 = f1;\n f1 = dp[u];\n }\n else{\n f2 = max(f2 , dp[u]);\n }\n }\n }\n \n ln = max(ln , dp[v] + f2 + f1);\n dp[v] += f1;\n}\ninline bool can(int low){\n ln = 0;\n for (int i = 1 ; i <= n ; i ++){\n mark[i] = 0;\n deg[i] = g[i].size();\n dp[i] = 0;\n del[i] = 0 ;\n mark[i] = 0 ;\n vl[i] = 1;\n forb[i] = (a[i] < low);\n }\n BombProcess();\n for (int i = 1 ; i <= n ; i ++)if (!mark[i] && !forb[i]) dfs(i , -1);\n return ln >= k;\n}\nint32_t main()\n{\n n = in() , k = in();\n for (int i = 0 ; i < n ; i ++) a[i + 1] = in();\n for (int i = 0 ; i < n - 1 ; i ++){\n int v = in() , u = in();\n g[v].push_back(u);\n g[u].push_back(v);\n \n }\n int l = 0 , r = (1 << 20) , best = 0 , mid;\n while (l <= r){\n mid = (l + r) >> 1;\n if (can(mid)) {best = mid ; l = mid + 1 ; continue ; }\n r = mid - 1;\n }\n cout << best << \"\\n\";\n}", "lang_cluster": "C++", "tags": ["dfs and similar", "greedy", "binary search", "graphs"], "code_uid": "c561ca2f393f9c97b7b618f7b1dc9323", "src_uid": "4fb83b890e472f86045981e1743ddaac", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#pragma comment(linker, \"/STACK:16777216\")\n#pragma warning(disable:4786)\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define MAX_SIZE 100100\n#define MAX_LENGTH 100100\n#define INF ( 1 << 29 );\n\n#define CLR( a ) memset( a , NULL , sizeof( a ) )\n#define MEM( a ) memset( a , -1 , sizeof( a ) )\n#define fort( a , b ) for( ind = ( a ); ind <= ( b ); ind++ )\n#define foriab( a , b ) for( i = ( a ); i < ( b ); i++ )\n#define fori( a ) for( i = 0; i < ( a ); i++ )\n#define forj( a ) for( j = 0; j < ( a ); j++ )\n#define print1( a ) printf( \"%d ---\\n\" , ( a ) )\n#define print2( a , b ) printf( \"%d %d ---\\n\" , ( a ) , ( b ) )\n\ntypedef __int64 lll ;\n\nint MIN( int a , int b ) { return a < b ? a : b ; }\nint MAX( int a , int b ) { return a > b ? a : b ; }\nint GCD( int a , int b ) { while( b ) b ^= a ^= b ^= a %= b ; return a ; }\nint LCM( int a , int b ) { return a * ( b / GCD( a , b ) ) ; }\nvoid SWAP( int &a , int &b ) { a = a ^ b ; b = a ^ b ; a = a ^ b ; }\n\nconst double PI = acos( -1 ) ;\nconst double EPS = 1e-11 ;\n\nstruct st {\n int b , s , r ;\n} arr[ 111 ][ 111 ] ;\n\nstruct ss {\n int p , in ;\n bool operator() ( const ss &a , const ss &b ) {\n return a.p > b.p ;\n }\n} prof[ 111 ] , cmp ;\nint N , M , K , mask , memo[ 11 ][ 111 ] ;\n\nint dp( int i , int j ) {\n if( i >= N ) { return 0 ; }\n if( j >= M ) {\n return dp( i + 1 , 0 ) ;\n }\n int &ret = memo[ i ][ j ] ;\n if( ret != -1 ) {\n return ret ;\n }\n int res , k , l ;\n res = 0 ;\n int ma = -INF ;\n if( ( mask & ( 1 << i ) ) == 0 ) {\n for( k = 0 ; k < N ; k++ ) {\n if( k != i ) {\n ma = MAX( ma , arr[ k ][ j ].s ) ;\n }\n }\n for( l = 0 ; l <= arr[ i ][ j ].r ; l++ ) {\n int cost = arr[ i ][ j ].b * l ;\n if( l <= ma ) {\n int a = ma * l - cost ;\n if( a > 0 ) {\n res += a ;\n }\n }\n else {\n break ;\n }\n }\n }\n res += dp( i , j + 1 ) ;\n //printf( \"%d %d :: %d\\n\" , i , j , res ) ;\n return ret = res ;\n}\n\nint main() {\n //freopen( \"C.in\" , \"r\" , stdin ) ;\n\t//freopen( \"out.txt\" , \"w\" , stdout ) ;\n\tint T , res , n , i , ind , m , k , j , l ;\n\twhile( scanf( \"%d%d%d\" , &n , &m , &k ) != EOF ) {\n\t K = k ;\n\t N = n ;\n\t M = m ;\n CLR( arr ) ;\n res = 0 ;\n fori( n ) {\n char brr[ 200 ] ;\n scanf( \"%s\" , &brr ) ;\n forj( m ) {\n scanf( \"%d%d%d\" , &arr[ i ][ j ].b , &arr[ i ][ j ].s , &arr[ i ][ j ].r ) ;\n }\n }\n /*fori( n ) {\n forj( m ) {\n printf( \"%d %d %d\\n\" , arr[ i ][ j ].b , arr[ i ][ j ].s , arr[ i ][ j ].r ) ;\n }\n printf( \"========================\\n\" ) ;\n }*/\n res = 0 ;\n for( i = 0 ; i < n ; i++ ) {\n for( l = 0 ; l < n ; l++ ) {\n if( i != l ) {\n k = K ;\n int re = 0 ;\n forj( m ) {\n int sell = arr[ l ][ j ].s ;\n int buy = arr[ i ][ j ].b ;\n if( sell > buy ) {\n prof[ j ].p = ( sell - buy ) ;\n }\n else {\n prof[ j ].p = 0 ;\n }\n prof[ j ].in = arr[ i ][ j ].r ;\n }\n sort( prof , prof + m , cmp ) ;\n forj( m ) {\n if( i == 0 && l == 1 ) {\n //print2( prof[ j ].p , prof[ j ].in ) ;\n }\n if( k < prof[ j ].in ) {\n re += ( k * prof[ j ].p ) ;\n }\n else {\n re += ( prof[ j ].in * prof[ j ].p ) ;\n }\n k -= prof[ j ].in ;\n if( k <= 0 ) { break ; }\n }\n res = MAX( res , re ) ;\n }\n }\n }\n\t\tprintf( \"%d\\n\" , res ) ;\n\t}\n\treturn 0 ;\n}\n\n\n/*bambhbdjgmlnhqsshhfpsnhftteroephehidadfgpilpebfdik*/", "lang_cluster": "C++", "tags": ["greedy", "games", "graph matchings"], "code_uid": "55233e0b6285bfb5a37455eb5a7d6c50", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#define max(a,b) (a>b?a:b)\n#define min(a,b) (a'9'){if(ch=='-')pd=-pd;ch=getchar();}\n\twhile(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}\n\tx*=pd;\n}\ninline void write(const int &x)\n{\n\tchar ggg[10001];int s=0;int tmp=x;\n\tif(tmp==0){putchar('0');return;}\n\tif(tmp<0){tmp=-tmp;putchar('-');}\n\twhile(tmp>0){ggg[s++]=tmp%10+'0';tmp/=10;}\n\twhile(s>0){putchar(ggg[--s]);}\n}\n\ninline void wrl(const int &x)\n{\n\twrite(x);\n\tputchar('\\n');\n}\n\ninline void wrs(const int &x)\n{\n\twrite(x);\n\tputchar(' ');\n}\n\ninline int F(int x)\n{\n\tint ans=0;\n\tfor(;!(x&1);x>>=1)++ans;\n\treturn ans;\n} \n\n\nint n,x,p;\nint k;\ndouble f[500][500];\n\nint main()\n{\n\tread(x);\n\tread(k);\n\tread(p);\n\tdouble p2=p/100.0;\n\tdouble p1=1-p2;\n\tfor(register int i=0;i<=k;++i)\n\t{\n\t\tf[0][i]=F(x+i);\n\t}\n\tfor(register int i=0;i\nusing namespace std;\n\nint dx[] = {1 , -1 , 0 , 0};\nint dy[] = {0 , 0 , 1 , -1};\n#define ll long long\n#define vi vector \n#define pi pair< int , int >\n#define pl pair< ll , ll >\n#define pii pair< pi , int >\n#define fr first\n#define sc second\n#define pb push_back\n#define FOR(i,a,b) for(ll i=a;i 0 && s[i] != s[k])\n k = ret[k-1];\n if(s[i] == s[k])k++;\n ret[i] = k;\n }\n\n for(int i = 0 ; i < s.size() ; i++)\n for(int j = 0 ; j < 26 ; j++)\n kmp[i][j] = ( j == s[i] - 'A' ? i+1 : i > 0 ? kmp[ret[i-1]][j] : 0);\n\n for(int j = 0 ; j < 26 ; j++)kmp[s.size()][j] = s.size();\n}\nint main()\n{\n cin >> a >> b >> s;\n preffixFunc(s);\n memset(dp,-1,SZ(dp));\n get_path();\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["strings", "dp"], "code_uid": "fac48cba7904912395c9758bfe214401", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n\nusing namespace std;\n\nint read(){\n int x = 0; int zf = 1; char ch = ' ';\n while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();\n if (ch == '-') zf = -1, ch = getchar();\n while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;\n}\n\n//const double eps = 1e-15;\nconst double PI = 3.141592653589793238462643383279502; //acos(-1);\n\nint main(){\n int n = read(), r = read(), v = read();\n //int n, r, v; scanf(\"%d %d %d\", &n, &r, &v);\n while (n--){\n int s = read(), f = read();\n //int s, f; scanf(\"%d %d\", &s, &f);\n double len = f - s; double c = PI * r * 2; int cnt = len / c; double ans = c * cnt / v;\n len -= c * cnt; len /= 2;\n double L = 0, R = len, mid;\n for (int i = 1; i <= 100; ++i){\n mid = (L + R) / 2;\n if (mid + r * sin(mid / r) >= len) R = mid;\n else L = mid;\n }\n ans += 2 * L / v;\n printf(\"%.9f\\n\", ans);\n }\n return 0;\n}//hellobig_tq", "lang_cluster": "C++", "tags": ["geometry"], "code_uid": "f34e7bfc0e09941471be259b9d922895", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n\nusing namespace std;\n\n#define ll \t\tlong long\n#define mp \t\tmake_pair\n#define sz(v) \t(int)v.size()\n#define pb \tpush_back\n#define b_p(n)\t\t__builtin_popcount(n)\n#define s second\n#define f first\n\nint const mxsz = 1000009;\nbool vis1[mxsz], vis2[mxsz];\n\nll reach(ll h1, ll x1, ll y1, ll a1, ll m) {\n\tmemset(vis1, 0, sizeof(vis1));\n\tint t = 0;\n\twhile (!vis1[h1]) {\n\t\tvis1[h1] = 1;\n\t\tif (h1 == a1)\n\t\t\treturn t;\n\t\th1 = (x1 * h1 + y1) % m;\n\t\tt++;\n\t}\n\treturn -1;\n}\nll takestoreachgoalagain(ll h1, ll x1, ll y1, ll a1, ll m) {\n\tll t = 0;\n\th1 = a1;\n\tmemset(vis1, 0, sizeof(vis1));\n\twhile (true) {\n\t\tvis1[h1] = 1;\n\t\tif (t != 0 && h1 == a1)\n\t\t\treturn t;\n\t\th1 = (x1 * h1 + y1) % m;\n\t\tt++;\n\t\tif (t > mxsz + 10)\n\t\t\treturn -1;\n\t}\n\treturn -1;\n}\nint main() {\n\tll m, h1, a1, x1, y1, h2, a2, x2, y2;\n\tcin >> m >> h1 >> a1 >> x1 >> y1 >> h2 >> a2 >> x2 >> y2;\n\tll t1 = reach(h1, x1, y1, a1, m);\n\tll t2 = reach(h2, x2, y2, a2, m);\n\tif (t1 == t2 && t1 != -1)\n\t\tcout << t1 << endl;\n\n\telse if (t1 == -1 || t2 == -1)\n\t\tcout << -1 << endl;\n\telse {\n\t\tll cyc1 = takestoreachgoalagain(h1, x1, y1, a1, m);\n\t\tll cyc2 = takestoreachgoalagain(h2, x2, y2, a2, m);\n\t\tif (cyc1 == -1 && cyc2 == -1)\n\t\t\tcout << -1 << endl;\n\t\telse if (cyc1 == -1) {\n\t\t\tif (t1 > t2) {\n\t\t\t\tll T = t1 - t2;\n\t\t\t\tif ((T + t2) % cyc2 == 0)\n\t\t\t\t\tcout << t1 << endl;\n\t\t\t\telse\n\t\t\t\t\tcout << -1 << endl;\n\t\t\t} else\n\t\t\t\tcout << -1 << endl;\n\t\t} else if (cyc2 == -1) {\n\t\t\tif (t2 > t1) {\n\t\t\t\tll T = t2 - t1;\n\t\t\t\tif ((T + t1) % cyc1 == 0)\n\t\t\t\t\tcout << t2 << endl;\n\t\t\t\telse\n\t\t\t\t\tcout << -1 << endl;\n\t\t\t} else\n\t\t\t\tcout << -1 << endl;\n\n\t\t} else {\n\t\t\tll res = max(t1, t2);\n\t\t\tll mn = 9223372036854775807LL;\n\t\t\tt1 = abs(t1 - res) % cyc1;\n\t\t\tt2 = abs(t2 - res) % cyc2;\n\t\t\tfor (ll i = 0; i <= mxsz; ++i) {\n\t\t\t\tif (t1 == 0) {\n\t\t\t\t\tif ((cyc1 * i + t2) % cyc2 == 0)\n\t\t\t\t\t\tmn = min(mn, cyc1 * i);\n\t\t\t\t\telse if ((cyc2 * i + abs(cyc2 - t2) + t1) % cyc1 == 0)\n\t\t\t\t\t\tmn = min(mn, cyc2 * i + abs(cyc2 - t2));\n\t\t\t\t}\n\n\t\t\t\tif (t2 == 0) {\n\t\t\t\t\tif ((cyc2 * i + t1) % cyc1 == 0)\n\t\t\t\t\t\tmn = min(mn, cyc2 * i);\n\t\t\t\t\telse if ((cyc1 * i + abs(cyc1 - t1) + t2) % cyc2 == 0)\n\t\t\t\t\t\tmn = min(mn, cyc1 * i + abs(cyc1 - t1));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (mn == 9223372036854775807LL)\n\t\t\t\tcout << -1 << endl;\n\t\t\telse\n\t\t\t\tcout << mn + res << endl;\n\t\t}\n\t}\n//\tcout << -1 << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["math", "greedy", "number theory"], "code_uid": "c4d197b4677becd4f1cc2b58d0689723", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef vector> mat;\nint x, k, p, q, B, curx, n;\nll c[10],w;\nmap mp;\nvector dp;\nvector bitset;\nmat a, o;\nvoid pow2(mat &a) {\n\tmat b(B, vector(B, 1e18));\n\tfor (int k : bitset) {\n\t\tfor (int i : bitset)\n\t\t\tfor (int j : bitset)\n\t\t\t\tb[i][j] = min(b[i][j], a[i][k] + a[k][j]);\n\t}\n\ta = b;\n}\nvoid operator *=(vector &dp, mat &a) {\n\tvector dpn(B, 1e18);\n\tfor (int i : bitset) {\n\t\tfor (int j : bitset) {\n\t\t\tdpn[j] = min(dpn[j], dp[i] + a[i][j]);\n\t\t}\n\t}\n\tswap(dp, dpn);\n}\nvoid jump(ll to) {\n\ta = o;\n\tll jump = to - curx;\n\tfor (;jump;pow2(a), jump >>= 1) {\n\t\tif (jump & 1) dp *= a;\n\t}\n\tcurx = to;\n}\nint main() {\n\tios::sync_with_stdio(0), cin.tie(0);\n\tcin >> x >> k >> n >> q;\n\tB = 1 << k;\n\tdp.resize(B, 1e18);\n\to.resize(B, vector(B, 1e18));\n\tfor (int b = 1;b < B;b++)\n\t\tif (__builtin_popcount(b) == x) bitset.push_back(b);\n\tdp[bitset[0]] = 0;\n\tfor (int i = 1;i <= k;i++) cin >> c[i];\n\tfor (int cur : bitset) {\n\t\tint next = cur >> 1;\n\t\tif (cur & 1) {\n\t\t\tfor (int i = 1, b = 1;i <= k;i++, b <<= 1) if (~next & b) {\n\t\t\t\to[cur][next | b] = c[i];\n\t\t\t}\n\t\t}\n\t\telse o[cur][next] = 0;\n\t}\n\tfor (int i = 1;i <= q;i++) {\n\t\tcin >> p >> w;\n\t\tif (w) mp[p] = w;\n\t}\n\tmp[n + k - x + 1] = 0;\n\tcurx = k;\n\tfor (auto it = mp.begin();curx < n + k - x;) {\n\t\tif (it->first <= curx - k) {\n\t\t\tit++; continue;\n\t\t}\n\t\tif (it->first <= curx + 1) {\n\t\t\tvector dpn(B, 1e18);\n\t\t\tcurx++;\n\t\t\tfor (int cur : bitset) {\n\t\t\t\tint next = cur >> 1;\n\t\t\t\tif (cur & 1) {\n\t\t\t\t\tfor (int i = 1, b = 1;i <= k;i++, b <<= 1) if (~next & b) {\n\t\t\t\t\t\tdpn[next | b] = min(dpn[next | b], dp[cur] + c[i] + (mp.count(curx - k + i) ? mp[curx - k + i] : 0));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse dpn[next] = min(dpn[next], dp[cur]);\n\t\t\t}\n\t\t\tswap(dp, dpn);\n\t\t}\n\t\telse jump(it->first - 1);\n\t}\n\tprintf(\"%lld\", dp[bitset[0]]);\n}", "lang_cluster": "C++", "tags": ["matrices", "dp", "combinatorics"], "code_uid": "16baf000d1b927849b5a183bdf0821f4", "src_uid": "e3dd409ceeba2a21890d35ceab9607eb", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#include \n\n#define pb push_back\n#define F first\n#define S second\n#define all(x) x.begin(), x.end()\n#define debug(x) cerr << #x << \" : \" << x << '\\n'\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntypedef long long ll;\ntypedef long double ld;\ntypedef string str;\ntypedef pair pll;\ntypedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n\nconst ll Mod = 1000000007LL;\nconst int Maxn = 2e3 + 10;\nconst ll Inf = 2242545357980376863LL;\nconst ll Log = 30;\n\nvector G[Maxn], H[Maxn];\npll exf[Maxn * Maxn];\npll exg[Maxn * Maxn];\n\nll n, m1, m2;\n\nll neg(ll a){\n\treturn (a > n ? a - n : a + n);\n}\n\nbitset bt, vis[Maxn];\nll mk[Maxn];\nvector top;\n\nvoid DFS(ll u){\n\tmk[u] = 1;\n\tvis[u][u] = 1;\n\tfor(auto adj : G[u]){\n\t\tif(!mk[adj]) DFS(adj);\n\t\tvis[u] |= vis[adj];\n\t}\n\ttop.pb(u);\n}\n\nint com[Maxn];\n\nvoid dfs(ll u, ll c){\n\tbt |= vis[u];\n\tcom[u] = c;\n\tmk[u] = 1;\n\tfor(auto adj : H[u]){\n\t\tif(!mk[adj]) dfs(adj, c);\n\t}\n\tvis[u] |= bt;\n}\n\n\nll ans[Maxn], on[Maxn];\n\nvoid print(){\n\tmemset(mk, 0, sizeof mk); top.clear();\n\tfor(int i = 1; i <= n + n; i++) if(!mk[i]) DFS(i);\n\t\n\treverse(all(top));\n\tmemset(mk, 0, sizeof mk);\n\tmemset(com, 0, sizeof com);\n\tint c = 1;\n\tfor(auto x : top){\n\t\tif(!mk[x]) dfs(x, x);\n\t}\n\t\n\tbool val = true;\n\tfor(int i = 1; i <= n; i++) val &= (com[i] != com[neg(i)]);\n\tassert(val);\n\t\n\t\n\treverse(all(top));\n\tmemset(ans, -1, sizeof ans);\n\tfor(auto x : top){\n\t\tif(com[x] != x) continue;\n\t\tif(on[com[neg(x)]]) continue;\n\t\ton[x] = 1;\n\t}\n\t/*\n\tbool F = true;\n\tll u, v;\n\tfor(int i = 0; i < m1; i++){\n\t\tu = exf[i].F;\n\t\tv = exf[i].S;\n\t\tF &= ( (v > n ? 1 - ans[neg(v)] : ans[v]) || (u > n ? 1 - ans[neg(u)] : ans[u]));\n\t}\n\tassert(!F);\n\tbool G = true;\n\tfor(int i = 0; i < m2; i++){\n\t\tu = exg[i].F;\n\t\tv = exg[i].S;\n\t\tG &= ( (v > n ? 1 - ans[neg(v)] : ans[v]) || (u > n ? 1 - ans[neg(u)] : ans[u]));\n\t}\n\t//assert(G);\n\t*/\n\tfor(int i = 1; i <= n; i++) cout << on[com[i]] << ' ';\n\texit(0);\n}\n\nvoid solve(){\n\tfor(int i = 0; i < Maxn; i++){\n\t\tG[i].clear();\n\t\tH[i].clear();\n\t\tvis[i] &= vis[0];\n\t}\n\tll u, v;\n\tfor(int i = 0; i < m2; i++){\n\t\tu = exg[i].F;\n\t\tv = exg[i].S;\n\t\t\n\t\tG[neg(u)].pb(v);\n\t\tG[neg(v)].pb(u);\n\t\tH[v].pb(neg(u));\n\t\tH[u].pb(neg(v));\n\t}\n\tmemset(mk, 0, sizeof mk); top.clear();\n\tfor(int i = 1; i <= n + n; i++) if(!mk[i]) DFS(i);\n\treverse(all(top));\n\t\n\tmemset(mk, 0, sizeof mk);\n\tint c = 1;\n\tfor(auto x : top){\n\t\tif(!mk[x]) bt = vis[0], dfs(x, x);\n\t}\n\t\n\tbool val = true;\n\tfor(int i = 1; i <= n; i++) val &= (com[i] != com[neg(i)]);\n\tif(!val) return ;\n\tfor(int i = 0; i < m1; i++){\n\t\tu = exf[i].F;\n\t\tv = exf[i].S;\n\t\tif(vis[neg(u)][u] || (vis[neg(u)][v] && vis[neg(v)][u])) continue;\n\t\tif(vis[neg(v)][v] || (vis[neg(v)][u] && vis[neg(u)][v])) continue;\n\t\t\n\t\tG[u].pb(neg(u));\n\t\tH[neg(u)].pb(u);\n\t\t\n\t\tG[v].pb(neg(v));\n\t\tH[neg(v)].pb(v);\n\t\tprint();\n\t}\n}\n\n\nint main(){\n\tios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n\tcin >> n >> m1 >> m2;\n\tll u, v;\n\tfor(int i = 0; i < m1; i++){\n\t\tcin >> u >> v;\n\t\tif(u < 0) u = n - u;\n\t\tif(v < 0) v = n - v;\n\t\texf[i] = {u, v};\n\t}\n\t\n\tfor(int i = 0; i < m2; i++){\n\t\tcin >> u >> v;\n\t\tif(u < 0) u = n - u;\n\t\tif(v < 0) v = n - v;\n\t\texg[i] = {u, v};\n\t}\n\tsolve();\n\tswap(m1, m2);\n\tswap(exf, exg);\n\tsolve();\n\tcout << \"SIMILAR\\n\";\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["graphs"], "code_uid": "0a6188eb1df27780bc4b106acb2f7cc0", "src_uid": "e7f585455aaf039aa6f0f2846d818b40", "difficulty": 3000.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)\n#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)\n#define mp(x,y) make_pair((x),(y))\n#define sz(x) (int)(x).size()\n#define pb push_back\ntypedef long long ll;\ntypedef pair pii;\ninline int read(){\n register int x=0,f=1;register char ch=getchar();\n while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}\n while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}\n return f?x:-x;\n}\n\nconst int N=2e5+5,M=2e6+5,mod=1e9+7;\nint n,p[N],num[M],cnt[M],a[N];\ninline int power(int b,int n){int ans=1;for(;n;n>>=1,b=1ll*b*b%mod)if(n&1)ans=1ll*ans*b%mod;return ans;}\n\nint insert(int p){\n\tif(!num[p])return num[p]=cnt[p]=1,0;\n\t--p;\n\tfor(int i=2;i<=sqrt(p);++i){\n\t\tif(p%i)continue;\n\t\tint c=0;\n\t\twhile(p%i==0)p/=i,++c;\n\t\tif(num[i]b;});\n\tREP(i,1,n)a[i]=p[i]-insert(p[i]);\n\tint ans=1;\n\tREP(i,2,M-1)ans=1ll*ans*power(i,num[i])%mod;\n\tREP(i,1,n)if(check(a[i])){ans=(ans+1)%mod;break;}\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["number theory"], "code_uid": "2ebe9a7128c31d85a7814c5c1abe1072", "src_uid": "816a82bee65cf79ba8e4d61babcd0301", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define REP(i,n) for(int i=0;i mp[MAX_N];\n\nstring trans(string a,bool cyc=true){\n\tint n=a.size();\n\tstatic bool swp[MAX_N]={};\n\tfor(int i=0;i2){\n\t\tstring t=trans(my.substr(0,at),false);\n\t\tif(t.size()>2 && t.substr(1,t.size()-2) != s.substr(1,t.size()-2))\n\t\t\treturn 0;\n\t}\n\t\t\n\tstring key=my.substr(0,min(3,at));\n\tkey+=\" \"+my.substr(max(0,at-3),3);\n\tif(mp[at].count(key))\n\t\treturn mp[at][key];\n\tint64&ret=mp[at][key]=0;\n\tif(at==n){\n\t\tstring t=trans(my);\n\t\treturn ret=s==t;\n\t}\n\tmy[at]='A';\n\tret+=rec(at+1);\n\tmy[at]='B';\n\tret+=rec(at+1);\n\treturn ret;\n}\n\nint main(){\n\tcin>>s;\n\tn=s.size();\n\tmy=s;\n\tcout<\nusing namespace std;\n\nconst int p1 = 998244353, p2 = 469762049, Maxn = 1 << 17 | 5;\nint maxn, maxa, mod, rev[Maxn];\nint tot, l[Maxn];\nconst long long lcm = p1 * (long long) p2;\nvoid get_rev(int len)\n{\n\tfor (int i = 0; i < len; i++)\n\t\trev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (len >> 1));\n}\nlong long fast_pow(long long x, long long y, int p)\n{\n\tlong long ans = 1, now = x;\n\twhile (y)\n\t{\n\t\tif (y & 1) ans = ans * now % p;\n\t\tnow = now * now % p;\n\t\ty >>= 1;\n\t}\n\treturn ans;\n}\nvoid NTT(int now[], int len, int p, bool type = false)\n{\n\tl[0] = 1;\n\tint inv3 = fast_pow(3, p - 2, p);\n\tfor (int i = 0; i < len; i++)\n\t\tif (i < rev[i]) swap(now[i], now[rev[i]]);\n\tfor (int i = 1; i < len; i <<= 1)\n\t{\n\t\tlong long w = fast_pow(type ? inv3 : 3, (p - 1) / (i << 1), p);\n\t\tfor (int j = 1; j < i; j++)\n\t\t\tl[j] = l[j - 1] * w % p;\n\t\tfor (int j = 0; j < len; j += (i << 1))\n\t\t\tfor (int k = j; k < i + j; k++)\n\t\t\t{\n\t\t\t\tint x = now[i + k] * (long long) l[k - j] % p, y = now[k];\n\t\t\t\tnow[k] = (x + y) % p;\n\t\t\t\tnow[i + k] = (y - x + p) % p;\n\t\t\t}\n\t}\n\tif (type)\n\t{\n\t\tlong long inv = fast_pow(len, p - 2, p);\n\t\tfor (int i = 0; i < len; i++)\n\t\t\tnow[i] = now[i] * inv % p;\n\t}\n}\nvoid multi(int x[], int y[], int result[], int len, int p)\n{\n\tNTT(x, len, p), NTT(y, len, p);\n\tfor (int i = 0; i < len; i++)\n\t\tresult[i] = x[i] * (long long) y[i] % p;\n\tNTT(result, len, p, true);\n}\nlong long mul(long long x, long long y)\n{\n\treturn ((unsigned long long) x * y - (long long) (x / (long double) lcm * y) * lcm + lcm) % lcm;\n}\nvoid multi(int x[], int y[], int result[], int len)\n{\n\tget_rev(len);\n\tstatic int tmp1[Maxn], tmp2[Maxn], tmpx[Maxn], tmpy[Maxn];\n\tfor (int i = 0; i < len; i++)\n\t\ttmpx[i] = x[i], tmpy[i] = y[i];\n\tmulti(tmpx, tmpy, tmp1, len, p1);\n\tfor (int i = 0; i < len; i++)\n\t\ttmpx[i] = x[i], tmpy[i] = y[i];\n\tmulti(tmpx, tmpy, tmp2, len, p2);\n\tlong long P1 = fast_pow(p2, p1 - 2, p1), P2 = fast_pow(p1, p2 - 2, p2);\n\tfor (int i = 0; i < len; i++)\n\t\tresult[i] = (mul(mul(tmp1[i], p2), P1) + mul(mul(tmp2[i], p1), P2)) % lcm % mod;\n}\nvoid poly_pow(int y, int len)\n{\n\tint now = 0;\n\tstatic int ans[2][Maxn];\n\tmemset(ans[0], 0, sizeof(int[len << 1]));\n\tmemset(ans[1], 0, sizeof(int[len << 1]));\n\tstatic int tmp[Maxn], result[2][Maxn];\n\tfor (int j = 30; j >= 0; j--)\n\t{\n\t\tcerr << j << endl;\n\t\tmemset(tmp, 0, sizeof(int[len << 1]));\n\t\tfor (int i = 0; i < len; i++)\n\t\t\ttmp[i] = (ans[0][i] + ans[1][i]) % mod;\n\t\ttmp[0]++;\n\t\tfor (int p = 0; p <= 1; p++)\n\t\t\tmulti(tmp, ans[(now & 1) ^ p], result[p], len << 1);\n\t\tfor (int p = 0; p <= 1; p++)\n\t\t\tfor (int i = 0; i < len; i++)\n\t\t\t\t(ans[p][i] += result[p][i]) %= mod;\n\t\tnow <<= 1;\n\t\tif (y & (1 << j))\n\t\t{\n\t\t\tfor (int i = len - 1; i; i--)\n\t\t\t\t(ans[1][i] += ans[0][i - 1] + ans[1][i - 1]) %= mod;\n\t\t\tans[1][1]++; \n\t\t\tnow++;\n\t\t}\n\t\tif (now != y)\n\t\t\tfor (int i = 1; i <= maxn; i += 2)\n\t\t\t\t(tot += ans[1][i]) %= mod;\n\t}\n}\nint lower(int x)\n{\n\tint tmp = 1;\n\tfor (; tmp < x; tmp <<= 1);\n\treturn tmp;\n}\nint main()\n{\n\tscanf(\"%d%d%d\", &maxn, &maxa, &mod);\n\tpoly_pow(maxa, lower(maxn + 1));\n\tprintf(\"%d\", tot);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["divide and conquer", "math", "dp", "combinatorics", "fft", "number theory"], "code_uid": "6856ab94d32ed126ea27d37b3db2a3c5", "src_uid": "aac481d9e5ea3e3d43b324c8750882be", "difficulty": 3400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\ntypedef unsigned long long ullong;\n\nullong my_sqrt(ullong k) {\n ullong low = 1, high = k;\n while (low <= high) {\n ullong mid = low + ((high - low) >> 1);\n if (mid * mid > k)\n high = mid - 1;\n else if (mid * mid < k)\n low = mid + 1;\n else\n return mid;\n }\n return high;\n}\n\nint main() {\n ullong n;\n scanf(\"%llu\", &n);\n if (n % 3) {\n puts(\"0\");\n return 0;\n }\n n /= 3;\n ullong res = 0;\n for (ullong x = 2; x * x * x <= n; ++x) {\n if (n % x)\n continue;\n ullong nx = n / x;\n ullong sqrt_nx = my_sqrt(nx);\n for (ullong y = sqrt_nx; y >= x; --y) {\n if (nx % y)\n continue;\n ullong z = nx / y;\n ullong sum = x + y + z;\n if (sum <= z << 1)\n break;\n if (sum & 1)\n continue;\n if (x == y && y == z)\n ++res;\n else if (x == y || y == z || z == x)\n res += 3;\n else\n res += 6;\n }\n }\n printf(\"%llu\", res);\n}\n", "lang_cluster": "C++", "tags": ["brute force", "math", "number theory"], "code_uid": "0e6d5f48914d2c1933ca032214d71527", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \nusing namespace std;\n\nusing Poly = vector;\n\nconst int P = 998244353;\n\nPoly operator+(Poly lhs, Poly rhs) {\n\tPoly ret(max(lhs.size(), rhs.size()), 0);\n\tfor (int i = 0; i < ret.size(); i++) ret[i] = ((i < lhs.size() ? lhs[i] : 0) + (i < rhs.size() ? rhs[i] : 0)) % P;\n\treturn ret;\n}\n\nPoly operator-(Poly lhs, Poly rhs) {\n\tPoly ret(max(lhs.size(), rhs.size()), 0);\n\tfor (int i = 0; i < ret.size(); i++) ret[i] = ((i < lhs.size() ? lhs[i] : 0) + (i < rhs.size() ? P - rhs[i] : 0)) % P;\n\treturn ret;\n}\n\nPoly operator*(Poly lhs, Poly rhs) {\n\tPoly ret(max(0, (int)(lhs.size() + rhs.size()) - 1), 0);\n\tfor (int i = 0; i < lhs.size(); i++) {\n\t\tfor (int j = 0; j < rhs.size(); j++) {\n\t\t\tret[i+j] = (ret[i+j] + lhs[i] * 1LL * rhs[j]) % P;\n\t\t}\n\t}\n\treturn ret;\n}\n\nPoly operator*(Poly lhs, int rhs) {\n\tfor (int &x : lhs) x = x * 1LL * rhs % P;\n\treturn lhs;\n}\n\nPoly s(Poly p, int k) {\n\tPoly q(k, 0); p.insert(p.begin(), q.begin(), q.end());\n\treturn p;\n}\n\nPoly dot(Poly p) {\n\tfor (int i = 0; i < p.size(); i++) p[i] = 1LL * i * p[i] % P;\n\treturn p;\n}\n\nint calc(Poly &a) {\n\treverse(a.begin(), a.end());\n\tint ret = 0;\n\twhile (!a.empty() && !a.back()) a.pop_back(), ret++;\n\treverse(a.begin(), a.end());\n\treturn ret;\n}\n\nint solve(Poly a, Poly b, int n) {\n\tn -= calc(a) - calc(b);\n\tif (n < 0) return 0;\n\tvector c(n + 1, 0);\n\tfor (int i = 0; i <= n; i++) {\n\t\tc[i] = i < a.size() ? a[i] : 0;\n\t\tfor (int j = 1; j < b.size() && j <= i; j++) c[i] = (c[i] + (P - c[i - j]) * 1LL * b[j]) % P;\n\t}\n\treturn c[n];\n}\n\nint main() {\n\tint n; cin >> n;\n\tPoly A = {1, 0, P-1, 0, P-1}, B = dot(A), C = dot(B);\n\tPoly F0 = B * B * 2 - C * A, F1 = F0 + A * A - B * A * 2, F2 = F1 + A * A * 3 - B * A * 2;\n\tF0 = A * A * A - s(F0, 1), F1 = s(F1, 2), F2 = A * A * A - s(F2, 3);\n\tPoly F = F0 * F2 - F1 * F1;\n\tcout << (solve(B, A, n) * 6LL + P - solve(dot(F), F, n)) % P << endl;\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["divide and conquer", "math", "dp", "combinatorics", "fft"], "code_uid": "2617288eb6e6db7a9a7c008e33b241cf", "src_uid": "24fd5cd218f65d4ffb7c5b97b725293e", "difficulty": 3400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\n\nconst int INF = INT_MAX / 2;\n\nsigned main() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int n, m;\n cin >> n >> m;\n vector> graph(n);\n vector> rgraph(n);\n for (int i = 0; i < m; i++) {\n int v, u;\n cin >> v >> u;\n v--;\n u--;\n graph[v].emplace_back(u);\n rgraph[u].emplace_back(v);\n }\n int k;\n cin >> k;\n vector path(k);\n for (auto &e : path) {\n cin >> e;\n e--;\n }\n int s = path[0];\n int f = path.back();\n vector dist(n, INF);\n vector cnt(n, 0);\n dist[f] = 0;\n cnt[f] = 0;\n set> q;\n q.emplace(0, f);\n while (!q.empty()) {\n auto v = q.begin()->second;\n q.erase(q.begin());\n for (auto u : rgraph[v]) {\n if (dist[u] > dist[v] + 1) {\n dist[u] = dist[v] + 1;\n cnt[u] = 0;\n q.emplace(dist[u], u);\n } else if (dist[u] == dist[v] + 1 && cnt[u] == 0) {\n cnt[u] ++;\n q.emplace(dist[u], u);\n }\n }\n }\n int ans_mn = 0;\n int ans_mx = 0;\n for (int i = 0; i < k - 1; i++) {\n if (dist[path[i]] != dist[path[i + 1]] + 1) {\n ans_mn++;\n ans_mx++;\n } else if (cnt[path[i]]) {\n ans_mx++;\n }\n }\n assert(ans_mn <= ans_mx);\n cout << ans_mn << ' ' << ans_mx;\n return 0;\n}", "lang_cluster": "C++", "tags": ["shortest paths", "graphs"], "code_uid": "f7c2f34929c0dbb9638097e67768cbe4", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "//#include \"stdafx.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nlong long kol1, l, tekres, ee, kol, r, n, k, p, e, c, a, b, f,m;\nint main()\n{\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n\tscanf(\"%d%d%d\", &n, &m, &k);\n\tscanf(\"%d%d\", &a, &b);\n\tlong long res = 0;\n\tlong long a1 = (a+m*k-1) / (m*k), b1 = (b+m*k-1) / (m*k);\n\tlong long a2 = (a-(a1-1)*(m*k)+k-1) / k, b2 = (b - (b1 - 1)*(m*k) + k - 1) / k;\n\tif (a1 == b1 && a2 == b2)\n\t{\n\t\tprintf(\"0\");\n\t\treturn 0;\n\t}\n\tif (a1 == b1)\n\t{\n\t\tprintf(\"%d\", min(10 + abs(a2 - b2), abs(a2 - b2) * 5));\n\t\treturn 0;\n\t}\n\tres += min(10 + a2 - 1, 5 * (a2 - 1));\n\tres += min(abs(b1 - a1) * 15, (n - max(a1, b1) + min(a1, b1))*15);\n\tres += min(10 + b2 - 1, 5 * (b2 - 1));\n\tprintf(\"%d\", res);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["constructive algorithms"], "code_uid": "0dd2808201ed8dd59d18a5ce63cf2458", "src_uid": "c37b46851abcf7eb472869bd1ab9f793", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \nusing namespace std;\ntypedef long long ll;\ntypedef pair pii;\nbool SR(int &x){return scanf(\"%d\",&x)==1;}bool SR(ll &x){return scanf(\"%lld\",&x)==1;}\nbool SR(double &x){return scanf(\"%lf\",&x)==1;}bool SR(char *s){return scanf(\"%s\",s)==1;}\nbool RI(){return 1;}\ntemplate\nbool RI(I &x,T&... tail){return SR(x)&&RI(tail...);}\n#ifndef darry140\n#define debug(...)\n#else\n#define debug(...) do{\\\n\tfprintf(stderr,\"%s - %d : \",__PRETTY_FUNCTION__,__LINE__);\\\n\t_DO(__VA_ARGS__);}while(0)\nvoid _DO(){}\ntemplate\nvoid _DO(I&& x,T&&... tail){cerr< v;\nvoid read()\n{\n\tRI(n);\n\tint t[2]={0,1};\n\tREP(i,60)\n\t{\n\t\tif(n%10==t[0]) v.pb(i);\n\t\tswap(t[0],t[1]);\n\t\tt[0]+=t[1];t[0]%=10;\n\t}\n}\nll mul(ll a,ll b,ll mod)\n{\n\tif(b==0) return 0;\n\tll tmp=mul(a,b/16,mod);\n\ttmp=(tmp*16)%mod;\n\treturn (tmp+a*(b&15))%mod;\n}\narray,2> powmod(ll x,ll MOD)\n{\n\tif(x==0) return {array{1LL,0LL},array{0LL,1LL}};\n\tauto tmp=powmod(x/2,MOD);\n\tauto c=tmp;REP(i,2) REP(j,2) c[i][j]=0; \n\tREP(i,2) REP(j,2) REP(k,2) c[i][j]+=mul(tmp[i][k],tmp[k][j],MOD);\n\tREP(i,2) REP(j,2) c[i][j]%=MOD;\n\tif(x&1)\n\t{\n\t\tauto d=tmp;REP(i,2) REP(j,2) d[i][j]=0;\n\t\ttmp={array{0LL,1LL},array{1LL,1LL}};\n\t\tREP(i,2) REP(j,2) REP(k,2) d[i][j]+=mul(tmp[i][k],c[k][j],MOD);\n\t\tREP(i,2) REP(j,2) d[i][j]%=MOD;\n\t\treturn d;\n\t}\n\treturn c;\n}\nbool chk(ll id,ll MOD)\n{\n\tauto A=powmod(id,MOD);\n\treturn A[1][0]%MOD==n%MOD;\n}\nvoid build()\n{\n\tvector pw(13);\n\tpw[0]=10;\n\tREP1(i,1,12) pw[i]=pw[i-1]*10;\n\tREP1(r,1,12)\n\t{\n\t\tll BAS=bas(r),BM=bas(r-1);\n\t\tll div=BAS/BM;\n\t\tvector cur(div*SZ(v));\n\t\tREP(i,div) REP(j,SZ(v))\n\t\t\tcur[i*SZ(v)+j]=v[j]+i*BM;\n\t\tv.clear();\n\t\tfor(ll x:cur) if(chk(x,pw[r]))\n\t\t\tv.pb(x);\n\t}\n}\nvoid sol()\n{\n\tif(SZ(v)) printf(\"%lld\\n\",v[0]);\n\telse puts(\"-1\");\n}\nint main()\n{\n\tread();\n\tbuild();\n\tsol();\n\treturn 0;\n}\n\n", "lang_cluster": "C++", "tags": ["brute force", "math", "matrices"], "code_uid": "1b68182df9bd940ffd521ffe00844e19", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "//Tornike Mandzulashvili\n//#pragma comment(linker, \"/STACK:16777216\")\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define PI 3.14159265\n#define hash1 1000003\n#define hash2 1000033\n#define md 1000000007\n#define INF 1000000000\n\nusing namespace std;\n\nlong long d[41]={2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583};\nlong long n;\nlong long go(long long num)\n{\n if (num==0) return 1;\n long long h=go(num/2);\n if (num%2) return (h*h%md)*2LL%md;else\n return h*h%md;\n}\nmain()\n{\n//freopen(\"text.in\",\"r\",stdin);freopen(\"text.out\",\"w\",stdout);\n\n cin>>n;\n cout<<(go(d[n-1]-1)+md-1)%md<\n#include\n#include\n#include\nusing namespace std;\nint n,k,p;\nint fpow(int a,int b)\n{\n\tint ans=1,t=a;\n\twhile(b)\n\t{\n\t\tif(b&1)ans=1ll*ans*t%p;\n\t\tt=1ll*t*t%p;b>>=1;\n\t}\n\treturn ans;\n}\nint lowbit(int x)\n{\n\treturn x&(-x);\n}\nint f[26][250010];\nint fac[250010],inv[250010];\nvoid init()\n{\n\tfac[0]=1;\n\tfor(int i=1;i<=n;i++)\n\t\tfac[i]=1ll*fac[i-1]*i%p;\n\tinv[n]=fpow(fac[n],p-2);\n\tfor(int i=n;i>=1;i--)\n\t\tinv[i-1]=1ll*inv[i]*i%p;\n\treturn ;\n}\nint solve(int cur,int S)\n{\n\tif(f[cur][S]!=-1)\n\t\treturn f[cur][S];\n\tif(!S){\n\t\tf[cur][S]=fac[n];\n\t\tfor(int i=1;i<=cur;i++)\n\t\t\tf[cur][S]=1ll*f[cur][S]*(k-i+1)%p;\n\t\treturn f[cur][S];\n\t}\n\tf[cur][S]=0;\n\tint U=S-lowbit(S);\n\tfor(int T=U;T;T=(T-1)&U)\n\t\tf[cur][S]=(f[cur][S]+1ll*inv[S-T]*solve(cur+1,T))%p;\n\tf[cur][S]=(f[cur][S]+1ll*inv[S]*solve(cur+1,0))%p;\n\treturn f[cur][S];\n}\nint main()\n{\n\tscanf(\"%d %d %d\",&n,&k,&p);\n\tint ans=1;\n\tfor(int i=1;i<=n;i++)\n\t\tans=1ll*ans*k%p;\n\tif(n%2==0){\n\t\tinit();\n\t\tmemset(f,-1,sizeof(f));\n\t\tans=(ans-solve(0,n)+p)%p;\n\t}\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp", "games"], "code_uid": "f019491af76df7f8d3b735e99349717a", "src_uid": "97f737f59100babe5e45e1a82a1f7d99", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "/*\n\u0917\u093f\u0930\u0924\u0947 \u0939\u0948\u0902 \u0936\u0939\u0938\u0935\u093e\u0930 \u0939\u0940 \u092e\u0948\u0926\u093e\u0928-\u090f-\u091c\u0902\u0917 \u092e\u0947\u0902 \u0964\n\u0935\u094b \u0924\u093f\u092b\u093c\u094d\u0932 \u0915\u094d\u092f\u093e \u0917\u093f\u0930\u0947 \u091c\u094b \u0918\u0941\u091f\u0928\u094b\u0902 \u0915\u0947 \u092c\u0932 \u091a\u0932\u0947 \u0964\u0964\n*/\n#include\n#include \n#include \nusing namespace __gnu_pbds;\nusing namespace std;\n#define int long long int\n#define ull unsigned int\n#define ld long double\n#define pb push_back\n#define pa pair\n#define v1d vector\n#define v2d vector >\n#define vpa vector>\n#define M 1000000007\n#define MN LLONG_MIN\n#define MX LLONG_MAX\n#define ff first\n#define ss second\n#define endl \"\\n\"\n#define v1s vector\n#define all(v) v.begin(),v.end()\n#define S(v) sort(v.begin(),v.end())\n#define RS(v) sort(v.rbegin(),v.rend())\n#define R(v) reverse(v.begin(),v.end())\n#define mxpq(T) priority_queue \n#define mnpq(T) priority_queue,greater>\n#define T int tc;cin>>tc;while(tc--)\n#define p2d(v) for(auto a:v){for(auto b:a)cout<,rb_tree_tag,tree_order_statistics_node_update> oset;\n#define N 400005\n\n\nvoid Weapons19(){\n int n,m,a,b,c,d;\n cin>>n>>m>>a>>b>>c>>d;\n if(abs(b-d)>4||abs(c-a)>4)cout<<\"Second\";\n else if(abs(b-d)==4&&abs(c-a)==3)cout<<\"Second\";\n else if(abs(b-d)==3&&abs(c-a)==4)cout<<\"Second\";\n else if(abs(b-d)==4&&abs(c-a)==4)cout<<\"Second\";\n else cout<<\"First\";\n\n}\n\nint32_t main(){\n\n /*\n \u0924\u094d\u092f\u0915\u094d\u0924\u0935\u093e\u0927\u0930\u094d\u092e\u0902 \u091a \u0932\u094b\u092d\u0902 \u091a\n \u092e\u094b\u0939\u0902\u091a\u094b \u0926\u094d\u092f\u092e\u093e\u0938\u094d\u0925\u093f\u0924\u093e\u0964\n \u092f\u0941\u0926\u094d\u0927\u094d\u092f\u0927\u094d\u0935\u092e\u0928\u0939\u0902\u0915\u093e\u0930\u093e\n \u092f\u0924\u094b \u0927\u0930\u094d\u092e\u0938\u094d\u0924\u0924\u094b \u091c\u092f\u0903\u0964\u0964\n */\n\n cout<\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\nusing namespace std;\r\ntypedef long long LL;\r\ntypedef unsigned long long ULL;\r\n#define MEM(a,b) memset((a),(b),sizeof(a))\r\nconst LL INF = 1e9 + 7;\r\nconst int N = 1e5 + 10;\r\nint y[27] = { 10010,11020,20011,21012,11011,21021,22022,12021,11011,12012,10120,11130,20121,21122,11121,21131,22132,12131,11121,12122,10221,11231,12113,20222,21223,11222 };\r\nchar x[30000];\r\nint main()\r\n{\r\n\t//freopen(\"input.txt\", \"r\", stdin);\r\n\t//freopen(\"output.txt\", \"w\", stdout);\r\n\tint t, s, z;\r\n\tfor (int i = 0; i < 26; i++) \r\n\t{\r\n\t\tif (!x[y[i]]) x[y[i]] = i + 'a';\r\n\t}\r\n\tscanf(\"%d\", &t);\r\n\twhile (t--)\r\n\t{\r\n\t\tz = 0;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tscanf(\"%d\", &s), z = z * 10 + s;\r\n\t\tputchar(x[z]);\r\n\t}\r\n\treturn 0;\r\n}", "lang_cluster": "C++", "tags": ["implementation"], "code_uid": "983ca0bc23343802dec86359d1f70038", "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#include\n#define mod 1000000007\nint c[1010][1010];\nint num[3];\nint n,p;\nint add(int x,int y){\n\treturn (x+=y)>=1)x=mul(x,x);else\n\t\t\tbreak;\n\t}\n\treturn r;\n}\nconst int sg[]={\n1,0,\n3,1,\n4,2,\n5,1,\n7,2,\n9,0,\n13,1,\n15,2,\n19,0,\n27,1,\n39,2,\n40,0,\n57,2,\n58,1,\n81,2,\n85,0,\n120,2,\n121,1,\n174,2,\n179,0,\n255,2,\n260,1,\n363,2,\n382,0,\n537,2,\n544,1,\n780,2,\n805,0,\n1146,2,\n1169,1,\n1632,2,\n1718,0,\n2415,2,\n2447,1,\n3507,2,\n3622,0,\n5154,2,\n5260,1,\n7341,2,\n7730,0,\n10866,2,\n11011,1,\n15780,2,\n16298,0,\n23190,2,\n23669,1,\n33033,2,\n34784,0,\n48894,2,\n49549,1,\n71007,2,\n73340,0,\n104352,2,\n106510,1,\n148647,2,\n156527,0,\n220020,2,\n222970,1,\n319530,2,\n330029,0,\n469581,2,\n479294,1,\n668910,2,\n704371,0,\n990087,2,\n1003364,1,\n1437882,2,\n1485130,0,\n2113113,2,\n2156822,1,\n3010092,2,\n3169669,0,\n4455390,2,\n4515137,1,\n6470466,2,\n6683084,0,\n9509007,2,\n9705698,1,\n13545411,2,\n14263510,0,\n20049252,2,\n20318116,1,\n29117094,2,\n30073877,0,\n42790530,2,\n43675640,1,\n60954348,2,\n64185794,0,\n90221631,2,\n91431521,1,\n131026920,2,\n135332446,0,\n192557382,2,\n196540379,1,\n274294563,2,\n288836072,0,\n405997338,2,\n411441844,1,\n589621137,2,\n608996006,0,\n866508216,2,\n884431705,1,\n1000000000,-1};\nint main(){\n/*\tfor(int i=1; i<1000000000; i++){\n\t\td[i]=0;\n\t\tif(i>2){\n\t\t\tint x=i/3;\n\t\t\tint y=d[x],z=d[i-x];\n\t\t\tif(y!=0 && z!=0)\n\t\t\t\td[i]=0;\n\t\t\telse\n\t\t\tif(y!=1 && z!=1)\n\t\t\t\td[i]=1;\n\t\t\telse\n\t\t\t\td[i]=2;\n\t\t}\n\t\tif(d[i]!=d[i-1])printf(\"%d,%d,\\n\",i,d[i]);\n\t}*/\n\tscanf(\"%d%d\",&n,&p);\n\tfor(int i=0; sg[i]\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define y0 sdkfaslhagaklsldk\n#define y1 aasdfasdfasdf\n#define yn askfhwqriuperikldjk\n#define j1 assdgsdgasghsf\n#define tm sdfjahlfasfh\n#define lr asgasgash\n\n#define INF 100000000\n#define eps 1e-11\n//#define M_PI 3.141592653589793\n//#define mx 1000000000000ll\n#define bs 1000000007\n#define bsize 256\n\nusing namespace std;\n\nlong long n,k,a,b,need;\nvector > v;\nvector v1,v2;\nlong long ans,alost,rem,todel,cost;\n\nint main(){\n//freopen(\"melman.in\",\"r\",stdin);\n//freopen(\"melman.out\",\"w\",stdout);\n//freopen(\"C:/input.txt\",\"r\",stdin);\n//freopen(\"C:/output.txt\",\"w\",stdout);\nios_base::sync_with_stdio(0);\ncin.tie(0);\n\ncin>>n>>k;\nfor (int i=1;i<=n;i++)\n{\n cin>>a>>b;\n v.push_back(make_pair(a,b));\n}\n\nsort(v.begin(),v.end());\nreverse(v.begin(),v.end());\n\nif (k==v.size()+1)need=0;else\nneed=v[k-1].first;\n\nans=1e18;\n\nfor (int score=need;score<=need+10;score++)\n{\n alost=0;\n if (score>n)continue;\n for (int p=0;pscore){alost++;}\n rem=k-alost-1;\n if(rem<0)continue;\n v1.clear();\n v2.clear();\n for (int i=0;iscore||v[i].firstrem)\n {\n todel=v2.size()-rem;\n }\n else todel=0;\n cost=0;\n if (todel>score)continue;\n for (int i=0;i1e16)ans=-1;\n\ncout<\n\nusing namespace std;\nusing ll = long long;\n\nconst int N = 7002;\n\nint n, d[N];\nll a[N], b[N];\nbool used[N], adj[N][N];\n\nint main() {\n ios::sync_with_stdio(false);\n cin >> n;\n for (int i = 1; i <= n; ++i) cin >> a[i];\n for (int i = 1; i <= n; ++i) cin >> b[i];\n for (int i = 1; i <= n; ++i)\n for (int j = 1; j <= n; ++j) {\n if (a[i] > (a[i] & a[j])) {\n ++d[i];\n adj[j][i] = true;\n }\n }\n int cur = n;\n while (true) {\n vector v;\n v.clear();\n for (int i = 1; i <= n; ++i)\n if (!used[i] && d[i] + 1 == cur)\n v.push_back(i);\n if (v.empty()) break;\n for (int u : v) {\n used[u] = true;\n --cur;\n for (int i = 1; i <= n; ++i)\n if (adj[u][i]) --d[i];\n }\n }\n ll ans = 0;\n for (int i = 1; i <= n; ++i) if (!used[i]) ans += b[i];\n cout << ans << \"\\n\";\n return 0;\n}", "lang_cluster": "C++", "tags": ["brute force", "greedy"], "code_uid": "3ebc8bbf4313c01a7078b4fd190e0ff5", "src_uid": "9404ec14922a69082f3573bbaf78ccf0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n\nusing namespace std;\n\nconst int MOD = 998244353;\n\ntemplate \nstruct modular {\n constexpr modular() : val(0){}\n constexpr modular(const modular& _m) : val(_m.val) {}\n template constexpr modular(const U& _r = U()) {\n val = -MOD <= _r && _r < MOD ? _r: _r % MOD;\n if (val < 0) { val += MOD; } }\n const T operator()() { return val; }\n template explicit operator U() const { return static_cast(val); }\n modular& operator+=(const modular& _m) { if ((val += _m.val) >= MOD) { val -= MOD; } return *this; }\n modular& operator-=(const modular& _m) { if ((val -= _m.val) < 0) { val += MOD; } return *this; }\n modular& operator*=(const modular& _m) { val = modular(static_cast(val) * static_cast(_m.val)).val; return *this; }\n modular& operator/=(const modular& _m) {\n T a = _m.val, b = MOD, u = 0, v = 1;\n while (a != 0) {\n T q = b / a;\n b -= q * a; swap(a, b);\n u -= q * v; swap(u, v); \n } return *this *= u; }\n modular& operator =(const modular& _m) { val = _m.val; return *this; }\n template modular& operator+=(const U& _r) { return *this += modular(_r); }\n template modular& operator-=(const U& _r) { return *this -= modular(_r); }\n template modular& operator*=(const U& _r) { return *this *= modular(_r); }\n template modular& operator/=(const U& _r) { return *this /= modular(_r); } \n template modular& operator =(const U& _r) { val = modular(_r).val; return *this; }\n modular operator-() { return modular(-val); } \n template friend bool operator==(const modular&, const modular&);\n friend std::istream& operator>>(std::istream& os, modular& _m) { os >> _m.val; _m *= 1; return os; }\n friend std::ostream& operator<<(std::ostream& os, const modular& _m) { return os << _m.val; }\n template \n modular exp(U e) {\n modular res = 1;\n modular b = val;\n if (e < 0) { b = 1/b; e *= -1; }\n for (; e; e >>= 1) {\n if (e & 1) { res *= b; }\n b *= b;\n } return res; }\nprivate:\n T val;\n};\ntemplate inline modular operator+(const modular& _lhs, const modular& _rhs) { return modular(_lhs) += _rhs; }\ntemplate inline modular operator+(const modular& _lhs, const U& _rhs) { return modular(_lhs) += _rhs; }\ntemplate inline modular operator+(const U& _lhs, const modular& _rhs) { return modular(_lhs) += _rhs; }\ntemplate inline modular operator-(const modular& _lhs, const modular& _rhs) { return modular(_lhs) -= _rhs; }\ntemplate inline modular operator-(const modular& _lhs, const U& _rhs) { return modular(_lhs) -= _rhs; }\ntemplate inline modular operator-(const U& _lhs, const modular& _rhs) { return modular(_lhs) -= _rhs; }\ntemplate inline modular operator*(const modular& _lhs, const modular& _rhs) { return modular(_lhs) *= _rhs; }\ntemplate inline modular operator*(const modular& _lhs, const U& _rhs) { return modular(_lhs) *= _rhs; }\ntemplate inline modular operator*(const U& _lhs, const modular& _rhs) { return modular(_lhs) *= _rhs; }\ntemplate inline modular operator/(const modular& _lhs, const modular& _rhs) { return modular(_lhs) /= _rhs; }\ntemplate inline modular operator/(const modular& _lhs, const U& _rhs) { return modular(_lhs) /= _rhs; }\ntemplate inline modular operator/(const U& _lhs, const modular& _rhs) { return modular(_lhs) /= _rhs; }\ntemplate inline bool operator==(const modular& _lhs, const modular& _rhs) { return _lhs.val == _rhs.val; }\ntemplate inline bool operator==(const modular& _lhs, const U& _rhs) { return _lhs == modular(_rhs); }\ntemplate inline bool operator==(const U& _lhs, const modular& _rhs) { return modular(_lhs) == _rhs; }\ntemplate inline bool operator!=(const modular& _lhs, const modular& _rhs) { return !(_lhs == _rhs); }\ntemplate inline bool operator!=(const modular& _lhs, const U& _rhs) { return !(_lhs == _rhs); }\ntemplate inline bool operator!=(const U& _lhs, const modular& _rhs) { return !(_lhs == _rhs); }\ntypedef modular mint;\n\nconst int N = 3003; \nmint dp[N][N];\n\nvoid solve() {\n memset(dp, 0, sizeof dp);\n int n, m;\n cin >> n >> m;\n vector a(n);\n vector w(n);\n for (auto& x: a) {\n cin >> x;\n }\n int H = 0, T = 0;\n for (int i = 0; i < n; i++) {\n int x; cin >> x;\n w[i] = x;\n if (a[i]) H += x;\n else T += x;\n }\n int tot = H + T;\n dp[0][0] = 1;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j <= i; j++) {\n if (i-j <= T) {\n dp[i+1][j] += dp[i][j] * (T - (i-j)) / (tot + j - (i-j));\n dp[i+1][j+1] += dp[i][j] * (H + j) / (tot + j - (i-j));\n }\n }\n }\n mint ad = 0;\n mint mi = 0;\n for (int j = 0; j <= m; j++) {\n ad += dp[m][j] * j;\n mi += dp[m][j] * (m-j);\n }\n vector res(n);\n for (int i = 0; i < n; i++) {\n if (a[i]) {\n res[i] = w[i] + ad * w[i] / H;\n }else {\n res[i] = w[i] - mi * w[i] / T;\n }\n }\n for (auto& x: res) {\n cout << x << \"\\n\";\n }\n}\n\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n solve();\n cout << endl;\n}\n", "lang_cluster": "C++", "tags": ["dp", "probabilities"], "code_uid": "f6e2c6c49811cbe1e2637de827a7c7ef", "src_uid": "ba9c136f84375cd317f0f8b53e3939c7", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \nusing namespace std;\n#define Maxn 1000\nint head[Maxn+5],arrive[Maxn<<1|5],nxt[Maxn<<1|5],tot;\nvoid add_edge(int from,int to){\n\tarrive[++tot]=to;\n\tnxt[tot]=head[from];\n\thead[from]=tot;\n}\nint n;\nint sz[Maxn+5],maxn[Maxn+5];\nint rt,G;\nint mx(int a,int b){\n\treturn a>b?a:b;\n}\nvoid get_root(int root,int fa){\n\tsz[root]=1;\n\tfor(int i=head[root];i;i=nxt[i]){\n\t\tif(arrive[i]==fa){\n\t\t\tcontinue;\n\t\t}\n\t\tget_root(arrive[i],root);\n\t\tsz[root]+=sz[arrive[i]];\n\t\tmaxn[root]=mx(maxn[root],sz[arrive[i]]);\n\t}\n\tmaxn[root]=mx(maxn[root],n-sz[root]);\n\tif(G>maxn[root]){\n\t\tG=maxn[root];\n\t\trt=root;\n\t}\n}\nint fa[Maxn+5];\nvoid init_dfs(int root){\n\tsz[root]=1;\n\tfor(int i=head[root];i;i=nxt[i]){\n\t\tif(arrive[i]==fa[root]){\n\t\t\tcontinue;\n\t\t}\n\t\tfa[arrive[i]]=root;\n\t\tinit_dfs(arrive[i]);\n\t\tsz[root]+=sz[arrive[i]];\n\t}\n}\nvector edge[Maxn+5];\nbool cmp(int x,int y){\n\treturn sz[x]>sz[y];\n}\nint cnt=1,t=1;\nvoid dfs_1(int root,int w){\n\tprintf(\"%d %d %d\\n\",fa[root],root,cnt-w);\n\tint now=cnt;\n\tcnt++;\n\tfor(int i=0;i<(int)edge[root].size();i++){\n\t\tif(edge[root][i]==fa[root]){\n\t\t\tcontinue;\n\t\t}\n\t\tdfs_1(edge[root][i],now);\n\t}\n}\nvoid dfs_2(int root,int w){\n\tprintf(\"%d %d %d\\n\",fa[root],root,cnt*t-w);\n\tint now=cnt*t;\n\tt++;\n\tfor(int i=0;i<(int)edge[root].size();i++){\n\t\tif(edge[root][i]==fa[root]){\n\t\t\tcontinue;\n\t\t}\n\t\tdfs_2(edge[root][i],now);\n\t}\n}\nint main(){\n\tscanf(\"%d\",&n);\n\tint u,v;\n\tfor(int i=1;i\n#define ll long long\nusing namespace std;\nconst int MAXN=1e5+10;\nstruct node{int c,id;bool operator<(const node &r)const{return c==r.c?id>r.id:cq;\nll n,m,k,c[MAXN];\nll d[MAXN],a[MAXN],k1[25],k2[25],h;\nbool vis[MAXN];\nqueuef;\nint main()\n{\n\tios::sync_with_stdio(0);\n\tcin>>h>>n>>m>>k;\n\tfor(int i=0;i<=k;++i) d[i]=1e18;\n\td[1]=0;\n\tfor(int i=1;i<=n;++i)\n\t{\n\t\tcin>>a[i]>>c[i];\n\t\tif(a[i]%k==1||k==1)\n\t\t\tq.push((node){c[i],i});\n\t}\n\tint now=0;\n\twhile(m--)\n\t{\n\t\tint op;\n\t\tll x,y,z;\n\t\tcin>>op;\n\t\tif(op==1)\n\t\t{\n\t\t\tcin>>z;\n\t\t\tif(k==1) continue;\n\t\t\tk1[++now]=z/k;\n\t\t\tk2[now]=z%k;\n\t\t\tint l=0,r=0;\n\t\t\tfor(int i=1;i<=k;++i)\n\t\t\t\tf.push(i-1);\n\t\t\twhile(!f.empty())\n\t\t\t{\n\t\t\t\tx=f.front();\n\t\t\t\tf.pop();\n\t\t\t\tvis[x]=0;\n\t\t\t\tfor(int i=1;i<=now;++i)\n\t\t\t\t{\n\t\t\t\t\t(y=x+k2[i])%=k;\n\t\t\t\t\tz=d[x]+k1[i]+(x+k2[i])/k;\n\t\t\t\t\tif(z>x>>y;\n\t\t\tc[x]-=y;\n\t\t\tif(d[a[x]%k]<=a[x]/k||k==1)\n\t\t\t\tq.push((node){c[x],x});\n\t\t}\n\t\tif(op==3)\n\t\t{\n\t\t\twhile(!q.empty()&&c[q.top().id]!=q.top().c) q.pop();\n\t\t\tif(q.empty()) cout<<\"0\"<\n#define fi first\n#define se second\n#define NAME \"data\"\nusing namespace std;\ntypedef long long LL;\ntypedef double DB;\ntypedef pair pLL;\nconst int NMAX = 3e5+7;\nconst LL MOD = 998244353;\n\nint n;\nvector a[NMAX];\nLL f[3][NMAX];\n\nLL rv(LL a, LL b = MOD) {\n LL xa, xb, xr, r;\n xa = 1; xb = 0;\n while(b != 0) {\n LL q = a / b;\n r = a - b*q;\n xr = xa - xb*q;\n a = b; xa = xb;\n b = r; xb = xr;\n }\n return (xa+MOD)%MOD;\n}\n\nvoid dp(int u, int p) {\n for(auto v : a[u])\n if(v != p) dp(v, u);\n\n f[0][u] = 1;\n for(auto v : a[u])\n if(v != p) f[0][u] = f[0][u] * ((f[0][v]+f[1][v])%MOD) % MOD;\n\n LL tmp = 1;\n for(auto v : a[u])\n if(v != p)\n tmp = tmp * (f[0][v]+f[1][v]*2%MOD) % MOD;\n for(auto v : a[u])\n if(v != p)\n f[1][u] = (f[1][u] + tmp * rv(f[0][v]+2*f[1][v]%MOD) % MOD * ((f[0][v]+f[2][v])%MOD) % MOD) % MOD;\n\n LL tmp1 = 1;\n LL tmp2 = 1;\n for(auto v : a[u])\n if(v != p) {\n tmp1 = tmp1 * ((f[1][v]*2%MOD+f[0][v])%MOD) % MOD;\n tmp2 = tmp2 *((f[1][v]+f[0][v])%MOD) % MOD;\n }\n f[2][u] = (tmp1 - tmp2 + MOD*MOD) % MOD;\n\n //cerr << u << \" : \" << f[0][u] << ' ' << f[1][u] << ' ' << f[2][u] << '\\n';\n}\n\nint main() {\n ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n //freopen(NAME\".inp\", \"r\", stdin);\n //freopen(NAME\".out\", \"w\", stdout);\n cin >> n;\n for(int i = 1; i < n; ++i) {\n int u, v;\n cin >> u >> v;\n a[u].push_back(v);\n a[v].push_back(u);\n }\n dp(1, 1);\n cout << (f[1][1] + f[0][1])%MOD;\n}\n\n", "lang_cluster": "C++", "tags": ["dp", "trees"], "code_uid": "e0cf63d8919ac18dd356c132bed501e3", "src_uid": "a40e78a7144ac2fae1890ac7598990bf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\n#include\n#include\n#include\n#define rep(i,l,r) for (int i=(l); i<=(r); i++)\ntypedef long long ll;\nusing namespace std;\n\nconst int N=510,mod=1e9+7;\nint n,m,a[N],b[N],c[N],z[N],A[N],B[N];\nll K;\n\nvoid inc(int &x,int y){ x=x+y>=mod ? x+y-mod : x+y;}\nvoid dec(int &x,int y){ x=x-y<0 ? x-y+mod : x-y;}\n\nvoid mult(int u[],int v[]){\n\tmemset(z,0,sizeof(z));\n\trep(i,0,249) rep(j,0,249) z[i+j]=(z[i+j]+1LL*u[i]*v[j])%mod;\n\tfor(int i=498; i>=250; i--)\n\t\trep(j,1,m) inc(z[i-b[j]],z[i]);\n\trep(i,0,249) u[i]=z[i];\n}\n\nvoid ksm(int c[],ll n){\n\tmemset(A,0,sizeof(A));\n\tA[0]=1;\n\twhile(n){\n\t\tif(n&1) mult(A,c);\n\t\tn>>=1,mult(c,c);\n\t}\n}\n\nint main(){\n\tcin>>n>>m>>K;\n\trep(i,1,n) scanf(\"%d\",&a[i]);\n\trep(i,1,m) scanf(\"%d\",&b[i]);\n\trep(i,1,n){\n\t\tmemset(c,0,sizeof(c));\n\t\tc[1]=1; ksm(c,a[i]);\n\t\trep(j,0,249) inc(B[j],A[j]);\n\t}\n\tksm(B,K);\n\trep(i,0,249) B[i]=A[i];\n\tfor(int i=249; i>0; i--) rep(j,1,m) if(i>=b[j]) inc(B[i-b[j]],B[i]);\n\tcout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\n//#define int long long\ntypedef long long ll;\n\ntypedef unsigned long long ul;\ntypedef unsigned int ui;\nll mod = 1000000009;\nconst ll INF = mod * mod;\ntypedef pairP;\n#define stop char nyaa;cin>>nyaa;\n#define rep(i,n) for(int i=0;i=0;i--)\n#define Rep(i,sta,n) for(int i=sta;i=1;i--)\n#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)\n#define all(v) (v).begin(),(v).end()\ntypedef pair LP;\ntypedef double ld;\ntypedef pair LDP;\nconst ld eps = 1e-12;\nconst ld pi = acosl(-1.0);\n\nll mod_pow(ll x, ll n, ll m = mod) {\n ll res = 1;\n while (n) {\n if (n & 1)res = res * x % m;\n x = x * x % m; n >>= 1;\n }\n return res;\n}\nstruct modint {\n ll n;\n modint() :n(0) { ; }\n modint(ll m) :n(m) {\n if (n >= mod)n %= mod;\n else if (n < 0)n = (n % mod + mod) % mod;\n }\n operator int() { return n; }\n};\nbool operator==(modint a, modint b) { return a.n == b.n; }\nmodint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }\nmodint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }\nmodint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }\nmodint operator+(modint a, modint b) { return a += b; }\nmodint operator-(modint a, modint b) { return a -= b; }\nmodint operator*(modint a, modint b) { return a *= b; }\nmodint operator^(modint a, ll n) {\n if (n == 0)return modint(1);\n modint res = (a * a) ^ (n / 2);\n if (n % 2)res = res * a;\n return res;\n}\n\nll inv(ll a, ll p) {\n return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);\n}\nmodint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }\n\nconst int max_n = 1 << 18;\nmodint fact[max_n], factinv[max_n];\nvoid init_f() {\n fact[0] = modint(1);\n for (int i = 0; i < max_n - 1; i++) {\n fact[i + 1] = fact[i] * modint(i + 1);\n }\n factinv[max_n - 1] = modint(1) / fact[max_n - 1];\n for (int i = max_n - 2; i >= 0; i--) {\n factinv[i] = factinv[i + 1] * modint(i + 1);\n }\n}\nmodint comb(int a, int b) {\n if (a < 0 || b < 0 || a < b)return 0;\n return fact[a] * factinv[b] * factinv[a - b];\n}\n\nusing mP = pair;\nmP mul(mP a, mP b) {\n return { a.first * b.first,a.second * b.first + a.first * b.second };\n}\nmP plu(mP a, mP b) {\n return { a.first + b.first,a.second + b.second };\n}\n\n\nmP dp[501];\nbool used[501];\nvoid init() {\n init_f();\n dp[0] = { 1,0 };\n dp[1] = { 2,0 };\n for (int n = 2; n <= 500; n++) {\n rep(j, n) {\n modint cnt = n + 1; modint sum = 0;\n rep(k, n)sum += abs(j - k);\n mP cl = dp[j];\n mP cr = dp[n - 1 - j];\n mP x = mul(cl, cr);\n x.first *= comb(n - 1, j);\n x.second *= comb(n - 1, j);\n x = mul(x, { cnt,sum });\n dp[n] = plu(dp[n], x);\n }\n }\n}\n\nmP dp2[502][501];\nvoid solve() {\n int n, m; cin >> n >> m >> mod;\n init();\n dp2[0][0] = { 1,0 };\n rep(i, n) {\n rep(k, i + 1) {\n for (int j = i; j < n; j++) {\n int ni = j + 2; ni = min(ni, n);\n int nk = k + j - i + 1;\n if (nk <= m) {\n mP x = mul(dp2[i][k], dp[j - i + 1]);\n x.first *= comb(nk, k);\n x.second *= comb(nk, k);\n dp2[ni][nk] = plu(dp2[ni][nk], x);\n }\n }\n dp2[i + 1][k] = plu(dp2[i + 1][k], dp2[i][k]);\n }\n }\n modint ans = dp2[n][m].second;\n cout << ans << \"\\n\";\n}\n\nsigned main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n // cout << fixed << setprecision(15);\n //init_f();\n //init();\n //expr();\n //int t; cin >> t; rep(i, t)\n solve();\n return 0;\n}", "lang_cluster": "C++", "tags": ["dp", "combinatorics", "fft"], "code_uid": "a30a1237b67c849b051721c3ffa6bc07", "src_uid": "9812de5f2d272511a63ead8765b23190", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#include \n#define debug(x) cout << #x << \": \" << x << endl \n\nusing namespace std; \nconst int MAX_N = 33; \n\nconst long long MOD = 1000000007; \nlong long dp[MAX_N][2][2][2]; \nlong long numb[MAX_N][2][2][2]; \nint query; \nint X1, Y1, X2, Y2, k; \n\nvector change(int r) {\n\tvector res;\n\tfor (int i = 0; i < 31; i++) {\n\t\tif ((long long) r & (1LL << (long long) i)) {\n\t\t\tres.push_back(1); \t\n\t\t}\n\t\telse {\n\t\t\tres.push_back(0); \n\t\t}\n\t}\t\n\t\n\treturn res; \n}\n\nlong long calc(int x, int y) {\n\tif (x == 0 || y == 0) {\n\t\treturn 0; \n\t}\n\n\tmemset(dp, 0LL, sizeof(dp)); \n\tmemset(numb, 0LL, sizeof(numb)); \n\tvector X, Y, K;\n\tX = change(x - 1);\n\tY = change(y - 1);\n\tK = change(k - 1);\n long long res = 0LL; \n \n numb[31][1][1][1] = 1; \n \n\tfor (int i = 31; i >= 1; i--) {\n\t\t//cout << i << endl; \n\t\tfor (int flagX = 0; flagX <= 1; flagX++) {\n\t\t\tfor (int flagY = 0; flagY <= 1; flagY++) {\n\t\t\t\tfor (int flagK = 0; flagK <= 1; flagK++) {\n\t\t\t\t\t//cout << dp[i][flagX][flagY][flagK] << endl; \n\t\t\t\t\tif (numb[i][flagX][flagY][flagK] == 0) {\n\t\t\t\t\t\tcontinue; \n\t\t\t\t\t}\n\n\t\t\t\t\t//cout << i << ' ' << flagX << ' ' << flagY << ' ' << flagK << ' ' << numb[i][flagX][flagY][flagK] << ' ' << dp[i][flagX][flagY][flagK] << endl; \n\t\t\t\t\tfor (int b1 = 0; b1 <= 1; b1++) {\n\t\t\t\t\t\tfor (int b2 = 0; b2 <= 1; b2++) {\n\t\t\t\t\t\t\tif ((flagX == 1 && b1 > X[i - 1]) || (flagY == 1 && b2 > Y[i - 1]) || (flagK == 1 && ((b1 ^ b2) > K[i - 1]))) {\n\t\t\t\t\t\t\t\tcontinue; \n\t\t\t\t\t\t\t}\n\n int nflagX = (flagX == 1 && b1 == X[i - 1]);\n int nflagY = (flagY == 1 && b2 == Y[i - 1]); \n int nflagK = (flagK == 1 && ((b1 ^ b2) == K[i - 1])); \n (numb[i - 1][nflagX][nflagY][nflagK] += numb[i][flagX][flagY][flagK]) %= MOD; \n (dp[i - 1][nflagX][nflagY][nflagK] += ((dp[i][flagX][flagY][flagK] * 2LL) % MOD + numb[i][flagX][flagY][flagK] * (b1 ^ b2)) % MOD) %= MOD; \n\t\t\t\t\t\t}\n\t\t\t\t\t}\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (int flagX = 0; flagX <= 1; flagX++) {\n\t\tfor (int flagY = 0; flagY <= 1; flagY++) {\n\t\t\tfor (int flagK = 0; flagK <= 1; flagK++) {\n\t\t\t\t(res += dp[0][flagX][flagY][flagK]) %= MOD; \n\t\t\t\t(res += numb[0][flagX][flagY][flagK]) %= MOD; \n\t\t\t}\n\t\t}\n\t}\n\n\t//cout << res << endl; \n\n\treturn res; \n}\n\nint main () {\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout); \n\tscanf(\"%d\", &query);\n\twhile (query--) {\n\t\tscanf(\"%d %d %d %d %d\", &X1, &Y1, &X2, &Y2, &k); \n\t\tlong long res = calc(X2, Y2); \n\t\tres -= calc(X1 - 1, Y2);\n\t\tres -= calc(X2, Y1 - 1); \n\t\t(res += 3LL * MOD) %= MOD; \n\t\t(res += calc(X1 - 1, Y1 - 1)) %= MOD; \n\t\tprintf(\"%I64d\\n\", res); \n\t}\t\n\treturn 0; \n}", "lang_cluster": "C++", "tags": ["divide and conquer", "dp"], "code_uid": "0622244105420d31daa146ded89bfbc8", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n\n#define FO(i,a,b) for (int i = (a); i < (b); i++)\n#define sz(v) int(v.size())\n\nusing namespace std;\n\nint gdt(int,int);\n\nint gcd(int a, int b) {\n if (b == 0) return a;\n else return gcd(b, a % b);\n}\n\nint t2(int b, int d) {\n int r = 0;\n while (gcd(b,d) != 1) r++, d /= gcd(b,d);\n return d == 1 ? r : 0;\n}\n\nbool t6(int b, int d) {\n int D = d;\n\n int c = 2;\n while (d > 1) {\n int r = 1;\n while (d % c == 0) {\n d /= c;\n r *= c;\n }\n if (r == D) return false;\n if (gdt(b,r) == 7) return false;\n c++;\n }\n return true;\n}\n\nint gdt(int b, int d) {\n if (t2(b,d)) return 2;\n else if (b % d == 1) return 3;\n else if (b % d == d-1) return 11;\n else if (t6(b,d)) return 6;\n else return 7;\n}\n\nint main() {\n int b, d;\n scanf(\"%d %d\", &b, &d);\n int T = gdt(b,d);\n printf(\"%d-type\\n\", gdt(b,d));\n if (T == 2) printf(\"%d\\n\", t2(b,d));\n}\n\n", "lang_cluster": "C++", "tags": ["math", "number theory"], "code_uid": "6deae6cb4174159fb204b21edd7e15d8", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n\nusing namespace std;\n\ntypedef long long ll;\n\nvector ms = {(int) (1e9 + 7), (int) (1e9 + 9), (int) (998244353)};\nvector bs;\n\nstruct hash_str {\n vector h[3], p[3];\n hash_str(vector > e) {\n if (!e.empty()) {\n for (int i = 0; i < 3; i++) {\n h[i].resize(e.size());\n p[i].resize(e.size());\n h[i][0] = e[0].second + 1;\n p[i][0] = 1;\n for (int j = 1; j < (int) e.size(); j++) {\n h[i][j] = (h[i][j - 1] * (ll) bs[i] + e[j].second + 1) % ms[i];\n p[i][j] = (p[i][j - 1] * (ll) bs[i]) % ms[i];\n }\n }\n }\n }\n string get(int l, int r) {\n string s = \"\";\n for (int i = 0; i < 3; i++) {\n int hsh = 0;\n if (!l) {\n hsh = h[i][r];\n } else {\n hsh = h[i][r] - (h[i][l - 1] * (ll) p[i][r - l + 1]) % ms[i];\n if (hsh < 0) hsh += ms[i];\n }\n s += to_string(hsh);\n }\n return s;\n }\n};\n\nint main() {\n#ifdef iq\n\tfreopen(\"a.in\", \"r\", stdin);\n#endif\n ios::sync_with_stdio(0);\n cin.tie(0);\n mt19937 rnd(time(0));\n string s = \"asdasdasdfafdsfahfdashfdashfdashdahfkljdhsfkljdhasfhdsshfjdashfhyruyqrweyruoqewyryqew\";\n for (int i = 0; i < (int) s.size(); i++) rnd();\n for (int i = 0; i < 3; i++) {\n if (i == 0) {\n string s = \"asdasdasfdasfdasfhdasjhfvhfhfdlashfdashvkljdashfdashfjdhaskljfhfhhfshfkljashfkljdashhfdaslfhdasyhfryupwyerupqhqwurqewyewpuirhfasjfkldhsfkljdhsjflashduyfuqew ory \\n 21321321 \";\n int x = rnd() % 256;\n for (auto c : s) {\n x += c;\n }\n x %= 256;\n bs.push_back(x + 200);\n } else {\n bs.push_back((bs.back() * 12345 + rnd() % 23) % 256 + 200);\n }\n }//yes I forgot how to write a good random\n int n;\n cin >> n;\n string t;\n cin >> t;\n vector > a, b;\n int chet = 0;\n vector p(n);\n for (int i = 0; i < (int) t.size(); i++) {\n if (t[i] == '1') chet ^= 1;\n p[i] = chet;\n if (t[i] == '0') {\n a.push_back({i, chet});\n b.push_back({i, chet ^ 1});\n }\n }\n hash_str x(a);\n hash_str y(b);\n int q;\n cin >> q;\n auto f_a = [&] (int l, int r) {\n return x.get(l, r);\n };\n auto f_b = [&] (int l, int r) {\n return y.get(l, r);\n };\n auto get = [&] (int l, int r, int chet) {\n int x = -1, y = -1;\n {\n int vl = -1, vr = (int) a.size();\n while (vl < vr - 1) {\n int vm = (vl + vr) / 2;\n if (a[vm].first < l) {\n vl = vm;\n } else {\n vr = vm;\n }\n }\n x = vl + 1;\n }\n {\n int vl = -1, vr = (int) a.size();\n while (vl < vr - 1) {\n int vm = (vl + vr) / 2;\n if (a[vm].first <= r) {\n vl = vm;\n } else {\n vr = vm;\n }\n }\n y = vl;\n }\n if (x > y) {\n string s = \"\";\n return make_pair(0, s);\n } else {\n if (!chet)\n return make_pair(y - x + 1, f_a(x, y));\n else\n return make_pair(y - x + 1, f_b(x, y));\n }\n };\n auto f = [&] (int l, int r) {\n if (l && p[l - 1]) return get(l, r, 1);\n else return get(l, r, 0);\n };\n while (q--) {\n int l1, l2, len;\n cin >> l1 >> l2 >> len;\n l1--, l2--;\n if (f(l1, l1 + len - 1) != f(l2, l2 + len - 1)) {\n cout << \"No\\n\";\n } else {\n cout << \"Yes\\n\";\n }\n }\n}\n", "lang_cluster": "C++", "tags": ["strings", "data structures"], "code_uid": "64a0a66d6c4ba047efdae146177c0293", "src_uid": "6bd41042c6a442765cd93c73d55f6189", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "GNU C++", "source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nvector happy;\n\nvoid rec (int md, int d = 0, long long x = 0)\n{\n if (d == md)\n {\n happy.push_back(x);\n return;\n }\n for (int i = 0; i < 2; i++)\n {\n x *= 10;\n if (i)\n x += 7;\n else\n x += 4;\n rec(md, d + 1, x);\n x /= 10;\n }\n return;\n}\n\nlong long pl, pr, vl, vr, k;\n\nint main()\n{\n //freopen(\"input.txt\", \"r\", stdin);\n //freopen(\"output.txt\", \"w\", stdout);\n long long res = 0;\n happy.push_back(0);\n for (long long i = 1; i < 11; i++)\n rec(i);\n cin >> pl >> pr >> vl >> vr >> k;\n for (int i = 1; i < happy.size() - k; i++)\n {\n long long a = (min(pr, happy[i]) - max(happy[i - 1] + 1, pl) + 1);\n long long b = (min(vr, happy[i + k] - 1) - max(happy[i + k - 1], vl) + 1);\n long long c = (min(vr, happy[i]) - max(happy[i - 1] + 1, vl) + 1);\n long long d = (min(pr, happy[i + k] - 1) - max(happy[i + k - 1], pl) + 1);\n if (a > 0 && b > 0)\n res += a * b;\n if (c > 0 && d > 0)\n res += c * d;\n if (k == 1 && pl <= happy[i] && happy[i] <= pr && vl <= happy[i] && happy[i] <= vr)\n res--;\n }\n printf(\"%.12lf\", (double)res / (double)((pr - pl + 1) * (vr - vl + 1)));\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["dfs and similar", "probabilities", "combinatorics", "brute force"], "code_uid": "a727dcd2d84e91c4234630c0329aeeb0", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "//CLOCKS_PER_SEC\nusing namespace std;\n#include\n#define sqr(x) (x)*(x)\n//#define sort stable_sort\n#define ll long long\n#define mk make_pair\n#define pb push_back\n#define in insert\n#define mtr(x,y,z) mk(mk(x,y),z)\n#define fi first\n#define se second\n#define lch(x) ((x)<<1)\n#define rch(x) (((x)<<1)|1)\n#define all(x) (x).begin(),(x).end()\n#define titose CLOCKS_PER_SEC\n#define fpi(x) freopen(x,\"r\",stdin);\n#define fpo(x) freopen(x,\"w\",stdout);\n#define fprio fpi(\"in.txt\");fpo(\"out.txt\");\n#define fast ios_base::sync_with_stdio(false);\ninline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}\ninline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}\ninline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\\n');x=c;}\ninline void writes(string s){puts(s.c_str());}\ninline void writeln(){writes(\"\");}\ninline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}\ninline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}\n#define pii pair\n#define pll pair\n#define vi vector\n#define vl vector\n#define si set\n#define sl set\n#define mii map\n#define mll map\n#define msi map\n#define msl map\n#define piii pair\n#define piipi pair\n#define plll pair\n#define pllpl pair\n#define pqi priority_queue\n#define pql priority_queue\n#define npqi priority_queue,greater >\n#define npql priority_queue,greater >\n#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)\n#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)\n#define rep(i,x) forup ((i),1,(x))\n#define repd(i,x) fordo ((i),(x),1)\n#define itr iterator\n#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)\n#define NO {cout<<\"NO\";return 0;}\n#define YES {cout<<\"YES\";return 0;}\n#define y0 y000000000000000000000000000\n#define y1 y111111111111111111111111111\n#define j0 j000000000000000000000000000\n#define j1 j111111111111111111111111111\n#define cl0(a) memset((a),(0),(sizeof((a))))\n#define clz(a) memset((a),(0x16),(sizeof((a))))\n#define clf(a) memset((a),(-(0x16)),(sizeof((a))))\n#define inf 0x3bbbbbbb\n#define lnf 0x1bbbbbbbbbbbbbbbll\n#define sqrt divi\n#define p2(i) (1ll<<(i))\n#define readi read\n#define readll read\n/*************************************************/\nint mod=998244353;\nvoid add(int &x,int y)\n{\n\tx+=y;\n\tif(x>=mod) x-=mod;\n}\nint n,m,i,j,msk,cpx,cnx,cpy,cny,bx,by,dp[31][21][21][21][21][2][2],x[15],y[15],px[1<<5],py[1<<5],nx[1<<5],ny[1<<5];\nint main()\n{\n\tread(n);read(m);\n\trep(i,n){\n\t\tread(x[i]);\n\t\tread(y[i]);\n\t}\n\tforup(i,0,(1<>(j-1))&1){\n\t\t\t\t(x[j]>0?px[i]:nx[i])+=abs(x[j]);\n\t\t\t\t(y[j]>0?py[i]:ny[i])+=abs(y[j]);\n\t\t\t}\n\t\t}\n\t}\n\tdp[0][0][0][0][0][0][0]=1;\n\tforup(i,0,29){\n\t\tforup(cpx,0,19)forup(cnx,0,19)forup(cpy,0,19)forup(cny,0,19){\n\t\t\tforup(bx,0,1)forup(by,0,1)if(dp[i][cpx][cnx][cpy][cny][bx][by]){\n\t\t\t\tforup(msk,0,(1<>i)&1),my=mx;\n\t\t\t\t\tadd(dp[i+1][npx>>1][nnx>>1][npy>>1][nny>>1][(cx==mx)?bx:(cx>mx)][(cy==my)?by:(cy>my)],dp[i][cpx][cnx][cpy][cny][bx][by]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tcout<<(dp[30][0][0][0][0][0][0]+mod-1)%mod;\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["dp"], "code_uid": "f9b8768433486cc4a6e151f2c35329dc", "src_uid": "fba104bc43111a6f2692216a4edea2bc", "difficulty": 3500.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include\nusing namespace std;\n#define int long long\n#define N 2005\nstruct node{\n\tdouble x,y;\n\tint pos;\n\tbool flag;\n}p[N];\nint read(){\n\tchar ch=getchar();\n\twhile(ch!='L'&&ch!='R')ch=getchar();\n\treturn ch=='L';\n}\ndouble cross(double x1,double y1,double x2,double y2){\n\treturn (x1*y2-x2*y1);\n}\ndouble compare(node a,node b,node c){\n\treturn cross((b.x-a.x),(b.y-a.y),(c.x-a.x),(c.y-a.y));\n}\nbool cmp(node a,node b){\n\tif(a.y!=b.y)return a.y0)t=j;\n\t\t}\n\t\telse for(int j=1;j<=n;j++){\n\t\t\tif(!p[j].flag)continue;\n\t\t\tif(!p[t].flag||compare(p[la],p[j],p[t])<0)t=j;\n\t\t}\n\t\tans[i+1]=p[t].pos,p[t].flag=0,la=t;\n\t}\n\tfor(int i=1;i<=n;i++)\n\t\tif(p[i].flag){\n\t\t\tans[n]=p[i].pos;\n\t\t\tbreak;\n\t\t}\n\tfor(int i=1;i<=n;i++)\n\t\tprintf(\"%lld \",ans[i]);\n\treturn 0;\n}", "lang_cluster": "C++", "tags": ["math", "geometry", "constructive algorithms"], "code_uid": "9973b1c70bb341bc523e8a951d79b1a4", "src_uid": "13d7f6127a7fe945e19d461b584c6228", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#define ll long long\n#define clr(x) memset(x,0,sizeof(x))\n#define _clr(x) memset(x,-1,sizeof(x))\n#define fr(i,a,b) for(int i = a; i < b; ++i)\n#define frr(i,a,b) for(int i = a; i > b; --i)\n#define pb push_back\n#define sf scanf\n\n#define pf printf\n#define mp make_pair\n\nusing namespace std;\nconst ll mod = 1000000007;\nconst int MAXN = 10000005;\nconst double eps = 1e-6;\nint n,m,z;\nll a[1000000];\nint cmd[500010], v[500010],l[500010],r[500010],t[500010], s[1000010],val[1000010];\n\n\nmap time_idx, pre_time,ft;\nint idx;\n\nvoid add_t(int t) {\n\tif(time_idx.find(t)==time_idx.end()) {\n\t\tpre_time[idx]=t;\n\t\ttime_idx[t]=idx++;\n\t}\n}\n\nvoid push_down(int node) {\n}\n\nstruct Info{\n\t\n\tll s0; \n\tll st; \n\tll min_v;\n\tll sp;\n\tll start_time;\n\tll end_time;\n\tint flag;\n\tInfo(){flag = 0;}\n\n}info[1000010];\n\nInfo merge(const Info <, const Info &rt) {\n\t//printf(\"lt flag %d rt flag %d\\n\",lt.flag, rt.flag);\n\tInfo cur;\n\tif(lt.flag&&rt.flag) {\n\t\tint ed = lt.end_time;\n\t\tint sd = rt.start_time;\n\t\tll ssp = lt.st + (sd-ed)*lt.sp;\n\t\t//printf(\"ssp = %lld ed = %d sd = %d st = %lld sp = %lld\\n\",ssp,ed,sd, lt.st,lt.sp);\n\t\tcur.s0 = lt.s0;\n\t\tcur.st = ssp+rt.st;\n\t\tcur.min_v = min(lt.min_v,min(ssp,rt.min_v+ssp));\n\t\tcur.sp = rt.sp;\n\t\tcur.start_time = lt.start_time;\n\t\tcur.end_time = rt.end_time;\n\t\tcur.flag = 1;\n\t}\n\telse if(lt.flag) {\n\t\tcur = lt;\n\t}\n\telse if(rt.flag) {\n\t\tcur = rt;\n\t}\n\treturn cur;\n}\n\n\nvoid push_up(int node, int l, int r) {\n\tInfo lt = info[node<<1], rt = info[node<<1|1];\n\tinfo[node]=merge(lt,rt);\n}\n\nvoid add(int node, int l, int r, int t_idx, int v, int flag) {\n\t//printf(\"l = %d r = %d idx = %d v = %d\\n\",l,r,t_idx,v);\n\tif(l==r&&l==t_idx) {\n\t\tval[r] = v;\n\t\tinfo[node].s0 = 0;\n\t\tinfo[node].st = 0;\n\t\tinfo[node].min_v = 0;\n\t\tinfo[node].sp=v;\n\t\tinfo[node].start_time=pre_time[l];\n\t\tinfo[node].end_time=pre_time[r];\n\n\t\tif(flag>0) {\n\t\t\tinfo[node].flag=1;\n\t\t}\n\t\telse {\n\t\t\tinfo[node].flag=0;\n\t\t}\n\t\t//printf(\"node = %d v = %d flag = %d\\n\",node,v, flag);\n\t\treturn;\n\t}\n\n\tint mid = (l+r)>>1;\n\tif(mid>=t_idx) {\n\t\tadd(node<<1,l,mid,t_idx,v,flag);\n\t}\n\telse {\n\t\tadd(node<<1|1,mid+1,r,t_idx,v,flag);\n\t}\n\tpush_up(node,l,r);\n\tInfo cur = info[node];\n\t//printf(\"l = %d r = %d s0 = %lld st = %lld start = %lld end = %lld min = %lld flag %d\\n\",l,r,cur.s0,cur.st,cur.start_time,cur.end_time,cur.min_v, cur.flag);\n}\n\nInfo query(int node, int l, int r, int ql, int qr) {\n\t//printf(\"query l = %d r = %d ql = %d qr = %d\\n\",l,r, ql, qr);\n\tif(ql<=l&&qr>=r) {\n\t\treturn info[node];\n\t}\n\tif(ql>r||qr>1;\n\tif(qr<=mid) {\n\t\treturn query(node<<1,l,mid,ql,qr);\n\t}\n\telse if(ql>mid) {\n\t\treturn query(node<<1|1,mid+1,r,ql,qr);\n\t}\n\n\tInfo sum1 = query(node<<1,l,mid,ql,qr);\n\tInfo sum2 = query(node<<1|1,mid+1,r,ql,qr);\n\treturn merge(sum1,sum2);\n}\n\ndouble cal(double start,double end, int v) {\n\n\tauto it1 = ft.lower_bound(start);\n\tauto it2 = ft.upper_bound(end);\n\tif(it2!=ft.begin()) {\n\t\tit2--;\n\t\tif(it1->second > it2->second) return 0;\n\t\t//printf(\"cal start = %lf end = %lf v= %d\\n\",start,end,v);\n\t\tInfo sum;\n\t\tif(it1->second!=it2->second) {\n\t\t\tsum = query(1,0,idx-1,it1->second,it2->second);\n\t\t\t//printf(\"sum %lld\\n\",sum.sp);\n\t\t}\n\t\telse {\n\t\t\tsum.st = 0;\n\t\t\tsum.sp = val[it2->second];\n\t\t\tsum.end_time = it2->first;\n\t\t\tsum.start_time = it2->first;\n\t\t\tsum.min_v = 0;\n\t\t}\n\t\tdouble left_t = end-sum.end_time;\n\t\tdouble res = sum.st+sum.sp*left_t;\n\t\t//printf(\"st = %lld sp = %lld res = %.10lf\\n\",sum.st,sum.sp,res);\n\t\tdouble min_v = min((double)sum.min_v, res);\n\t\t//printf(\"total sum = %lf left = %lf min = %lf last = %lld end = %lf last end = %lld\\n\",res, left_t, min_v,sum.sp, end, sum.end_time);\n\t\treturn min_v;\n\t}\n\telse {\n\t\treturn 0;\n\t}\n}\n\nvoid query(int start,int end, int v) {\n\tif(v==0) {\n\t\tprintf(\"%d\\n\",start);\n\t\treturn;\n\t}\n\tauto it1 = ft.lower_bound(start);\n\tauto it2 = ft.lower_bound(end);\n\tif(it1 == it2) {\n\t\tprintf(\"-1\\n\");\n\t\treturn;\n\t\tif(it1==ft.begin()) {\n\t\t\tprintf(\"-1\\n\");\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tit1--;\n\t\t\tll s = val[it1->second];\n\t\t\tll sum = s*(end-start);\n\t\t\tdouble x = (double)v/s;\n\t\t\tif(start+x>end+eps) {\n\t\t\t\tprintf(\"-1\\n\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tprintf(\"%.6lf\\n\",start+x);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n\n\t//printf(\"query start = %d end = %d v = %d\\n\",start,end,v);\n\tdouble l = start, r = end+eps;\t\n\tfor(int i = 0; i < 48&&fabs(l-r)>eps; ++i) {\n\t\tdouble mid =(l+r)/2.0;\n\t\tdouble sum = cal(start,mid,v);\n\t\tif(sum+v>eps){\n\t\t\tl = mid;\t\n\t\t}\n\t\telse {\n\t\t\tr = mid;\n\t\t}\n\t}\n\t//printf(\"l = %lf r = %lf\\n\",l,r);\n\tdouble t = cal(start,r,v);\n\t//printf(\"l = %lf r = %lf sum = %.10lf, %d\\n\",l,r,t, (t+v)>eps);\n\tt+=v;\n\t//printf(\"l = %lf t = %.10lf check %d\\n\",r,t, (t-eps)>=0);\n\tif(t>eps) printf(\"-1\\n\");\n\telse printf(\"%.6lf\\n\",r);\n}\n\nvoid sol(){\n\tfr(i,0,n) {\n\t\t//printf(\"i = %d\\n\",i);\n\t\tif(cmd[i]==1) {\n\t\t\tadd(1,0,idx-1,time_idx[t[i]],s[i],1);\n\t\t\tft[t[i]]=time_idx[t[i]];\n\t\t}\n\t\telse if(cmd[i]==2) {\n\t\t\tadd(1,0,idx-1,time_idx[t[i]],0,0);\n\t\t\tft.erase(ft.find(t[i]));\n\t\t}\n\t\telse {\n\t\t\tquery(l[i],r[i],v[i]);\n\t\t}\n\t}\n}\n\nint main(){\n\n\tidx = 0;\n\tsf(\"%d\",&n);\n\tvector xxx;\n\tfr(i,0,n) {\n\t\tsf(\"%d\",&cmd[i]);\n\t\tif(cmd[i]==1) {\n\t\t\tsf(\"%d%d\",&t[i],&s[i]);\n\t\t\txxx.pb(t[i]);\n\t\t}\n\t\telse if(cmd[i]==2) {\n\t\t\tsf(\"%d\",&t[i]);\n\t\t}\n\t\telse if(cmd[i]==3) {\n\t\t\tsf(\"%d%d%d\",&l[i],&r[i],&v[i]);\n\t\t}\n\t}\n\tsort(xxx.begin(), xxx.end());\n\tint pos = unique(xxx.begin(), xxx.end())-xxx.begin();\n\tfor(int i = 0; i < pos; ++i) {\n\t\tadd_t(xxx[i]);\n\t}\n\tsol();\n}\n", "lang_cluster": "C++", "tags": ["data structures"], "code_uid": "cba864da2153719200334186757ea492", "src_uid": "23440d055baf6c831e91e76b99b9ada8", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++11", "source_code": "#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define mp make_pair\n#define pb push_back\n#define ll long long\n\n#define maxN 66\n\nint r, c, n, i;\nchar s[maxN];\nll comb[maxN][maxN];\n\nint cnt_a[maxN], cnt_b[maxN];\nvector partial[maxN], partial_zero[maxN];\n\nvoid compute_comb() {\n int i, j;\n\n for (i = 0; i <= n; i++) {\n comb[i][0] = 1;\n for (j = 1; j <= i; j++)\n comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];\n }\n}\n\nll get_difs(int conf, int a_bef, int b_bef) {\n int i;\n ll ans = 0;\n ll aux1, aux2;\n\n for (i = 0; i < c + 1; i++) {\n if (conf & (1 << i)) {\n //! here comes a B\n b_bef++;\n\n aux1 = comb[b_bef - 1][r - 1];\n aux2 = comb[n - b_bef][r] - comb[a_bef][r];\n\n ans -= aux1 * aux2;\n } else {\n //! here comes an A\n a_bef++;\n\n aux1 = comb[a_bef - 1][r - 1];\n aux2 = comb[n - a_bef][r] - comb[b_bef][r];\n\n ans += aux1 * aux2;\n }\n }\n\n return ans;\n}\n\nbool check(int conf) {\n int i;\n\n for (i = 0; i < c + 1; i++) {\n if (s[2 * r + c + i] == 'A' && ( (conf >> i) & 1 ) == 1) return false;\n if (s[2 * r + c + i] == 'B' && ( (conf >> i) & 1 ) == 0) return false;\n }\n\n return true;\n}\n\nvoid compute_second_part() {\n int i, conf;\n int limit = 1 << (c + 1);\n int a_here, b_here;\n\n for (conf = 0; conf < limit; conf++) {\n b_here = __builtin_popcount(conf);\n a_here = c + 1 - b_here;\n\n if (check(conf))\n partial[a_here].pb(get_difs(conf, r + c - a_here, r + c - b_here));\n else\n partial_zero[a_here].pb(get_difs(conf, r + c - a_here, r + c - b_here));\n }\n\n for (i = 0; i <= c + 1; i++) {\n sort(partial[i].begin(), partial[i].end());\n sort(partial_zero[i].begin(), partial_zero[i].end());\n }\n}\n\nll get_coef(int conf) {\n int i, j;\n\n for (i = 0; i < c + 1; i++)\n if ( ((conf >> i) & 1) != (conf & 1) )\n break;\n\n for (j = i; j < c + 1; j++) {\n if (s[2 * r - 1 + j] == 'A' && (( (conf >> j) & 1 ) == 1)) return 0;\n if (s[2 * r - 1 + j] == 'B' && (( (conf >> j) & 1 ) == 0)) return 0;\n }\n\n int set_a = r - 1 + ( (conf & 1) == 0 ? i : 0 );\n int set_b = r - 1 + ( (conf & 1) == 1 ? i : 0 );\n\n if (set_a < cnt_a[2 * r - 2 + i]) return 0;\n if (set_b < cnt_b[2 * r - 2 + i]) return 0;\n return comb[set_a + set_b - cnt_a[2 * r - 2 + i] - cnt_b[2 * r - 2 + i]][set_a - cnt_a[2 * r - 2 + i]];\n}\n\nvoid upd(pair& ans, pair act) {\n if (act.first < 0) act.first = -act.first;\n\n if (ans.first < act.first) return;\n if (ans.first > act.first) {\n ans = act;\n return;\n }\n\n ans.second += act.second;\n}\n\nll how_many(vector& data, ll val) {\n auto it1 = lower_bound(data.begin(), data.end(), val);\n auto it2 = upper_bound(data.begin(), data.end(), val);\n return it2 - it1;\n}\n\nll compute_first_part() {\n int i, conf;\n int limit = 1 << (c + 1);\n int a_here, b_here;\n ll act, coef, coef2;\n pair ans = mp(1LL << 60, 0);\n\n\n for (conf = 0; conf < limit; conf++) {\n b_here = __builtin_popcount(conf);\n a_here = c + 1 - b_here;\n act = get_difs(conf, r - 1, r - 1);\n\n //! coef may be != 0\n coef = get_coef(conf);\n auto it = lower_bound(partial[c + 1 - a_here].begin(),\n partial[c + 1 - a_here].end(),\n -act);\n\n\n if (it != partial[c + 1 - a_here].end()) {\n if (ans.first >= abs(*it + act)) {\n coef2 = how_many(partial[c + 1 - a_here], *it);\n upd(ans, mp(*it + act, coef * coef2));\n }\n }\n\n if (it != partial[c + 1 - a_here].begin()) {\n it--;\n if (ans.first >= abs(*it + act)) {\n coef2 = how_many(partial[c + 1 - a_here], *it);\n upd(ans, mp(*it + act, coef * coef2));\n }\n }\n\n //! coef is clearly 0\n coef = 0;\n it = lower_bound(partial_zero[c + 1 - a_here].begin(),\n partial_zero[c + 1 - a_here].end(),\n -act);\n\n\n if (it != partial_zero[c + 1 - a_here].end()) {\n coef2 = how_many(partial[c + 1 - a_here], *it);\n if (ans.first >= abs(*it + act)) {\n coef2 = how_many(partial[c + 1 - a_here], *it);\n upd(ans, mp(*it + act, coef * coef2));\n }\n }\n\n if (it != partial_zero[c + 1 - a_here].begin()) {\n it--;\n if (ans.first >= abs(*it + act)) {\n coef2 = how_many(partial[c + 1 - a_here], *it);\n upd(ans, mp(*it + act, coef * coef2));\n }\n }\n }\n\n return ans.second;\n}\n\nint main()\n{\n //freopen(\"test.in\",\"r\",stdin);\n\n scanf(\"%d%d\\n%s\", &r, &c, s + 1);\n n = 2 * (r + c);\n\n compute_comb();\n\n for (i = 1; i <= n; i++) {\n cnt_a[i] = cnt_a[i - 1] + (s[i] == 'A' ? 1 : 0);\n cnt_b[i] = cnt_b[i - 1] + (s[i] == 'B' ? 1 : 0);\n }\n\n compute_second_part();\n ll sol = compute_first_part();\n\n printf(\"%lld\", sol);\n\n return 0;\n}\n", "lang_cluster": "C++", "tags": ["meet-in-the-middle", "combinatorics"], "code_uid": "bfdb92370f4178211c969e0651acabbc", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "GNU C++14", "source_code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC optimize (\"unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#include \nusing namespace std;\n\nvector v1, v2, ps1, ps2; string s1, s2, aux1, aux2;\nvector> ans, aux;\n\nvoid addLast(string &str, vector &pos) {\n for (int i = 0, j = 0; i < str.length(); i = j) {\n while (j < str.length() and str[j] == str[i]) {\n ++j; }\n pos.push_back(j - 1); } }\n\ninline int siz(vector &pos, int p) {\n if (p < 0 or !pos.size()) {\n return 0; }\n if (p >= pos.size()) {\n return pos.back() + 1; }\n return pos[p] + 1; }\n\nvoid solve(string &str1, string &str2, vector> &ans) {\n ps1.clear(); ps2.clear(); addLast(str1, ps1); addLast(str2, ps2);\n int c1 = (int) max(ps1.size() - (ps1.size() and str1.back() == 'a'),\n ps2.size() - (ps2.size() and str2.back() == 'b')),\n c2 = (int) max(ps1.size() - (ps1.size() and str1.back() == 'b'),\n ps2.size() - (ps2.size() and str2.back() == 'a'));\n if (c1 <= c2) { // move 'a' to string 1, 'b' to string 2\n int p1 = (int) ps1.size() - 1, p2 = (int) ps2.size() - 1;\n if (ps1.size() and str1.back() == 'a') { --p1; }\n if (ps2.size() and str2.back() == 'b') { --p2; }\n for (bool ok = false; p1 >= 0 or p2 >= 0; --p1, --p2, ok ^= true) {\n ans.push_back(!ok ? make_pair(siz(ps1, p1), siz(ps2, p2)) :\n make_pair(siz(ps2, p2), siz(ps1, p1))); } }\n else {\n int p1 = (int) ps1.size() - 1, p2 = (int) ps2.size() - 1;\n if (ps1.size() and str1.back() == 'b') { --p1; }\n if (ps2.size() and str2.back() == 'a') { --p2; }\n for (bool ok = false; p1 >= 0 or p2 >= 0; --p1, --p2, ok ^= true) {\n ans.push_back(!ok ? make_pair(siz(ps1, p1), siz(ps2, p2)) :\n make_pair(siz(ps2, p2), siz(ps1, p1))); } } }\n\nint main(void) {\n ios::sync_with_stdio(false);\n cin.tie(0); cout.tie(0);\n cin >> s1 >> s2; bool ok = false;\n addLast(s1, v1); addLast(s2, v2);\n if (v1.size() > v2.size()) {\n swap(v1, v2); swap(s1, s2); ok = true; }\n solve(s1, s2, ans);\n for (int i = -1; i <= min(3, (int) v1.size()); ++i) {\n int x = (int) max(-1, (int)((v2.size() - v1.size()) / 2 - 3)),\n y = (int) min(v2.size(), (v2.size() - v1.size()) / 2 + 3);\n for (int j = x; j <= y; ++j) {\n int p1 = siz(v1, i), p2 = siz(v2, j);\n aux2 = s1.substr(0, p1) + s2.substr(p2);\n aux1 = s2.substr(0, p2) + s1.substr(p1);\n // cerr << aux1 << \" \" << aux2 << \"\\n\";\n aux.clear(); aux.push_back(make_pair(p1, p2));\n solve(aux1, aux2, aux);\n if (aux.size() < ans.size()) {\n ans = aux; } } }\n cout << ans.size() << \"\\n\";\n if (ok) {\n for (pair &p : ans) {\n swap(p.first, p.second); } }\n for (pair p : ans) {\n cout << p.first << \" \" << p.second << \"\\n\"; }\n return 0; }\n", "lang_cluster": "C++", "tags": ["strings", "constructive algorithms"], "code_uid": "9563e14d21ad08cd7d167c7e3b2398fb", "src_uid": "4a50c4147becea13946272230f3dde6d", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "GNU C++17", "source_code": "#include\nusing namespace std;\nconst int maxn = 1e5 + 10;\n\nchar A[maxn],B[maxn];\nint f[30];\nint to[30];\nint dp[1 << 20],vis[1 << 20];\nint n;\n\nint ufind(int x){\n return x == f[x] ? x : f[x] = ufind(f[x]);\n}\n\nint main(){\n int T; scanf(\"%d\",&T);\n while(T-- ){\n scanf(\"%d\",&n);\n scanf(\"%s%s\",A + 1,B + 1);\n memset(to,0,sizeof(to));\n for(int i = 0 ; i < 20 ; i++ )\n f[i] = i;\n for(int i = 1 ; i <= n ; i++ ){\n int u = A[i] - 'a',v = B[i] - 'a';\n to[u] |= (1 << v);\n int fu = ufind(u),fv = ufind(v);\n if(fu == fv) continue;\n f[fu] = fv; \n }\n int ans = 40;\n for(int i = 0 ; i < 20 ; i++ )\n if(i == ufind(i)) --ans;\n memset(dp,0,sizeof(dp));\n dp[0] = 1;\n int maxi = 0;\n for(int s = 0 ; s < (1 << 20) ; s++ ){\n if(!dp[s]) continue;\n int cnt = 0;\n for(int i = 0 ; i < 20 ; i++ ){\n int u = (1 << i);\n if(s & u) ++cnt;\n if(s & to[i]) continue;\n dp[s | u] = 1;\n }\n maxi = max(maxi,cnt);\n }\n printf(\"%d\\n\", ans - maxi);\n }\n return 0;\n}", "lang_cluster": "C++", "tags": ["dp", "graphs", "trees", "bitmasks"], "code_uid": "a4d97afa27a5d34d4e956a6e57d933a7", "src_uid": "d0735a763e2a40bfc94085019cd646f0", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "MS C++", "source_code": "#pragma comment(linker, \"/STACK:102400000,102400000\")\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define CLR(a,v) memset(a,v,sizeof(a))\n#define ReadFile(file) freopen(file,\"r\",stdin) \n#define WriteFile(file) freopen(file,\"w\",stdout)\nusing namespace std;\ntypedef long long ll;\ntypedef pair pii;\ntypedef unsigned int uint;\ntypedef unsigned long long ull;\n\nconst double eps = 1e-6;\nconst double PI = acos(-1.0);\nconst double EPS = eps;\nconst double pi = PI;\nconst int N = 1e2+10;\n\nstruct Point{\n\tdouble x,y;\n\tPoint(){}\n\tPoint(const Point& Val){x=Val.x;y=Val.y;}\n\tPoint(double x,double y):x(x),y(y){}\n\tvoid set(double x,double y){\n\t\tthis->x = x;this->y = y;\n\t}\n\tvoid read(){\n\t\tscanf(\"%lf%lf\",&x,&y);\n\t}\n\tvoid print(char end[]){\n\t\tif(end==NULL) end[0]='\\0';\n\t\tprintf(\"%.6f %.6f%s\",x,y,end);\n\t}\n\tPoint rot90(){\n\t\treturn Point(-y,x);\n\t}\n\tPoint operator + (const Point& Val)const{\n\t\treturn Point(x+Val.x, y+Val.y);\n\t}\n\tPoint operator - (const Point& Val)const{\n\t\treturn Point(x-Val.x, y-Val.y);\n\t}\n\tPoint operator * (double Val)const{\n\t\treturn Point(x*Val, y*Val);\n\t}\n\tPoint operator / (double Val)const{\n\t\treturn (*this) * (1.0/Val);\n\t}\n};\ntypedef Point Vec;\nistream& operator >> (istream &io, Point& p){\n\tio >> p.x >> p.y;\n\treturn io;\n}\nostream& operator << (ostream &io, Point& p){\n\tio << \"(\" << (fabs(p.x-0) LineCrossCircle(Point a,Point b,Point o,double r){\n\t// \u76f4\u7ebf\u4e0e\u5706\u7684\u4ea4\u70b9\n\tvector ret;\n\tPoint t = ShadowPOnLine(o,a,b); // o\u5230\u76f4\u7ebf|ab|\u7684\u5782\u8db3\n\tVec ot = PtoV(o,t);\n\tif(VecMod(ot)-r>eps)return ret; // \u6ca1\u6709\u4ea4\u70b9\n\tif(fabs(VecMod(ot)-r) PointTangentCircle(Point p,Point o,double r){\n\t// \u5706\u5916\u4e00\u70b9\u4f5c\u4e24\u4e2a\u5207\u7ebf \u8fd4\u56de\u5207\u70b9\n\tdouble x2 = VecMod2(p-o);\n\tdouble d2 = x2 - r*r;\n\tvector ret;\n\tif(d2 < -eps)return ret; // \u70b9\u5728\u5706\u5185\n\tif(r <= eps){ // \u5706\u9000\u5316\u4e3a\u70b9\n\t\tret.push_back(o);\n\t\tret.push_back(o);\n\t\treturn ret;\n\t}\n\td2 = max(d2,0.);\n\tPoint q1 = o + (p-o) * (r*r/x2);\n\tPoint q2 = (p-o).rot90() * (-r*sqrt(d2) / x2);\n\tret.push_back(q1 - q2);\n\tret.push_back(q1 + q2);\n\treturn ret;\n\t//double x2 = (p - c).abs2(); // x * x + y * y\n\t//double d2 = x2 - r * r;\n\t//vector ret;\n\t//if (d2 < -EPS)\n\t//\treturn ret;\n\t//if (r <= EPS) {\n\t//\tret.push_back(c);\n\t//\tret.push_back(c);\n\t//\treturn ret;\n\t//}\n\t//d2 = max(d2, 0.);\n\t//Point q1 = c + (p - c) * (r * r / x2);\n\t//Point q2 = (p - c).rot90() * (-r * sqrt(d2) / x2);\n\t//ret.push_back(q1 - q2);\n\t//ret.push_back(q1 + q2);\n\t//return ret;\n\n\t//vector ret;\n\t//Vec po = PtoV(p,o);\n\t//if(VecMod(po)-r < eps) return ret;\n\t//if(fabs(VecMod(po)-r) < eps){\n\t//\tret.push_back(p);\n\t//\treturn ret;\n\t//}\n\t//double alph = asin(r/VecMod(po));\n\t//cout << \"alpha===>\" << alph*180/pi << \" r=>\" << r << \" |po|=>\" << VecMod(po) << endl;\n\t//cout << \"circle o==>\" << o << \" p===>\" << p << endl;\n\t//cout << \"|p,T2|==>\" << VRotate(VecUnit(po),alph) * sqrt(VecMod2(po)+r*r) << endl;\n\t//cout << \"\u5355\u4f4d\u5411\u91cf|p.T2|\" << VRotate(VecUnit(po),alph) << \" \u957f\u5ea6|pT2|\" << sqrt(VecMod2(po)+r*r) << endl;\n\t//\n\t//ret.push_back(p + VRotate(VecUnit(po),alph) * sqrt(VecMod2(po)+r*r));\n\t//ret.push_back(p + VRotate(VecUnit(po),2*pi-alph) * sqrt(VecMod2(po)+r*r));\n\t//return ret;\n\n\t//Vec pt = VecUnit(VRotate(po,asin(r/VecMod(po))))*sqrt(VecMod2(po)+r*r);\n\t//ret.push_back(p+pt);\n\t//Point tot = ShadowPOnLine(p+pt,p,o);\n\t//ret.push_back(tot + PtoV(tot,o));\n\t//return ret;\n}\nbool POnSeg(Point p, Point a, Point b){\n\t// \u70b9\u5728\u7ebf\u6bb5\u4e0a\n\tif(fabs(xMult(PtoV(a,b), PtoV(a,p))) > eps)return false;\n\tif(min(a.x,b.x) > p.x || p.x > max(a.x,b.x))return false;\n\tif(min(a.y,b.y) > p.y || p.y > max(a.y,b.y))return false;\n\treturn true;\n}\n\n\ndouble PDisLine(Point p,Point a, Point b){\n\t// p\u70b9\u5230\u76f4\u7ebf|ab| \u7684\u8ddd\u79bb\n\treturn VecMod(ShadowPOnLine(p,a,b) - p);\n}\n//--------\u5411\u91cf\u8fd0\u7b97---------End\n\n\nvoid debug_function(){\n\tPoint h(25,45),j(30,30),i(15,35),k(5,45);\n\t//cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(9); \n\tPoint aaa(0,0), bbb(0,5), ppp(0,-1);\n\tcout << \"p in |ab| ? => \" << POnSeg(ppp,aaa,bbb) << endl;\n\n\tcout << \"\u03c0:\" << pi << \"\\t\\t\u03c0 checked\" << endl;\n\tcout << i << h << j << \"\\tio checked\" << endl;\n\tcout << Corner2V(PtoV(i,h),PtoV(i,j))*(180/pi) << \"\\t\\t\\tCorner2V() checked\" << endl;\n\ti.set(0,0);k.set(-10,4);\n\tcout << VRotate(PtoV(i,k),pi/2) << \" \" << PtoV(i,k) << PtoV(i,Point(-4,-10)) << \"VRotate() checked\" << endl;\n\tPoint p(10,2) , a(-6,6) , b(10,-10);\n\tcout << ShadowPOnLine(p,a,b) << \"\\t\\t\\tShadowPOnLine() checked\" << endl;\n\t\n\tdouble r = 6.64;\n\tvector CP = LineCrossCircle(a,b,Point(0,0),r);\n\tcout << \"cross point:\" << CP.size() << \" \";\n\tfor(int i = 0 ; i < CP.size() ; i++) cout << CP[i] << \" \" ;\n\tcout << \"\\tchecked\" << endl;\n\n\tp.set(10,2); r = 6.64;\n\tvector CT = PointTangentCircle(p,Point(0,0),r);\n\tcout << \"tangent point:\" << CT.size() << \" \";\n\tfor(int i = 0 ; i < CT.size() ; i++) cout << CT[i] << \" \" ;\n\tcout << endl;\n\n\n\texit(0);\n}\n\nPoint p,s;\ndouble vp,vs,r , sita;\nbool check(double t){\n\tdouble len_or = VecMod(p);\n\tPoint e(len_or * cos(sita+t*vp/len_or) , len_or * sin(sita+t*vp/len_or)); // \u7ec8\u70b9\n\t//printf(\"t:%lf (%lf,%lf) \\t\\t\",t,e.x,e.y);\n\tvector ccp;\n\tccp = LineCrossCircle(s,e, Point(0,0), r);\n\tif(ccp.size() != 2 || (!POnSeg(ccp[0], s, e) && !POnSeg(ccp[1], s, e)) ){\n\t\t//cout << \"| |len = \" << VecMod(e-s) << endl;\n\t\treturn vs*t > VecMod(e-s); // \u5982\u679c\u6ca1\u6709\u4ea4\u70b9\u8def\u5f84\u5c31\u662f\u76f4\u7ebf\t\n\t}\n\tvector ttp1 = PointTangentCircle(s,Point(0,0),r);\n\tif( PDisLine(ttp1[0],s,e) > PDisLine(ttp1[1],s,e) ) \n\t\tswap(ttp1[0],ttp1[1]);\n\tdouble l1 = VecMod(PtoV(s,ttp1[0]));\n\t\n\tvector ttp2 = PointTangentCircle(e,Point(0,0),r);\n\tif( PDisLine(ttp2[0],s,e) > PDisLine(ttp2[1],s,e) ) \n\t\tswap(ttp2[0],ttp2[1]);\n\tdouble l2 = VecMod(PtoV(e,ttp2[0]));\n\n\tdouble alph = Corner2V(PtoV(Point(0,0),ttp1[0]) , PtoV(Point(0,0),ttp2[0]));\n\t//cout << \"tangent:\" << ttp1[0] << \" \" << ttp2[0] << endl;\n\t//cout << \"|-|alph = \" << alph << \", \" << VecMod( PtoV(s,ttp1[0]) ) << \",\" << VecMod( PtoV(e,ttp2[0]) ) << endl;\n\treturn VecMod( PtoV(s,ttp1[0]) )\n\t\t+ VecMod( PtoV(e,ttp2[0]) )\n\t\t+ alph * r < vs*t;\n}\nint main(){\n\tios::sync_with_stdio(false);\n\t//debug_function();\n\t//freopen(\"d:\\\\Program Files (x86)\\\\Microsoft Visual Studio 9.0\\\\por\\\\20130820\\\\20130820\\\\in.txt\",\"r\",stdin);\n//\tfreopen(\"out.txt\",\"w\",stdout);\n\t//cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); \n\t//cout << fixed << setprecision(2) << (*it).first << endl;\n\twhile(cin >> p >> vp >> s >> vs >> r){\n\t\t//cout << p << vp << s << vs << \" \" << r << endl;\n\t\t//check(9.584544103);exit(0);\n\t\tsita = acos(p.x/VecMod(p));\n\t\tif(p.y<0)sita = -sita; // \u8de8\u8fc7\u4e86180\u5ea6\n\t\t\n\t\tdouble left = 0, right = 1e+10;\n\t\twhile( fabs(left-right) > 1e-12 ){\n\t\t\tdouble mid = (left+right)*0.5;\n \t\t\tif(check(mid))\n\t\t\t\tright = mid;\n\t\t\telse \n\t\t\t\tleft = mid;\n\t\t}\n\t\tcout << fixed << setprecision(9) << left << endl;\n\t}\n\treturn 0;\n}\n", "lang_cluster": "C++", "tags": ["geometry", "binary search"], "code_uid": "7a844bea1b7ef8be568d42b3ec928a80", "src_uid": "e8471556906e5fa3a701842570fa4ee2", "difficulty": 2400.0, "exec_outcome": "PASSED"}