{"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\n#define REP(i,N) for(int i=0,iVd)\n\t {\n\t \tprintf(\"0\\n\");\n\t \treturn 0;\n\t }\n\t double Dpos=0,Ppos=double(Vp)*ti,t;\n\t int res=0;\n\t while(Ppos=C)break;\n\t\t //printf(\"caught %f\\n\",Ppos);\n\t\t Ppos+=Vp*double(t+f);\n\t\t //printf(\"then %f\\n\",Ppos);\n\t\t res++;\n\t\t \n\t\t \n\t\t \n\t\t \n\t\t /*if(Ppos<=Dpos)\n\t\t {\n\t\t //printf(\"---%d\\n\",Ppos);\n\t\t\t Ppos+=Vp*(t+f);\n\t\t\t Dpos=0;\n\t\t\t t=0;\n\t\t\t res++;\n\t\t\t continue;\n\t\t }\n\t\t t++;\n\t\t Ppos+=Vp;\n\t\t Dpos+=Vd;\n\t\t */\n\t }\n\t //printf(\"-LL-%d\\n\",Ppos);\n\t printf(\"%d\\n\",res);\n\t return 0;\n}\n", "src_uid": "c9c03666278acec35f0e273691fe0fff"} {"source_code": "#include \nusing namespace std;\n\ntypedef long long ll;\ntypedef long double ld;\n#define F first\n#define S second\n#define ii pair \n#define ever (;;)\n\nconst int N = 110;\n\nll x,y,a,b,n,xx,yy;\nchar A[N];\nstring s;\n\nbool ok(ll mid)\n{\n ll xx = x*mid;\n ll yy = y*mid;\n\n if( xx==0 )\n {\n if( yy>0 )\n return yyb;\n }\n if( yy==0 )\n {\n if( xx>0 )\n return xxa;\n }\n\n\n if( xx>=0 && yy>=0 )\n return xx<=a && yy<=b;\n if( xx>=0 && yy<=0 )\n return xx<=a && yy>=b;\n if( xx<=0 && yy>=0 )\n return xx>=a && yy<=b;\n if( xx<=0 && yy<=0 )\n return xx>=a && yy>=b;\n}\n\nint main()\n{\n scanf(\"%lld%lld%s\",&a,&b,&A);\n s = A;\n n = s.length();\n\n if( !a && !b )\n {\n printf(\"Yes\");\n return 0;\n }\n\n for(int i=0;i<110;i++)\n {\n for(int j=0;j0 && a<0 ) || ( x<0 && a>0) || ( y>0 && b<0 ) || ( y<0 && b>0 ) )\n {\n printf(\"No\");\n return 0;\n }\n\n ll low = 110,high = 1e9+110;\n while(low\n#include\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 n,k,a[200100],now[200100],siz[200100],Ans,all[200100],mid,pl;\nvectorv[200100];\ninline void work(int x,int fa){\n\tsiz[x]=all[x]=1;\n\tint maxn=0,sen=0;\n\tfor(int i=0;imaxn)swap(maxn,siz[v[x][i]]);\n\t if(siz[v[x][i]]>sen)swap(sen,siz[v[x][i]]);\n\t }\n\t }\n\tsiz[x]+=maxn;\n\tif(a[x]=k)return 1;\n\t else return 0;\n}\nint main(){\n int i,minn=1e9+7;\n scanf(\"%d%d\",&n,&k);\n for(i=1;i<=n;i++){\n scanf(\"%d\",&a[i]);\n if(a[i]1){\n mid=(le+ri)>>1;\n if(ck())le=mid;\n else ri=mid;\n }\n cout<\n#include\n#include\n#include\n#define N 110\n#define M 7846\n#define mo 1000000007\n#define ll long long\n\nusing namespace std;\n\nint cnt,f[M][M],no[N][N],n,a,b,c,d,p1,p2,p3,p4;\n\nll qpow(ll a,ll i){\n\tll r=1;for(;i;i>>=1,a=a*a%mo)if(i&1)r=r*a%mo;return r;\n}\n\nint main(){\n//\tfreopen(\"e.in\",\"r\",stdin);\n//\tfreopen(\"e.out\",\"w\",stdout);\n\tscanf(\"%d %d %d %d %d\",&n,&a,&b,&c,&d);\n\tp1=(ll)a*qpow(a+b+c+d,mo-2)%mo;p2=(ll)b*qpow(a+b+c+d,mo-2)%mo;\n\tp3=(ll)c*qpow(a+b+c+d,mo-2)%mo;p4=(ll)d*qpow(a+b+c+d,mo-2)%mo;\n\tfor(int i=n,x;i>=-n;i--){\n\t\tx=floor(sqrt(n*n-i*i));\n\t\tfor(int j=-x;j<=x;j++)no[i+n][j+n]=++cnt;\n\t}\n\tfor(int i=n,x;i>=-n;i--){\n\t\tx=floor(sqrt(n*n-i*i));\n\t\tfor(int j=-x;j<=x;j++){\n\t\t\tint p,q;f[no[i+n][j+n]][no[i+n][j+n]]=mo-1;f[no[i+n][j+n]][0]=mo-1;\n\t\t\tp=i-1;q=j;\n\t\t\tif(p*p+q*q<=n*n)f[no[i+n][j+n]][no[p+n][q+n]]=p1;\n\t\t\tp=i;q=j-1;\n\t\t\tif(p*p+q*q<=n*n)f[no[i+n][j+n]][no[p+n][q+n]]=p2;\n\t\t\tp=i+1;q=j;\n\t\t\tif(p*p+q*q<=n*n)f[no[i+n][j+n]][no[p+n][q+n]]=p3;\n\t\t\tp=i;q=j+1;\n\t\t\tif(p*p+q*q<=n*n)f[no[i+n][j+n]][no[p+n][q+n]]=p4;\n\t\t}\n\t}\n\tfor(int i=1;i<=cnt;i++){\n\t\tint ny=qpow(f[i][i],mo-2);\n\t\tfor(int l=i+1;l<=i+n+n && l<=cnt;l++)if(f[l][i]>0){\n\t\t\tint v=(ll)f[l][i]*ny%mo;f[l][0]=(f[l][0]-(ll)f[i][0]*v%mo+mo)%mo;\n\t\t\tfor(int k=i+1;k<=cnt && k<=i+n+n;k++)f[l][k]=(f[l][k]-(ll)f[i][k]*v%mo+mo)%mo;\n\t\t}\n\t}\n\tfor(int i=cnt;i;i--){\n\t\tfor(int l=i+1;l<=i+n+n && l<=cnt;l++){\n\t\t\tf[i][0]=(f[i][0]-(ll)f[i][l]*f[l][0]%mo+mo)%mo;\n\t\t}\n\t\tf[i][0]=(ll)f[i][0]*qpow(f[i][i],mo-2)%mo;\n\t}\n\tprintf(\"%d\",f[no[n][n]][0]);\n\treturn 0;\n}\n\n", "src_uid": "bd6bcb5bffd039de93f217b02f5eae17"} {"source_code": "#include \nusing namespace std;\n#define eb emplace_back\n#define emp emplace\n#define fi first\n#define se second\n#define INF 0x3f3f3f3f\ntypedef long long ll;\ntypedef pair ii;\n\nll get_dist(ll ax, ll ay, ll bx, ll by) {\n\treturn (ax-bx)*(ax-bx) + (ay-by)*(ay-by);\n}\n\nint main(void) {\n\tios_base::sync_with_stdio(false);\n\n\tll ax, ay, bx, by, cx, cy;\n\tcin >> ax >> ay >> bx >> by >> cx >> cy;\n\n\tif (get_dist(ax, ay, bx, by) == get_dist(bx, by, cx, cy)) {\n\t\tif ((ax*(by-cy) + bx*(cy-ay) + cx*(ay-by)) == 0) cout << \"No\" << endl;\n\t\telse cout << \"Yes\" << endl;\n\t} else {\n\t\tcout << \"No\" << endl;\n\t}\n \n\treturn 0;\n}\n", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"source_code": "// Awwawa! Dis cold yis ratten buy tEMMIE!\n#include \n#define ll long long\n#define maxn 1000005 /*rem*/\n#define mod 998244353\n#define db double\n#define vi vector\n#define pb push_back\n#define mp make_pair\n#define pi pair\n#define fi first\n#define se second\n\ntemplate bool chkmax(T &x, T y) {\n return x < y ? x = y, true : false;\n}\ntemplate bool chkmin(T &x, T y) {\n return x > y ? x = y, true : false;\n}\n\nusing namespace std;\n\nll ksm(ll a, ll b) {\n if (!b)\n return 1;\n ll ns = ksm(a, b >> 1);\n ns = ns * ns % mod;\n if (b & 1)\n ns = ns * a % mod;\n return ns;\n}\n\nconst int md = 998244353;\n\ninline void add(int &x, int y) {\n x += y;\n if (x >= md) {\n x -= md;\n }\n}\n\ninline void sub(int &x, int y) {\n x -= y;\n if (x < 0) {\n x += md;\n }\n}\n\ninline int mul(int x, int y) { return (long long)x * y % md; }\n\ninline int power(int x, int y) {\n int res = 1;\n for (; y; y >>= 1, x = mul(x, x)) {\n if (y & 1) {\n res = mul(res, x);\n }\n }\n return res;\n}\n\ninline int inv(int a) {\n a %= md;\n if (a < 0) {\n a += md;\n }\n int b = md, u = 0, v = 1;\n while (a) {\n int t = b / a;\n b -= t * a;\n swap(a, b);\n u -= t * v;\n swap(u, v);\n }\n if (u < 0) {\n u += md;\n }\n return u;\n}\n\nnamespace ntt {\nint base = 1, root = -1, max_base = -1;\nvector rev = {0, 1}, roots = {0, 1};\n\nvoid init() {\n int temp = md - 1;\n max_base = 0;\n while (temp % 2 == 0) {\n temp >>= 1;\n ++max_base;\n }\n root = 2;\n while (true) {\n if (power(root, 1 << max_base) == 1 &&\n power(root, 1 << max_base - 1) != 1) {\n break;\n }\n ++root;\n }\n}\n\nvoid ensure_base(int nbase) {\n if (max_base == -1) {\n init();\n }\n if (nbase <= base) {\n return;\n }\n assert(nbase <= max_base);\n rev.resize(1 << nbase);\n for (int i = 0; i < 1 << nbase; ++i) {\n rev[i] = rev[i >> 1] >> 1 | (i & 1) << nbase - 1;\n }\n roots.resize(1 << nbase);\n while (base < nbase) {\n int z = power(root, 1 << max_base - 1 - base);\n for (int i = 1 << base - 1; i < 1 << base; ++i) {\n roots[i << 1] = roots[i];\n roots[i << 1 | 1] = mul(roots[i], z);\n }\n ++base;\n }\n}\n\nvoid dft(vector &a) {\n int n = a.size(), zeros = __builtin_ctz(n);\n ensure_base(zeros);\n int shift = base - zeros;\n for (int i = 0; i < n; ++i) {\n if (i> shift) {\n swap(a[i], a[rev[i] >> shift]);\n }\n }\n for (int i = 1; i < n; i <<= 1) {\n for (int j = 0; j < n; j += i << 1) {\n for (int k = 0; k < i; ++k) {\n int x = a[j + k], y = mul(a[j + k + i], roots[i + k]);\n a[j + k] = (x + y) % md;\n a[j + k + i] = (x + md - y) % md;\n }\n }\n }\n}\n\nvector multiply(vector a, vector b) {\n int need = a.size() + b.size() - 1, nbase = 0;\n while (1 << nbase < need) {\n ++nbase;\n }\n ensure_base(nbase);\n int sz = 1 << nbase;\n a.resize(sz);\n b.resize(sz);\n bool equal = a == b;\n dft(a);\n if (equal) {\n b = a;\n } else {\n dft(b);\n }\n int inv_sz = inv(sz);\n for (int i = 0; i < sz; ++i) {\n a[i] = mul(mul(a[i], b[i]), inv_sz);\n }\n reverse(a.begin() + 1, a.end());\n dft(a);\n a.resize(need);\n return a;\n}\n\nvector inverse(vector a) {\n int n = a.size(), m = n + 1 >> 1;\n if (n == 1) {\n return vector(1, inv(a[0]));\n } else {\n vector b = inverse(vector(a.begin(), a.begin() + m));\n int need = n << 1, nbase = 0;\n while (1 << nbase < need) {\n ++nbase;\n }\n ensure_base(nbase);\n int sz = 1 << nbase;\n a.resize(sz);\n b.resize(sz);\n dft(a);\n dft(b);\n int inv_sz = inv(sz);\n for (int i = 0; i < sz; ++i) {\n a[i] = mul(mul(md + 2 - mul(a[i], b[i]), b[i]), inv_sz);\n }\n reverse(a.begin() + 1, a.end());\n dft(a);\n a.resize(n);\n return a;\n }\n}\n} // namespace ntt\n\nusing ntt::inverse;\nusing ntt::multiply;\n\nvector &operator+=(vector &a, const vector &b) {\n if (a.size() < b.size()) {\n a.resize(b.size());\n }\n for (int i = 0; i < b.size(); ++i) {\n add(a[i], b[i]);\n }\n return a;\n}\n\nvector operator+(const vector &a, const vector &b) {\n vector c = a;\n return c += b;\n}\n\nvector &operator-=(vector &a, const vector &b) {\n if (a.size() < b.size()) {\n a.resize(b.size());\n }\n for (int i = 0; i < b.size(); ++i) {\n sub(a[i], b[i]);\n }\n return a;\n}\n\nvector operator-(const vector &a, const vector &b) {\n vector c = a;\n return c -= b;\n}\n\nvector &operator*=(vector &a, const vector &b) {\n if (min(a.size(), b.size()) < 128) {\n vector c = a;\n a.assign(a.size() + b.size() - 1, 0);\n for (int i = 0; i < c.size(); ++i) {\n for (int j = 0; j < b.size(); ++j) {\n add(a[i + j], mul(c[i], b[j]));\n }\n }\n } else {\n a = multiply(a, b);\n }\n return a;\n}\n\nvector operator*(const vector &a, const vector &b) {\n vector c = a;\n return c *= b;\n}\n\nint n, k;\nll f[maxn], g[maxn];\nint main() {\n scanf(\"%d%d\", &n, &k);\n f[0] = 1;\n g[0] = 1;\n for (int i = 1; i <= k; i++) {\n f[i] = f[i - 1] * i % mod;\n g[i] = ksm(f[i], mod - 2);\n }\n vi f1(k + 1, 0), g1(k + 1, 0);\n for (int i = 0; i <= k; i++) {\n f1[i] = ksm(mod - 1, i) * g[i] % mod;\n g1[i] = ksm(i, k) * g[i] % mod;\n }\n vi s = f1 * g1;\n ll r = 1, ans = 0;\n for (int i = 0; i <= k && i <= n; i++) {\n ans = (ans + s[i] * ksm(n + 1, n - i) % mod * r) % mod;\n r = r * (n - i) % mod;\n }\n printf(\"%lld\\n\", ans);\n}", "src_uid": "bc57a69c39c6e74d6d81a9c504104809"} {"source_code": "#include \n#include \n#include \nusing namespace std;\n\nint main() {\n\tunsigned long long k, init = 1, num = 0;\n\tcin >> k;\n\tint i = 1;\n\twhile (init + i * (pow(10, i) - pow(10, i - 1)) <= k) init += (i++)*(pow(10, i) - pow(10, i - 1)); \n\tnum = pow(10, i-1) + (k - init) / i;\n\tcout << to_string(num)[(k-init) % i];\n\treturn 0;\n}", "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"source_code": "#include\n#define re register\n#define LL long long\n#define max(a,b) ((a)>(b)?(a):(b))\n#define min(a,b) ((a)<(b)?(a):(b))\ninline int read() {\n\tchar c=getchar();int x=0;while(c<'0'||c>'9')c=getchar();\n\twhile(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-48,c=getchar();return x;\n}\nconst int maxn=3005;\nint n,c,m,k;LL tot,ans;\nstruct node{int x,y;}p[maxn];\nint va[maxn],nxt[maxn],pre[maxn],l[maxn],vl[maxn],vis[maxn];\ninline int cmp(const node &A,const node &B) {return A.yx) break;\n\t\tif(vis[nw]) {nw=nxt[nw];continue;}\n\t\tvl[nw]--;\n\t\tif(vl[nw]=k) tot+=l[u]*calc(u);else vis[u]=1;\n\t\t\tu=pre[u];\n\t\t}\n\t\tans+=tot;lp=m;\n\t\tfor(re int j=c-1;j>=i;--j) {\n\t\t\twhile(lp&&p[lp].y>j) {\n\t\t\t\tdel(p[lp].x);\n\t\t\t\t--lp;\n\t\t\t}\n\t\t\tans+=tot;\n\t\t}\n\t}\n\tprintf(\"%lld\\n\",ans);\n\treturn 0;\n}", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"source_code": "#include\nusing namespace std;\nconst int N=1001,M=10,K=100;\nlong long n,m,D,t=1,f[N][M][K],A;\nlong long P(long long a,long long b)\n{\n\tt=1;\n\twhile(b)\n\t{\n\t\tif(b&1)\n\t\t\t(t*=a)%=D;\n\t\t(a*=a)%=D,b/=2;\n\t}\n\treturn t;\n}\nint main()\n{\n\tcin>>n>>m>>D;\n\tfor(int i=1;i\n#include \n#include \n\nusing namespace std;\n\nclass state {\npublic:\n int x,y,t,b;\n state (int x0,int y0,int t0,int b0) { x=x0, y=y0, t=t0, b=b0; };\n};\n\nint n,m;\nint bx[8], by[8], tx[8], ty[8], tv[8], nb=0, nt=0, sx, sy;\nstring T[20];\nqueue Q;\nint dist[20][20][256][256];\n\nbool valid(int x,int y) { \n return 0<=x && xpx && y0> n >> m;\n for (int i=0; i> T[i];\n for (int j=0; j> tv[i];\n\n // dist[x][y][treasure-mask][bomb-mask]\n for (int x=0; x=0) {\n int value = -dist[sx][sy][s][0];\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#include\nusing namespace std;\n#define maxv(A,B) (A>B?A:B)\n#define minv(A,B) (A>B?B:A)\n#define inf 2147483647\n#define pi (2*acos(0.0))\n#define eps 1e-9\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 fx[]={0,0,1,-1};\nint fy[]={-1,1,0,0};\nint main()\n{\n\n\t//freopen(\"input.txt\",\"r\",stdin);\n\t//freopen(\"output.txt\",\"w\",stdout);\nint n,x,y,sa,sb,fl,i;\n\twhile(cin>>n){\n\t sa=sb=fl=0;\n\t for(i=0;i>x>>y;\n\t sa+=x;\n\t sb+=y;\n\t if((x%2)!=(y%2))fl=1;\n\t }\n\t if(sa%2==0 && sb%2==0)cout<<0<\n#include\n#include\n#include\n#include\n \nusing namespace std;\n#define LL long long\n \ninline LL read(){\n\tLL x=0,f=1;char c=getchar();\n\tfor(;!isdigit(c);c=getchar()) if(c=='-') f=-1;\n\tfor(;isdigit(c);c=getchar()) x=x*10+c-'0';\n\treturn x*f;\n}\nLL N,M;\n \nconst LL MAXN = 5000;\nconst LL INF = 2147483600;\nconst LL Mod = 998244353LL;\n \nLL a[2010][2010];\nLL g[2010][2010];\nnamespace BIT{\n\tLL c[3][MAXN+1];\n\t#define lowbit(x) (x&(-x))\n\tinline void Add(LL n,LL k,LL x){\n\t\tfor(;k<=N;k+=lowbit(k)) c[n][k]+=x;\t\n\t} inline LL Query(LL n,LL k){\n\t\tLL ans=0; for(;k;k-=lowbit(k)) ans+=c[n][k]; return ans;\t\n\t} \n} using namespace BIT;\nLL f[2010],fac[2010];\nbool vis[2010];\nLL vall[2010];\n \nint main(){\n\tN=read();\n\tfor(LL i=1;i<=N;i++){\n\t\tfor(LL j=1;j<=N;j++)\n\t\t\ta[i][j]=read();\t\n\t} g[0][0]=1; g[1][0]=0;\n\tfor(LL i=2;i<=N;i++){\n\t\tg[i][0]=1LL*(i-1)*(g[i-1][0]+g[i-2][0])%Mod;\n\t} for(LL i=1;i<=N;i++){\n\t\tfor(LL j=1;j<=i;j++)\n\t\t\tg[i][j]=(g[i-1][j-1]+g[i][j-1])%Mod;\n\t} \n\tLL Fn=g[N][0]; f[0]=1; LL rak=0;\n\tfor(LL i=1;i<=N;i++) f[i]=f[i-1]*Fn%Mod; fac[0]=1; LL ans=0;\n\tfor(LL i=1;i<=N;i++) fac[i]=fac[i-1]*i%Mod;\n\tfor(LL i=1;i<=N;i++) rak=(rak+(a[1][i]-1-Query(0,a[1][i]))*fac[N-i]%Mod)%Mod,Add(0,a[1][i],1);\n\t(ans+=rak*f[N-1]%Mod)%=Mod;\n\tfor(LL i=2;i<=N;i++){\n\t\tfor(LL j=1;j<=N;j++) c[0][j]=c[1][j]=c[2][j]=0,vall[j]=vis[j]=0; LL cnt=0;\n\t\tfor(LL j=1;j<=N;j++){\n\t\t\tif(vall[a[i-1][j]]) ++cnt;\n\t\t\tLL d1=a[i][j]-1-Query(0,a[i][j]-1)+Query(1,a[i][j]-1)-(a[i-1][j]\n#include \n#include \n\nusing namespace std;\nconst int N = 3e5 + 10;\n\nint k[N][2];\nint res[N];\nvector edges[N];\nqueue need;\n\nvoid update(int x, int color, int cnt) {\n k[x][color] += cnt;\n if (cnt < 0) {\n return;\n }\n if (color == res[x] && k[x][color] > 1) {\n need.push(x);\n }\n}\n\nint main() {\n ios_base::sync_with_stdio(false);\n int n;\n int m;\n cin >> n >> m;\n for (int i = 1; i <= m; i++) {\n int x;\n int y;\n cin >> x >> y;\n edges[x].push_back(y);\n edges[y].push_back(x);\n }\n for (int i = 1; i <= n; i++) {\n res[i] = 0;\n update(i, 0, (int)edges[i].size());\n }\n while (!need.empty()) {\n int x = need.front();\n need.pop();\n if (k[x][res[x]] > 1) {\n res[x] = 1 - res[x];\n for (size_t i = 0; i < edges[x].size(); i++) {\n update(edges[x][i], res[x], +1);\n update(edges[x][i], 1 - res[x], -1);\n }\n }\n }\n for (int i = 1; i <= n; i++) {\n cout << res[i];\n }\n return 0;\n}", "src_uid": "7017f2c81d5aed716b90e46480f96582"} {"source_code": "#include\r\nusing namespace std;\r\n#define rep(i,a,n) for (int i=a;i=a;i--)\r\n#define pb push_back\r\n#define mp make_pair\r\n#define all(x) (x).begin(),(x).end()\r\n#define fi first\r\n#define se second\r\n#define SZ(x) ((int)(x).size())\r\n#define ll long long\r\ntypedef vector VI;\r\ntypedef pair PII;\r\nconst ll mod=2;\r\nll powmod(ll a,ll b) {if(!b) return 1;return a&1;}\r\n// head\r\n\r\nnamespace tui {\r\n const int N=80;\r\n bitset _c,_md,res;\r\n void mul(bitset &a,int k) {\r\n \tbitset A;\r\n \tA.reset();\r\n \tfor(int i=0;i=k;i--) if (_c[i]) _c^=_md<=0;p--) {\r\n mul(res,k);\r\n if ((n>>p)&1) {\r\n\t\t\t\tres<<=1;\r\n if(res[k]) res^=_md;\r\n }\r\n }\r\n rep(i,0,k) ans=(ans^res[i]&b[i])&1;\r\n return ans;\r\n }\r\n VI BM(VI s) {\r\n VI C(1,1),B(1,1);\r\n int L=0,m=1,b=1;\r\n rep(n,0,SZ(s)) {\r\n ll d=0;\r\n rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])&1;\r\n if (d==0) ++m;\r\n else if (2*L<=n) {\r\n VI T=C;\r\n ll c=d*powmod(b,mod-2)&1;\r\n while (SZ(C) v;\r\n#define int long long\r\nconst int Mod=1e6+7,XOR=123456789;\r\nconst int B=10000000;\r\nstruct hashmap{\r\n\tint X[B],nw;\r\n\tsigned nx[B],Y[B],head[Mod];\r\n\tinline void ins(int x,int y)\r\n\t{\r\n\t\tif(x<0) x=-x;\r\n\t\tx^=XOR;\r\n\t\tnx[++nw]=head[x%Mod];\r\n\t\thead[x%Mod]=nw;\r\n\t\tX[nw]=x,Y[nw]=y;\r\n\t}\r\n\tinline int ask(int x)\r\n\t{\r\n\t\tif(x<0) x=-x;\r\n\t\tx^=XOR;\r\n\t\tfor(int i=head[x%Mod];i;i=nx[i])\r\n\t\t\tif(X[i]==x) return Y[i];\r\n\t\treturn 0;\r\n\t}\r\n}Mp;\r\nint F[B+5];\r\nsigned main() {\r\n\tstring s;\r\n\tcin >> s;\r\n\tint p1=0,p2=0;\r\n\tlong long x=0;\r\n\tfor(int i=0;i>p1-1;\r\n\tx>>=p1;\r\n\tint ans=p1;\r\n\tint fi=x;\r\n\tif(x==1)\r\n\t{\r\n\t\tcout << p1 << \" \" << p1+1;\r\n\t\treturn 0;\r\n\t}\r\n\tfor(int i=1;i<=100;i++)\r\n\t{\r\n\t\tv.push_back(x&1); \r\n\t\tx^=(x&1)*S,x>>=1,++ans;\r\n\t\tif(x==1)\r\n\t\t{\r\n\t\t\tcout << p1 << \" \" << p1+i+1;\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n\ttui::c=tui::BM(v);\r\n tui::c.erase(tui::c.begin());\r\n while(v.size()>tui::c.size()) v.pop_back();\r\n\tx=1;\r\n\tfor(int i=1;i<=B;i++)\r\n\t{\r\n\t\tF[i]=x&1;\r\n\t\tx^=(x&1)*S,x>>=1,++ans;\r\n\t}\r\n\tint nw=0;\r\n\tfor(int i=0;i<35;i++) nw|=(F[i]<>=1;\r\n\t\tMp.ins(nw,i);\r\n\t}\r\n\tfor(int i=B;;i+=B)\r\n\t{\r\n\t\tint nw=0;\r\n\t\tfor(int j=i;j<=i+34;j++)\r\n\t\t\tnw|=((long long)tui::gao(v,j)<\nusing namespace std;\n\n/*I'm going to pass one by one through the bits\niF it's 1, ignore it. If it is 0 I'll make a counter for 0s and 1s.\nIf 1s greater than 0s I'll ignore it, other wise this is the largest\n*/\n\nint main()\n{\n\tint n;\n\tint *arr;\n\tcin >> n;\n\n\tarr = new int[n];\n\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> arr[i];\n\n\t//now check\n\tint first = 0, last = 0, count = 0, i = 0;\n\tint temp1 = 0, temp2 = 0;\n\tbool exit = false;\n\tint min = 0, max = 0;\n\n\tfor (int j = 0; j < n; j++)\n\t{\n\n\t\tif (arr[j] != 1) //If not equal to 0 no need to explore\n\t\t{\n\t\t\ttemp1 = i;\n\t\t\ttemp2 = j;\n\t\t\tcount++; //Will change a 0 to a 1\n\t\t\tmax++;\n\t\t}\n\n\t\telse\n\t\t{\n\t\t\tcount--;\n\t\t\tmax--;\n\t\t}\n\n\t\t\n\t\tif (max > min)\n\t\t{\n\t\t\tmin = max;\n\t\t\tfirst = temp1;\n\t\t\tlast = temp2;\n\n\t\t}\n\n\t\tif (count < 0 || j + 1 == n)\n\t\t{\n\t\t\ti = j + 1;\n\t\t\tmax = 0;\n\t\t\tcount = 0;\n\n\t\t}\n\t\t\t\n\t}\n\n\n\t\n\tcount = 0;\n\tfor (int i = 0; i= first && i <= last)\n\t\t{\n\t\t\tif (arr[i] == 0) count++; //since everyting will be reversed\n\t\t}\n\n\t\telse if (arr[i] == 1) count++;\n\t}\n\n\tcout << count << endl;\n\n}\n\n\n", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"source_code": "#include \"iostream\"\n#include \"set\"\n#define int long long\nusing namespace std;\nstruct _ { _() { cin.sync_with_stdio(0), cin.tie(0); } }_;\n\nsigned main()\n{\n\tset s1, s2;\n\tint c1 = 2, c2 = 4;\n\ts1.insert(1);\n\ts2.insert(2);\n\twhile (*s1.rbegin() <= 1e9) s1.insert(c1 * c1), c1 += 1;\n\twhile (*s2.rbegin() <= 1e9) s2.insert(*s2.rbegin() + c2), c2 += 2;\n\tint x, y, d1, d2;\n\tcin >> x >> y;\n\tauto i1 = s1.upper_bound(x);\n\tauto i2 = s2.upper_bound(y);\n\tif (x < *s1.begin()) d1 = 0;\n\telse d1 = distance(s1.begin(), i1);\n\tif (y < *s2.begin()) d2 = 0;\n\telse d2 = distance(s2.begin(), i2);\n\tif (d1 <= d2) cout << \"Vladik\";\n\telse cout << \"Valera\";\n}\n", "src_uid": "87e37a82be7e39e433060fd8cdb03270"} {"source_code": "#include \n#define M 51123987\n#define r(i,s,t) for(int i=s;i<=(t);i++)\n#define u(x) ((x+=c)%=M)\nusing namespace std;\nint n,m,c,f[152][52][52][52],t[3][152],a;\nstring s;\nint main(){\n\tcin>>n>>s;\n\tfor(int i=n;i;i--){r(j,0,2)t[j][i]=t[j][i+1];t[s[i-1]-'a'][i]=i;}\n\tr(l,f[1][0][0][0]=1,n)r(i,0,m=(n+2)/3)r(j,0,m)r(k,0,m)(a+=(i+j+k==n)*(abs(i-j)<=1)*(abs(j-k)<=1)*(abs(i-k)<=1)*(c=f[l][i][j][k]))%=M,u(f[t[0][l]][i+1][j][k]),u(f[t[1][l]][i][j+1][k]),u(f[t[2][l]][i][j][k+1]);\n\tcout<\n#include \n#include \n#include \n#define INF 99999999\nusing namespace std;\n\nint a[24], che[(1<<24)], n;\nint dfs(int c)\n{\n\tif(che[c]) return che[c];\n\tif(c == 1) return 1;\n\tint x = n-1, cnt = __builtin_popcount(c), mn = INF;\n\tfor(; x > 0; x--) if(c & (1 << x)) break;\n\tfor(int i = 0; i < x; i++)\n\t\tfor(int j = 0; j <= i; j++)\n\t\t\tif(a[i]+a[j] == a[x]){\n\t\t\t\tint v = dfs(c & ~(1<> n;\n\tfor(int i = 0; i < n; i++) cin >> a[i];\n\tint ans = dfs(1 << (n-1));\n\tif(ans == INF) cout << -1 << endl;\n\telse cout << ans << endl;\n}\n", "src_uid": "359f5d1264ce16c5c5293fd59db95628"} {"source_code": "#include \nusing namespace std;\n#define fo(i,n) for(i=0;in;k\n#define pii pair\n#define vi vector\n#define endl \"\\n\"\n#define deb(x) cout << #x << \"=\" << x << endl\nconst ll mod = 1e9+7;\n\nll msum(ll a,ll b,ll m) { return (a%m+b%m)%m; }\nll msub(ll a,ll b,ll m) { return (a%m-b%m)%m; }\nll mpro(ll a,ll b,ll m) { return ((a%m)*(b%m))%m; }\nll m_m(ll a,ll b,ll m);\nll fxp(ll a,ll b,ll m);\nvoid swap(ll &a,ll &b){ ll t=a; a=b; b=t;}\n\n// also present in ladder 3\nll dp[2005][2005];\n\nll solve(ll n,ll k,ll i)\n{\n if(k==0)\n {\n return 1;\n }\n // deb(dp[i][k]);\n if(dp[i][k]!=-1)\n return dp[i][k];\n ll ans=0;\n for(ll j=i;j<=n;j+=i)\n {\n ans+=solve(n,k-1,j);\n ans=ans%mod;\n }\n // deb(dp[i][k]);\n return dp[i][k]=ans;\n}\n\n\n\nint main()\n{\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n ll n,k;\n memset(dp,-1,sizeof(dp));\n cin>>n>>k;\n ll val=solve(n,k,1);\n cout<\n#endif\n#include \nusing namespace std;\n#define int long long\n#define sp ' '\n#define endl '\\n'\n#define fi first\n#define se second\n#define bit(x,y) ((x>>y)&1)\n#define loop(i,l,r) for(int i=(l); i<=(r); i++)\n#define rloop(i,l,r) for(int i=(l); i>=(r); i--)\n#define debug(x...) {cout << \"[\" << #x << \"] =\"; _print(x);}\nvoid _print() {cout << endl;}\ntemplate void _print(const T& value, const Ts&... values) {cout << ' ' << value; _print(values...);}\ntemplate void print(const T& value, const Ts&... values) {cout << value; _print(values...);}\nconst int N = 55;\n\nint n;\nint a[N];\npair dp[N];\nconst int INF = 1e18;\n\npair back(int pos) {\n if (pos >= n + 1) return {0, 0};\n auto &ret = dp[pos];\n if (ret.fi != -1) return ret;\n ret = {0, INF};\n int s1 = a[pos], s2 = 0;\n loop(i, pos - 1, n) {\n if (i != pos - 1) {\n s1 -= a[i]; s2 += a[i];\n s1 += a[i + 1];\n }\n auto rec = back(i + 2);\n if (ret.fi - ret.se < s1 + rec.se - s2 - rec.fi) {\n ret = {s1 + rec.se, s2 + rec.fi};\n }\n }\n return ret;\n}\n\nsigned main() {\n ios_base::sync_with_stdio(false); cin.tie(0);\n cin >> n;\n loop(i, 1, n) cin >> a[i];\n memset(dp, -1, sizeof(dp));\n auto rec = back(1);\n cout << rec.se << sp << rec.fi << endl;\n}", "src_uid": "414540223db9d4cfcec6a973179a0216"} {"source_code": "#include \n\nint iao_year(int n, int dig)\n{\n int pw = 1, sum = 0;\n for (int i = 0; i < dig; ++i) {\n pw *= 10;\n sum += pw;\n }\n int lwb = 1989 + sum - pw,\n upb = 1989 + sum;\n if (n >= lwb % pw) return lwb / pw * pw + n;\n else return upb / pw * pw + n;\n}\n\nint main()\n{\n int t, n, dig;\n char ch;\n scanf(\"%d\", &t); getchar();\n do {\n for (int i = 0; i < 4; ++i) getchar();\n n = 0; dig = 0;\n while ((ch = getchar()) >= '0' && ch <= '9') {\n n = n * 10 + ch - '0';\n ++dig;\n }\n printf(\"%d\\n\", iao_year(n, dig));\n } while (--t);\n return 0;\n}\n", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21"} {"source_code": "//K-OS WITH THE OCDE\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\nusing namespace std;\n\ntypedef long long int ll;\ntypedef long double db;\n\n\n#define TEST ll t; cin>>t; while(t--)\n#define vell vector\n#define vel2 vector>\n#define all(v) v.begin(),v.end()\n#define pb push_back\n\n#define endl \"\\n\"\n#define INF 1e18\n#define mod 1000000007\n\n\n\nvoid solve()\n{\n ll n, M;\n cin >> n >> M;\n vector a(n) , f(n) , pref(n);\n priority_queue pq;\n for (ll i = 0 ; i < n ; ++i) {\n cin >> a[i];\n }\n\n pref[0] = a[0];\n for (ll i = 1 ; i < n ; ++i) {\n pref[i] = pref[i - 1] + a[i];\n }\n\n for (ll i = 0 ; i < n ; ++i) {\n\n ll curr = 0 , removed = 0;\n\n if (pref[i] <= M) {\n f[i] = curr;\n pq.push(a[i]);\n continue;\n }\n\n vector v;\n while (!pq.empty() && pref[i] - removed > M) {\n removed += pq.top();\n v.pb(pq.top());\n pq.pop();\n curr++;\n }\n\n while (!v.empty()) {\n pq.push(v.back());\n v.pop_back();\n }\n\n f[i] = curr;\n pq.push(a[i]);\n\n\n }\n\n for (ll i = 0 ; i < n ; ++i)\n cout << f[i] << \" \";\n\n}\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#endif\n ios_base::sync_with_stdio(0); cin.tie(0);\n //TEST\n solve();\n}\n\n", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"} {"source_code": "#include \nusing namespace std;\n\n\n\nint a,posss,l,r,v,k,p1;\n\nint main()\n{\n cin >> a >> posss >> l >> r;\n p1 = posss;\n if (l!=1) {\n v += abs(posss-l) ;\n v++;\n p1 = l;\n }\n if (r!=a) v += abs(r - p1) + 1;\n p1 = posss;\n if (r!= a) {\n k += abs(posss-r) ;\n k++;\n p1 = r;\n }\n if (l!= 1) k += abs(p1-l) + 1;\n cout << min(k,v) << endl;\n}\n", "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#define for(i,n) for(int i=0;i>a[0]>>a[1]>>a[2]>>a[3];\n sort(a,a+4);\n if(a[0]+a[1]>a[2]||a[1]+a[2]>a[3])\n cout<<\"TRIANGLE\";\n else if(a[1]+a[2]==a[3]||a[0]+a[1]==a[2])\n cout<<\"SEGMENT\";\n else cout<<\"IMPOSSIBLE\";\n}\n", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"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\nusing namespace std;\n\ntypedef long long LL;\ntypedef pair PII;\ntypedef vector VI;\ntypedef vector VS;\n\n#define sz(X) ((int)(X.size()))\n#define all(x) x.begin(),x.end()\n#define clr(x,c) memset(x,c,sizeof(x))\n#define rep(i,s,e) for(int i=s;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#include \n#include \n\nusing namespace std;\n\ntypedef long long LL;\ntypedef pair PII;\ntypedef vector VI;\ntypedef vector VS;\n\n#define sz(X) ((int)(X.size()))\n#define all(x) x.begin(),x.end()\n#define clr(x,c) memset(x,c,sizeof(x))\n#define rep(i,s,e) for(int i=s;istart&&keep[i]end)) {\n\t\t\t\t\t//cout<start&&keep[i-1]end)) {\n\t\t\t\t\t//cout<\n#include\nusing namespace std;\nint main(){\n char str1[101],str2[101],z[101];\n int i,j,k=0;\n cin>>str1>>str2;\n for(i=0;str1[i]!='\\0';i++){\n if(str1[i]==str2[i])\n z[i]=str1[i];\n else if(str1[i]>str2[i])\n z[i]=str2[i];\n else k=1;\n }\n z[i]='\\0';\n if(k)\n cout<<-1<\n#include\n#include\n#include\n#include\n#include\n#include\n#define inf 1000000000000000000LL\nusing namespace std;\ntypedef long long ll;\nchar s[21],t[21];\nint a[21],de[21],bin[1<<14],num[1<<14],n;\nll ans=inf,f[1<<14];\ninline ll solve()\n{\n for(int S=1;S<1<=16) continue;\n for(int i=1;i<=n;i++)\n if(S&(1<='0' && s[i]<='9') a[n-i+1]=s[i]-'0';\n else a[n-i+1]=s[i]-'a'+10;\n for(int S=0;S<(1<1 && (S&(1<0) de[i]++;\n if(de[i]>=16 || de[i]<=-16) kill=1;\n sum+=de[i];\n\t}\n\tif(kill==0 && sum==0) ans=min(ans,solve());\n }\n if(ans==inf) printf(\"NO\\n\");\n else\n {\n int n=0;\n\twhile(ans>0){t[++n]=ans&15; ans=ans>>4;}\n\tfor(int i=::n;i>=1;i--)\n if(t[i]<10) printf(\"%c\",t[i]+'0');\n\t else printf(\"%c\",t[i]-10+'a');\n }\n return 0;\n}\n", "src_uid": "7fab93f1307159262fcc6044ecba6284"} {"source_code": "#include \nusing namespace std;\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n vector inp(5);\n vector> freq;\n for (int i = 0; i < 5; ++i)\n cin >> inp[i];\n for (int i = 0; i < 5; ++i) {\n bool flag = false;\n for (int j = 0; j < i; ++j) {\n if (inp[i] == inp[j]) {\n flag = true;\n break;\n }\n }\n if (!flag) {\n int herz = 1;\n for (int j = i+1; j < 5; ++j)\n if (inp[i] == inp[j])\n ++herz;\n freq.push_back(make_pair(herz, inp[i]));\n }\n }\n int sum = 0;\n for (int i = 0; i < 5; ++i)\n sum+=inp[i];\n sort(freq.rbegin(), freq.rend());\n if (freq.size() == 1)\n cout << sum - 3*freq[0].second << \"\\n\";\n else if (freq.size() == 2) {\n if (freq[0].first == 4)\n cout << sum - 3*freq[0].second << \"\\n\";\n else\n cout << sum - max(3*freq[0].second, 2*freq[1].second) << \"\\n\";\n }\n else if (freq.size() == 3) {\n if (freq[0].first == 3)\n cout << sum - 3*freq[0].second << \"\\n\";\n else\n cout << sum - max(2*freq[0].second, 2*freq[1].second) << \"\\n\";\n }\n else if (freq.size() == 4)\n cout << sum - 2*freq[0].second << \"\\n\";\n else\n cout << sum << \"\\n\";\n return 0;\n}\n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"source_code": "#include\n#include\nint n,m,i;\nlong long ans=1,j=1;\nint main()\n{\n scanf(\"%d%d\",&n,&m);\n for(i=1;i<=m;++i)j=(j<<1)%1000000009;\n for(i=1;i<=n;++i)ans=(ans*(--j))%1000000009;\n printf(\"%lld\",ans);\n return 0;\n}", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main(void)\n{\n\tstring str;\n\tcin >> str;\n\tstring a, b, c;\n\tstringstream stream;\n\tunsigned long long m = 0, q, w, e;\n\tbool f = false;\n\tif (str.size() < 3)\n\t{\n\t\tcout << -1;\n\t\treturn 0;\n\t}\n\tfor (string::size_type i = 1; i < str.size() - 1; ++i)\n\t{\n\t\tfor (string::size_type j = 1; j < str.size() - i; ++j)\n\t\t{\n\t\t\ta = str.substr(0, i);\n\t\t\tb = str.substr(i, j);\n\t\t\tif (b == str.substr(i))\n\t\t\t\tcontinue;\n\t\t\tif (i + j >= str.size())\n\t\t\t\tcontinue;\n\t\t\tc = str.substr(i+j);\n\t\t\tif (!a.empty() && !b.empty() && !c.empty()\n\t\t\t\t&& a.size() <= 7 && b.size() <= 7 && c.size() <= 7\n\t\t\t\t&&\t!(a[0] == '0' && a.size() > 1)\n\t\t\t\t&& !(b[0] == '0' && b.size() > 1)\n\t\t\t\t&& !(c[0] == '0' && c.size() > 1)\t\t\t\t\t\n\t\t\t\t)\t\t\t\t\n\t\t\t{\n\t\t\t\tstream.clear();\n\t\t\t\tstream << a << ' ' << b << ' ' << c;\n\t\t\t\tstream >> q >> w >> e;\n\t\t\t\tif (q <= 1000*1000 && w <= 1000*1000 && e <= 1000*1000)\n\t\t\t\t{\n\t\t\t\t\tm = max(m, q+w+e);\n\t\t\t\t\tf = true;\n\t\t\t\t}\n\t\t\t}\t\t\t\n\t\t}\n\t}\n\tif (f)\n\t\tcout << m << endl;\n\telse\n\t\tcout << -1 << endl;\n\treturn 0;\n}", "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"source_code": "#include \n#include\nusing namespace std;\n#define max(a,b) a>b?a:b;\n \n//#define fabs(a) a>0?a:-a; \nint main(){\n\tchar x1,x2;\n\tint y1,y2;\n\twhile(cin>>x1>>y1>>x2>>y2){\n\t\tint heng=x2-x1; //横向的差 \n\t\tint zong=y2-y1; //纵向的差\n\t\tint sum=max(fabs(heng),fabs(zong));\n\t\tcout<0&&zong>0){ //在右上角 \n\t\t \tcout<<\"RU\"<0&&zong<0){ //在右下角 \n\t\t\t\tcout<<\"RD\"<0){ //在左上角 \n\t\t\t\tcout<<\"LU\"<0){\n\t\t\t\tcout<<\"R\"<0){\n\t\t\t\tcout<<\"U\"<\nusing namespace std ;\n\nint main()\n{\n \n int a,b,c,d,h,ans;\n cin>>a>>b>>c>>d;\n h=min(a,min(c,d));\n ans=h*256;\n a-=h;\n h=min(b,a);\n ans+=h*32;\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\ntypedef long long ll;\ntypedef long double ld;\n\n#define int ll\n\nmap used;\n\nvoid del(string &s, int pos)\n{\n\tfor (int i = pos; i < s.size() - 1; i++)\n\t\ts[i] = s[i + 1];\n\ts.resize(s.size() - 1);\n}\n\nint to_int(string s)\n{\n\tint res = 0, p = 1;\n\n\tfor (int i = s.size() - 1; i >= 0; i--)\n\t{\n\t\tres += (s[i] - '0') * p;\n\t\tp *= 10;\n\t}\n\treturn res;\n}\n\nint sqt(int n)\n{\n\tint l = 0, r = 2000000000;\n\n\twhile (r - l > 1)\n\t{\n\t\tint m = (l + r) / 2;\n\t\tif (m * m < n)\n\t\t\tl = m;\n\t\telse\n\t\t\tr = m;\n\t}\n\treturn r;\n}\n\nint ans = 1000000000;\n\nvoid r(string now, int cnt)\n{\n\tif (now.size() == 0 || cnt >= ans || now[0] == '0' || used[now])\n\t\treturn;\n\tused[now]++;\n\t//cout << now << \" \" << to_int(now) << endl;\n\n\tint tmp = int(sqt(to_int(now)));\n\tif (tmp * tmp == to_int(now))\n\t{\n\t\tans = min(ans, cnt);\n\t}\n\n\tint ans = 1000000000;\n\n\tfor (int i = 0; i < now.size(); i++)\n\t{\n\t\tstring b = now;\n\t\tdel(b, i);\n\t\tr(b, cnt + 1);\n\t}\n\n\treturn;\n}\n\nsigned main()\n{\n#ifdef _DEBUG\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\n\tstring s;\n\n\tcin >> s;\n\tr(s, 0);\n\n\tif (ans == 1000000000)\n\t\tcout << -1;\n\telse\n\t\tcout << ans;\n\t\n\treturn 0;\n}", "src_uid": "fa4b1de79708329bb85437e1413e13df"} {"source_code": "#include\n\nusing namespace std;\ntypedef long long LL;\n\nint chk(int t1,int t2,int a,int b, int c)\n{\n\ta%=3600*60;\n\tb%=3600*60;\n\tc%=3600*60;\n\tt1%=3600*60;\n\tt2%=3600*60;\n\tfor(;t1!=t2;t1=(t1+1)%(3600*60))\n\t{\n\t\tif(t1==a||t1==b||t1==c){\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 1;\n}\n\n\nint main()\n{\n\tios::sync_with_stdio(false);\n\t\n\tint h,m,s,t1,t2;cin>>h>>m>>s>>t1>>t2;\n\t\n\tif(chk(t1*5*3600,t2*5*3600,h*5*3600+60*m+s,3600*m+60*s,3600*s)==1||chk(t2*5*3600,t1*5*3600,h*5*3600+60*m+s,3600*m+60*s,3600*s)==1)\n\t{\n\t\tcout<<\"YES\"<\n#define pb push_back\n#define INF 10000000\nusing namespace std;\nint n,box;\nint a[105],b[105],d[105],bit[53];\nint asal[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};\nint dp[105][100005];\nint d1[105][100005];\nint d2[105][100005];\nint rec(int x,int mark)\n{\n int res=INF;\n if(dp[x][mark] != -1) \n return dp[x][mark];\n if(x == n+1)\n return 0;\n for (int i = 1; i <= 53; i++)\n {\n if((mark & bit[i]))\n continue;\n int mark2 = (mark | bit[i]);\n int tmp=rec(x+1,mark2)+abs(a[x]-i);\n if(res > tmp)\n {\n res=tmp;\n d1[x][mark]=i;\n d2[x][mark]=mark2;\n }\n }\n return dp[x][mark]=res;\n}\nint main()\n{\n scanf(\"%d\",&n);\n for (int i = 1; i <= n; i++)\n scanf(\"%d\",&a[i]);\n for (int i = 1; i <= 53; i++)\n for (int j = 0; j < 16; j++)\n if(i%asal[j] == 0)\n bit[i]+=(1 << j);\n memset(dp,-1,sizeof dp);\n rec(1,0);\n for (int i = 1; i <= n ; i++)\n {\n printf(\"%d \",d1[i][box]);\n box=d2[i][box];\n }\n}", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"} {"source_code": "#include\n#define N 100000\n#define reg register\n#define inl inline\n#define int long long\nusing namespace std;\nint n,a[N+5],tot,ans=1e18,Ans;\nsigned main()\n{\n\tscanf(\"%lld\",&n);\n\tAns=3*3*(n+1)-n;\n\ta[++tot]=1;\n\ta[++tot]=n;\n\tfor(reg int i=2;i<=(int)(sqrt(n));i++)\n\t{\n\t\tif(!(n%i))\n\t\t{\n\t\t\ta[++tot]=i;\n\t\t\tif(i*i!=n) a[++tot]=n/i;\n\t\t}\n\t}\n\tfor(reg int i=1;i<=tot;i++)\n\t{\n\t\tfor(reg int j=1;j<=tot;j++)\n\t\t{\n\t\t\treg int x=a[i],y=a[j],z=n/a[i]/a[j];\n\t\t\tif(n%(x*y)) continue;\n\t\t\tif(x*y*z!=n) continue;\n\t\t\tans=min(ans,(x+1)*(y+2)*(z+2));\n\t\t}\n\t}\n\tans-=n;\n\tprintf(\"%lld %lld\\n\",ans,Ans);\n\treturn 0;\n}", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"} {"source_code": "#include\nusing namespace std;\nnamespace AERIX{\n\n/****************************************************************/\nint ns, n, ans;\nchar s[100000];\nint pos[26];\nvoid main(){\n scanf(\"%d%s\",&ns,s);\n int i=0;\n ans=0;\n while(ians)ans=n;\n }\n printf(\"%d\\n\",ans);\n}\n/****************************************************************/\n\n}\nint main(){\n#ifdef USEFILE\n freopen(\"input.txt\",\"r\",stdin);\n#endif // USEFILE\n AERIX::main();\n return 0;\n}\n", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"source_code": "//\n#include \n#define lli long long int\n#define mod 1000000007\nusing namespace std;\nint main ()\n{\n lli n;\n cin>>n;\n lli a[]={1, 5, 10, 20, 100};\n lli count=0;\n for (int i=4; i>=0 && n>0; i--) {\n count+=(n/a[i]);\n n=n%a[i];\n }\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main()\n{\n long long n, a, b, a1, b1, nod;\n cin >> n >> a >> b;\n a1 = a;\n b1 = b;\n while (a1 > 0 && b1 > 0)\n {\n if (a1 >= b1) a1 = a1 % b1;\n else b1 = b1 % a1;\n }\n if (a1 == 0) nod = b1;\n else nod = a1;\n if (n % nod != 0 || (n < a && n < b))\n {\n cout << \"NO\";\n return 0;\n }\n else if (n % a == 0)\n {\n cout << \"YES\" << endl;\n cout << n/a << \" \" << 0;\n return 0;\n }\n else if (n % b == 0)\n {\n cout << \"YES\" << endl;\n cout << 0 << \" \" << n/b;\n return 0;\n }\n else\n {\n for (int i = 0; i <= n; i++)\n {\n if ((n-i*a)%b == 0)\n {\n if (i > 0 && (n - i*a)/b > 0)\n {\n cout << \"YES\" << endl;\n cout << i << \" \" << (n - i*a)/b;\n return 0;\n }\n }\n }\n }\n cout << \"NO\";\n\treturn 0;\n}", "src_uid": "b031daf3b980e03218167f40f39e7b01"} {"source_code": "#pragma GCC optimize(\"O3\")\n#include \n\n#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n#define files(name) name!=\"\"?freopen(name\".in\",\"r\",stdin),freopen(name\".out\",\"w\",stdout):0\n#define files_ds(name) name!=\"\"?freopen(name\".dat\",\"r\",stdin),freopen(name\".sol\",\"w\",stdout):0\n#define all(a) a.begin(),a.end()\n#define len(a) (int)(a.size())\n#define elif else if\n#define mp make_pair\n#define pb push_back\n#define fir first\n#define sec second\n\nusing namespace std;\n#define int long long\n\ntypedef unsigned long long ull;\ntypedef pair pii;\ntypedef vector vi;\ntypedef long double ld;\ntypedef long long ll;\n\nconst int arr=2e5+10;\nconst int ar=2e3+10;\nconst ld pi=acos(-1);\nconst ld eps=1e-10;\nconst ll md=1e9+7;\n\n///---program start---///\n\n#define arr (int)(5e5+10)\n\nint a[arr];\n\nmain()\n{\n #ifdef I_love_Maria_Ivanova\n files(\"barik\");\n freopen(\"debug.txt\",\"w\",stderr);\n #else\n files(\"\");\n files_ds(\"\");\n #endif\n\n fast;\n int n;\n cin>>n;\n for (int i=0;i>a[i];\n }\n set oryshych;\n oryshych.clear();\n for (int i=0;i to_sort(0);\n for (int i=0;i\nusing namespace std;\nconst int maxn=55;\ntypedef long long ll;\nll f[maxn][maxn],a[maxn];\nbool vis[maxn];\nchar s[maxn];\nint main(){\n scanf(\"%s\",s+1);\n int len=strlen(s+1);\n for(int i=1;i<=len;i++){\n a[i]=s[i]-'0';\n }\n for(int i=0;i<=9;i++){\n f[1][i]=1;\n }\n int cnt=1;\n for(int i=2;i<=len;i++){\n bool jud=0;\n for(int j=0;j<=9;j++){\n int now=j+a[i];\n if(now%2==0) {\n f[i][now/2]+=f[i-1][j];\n if(now/2==a[i] && j==a[i-1]) jud=1;\n }\n else {\n f[i][now/2]+=f[i-1][j];\n f[i][(now+1)/2]+=f[i-1][j];\n if(now/2==a[i] && j==a[i-1]) jud=1;\n if((now+1)/2==a[i] && j==a[i-1]) jud=1;\n }\n }\n cnt+=jud; \n }\n ll ans=0;\n for(int i=0;i<=9;i++){\n ans+=f[len][i];\n }\n if(cnt==len) ans--;\n printf(\"%lld\\n\",ans);\n return 0;\n}", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b"} {"source_code": "#include\nusing namespace std ;\nint convert (string s )\n{\n if(s==\"January\")\n return 1 ;\n else if (s==\"February\")\n return 2 ;\n else if (s==\"March\")\n return 3 ;\n else if (s==\"April\")\n return 4 ;\n else if (s==\"May\")\n return 5 ;\n else if (s==\"June\")\n return 6 ;\n else if (s==\"July\")\n return 7 ;\n else if (s==\"August\")\n return 8 ;\n else if (s==\"September\")\n return 9 ;\n else if (s==\"October\")\n return 10 ;\n else if (s==\"November\")\n return 11 ;\n else if (s==\"December\")\n return 12 ;\n\n\n}\nint main()\n{\n string arr[]={\"January\", \"February\", \"March\", \"April\", \"May\",\n \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"};\n string ss; int n ;\n cin>>ss>>n;\n\n int i = ((convert(ss)+n)%12)-1 ;\n if(i<0)\n i=11;\n\n\n cout<\n#include \n#include \n#include \n#include \n#include \n\n\nusing namespace std;\n\n#define sz(x) ((int)(x).size())\n#define M 100000000\n#define GETBIT(x,i) ((x>>i)&1)\n#define sqr(x) ((x)*(x))\n#define cube(x) ((x)*(x)*(x))\n\n#define eps 1e-10\n#define inf 1e20\n\n#define M_PI 3.14159265358979323846\n#define M_E 2.71828182845904523536\n#define RAND2_MAX\n#define __int64 long long\n\n\nint m,n,a,b;\n\nint x,y,k;\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"rt\", stdin);\n freopen(\"output.txt\", \"wt\", stdout);\n#endif\n\n cin >> n >> m >> a >> b;\n\n\n\n --a;\n --b;\n x = a % m;\n y = b % m;\n k = b/m-a/m-1;\n\n if (b == n-1)\n {\n y = m-1;\n }\n\n if (k == -1) \n {\n cout << 1;\n return 0;\n }\n\n if (k == 0)\n {\n if (x == 0 && y == m-1)\n {\n cout << 1;\n return 0;\n }\n cout << 2;\n return 0;\n }\n\n if (x == 0 && y == m-1)\n {\n cout << 1;\n return 0;\n }\n\n if (x == 0 || y == m-1)\n {\n cout << 2;\n return 0;\n }\n\n if (y == x-1)\n {\n cout << 2;\n return 0;\n }\n\n cout << 3;\n\n}", "src_uid": "f256235c0b2815aae85a6f9435c69dac"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n int a,b;\n cin>>a;\n for(int i=10;1;i*=10)\n {\n b=a%i;\n if(b<10){\n if(b>=6)a=a+(10-b);\n else a=a-b;\n cout<\n#include\n#include\n#include\n#include\nusing namespace std;\n\nint main() {\n int k, l;\n scanf(\"%d%d\", &k, &l);\n if(k == l) {\n printf(\"YES\\n0\");\n //system(\"pause\");\n return 0;\n }\n if((k == 1 && k < l) || k > l) {\n printf(\"NO\");\n //system(\"pause\");\n return 0;\n }\n long long ans = k;\n for(int i = 1; ; i++) {\n ans *= k;\n if(ans == l) {\n printf(\"YES\\n%d\", i);\n break;\n }\n if(ans > l) {\n printf(\"NO\");\n break;\n }\n }\n //system(\"pause\");\n return 0;\n}\n\n\n ", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"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\nint main ()\n{\n long long n , d ,x ;\n cin>>n>>d ;\n x=++n ;\n for(long long i=10;(n%i)<=d;)\n {\n x=n-(n%i) ;\n i*=10 ;\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\n#include\n\nusing namespace std;\n\n#define double long double\n\ntypedef pair ii;\ntypedef pair il;\ntypedef pair ll;\ntypedef pair lli;\ntypedef pair li;\ntypedef pair dd;\ntypedef pair iii;\ntypedef pair di;\ntypedef pair iii2;\ntypedef pair iiii;\nint mod = 1000000007LL;\nlong long large = 2000000000000000000LL;\n\n\n\nint sz = 0;\nint x,k,n,q;\n\nmap comp;\nvector mask;\nvector c;\n\nvector > g;\nvector w;\n\nvector > mul(vector > a,vector > b){\n\tvector > c(sz,vector(sz,large));\n\tfor(int i=0;i > power(vector > a,long long x){\n\tvector > ans(sz,vector(sz,large));\n\tfor(int i=0;i>=1;\n\t}\n\treturn ans;\n}\n\nstring getmask(int x){\n\tstring s = \"\";\n\tfor(int i=0;i mul2(vector b,vector > a){\n\tvector c(sz,large);\n\tfor(int i=0;i comp2;\n\nvector get1(vector b,int pos){\n\tvector re(sz,large);\n\tfor(int i=0;i>=1;\n\t\t\tfor(int j=0;j>1]] = min(re[comp[m>>1]],b[i]);\n\t\t}\n\t}\n\treturn re;\n}\nint main(){\n\n\tcin>>x>>k>>n>>q;\n\tc.assign(k,0);\n\tfor(int i=0;i>c[i];\n\n\tfor(int i=0;i<(1<(sz,large));\n\n\tfor(int i=0;i>=1;\n\t\t\tfor(int j=0;j>1]]=0;\n\t\t}\n\t}\n\n\n\t/*for(int i=0;i>a>>b;\n\t\ta--;\n\t\tw.push_back(il(a,b));\n\t}\n\tsort(w.begin(),w.end());\n\n\tfor(int i=0;i ind;\n\tind.push_back(0);\n\tfor(int i=0;in-x) ind.pop_back();\n\n\tvector > re((int)ind.size(),vector());\n\tre[0] = vector(sz,large);\n\tre[0][comp[(1<\nusing namespace std;\n\n\nvoid solve()\n{\n int n;cin>>n;\n int a;cin>>a;\n int old = a;\n vectorv(n-1);\n for(int i=0;i>v[i];\n sort(v.begin(),v.end());\n while(v[n-2]>=a)\n {\n v[n-2]-=1;\n a+=1;\n sort(v.begin(),v.end());\n }\n cout << a-old<<\"\\n\";\n}\n\nint main()\n{\n int t=1;//cin>>t;\n while(t--)\n solve();\n return 0;\n}\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"} {"source_code": "#include \n#include \nusing namespace std;\n\nint main () {\n\tint chess[8][8], r1, c1, r2, c2, rook = 0, bi = 0, king = 0;\n\tscanf(\"%d %d %d %d\", &r1, &c1, &r2, &c2);\n\tking = max(abs(r1-r2), abs(c1-c2));\n\tif (r1 == r2 && c1 == c2) {\n\t\tprintf(\"0 0 0\\n\");\n\t\treturn 0;\n\t}\n\telse if (r1 != r2 && c1 == c2 || r1 == r2 && c1 != c2) {\n\t\trook = 1;\n\t}\n\telse {\n\t\trook = 2;\n\t}\n\tif (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2) {\n\t\t\tbi = 1;\n\t}\n\telse if ((abs(r1-r2) + abs((c1-c2)))%2!=0) {\n\t\tbi = 0;\n\t}\n\telse {\n\t\tbi = 2;\n\t}\n\tprintf(\"%d %d %d\\n\", rook, bi, king);\n\treturn 0;\n}\n", "src_uid": "7dbf58806db185f0fe70c00b60973f4b"} {"source_code": "#define _CRT_SECURE_NO_WARNINGS\n#define _USE_MATH_DEFINES\n#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"time.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 \n#include \n//#include \n#include \n#include \nusing namespace std;\n//typedef long long ll;\n#define ll long long\n#define ld long double\n\n\n#define MIN(x,y) ((x)<(y)?(x):(y))\n#define MAX(x,y) ((x)>(y)?(x):(y))\n//#define PI 3.14159265358979323846\n#define PI M_PI;\n#define ABS(a) ((a)<0?-(a):(a))\nconst long long MOD = 998244353;\nconst long long MAX = 1000000000;\nconst long long LLONG = 9223372036854775807;\nconst int N = 100000;\nconst double EPS = 0.00000001;\nconst int sqsz = 5000;\ntemplate inline int sgn(const T& val) { return (T(0) < val) - (val < T(0)); }\ninline unsigned long long hsh(int x, int y) { return (((unsigned long long)x) << 32) + y; }\ntemplate inline T gcd(T a, T b) {\n while (b) { a %= b; swap(a, b); }\n return a;\n}\ninline void fastio() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n}\n//reverse pair sort: [](pair a, pairb) {return a.first > b.first || ((a.first == b.first) && (a.second < b.second)); }\n\n\nint main()\n{\n //freopen(\"output.txt\", \"w+\", stdout);\n //freopen(\"input.txt\", \"r\", stdin);\n int n, k, m, a, c;\n scanf(\"%i %i %i %i\", &n, &k, &m, &a);\n m = m - a;\n vector,int>> cns(n);\n vector res(n), prefsum(n + 1);\n while (a--)\n {\n scanf(\"%i\", &c);\n c--;\n cns[c].first.first++;\n cns[c].first.second = a;\n }\n if (n == k)\n {\n for (int i = 0; i < n; i++)\n if (cns[i].first.first)\n printf(\"1 \");\n else\n if (m)\n printf(\"2 \");\n else\n printf(\"3 \");\n return 0;\n }\n for (int i = 0; i < n; i++)\n cns[i].second = i;\n sort(cns.rbegin(), cns.rend());\n prefsum[0] = 0;\n for (int i = 0; i < n; i++)\n prefsum[i + 1] = prefsum[i] + cns[i].first.first;\n for (int i = 0; i < n; i++)\n {\n if (!(cns[i].first.first || m))\n {\n res[cns[i].second] = 3;\n continue;\n }\n if (i < k)\n {\n if ((k - i) * (cns[i].first.first + 1) - prefsum[k + 1] + prefsum[i + 1] <= m)\n res[cns[i].second] = 2;\n else\n if (!(cns[i].first.first))\n res[cns[i].second] = 2;\n else\n res[cns[i].second] = 1;\n }\n else\n {\n if (cns[i].first.first + m > cns[k - 1].first.first)\n res[cns[i].second] = 2;\n else\n res[cns[i].second] = 3;\n }\n }\n for (int a : res)\n printf(\"%i \", a);\n}", "src_uid": "81a890bd542963bbcec7a041dde5c247"} {"source_code": "#include\nusing namespace std;\nlong long n,m,s,a,b,c,d;\nint main() {\n\tcin>>n>>m>>s;\n\ta=n%s;\n\tb=m%s;\n\tc=n/s;\n\td=m/s;\n\tif(a==0)\n\t\ta=s;\n\telse\n\t\tc++;\n\tif(b==0)\n\t\tb=s;\n\telse\n\t\td++;\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#define mp make_pair\n#define pb push_back\n#define rep(i,j,k) for(int (i)=(j);(i)<=k;(i)++) \nusing namespace std;\nlong long n,k,s=0,t;\nint main(){\n\tcin>>n>>k;\n\t//if(k>(n+1)/2){\n\t// if(k-((n-1)/2)%2==0)k=(n-1)/2;\n\t// else k=(n-1)/2-1;}\n\tfor(int i=1;i<=k;i++){\n\t\tif(n>s){s++;t+=n-s;}if(n>s){s++;t+=n-s;}\n\t\t//if(s>=99998){cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#define ll long long\n#define lf else if\n#define For(i,x,y) for(ll i=x;i<=y;++i)\n#define FOr(i,x,y) for(ll i=x;i>=y;--i)\nusing namespace std;\ninline ll read(){ ll x=0,f=1;char 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; } \ninline void write(ll x){ if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0'); } \ninline void writeln(ll x){ write(x); puts(\"\"); }\nconst ll N=1000010,bas=37,mod=998244353;\nll n,bin[N],a[N],b[N],c,d;\nchar s1[N],s2[N];\nll get(char ch){\n\tif (ch=='N')\treturn 0;\n\tif (ch=='S')\treturn 3;\n\tif (ch=='W')\treturn 1;\n\treturn 2;\n}\nint main(){\n//\tfreopen(\"shenzhebei.in\",\"r\",stdin);\n\tn=read()-1;\tscanf(\"%s%s\",s1+1,s2+1);\n\tFor(i,1,n)\ta[i]=3-get(s1[i]),b[i]=get(s2[i]);\n\tbin[0]=1;\tFor(i,1,n)\tbin[i]=bin[i-1]*bas%mod;\n\tFOr(i,n,1){\n\t\tc=(c*bas+a[i])%mod;\n\t\td=(d+bin[n-i]*b[i])%mod;\n\t\tif (c==d)\treturn puts(\"NO\");\n\t}puts(\"YES\");\n}", "src_uid": "85f43628bec7e9b709273c34b894df6b"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n int i,d=0,j;\n long s[5];\n for (i=1;i<=4;i++) cin>>s[i];\n for (i=1;i<4;i++)\n if (s[i]==-1) continue;\n else\n {\n for (j=i+1;j<=4;j++) \n if (s[j]==s[i]) \n {\n d++;\n s[j]=-1;\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#define MM(a,b) memset(a,b,sizeof(a))\n#define rf(a) scanf(\"%lf\",&a)\n#define ri(a) scanf(\"%d\",&a)\n#define PF printf\n#define PB push_back\n#define SC scanf\n#define CT continue\ntypedef long long ll;\ntypedef unsigned long long ull;\nconst double eps = 1e-14;\nconst int inf = 0x3f3f3f3f;\nconst int N=1e5+10;\nconst int mod=1e4+7;\nconst double pi=acos(-1);\nusing namespace std;\n\nint ans,a,b,h,w,n,s[N];\n\nvoid dfs(ll a,ll b,ll w,ll h,int c)\n{\n if(c>n) return;\n if(a<=w&&b<=h){\n ans=min(ans,c);\n return;\n }\n if(s[c]==2){\n while(a>w) w*=2,c++;\n while(b>h) h*=2,c++;\n ans=min(ans,c);\n return;\n }\n if(a>w) dfs(a,b,w*s[c+1],h,c+1);\n if(b>h) dfs(a,b,w,h*s[c+1],c+1);\n}\n\nbool cmp(int &a,int &b)\n{\n return a>b;\n}\n\nint main()\n{\n while(~SC(\"%d%d%d%d%d\",&a,&b,&h,&w,&n)){\n for(int i=1;i<=n;i++) ri(s[i]);\n sort(s+1,s+n+1,cmp);\n ans=n+10;\n dfs(a,b,w,h,0);\n dfs(a,b,h,w,0);\n PF(\"%d\\n\",ans>n?-1:ans);\n }\n return 0;\n}\n", "src_uid": "18cb436618b2b85c3f5dc348c80882d5"} {"source_code": "#include\n#include\n#include\n#define LL long long\nusing namespace std;\nLL f[200005],r[200005],d[200005],mi[200005],ma[200005];\nLL getfa(LL x)\n{\n\tif(f[x]==x)\n\t\treturn x;\n\tLL fx=f[x];\n\tf[x]=getfa(fx);\n\tr[x]+=r[fx];\n\treturn f[x];\n}\nint main()\n{\n\tLL n,m,x,y,a,b,i,total=0,nowmax=-0x7fffffff;\n\tscanf(\"%I64d%I64d\",&n,&m);\n\tfor(i=1;i<=n;i++)\n\t\tf[i]=i;\n\tmi[1]=0x7fffffff;\n\tma[1]=-0x7fffffff;\n\tmi[n]=0x7fffffff;\n\tma[n]=-0x7fffffff;\n\tfor(i=1;i<=m;i++)\n\t{\n\t\tscanf(\"%I64d%I64d%I64d%I64d\",&x,&y,&a,&b);\n\t\td[x]+=b;d[y]-=b;\n\t\ttotal+=a*b*b;\n\t\tLL fx=getfa(x);\n\t\tLL fy=getfa(y);\n\t\tif(fx==fy)\n\t\t{\n\t\t\tif(r[x]+a*b==r[y])\n\t\t\t\tcontinue;\n\t\t\treturn printf(\"BAD %I64d\\n\",i),0;\n\t\t}\n\t\tif(fx!=fy)\n\t\t{\n\t\t\tf[fy]=fx;\n\t\t\tr[fy]=r[x]+a*b-r[y];\n\t\t\tmi[fx]=min(mi[fy]+r[fy],mi[fx]);\n\t\t\tma[fx]=max(ma[fy]+r[fy],ma[fx]);\n\t\t\tnowmax=max(ma[fx]-mi[fx],nowmax);\n\t\t\tgetfa(y);\n\t\t\tif(mi[getfa(1)]<=r[1])\n\t\t\t\treturn printf(\"BAD %I64d\\n\",i),0;\n\t\t\tif(ma[getfa(n)]>=r[n])\n\t\t\t\treturn printf(\"BAD %I64d\\n\",i),0;\n\t\t\tif(getfa(1)==getfa(n)&&(nowmax>=r[n]-r[1]||r[n]<=r[1]))\n\t\t\t\treturn printf(\"BAD %I64d\\n\",i),0;\n\t\t}\n\t}\n\tif(getfa(1)!=getfa(n))\n\t\treturn puts(\"UNKNOWN\"),0;\n\tfor(i=2;i0)\n\t\t{\n\t\t\ttotal+=(r[i]-r[1])*d[i];\n\t\t\td[1]+=d[i];d[i]=0;\n\t\t}\n\t\tif(d[i]<0)\n\t\t{\n\t\t\ttotal+=(r[n]-r[i])*-d[i];\n\t\t\td[n]-=d[i];d[i]=0;\n\t\t}\n\t}\n\tprintf(\"%.0lf\",round((double)total/d[1]));\n}", "src_uid": "b047916b7d99bc34a64ad41f43a37bf0"} {"source_code": "#include \n\nusing namespace std;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int n; cin >> n;\n string word; cin >> word;\n bool got = false;\n for (int i = 0; i < n; i++) {\n if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u' || word[i] == 'y') {\n if (!got) {\n cout << word[i];\n got = true;\n }\n } else {\n cout << word[i];\n got = false;\n }\n }\n return 0;\n}", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "#include \n\ntypedef long long LL;\nusing namespace std;\n\nconst LL N = 1e5 + 9;\nLL n, m, i = 0;\n\n\n// Let it go! Let it go! Can't hold it back anymore! Let it go! Let it go! Turn away and slam the door!\n\n\n\nint main()\n{\n cin >> n >> m;\n while (n) {\n n--;\n i++;\n if (i % m == 0) n++;\n }\n cout << i;\n}\n\n// take your age, substract 15, add 15, This is your age now :)\n// funny joke.", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define pb push_back\n#define mp make_pair\n#define y1 y1asd\n#define F first\n#define S second\nusing namespace std;\ntypedef long long ll;\ntypedef pair pii;\nconst int mod = (int)1e9 + 7;\nconst int inf = (1 << 30) - 1;\nconst int N = 505;\n\nll binpow(ll x, ll n) {\n\tll res = 1;\n\twhile (n) {\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}\n\nll inv(ll x) {\n\treturn binpow(x, mod - 2);\n}\n\nstruct num {\n\tll a, b;\n\tnum() : a(0), b(0) {}\n\tnum(ll x) : a(x % mod), b(0) {}\n\tnum(ll a, ll b) : a(a % mod), b(b % mod) {}\n\tbool const operator ==(const num &n) const {\n\t\treturn a == n.a && b == n.b;\n\t}\n\tnum const operator +(const num &n) const {\n\t\treturn num(a + n.a, b + n.b);\n\t}\n\tnum const operator -(const num &n) const {\n\t\treturn num(a - n.a + mod, b - n.b + mod);\n\t}\n\tnum const operator *(const num &n) const {\n\t\treturn num(a * n.a + 5 * b * n.b, a * n.b + b * n.a);\n\t}\n\tnum const operator *(ll k) const {\n\t\treturn num(a * k, b * k);\n\t}\n\tnum const operator /(ll k) const {\n\t\tk = inv(k);\n\t\treturn num(a * k, b * k);\n\t}\n} powA[N], powB[N], powX[N];\n\nconst num E = num(1, 0);\nconst num A = num(1, 1) / 2;\nconst num B = num(1, mod-1) / 2;\nconst num X = num(0, inv(5));\n\nint k;\nll s[N][N], c[N][N], factK;\n\nvoid preprocess() {\n\ts[0][0] = c[0][0] = 1;\n\tfor (int i = 1; i < N; i++) {\n\t\ts[i][0] = (mod - i + 1) * s[i-1][0] % mod;\n\t\tc[i][0] = 1;\n\t\tfor (int j = 1; j <= i; j++) {\n\t\t\tc[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;\n\t\t\ts[i][j] = (s[i-1][j-1] + mod + (mod - i + 1) * s[i-1][j] % mod) % mod;\n\t\t}\n\t}\n\tfactK = 1;\n\tpowA[0] = powB[0] = powX[0] = E;\n\tfor (int i = 1; i <= k; i++) {\n\t\tfactK = factK * i % mod;\n\t\tpowA[i] = powA[i-1] * A;\n\t\tpowB[i] = powB[i-1] * B;\n\t\tpowX[i] = powX[i-1] * X;\n\t}\n}\n\npair get_progression(num C, ll n) { // (1+C+..+C^n, C^n)\n\tif (n == 0) return mp(E, E);\n\tif (n == 1) return mp(E + C, C);\n\tpair p = get_progression(C, n / 2);\n\tif (n & 1) return mp(p.F * (E + C * p.S), p.S * p.S * C);\n\treturn mp(p.F - p.S + p.S * p.F, p.S * p.S);\n}\n\nint get(ll n) {\n\tll ans = 0;\n\tfor (int j = 1; j <= k; j++) {\n\t\tfor (int t = 0; t <= j; t++) {\n\t\t\tll coef = s[k][j] * c[j][t] % mod;\n\t\t\tif ((j-t) & 1) coef = (mod - coef) % mod;\n\t\t\tnum num_part = get_progression(powA[t] * powB[j-t], n).F;\n\t\t\t// printf(\"n = %lld: (j, t)=(%d %d) --> %lld * (%lld, %lld) phi^%d* psi^%d\\n\", n, j, t, coef, num_part.a, num_part.b, t, j - t);\n\t\t\tnum_part = num_part * powX[j];\n\t\t\tans += coef * num_part.a % mod;\n\t\t\tans %= mod;\n\t\t}\n\t}\n\treturn ans * inv(factK) % mod;\n}\n\nint main() {\n\tll l, r;\n\tcin >> k >> l >> r;\n\tpreprocess();\n\t// printf(\"get(1) = %d\\n\", get(3));\n\t// for (int i = 0; i <= 3; i++) {\n\t// \tprintf(\"get(%d) = %d\\n\", i, get(i + 2));\n\t// \tputs(\"____\\n\");\n\t// }\n\tll ans = get(r + 2) + mod - get(l + 1);\n\tans %= mod;\n\tprintf(\"%d\\n\", (int)ans);\n\n\n\treturn 0;\n}\n", "src_uid": "dee552588e1281c2523868cd4090b46f"} {"source_code": "#include\n#include\nusing namespace std;\n#define sz(v) ((int)v.size())\n#define repi(n) for(int i = 0; i < (int)(n); ++i)\nint main()\n{\n\tstring s, ans;\n\tcin >> s;\n\trepi(sz(s))\n\t\tif( i == 0 && s[i] == '9' || s[i] < '5') ans.push_back(s[i]);\n\t\telse ans.push_back('9' - s[i] + '0');\n\t\tcout << atoll(ans.c_str());\n\t\treturn 0;\n}", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"source_code": "#define _CRT_SECURE_NO_DEPRECATE\n#include \n#include \n#include \n#include \n#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#pragma comment(linker, \"/STACK:196777216\")\n\n#define CL(x) memset(x, 0, sizeof(x))\n\n#define FOR(i, n) for (int i = 0; i < (int)(n); i++)\n\ntypedef vector VS;\ntypedef vector vi;\n\ntypedef unsigned long long LL;\n\nLL d[64][64];\nint c[64][64];\n\nLL D(int n, int h)\n{\n\tif (n == 0)\n\t\treturn h == 0;\n\tif (n == 1)\n\t\treturn h == 1;\n\tif (n < h)\n\t\treturn 0;\n\tLL & res = d[n][h];\n\tif (c[n][h])\n\t\treturn res;\n\tc[n][h] = 1;\n\tres = 0;\n\tfor (int cL = 0; cL < n; cL++)\n\t{\n\t\tint cR = n - 1 - cL;\n\t\tfor (int hL = 0; hL <= cL; hL++)\n\t\t\tfor (int hR = 0; hR <= cR; hR++)\n\t\t\t\tif (max(hL, hR) + 1 == h)\n\t\t\t\t{\n\t\t\t\t\tLL a = D(cL, hL);\n\t\t\t\t\tLL b = D(cR, hR);\n\t\t\t\t\tres += a * b;\n\t\t\t\t}\n\t}\n\treturn res;\n}\n\n\nint main()\n{\n\tint n, h;\n\tscanf(\"%d %d\", &n, &h);\n\tLL res = 0;\n\tfor (int k = h; k <= n; k++)\n\t\tres += D(n, k);\n\tprintf(\"%I64u\\n\", res);\n\treturn 0;\n}", "src_uid": "faf12a603d0c27f8be6bf6b02531a931"} {"source_code": "#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\t//freopen(\"input.txt\",\"r\",stdin);\n\t//freopen(\"output.txt\",\"w\",stdout);\n\tint n,a,b,c,ans=0;\n\tcin>>n>>a>>b>>c;\n\tfor(int i=0;i<=a;i++){\n\t\tfor(int j=0;j<=b;j++){\n\t\t\tdouble z=(n-0.5*i-j)/2;\n\t\t\tif(int(z)==z && z<=c && z>=0) ans++;\n\t\t}\n\t}\n\tcout<\nusing namespace std;\n\nint main()\n{\n\tlong long cnt1, cnt2, x, y;\n\tcin >> cnt1 >> cnt2 >> x >> y;\n\tlong long l, r;\n\tl = 0;\n\tr = 10000000000;\n\tlong long c1, c2;\n\tc1 = cnt1;\n\tc2 = cnt2;\n\twhile (r - l > 1)\n\t{\n\t\tlong long m;\n\t\tm = (l + r) / 2;\n\t\tbool enough = 1;\n\t\tcnt1 = c1;\n\t\tcnt2 = c2;\n\t\tcnt1 -= m / y - m / (x * y);\n\t\tcnt2 -= m / x - m / (x * y);\n\t\tif (cnt1 < 0)\n\t\t\tcnt1 = 0;\n\t\tif (cnt2 < 0)\n\t\t\tcnt2 = 0;\n\t\tif (cnt1 + cnt2 > m - m / x - m / y + m / (x * y))\n\t\t\tenough = 0;\n\t\tif (enough)\n\t\t\tr = m;\n\t\telse\n\t\t\tl = m;\n\t}\n\tcout << r;\n\treturn 0;\n}", "src_uid": "ff3c39b759a049580a6e96c66c904fdc"} {"source_code": "#include \nusing namespace std;\ntypedef vector vi;\ntypedef vector > vpii;\ntypedef pair pii;\ntypedef long long ll;\ntypedef pair pll;\ntypedef pair pdd;\n#define INF 1000000000\n#define MOD 1000000007\n#define EPSILON 0.00001\n#define f first\n#define s second\n#define pb push_back\n#define mp make_pair\n\n#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)\n#define F0R(i, a) for (int i=0; i<(signed)(a); i++)\n#define RFOR(i, a, b) for (int i=(a); i >= b; i--)\n\n#define MN 10\nint gr[MN][MN];\nvpii moves;\n\nvoid swp(int x, int y, int d){ //0 = up/down, 1 = left/right\n if(d == 1){\n F0R(i, 6){\n moves.pb({'D', y});\n if(i % 2 == 0){\n moves.pb({'L', x});\n } else{\n moves.pb({'R', x});\n }\n }\n moves.pb({'D', y});\n } else{\n F0R(i, 6){\n moves.pb({'R', x});\n if(i % 2 == 0){\n moves.pb({'U', y});\n } else{\n moves.pb({'D', y});\n }\n }\n moves.pb({'R', x});\n }\n}\n\nint main(){\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n \n FOR(i, 1, 6){\n FOR(j, 1, 6){\n char c;\n cin >> c;\n if(c >= '0' && c <= '9'){\n gr[i][j] = c-'0';\n } else{\n gr[i][j] = 10+c-'A';\n }\n }\n }\n FOR(i, 1, 6){\n FOR(j, 1, 6){\n int v = 6*i+j-7;\n int ok = false;\n FOR(a, 1, 6){\n FOR(b, 1, 6){\n if(gr[a][b] == v){\n RFOR(c, b-1, j){\n swp(a, c, 1);\n swap(gr[a][c], gr[a][c+1]);\n }\n FOR(c, b, j-1){\n swp(a, c, 1);\n swap(gr[a][c], gr[a][c+1]);\n }\n RFOR(c, a-1, i){\n swp(c, j, 0);\n swap(gr[c][j], gr[c+1][j]);\n }\n ok = true;\n break;\n }\n }\n if(ok) break;\n }\n }\n }\n cout << moves.size() << \"\\n\";\n for(auto u : moves){\n cout << (char)u.f << u.s << \"\\n\";\n }\n\n return 0;\n}\n", "src_uid": "10b2c1c53580dd382c41a56f7413e709"} {"source_code": "#include \n\nusing namespace std;\n\ntemplate inline void Read(T &t)\n{\n\tint c=getchar(),f=0;\n\tfor (;c<'0'||c>'9';c=getchar()) f=(c=='-');\n\tfor (t=0;c>='0'&&c<='9';c=getchar()) t=(t<<3)+(t<<1)+(c^48);\n\tif (f) t=-t;\n}\n \ntypedef long long ll;\nconst int N=1e6+5;\nint n,k,prime[N],phi[N];\nbool inp[N]; // is not prime\n\nvoid get_prime()\n{\n\tinp[1]=true;\n\tphi[1]=1;\n\tfor (register int i=2;i<=n;i++)\n\t{\n\t\tif (!inp[i]) prime[++prime[0]]=i,phi[i]=i-1;\n\t\tfor (register int j=1;j<=prime[0]&&i*prime[j]<=n;j++)\n\t\t{\n\t\t\tinp[prime[j]*i]=true;\n\t\t\tif (i%prime[j]==0) { phi[prime[j]*i]=prime[j]*phi[i]; break; } \n\t\t\tphi[prime[j]*i]=phi[prime[j]]*phi[i];\n\t\t}\n\t}\n}\n\nint main()\n{\n\tRead(n),Read(k);\n\tget_prime();\n\tsort(phi+3,phi+n+1);\n\tlong long res=0;\n\tfor (int i=1;i<=k;i++) res+=phi[i+2];\n\tprintf(\"%lld\\n\",res+2-(k==1));\n\treturn 0;\n}", "src_uid": "c2f7012082c84d773c2f4b1858c17110"} {"source_code": "#include\nusing namespace std;\n#define endl '\\n'\nmain()\n{\n int n,x,k,cnt=0,i,j,s,t;\n cin>>n>>x;\n int a[n+1];\n for(i=0;i>a[i];\n if(a[i]==x)\n cnt++;\n }\n sort(a,a+n);\n\n for(s=0;s\r\nusing namespace std;\r\n\r\ntypedef long long ll;\r\nconst ll INF = 1e9+7;\r\n\r\nll power(ll a,ll b,ll mod){\r\n if(b == 0){\r\n return 1;\r\n }\r\n ll ans = power(a,b/2,mod);\r\n ans *= ans;\r\n ans %= mod;\r\n if(b % 2){\r\n ans *= a;\r\n }\r\n return ans % mod;\r\n}\r\nint main(void){\r\n ios_base::sync_with_stdio(0);\r\n cin.tie(0);\r\n ll k;\r\n cin>>k;\r\n ll othernodes = (1LL<\n#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 vd vector\n#define all(v) v.begin(), v.end()\n\n\n#define mp make_pair\n#define pb push_back\n#define forn(i, l) for (int i = 0; i < l; i++)\n\nusing namespace std;\ntypedef pair pi;\ntypedef complex cd;\ntypedef long double ld;\ntypedef vector vi;\ntypedef pair pd;\ntypedef long long li;\nconst int N = 2096;\nconst ld eps = 0.2, eps2 = 0.0001;\nconst int INF = (int)1e9 + 7, MOD = INF;\nconst long long LINF = 1e16;\nconst double PI = acos(-1.0);\n\nli a, b;\nvector x, y, ans;\nmultiset sx, sy;\n\nvoid get(li n, vector &v, multiset &s) {\n\twhile (n > 0) {\n\t\tv.pb(n % 10);\n\t\ts.insert(-v.back());\n\t\tn /= 10;\n\t}\n}\n\nvoid printmax() {\n\tfor (auto it = sx.rbegin(); it != sx.rend(); it++) {\n\t\tans.pb(-(*it));\n\t}\n}\n\nbool rec(int pos) {\n\tif (pos == x.size() - 1) {\n\t\tif (*(sx.begin()) >= -y[pos]) {\n\t\t\tprintmax();\n\t\t\treturn 1;\n\t\t} else {\n\t\t\treturn 0;\n\t\t}\n\t}\n\tauto it2 = sx.lower_bound(-y[pos]);\n\tif (it2 != sx.end() && *(it2) == -y[pos]) {\n\t\tsx.erase(it2);\n\t\tif (rec(pos + 1)) {\n\t\t\tans.pb(y[pos]);\n\t\t\treturn 1;\n\t\t} else {\n\t\t\tsx.insert(-y[pos]);\n\t\t}\n\t}\n\tauto it1 = sx.upper_bound(-y[pos]);\n\tif (it1 != sx.end()) {\n\t\tint u = (-(*it1));\n\t\tsx.erase(it1);\n\t\tprintmax();\n\t\tans.pb(u);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nint main() {\n#ifdef _DEBUG\n\tfreopen(\"in.txt\", \"r\", stdin);\n\tfreopen(\"out.txt\", \"w\", stdout);\n#endif\n\tcin >> a >> b;\n\tget(a, x, sx), get(b, y, sy);\n\treverse(all(x)), reverse(all(y));\n\tif (x.size() < y.size()) {\n\t\tprintmax();\n\t} else {\n\t\trec(0);\n\t}\n\tforn(i, ans.size()) {\n\t\tcout << ans[ans.size() - 1 - i];\n\t}\n}", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"source_code": "#include \n#include \nusing namespace std;\n\nlong long int a[26];\n\nvoid bsort(int n) {\n while (true) {\n bool trocou = false;\n for (int i = 0; i < n - 1; i++) {\n if (a[i] > a[i + 1]) {\n int temp = a[i];\n a[i] = a[i + 1];\n a[i + 1] = temp;\n trocou = true;\n }\n }\n if (!trocou) break;\n }\n}\n\nint main() {\n int n;\n\n scanf(\"%d\", &n);\n\n for (int i = 0; i < n; i++) {\n scanf(\"%I64d\", &a[i]);\n }\n\n bsort(n);\n\n long long int sum = a[n - 1];\n long long int l = a[n - 1];\n for (int i = n - 2; i >= 0; i--) {\n //printf(\"l === %I64d\\n\", l);\n //printf(\"sum === %I64d\\n\", sum);\n //printf(\"a === %I64d\\n\", a[i]);\n if (l == 0) break;\n if (a[i] == a[i + 1]) {\n l--;\n sum += l;\n } else {\n if (a[i] >= l) {\n l--;\n sum += l;\n }\n else {\n sum += a[i];\n l = a[i];\n }\n }\n }\n\n printf(\"%I64d\", sum);\n\n return 0;\n}\n", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"source_code": "#include \nusing namespace std;\n\nint main () \n{\n int a,b,c;\n cin>>a>>b>>c;\n int m;\n m=0;\n if (a+b*c>m) m=a+b*c;\n if (a*(b+c)>m) m=a*(b+c);\n if (a*b*c>m) m=a*b*c;\n if((a+b)*c>m) m=(a+b)*c;\n if(a+b+c>m) m=a+b+c;\n cout<\n#define ll long long\n#define ull unsigned ll\n#define uint unsigned\n#define pii pair\n#define pll pair\n#define PB push_back\n#define fi first\n#define se second\n#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)\n#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)\n#define CLR(a,v) memset(a,v,sizeof(a));\n#define CPY(a,b) memcpy(a,b,sizeof(a));\nusing namespace std;\nconst int N=100005;\nint n,m,deg[N],fa[N];\nll val[N],v[N],dif[N];\nstruct ZKW{\n\tll mn[N*4],mx[N*4];\n\tint nn;\n\tvoid build(int n){\n\t\tfor (nn=1;nn<=n+1;nn<<=1);\n\t\tFor(i,0,2*nn-1)\tmn[i]=1ll<<60,mx[i]=-(1ll<<60);\n\t}\n\tvoid change(int x,ll v1,ll v2){\n\t\tx+=nn;\n\t\tmn[x]=v1; mx[x]=v2;\n\t\tfor (x>>=1;x;x>>=1){\n\t\t\tmn[x]=min(mn[x<<1],mn[x<<1|1]);\n\t\t\tmx[x]=max(mx[x<<1],mx[x<<1|1]);\n\t\t}\n\t}\n}ANS;\nstruct HEAP{\n\tpriority_queue Q1,Q2,Q3,Q4;\n\tvoid push(int x){\n\t\tQ1.push(pll(val[x],x));\n\t\tQ3.push(pll(-val[x],x));\n\t}\n\tvoid erase(int x){\n\t\tQ2.push(pll(val[x],x));\n\t\tQ4.push(pll(-val[x],x));\n\t}\n\tll askmx(){\n\t\tfor (;!Q1.empty()&&!Q2.empty()&&Q1.top()==Q2.top();) Q1.pop(),Q2.pop();\n\t\treturn Q1.empty()?-(1ll<<60):Q1.top().fi;\n\t}\n\tll askmn(){\n\t\tfor (;!Q3.empty()&&!Q4.empty()&&Q3.top()==Q4.top();) Q3.pop(),Q4.pop();\n\t\treturn Q3.empty()?1ll<<60:-Q3.top().fi;\n\t}\n}Q[N];\nvoid update(int x){\n\tANS.change(x,Q[x].askmn()+dif[x],Q[x].askmx()+dif[x]);\n}\nvoid erase(int x){\n\tint y=fa[x],z=fa[y];\n\tQ[y].erase(x);\n\tQ[z].erase(y);\n\tQ[fa[z]].erase(z);\n\tval[z]-=dif[y]; val[y]-=dif[x];\n\tval[y]-=v[y]-dif[y]*(deg[y]-1);\n\tval[x]-=v[x]-dif[x]*(deg[x]-1);\n\t--deg[x]; --deg[y];\n\tdif[x]=v[x]/deg[x];\n\tdif[y]=v[y]/deg[y];\n\tval[y]+=v[y]-dif[y]*(deg[y]-1);\n\tval[x]+=v[x]-dif[x]*(deg[x]-1);\n\tval[z]+=dif[y];\n\tQ[z].push(y);\n\tQ[fa[z]].push(z);\n\tupdate(x);\n\tupdate(y);\n\tupdate(z);\n\tupdate(fa[z]);\n}\nvoid insert(int x){\n\tint y=fa[x],z=fa[y];\n\tQ[z].erase(y);\n\tQ[fa[z]].erase(z);\n\tval[z]-=dif[y];\n\tval[y]-=v[y]-dif[y]*(deg[y]-1);\n\tval[x]-=v[x]-dif[x]*(deg[x]-1);\n\t++deg[x]; ++deg[y];\n\tdif[x]=v[x]/deg[x];\n\tdif[y]=v[y]/deg[y];\n\tval[y]+=v[y]-dif[y]*(deg[y]-1);\n\tval[x]+=v[x]-dif[x]*(deg[x]-1);\n\tval[z]+=dif[y]; val[y]+=dif[x];\n\tQ[y].push(x);\n\tQ[z].push(y);\n\tQ[fa[z]].push(z);\n\tupdate(x);\n\tupdate(y);\n\tupdate(z);\n\tupdate(fa[z]);\n}\nint main(){\n\t//freopen(\"1.in\",\"r\",stdin);\n\tscanf(\"%d%d\",&n,&m);\n\tFor(i,1,n) deg[i]=2;\n\tFor(i,1,n) scanf(\"%lld\",&v[i]);\n\tFor(i,1,n) scanf(\"%d\",&fa[i]),++deg[fa[i]];\n\tFor(i,1,n){\n\t\tval[i]+=v[i]-v[i]/deg[i]*(deg[i]-1);\n\t\tval[fa[i]]+=v[i]/deg[i];\n\t\tdif[i]=v[i]/deg[i];\n\t}\n\tANS.build(n);\n\tFor(i,1,n) Q[fa[i]].push(i);\n\tFor(i,1,n) update(i);\n\twhile (m--){\n\t\t//printf(\"%d \",m);\n\t\tint tp,x;\n\t\tscanf(\"%d\",&tp);\n\t\tif (tp==1){\n\t\t\tint x;\n\t\t\tscanf(\"%d\",&x);\n\t\t\terase(x);\n\t\t\tscanf(\"%d\",&fa[x]);\n\t\t\tinsert(x);\n\t\t}\n\t\telse if (tp==2){\n\t\t\tscanf(\"%d\",&x);\n\t\t\tprintf(\"%lld\\n\",val[x]+dif[fa[x]]);\n\t\t}\n\t\telse\n\t\t\tprintf(\"%lld %lld\\n\",ANS.mn[1],ANS.mx[1]);\n\t}\n}\n/*\n儿子\n自己\n爹\n*/", "src_uid": "6a17d93dad158f70a36905206aa0ba3b"} {"source_code": "#include \n\nusing namespace std;\n\nint main() {\n\tint l, r, a, answer = 0;\n\n\tcin >> l >> r >> a;\n\t\n\tif (l == r) {\n\t\tanswer += 2 * l;\n\t\tanswer += 2 * (a / 2);\n\t}\n\telse {\n\t\tif (l < r) {\n\t\t\tanswer += 2 * l;\n\t\t\tr -= l;\n\t\t\tif (a == r) {\n\t\t\t\tanswer += 2 * a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (a < r) {\n\t\t\t\t\tanswer += 2 * a;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tanswer += 2 * r;\n\t\t\t\t\ta -= r;\n\t\t\t\t\tanswer += 2 * (a / 2);\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\telse {\n\t\t\tanswer += 2 * r;\n\t\t\tl -= r;\n\t\t\tif (a == l) {\n\t\t\t\tanswer += 2 * a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (a < l) {\n\t\t\t\t\tanswer += 2 * a;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tanswer += 2 * l;\n\t\t\t\t\ta -= l;\n\t\t\t\t\tanswer += 2 * (a / 2);\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t}\n\t\n\n\tcout << answer;\n\treturn 0;\n}", "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#define endl '\\n'\nusing namespace std;\n\nconst int MAXN = 100000;\n\nbool used[MAXN + 5];\nint a[MAXN + 5], b[MAXN + 5];\nlong double c[MAXN + 5];\nvector< pair > G[MAXN + 5];\n\nbool BFS(int u)\n{\n vector checked;\n queue q;\n used[u] = true;\n a[u] = 0;\n b[u] = 1;\n checked.push_back(u);\n q.push(u);\n \n bool flag = false;\n long double d;\n while (!q.empty())\n {\n u = q.front();\n q.pop();\n for (int i = 0; i < G[u].size(); ++ i)\n {\n int v = G[u][i].first;\n int w = G[u][i].second;\n if (!used[v])\n {\n used[v] = true;\n a[v] = w - a[u];\n b[v] = -b[u];\n checked.push_back(v);\n q.push(v);\n }\n else\n {\n if (b[u] != b[v])\n {\n if (a[u] + a[v] != w) return false;\n }\n else\n {\n long double x = 1.0 * (w - (a[u] + a[v])) / (b[u] + b[v]);\n if (!flag)\n {\n d = x;\n flag = true;\n }\n else\n {\n if (d != x) return false;\n }\n }\n }\n }\n }\n \n if (flag)\n {\n int s = checked.size();\n for (int i = 0; i < s; ++ i)\n {\n u = checked[i];\n c[u] = 1.0 * a[u] + d * b[u];\n }\n }\n else\n {\n int s = checked.size();\n d = -100.0;\n long double sum1 = 1000000.0 * s, dd = 0.0;\n while (d <= 100.0)\n {\n long double sum2 = 0.0;\n for (int i = 0; i < s; ++ i)\n {\n u = checked[i];\n sum2 += fabs(1.0 * a[u] + d * b[u]);\n }\n if (sum2 < sum1)\n {\n sum1 = sum2;\n dd = d;\n }\n d += 0.5;\n }\n \n for (int i = 0; i < s; ++ i)\n {\n u = checked[i];\n c[u] = 1.0 * a[u] + dd * b[u];\n }\n }\n \n return true;\n}\n\nint main()\n{\n ios :: sync_with_stdio(false);\n cin.tie(NULL); cout.tie(NULL);\n \n int N, M;\n cin >> N >> M;\n \n for (int i = 1; i <= M; ++ i)\n {\n int u, v, w;\n cin >> u >> v >> w;\n G[u].push_back(make_pair(v, w));\n G[v].push_back(make_pair(u, w));\n }\n \n bool flag = true;\n for (int i = 1; i <= N; ++ i)\n {\n if (!used[i])\n {\n flag = (flag & BFS(i));\n }\n }\n \n if (flag)\n {\n cout << \"YES\" << endl;\n for (int i = 1; i <= N; ++ i)\n {\n cout << c[i] << \" \";\n }\n cout << endl;\n }\n else cout << \"NO\" << endl;\n \n return 0;\n}", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8"} {"source_code": "//Sasayego! Sasayego! Shinzou wo Sasageyo!\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#define debug(x) cerr << #x << \" = \" << x << endl\n#define lid (id << 1)\n#define rid (lid ^ 1)\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef pair pll;\ntypedef pair pii;\n\nconst int maxN = 3e5 + 5;\nconst int SQ = 550;\nconst ll INF = 1e18;\nconst ll MOD = 1e9 + 7;\n\nbool flag;\nint l[maxN], pt[maxN];\nvector P[maxN];\nvector Q[maxN];\n\nint main(){\n\ttime_t START = clock();\n\tios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n\tint T; scanf(\"%d\", &T);\n\twhile (T--){\n\t\tint n, q; scanf(\"%d%d\", &n, &q);\n\t\tflag = false;\n\t\tfor (int i = 0; i < q; i++){\n\t\t\tscanf(\"%d\", l + i);\n\t\t\tfor (int inp, j = 0; j < l[i]; j++){\n\t\t\t\tscanf(\"%d\", &inp);\n\t\t\t\tP[i].push_back(inp);\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < q; i++){\n\t\t\tif (l[i] >= SQ){\n\t\t\t\tmemset(pt, -1, sizeof pt);\n\t\t\t\tfor (int j = 0; j < l[i]; j++)\n\t\t\t\t\tpt[P[i][j]] = j;\n\t\t\t\tfor (int j = 0; j < q; j++)\n\t\t\t\t\tif (l[j] <= SQ || j > i){\n\t\t\t\t\t\tint mx = 0;\n\t\t\t\t\t\tfor (int k = l[j] - 1; k > -1; k--){\n\t\t\t\t\t\t\tif (pt[P[j][k]] != -1 && mx > pt[P[j][k]] && P[j][k + 1] != P[i][pt[P[j][k]] + 1])\n\t\t\t\t\t\t\t\tflag = true;\n\t\t\t\t\t\t\tmx = max(mx, pt[P[j][k]]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t\tfor (int lt = 0; lt < l[i]; lt++)\n\t\t\t\t\tfor (int rt = lt + 1; rt < l[i]; rt++)\n\t\t\t\t\t\tQ[P[i][lt]].push_back({P[i][rt], P[i][lt + 1]});\n\t\t}\n\t\tmemset(pt, -1, sizeof pt);\n\t\tfor (int i = 1; i <= n; i++){\n\t\t\tfor (pii pp : Q[i]){\n\t\t\t\tif (pt[pp.first] != -1 && pt[pp.first] != pp.second)\n\t\t\t\t\tflag = true;\n\t\t\t\tpt[pp.first] = pp.second;\n\t\t\t}\n\t\t\tfor (pii pp : Q[i])\n\t\t\t\tpt[pp.first] = -1;\n\t\t}\n\t\tprintf(flag ? \"Human\\n\" : \"Robot\\n\");\n\t\tfor (int i = 0; i <= max(q, n); i++){\n\t\t\tP[i].clear();\n\t\t\tQ[i].clear();\n\t\t}\n\t}\n\ttime_t FINISH = clock();\n\tcerr << \"Execution time: \" << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << \" milliseconds.\\n\";\n\treturn 0;\n}\n \n\n", "src_uid": "d742933184ce1cad098fcb8a264df630"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nchar a[105],b[105];\nint main()\n{\n\twhile(~scanf(\"%s%s\",a,b))\n\t{\n\t if(strcmp(a,b)==0)\n\t printf(\"%s\\n\",a);\n\t else\n\t printf(\"1\\n\");\n\t}\n\treturn 0;\n}\n", "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"source_code": "#include\r\n#define sz 200002\r\n\r\n#define pb push_back\r\n#define ff first\r\n#define ss second\r\n#define ll unsigned long long\r\n#define pi pair\r\n#define PQ priority_queue, greater >q\r\n#define _sort(v) sort(v.begin(),v.end())\r\n#define MP mapmp\r\n#define MEM(x) memset(x,-1,sizeof(x))\r\n#define FOR(i,a,b) for(int i=(a);i<(b);++i)\r\n#define vec() vectorv1,v2\r\n#define CASE cout<<\"Case \"<<++cs<<\": \"\r\n#define VEC(n) ll int x; vectorv;for(int i=0;i>x;v.pb(x);}\r\n#define TEST() int test;cin>>test; while(test--)\r\n#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)\r\n\r\nusing namespace std;\r\n//Upper_bound auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;\r\n//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}\r\n//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}\r\n//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}\r\n//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}\r\n//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else { c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}\r\n//int pos;string mul(int n) {string s;for(int i=0; i=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;} reverse(s.begin(),s.end());return s;}\r\n//ll int pre[1000020];string prefixPalindrome(string s){string a=s;reverse(s.begin(),s.end());a=a+\"@\"+s;ll int c=0;for(int i=1;iv,ll int x)\r\n{\r\n v.pb(x);\r\n ll int num=0;\r\n ll int pw=1;\r\n for(int i=0;iv;\r\n if(mp[x])return;\r\n\r\nmp[x]++;\r\nif(x==n){res=\"YES\";return;}\r\n\r\n while(x)\r\n {\r\n v.pb(x%2);\r\n x/=2;\r\n\r\n }\r\n reverse(v.begin(),v.end());\r\n if(cnt>100000)return;\r\n ll int a,b;\r\n\r\n a=check(v,0);\r\n b=check(v,1);\r\n\r\n\r\n fun(a);\r\n fun(b);\r\n\r\n\r\n\r\n}\r\nint main()\r\n{\r\n cin>>m>>n;\r\n ll int nn=n;\r\n\r\n while(nn)len++,nn/=2;\r\n\r\n\r\n fun(m);\r\n\r\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \ntypedef long long ll;\n#define all(a) a.begin(),a.end()\n#define pb(a,i) a.push_back(i)\n#define mem(a,b) memset(a,b,sizeof a)\nusing namespace std;\nint main()\n{\n //freopen(\"input.txt\",\"r\",stdin);\n //freopen(\"output.txt\",\"w\",stdout);\n int n,i,j,l=0,c=0;\n string s,t;\n cin>>s;\n cin>>t;\n for(i=0;i\nusing namespace std;\ntypedef long long ll;\nvoid Main();\n#ifdef ConanYu\n#include \"local.hpp\"\n#else\n#define debug(...) do { } while(0)\nint main() {\n ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);\n Main();\n}\n#endif\n\nbool dcmp(double x, double res) {\n if(fabs(x) < 1e-3 || fabs(res - x) < 1e-3) return true;\n return false;\n}\n\nstruct node {\n double x, y;\n} A, B, C;\n\nnode wx(const node &a, const node &b, const node &c) {\n double A1 = 2.0 * (b.x - a.x), B1 = 2.0 * (b.y - a.y), C1 = b.x * b.x + b.y * b.y - a.x * a.x - a.y * a.y;\n double A2 = 2.0 * (c.x - b.x), B2 = 2.0 * (c.y - b.y), C2 = c.x * c.x + c.y * c.y - b.x * b.x - b.y * b.y;\n return {(C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1), (A1 * C2 - A2 * C1) / (A1 * B2 - A2 * B1)};\n}\n\ndouble dis(const node &a, const node &b) {\n return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));\n}\n\ndouble deg(const node &o, const node &a, const node &b) {\n const double da = dis(b, o), db = dis(a, o), oo = dis(a, b);\n return acos((da * da + db * db - oo * oo) / (2.0 * da * db));\n}\n\nconst double PI = acos(-1.0);\n\ndouble Gcd(double d1, double d2, double d3) {\n double mn = d1;\n if(d2 < d1) {\n mn = d2;\n swap(d1, d2);\n }\n if(d3 < d1) {\n mn = d3;\n swap(d1, d3);\n }\n for(int i = 1; true; i++) {\n double res = mn / double(i);\n if(dcmp(fmod(d2, res), res) && dcmp(fmod(d3, res), res)) {\n return res;\n }\n }\n}\n\nvoid Main() {\n cin >> A.x >> A.y;\n cin >> B.x >> B.y;\n cin >> C.x >> C.y;\n node WX = wx(A, B, C);\n double d1 = deg(WX, A, B);\n double d2 = deg(WX, B, C);\n double d3 = 2.0 * PI - d1 - d2;\n double g = Gcd(d1, d2, d3);\n const double n = 2.0 * PI / g;\n double r = dis(WX, A);\n double S = 0.5 * r * r * sin(g) * n;\n cout << fixed << setprecision(10) << S << \"\\n\";\n}\n", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"} {"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\ntypedef long long LL;\ntypedef unsigned long long ULL;\n\n#define PI 3.1415926535897932384626433832795\n#define sqr(x) ((x)*(x))\n\nusing namespace std;\n\n#define N 1555\n\nLL xx[N], yy[N];\nvector g[N];\nint n, x, y;\nint was[N], w[N], p[N], ans[N];\n\nstruct Tp{\n\tint x, y, i;\n\n\tbool operator<(const Tp &B)const{\n\t\treturn x < B.x || x == B.x && y < B.y;\n\t}\n} a[N];\n\nclass AngleCompare {\n\tint cx, cy;\n\npublic:\n\tAngleCompare(int x, int y) : cx(x), cy(y) { };\n\n\tbool operator()(const Tp& A, const Tp& B) {\n//\t\tcerr << A.x << \" \" << A.y << \" vs \" << B.x << \" \" << B.y << \"\\t\\t\" << (LL(A.x - cx) * (B.y - cy) <= LL(B.x - cx) * (A.y - cy)) << endl;\n\t\treturn LL(A.x - cx) * (B.y - cy) <= LL(B.x - cx) * (A.y - cy);\n\t}\n};\n\n/*\nbool intersect(int p1, int p2, int p3, int p4) {\n\tif (p1 == p3 && p2 == p4 || p1 == p4 && p2 == p3) return true;\n\tif (p1 == p3 || p1 == p4 || p2 == p4 || p2 == p3) return false;\n\n\tLL a = yy[p2] - yy[p1];\n\tLL b = xx[p1] - xx[p2];\n\tLL c = -a * xx[p1] - b * yy[p1];\n\tLL t1 = a * xx[p3] + b * yy[p3] + c;\n\tLL t2 = a * xx[p4] + b * yy[p4] + c;\n\tif (t1 < 0 && t2 < 0 || t1 > 0 && t2 > 0) return false;\n\n\ta = yy[p4] - yy[p3];\n\tb = xx[p3] - xx[p4];\n\tc = -a * xx[p3] - b * yy[p3];\n\tt1 = a * xx[p1] + b * yy[p1] + c;\n\tt2 = a * xx[p2] + b * yy[p2] + c;\n\tif (t1 < 0 && t2 < 0 || t1 > 0 && t2 > 0) return false;\n\treturn true;\n}\n*/\n\nvoid dfs(int x) {\n\twas[x] = true;\n\tw[x] = 1;\n\tfor (int i = 0; i < g[x].size(); i++) {\n\t\tint y = g[x][i];\n\t\tif (!was[y]) {\n\t\t\tdfs(y);\n\t\t\tp[y] = x;\n\t\t\tw[x] += w[y];\n\t\t}\n\t}\n}\n\nvoid dfs2(int x, int l, int r) {\n\tsort(a + l + 1, a + r, AngleCompare(a[l].x, a[l].y));\n//\treturn;\n\n\tans[a[l].i] = x + 1;\n\n\tint off = 1;\n\tfor (int i = 0; i < g[x].size(); ++i) {\n\t\tint y = g[x][i];\n\t\tif (p[y] == x) {\n\t\t\tdfs2(y, l + off, l + off + w[y]);\n\t\t\toff += w[y];\n\t\t}\n\t}\n}\n\nint main() {\n//\tfreopen(\".in\", \"r\", stdin);\n//\tfreopen(\".out\", \"w\", stdout);\n\n\tcin >> n;\n\tfor (int i = 0; i < n - 1; i++) {\n\t\tcin >> x >> y;\n\t\tx--;\n\t\ty--;\n\t\tg[x].push_back(y);\n\t\tg[y].push_back(x);\n\t}\n\tfor (int i = 0; i < n; i++) {\n\t\tcin >> a[i].x >> a[i].y;\n\t\ta[i].i = i;\n\t}\n\tsort(a, a + n);\n\n\tdfs(0);\n\tdfs2(0, 0, n);\n\n\tfor (int i = 0; i < n; i++) cout << ans[i] << \" \";\n\tcout << endl;\n\n\treturn 0;\n}\n", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba"} {"source_code": "#include\nusing namespace std;\n#define ll long long\n#define int long long\nconst int N=2000000;\n\nll M,H1,A1,X1,Y1,H2,A2,X2,Y2,cnt,c1,c2,p1,p2,k1,x_1,y_1,p_1,p_2;\nll P1[N],P2[N],ans;\n\nint gcd(int x,int y)\n{\n\tif (!y) return x;\n\treturn gcd(y,x%y);\n}\n\nvoid exgcd(int x,int y)\n{\n\tif (!y) {x_1=1,y_1=0;return;}\n\texgcd(y,x%y);\n\tint x_2=x_1,y_2=y_1;\n\tx_1=y_2;y_1=((x_2-x/y*y_2)%p_2+p_2)%p_2;\n}\n\nint inv(int x,int y)\n{\n\texgcd(x,y);\n\treturn x_1;\n}\n\nsigned main()\n{\n\tcin>>M>>H1>>A1>>X1>>Y1>>H2>>A2>>X2>>Y2;\n\twhile (true)\n\t{\n\t\tH1=(H1*X1+Y1)%M;++cnt;\n\t\tif (P1[H1]&&H1==A1) {p1=cnt-P1[H1];c1=P1[H1];break;}\n\t\tP1[H1]=cnt;\n\t\tif (cnt==M*3) break;\n\t}\n\tcnt=0;\n\twhile (true)\n\t{\n\t\tH2=(H2*X2+Y2)%M;++cnt;\n\t\tif (P2[H2]&&H2==A2) {p2=cnt-P2[H2];c2=P2[H2];break;}\n\t\tP2[H2]=cnt;\n\t\tif (cnt==M*3) break;\n\t}\n//\tcout< \nusing namespace std;\nint main(){\n int n;\n cin >> n;\n cout << (2*n+1)/3;\n\n return 0;\n}", "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"source_code": "#include \nusing namespace std;\n\nusing ll = long long;\nconstexpr int maxn = 2e2 + 5;\nconstexpr int inf = 0x3f3f3f3f;\n\nint n, k;\nchar a[maxn], b[maxn];\nint dp[maxn][maxn][maxn]; // dp[i][j][k]表示前i位,用了j步,有k个b[1]\n\nint main() {\n#ifdef DEBUG\n freopen(\"test.in\", \"r\", stdin);\n freopen(\"test.out\", \"w\", stdout);\n#endif\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n cin >> n >> k;\n cin >> (a + 1) >> (b + 1);\n if (b[1] == b[2]) {\n int cnt = 0;\n for (int i = 1; i <= n; i++) cnt += a[i] == b[1];\n cnt += k;\n cnt = min(cnt, n);\n cout << cnt * (cnt - 1) / 2 << \"\\n\";\n return 0;\n }\n for (int i = 0; i <= n; ++i)\n for (int j = 0; j <= n; ++j) fill(dp[i][j], dp[i][j] + n + 1, -inf);\n dp[0][0][0] = 0;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n for (int k = 0; k <= n; k++) {\n dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);\n dp[i][j + (a[i] != b[1])][k + 1] =\n max(dp[i][j + (a[i] != b[1])][k + 1], dp[i - 1][j][k]);\n dp[i][j + (a[i] != b[2])][k] =\n max(dp[i][j + (a[i] != b[2])][k], dp[i - 1][j][k] + k);\n }\n }\n }\n int ans = 0;\n for (int i = 1; i <= n; ++i)\n for (int j = 0; j <= k; ++j)\n ans = max(ans, *max_element(dp[i][j], dp[i][j] + n + 1));\n cout << ans << '\\n';\n\n return 0;\n}", "src_uid": "9c700390ac13942cbde7c3428965b18a"} {"source_code": "#include\n#include\n#include\nusing namespace std;\nint main()\n{\n int n,x=0,y=0,s=0;\n cin>>n;\n int w[n];\n for(int i=0;i>w[i];\n if(w[i]==100)\n {\n x++;\n s+=w[i];\n }\n else {\n y++;\n s+=w[i];\n }\n }\n\n if(n==1||(x==1&&y==1))\n {\n cout<<\"NO\";\n return 0;\n }\n if ((x==y*2||(x%2==0&&y%2==0)||(y%2!=0&&x%2==0&&x!=0)||(x==y&&x%2==0&&y%2==0)))\n {\n cout<<\"YES\";\n }\n else cout<<\"NO\";\n}", "src_uid": "9679acef82356004e47b1118f8fc836a"} {"source_code": "#include\nusing namespace std;\nconst int max_n = 50+5;\nconst int max_e = 55*100;\n\nint n,m,pi;\nint f[max_n],r[max_n];\ndouble p[max_n];\ndouble dp[max_n][max_e];\n\nbool check(double init) {\n double t1 , t2;\n for(int i = n-1;i >= 0; --i) {\n for(int j = m + 1;j < max_e; ++j) dp[i + 1][j] = init;\n for(int j = 0;j <= m; ++j) {\n t1 = (dp[i + 1][j + f[i]] + f[i]) * p[i];\n t2 = (dp[i + 1][j + r[i]] + r[i]) * (1 - p[i]);\n dp[i][j] = min(init , t1 + t2);\n }\n }\n return dp[0][0] < init;\n}\n\nvoid solve() {\n double li = 0.0 , ri = 1e10 , mid;\n for(int i = 1;i <= 100; ++i) {\n mid = (li + ri) / 2.0;\n if(check(mid)) ri = mid;\n else li = mid;\n }\n printf(\"%.8f\\n\",ri);\n}\n\nint main() {\n scanf(\"%d%d\",&n,&m);\n for(int i = 0;i < n; ++i) {\n scanf(\"%d%d%d\",&f[i],&r[i],&pi);\n p[i] = pi / 100.0;\n }\n solve();\n return 0;\n}", "src_uid": "b461bb51eab4ff8088460c1980dacb93"} {"source_code": "#include \nusing namespace std;\nlong long n;\nmain(){\n\tcin>>n;\n\tif(n%2==0) {cout<<\"2\";} else cout<<\"1\";\n}\n", "src_uid": "816ec4cd9736f3113333ef05405b8e81"} {"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 \nusing namespace std;\n#define all(v) v.begin(),v.end()\ntypedef long long int ll;\ntypedef long double lld;\nconst long double PI = 4*atan(1);\n\n\nvoid solve()\n{\n\tint x; cin>>x;\n\tcout<>t;\n while(t--)\n solve();\n \n return 0;\n}\n", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"} {"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\nusing namespace std;\n\n#define ll long long\n#define pi pair\n#define pll pair\n#define pii pair\n#define X first\n#define Y second\n#define pb push_back\n#define ab(x) ((x)<0?(-(x)):(x))\n#define xx(x) ((x)*(x))\n#define mp make_pair\n#define vi vector\n#define vll vector\n#define vs vector\n#define vpi vector\n#define vpll vector\n#define ALL(x) (x).begin(),(x).end()\n#define Max (1<<30)\n#define LLMax (1ll<<60)\ntemplatestring ToString(T t){stringstream s;s<void ToOther(T&t,string a){stringstream s(a);s>>t;}\n\n\nint n,V,m;\nint a[333];\nint b[333];\nbool g[333][333];\nbool ck[333];\n\nvi t;\nvi v[555];\n\nvi r1,r2,r3;\nvi rr,rv;\n\nvoid dfs(int x){\n\tck[x]=1;\n\tt.pb(x);\n\tfor(int i=0;i A1,A2;\n\tqueue B1,B2;\n\tint tot=0;\n\tfor(int i=0;i0)A1.push(k),A2.push(dif);\n\t\tif(dif<0)B1.push(k),B2.push(-dif);\n\n\t}\n\tif(tot!=0)return 0;\n\n\twhile(A1.size()){\n\t\tint &k=A1.front();\n\t\tint &S=A2.front();\n\n\t\tif(B1.size()==0)break;\n\n\t\twhile(S && B1.size()){\n\t\t\tint &tar=B1.front();\n\t\t\tint &S2=B2.front();\n\n\t\t\tint can=min(S,S2);\n\n\t\t\trr.clear();\n\t\t\trv.clear();\n\n\t\t\tflow(-1,k,tar,can);\n\t\t\treverse(ALL(rr));\n\n\t\t\tint N=rr.size();\n\t\t\t\n\t\t\twhile(1){\n\t\t\t\tbool end=1;\n\t\t\t\tfor(int i=0;in*n*2)while(1);\n\t\t\t\t}\n\t\t\t\tif(end)break;\n\t\t\t}\n\n\t\t\tS-=can;\n\t\t\tS2-=can;\n\n\t\t\tif(S2==0)B1.pop(),B2.pop();\n\t\t}\n\t\tif(S==0)A1.pop(),A2.pop();\n\t}\n\n}\nint main(){\n\tcin>>n>>V>>m;\n\tfor(int i=0;i\r\nusing namespace std;\r\n\r\n#define int long long\r\n#define ld long double\r\n#define ff first\r\n#define ss second\r\n#define MOD 1000000007\r\n#define pb push_back\r\n#define sz(x) x.size();\r\n#define all(x) x.begin(), x.end()\r\n#define allrev(x) x.rbegin(), x.rend()\r\n#define vi vector\r\n#define vvi vector>\r\n#define umii unordered_map\r\n#define mpb make_pair\r\n\r\nvoid printv(vector a)\r\n{\r\n for (int i = 0; i < a.size(); i++)\r\n cout << a[i] << ' ';\r\n cout << endl;\r\n}\r\nvoid take(vector &a, int n)\r\n{\r\n for (int i = 0; i < n; i++)\r\n {\r\n int x;\r\n cin >> x;\r\n a.pb(x);\r\n }\r\n}\r\nvoid solve()\r\n{\r\n int n;\r\n cin >> n;\r\n // if (n == 1)\r\n // {\r\n // cout << 1 << endl;\r\n // return;\r\n // }\r\n // if (n == 2)\r\n // {\r\n // cout << 3 << endl;\r\n // return;\r\n // }\r\n // if (n == 3)\r\n // {\r\n // cout << 7 << endl;\r\n // return;\r\n // }\r\n // if (n == 4)\r\n // {\r\n // cout << 15 << endl;\r\n // return;\r\n // }\r\n // long long x = 15, y;\r\n // long long z = pow(2, n);\r\n // for (long long i = 17; i < z; i += 2)\r\n // {\r\n // if ((i + i + 1) % 2 == 0)\r\n // {\r\n // y = i + 1;\r\n // x = max(y, x);\r\n // }\r\n // else\r\n // {\r\n // y = i;\r\n // x = max(y, x);\r\n // }\r\n // }\r\n long long ans = 1;\r\n for (int i = 0; i < n; i++)\r\n {\r\n ans *= 2;\r\n }\r\n cout << ans - 1 << endl;\r\n}\r\n\r\nint_fast32_t main()\r\n{\r\n int t;\r\n cin >> t;\r\n while (t--)\r\n solve();\r\n return 0;\r\n}", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"source_code": "#include \n#include \nusing namespace std;\n\nint main()\n{\n\tint x, y; \n\n cin >> x >> y;\n\tcout << min( (x + y) / 3 , min(x , y) );\n\t\n\treturn 0;\n}\n ", "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nint grassh(string s,int n,int k,int t,int p)\n{\n\tint i,a=0;\n\tif(p>t)\n\t{\n\t\tif(p-t >n>>k;\n cin>>s;\n\tint t=s.find('G');\n\tint p=s.find('T');\n\tgrassh(s,n,k,t,p);\n\t\n\treturn 0;\n}", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"source_code": "#include\r\n#define ll long long\r\n#define pll pair\r\n#define mp make_pair\r\n#define pb push_back\r\n#define fi first\r\n#define se second\r\n\r\nusing namespace std;\r\n\r\n#define LOCALIO \"C:/Users/admin/Documents/Code/freopen/\"\r\n\r\nmap Map;\r\nll req;\r\n\r\nll track(ll s, ll i)\r\n{\r\n // cout << s << \" \" << i << \"\\n\";\r\n if (s>=req)\r\n {\r\n // cout << s << \" \" << i << \" \" << req << \"\\n\";\r\n Map[s]=1;\r\n return 1;\r\n }\r\n ll x=Map[s];\r\n if (x!=0)\r\n return x;\r\n bool cnt[10]={};\r\n ll num=s;\r\n while (num>0)\r\n {\r\n cnt[num%10]=1;\r\n num/=10;\r\n }\r\n ll ans=LLONG_MAX-1;\r\n for (ll j=9; j>1; j--)\r\n {\r\n if (cnt[j])\r\n {\r\n ans=min(ans, track(s*j, i+1));\r\n }\r\n }\r\n // cout << s << \" \" << ans << \"\\n\";\r\n Map[s]=ans+1;\r\n return ans+1;\r\n}\r\n\r\nint main()\r\n{\r\n #ifdef LOCAL\r\n freopen( LOCALIO \"input.txt\",\"r\",stdin) ;\r\n freopen( LOCALIO \"output.txt\",\"w\",stdout) ;\r\n #endif\r\n\r\n ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);\r\n//\tfreopen(\"FIBONACCI.inp\",\"r\",stdin);\r\n//\tfreopen(\"FIBONACCI.out\",\"w\",stdout);\r\n ll n, x; cin >> n >> x;\r\n bool check=0;\r\n ll num=x;\r\n while (num>0)\r\n {\r\n if (num%10>1)\r\n {\r\n check=1;\r\n break;\r\n }\r\n num/=10;\r\n }\r\n if (check==0)\r\n cout << -1;\r\n else\r\n {\r\n req=1;\r\n for (ll i=1; i\n\nint main()\n{\n\tint a[3][3];\n\tint b[3][3];\n\tchar str[3][4];\n\tint i,j,k=0;\n\tfor(i=0;i<3;i++)\n\t{\n\t\tscanf(\"%s\",&str[i][0]);\n\t\tfor(j=0;j<3;j++)\n\t\t{\n\t\t\tif(str[i][j]=='.')\n\t\t\t\ta[i][j]=0;\n\t\t\telse\n\t\t\t\ta[i][j]=1;\n\t\n\t\t}\n\t}\n\tfor(i=0;i<3;i++)\n\t\tfor(j=0;j<3;j++)\n\t\t\tb[i][j]=a[2-i][2-j];\n\tfor(i=0;i<3;i++)\n\t{\n\t\tfor(j=0;j<3;j++)\n\t\t{\n\t\t\tif(b[i][j]!=a[i][j])\n\t\t\t{\n\t\t\t\tk=1;\n\t\t\t}\n\t\t}\n\t}\n\tif(k==1)\n\t\tprintf(\"NO\");\n\telse \n\t\tprintf(\"YES\");\n\treturn 0;\n}", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"source_code": "#include\n#define mp make_pair\n#define pb push_back\n#define x first\n#define y second\n#define sz(a) int(a.size())\n#define clr(a) memset(a,0,sizeof(a))\n#define all(a) a.begin(),a.end()\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\ntypedef pair pii;\ntypedef pair pli;\nconst int inf=1e9;\nconst ll Inf=1e18;\nconst int N=30;\nconst int mod=0;\nint gi() {\n\tint x=0,o=1;char ch=getchar();\n\twhile((ch<'0'||ch>'9')&&ch!='-') ch=getchar();\n\tif(ch=='-') o=-1,ch=getchar();\n\twhile(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();\n\treturn x*o;\n}\ntemplate bool chkmax(T &a,T b) { return a bool chkmin(T &a,T b) { return a>b?a=b,1:0; };\nint add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }\nint sub(int a,int b) { return a-b<0?a-b+mod:a-b; }\nvoid inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }\nvoid dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }\nint n,m,g[N][N];\nvector> ans;\npii operator+(pii a,pii b) \n{\n\treturn mp(a.x+b.x,a.y+b.y);\n}\npii operator-(pii a,pii b) \n{\n\treturn mp(a.x-b.x,a.y-b.y);\n}\npii rotate(pii a) \n{\n\treturn mp(a.y,-a.x);\n}\nvoid rot_cycle(vector v) \n{\n\tvector w;\n\tfor(pii p:v) w.pb(g[p.x][p.y]);\n\tans.pb(w);\n\tint pre=g[v.back().x][v.back().y];\n\tfor(int i=sz(v)-1;i;i--) g[v[i].x][v[i].y]=g[v[i-1].x][v[i-1].y];\n\tg[v[0].x][v[0].y]=pre;\n}\nint in(pii p) \n{\n\treturn 1<=p.x&&p.x<=n&&1<=p.y&&p.y<=m;\n}\nvoid ex_swap(pii a,pii b,pii d) \n{\n\tpii c=b+b-a,e=b+d-a,f=c+d-a;\n\trot_cycle({a,b,e,d});\n\trot_cycle({b,c,f,e});\n\trot_cycle({a,d,e,f,c,b});\n}\nvoid _swap(pii a,pii b) \n{\n\tpii c=b+b-a;\n\tif(!in(c)) swap(a,b);\n\tpii v=rotate(a-b),d=a+v;\n\tif(!in(d)) d=a-v;\n\tex_swap(a,b,d);\n}\nvoid move(int s) \n{\n\tpii to=mp((s-1)/m+1,(s-1)%m+1),fr;\n\tfor(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(g[i][j]==s) fr=mp(i,j);\n\twhile(fr.y>to.y) \n\t{\n\t\tif(fr.x+1<=n) rot_cycle({fr,fr+mp(0,-1),fr+mp(1,-1),fr+mp(1,0)});\n\t\telse if(fr.x-1>to.x) rot_cycle({fr,fr+mp(0,-1),fr+mp(-1,-1),fr+mp(-1,0)});\n\t\telse _swap(fr,fr+mp(0,-1));\n\t\t--fr.y;\n\t}\n\twhile(fr.yto.x) rot_cycle({fr,fr+mp(0,1),fr+mp(-1,1),fr+mp(-1,0)});\n\t\telse _swap(fr,fr+mp(0,1));\n\t\t++fr.y;\n\t}\n\twhile(fr.x>to.x) \n\t{\n\t\tif(fr.y+1<=m) rot_cycle({fr,fr+mp(-1,0),fr+mp(-1,1),fr+mp(0,1)});\n\t\telse _swap(fr,fr+mp(-1,0));\n\t\t--fr.x;\n\t}\n}\nint main()\n{\n\tn=gi(),m=gi();\n\tfor(int i=1;i<=n;i++) for(int j=1;j<=m;j++) g[i][j]=gi();\n\tfor(int i=1;i<=n*m;i++) move(i);\n\tprintf(\"%d\\n\",sz(ans));\n\tfor(auto x:ans) \n\t{\n\t\tprintf(\"%d \",sz(x));\n\t\tfor(auto y:x) printf(\"%d \",y);\n\t\tputs(\"\");\n\t}\n\treturn 0;\n}", "src_uid": "476afa2d8208ec933617c97637b65aff"} {"source_code": "#include \n\nusing namespace std;\n\ntypedef long long ll;\nconst int INF = 0x3f3f3f3f;\nconst int MAXN = 5e5 + 100;\nconst int MAXM = 3e3 + 10;\nconst double eps = 1e-5;\n\ntemplate < typename T > inline void read(T &x) {\n\tx = 0; T ff = 1, ch = getchar();\n\twhile(!isdigit(ch)) {\n\t\tif(ch == '-') ff = -1;\n\t\tch = getchar();\n\t}\n\twhile(isdigit(ch)) {\n\t\tx = (x << 1) + (x << 3) + (ch ^ 48);\n\t\tch = getchar();\n\t}\n\tx *= ff;\n}\n\ntemplate < typename T > inline void write(T x) {\n\tif(x == 0) {\n\t\tputchar('0');\n\t\treturn ; \n\t}\n\tif(x < 0) putchar('-'), x = -x;\n\tstatic T tot = 0, ch[30];\n\twhile(x) {\n\t\tch[++tot] = x % 10 + '0';\n\t\tx /= 10;\n\t}\n\twhile(tot) putchar(ch[tot--]);\n}\n\nint n, t;\ndouble p, ans, f[MAXM][MAXM];\n\nint main() {\n\tscanf(\"%d %lf %d\", &n, &p, &t);\n\tf[0][0] = 1;\n\tfor(int i = 1; i <= t; ++i) {\n\t\tf[0][i] = f[0][i - 1] * (1.0 - p);\n//\t\tprintf(\"f[0][%d] = %lf\\n\", i, f[0][i]);\n\t}\n\tfor (int i = 1; i <= n; ++i) {\n\t\tfor (int j = 1; j <= t; ++j) {\n\t\t\tif (i != n) f[i][j] = f[i][j - 1] * (1.0 - p);\n\t\t\telse f[i][j] = f[i][j - 1];\n\t\t\tf[i][j] += f[i - 1][j - 1] * p;\n//\t\t\tif(i == n) f[i][j] = f[i][j - 1];\n//\t\t\tprintf(\"f[%d][%d] = %lf\\n\", i, j, f[i][j]);\n\t\t}\n\t\tans += f[i][t] * i;\n\t}\n\tprintf(\"%lf\", ans);\n\treturn 0;\n}", "src_uid": "20873b1e802c7aa0e409d9f430516c1e"} {"source_code": "/** || By The Name of Allah, Who Created Me. || **/\n\n/**\n\t* Author : Farid ul Islam Chy.\n\t* ID : 1512020238.\n\t* Batch : 38th.\n\t* Semester : 4C(E).\n\t* Team : LU_AntiVirus.\n\n\t* Leading University, Sylhet.\n**/\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\nusing namespace std;\n\n#define ll \t\t long long int\n#define SS\t\t stringstream\n#define pb \t\t push_back\n#define ull \t\t unsigned long long int\n#define MII \t map \n#define MSI \t map \n#define MIS \t map \n#define MLI \t map \n#define MIL \t map \n#define MLL \t map \n#define VS \t vector n;\n#define VI \t vector n;\n#define VC \t vector n;\n#define ForA(n) \t for (int i=0; i0; i--)\n#define ForN(n) \t for (int i=1; i<=n; i++)\n#define ForN2(n) \t for (int j=1; j<=n; j++)\n#define ForN3(n) \t for (int k=1; k<=n; k++)\n#define ForD(m,n) \t for (int i=m; i<=n; i++)\n#define ForD2(m,n) \t for (int j=m; j<=n; j++)\n#define ForD3(m,n) \t for (int k=m; k<=n; k++)\n#define SortA(n,x) \t sort(n,n+x)\n#define SortS(s) \t sort(s.begin(), s.end())\n#define SortRS(s) \t sort(s.rbegin(), s.rend())\n#define Search(s) s.begin(), s.end()\n#define SortSG(n)\t sort(n.begin(), n.end(), greater())\n#define Cin(a)\t\t cin>>a\n#define GCin(a)\t\t getline(cin,a)\n#define Cin2(a,b)\t cin>>a>>b\n#define Cin3(a,b,c)\t cin>>a>>b>>c\n#define Cin4(a,b,c,d)\t cin>>a>>b>>c>>d\n#define PI \t\t 3.1415926535897932384626433832795l\n#define Ignore\t\t cin.ignore()\n\nint isprime(ll n){\n ll i;\n if(n==2) return 1;\n if(n%2==0) return 0;\n for(i=3;i<=sqrt(n);i+=2)\n if(n%i==0) return 0;\n return 1;\n}\n\nbool cmp(string i,string j){\n return i+j=5&&sum==4)?\"Correct\":\"Too weak\") <\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint mp[200001];\nint main()\n{\n long long n,ans=0,qianfu,guodao,zuo;\n char c;\n scanf(\"%lld%c\",&n,&c);\n qianfu=(n-1)/4;\n qianfu*=2;\n if(n%4==2||n%4==0)\n qianfu++;\n if(n%4==1||n%4==2)\n guodao=n-1;\n else\n guodao=n-3;\n if(c=='f')\n zuo=1;\n if(c=='e')\n zuo=2;\n if(c=='d')\n zuo=3;\n if(c=='a')\n zuo=4;\n if(c=='b')\n zuo=5;\n if(c=='c')\n zuo=6;\n ans=qianfu*6+guodao+zuo;\n printf(\"%lld\\n\",ans);\n return 0;\n}\n\n\t\t\t \t \t\t\t \t\t\t\t\t \t\t\t\t\t \t \t\t", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"source_code": "/**\n * code generated by JHelper\n * More info: https://github.com/AlexeyDmitriev/JHelper\n * @author majk\n */\n\n#ifndef MAJK_LIB\n#define MAJK_LIB\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 \nusing namespace std;\n\n#define x first\n#define y second\ntypedef std::pair pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair puu;\n\ntemplate std::istream&operator>>(std::istream&i, pair&p) {i >> p.x >> p.y; return i;}\ntemplatestd::istream&operator>>(std::istream&i,vector&t) {for(auto&v:t){i>>v;}return i;}\ntemplatestd::ostream&operator<<(std::ostream&o,const vector&t) {if(t.empty())o<<'\\n';for(size_t i=0;i std::ostream&operator<<(std::ostream&o, pair&p) {o << p.x << ' ' << p.y; return o;}\ntemplate using minheap = priority_queue, greater>;\ntemplate using maxheap = priority_queue, less>;\ntemplate bool in(T a, T b, T c) { return a <= b && b < c; }\nui logceil(int x) { return 8*sizeof(int)-__builtin_clz(x); }\n\nnamespace std {\n templatestruct hash>{hasht;hashu;size_t operator()(const pair&p)const{return t(p.x)^(u(p.y)<<7);}};\n}\ntemplateT bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}\ntemplate double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}\ntemplateT bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}\ntemplate double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}\ntemplate T gcd(T a,T b) { if (aclass vector2:public vector>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector>(a,vector(b,t)){}};\ntemplateclass vector3:public vector>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector>(a,vector2(b,c,t)){}};\ntemplateclass vector4:public vector>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector>(a,vector3(b,c,d,t)){}};\ntemplateclass vector5:public vector>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector>(a,vector4(b,c,d,e,t)){}};\ntemplate struct bounded_priority_queue {\n\tinline bounded_priority_queue(ui X) : A(X), B(0), s(0) {}\n\tinline void push(ui L, T V) { B = max(B, L); A[L].push(V); ++s; }\n\tinline const T &top() const { return A[B].front(); }\n\tinline void pop() { --s; A[B].pop(); while (B > 0 && A[B].empty()) --B; }\n\tinline bool empty() const { return A[B].empty(); }\n\tinline void clear() { s = B = 0; for (auto &a: A) a = queue(); }\n\tinline ui size() const { return s; }\nprivate:\n\tvector> A; ui B; int s;\n};\n\n\n#endif\n#ifndef MOD_H\n#define MOD_H\n\n\n\ntemplate class Field {\n typedef unsigned int ui;\n typedef unsigned long long ull;\n\tinline ui pow(ui a, ui p){ui r=1,e=a;while(p){if(p&1){r=((ull)r*e)%N;}e=((ull)e*e)%N;p>>=1;}return r;}\n\t/*extended GCD(slow):ll t=0,nt=1,r=N,nr=a;while(nr){ll q=r/nr;t-=q*nt;swap(t,nt);r-=q*nr;swap(r,nr);}assert(r<=1);return(t<0)?t+N:t;*/\n\tinline ui inv(ui a){return pow(a,N-2);}\npublic:\n inline Field(int x = 0) : v(x) {}\n\tinline Field pow(int p){return (*this)^p; }\n\tinline Field operator^(int p){return {(int)pow(v,(ui)p)};}\n inline Field&operator+=(const Field&o) {if ((ll)v+o.v >= N) v = (ll)v+o.v-N; else v = v+o.v; return *this; }\n inline Field&operator-=(const Field&o) {if (v&operator*=(const Field&o) {v=(ull)v*o.v % N; return *this; }\n inline Field&operator/=(const Field&o) { return *this*=inv(o.v); }\n inline Field operator+(const Field&o) const {Fieldr{*this};return r+=o;}\n inline Field operator-(const Field&o) const {Fieldr{*this};return r-=o;}\n inline Field operator*(const Field&o) const {Fieldr{*this};return r*=o;}\n inline Field operator/(const Field&o) const {Fieldr{*this};return r/=o;}\n inline Field operator-() {if(v) return {(int)(N-v)}; else return {0};};\n inline Field& operator++() { ++v; if (v==N) v=0; return *this; }\n inline Field operator++(int) { Fieldr{*this}; ++*this; return r; }\n inline Field& operator--() { --v; if (v==-1) v=N-1; return *this; }\n inline Field operator--(int) { Fieldr{*this}; --*this; return r; }\n inline bool operator==(const Field&o) const { return o.v==v; }\n\tinline bool operator!=(const Field&o) const { return o.v!=v; }\n\tinline explicit operator ui() const { return v; }\n\tinline static vector>fact(int t){vector>F(t+1,1);for(int i=2;i<=t;++i){F[i]=F[i-1]*i;}return F;}\n\tinline static vector>invfact(int t){vector>F(t+1,1);Field X{1};for(int i=2;i<=t;++i){X=X*i;}F[t]=1/X;for(int i=t-1;i>=2;--i){F[i]=F[i+1]*(i+1);}return F;}\nprivate: ui v;\n};\ntemplateistream &operator>>(std::istream&is,Field&f){unsigned int v;is>>v;f=v;return is;}\ntemplateostream &operator<<(std::ostream&os,const Field&f){return os<<(unsigned int)f;}\ntemplateField operator+(int i,const Field&f){return Field(i)+f;}\ntemplateField operator-(int i,const Field&f){return Field(i)-f;}\ntemplateField operator*(int i,const Field&f){return Field(i)*f;}\ntemplateField operator/(int i,const Field&f){return Field(i)/f;}\n\n\ntypedef Field<1000000007> FieldMod;\n\nstruct Ring {\n\tstatic int div(int p, int q, int N) {\n\t\tll t=0,nt=1,r=N,nr=q;\n\t\twhile(nr){ ll q=r/nr;t-=q*nt;r-=q*nr;swap(t,nt);swap(r,nr); }\n\t\tt=(t<0)?t+N:t;\n\t\tr=(r<0)?r+N:r;\n\t\tif (gcd(p,N)%r) { return 0; }\n\t\treturn (int)(((ll)t*(ll)p/r)%N);\n\t}\n};\n#endif\n\n\nclass TaskD {\npublic:\n ll floorSqrt(ll x) {\n ll y = (ll)sqrt(x);\n while (y*y < x) ++y;\n while (y*y > x) --y;\n return y;\n }\n\n\n void solve(istream& cin, ostream& cout) {\n ll M; cin >> M;\n ll S = floorSqrt(M);\n\n FieldMod i2 = 1, i3 = 1, i6 = 1, i30 = 1, i42 = 1;\n i2 /= 2;\n i3 /= 3;\n i6 /= 6;\n i30 /= 30;\n i42 /= 42;\n FieldMod fm = ui(M%1000000007);\n\n FieldMod ans = 0;\n for (ll x = 1; x*x <= M; ++x) {\n FieldMod fx = ui(x);\n FieldMod fy = ui(floorSqrt(M-x*x));\n fx *= fx;\n\n FieldMod a = i3;\n FieldMod b = -fm*i2+fx-1;\n FieldMod c = -fm*fx+fm*i2+fx*fx-2*fx+2*i3;\n FieldMod d = fm*fm*fm*i6+fm*fm*i2-fm*fx*fx*i2+fm*fx*i2+fm*i3+fx*fx*fx*i3-fx*fx+2*fx*i3;\n\n ans += a*fy*(fy+1)*(2*fy+1)*(3*fy*fy*fy*fy+6*fy*fy*fy-3*fy+1)*i42;\n ans += b*fy*(fy+1)*(2*fy+1)*(3*fy*fy+3*fy-1)*i30;\n ans += c*fy*(fy+1)*(2*fy+1)*i6;\n ans += d*(fy+1);\n }\n\n cout << 4*ans + fm*(fm+1)*(fm+2)*i6 << endl;\n\n\n }\n};\n\n\nint main() {\n\tios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);\n\tTaskD solver;\n\tstd::istream& in(std::cin);\n\tstd::ostream& out(std::cout);\n\tsolver.solve(in, out);\n return 0;\n}\n", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48"} {"source_code": "#include\nusing namespace std;\nlong long n;\nmain(){\ncin>>n;\ncout<<(n-2)*(n-2)<\n#include \n#include \nusing namespace std;\n \ntypedef long long ll;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef pair pii;\ntypedef pair pll;\ntypedef vector vpii;\ntypedef vector vpll;\ntypedef vector vll;\n \n#define all(v) v.begin(),v.end()\n#define test() int t;cin>>t;while(t--) \n#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\nconst int mod = 1e9+7;\n\nmap, double> m;\ndouble prob(int w, int b)\n{\n if(w==0)return(0);\n if(b==0)return(1);\n if(m.find({w, b})!=m.end())return(m[{w, b}]);\n double ans = w * (1.0/(w+b)), cont = b*(1.0/(w+b));\n b--;\n if(b>=0)cont*= b*(1.0/(w+b));\n b--;\n double jumpb=0, jumpw=0;\n if(b>0)jumpb = b*(1.0/(w+b))*prob(w, b-1);\n if(b>=0)jumpw = w*(1.0/(w+b))*prob(w-1, b);\n ans+=(cont*(jumpw+jumpb));\n m[{w, b+2}]=ans; \n return(ans);\n}\nint main()\n{\n fastio\n int w, b;\n cin>>w>>b;\n cout<> a >>b;\n // if(a==b){\n // cout << \"0\" << endl;\n // return 0;\n // }\n vector v;\n ll diff = abs(a-b);\n for(ll i=1;i*i<=diff;i++){\n if(diff%i==0){\n v.push_back(i);\n if((diff/i)!=i){\n v.push_back(diff/i);\n }\n }\n }\n sort(v.begin(),v.end());\n ll val = a*b,ans=0;\n for(int i=0;i\n#define il inline\n#define RG register\n#define ld long double\n#define eps (1e-12)\n\nusing namespace std;\n\nstruct point{\n ld x,y,r;\n il int operator == (const point &a) const{\n return fabs(x-a.x)B.x) swap(A,B);\n if (d>A.r+B.r || d>n;\n for (RG int i=1;i<=n;++i)\n cin>>p[i].x>>p[i].y>>p[i].r,fa[i]=i;\n for (RG int i=1;i\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tstring s1, s2, s3;\n\tcin >> s1 >> s2 >> s3;\n\tif (s1[1] == s2[1]&&s1[1] == s3[1])\n\t{\n\t\tint a = s1[0] - 48, b = s2[0] - 48, c = s3[0] - 48;\n\t\tif (a == b&&b == c)\n\t\t{\n\t\t\tprintf(\"0\\n\");\n\t\t}\n\t\telse if ((1.0*(a + b)/ 2 == c || 1.0*(a + c)/ 2 == b || 1.0*(c + b) / 2 == a)&&((a+1==b||a-1==b)||(a+1==c||a-1==c)||(c+1==b||c-1==b)))\n\t\t{\n\t\t\tprintf(\"0\\n\");\n\t\t}\n\t\telse if (a == b)\n\t\t{\n\t\t\tprintf(\"1\\n\");\n\t\t}\n\t\telse if (a == c)\n\t\t{\n\t\t\tprintf(\"1\\n\");\n\t\t}\n\t\telse if (b == c)\n\t\t{\n\t\t\tprintf(\"1\\n\");\n\t\t}\n\t\telse if (a != b&&b != c&&a!=c)\n\t\t{\n\t\t\tif (a + 1 == b || a - 1 == b)\n\t\t\t{\n\t\t\t\tprintf(\"1\\n\");\n\t\t\t}\n\t\t\telse if (a + 1 == c || a - 1 == c)\n\t\t\t{\n\t\t\t\tprintf(\"1\\n\");\n\t\t\t}\n\t\t\telse if (b + 1 == c || b - 1 == c)\n\t\t\t{\n\t\t\t\tprintf(\"1\\n\");\n\t\t\t}\n\t\t\telse if (a + 2 == b || a - 2 == b)\n\t\t\t{\n\t\t\t\tprintf(\"1\\n\");\n\t\t\t}\n\t\t\telse if (a + 2 == c || a - 2 == c)\n\t\t\t{\n\t\t\t\tprintf(\"1\\n\");\n\t\t\t}\n\t\t\telse if (b + 2 == c || b - 2 == c)\n\t\t\t{\n\t\t\t\tprintf(\"1\\n\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tprintf(\"2\\n\");\n\t\t\t}\n\t\t}\n\t}\n\telse if (s1[1] != s2[1] && s1[1] != s3[1] && s2[1] != s3[1])\n\t{\n\t\tprintf(\"2\\n\");\n\t}\n\telse if (s1[1] == s2[1])\n\t{\n\t\tif (s1[0] != s2[0] && s1[0] != s2[0] + 1 && s1[0] != s2[0] - 1&& s1[0] != s2[0] + 2&& s1[0] != s2[0] - 2)\n\t\t{\n\t\t\tprintf(\"2\\n\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"1\\n\");\n\t\t}\n\t}\n\telse if (s1[1] == s3[1])\n\t{\n\t\tif (s1[0] != s3[0] && s1[0] != s3[0] + 1 && s1[0] != s3[0] - 1&& s1[0] != s3[0] + 2&& s1[0] != s3[0] - 2)\n\t\t{\n\t\t\tprintf(\"2\\n\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"1\\n\");\n\t\t}\n\t}\n\telse if (s2[1] == s3[1])\n\t{\n\t\tif (s3[0] != s2[0] && s3[0] != s2[0] + 1 && s3[0] != s2[0] - 1&& s3[0] != s2[0] + 2&& s3[0] != s2[0] - 2)\n\t\t{\n\t\t\tprintf(\"2\\n\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"1\\n\");\n\t\t}\n\t}\n\treturn 0;\n}", "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"source_code": "#include \n\nusing namespace std;\nint find(int a[],int b[],int n){\n int i;\n int maxi[30];\n int max=0;\n for(i=0;imax)\n max=maxi[i];\n }\n for(i=0;i>n>>k;\n for(i=0;i>a[i]>>b[i];\n min=min+a[i];\n max=max+b[i];\n }\n if((k>max)||(k0){\n for(i=0;in)\n i=i-n;\n if(b[i]<=a[i]){\n b[i+1]--;\n continue;}\n --b[i];}\n }*/\n while(g>0){\n diff=find(a,b,n);\n b[diff]--;\n g--;\n \n }}\n \n \n for(i=0;i\nusing namespace std;\n\n#define rep(i, x, y) for(int i = (x), _ = (y); i <= _; ++ i)\n#define per(i, x, y) for(int i = (x), _ = (y); i >= _; -- i)\n#define dprintf(...) fprintf(stderr, __VA_ARGS__)\n#define disp(x) cout << #x << \" = \" << x << \"; \"\n#ifdef __linux__\n#define getchar getchar_unlocked\n#define LLFORMAT \"%lld\"\n#else\n#define LLFORMAT \"%I64d\"\n#endif\n\ntypedef long long LL;\n\ntemplate bool chkmin(T& a, T b) { return a > b ? a = b, true : false; }\ntemplate bool chkmax(T& a, T b) { return a < b ? a = b, true : false; }\n\ntemplate void read(T& a) {\n\tchar c = getchar(); T f = 1; a = 0;\n\tfor(; !isdigit(c); c = getchar()) if(c == '-') f = -1;\n\tfor(; isdigit(c); c = getchar()) a = a * 10 + c - '0';\n\ta *= f;\n}\n/*}}}*/\n\nconst int maxN = 1e5 + 5, mo = 1e9 + 7;\n\nint pow_mod(int x, int t)\n{\n\tint ret = 1;\n\twhile(t) \n\t{\n\t\tif(t & 1) ret = (LL) ret * x % mo;\n\t\tx = (LL) x * x % mo; t >>= 1;\n\t}\n\treturn ret;\n}\n\nint a[maxN], N, M, tp, ans;\nint cnt[4];\nint pre;\nint len[maxN], tot[maxN], lala[maxN], pos[maxN];\nbool appear[maxN], vis[maxN];\nvector dp[maxN], invdp[maxN], chain;\n\nvoid upd(int& a, int b)\n{\n\ta += b;\n\tif(a < 0) a += mo;\n\tif(a >= mo) a -= mo;\n}\n\nvoid prework()\n{\n\trep(i, 1, N)\n\t{\n\t\tdp[i].resize(N / i + 5);\n\t\tinvdp[i].resize(N / i + 5);\n\t\tdp[i][0] = invdp[i][0] = 1;\n\n\t\trep(j, 1, N / i + 2)\n\t\t{\n\t\t\tdp[i][j] = (LL) dp[i][j - 1] * i % mo;\n\t\t\tif(j >= 2) upd(dp[i][j], (LL) dp[i][j - 2] * (j - 1) % mo * i % mo);\n\t\t\tinvdp[i][j] = pow_mod(dp[i][j], mo - 2);\n\t\t}\n\t}\n}\n\nvoid calc(int haha)\n{\n//\tdprintf(\"in calc \"); disp(haha), puts(\"-----------\");\n\tint pre1 = (LL) pre * haha % mo;\n//\trep(i, 1, tp)\n//\t\tdisp(i), disp(len[i]), puts(\"\");\n\trep(i, 1, tp)\n\t{\n\t\tpre1 = (LL) pre1 * invdp[len[i]][lala[len[i]]] % mo;\n//\t\tdisp(pre1), puts(\"\");\n//\t\tdisp(lala[len[i]]), puts(\"\");\n\t\tcnt[min(len[i], 3)] ++;\n\t\tpre1 = (LL) pre1 * dp[len[i]][++ lala[len[i]]] % mo;\n//\t\tdisp(pre1), puts(\"\");\n\t}\n\n\tif(cnt[3] == 0) pre1 = haha;\n\tupd(ans, pre1);\n\n\trep(i, 1, tp)\n\t{\n\t\tlala[len[i]] --;\n\t\tcnt[min(len[i], 3)] --;\n\t}\n}\n\nvoid dfs(int x, int haha)\n{\n\tif(x >= (int) chain.size())\n\t{\n\t\tcalc(haha);\n\t\treturn;\n\t}\n\n\ttot[++ tp] = 1;\n\tlen[tp] = chain[x];\n\tdfs(x + 1, haha);\n\t-- tp;\n\n\trep(i, 1, tp)\n\t{\n\t\ttot[i] ++;\n\t\tlen[i] += chain[x];\n\t\tdfs(x + 1, (LL) haha * (tot[i] - 1) % mo);\n\t\tlen[i] -= chain[x];\n\t\ttot[i] --;\n\t}\n}\n\nint main()\n{\n#ifdef Leeson\n\tfreopen(\"tmp.in\", \"r\", stdin);\n\tfreopen(\"tmp.out\", \"w\", stdout);\n#endif\n\n\tread(N); read(M);\n\tprework();\n\n\trep(i, 1, N)\n\t{\n\t\tread(a[i]);\n\t\tpos[a[i]] = i;\n\t}\n\n\trep(i, 1, N) if(a[i] == 0)\n\t{\n//\t\tprintf(\"while i = %d ----------------\\n\", i);\n\t\tint len = 0;\n\t\tfor(int x = i; x; x = pos[x])\n\t\t\tvis[x] = 1, ++ len;\n//\t\tdisp(len), puts(\"\");\n\t\tchain.push_back(len);\n\t}\n\n\trep(i, 1, N) if(vis[i] == 0)\n\t{\n\t\tint len = 0;\n\t\tfor(int x = i; vis[x] == 0; x = pos[x])\n\t\t\tvis[x] = 1, ++ len;\n\t\tcnt[min(len, 3)] ++;\n//\t\tdisp(len), puts(\"\");\n\t\tlala[len] ++;\n\t}\n\n\tpre = 1;\n\trep(i, 1, N)\n\t\tif(lala[i]) pre = (LL) pre * dp[i][lala[i]] % mo;\n//\tdisp(pre), puts(\"\");\n//\trep(i, 1, N)\n//\t\tdisp(i), disp(lala[i]), puts(\"\");\n//\trep(i, 0, chain.size() - 1)\n//\t\tdisp(chain[i]), puts(\"\");\n//\n//\tdisp(pre),puts(\"\");\n\n\tdfs(0, 1);\n\tcout << ans << endl;\n\n\treturn 0;\n}\n", "src_uid": "3467cbf1f1bf689096841b91405a9651"} {"source_code": "#include\n\nint main(void)\n{\n long long a,b,c,d,flag=0;\n scanf(\"%lld %lld\",&a,&b);\n if(a==b){\n printf(\"%lld\",a/b);\n flag =1;\n }\n if(b%2==1&&flag==0)\n printf(\"%lld\",(b/2)+1);\n else if(b%2==0&&flag==0)\n printf(\"%lld\",((a-b)/2)+1);\n}\n", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"} {"source_code": "#include\nusing namespace std;\n\n#define ll long long\n#define fr first\n#define sec second\n#define pi 3.141592653589793\n#define M 1000000007\n#define mod 998244353\n#define maxint 2147483647\n#define minint -2147483648\n#define maxll 9223372036854775807\n#define minll -9223372036854775808\n#define meme0(a) memset(a,0,sizeof(a));\n#define meme1(a) memset(a,1,sizeof(a));\n#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n#define open freopen(\"input.txt\",\"r\",stdin);\n#define close freopen(\"output.txt\",\"w\",stdout);\n#define v_int vector\n#define v_ll vector\n#define pb push_back\n#define mk make_pair\n//#define int long long\n//upper_bound(begin(),end(),key)\n//lower_bound(begin(),.end(),key);\n\nll expo(ll x , ll n , ll m){\n if(n==0)\n return 1;\n else if(n%2==0)\n return expo((x*x)%m , n/2 , m);\n else\n return (x*expo((x*x)%m,(n-1)/2,m))%m;\n\n}\n\nvoid solve(){\n ll n,a,b;\n cin >> n >> a >> b;\n /*\n vector dd;\n for(int i=1;i*i<=n;i++){\n if(n%i==0){\n dd.push_back(i);\n if(i!=n/i)\n dd.push_back(n/i);\n }\n }\n */\n ll area = 6*n;\n if(area <= a*b){\n cout << a*b << endl;\n cout << a << \" \" << b << endl;\n return ;\n }\n float k = sqrt(area);\n\n bool lol = false;\n if(a>b){\n lol = true;\n swap(a,b);\n }\n\n ll m = k;\n ll p = b;\n ll q = a;\n //cout << m <<\" \" << area << endl;\n a = maxint;\n b = maxint;\n for(ll i=q;i<=m+5;i++){\n ll j = area/i;\n if(j=area){\n if(i*j=area){\n if(i*j=x)\n q = area/p;\n }\n\n b = p;\n a = q;\n }\n if(lol)\n swap(a,b);\n cout << a*b << endl <> t;\n while(t--)\n solve();\n\n return (int)0;\n}\n", "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"source_code": "#include\nusing namespace std;\n#define pb push_back\n#define ll long long\n#define maxn 100005\n#define fr(i,j,k) for(int i=j;i>n){\n ll now=1,ans=0;\n while(n>1){\n ans+=n/2*now;\n now<<=1;\n n-=n>>1;\n }\n cout<\n#define rep(i,j,k) for(int i=(j);i<(k);i++)\n#define mp make_pair\n#define sz(a) (int)(a).size()\n#define pb push_back\nusing namespace std;\ntypedef long long ll;\ntypedef pair pii;\ntypedef long double ld;\n//----head----\nconst ll mod=1e9+7;\nll dp[105][105][105];//dp[i][l][r]��ʾf(i)�д���s[l-r]�������� \nchar s[105];\nint n,m;\nll modpow2[105]={2,2};\nint main()\n{\n\trep(i,2,105)modpow2[i]=modpow2[i-1]*modpow2[i-2]%mod;\n scanf(\"%d%d\",&m,&n);\n scanf(\"%s\",s);\n rep(i,0,m)dp[s[i]-'0'][i+1][i+1]=1;\n rep(i,2,n+1)rep(l,1,m+1)rep(r,l,m+1)\n {\n dp[i][l][r]=(dp[i][l][r]+dp[i-1][l][r]*(r==m?modpow2[i-2]:1))%mod;\n dp[i][l][r]=(dp[i][l][r]+dp[i-2][l][r]*(l==1?modpow2[i-1]:1))%mod;\n rep(k,l,r)dp[i][l][r]=(dp[i][l][r]+dp[i-1][l][k]*dp[i-2][k+1][r])%mod;\n }\n printf(\"%lld\\n\",dp[n][1][m]);\n return 0;\n}\n", "src_uid": "52c6aa73ff4460799402c646c6263630"} {"source_code": "#include \n#include \n#include \n#include \n\n\nusing namespace std;\n\n\nint n,k;\nint A[6][3] = { 0,1,2 ,1,0,2,1,2,0,2,1,0,2,0,1,0,2,1} ;\n\n\nint main()\n{\n\tscanf(\"%d%d\", &n, &k);\n\tn = n % 6;\n\tprintf(\"%d\", A[n][k]);\n\treturn 0;\n}", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"} {"source_code": "#include\n#include\nusing namespace std;\nvoid P(int x){printf(\"%d\\n\",x);exit(0);}\nint main(){\n\tint n,m,ans=0,f=0;\n\tscanf(\"%d%d\",&m,&n);\n\tif(n==1)P(-1);\n\tif(n==2 && m==3)P(11);\n\tif(n==3 && m==5)P(11);\n\tfor(;;){\n\t\tif(n>=m+m)P(ans+1);\n\t\tif(n>=m)P(ans+(n==m?5:3));\n\t\tif(!f)m-=n-2,ans=4,f=1;\n\t\telse {\n\t\t\tif(n/2==1)P(-1);\n\t\t\tm-=n/2-1,ans+=2;\n\t\t}\n\t}\n}\n", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80"} {"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\nconst int maxN = 110;\n\nstring s;\nint n;\n\nchar get(int i) {\n return s[(i % n + n) % n];\n}\n\nint index(int i) {\n return (i % n + n) % n;\n}\n\nint used[maxN];\nlong long dp1[maxN];\nlong long dp2[maxN];\n\nint main() {\n //freopen(\"input.txt\", \"r\", stdin);\n //freopen(\"output.txt\", \"w\", stdout);\n\n cin >> s;\n n = s.length();\n for (int i = 0; i < n; ++i) {\n if (get(i) == 'A' && get(i + 1) == 'A' && get(i + 2) == 'B' && get(i + 3) == 'B') {\n cout << 0 << endl;\n return 0;\n }\n }\n\n vector lengths;\n vector start;\n vector finish;\n\n for (int i = 0; i < n; ++i) {\n if (!used[i]) {\n if (get(i) == 'B' && get(i + 1) == 'A') {\n used[index(i)] = used[index(i + 1)] = 1;\n int j = i - 2;\n int length = 2;\n while (1) {\n if (used[index(j)]) break;\n if (get(j) == 'B' && get(j + 1) == 'A') {\n used[index(j)] = used[index(j + 1)] = 1;\n length += 2;\n j -= 2;\n } else {\n break;\n }\n }\n start.push_back(get(j + 1) - 'A');\n j = i + 2;\n while (1) {\n if (used[index(j)]) break;\n if (get(j) == 'B' && get(j + 1) == 'A') {\n used[index(j)] = used[index(j + 1)] = 1;\n length += 2;\n j += 2;\n } else {\n break;\n }\n }\n finish.push_back(get(j) - 'A');\n lengths.push_back(length / 2);\n }\n }\n }\n\n dp1[0] = 1;\n dp2[0] = 1;\n\n dp1[1] = 1; dp1[2] = 2;\n dp2[1] = 1; dp2[2] = 1;\n for (int i = 3; i < maxN; ++i) {\n dp1[i] = dp1[i - 1] + dp1[i - 2];\n dp2[i] = dp2[i - 1] + dp2[i - 2];\n }\n\n long long answer = 1;\n\n for (int i = 0; i < lengths.size(); ++i) {\n if (lengths[i] * 2 == n) {\n long long res1 = dp1[lengths[i] - 1];\n long long res2 = dp2[lengths[i] - 1];\n\n long long ans = res1 + dp1[lengths[i] - 2] + res2;\n cout << ans << endl;\n return 0;\n } else {\n long long dist = lengths[i];\n int lt = start[i];\n int rt = finish[i];\n\n if (dist == 1) {\n if (lt == 1 && rt == 0) {\n answer *= 2;\n }\n continue;\n }\n\n if (lt == 0 && rt == 1) {\n answer *= dp2[dist];\n } else \n if (lt == 0 && rt == 0) {\n answer *= dp2[dist] + dp2[dist - 1];\n } else \n if (lt == 1 && rt == 1) {\n answer *= dp1[dist];\n } else {\n answer *= dp1[dist] + dp1[dist - 1];\n }\n }\n }\n\n cout << answer << endl;\n\n return 0;\n}", "src_uid": "ad27d991516054ea473b384bb2563b38"} {"source_code": "// be name khoda\n\n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\nconst int maxN = 7002;\n\nstruct node{\n int lr;\n int x, ind, pl;\n};\n\nint /*l[maxN][maxN], r[maxN][maxN],*/ type[maxN], lr[maxN][2], n;\nvector timeLine[maxN];\n//vector l[maxN], r[maxN];\nset ans;\n\nint lg(ll v)\n{\n int k = 0;\n while((1 << k) < v)\n k++;\n return k;\n}\n\nvoid count(int n)\n{\n ll a[maxN], sum[maxN];\n a[1] = sum[1] = 1;\n for(int i = 2; i < n; i++) \n {\n a[i] = a[i - 1] + lg(a[i - 1]);\n sum[i] = sum[i - 1] + a[i];\n }\n for(int i = 6500; i < 7000; i++)cerr << i << \" : \" << a[i] << \", \" << sum[i] << endl;\n}\n\nbool cmp(node l, node r)\n{\n return l.pl < r.pl;\n}\n\nint main()\n{\n int n, m;\n cin >> n >> m;\n for(int i = 0; i < m; i++)\n {\n int t;\n cin >> t;\n type[i] = t;\n if(t == 1)\n {\n int t, lll, rr, x;\n cin >> t >> lll >> rr >> x;\n node a, b;\n a.ind = b.ind = i;\n a.lr = rr;\n b.lr = lll;\n a.pl = lll;\n b.pl = rr;\n a.x = b.x = x;\n timeLine[t].push_back(a);\n timeLine[t].push_back(b);\n }\n else\n {\n int t, v;\n cin >> t >> v;\n int lll = v, rr = v;\n ans.clear();\n for(int j = t; j <= n; j++)\n {\n for(int k = 0; k < timeLine[j].size(); k++)\n //cerr << k << \" : \" << timeLine[j][k].pl << timeLine[j][k].lr << endl;\n if((timeLine[j][k].pl >= lll && timeLine[j][k].pl <= rr)||(timeLine[j][k].pl < lll && timeLine[j][k].lr > rr))\n ans.insert(timeLine[j][k].x);\n //cerr << i << \" ,,, \" << j << \" : \" << lll << \" \" << rr << endl;\n //l[i].push_back(lll);\n //r[i].push_back(rr);\n //l[i][j] = lll;\n //r[i][j] = rr;\n int lgl = lg(lll);\n int lgr = lg(rr);\n //if(1 << (lgl) == lll)\n // lll = lll + lgl;\n //else\n lll = lll + lgl;\n if(1 << (lgr) == rr)\n rr = rr + lgr + 1;\n else\n rr = rr + lgr;\n }\n cout << ans.size() << endl;\n }\n }\n //for(int i = 1; i <= n; i++)\n // sort(timeLine[i].begin(), timeLine[i].end(), cmp); lazem nis!!:D\n /*\n for(int i = 0; i < m; i++)\n if(type[i] == 2)\n {\n ans.clear();\n for(int j = lr[i][0]; j <= n; j++)\n {\n //cerr << i << \", \" << j << \" : \" << l[i][j] << \", \" << r[i][j] << endl;\n for(int k = 0; k < timeLine[j].size(); k++)\n if(((timeLine[j][k].pl >= l[i][j] && timeLine[j][k].pl <= r[i][j])||(timeLine[j][k].pl < l[i][j] && timeLine[j][k].lr > r[i][j])) && timeLine[j][k].ind < i)\n {\n ans.insert(timeLine[j][k].x);\n //cerr << \" : \" << timeLine[j][k].x << endl;\n }\n // for(int k = l[i][j]; k <= r[i][j]; k++)\n // {\n //\n // }\n }\n cout << ans.size() << endl;\n }*/\n}\n", "src_uid": "9f239cfd29c1a2652a065bfe5c15476a"} {"source_code": "#include \nusing namespace std;\n#pragma comment(linker,\"/STACK:102400000,102400000\")\n#define LL long long\n#define ALL(a) a.begin(), a.end()\n#define pb push_back\n#define mk make_pair\n#define fi first\n#define se second\n#define haha printf(\"haha\\n\")\nconst int maxn = 1e3 + 5;\nvector day[maxn];\nint n, m;\nint d[maxn], s[maxn], c[maxn];\nint ans[maxn];\n\nbool solve(){\n memset(ans, -1, sizeof(ans));\n for (int i = 1; i <= m; i++){\n day[d[i]].pb(i);\n ans[d[i]] = m + 1;\n }\n priority_queue > > que;\n for (int i = n; i >= 1; i--){\n if (day[i].size() > 0){\n for (int j = 0; j < day[i].size(); j++){\n int p = day[i][j];\n que.push(mk(s[p], mk(c[p], p)));\n }\n }\n if (ans[i] != -1) continue;\n if (que.empty()){///休息\n ans[i] = 0;\n continue;\n }\n int spos = que.top().fi;\n int restday = que.top().se.fi;\n int pos = que.top().se.se;\n que.pop();\n if (spos > i && restday > 0) return false;\n restday--;\n ans[i] = pos;\n if (restday == 0){\n continue;\n }\n que.push(mk(spos, mk(restday, pos)));\n }\n if (!que.empty()) return false;\n for (int i = 1; i <= n; i++){\n printf(\"%d \", ans[i]);\n }\n cout << endl;\n return true;\n}\n\nint main(){\n cin >> n >> m;\n for (int i = 1; i <= m; i++){\n scanf(\"%d%d%d\", s + i, d + i, c + i);\n }\n if (solve() == false) puts(\"-1\");\n return 0;\n}", "src_uid": "02d8d403eb60ae77756ff96f71b662d3"} {"source_code": "#include \nusing namespace std;\nint main(){\n\t\n int i,j,k;\n\tcin>>i;\n\tfor(j=1;j<=i;j++)\n\t{\n\t\tfor(k=1;k<=j;k++)\n\t\t{\n\t\t\tif(j%k==0 && (k*j)>i && (j/k)\n#include \n#include \n#include \n#include \n#include \n#define mod 1000000007\n#define M 1000005\ntypedef long long ll;\ntypedef std::vector Poly;\nint n,m,P[M],C[M],maxn,ans;\nll T;\nint read(){\n\tchar c=getchar();int ans=0;\n\twhile (c<'0'||c>'9') c=getchar();\n\twhile (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();\n\treturn ans;\n}\nll read_ll(){\n\tchar c=getchar();ll ans=0;\n\twhile (c<'0'||c>'9') c=getchar();\n\twhile (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();\n\treturn ans;\n}\nvoid Write(int x){\n\tif (x<10) putchar(x^48);\n\telse Write(x/10),putchar((x%10)^48);\n\treturn;\n}\nint power(ll x,int y){\n\tll ans=1;\n\tfor (;y;y>>=1,x=x*x%mod)\n\t\tif (y&1) ans=ans*x%mod;\n\treturn ans;\n}\nint invs(int x){return x==1?1:(mod-mod/x+0ll)*invs(mod%x)%mod;}\nint min(int x,int y){return xy?x:y;}\nint add(int x,int y){return (x+=y)>=mod?x-mod:x;}\nint sub(int x,int y){return (x-=y)<0?x+mod:x;}\nPoly operator+ (Poly A,Poly B){\n\tA.resize(max(A.size(),B.size()));B.resize(A.size());\n\tfor (register int i=0;i=B.size()-1;i--){\n\t\tint tmp=(mod-A[i]+0ll)*invs(B.back())%mod;\n\t\tfor (register int j=i,k=B.size()-1;k>=0;j--,k--) A[j]=(A[j]+(tmp+0ll)*B[k])%mod;\n\t}\n\tA.resize(B.size()-1);return A;\n}\nPoly Power(Poly A,ll y,Poly Mod){\n\tPoly ans;ans.resize(Mod.size()-1);ans[0]=1;\n\tfor (;y;y>>=1,A=A*A%Mod)\n\t\tif (y&1) ans=ans*A%Mod;\n\treturn ans;\n}\nPoly get_X(){Poly ans;ans.resize(2);ans[0]=0,ans[1]=1;return ans;}\nint main(){\n\tn=read(),m=read(),T=read_ll();\n\tfor (register int i=1;i<=n;i++) P[i]=read();\n\tfor (register int i=1,tmp;i<=m;i++) ++C[tmp=read()],maxn=max(maxn,tmp);\n\tPoly Mod,Ans,G;Mod.resize(maxn+1);Mod[maxn]=1;\n\tfor (register int i=1;i<=maxn;i++) Mod[maxn-i]=sub(0,C[i]);\n\tfor (register int i=1;i<=n;i++) Ans+=Power(get_X(),P[i],Mod);\n\tAns=Power(Ans,T,Mod);G.resize(maxn);G[0]=1;\n\tfor (register int i=1;i= 0 ){\n b = total - n*a;\n if( b >= 0 ) ans = min( a*c + b*d, ans );\n else ans = min( a*c, ans );\n //printf(\"when a = %d b = %d, ans = %d\\n\", a, b, ans );\n a++;\n }\n return ans;\n}\n\nmain(){\n cin >> c >> d >> n >> m >> k;\n cout << solve();\n}\n", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb"} {"source_code": "#include\n#define ff first\n#define ss second\n#define mp make_pair\n#define pb push_back\n#define fori(a, l, f) for(int a = l; a=f; --a)\n#define pq priority_queue\n#define checkBit(mask, i) ((mask & (1 << i)) != 0) ? true:false\n#define setBit(mask, i) mask = mask | (1 << i)\n#define debug(x) cout< ii;\ntypedef pair iii;\ntypedef vector vi;\ntypedef vector vii;\ntypedef vector viii;\n///////////////////////////////////////////////////////////////////////////////\n\nint main(){\n\tll n, m, k;\n\tscanf(\"%lld %lld %lld\", &n, &m, &k);\n\t\n\tif(k < n) printf(\"%lld\\n 1\", k+1);\n\telse{\n\t\tk -= n;\n\t\t\n\t\tll l = n - k/(m-1);\n\t\tll s = k%(m-1);\n\t\tll c;\n\t\tif(l % 2 == 0) c = 2 + s;\n\t\telse c = m-s;\n\t\t\n\t\tprintf(\"%lld %lld\\n\", l, c);\t\n\t}\n\t\t\t\n\treturn 0;\n}\n", "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"source_code": "#include \nusing namespace std;\ntypedef signed long long ll;\n\n#undef _P\n#define _P(...) (void)printf(__VA_ARGS__)\n#define FOR(x,to) for(x=0;x<(to);x++)\n#define FORR(x,arr) for(auto& x:arr)\n#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)\n#define ALL(a) (a.begin()),(a.end())\n#define ZERO(a) memset(a,0,sizeof(a))\n#define MINUS(a) memset(a,0xff,sizeof(a))\n//-------------------------------------------------------\n\nint N,K;\ndouble P[30];\ndouble dp[1<<20];\ndouble R[30];\n\nvoid solve() {\n\tint i,j,k,l,r,x,y; string s;\n\t\n\tcin>>N>>K;\n\tFOR(i,N) cin>>P[i];\n\t\n\tdp[0]=1;\n\tfor(int mask=0;mask<1< \nusing namespace std;\n\nint main() \n{\n\tint s, x, y, p, d;\n\tlong long tram, igor;\n\tcin >> s >> x >> y;\n\tcin >> tram >> igor;\n\tcin >> p >> d;\n\tif(tram > igor) \n\t{\n\t\tcout << abs(y-x) * igor;\n\t\treturn 0;\n\t}\n\tlong long ans = abs(y-x) * igor;\n\tif(x <= y) \n\t{\n\t\tif(p <= x && d > 0) \n\t\t{\n\t\t\tans = min(ans, (y - p)*tram);\n\t\t}\n\t\telse if(p <= x && d < 0) \n\t\t{\n\t\t\tans = min(ans, (p + y)*tram);\n\t\t}\n\t\telse if(p > x && d > 0) \n\t\t{\n\t\t\tans = min(ans, (s - p + s + y)*tram);\n\t\t}\n\t\telse if(p > x && d < 0)\n\t\t{\n\t\t\tans = min(ans, (p + y)*tram);\n\t\t}\n\t}\n\telse\n\t{\n\t\tif(p < x && d > 0)\n\t\t{\n\t\t\tans = min(ans, (s - p + s - y)*tram);\n\t\t}\n\t\telse if(p < x && d < 0)\n\t\t{\n\t\t\tans = min(ans, (p + s + s - y)*tram);\n\t\t}\n\t\telse if(p >= x && d > 0)\n\t\t{\n\t\t\tans = min(ans, (s - p + s - y)*tram);\n\t\t}\n\t\telse if(p >= x && d < 0)\n\t\t{\n\t\t\tans = min(ans, (p - y)*tram);\n\t\t}\n\t}\n\tcout << ans;\n\t\n\t\n}", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821"} {"source_code": "#pragma comment(linker, \"/STACK:20000000\")\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#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 int64;\n#ifdef HOME\n\t#define E(c) cerr<<#c\n\t#define Eo(x) cerr<<#x<<\" = \"<<(x)<>=1) {\n\t\tif (p & 1) res = Mult(res, x);\n\t\tx = Mult(x, x);\n\t}\n\treturn res;\n}\n\nint main() {\n#ifdef HOME\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\t\n\tscanf(\"%d%d\", &n, &m);\n\tfor (int i = 0; i cst)\n\t\t\tnum = cst;\n\t}\n\n\ts = 3*n+1;\n\tmemset(&graph, 63, sizeof(graph));\n\tfor (int i = 0; i INF) continue;\n\t\t\t\tauto& num = graph.a[i][i+b];\n\t\t\t\tnum = min(num, cst);\n\t\t\t}\n\n/*\tfor (int i = 0; i %d in %d\\n\", i, j, graph.a[i][j]);*/\n\n\tMatr trans = pwr(graph, m);\n\tprintf(\"%I64d\\n\", trans.a[0][0]);\n\n\treturn 0;\n}", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601"} {"source_code": "#include \nusing namespace std;\nint main(){\n int T,S,Q;\n \n cin >> T >> S >> Q;\n \nint cnt = 0;\nwhile(S < T){\ncnt++;\nS = S*Q;\n}\ncout << cnt << endl;\n}", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"source_code": " #include \n using namespace std;\n\n int ans,n,cnt;\n int arr[2500][2500];\n int main()\n {\n cin >>n;\n for(int i=1;i<=n;i++){\n for(int j=1;j<=n;j++)\n {\n\n int t=i^j;\n if(i+j > t && t>i && t>j&& i<=n && j<=n &&t<=n && !arr[i][j]) {arr[i][j]=t,arr[j][i]=t;\n ans++;\n }\n}\n}\n cout << ans << endl;\n }\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "#include \n\nusing namespace std;\nlong long n,uc,ok,sol=1;\nint main(){\n cin>>n;\n n=n+1;\n if(n<=10){\n cout<<9;\n }\n else{\n ok=0;\n while(ok==0){\n uc=n%10;\n while(uc!=0){\n n++;\n sol++;\n uc=n%10;\n }\n n=n/10;\n if(n<=10){\n ok=1;\n sol=sol+9;\n }\n }\n cout<\n\nusing namespace std;\nint main() {\n int n=0, m,i=0;\n cin >> n >> m;\n if (m % n != 0) {\n cout << \"-1\";\n return 0;\n }\n m /= n;\n while (m % 2 == 0) m /= 2, i++;\n while (m % 3 == 0) m /= 3, i++;\n if (m != 1) \n i = -1;\n cout << i;\n return 0;\n}", "src_uid": "3f9980ad292185f63a80bce10705e806"} {"source_code": "#include\nusing namespace std;\ntypedef long long ll;\nconst ll ans[36]={25,125,230,120,27,26,2000000000000000000,2,52,53,207,6699,6812,622832834,620189650,624668154,625406094,12972,12972,216245,216245,240314083,240314083,122973,1038071,20203527703,19018621728,247432457339710,229533246298127,20929602014808,7900,17544094280356,17544044596722,17469733613212,27728032700840,221336290388556};\nconst ll res[36]={236,34,375346,1131353016,61,104,-1000000002189950948,-999999998388862978,390,2834047,1588095501,-1433495032,1835054247,-3257985426,-3474511695,2318144538,-1123191892,-1638241583,-702891379,-438790925,1362927999,400935020,1246154068,-740509561,3600830483,3727042282,-21828920302,18152023769504,111936706690968,-38601483812363,1434863129,5952546959775,-5948496013101,9579018573169,38450249435581,-34189700362120};\nll sum;\nint cnt;\nint main(){\n\tios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n\tfor (ll x;cin>>x;cnt+=cnt^x)sum^=x+cnt;\n\tfor (int i=0;i<36;++i)\n\t\tif (sum==res[i]){\n\t\t\tcout<\n#include \n#include \n#include \n#include \nusing namespace std;\n\nconst int MOD = 32768;\nint ans, v, f[MOD + 5], num, p, l;\nstring s[105], tmp;\n\nint exp();\n\nint getnum() {\n if (tmp[l] == 'n') {\n ++l;\n return v;\n }\n if (tmp[l] == 'f') {\n l += 2;\n int ret = f[exp()];\n l++;\n return ret;\n }\n int ret = 0;\n while (tmp[l] >= '0' && tmp[l] <= '9') ret = ret * 10 + (tmp[l++] - '0');\n return ret;\n}\n\nint sl() {\n int ret = getnum();\n while (tmp[l] == '*' || tmp[l] == '/') {\n char tp = tmp[l++];\n int t1 = getnum();\n if (tp == '*') {\n ret = (int)(((long long)ret * t1) % MOD);\n } else {\n ret = (ret / t1) % MOD;\n }\n }\n return ret;\n}\n\nint exp() {\n int ret = sl();\n while (tmp[l] == '+' || tmp[l] == '-') {\n char tp = tmp[l++];\n int t1 = sl();\n if (tp == '+')\n ret = (ret + t1) % MOD;\n else\n ret = (ret + MOD - t1) % MOD;\n }\n return ret;\n}\n\nbool iexp() {\n int p1, p2, tp;\n p1 = exp();\n switch (tmp[l]) {\n case '=': {\n tp = 0;\n l += 2;\n break;\n }\n case '<': {\n tp = -1;\n ++l;\n break;\n }\n case '>': {\n tp = 1;\n ++l;\n break;\n }\n }\n p2 = exp();\n if (tp == 0) return p1 == p2;\n if (tp == -1) return p1 < p2;\n if (tp == 1) return p1 > p2;\n return false;\n}\n\nint getans() {\n for (int i = 0; i < num; ++i) {\n tmp = s[i];\n if (tmp[0] == 'i') {\n l = 3;\n if (iexp()) {\n l += 7;\n return exp();\n }\n } else {\n l = 6;\n return exp();\n }\n }\n return -1;\n}\n\nint main() {\n char ch;\n scanf(\"%d\", &ans);\n cin >> ch;\n while (ch != '{') cin >> ch;\n num = 0;\n while (true) {\n cin >> ch;\n if (ch == '}') break;\n if (ch == ';')\n ++num;\n else\n s[num] += ch;\n }\n\n int anst = -1;\n for (int i = 0; i <= 32767; ++i) {\n v = i;\n f[i] = getans();\n if (f[i] == ans) anst = i;\n }\n printf(\"%d\\n\", anst);\n return 0;\n}\n", "src_uid": "698c5a87f9adbe6af60d9f70519c9672"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nint n,i,j,k;\nint main()\n{\n\tint x,y;\n\tscanf(\"%d%d\",&x,&y);\n\tif(x!=0&&y==1)\n\t{\n\t\tprintf(\"No\");\n\t\treturn 0;\n\t}\n\tif(x\n#include \nusing namespace std;\n\nint main()\n{\n\tlong long n, m;\n\tint a, b;\n\tscanf(\"%lld %lld %d %d\", &n, &m, &a, &b);\n\tif (n % m == 0)\n\t{\n\t\tprintf(\"0\");\n\t}\n\telse if (n < m)\n\t{\n\t\tif (a * (m - n) <= b * n)\n\t\t\tprintf(\"%lld\", a * (m - n));\n\t\telse\n\t\t\tprintf(\"%lld\", b * n);\n\t}\n\telse\n\t{\n\t\tif (a * ((n / m + 1)* m - n) <= b * (n - n / m * m))\n\t\t\tprintf(\"%lld\", a * ((n / m + 1)* m - n));\n\t\telse\n\t\t\tprintf(\"%lld\", b * (n - n / m * m));\n\t}\n}", "src_uid": "c05d753b35545176ad468b99ff13aa39"} {"source_code": "#include\nusing namespace std;\nint main(){\nlong long int k,a,b;\ncin>>k>>a>>b;\nif((a/k)+(b/k)==0)\n cout<<\"-1\";\nelse\n{\n if(a>=k&&b>=k)\n cout<<(a/k)+(b/k);\n else\n {\n if(a!=0&&b!=0)\n {\n if(a%k!=0&&b%k!=0)\n cout<<\"-1\";\n else cout<<(a/k)+(b/k);\n }\n else\n {\n if(a%k==0&&b%k==0)\n cout<<(a/k)+(b/k);\n else cout<<\"-1\";\n }\n }\n}\n}", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"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\nlong long n;\nvector v;\n\nvoid gen(long long a)\n{\n if (a > 4444477777) return;\n long long x = a;\n int c4 = 0, c7 = 0;\n while(x)\n {\n long long l = x % 10;\n if (l == 4) ++c4;\n else if (l == 7) ++c7;\n x /= 10;\n }\n if (c4 == c7)\n {\n v.push_back(a);\n }\n gen(a * 10 + 4);\n gen(a * 10 + 7);\n return;\n}\n\nint main()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n #endif\n cin >> n;\n gen(0);\n sort(v.begin(), v.end());\n for (long long i : v)\n if (i >= n)\n {\n cout << i << endl;\n break;\n }\n return 0;\n}\n", "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"source_code": "#include \n\nint main()\n{\n int n; std::cin >> n;\n\n int res = 0;\n\n for (int i = 1; i < n; i++)\n {\n int x = i;\n bool b = true;\n for (int j = 0; j < n - 2; j++)\n {\n if (!((x - 1 + n) % n))\n {\n b = false;\n break;\n }\n x *= i;\n x %= n;\n }\n res += b && !((x - 1 + n) % n);\n }\n\n std::cout << res << std::endl;\n}", "src_uid": "3bed682b6813f1ddb54410218c233cff"} {"source_code": "#include\nusing namespace std;\nint isprime(int x)\n{\n int y=2;\n if(x==1 || x==0)return 0;\n while(y>n>>m;\n w=n+1;\n while(1)\n {\n if(isprime(w)==1)break;\n else w++;\n }\n if(w==m)cout<<\"YES\"<\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) x.begin(), x.end()\n#define sz(x) (int)(x).size()\n#define hash dhsjakhd\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\ntypedef vector vi;\ntypedef vector vl;\ntypedef long double ld;\n\nstruct FT {\n\tvector s;\n\tFT(int n) : s(n) {}\n\tvoid update(int pos, ll dif) { // a[pos] += dif\n\t\tfor (; pos < sz(s); pos |= pos + 1) s[pos] += dif;\n\t}\n\tll query(int pos) { // sum of values in [0, pos)\n\t\tll res = 0;\n\t\tfor (; pos > 0; pos &= pos - 1) res += s[pos-1];\n\t\treturn res;\n\t}\n\tint lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum\n\t\t// Returns n if no sum is >= sum, or -1 if empty sum is.\n\t\tif (sum <= 0) return -1;\n\t\tint pos = 0;\n\t\tfor (int pw = 1 << 25; pw; pw >>= 1) {\n\t\t\tif (pos + pw <= sz(s) && s[pos + pw-1] < sum)\n\t\t\t\tpos += pw, sum -= s[pos-1];\n\t\t}\n\t\treturn pos;\n\t}\n};\n\nunsigned seed = std::chrono::system_clock::now().time_since_epoch().count();\nstd::mt19937 eng(seed);\n\nuniform_int_distribution<> DD(0, (1ll << 31));\n\nll random2(){\n return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);\n}\n\nll n,m,T,k,q;\n\nconst ll big = 1000000007;\nconst ll big2 = 1000000009;\nconst ll mod = 998244353;\n\nconst ll MAXN = 500001;\n\nvl x,X;\nvl y,Y;\nvl ind;\n\nbool solve(set &sx, set &SX, set &sy, set &SY){\n if(sz(sx) <= 1)return 1;\n int N = sz(sx);\n auto itx = sx.begin();\n auto ITX = SX.begin();\n auto ity = sy.begin();\n auto ITY = SY.begin();\n ll mx = -big;\n ll MX = big;\n ll my = -big;\n ll MY = big;\n vi news;\n //cerr << N << \"\\n\";\n rep(c1,0,N){\n\n pii px = *itx;\n if(itx != sx.begin() && px.first >= mx){\n auto it = sx.begin();\n while(it != itx){\n pii p = *it;\n news.push_back(p.second);\n it++;\n }\n break;\n }\n mx = max(mx, X[px.second]);\n itx++;\n\n pii py = *ity;\n if(ity != sy.begin() && py.first >= my){\n auto it = sy.begin();\n while(it != ity){\n pii p = *it;\n news.push_back(p.second);\n it++;\n }\n break;\n }\n my = max(my, Y[py.second]);\n ity++;\n\n\n pii PX = *ITX;\n if(ITX != SX.begin() && -PX.first <= MX){\n auto it = SX.begin();\n while(it != ITX){\n pii p = *it;\n news.push_back(p.second);\n it++;\n }\n break;\n }\n MX = min(MX, x[PX.second]);\n ITX++;\n\n pii PY = *ITY;\n if(ITY != SY.begin() && -PY.first <= MY){\n auto it = SY.begin();\n while(it != ITY){\n pii p = *it;\n news.push_back(p.second);\n it++;\n }\n break;\n }\n MY = min(MY, y[PY.second]);\n ITY++;\n\n }\n if(sz(news) == 0)return 0;\n set sx2,SX2,sy2,SY2;\n rep(c1,0,sz(news)){\n int a = news[c1];\n sx.erase({x[a],a});\n sx2.insert({x[a],a});\n\n SX.erase({-X[a],a});\n SX2.insert({-X[a],a});\n\n sy.erase({y[a],a});\n sy2.insert({y[a],a});\n\n SY.erase({-Y[a],a});\n SY2.insert({-Y[a],a});\n }\n return (solve(sx,SX,sy,SY) && solve(sx2,SX2,sy2,SY2));\n}\n\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n\n //freopen(\"input.txt\",\"r\",stdin);\n // freopen(\"autput.txt\",\"w\",stdout);\n\n ll a,b,c,d;\n cin >> n;\n set sx;\n set SX;\n set sy;\n set SY;\n\n rep(c1,0,n){\n cin >> a >> b >> c >> d;\n x.push_back(a);\n X.push_back(c);\n y.push_back(b);\n Y.push_back(d);\n ind.push_back(c1);\n sx.insert({a,c1});\n SX.insert({-c,c1});\n sy.insert({b,c1});\n SY.insert({-d,c1});\n }\n\n bool ans = solve(sx,SX,sy,SY);\n if(ans){\n cout << \"YES\\n\";\n }\n else{\n cout << \"NO\\n\";\n }\n\n return 0;\n}\n", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37"} {"source_code": "#include \n\nusing namespace std;\n\nconst int MOD = 1e9 + 7;\n\nint main()\n{\n vector k(3);\n cin >> k[0] >> k[1] >> k[2];\n\n sort(k.begin(), k.end());\n\n if (k[0] == 1)\n {\n cout << \"YES\";\n return 0;\n }\n\n vector times(1e5, 0);\n for (int i = 0; i < 1e5; i += k[2])\n times[i] = 1;\n\n for (int i = 1; i < 1e5; i += k[1])\n times[i] = 1;\n\n int i;\n for (i = 2; i < 1e5; i++)\n {\n if (times[i] == 0 && ((k[0] == 2 && i % 2 != 0) || (k[0] != 2 && i % k[0] != 2)))\n {\n break;\n }\n }\n if (i == 1e5)\n {\n cout << \"YES\";\n return 0;\n }\n\n times = vector(1e5, 0);\n\n swap(k[0], k[1]);\n for (int i = 0; i < 1e5; i += k[2])\n times[i] = 1;\n\n for (int i = 1; i < 1e5; i += k[1])\n times[i] = 1;\n\n for (i = 2; i < 1e5; i++)\n {\n if (times[i] == 0 && ((k[0] == 2 && i % 2 != 0) || (k[0] != 2 && i % k[0] != 2)))\n {\n cout << \"NO\";\n return 0;\n }\n }\n\n cout << \"YES\";\n return 0;\n}\n", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"source_code": "#include\nusing namespace std;\n\n\nint main(){\n int k,n,w, totalCost;\n cin>>k>>n>>w;\n totalCost = w*(w+1)/2*k;\n if(totalCost <= n) cout<<0;\n else cout<\n#define F(i,j,k) for(int i=(j);i<=(k);i++)\nusing namespace std;\n\nnamespace Base {\n\tinline char gc(void)\n\t{\n\t\tstatic char buf[100000], *p1 = buf, *p2 = buf;\n\t\treturn p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;\n\t}\n\n\ttemplate inline void read(T &x)\n\t{\n\t\tT flag = (T) 1; x = 0; static char ch = gc();\n\t\tfor (; ch > '9' || ch < '0'; ch = gc())\n\t\t\tflag = ch == '-' ? -1 : 1;\n\t\tfor (; ch >= '0' && ch <= '9'; ch = gc())\n\t\t\tx = (x << 1) + (x << 3) + (ch & 15);\n\t\tx *= flag; return;\n\t}\n\n\tint wbuf[25], _wl = 0;\n\ttemplate inline void write(T x) {\n\t\tif (x == 0) { putchar(48); return; }\n\t\tif (x < 0) putchar('-'), x = -x; _wl = 0;\n\t\twhile (x) wbuf[++_wl] = x % 10, x /= 10;\n\t\tfor (int i = _wl; i >= 1; i--) putchar(wbuf[i] + 48);\n\t}\n\n\ttemplate inline void writeln(T x) { write(x); puts(\"\"); }\n\ttemplate inline void writeln(T x, char c) { write(x); putchar(c); }\n\ttemplate inline void writeln(char c, T x) { putchar(c); write(x); }\n}\n\nusing namespace Base;\n\nconst int N=1e6+100;\nint x[N],y[N],w[N],s[N],v[N];\nbool in[N*2];\nvector > e[N];\nvector res; int n, m;\nint main(){\n \tread(n), read(m);\n \tF(i,1,m){\n \t\tread(x[i]), read(y[i]); w[i]=1;s[x[i]]++;s[y[i]]++;\n \t\te[max(x[i],y[i])].push_back(make_pair(min(x[i],y[i]),i));\n \t}\n \tF(i,1,n){\n \t\tfor(auto it:e[i]){if(!v[it.first]){v[it.first]=1;w[it.second]=0;s[i]--;}in[s[it.first]]=1;}\n \t\tfor(auto it:e[i]){if(!in[s[i]])break;s[i]++;v[it.first]=0;w[it.second]++;}\n \t\tfor(auto it:e[i])in[s[it.first]]=0;\n \t}\n \tF(i,1,n)if(v[i])res.push_back(i);\n \twriteln(int(res.size()));\n \tfor(auto it:res)writeln(it, ' ');puts(\"\");\n \tF(i,1,m) writeln(x[i], ' '), writeln(y[i], ' '), writeln(w[i]);\n return 0;\n}", "src_uid": "6e184abbbc3ca323c8c092ef727cc7a1"} {"source_code": "#include \n\n#define pb push_back\n#define pob pop_back\n#define ll long long\n#define pll pair < ll, ll >\n#define fi first\n#define se second\n#define sefi second.first\n#define sese second.second\n\nusing namespace std;\n\n\nll n, s = 0, ans1 , r, ans = 0, b, c, a;\nint main(){\n cin >> n >> a >> b >> c;\n if(n >= b && a >= b - c){\n r = (n - b) / (b - c) + 1;\n ans += r;\n n -= r * (b - c);\n }\n ans += n / a;\n cout << ans;\n\n}\n", "src_uid": "0ee9abec69230eab25de51aef0984f8f"} {"source_code": "#include \n//#include\n#include \n\nusing namespace std;\n\n#pragma warning(disable:4996)\n\nconst int MAXN = 1e5 + 10;\n\nlong long n, m, ad[MAXN], ac[MAXN], bd[MAXN], bc[MAXN], indsa[MAXN], indsb[MAXN], pr[MAXN], d, prc[MAXN];\n\nbool keya(int x, int y) {\n\tif (ac[x] == ac[y]) return ad[x] < ad[y];\n\treturn ac[x] > ac[y];\n}\n\nbool keyb(int x, int y) {\n\tif (bc[x] == bc[y]) return bd[x] < bd[y];\n\treturn bc[x] > bc[y];\n}\n\nint main() {\n#ifdef _DEBUG\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\tcin >> n >> m >> d;\n\tfor (int i = 0; i < n; i++) {\n\t\tcin >> ac[i] >> ad[i];\n\t\tindsa[i] = i;\n\t}\n\tfor (int i = 0; i < m; i++) {\n\t\tcin >> bc[i] >> bd[i];\n\t\tindsb[i] = i;\n\t}\n\tsort(indsa, indsa + n, keya);\n\tsort(indsb, indsb + m, keyb);\n\tfor (int i = 0; i < m; i++) {\n\t\tpr[i] = ((i > 0) ? pr[i - 1] : 0) + bd[indsb[i]];\n\t\tprc[i] = ((i > 0) ? prc[i - 1] : 0) + bc[indsb[i]];\n\t}\n\tlong long kol = 0;\n\tlong long ans = 0;\n\tlong long koks = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tkol += ad[indsa[i]];\n\t\tkoks += ac[indsa[i]];\n\t\tint l = -1;\n\t\tint r = m;\n\t\twhile (r - l > 1) {\n\t\t\tint mid = r + l >> 1;\n\t\t\tif (pr[mid] + kol <= d) {\n\t\t\t\tl = mid;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tr = mid;\n\t\t\t}\n\t\t}\n\t\tif (l != -1) {\n\t\t\tans = max(ans, koks + prc[l]);\n\t\t\t//cout << ans << \" \" << i << \" \" << l << \"\\n\";\n\t\t}\n\t}\n\tcout << ans;\n\treturn 0;\n}", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"} {"source_code": "#include\n \nusing namespace std;\n\ntypedef long long ll;\n\nconst ll M = 1e9+7;\n\nll pw(ll a, ll b){\n\tll ret = 1;\n\twhile(b){\n\t\tif(b&1){ ret = ret * a % M; }\n\t\tb>>=1;\n\t\ta = a * a % M;\n\t}\n\treturn ret;\n}\n\nvoid solve(){\n\tll n, m, k, r, c; cin >> n >> m >> k >> r >> c;\n\tll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;\n\tif(x1 > x2)swap(x1,x2);\n\tif(y1 > y2)swap(y1,y2);\n\tll ans = 1;\n\tll sz1 = r*c, sz2 = sz1;\n\tif(x1+r-x2 > 0 && y1+c-y2 > 0) sz2-= (x1+r-x2)*(y1+c-y2);\n\tif(!sz2)ans*=(pw(k,sz1));\n\telse ans*=(pw(k,sz2));\n\tans%=M;\n\tans*=(pw(k,n*m-sz1-sz2));\n\tans%=M;\n\tcout << ans << '\\n';\n\n\n}\n\nint main(){\n\tios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n\tsolve();\n}\n\n", "src_uid": "3478e6a4ff2415508fd517413d40c13a"} {"source_code": "#define _CRT_SECURE_NO_WARNINGS true\n\n#include \nint main(){\n\tint n, s;\n\tscanf(\"%d%d\", &n, &s);\n\tint max = 0;\n\tfor (int i = 0; i < n; i++){\n\t\tint a;\n\n\t\tscanf(\"%d\", &a);\n\t\tif (a>max)\n\t\t\tmax = a;\n\t\ts -= a;\n\t}\n\ts += max;\n\tif (s < 0)\n\t\tprintf(\"NO\");\n\telse\n\t\tprintf(\"YES\");\n\treturn 0;\n}", "src_uid": "496baae594b32c5ffda35b896ebde629"} {"source_code": "#include\nusing namespace std;\nlong long int ans=0,num=0;\nstring a[50];\nint main()\n{\n\tint i,n,p;\n\tscanf(\"%d%d\",&n,&p);\n\tp/=2;\n\tfor(i=1;i<=n;i++)\n\tcin>>a[i];\n\tfor(i=n;i>=1;i--)\n\t{\n\t\tnum*=2;\n\t\tif(a[i]==\"halfplus\")\n\t\tnum++;\n\t\tans+=num;\n\t}\n\tans*=p;\n\tprintf(\"%lld\",ans);\n}", "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n\tlong long n,k;\n\tcin>>n>>k;\n\tlong long minv=min(n,(long long)65000);\n\tfor(long long i=minv;i>=0;i--)\n\t{\n\t\tif((i*i+i)/2-n+i==k)\n\t\t{\n\t\t\tcout<\n#include \nusing namespace std;\n\nint main()\n{ string arrangement;\n int cnt = 0,i;\n cin >> arrangement;\n char value = arrangement[0];\n for(i = 0; i \n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nconst double eps=1e-10;\nconst int SIZEN=110,SIZEM=5010;\nvoid Gauss_Jordan(double A[SIZEN][SIZEN],double b[SIZEN],int N){\n\t//for(int i=1;i<=N;i++){for(int j=1;j<=N+1;j++) cout<fabs(A[r][j])) r=i;\n\t\t}\n\t\tfor(int k=1;k<=N+1;k++) swap(A[r][k],A[j][k]);\n\t\tif(fabs(A[j][j])\nusing namespace std;\nconst int MAXN = 100005;\nusing lint = long long;\nusing pi = pair;\n \nstruct edg{\n\tint pos; lint cst;\n\tint idx;\n};\n \nint n, q; lint w;\nvector gph[MAXN];\nvector updList[MAXN];\nbool vis[MAXN];\n\nstruct segtree{\n\tvector tree, lazy;\n\tint lim;\n\tvoid init(int n){\n\t\tfor(lim = 1; lim <= n; lim <<= 1);\n\t\ttree.resize(2 * lim);\n\t\tlazy.resize(2 * lim);\n\t}\n\tvoid lazydown(int p){\n\t\tlint cur = lazy[p]; lazy[p] = 0;\n\t\tfor(int j=0; j<2; j++){\n\t\t\tlazy[2*p+j] += cur;\n\t\t\ttree[2*p+j] += cur;\n\t\t}\n\t}\n\tvoid add(int s, int e, int ps, int pe, int p, lint v){\n\t\tif(e < ps || pe < s) return;\n\t\tif(s <= ps && pe <= e){\n\t\t\ttree[p] += v;\n\t\t\tlazy[p] += v;\n\t\t\treturn;\n\t\t}\n\t\tint pm = (ps+pe)/2;\n\t\tlazydown(p);\n\t\tadd(s, e, ps, pm, 2*p, v);\n\t\tadd(s, e, pm+1, pe, 2*p+1, v);\n\t\ttree[p] = max(tree[2*p], tree[2*p+1]);\n\t}\n\tlint query(int s, int e, int ps, int pe, int p){\n\t\tif(e < ps || pe < s) return -1e18;\n\t\tif(s <= ps && pe <= e) return tree[p];\n\t\tint pm = (ps + pe) / 2;\n\t\tlazydown(p);\n\t\treturn max(query(s, e, ps, pm, 2*p), query(s, e, pm+1, pe, 2*p+1));\n\t}\n};\n\nstruct dcmp{\n\tint idx;\n\tmap din, dout;\n\tint piv;\n\tvector ds;\n\tvector intv;\n\tvector assoc;\n\tmultiset maxVal;\n\tlint ans;\n\n\tsegtree DS;\n}cd[MAXN];\n\npriority_queue> pq;\n\nlint query(){\n\twhile(!pq.empty() && cd[pq.top().second].ans != pq.top().first){\n\t\tpq.pop();\n\t}\n\tif(pq.empty()) return 0;\n\treturn pq.top().first;\n}\n \nvoid update(int e, int x, int y, lint d){\n\tfor(auto &i : updList[e]){\n\t\tif(cd[i].din[x] > cd[i].din[y]) swap(x, y);\n\t\tint l = cd[i].din[y];\n\t\tint r = cd[i].dout[y];\n\n\t\tcd[i].DS.add(l, r - 1, 0, cd[i].piv - 1, 1, d);\n\n\t\tint pos = lower_bound(cd[i].intv.begin(), cd[i].intv.end(), pi(l, 1e9)) \n\t\t- cd[i].intv.begin() - 1;\n\t\tcd[i].maxVal.erase(cd[i].maxVal.find(cd[i].assoc[pos]));\n\n\t\tcd[i].assoc[pos] = \n\t\tcd[i].DS.query(cd[i].intv[pos].first, cd[i].intv[pos].second - 1, \n\t\t0, cd[i].piv - 1, 1);\n\n\t\tcd[i].maxVal.insert(cd[i].assoc[pos]);\n\t\tassert(cd[i].maxVal.size());\n\t\tif(cd[i].maxVal.size() == 1) cd[i].ans = *cd[i].maxVal.rbegin();\n\t\telse{\n\t\t\tauto cur = prev(cd[i].maxVal.end());\n\t\t\tcd[i].ans = *cur + *prev(cur);\n\t\t}\n\t\tpq.emplace(cd[i].ans, i);\n\t}\n}\n \nvoid dfs(int x, int p, dcmp &cd){\n\tcd.din[x] = cd.piv++;\n\tfor(auto &i : gph[x]){\n\t\tif(i.pos != p && !vis[i.pos]){\n\t\t\tupdList[i.idx].push_back(cd.idx);\n\t\t\tdfs(i.pos, x, cd);\n\t\t}\n\t}\n\tcd.dout[x] = cd.piv;\n}\n\nvoid sangsoo(int x, int p, dcmp &cd){\n\tfor(auto &i : gph[x]){\n\t\tif(i.pos != p && !vis[i.pos]){\n\t\t\tcd.DS.add(cd.din[i.pos], cd.dout[i.pos] - 1, 0, cd.piv - 1, 1, i.cst);\n\t\t\tsangsoo(i.pos, x, cd);\n\t\t}\n\t}\n}\n\nvoid build(int v, dcmp &cd){\n\tcd.idx = v;\n\tdfs(v, -1, cd);\n\tcd.DS.init(cd.piv);\n\tsangsoo(v, -1, cd);\n\tfor(auto &i : gph[v]){\n\t\tif(vis[i.pos]) continue;\n\t\tcd.intv.emplace_back(cd.din[i.pos], cd.dout[i.pos]);\n\t}\n\tsort(cd.intv.begin(), cd.intv.end());\n\tfor(int i=0; i dfn;\nint sz[MAXN], msz[MAXN];\n \nvoid dfsc(int x, int p){\n\tdfn.push_back(x);\n\tsz[x] = 1;\n\tmsz[x] = 0;\n\tfor(auto &i : gph[x]){\n\t\tif(!vis[i.pos] && i.pos != p){\n\t\t\tdfsc(i.pos, x);\n\t\t\tsz[x] += sz[i.pos];\n\t\t\tmsz[x] = max(msz[x], sz[i.pos]);\n\t\t}\n\t}\n}\n \nint get_center(int x){\n\tdfsc(x, -1);\n\tpi ret(1e9, 1e9);\n\tfor(auto &i : dfn){\n\t\tint mxv = max(msz[i], (int)dfn.size() - sz[i]);\n\t\tret = min(ret, pi(mxv, i));\n\t}\n\tdfn.clear();\n\treturn ret.second;\n}\n \nint main(){\n\tlint w;\n\tscanf(\"%d %d %lld\",&n,&q,&w);\n\tvector S(n - 1), E(n - 1); \n\tvector X(n - 1);\n\tfor(int i=0; i que;\n\tque.push(1);\n\twhile(!que.empty()){\n\t\tint x = que.front(); que.pop();\n\t\tx = get_center(x);\n\t\tbuild(x, cd[x]);\n\t\tvis[x] = 1;\n\t\tfor(auto &i : gph[x]){\n\t\t\tif(!vis[i.pos]){\n\t\t\t\tque.push(i.pos);\n\t\t\t}\n\t\t}\n\t}\n\tlint last = 0;\n\twhile(q--){\n\t\tlint d, e; scanf(\"%lld %lld\",&d,&e);\n\t\td = (d + last) % (n - 1);\n\t\te = (e + last) % w;\n\t\tupdate(d, S[d], E[d], e - X[d]);\n\t\tX[d] = e;\n\t\tlast = query();\n\t\tprintf(\"%lld\\n\", last);\n\t}\n}\n\n", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c"} {"source_code": "#include\n#include\n#include\nusing namespace std;\ninline int gi()\n{\n\tchar c;int num=0,flg=1;\n\twhile((c=getchar())<'0'||c>'9')if(c=='-')flg=-1;\n\twhile(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}\n\treturn num*flg;\n}\n#define N 300005\nint fir[N],to[4*N],nxt[4*N],cnt;\nvoid adde(int a,int b)\n{\n\tto[++cnt]=b;nxt[cnt]=fir[a];fir[a]=cnt;\n\tto[++cnt]=a;nxt[cnt]=fir[b];fir[b]=cnt;\n}\n\nint bel[N];// !!!\nnamespace BBC{\n\tint dfn[N],low[N],bbcno[N],stk[N],top,dc,bbccnt;\n\tvoid dfs(int u,int ff){\n\t\tdfn[u]=low[u]=++dc;\n\t\tstk[top++]=u;\n\t\tfor(int v,p=fir[u];p;p=nxt[p]){\n\t\t\tif((p^1)==ff)continue;\n\t\t\tv=to[p];\n\t\t\tif(!dfn[v]){dfs(v,p);low[u]=min(low[u],low[v]);}\n\t\t\telse low[u]=min(low[u],dfn[v]);\n\t\t}\n\t\tif(dfn[u]==low[u]){\n\t\t\tbbccnt++;\n\t\t\twhile(top>0){\n\t\t\t\tbbcno[stk[--top]]=bbccnt;\n\t\t\t\tif(stk[top]==u)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}//----BBC----\n\nint root[N],nowrt,dep[N],fa[N],siz[N],son[N],top[N];\nvoid dfs1(int u)\n{\n\troot[u]=nowrt;\n\tdep[u]=dep[fa[u]]+1;siz[u]=1;\n\tfor(int v,p=fir[u];p;p=nxt[p]){\n\t\tif((v=to[p])!=fa[u]){\n\t\t\tfa[v]=u;dfs1(v);\n\t\t\tsiz[u]+=siz[v];\n\t\t\tif(siz[son[u]]1)adde(stk[tp-1],stk[tp]),tp--;tp=0;\n\t\t\tif(u!=root[u])dl[++dcnt]=stk[++tp]=root[u];\n\t\t}\n\t\tif(i<=1||(lca=LCA(stk[tp],u))==stk[tp]){stk[++tp]=u;continue;}\n\t\twhile(tp>1&&dep[stk[tp-1]]>=dep[lca]){adde(stk[tp-1],stk[tp]);tp--;}\n\t\tif(lca!=stk[tp]){adde(lca,stk[tp]);stk[tp]=lca;dl[++dcnt]=lca;}\n\t\tstk[++tp]=u;\n\t}\n\twhile(tp>1)adde(stk[tp-1],stk[tp]),tp--;\n}\nvoid CL()\n{\n\tfor(int i=1,u;i<=dcnt;i++){\n\t\tfir[u=dl[i]]=0;\n\t\tBBC::dfn[u]=BBC::bbcno[u]=BBC::low[u]=0;\n\t}\n\tcnt=1;dcnt=0;BBC::dc=BBC::top=BBC::bbccnt=0;\n}\nstruct enode{int u,v;}e[N],etmp[N];\nbool pd[N];int ptmp[N];\nint main()\n{\n\t//freopen(\"3.in\",\"r\",stdin);\n\tcnt=1;\n\tint n,m,Q,i,u,v;\n\tn=gi();m=gi();Q=gi();\n\tfor(i=1;i<=m;i++){\n\t\tu=gi();v=gi();adde(u,v);\n\t\te[i].u=u;e[i].v=v;\n\t}\n\tfor(i=1;i<=n;i++)if(!dfn[i])BBC::dfs(i,0);\n\tcnt=1;memset(fir,0,sizeof(fir));\n\tmemcpy(bel,BBC::bbcno,sizeof(BBC::bbcno));\n\t//printf(\"bel:\");for(i=1;i<=n;i++)printf(\"%d \",bel[i]);printf(\"\\n\");\n\t\n\tfor(i=1;i<=m;i++){\n\t\tint p=bel[e[i].u],q=bel[e[i].v];\n\t\tif(p!=q)adde(p,q);//,printf(\"adde:%d %d\\n\",p,q);\n\t}\n\tfor(i=1;i<=BBC::bbccnt;i++){\n\t\tif(root[i])continue;\n\t\tnowrt=i;dfs1(i);top[i]=i;dfs2(i);\n\t}\n\t//printf(\"root:\");for(i=1;i<=BBC::bbccnt;i++)printf(\"%d \",root[i]);printf(\"\\n\");\n\t\n\tmemset(BBC::dfn,0,sizeof(BBC::dfn));\n\tmemset(BBC::low,0,sizeof(BBC::low));\n\tmemset(BBC::bbcno,0,sizeof(BBC::bbcno));\n\tBBC::dc=BBC::top=BBC::bbccnt=0;\n\tcnt=1;memset(fir,0,sizeof(fir));\n\tint R=0,nn,mm,cas=0;\n\twhile(Q--){\n\t\tcas++;\n\t\tnn=gi();mm=gi();\n\t\tfor(i=1;i<=nn;i++){\n\t\t\tu=ptmp[i]=bel[(gi()+R-1)%n+1];\n\t\t\tif(!pd[u])dl[++dcnt]=u,pd[u]=1;\n\t\t}\n\t\tfor(i=1;i<=mm;i++){\n\t\t\tetmp[i].u=u=bel[(gi()+R-1)%n+1];\n\t\t\tetmp[i].v=v=bel[(gi()+R-1)%n+1];\n\t\t\tif(!pd[u])dl[++dcnt]=u,pd[u]=1;\n\t\t\tif(!pd[v])dl[++dcnt]=v,pd[v]=1;\n\t\t}\n\t\tbuild();\n\t\tfor(i=1;i<=mm;i++){\n\t\t\tint p=etmp[i].u,q=etmp[i].v;\n\t\t\tif(p!=q)adde(p,q);//,printf(\"adde:%d %d\\n\",p,q);\n\t\t}\n\t\tfor(i=1;i<=dcnt;i++)\n\t\t\tif(!BBC::dfn[dl[i]])BBC::dfs(dl[i],0);\n\t\t//printf(\"bbcno:\");for(i=1;i<=n;i++)printf(\"%d \",BBC::bbcno[i]);printf(\"\\n\");\n\t\tbool flg=0;\n\t\tfor(i=1;i<=nn;i++)\n\t\t\tif(BBC::bbcno[ptmp[i]]!=BBC::bbcno[ptmp[1]]){flg=1;break;}\n\t\tif(!flg){printf(\"YES\\n\");R=(R+cas)%n;}\n\t\telse printf(\"NO\\n\");\n\t\tCL();\n\t\tfor(i=1;i<=nn;i++)pd[ptmp[i]]=0;\n\t\tfor(i=1;i<=mm;i++)pd[etmp[i].u]=pd[etmp[i].v]=0;\n\t}\n}", "src_uid": "53f64841886b32816eadce278e636bbc"} {"source_code": "#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tint n,i,j,k,g=0;\n\tscanf(\"%d\",&n);\n\tint a[n+1],c[n+1],h=0;\n \tfor(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#include \n#include \n#include \n#define LL long long\n#define rei(x) scanf(\"%d\",&x)\n#define rel(x) scanf(\"%I64d\",&x)\n#define fi first\n#define se second\n#define mp make_pair\n#define pb push_back\n#define f(i, a, b) for(int i = a; i <= b; i++)\n#define ms(Arr) memset(Arr,0,sizeof(Arr));\n#define CLR(arr,val) memset(arr,val,sizeof(arr)) \n\nusing namespace std;\nconst int INF = 0x3f3f3f3f;\nconst LL mod = 1000000007;\nconst double eps = 1e-6;\nconst double pi = acos(1.0*(-1));\ntypedef pair Pii;\ntypedef pair Pll;\n\n//最大公因数\nint gcd(int a, int b)\n{\n\tif (!b)return a;\n\treturn gcd(b, a%b);\n}\n\n//快速幂取模\nint PowerMod(int a, int b, int c)\n\n{\n\n\tint ans = 1;\n\n\ta = a % c;\n\n\twhile (b > 0)\n\n\t{\n\n\t\tif (b % 2 == 1)\n\n\t\t\tans = (ans * a) % c;\n\n\t\tb = b / 2;\n\n\t\ta = (a * a) % c;\n\n\t}\n\n\treturn ans;\n\n}\n\n//幂函数\nint p(int a, int b)\n{\n\tint ans = 1;\n\tfor (int i = 0; i < b;i++)\n\t\tans *= a;\n\treturn ans;\n}\n\nconst int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };\nconst int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };\n\n//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//long long 范围:-9223372036854775808~9223372036854775807\n//int 范围:-2147483648~2147483647\n//double 范围:-1.7*10^-308~1.7*10^308,15~16位有效数字\n//long double 范围:-1.2*10^-4932~1.2*10^4932,18~19位有效数字\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nLL sum(LL a)\n{\n\tLL res = 0;\n\twhile (a)\n\t{\n\t\tres += a % 10;\n\t\ta /= 10;\n\t}\n\treturn res;\n}\nint main()\n{\n\tLL n, s;\n\trel(n);\n\trel(s);\n\tLL l = 1,r = n;\n\twhile (r > l)\n\t{\n\t\tLL mid = (l + r) / 2;\n\t\tif (mid - sum(mid) >= s)\n\t\t\tr = mid;\n\t\telse\n\t\t\tl = mid + 1;\n\t}\n\tLL ans = n - r;\n\tif (n - sum(n) >= s)\n\t\tans++;\n\tprintf(\"%I64d\\n\", ans);\n\treturn 0;\n}\n\n\n\n\n \t \t \t \t \t \t \t \t\t\t \t\t", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"source_code": "#include \n#include \nusing namespace std;\n\n#define ll unsigned long long\n#define P 31415927\n#define Q 8592637\n\nstruct hash{\n\tint head[Q], next[Q], t;\n\tll lk[Q];\n\tdouble x[Q];\n\n\tdouble find(ll s){\n\t\tfor(int i=head[s%Q]; i; i=next[i]) if(lk[i]==s) return x[i];\n\t\treturn -1;\n\t}\n\n\tvoid ins(ll s,double f){\n\t\tif(find(s)>-1) return;\n\t\tlk[++t]=s, x[t]=f, next[t]=head[s%Q], head[s%Q]=t;\n\t}\n} H;\n\nint N, a[105], F[256], b[105];\n\ninline int G(int x){ return !!x; }\n\ninline void get(int x,int*a){ a[0]=(x>>4)&3, a[1]=(x>>2)&3, a[2]=x&3; }\n\ninline int BG(int a,int b,int c){\n\tif(a>c) swap(a,c);\n\treturn (((a<<2)+b)<<2)+c;\n}\n\nvoid init(){\n\tscanf(\"%d\",&N), F['G']=1, F['B']=2, F['R']=3;\n\tchar s[4];\n\tfor(int i=1; i<=N; i++)\n scanf(\"%s\",s), a[i]=BG(F[s[0]],F[s[1]],F[s[2]]);\n}\n\nll Hash(int n){\n\tll s=0;\n\tfor(int i=1; i<=n; i++) b[i]=a[i];\n\tsort(b+1,b+n);\n\tfor(int i=1; i<=n; i++) (s*=P)+=b[i];\n\treturn s;\n}\n\ndouble dfs(int n){\n\tll s=Hash(n);\n\tdouble f=H.find(s), c[4]={0,1e9,1e9,1e9};\n\tif(f>-1) return f;\n\tfor(int i=1; i\nusing namespace std;\nint main()\n{\n\tint n,t0=0,t1=0;\n\tchar a[101];\n\tcin>>n;\n\tfor(int i=0;i>a[i];\n\t\tif(a[i]=='0')\n\t\t\tt0++;\n\t\telse\n\t\t\tt1++;\n\t}\n\tif(t0==t1)\n\t{\n\t\tcout<<2<\nusing namespace std;\nint main()\n{\n\tint num,n=1,m=1;\n\tcin>>num;\n\tfor(int i=1;;i++)\n\t{\n\t\tn=pow(2,2*i-1)-(pow(2,i-1));\n\t\tif(n<=num && num%n==0)\n\t\t\tm=n;\n\t\telse if(n>num)\n\t\t\tbreak;\n\t}\n\tcout<\nusing namespace std;\nconst int N = 1e8;\n\nset a;\n\nvoid work(int l, int r) {\n int m = (l + r) / 2, d, d2;\n if (m == l || m == r)\n return;\n printf(\"0 %d %d\\n\", m, m);\n fflush(stdout);\n scanf(\"%d\", &d);\n if (m - d > l) {\n printf(\"0 %d %d\\n\", m - d, m - d);\n fflush(stdout);\n scanf(\"%d\", &d2);\n if (!d2) {\n a.insert(m - d);\n work(l, m - d);\n work(m - d, r);\n return;\n }\n }\n if (m + d < r) {\n printf(\"0 %d %d\\n\", m + d, m + d);\n fflush(stdout);\n scanf(\"%d\", &d2);\n if (!d2) {\n a.insert(m + d);\n work(l, m + d);\n work(m + d, r);\n return;\n }\n }\n}\n\nint main() {\n int dx, dy;\n printf(\"0 %d %d\\n0 %d %d\\n\", -N, -N, N, N);\n fflush(stdout);\n scanf(\"%d%d\", &dx, &dy);\n dx = dx - N;\n dy = N - dy;\n a.insert(dx);\n a.insert(dy);\n work(dx, dy);\n\n int z = 0;\n while (a.count(z))\n ++z;\n vector x, y;\n for (int i : a) {\n printf(\"0 %d %d\\n0 %d %d\\n\", i, z, z, i);\n fflush(stdout);\n scanf(\"%d%d\", &dx, &dy);\n if (!dx)\n x.push_back(i);\n if (!dy)\n y.push_back(i);\n }\n printf(\"1 %d %d\\n\", (int)x.size(), (int)y.size());\n for (int i : x)\n printf(\"%d \", i);\n puts(\"\");\n for (int i : y)\n printf(\"%d \", i);\n puts(\"\");\n return 0;\n}\n", "src_uid": "583cd1e553133b297f99fd52e5ad355b"} {"source_code": "using namespace std;\n#include\n#include \ntypedef long long int ll;\ntypedef long double ld;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//#define N 4\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define PI 3.14159265358979323846264338327950\n#define mp make_pair\n#define inf 1e9\n#define M 1000000007\n#define N 100005\n\nint main() {\n\n\tios::sync_with_stdio(0);\n\tcin.tie(0);\n\n\tint a, b, c;\n\tcin >> a >> b >> c;\n\n\tfor (int x = 0; x <= 1e6; x++) {\n\t\tint y = b - x;\n\t\tint z = a - x;\n\n\t\tif (x >= 0 && y >= 0 && z >= 0 && z + y == c) {\n\t\t\tcout << x << \" \" << y << \" \" << z << endl;\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tcout << \"Impossible\" << endl;\n}\n\n", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"source_code": "#include\n#define ll long long\n#define endl \"\\n\"\n#define pb push_back\n#define READ(FILE) freopen(FILE,\"r\",stdin)\n#define WRITE(FILE) freopen(FILE,\"w\",stdout)\nusing namespace std;\nvoid mego()\n{\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n}\nll calc(ll x)\n{\n return ((x*(x+1))/2);\n}\nint main()\n{\n\n mego();\n int n,m,k=0,x,y,cost=0;\n cin>>n;\nvector v;\nfor(int i=0;i>x;\n v.pb(x);\n}\nsort(v.begin(),v.end());\nfor(int i=0;iv[i+2] && v[i]+v[i+2] >v[i+1])\nreturn cout<<\"YES\",0;\ncout<<\"NO\";\n return 0;\n}\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "#define _CRT_SECURE_NO_WARNINGS\n#pragma comment(linker,\"/STACK:64000000\")\n#include \n#include \n#include \n#include \n#include \n#include \n#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 unsigned long long ul;\ntypedef pair pii;\ntypedef vector vi;\ntypedef vector vll;\ntypedef vector vvi;\ntypedef vector vvll;\ntypedef pair pll;\ntypedef pair psi;\n\n#define pb push_back\n#define mp make_pair\n#define eps 1e-7\n#define PI 3.14159265358979323846\n#define X first\n#define Y second\n#define ACCEPTED return 0;\n\nint main() {\n#ifdef _DEBUG\n\tfreopen(\"input.txt\", \"rt\", stdin);\n\tfreopen(\"output.txt\", \"wt\", stdout);\n#endif\n\tint usab[6][8] = {\n\t\t{ 3, 3, 0, 4, 4, 0, 3, 3 },\n\t\t{ 3, 3, 0, 4, 4, 0, 3, 3 },\n\t\t{ 2, 2, 0, 3, 3, 0, 2, 2 },\n\t\t{ 2, 2, 0, 3, 3, 0, 2, 2 },\n\t\t{ 1, 1, 0, 2, 2, 0, 1, 1 },\n\t\t{ 1, 1, 0, 2, 2, 0, 1, 1 }\n\t};\n\tstring A[6];\n\tint max = 0, x, y;\n\tfor (int i = 0; i < 6; i++) cin >> A[i];\n\tfor (int i = 0; i < 6; i++)\n\t\tfor (int j = 0; j < 8; j++)\n\t\t\tif (A[i][j] == '.' && usab[i][j] > max) {\n\t\t\t\tmax = usab[i][j];\n\t\t\t\tx = i;\n\t\t\t\ty = j;\n\t\t\t}\n\tA[x][y] = 'P';\n\tfor (int i = 0; i < 6; i++) cout << A[i] << endl;\n\tACCEPTED\n}\n", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"source_code": "#include \n#include \n#include \n#include \nusing namespace std;\ndouble a[55][55], b[55][55];\nint n; double P;\ndouble f[55][55];\nstruct matrix {\n\tdouble a[55][55]; int l1, l2;\n\tmatrix operator*(const matrix &A) const {\n\t\tmatrix ret;\n\t\tmemset(ret.a, 0, sizeof(ret.a));\n\t\tret.l1 = l1; ret.l2 = A.l2;\n\t\tfor(int i = 1; i <= ret.l1; i++){\n\t\t\tfor(int j = 1; j <= ret.l2; j++){\n\t\t\t\tfor(int k = 1; k <= l2; k++) ret.a[i][j] += a[i][k]*A.a[k][j];\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n}x, z, fn;\nint main() {\n\tint i, j, k;\n\tscanf(\"%d%lf\", &n, &P);\n\tP /= 1e9;\n\ta[1][1] = P; a[1][2] = 1.0-P;\n\tb[1][2] = 1.0-P;\n\tfor(i = 2; i < 50; i++){\n\t\ta[i][1] = P; a[i][2] = 1.0-P;\n\t\tb[i][2] = 1.0-P;\n\t\tfor(j = 2; j <= 50; j++){\n\t\t\ta[i][j] += a[i][j-1]*a[i-1][j-1];\n\t\t\tb[i][j] += b[i][j-1]*a[i-1][j-1];\n\t\t}\n\t}\n\tif(n < 50){\n\t\tf[1][1] = 1; f[1][2] = 2;\n\t\tfor(i = 2; i <= n; i++){\n\t\t\tdouble sum = 0.0;\n\t\t\tfor(k = 2; k <= i; k++){\n\t\t\t\tf[i][1] += f[i-1][k]*b[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t\tsum += b[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t}\n\t\t\tf[i][1] /= sum;\n\t\t\tf[i][1] += 1.0;\n\t\t\tfor(j = 2; j <= 50; j++){\n\t\t\t\tsum = 0.0;\n\t\t\t\tfor(k = 1; k < j; k++){\n\t\t\t\t\tf[i][j] += f[i-1][k]*a[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t\t\tsum += a[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t\t}\n\t\t\t\tf[i][j] /= sum;\n\t\t\t\tf[i][j] += j;\n\t\t\t}\n\t\t}\n\t\tdouble ans = 0.0;\n\t\tfor(i = 1; i <= n+1; i++) ans += a[n][i]*(1.0-a[n-1][i])*f[n][i];\n\t\tprintf(\"%.10lf\\n\", ans);\n\t} else {\n\t\tf[1][1] = 1; f[1][2] = 2;\n\t\tfor(i = 2; i < 50; i++){\n\t\t\tdouble sum = 0.0;\n\t\t\tfor(k = 2; k <= i; k++){\n\t\t\t\tf[i][1] += f[i-1][k]*b[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t\tsum += b[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t}\n\t\t\tf[i][1] /= sum;\n\t\t\tf[i][1] += 1.0;\n\t\t\tfor(j = 2; j <= 50; j++){\n\t\t\t\tsum = 0.0;\n\t\t\t\tfor(k = 1; k < j; k++){\n\t\t\t\t\tf[i][j] += f[i-1][k]*a[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t\t\tsum += a[i-1][k]*(1.0-a[i-2][k]);\n\t\t\t\t}\n\t\t\t\tf[i][j] /= sum;\n\t\t\t\tf[i][j] += j;\n\t\t\t}\n\t\t}\n\t\tdouble sum = 0.0;\n\t\tx.l1 = x.l2 = 51;\n\t\tfor(i = 2; i <= 50; i++) sum += b[49][i]*(1.0-a[49][i]);\n\t\tfor(i = 2; i <= 50; i++) x.a[i][1] = b[49][i]*(1.0-a[49][i])/sum;\n\t\tfor(i = 2; i <= 50; i++){\n\t\t\tsum = 0.0;\n\t\t\tfor(j = 1; j < i; j++) sum += a[49][j]*(1.0-a[49][j]);\n\t\t\tfor(j = 1; j < i; j++) x.a[j][i] = a[49][j]*(1.0-a[49][j])/sum;\n\t\t}\n\t\tfor(i = 1; i <= 50; i++) x.a[51][i] = i;\n\t\tx.a[51][51] = 1;\n\t\tz.l1 = z.l2 = 51;\n\t\tfor(i = 1; i <= 51; i++) z.a[i][i] = 1;\n\t\tint k = n-49;\n\t\twhile(k){\n\t\t\tif(k&1) z = z*x;\n\t\t\tx = x*x;\n\t\t\tk >>= 1;\n\t\t}\n\t\tfn.l1 = 1; fn.l2 = 51;\n\t\tfor(i = 1; i <= 50; i++) fn.a[1][i] = f[49][i];\n\t\tfn.a[1][51] = 1;\n\t\tfn = fn*z;\n\t\tdouble ans = 0.0;\n\t\tfor(i = 1; i <= 50; i++) ans += a[49][i]*(1.0-a[49][i])*fn.a[1][i];\n\t\tprintf(\"%.10lf\\n\", ans);\n\t}\n\treturn 0;\n}", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66"} {"source_code": "#include\n\nusing namespace std ;\n\nint main()\n{\n string f, m , s ;\n cin>>f ;\n cin>>m;\n cin>>s ;\n\n if( (f==\"rock\"&& m==\"scissors\" && s==\"scissors\") ||\n (f==\"paper\" && m==\"rock\" && s==\"rock\")\n || (f==\"scissors\" && m==\"paper\" && s==\"paper\") )\n {\n cout<<\"F\" <\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 = 400000;\nll x[N + 1];\n\nvoid solve(){\n\tll n, k;\n\tint m;\n\tscanf(\"%lld%d%lld\", &n, &m, &k);\n\tx[0] = 0;\n\tf(i, 1, m + 1)scanf(\"%lld\", x + i);\n\tf(i, 0, m + 1)x[i] = (i == m ? n : x[i + 1]) - x[i];\n\t++m;\n\tk += m;\n\t\n\tauto sm1 = [&](ll n){\n\t\tll an = 0;\n\t\tf(i, 0, m)an += x[i] / n;\n\t\treturn an;\n\t};\n\tauto sm2 = [&](ll n){\n\t\tll an = 0;\n\t\tf(i, 0, m)an += (x[i] + n - 1) / n;\n\t\treturn an;\n\t};\n\t\n\tll l = 1, r = *min_element(x, x + m);\n\twhile (r > l){\n\t\tll m = l + r + 1 >> 1;\n\t\tif (sm1(m) < k)r = m - 1;\n\t\telse l = m;\n\t}\n\tll L = l;\n\t\n\tl = 1, r = n;\n\twhile (r > l){\n\t\tll m = l + r >> 1;\n\t\tif (sm2(m) > k)l = m + 1;\n\t\telse r = m;\n\t}\n\tll R = l;\n\t\n\tmultiset st;\n\tst.insert(L);\n\tst.insert(R);\n\tvector > v;\n\tf(i, 0, m)if (x[i] / L < (x[i] + R - 1) / R){\n\t\tll a = (x[i] + R - 1) / R, b = x[i] / L;\n\t\tv.emplace_back(x[i] / a, (x[i] + b - 1) / b);\n\t\tst.insert(v.back().first);\n\t}\n\tll an = *st.rbegin() - *st.begin();\n\tsort(v.begin(), v.end());\n\tfor (auto &u: v){\n\t\tst.erase(st.find(u.first));\n\t\tst.insert(u.second);\n\t\tan = min(an, *st.rbegin() - *st.begin());\n\t}\n\tprintf(\"%lld\\n\", an);\n}\n\nint main(){\n\tint t;\n\tscanf(\"%d\", &t);\n\twhile (t--)solve();\n}", "src_uid": "37d912c36aedea1b8f8e78a849062d90"} {"source_code": "#include \nusing namespace std;\n\nint main () {\n int n, val = 0;\n cin >> n;\n \n for(int i=3; i<=n; i++) {\n if (i == 3) {\n val = 1*2*3;\n }else {\n val = val + (i * (i-1));\n }\n } \n \n cout << val;\n \n return 0;\n}", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"source_code": "#define frp\n\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 ll INF = 0x3f3f3f3f;\nconst ll inf = 0x7fffff;\nconst int maxn = 2e6;\nconst int MAXN = 100000 + 5;\nconst int MOD = 1e9 + 7;\n\nll n,num=1,tot;\nvoid solve() {\n cin>>n;\n tot=n;\n for (int i = 2; i < n+1; ++i) {//通过枚举,得到最小分解底数\n if(tot%i==0){\n num*=i;\n }\n while(tot%i==0){\n tot/=i;\n }\n }\n int ans=0,tmp=num;\n while(num%n){\n num*=num;\n ans++;\n }\n cout<n?ans+1:ans)<> t;\n while (t--) {\n solve();\n }\n return 0;\n}\n", "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"source_code": "#include \nusing namespace std;\ntypedef signed long long ll;\n\n#undef _P\n#define _P(...) (void)printf(__VA_ARGS__)\n#define FOR(x,to) for(x=0;x > Ls,Rs;\nvector > events;\nvector P;\n\ntemplate class SegTree_1 {\npublic:\n\tvector val;\n\tstatic V const def=0;\n\tV comp(V l,V r){ return max(l,r);};\n\t\n\tSegTree_1(){val=vector(NV*2,def);};\n\tV getval(int x,int y,int l=0,int r=NV,int k=1) {\n\t\tif(r<=x || y<=l) return def;\n\t\tif(x<=l && r<=y) return val[k];\n\t\treturn comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));\n\t}\n\tvoid update(int entry, V v) {\n\t\tentry += NV;\n\t\tval[entry]=v;\n\t\twhile(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);\n\t}\n};\n\nSegTree_1 ST;\nmap MM;\n\nvoid solve() {\n\tint i,j,k,l,r,x,y; string s;\n\t\n\tcin>>N>>M;\n\tFOR(i,N) {\n\t\tcin>>L[i]>>R[i];\n\t\tif(L[i]>A[i]>>B[i]>>C[i];\n\t\tif(A[i]first)-pos;\n\t\t\t\t\tif(retsecond;\n\t\t\t\t\t\tidy=r;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(B[r]==pos) {\n\t\t\t\tif(Ls.size()) {\n\t\t\t\t\tll len = pos-max(A[r],Ls.begin()->first);\n\t\t\t\t\tif(retsecond;\n\t\t\t\t\t\tidy=r;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tx = lower_bound(ALL(P),A[r])-P.begin();\n\t\t\t\ty = lower_bound(ALL(P),B[r])-P.begin();\n\t\t\t\tll len = ST.getval(x,y);\n\t\t\t\tif(retv) {\n\t\t\t\t\tv=R[r]-L[r];\n\t\t\t\t\tST.update(l,v);\n\t\t\t\t\tMM[v]=r;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tLs.erase({L[r],r});\n\t\t\t\tRs.erase({L[r],r});\n\t\t\t}\n\t\t}\n\t}\n\t\n\tif(ret) {\n\t\tcout<\nusing namespace std;\ntypedef long long ll;\nint main()\n{\n ll t;\n cin>>t;\n while(t--)\n {\n ll n;\n cin>>n;\n if(n%2==0)\n {\n cout<\n#include \n\nusing namespace std;\n\nmain(){\n // freopen(\"80b.txt\",\"r\",stdin);\n int ora,perc;\n scanf(\"%d:%d\",&ora,&perc);\n if (ora>=12){\n ora=ora-12;\n }\n double sol1=1.0*((360/12)*ora+perc/2);\n cout.precision(10);\n if (perc%2==1){\n sol1+=0.5;\n }\n cout<\n#include\nusing namespace std;\n \ntemplate void chmin(T&x,const T &y)\n{\n\tif(x>y)x=y;\n}\ntemplate void chmax(T &x,const T &y)\n{\n\tif(x pii;\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 rep0(i,l,r) for(int i=l;i='0')x=x*10+c-'0';\n\t\treturn -x;\n\t}\n\tint x=c-'0';\n\twhile(gc>='0')x=x*10+c-'0';\n\treturn x;\n}\n#undef gc\n \nconst int N=1e5+5;\nint n;\t\nmap Map_A;\nmap> Map_V;\nnamespace BIT\n{\n//kx+b\t\ns64 s0[N],s1[N];//sum_b,sum_k\nvoid A(int i,int k,int b)\n{\n\tfor(;i<=n;i+=i&-i)\n\t{\n\t\ts1[i]+=k;\n\t\ts0[i]+=b;\n\t}\n}\nvoid add(int l,int r,int k,int b)\n{\n\tif(l>r)return ;\n\tA(l,k,b);\n\tA(r+1,-k,-b);\n}\ns64 query(int x)\n{\n\ts64 k=0,b=0;\n\tfor(int i=x;i;i-=i&-i){k+=s1[i];b+=s0[i];}\n\treturn k*x+b;\n}\n};\n \nvoid add_ij(int i,int j,int w)\n{\n\tassert(jr)return ;\n\tBIT::add(1,n-r+1,0,(r-l+1)*w);\n\tBIT::add(n-r+2,n-l+1,-1*w,(n-l+1+1)*w);\n}\nvoid ins(map &Map,int l,int r)\n{\n\tauto it=Map.lower_bound(l);\n\tint r1=0,l1=0;\n\tif(it!=Map.end())\n\t\tadd_ij(r1=it->first,r,1);\t\t\n\tif(it!=Map.begin())\n\t\tl1=(--it)->second;\n \n\tadd_ij(l,l1,1);\n\tif(r1)add_ij(r1,l1,-1);\n \n\tadd_lr(l,r,1);\n\tMap[l]=r;\n}\nvoid del(map &Map,int l,int r)\n{\n\tauto split=[&](int p)\n\t{\n\t\tauto it=Map.lower_bound(p);\n\t\tif(it==Map.begin())return ;\n\t\t--it;\n\t\tif(it->second>=p)\n\t\t{\n\t\t\tMap[p]=it->second;\n\t\t\tit->second=p-1;\n\t\t}\n\t};\n\tsplit(l);split(r+1);\n\t\n\tauto it=Map.lower_bound(l);\n\tif(it==Map.end())\n\t{\n\t\tcerr<<\"it==Map.end() \"<second!=r)\n\t{\n\t\tcerr<<\"it->second!=r \"<second<<\" \"<first,r,-1);\t\n\tif(it!=Map.begin())\n\t\tl1=(--it)->second;\n\tadd_ij(l,l1,-1);\n\tif(r1)add_ij(r1,l1,1);\n \n\tadd_lr(l,r,-1);\n}\nvoid split(int p)//split p-1 and p\n{\n\tauto it=Map_A.lower_bound(p);\n\tif(it->first==p)return ;\n\t--it;\n\tMap_A[p]=it->second;\n}\n \nint main()\n{\n#ifdef kcz\n\tfreopen(\"1.in\",\"r\",stdin);//freopen(\"1.out\",\"w\",stdout);\n#endif\n\tn=read();int m=read();\n\trep(i,1,n)\n\t{\n\t\tint x=read();\n\t\tins(Map_V[x],i,i);\n\t\tMap_A[i]=x;\n\t}\n\tMap_A[n+1]=0;\n\twhile(m--)\n\tif(read()==1)\n\t{\n\t\tint l=read(),r=read(),x=read();\n\t\tsplit(l);split(r+1);\n\t\tauto it=Map_A.lower_bound(l);\n\t\twhile(it->first<=r)\n\t\t{\n\t\t\tauto it1=it;\n\t\t\t++it1;\n\t\t\t//cerr<second<second],it->first,it1->first-1);\n\t\t\tMap_A.erase(it);\n\t\t\tit=it1;\n\t\t}\n\t\tMap_A[l]=x;\n\t\tins(Map_V[x],l,r);\n\t}\n\telse \n\t{\n\t\tprintf(\"%lld\\n\",BIT::query(read()));\n\t}\n}", "src_uid": "ac85e953ff1cce050834f4e793ec1f02"} {"source_code": "#include \n#include \n#include \n#include \nusing namespace std;\nconst int mo = 1000000007;\nint b[120], a[120], i, n, p, j, tot, lmax, rmax, l, r, f[1200][4], g[4], k;\nint mel(int x, int y) {\n for (int i = 0; i <= 2; ++i)\n if (x != i && y != i) return i;\n}\nint calc(int x, int y) {\n int r = p - x, l = p - y;\n return (long long)(l + r) * (r - l + 1) / 2 % mo;\n}\nint main() {\n tot = 1;\n a[tot] = 2;\n b[tot] = 0;\n scanf(\"%d%d\", &n, &p);\n l = r = 1;\n while (a[tot] < p) {\n lmax = (a[l] + 1) * 3 - 1;\n if (a[r] & 1)\n rmax = (a[r] - 1) / 2 * 3 + 1;\n else\n rmax = a[r] / 2 * 3;\n\n b[++tot] = mel(b[l], b[r]);\n if (b[tot] == b[tot - 1]) tot--;\n a[tot] = min(rmax, lmax);\n if (lmax == a[tot]) l++;\n if (rmax == a[tot]) r++;\n }\n for (i = 1; i <= tot; ++i) {\n if (i != tot)\n g[b[i]] = (g[b[i]] + calc(a[i - 1] + 1, a[i])) % mo;\n else\n g[b[i]] = (g[b[i]] + calc(a[i - 1] + 1, p)) % mo;\n }\n f[0][0] = 1;\n for (i = 1; i <= n; ++i) {\n for (j = 0; j <= 3; ++j)\n for (k = 0; k <= 2; ++k)\n f[i][j ^ k] = ((long long)f[i - 1][j] * g[k] + f[i][j ^ k]) % mo;\n }\n printf(\"%d\\n\", ((long long)f[n][1] + f[n][2] + f[n][3]) % mo);\n}\n", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0"} {"source_code": "#include \n\nconst int MAXN = 24 + 10;\nint N;\nint A[MAXN];\nint month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\nbool visited;\n\nint main() {\n\tregister int i, j;\n\tscanf( \"%d\", &N );\n\tfor( i = 0; i < N; ++i )\n\t\tscanf( \"%d\", A + i );\n\tfor( i = 0; i < 12; ++i ) {\n\t\tvisited = 0;\n\t\tfor( j = 0; j < N; ++j ) {\n\t\t\tif( ( i + j ) % 12 == 1 && !visited && A[j] == 29 ) {\n\t\t\t\tvisited = 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif( A[j] != month[( i + j ) % 12] )\n\t\t\t\tbreak;\n\t\t}\n\t\tif( j == N )\n\t\t\treturn 0 * printf( \"YES\" );\n\t}\n\tprintf( \"NO\" );\n\treturn 0;\n}\n", "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n\t\tint n; cin>>n;\n\t\tsets;\n\t\tfor(int i=0;i>x;\n\t\t\ts.insert(x);\n\t\t}\n\t\tvectorcp;\n\t\tfor(auto x: s)\n\t\t{\n\t\t\tcp.push_back(x);\n\t\t}\n\t\tif(cp.size()==1){cout<<0<3){cout<<-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#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n\n#define forn(i,n) for(int i=0;i<(int)(n);i++)\n#define si(c) ((int)(c).size())\n#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)\n#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)\n#define decl(v, c) typeof(c) v = c\n#define forall(i, c) for(decl(i, c.begin()); i!=c.end(); ++i)\n#define dforall(i, c) for(decl(i, c.rbegin()); i!=c.rend(); ++i)\n#define all(c) (c).begin(), (c).end()\n#define rall(c) (c).rbegin(), (c).rend()\n#define D(a) cerr << #a << \"=\" << a << endl;\n#define pb push_back\n#define mp make_pair\n\n\ntypedef long long int tint;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef vector vt;\ntypedef vector vvt;\ntypedef vector vd;\ntypedef vector vvd;\ntypedef vector vb;\ntypedef vector vvb;\ntypedef vector vs;\ntypedef pair pii;\n\nconst int INF = 1<<29;\n\nmap memo;\nint go(tint n) {\n\tif (n == 0) return 0;\n\n\tif (memo.count(n)) return memo[n];\n\tint &res = memo[n];\n\n\ttint ones = 1, d = n, k = 1;\n\twhile (d >= 10) {\n\t\td /= 10;\n\t\tones = 10*ones + 1;\n\t\tk++;\n\t}\n\n\tres = d*k + go(abs(n-ones*d));\n\tif (d>1) res = min(res, int((d-1)*k) + go(abs(n-ones*(d-1))));\n\tres = min(res, int((11-d)*k) + 1 + go(abs(n-ones*d-1)));\n\tif (d > 1) res = min(res, int((12-d)*k) + 1 + go(abs(n-ones*(d-1)-1)));\n\treturn res;\n}\n\n\n\nint main() {\n\n\t#ifndef ONLINE_JUDGE\n\t\tfreopen(\"in.txt\",\"r\",stdin);\n\t //freopen(\"out.txt\",\"w\",stdout);\n\t#endif\n\n\ttint n; cin >> n;\n\tcout << go(n) << endl;\n\n return 0;\n}\n", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"} {"source_code": "#include\nusing namespace std;\nint w1,o1,w2,o2,w3,o3,c[3],c1[3],i;\nmain()\n{\n\tcin>>w1>>o1>>w2>>o2>>w3>>o3;\n cout<<3<\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 main()\n{\n ll n,m,a;\n while(cin>>n>>m>>a)\n {\n ll x1=0,x2=0;\n x1=(ceil)(n/(double)a);\n x2=(ceil)(m/(double)a);\n cout<\n#include \n#include \n\n#include \n\nusing namespace std;\n\nint main(){\n\tchar n[10];\n\n\tcin >> n;\n\n\tlong long int x = 0;\n\tx = x * 10 + n[0] - '0';\n\tx = x * 10 + n[2] - '0';\n\tx = x * 10 + n[4] - '0';\n\tx = x* 10 + n[3] - '0';\n\tx = x* 10 + n[1] - '0';\n\n\tlong long y = x;\n\tx = (x * y) % 100000;\n\tx = (x * y) % 100000;\n\tx = (x * y) % 100000;\n\tx = (x * y) % 100000;\n\n\tprintf(\"%05d\", x);\n\n\n\treturn 0;\n}", "src_uid": "51b1c216948663fff721c28d131bf18f"} {"source_code": "#include\n#include\n#include\n#include\n//#include\nusing namespace std;\n#include\n#define T 1e16\n#define L 1000003\nlong long c[28]={0,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368000,20922789888000,355687428096000,6402373705728000,121645100408832000};\nstruct node\n{\n long long value;\n int t;\n int same;\n}tem;\n\nint cmp(const void *a,const void *b)\n{\n return ((struct node*)a)->value < ((struct node*)b)->value; \n}\nint get_ha(long long x)\n{\n x*=131;\n return x%L;\n}\nvector vec[L];\nint a[100];\nlong long s,count;\nint lim,len,n,ha,k;\nvoid dfs(int cur,long long sum,int ik,int fg)\n{\n int i;\n if(sum>s)\n {\n return ;\n }\n if(fg==0&&cur==lim)\n {\n \n tem.value=sum;\n tem.t=ik;\n tem.same=1;\n ha=get_ha(sum);\n len=vec[ha].size();\n for(i=0;i\r\nusing namespace std; \r\ntypedef long long ll; \r\n#define int long long \r\n#define ull unsigned long long\r\n#define CY printf(\"YES\\n\")\r\n#define CN printf(\"NO\\n\")\r\n#define x first\r\n#define y second\r\n#define PII pair \r\n#define de(x) cerr<<#x<<'='<= (b); i --)\r\n#define vi vector\r\n#define vpii vector\r\n#define pb push_back\r\n#define rvs(s) reverse(s.begin(),s.end())\r\n#define all(s) s.begin(),s.end()\r\nint qmi(int a, int k);\r\nint mo(int x,int p){return x = ((x%p)+p)%p;}\r\nconst int N=2000007;\r\nconst int mod=1e9+7;\r\nconst int inf=0x3f3f3f3f3f3f3f3f;\r\nconst double eps=1e-8;\r\nint dx[4]={-1,0,1,0};\r\nint dy[4]={0,1,0,-1};\r\nint n,m,k,t,q,p,x,y;\r\nint a[N],vis[N],b[N],dp[N];\r\nbool st[100000000];\r\nint cnt=0;\r\nsigned main (){\r\n\tcin>>n>>m;\r\n\trep(i,1,20){\r\n\t\trep(j,1,m){\r\n\t\t\tif(st[i*j]==false){\r\n\t\t\t\tcnt++;\r\n\t\t\t\tst[i*j]=true;\r\n\t\t\t}\t\r\n\t\t}\r\n\t\tdp[i]=cnt;\r\n\t}\r\n\tint res=1;\r\n\trep(i,2,n){\r\n\t\tif(vis[i]==0){\r\n\t\t\tint ct=0;\r\n\t\t\tfor(int j=i;j<=n;j*=i){\r\n\t\t\t\tct++;\r\n\t\t\t\tvis[j]=1;\r\n\t\t\t}\r\n\t\t\tres+=dp[ct];\r\n\t\t}\r\n\t}\r\n\tcout<>= 1;}return res;}\r\n\r\n", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long LL;\n\nconst int MOD=1e9+7;\nconst int Maxn=100+9;\n\n#define plus(x,y) (x=((x)+(y)>=MOD)?((x)+(y)-MOD):((x)+(y)))\n\nint c[Maxn][Maxn],n,m,K,dp[2][Maxn][Maxn][Maxn],Ans;\n\n\nint main()\n{\n\tscanf(\"%d%d%d\",&n,&m,&K);\n\t\n\tc[0][0]=1;\n\t\n\tfor(int i=1;i<=K;++i)\n\t\tfor(int j=0;j<=i;++j)\n\t\t{\n\t\t\tc[i][j]=(j?c[i-1][j-1]:0)+c[i-1][j];\n\t\t\t\n\t\t\tif(c[i][j]>K)\n\t\t\t\tc[i][j]=K+1;\n\t\t}\n\t\t\n\t++n;\n\t\n\tint now=1,last=0;\n\t\n\tdp[now][0][1][1]=1;\n\t\n\tfor(int i=0;i<=m;++i)\n\t{\n\t\tlast=now,now^=1;\n\t\t\n\t\tif(i)\n\t\t{\n\t\t\tint tmp=0;\n\t\t\t\n\t\t\tfor(int j=2;j<=n;++j)\n\t\t\t\tfor(int l=1;l<=K;++l)\n\t\t\t\t\tplus(tmp,dp[last][j][0][l]);\n\t\t\t\t\t\n\t\t\tplus(Ans,(LL)tmp*(m-i+1)%MOD);\n\t\t}\n\t\t\n\t\tif(i==m)\n\t\t\tbreak;\n\t\t\t\n\t\tmemset(dp[now],0,sizeof(dp[now]));\n\t\t\n\t\tfor(int j=0;j<=n;++j)\n\t\t\tfor(int k=1;k<=n;++k)\n\t\t\t\tfor(int l=1;l<=K;++l)\n\t\t\t\t\tif(dp[last][j][k][l])\n\t\t\t\t\t\tfor(int t=k;t<=n-j;++t)\n\t\t\t\t\t\t\tif(l*c[t-1][k-1]<=K)\n\t\t\t\t\t\t\t\tplus(dp[now][j+t][t-k][l*c[t-1][k-1]],dp[last][j][k][l]);\n\t}\n\t\n\tprintf(\"%d\\n\",Ans);\n\t\n\treturn 0;\n}", "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b"} {"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#pragma comment(linker, \"/STACK:400000000\")\n\n#define EPS 1e-9\n#define INF MOD\n#define MOD 1000000007LL\n#define fir first\n#define foreach(it,X) for(it=X.begin();it!=X.end();it++)\n#define iss istringstream\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 x;\n\nint main(){\n\tcin>>x;\n\tif(x==2){cout<<3;return 0;}\n\tif(x==3){cout<<5;return 0;}\n\tint ans=1;\n\twhile(1){\n\t\tif((ans*ans+1)/2>=x){\n\t\t\tcout<\n// #define LOCAL\n#ifdef LOCAL\n#define DEBUG(fmt, ...) printf(fmt, ##__VA_ARGS__)\n#else\n#define DEBUG(fmt, ...)\n#endif\n\nusing namespace std;\n#define szof(v) ((int)(v).size())\n#define allof(v) begin(v), end(v)\nusing ll = long long;\nusing ii = pair;\nusing vi = vector;\ntemplate \nusing minheap = priority_queue, greater>;\ntemplate \nusing maxheap = priority_queue;\n\nset> visit;\nunordered_set dests;\n\nvoid dfs(ll x, int rem) {\n visit.insert({x, rem});\n if (rem > 0) {\n if (visit.find(make_pair(x + 1, rem - 1)) == visit.end()) {\n dfs(x + 1, rem - 1);\n }\n if (visit.find(make_pair(x + 5, rem - 1)) == visit.end()) {\n dfs(x + 5, rem - 1);\n }\n if (visit.find(make_pair(x + 10, rem - 1)) == visit.end()) {\n dfs(x + 10, rem - 1);\n }\n if (visit.find(make_pair(x + 50, rem - 1)) == visit.end()) {\n dfs(x + 50, rem - 1);\n }\n } else {\n // DEBUG(\"dest = %lld\\n\", x);\n // ++cnt;\n dests.insert(x);\n }\n}\n\nvoid mmain() {\n // int lastans = 0;\n int n;\n scanf(\"%d\", &n);\n vector small = {\n 0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341, 390, 439, 488,\n };\n if (n <= 15) {\n printf(\"%d\\n\", small[n]);\n return;\n } else {\n printf(\"%lld\\n\", 49LL * (n - 15) + 1LL*small[15]);\n }\n\n // dfs(0, 200);\n // int ans = dests.size();\n // if (ans == 49LL * (200 - 15) + small[15]) {\n // printf(\"cool\\n\");\n // } else {\n // printf(\"no\\n\");\n // }\n // for (int n = 1; n <= 15; ++n) {\n // visit.clear();\n // dests.clear();\n // dfs(0, n);\n // printf(\"%d, \", szof(dests));\n // // printf(\"n = %d, ans = %d, delta = %d\\n\", n, szof(dests),\n // // szof(dests) - lastans);\n // // lastans = szof(dests);\n // }\n // int n;\n // scanf(\"%d\", &n);\n // if (n <=)\n // dfs(0, n);\n // cout << dests.size() << \"\\n\";\n}\n\nint main() {\n#ifdef LOCAL\n clock_t begin = clock();\n printf(\"*********Starting program*********\\n\\n\");\n freopen(\"data.txt\", \"r\", stdin);\n#endif\n mmain();\n#ifdef LOCAL\n clock_t end = clock();\n double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;\n printf(\"\\nTime taken: %lf\\n\", elapsed_secs);\n#endif\n}", "src_uid": "75ec99318736a8a1b62a8d51efd95355"} {"source_code": "#include \r\nusing namespace std;\r\n\r\nconst int mod = 998244353;\r\nconst int N = 55;\r\nconst int M = 2010;\r\n\r\ntypedef long long LL;\r\n\r\nint Pow(int x, int y) {\r\n\tint res = 1;\r\n\tfor (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;\r\n\treturn res;\r\n}\r\n\r\nint a[N], coef[2][N][M], frac[M], inv[M];\r\n\r\nint main() {\r\n\tint n, k, L = 0; cin >> n >> k;\r\n\tbool flag = false;\r\n\tfor (int i = 1; i <= n; i++) {\r\n\t\tcin >> a[i], L += a[i];\r\n\t\tif (a[i] > k) flag = true;\r\n\t}\r\n\tif (!flag) return puts(\"0\"), 0;\r\n\tfrac[0] = inv[0] = 1;\r\n\tfor (int i = 1; i <= M - 10; i++) \r\n\t\tfrac[i] = (LL)frac[i - 1] * i % mod, inv[i] = Pow(frac[i], mod - 2);\r\n\tint tot = 0; coef[0][0][0] = 1;\r\n\tint cur = 0;\r\n\tL = Pow(L, mod - 2);\r\n\tfor (int i = 1; i <= n; i++) {\r\n\t\tcur ^= 1, memset(coef[cur], 0, sizeof(coef[cur]));\r\n\t\tint lim = (a[i] - 1) / k;\r\n\t\tstatic int tmp[M], tmp1[M];\r\n\t\tfor (int l = 0; l <= lim; l++) {\r\n\t\t\tint w1 = (LL)(a[i] - l * k) * L % mod;\r\n\t\t\ttmp[l] = Pow(w1, l);\r\n\t\t\tif (l) tmp1[l] = Pow(w1, l - 1);\r\n\t\t}\r\n\t\tfor (int j = 0; j < i; j++)\r\n\t\t\tfor (int t = j; t <= tot; t++) if (coef[cur ^ 1][j][t]) {\r\n\t\t\t\tint w = coef[cur ^ 1][j][t];\r\n\t\t\t\tfor (int l = 0; l <= lim; l++) {\r\n\t\t\t\t\tint hh = (LL)w * inv[l] % mod;\r\n\t\t\t\t\tif (l & 1) hh = mod - hh;\r\n\t\t\t\t\tcoef[cur][j][t + l] = (coef[cur][j][t + l] + (LL)hh * tmp[l]) % mod;\r\n\t\t\t\t\tif (l) coef[cur][j + 1][t + l] = (coef[cur][j + 1][t + l] + (LL)hh * l % mod * tmp1[l]) % mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\ttot += lim;\r\n\t}\r\n\tint res = 0;\r\n\tfor (int i = 0; i <= n; i++)\r\n\t\tfor (int j = i; j <= tot; j++) if (coef[cur][i][j]) {\r\n\t\t\tint w = coef[cur][i][j];\r\n\t\t\tint a = j - i, b = 1 - (LL)j * k * L % mod;\r\n\t\t\tif (b < 0) b += mod;\r\n\t\t\tres = (res + (LL)w * frac[a] % mod * Pow(Pow(mod + 1 - b, mod - 2), a + 1)) % mod;\r\n\t\t}\r\n\tprintf(\"%d\\n\", (mod - res) % mod);\r\n}", "src_uid": "26d565c193a5920b042c783109496b4c"} {"source_code": "#include \n#include \n#include \n#include \n\n\nconst double EPS = 1e-9;\n\n\nstruct point3d {\n double x, y, z;\n\n point3d ( double a , double b , double c ) : x(a) , y(b) , z(c) {}\n point3d ( double a , double b ) : x(a) , y(b) , z(0) {}\n point3d ( void ) : x(0) , y(0) , z(0) {}\n\n point3d operator- ( const point3d& o ) const {\n return point3d(x - o.x, y - o.y, z - o.z);\n }\n\n point3d operator* ( double o ) const {\n return point3d(o*x, o*y, o*z);\n }\n\n double cross ( const point3d& o ) const {\n return x * o.y - o.x * y;\n }\n};\n\nstruct segment {\n point3d p0, p1, u;\n\n segment ( point3d& a , point3d& b ) : p0(a) , p1(b) , u(b - a) {}\n};\n\nstruct polygon {\n int n_points;\n std::vector points;\n\n polygon ( void ) : n_points(0) { }\n\n point3d& operator[] ( int i ) {\n return points[i];\n }\n};\n\nstruct ray {\n point3d v;\n\n ray ( void ) { }\n\n ray ( point3d a ) : v(a) {}\n\n double intersect ( point3d& p ) {\n double point_t;\n if ( fabs(v.cross(p)) < EPS ) {\n point_t = p.x / (double) v.x;\n if ( point_t < -EPS || point_t > 1 + EPS ) {\n return INFINITY;\n }\n return point_t;\n }\n return INFINITY;\n }\n\n double intersect ( segment&& s ) {\n const point3d& u = s.u;\n const point3d& w = s.p0;\n\n double det, ray_t, segment_t;\n\n det = v.cross(u);\n if ( fabs(det) < EPS ) {\n return std::min(intersect(s.p0), intersect(s.p1));\n }\n\n ray_t = w.cross(u) / det;\n segment_t = w.cross(v) / det;\n\n if ( ray_t < -EPS || segment_t < -EPS || segment_t > 1 + EPS ) {\n return INFINITY;\n }\n\n return ray_t;\n }\n\n double intersect ( polygon& p ) {\n int i;\n double min_t;\n\n min_t = INFINITY;\n for ( i = 0 ; i < p.n_points ; ++ i ) {\n min_t = std::min(min_t, intersect(segment(p[i], p[i+1])));\n }\n\n return min_t;\n }\n\n bool is_parallel ( ray& o ) {\n return fabs(v.cross(o.v)) < EPS;\n }\n};\n\n\nstd::pair ray_time ( ray& free_fall , ray& parachute , polygon& fence , int g ) {\n double free_fall_t, parachute_t, aux_t;\n\n free_fall_t = free_fall.intersect(fence);\n parachute_t = parachute.intersect(fence);\n\n if ( free_fall_t < parachute_t ) {\n aux_t = - free_fall.v.z * free_fall_t / (double) g;\n return std::make_pair(free_fall_t, aux_t);\n }\n return std::make_pair(parachute_t, 0);\n}\n\nstd::pair vertex_time ( point3d& vertex , point3d& plane , point3d& wind , int g ) {\n double A, B, C, D, det;\n std::pair ans;\n\n A = plane.x - plane.z * wind.x / (double) wind.z;\n B = - g * wind.x / (double) wind.z;\n C = plane.y - plane.z * wind.y / (double) wind.z;\n D = - g * wind.y / (double) wind.z;\n\n det = A * D - B * C;\n ans.first = ( vertex.x * D - B * vertex.y ) / det;\n ans.second = ( A * vertex.y - vertex.x * C ) / det;\n\n if ( ans.first < -EPS || ans.second < -EPS || plane.z * ans.first + g * ans.second < -EPS ) {\n return std::make_pair(INFINITY, INFINITY);\n }\n\n return ans;\n}\n\nint main ( void ) {\n\n int i, g;\n polygon fence;\n point3d origin, plane, wind;\n ray free_fall, parachute_fall;\n std::pair best_t;\n\n std::cin >> fence.n_points;\n fence.points.resize(fence.n_points + 1);\n\n for ( i = 0 ; i < fence.n_points ; ++ i ) {\n std::cin >> fence[i].x >> fence[i].y;\n }\n fence[fence.n_points] = fence[0];\n\n std::cin >> origin.x >> origin.y;\n std::cin >> plane.x >> plane.y >> plane.z;\n std::cin >> g;\n std::cin >> wind.x >> wind.y >> wind.z;\n\n for ( i = 0 ; i <= fence.n_points ; ++ i ) {\n fence[i].x -= origin.x;\n fence[i].y -= origin.y;\n }\n\n free_fall = ray(plane);\n parachute_fall = ray(plane - wind * (plane.z/(double)wind.z));\n\n best_t = ray_time(free_fall, parachute_fall, fence, g);\n\n if ( !free_fall.is_parallel(parachute_fall) ) {\n for ( point3d& p : fence.points ) {\n best_t = std::min(best_t, vertex_time(p, plane, wind, g));\n }\n }\n\n if ( best_t.first == INFINITY || best_t.second == INFINITY ) {\n std::cout << \"-1 -1\" << std::endl;\n return 0;\n }\n\n// std::cout << best_t.first << std::endl;\n// std::cout << (free_fall.v * best_t.first).x << \" \" << (free_fall.v * best_t.first).y << std::endl;\n\n// std::cout << (parachute_fall.v * best_t.first).x << \" \" << (parachute_fall.v * best_t.first).y << std::endl;\n// std::cout << (parachute_fall.v * 1).x << \" \" << (parachute_fall.v * 1).y << std::endl;\n// std::cout << (parachute_fall.v * 2).x << \" \" << (parachute_fall.v * 2).y << std::endl;\n\n std::cout << std::fixed << std::setprecision(10)\n << best_t.first << \" \" << best_t.second << std::endl;\n\n return 0;\n}\n", "src_uid": "d6afa6a515fc0adde11891e81cb179d7"} {"source_code": "#include \n\nusing namespace std;\n\n#define dbgs(x) cerr << (#x) << \" --> \" << (x) << ' '\n#define dbg(x) cerr << (#x) << \" --> \" << (x) << endl\n\n#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)\n#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)\n#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)\n\n#define type(x) __typeof(x.begin())\n\n#define orta (bas + son >> 1)\n#define sag (k + k + 1)\n#define sol (k + k)\n\n#define pb push_back\n#define mp make_pair\n\n#define nd second\n#define st first\n\n#define endl '\\n'\n\ntypedef pair < int ,int > pii;\n\ntypedef long long ll;\n\nconst long long linf = 1e18+5;\nint mod = (int) 1e9 + 7;\nconst int logN = 18;\nconst int SQ = 250;\nconst int inf = 1e9;\nconst int N = 5e4 + 5;\n\nll all, ch[N], path[N];\nint size[N], ok[N], dp[N], n, m, P[N], p[N], x, y, z, t, val[N], C[N];\nvector< pair< int , pii > > q;\nvector< int > v[N], nodes;\nchar c;\n\nint up(int x, int y) {\n if(!x) return 0;\n int &r = dp[x];\n if(r != -1) return r;\n if(P[x] == y) return r = x;\n return r = up(P[x], y);\n}\n\nint up2(int x) {\n if(ok[x]) return x;\n int &r = dp[x];\n if(r != -1) return r;\n return r = up2(P[x]);\n}\n\nint dfs1(int node) {\n size[node] = 1;\n int s = ok[node] ? 2 : 0;\n ch[node] = 0;\n foreach(it, v[node]) {\n s += dfs1(*it);\n size[node] += size[*it];\n ch[node] -= size[*it] * (ll) size[*it];\n } ch[node] += size[node] * (ll) size[node];\n if(s >= 2) ok[node] = 1;\n all += ch[node] * (ll) val[node];\n return s != 0;\n}\n\nvoid dfs2(int node, int last, int root, int bef = 0) {\n path[node] = path[root] + (size[root] - size[node]) * (ll) val[root];\n C[node] = size[bef];\n if(ok[node]) { nodes.pb(node); P[node] = last; last = node; bef = -1; }\n foreach(it, v[node]) {\n if(bef == -1) dfs2(*it, node, node, *it);\n else dfs2(*it, last, node, bef);\n }\n}\n\nint ctr(int x, int y) {\n while(x) {\n if(x == y) return 1;\n x = P[x];\n } return 0;\n}\n\nint main() {\n\n scanf(\"%d\", &n);\n FOR(i, 2, n) scanf(\"%d\", &p[i]);\n FOR(i, 1, n) scanf(\"%d\", &val[i]);\n\n scanf(\"%d\", &m);\n\n FOR(i, 1, m) {\n scanf(\" %c %d %d\", &c, &y, &z);\n if(c == 'P') { ok[y] = ok[z] = 1; q.pb(mp(0, mp(y, z))); }\n if(c == 'V') { ok[y] = 1; q.pb(mp(1, mp(y, z))); }\n if(i == m || i % SQ == 0) {\n FOR(i, 1, n) v[i].clear();\n FOR(i, 2, n) v[p[i]].pb(i);\n nodes.clear();\n ok[1] = 1; all = 0;\n dfs1(1), dfs2(1, 0, 0, 1);\n memset(ok, 0, sizeof ok);\n foreach(it, q) {\n printf(\"%.12lf\\n\", all / (1.0 * n * n));\n foreach(it3, nodes) ok[*it3] = 0;\n if(it->st == 1) {\n int node = it->nd.st, val = it->nd.nd - ::val[node];\n all += val * ch[it->nd.st];\n foreach(it3, nodes) dp[*it3] = -1;\n foreach(it3, nodes) {\n int take = up(*it3, node);\n if(take == 0) continue;\n path[*it3] += val * (ll) (size[node] - C[take]);\n } :: val[node] += val;\n }\n else {\n if(ctr(it->nd.nd, it->nd.st)) swap(it->nd.nd, it->nd.st);\n p[it->nd.st] = it->nd.nd;\n int node = it->nd.st, par = P[it->nd.st], sz = size[node];\n all -= 2 * sz * path[node];\n while(par) {\n ok[par] = ok[node] = 1;\n ch[par] -= 2LL * sz * (size[par] - C[node]);\n size[par] -= sz; C[node] -= sz;\n node = P[node]; par = P[par];\n } C[1] -= sz; C[it->nd.st] = sz;\n ll ggg = path[it->nd.st];\n foreach(it3, nodes) dp[*it3] = -1;\n foreach(it3, nodes) {\n if(!ok[*it3] || *it3 == it->nd.st) {\n int take = up2(*it3);\n if(take == it->nd.st) path[*it3] -= ggg;\n else path[*it3] -= val[take] * (ll) sz;\n }\n }\n foreach(it3, nodes) dp[*it3] = -1, ok[*it3] = 0; C[it->nd.st] = 0;\n node = it->nd.st, par = it->nd.nd, P[node] = par;\n while(par) {\n ok[par] = ok[node] = 1;\n size[par] += sz; C[node] += sz;\n ch[par] += 2LL * sz * (size[par] - C[node]);\n node = P[node]; par = P[par];\n } C[1] += sz;\n foreach(it3, nodes) dp[*it3] = -1;\n ggg = path[it->nd.nd] + (ll) (size[it->nd.nd] - sz) * val[it->nd.nd];\n foreach(it3, nodes) {\n if(!ok[*it3] || *it3 == it->nd.st) {\n int take = up2(*it3);\n if(take == it->nd.st) path[*it3] += ggg;\n else path[*it3] += val[take] * (ll) sz;\n }\n }\n all += 2 * path[it->nd.st] * size[it->nd.st];\n foreach(it3, nodes) dp[*it3] = -1, ok[*it3] = 0;\n }\n }\n q.clear();\n memset(ok, 0, sizeof ok);\n }\n }\n printf(\"%.12lf\\n\", all / (1.0 * n * n));\n return 0;\n}\n", "src_uid": "013df41c0042f752a995bdcf16b28c7e"} {"source_code": "#include \n\nusing namespace std;\n\n//#define input(a) scanf(\"%d\", &a)\n//#define input2(a,b) scanf(\"%d %d\", &a,&b)\n\nint main(){\n\n\tlong long int n;\n\tlong long int a=0, b=0;\n\tcin>>n;\n\tcin>>a>>b;\n\t/*int mayor=0, menor=0;\n\n\tif(a\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\ndouble ans=0;\nint ne,nf,ns;\ndouble le,lf,ls;\nint rf,re,rs;\nint de,df;\ndouble interFLen[30][30];\ndouble interELen[30][30];\ndouble inter(double st1,double ed1,double st2,double ed2){\n\tif(st2>ed1 || st1>ed2)return 0;\n\treturn min(ed1,ed2)-max(st1,st2);\n}\nint place[30];\nvoid calc(){\n\tstatic double winF[30];\n\tstatic double winE[30];\n\tfor(int i=1;i<=13;i++){\n\t\twinF[i]=2*lf;\n\t\twinE[i]=2*le;\n\t\tfor(int j=1;j<=13;j++){\n\t\t\twinF[i]+=interFLen[i][j]*place[j];\n\t\t\twinE[i]+=interELen[i][j]*place[j];\n\t\t}\n\t\twinF[i]*=df;\n\t\twinE[i]*=de;\n\t}\n\tstatic double f[30][30];\n\tmemset(f,0,sizeof(f));\n\tfor(int pos=1;pos<=13;pos++){\n\t\tfor(int times=1;times<=2-place[pos];times++){\n\t\t\tfor(int i=nf;i>=0;i--){\n\t\t\t\tfor(int j=ne;j>=0;j--){\n\t\t\t\t\tif(i)\n\t\t\t\t\t\tf[i][j]=max(f[i][j],f[i-1][j]+winF[pos]);\n\t\t\t\t\tif(j)\n\t\t\t\t\t\tf[i][j]=max(f[i][j],f[i][j-1]+winE[pos]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tans=max(ans,f[nf][ne]);\n}\nvoid dfs(int id,int left){\n\tif(id==14){\n\t\tif(!left)\n\t\t\tcalc();\n\t\treturn;\n\t}\n\t//Nothing\n\tdfs(id+1,left);\n\t//Place one\n\tif(left>=1){\n\t\tplace[id]=1;\n\t\tdfs(id+1,left-1);\n\t\tplace[id]=0;\n\t}\n\t//Place two\n\tif(left>=2){\n\t\tplace[id]=2;\n\t\tdfs(id+1,left-2);\n\t\tplace[id]=0;\n\t}\n}\nint main(){\n\tscanf(\"%d%d%d\",&nf,&ne,&ns);\n\tscanf(\"%d%d%d\",&rf,&re,&rs);\n\tscanf(\"%d%d\",&df,&de);\n\tlf=sqrt(rf*rf-1);\n\tle=sqrt(re*re-1);\n\tls=sqrt(rs*rs-1);\n\tfor(int i=1;i<=13;i++)\n\t\tfor(int j=1;j<=13;j++)\n\t\t\tinterFLen[i][j]=inter(i-lf,i+lf,j-ls,j+ls),\n\t\t\tinterELen[i][j]=inter(i-le,i+le,j-ls,j+ls);\n\tdfs(1,ns);\n\tcout<\nusing namespace std;\n\nint main()\n{\n\tint n,i,d=0,f=0;\n\tcin>>n;\n\tint a[n];\n\tfor(i=0;i>a[i];\n\t}\n\td=a[1]-a[0];\n\t \n for (int i=1; i\nusing namespace std;\nint main()\n{\n long long n,i=0,k,j,ans=0,x=0,y=0,m=0,a[101],t;\n char ch[1201];\n cin>>n>>ch;\n k=strlen(ch);\n //cout<\nusing namespace std;\nint n,i,j,k,l,f[402][402],g[402][402],h[402][402],a[402],v[402],ans[402];\nint main(){\n\tscanf(\"%d\",&n);\n\tfor(i=1;i<=n;i++)scanf(\"%d\",&v[i]);\n\tfor(i=1;i<=n;i++)scanf(\"%d\",&a[i]);\n\tfor(l=1;l<=n;l++){\n\t\tfor(i=1;i+l-1<=n;i++){\n\t\t\tj=i+l-1;\n\t\t\tif(i==j){\n\t\t\t\tg[i][j]=h[i][j]=0;f[i][j]=v[1];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tg[i][j]=h[i][j]=-1e9;\n\t\t\tfor(k=i+1;k<=j;k++)if(a[i]+1==a[k])g[i][j]=max(g[i][j],f[i+1][k-1]+g[k][j]);\n\t\t\t else if(a[i]-1==a[k])h[i][j]=max(h[i][j],f[i+1][k-1]+h[k][j]);\n\t\t\tf[i][j]=-1e9;\n\t\t\tfor(k=i;k-1e8&&h[k][j]>-1e8)\n\t\t\t f[i][j]=max(f[i][j],g[i][k]+h[k][j]+v[a[k]*2-a[i]-a[j]+1]);\n\t\t}\n\t}\n\tfor(i=1;i<=n;i++){\n\t\tans[i]=ans[i-1];\n\t\tfor(j=0;j\n#include \n#include \n#include \nusing namespace std;\nint main() {\n int n;\n cin >> n;\n getchar();\n int sum1 = 0;\n for(int i = 0; i < n / 2; ++i){\n char d = getchar();\n if(d != '4' && d != '7'){\n cout << \"NO\";\n return 0;\n }\n sum1 += d - '0';\n }\n int sum2 = 0;\n for(int i = 0; i < n / 2; ++i){\n char d = getchar();\n if(d != '4' && d != '7'){\n cout << \"NO\";\n return 0;\n }\n sum2 += d - '0';\n }\n if(sum1 == sum2){\n cout << \"YES\";\n }\n else{\n cout << \"NO\";\n }\n\n\n\treturn 0;\n}\n", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"source_code": "#include \nusing namespace std;\n\ntypedef long long ll;\ntypedef pair pii;\ntypedef vector vi;\n#define mp make_pair\n#define pb push_back\n#define fi first\n#define se second\n#define sz(x) (int)x.size()\n\nconst int N = 30;\nint n;\nmap dp;\nint s[35];\n\nint dfs(int S) {\n\tif (dp.count(S)) return dp[S];\n\tint sg = 0;\n\tfor (int i = 0; i < 30; i++) if (S>>i&1) {\n\t\tsg |= (1<\nusing namespace std;\nint main()\n{ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int n;\n cin>>n;\n string s,a;\n cin>>s;\n for(int i=0;i\nusing namespace std;\nint main(void)\n{\n int a,s,d;\n cin>>a>>s>>d;\n cout<< min(min(2*(a+s),2*(a+d)), min(a+s+d,2*(d+s))) <\n#define ss second\n#define ff first\n#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)\n#define ret(n) return cout << n, 0\n#define se(n) cout << setprecision(n) << fixed\n#define ll long long\n#define pb push_back\nusing namespace std;\n \nconst int N = 1e5 + 100, M = 1e9 + 7;\ntypedef pair pii;\nstring s, t;\n \nbool IS(string f) {\n\tint j = 0;\n\tfor(int i = 0; i < f.size(); i++) {\n\t\tif(f[i] == t[j])\n\t\t\tj++;\n\t\tif(j == t.size())\n\t\t\tbreak;\n\t}\n\tif(j != t.size()) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n \nint main() {\n\tcin >> s >> t;\n\tint ans = 0;\n\tfor(int i = 0; i < s.size(); i++) {\n\t\tfor(int j = i; j < s.size(); j++) {\n\t\t\tstring f = s;\n\t\t\tf.erase(i, (j - i + 1));\n\t\t\tif(IS(f)) {\n\t\t\t\tans = max(ans, (j - i + 1));\n\t\t\t}\n\t\t}\n\t}\n\tcout << ans << endl;\n}", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"source_code": "#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#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#ifndef __GNUC__\n#include \n#endif\nusing namespace std;\ntypedef long long ll;\n\nvoid ans()\n{\n\tcout << \"YES\";\n\texit(0);\n}\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL); cout.tie(NULL);\n#ifndef ONLINE_JUDGE\n\t////#ifdef LOCAL_PROJECT\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#else\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n#endif // !ONLINE_JUDGE\n\n\tll n;\n\tcin >> n;\n\tif (n < 5)\n\t{\n\t\tcout << ((n)*(n - 1)) / 2;\n\t\treturn 0;\n\t}\n\tfor (ll i = 1000000000; i >= 10; i /= 10)\n\t{\n\t\t//100 [50-500)\n\t\tint buf = i / 2;\n\t\tif (n < buf)\n\t\t\tcontinue;\n\t\tll ans = 0;\n\t\tll j;\n\t\tll last = buf;\n\t\tfor (j = 0; j < 5; j++)\n\t\t{\n\t\t\tll cur = j*i + buf;\n\t\t\tif (n >= cur)\n\t\t\t{\n\t\t\t\tans += (j + 1)*(min(n, cur + i - 1) - (last - 1));\n\t\t\t\tif (n >= (j + 1)*i - 1)\n\t\t\t\t\tans--;\n\t\t\t}\n\t\t\tlast = cur + i;\n\t\t}\n\t\tcout << ans;\n\t\tbreak;\n\t}\n}", "src_uid": "c20744c44269ae0779c5f549afd2e3f2"} {"source_code": "#include\nusing namespace std;\nconst long long maxn=1005;\nconst long long inf=0x3f3f3f3f;\nconst long long mod=1e9+7;\nlong long n,m,k;\nlong long buf[maxn][maxn],col[maxn][maxn],reach[maxn][maxn];\nlong long match[maxn],appear[maxn],rev[maxn];\nlong long calc()\n{\n\tmemset(rev,-1,sizeof(rev));\n\tmemset(match,-1,sizeof(match));\n\tmemset(appear,0,sizeof(appear));\n\tfor(long long i=0;i0?reach[x-1][y]:0)|(y>0?reach[x][y-1]:0));\n\tfor(long long i=0;i>i&1)\n\t\t\tcontinue;\n\t\treach[x][y]|=(1<=mod)\n\t\t\tres-=mod;\n\t\treach[x][y]^=(1<>n>>m>>k;\n for(long long i=0;i>buf[i][j];\n \t\tbuf[i][j]--;\n\t\t}\n\t}\n\tif(n+m-1>k)\n\t{\n\t\tcout<<\"0\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define N 1000005\n#define ll long long\n#define mod 1000000007\nint fac[N],inv[N],n,m,maxn,ans;\nint q_pow(int x,int n){int ret=1;for(;n;n>>=1,x=(ll)x*x%mod)if(n&1)ret=(ll)ret*x%mod;return ret;}\nint C(int n,int m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}\nint main()\n{\n\tscanf(\"%d%d%*d%*d\",&n,&m);maxn=max(n,m);fac[0]=1;\n\tfor(int i=1;i<=maxn;i++)fac[i]=fac[i-1]*(ll)i%mod;inv[maxn]=q_pow(fac[maxn],mod-2);\n\tfor(int i=maxn;i;i--)inv[i-1]=(ll)i*inv[i]%mod;\n\tfor(int i=1;i\n#include\n#include\n#include\n#include\n#include\n#include\n#include \nusing namespace std;\n\n\n\n// Codeforces 577A\nint main() {\n\tlong long n, x;\n\tcin >> n >> x;\n\tlong long res = 0;\n\tlong long timesN = n * n;\n\n\tif (x > timesN) {\n\t\tcout << 0 << endl;\n\t\treturn 0;\n\t}\n\n\tif (x == 1) {\n\t\tcout << 1 << endl;\n\t\treturn 0;\n\t}\n\n\n\tfor (int i = 1; i < n + 1; i++) {\n\t\tif (x % i == 0) {\n\t\t\tif (x / i <= n) {\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t}\n\n\tcout << res << endl;\n\n\treturn 0;\n}\n\n", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "#include \nusing namespace std;\nlong long a[10000],b[10000];\nconst int Mod = 1e9 + 7;\n\n\nint main(){\n\tint n,k,d;\n\tcin >> n >> k >> d;\n\ta[0]=1;\n\tb[0]=1;\n\tfor (int i=1;i=i-k;j--){\n\t\t\ta[i]+=a[j];\n\t\t\ta[i]=a[i]%1000000007;\n\t\t}\t\n\t}\n\tfor (int i=1;i=i-d+1;j--){\n\t\t\tb[i]+=b[j];\n\t\t\tb[i]=b[i]%1000000007;\n\t\t}\t\n\t}\n\tif (n==1 && n>=d){\n\t\tcout << n;\n\t\treturn 0;\n\t}\n\tcout << (a[n-1]-b[n-1] + Mod) % Mod;\n}\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "#include \n\nint main(){\n\tint n, m;\n\t\n\tscanf(\"%d %d\", &n, &m);\n\t\n\tint x;\n\tint y;\n\t\n\tif (n >= m){\n\t\tx = m;\n\t\ty = n;\n\t}\n\t\n\telse {\n\t\tx = n;\n\t\ty = m;\n\t}\n\t\n\tint count = 0;\n\t\n\tif (x == y){\n\t\tprintf(\"1\");\n\t\treturn 0;\n\t}\n\t\n\tfor (;;){\n\t\tcount ++;\n\t\tx *= 3;\n\t\ty *= 2;\n\t\t\n\t\tif (x > y){\n\t\t\tprintf(\"%d\", count);\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 0;\n}", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"source_code": "#include \n#include \n\ntypedef std::vector > vii;\n\nvii combine(vii a, vii b) {\n\tfor(int i = 0; i < a.size(); i++) {\n\t\tfor(int j = 0; j < a[i].size(); j++) {\n\t\t\ta[i][j] += b[i][(j + a[i][j]) % a[i].size()];\n\t\t}\n\t}\n\treturn a;\n}\n\nint fexp(vii x, int e) {\n\tvii ans = x;\n\tfor(int i = 0; i < ans.size(); i++) {\n\t\tfor(int j = 0; j < ans[i].size(); j++) {\n\t\t\tans[i][j] = 0;\n\t\t}\n\t}\n\tfor(; e > 0; e /= 2) {\n\t\tif(e & 1) {\n\t\t\tans = combine(ans, x);\n\t\t}\n\t\tx = combine(x, x);\n\t}\n\treturn ans[0][0];\n}\n\nint main() {\n\tint b, d;\n\tstd::cin >> b >> d;\n\tstd::string s1, s2;\n\tstd::cin >> s1 >> s2;\n\tvii base(s1.size());\n\tfor(int i = 0; i < s1.size(); i++) {\n\t\tfor(int k = 0; k < s2.size(); k++) {\n\t\t\tbase[i].push_back(0);\n\t\t\tfor(int j = i; j < s1.size(); j++) {\n\t\t\t\tif(s1[j] == s2[(base[i][k] + k) % s2.size()]) {\n\t\t\t\t\tbase[i][k]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tstd::cout << fexp(base, b) / s2.size() / d << '\\n';\n}", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\n#define f first\n#define s second\n#define mp make_pair\n#define pll pair\nll n2;\nbool rem(pll &A){\n ll d1=(A.f+1)*(A.f+1)+(A.s)*A.s;\n ll d2=(A.f)*A.f+(A.s+1)*(A.s+1);\n if (d1>n2 or d2>n2)\n return true;\n return false;\n}\n\nint main(){\n ios::sync_with_stdio(0);cin.tie(0);\n ll n;\n cin >> n;\n if (n==0){\n cout << \"1\\n\";\n return 0;\n }\n n2=n*n;\n pll Point(0, n);\n pll Ret1(n, 0);\n ll contador=0;\n while (Point!=Ret1){\n if (rem(Point)){\n contador++;\n }\n ll d1=((Point.f+1)*(Point.f+1))+(Point.s*Point.s);\n if (d1<=n2)\n Point.f++;\n else\n Point.s--;\n }\n cout << contador*4 << \"\\n\";\n return 0;\n}\n", "src_uid": "d87ce09acb8401e910ca6ef3529566f4"} {"source_code": "#include\nusing namespace std;\n\nint n , m ;\nint arr[101] = {};\nint q[101] = {};\nint c[101] = {};\n\nint main()\n{\n ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);\n\n cin >> n >> m;\n\n for(int i = 0 ;i < n ; i++)\n cin >> arr[i];\n\n for(int i = 1 ; i <= m ; i++)\n cin >> q[i];\n\n for(int i = 0 ; i < n ; i++)\n c[arr[i]]++;\n\n for(int i = 0 ; i < n ; i++)\n {\n int c[m+1] = {};\n bool ok = 1;\n for(int j = i ;j < n ;j++)\n {\n c[arr[j]]++;\n bool ok = 1;\n\n for(int k = 1; k <= m ; k++)\n {\n if(c[k] != q[k])\n {\n ok = 0;\n break;\n }\n }\n\n if(ok)\n return cout << \"YES\" , 0;\n\n }\n\n\n }\n\n\n cout << \"NO\";\n\n return 0;\n}\n", "src_uid": "59f40d9f35e5fe402112214b42b682b5"} {"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#define mkp make_pair\n#define pb push_back\n#define IOS ios_base::sync_with_stdio(0),cin.tie(0)\nusing namespace std;\ntypedef pair pii;\ntypedef long long ll;\nconst int maxn=2e5+5;\nconst int mod=1e9+7;\nconst int INF=2147483647;\nlong long F[maxn];\nlong long S[maxn];\nint main(){\n\tIOS;\n\tint n,m;\n\tcin>>n>>m;\n\tF[0]=1, F[1]=2;\n\tfor(int i=2;i<=100000;i++){\n\t\tF[i]=(F[i-1]+F[i-2])%mod;\n\t}\n\tS[1]=-1,S[2]=0,S[3]=F[0];\n\tfor(int i=4;i<=100000;i++){\n\t\tS[i]=(S[i-1]+F[i-3])%mod;\n\t}\n\tcout<<((S[n]+S[m]+3)*2)%mod<<'\\n';\n\treturn 0;\n}\n", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n long long k,n,s,p;cin>>k>>n>>s>>p;cout<\nusing namespace std;\n\nint prime[1000],primeSize = 0;\n\nvoid fill(int n){\n\tint root = (int)sqrt(n) + 1;\n\tfor (int i = 2; i < root; ++i)\n\t{\n\t\tbool Isprime = true;\n\t\tfor (int j = 0; j < primeSize; ++j)\n\t\t{\n\t\t\tif(i % prime[j] == 0){\n\t\t\t\tIsprime = false;\n\t\t\t}\n\t\t}\n\t\tif(Isprime == true && n % i == 0){\n\t\t\tprime[primeSize++] = i;\n\t\t}\n\t}\n}\n\nint smalld(int n){\n\tfor (int i = 0; i < primeSize; ++i)\n\t{\n\t\tif(n % prime[i] == 0){\n\t\t\treturn prime[i];\n\t\t}\n\t}\n\treturn -1;\n}\n\nvoid devide(int n,int k){\n\tint dev[1000];\n\tint devS = 0;\n\tfor (int i = 0; i < k - 1; ++i)\n\t{\n\t\tint num = smalld(n);\n\t\tif(num == -1 || num == n){\n\t\t\tcout<<-1;\n\t\t\treturn;\n\t\t}else{\n\t\t\tdev[devS++] = num;\n\t\t\tn /= num;\n\t\t}\n\t}\n\tfor (int i = 0; i < devS; ++i)\n\t{\n\t\tcout<> n >>k;\n\tfill(n);\n\tdevide(n,k);\n\treturn 0;\n}", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"} {"source_code": "// luogu-judger-enable-o2\n#include\nusing namespace std;\n#define fo(i,a,b) for(int i=a;i<=b;i++)\nchar l[1010],r[1010];\nint ct,c[20000][10],fa[20000],s[17000][2010],n,f[2005][17000],ok[2005][17000],l1,l2;\nint nt(int x,int y){\n\treturn !c[x][y]?c[x][y]=++ct:c[x][y];\n}\nvoid ins(){\n\tl1=strlen(l+1),l2=strlen(r+1);\n\tint x=0,y=0;\n\tif(l1==l2){\n\t\tfo(i,1,l1){\n\t\t\tif(x==y){\n\t\t\t\tfo(j,l[i]-'0'+1,r[i]-'0'-1)\n\t s[nt(x,j)][l1-i]++;\n x=nt(x,l[i]-'0');\n y=nt(y,r[i]-'0');\n\t\t\t}\n\t\t\telse{\n\t\t\t\tfo(j,l[i]-'0'+1,9)\n\t\t s[nt(x,j)][l1-i]++;\n x=nt(x,l[i]-'0');\n fo(j,(i==1),r[i]-'0'-1)\n \ts[nt(y,j)][l2-i]++;\n y=nt(y,r[i]-'0');\n\t\t\t}\n\t\t}\n\t\ts[x][0]++;\n\t\tif(x!=y)s[y][0]++;\n\t}\n\telse{\n\t\tfo(i,1,l1){\n\t\t\tfo(j,l[i]-'0'+1,9)\n\t\t\t\ts[nt(x,j)][l1-i]++;\n\t\t\tx=nt(x,l[i]-'0');\n\t\t}\n\t\tfo(i,1,l2){\n\t\t\tfo(j,(i==1),r[i]-'0'-1)\n\t\t\t\ts[nt(y,j)][l2-i]++;\n\t\t\ty=nt(y,r[i]-'0');\n\t\t}\n\t\tfo(i,l1+1,l2-1)fo(j,1,9)\n\t\t\ts[nt(0,j)][i-1]++;\n\t\ts[x][0]++;\n\t\ts[y][0]++;\n\t}\n}\nqueueq;\nvoid bd(){\n fo(i,0,9)if(c[0][i])\n\t q.push(c[0][i]);\n while(!q.empty()){\n \tint x=q.front();\n \tq.pop();\n \tfo(i,0,l2-1)s[x][i]+=s[fa[x]][i];\n fo(i,0,9){\n \tif(c[x][i]){\n \t\tq.push(c[x][i]);\n \t\tfa[c[x][i]]=c[fa[x]][i];\n\t\t\t}\n\t\t\telse c[x][i]=c[fa[x]][i];\n\t\t}\n\t}\n\tfo(i,0,ct)fo(j,1,n)\n s[i][j]+=s[i][j-1];\n}\nint main(){\n\tscanf(\"%s%s%d\",l+1,r+1,&n);\n\tins();\n\tbd();\n\tmemset(f,-32,sizeof(f));\n\tf[0][0]=0;\n\tfo(i,0,n-1)fo(j,0,ct)if(f[i][j]>=0)\n\t\tfo(k,0,9)f[i+1][c[j][k]]=max(f[i+1][c[j][k]],f[i][j]+s[c[j][k]][n-i-1]);\n\tint r=-1e9;\n\tfo(i,0,ct)r=max(r,f[n][i]);\n\tprintf(\"%d\\n\",r);\n\tfo(i,0,ct)ok[n][i]=(r==f[n][i]);\n\tfor(int i=n-1;i;i--)\n\t\tfo(j,0,ct)fo(k,0,9)\n\t\t\tok[i][j]|=ok[i+1][c[j][k]]&&(f[i+1][c[j][k]]==f[i][j]+s[c[j][k]][n-i-1]);\n\tint x=0;\n\tfo(i,1,n)fo(k,0,9)\n\t\tif(ok[i][c[x][k]]&&f[i][c[x][k]]==f[i-1][x]+s[c[x][k]][n-i]){\n\t\t\tprintf(\"%d\",k);\n\t\t\tx=c[x][k];\n\t\t\tbreak;\n\t\t}\n}", "src_uid": "2e79c95bf4c2b7de8a4741b24a880829"} {"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#define mx(ans, cnt) ans = max(ans, cnt)\n#define fauto(a) for(auto i : a) cout << i << \" \"; cout << endl;\n#define sp(n) fixed << setprecision(n)\n#define all(v) v.begin(), v.end()\n#define rall(v) v.rbegin(), v.rend()\n#define _ << \" \" <<\n#define swp(x, y) if (x > y) swap(x, y);\n#define swpg(x, y) if (x < y) swap(x, y);\n#define ff first\n#define ss second\n#define xx first\n#define yy second\n#define pb push_back\n#define pf push_front\n#define nn end1\n#define intmax ((1ll << 32) - 1)\n \nusing namespace std;\nusing pii = pair;\nusing ll = long long;\nusing ld = long double;\nusing pll = pair;\nusing ull = unsigned long long;\n\n//while (l < r) {\n// int mid = (r + l + 1) / 2; правый\n// if (a[mid] > x) r = mid - 1;\n// else l = mid;\n//}\n//while (l < r) {\n// int mid = (r + l) / 2; левый\n// if (a[mid] >= x) r = mid;\n// else l = mid + 1;\n//}\n\n\n//ll gcd(ll a, ll b) {\n// if (b == 0) return a;\n// return gcd(b, a % b);\n//}\n\n\n\nint main() {\n \n ios::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n //setlocale(LC_ALL, \"Russian\");\n\n \n int n, k, p;\n cin >> n >> k >> p;\n \n p *= n;\n \n ll ans = 0;\n while (n > 1) {\n int cnt = 1;\n while (cnt <= n) cnt *= 2;\n cnt /= 2;\n \n ans += cnt * k + cnt / 2;\n n -= cnt / 2;\n }\n \n cout << ans _ p << endl;\n \n#ifdef LOCAL_DEBUG\n cerr << \"Execution time: \" << 1.0 * clock() / CLOCKS_PER_SEC << \"s.\\n\";\n#endif\n return 0;\n}\n// *1* 2 4 8 6\n// 1 3 9 7\n// *1* 4 6\n\n/*\n ╔═════════════════════════════════════════════════════════════════════════════════════════╗\n ║ ║\n ║ ║███████║ ║█████║ ║████║ ║██████║ ║████║ ║██║ ║██║ ║██║ ║██║ ║█████║ ║\n ║ ║██║ ║██║ ║██║ ║██║ ║██║ ║██║ ║██║║██║ ║██║║██║ ║██║ ║██║ ║██║ ║\n ║ ║████║ ║██║ ║███║ ║██║ ║██║ ║███║║██║ ║██║ ║██║ ║████║ ║██║ ║██║ ║████║ ║\n ║ ║██║ ║██║ ║██║ ║██║ ║██║ ║██║██║ ║█████████║║██║║██║ ║██║ ║██║ ║██║ ║\n ║ ║███████║ ║██████║ ║████ ║██ ║██║ ║██║ ║██║ ║██║ ║████║ ║█████║ ║\n ║ ║\n ╚═════════════════════════════════════════════════════════════════════════════════════════╝\n */\n\n/*\n n!\n \n n!\n --------\n (n - k)!\n \n \n n!\n ------------\n k! * (n - k)!\n */\n\n\n", "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\ntypedef pair PII;\ntypedef pair PIP;\n#define N 30\n\ninline int value(char c) {\n return c - 'a' + 1;\n}\n\nstring w[N];\nmap score;\nmap dp;\n\nPIP DFS(const string &s) {\n if (dp.count(s) != 0) {\n return dp[s];\n }\n PIP &ret = dp[s];\n ret = PIP(-1, PII(0, 0));\n string t; PIP tmp;\n for (char c = 'a'; c <= 'z'; c++) {\n for (int d = 0; d < 2; d++) {\n t = d ? (c + s) : (s + c);\n map::iterator it = score.find(t);\n if (it != score.end()) {\n tmp = DFS(t);\n tmp = PIP(tmp.first * -1, PII(- tmp.second.second + it->second, - tmp.second.first));\n ret = max(ret, tmp);\n }\n }\n }\n return ret;\n}\n\nint main () {\n int n;\n while (cin >> n) {\n score.clear();\n for (int i = 0; i < n; i++) {\n cin >> w[i];\n }\n score.clear();\n for (int i = 0; i < n; i++) {\n int len = w[i].length();\n for (int j = 0; j < len; j++) {\n for (int k = 1; j + k <= len; k++) {\n score[ w[i].substr(j, k) ] |= (1 << i);\n }\n }\n }\n for (map::iterator it = score.begin(); it != score.end(); it++) {\n int cb = 0;\n for (int i = 0; i < n; i++) {\n cb += ((it->second & (1 << i)) != 0);\n }\n int len = it->first.length();\n int sum = 0, maxvalue = 0;\n for (int i = 0; i < len; i++) {\n int v = value(it->first[i]);\n sum += v;\n maxvalue = max(maxvalue, v);\n }\n it->second = sum * maxvalue + cb;\n }\n dp.clear();\n PIP ans = DFS(\"\");\n puts (ans.first == 1 ? \"First\" : \"Second\");\n printf (\"%d %d\\n\", ans.second.first, -ans.second.second);\n }\n return 0;\n}\n", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9"} {"source_code": "#include\n\nusing namespace std;\nint main()\n \n {\n int n;\n cin>>n;\n if(n==2)\n cout<<2<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n#define ll long long\n#define MOD 1000000007\n#define mp(a, b) make_pair(a, b)\n#define PI 3.1415926535\n#define EPS 0.00000001\n#define pii pair\n#define INF 3000000\n\nint main()\n{\n int xp, yp, xv, yv;\n cin >> xp >> yp >> xv >> yv;\n if(xp <= xv && yp <= yv)\n {\n cout << \"Polycarp\";\n return 0;\n }\n if(xp >= xv && yp >= yv)\n {\n cout << \"Vasiliy\";\n return 0;\n }\n\n if(xp > xv)\n {\n if(yp <= yv - xp)\n {\n cout << \"Polycarp\";\n }\n else\n cout << \"Vasiliy\";\n }\n else\n {\n if(xp <= xv - yp)\n {\n cout << \"Polycarp\";\n }\n else\n cout << \"Vasiliy\";\n }\n}", "src_uid": "2637d57f7809ff8f922549c617709074"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nint main(){\n\n string cad,protocol,domain,context = \"\";\n int pos1,pos2;\n\n cin >> cad;\n\n if(cad[0] == 'f'){\n protocol = \"ftp\";\n pos1 = 3;\n }else{\n protocol = \"http\";\n pos1 = 4;\n }\n\n pos2 = cad.rfind(\"ru\");\n //cout << cad.size() << endl;\n //cout << pos1 << \"-\" << pos2+2 << endl; \n domain = cad.substr(pos1,pos2-pos1);\n context = cad.substr(pos2+2);\n\n //cout << cad << endl;\n if(context != \"\") printf(\"%s://%s.ru/%s\\n\",protocol.c_str(),domain.c_str(),context.c_str()); \n else printf(\"%s://%s.ru\\n\",protocol.c_str(),domain.c_str());\n\n return 0;\n}", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"source_code": "#include \n#include \n#include \nusing namespace std;\nint main(){\n\tvector < int > a;\n\tvector < int > b;\n\tint n;\n\tcin>>n;\n\tstring s;\n\tcin>>s;\n\tint x,c=0,t=0;\n\tfor(int i=0;ib[i]){\n\t\t\tt++;\n\t\t}\n\t}\n\tif(c==n || t==n){\n\t\tcout<<\"YES\";\n\t}\n\telse{\n\t\tcout<<\"NO\";\n\t}\t\t\n\t\n\t\n}", "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nlong double pi;\nlong double px[5],py[5];\nint main(){\n\tint n,i;\n\tpi=acos((long double)-1);\n//\tstd::cout.precision(12);\n\tstd::cout<0;i--)\n\t\tprintf(\"%d \",i*4+1);\n\tprintf(\"%d\\n\",1);\n}\n", "src_uid": "db263b866e93e3a97731e11102923902"} {"source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long LL;\n\nstruct node {\n LL x, y;\n};\nnode b, c;\n\nbool Judge(LL x, LL y) {\n node a;\n a.x = x;\n a.y = y;\n if (c.x == 0 && c.y == 0) {\n if (a.x == b.x && a.y == b.y)\n return true;\n return false;\n }\n LL k, C;\n LL g, h;\n g = b.x - a.x;\n h = b.y - a.y;\n k = g * c.x + h * c.y;\n if (k % (c.x * c.x + c.y * c.y) == 0) {\n k /= (c.x * c.x + c.y * c.y);\n if (c.y != 0) {\n C = g - k * c.x;\n if (C % c.y == 0) {\n return true;\n }\n return false;\n } else {\n C = k * c.y - h;\n if (C % c.x == 0) {\n return true;\n }\n return false;\n }\n /* C = g - k * c.x;\n if ((c.y == 0 && C == 0) || (c.y != 0 && C % c.y == 0)) {\n if (c.y != 0)\n C = C / c.y;\n else C = 0;\n //cout << a.x << \" \" << a.y << endl;\n if (g == k * c.x + C * c.y && h == k * c.y - C * c.x)\n return true;\n return false;\n }*/\n }\n return false;\n}\n\nint main() {\n node a;\n while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y) {\n if (Judge(a.x, a.y) == true) {\n puts(\"YES\");\n } else if (Judge(-a.y, a.x) == true) {\n puts(\"YES\");\n } else if (Judge(a.y, -a.x) == true) {\n puts(\"YES\");\n } else if (Judge(-a.x, -a.y) == true) {\n puts(\"YES\");\n } else {\n puts(\"NO\");\n }\n }\n return 0;\n}\n/*\n-2 2\n3 3\n5 0\n\n */\n\n \t \t\t \t \t\t\t \t\t \t \t \t \t\t", "src_uid": "cc8a8af1ba2b19bf081e379139542883"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#define PI acos(-1.0)\nusing namespace std;\nint main()\n{\n\tlong long n;\n\tcin >> n;\n\tif (n % 4 == 1 || n % 4 == 2)\n\t\tcout << 1;\n\telse\n\t\tcout << 0;\n\treturn 0;\n}", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"} {"source_code": "#include \n#include \n\nstd::queueq[3];\nint t,n,a[200001],head[200001],nxt[400001],b[400001],k,d[200001];\nbool vis[200001];\nvoid push(int s,int t){\n\tnxt[++k]=head[s];\n\thead[s]=k;\n\tb[k]=t;\n}\nint main(){\n\tscanf(\"%d\",&t);\n\tfor(int fd=1;fd<=t;fd++){\n\t\tscanf(\"%d\",&n);\n\t\tfor(int i=1;i<=n;i++)scanf(\"%d\",a+i),head[i]=0,a[i]=(a[i]==0)?2:(a[i]-1);\n\t\tk=0;\n\t\tfor(int i=1,u,v;ians)fin=ans;\n\t\t}\n\t\tprintf(\"%d\\n\",fin);\n\t}\n}", "src_uid": "7c5ae79eeff98960fb52416541dd6528"} {"source_code": "#include\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=2e5+10,MAXM=1e7+10;\nconst int INF=INT_MAX,SINF=0x3f3f3f3f;\nconst ll llINF=LLONG_MAX;\nconst int MOD=1e9+7,mod=998244353;\n#define lowbit(x) x&-x\nconst int inv2=5e8+4;\n\nll h1,h2,a,b;\n\nint main()\n{\n scanf(\"%lld%lld%lld%lld\",&h1,&h2,&a,&b);\n h2-=h1;\n int now=14,d=0;\n while(h2>0)\n {\n if(now>=10&&now<22)h2-=a;\n else h2+=b;\n now++;\n if(now>=24)\n {\n now-=24;\n d++;\n }\n if(d>1e6)return puts(\"-1\"),0;\n }\n cout<\nusing namespace std;\nint main()\n{\n\tios::sync_with_stdio(0),cin.tie(0);\n\tstring s;\n\tcin>>s;\n\tint n;\n\tcin>>n;\n\tbool x=0,y=0;\n\twhile(n--)\n\t{\n\t\tstring t;\n\t\tcin>>t;\n\t\tif(t==s)\n\t\t\treturn cout<<\"YES\",0;\n\t\t\t\n\t\tif(t[0]==s[1])\n\t\t\tx=1;\n\t\tif(t[1]==s[0])\n\t\t\ty=1;\n\t}\n\tcout<<(x && y ?\"YES\":\"NO\");\n}\n", "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\n\nint main() {\n ios::sync_with_stdio(false);\n int n;\n cin >> n;\n int a[n];\n for(int i=0;i> a[i];\n sort(a,a+n);\n //sort(a+1,a+n-1);\n cout << a[n-1] << \" \";\n for(int i=1;i\nusing namespace std;\nint n,k,a[100000],sum=1,s,ans;\n//a[100000]是素数表,sum是n之前素数数量,ans是“好素数”数量\nvoid prime(){\n bool t;\n a[0]=2;\n for(int i=3;i<=n;i+=2){\n //优化(i+=2),因为素数除 2 外都是单数。\n t=1;\n for(int j=2;j> n >> k;\n prime();\n for(int i=0;i=k) cout << \"YES\";\n else cout << \"NO\";\n}", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\n#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n#define Alhamdulillah return 0;\n#define loop(i,k,n) for (ll i = k ; i < n ; ++i)\n#define all(v) v.begin(),v.end()\n#define debug(n) cerr << \"[\" << #n << \" = \" << n << \"]\" << endl\n\nvoid Suhaib_Sawalha (){\n\n int a , b , g , l;\n cin >> a >> b >> g >> l;\n if (l % g){\n cout << 0;\n return;\n }\n l /= g;\n int sq = sqrt(l) , ans = 0;\n for (int i = 1 ; i <= sq ; ++i){\n if (l % i == 0){\n int c = l/i;\n if (__gcd(i,c) == 1 && i * g >= a && i * g <= b && c * g >= a && c * g <= b)\n ans += 1 + (i != c);\n }\n }\n cout << ans;\n}\n\nint main(){\n In_The_Name_Of_Allah_The_Merciful /* بسم الله الرحمن الرحيم */\n#ifndef ONLINE_JUDGE\n freopen(\"SuhaibSawalha1.txt\",\"r\",stdin);\n#endif\n//int _;for(cin>>_;_;--_,cout<\nusing namespace std;\n\n#define ll long long\n#define sz(c) (int)c.size()\n\nint main() {\n\tint n;\n\tcin >> n;\n\tcout << n * 3 / 2 << endl;\n}\n\n", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n int n;\n cin>>n;\n char y;\n cin.get(y);\n string s;\n getline(cin,s);\n vector v;\n string s1 = \"\";\n for(int i=0; i> x;\n v.push_back(x);\n s1 = \"\";\n }\n else{\n s1 = s1 + s[i];\n }\n }\n stringstream ss;\n ss << s1;\n int x;\n ss >> x;\n v.push_back(x);\n\n int e=0;\n for(int i=0; i e){\n break;\n }\n k++;\n }\n cout<\n\nusing namespace std;\n\nlong dist[200005];\n\nbool visit[200005];\n\nbool present[200005];\n\nvoid getDist(vector G[],long src) {\n\n queue Q;\n\n memset(visit,false,sizeof visit);\n\n memset(present,false,sizeof present);\n\n memset(dist,-1,sizeof dist);\n\n Q.push(src);\n\n dist[src]=0;\n\n present[src]=1;\n\n while(!Q.empty()) {\n\n long cur = Q.front();\n\n Q.pop();\n\n present[cur]=false;\n\n visit[cur]=true;\n\n for(long x:G[cur]) {\n\n if(!visit[x]) {\n\n if(dist[x]==-1)\n\n dist[x]=dist[cur]+1;\n\n else\n\n dist[x]=min(dist[x],dist[cur]+1);\n\n if(!present[x]) {\n\n Q.push(x);\n\n present[x]=true;\n\n }\n\n }\n\n }\n\n }\n\n return ;\n\n}\n\nint32_t main() {\n\n ios_base::sync_with_stdio(false);\n\n cin.tie(0);\n\n long n;\n\n cin >> n;\n\n long m;\n\n cin >> m;\n\n vector G1[200005],G2[200005];\n\n for(long i = 0 ; i < m ; i++) {\n\n long u;\n\n cin >> u;\n\n long v;\n\n cin >> v;\n\n G1[u].push_back(v);\n\n G2[v].push_back(u);\n\n }\n\n long k;\n\n cin >> k;\n\n vector p(k);\n\n for(long i = 0 ; i < k ; i++) {\n\n cin >> p[i];\n\n }\n\n getDist(G2,p.back());\n\n long res_min =0;\n\n long res_max=0;\n\n for(long i=1; i1) {\n\n res_max++;\n\n }\n\n } else {\n\n res_min++;\n\n res_max++;\n\n }\n\n }\n\n cout << res_min << ' ' << res_max << '\\n';\n\n return 0;\n\n}\n\n", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a"} {"source_code": "#include\nusing namespace std;\n\n#define FOR(i, a, b) for(int i=a; i<=b; i++)\n#define DOW(i, a, b) for(int i=a; i>=b; i--)\n#define S(a) scanf(\"%d\",&a)\n#define LS(a) scanf(\"%lld\",&a)\n#define DS(a) scanf(\"%lf\",&a)\n#define PC(a) printf(\"Case %d: \",a)\n#define P(a) printf(\"%d\\n\",a)\n#define LP(a) printf(\"%lld\",a)\n#define DP(a) printf(\"%.04lf\",a)\n#define pb push_back\n#define mp make_pair\n#define fi first\n#define se second\n#define fast std::ios::sync_with_stdio(false)\n#define init freopen(\"input.txt\",\"r\",stdin)\n#define outit freopen(\"output.txt\",\"w\",stdout)\n#define INF 0xfffffff\n#define gc getchar\n\ntypedef long long ll;\ntypedef vector vi;\ntypedef pair ii;\ntypedef vector vii;\ntypedef vector> vvi;\ntypedef vector> vvii;\n\nvoid scanint( int &x)\n{\n register int c = gc();\n x = 0;\n int neg = 0;\n for(; ((c<48 || c>57) && c != '-'); c = gc());\n if(c=='-')\n {\n neg=1;\n c=gc();\n }\n for(; c>47 && c<58; c = gc())\n {\n x = (x<<1) + (x<<3) + c - 48;\n }\n if(neg) x=-x;\n}\n ll x[3],y[3];\nbool checkx(int i,int j,int k){\n if(x[i]==x[j] && ((y[k]>y[i] && y[k]>y[j]) ||(y[k]x[i] && x[k]>x[j]) || (x[k]>x[i]>>y[i];\n\n if((x[0]==x[1] && x[1]==x[2]) ||(y[0]==y[1] && y[1]==y[2])){\n cout<<\"1\\n\";\n return 0;\n }\n // bool ans=false;\n if(checkx(0,1,2) || checkx(1,2,0) || checkx(2,0,1) || checky(0,1,2) || checky(1,2,0) || checky(2,0,1) )\n {\n cout<<\"2\\n\";\n return 0;\n\n }\n cout<<\"3\\n\";\n }\n\n return 0;\n\n}\n", "src_uid": "36fe960550e59b046202b5811343590d"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\n\n#define pb push_back\n#define ppp pop_back\n#define pii pair\n#define fi first\n#define se second\n\nconst int N = 1005;\nconst ll p = 1e9 + 7;\n\npair dp[2*N][2*N];\n\nll add(ll a, ll b) {\n\tif (a + b >= p) return a + b - p;\n\telse return a + b;\n}\n\nint main() {\n\tios_base::sync_with_stdio(0); cin.tie(0);\n#ifdef LOCAL\n\tfreopen(\"input.txt\", \"r\", stdin);\n#endif\n\tint n;\n\tcin >> n;\n\tdp[0][0] = {0, 1};\n\tfor (int i=1; i<=2*n; i++) {\n\t\tfor (int j=0; j<=i; j++) {\n\t\t\tll cur = 0;\n\t\t\tbool used = 0;\n\t\t\tif (j) {\n\t\t\t\tcur = dp[i-1][j-1].fi;\n\t\t\t\tused = dp[i-1][j-1].se;\n\t\t\t}\n\t\t\tif (j+1 <= i-1) {\n\t\t\t\tcur = add(cur, dp[i-1][j+1].fi);\n\t\t\t\tused |= dp[i-1][j+1].se;\n\t\t\t}\n\t\t\tif (used) dp[i][j] = {add(cur, 1), 0};\n\t\t\telse dp[i][j] = {cur, 1};\n\t\t}\n\t}\n\tcout << dp[2*n][0].fi << \"\\n\";\n return 0;\n}\n", "src_uid": "8218255989e5eab73ac7107072c3b2af"} {"source_code": "#include\nusing namespace std;\n\n#define N 55\n\nint d[N][N], dp[N][N], deg[N], fi[N], se[N], p[N], q[N], r[N];\n\nint f(int x) {return x == p[x] ? x : p[x] = f(p[x]);}\n\nint main() {\n int n, i, j, k, l, L, R, tot, s, m, mid;\n scanf(\"%d\", &n);\n for(i = 1; i <= n; i ++) for(j = 1; j <= n; j ++) if(i != j) d[i][j] = 1e9;\n for(i = 1; i < n; i ++) {\n scanf(\"%d%d%d\", &j, &k, &l);\n fi[i] = j;\n se[i] = k;\n d[j][k] = d[k][j] = l;\n deg[j] ++;\n deg[k] ++;\n }\n scanf(\"%d%d\", &s, &m);\n for(i = 1; i <= n; i ++) p[i] = i;\n for(i = 1; i < n; i ++) if(fi[i] != s && se[i] != s) p[f(fi[i])] = f(se[i]);\n for(i = 0; i < m; i ++) {\n scanf(\"%d\", &j);\n q[f(j)] ++;\n }\n for(k = 1; k <= n; k ++)for(i = 1; i <= n; i ++)for(j = 1; j <= n; j ++)\n if(d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];\n for(i = 1; i <= m; i ++) for(j = 1; j <= n; j ++) if(deg[j] == 1) {\n L = 0, R = 1e9;\n while(L < R) {\n mid = L + R + 1 >> 1;\n tot = 0;\n for(k = 1; k <= n; k ++) if(deg[k] == 1) {\n l = 0;\n while(l < i && dp[l][k] + d[j][k] < mid) l ++;\n tot += i - l;\n }\n if(tot < i) R = mid - 1;\n else L = mid;\n }\n dp[i][j] = L;\n }\n L = 0, R = 1e9;\n while(L < R) {\n mid = L + R + 1 >> 1;\n for(k = 1; k <= n; k ++) r[k] = 0;\n for(k = 1; k <= n; k ++) if(deg[k] == 1) {\n l = 0;\n while(l < m && dp[l][k] + d[s][k] < mid) l ++;\n r[f(k)] += m - l;\n }\n for(k = 1; k <= n; k ++) if(r[k] < q[k]) break;\n if(k > n) L = mid;\n else R = mid - 1;\n }\n printf(\"%d\\n\", L);\n}\n", "src_uid": "34b926f903c2412fe76f912ccb8a00dd"} {"source_code": "#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 double db;\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\ntypedef pair pdd;\n#define rep(i, n) for(int i=0;i Q, pdd D[MX]){\n if( Q.size() == 0 ) return node(-1, -1, -1, circle(pdd(0, 0), 0));\n if( Q.size() == 1 ) return node(Q[0], -1, -1, circle(D[Q[0]], 0));\n circle res;\n for(int i = 0; i < Q.size(); i++){\n swap(Q.back(), Q[i]);\n res = circle((D[Q[0]]+D[Q[1]]) * 0.5, size(D[Q[0]]-D[Q[1]])/2);\n bool ch = 1;\n for(int c : Q){\n if( size2(D[c]-res.O) > sq(res.r) + 1e-6) ch = 0;\n }\n if( ch ) return node(Q[0], Q[1], -1, res);\n swap(Q.back(), Q[i]);\n }\n get_circle(D[Q[0]], D[Q[1]], D[Q[2]], res);\n return node(Q[0], Q[1], Q[2], res);\n}\n\nnode smallest_circle(vector &P, vector &Q, int N, pdd D[MX])\n{\n node c = make_circle(Q, D);\n if( N == 0 || Q.size() >= 3 ) return c;\n for(int i = 0; i < N; i++){\n if( size2(c.X.O - D[P[i]]) > sq(c.X.r) ){\n Q.push_back(P[i]);\n c = smallest_circle(P, Q, i, D);\n Q.pop_back();\n }\n }\n return c;\n}\n\nint counter = 0;\nvoid get_enc(vector L, vector X, vector &ans, pdd D[MX], double prob = 1){\n if(prob < 1e-4) return;\n counter++;\n vector P, Q;\n random_shuffle(L.begin(), L.end());\n for(int c : X) P.push_back(c);\n for(int c : L) P.push_back(c);\n node x = smallest_circle(P, Q, L.size(), D);\n ans.push_back(x);\n vector t1;\n auto is_in = [](vector &X, int x){\n for(int c : X) if(c == x) return true;\n return false;\n };\n if(!is_in(X, x.a)) t1.push_back(x.a);\n if(!is_in(X, x.b)) t1.push_back(x.b);\n if(!is_in(X, x.c)) t1.push_back(x.c);\n\n for(int c : t1){\n for(int j = 0; j < L.size(); j++) if(L[j] == c) L.erase(L.begin()+j);\n get_enc(L, X, ans, D, prob / 3);\n prob = prob * 2 / 3;\n X.push_back(c);\n }\n}\n\npdd D1[MX], D2[MX];\nint N, N1, N2;\nmap Mx;\n\nvoid check(pdd O1, pdd O2, double a)\n{\n auto move = [&](pdd c){\n return rotate(c - O1, a) + O2;\n };\n counter++;\n int corr = 0;\n vector ansv;\n for(int i=1;i<=N1;i++) {\n pdd ex = move(D1[i]);\n\n int tx = (int)(ex.first * 100 + 0.5);\n int ty = (int)(ex.second * 100 + 0.5);\n int f = 0;\n for(int dx=-1;dx<=1;dx++) for(int dy=-1;dy<=1;dy++) if(f == 0) {\n if(Mx.find(pii(tx + dx, ty + dy)) != Mx.end()) {\n int idx = Mx[pii(tx + dx, ty + dy)];\n ansv.emplace_back(i, idx);\n f = 1;\n }\n }\n corr += f;\n if(i > 100 && ((double)corr / i) * N1 < N * 0.5) break;\n }\n if(szz(ansv) > 0.91 * N) {\n int chkA[MX] = {}, chkB[MX] = {};\n for(pii e : ansv) chkA[e.Fi] = chkB[e.Se] = 1;\n int ia = 1, ib = 1;\n while(szz(ansv) < N) {\n while(chkA[ia] == 1) ++ia;\n while(chkB[ib] == 1) ++ib;\n ansv.pb(pii(ia, ib));\n ++ia; ++ib;\n }\n for(pii e : ansv) printf(\"%d %d\\n\", e.Fi, e.Se);\n exit(0);\n }\n}\n\nint main()\n{\n// freopen(\"A.out\",\"r\",stdin);\n scanf(\"%d\", &N);\n scanf(\"%d\", &N1);\n// printf(\"%d %d\\n\", N, N1);\n for(int i = 1; i <= N1; i++) scanf(\"%lf%lf\", &D1[i].first, &D1[i].second);\n scanf(\"%d\", &N2);\n for(int i = 1; i <= N2; i++) scanf(\"%lf%lf\", &D2[i].first, &D2[i].second);\n for(int i=1;i<=N2;i++) {\n int tx = (int)(D2[i].first * 100 + 0.5);\n int ty = (int)(D2[i].second * 100 + 0.5);\n Mx[pii(tx, ty)] = i;\n }\n\n vector t1, t2;\n vector A1, A2;\n for(int i = 1; i <= N1; i++) t1.push_back(i);\n get_enc(t1, t2, A1, D1);\n\n t1.clear();\n for(int i = 1; i <= N2; i++) t1.push_back(i);\n get_enc(t1, t2, A2, D2);\n // printf(\"%d\\n\", counter); counter = 0;\n\n for(node a1 : A1){\n for(node a2 : A2){\n if(fabs(a1.X.r - a2.X.r) > 0.1 ) continue;\n pdd P1[] = {D1[a1.a], D1[a1.b], D1[a1.c]};\n pdd P2[] = {D2[a2.a], D2[a2.b], D2[a2.c]};\n\n for(pdd &c : P1) c = c - a1.X.O;\n for(pdd &c : P2) c = c - a2.X.O;\n\n int O[3] = {0, 1, 2};\n do{\n int ch = 1;\n double t = atan2(P1[0] / P2[O[0]], P1[0] * P2[O[0]]);\n for(int i = 1; i < 3; i++){\n double u = atan2(P1[i] / P2[O[i]], P1[i] * P2[O[i]]);\n if(fabs(t-u) < EPS) ch = 0;\n }\n check(a1.X.O, a2.X.O, t);\n }while(next_permutation(O, O+3));\n }\n }\n // printf(\"%d\\n\", counter); counter = 0;\n}", "src_uid": "fc238a230bb556c9ffecf343989b988a"} {"source_code": "#include \n using namespace std;\n#define mp make_pair\n#define pb push_back\n#define ff first\n#define ss second\nconst double pi=3.1415926535897932384626433832;\nconst long long mod=1e9+7;\n//long long primeset[5000000]={};\ntypedef complex cd;\ntypedef long long ll;\ntypedef double ld;\n//#define For(i,0,n) for(long long i = 0 ; i>q;\n\twhile(q--)\n\t{\n\t\tll a,b,m;\n\t\tcin>>a>>b>>m;\n\n\t\tll pow[50];\n\t\tpow[0]=1;\n\t\tpow[1]=1;\n\t\tfor(ll i=2 ;i<=50 ;i++)\n\t\t{\n\t\t\tpow[i]=2*pow[i-1];\n\t\t}\n\n\t\tll check=0;\n\t\tif(a == b)\n\t\t{\n\t\t\tcout<<1<<' '<=b)\n\t\t\t{\n\t\t\t\tll curb=b;\n\t\t\t\tcheck = 1;\n\t\t\t\tll mchoice[k-1]={};\n\t\t\t\tb=b-l;\n\n\t\t\t\tfor(ll j = k-1 ; j>0 ;j--)\n\t\t\t\t{\n\t\t\t\t\t//cout<<\"b = \"<=pow[j-1])\n\t\t\t\t\t{\n\t\t\t\t\t\tmchoice[k-1-j]= min(b/pow[j-1],m-1);\n\n\n\t\t\t\t\t}\n\t\t\t\t\telse \n\t\t\t\t\tmchoice[k-1-j]=0;\t\n\n\t\t\t\t\t//cout<<\" mc \"< log(curb)+ 1e-5 )\n\t\t\t\t{\n\t\t\t\t\tcheck=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tcout<\n#include\n#include\n#include\n#include\nusing namespace std;\n#define ll long long\nconst int maxn = 2500;\nconst int inf = 0x3f3f3f3f;\nint main()\n{\n ll a,b;\n ll vac = 1;\n scanf(\"%lld%lld\",&a,&b);\n for(ll i=a+1;i<=b;i++)\n {\n vac = ((vac%10) * (i%10))%10;\n if(vac == 0)\n break;\n }\n printf(\"%lld\\n\",vac);\n return 0;\n}\n", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"} {"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;\n\ntypedef long long LL;\nconst int Mod = 1e9 + 9;\ninline int FIX(LL a) {return (a % Mod + Mod) % Mod;}\n#define MP(x,y) make_pair(x,y)\n#define LEN(x) ((int)x.length())\n#define take(x,y) (((x)>>(y)) & 1ll)\n//#define move(n) (1<<(n))\n#define what_is(x) cerr << #x << \" is \" << x << endl;\n#define eb emplace_back\n#define UNQ(x) (sort(begin(x),end(x)),x.erase(unique(begin(x),end(x)),end(x)))\n\nint n,m,k;\nLL cal(LL cnt) {\n //cal 2^cnt\n if(cnt == 1) return 2;\n LL cur = cal(cnt/2);\n cur = cur * cur % Mod;\n if(cnt % 2 == 1) cur = cur * 2 % Mod;\n return cur;\n}\nint main(){\n scanf(\"%d %d %d\",&n,&m,&k);\n int x1 = m/(k-1),x2 = n - m;\n if(x1 <= x2) {\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 \n#include \n#include \n#include \n#pragma comment(linker, \"/stack:256000000\")\n\nusing namespace std;\n\nint main () {\n ios_base::sync_with_stdio(false);\n int n, sum = 0;\n cin >> n;\n for (int i=0; i> a;\n sum += a;\n }\n int ans = 0;\n for (int i=1; i<=5; i++)\n if ((sum + i) % (n+1) != 1)\n ans ++ ;\n cout << ans << endl;\n return 0;\n}\n", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"source_code": "#include \nusing namespace std;\n\n#define print(x) cerr << #x << \" is \" << x << endl;\n#define int long long int\n#define ll long long\n#define vi vector\n#define vvi vector>\n#define vpi vector>\n#define all(v) (v).begin(), (v).end()\n#define pii pair\n#define pb push_back\n#define PI 3.1415926535897932384626\n#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))\n#define out cout << fixed << setprecision(12) <<\n\nconst int N = 2e5 + 10;\nconst int mod = 1e9 + 7;\nconst double lifeofpi = acos(-1);\n\nint32_t main(){\n ios::sync_with_stdio(false);\n cin.tie(0);\n\n int a, b, f, k;\n cin >> a >> b >> f >> k;\n\n int ans = 0, fuel = b;\n int x = 0;\n while(k--){\n int y = a - x;\n if(abs(x - f) > fuel){\n ans = -1;\n break;\n }\n fuel -= (abs(x - f));\n \n if(abs(y - f) > b){\n ans = -1;\n break;\n }\n if(abs(y - f) > fuel || (k && 2 * abs(y - f) > fuel)) {\n ans++;\n fuel = b;\n }\n\n fuel -= abs(y - f);\n x = y;\n }\n\n cout << ans << '\\n';\n return 0;\n}", "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"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#define EPS (1e-10)\n\nint main(){\n int i,j,n,m,a[11],b[11],c[11],d[11],dp[1001][2],tmp,t;\n cin>>n>>m>>c[0]>>d[0];\n for(i=1;i<=m;i++)\n cin>>a[i]>>b[i]>>c[i]>>d[i];\n for(i=0;i<=n;i++) {\n dp[i][0]=0;\n dp[i][1]=0;\n }\n for(i=1;i<=n;i++){\n if(i%c[0]==0&&dp[i-c[0]][1]+c[0]<=n){\n dp[i][0]=dp[i-c[0]][0]+d[0];\n dp[i][1]=dp[i-c[0]][1]+c[0];\n }\n }\n for(i=1;i<=m;i++){\n tmp = a[i]-b[i];\n while(tmp>=0){\n for(j=n;j>=1;j--){\n if(j-c[i]==0||j-c[i]>=0&&dp[j-c[i]][0]!=0&&dp[j-c[i]][1]+c[i]<=n){\n if(dp[j][0]==dp[j-c[i]][0]+d[i])\n dp[j][1] = min(dp[j][1],dp[j-c[i]][1]+c[i]);\n else if(dp[j][0]\n#define pb emplace_back\n#define ll long long\n#define lson rt << 1\n#define rson rt << 1 | 1\n#define all(x) (x).begin(),(x).end()\n#define pii pair\n#define pll pair\nusing namespace std;\n\nstruct Scanner {\n FILE* fp = nullptr;\n char line[(1 << 15) + 1];\n size_t st = 0, ed = 0;\n void reread() {\n memmove(line, line + st, ed - st);\n ed -= st;\n st = 0;\n ed += fread(line + ed, 1, (1 << 15) - ed, fp);\n line[ed] = '\\0';\n }\n bool succ() {\n while (true) {\n if (st == ed) {\n reread();\n if (st == ed) return false;\n }\n while (st != ed && isspace(line[st])) st++;\n if (st != ed) break;\n }\n if (ed - st <= 50) reread();\n return true;\n }\n template ::value, int> = 0>\n bool read_single(T& ref) {\n if (!succ()) return false;\n while (true) {\n size_t sz = 0;\n while (st + sz < ed && !isspace(line[st + sz])) sz++;\n ref.append(line + st, sz);\n st += sz;\n if (!sz || st != ed) break;\n reread(); \n }\n return true;\n }\n template ::value, int> = 0>\n bool read_single(T& ref) {\n if (!succ()) return false;\n bool neg = false;\n if (line[st] == '-') {\n neg = true;\n st++;\n }\n ref = T(0);\n while (isdigit(line[st])) {\n ref = 10 * ref + (line[st++] - '0');\n }\n if (neg) ref = -ref;\n return true;\n }\n template bool read_single(vector& ref) {\n for (auto& d : ref) {\n if (!read_single(d)) return false;\n }\n return true;\n }\n void read() {}\n template void read(H& h, T&... t) {\n bool f = read_single(h);\n assert(f);\n read(t...);\n }\n Scanner(FILE* _fp) : fp(_fp) {}\n};\n \nstruct Printer {\n public:\n template void write() {}\n template \n void write(const H& h, const T&... t) {\n if (F) write_single(' ');\n write_single(h);\n write(t...);\n }\n template void writeln(const T&... t) {\n write(t...);\n write_single('\\n');\n }\n \n Printer(FILE* _fp) : fp(_fp) {}\n ~Printer() { flush(); }\n \n private:\n static constexpr size_t SIZE = 1 << 15;\n FILE* fp;\n char line[SIZE], small[50];\n size_t pos = 0;\n void flush() {\n fwrite(line, 1, pos, fp);\n pos = 0;\n }\n void write_single(const char& val) {\n if (pos == SIZE) flush();\n line[pos++] = val;\n }\n template ::value, int> = 0>\n void write_single(T val) {\n if (pos > (1 << 15) - 50) flush();\n if (val == 0) {\n write_single('0');\n return;\n }\n if (val < 0) {\n write_single('-');\n val = -val; // todo min\n }\n size_t len = 0;\n while (val) {\n small[len++] = char('0' + (val % 10));\n val /= 10;\n }\n for (size_t i = 0; i < len; i++) {\n line[pos + i] = small[len - 1 - i];\n }\n pos += len;\n }\n void write_single(const string& s) {\n for (char c : s) write_single(c);\n }\n void write_single(const char* s) {\n size_t len = strlen(s);\n for (size_t i = 0; i < len; i++) write_single(s[i]);\n }\n template void write_single(const vector& val) {\n auto n = val.size();\n for (size_t i = 0; i < n; i++) {\n if (i) write_single(' ');\n write_single(val[i]);\n }\n }\n};\n \nScanner sc(stdin);\nPrinter pr(stdout);\n\nconst int mol = 1e9 + 7;\n \nint f[18];\nbool a[66];\nint sum[10];\ninline void add(int &a,int b) { a += b; if (a >= mol) a -= mol; }\n\nint main(){ \n\tint t; sc.read(t);\n\tint p = 1;\n\twhile (t--) {\n\t\tll n; sc.read(n);\n\t\tif (n == 1) { pr.writeln(p); continue; }\n\t\tint s = 0;\n\t\tfor (register int i = 0; i <= 60; ++i) {\n\t\t\tif ((1ll << i) > n) break;\n\t\t\tif (n & (1ll << i)) { a[i] = 1; s = i; } else a[i] = 0;\n\t\t}\n\t\tfor (register int i = 0; i <= 6; ++i) sum[i] = 1;\n\t\tfor (register int i = s - 1; i >= 0; --i) {\n\t\t\tint op = a[i + 1]; int x = a[i + 1];\n\t\t\tfor (int j = 0; j <= 6; ++j) {\n\t\t\t\tint k = a[i] + (j << 1);\n\t\t\t\tint st = j + x;\n\t\t\t\tx ^= 1;\n\t\t\t\tint l = (st - a[i + 1]) >> 1;\n\t\t\t\tint r = (j + 7 - a[i + 1]) >> 1;\n\t\t\t\tif (!l) f[k] = sum[r];\n\t\t\t\telse {\n\t\t\t\t\tf[k] = sum[r] - sum[l - 1];\n\t\t\t\t\tif (f[k] < 0) f[k] += mol;\n\t\t\t\t}\n\t\t\t}\n\t\t\tsum[0] = f[a[i]];\n\t\t\tfor (register int j = 1; j <= 6; ++j) {\n\t\t\t\tsum[j] = sum[j - 1] + f[a[i] + (j << 1)];\n\t\t\t\tif (sum[j] >= mol) sum[j] -= mol;\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (register int i = 0; i <= 3; ++i) add(ans , f[a[0] + (i << 1)]);\n\t\tpr.writeln(ans);\n\t} \n\n} ", "src_uid": "24f4bd10ae714f957920afd47ac0c558"} {"source_code": "#include \n\n\n\nint main() {\n \n int h1, m1, h2, m2;\n int hRes, mRes;\n int horaMenos = 0;\n \n scanf(\"%d:%d\", &h1, &m1);\n \n scanf(\"%d:%d\", &h2, &m2);\n \n mRes = m1-m2;\n \n if(mRes < 0){\n mRes = 60 + mRes;\n horaMenos++;\n }\n \n hRes = h1-h2-horaMenos;\n \n if(hRes < 0){\n hRes = 24+hRes;\n }\n \n if (hRes < 10 && mRes < 10) {\n printf(\"0%d:0%d\\n\", hRes, mRes);\n }\n \n else if (hRes >= 10 && mRes < 10) {\n printf(\"%d:0%d\\n\", hRes, mRes);\n }\n \n else if (hRes < 10 && mRes >= 10) {\n printf(\"0%d:%d\\n\", hRes, mRes);\n }\n \n else{\n printf(\"%d:%d\\n\", hRes, mRes);\n }\n \n \n \n return 0;\n}\n\n// 1475086813462", "src_uid": "595c4a628c261104c8eedad767e85775"} {"source_code": "#include \nusing namespace std;\n\n\nnamespace geometry {\n\n using type = long double;\n const type EPS = 1e-9;\n const type PI = cosl(-1.0);\n const type INF = 1e9;\n\n struct Point {\n type x;\n type y;\n \n Point(type x_ = 0.0, type y_ = 0.0): x(x_), y(y_) {}\n \n Point operator + (const Point o) const {\n return Point(this->x + o.x, this->y + o.y);\n }\n \n Point* operator += (const Point o) {\n this->x += o.x;\n this->y += o.y;\n return this;\n }\n\n Point operator - (const Point o) const {\n return Point(this->x - o.x, this->y - o.y);\n }\n \n Point* operator -= (const Point o) {\n this->x -= o.x;\n this->y -= o.y;\n return this;\n }\n\n Point operator * (const type c) const {\n return Point(this->x * c, this->y * c);\n }\n \n Point* operator *= (const type c) {\n this->x *= c;\n this->y *= c;\n return this;\n }\n\n Point operator / (const type c) const {\n return Point(this->x / c, this->y / c);\n }\n \n Point* operator /= (const type c) {\n this->x /= c;\n this->y /= c;\n return this;\n }\n\n Point rot(const type rad) const {\n return Point(this->x * cosl(rad) - this->y * sinl(rad), this->x * sinl(rad) + this->y * cosl(rad));\n }\n\n type rot_diff(const Point o) const {\n type rot1 = atan2(this->y, this->x);\n type rot2 = atan2(o.y, o.x);\n type res = rot2 - rot1;\n return res;\n }\n\n };\n\n type dot(Point a, Point b) {\n return (a.x * b.x) + (a.y * b.y);\n }\n\n type cross(Point a, Point b) {\n return (a.x * b.y) - (a.y * b.x);\n }\n\n int sign(type o) {\n if (o > 0) return +1;\n if (o < 0) return -1;\n return 0;\n }\n\n bool in_triangle(Point A, Point B, Point C, Point P) {\n /* If P is in triangle ABC, then its orientation must be the same for\n all permutations of the cross products between P and triangle vertices.\n */\n\n if (sign(cross(A - C, B - C)) != sign(cross(P - C, B - C))) return false;\n if (sign(cross(B - A, C - A)) != sign(cross(P - A, C - A))) return false;\n if (sign(cross(C - B, A - B)) != sign(cross(P - B, A - B))) return false;\n\n if (sign(cross(B - C, A - C)) != sign(cross(P - C, A - C))) return false;\n if (sign(cross(C - A, B - A)) != sign(cross(P - A, B - A))) return false;\n if (sign(cross(A - B, C - B)) != sign(cross(P - B, C - B))) return false;\n \n return true;\n }\n \n using Shape = vector;\n\n type get_area(Shape s) {\n type res = 0.0;\n int sz = s.size();\n for (int i = 0; i < sz; i++) {\n res += s[i].x * s[(i + 1) % sz].y;\n res -= s[i].y * s[(i + 1) % sz].x;\n }\n \n res /= 2.0;\n return res;\n }\n\n void print_shape(Shape s) {\n int sz = s.size();\n Shape tmp;\n tmp.emplace_back(s[0]);\n for (int i = 1; i < sz; i++) if (hypotl(s[i].x - s[i - 1].x, s[i].y - s[i - 1].y) > EPS) tmp.emplace_back(s[i]);\n\n s = tmp;\n sz = s.size();\n cout << sz << \" \";\n for (int i = 0; i < sz; i++) cout << s[i].x << \" \" << s[i].y << \" \";\n cout << \"\\n\";\n }\n\n Shape read_shape() {\n Shape res;\n Point in;\n int n; cin >> n; while (n--) {\n cin >> in.x >> in.y;\n res.emplace_back(in);\n }\n return res;\n }\n\n}\n\nusing namespace geometry;\n\n\nstruct Operation {\n Shape start_shape;\n vector cut_shapes;\n\n vector tape_shapes;\n Shape final_shape;\n\n Operation() {}\n};\n\n\nclass Scissors_and_Tape {\n\nprivate:\n\n Shape Start, Target;\n type Area;\n\n vector reverse_operations(vector op) {\n reverse(op.begin(), op.end());\n for (auto &i : op) swap(i.start_shape, i.final_shape);\n for (auto &i : op) swap(i.cut_shapes, i.tape_shapes);\n return op;\n }\n\n void rotate_left(Point &a, Point &b, Point &c) {\n Point tmp = a; a = b; b = c; c = tmp;\n }\n\n void rotate_right(Point &a, Point &b, Point &c) {\n Point tmp = c; c = b; b = a; a = tmp;\n }\n\n struct ListOfRectangles {\n\n vector H, W;\n\n ListOfRectangles() {}\n\n int size() {\n return H.size();\n }\n \n };\n\n /* Terms used:\n - Total Area = area of polygons S and T\n - Side = sqrt(Total Area)\n - Ideal Rectangle = a rectangle with heighh such that (Side / 2) <= H < Side\n - Rectangle = any rectangle, no requirements\n - Triangulate = cut polygons to triangles, and cut triangles and tape them to\n get rectangles\n\n Main Idea:\n - Turn S and T to squares, then inverse operations done on T\n - Any polygon can be cut into triangles, and if we put the side with longest length on the\n x-axis, then cut it in 3 parts (at half height), we get a rectangle\n - A rectangle can be turned into any rectangle by turning it to ideal, then cutting it into\n 3 pieces: small triangle, big triangle, and pentagon. Pentagon stays where it is, the big\n triangle is shifted diagonally up, and small triangle is moved from its original position\n to fill the gap, abpve the pentagon and on the left side of the big triangle.\n */\n\n ListOfRectangles triangulate_to_rectangles(Shape s, vector &ops) {\n Operation op;\n ListOfRectangles res;\n op.start_shape = s;\n\n type cur_x = 0.0;\n while (s.size() > 2) {\n for (int i = 0, N = s.size(); i < N; i++) {\n Point A = s[(i + N - 1) % N], B = s[i], C = s[(i + 1) % N];\n if (sign(cross(B - A, C - A)) == -1) continue; // the angle is concave\n\n /* Check if there is a point inside the triangle ABC */\n bool no_point_inside_triangle = true;\n for (int j = 0; j < N; j++) {\n if (i == j || ((i + N - 1) % N) == j || ((i + N + 1) % N) == j) continue;\n if (in_triangle(A, B, C, s[j])) no_point_inside_triangle = false;\n }\n if (!no_point_inside_triangle) continue;\n\n /* Make side AB the longest side */\n type l_AB = dot(B - A, B - A), l_BC = dot(C - B, C - B), l_AC = dot(C - A, C - A);\n while (l_AB < max(l_BC, l_AC)) {\n rotate_left(A, B, C);\n l_AB = dot(B - A, B - A), l_BC = dot(C - B, C - B), l_AC = dot(C - A, C - A);\n }\n\n /* Recompute after changes */\n Point U = A + (C - A) * 0.5; // halfway on line AC\n Point V = B + (C - B) * 0.5; // halfway on line BC\n Point M = ((U * dot(V - U, V - U)) + ((V - U) * dot(C - U, V - U))) / dot(V - U, V - U); // intersection of height of UVC and line UV \n\n /* Cut polygons UMC, MVC, ABVU */\n Point shift = A; // vector shifting triangle to 0, 0\n type deg = (B - shift).rot_diff(Point(0, 0)); // all points needed to be rotated by this much\n\n if (get_area({A, B, V, U}) > 0) {\n op.cut_shapes.push_back({A, B, V, U});\n op.tape_shapes.push_back({Point(cur_x, 0) + (A - shift).rot(deg), Point(cur_x, 0) + (B - shift).rot(deg), \n Point(cur_x, 0) + (V - shift).rot(deg), Point(cur_x, 0) + (U - shift).rot(deg)});\n }\n\n if (get_area({U, M, C}) > 0) {\n op.cut_shapes.push_back({U, M, C});\n op.tape_shapes.push_back({Point(cur_x, 0) + (U - shift).rot(deg), Point(cur_x, 0) + (U + U - M - shift).rot(deg), \n Point(cur_x, 0) + (A - shift).rot(deg)});\n \n }\n\n if (get_area({V, C, M}) > 0) {\n op.cut_shapes.push_back({V, C, M});\n op.tape_shapes.push_back({Point(cur_x, 0) + (V - shift).rot(deg), Point(cur_x, 0) + (B - shift).rot(deg), \n Point(cur_x, 0) + (V + V - M - shift).rot(deg)});\n }\n\n res.W.push_back(sqrtl(l_AB));\n res.H.push_back(get_area({A, B, C}) / res.W.back());\n\n op.final_shape.push_back({cur_x, res.H.back()});\n op.final_shape.push_back({cur_x + res.W.back(), res.H.back()});\n\n cur_x += sqrtl(l_AB);\n s.erase(s.begin() + i);\n break; \n }\n }\n\n op.final_shape.emplace_back(cur_x, 0);\n op.final_shape.emplace_back(0, 0);\n reverse(op.final_shape.begin(), op.final_shape.end());\n ops.emplace_back(op);\n\n return res;\n }\n\n ListOfRectangles rectangles_to_ideal_rectangles(ListOfRectangles rect, vector &ops) {\n type side = sqrtl(Area);\n vector &H = rect.H;\n vector &W = rect.W;\n\n while (true) {\n int N = rect.size();\n bool stop = true;\n ListOfRectangles nxt;\n type cut_x = 0.0;\n type tape_x = 0.0;\n Operation op;\n op.start_shape = ops.back().final_shape;\n\n for (int i = 0; i < N; i++) {\n if (H[i] * 2.0 < side) {\n stop = false;\n op.cut_shapes.push_back({{cut_x, 0}, {cut_x + W[i] / 2.0, 0}, {cut_x + W[i] / 2.0, H[i]}, {cut_x, H[i]}});\n op.tape_shapes.push_back({{tape_x, 0}, {tape_x + W[i] / 2.0, 0}, {tape_x + W[i] / 2.0, H[i]}, {tape_x, H[i]}});\n \n op.cut_shapes.push_back({{cut_x + W[i] / 2.0, 0}, {cut_x + W[i], 0}, {cut_x + W[i], H[i]}, {cut_x + W[i] / 2.0, H[i]}});\n op.tape_shapes.push_back({{tape_x, H[i]}, {tape_x + W[i] / 2.0, H[i]}, {tape_x + W[i] / 2.0, H[i] * 2.0}, {tape_x, H[i] * 2.0}});\n \n op.final_shape.emplace_back(tape_x, H[i] * 2.0);\n op.final_shape.emplace_back(tape_x + W[i] / 2.0, H[i] * 2.0);\n \n tape_x += W[i] / 2.0;\n cut_x += W[i];\n\n nxt.W.push_back(W[i] / 2.0);\n nxt.H.push_back(H[i] * 2.0);\n } else if (H[i] >= side) {\n stop = false;\n op.cut_shapes.push_back({{cut_x, 0}, {cut_x + W[i], 0}, {cut_x + W[i], H[i] / 2.0}, {cut_x, H[i] / 2.0}});\n op.tape_shapes.push_back({{tape_x, 0}, {tape_x + W[i], 0}, {tape_x + W[i], H[i] / 2.0}, {tape_x, H[i] / 2.0}});\n \n op.cut_shapes.push_back({{cut_x, H[i] / 2.0}, {cut_x + W[i], H[i] / 2.0}, {cut_x + W[i], H[i]}, {cut_x, H[i]}});\n op.tape_shapes.push_back({{tape_x + W[i], 0}, {tape_x + W[i] * 2.0, 0}, {tape_x + W[i] * 2.0, H[i] / 2.0}, {tape_x + W[i], H[i] / 2.0}});\n \n op.final_shape.emplace_back(tape_x, H[i] / 2.0);\n op.final_shape.emplace_back(tape_x + W[i] * 2.0, H[i] / 2.0);\n \n tape_x += W[i] * 2.0;\n cut_x += W[i];\n \n nxt.W.push_back(W[i] * 2.0);\n nxt.H.push_back(H[i] / 2.0);\n } else {\n op.cut_shapes.push_back({{cut_x, 0}, {cut_x + W[i], 0}, {cut_x + W[i], H[i]}, {cut_x, H[i]}});\n op.tape_shapes.push_back({{tape_x, 0}, {tape_x + W[i], 0}, {tape_x + W[i], H[i]}, {tape_x, H[i]}});\n \n op.final_shape.emplace_back(tape_x, H[i]);\n op.final_shape.emplace_back(tape_x + W[i], H[i]);\n \n tape_x += W[i];\n cut_x += W[i];\n\n nxt.W.push_back(W[i]);\n nxt.H.push_back(H[i]);\n }\n }\n\n op.final_shape.emplace_back(tape_x, 0);\n op.final_shape.emplace_back(0, 0);\n\n reverse(op.final_shape.begin(), op.final_shape.end());\n\n ops.emplace_back(op);\n rect = nxt;\n if (stop) break;\n }\n\n return rect;\n }\n\n void ideal_rectangles_to_square(ListOfRectangles rect, vector &ops) {\n type cut_x = 0.0;\n type tape_x = 0.0;\n type side = sqrtl(Area);\n Operation op;\n op.start_shape = ops.back().final_shape;\n \n int N = rect.size();\n vector H = rect.H;\n vector W = rect.W;\n\n for (int i = 0; i < N; i++) {\n type new_cut_x = cut_x + W[i];\n type right_triangle = ((H[i] * W[i]) / side);\n type diff_height = side - H[i];\n /* Cut rectangle to 3 pieces: 2 triangles and pentagon */\n\n /* Triangles */\n op.cut_shapes.push_back({{right_triangle + cut_x, 0}, {new_cut_x, 0}, {right_triangle + cut_x, diff_height}});\n op.tape_shapes.push_back({{tape_x, side - diff_height}, {W[i] - right_triangle + tape_x, side - diff_height}, {tape_x, side}});\n\n op.cut_shapes.push_back({{new_cut_x, 0}, {new_cut_x, H[i]}, {W[i] - right_triangle + cut_x, H[i]}});\n op.tape_shapes.push_back({{tape_x + right_triangle, diff_height}, {tape_x + right_triangle, side}, {tape_x, side}});\n\n /* Pentagon */ \n op.cut_shapes.push_back({{cut_x, 0}, {cut_x + right_triangle, 0}, {cut_x + right_triangle, diff_height}, \n {cut_x + W[i] - right_triangle, H[i]}, {cut_x, H[i]}});\n op.tape_shapes.push_back({{tape_x, 0}, {tape_x + right_triangle, 0}, {tape_x + right_triangle, diff_height}, \n {tape_x + W[i] - right_triangle, H[i]}, {tape_x, H[i]}});\n \n cut_x = new_cut_x;\n tape_x = tape_x + right_triangle;\n }\n\n op.final_shape = {{0, 0}, {side, 0}, {side, side}, {0, side}};\n ops.emplace_back(op);\n }\n\n vector polygon_to_square(Shape s) {\n vector res;\n ListOfRectangles rectangles = triangulate_to_rectangles(s, res);\n ListOfRectangles ideal_rectangles = rectangles_to_ideal_rectangles(rectangles, res);\n ideal_rectangles_to_square(ideal_rectangles, res);\n return res;\n }\n\npublic:\n\n Scissors_and_Tape() {};\n\n Scissors_and_Tape(Shape s, Shape t): Start(s), Target(t) {}\n\n vector get_solution() {\n Area = get_area(Start);\n vector start_to_square = polygon_to_square(Start);\n vector target_to_square = reverse_operations(polygon_to_square(Target)); \n vector res;\n res.insert(res.end(), start_to_square.begin(), start_to_square.end());\n res.insert(res.end(), target_to_square.begin(), target_to_square.end());\n\n return res;\n }\n\n};\n\n\nint main() {\n cout << fixed << setprecision(10);\n \n Shape Start = read_shape();\n Shape Target = read_shape();\n\n Scissors_and_Tape solver(Start, Target);\n vector solution = solver.get_solution();\n \n int cur_id = 0;\n for (auto op : solution) {\n int new_id = cur_id + op.cut_shapes.size() + 1;\n\n cout << \"scissors\\n\";\n cout << cur_id << \" \" << op.cut_shapes.size() << \"\\n\";\n for (auto s : op.cut_shapes) print_shape(s);\n\n cout << \"tape\\n\";\n cout << op.tape_shapes.size();\n for (int id = cur_id + 1; id < new_id; id++) cout << \" \" << id;\n cout << \"\\n\";\n for (auto s : op.tape_shapes) print_shape(s);\n print_shape(op.final_shape);\n\n cur_id = new_id;\n }\n\n return 0;\n}\n", "src_uid": "375b83d1b7a911c1ca67d5209d39adb4"} {"source_code": "#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 cin>>n;\n\n int s = 0;\n for (s=1;s*(s+1)/2 < n;s++);\n\n if ( s*(s+1)/2 == n )\n {\n cout<\n\nusing namespace std;\nint arr[110][2], arr2[100], n, k, i, a, cnt;\n\nbool isSuitable()\n{\n for(i = 1 ; i <= 100 ; i++)\n {\n if(arr[i][0] != 0)\n {\n cnt++;\n arr2[cnt] = arr[i][1];\n }\n }\n if(cnt >= k)\n return true;\n else\n return false;\n}\n\nvoid readA()\n{\n for(i = 1 ; i <= n ; i++)\n {\n scanf(\"%d\", &a);\n arr[a][0]++;\n arr[a][1] = i;\n }\n}\nint main()\n{\n scanf(\"%d%d\", &n, &k);\n readA();\n bool suitable;\n suitable = isSuitable();\n sort(arr2, arr2 + cnt);\n printf(\"%s\\n\", suitable ? \"YES\" : \"NO\");\n if(suitable)\n for(i = 1 ; i <= k ; i ++)\n printf(\"%d \", arr2[i]);\n \n printf(\"\\n\");\n\n}", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"source_code": "#include \n#include \n#include \nusing namespace std;\nconst int N = 315;\nint s1[N],s2[N];\nint main()\n{\n int x,t,a,b,d1,d2;\n while(scanf(\"%d%d%d%d%d%d\",&x,&t,&a,&b,&d1,&d2) != EOF)\n {\n for(int i = 0; i < t; i++)\n {\n s1[i] = a - d1 * i;\n s2[i] = b - d2 * i;\n }\n s1[t] = s2[t] = 0;\n bool mark = false;\n for(int i = 0; i <= t; i++)\n {\n for(int j = 0; j <= t; j++)\n {\n if(s1[i] + s2[j] == x)\n {\n mark = true;\n break;\n }\n }\n }\n puts(mark ? \"YES\" : \"NO\");\n }\n return 0;\n}\n\n", "src_uid": "f98168cdd72369303b82b5a7ac45c3af"} {"source_code": "#include\ntypedef long long ll;\nusing namespace std;\n#define N 200010\nstruct Edge{\n\tll l;\n\tint e,n;\n}e[N<<1];\nint hd[N],cur[N],cnt=1;\nvoid add(int a,int b,ll l){\n\te[++cnt].e=b;e[cnt].l=l;e[cnt].n=hd[a];hd[a]=cnt;\n\te[++cnt].e=a;e[cnt].l=0;e[cnt].n=hd[b];hd[b]=cnt;\n}\nll inf=1e15;\nint n,m,s,t;\nll a[N];\nint dep[N];\nqueueQ;\nll dfs(int p,ll flow){\n\tif(p==t)return flow;\n\tint i;\n\tfor(i=cur[p];i;i=e[i].n){\n\t\tint q=e[i].e;\n\t\tcur[p]=i;\n\t\tif(dep[q]==dep[p]+1&&e[i].l){\n\t\t\tll ans=dfs(q,min(flow,e[i].l));\n\t\t\tif(ans){\n\t\t\t\te[i].l-=ans;\n\t\t\t\te[i^1].l+=ans;\n\t\t\t\treturn ans;\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\nint bfs(){\n\tmemset(dep,0,sizeof(dep));\n\tQ.push(s);dep[s]=1;\n\tint i;\n\twhile(!Q.empty()){\n\t\tint p=Q.front();Q.pop();\n\t\tfor(i=hd[p];i;i=e[i].n){\n\t\t\tint q=e[i].e;\n\t\t\tif(!dep[q]&&e[i].l)dep[q]=dep[p]+1,Q.push(q);\n\t\t}\n\t}\n\treturn dep[t];\n}\nint tot;//�ڵ�\nll dinic(){\n\tint i;\n\tll d,ans=0;\n\twhile(bfs()){\n\t\tfor(i=0;i<=tot;i++)cur[i]=hd[i];\n\t\twhile((d=dfs(s,inf)))ans+=d;\n\t}\n\treturn ans;\n}\nint id[N],L[N],R[N];\nvoid build(int p,int l,int r){\n\tid[p]=++tot;\n\tL[p]=l;R[p]=r;\n\tif(l==r){\n\t\tadd(tot,l,1);\n\t\treturn;\n\t}\n\tbuild(p<<1,l,(l+r)>>1);\n\tbuild(p<<1|1,((l+r)>>1)+1,r);\n\tadd(id[p],id[p<<1],inf);\n\tadd(id[p],id[p<<1|1],inf);\n}\nvoid upd(int p,int l,int r){\n\tif(L[p]>=l&&R[p]<=r){\n\t\tadd(tot,id[p],1);\n\t\treturn;\n\t}\n\tif(L[p]>r||R[p]mp[N];\nint vis[N],start,ret;\nvoid solve(int x){\n\tif(x>=start){ret=x-start;return;}\n\tmap::iterator it=mp[x].begin();\n\tsolve(it->first);\n\t--it->second;\n\tif(!it->second)mp[x].erase(it);\n}\nint main(){\n\tint i,j,u,k,l,r,opt;\n\tint temp=0;\n\tscanf(\"%d%d\",&n,&m);\n\ttot=m;\n\tbuild(1,1,m);\n\ts=++tot;t=++tot;\n\tstart=tot;\n\tfor(i=1;i<=n;i++){\n\t\t++tot;\n\t\tscanf(\"%d\",&opt);\n\t\tif(opt==0){\n\t\t\tadd(s,tot,1);\n\t\t\tscanf(\"%d\",&k);\n\t\t\twhile(k--)scanf(\"%d\",&u),add(tot,u,1);\n\t\t}else if(opt==1){\n\t\t\tadd(s,tot,1);\n\t\t\tscanf(\"%d%d\",&l,&r);\n\t\t\tupd(1,l,r);\n\t\t}else{\n\t\t\tint A,B,C;\n\t\t\tscanf(\"%d%d%d\",&A,&B,&C);\n\t\t\tadd(tot,A,1);\n\t\t\tadd(tot,B,0);e[cnt].l=1;vis[B]=1;\n\t\t\tadd(tot,C,1);e[cnt].l=1;vis[C]=1;\n\t\t\ttemp+=2;\n\t\t}\n\t}\n\tfor(i=1;i<=m;i++)if(!vis[i])add(i,t,1);\n\tprintf(\"%I64d\\n\",dinic()+temp);\n\tfor(i=1;i<=tot;i++)\n\t\tfor(j=hd[i];j;j=e[j].n)\n\t\t\tif((j&1)&&e[j].l)mp[i][e[j].e]=e[j].l;\n\tfor(i=1;i<=m;i++){\n\t\tint flag=0;\n\t\tfor(j=hd[i];j;j=e[j].n)if(e[j].e==t&&e[j].l){\n\t\t\tflag=1;\n\t\t\tbreak;\n\t\t}\n\t\tif(flag)continue;\n\t\tsolve(i);\n\t\tprintf(\"%d %d\\n\",ret,i);\n\t}\n\treturn 0;\n}\n", "src_uid": "429a94c8e3f28100c8c532e948cc36e3"} {"source_code": "#include \n\n#define SQ(a) (a)*(a)\n\n#define F0R(i, a) for(int i = 0; i < (a); i++)\n#define FOR(i, a, b) for(int i = (a); i < (b); i++)\n#define R0F(i, a) for(int i = (a) - 1; i >= 0; i--)\n#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)\n\n#define ran() (rand() & 0x7FFF)\n#define rand31() ((ran() << 16) | (ran() << 1) | (ran() & 1))\n#define rand32() ((ran() << 17) | (ran() << 2) | (ran() & 3))\n#define rand63() (((ll)ran() << 48) | ((ll)ran() << 33) | ((ll)ran() << 18) | ((ll)ran() << 3) | ((ll)ran() & 7))\n#define rand64() (((ll)ran() << 49) | ((ll)ran() << 34) | ((ll)ran() << 19) | ((ll)ran() << 4) | ((ll)ran() & 15))\n\n#define F first\n#define S second\n#define PB push_back\n#define MP make_pair\n#define MT make_tuple\n#define UB upper_bound\n#define LB lower_bound\n#define X real()\n#define Y imag()\n#define R real()\n#define I image()\n#define PI acos(-1)\n#define MAXN 30\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\ntypedef pair pii;\ntypedef vector vi;\ntypedef complex point;\ntypedef complex cld;\n\nnamespace NTT {\n\nconst int MAX_DEG = 20, EXP_MULT = 119ULL, EXP = 23;\null NTTMod = (EXP_MULT << EXP) + 1, NTTBuild[1 << MAX_DEG][2], rt[(1 << MAX_DEG) + 1];\n\null modPow(ull a, ull p) {\n if(!p) return 1;\n if(p & 1) return a * modPow(a, p ^ 1) % NTTMod;\n ull sqrt = modPow(a, p >> 1);\n return SQ(sqrt) % NTTMod;\n}\n\null invMod(ull a) {\n return modPow(a, NTTMod - 2);\n}\n\null findCyclic() {\n vi multFactors;\n ull temp = EXP_MULT;\n for(int i = 2; i * i <= temp; i += 2) {\n if(temp % i == 0) multFactors.PB(i);\n while(temp % i == 0) temp /= i;\n if(i == 2) i--;\n }\n if(temp > 1) multFactors.PB(temp);\n FOR(i, 2, NTTMod) {\n bool works = 1;\n if(modPow(i, NTTMod >> 1) == 1) works = 0;\n for(const int factor : multFactors) if(modPow(i, NTTMod / factor) == 1) works = 0;\n if(works) return i;\n }\n}\n\nvoid buildRT() {\n if(rt[0] == 1) return;\n rt[0] = 1;\n rt[1] = modPow(findCyclic(), EXP_MULT << (EXP - MAX_DEG));\n FOR(i, 2, (1 << MAX_DEG) + 1) rt[i] = rt[i - 1] * rt[1] % NTTMod;\n}\n\nvoid ntt(int neededDeg, ull* vals, int len) {\n R0F(i, neededDeg + 1) {\n int arr = i & 1, narr = arr ^ 1, lli = 1 << i, llil = lli << 1, llndim1 = 1 << (neededDeg - i - 1), rtp = lli << (MAX_DEG - neededDeg);\n if(i == neededDeg) {\n F0R(j, len) NTTBuild[j][arr] = vals[j];\n FOR(j, len, lli) NTTBuild[j][arr] = 0;\n } else F0R(j, lli) {\n int x = j, y = 0, z = j, w = j + lli;\n F0R(k, llndim1) {\n NTTBuild[x][arr] = (NTTBuild[z][narr] + NTTBuild[w][narr] * rt[y]) % NTTMod;\n x += lli, y += rtp, z += llil, w += llil;\n }\n z = j, w = j + lli;\n F0R(k, llndim1) {\n NTTBuild[x][arr] = (NTTBuild[z][narr] + NTTBuild[w][narr] * rt[y]) % NTTMod;\n x += lli, y += rtp, z += llil, w += llil;\n }\n }\n }\n}\n\nvoid invntt(ull *p, int pdeg) {\n int mp = 1 << MAX_DEG;\n R0F(i, pdeg + 1) {\n int arr = i & 1, narr = arr ^ 1, lli = 1 << i, llil = lli << 1, llpdim1 = 1 << (pdeg - i - 1), rtp = lli << (MAX_DEG - pdeg);\n R0F(j, lli) {\n if(i == pdeg) NTTBuild[j][arr] = p[j];\n else {\n int x = j, y = mp, z = j, w = lli + j;\n F0R(k, llpdim1) {\n NTTBuild[x][arr] = (NTTBuild[z][narr] + NTTBuild[w][narr] * rt[y]) % NTTMod;\n x += lli, y -= rtp, z += llil, w += llil;\n }\n z = j, w = lli + j;\n F0R(k, llpdim1) {\n NTTBuild[x][arr] = (NTTBuild[z][narr] + NTTBuild[w][narr] * rt[y]) % NTTMod;\n x += lli, y -= rtp, z += llil, w += llil;\n }\n }\n }\n }\n ull u = invMod(1 << pdeg);\n F0R(i, 1 << pdeg) NTTBuild[i][0] *= u, NTTBuild[i][0] %= NTTMod;\n}\n\n};\n\nusing namespace NTT;\n\null tempPVPoly[1 << MAX_DEG];\n\nstruct Polynomial {\n\n int deg;\n ull *coefficients;\n\n Polynomial(int d = 0) {\n deg = d;\n coefficients = new ull[deg + 1];\n memset(coefficients, 0, (deg + 1) * sizeof(ull));\n buildRT();\n }\n\n Polynomial operator ()(Polynomial p) {\n Polynomial curr;\n curr[0] = 1;\n Polynomial res;\n F0R(i, deg + 1) {\n res += curr * coefficients[i];\n curr *= p;\n }\n return res;\n }\n\n ull& operator [](int idx) { return coefficients[idx]; }\n\n Polynomial operator +(ull a) {\n Polynomial p(deg);\n F0R(i, deg + 1) p[i] = coefficients[i];\n p[0] += a;\n p[0] %= NTTMod;\n return p;\n }\n\n Polynomial operator -(ull a) {\n Polynomial p(deg);\n F0R(i, deg + 1) p[i] = coefficients[i];\n p[0] += NTTMod - a;\n p[0] %= NTTMod;\n return p;\n }\n\n Polynomial operator *(ull mult) {\n Polynomial p(deg);\n F0R(i, deg + 1) p[i] = coefficients[i] * mult % NTTMod;\n return p;\n }\n\n Polynomial operator /(ull div) { return *this * invMod(div); }\n\n Polynomial operator +(Polynomial b) {\n Polynomial res(max(deg, b.deg));\n F0R(i, max(deg, b.deg) + 1) res[i] = (((i > deg) ? 0 : coefficients[i]) + ((i > b.deg) ? 0 : b[i])) % NTTMod;\n return res;\n }\n\n Polynomial operator -(Polynomial p) { return *this + (p * (NTTMod - 1)); }\n\n Polynomial operator *(Polynomial b) {\n int neededDeg = 32 - __builtin_clz(deg + b.deg);\n ntt(neededDeg, coefficients, deg + 1);\n F0R(i, (1 << neededDeg)) tempPVPoly[i] = NTTBuild[i][0];\n ntt(neededDeg, b.coefficients, b.deg + 1);\n F0R(i, (1 << neededDeg)) tempPVPoly[i] = tempPVPoly[i] * NTTBuild[i][0] % NTTMod;\n invntt(tempPVPoly, neededDeg);\n Polynomial res(deg + b.deg);\n F0R(i, res.deg + 1) res[i] = NTTBuild[i][0];\n return res;\n }\n\n void operator +=(ull a) { coefficients[0] += a, coefficients[0] %= NTTMod; }\n\n void operator -=(ull a) { *this += NTTMod - a; }\n\n void operator *=(ull mult) { F0R(i, deg + 1) coefficients[i] *= mult, coefficients[i] %= NTTMod; }\n\n void operator /=(ull div) { *this *= invMod(div); }\n\n void operator +=(Polynomial b) { *this = *this + b; }\n\n void operator -=(Polynomial p) { *this = *this - p; }\n\n void operator *=(Polynomial b) { *this = *this * b; }\n\n};\n\nint n;\null x[MAXN];\null modX[MAXN];\nvector, pair>>> func;\n\nPolynomial indefInt(Polynomial f) {\n Polynomial res(f.deg + 1);\n FOR(i, 1, res.deg + 1) res[i] = f[i - 1] * invMod(i) % NTTMod;\n return res;\n}\n\nPolynomial defInt(Polynomial f, Polynomial lo, Polynomial hi) {\n Polynomial F = indefInt(f);\n return F(hi) - F(lo);\n}\n\nPolynomial makeCopy(Polynomial p) {\n Polynomial res(p.deg);\n F0R(i, res.deg + 1) res[i] = p[i];\n return res;\n}\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cin >> n;\n F0R(i, n) {\n string s;\n cin >> s;\n int numDecimalPlaces = 0;\n R0F(j, s.size()) if(s[j] == '.') numDecimalPlaces = s.size() - j - 1;\n ull base = modPow(10, 6 - numDecimalPlaces);\n R0F(j, s.size()) if(s[j] != '.') {\n x[i] += base * (s[j] - '0');\n base *= 10;\n }\n }\n x[0] = min(1000000ULL, x[0]);\n FOR(i, 1, n) x[i] = min(x[i], x[i - 1] + 1000000ULL);\n ull invMillion = invMod(1000000ULL);\n F0R(i, n) modX[i] = x[i] * invMillion % NTTMod;\n func.PB(MP(Polynomial(), MP(MP(0, 0), MP(x[0], modX[0]))));\n func[0].F[0] = 1;\n Polynomial xPoly(1);\n xPoly[1] = 1;\n F0R(i, n - 1) {\n vector v2;\n vector, bool, int>> v;\n F0R(j, func.size()) {\n pair lo = func[j].S.F;\n pair hi = func[j].S.S;\n Polynomial loPoly;\n Polynomial hiPoly;\n loPoly[0] = lo.S;\n hiPoly[0] = hi.S;\n pair xVal = MP(x[i + 1], modX[i + 1]);\n pair loP1 = MP(lo.F + 1000000ULL, (lo.S + 1) % NTTMod);\n pair hiP1 = MP(hi.F + 1000000ULL, (hi.S + 1) % NTTMod);\n if(xVal.F > lo.F) {\n v2.PB(defInt(func[j].F, loPoly, xPoly));\n v.PB(MT(lo, 1, v2.size() - 1));\n v.PB(MT(min(hi, xVal), 0, v2.size() - 1));\n }\n if(hi.F < lo.F + 1000000ULL && xVal.F > hi.F) {\n v2.PB(defInt(func[j].F, loPoly, hiPoly));\n v.PB(MT(hi, 1, v2.size() - 1));\n v.PB(MT(min(loP1, xVal), 0, v2.size() - 1));\n }\n if(lo.F + 1000000ULL < xVal.F) {\n v2.PB(defInt(func[j].F, xPoly + (NTTMod - 1), hiPoly));\n v.PB(MT(loP1, 1, v2.size() - 1));\n v.PB(MT(min(hiP1, xVal), 0, v2.size() - 1));\n }\n }\n func.clear();\n sort(v.begin(), v.end());\n pair last = MP(0, 0);\n Polynomial curr;\n for(const tuple, bool, int> t : v) {\n if(get<0>(t) > last) func.PB(MP(makeCopy(curr), MP(last, get<0>(t))));\n if(get<1>(t)) curr += v2[get<2>(t)];\n else curr -= v2[get<2>(t)];\n last = get<0>(t);\n }\n }\n Polynomial res;\n F0R(i, func.size()) {\n Polynomial lo, hi;\n lo[0] = func[i].S.F.S;\n hi[0] = func[i].S.S.S;\n res += defInt(func[i].F, lo, hi);\n }\n cout << res[0] << endl;\n return 0;\n}\n", "src_uid": "fed8173bf7731f3d663467cc0131d788"} {"source_code": "#include\nusing namespace std;\nint main(){\n int n,k;\n cin>>n>>k;\n cout<\n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\n#include \n// ♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂\nusing namespace std;\n#define ll long long\n#define ull unsigned long long\n#define all(x) (x).begin(), (x).end() \n#define ayacin ios::sync_with_stdio(false);\n#define yukari 9999999999999999\n#define mod 1000000007\n#define M_PI12 3.141592653\n#define Parseedouble long double\n#define lson l , m , rt << 1\n#define rson m + 1 , r , rt << 1 | 1\n#define reimu iterator \n#define x first\n#define y second\nconst int MAXN=1e5+5;\nint a[MAXN];\nint main(){\n\tint m,n,i,j,k;\n\tayacin;\n\tcin>>m;\n\tfor(i=1;i<=m;i++) cin>>a[i];\n\tsort(a+1,a+1+m);\n\treverse(a+1,a+1+m);\n\tfor(i=2;i<=m;i++){\n\t\tif(a[i]*2>a[i-1]&&a[i]!=a[i-1]) return puts(\"YES\");\n\t}\n\treturn puts(\"NO\");\n}\n", "src_uid": "ab003ab094931fc105384df9d144131e"} {"source_code": "#include \nusing namespace std;\n\n#define ll long long\n#define ld long double\n#define ar array\n\n#include \n#include \nusing namespace __gnu_pbds;\n\ntemplate using oset = tree, rb_tree_tag, tree_order_statistics_node_update>;\n\n#define vt vector\n#define pb push_back\n#define all(c) (c).begin(), (c).end()\n#define sz(x) (int)(x).size()\n\n#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))\n#define F_OR1(e) F_OR(i, 0, e, 1)\n#define F_OR2(i, e) F_OR(i, 0, e, 1)\n#define F_OR3(i, b, e) F_OR(i, b, e, 1)\n#define F_OR4(i, b, e, s) F_OR(i, b, e, s)\n#define GET5(a, b, c, d, e, ...) e\n#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)\n#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)\n#define EACH(x, a) for (auto& x: a)\n\ntemplate bool umin(T& a, const T& b) {\n\treturn b bool umax(T& a, const T& b) { \n\treturn a f, ll lb, ll rb) {\n\twhile(lb f, ll lb, ll rb) {\n\twhile(lb void read(vt& v);\ntemplate void read(ar& a);\ntemplate void read(T& x) {\n\tcin >> x;\n}\nvoid read(double& d) {\n\tstring t;\n\tread(t);\n\td=stod(t);\n}\nvoid read(long double& d) {\n\tstring t;\n\tread(t);\n\td=stold(t);\n}\ntemplate void read(H& h, T&... t) {\n\tread(h);\n\tread(t...);\n}\ntemplate void read(vt& x) {\n\tEACH(a, x)\n\t\tread(a);\n}\ntemplate void read(array& x) {\n\tEACH(a, x)\n\t\tread(a);\n}\n\nstring to_string(char c) {\n\treturn string(1, c);\n}\nstring to_string(bool b) {\n\treturn b?\"true\":\"false\";\n}\nstring to_string(const char* s) {\n\treturn string(s);\n}\nstring to_string(string s) {\n\treturn s;\n}\nstring to_string(vt v) {\n\tstring res;\n\tFOR(sz(v))\n\t\tres+=char('0'+v[i]);\n\treturn res;\n}\n\ntemplate string to_string(bitset b) {\n\tstring res;\n\tFOR(S)\n\t\tres+=char('0'+b[i]);\n\treturn res;\n}\ntemplate string to_string(T v) {\n bool f=1;\n string res;\n EACH(x, v) {\n\t\tif(!f)\n\t\t\tres+=' ';\n\t\tf=0;\n\t\tres+=to_string(x);\n\t}\n return res;\n}\n\ntemplate void write(A x) {\n\tcout << to_string(x);\n}\ntemplate void write(const H& h, const T&... t) { \n\twrite(h);\n\twrite(t...);\n}\nvoid print() {\n\twrite(\"\\n\");\n}\ntemplate void print(const H& h, const T&... t) { \n\twrite(h);\n\tif(sizeof...(t))\n\t\twrite(' ');\n\tprint(t...);\n}\n\nvoid DBG() {\n\tcerr << \"]\" << endl;\n}\ntemplate void DBG(H h, T... t) {\n\tcerr << to_string(h);\n\tif(sizeof...(t))\n\t\tcerr << \", \";\n\tDBG(t...);\n}\n#ifdef _DEBUG\n#define dbg(...) cerr << \"LINE(\" << __LINE__ << \") -> [\" << #__VA_ARGS__ << \"]: [\", DBG(__VA_ARGS__)\n#else\n#define dbg(...) 0\n#endif\n\ntemplate void offset(ll o, T& x) {\n\tx+=o;\n}\ntemplate void offset(ll o, vt& x) {\n\tEACH(a, x)\n\t\toffset(o, a);\n}\ntemplate void offset(ll o, ar& x) {\n\tEACH(a, x)\n\t\toffset(o, a);\n}\n\nmt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());\nll randint(ll a, ll b) {\n\treturn uniform_int_distribution(a, b)(mt_rng);\n}\n\ntemplate void vti(vt &v, U x, size_t n) {\n\tv=vt(n, x);\n}\ntemplate void vti(vt &v, U x, size_t n, size_t m...) {\n\tv=vt(n);\n\tEACH(a, v)\n\t\tvti(a, x, m);\n}\n\nconst int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};\nconst int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};\n\nconst int mxA=5e6, M=998244353;\nint n, m;\nll iv[mxA], f1[mxA], f2[mxA];\n\nll inv(ll a, ll m) {\n\treturn (a%=m)>1?(1-m*inv(m, a))/a+m:1;\n}\n\nvoid solve() {\n\tiv[1]=1;\n\tFOR(i, 2, mxA)\n\t\tiv[i]=M-M/i*iv[M%i]%M;\n\tf1[0]=f2[0]=1;\n\tFOR(i, 1, mxA) {\n\t\tf1[i]=f1[i-1]*i%M;\n\t\tf2[i]=f2[i-1]*iv[i]%M;\n\t}\n\tread(n, m);\n\tll ans=0;\n\tFOR(x, 1, n+1) {\n\t\tint y=n-x;\n\t\tll ca=(M+x%2*2-1)*f1[n]%M*f2[x]%M*f2[y]%M;\n\t\t//ll d=m*iv[x+m]%M*f1[x]%M*f1[y]%M*f2[n]%M;\n\t\tll d=m*iv[x+m]%M;\n\t\tdbg(d, iv[4]);\n\t\tca=ca*inv(M+1-d, M)%M;\n\t\t//ca=ca*f1[x]%M*f1[y]%M*f1[m]%M*f2[n+m]%M*f1[n+m+1]%M*f2[m+1]%M*f2[n]%M;\n\t\tca=ca*f1[m]%M*f2[n+m]%M*f1[n+m+1]%M*f2[m+1]%M;\n\t\t//dbg(f1[x]%M*f1[y]%M*f1[m]%M*f2[n+m]%M*f1[n+m+1]%M*f2[m+1]%M*f2[n]%M);\n\t\tdbg(ca);\n\t\tans+=ca;\n\t}\n\tprint(ans%M);\n}\n\nint main() {\n\tios::sync_with_stdio(0);\n\tcin.tie(0);\n\n\tint t=1;\n\t//read(t);\n\tFOR(t) {\n\t\t//write(\"Case #\", i+1, \": \");\n\t\tsolve();\n\t}\n}", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613"} {"source_code": "#include\nusing namespace std;\n\nint main()\n{\n\tint q,flag=0;\n\tcin >> q;\n\tint a,b;\n\n\tint arr[5][5]={0};\n\tfor(int g=0;g<5;g++)\n\tarr[g][g]=-1;\n\tfor(int i=0;i> a >> b;\n\t\ta--,b--;\n\t\tarr[a][b]=arr[b][a]=1;\n\t}\n\t/*for(int j=0;j<5;j++)\n\t{\n\t for(int h=0;h<5;h++)\n\t {\n\t cout << arr[j][h] << \" \";\n\t }\n\t \n\t cout << \"\\n\";\n\t}*/\n\t\n\tfor(int j=0;j<5;j++)\n\t{\n\t\tfor(int k=0;k<4;k++)\n\t\t{\n\t\t\tfor(int h=k+1;h<5;h++)\n\t\t\t{\n\t\t\t\tif(arr[j][k]+arr[j][h]+arr[h][k]==0 || arr[j][k]+arr[j][h]+arr[h][k]==3)\n\t\t\t\t\tflag++;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(flag==0)\n\t\tcout << \"FAIL\" << endl;\n\telse \n\t cout << \"WIN\" << endl;\n\treturn 0;\n\n}\n", "src_uid": "2bc18799c85ecaba87564a86a94e0322"} {"source_code": "#include\nusing namespace std;\n#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n#define endl \"\\n\"\n//#define int long long \n// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};\n// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};\nconst long long mod = 1e9 + 7;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef vector vs;\ntypedef vector vb;\ntypedef pair ii;\ntypedef vector< pair< int, int > > vii;\ntypedef map mii;\ntypedef pair pip;\ntypedef pair ppi;\n#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i>arr[i];\n#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i>t; while(t--)\n#define takeInp(n) int n;cin>>n;\n#define fr(i,init,final) for(int i=init;i>n)arr.push_back(n);\n\treturn arr;\n}\nint pow(int x, int y)\n{ \n\tif(y==0)return 1;\n\tint u=pow(x,y/2);\n\tu=u*u;\n\tif(y%2)u=x*u;\n\treturn u;\n \n}\nint gcd(int a,int b)\n{\n\tif(ar||idx(l+(r-l+1)/2-1)&&idx<=r)return q1+1;\n\t\tll q2=solve(l,(l+(r-l+1)/2-1),idx,h-1,1);\n\t\treturn q1+q2+1;\t\n\t}\n\telse \n\t{\n\t\t ll q2=solve(l,(l+(r-l+1)/2-1),idx,h-1,1);\n\n\t\tif(idx<=(l+(r-l+1)/2-1)&&idx>=l)return q2+1;\n\t\tll q1=solve(l+(r-l+1)/2-1+1,r,idx,h-1,0);\n\t\treturn q1+q2+1;\n\n\t}\n}\nsigned main()\n{\n\tIOS\n\tll n ,h;\n\tcin>>h>>n;\n\tll q=solve(1,(ll)1<\n#include \ntypedef std::pair ii;\nusing namespace std;\n\nint abs(int a) {\n if (a > 0) return a;\n return -a;\n}\nint solve(int N) {\n ii c[4];\n int i;\n for (i = 0; i < 4; i++) {\n int x, y; scanf(\"%d %d\", &x, &y);\n c[i] = { x, y };\n }\n if (N == 1) return -1;\n if (N == 2) {\n int area = (c[1].first - c[0].first) * (c[1].second - c[0].second);\n area = abs(area);\n if (area == 0) area = -1;\n return area;\n }\n if (N == 3) {\n int a1 = (c[1].first - c[0].first) * (c[1].second - c[0].second);\n int a2 = (c[2].first - c[1].first) * (c[2].second - c[1].second);\n int a3 = (c[2].first - c[0].first) * (c[2].second - c[0].second);\n if (a1 != 0) return abs(a1);\n if (a2 != 0) return abs(a2);\n return abs(a3);\n }\n if (N == 4) {\n int xmin = 1001, xmax = -1001, ymin = 1001, ymax = -1001;\n for (i = 0; i < 4; i++) {\n if (xmin > c[i].first) xmin = c[i].first;\n if (xmax < c[i].first) xmax = c[i].first;\n if (ymin > c[i].second) ymin = c[i].second;\n if (ymax < c[i].second) ymax = c[i].second;\n }\n return abs( (xmax - xmin) * (ymax - ymin)) ;\n }\n return -1;\n}\nint main(void) {\n int N; scanf(\"%d\", &N);\n printf(\"%d\\n\", solve(N));\n}", "src_uid": "ba49b6c001bb472635f14ec62233210e"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nconst int MAXN = 1000005;\nint n, head[MAXN], cnt;\nint endpoint[MAXN][2];\nlong long number[MAXN], d[MAXN];\nbool vis[MAXN];\nstruct point\n{\n long long x, y;\n} P[MAXN];\nlong long dist(point a, point b)\n{\n return abs(a.x - b.x) + abs(a.y - b.y);\n}\nbool operator < (point a, point b)\n{\n return max(a.x, a.y) < max(b.x, b.y) || (max(a.x, a.y) == max(b.x, b.y) && a.y * b.x < b.y * a.x);\n}\nstruct edge\n{\n int v, nxt;\n long long value;\n} Edge[MAXN];\nstruct node\n{\n long long d;\n int id;\n node(long long _d, int _id):\n d(_d), id(_id) {}\n};\nbool operator < (node a, node b)\n{\n return a.d > b.d;\n}\nvoid init()\n{\n cnt = 0;\n memset(head, -1, sizeof(head));\n memset(vis, false, sizeof(vis));\n memset(d, 0x3f, sizeof(d));\n memset(endpoint, -1, sizeof(endpoint));\n d[0] = 0;\n}\nvoid addedge(int u, int v, long long value)\n{\n Edge[cnt].v = v;\n Edge[cnt].value = value;\n Edge[cnt].nxt = head[u];\n head[u] = cnt;\n cnt++;\n}\npriority_queue que;\nint main(void)\n{\n scanf(\"%d\", &n);\n\n for(int i = 1; i <= n; i++)\n {\n scanf(\"%I64d%I64d\", &P[i].x, &P[i].y);\n number[i] = max(P[i].x, P[i].y);\n }\n\n P[0] = (point){0, 0};\n number[0] = 0;\n\n sort(P, P + n + 1);\n sort(number, number + n + 1);\n int size = unique(number, number + n + 1) - number;\n\n init();\n int pos = 0;\n int tot = 0;\n\n for(int i = 0; i < size; i++)\n {\n tot = 0;\n while(max(P[pos].x, P[pos].y) == number[i])\n {\n if(tot == 0)\n endpoint[i][tot++] = pos;\n else if(max(P[pos + 1].x, P[pos + 1].y) != number[i])\n endpoint[i][tot++] = pos;\n ++pos;\n }\n if(endpoint[i][1] == -1)\n endpoint[i][1] = endpoint[i][0];\n }\n\n for(int i = 0; i < size; i++)\n {\n if(i < size - 1)\n {\n addedge(2 * i, 2 * (i + 1), dist(P[endpoint[i][0]], P[endpoint[i][1]]) + dist(P[endpoint[i][0]], P[endpoint[i + 1][1]]));\n addedge(2 * i + 1, 2 * (i + 1), dist(P[endpoint[i][0]], P[endpoint[i][1]]) + dist(P[endpoint[i][1]], P[endpoint[i + 1][1]]));\n addedge(2 * i, 2 * (i + 1) + 1, dist(P[endpoint[i][0]], P[endpoint[i][1]]) + dist(P[endpoint[i][0]], P[endpoint[i + 1][0]]));\n addedge(2 * i + 1, 2 * (i + 1) + 1, dist(P[endpoint[i][0]], P[endpoint[i][1]]) + dist(P[endpoint[i][1]], P[endpoint[i + 1][0]]));\n }\n else\n {\n addedge(2 * i, 2 * (i + 1), dist(P[endpoint[i][0]], P[endpoint[i][1]]));\n addedge(2 * i + 1, 2 * (i + 1), dist(P[endpoint[i][0]], P[endpoint[i][1]]));\n }\n }\n\n que.push(node(0, 0));\n\n while(!que.empty())\n {\n node current = que.top();\n que.pop();\n if(vis[current.id])\n continue;\n vis[current.id] = true;\n for(int i = head[current.id]; i != -1; i = Edge[i].nxt)\n {\n d[Edge[i].v] = min(d[Edge[i].v], d[current.id] + Edge[i].value);\n que.push(node(d[Edge[i].v], Edge[i].v));\n }\n }\n\n printf(\"%I64d\\n\", d[2 * size]);\n\n return 0;\n}\n", "src_uid": "06646a9bdce2d65e92e525e97b2c975d"} {"source_code": "#include \n#include \nusing namespace std;\n\nint main() {\n int x[3], y[3], m, n;\n bool a, b;\n for (int i = 0; i < 3; i++)\n cin >> x[i] >> y[i];\n m = abs(x[1] - x[0]);\n n = abs(y[1] - y[0]);\n\n if (x[2] != 0) {\n if ((m % x[2]) == 0) {\n a = 1;\n m = m / x[2];\n }\n else if (m == 0) {\n a = 1;\n m = 0;\n }\n else\n a = 0;\n }\n\n if (y[2] != 0) {\n if ((n % y[2]) == 0) {\n b = 1;\n n = n / y[2];\n }\n else if (n == 0) {\n b = 1;\n n = 0;\n }\n else\n b = 0;\n }\n\n if (a && b) {\n if (n % 2 == m % 2 )\n cout << \"YES\";\n else\n cout << \"NO\";\n }\n else\n cout << \"NO\";\n\n return 0;\n}\n", "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"source_code": "#include \nusing namespace std;\nint aa[155];\nint main ()\n{\n //freopen (\"data.in\",\"r\",stdin);\n double x,t=10,b=45;\n int n;\n cin >>n;\n for (int i=0;i>aa[i];\n x+=aa[i];\n }\n sort(aa,aa+n);\n x*=t;\n if (x/n>=b)\n {\n cout <<\"0\"<=b*n)\n {\n cout <\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tint n;\n\tcin>>n;\n\tint a[130];\n\tint i;\n\tfor(i=0;i>a[i];\n\t\tsort(a,a+n);\n\tint x,y;\n\tx=a[n-1];\n\tcout<=0;--i)\n\t\t{\n\t\tif(a[n-1]%a[i]!=0||a[i]==a[i-1]) \n\t\t{\n\t\t\tcout<\n#include \n#include \"numeric\"\n#include \n\nusing namespace std;\n\n//#define f(i,n) for(int i=0; i=0;i--)\n//#define forn(i, j, n) for(int i=j; i mii;\ntypedef pair pii;\ntypedef pair psi;\ntypedef pair pis;\ntypedef vector vi;\ntypedef vector vd;\ntypedef vector vpii;\ntypedef vector vc;\ntypedef vector vvi;\n\ntemplate\nvoid show(const vector &a)\n{\n\tfor (T x : a)\n\t\tcout << x << \" \";\n\tcout << endl;\n}\n\nconst int N = 3e5 + 50, oo = 1e18 + 100, mod = 1e9 + 7;\nconst double eps = 1e-9, PI = 2 * acos(0.0);\nvi vertices[N];\nvi g[N];\nvi visit(N, 0);\nint n, m, k;\nint cnt = 0;\n\nconst int B = 4010;\nint pref[N];\nint col[N];\n\nsigned main()\n{\n\tios::sync_with_stdio(0);\n\tcout.tie(0); cin.tie(0);\n\t/*freopen(\"stars.in\", \"r\", stdin);\n\tfreopen(\"stars.out\", \"w\", stdout);*/\n\n\tint d, k, a, b, t;\n\tcin >> d >> k >> a >> b >> t;\n\n\tint ans = oo;\n\tint time;\n\n\tvi check = { 0, 1, 2, d / k, d / k + 1 };\n\n\tif (d / k - 1 > 0)\n\t\tcheck.pb(d / k - 1);\n\n\tfor (auto x : check)\n\t{\n\t\ttime = 0;\n\n\t\tif (x)\n\t\t\ttime += min(k*x, d)*a + (x - 1)*t;\n\n\t\ttime += max(0ll, d - k*x)*b;\n\n\t\tmini(ans, time);\n\t}\n\n\tcout << ans;\n\treturn 0;\n}", "src_uid": "359ddf1f1aed9b3256836e5856fe3466"} {"source_code": "#include \n\nusing namespace std;\n\nusing ll = long long;\n#define pb push_back\n#define dbg(x) cerr << #x << \" \" << x << \"\\n\"\n\n#define TYPE 0\n\nconst int N = 1e5;\n\nint n;\nvector gr[1 + N];\nint villager[1 + N];\nll ans;\n\nvoid dfsMin (int node, int par) {\n for (int son : gr[node])\n if (son != par)\n dfsMin (son, node);\n if (villager[node] == node) {\n if (par)\n swap (villager[node], villager[par]);\n else\n swap (villager[node], villager[gr[node].back ()]);\n ans += 2;\n }\n}\n\nvoid minimum () {\n for (int i = 1; i <= n; i++)\n villager[i] = i;\n dfsMin (1, 0);\n cout << ans << \"\\n\";\n for (int i = 1; i <= n; i++)\n cout << villager[i] << \" \";\n cout << \"\\n\";\n}\n\nint order[1 + N];\nint nr;\nint sz[1 + N];\nint sol[1 + N];\nvoid dfsOrder (int node, int par) {\n order[++nr] = node;\n for (int son : gr[node])\n if (son != par)\n dfsOrder (son, node);\n}\n\nvoid dfsCalc (int node, int par) {\n sz[node] = 1;\n for (int son : gr[node])\n if (son != par) {\n dfsCalc (son, node);\n ans += 2 * min (sz[son], n - sz[son]);\n sz[node] += sz[son];\n }\n}\n\nvoid maximum () {\n dfsOrder (1, 0);\n for (int i = 1; i <= n; i++) {\n int from = i;\n int to = i + n / 2;\n if (to > n) to -= n;\n sol[order[to]] = order[from];\n }\n dfsCalc (1, 0);\n cout << ans << \"\\n\";\n for (int i = 1; i <= n; i++)\n cout << sol[i] << \" \";\n cout << \"\\n\";\n}\n\nint main() {\n ios::sync_with_stdio (false);\n cin.tie (0); cout.tie (0);\n cin >> n;\n for (int i = 1; i < n; i++) {\n int x, y;\n cin >> x >> y;\n gr[x].pb (y);\n gr[y].pb (x);\n }\n if (TYPE)\n minimum ();\n else\n maximum ();\n return 0;\n}\n", "src_uid": "343dbacbc6bb4981a062dda5a1a13656"} {"source_code": "/**\n * author: lucasfcm9\n * created: 21.07.20 22:57:33\n**/\n#include \n\nusing namespace std;\n\nint a[23456789];\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int n;\n cin >> n;\n for (int i = 0; i < n; i++) {\n cin >> a[i];\n }\n sort(a, a + n);\n for (int i = 0; i < n; i++) {\n cout << a[i] << (i + 1 == n ? '\\n' : ' ');\n }\n\treturn 0;\n}\n\n", "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"source_code": "\n#include\nusing namespace std;\n#pragma comment(linker, \"/STACK:102400000,102400000\")\n#define rep(i,a,b) for (int i=a; i<=b; ++i)\n#define per(i,b,a) for (int i=b; i>=a; --i)\n#define mes(a,b) memset(a,b,sizeof(a))\n#define INF 0x3f3f3f3f\n#define MP make_pair\n#define PB push_back\n#define fi first\n#define se second\ntypedef long long ll;\nconst int N = 200005;\n\nint n, b[N];\npair< int , int > p[N];\nint main()\n{\n scanf(\"%d\", &n);\n rep(i,1,n)\n scanf(\"%d\", &p[i].fi), p[i].se=i;\n sort(p+1, p+1+n);\n b[p[1].se] = p[n].fi;\n rep(i,2,n)\n b[p[i].se] = p[i-1].fi;\n rep(i,1,n)\n printf(\"%d \", b[i]);\n\n\n return 0;\n}\n/*\n4\n1000 10 1 100\n*/\n", "src_uid": "e314642ca1f82be8f223e2eba00b5531"} {"source_code": "#include\nusing namespace std;\nconst long long int mod=1e9+7;\nlong long int magic(long long int r,long long int s)\n{\n if(!s) //if s==0\n return 1;\n long long int t=magic(r,s/2);\n t=t*t%mod;\n if(!(s&1))\n return t;\n return t*r%mod;\n}\nint main()\n{\n long long int a,b,c;\n cin>>a>>b>>c;\n if(c<0&&((a+b)&1))cout<<0;\n else\n cout<= (b); i -= (c))\n#define CICLE(i,a,b,c) for(int i=(a); i<=(b); i += (c))\n#include \n#include \n#include \nint MEMO[450][450], TOT = 0;\nbool InRange(int p) { return p >= 0 && p <= 400; }\ndouble DST(int x, int y, int ax, int ay)\n{\n double tmp = 1.0*((x-ax)*(x-ax) + (y-ay)*(y-ay)); return tmp;\n return sqrt(tmp);\n}\n//bool anton = false, dasha = false;\nint x, y, n, d, ax[21], ay[21];\n\nint Simule(int xx, int yy)\n{\n //if(TOT > 99999) return 0; TOT++;\n //printf(\"Calculando para %d y %d\\n\",xx,yy);\n if(!InRange(xx) || !InRange(yy)) return 0;\n if(MEMO[xx][yy]!=-1) return MEMO[xx][yy];\n if(double(d) < DST(200,200,xx,yy))\n return MEMO[xx][yy] = 0;\n //if(player == 0) printf(\"Simulando DASHA desde %d y %d\\n\",xx,yy);\n //if(player == 1) printf(\"Simulando ANTON desde %d y %d\\n\",xx,yy);\n CICLE(p,1,n,1) if( Simule(xx + ax[p], yy + ay[p]) ) return MEMO[xx][yy] = 0;\n //if(player == 0 && anton == false)\n //{ anton = true; if(Simule((player+1)%2, yy, xx)) { anton = false; return false; } anton = false; }\n //if(player == 1 && dasha == false)\n //{ dasha = true; if(Simule((player+1)%2, yy, xx)) { dasha = false; return false; } dasha = false; }\n return MEMO[xx][yy] = 1;\n}\n\nint main()\n{\n scanf(\"%d%d%d%d\",&x,&y,&n,&d); d *= d;\n CICLE(p,1,n,1) scanf(\"%d%d\",&ax[p],&ay[p]);\n CICLE(p,0,400,1) CICLE(q,0,400,1) MEMO[p][q] = -1;\n if(Simule(x+200,y+200) == 1) printf(\"Dasha\");\n else printf(\"Anton\");\n}", "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f"} {"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\n\nusing namespace std;\n\nstruct orc{\n\tint num;\n\tint x;\n\tint y;\n};\n\nbool myfunction (orc i,orc j) { return (i.x= n) r = mid;\n// else l = mid + 1;\n// }\n\n\n\nint gcd(int a, int b) { return a ? gcd(b%a, a) : b; }\n\n\ndouble q[2001];\n\nint main(){\n\t\n\t\n\t\n\tint t;\n\tcin>>t;\n\twhile(t--){\n\t\tvector k;\n\t\t\n\t\t int iSecret, iGuess;\n\n\t \t/* initialize random seed: */\n\t\t srand (time(NULL));\n\n\t\t\n\t\tfor(int i =0; i<=2000; i++)\n\t\t\tq[i]=0;\n\t\t\n\t\tfor(int i =0; i<250; i++){\n\t\t\tint a;\n\t\t\tcin>>a;\n\t\t\tk.push_back(a);\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i = 0; i<1000; i++){\n\t\t\tiSecret = rand() % 250 ;\n\t\t\tk.push_back(k[iSecret]);\n\t\t}\n\t\t\n\t\tfor(int i=0; ib1) {\n\t\t\tcout<\n#include\n#include\n#include\n#define int64 long long\nusing namespace std;\nconst int bignumlen=2200;\nconst int Blen=8;\nconst int64 base=100000000;\nstruct bignum{\n\tint len;\n\tint64 data[bignumlen];\n\tint64 &operator [](int x){ return(data[x]);}\n\tconst int64 &operator [](int x)const { return(data[x]);}\n\tbignum (){\n\t\tmemset(data,0,sizeof(data));\n\t\tlen=0;\n\t}\n\tvoid clear(){\n\t\tfor(int i=len;i>=1;--i)data[i]=0;\n\t\tlen=0;\n\t}\n\tint check (const bignum &a,const bignum &b){\n\t\tif(a.len>b.len)return(0);\n\t\tif(b.len>a.len)return(1);\n\t\tfor(int i=a.len;i>=1;--i){\n\t\t\tif(a.data[i] (const bignum &b){ return(check(*this,b)==0);}\n\tbool operator <=(const bignum &b){ return(check(*this,b)>=1);}\n\tbool operator >=(const bignum &b){ return(check(*this,b)%2==0);}\n\tbool operator !=(const bignum &b){ return(check(*this,b)!=2);}\n\tbool operator ==(const bignum &b){ return(check(*this,b)==2);}\n\t\n\tbignum operator=(const bignum &x){\n\t\tfor(int i=x.len+1;i<=len;++i)data[i]=0;\n\t\tfor(int i=1;i<=x.len;++i)data[i]=x.data[i];\n\t\tlen=x.len;\n\t\treturn *this;\n\t}\n\tbignum operator=(int64 x){\n\t\tfor(int i=len;i>=0;--i)data[i]=0;\n\t\tlen=0;\n\t\twhile(x){\n\t\t\tdata[++len]=x%base;\n\t\t\tx/=base;\n\t\t}\n\t\treturn *this;\n\t}\n\tbignum(int64 x){\n\t\tmemset(data,0,sizeof(data));\n\t\tlen=0;\n\t\t(*this)=x;\n\t}\n\tbignum operator *(const bignum &b){\n\t\tint i,j;\n\t\tbignum tmp;\n\t\tfor(i=1;i<=len;++i)if(data[i]!=0)\n\t\t\tfor(j=1;j<=b.len;++j)if(b.data[j]!=0){\n\t\t\t\ttmp.data[i+j-1]+=data[i]*b.data[j];\n\t\t\t\ttmp.data[i+j]+=tmp.data[i+j-1]/base;\n\t\t\t\ttmp.data[i+j-1]%=base;\n\t\t\t}\n\t\ttmp.len=len+b.len-1;\n\t\twhile(tmp.data[tmp.len+1])tmp.len++;\n\t\treturn tmp;\n\t}\n\tbignum operator *(int64 x){\n\t\tint i;\n\t\tbignum tmp;\n\t\tfor(i=1;i<=len;++i)tmp[i]=data[i]*x;\n\t\ttmp.len=len;\n\t\tfor(i=1;i<=len;++i){\n\t\t\ttmp[i+1]+=tmp[i]/base,tmp[i]%=base;\n\t\t\tif(tmp[i+1]&&i+1>tmp.len)tmp.len++;\n\t\t}\n\t\treturn tmp;\n\t}\n\tbignum operator /(int64 x){\n\t\tint i;\n\t\tbignum tmp;\n\t\tint64 y=0;\n\t\tfor(i=len;i>=1;--i){\n\t\t\ty=y*base+data[i];\n\t\t\ttmp[i]=y/x;\n\t\t\ty%=x;\n\t\t}\n\t\ttmp.len=len;\n\t\twhile(tmp[tmp.len]==0&&tmp.len>1)tmp.len--;\n\t\treturn tmp;\n\t}\n\tbignum operator /(const bignum &b){\n\t\tif(b.len<=1 && b[1]==0){\n\t\t\tprintf(\"error\");\n\t\t\tfor(;;);\n\t\t}\n\t\tint i,l1=(len-1)*Blen,l2=(b.len-1)*Blen;\n\t\tint64 x=data[len],y=b[b.len];\n\t\twhile(x)x/=10,l1++;\n\t\twhile(y)y/=10,l2++;\n\t\tbignum tmp,chu,B;\n\t\tchu=*this; B=b;\n\t\t\n\t\tfor(i=1;i*Blen<=l1-l2;++i)B*=base;\n\t\tfor(i=1;i<=(l1-l2)%Blen;++i)B*=10;\n\t\tfor(i=l1-l2;i>=0;--i){\n\t\t\tx=0;\n\t\t\twhile(chu>=B)chu-=B,x++;\n\t\t\ttmp[i/Blen+1]=tmp[i/Blen+1]*10+x;\n\t\t\tB/=10;\n\t\t}\n\t\ttmp.len=(l1-l2)/Blen+1;\n\t\twhile(tmp.len>=1 && !tmp[tmp.len])tmp.len--;\n\t\treturn tmp;\n\t}\n\tbignum operator +(const bignum &b){\n\t\tbignum tmp;\n\t\tint i,l=max(len,b.len);\n\t\tfor(i=1;i<=l;++i)tmp[i]=data[i]+b[i];\n\t\tfor(i=1;i<=l;++i)tmp[i+1]+=tmp[i]/base,tmp[i]%=base;\n\t\ttmp.len=l;\n\t\tif(tmp[tmp.len+1])tmp.len++;\n\t\treturn tmp;\n\t}\n\tbignum operator +(int64 x){\n\t\tbignum tmp; tmp=*this;\n\t\ttmp[1]+=x;\n\t\tfor(int i=1;i<=len&&tmp[i]>=base;++i)tmp[i+1]+=tmp[i]/base,tmp[i]%=base;\n\t\twhile(tmp[tmp.len+1])tmp.len++;\n\t\treturn tmp;\n\t}\n\tbignum operator -(const bignum &b){\n\t\tint i;\n\t\tbignum tmp;\n\t\tfor(i=1;i<=len;++i)tmp.data[i]=data[i]-b.data[i];\n\t\tfor(i=1;i<=len;++i){\n\t\t\tif(tmp[i]<0)tmp.data[i]+=base,tmp.data[i+1]--;\n\t\t}\n\t\ttmp.len=len;\n\t\twhile(tmp[tmp.len]==0&&tmp.len>1)tmp.len--;\n\t\treturn tmp;\n\t}\n\tbignum operator -(int64 x){\n\t\tbignum tmp; tmp=*this;\n\t\ttmp[1]-=x;\n\t\tfor(int i=1;i<=len&&tmp[i]<0;++i){\n\t\t\ttmp[i+1]+=(tmp[i]+1)/base-1;\n\t\t\ttmp[i]=(tmp[i]+1)%base+base-1;\n\t\t}\n\t\twhile(!tmp[tmp.len]&&tmp.len>1)tmp.len--;\n\t\treturn tmp;\n\t}\n\tint64 operator %(int64 x){\n\t\tint i;\n\t\tint64 y=0;\n\t\tfor(i=len;i>=1;--i)y=(y*base+data[i])%x;\n\t\treturn y;\n\t}\n\tbignum operator %(const bignum &b){\n\t\tif(b.len<=1 && b[1]==0){\n\t\t\tprintf(\"error\");\n\t\t\tfor(;;);\n\t\t}\n\t\tint i,l1=(len-1)*Blen,l2=(b.len-1)*Blen;\n\t\tint64 x=data[len],y=b[b.len];\n\t\twhile(x)x/=10,l1++;\n\t\twhile(y)y/=10,l2++;\n\t\tbignum chu,B;\n\t\tchu=*this; B=b;\n\t\t\n\t\tfor(i=1;i*Blen<=l1-l2;++i)B*=base;\n\t\tfor(i=1;i<=(l1-l2)%Blen;++i)B*=10;\n\t\tfor(i=l1-l2;i>=0;--i){\n\t\t\twhile(chu>=B)chu-=B;\n\t\t\tB/=10;\n\t\t}\n\t\treturn chu;\n\t}\n\t\n\tbignum operator +=(const bignum &b){return *this=(*this+b);}\n\tbignum operator *=(const bignum &b){return *this=(*this*b);}\n\tbignum operator -=(const bignum &b){return *this=(*this -b);}\n\tbignum operator /=(const bignum &b){return *this=(*this/b);}\n\tbignum operator %=(const bignum &b){return *this=(*this%b);}\n\tbignum operator *=(int64 x) {return( *this=(*this *x));}\n\tbignum operator +=(int64 x) {return( *this=(*this +x));}\n\tbignum operator -=(int64 x) {return( *this=(*this -x));}\n\tbignum operator /=(int64 x) {return( *this=(*this /x));}\n\tvoid read(){\n\t\tchar c[bignumlen*Blen+10];\n\t\tscanf(\"%s\",c+1);\n\t\tint l=strlen(c+1);\n\t\t(*this).clear();\n\t\tint64 x;\n\t\tfor(int i=1;i<=(l-1)/Blen+1;++i){\n\t\t\tx=0;\n\t\t\tfor(int j=l-Blen*i+1;j<=l-Blen*i+Blen;++j)if(j>=1)x=x*10+c[j]-48;\n\t\t\tdata[++len]=x;\n\t\t}\n\t}\n\tvoid write(){\n\t\tprintf(\"%I64d\",data[len]);\n\t\tfor(int i=len-1;i>=1;--i)printf(\"%0*I64d\",Blen,data[i]);\n\t}\n}p,q,pp,qq;\nbignum gcd(const bignum &A,const bignum &B){\n\tbignum a=A,b=B,res=1;\n\twhile(!(a[1]&1) && !(b[1]&1))a/=2,b/=2,res*=2;\n\tfor(;;){\n\t\tif(a.len==1 && a[1]==0)return b*res;\n\t\tif(b.len==1 && b[1]==0)return a*res;\n\t\twhile(!(a[1]&1))a/=2;\n\t\twhile(!(b[1]&1))b/=2;\n\t\tif(a>b)a-=b;\n\t\telse b-=a;\n\t}\n}\nvoid YF(bignum &A,bignum &B){\n\tbignum tmp=gcd(A,B);\n\tA/=tmp; B/=tmp;\n}\nint n,i,x,num;\nint main(){\n\tscanf(\"%d\",&n);\n\twhile(n%2==0){\n\t\tn/=2;\n\t\tnum++;\n\t}\n\tif(n==1){\n\t\tprintf(\"%d/%d\\n\",num,1);\n\t\treturn 0;\n\t}\n\tp=0; q=1;\n\tpp=1; qq=1;\n\tfor(i=n+1;;){\n\t\tif(i>n){\n\t\t\tif(q%(i-n)==0)q/=i-n;\n\t\t\telse p*=i-n;\n\t\t\t\n\t\t\tif(qq%(i-n)==0)qq/=i-n;\n\t\t\telse pp*=i-n;\n\t\t\t\n\t\t\tif(p%i==0)p/=i;\n\t\t\telse q*=i;\n\t\t\t\n\t\t\tif(pp%i==0)pp/=i;\n\t\t\telse qq*=i;\n\t\t\t\n\t\t}else p+=q;\n\t\tif(i==1)break;\n\t\tif(i%2==0)i/=2;\n\t\telse i+=n;\n\t}\n\tYF(p,q);\n\tp=p*qq;\n\tq=q*(qq-pp);\n\t\n\tp+=q*num;\n\tbignum tmp=gcd(p,q);\n\t(p/tmp).write();\n\tprintf(\"/\");\n\t(q/tmp).write();\n}", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e"} {"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 REP(i,n) for(int i=0;i<(n);i++)\n#define fi first\n#define se second\n#define pb push_back\n#define mp make_pair\nusing namespace std;\ntypedef pair pii;\ntypedef vector vi;\ntypedef long long ll;\n\ntemplate inline void read(T &x){\n\tint f=0;x=0;char ch=getchar();\n\tfor(;!isdigit(ch);ch=getchar())f|=(ch=='-');\n\tfor(;isdigit(ch);ch=getchar())x=x*10+ch-'0';\n\tif(f)x=-x;\n}\n\nconst int mod=1e9+7;\nint power(int x,int p){\n\tint res=1;\n\tfor(;p;p>>=1,x=(ll)x*x%mod)\n\t\tif(p&1)res=(ll)res*x%mod;\n\treturn res;\n}\nint n,m,res;\n\nint main(){\n\tread(n),read(m);\n\tres=(ll)power(2,m)*power(n+1,m-1)%mod*(n+1-m)%mod;\n\tcout<\n#define ll long long int\n#define ld long double\n#define pb push_back\n#define mp make_pair\n#define endl cout<<\"\\n\";\n#define test long long int t; cin>>t; while(t-->0)\n#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);\n#define loop(n) for(long long int i=0;i>n;\n int a[n],b[n];\n loop(n)\n cin>>a[i];\n int maxd=0;\n for(int i=0;i\nusing namespace std;\nint main ()\n{\n\tint a,b,d=1;\n\tcin>>a>>b;\n\tif(a\n#include\nint main()\n{\n char a[101];\n char b[101];\n while(~scanf(\"%s%s\",a,b))\n {\n int cnt=0;\n for(int i=strlen(a)-1;i>=0;i--)\n {\n if(i==strlen(a)-1)\n {\n a[i]+='b'-'a';\n int cnt1=(a[i]-'a')/(26);\n a[i]=(a[i]+cnt-'a')%(26)+'a';\n cnt=cnt1;\n\n }\n else\n {\n int cnt1 =(a[i]-'a'+cnt)/(26);\n a[i]=(a[i]+cnt-'a')%(26)+'a';\n cnt=cnt1;\n }\n }\n if(cnt!=0)\n {\n printf(\"No such string\\n\");\n }\n else\n {\n int p=1;\n for(int i=0;ib[i])\n {\n p=0;\n break;\n }\n else if(b[i]>a[i])\n {\n p=2;\n break;\n }\n }\n if(p==2)\n {\n a[strlen(a)]='\\0';\n printf(\"%s\\n\",a);\n }\n else\n {\n printf(\"No such string\\n\");\n }\n }\n }\n}\n", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"} {"source_code": "#include \n#define NN 5000\n#define inf 0x3f3f3f3f\n\nusing namespace std;\n\nint n,a,b,c;\nint dp[NN];\n\nint main () {\n\t\n\tcin>>n>>a>>b>>c;\n\tmemset (dp,-inf, sizeof(dp));\n\tdp[0] = 0;\n\tfor(int i=1; i<=n; i++) {\n\t\tif (i>=a) dp[i] = max(dp[i], dp[i-a]+1);\n\t\tif (i>=b) dp[i] = max(dp[i], dp[i-b] + 1);\n\t\tif (i>=c) dp[i] = max(dp[i], dp[i-c] + 1);\n\t}\t\n\tprintf(\"%d\\n\", dp[n]);\n}\n ", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\nconst int MOD = 1e9+7, N = 4e4+5, K = 40;\nbool draw[N][K], win[N][K], lose[N][K];\nint a,p,x;\nll ipow(ll _a, ll _p){\n if(_p == 0)\n return 1;\n if(_p == 1)\n return _a;\n return min((ll)MOD,ipow(min((ll)MOD,_a*_a),_p/2)*ipow(_a,_p%2));\n}\nbool lost(int _a, int _p){\n return ipow(_a,_p) >= x;\n}\nint main(){\n cin >> a >> p >> x;\n if((x - (N-1))%2 == 0)\n win[N-1][1] = true;\n else\n lose[N-1][1] = true;\n for(int i = N-2; i >= 0; --i){\n for(int j = K-2; j >= 0; --j){\n if(lost(i,j)){\n win[i][j] = true;\n continue;\n }\n if(lose[i+1][j] || lose[i][j+1]){\n win[i][j] = true;\n continue;\n }\n if(win[i+1][j] && win[i][j+1]){\n lose[i][j] = true;\n continue;\n }\n draw[i][j] = true;\n }\n }\n if(win[a][p])\n puts(\"Masha\");\n if(lose[a][p])\n puts(\"Stas\");\n if(draw[a][p])\n puts(\"Missing\");\n}", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b"} {"source_code": "#include \n\n\nusing namespace std;\n\nint main()\n{ int zeros=0,n,tk;\nlong long x =1 ;\nbool flag = false ;\n scanf(\"%d\",&n);\n if(n==1) { scanf(\"%d\",&tk); tk ==0 ? printf(\"%d\",0) : printf(\"%d\",1); }else {\nwhile(n--){\n scanf(\"%d\",&tk);\n tk== 1 ? flag=true:flag;\n flag == true ? (tk == 0 ? ++zeros:(zeros != 0 ? x*= ++zeros,zeros=0:zeros )) : flag ;\n}\nflag==true ? cout<\nusing namespace std;\n\n//#include \n//#include \n//using namespace __gnu_pbds;\n//typedef tree, rb_tree_tag, tree_order_statistics_node_update> index_set;\n//typedef tree, rb_tree_tag, tree_order_statistics_node_update>indexed_multiset; \n\n#define ull unsigned long long\n#define ll long long int\n#define ld long double\n#define MOD 1000000007\n#define pi 3.14159265358979323846\n#define N 100005\n#define sz(x) ((int)(x).size())\n#define test ll t; cin >> t; while(t--)\n#define all(x) (x).begin(), (x).end()\n#define ld long double\n#define bigint int64_t\n#define vll vector\n#define vpll vector>\n#define mp make_pair\n#define pb push_back\n#define pll pair\n#define vvll vector>\n#define fi first\n#define se second\n#define ins insert\n#define endl \"\\n\"\n#define rep(i,a,n) for(ll (i) = a;(i) < (n); (i)++)\n#define repn(i,a,n) for(ll (i) = a;(i) <= (n); (i)++)\n#define repr(i,a,n) for(ll (i) = a;(i) >= (n); (i)--)\n\n//-------------------DEBUGGING-----------------------\n\nvector vec_splitter(string s) {\n s += ',';\n vector res;\n while(!s.empty()) {\n res.push_back(s.substr(0, s.find(',')));\n s = s.substr(s.find(',') + 1);\n }\n return res;\n}\nvoid debug_out(\nvector __attribute__ ((unused)) args,\n__attribute__ ((unused)) int idx, \n__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } \ntemplate \nvoid debug_out(vector args, int idx, int LINE_NUM, Head H, Tail... T) {\n if(idx > 0) cerr << \", \"; else cerr << \"Line(\" << LINE_NUM << \") \";\n stringstream ss; ss << H;\n cerr << args[idx] << \" = \" << ss.str();\n debug_out(args, idx + 1, LINE_NUM, T...);\n}\n#ifdef XOX\n#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)\n#else\n#define debug(...) 42\n#endif\n//-----------------------------------------------------------------------\n\n// doing the brute\nll sumd(ll n){\n\tif(n < 0) return -1;\n\tll sum = 0;\n\twhile(n){\n\t\tsum+=n%10;\n\t\tn/=10;\n\t}\n\treturn sum;\n}\nvoid solve(){\n\tll a, b, c; cin >> a >> b >> c;\n\tvll v;\n\trepn(i,1,81){\n\t\tll eq = (b*pow(i, a)+c);\n\t\tll key = sumd(eq);\n\t\tif( key == i && eq < 1e9){\n\t\t\tv.pb(eq);\n\t\t}\n\t}\n\tcout << sz(v) << endl;\n\tfor(auto it : v) cout << it << ' ';\n\t\n}\n\n\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n \n solve();\n return 0;\n }\n// Problem : B. Little Dima and Equation\n// Contest : Codeforces - Codeforces Round #262 (Div. 2)\n// URL : https://codeforces.com/problemset/problem/460/B\n// Memory Limit : 256 MB\n// Time Limit : 1000 ms\n// Powered by CP Editor (https://github.com/cpeditor/cpeditor)\n\n", "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"source_code": "/*************************************************************************\n\t> File Name: 2019_10_13_3.cpp\n\t> Author: z472421519\n\t> Mail: \n\t> Created Time: 2019年10月13日 星期日 17时46分57秒\n ************************************************************************/\n\n#include \n#include \n#include \n#define ll long long \nusing namespace std;\nvoid ex_gcd(ll a,ll b,ll &x,ll &y)\n{\n if(b == 1)\n {\n x = 1;\n y = 1 - a;\n }\n else\n {\n ll x1,y1;\n ex_gcd(b,a % b,x1,y1);\n x = y1;\n y = x1 - x * (a / b);\n }\n}\n/*\nll inv(ll t, ll p){//如果不存在,返回-1\n ll d, x, y;\n ex_gcd(t, p, x, y, d);\n return d == 1 ? (x % p + p) % p : -1;\n}*/\nint main()\n{\n ll n,w,d,p;\n cin >> n >> p >> d >> w;\n ll gcd = __gcd(d,w);\n ll x,y;\n d /= gcd;\n w /= gcd;\n if(p == 0)\n {\n printf(\"0 0 \");\n cout << n << endl;\n return 0;\n }\n if(p % gcd != 0)\n {\n printf(\"-1\\n\");\n return 0;\n }\n ex_gcd(d,w,x,y);\n ll vx;\n ll vy;\n bool flag = false,flag1 = false;\n \n //if(x / gcd <= n / p)\n {\n vx = (((p / gcd % w) * (x % w)) % w + w) % w;\n vy = (p / gcd - vx * d) / w;\n if(vy < 0)\n vy = -vy;\n //flag = true;\n }\n //if(y / gcd <= n / p)\n {\n //y /= gcd;\n y = (((p / gcd % d) * (y % d)) % d + d) % d;\n x = (p / gcd - w * y) / d;\n if(x < 0)\n x = -x;\n //flag1 = true;\n }\n //printf(\"%lld %lld %lld %lld\\n\",vx,vy,x,y);\n if(x + y > vx + vy)\n {\n x = vx;\n y = vy;\n }\n /*\n else if(flag1)\n {\n x = vx;\n y = vy;\n }*/\n if(x + y > n || x * d + w * y != p / gcd)\n printf(\"-1\\n\");\n else\n cout << x << \" \" << y << \" \" << n - x - y << endl;\n}\n", "src_uid": "503116e144d19eb953954d99c5526a7d"} {"source_code": "#include \n\nusing namespace std;\n\nint n,b;\nint v[110];\nint x[110];\nint y[110];\nint dp[110][110];\n\nint f(int pos, int w) {\n if(pos == n) return 0;\n if(dp[pos][w] != -1) return dp[pos][w];\n int ans = -1e9;\n for (int i = pos; i < n; ++i) {\n int cost = abs(v[i] - v[i + 1]);\n int even = x[i];\n int odd = y[i];\n if(pos) {\n even -= x[pos - 1];\n odd -= y[pos - 1];\n }\n if(even == odd) {\n if(i < n - 1 and w >= cost) ans = max(ans,f(i + 1, w - cost) + 1);\n else ans = max(ans,f(i + 1, w));\n }\n }\n return dp[pos][w] = ans;\n}\n\nint main(){\n memset(dp, -1,sizeof dp);\n\n cin >> n >> b;\n\n for (int i = 0; i < n; ++i) {\n cin >> v[i];\n if(v[i] & 1) y[i] = 1;\n else x[i] = 1;\n }\n\n for (int i = 1; i < n; ++i) {\n x[i] += x[i - 1];\n y[i] += y[i - 1];\n }\n \n cout << f(0,b) << \"\\n\";\n return 0;\n}", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"} {"source_code": "#include \nusing namespace std;\n\n\ntemplate\nclass Modular {\n \n private:\n\n using Type = typename decay::type;\n Type value;\n\n public:\n\n Modular() { value = 0; }\n\n template \n Modular(const U& x) { value = normalize(x); }\n\n template\n Type normalize(const U& x) {\n Type res;\n if (-mod() <= x && x < mod()) {\n res = static_cast(x);\n } else {\n res = static_cast(x % mod());\n }\n if (res < 0) {\n res += mod();\n }\n return res;\n }\n\n explicit operator Type() const { return value; }\n template explicit operator U() const { return static_cast(value); }\n constexpr static Type mod() { return T::value; }\n\n Modular power(Modular n, Type x) {\n assert(x >= 0);\n Modular res = 1;\n for (; x; x /= 2, n *= n) if (x & 1) res *= n;\n return res;\n }\n\n Type inverse(Type a, Type m) {\n Type x = 0, y = 1;\n while (a != 0) {\n Type q = m / a;\n m -= q * a; swap(a, m);\n x -= q * y; swap(x, y);\n }\n assert(m == 1);\n return x;\n }\n\n Modular& operator+=(const Modular& o) { if ((value += o.value) >= mod()) value -= mod(); return *this; }\n template Modular& operator+=(const U& o) { return *this += Modular(o); }\n\n Modular& operator-=(const Modular& o) { if ((value -= o.value) < 0) value += mod(); return *this; }\n template Modular& operator-=(const U& o) { return *this -= Modular(o); }\n\n Modular& operator*=(const Modular& o) { value = normalize(1ll * value * o.value); return *this; }\n template Modular& operator*=(const U& o) { return *this *= Modular(o); }\n\n Modular& operator/=(const Modular &o) { return *this *= Modular(inverse(o.value, mod())); }\n template Modular& operator/=(const U& o) { return *this /= Modular(o); }\n \n Modular operator+() { return Modular(+value); }\n Modular operator-() { return Modular(-value); }\n\n Modular& operator++() { return *this += 1; }\n Modular& operator--() { return *this -= 1; }\n\n friend ostream& operator<<(ostream &os, const Modular &x) { os << x.value; return os; }\n friend istream& operator>>(istream &is, Modular &x) { \n typename common_type::type in;\n is >> in; \n x.value = x.normalize(in);\n return is; \n }\n\n friend bool operator==(const Modular& a, const Modular& b) { return a.value == b.value; }\n template friend bool operator==(const Modular &a, U b) { return a == Modular(b); }\n template friend bool operator==(U a, const Modular &b) { return Modular(a) == b; }\n\n friend bool operator!=(const Modular& a, const Modular& b) { return a.value != b.value; }\n template friend bool operator!=(const Modular &a, U b) { return a != Modular(b); }\n template friend bool operator!=(U a, const Modular &b) { return Modular(a) != b; }\n \n friend bool operator>(const Modular& a, const Modular& b) { return a.value > b.value; }\n template friend bool operator>(const Modular &a, U b) { return a > Modular(b); }\n template friend bool operator>(U a, const Modular &b) { return Modular(a) > b; }\n\n friend bool operator<(const Modular& a, const Modular& b) { return a.value < b.value; }\n template friend bool operator<(const Modular &a, U b) { return a < Modular(b); }\n template friend bool operator<(U a, const Modular &b) { return Modular(a) < b; }\n\n friend bool operator>=(const Modular& a, const Modular& b) { return a.value >= b.value; }\n template friend bool operator>=(const Modular &a, U b) { return a >= Modular(b); }\n template friend bool operator>=(U a, const Modular &b) { return Modular(a) <= b; }\n\n friend bool operator<=(const Modular& a, const Modular& b) { return a.value <= b.value; }\n template friend bool operator<=(const Modular &a, U b) { return a <= Modular(b); }\n template friend bool operator<=(U a, const Modular &b) { return Modular(a) <= b; }\n \n friend Modular operator+(const Modular &a, const Modular& b) { return Modular(a) += b; }\n template friend Modular operator+(const Modular &a, const U& b) { return Modular(a) += Modular(b); }\n template friend Modular operator+(const U& a, const Modular &b) { return Modular(a) += b; }\n\n friend Modular operator-(const Modular &a, const Modular& b) { return Modular(a) -= b; }\n template friend Modular operator-(const Modular &a, const U& b) { return Modular(a) -= Modular(b); }\n template friend Modular operator-(const U& a, const Modular &b) { return Modular(a) -= b; }\n \n friend Modular operator*(const Modular &a, const Modular& b) { return Modular(a) *= b; }\n template friend Modular operator*(const Modular &a, const U& b) { return Modular(a) *= Modular(b); }\n template friend Modular operator*(const U& a, const Modular &b) { return Modular(a) *= b; }\n \n friend Modular operator/(const Modular &a, const Modular& b) { return Modular(a) /= b; }\n template friend Modular operator/(const Modular &a, const U& b) { return Modular(a) /= Modular(b); }\n template friend Modular operator/(const U& a, const Modular &b) { return Modular(a) /= b; }\n \n};\n\nconstexpr int MOD = 1e9 + 7;\nusing Mint = Modular::type, MOD>>;\n\ntemplate\nclass Matrix {\n\n private:\n\n vector> M;\n\n public:\n\n Matrix() {}\n\n Matrix(int n, int m) {\n M.assign(n, vector(m, 0));\n }\n\n size_t size() {\n return M.size();\n }\n\n vector& operator[](int i) { return M[i]; }\n const vector& operator[](int i) const { return M[i]; }\n\n friend Matrix operator*(Matrix a, Matrix b) {\n assert(a[0].size() == b.size());\n Matrix res(a.size(), b[0].size());\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 res[i][j] += a[i][k] * b[k][j];\n }\n }\n }\n return res;\n }\n\n};\n\nMint DP(int N, int K, int M) {\n vector>> DP(N + 2, vector>(K + 2, vector(1 << M, 0)));\n DP[0][0][0] = 1;\n \n for (int n = 0; n < N; n++) { // first n planets\n for (int k = 0; k <= K; k++) { // visited k planets\n for (int mask = 0; mask < (1 << M); mask++) { // last mask planets\n int next_mask = (mask << 1) % (1 << M);\n\n /* Do not visit n-th planet */\n DP[n + 1][k][next_mask] += DP[n][k][mask];\n\n /* Visit n-th planet, use combinatorics to count variations regarding mask */\n DP[n + 1][k + 1][next_mask ^ 1] += DP[n][k][mask] * (1 + __builtin_popcount(mask));\n\n }\n }\n } \n\n Mint ans = 0;\n for (int mask = 0; mask < (1 << M); mask++) {\n ans += DP[N][K][mask];\n }\n return ans;\n}\n\n\ntemplate\nT power(T n, long long x) {\n if (x == 1) {\n return n;\n }\n if (x & 1) {\n return n * power(n, x - 1);\n }\n T res = power(n, x / 2);\n return res * res;\n}\n\n\nMint MatrixExponentiation(int N, int K, int M) {\n vector> name(K + 1, vector(1 << M, -1));\n int cnt = 0;\n for (int k = 0; k <= K; k++) {\n for (int mask = 0; mask < (1 << M); mask++) {\n name[k][mask] = cnt++; \n }\n }\n\n Matrix Transition(cnt, cnt);\n Matrix Base(cnt, 1);\n\n for (int k = 0; k <= K; k++) {\n for (int mask = 0; mask < (1 << M); mask++) {\n int next_mask = (mask << 1) % (1 << M);\n Transition[name[k][next_mask]][name[k][mask]] = 1;\n if (k < K) {\n Transition[name[k + 1][next_mask ^ 1]][name[k][mask]] = 1 + __builtin_popcount(mask);\n }\n }\n }\n\n Base[name[0][0]][0] = 1;\n\n Matrix ans = power(Transition, N) * Base;\n Mint res = 0;\n\n for (int mask = 0; mask < (1 << M); mask++) {\n res += ans[name[K][mask]][0];\n }\n\n return res;\n}\n\nint main() {\n int N, K, M;\n cin >> N >> K >> M;\n\n cout << MatrixExponentiation(N, K, M) << \"\\n\";\n return 0;\n}\n", "src_uid": "87931a8ae9a76d85bd2a2b4bba93303d"} {"source_code": "#include \nusing namespace std;\nconst int maxn = 1500, maxm = 1e5, mod = 1e9 + 7;\nint n, m, val[maxn + 10], p, tmp, k;\nint f[maxn + 10][maxn + 10], sf[maxn + 10][maxn + 10];\nint inv[maxm + 10], fac[maxm + 10], ifac[maxm + 10];\nint sv[maxn + 10], ssf[maxn + 10][maxn + 10];\nint pn[maxm + 10], pm[maxm + 10];\n\nvoid init() {\n\tfac[0] = ifac[0] = pn[0] = pm[0] = 1;\n\tfor (int i = 1; i <= maxm; ++i) {\n\t\tfac[i] = 1ll * fac[i - 1] * i % mod;\n\t\tinv[i] = i == 1 ? 1 : mod - 1ll * (mod / i) * inv[mod % i] % mod;\n\t\tifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;\n\t\tpn[i] = 1ll * pn[i - 1] * p % mod;\n\t\tpm[i] = 1ll * pm[i - 1] * (mod + 1 - p) % mod;\n\t}\n}\n\nint fpow(int x, int y) {\n\tint ans = 1;\n\twhile (y) {\n\t\tif (y & 1) ans = 1ll * ans * x % mod;\n\t\ty >>= 1; x = 1ll * x * x % mod;\n\t}\n\treturn ans;\n}\n\ninline int comb(int x, int y) {\n\treturn 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;\n}\n\nint main() {\n\tscanf(\"%d%d%d%d%d\", &n, &m, &p, &tmp, &k);\n\tp = 1ll * p * fpow(tmp, mod - 2) % mod;\n\tinit();\n\tfor (int i = 0; i <= m && i <= k; ++i)\n\t\tval[i] = 1ll * comb(k, i) * pn[i] % mod * pm[k - i] % mod;\n\tfor (int i = 0; i <= m; ++i)\n\t\tsv[i] = ((i ? sv[i - 1] : 0) + val[i]) % mod;\n\tfor (int i = 1; i <= m; ++i)\n\t\tfor (int j = 1; j <= i; ++j)\n\t\t\t(f[1][i] += 1ll * val[j - 1] * val[m - i] % mod) %= mod;\n\tfor (int i = 2; i <= n + 1; ++i) {\n\t\tfor (int j = 1; j <= m; ++j) {\n\t\t\tsf[i - 1][j] = (sf[i - 1][j - 1] + f[i - 1][j]) % mod;\n\t\t\tssf[i - 1][j] = (ssf[i - 1][j - 1] + 1ll * sf[i - 1][j] * val[j]) % mod;\n\t\t}\n\t\tfor (int j = 1; j <= m; ++j) {\n\t\t\tint w = sf[i - 1][m] - sf[i - 1][m - j];\n\t\t\tif (w < 0) w += mod;\n\t\t\tw = 1ll * w * sv[j - 1] % mod;\n\t\t\tw -= ssf[i - 1][j - 1];\n\t\t\tw = (w % mod + mod) % mod;\n\t\t\tf[i][j] = 1ll * w * val[m - j] % mod;\n\t\t}\n\t}\n\tprintf(\"%d\", sf[n][m]);\n}\n", "src_uid": "33b6b0d3a6af273f22b703491bd17289"} {"source_code": "#include\n\nusing namespace std;\n\ntypedef long long int ll;\n#define pb push_back\n#define fst first\n#define snd second\n\nint main()\n{\n\tint n;\n\tcin >> n;\n\tstring s;\n\tcin >> s;\n\tint o = 0, z = 0;\n\tfor(int i = 0; i < n; i++)\n\t{\n\t\tif(s[i] == '1') o++;\n\t\telse z++;\n\t} \n\tif(o == 0)\n\t{\n\t\tcout << 0;\n\t\treturn 0;\n\t}\n\tcout<< 1;\n\tfor(int i = 0; i < z; i++) cout << 0;\n}\n", "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"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\nint n,m,x1,Y1,x2,Y2;\nstring a=\"First\",b=\"Second\";\n\nint main(){\n\tcin>>n>>m>>x1>>Y1>>x2>>Y2;\n\tif(abs(x1-x2)>=4&&abs(Y1-Y2)>=4) cout<4||abs(Y1-Y2)>4) cout<\n#include\n#include\n#include\nusing namespace std;\nint gcd(int a,int b) {\n return b==0?a:gcd(b,a%b);\n}\nint main() {\n int a,b,x,y;\n while(scanf(\"%d%d%d%d\",&a,&b,&x,&y)!=EOF) {\n int g=gcd(x,y);\n x=x/g;\n y=y/g;\n int mul=min(a/x,b/y);\n printf(\"%d %d\\n\",mul*x,mul*y);\n }\n return 0;\n}\n\t\t\t \t \t\t\t\t \t \t \t\t \t\t \t", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"source_code": "#include \n#include \n\nusing namespace std ; \n\n\nint main ()\n{\n\tint da(0),db(0),a(0),b(0);\n\tcin>>da>>db ; \n\t\n\tif (db-da==0)\n\t{\n\t\ta=da*10 ;\n\t\tb=db*10+1;\n\t}\n\telse if (db-da==1)\n\t{\n\t\ta=da*10+9;\n\t\tb=db*10;\n\t}\n\telse if ((da==9)&&(db==1))\n\t{\n\t\ta=da;\n\t\tb=10;\n\t}\n\telse \n\t{\n\t\ta=-1;\n\t}\n\tif (a>0)\n\t{\n\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 \nusing namespace std;\n#define pb push_back\n#define mp make_pair\ntypedef pair pii;\ntypedef long long ll;\ntypedef double ld;\ntypedef vector vi;\n#define fi first\n#define se second\n#define fe first\n#define FO(x) {freopen(#x\".in\",\"r\",stdin);freopen(#x\".out\",\"w\",stdout);}\n#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}\n#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}\n#define es(x,e) (int e=fst[x];e;e=nxt[e])\n#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])\n#define SZ 666666\nint n,t,k;\nll a[SZ],b[SZ],c[SZ],sa[SZ],sb[SZ],sc[SZ];\nll d[235][235][235],g[235][235][235];\ninline void cmin(ll&a,ll b)\n{if(a>b) a=b;}\nint main()\n{\n\tcin>>n>>t>>k; ++n;\n\tconst ll inf=1e18;\n\tfor(int i=1;i<=n;++i)\n\t{\n\t\tif(i==n) a[i]=c[i]=inf;\n\t\telse cin>>a[i]>>b[i]>>c[i];\n\t\tsa[i]=sa[i-1]+a[i];\n\t\tsb[i]=sb[i-1]+b[i];\n\t\tsc[i]=sc[i-1]+c[i];\n\t}\n\tfor(int p=1;p<=n;++p)\n\t\tfor(int s=0;s<=t;++s)\n\t\t\tfor(int z=0;z<2;++z)\n\t\t\t{\n\t\t\t\td[p][s][z]=g[p][s][z]=inf;\n\t\t\t\tif(s*b[p]+z*a[p]<=c[p]\n\t\t\t\t&&d[p-1][s][z]\nusing namespace std;\nconst int N=1e2+7;\nint n,m;\nint arr[N] , mx , ans2;\n\nbool can(int mid){\n int ret=0;\n for(int i =0 ; i < n ; ++i){\n ret+=(mid-arr[i]);\n }\n return ret>=m;\n}\n\nint main(){\n scanf(\"%d %d\",&n,&m);\n for(int i=0 ; i < n ; ++i){\n scanf(\"%d\",arr+i);\n mx=max(mx,arr[i]);\n }\n ans2=mx+m;\n int l=mx , h=ans2+7;\n while(l>1;\n if(can(mid))\n h=mid;\n else\n l=mid+1;\n }\n printf(\"%d %d\",h , ans2);\n}\n", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"source_code": "#include\n#define cs const\nusing namespace std;\ntypedef long long ll;\ncs int N = 205;\ncs ll lim = 1e18 + 1;\nint n, m; ll k;\nstring ans = \"\", f[15];\nbool pre(int pos, cs string &s, int st, int len){\n\tint id = pos <= 14 ? pos : 14 - (pos&1);\n\tif(f[id].length() < len) return false;\n\tfor(int i = 0; i < len; i++) if(f[id][i] != s[st + i]) return false;\n\treturn true;\n}\nbool suf(int pos, cs string &s, int st, int len){\n\tint id = min(pos, 14);\n\tif(f[id].length() < len) return false;\n\tint l = f[id].length();\n\tfor(int i = l - len; i < l; i++) if(f[id][i] != s[st + i - (l - len)]) return false;\n\treturn true;\n}\nll calc(int n, cs string &s){\n\tstatic ll g[N];\n\tfor(int i = 0; i <= n; i++){\n\t\tif(i < 2){ g[i] = f[i] == s; continue; }\n\t\tg[i] = g[i - 1] + g[i - 2];\n\t\tfor(int j = 1, up = s.length(); j < up; j++) if(suf(i - 2, s, 0, j) && pre(i - 1, s, j, up - j)) ++g[i];\n\t\tg[i] = min(g[i], lim);\n\t} return g[n];\n}\nint main(){\n//\tfreopen(\"1.in\",\"r\",stdin);\n\tscanf(\"%d%lld%d\", &n, &k, &m);\n\tf[0] = \"0\"; f[1] = \"1\";\n\tfor(int i = 2; i <= 14; i++) f[i] = f[i-2] + f[i-1];\n\tfor(int i = 1; i <= m; i++){\n\t\tll cnt = calc(n, ans + \"0\");\n\t\tll exi = ans != \"\" && suf(n, ans, 0, ans.length());\n\t\tif(k <= exi) break;\n\t\tif(k <= exi + cnt) k -= exi, ans += \"0\";\n\t\telse k -= exi + cnt, ans += \"1\";\n\t} cout << ans; return 0;\n}", "src_uid": "7b4a057efee5264bfaaf60d50fccb92b"} {"source_code": "#include\n\n#define bit(x, y) (((x)>>(y))&1)\n#define bpt(x) (__builtin_popcount(x))\n\nusing namespace std;\n\ntypedef long long INT;\ntypedef vector VI;\n#define pb push_back\n\ntemplate inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}\ntemplate inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}\n\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}\n#define NN 300100\n\nint st[NN];\nVI adj[NN], res[NN], A[NN];\nint lena, lenb;\nVI Ax, Bx;\nint n, m;\nint deg[NN];\n\nint get_id() {\n\tmemset(deg, 0, sizeof deg);\n\tfor(int i=1; i<=n; i++) {\n\t\tfor(auto u : res[i]) {\n\t\t\tdeg[u]++;\n\t\t}\n\t}\n\tint nn = 0;\n\tAx.clear();\n\tfor(int i=1; i<=n; i++) if(!deg[i]) Ax.pb(i);\n\twhile(Ax.size()) {\n\t\tBx.clear();\n\t\tA[nn].clear();\n\t\tfor(auto u : Ax) {\n\t\t\tA[nn].pb(u);\n\t\t\tfor(auto v : res[u]) {\n\t\t\t\tdeg[v]--;\n\t\t\t\tif(!deg[v]) Bx.pb(v);\n\t\t\t}\n\t\t}\n\t\tnn++;\n\t\tAx.clear();\n\t\tfor(auto u : Bx) Ax.pb(u);\n\t}\n\treturn nn;\n}\n\nint flag[NN];\nVI ok[NN];\nint cnt[NN];\nint vst[NN];\n\nint update(int u) {\n\tfor(auto v : A[u+1]) cnt[v] = 0;\n\tfor(auto v : A[u]) {\n\t\tfor(auto x : res[v]) {\n\t\t\tcnt[x]++;\n\t\t}\n\t}\n\tfor(auto v : A[u]) {\n\t\tvst[v] = 0;\n\t\tfor(auto x : res[v]) if(cnt[x] == 1) {\n\t\t\tvst[v] = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nint solve() {\n\tmemset(vst, 0, sizeof vst);\n\tint nn = get_id();\n\tfor(int i=0; i=0; i--) {\n\t\tfor(auto u : A[i]) {\n\t\t\tif(st[u] == -1) continue;\n\t\t\tif(A[i].size() > 2) {\n\t\t\t\tst[u] = -1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor(auto v : A[i]) if(v != u) ok[u].pb(v);\n\t\t\tif(i == nn-1) continue;\n\t\t\tint s = 0;\n\t\t\tfor(auto v : A[i+1]) flag[v] = 0;\n\t\t\tfor(auto v : res[u]) {\n\t\t\t\tflag[v] = 1;\n\t\t\t}\n\t\t\tfor(auto v : A[i+1]) if(!flag[v]) s++;\n\t\t\tif(s >= 2) st[u] = -1;\n\t\t\telse if(s == 1) {\n\t\t\t\tfor(auto v : A[i+1]) if(!flag[v]){\n\t\t\t\t\tif(vst[v]) st[u] = -1;\n\t\t\t\t\telse ok[u].pb(v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn nn;\n}\nVI IDA;\nVI IDB;\nint id[NN];\nVI b[NN];\n\nint calc_lt(int u) {\n\tint x = -1;\n\tfor(; u; u-=u&-u) if(b[u].size()){\n\t\tif(b[u].size() > 1) return 0;\n\t\tif(x > 0) return 0;\n\t\tx = b[u][0];\n\t}\n\treturn x;\n}\n\nint calc_rt(int u) {\n\tint x = -1;\n\tfor(; u 1) return 0;\n\t\tif(x > 0) return 0;\n\t\tx = b[u][0];\n\t}\n\treturn x;\n}\n\nint update_lt(int u, int val) {\n\tfor(; u; u-=u&-u) {\n\t\tif(b[u].size() > 1) continue;\n\t\tb[u].pb(val);\n\t}\n}\n\nint update_rt(int u, int val) {\n\tfor(; u 1) continue;\n\t\tb[u].pb(val);\n\t}\n}\n\nint check_final() {\n\tfor(int i=0; i 0) ok[v].pb(x);\n\t\tupdate_lt(id[v], v);\n\t}\n\tfor(int i=0; i=0; i--) {\n\t\tint v = IDA[i];\n\t\tint x = calc_lt(id[v]);\n\t\tif(x == 0) st[v] = -1;\n\t\tif(x > 0) ok[v].pb(x);\n\t\tupdate_rt(id[v], v);\n\t}\n\tfor(int i=1; i<=n; i++) {\n\t\tsort(ok[i].begin(), ok[i].end());\n\t\tok[i].resize(unique(ok[i].begin(), ok[i].end())-ok[i].begin());\n\t\tif(ok[i].size() > 1) st[i] = -1;\n\t}\n}\n\nint main(){\n#ifndef ONLINE_JUDGE\n\tfreopen(\"in.in\", \"r\", stdin);\n\tfreopen(\"out.out\", \"w\", stdout);\n#endif\n\tgn(n, m);\n\tfor(int i=1; i<=n; i++) st[i] = 1;\n\tfor(int i=1; i<=m; i++) {\n\t\tint u, v;\n\t\tgn(u, v);\n\t\tadj[u].pb(v);\n\t}\n\tfor(int i=1; i<=n; i++) res[i] = adj[i];\n\tint nn = solve();\n\tfor(int i=0; i=0; i--) {\n\t\tfor(auto u : A[i]) {\n\t\t\tIDB.pb(u);\n\t\t}\n\t}\n\tcheck_final();\n\tint ans = 0;\n\tfor(int i=1; i<=n; i++) if(st[i] == 1) ans++;\n\tprintf(\"%d\\n\", ans);\n}\n\n ", "src_uid": "be26e93ca7aef1235e96e10467a6417e"} {"source_code": "#include\nusing namespace std;\n\n#define int long long\n#define fi first\n#define se second\n#define pb push_back\n\ntypedef pair ii;\ntypedef pair iii;\ntypedef pair iiii;\n\nconst int N = 1e6 + 3;\n\nint a, b, p, x, sum;\nvector ck[N];\n\nint binpw(int base, int pw, int mod){\n\tint ans = 1;\n\twhile(pw){\n\t\tif(pw & 1) ans = (ans * base) % mod;\n\t\tbase = (base * base) % mod;\n\t\tpw >>= 1;\n\t}\n\treturn ans;\n}\n\nint find(int a, int b){// % p = a, % (p - 1) = b\n\tif(a < b) return (b - a) * (p - 1) + b;\n\telse if(a == b) return a;\n\telse return (p * (p - 1)) - find(p - a, p - 1 - b);\n}\n\nsigned main(){\n\tios_base::sync_with_stdio(0);\n\tcin >> a >> b >> p >> x;\n\tfor(int i = 0; i < p - 1; i++) ck[binpw(a, i, p)].pb(i);\n\tfor(int i = 0; i < p; i++){\n\t\tif(b && !i) continue;\n\t\tint temp = b * binpw(i, p - 2, p) % p;\n\t\t//cout << i << \" \" << temp << \"\\n\";\n\t\tif(!ck[temp].size()) continue;\n\t\tfor(int j = 0; j < ck[temp].size(); j++){\n\t\t\t//cout << ck[temp][j] << \" \" << i << \" \";\n\t\t\tint temp2 = find(i, ck[temp][j]);\n\t\t\t//cout << temp2 << \"\\n\";\n\t\t\tif(!temp2) temp2 += p * (p - 1);\n\t\t\tsum += x / (p * (p - 1));\n\t\t\tint temp3 = x % (p * (p - 1));\n\t\t\tsum += (temp3 >= temp2);\n\t\t}\n\t}\n\tcout << sum;\n}\n", "src_uid": "4b9f470e5889da29affae6376f6c9f6a"} {"source_code": "#include\nusing namespace std;\nint main(){\nint n;cin>>n;\ncout<<((n%2)?\"black\":\"white\\n\");\nif(n%2==0)\n cout<<\"1 \"<<2<\n#define ll long long\n#define sf scanf\n#define pf printf\n#define end return 0\n#define d double\n#define f float\n#define b break\n#define c continue\nusing namespace std;\nint main()\n{\n ll n,x=1234567,y=123456,z=1234,i,j,a;\n cin>>n;\n for(i=0; ; i++)\n {\n for(j=0; ; j++)\n {\n a=n-((i*x)+(j*y));\n if(a<0)\n b;\n if(!(a%z))\n {\n cout<<\"YES\"<n)\n b;\n }\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#define SZ(X) ((int)(X).size())\n#define ALL(X) (X).begin(), (X).end()\n#define REP(I, N) for (int I = 0; I < (N); ++I)\n#define REPP(I, A, B) for (int I = (A); I < (B); ++I)\n#define REPC(I, C) for (int I = 0; !(C); ++I)\n#define RI(X) scanf(\"%d\", &(X))\n#define RII(X, Y) scanf(\"%d%d\", &(X), &(Y))\n#define RIII(X, Y, Z) scanf(\"%d%d%d\", &(X), &(Y), &(Z))\n#define DRI(X) int (X); scanf(\"%d\", &X)\n#define DRII(X, Y) int X, Y; scanf(\"%d%d\", &X, &Y)\n#define DRIII(X, Y, Z) int X, Y, Z; scanf(\"%d%d%d\", &X, &Y, &Z)\n#define RS(X) scanf(\"%s\", (X))\n#define CASET int ___T, case_n = 1; scanf(\"%d \", &___T); while (___T-- > 0)\n#define MP make_pair\n#define PB push_back\n#define MS0(X) memset((X), 0, sizeof((X)))\n#define MS1(X) memset((X), -1, sizeof((X)))\n#define LEN(X) strlen(X)\n#define F first\n#define S second\nusing namespace std;\nstruct data{\n int p,e;\n bool operator<(const data& b)const{\n return eb.p);\n }\n}a[200010];\nint yo[200010],yon;\nvoid fresh(long long& x,long long v){\n if(x==-1||x>v)x=v;\n}\nint err[2][200010];\nint main(){\n DRII(n,k);\n int win=n+1-k;\n REP(i,n){\n scanf(\"%d%d\",&a[i].p,&a[i].e);\n yo[yon++]=a[i].p;\n }\n if(win==0){\n puts(\"0\");\n return 0;\n }\n sort(yo,yo+yon);\n sort(a,a+n);\n long long an=-1;\n int low=0,st=200004;\n REPP(i,1,200001){\n while(low=win){\n st=i;\n break;\n }\n }\n for(int i=0;i<20;i++,st++){\n if(st<1)continue;\n if(st>n)break;\n long long v=0;\n int ha=0;\n int en1=0,en2=0;\n REP(j,st){\n v+=a[j].e;\n if(a[j].p<=st)ha++;\n if(a[j].p<=st-2||a[j].p>st)err[0][en1++]=a[j].e;\n }\n REPP(j,st,n){\n if(a[j].p<=st-2)ha++;\n else if(a[j].p<=st){\n err[1][en2++]=a[j].e;\n }\n }\n if(ha+min(en1,en2)\r\nusing namespace std;\r\n#define AC return\r\n#define Please 0\r\n#define itn int\r\n#define enld '\\n' //IO?\r\n#define endl '\\n' //IO?\r\n#define Endl '\\n' //IO?\r\n#define esle else\r\n#define ciN cin\r\n#define YES \"YES\"\r\n#define NO \"NO\"\r\n#define eb emplace_back\r\n#define wide(x,ch) setw(x)< \"<<\r\nclass MyCpiise{public:bool operator()(pair a,pair b){return a.second \";err(x);}while (0)\r\nvoid err(){cout<<'\\n';}\r\ntemplate\r\nvoid err(T arg, Ts... args) {\r\n cout<\r\nT read(T judge){\r\n T x=0,f=1;\r\n char c=getchar();\r\n while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}\r\n while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=getchar();\r\n return f*x;\r\n}\r\ninline void reads(){return;}\r\ntemplate\r\ninline void reads(T &x,Ts&... xs) {\r\n x=0;\r\n char c=getchar();\r\n while('0'<=c&&c<='9') {\r\n x=(x<<3)+(x<<1)+(c^48);\r\n c=getchar();\r\n }\r\n reads(xs...);\r\n}\r\ntemplate\r\nvoid print(T x){\r\n if (x<0) putchar('-'),x=-x;\r\n if (x/10) print(x/10);\r\n putchar(x%10+'0');\r\n}\r\nmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());\r\nlong long rng(long long l, long long r) {\r\n uniform_int_distribution uni(l, r);\r\n return uni(mt);\r\n}\r\n\r\n#define int long long //int main()->signed main()?\r\n#define INF 0x3f3f3f3f\r\n#define LLINF 9223372036854775807\r\n#define pii pair\r\n#define pip pair\r\n#define ppi pair\r\n#define ppp pair\r\nconst int MOD1=998244353;\r\nconst int MOD2=1e9+7;\r\nconst int N4=1e4+10;\r\nconst int N5=1e5+10;\r\nconst int NN5=2e5+10;\r\nconst int N6=1e6+10;\r\nconst int N7=1e7+10;\r\nconst int N8=1e8+10;\r\nconst int N9=1e9+10;\r\nint dr[4]={0,1,0,-1};\r\nint dc[4]={1,0,-1,0};\r\nint dx[4]={1,0,-1,0};\r\nint dy[4]={0,1,0,-1};\r\n#define is_odd(x) (x&1)\r\n#define lowbit(x) (x&(-x))\r\nvoid bin_print(int now,int cnt){\r\n if(!cnt) return;\r\n bin_print(now>>1,cnt-1);\r\n cout<<(now&1);\r\n}\r\nint fast_pow(int x,int n=MOD2-2,int mod=MOD2,int ret=1){\r\n while(n){\r\n if(n&1) ret=ret*x%mod;\r\n x=x*x%mod;\r\n n>>=1;\r\n }\r\n return ret;\r\n}\r\nlong long fast_ll_pow(long long x,long long n,long long ret=1){\r\n while(n){\r\n if(n&1) ret=ret*x;\r\n x=x*x;\r\n n>>=1;\r\n }\r\n return ret;\r\n}\r\nint exgcd(int a,int b,int &x,int &y){\r\n if(!b){x=1;y=0;return a;}\r\n else{int ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}\r\n}\r\nint lcm(int a,int b){return a*b/__gcd(a,b);}\r\ntypedef long long ll;\r\n\r\nvoid run()\r\n{\r\n int n,m,k;\r\n cin>>n>>m>>k;\r\n if(n&1){\r\n int r=m/2;\r\n if(k(m/2)*n) return (void)(cout<>T;\r\n while(T--)\r\n {\r\n run();\r\n }\r\n\r\n\r\n\r\n AC Please;\r\n}\r\n// \"str.size()-num\" --> \"(int)str.size()-num\" ?\r\n", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"source_code": "// Build DAG by adding single vertices.\n// If we add vertex i, we can't add any vertex < i\n// until there is an edge to it from vertex i or any later added vertex.\n// States of DP: (added vertices, candidates for next added). O(4^N).\n#include \nusing namespace std;\n\nstruct state {\n\tint candidates;\n\tint cnt, sum;\n\tconstexpr static int mod = 998244353;\n\n\tstate() = default;\n\tstate(int candidates_, int cnt_, long long sum_)\n\t\t: candidates(candidates_), cnt(cnt_), sum(sum_ % mod) {}\n\n\tinline state & operator+=(const state & S) {\n\t\tcnt += S.cnt;\n\t\tif(cnt >= mod) cnt -= mod;\n\t\tsum += S.sum;\n\t\tif(sum >= mod) sum -= mod;\n\t\treturn *this;\n\t}\n\n\tbool operator<(const state & S) const {\n\t\treturn candidates < S.candidates;\n\t}\n};\n\nint main() {\n\tcin.sync_with_stdio(0);\n\tcin.tie(0);\n\tint N, M;\n\tcin >> N >> M;\n\tvector E(N, 0), Ei(N, 0), E_all(N, 0);\n\tfor(int i = 0; i < M; i++) {\n\t\tint u, v;\n\t\t/* rand */\n\t\t// static mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());\n\t\t// u = rng()%N, v = rng()%N;\n\t\t// while(u == v || (E_all[u]>>v)&1)\n\t\t// \tu = rng()%N, v = rng()%N;\n\t\t/* rand */\n\t\t/* input */\n\t\tcin >> u >> v;\n\t\tu--, v--;\n\t\t/* input */\n\t\tE[u] |= 1< > dp(1<>j)&1) {\n\t\t\t\t\tint next_used = used | (1<\n#include\n#include\nusing namespace std;\n\n\n\nint main()\n{\n \nlong long a,b;\n\ncin>>a>>b;\nint count=0;\nbool f=0;\n\nfor(long long k=a;k<=b;k++)\n{\n for(long long j=k+1;j<=b;j++)\n {\n for(long long i=j+1;i<=b;i++)\n {\n \n long long d1=std::__gcd(i,j);\n long long d2=std::__gcd(j,k);\n long long d3=std::__gcd(i,k);\n if ( ( d1==d2) && ( d2!=d3) )\n { cout<\n#include \n\ninline bool is_upper(char c) {\n return c >= 'A' && c <= 'Z';\n}\n\nchar to_upper(char c) {\n if (is_upper(c))\n return c;\n return c - 'a' + 'A';\n}\n\nchar to_lower(char c) {\n if (!is_upper(c))\n return c;\n return c - 'A' + 'a';\n}\n\n\nint main() {\n std::string s;\n std::cin >> s;\n\n int numLowerCase, numUpperCase;\n numLowerCase = numUpperCase = 0;\n for (size_t i = 0; i < s.size(); ++i) {\n char c = s[i];\n if (is_upper(c)) {\n ++numUpperCase;\n } else {\n ++numLowerCase;\n }\n }\n\n if (numUpperCase > numLowerCase) {\n for (size_t i = 0; i < s.size(); ++i)\n std::cout << to_upper(s[i]);\n } else {\n for (size_t i = 0; i < s.size(); ++i)\n std::cout << to_lower(s[i]);\n }\n\n std::cout << std::endl;\n return 0;\n}\n", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"source_code": "#include\nusing namespace std;\n\nchar grid[502][502];\nint t, n, k, vis[502][502];\nvector cntCells;\n\nbool valid(int x, int y) {\n return (x && y && x <= n && y <= n && grid[x][y] != 'X' && vis[x][y] == -1);\n}\n\nvoid DFS(int x, int y) {\n vis[x][y] = t;\n cntCells[t]++;\n if (valid(x-1,y)) DFS(x-1,y);\n if (valid(x+1,y)) DFS(x+1,y);\n if (valid(x,y-1)) DFS(x,y-1);\n if (valid(x,y+1)) DFS(x,y+1);\n}\n\nvoid findCC() {\n t = 0;\n memset(vis,-1,sizeof vis);\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= n; j++) {\n if (valid(i,j)) {\n cntCells.push_back(0);\n DFS(i,j);\n t++;\n }\n }\n }\n}\n\nint main() {\n int res = 0;\n scanf(\"%d %d\", &n, &k);\n for (int i = 1; i <= n; i++) {\n cin.ignore();\n for (int j = 1; j <= n; j++) {\n scanf(\"%c\", &grid[i][j]);\n }\n }\n findCC();\n int vs[cntCells.size()+1] = {0};\n // pre-processing\n for (int i = 1; i <= k; i++) {\n for (int j = 1; j <= k; j++) {\n if (vis[i][j] != -1) cntCells[vis[i][j]]--;\n }\n }\n\n for (int i = 1; i+k-1 <= n; i++) {\n if (i&1) {\n // Pre-processing Vertically\n for (int u = 1; u <= k && i != 1; u++) {\n if (grid[i-1][u] == '.') cntCells[vis[i-1][u]]++;\n if (grid[i+k-1][u] == '.') cntCells[vis[i+k-1][u]]--;\n }\n\n for (int j = 1; j+k-1 <= n; j++, t++) {\n int tmp = k*k;\n\n // Pre-processing Horizontally\n if (j != 1) {\n for (int u = i; u < i+k; u++) {\n if (grid[u][j-1] == '.') cntCells[vis[u][j-1]]++;\n if (grid[u][j+k-1] == '.') cntCells[vis[u][j+k-1]]--;\n }\n }\n\n // Check for components at borders & add their counts\n for (int u = 0; u < k; u++) {\n if (vis[i-1][j+u] != -1 && vs[vis[i-1][j+u]] != t) {tmp += cntCells[vis[i-1][j+u]]; vs[vis[i-1][j+u]] = t;}\n if (vis[i+k][j+u] != -1 && vs[vis[i+k][j+u]] != t) {tmp += cntCells[vis[i+k][j+u]]; vs[vis[i+k][j+u]] = t;}\n if (vis[i+u][j-1] != -1 && vs[vis[i+u][j-1]] != t) {tmp += cntCells[vis[i+u][j-1]]; vs[vis[i+u][j-1]] = t;}\n if (vis[i+u][j+k] != -1 && vs[vis[i+u][j+k]] != t) {tmp += cntCells[vis[i+u][j+k]]; vs[vis[i+u][j+k]] = t;}\n }\n\n // Maximize\n res = max(res, tmp);\n }\n } else {\n\n // Pre-processing Vertically\n for (int u = n-k+1; u <= n; u++) {\n if (grid[i-1][u] == '.') cntCells[vis[i-1][u]]++;\n if (grid[i+k-1][u] == '.') cntCells[vis[i+k-1][u]]--;\n }\n\n for (int j = n-k+1; j > 0; j--, t++) {\n int tmp = k*k;\n\n // Pre-processing Horizontally\n if (j != n-k+1) {\n for (int u = i; u < i+k; u++) {\n if (grid[u][j] == '.') cntCells[vis[u][j]]--;\n if (grid[u][j+k] == '.') cntCells[vis[u][j+k]]++;\n }\n }\n\n // Check for components at borders & add their counts\n for (int u = 0; u < k; u++) {\n if (vis[i-1][j+u] != -1 && vs[vis[i-1][j+u]] != t) {tmp += cntCells[vis[i-1][j+u]]; vs[vis[i-1][j+u]] = t;}\n if (vis[i+k][j+u] != -1 && vs[vis[i+k][j+u]] != t) {tmp += cntCells[vis[i+k][j+u]]; vs[vis[i+k][j+u]] = t;}\n if (vis[i+u][j-1] != -1 && vs[vis[i+u][j-1]] != t) {tmp += cntCells[vis[i+u][j-1]]; vs[vis[i+u][j-1]] = t;}\n if (vis[i+u][j+k] != -1 && vs[vis[i+u][j+k]] != t) {tmp += cntCells[vis[i+u][j+k]]; vs[vis[i+u][j+k]] = t;}\n }\n\n // Maximize\n res = max(res, tmp);\n }\n }\n }\n printf(\"%d\", res);\n}", "src_uid": "d575f9bbdf625202807db59490c5c327"} {"source_code": "/* NOOB CODER */\n//I think of what the world could be, A vision of the one I see, A million dreams is all it's gonna take.\n\n#include\nusing namespace std;\n\n#define F first\n#define pb(x) push_back(x)\n#define S second\n#define rep(i,a,b) for(int i=a; i pii;\ntypedef pair pll;\nll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}\nll lcm(ll a,ll b){return a/gcd(a,b)*b;}\n\nbool isPrime(ll n)\n{\n\n if (n <= 1)\n return false;\n\n\n for (ll i = 2; i <=sqrt(n); i++)\n if (n % i == 0)\n return false;\n\n return true;\n}\n\nint setbit(int n){int c;while(n){c+= n & 1;n>>= 1;}return c;}\nbool sortinrev(const pair &a,\n const pair &b)\n{\n return (a.first > b.first);\n}\nconst int N = 300050;\nconst int maxN = 5e5 + 5;\nll poww(ll a, ll b)\n{\n ll res = 1;\n for(int i = 1; i<=b; ++i)\n res *= a;\n\n return res;\n}\n\n\nint main()\n{\n GO_CORONA_GO\n\n int tt=1;\n //cin>>tt;\n\n while(tt--)\n {\n int n;cin>>n;\n if(n==0)\n cout<<\"O-|-OOOO\";\n while(n){\n int x=n%10;\n\n if (x<5)cout<<\"O-|\";else {x-=5;cout<<\"-O|\";}\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\nusing namespace std;\nint n,k,x;\nint gao(int ans,int a[])\n{\n int vis[111];\n int sum=0;\n int b[200];\n for(int i=0;i=3){\n flag=1;for(int j=sign;j<=i;j++) vis[j]=1,sum++;\n }\n cnt=1;\n i++;\n }\n int gg=0;\n for(int i=0;i\nusing namespace std;\nlong long int gcd(long long int a, long long int b)\n{\n if(b==0)\n {\n return a;\n }\n return gcd(b, a%b);\n}\nlong long int gcdi(long long int a, long long int b)\n{\n if(a>num>>a>>b>>ac>>bc;\n long long int net=a*b;\n long long int anet=num/a;\n long long int sub=(gcdi(a, b)*num)/net;\n long long int bnet=num/b;\n if(ac>bc)\n {\n bnet-=sub;\n }\n else\n {\n anet-=sub;\n }\n long long int ans=(anet*ac) + (bnet*bc);\n cout<\nusing namespace std;\n#define int long long\n#define endl '\\n'\nconst int M = 10000;\n\nsigned main() {\n iostream::sync_with_stdio(false);\n int n, px;\n string py;\n cin>>n>>px>>py;\n\n while(py.size()!=5) {\n py.push_back('0');\n }\n\n int p = px*M + stoi(py.substr(1));\n\n int tot = (n*(n-1)*(n-2))/6;\n for(int m=0; m<=n; m++) {\n int cur = 2*(m*(m-1)*(m-2))/6;\n cur += 2*((m*(m-1))/2)*(n-m);\n cur += (m*(n-m)*(n-m-1)/2);\n if(cur*M/2 >= p*tot) {\n cout<\n#include\nusing namespace std;\n\nbool check(unsigned long z, unsigned long f, string x, string y)\n{\n if(f!=z)\n return false;\n \n for(int i=0; i>x;\n cin>>y;\n z = x.length();\n f = y.length();\n \n if ( check(z,f,x,y) == true )\n cout<<\"YES\";\n else\n cout<<\"NO\";\n}", "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"source_code": "#include\nusing namespace std;\n#define int long long \nint sum,n;\nsigned main(){\n\tscanf(\"%lld\",&n);\n\tsum=n;\t//sum初始化为n \n\t\n\tsum-=n/2;sum-=n/3;sum-=n/5;sum-=n/7;\n\t//第一部分 减去1个数 \n\t\n\tsum+=n/6;sum+=n/10;sum+=n/14;sum+=n/15;sum+=n/21;sum+=n/35;\n\t//第二部分 加上2个数 \n\t\n\tsum-=n/30;sum-=n/42;sum-=n/70;sum-=n/105;\n\t//第三部分 减去3个数\n\t \n\tsum+=n/210;\n\t//最后一步 加上4个数 \n\t\n\tprintf(\"%lld\",sum);\n\treturn 0; \n} ", "src_uid": "e392be5411ffccc1df50e65ec1f5c589"} {"source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\nchar a[101];\nint b[101]={0},sum=0,ans=0;\n\nint main()\n{\n\tcin>>a;\n\tfor(int i=1;i<=strlen(a);i++)\n\t{\n\t\tif(a[i-1]=='Q')\n\t\t{\n\t\t\tsum++;\n\t\t\tb[i]=b[i-1]+1;\n\t\t}\n\t\telse b[i]=b[i-1];\n\t}\n\tfor(int i=0;i\nusing namespace std;\nint main()\n{\n int n,g=0,f=0+1-1;\n cin>>n;\n int x[n]={0};\n for(int i=1;i<=n;i++)\n {\n x[i-1]+=i;\n }\n for(int i=0;ii&&x[i]/x[j]%2==0)\n {\n g=x[i];f=x[j];\n }\n }\n }\n if(g%2==0&&f%2==0)\n {\n cout<\nusing namespace std;\n\nint main()\n{\n int n,m,h;\n cin>>n>>h>>m;\n int arr[n+3]={0};\n for(int i=1;i<=n;i++)\n arr[i]=654;\n for(int i=0;i>l>>r>>x;\n for(int j=l;j<=r;j++)\n {\n if(arr[j]>x)\n arr[j]=x;\n }\n\n }\n for(int i=1;i<=n;i++)\n if(arr[i]==654)\n arr[i]=h;\n sort(arr,arr+n);\n long long int sum=0;\n//for(int i=1;i<=n;i++)\n // cout<=1;i--)\n {\n sum+=arr[i]*arr[i];\n }\n cout<\nusing namespace std;\n\nint main()\n{\n int n,m,p,v;\n cin>>n>>m;\n\n if(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\n#define inf 1<<30\n#define pi acos(-1.0)\n#define in(a) scanf(\"%lld\",&a)\n#define FOR(a,b,c) for(a=b;a<=c;a++)\n#define ROF(a,b,c) for(a=c;a>=1;a--)\n#define For(a,b,c) for(a=b;a=0;a--)\n#define rep(i,a,b,c) for(i=a;i<=b;i+=c)\n#define mm(arr,x) memset(arr,x,sizeof(arr))\n#define pf printf\n#define fin freopen(\"in.txt\",\"r\",stdin)\n#define fout freopen(\"out.txt\",\"w\",stdout)\n#define pb push_back\n#define sq(x) ((x)*(x))\n#define Sqrt(n) (long long)round(sqrt((double)n))\n#define logg(x,y) (double)log(y)/(double)log(x)\n#define cl clear()\n#define ps push\n#define mod 1000000007\n#define mid (lo+hi)/2\n#define LEFT node*2\n#define RIGHT (node*2)+1\n\n\nusing namespace std;\ntypedef long long ll;\ntypedef string S;\ntypedef double D;\n\nvectorv;\nvectorvv;\n\nll arr[100005];\n\nll attoi(S s)\n{\n ll len=s.length(),x=0;\n for(ll i=len-1;i>=0;i--)\n {\n x=x*10+s[i]-'0';\n }\n return x;\n}\n\nvoid call(S s,ll pos,ll len)\n{\n if(pos==len/2)\n {\n for(ll i=0;i<(len/2);i++)\n {\n char c=s[pos-i-1];\n s+=c;\n }\n v.pb(s);\n return;\n }\n ll start=0;\n if(pos==0)\n start=1;\n for(ll i=start;i<=9;i++)\n {\n char c='0'+i;\n call(s+c,pos+1,len);\n }\n return;\n}\n\nint main()\n{\n ll i,j,k,n,m,x,cnt=0,count=0,t,y,p,q,maxx=0,minn=1<<30,a,b,test=0,len,sum=0,c;\n string s,s1,s2;\n s.clear();\n call(s,0,2);\n call(s,0,4);\n call(s,0,6);\n call(s,0,8);\n call(s,0,10);\n v.pb(\"100000000001\");\n ll sz=v.size();\n for(i=0;i\n \nusing namespace std;\n \n#define fo(i, a, b) for(int i = a; i <= b; i++)\n#define _fo(i, a, b) for(int i = a; i >= b; i--)\n#define sz(a) ((int) a.size())\n#define all(a) begin(a), end(a)\n#define fi first\n#define se second\n#define pb(x) push_back(x)\n#define mk(x, y) make_pair(x, y) \n \ntypedef long long ll;\ntypedef pair pll;\ntypedef vector vl;\ntypedef pair pii;\ntypedef vector vi;\n \nconst int MAX = 1e5+5;\nconst int MOD = 1e9+7;\nconst ll INF = INT_MAX;\nconst ll _INF = INT_MIN; \n\nll lcm(ll a, ll b) {\n\treturn (a*b) / __gcd(a, b);\n}\n\nsigned main() {\n\tll c;\n\tpll candy[2];\n\t\n\tcin >> c >> candy[0].fi >> candy[1].fi >> candy[0].se >> candy[1].se;\n\t\n\tbool opt = (candy[0].fi*candy[1].se < candy[1].fi*candy[0].se);\t\t\n\tbool mxw = (candy[0].se < candy[1].se);\n\tll d = lcm(candy[0].se, candy[1].se);\n\t\n\tll ans = 0;\n\tfo(i, 0, 2) {\n\t\tll temp = (c%d) + i*d;\n\t\tif(temp > c) break;\n\t\tfor(ll j = 0; candy[mxw].se*j <= min(temp, d-1); j++) \n\t\t\tans = max(ans, candy[opt].fi*(c-temp)/candy[opt].se + candy[mxw].fi*j + candy[(mxw^1)].fi*min(d/candy[(mxw^1)].se-1, (temp-candy[mxw].se*j)/candy[(mxw^1)].se));\t\n\t}\n\n\tcout << ans;\n}", "src_uid": "eb052ca12ca293479992680581452399"} {"source_code": "#include\n#define int long long\nusing namespace std;\nconst int N=1e6;\nconst int lim=1e6+5;\nconst int P=1e9+7;\nint inv[lim],f[lim];\nbool vis[lim];\nvectorfac[lim];\nint g[lim],cnt[lim];\nint x;\nint n,q,k;\nint ans=0;\ninline int C(int n,int m){\n\tif(m>n)return 0;\n\treturn 1ll*f[n]*inv[m]%P*inv[n-m]%P;\n}\nvoid update(){\n\tfor(auto i:fac[x]){\n\t\tans=(ans+1ll*g[i]*C(cnt[i],k-1)%P)%P;\n\t\tcnt[i]++;\n\t}\n}\ninline int qpow(int a,int b){\n\tint res=1;\n\twhile(b){\n\t\tif(b&1){\n\t\t\tres=1ll*res*a%P;\n\t\t}\n\t\ta=1ll*a*a%P;\n\t\tb>>=1;\n\t}\n\treturn res;\n}\nsigned main()\n{\n\tfor(int i=1;i<=N;i++){\n\t\tg[i]=i;\n\t}\n\tfor(int i=1;i<=N;i++){\n\t\tfac[i].push_back(i);\n\t\tfor(int j=i+i;j<=N;j+=i){\n\t\t\tfac[j].push_back(i);\n\t\t\tg[j]-=g[i];\n\t\t}\n\t}\n\tf[0]=1;\n\tfor(int i=1;i<=N;i++){\n\t\tf[i]=1ll*i*f[i-1]%P;\n\t}\n\tinv[N]=qpow(f[N],P-2);\n\tfor(int i=N-1;i>=0;i--){\n\t\tinv[i]=1ll*inv[i+1]*(i+1)%P;\n\t}\n\tscanf(\"%d%d%d\",&n,&k,&q);\n\tfor(int i=0;i\n#define x first\n#define y second\nusing namespace std;\ntypedef pair ii;\nconst char leta='a';\nconst char letb='b';\nconst char win[]=\"FIRST\";\nconst char draw[]=\"DRAW\";\nconst char lose[]=\"SECOND\";\nconst int INF=7e3;\nchar board[23][23];\nint n;\nint f[41][(1<<20)+7];\nbool c[41][(1<<20)+7];\nint dx[]={0,1};\nint dy[]={1,0};\nint diagsize(const int &id) {\n\tif (idy) x=y;\n}\nvoid maximize(int &x,const int &y) {\n\tif (x0);\n\tif (c[id][state]) return (f[id][state]);\n\tif (id==2*n-2) return (0);\n\tif (id%2==0) f[id][state]=INF;\n\telse f[id][state]=-INF;\n\tint next[30];\n\tmemset(next,0,sizeof next);\n\tint i,j,vx,vy;\n\tii p;\t\n\tfor (i=0;i0) {\n\t\t\tif (id%2==0) minimize(f[id][state],count(id+1,next[i-'a'])+(i==leta)-(i==letb));\n\t\t\telse maximize(f[id][state],count(id+1,next[i-'a'])+(i==leta)-(i==letb));\n\t\t}\n\tc[id][state]=true;\n\tassert(f[id][state]-INF);\n\t//printf(\"f(%d,%d)=%d\\n\",id,state,f[id][state]);\n\treturn (f[id][state]);\n}\nvoid process(void) {\n\tint res=count(0,1)+(board[0][0]==leta)-(board[0][0]==letb);\n\tif (res>0) printf(\"%s\",win);\n\tif (res<0) printf(\"%s\",lose);\n\tif (res==0) printf(\"%s\",draw);\n}\nint main(void) {\n\tinit();\n\tprocess();\n\treturn 0;\n}\n", "src_uid": "d803fe167a96656f8debdc21edd988e4"} {"source_code": "#include \n#include \n#include \n\nint main( ){\n\tint n, t;\n\tstd::cin >> n >> t;\n\tstd::string s;\n\tstd::cin >> s;\n\tchar c;\n\tbool is_used = false;\n\tfor (int i = 0; i < t; ++i){\n\t\tfor (int j = s.size() - 1; j >= 1; --j){\n\t\t\tif (is_used){\n\t\t\t\tis_used = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (s[j] == 'G' && s[j - 1] == 'B'){\n\t\t\t\tc = s[j];\n\t\t\t\ts[j] = s[j - 1];\n\t\t\t\ts[j - 1] = c;\n\t\t\t\tis_used = true;\n\t\t\t}\n\t\t}\n\t}\n\tstd::cout << s;\n\n\treturn 0;\n}", "src_uid": "964ed316c6e6715120039b0219cc653a"} {"source_code": "#include \nusing namespace std;\n\n#define endl \"\\n\"\n#define pb push_back\n#define mp make_pair\n#define ff first\n#define ss second\n#define trace1(x) cout<<#x<<\": \"< plli;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef vector > vplli;\ntypedef vector vlli;\ntypedef vector vvlli;\ntypedef vector vc;\ntypedef vector vvc;\ntypedef vector vb;\ntypedef vector vvb;\n\n#define PI 3.141592653589793\n#define mod (lli)(1000*1000*1000+7)\n\ntemplate T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }\ntemplate T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }\n\nint main(){\n\tlli n, m;\n\tcin>>n>>m;\n\tlli cnt = 0;\n\tfor(lli i = 1 ; i <= m ; i++){\n\t\tfor(lli j = i ; j <= m ; j++){\n\t\t\tif((i*i+j*j)%m == 0){\n\t\t\t\tif(i==j) cnt++;\n\t\t\t\telse cnt+=2;\n\t\t\t}\n\t\t}\n\t}\n\tlli l = n/m;\n\n\tcnt *= (l*l);\n\tlli cnt2 = 0;\n\tfor(lli i = m*l+1; i <= n ; i++){\n\t\tfor(lli j = 1 ; j<= m ; j++){\n\t\t\tif((i*i+j*j)%m == 0){\n\t\t\t\tcnt2+=2;\n\t\t\t}\n\t\t}\n\t}\n\tcnt2 *= l;\n\tcnt+=cnt2;\n\tfor(lli i = m*l+1; i <= n ; i++){\n\t\tfor(lli j = i ; j<= n ; j++){\n\t\t\tif((i*i+j*j)%m == 0){\n\t\t\t\tif(i==j) cnt++;\n\t\t\t\telse cnt+=2;\n\t\t\t}\n\t\t}\n\t}\n\tcout<\n\nusing namespace std;\n\n#define REP(i, n) for(int i = 0; i < n; i++)\n\nchar bel[4], els[4];\n\nint main(){\n //freopen(\"in.in\", \"r\", stdin);\n REP(i, 4) cin >> bel[i];\n REP(i, 4) cin >> els[i];\n \n int brow, erow;\n int b = 0, e = 0;\n \n // counting inversions\n // checking whether the blank is on odd row\n REP(i, 3){\n REP(j, 3){\n if(bel[i] == 'X') \n if(i < 2) brow = 1;\n else brow = 0; \n else if(i < j+1 && bel[i] > bel[j+1]) b++;\n }\n }\n \n REP(i, 3) {\n REP(j, 3){\n if(els[i] == 'X')\n if(i < 2) erow = 1;\n else erow = 0; \n else if(i < j+1 && els[i] > els[j+1]) e++;\n }\n }\n\n // checking solvability\n if((brow == 1) == (b % 2 == 0))\n b = 1;\n else b = 0;\n if((erow == 1) == (e % 2 == 0))\n e = 1;\n else e = 0;\n\n if (b == e) cout << \"YES\" << endl;\n else cout << \"NO\" << endl;\n\n return 0;\n}\n", "src_uid": "46f051f58d626587a5ec449c27407771"} {"source_code": "#include\nusing namespace std;\nint a[110],id[110];\nint main(){\nint n;scanf(\"%d\",&n);\nint s=0;\nfor(int i=1;i<=n;i++) scanf(\"%d\",a+i),s+=a[i];\nint ss=a[1],ans=0;\nid[0]=1;\nfor(int i=2;i<=n;i++){\nif(a[i]*2<=a[1]) {\nid[++ans]=i;\nss+=a[i];\n}\n}\nif(ss*2>s){\nprintf(\"%d\\n\",ans+1);\nfor(int i=0;i<=ans;i++) printf(\"%d \",id[i]);\n}\nelse printf(\"0\\n\");\nreturn 0;\n}\n ", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "/*\nID: zhaowei10\nTASK:\nLANG: C++14\n*/\n#include \n\n#include \n#include \n#include \n\nusing namespace __gnu_cxx;\nusing namespace __gnu_pbds;\nusing namespace std;\n\n#ifdef LOCAL\n#include \n#else\n#define debug(...) 0\n#endif\n\n#define eb emplace_back\n\nusing ll = long long;\nusing ld = long double;\nusing ii = pair;\nusing vi = vector;\nusing vii = vector;\nusing vc = vector;\nusing vb = vector;\nusing vll = vector;\n\nint main() {\n cin.tie(nullptr);\n ios::sync_with_stdio(false);\n cout << fixed << setprecision(9);\n\n#ifdef LOCAL\n freopen(\"test.in\", \"r\", stdin);\n freopen(\"test.out\", \"w\", stdout);\n#else\n#endif\n\n int w, h;\n cin >> w >> h;\n ll ans = 0;\n for (int i = 2; i <= w; i += 2) {\n for (int j = 2; j <= h; j += 2) {\n ll cur = (ll)(w - i + 1) * (h - j + 1);\n ans += cur;\n }\n }\n cout << ans;\n}", "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"source_code": "#include \nusing namespace std;\n#define ll long long int \n#define ulli unsigned long long int \n#define li long int \n#define ff(i,a,b) for(int i=a;i=a;i--)\n#define w(t) while(--t >= 0)\n#define l(s) s.length()\n#define ci(n) cin>>n;\n#define fast ios_base::sync_with_stdio(false);\n#define sa(a,n) sort(a,a+n)\n#define sv(v) sort(v.begin(),v.end())\n#define cy cout<<\"YES\\n\"\n#define cn cout<<\"NO\\n\"\n#define nl cout<<\"\\n\"\n#define minus cout<<\"-1\\n\";\n#define vi vector\n#define pb push_back\n#define tc int t; cin>>t;\n#define pp pair\n#define input(a,n) for(int i=0;i>a[i];\n#define mod 1000000007\n#define co(n) cout<\n#define output(a,n) for(int i=0;i> n;\n w(n)\n {\n cin>>w>>x>>y>>z;\n S += (y-w)*(z-x);\n W = min(w, W);\n X = min(x, X),\n Y = max(y, Y);\n Z = max(z, Z);\n }\n cout<<((S==((Y-W)*(Z-X)) && (Y-W)==(Z-X)) ? \"YES\" : \"NO\");\n}", "src_uid": "f63fc2d97fd88273241fce206cc217f2"} {"source_code": "#include\nusing namespace std;\ntypedef long long ll;\ntypedef pair ii;\ntypedef pair pll;\ntypedef vector vii;\ntypedef vector vi;\ntypedef vector vll;\ntypedef vector vs;\ntypedef map mpii;\ntypedef map mpsi;\ntypedef set si;\ntypedef set sll;\n#define pb push_back\n#define INF 1000000000\n#define LINF INF*INF\n#define all(x) x.begin(),x.end()\nvll fact(20);\nmap vss;\nll getans(vi cnt)\n{\n int sum=0;\n\tfor(int i=0;i<=9;i++)\n\t\tsum+=cnt[i];\n\tll ans=0;\n\tans=fact[sum];\n\tfor(auto it:cnt)\n\t\tans/=fact[it];\n\tint sum2=sum-cnt[0];\n\tans*=sum2;\n\tans/=sum;\n\treturn ans;\n}\nll recur(vi cnt)\n{\n\tll ans=0;\n\tans += getans(cnt);\n\tstringstream str;\n\tfor(auto it:cnt)\n\t str<1)\n\t\t{\n\t\t\tcnt[i]--;\n\t\t\ts[i]--;\n\t\t\tif(!vss[s]){\n\t\t\t vss[s]=1;\n\t\t\t ans+=recur(cnt);\n\t\t\t}\n\t\t\ts[i]++;\n\t\t\tcnt[i]++;\n\t\t}\n\t}\n\treturn ans;\t\n}\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tcin.tie(0);cout.tie(0);\n\tll n;cin>>n;\n\tstring t= to_string(n);\n\tvi cnt(10);\n\tfor(int i=0;i\n\nusing namespace std;\n\ntypedef pair pi;\n\nconst int MAXN = 200005;\n\nint n, m, q, rip, moze = 1;\nint a[MAXN], b[MAXN], ans[MAXN];\nint par[MAXN], col[MAXN];\nvector siz[MAXN];\nvector e;\n\nvoid dsu_init () {\n rip = 0;\n for (int i = 1; i <= n; i++) {\n par[i] = i;\n siz[i].clear();\n siz[i].push_back(1);\n }\n}\n\npi nadi (int x) {\n if (x == par[x]) return {par[x], 0};\n pi res = nadi(par[x]);\n return {res.first, res.second ^ col[x]};\n}\n\nvoid spoji (int a, int b) {\n pi resa = nadi(a), resb = nadi(b);\n a = resa.first, b = resb.first;\n\n if (a == b) {\n e.push_back({-a, rip});\n rip += resa.second == resb.second;\n return;\n }\n\n if (siz[a].back() < siz[b].size()) swap(a, b);\n par[b] = a;\n col[b] = resa.second == resb.second;\n siz[a].push_back(siz[a].back() + siz[b].back());\n e.push_back({a, b});\n}\n\nvoid makni () {\n int a = e.back().first, b = e.back().second;\n e.pop_back();\n if (a < 0) {\n rip = b;\n return;\n }\n par[b] = b;\n col[b] = 0;\n siz[a].pop_back();\n}\n\nvoid calc (int lef, int rig, int lo, int hi) {\n if (lef > rig) return;\n int mid = (lef + rig) / 2;\n\n int poc = e.size();\n for (int i = lef; i < mid; i++) spoji(a[i], b[i]);\n\n if (rip > 0) {\n ans[mid] = hi;\n } else {\n int prije = e.size();\n for (int i = hi - 1; i >= max(lo, mid); i--) {\n spoji(a[i], b[i]);\n if (rip > 0) {\n ans[mid] = i;\n break;\n }\n }\n while (e.size() > prije) makni();\n }\n\n spoji(a[mid], b[mid]);\n calc(mid + 1, rig, ans[mid], hi);\n while (e.size() > poc) makni();\n\n for (int i = hi - 1; i >= ans[mid]; i--) spoji(a[i], b[i]);\n calc(lef, mid - 1, lo, ans[mid]);\n while (e.size() > poc) makni();\n}\n\nint main () {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cin >> n >> m >> q;\n dsu_init();\n for (int i = 1; i <= m; i++) {\n cin >> a[i] >> b[i];\n spoji(a[i], b[i]);\n }\n if (rip == 0) {\n moze = 0;\n } else {\n dsu_init();\n calc(1, m, 1, m + 1);\n }\n for (int i = 0; i < q; i++) {\n int lo, hi;\n cin >> lo >> hi;\n if (moze == 0) {\n cout << \"NO\\n\";\n } else {\n if (hi < ans[lo]) cout << \"YES\\n\"; else cout << \"NO\\n\";\n }\n }\n return 0;\n}\n", "src_uid": "57ad95bb938906f7550f7eb6422130f7"} {"source_code": "//written by rraj001:)\n#include\n#define ll long long\n#define pb push_back\n#define ff first\n#define ss second\n#define ldd long double\n#define mod 1000000007\n#include\n//#include\n//#define umap unordered_map\nusing namespace std;\n\nint main()\n{\n\n std::ios::sync_with_stdio(false);\n ll x1,x2,y1,y2,x3,y3;\n cin>>x1>>y1;\n cin>>x2>>y2;\n cin>>x3>>y3;\n bool f=false;\n if(x1>=x2 && y1>=y2)\n {\n if(x3<=x1-x2 && y3<=y1)f=true;\n if(y3<=x1-x2 && x3<=y1)f=true;\n if(y3<=y1-y2 && x3<=x1)f=true;\n if(x3<=y1-y2 && y3<=x1)f=true;\n\n }\n if(x1>=x3 && y1>=y3)\n {\n if(x2<=x1-x3 && y2<=y1)f=true;\n if(y2<=x1-x3 && x2<=y1)f=true;\n if(y2<=y1-y3 && x2<=x1)f=true;\n if(x2<=y1-y3 && y2<=x1)f=true;\n }\n if(y1>=x2 && x1>=y2)\n {\n if(x3<=y1-x2 && y3<=x1)f=true;\n if(y3<=y1-x2 && x3<=x1)f=true;\n if(y3<=x1-y2 && x3<=y1)f=true;\n if(x3<=x1-y2 && y3<=y1)f=true;\n\n }\n if(y1>=x3 && x1>=y3)\n {\n if(x2<=y1-x3 && y2<=x1)f=true;\n if(y2<=y1-x3 && x2<=x1)f=true;\n if(y2<=x1-y3 && x2<=y1)f=true;\n if(x2<=x1-y3 && y2<=y1)f=true;\n }\n\n if(f)cout<<\"YES\"<\nusing namespace std; int n, x, y; int main() {\n cin >> n >> x >> y;\n cout << ((x == n / 2|| x == n / 2 + 1) && (y == n / 2 || y == n / 2 + 1) ? \"NO\" : \"YES\");\n}", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789"} {"source_code": "#include \nconst int N = 800010;\n#define For(i, x, y) for (i = x; i <= y; i++)\nusing namespace std;\nint i, j, k, n, m, nn, flag, Ge, D, len, shu, xi, num, wei, num4, sum, bian, t, X, Y;\nstruct read\n{\n char p[2], s[2];\n int x, y;\n inline char gai(char x)\n {\n return x == 'L' ? 'T' : x == 'R' ? 'B' : x == 'B' ? 'L' : 'R';\n }\n inline void change(char x, int &y)\n {\n if (x == 'L')\n y = n - y + 1;\n if (x == 'R')\n y = n - y + 1;\n }\n inline void fan()\n {\n change(p[0], x);\n change(s[0], y);\n p[0] = gai(p[0]);\n s[0] = gai(s[0]);\n }\n} rea[N];\nstruct ww\n{\n int x, y, ty;\n} a[N];\nint dui[N], F[N], ty[10], biao[N], b[N], anx[N], any[N], f[N];\ninline void fail()\n{\n printf(\"No solution\\n\");\n exit(0);\n}\ninline void print()\n{\n int i;\n if (!flag)\n {\n For(i, 1, n) printf(\"%d \", anx[i]);\n printf(\"\\n\");\n For(i, 1, m) printf(\"%d \", any[i]);\n printf(\"\\n\");\n }\n else\n {\n for (i = m; i; i--)\n printf(\"%d \", m - any[i] + 1);\n printf(\"\\n\");\n For(i, 1, n) printf(\"%d \", anx[i]);\n printf(\"\\n\");\n }\n}\ninline void gai(char x, int &y)\n{\n if (x == 'T')\n y += n;\n if (x == 'R')\n y += nn;\n if (x == 'B')\n y += n + nn;\n}\ninline void into(char x, char y)\n{\n if (x > y)\n swap(x, y);\n if (x == 'B' && y == 'L')\n ty[3]++;\n if (x == 'B' && y == 'R')\n ty[4]++;\n if (x == 'B' && y == 'T')\n ty[5]++;\n if (x == 'L' && y == 'R')\n ty[6]++;\n if (x == 'L' && y == 'T')\n ty[1]++;\n if (x == 'R' && y == 'T')\n ty[2]++;\n}\ninline void pre()\n{\n For(i, 1, nn)\n {\n scanf(\"%s%s%d%d\", rea[i].p, rea[i].s, &rea[i].x, &rea[i].y);\n into(rea[i].p[0], rea[i].s[0]);\n }\n if (ty[5] && ty[6])\n fail();\n if (ty[6])\n {\n For(i, 1, nn) rea[i].fan();\n swap(n, m);\n flag = 1;\n }\n memset(ty, 0, sizeof(ty));\n For(i, 1, nn)\n {\n char p = rea[i].p[0], s = rea[i].s[0];\n int x = rea[i].x, y = rea[i].y;\n gai(p, x);\n gai(s, y);\n dui[x] = y;\n dui[y] = x;\n into(p, s);\n }\n {\n bian = min(min(ty[1], ty[2]), min(ty[3], ty[4]));\n D = m - bian * 2;\n shu = n - bian * 2;\n Ge = __gcd(D, shu);\n if (Ge)\n len = (shu + D) / Ge;\n if (ty[1] > bian)\n xi = -shu;\n else\n xi = shu;\n int O = xi > 0 ? 1 : D;\n wei = O;\n For(i, 1, len)\n {\n int A = O + xi;\n if (A > 0 && A <= D)\n {\n if (O > 0 && A <= D)\n biao[i] = 5;\n if (O < 1)\n biao[i] = 3;\n if (O > D)\n biao[i] = 4;\n O = A;\n }\n else if (A < 1)\n {\n biao[i] = 1;\n O += D;\n }\n else\n {\n biao[i] = 2;\n O -= D;\n }\n }\n for (i = 2, j = 0; i <= len; i++)\n {\n for (; j && biao[j + 1] != biao[i]; j = f[j])\n ;\n if (biao[j + 1] == biao[i])\n j++;\n f[i] = j;\n }\n }\n}\ninline int shi(int x)\n{\n return x > nn ? x - nn : x;\n}\ninline int rev(int x)\n{\n return x <= nn ? x + nn : x - nn;\n}\ninline void jing(int x, int y)\n{\n if (x > y)\n swap(x, y);\n if (x <= n && y <= nn)\n a[++t] = (ww){x, y, 1};\n if (x > n && x <= nn && y > nn && y <= nn + n)\n a[++t] = (ww){x, y, 2};\n if (x <= n && y > nn + n)\n a[++t] = (ww){x, y, 3};\n if (x > nn && x <= nn + n && y > nn + n)\n a[++t] = (ww){x, y, 4};\n if (x > n && x <= nn && y > nn + n)\n a[++t] = (ww){x, y, 5};\n}\ninline void jia(int x)\n{\n if (x <= n)\n X = min(X, x);\n if (x > n && x <= nn)\n Y = min(Y, x);\n}\nvoid dfs(int x)\n{\n if (F[shi(x)])\n return;\n int A = dui[x], B = rev(A);\n jing(x, A);\n F[shi(x)] = 1;\n jia(x), jia(A);\n dfs(B);\n}\nvoid Dfs(int x, int y, int z)\n{\n if (z > len)\n return;\n int O = x + xi;\n if (O > 0 && O <= D)\n {\n if (x > 0 && x <= D)\n any[x + bian] = a[y].x - n;\n else if (x < 1)\n anx[1 - x + bian] = a[y].x;\n else\n anx[x - D + bian] = a[y].x - nn;\n x = O;\n }\n else if (O < 1)\n {\n any[x + bian] = a[y].y - n;\n x += D;\n }\n else\n {\n any[x + bian] = a[y].x - n;\n x -= D;\n }\n Dfs(x, y + 1, z + 1);\n}\ninline void work(int ff)\n{\n int s[10] = {}, i, j;\n For(i, 1, t)\n {\n ww A = a[i];\n s[A.ty]++;\n a[i + t] = a[i];\n b[i] = b[i + t] = A.ty;\n }\n if (s[1] && s[2] && s[3] && s[4])\n {\n if (max(max(s[1], s[2]), max(s[3], s[4])) > 1 || s[5])\n fail();\n int wa = 0;\n For(i, 1, t)\n {\n if (a[i].ty == 1)\n wa += (X != a[i].x) + (Y != a[i].y);\n if (a[i].ty == 4)\n wa += (X + nn == a[i].x) + (Y + nn == a[i].y);\n }\n if (wa & 1)\n fail();\n For(i, 1, t)\n {\n if (a[i].ty == 1)\n anx[num4 + 1] = a[i].x, any[num4 + 1] = a[i].y - n;\n if (a[i].ty == 2)\n any[m - num4] = a[i].x - n;\n if (a[i].ty == 3)\n anx[n - num4] = a[i].x;\n }\n num4++;\n if (num4 > bian)\n fail();\n return;\n }\n if (t != len)\n fail();\n j = 0;\n For(i, 1, t * 2)\n {\n for (; j && b[i] != biao[j + 1]; j = f[j])\n ;\n if (biao[j + 1] == b[i])\n j++;\n if (j == len)\n break;\n }\n if (i > t * 2)\n {\n if (ff)\n fail();\n reverse(a + 1, a + t + 1);\n work(1);\n return;\n }\n sum++;\n if (sum > Ge)\n fail();\n i = i - len + 1;\n Dfs(wei, i, 1);\n if (xi > 1)\n wei++;\n else\n wei--;\n}\nint main()\n{\n scanf(\"%d%d\", &n, &m);\n nn = n + m;\n pre();\n For(i, 1, nn) if (!F[i])\n {\n t = 0;\n X = Y = N;\n dfs(i);\n work(0);\n }\n print();\n return 0;\n}", "src_uid": "2ecce827acf880fd6b7692a4a3dffdf5"} {"source_code": "#include \n#include \n\nusing namespace std;\n\ntypedef int ll;\ntypedef long double ld;\n\n#define rep(i,a,b) for(ll i=a;i<=b;++i)\n#define rev(i,a,b) for(ll i=a;i>=b;i--)\n#define pll pair\n#define vll vector\n#define sll set\n#define vpll vector\n#define F first\n#define S second\n#define pb push_back\n#define mp make_pair\n#define ln length()\n#define M 1000000007\n\nll n,w,tpos,tneg;\nlong long ans;\npll pos[100005],neg[100005];\npair p[100005];\npll px[100005];\nll loc[100005],nx[100005],pr[100005];\n\n\nstruct element{\n vector > arr;\n vector bit;\n ll sz;\n}tree[1000005];\n\nll mycmp2(pair p1,pair p2,ll ty){\n ll num1=p1.S;\n ll num2=p2.S;\n if(num1*1LL*p2.F > num2*1LL*p1.F) return -1;\n if(num1*1LL*p2.F == num2*1LL*p1.F) return 0;\n return 1;\n}\n\nvoid _merge(ll node,ll ty){\n ll left = node * 2;\n ll right = node * 2 + 1;\n ll i = 0, j = 0, c = 0;\n ll lSize = tree[left].sz;\n ll rSize = tree[right].sz;\n ll newSize = lSize + rSize;\n tree[node].sz = newSize;\n tree[node].arr.resize(newSize);\n tree[node].bit.clear();\n tree[node].bit.resize(newSize+1);\n\n while(i < lSize && j < rSize){\n if(mycmp2(tree[left].arr[i],tree[right].arr[j],ty) < 0){\n tree[node].arr[c] = tree[left].arr[i];\n i++;\n }else{\n tree[node].arr[c] = tree[right].arr[j];\n j++;\n }\n c++;\n }\n\n while(i < lSize)\n tree[node].arr[c++] = tree[left].arr[i++];\n\n while(j < rSize)\n tree[node].arr[c++] = tree[right].arr[j++];\n\n}\n\n\nvoid initialize(ll ty,ll node, ll st, ll en){\n if(st == en){\n tree[node].arr.resize(1);\n if(ty == 1){\n tree[node].arr[0] = mp(w+p[st].F.S,p[st].F.F);\n }\n else tree[node].arr[0] = mp(w-p[st].F.S,p[st].F.F);\n tree[node].bit.clear();\n tree[node].bit.resize(1+1);\n tree[node].sz = 1;\n }else{\n ll mid = (st+en)/2;\n initialize(ty,node * 2, st, mid);\n initialize(ty,node * 2 + 1, mid + 1 , en);\n _merge(node,ty);\n }\n}\npair create(ll ty,ll which){\n if(ty == 1) return mp(w+p[which].F.S,p[which].F.F);\n return mp(w-p[which].F.S,p[which].F.F);\n}\npair reve(ll ty,pll p1){\n if(ty == 1) return mp(p1.S,p1.F-w);\n return mp(p1.S,w-p1.F);\n}\ninline void bit_update(ll node, ll ps){\n if(!ps) return;\n for(ll i=ps;i<=tree[node].arr.size();i+=(i&(-i))) tree[node].bit[i]++;\n return;\n}\ninline ll bit_query(ll node,ll ps){\n ll ret=0;\n for(ll i=ps;i;i-=(i&(-i))) ret+=tree[node].bit[i];\n return ret;\n}\nvoid update(ll ty,ll node, ll st,ll en, ll which) {\n if(st == en){\n bit_update(node,1);\n return;\n }\n ll mid=(st+en)/2;\n if(which <= mid) update(ty,2*node,st,mid,which);\n else update(ty,2*node+1,mid+1,en,which);\n\n ll lo=0,hi=tree[node].arr.size()-1,req=-1;\n while(lo <= hi){\n mid=(lo+hi)/2;\n ll cmpval=mycmp2(tree[node].arr[mid],create(ty,which),ty);\n if(cmpval == -1) lo=mid+1;\n else if(cmpval == 0){\n req=mid;\n hi=mid-1;\n }\n else hi=mid-1;\n }\n assert(req!=-1);\n bit_update(node,req+1);\n}\n\nll query(ll ty,ll node, ll st, ll en,ll l,ll r,ll which) {\n if(l > en || r < st || l > r)\n return 0;\n if(l <= st && r >= en){\n ll lo=0,hi=tree[node].arr.size()-1,mid,req=-1;\n while(lo <= hi){\n mid=(lo+hi)/2;\n ll cmpval=mycmp2(tree[node].arr[mid],create(ty,which),ty);\n if(cmpval == -1) {\n req=mid;\n lo=mid+1;\n }\n else if(cmpval == 0){\n req=mid;\n lo=mid+1;\n }\n else hi=mid-1;\n }\n /*rep(j,1,req+1){\n if(bit_query(node,j)-bit_query(node,j-1)){\n cout< p1,pair p2){\n if(p2.F.F*1LL*p1.F.S != p1.F.F*1LL*p2.F.S) return p2.F.F*1LL*p1.F.S < p1.F.F*1LL*p2.F.S;\n return p1.S < p2.S;\n}\nll mycmp(ll i,ll en){\n if(p[en].F.F*1LL*p[i].F.S == p[i].F.F*1LL*p[en].F.S) return 0;\n if(p[en].F.F*1LL*p[i].F.S > p[i].F.F*1LL*p[en].F.S) return 1;\n return -1;\n}\nvoid solve(){\n sort(p+1,p+n+1,cmp);\n rep(i,1,n){\n ll en=i;\n while(en <= n && mycmp(i,en) == 0) en++;\n en--;\n /*rep(j,i,en) cout<=1 && px[st].F == px[i].F) st--;\n st++;\n\n rep(j,st,i) {\n if(ty==1) {\n ans+=query(ty,1,1,n,nx[loc[j]],n,loc[j]);\n }\n else {\n ans+=query(ty,1,1,n,1,pr[loc[j]],loc[j]);\n }\n }\n rep(j,st,i) {\n update(ty,1,1,n,loc[j]);\n }\n i=st;\n }\n }\n\n\n /*rep(i,1,n) rep(j,i+1,n){\n if(px[i].F == px[j].F) continue;\n ll num=abs(px[i].S*px[j].F-px[j].S*px[i].F);\n if(num <= w*(px[j].F-px[i].F)){\n cout<<\"HEY matching \"< cross[100005];\nbool cmp3(pll p1,pll p2){\n ll num1=p1.S-w,den1=p1.F;\n ll num2=p2.S-w,den2=p2.F;\n if (num1*1LL*den2 != num2*1LL*den1) return num1*1LL*den2 <= num2*1LL*den1;\n return den1 < den2;\n}\nll BIT[100005];\ninline void b_update(ll ps){\n if(!ps) return;\n for(ll i=ps;i<=n;i+=(i&(-i))) BIT[i]++;\n return;\n}\ninline ll b_query(ll ps){\n ll ret=0;\n for(ll i=ps;i;i-=(i&(-i))) ret+=BIT[i];\n return ret;\n}\nint main()\n{\n //freopen(\"D.in\", \"r\", stdin);\n ios::sync_with_stdio(false);cin.tie(0);\n cin>>n>>w;\n rep(i,1,n){\n ll xi,vi;cin>>xi>>vi;\n if(xi < 0) neg[++tneg]=mp(-xi,vi);\n else pos[++tpos]=mp(xi,-vi);\n }\n sort(pos+1,pos+tpos+1);\n sort(neg+1,neg+tneg+1);\n\n rep(i,1,tpos) {\n p[i]=mp(pos[i],i);\n px[i]=pos[i];\n }\n n=tpos;\n if(n) solve();\n\n\n rep(i,1,tneg) {\n p[i]=mp(neg[i],i);\n px[i]=neg[i];\n }\n n=tneg;\n if(n) solve();\n\n\n\n rep(i,1,tpos) cross[i]=mp(pos[i],i);\n rep(i,1,tneg) cross[i+tpos]=mp(neg[i],i+tpos);\n n=tpos+tneg;\n sort(cross+1,cross+n+1,cmp);\n\n rep(i,1,n){\n ll en=i;\n while(en <= n && cross[i].F.F*1LL*cross[en].F.S==cross[i].F.S*1LL*cross[en].F.F) en++;\n en--;\n ll ct1=en-i+1,ct2=0;\n rep(j,i,en) if(cross[j].S > tpos) ct1--,ct2++;\n ans+=ct1*1LL*ct2;\n /*rep(j,i,en) rep(j1,j+1,en) {\n if((cross[j].S <= tpos && cross[j1].S > tpos )||(cross[j].S > tpos && cross[j1].S <= tpos)) {\n cout<<\" cross eq \"< tpos) {\n ll lo=1,hi=tpos,mid,req=0;\n while(lo <= hi){\n mid=(lo+hi)/2;\n long long cval=(w+cross[i].F.S)*1LL*pos[mid].F - (pos[mid].S-w)*1LL*cross[i].F.F;\n if(cval > 0) {\n req=mid;lo=mid+1;\n }\n else if(cval == 0){\n req=mid;\n lo=mid+1;\n }\n else hi=mid-1;\n }\n /*rep(j,1,req){\n if(b_query(j)-b_query(j-1)){\n cout<<\"neg to pos \"< 0) {\n lo=mid+1;\n }\n else if(cval == 0){\n req=mid;\n hi=mid-1;\n }\n else hi=mid-1;\n }\n assert(req>0);\n b_update(req);\n }\n }\n\n\n rep(i,1,n) BIT[i]=0;\n rep(i,1,tpos) cross[i]=mp(pos[i],i+tneg);\n rep(i,1,tneg) cross[i+tpos]=mp(neg[i],i);\n n=tpos+tneg;\n sort(cross+1,cross+n+1,cmp);\n sort(neg+1,neg+tneg+1,cmp3);\n rev(i,n,1){\n if(cross[i].S > tneg) {\n ll lo=1,hi=tneg,mid,req=0;\n while(lo <= hi){\n mid=(lo+hi)/2;\n long long cval=(w+cross[i].F.S)*1LL*neg[mid].F - (neg[mid].S-w)*1LL*cross[i].F.F;\n if(cval > 0) {\n req=mid;lo=mid+1;\n }\n else if(cval == 0){\n req=mid;\n lo=mid+1;\n }\n else hi=mid-1;\n }\n ans+=b_query(req);\n /*rep(j,1,req){\n if(b_query(j)-b_query(j-1)){\n cout<<\"pos to neg \"< 0) {\n lo=mid+1;\n }\n else if(cval == 0){\n req=mid;\n hi=mid-1;\n }\n else hi=mid-1;\n }\n assert(req>0);\n b_update(req);\n }\n }\n /*rep(i,1,tpos) rep(j,1,tneg) {\n ll num=abs(pos[i].S*neg[j].F-neg[j].S*pos[i].F);\n if(num <= w*(neg[j].F+pos[i].F)){\n cout<<\"HEY BRUTE matching \"<\n#define MAXN 1000005\n#define MOD 1000000007\n//思路:线段树优化dp\nusing namespace std;\ninline int read(){\n int x=0,f=1;\n 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<<3)+(x<<1)+(ch^'0');\n ch=getchar();\n }\n return x*f;\n}\nnamespace SegmentTree{\n struct node{\n int l,r;\n int val;\n bool tag;\n }tree[MAXN<<2];\n #define lc i<<1\n #define rc i<<1|1\n inline void pushup(const int &i){\n tree[i].val=(tree[lc].val+tree[rc].val)%MOD;\n }\n inline void Change(const int &i,const int &rt){\n tree[i].val=0;\n tree[i].tag=true;\n }\n inline void pushdown(const int &i){\n if (tree[i].tag){\n Change(lc,i),Change(rc,i);\n tree[i].tag=false;\n }\n }\n void Build(const int &l,const int &r,const int &i){\n tree[i].l=l,tree[i].r=r;\n tree[i].tag=0,tree[i].val=0;\n if(l==r){return ;}\n int mid=(l+r)>>1;\n Build(l,mid,lc);\n Build(mid+1,r,rc);\n }\n void Cover(const int &i,const int &L,const int &R){\n if (L<=tree[i].l&&tree[i].r<=R){\n tree[i].tag=true;\n tree[i].val=0;\n return ;\n }\n pushdown(i);\n int mid=(tree[i].l+tree[i].r)>>1;\n if (L<=mid) Cover(lc,L,R);\n if (mid>1;\n if (index<=mid) Update(lc,index,val);\n else Update(rc,index,val);\n pushup(i);\n }\n int Query(const int &i,const int &L,const int &R){\n if (L>R) return 0;\n // printf(\"%d %d %d\\n\",i,L,R);\n if (L<=tree[i].l&&tree[i].r<=R){\n return tree[i].val;\n }\n pushdown(i);\n int mid=(tree[i].l+tree[i].r)>>1,ans=0;\n if (L<=mid) ans=(ans+Query(lc,L,R))%MOD;\n if (midB.y2;\n }\n else {\n return A.y1>B.y1;\n }\n }\n}\n#define pii pair \n#define l first\n#define r second\n#define mp make_pair\nsetnow;//现在扫描到的竖线中的线段\nsgmt s[MAXN*2];int tot;//全部的竖线\ninline void Add(sgmt A){s[++tot]=A;}\nint main(){\n int n=read(),m=read(),k=read();\n for (register int i=1;i<=k;++i){\n int x1=read(),y1=read(),x2=read(),y2=read();\n Add(sgmt{x1,y1,y2,0});\n Add(sgmt{x2+1,y1,y2,1});\n }\n Build(1,m,1);\n Update(1,1,1);\n sort(s+1,s+1+tot);\n int p=1;\n for (p=1;s[p].x==1;++p){\n if (!s[p].flag){\n now.insert(mp(s[p].y1,s[p].y2));\n }\n }\n now.insert(mp(0,0));\n for (register int i=2;i<=n;++i){\n for (register int j=p;s[j].x==i;++j){//二分得到low 线段树区间加,维护DP\n int pos=s[j].y2+1;\n if (s[j].flag==0&&pos<=m){\n //s[j].y2+1<=m不加会RE\n int low=(*--now.lower_bound(mp(pos+1,0))).r;\n Update(1,pos,Query(1,low+1,pos));//玄学边界\n }\n }\n //下面都是维护now集合,删去移动区间导致消失的线段,加上新的线段\n //这两个顺序不能换(先下后上的原理)\n for (register int j=p;s[j].x==i;++j){//减去消失的线段\n if (s[j].flag){\n now.erase(mp(s[j].y1,s[j].y2));\n }\n }\n for (register int j=p;s[j].x==i;++j,++p){\n if (!s[j].flag){\n now.insert(mp(s[j].y1,s[j].y2));\n Cover(1,s[j].y1,s[j].y2);//顺便把有障碍物的区间设成0\n }\n }\n \n //至于F[i][j]=F[i-1][j]不要管,因为区间从左到右移动,直接继承上一个区间的F[i][j]\n }\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#define LL long long\nusing namespace std;\nconst LL pri=1000000007LL;\nLL a[7][7]={{0,0,1,1,1,0,0},{0,0,1,1,0,1,0},{1,1,0,0,0,0,0},{0,0,0,0,0,0,0},{1,0,0,0,0,0,0},{0,1,0,0,0,0,0},{1,1,1,1,1,1,1}},\ni[7][7]={{1,0,0,0,0,0,0},{0,1,0,0,0,0,0},{0,0,1,0,0,0,0},{0,0,0,1,0,0,0},{0,0,0,0,1,0,0},{0,0,0,0,0,1,0},{0,0,0,0,0,0,1}},\nans[7][7],c[7][7];\nvoid cheng(LL a[7][7])\n{\n memset(c,0,sizeof(c));\n for(int i=0;i<7;i++)\n for(int j=0;j<7;j++)\n for(int k=0;k<7;k++)\n c[i][j]=(c[i][j]+ans[i][k]*a[k][j]%pri)%pri;\n memcpy(ans,c,sizeof(c));\n}\nvoid ksm(LL y)\n{\n if(y==0)\n {\n memcpy(ans,i,sizeof(i));\n return ;\n }\n ksm(y/2);\n cheng(ans);\n if(y&1)\n cheng(a);\n}\nLL work(LL l)\n{\n ksm(l);\n LL T=(ans[6][0]+ans[6][1]+ans[6][2]+ans[6][3])%pri;\n ksm((l+1)/2);\n T=(T+ans[6][0]+ans[6][1]+ans[6][2]+ans[6][3])%pri;\n T=T*500000004LL%pri;\n return T;\n}\nint main()\n{\n LL L,R;\n scanf(\"%I64d%I64d\",&L,&R);\n printf(\"%I64d\\n\",(work(R)-work(L-1)+pri)%pri);\n return 0;\n}\n \t \t\t \t \t \t\t", "src_uid": "e04b6957d9c1659e9d2460410cb57f10"} {"source_code": "#include \n \nusing namespace std;\n \nint n, m;\nchar arr[1001][1001];\nchar res[1001][1001];\nstring sig[3] = {\"###\", \"#.#\", \"###\"};\n \nvoid write(int x, int y)\n{\n for (int i = 0; i < 3; i++)\n for (int j = 0; j < 3; j++)\n if (arr[x+i][y+j] != sig[i][j] && arr[x+i][y+j] == '.') return;\n for (int i = 0; i < 3; i++)\n for (int j = 0; j < 3; j++)\n if (res[x+i][y+j] == '.' && sig[i][j] == '#')\n res[x+i][y+j] = '#';\n}\n \nint main()\n{\n cin >> n >> m;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n cin >> arr[i][j], res[i][j] = '.';\n for (int i = 0; i < n-2; i++)\n for (int j = 0; j < m-2; j++)\n write(i, j);\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n if (res[i][j] != arr[i][j])\n return !printf(\"NO\");\n cout << \"YES\";\n}", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"} {"source_code": "#include \n#include \n#include \nusing namespace std;\n#define N 1234\nint n, m, s, t, c;\nchar str[N];\nvoid solve() {\n\tint i;\n\tbool flag = true;\n\tbool way = 0;\n\tfor (i = 0; i < n; i++) {\n\t\tif (str[i] != '?' && str[i] == str[i + 1]) {\n\t\t\tflag = false;\n\t\t\tbreak;\n\t\t}\n\t\tif (str[i] == '?') {\n\t\t\tif (i - 1 < 0 || str[i - 1] == '?') {\n\t\t\t\tway = 1;\n\t\t\t}\n\t\t\telse if (i + 1 >= n || str[i + 1] == '?') {\n\t\t\t\tway = 1;\n\t\t\t}\n\t\t\telse if (str[i - 1] == str[i + 1]) {\n\t\t\t\tway = 1;\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"%s\\n\", flag && way ? \"Yes\" : \"No\");\n}\nint main() {\n\twhile (scanf(\"%d %s\", &n, &str) != EOF) {\n\t\tsolve();\n\t}\n\treturn 0;\n}", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"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 ll long long int\n#define usll unsigned long long int\n#define endln \"\\n\"\n#define MAXX 1000007\n#define PI M_PI;\n#define MX 10002\n#define sps setprecision\n#define goodluck_code() main()\n#define TSUNAMI ios_base::sync_with_stdio(false); cin.tie(NULL);\n#define debug(a) cout << (#a) << \" = \" << a << \"\\n\";\n#define _Open_Minded_Short_Code_ return 0;\nusing namespace std;\nstack st , st2;\nmap mp;\nvector ve;\ngoodluck_code(){\n TSUNAMI\n ll a , b;\n cin >> a >> b;\n st.push(a);\n int i = 0;\n while(st.top() != b){\n ll x = st.top();\n if(mp[x] == 0){\n mp[x]++;\n// debug(st.top());\n st2.push(x);\n if(x * 10 + 1 <= b ){\n st.push(x * 10 + 1);\n }\n if(x * 2 <= b){\n st.push(x * 2);\n }\n }else{\n st.pop();\n st2.pop();\n }\n if(st.size() == 0){\n break;\n }\n }\n if(st2.size() == 0){\n cout<<\"NO\"<\nusing namespace std;\n\nint N,a[55][55][55],b[55][55][55];\n\nvoid go(int x,int y,int z,int dx,int dy,int dz,int p,int n,int m,int sp,int dp)\n{\n\tfor (int i=1; i<=n; i++)\n\t\tfor (int j=1; j<=m; j++)\n\t\t{\n\t\t\ta[x][y][z]=sp,sp+=dp;\n\t\t\tif (j\n//#include \n//#include \n//#include \n//6845684646\n//#include \n//#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 chushihua(x) memset(x,0,sizeof x)\n//using namespace std;\n//ll a[16];\n//void random(ll a[], ll n)\n//{\n//\tll index, tmp, i;\n//\tsrand(time(NULL));\n//\tfor (i = 0; i < n; i++)\n//\t{\n//\t\tindex = rand() % (n - i) + i;\n//\t\tif (index != i)\n//\t\t{\n//\t\t\ttmp = a[i];\n//\t\t\ta[i] = a[index];\n//\t\t\ta[index] = tmp;\n//\t\t}\n//\t}\n//}\n//ll gcd(ll a, ll b) {\n//\treturn a % b ? gcd(b, a%b) : b;\n//}\n//int main() {\n//\tint n;\n//\twhile (cin >> n) {\n//\t\tn = n * 2;\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tscanf(\"%d\", &a[i]);\n//\t\t}\n//\t\t//for (int i = 0; i < n; i++) {\n//\t\t//\tprintf(\"%d \", a[i]);\n//\t\t//}\n//\t\tif (n == 2) {\n//\t\t\tcout << a[0] + a[1] << endl;\n//\t\t}\n//\t\telse {\n//\t\t\tll sum = 0;\n//\t\t\tfor (ll i = 0; i < 10000; i++) {\n//\t\t\t\trandom(a, n);\n//\t\t\t\tll x = a[0] + a[1];\n//\t\t\t\tll y = a[2] + a[3];\n//\t\t\t\tsum = max(sum, gcd(x, y));\n//\t\t\t}\n//\t\t\tcout << sum << endl;\n//\t\t}\n//\t}\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 ll long long\n#define chushihua(x) memset(x,0,sizeof x)\nusing namespace std;\nint main() {\n\tint n, k;\n\tcin >> n >> k;\n\tint a[100 + 10];\n\tint e = 0, s = 0;\n\tfor (int i = 1; i <= n; i++) {\n\t\tscanf(\"%d\", &a[i]);\n\t\tif (a[i] == 1) {\n\t\t\te++;\n\t\t}\n\t\telse {\n\t\t\ts++;\n\t\t}\n\t}\n\t//cout << e << \" \" << s << endl;\n\tint E = e, S = s;\n\tint sum = 0;\n\tfor (int i = 1; i <= k; i++) {\n\t\te = E, s = S;\n\t\tfor (int j = i; j <= n; j+=k) {\n\t\t\tif (a[j] == 1) {\n\t\t\t\te--;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ts--;\n\t\t\t}\n\t\t}\n\t\t//cout << sum << endl;\n\t\tsum = max(sum, abs(e - s));\n\t}\n\tcout << sum << endl;\n\treturn 0;\n}", "src_uid": "6119258322e06fa6146e592c63313df3"} {"source_code": "// rc.cpp\n//\n\n#include \n#include \n\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 char uchar;\ntypedef unsigned int uint;\ntypedef unsigned __int64 uint64;\n\n#define PI 3.1415926535897932384626433832795\n#define EPS 1E-8\n\nuint kb[100],\n\t nkb,\n\t v[100],\n\t nv;\nint main(int argc, char* argv[])\n{\n\tuint s, k;\n\tcin >> s >> k;\n\n\tuint q = 1,\n\t\t c = 0;\n\tkb[nkb++] = 1;\n\twhile (q <= s)\n\t{\n\t\tkb[nkb++] = q;\n\t\tif (nkb > k)\n\t\t\tq += q - kb[nkb - k - 1];\n\t\telse\n\t\t\tq *= 2;\n\t}\n\n\t--nkb;\n\twhile (s)\n\t{\n\t\twhile (s < kb[nkb])\n\t\t\t--nkb;\n\t\ts -= kb[nkb];\n\t\tv[nv++] = kb[nkb--];\n\t}\n\n\tif (nv == 1)\n\t\t++nv;\n\n\tcout << nv << endl;\n\tcout << v[0];\n\tfor (uint i = 1; i < nv; ++i)\n\t\tcout << \" \" << v[i];\n\tcout << endl;\n\n\treturn 0;\n}\n", "src_uid": "da793333b977ed179fdba900aa604b52"} {"source_code": "#include\r\nusing namespace std;\r\nint n;\r\nint ans[46]={0,1,2,3,4,5,6,7,8,9,19,29,39,49,59,69,79,89,189,289,389,489,589,689,789,1789,2789,3789,4789,5789,6789,16789,26789,36789,46789,56789,156789,256789,356789,456789,1456789,2456789,3456789,13456789,23456789,123456789};\r\nvoid solve(){\r\n\tcin>>n;\r\n\tcout<>t;\r\n\twhile(t--){\r\n\t\tsolve();\r\n\t}\r\n\treturn 0;\r\n}\r\n", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"source_code": "//#define MYDEBUG\n#define _CRT_SECURE_NO_WARNINGS\n#pragma comment(linker, \"/STACK:134217728\")\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nconst long long MOD = 1000000007;\nconst long long INF = 2000000001;\nconst double EPS = 1e-5;\nconst int HASH_POW = 13;\nconst double PI = acos(-1.0);\n\nusing namespace std;\n\nvoid my_return(int code)\n{\n\t#ifdef MYDEBUG\n\t\tcout << \"\\nTime = \" << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;\n\t#endif\n\texit(code);\n}\n\nint main()\n{\n\t//cin.sync_with_stdio(0);\n\t#ifdef MYDEBUG\n\tfreopen(\"input.txt\", \"rt\", stdin);\n\tfreopen(\"output.txt\", \"wt\", stdout);\n\t#else\n\t//freopen(\"pentagon.in\", \"rt\", stdin);\n\t//freopen(\"pentagon.out\", \"wt\", stdout);\n\t#endif\n\n\tint h1, a1, d1, h2, a2, d2, h, a, d;\n\tscanf(\"%d %d %d\\n%d %d %d\\n%d %d %d\", &h1, &a1, &d1, &h2, &a2, &d2, &h, &a, &d);\n\tint ans = 1000000000;\n\tfor (int i = h1; i <= 5000; ++i)\n\t{\n\t\tfor (int j = a1; j <= 210; ++j)\n\t\t{\n\t\t\tfor (int k = d1; k <= 100; ++k)\n\t\t\t{\n\t\t\t\tint cost = h*(i - h1) + a*(j - a1) + d*(k - d1);\n\t\t\t\tif (j > d2)\n\t\t\t\t{\n\t\t\t\t\tint t = (h2 + j - d2 - 1)/(j - d2);\n\t\t\t\t\tif (i - t*(a2 - k) > 0)\n\t\t\t\t\t\tans = min(ans, cost);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"%d\\n\", ans);\n\n\tmy_return(0);\n}", "src_uid": "bf8a133154745e64a547de6f31ddc884"} {"source_code": "#include \nusing namespace std;\n\nint main()\n{ \n long long int n,a,b,c;\n cin>>n>>a>>b>>c;\n long long int rem=n%4;\n //cout<a+b&&a+b<3*a)cout<3*a&&a+b>3*a)cout<<3*a;\n else cout<\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 int N=31,S=64;\nint k;\nconst int mod=1e9+7;\nstruct M{\n\tint a[N][N];\n\tinline M operator * (const M &b) const {\n\t\tM ans={};\n\t\tfor (int i=0;i<=k;i++)\n\t\t\tfor (int j=0;j<=k;j++)\n\t\t\t\tfor (int t=0;t<=k;t++)\n\t\t\t\t\tans.a[i][j]=(ans.a[i][j]+1LL*a[i][t]*b.a[t][j])%mod;\n\t\treturn ans;\n\t}\n}f[S][N],pre[N],suf[N];\nint main()\n{\n#ifndef ONLINE_JUDGE\n\tfreopen(\"cf497e.in\",\"r\",stdin);\n\tfreopen(\"cf497e.out\",\"w\",stdout);\n#endif\n\tLL n;int num[S],len=0,i,j,s;M ans={};\n\tcin>>n>>k;ans.a[0][k]=1;\n\twhile (n) num[len++]=n%k,n/=k;\n\t\n\tfor (i=0;i\nusing namespace std;\n \n#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n#define endl \"\\n\"\n\nconst int N=6e5+5;\nconst int offset=3e5;\nconst int MOD=1e9+7;\n\nint a, b, k, t;\nint dp[2][102][N];\n\nint32_t main()\n{\n IOS;\n cin>>a>>b>>k>>t;\n for(int player=0;player<=1;player++)\n {\n for(int diff=-offset;diff<=offset;diff++)\n {\n dp[player][t+1][diff+offset]=(diff>0);\n dp[player][t+1][diff+offset]+=dp[player][t+1][diff+offset-1];\n dp[player][t+1][diff+offset]%=MOD;\n }\n } \n for(int turn=t;turn>=1;turn--)\n {\n for(int diff=-offset;diff<=offset;diff++)\n {\n int player=1;\n int &ans=dp[player][turn][diff+offset];\n ans=dp[player^1][turn+1][diff+k+offset] - dp[player^1][turn+1][diff-k-1+offset];\n ans+=MOD;\n ans%=MOD;\n ans+=dp[player][turn][diff-1+offset];\n ans%=MOD;\n }\n for(int diff=-offset;diff<=offset;diff++)\n {\n int player=0;\n int &ans=dp[player][turn][diff+offset];\n ans=dp[player^1][turn][diff+k+offset] - dp[player^1][turn][diff-k-1+offset];\n ans+=MOD;\n ans%=MOD;\n ans+=dp[player][turn][diff-1+offset];\n ans%=MOD;\n }\n }\n int ans=dp[0][1][a-b+offset]-dp[0][1][a-b-1+offset];\n ans+=MOD;\n ans%=MOD;\n cout<\nusing namespace std;\n\n/*\ncase 1 是否存在s使得f(s) = f(~s) = 0 -> 1\ncase 2 是否存在s使得f(s) = f(~s) = 1 -> 2\ncase 3 是否存在s使得f(s) ̸= f(~s) -> 4\n */\n\nbool case1(int x){\n return x & 1;\n}\nbool case2(int x){\n return x & 2;\n}\nbool case3(int x){\n return x & 4;\n}\nint parse(){\n char ch;\n if ((ch = getchar()) == '('){\n // cout<>n;\n getchar();\n cout << (case3(parse()) ? \"YES\" : \"NO\") << endl;\n}", "src_uid": "e060d26dc3b9ffb628f2380781d1cbe9"} {"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;\ntypedef long long ll;\n\nconst int MN = 100100;\nconst double EPS = 1e-9;\ntypedef pair P;\ntypedef pair Q;\n\nvector

v;\n\nnumber calc(number x,number y){\n\tnumber ret=-1.0;\n\tREP(i,n)ret=max(ret,(xx[i]-x)*(xx[i]-x)+(yy[i]-y)*(yy[i]-y));\n//\tcout<EPS){\n//\t\tcout< rRight)\n\t\t\tleft=leftThird;\n\t\telse\n\t\t\tright=rightThird;\n\t}\n//\tcout<EPS){\n//\t\t\t\tcout<rRight)\n\t\t\tleft=leftThird;\n\t\telse\n\t\t\tright=rightThird;\n\t}\n\tnumber x=(left+right)*0.5;\n\tnumber y=ternaryY(x);\n\treturn calc(x,y);\n}\n//}}}\n\nconst double phi=(1+sqrt(5))/2;\nconst double resphi=(double)2-phi;\n\n//{{{\ndouble goldenSectionSearchY(const double X){\n\tdouble a=-INF,b=INF, c=(phi*a+b)/(phi+1.0);\n\tdouble fb=calc(X,b);\n\tREP(i,80){\n//\t\tif(abs(c-a)b-a)x=b+resphi*(c-b);\n\t\telse x=b-resphi*(b-a);\n//\t\tcout<b-a)a=b,b=x;\n\t\t\telse c=b,b=x;\n\t\t\tfb=fx;\n\t\t}else{\n\t\t\tif(c-b>b-a)c=x;\n\t\t\telse a=x;\n\t\t}\n\t}\n\treturn (c+a)/2;\n}\n\ndouble goldenSectionSearch(){\n\tdouble a=-INF,b=INF, c=(phi*a+b)/(phi+1.0);\n\tdouble gb=goldenSectionSearchY(b),fb=calc(b,gb);\n\tREP(i,80){\n//\t\tif(abs(c-a)b-a)x=b+resphi*(c-b);\n\t\telse x=b-resphi*(b-a);\n//\t\tcout<b-a)a=b,b=x;\n\t\t\telse c=b,b=x;\n\t\t\tfb=fx;\n\t\t}else{\n\t\t\tif(c-b>b-a)c=x;\n\t\t\telse a=x;\n\t\t}\n\t}\n\tdouble x=(c+a)/2;\n//\tcout< v;\n\tx2=y1*c-z1*b;y2=z1*a-x1*c;z2=x1*b-y1*a;\n\tnumber d1=sqrt(x1*x1+y1*y1+z1*z1),d2=sqrt(x2*x2+y2*y2+z2*z2);\n\tx1/=d1;y1/=d1;z1/=d1;x2/=d2;y2/=d2;z2/=d2;\n\tREP(i,n){\n\t\txx[i]=x1*x[i]+y1*y[i]+z1*z[i];\n\t\tyy[i]=x2*x[i]+y2*y[i]+z2*z[i];\n\t\t//\t\tcout<\r\nusing namespace std;\r\nint T,n,mod,dp[410][410],p2[410],jc[410],c[410][410];\r\nint main(){\r\n\t\tscanf(\"%d%d\",&n,&mod);p2[0]=jc[0]=1;\r\n\t\tc[0][0]=1;\r\n\t\tfor(int i=1;i<=n;i++){\r\n\t\t\tc[i][0]=1;\r\n\t\t\tfor(int j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;\r\n\t\t}\r\n\t\tfor(int i=1;i<=n;i++)p2[i]=p2[i-1]*2%mod,jc[i]=1ll*jc[i-1]*i%mod;\r\n\t\tfor(int i=1;i<=n;i++)dp[i][1]=p2[i-1];\r\n\t\tfor(int j=2;j<=n;j++)for(int i=1;i<=n;i++)\r\n\t\t\tfor(int k=1;k\nusing namespace std;\nint main()\n{\n long long a,b,c,d,t=0,ans1;\n int e,f;\n cin>>a>>b>>c>>d>>e>>f;\n\n int B[3];\n if(e0)\n {\n if(a>t)\n {\n ans2=ans2+t*e;\n }\n else\n {\n ans2=ans2+a*e;\n }\n }\n cout<\n\nusing namespace std;\nint main()\n{\n int s,i,p,q,a,t;\n int b[2];\n \n for(i=0;i<2;i++)\n cin>>b[i];\n p = b[0];\n q = b[1];\n if(p%q==0)\n {\n s = p/q;\n for(i=0;i\n\nusing namespace std ;\nconst int maxn = 111 ;\nint a[maxn] ,vis[maxn];\n\nint main( ) {\n\n int n , ta = 0 , tb = 0 ; scanf( \"%d\" , &n) ;\n for( int i = 0 ; i < n/2 ; i++ ) scanf(\"%d\" , a + i );\n sort( a , a + n/2) ;\n int t = 1 ;\n for( int i = 0 ; i < n/2 ; i++ ) ta +=abs(t - a[i]) ,t+=2 ;\n t = 2 ;\n for( int i = 0 ; i < n/2 ; i++ ) tb +=abs(t - a[i]) ,t+=2 ;\n printf( \"%d\\n\" , min(ta,tb) ) ;\n return 0 ;\n}\n", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"source_code": "#include\n#define pb push_back\n#define PI acos(-1)\n#define all(x) x.begin(), x.end()\n#define debug(x) cerr << #x << \" = \" << x << \"\\n\";\n#define debug_v(x) cerr << #x << \" = \"; for(auto i : x){cerr << \"[\" << i << \"]\" << \" \";} cerr << \"\\n\";\nusing namespace std;\ntypedef long long ll;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef pair pii;\ntypedef vector vii;\nconst int mod = 1000 * 1000 * 1000 + 7;\nconst int inf = 1000 * 1000 * 1000 + 100;\nconst ll inf64 = (ll)1e18 + 100;\nset s;\nmultiset ms;\nvoid prime_factors(ll tiv){\n\twhile(tiv % 2 == 0){\n\t\ts.insert(2);\n\t\tms.insert(2);\n\t\ttiv /= 2;\n\t}\n\tfor(ll i = 3;i * i <= tiv;i++){\n\t\twhile(tiv % i == 0){\n\t\t\ts.insert(i);\n\t\t\tms.insert(i);\n\t\t\ttiv /= i;\n\t\t}\n\t}\n\tif(tiv > 2){\n\t\ts.insert(tiv);\n\t\tms.insert(tiv);\n\t}\n}\nint main(){\n\tios_base::sync_with_stdio(false);\n\tcin.tie(0);\n\tcout.tie(0);\n\tcout << fixed << setprecision(10);\n\tll b, answer = 1;\n\tcin >> b;\n\tif(b == 1){\n\t\tcout << 1 << \"\\n\";\n\t\treturn 0;\n\t}\n\tvector a;\n\tprime_factors(b);\n\tfor(auto x: s){\n\t\tanswer *= ms.count(x) + 1;\n\t}\n\tcout << answer << \"\\n\";\n\treturn 0;\n}\n", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"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\n#define f first\n#define s second\n#define mp make_pair\n#define pb push_back\n#define SZ(v) (int)(v).size()\n#define ALL(v) (v).begin(), (v).end()\n#define FOR(it, v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)\n#define FILE \"\"\n\ntypedef long long LL;\n\nstring s;\nint k;\n\nbool check(int st, int len){\n\tfor (int i = 0; i < len; i++){\n\t\tif (st + i + len >= SZ(s))\n\t\t\treturn true;\n\t\tif (s[st + i] != s[st + i + len])\n\t\t\treturn false;\t\t\n\t}\n\treturn true;\n}\n\nint main(){\n\t#ifndef ONLINE_JUDGE\n\tfreopen(FILE\".in\", \"r\", stdin);\n\t#endif\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\n\tcin >> s;\n\tcin >> k;\n\tfor (int l = (SZ(s) + k) / 2; l >= 1; l--)\n\t\tfor (int i = 0; i <= SZ(s) + k - 2 * l; i++)\n\t\t\tif (check(i, l)){\n\t\t\t\tcout << 2 * l;\n\t\t\t\treturn 0;\n\t\t \t}\n\n\treturn 0;\n} ", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab"} {"source_code": "#include\n#define ll long long\nusing namespace std;\nll n,i,j,ta;\nchar c[1010][1010];\nbool be[999010],b[1010];\nvoid rmt(string zz)\n{\n\t//cout<0)\n\t\tbe[(ll)stoi(zz)]=1;\n\tll ii,jj;\n\tfor(ii=1;ii<=n;ii++)\n\t{\n\t\tfor(jj=1;jj<=6;jj++)\n\t\t{\n\t\t\tif(!b[ii])\n\t\t\t{\n\t\t\t\tb[ii]=1;\n\t\t\t\trmt(zz+char(c[ii][jj]));\n\t\t\t\tb[ii]=0;\n\t\t\t}\n\t\t}\n\t}\n}\nint main()\n{\n\tcin>>n;\n\tfor(i=1;i<=n;i++)\n\t\tfor(j=1;j<=6;j++)\n\t\t{\n\t\t\tcin>>ta;\n\t\t\tc[i][j]=(ta+'0');\n\t\t}\t\n\trmt(\"\");\n\tfor(i=1;i<=15211;i++)\n\t{\n\t\tif(!be[i])\n\t\t{\n\t\t\tcout<\n#include\n#include\n#include\n#include\nusing namespace std;\n\nint main(){\n string str;int i=0;\n vector v;\n cin>>str;\n while(str[i]!='\\0'){\n if(str[i]=='0')\n {\n v.push_back(0);i++;\n }\n else if(str[i]=='.')\n {\n v.push_back(0);i++;\n }\n else if(str[i]=='-'&&str[i+1]=='.')\n {\n v.push_back(1);i=i+2;\n }\n if(str[i]=='-'&&str[i+1]=='-')\n {\n v.push_back(2);i=i+2;\n }\n }\n for(int j=0;j\n using namespace std;\n pair< int, int > arr[110];\n int ans[110];\n int main()\n {\n ios_base::sync_with_stdio(0);\n cin.tie(NULL);\n cout.tie(NULL);\n long long n, m, i;\n cin >> n >> m;\n for(i = 1; i <= n; i++){\n cin >> arr[i].first;\n arr[i].second = i;\n }\n sort(arr + 1, arr + 1 + n);\n for(i = 1; i <= n; i++){\n ans[arr[i].second] = i % 2;\n }\n for(i = 1; i <= n; i++){\n cout << ans[i] << \" \";\n }\n return 0;\n }\n", "src_uid": "692698d4b49ad446984f3a7a631f961d"} {"source_code": "#include \n#include \n#include \n\nint R,C;\nlong long bi[61][61],get[61][61],match[61][61];\nstd::mapmap[22];\nstd::setset[22];\nchar str[61];\nlong long Abs(long long x){return x<0?-x:x;}\nint main(){\n\tscanf(\"%d%d%s\",&R,&C,str+1);\n\tfor(int i=0;i<=(R+C)<<1;i++){\n\t\tbi[i][0]=1;\n\t\tfor(int j=1;j<=i;j++)\n\t\t\tbi[i][j]=bi[i-1][j]+bi[i-1][j-1];\n\t}\n\tfor(int i=1;i<=R+C;i++)\n\t\tfor(int j=0;j<=R+C;j++)\n\t\t\tget[i][j]=bi[i-1][R-1]*bi[j][R];\n\tfor(int i=0,start=(R<<1)+C;i<(1<<(C+1));i++){\n\t\tint u=(R+C)-__builtin_popcount(i);\n\t\tlong long ans=0;\n\t\tbool cando=1;\n\t\tfor(int j=0;jR-1+i||cnt2>R-1)match[i][0]=0;\n\t\telse match[i][0]=bi[i+((R-1)<<1)-cnt1-cnt2][R-1-cnt2];\n\t\tif(cnt1>R-1||cnt2>R-1+i)match[0][i]=0;\n\t\telse match[0][i]=bi[i+((R-1)<<1)-cnt1-cnt2][R-1-cnt1];\n\t}\n\tlong long fin=1e18,Ans=0;\n\tfor(int i=0,start=(R<<1)-1;i<(1<<(C+1));i++){\n\t\tbool same=1,cando=1;\n\t\tint cnt=1;\n\t\tfor(int j=1;jAbs(*now+ans))Ans=0;\n\t\t\tfin=std::min(fin,Abs(*now+ans));\n\t\t\tif(cando&&fin==Abs(*now+ans))Ans+=1ll*map[sum][*now]*((i&1)?match[cnt][0]:match[0][cnt]);\n\t\t}\n\t\tif(now!=set[sum].begin()){\n\t\t\t--now;\n\t\t\tif(fin>Abs(*now+ans))Ans=0;\n\t\t\tfin=std::min(fin,Abs(*now+ans));\n\t\t\tif(cando&&fin==Abs(*now+ans))Ans+=1ll*map[sum][*now]*((i&1)?match[cnt][0]:match[0][cnt]);\n\t\t}\n\t}\n\tprintf(\"%lld\",Ans);\n}", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85"} {"source_code": "#include \n\n#define FOR(i, j, n) for (int i(j); i < n; ++i)\n#define pb push_back\n#define all(c) (c).begin(), (c).end()\n#define dbg(x) std::cerr<<#x<<\" = \" << (x) << std::endl\n#define pnl(x) std::cout << x << \"\\n\"\n\ntypedef\tstd::vector\tvi;\ntypedef std::pair\tii;\ntypedef std::vector\tvs;\ntypedef std::vector\tvii;\ntypedef std::vector\tvl;\ntypedef\tlong long ll;\n\n\nconst int\tNB_D = 4;\nconst int\tDY[] = {-1, 1, 0, 0};\nconst int\tDX[] = {0, 0, -1, 1};\n\nint\t\tmain(void)\n{\n\tstd::ios_base::sync_with_stdio(false);\n\tll\tn,k;\n\tstd::cin >> n >> k;\n\t\n\tif (k >= 43)\n\t{\n\t\tpnl(\"No\");\n\t\treturn 0;\n\t}\n\n\tfor (ll\ti(2); i <= k; ++i)\n\t\tif (n % i != i - 1)\n\t\t{\n\t\t\tpnl(\"No\");\n\t\t\treturn 0;\n\t\t}\n\tpnl(\"Yes\");\n}\n\n", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"source_code": "#include \n#include \n#include \n#include \"math.h\"\nusing namespace std;\n\nint main()\n{\n long long int x,y,m,x1,y1;\n cin>>x>>y>>m;\n unsigned long long int num=0;\n while(1)\n {\n x1=x;\n y1=y;\n if(max(x,y)>=m)\n {\n cout<0&&y<0){\n unsigned long long int n=fabs(y)/x ;\n long long int xx=y;\n while(y<0){\n y=xx+x*n;\n n++;\n }\n num=num+n-1;\n continue;\n }\n\n else if(y>0&&x<0){\n unsigned long long int n=fabs(x)/y ;\n long long int xx=x;\n while(x<0){\n x=xx+y*n;\n n++;\n }\n num=num+n-1;\n continue;\n }\n\n else if(x\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long ll;\nconst ll M=998244353;\nint n,k,len[100005],i,j,l,m;\nll f[65][65][65],g[65][65],ans,h,h2;\nchar c[100005][15];\nmap v[100009];\nint main(){\n\tscanf(\"%d\",&n);\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tscanf(\"%s\",c[i]+1);\n\t\tlen[i]=strlen(c[i]+1);\n\t\th=h2=0;\n\t\tfor(j=len[i];j>=1;j--)\n\t\t{\n\t\t\th=(h*233+c[i][j])%100007;\n\t\t\th2=(h2*233+c[i][j])%M;\n\t\t}\n\t\tif(v[h][h2])\n\t\t{\n\t\t\ti--;\n\t\t\tn--;\n\t\t\tcontinue;\n\t\t}\n\t\th=h2=0;\n\t\tfor(j=1;j<=len[i];j++)\n\t\t{\n\t\t\th=(h*233+c[i][j])%100007;\n\t\t\th2=(h2*233+c[i][j])%M;\n\t\t}\n\t\tif(v[h][h2])\n\t\t{\n\t\t\ti--;\n\t\t\tn--;\n\t\t\tcontinue;\n\t\t}\n\t\tv[h][h2]=1;\n\t}\n\tfor(i=3;i<=10;i++)\n\t{\n\t\tmemset(g,0,sizeof(g));\n\t\tfor(j=1;j<=n;j++)\n\t\t\tif(len[j]==i)\n\t\t\t{\n\t\t\t\tint a,b;\n\t\t\t\tif(c[j][1]>='A'&&c[j][1]<='Z')\n\t\t\t\t\ta=c[j][1]-'A';\n\t\t\t\telse\n\t\t\t\t\tif(c[j][1]>='a'&&c[j][1]<='z')\n\t\t\t\t\t\ta=c[j][1]-'a'+26;\n\t\t\t\t\telse\n\t\t\t\t\t\ta=c[j][1]-'0'+52;\n\t\t\t\tif(c[j][i]>='A'&&c[j][i]<='Z')\n\t\t\t\t\tb=c[j][i]-'A';\n\t\t\t\telse\n\t\t\t\t\tif(c[j][i]>='a'&&c[j][i]<='z')\n\t\t\t\t\t\tb=c[j][i]-'a'+26;\n\t\t\t\t\telse\n\t\t\t\t\t\tb=c[j][i]-'0'+52;\n\t\t\t\tg[a][b]++;\n\t\t\t\tif(a==b)\n\t\t\t\t{\n\t\t\t\t\tfor(k=1;k<=len[j];k++)\n\t\t\t\t\t\tif(c[j][k]!=c[j][len[j]-k+1])\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\tif(k<=len[j])\n\t\t\t\t\t\tg[b][a]++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tg[b][a]++;\n\t\t\t}\n\t\tmemset(f,0,sizeof(f));\n\t\tfor(j=0;j<62;j++)\n\t\t{\n\t\t\tfor(k=0;k<62;k++)\n\t\t\t\tfor(l=k+1;l<62;l++)\n\t\t\t\t\tfor(m=l+1;m<62;m++)\n\t\t\t\t\t\tf[k][l][m]=(f[k][l][m]+g[j][k]*g[j][m]%M*g[j][l])%M;\n\t\t\tfor(k=0;k<62;k++)\n\t\t\t\tfor(l=k+1;l<62;l++)\n\t\t\t\t{\n\t\t\t\t\tf[k][k][l]=(f[k][k][l]+g[j][k]*g[j][k]%M*g[j][l])%M;\n\t\t\t\t\tf[k][l][l]=(f[k][l][l]+g[j][k]*g[j][l]%M*g[j][l])%M;\n\t\t\t\t}\n\t\t\tfor(k=0;k<62;k++)\n\t\t\t\tf[k][k][k]=(f[k][k][k]+g[j][k]*g[j][k]%M*g[j][k])%M;\n\t\t}\n\t\tfor(j=0;j<62;j++)\n\t\t\tfor(k=j+1;k<62;k++)\n\t\t\t\tfor(l=k+1;l<62;l++)\n\t\t\t\t\tfor(m=l+1;m<62;m++)\n\t\t\t\t\t\tans=(ans+f[j][k][l]*f[k][l][m]%M*f[j][l][m]%M*f[j][k][m]%M*24)%M;\n\t\tfor(j=0;j<62;j++)\n\t\t\tfor(k=j+1;k<62;k++)\n\t\t\t\tfor(l=k+1;l<62;l++)\n\t\t\t\t{\n\t\t\t\t\tans=(ans+f[j][k][l]*f[k][l][l]%M*f[j][l][l]%M*f[j][k][l]%M*12)%M;\n\t\t\t\t\tans=(ans+f[j][k][k]*f[k][k][l]%M*f[j][k][l]%M*f[j][k][l]%M*12)%M;\n\t\t\t\t\tans=(ans+f[j][j][k]*f[j][j][l]%M*f[j][k][l]%M*f[j][k][l]%M*12)%M;\n\t\t\t\t}\n\t\tfor(j=0;j<62;j++)\n\t\t\tfor(k=j+1;k<62;k++)\n\t\t\t{\n\t\t\t\tans=(ans+f[j][j][k]*f[j][k][k]%M*f[j][j][k]%M*f[j][k][k]%M*6)%M;\n\t\t\t\tans=(ans+f[j][j][j]*f[j][j][k]%M*f[j][j][k]%M*f[j][j][k]%M*4)%M;\n\t\t\t\tans=(ans+f[k][k][k]*f[j][k][k]%M*f[j][k][k]%M*f[j][k][k]%M*4)%M;\n\t\t\t}\n\t\tfor(j=0;j<62;j++)\n\t\t\tans=(ans+f[j][j][j]*f[j][j][j]%M*f[j][j][j]%M*f[j][j][j])%M;\n\t}\n\tcout<\nusing namespace std;\ndouble a,b,c,d,ans1,ans2;\nint main(void){\n ios::sync_with_stdio(false);\n cin>>a>>b>>c>>d;\n ans1=max(3*a/10.00,a-a*c/250.00);\n ans2=max(3*b/10.00,b-b*d/250.00);\n if (ans1ans2) printf(\"Misha\\r\");\n}", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"source_code": "#include\n#define MOD (long long)998244353\nusing namespace std;\nlong long fac[200003],lst[200003];\ninline long long qpow(long long a,long long b)\n{\n if(b==1) return a;\n long long t=qpow(a,b/2);\n t=t*t%MOD;\n if(b&1) t=t*a%MOD;\n return t;\n}\ninline long long c(long long m,long long n)\n{\n if(nn-m) m=n-m;\n long long a=lst[m],b=fac[m];\n return a*qpow(b,MOD-2)%MOD;\n}\ninline long long C(long long m,long long n)\n{\n if(nn-m) m=n-m;\n long long a=1,b=1;\n for(long long i=0;i>n>>m;\n\tlst[0]=fac[0]=1;\n\tfor(long long i=1; i\n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main()\n{\n string in;\n bool plus = false;\n bool equal = false;\n int a1 = 0;\n int a2 = 0;\n int a3 = 0;\n cin >> in;\n for(int i = 0; i void chkmn(T &a, const T &b) { \r\n\t(a > b) && (a = b); \r\n}\r\ntemplate void chkmx(T &a, const T &b) { \r\n\t(a < b) && (a = b); \r\n}\r\n\r\nint MOD;\r\nint adt(const LL &a) { \r\n\treturn (a % MOD + MOD) % MOD; \r\n} \r\nint inc(const int &a, const int &b) { \r\n\treturn a + b >= MOD ? a + b - MOD : a + b; \r\n}\r\nint dec(const int &a, const int &b) { \r\n\treturn a - b < 0 ? a - b + MOD : a - b; \r\n}\r\nint mul(const int &a, const int &b) { \r\n\treturn 1LL * a * b % MOD; \r\n}\r\nint sqr(const int &a) { \r\n\treturn 1LL * a * a % MOD; \r\n}\r\nvoid Adt(LL &a) {\r\n\ta = (a % MOD + MOD) % MOD;\r\n}\r\nvoid Inc(int &a, const int &b) { \r\n\t((a += b) >= MOD) && (a -= MOD); \r\n}\r\nvoid Dec(int &a, const int &b) { \r\n\t((a -= b) < 0) && (a += MOD); \r\n}\r\nvoid Mul(int &a, const int &b) { \r\n\ta = 1LL * a * b % MOD; \r\n}\r\nvoid Sqr(int &a) { \r\n\ta = 1LL * a * a % MOD; \r\n}\r\nint fsp(int a, int x = MOD - 2) {\r\n\tint res = 1;\r\n\tfor ( ; x; x >>= 1, Sqr(a)) {\r\n\t\tif (x & 1) {\r\n\t\t\tMul(res, a);\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nconst int maxn = 5e3 + 5;\r\nint n;\r\nint binom[maxn][maxn], pw[maxn][maxn], fac[maxn], fiv[maxn];\r\n\r\nint main() {\r\n\t\r\n read(n), read(MOD);\r\n fac[0] = 1;\r\n rep(i, 1, n) {\r\n fac[i] = mul(fac[i - 1], i);\r\n }\r\n fiv[n] = fsp(fac[n]);\r\n per(i, n, 1) {\r\n fiv[i - 1] = mul(fiv[i], i);\r\n }\r\n rep(i, 0, n) {\r\n binom[i][0] = binom[i][i] = 1;\r\n re(j, 1, i) {\r\n binom[i][j] = inc(binom[i - 1][j], binom[i - 1][j - 1]);\r\n }\r\n pw[i][0] = 1;\r\n rep(j, 1, n) {\r\n pw[i][j] = mul(pw[i][j - 1], i);\r\n }\r\n }\r\n int ans = 0;\r\n re(i, 0, n) {\r\n re(j, 1, n - i) {\r\n Inc(ans, mul(mul(binom[n][i], mul(fac[n - i], mul(fiv[j], binom[n - i - 1 - j][j - 1]))), mul(pw[n - i - j][i], pw[n - 1][j])));\r\n }\r\n }\r\n printf(\"%d\\n\", ans);\r\n\treturn 0;\r\n}", "src_uid": "2d5a5055aaf34f4d300cfdf7c21748c3"} {"source_code": "#include\nusing namespace std;\nvoid qmax(int &x,int y) {if (xy) x=y;}\nint read()\n{\n char s;\n int k=0,base=1;\n while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));\n if(s==EOF)exit(0);if(s=='-')base=-1,s=getchar();\n while(isdigit(s)){k=k*10+(s^'0');s=getchar();}\n return k*base;\n}\nvoid write(int x)\n{\n if(x<0){putchar('-');write(-x);}\n else{if(x/10)write(x/10);putchar(x%10+'0');}\n}\nconst int maxn=2e6+100;\nconst long long mod=1e9+7;\nint n,k,mu[maxn];\nint f[maxn],prime[maxn],tot;\nlong long ksm(long long x,int y)\n{\n\tlong long sum=1;\n\twhile (y)\n\t{\n\t\tif (y&1) sum=sum*x%mod;\n\t\ty>>=1;\n\t\tx=x*x%mod; \n\t}\n\treturn sum;\n}\nlong long ans[maxn],p[maxn],sum;\nint main()\n{\n\tn=read();k=read();\n\tfor (int i=1;i<=k;i++)\n\t{\n\t\tp[i]=ksm((long long)i,n);\n\t}\n\tmu[1]=1;\n\tfor (int i=2;i<=k;i++)\n\t{\n\t\tif (!f[i])\n\t\t{\n\t\t\ttot++;prime[tot]=i;mu[i]=-1;\n\t\t}\n\t\tfor (int j=1;j<=tot;j++)\n\t\t{\n\t\t\tif (i*prime[j]>k) break;\n\t\t\tf[i*prime[j]]=1;\n\t\t\tif (i%prime[j]==0) break; \n\t\t\tmu[i*prime[j]]=-mu[i];\n\t\t}\n\t} \n\tfor (int i=1;i<=k;i++)\n\t{\n\t\tfor (int j=i;j<=k;j+=i)\n\t\t{\n\t\t\tans[j]+=(long long)mu[i]*(p[j/i]-p[(j/i)-1])%mod;\n\t\t\tans[j]%=mod;\n\t\t}\n\t}\n\tfor (int i=2;i<=k;i++)\n\t{\n\t\tans[i]+=ans[i-1];\n\t\tans[i]%=mod;\n\t}\n\tfor (int i=1;i<=k;i++)\n\t{\n//\t\t\tprintf(\"%I64d\\n\",ans[i]);\n\t\tif (ans[i]<0) ans[i]=(ans[i]%mod+mod)%mod; \n\t\tsum+=ans[i]^(long long)i;\n\t\tif (sum>=mod) sum-=mod;\n\t}\n\tprintf(\"%I64d\\n\",sum);\n\treturn 0;\n} ", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa"} {"source_code": "#include\nusing namespace std;\nlong long n;\nint sum(long long n)\n{\n\tif(n==4||n==7) return true;\n\tif(n<10) return false;\n\treturn (n%10==4||n%10==7)+sum(n/10);\n}\nbool judge(int x)\n{\n\tif(x==4||x==7) return true;\n\tif(x<10) return false;\n\tif(x%10!=4&&x%10!=7) return false;\n\treturn judge(x/10);\n}\nint main()\n{\n\tscanf(\"%lld\",&n);\n\tprintf(\"%s\",judge(sum(n))?\"YES\":\"NO\");\n\treturn 0;\n}", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"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// numeric_limits::max()\nusing namespace std;\n#define LL int64_t // 64-bit long long int, use %I64d for scan and printf\nint DEBUG = 0;\n#define MOD 1000000009\nLL pascal[5000][5000];\nmain(int argc, char **argv) {\n DEBUG = (argc>=2) ? atoi(argv[1]) : 0;\n LL factorial[5000];\n factorial[0] = 1;\n for(int i = 1; i < 5000; i++){\n factorial[i] = (factorial[i-1] * i) % 1000000009;\n }\n for(int i = 0; i < 5000; i++){\n pascal[i][0] = pascal[i][i] = 1;\n }\n for(int i = 1; i < 5000; i++){\n for(int j = 1; j < 5000; j++){\n pascal[i][j] = (pascal[i-1][j-1] + pascal[i-1][j]) % MOD;\n }\n }\n int n, w, b;\n cin >> n >> w >> b;\n LL ans = (factorial[w]*factorial[b]) % MOD;\n LL mult = 0;\n for(int i = 1; i < n; i++){\n if((n-i) <= w && i <= b){\n LL here = 0;\n \n here = n-i-1;\n here = (here * (pascal[b-1][i-1])) % MOD;\n here = (here * (pascal[w-1][n-i-1])) % MOD;\n //cout << i << \" \" << here << endl;\n mult = (mult + here) % MOD;\n }\n }\n ans = (ans * mult) % MOD;\n cout << ans << endl;\n}\n\n\n\n", "src_uid": "63e93a161bbff623323e66c98d5e20ac"} {"source_code": "/**\n * code generated by JHelper\n * More info: https://github.com/AlexeyDmitriev/JHelper\n * @author\n */\n\n#include \n#include \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\n#define pb push_back\n#define sz(v) ((int)(v).size())\n#define all(v) (v).begin(),(v).end()\n#define mp make_pair\n\nusing namespace std;\n\ntypedef long long int64;\ntypedef vector vi;\ntypedef pair ii;\ntypedef long double ld;\n\nint BUBEN = 30;\nint BUBEN2 = 5;\nint BUBEN3 = 20;\n\nclass TaskH {\n public:\n void solveOne(istream &in, ostream &out) {\n ld start = clock() / (ld) CLOCKS_PER_SEC;\n\n int n;\n in >> n;\n vector x(n + 1);\n vector y(n + 1);\n for (int i = 0; i <= n; ++i) {\n in >> x[i] >> y[i];\n }\n vector offset;\n vector len;\n vector dx;\n vector dy;\n offset.push_back(0);\n for (int i = 0; i < n; ++i) {\n ld vx = x[i + 1] - x[i];\n ld vy = y[i + 1] - y[i];\n ld z = hypotl(vx, vy);\n dx.push_back(vx / z);\n dy.push_back(vy / z);\n len.push_back(z);\n offset.push_back(offset.back() + z);\n }\n auto ternary = [&](const auto& func, ld left, ld right) {\n while (right - left > 1e-12 * max((ld) 1.0, right)) {\n ld mleft = (2 * left + right) / 3;\n ld mright = (left + 2 * right) / 3;\n ld vleft = func(mleft);\n ld vright = func(mright);\n if (vleft > vright) {\n right = mright;\n } else {\n left = mleft;\n }\n }\n return func((left + right) / 2);\n };\n ld total = offset.back();\n\n auto where = [&](ld pos) {\n int i = lower_bound(all(offset), pos) - offset.begin() - 1;\n if (i < 0) i = 0;\n if (i >= n) i = n - 1;\n return i;\n };\n\n auto evalBefore = [&](ld pos) {\n int i = where(pos);\n ld xi = x[i] + dx[i] * (pos - offset[i]);\n ld yi = y[i] + dy[i] * (pos - offset[i]);\n\n ld bestBefore = 1;\n for (int j = 0; j < i; ++j) {\n auto eval2 = [&](ld t) {\n ld xj = x[j] + dx[j] * t;\n ld yj = y[j] + dy[j] * t;\n ld direct = pos - (offset[j] + t);\n return direct / max((ld) 1e-7, hypotl(xi - xj, yi - yj));\n };\n ld cur = ternary(eval2, 0, len[j]);\n bestBefore = max(bestBefore, cur);\n }\n return bestBefore;\n };\n\n auto evalAfter = [&](ld pos) {\n int i = where(pos);\n ld xi = x[i] + dx[i] * (pos - offset[i]);\n ld yi = y[i] + dy[i] * (pos - offset[i]);\n\n ld bestAfter = 1;\n for (int j = i + 1; j < n; ++j) {\n auto eval2 = [&](ld t) {\n ld xj = x[j] + dx[j] * t;\n ld yj = y[j] + dy[j] * t;\n ld direct = (offset[j] + t) - pos;\n return direct / max((ld) 1e-7, hypotl(xi - xj, yi - yj));\n };\n ld cur = ternary(eval2, 0, len[j]);\n bestAfter = max(bestAfter, cur);\n }\n return bestAfter;\n };\n\n auto eval = [&](ld pos) {\n return min(evalBefore(pos), evalAfter(pos));\n };\n\n\n ld STEP = total;\n vector> best;\n while (best.size() < 1e6 && clock() / (ld) CLOCKS_PER_SEC < start + 1) {\n STEP *= 0.5;\n for (ld at = STEP; at <= total; at += STEP * 2) {\n best.emplace_back(eval(at), where(at), at);\n }\n }\n sort(all(best));\n\n auto reduce = [&]() {\n sort(all(best), [](const auto& a, const auto& b) {\n return get<0>(a) > get<0>(b);\n });\n int got = 0;\n vector gotIn(n);\n for (int i = 0; i < best.size(); ++i) {\n if (got < BUBEN3 && gotIn[get<1>(best[i])] < BUBEN2) {\n best[got] = best[i];\n ++got;\n ++gotIn[get<1>(best[i])];\n }\n }\n best.resize(got);\n };\n\n while (clock() / (ld) CLOCKS_PER_SEC < start + 3) {\n reduce();\n STEP *= 0.5;\n sort(all(best), [](const auto& a, const auto& b) {\n return get<2>(a) < get<2>(b);\n });\n int old = best.size();\n ld prev = 0;\n for (int i = 0; i <= old; ++i) {\n ld cur;\n if (i == old) {\n cur = total;\n } else {\n cur = get<2>(best[i]);\n }\n if (cur - prev > 3 * STEP) {\n ld at = prev + STEP;\n best.emplace_back(eval(at), where(at), at);\n at = cur - STEP;\n best.emplace_back(eval(at), where(at), at);\n } else if (cur - prev > 2 * STEP) {\n ld at = (2 * prev + cur) / 3;\n best.emplace_back(eval(at), where(at), at);\n at = (prev + 2 * cur) / 3;\n best.emplace_back(eval(at), where(at), at);\n } else if (cur - prev > STEP) {\n ld at = (prev + cur) / 2;\n best.emplace_back(eval(at), where(at), at);\n }\n prev = cur;\n }\n }\n\n cerr << STEP << endl;\n\n ld res = 0;\n for (const auto& x : best) {\n res = max(res, get<0>(x));\n }\n out << res << \"\\n\";\n }\n\n\n\n void solve(std::istream &in, std::ostream &out) {\n out.precision(20);\n int nt = 1;\n for (int it = 0; it < nt; ++it) {\n solveOne(in, out);\n }\n }\n};\n\n\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n TaskH solver;\n std::istream& in(std::cin);\n std::ostream& out(std::cout);\n solver.solve(in, out);\n return 0;\n}\n", "src_uid": "ee115d3f08a53c52db3e429ad0cee906"} {"source_code": "#include\n#define ll long long\n#define ull unsigned ll\n#define uint ungigned\n#define db long double\n#define pii pair\n#define pll pair\n#define pli pair\n#define vi vector\n#define vpi vector\n#define IT iterator\n\n#define PB push_back\n#define MK make_pair\n#define LB lower_bound\n#define UB upper_bound\n#define fi first\n#define se second\n#define BG begin\n#define ED end\n\n#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)\n#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)\n#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)\n#define CLR(a,v) memset(a,v,sizeof(a));\n#define CPY(a,b) memcpy(a,b,sizeof(a));\n\n#define LS3 k*2,l,mid\n#define RS3 k*2+1,mid+1,r\n#define LS5 k*2,l,mid,x,y\n#define RS5 k*2+1,mid+1,r,x,y\n#define GET pushdown(k);int mid=(l+r)/2\n\n#define INF (1<<29)\n#define sqr(x) ((x)*(x))\n#define eps (1e-7)\nusing namespace std;\nconst int N=1005;\nstruct que{\n\tdouble x; int v;\n\tbool operator <(const que &a)const{\n\t\tif (abs(x-a.x)>eps)\n\t\t\treturn xeps;step/=5){\n\t\tint mx=0; double at;\n\t\tfor (double i=st;imx) mx=now,at=i;\n\t\t}\n\t\tst=at-5*step;\n\t\ted=at+5*step;\n\t\tans=max(ans,mx);\n\t}\n\tprintf(\"%lld\\n\",1ll*m*(m+1)/2+n+1ll*ans*m-m);\n}", "src_uid": "06ec7e481c963e635a6303503ffccc8b"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\n\n#define INF 0x3f3f3f3f\n#define REP(i,a,b)\tfor(int i=a;i<=b;++i)\n#define DOW(i,a,b)\tfor(int i=a;i>=b;--i)\n#define CL(a,b)\tmemset(a,b,sizeof(a))\n#define lint long long\n#define N 20\n#define getchar()\t(FS==FT&&(FT=(FS=BB)+fread(BB,1,1<<15,stdin),FS==FT)?EOF:*FS++)\nchar *FS,*FT,BB[1<<15];\n\nint read(){\n\tint x=1,i=0;\n\tchar ch;\n\tch=getchar();\n\twhile(!isdigit(ch)){\n\t\tif(ch==EOF){\n\t\t\texit(0);\n\t\t}\n\t\tif(ch=='-')x=-1;\n\t\tch=getchar();\n\t}\n\twhile(isdigit(ch)){\n\t\ti=i*10+ch-'0';\n\t\tch=getchar();\n\t}\n\t\n\treturn x*i;\n}\n\nint get(char *S){\n\tchar ch;\n\tint l=0;\n\tch=getchar();\n\twhile(!isalnum(ch)){\n\t\tif(ch==EOF){\n\t\t\texit(0);\n\t\t}\n\t\tch=getchar();\n\t}\n\twhile(isalnum(ch)){\n\t\tS[l++]=ch;\n\t\tch=getchar();\n\t}\n\treturn l;\n}\n\nint DA[400]={1,2,3,4,6,8,9,12,16,18,24,27,32,36,48,54,64,72,81,96,108,128,144,162,192,216,243,256,288,324,384,432,486,512,576,648,729,768,864,972,1024,1152,1296,1458,1536,1728,1944,2048,2187,2304,2592,2916,3072,3456,3888,4096,4374,4608,5184,5832,6144,6561,6912,7776,8192,8748,9216,10368,11664,12288,13122,13824,15552,16384,17496,18432,19683,20736,23328,24576,26244,27648,31104,32768,34992,36864,39366,41472,46656,49152,52488,55296,59049,62208,65536,69984,73728,78732,82944,93312,98304,104976,110592,118098,124416,131072,139968,147456,157464,165888,177147,186624,196608,209952,221184,236196,248832,262144,279936,294912,314928,331776,354294,373248,393216,419904,442368,472392,497664,524288,531441,559872,589824,629856,663552,708588,746496,786432,839808,884736,944784,995328,1048576,1062882,1119744,1179648,1259712,1327104,1417176,1492992,1572864,1594323,1679616,1769472,1889568,1990656,2097152,2125764,2239488,2359296,2519424,2654208,2834352,2985984,3145728,3188646,3359232,3538944,3779136,3981312,4194304,4251528,4478976,4718592,4782969,5038848,5308416,5668704,5971968,6291456,6377292,6718464,7077888,7558272,7962624,8388608,8503056,8957952,9437184,9565938,10077696,10616832,11337408,11943936,12582912,12754584,13436928,14155776,14348907,15116544,15925248,16777216,17006112,17915904,18874368,19131876,20155392,21233664,22674816,23887872,25165824,25509168,26873856,28311552,28697814,30233088,31850496,33554432,34012224,35831808,37748736,38263752,40310784,42467328,43046721,45349632,47775744,50331648,51018336,53747712,56623104,57395628,60466176,63700992,67108864,68024448,71663616,75497472,76527504,80621568,84934656,86093442,90699264,95551488,100663296,102036672,107495424,113246208,114791256,120932352,127401984,129140163,134217728,136048896,143327232,150994944,153055008,161243136,169869312,172186884,181398528,191102976,201326592,204073344,214990848,226492416,229582512,241864704,254803968,258280326,268435456,272097792,286654464,301989888,306110016,322486272,339738624,344373768,362797056,382205952,387420489,402653184,408146688,429981696,452984832,459165024,483729408,509607936,516560652,536870912,544195584,573308928,603979776,612220032,644972544,679477248,688747536,725594112,764411904,774840978,805306368,816293376,859963392,905969664,918330048,967458816,1019215872,1033121304,1073741824,1088391168,1146617856,1162261467,1207959552,1224440064,1289945088,1358954496,1377495072,1451188224,1528823808,1549681956,1610612736,1632586752,1719926784,1811939328,1836660096,1934917632};\n\nint main(){\n//\tfreopen(\"yq.in\",\"r\",stdin);\n//\tfreopen(\"yq.out\",\"w\",stdout);\n// int sum=0;\n//\tREP(i,1,2e9){\n// \tint k=i;\n// \twhile(k%2==0){\n// \t\tk/=2;\n// \t}\n// \twhile(k%3==0){\n// \t\tk/=3;\n// \t}\n// \tif(k==1)printf(\"%d,\",i),sum++;\n// }\n// printf(\"%d\",sum);\n int l,r;\n scanf(\"%d %d\",&l,&r);\n int L=lower_bound(DA,DA+326,l)-DA;\n int R=lower_bound(DA,DA+326,r+1)-DA;\n printf(\"%d\",R-L);\n \n return 0;\n}", "src_uid": "05fac54ed2064b46338bb18f897a4411"} {"source_code": "/******************************************\n* AUTHOR: CHIRAG AGARWAL *\n* INSTITUITION: BITS PILANI, PILANI *\n******************************************/\n#include \nusing namespace std;\n \ntypedef long long LL; \ntypedef long double LD;\n\nint cnt[43];\nset help;\nmap mp;\nint cur[43];\nint lft[43];\nvector fin;\n\nint val(LL tmp)\n{\n\tint cn=0;\n\twhile(tmp)\n\t{\n\t\ttmp/=2;\n\t\tcn++;\n\t}\n\treturn cn;\n}\n\nint main() \n{\n\tint n;\n\tscanf(\"%d\",&n);\n\tfor(LL i=1;i<=2e12;i=i*2)\n\t{\n\t\thelp.insert(i);\n\t\tmp[i]=0;\n\t}//powers of 2\n\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tLL a;\n\t\tscanf(\"%lld\",&a);\n\n\t\tif(help.find(a)!=help.end())\n\t\t{\n\t\t\tmp[a]++;\n\t\t}\n\n\t\tcnt[val(a)]++;\n\t}\t\n\t//cnt of powers of 2 stored\n\tint ans=0;\n\tint num=0;\n\twhile(true)\n\t{\n\t\tLL lst=0;\n\t\tfor(map :: iterator it=mp.begin();it!=mp.end();it++)\n\t\t{\n\t\t\tif(it->second==0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}//find the first power of 2 that doesn't exist, break;\n\t\t\telse\n\t\t\t{\n\t\t\t\tlst=it->first;\n\t\t\t}\n\t\t}\n\n\t\tif(lst==0)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tnum++;\n\t\tcur[val(lst)]++;\n\t\tint yu=1;\n\n\t\tfor(LL i=1;i<=lst;i=i*2)\n\t\t{\n\t\t\tcnt[yu]--;\n\t\t\tmp[i]--;\n\t\t\tyu++;\n\t\t}\n\t\t//cnt[1]=2\n\t\t//cnt[2]=2\n\t\t//mp[1]=2;\n\t\t//mp[2]=2;\n\t\t//cur[2]=1;\n\t/*\tfor(int i=1;i<=2;i++)\n\t\t{\n\t\t\tprintf(\"%d %d\\n\",cnt[i],mp[i]);\n\t\t}*/\n\t\tfor(int i=0;i<=42;i++)\n\t\t{\n\t\t\tlft[i]=cur[i];\n\t\t}\n\t/*\tfor(int i=1;i<=2;i++)\n\t\t{\n\t\t\tprintf(\"%d\\n\",lft[i]);\n\t\t}*/\n\n\t\tint flg=0;\n\t\tfor(int i=42;i>=1;i--)\n\t\t{\n\t\t\tif(i!=42)\n\t\t\t{\n\t\t\t\tlft[i]+=lft[i+1];\n\t\t\t}\n\t\t\tif(lft[i]>=cnt[i])\n\t\t\t{\n\t\t\t\tlft[i]-=cnt[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/*if(num==2)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"%d\\n\",i);\n\t\t\t\t}*/\n\t\t\t\tflg=1;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t\n\t\t}\n\t\tif(flg==0)\n\t\t{\n\t\t\tfin.push_back(num);\n\t\t\tans++;\n\t\t}\n\t}\n\tif(ans==0)\n\t{\n\t\tprintf(\"-1\\n\");\n\t}\n\telse\n\t{\n\t\tfor(int i=0;i\nusing namespace std;\nint main(){\n\tint i,j,n;\n\tcin>>n;\n\tfor(i=1;i\nusing namespace std;\n\n\nint main(){\n\n int n;\n\n cin>>n;\n int a[n+1];\n for(int i = 0; i < n; i++){\n cin>>a[i];\n }\n\n sort(a,a+n);\n\n if(a[0] == a[n/2]){\n cout<<\"Bob\"<\nusing namespace std;\n\nint seg[]={6,2,5,5,4,5,6,3,7,6};\nint count(int n) {\n int res=0;\n while(n){\n res+=seg[n%10];\n n/=10;\n }\n return res;\n}\n\nint main() {\n \n int x,y\n ,ans=0;\n cin>>x>>y;\n \n for(int i = x;i<=y;i++) {\n \t\t//cout<\nusing namespace std;\ntypedef long long LL;\nLL a[10000],inv[10000],c[10000],tot[10000];\nconst int modu=1000000007;\nint sum[5000][10000];\nconst int N=10000;\ninline LL norm(LL x){\n return (x%modu+modu)%modu;\n}\nvoid show(LL tab[][N],char* txt,int n){\n printf(\"%s\",txt);\n int i,j;\n for(i=0;i>=1){\n if(t&1) p=norm(p*x);\n x=norm(x*x);\n }\n return p;\n}\nint main(){\n int n,i,j,k;\n LL cur;\n scanf(\"%d\",&n);\n for(i=0;i=0;i--){\n for(k=0;k<=2*n-2;k++){\n sum[i][k]=norm((k>=2?sum[i+1][k-2]:0)*a[i]+(k+i0?2:1));\n }\n }\n for(i=0;i\nusing namespace std;\n#define FZ(n) memset((n),0,sizeof(n))\n#define FMO(n) memset((n),-1,sizeof(n))\n#define MC(n,m) memcpy((n),(m),sizeof(n))\n#define F first\n#define S second\n#define MP make_pair\n#define PB push_back\n#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)\n#define ALL(x) x.begin(),x.end()\n#define IOS ios_base::sync_with_stdio(0);cin.tie(0)\n\ntypedef long long i64;\ntypedef pair pll;\nconst i64 INF = 5e18;\nconst int MK = 10101;\nconst int MN = 101010;\ni64 H, M, N, K; \nmap mp;\nvector methods;\nvector ip[MK];\n\nbool pllcmp(pll p1, pll p2) { \n p1.S = -p1.S; p2.S = - p2.S;\n return p1 < p2;\n};\npriority_queue, std::function > pq(pllcmp);\ni64 dis[MK];\ni64 op[MN];\n\nvoid spfa() {\n for(int i=0; i qe; qe.push(0);\n while(qe.size()) {\n i64 v = qe.front(); qe.pop();\n \n for(int i=0; i<(int)methods.size(); i++) {\n i64 m = methods[i];\n i64 r = (m+v)%K;\n if(dis[r] > dis[v] + m) {\n dis[r] = dis[v] + m;\n qe.push(r);\n }\n }\n }\n\n pq = priority_queue, function >(pllcmp);\n for(int i=0; i= dis[r]) {\n pq.push(MP(c, i));\n }\n }\n}\n\nint main() {\n \n\n IOS;\n cin >> H >> N >> M >> K;\n\n for(int i=0; i> a >> c;\n a --;\n mp[a] = c;\n ip[a%K].PB(MP(i, c));\n op[i] = a;\n }\n //cout << \"ZZZ\" << endl;\n\n for(int i=0; i<(int)ip[0].size(); i++) {\n pq.push(MP(ip[0][i].S, ip[0][i].F));\n }\n\n for(int i=1; i> t;\n if(t == 1) {\n i64 x; cin >> x;\n methods.PB(x);\n spfa();\n } else if(t == 2) {\n i64 id, a, c; cin >> id >> c; id--;\n a = op[id];\n mp[a] -= c;\n //if(mp[a] < 0) cout << \"A: \" << a << ' ' << id << ' ' << c << endl;\n if( dis[a%K] <= a ) pq.push(MP(mp[a], id));\n } else if (t == 3) {\n pll tp;\n while(pq.size()) {\n tp = pq.top();\n if( mp[op[tp.S]] == tp.F ) break;\n pq.pop();\n }\n\n cout << (pq.size() ? tp.F : 0) << endl;\n if(pq.size()) mp[op[tp.S]] = 0;\n }\n }\n \n return 0;\n}\n", "src_uid": "03c4df4f640633f3364ca9225588caf7"} {"source_code": "/*\n _ _ ___ _____ ___ __ \n__ _(_) | ____ _ ___ / _ \\___ / _ \\ / /_ \n\\ \\ / / | |/ / _` / __| | | | / / | | | '_ \\ \n \\ V /| | < (_| \\__ \\ |_| |/ /| |_| | (_) |\n \\_/ |_|_|\\_\\__,_|___/\\___//_/ \\___/ \\___/ \n \n VIKAS SINGH */\n \n#include\n#define endl \"\\n\"\n#define pb push_back\n#define mp make_pair\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef unsigned int ui;\ntypedef std::vector vi;\ntypedef std::vector vl;\n#define all(v) v.begin(),v.end()\n#define maxall(v) *max_element(all(v))\n#define minall(v) *min_element(all(v))\n#define min3(a,b,c) min(a,min(b,c))\n#define max3(a,b,c) max(a,max(b,c))\n#define min4(a,b,c,d) min(min(a,b),min(c,d))\n#define max4(a,b,c,d) max(max(a,b),max(c,d))\n#define f(a,b,c) for(int a=b;a>a[ix];\n#define p(x) printf(\"%d\\n\",x);\n#define pl(x) printf(\"%lld\\n\",x);\n#define p1d(a,n) for(int ix=0;ix>n>>m;\n if(n<=m)\n cout<\n#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\nusing namespace std;\n\nint main()\n{\n fastio;\n\n long long k;\n cin>>k;\n\n if(k>=37 )\n {\n cout<<\"-1\";\n return 0;\n }\n\n else if(k==0)\n {\n cout<<\"7\";\n return 0;\n }\n\n else if(k%2==0)\n {\n for(long long i=0;i\n\nusing namespace std;\n\nint main()\n{\n int n = 0;\n int min1 = 0, max1 = 0, min2 = 0, max2 = 0, min3 = 0, max3 = 0;\n cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3;\n cout << min(n - min2 - min3, max1) << ' ' << min(n - min(n - min3 - min2, max1) - min3, max2) << ' ' << n - min(n - min2 - min3, max1) - min(n - min(n - min2 - min3, max1) - min3, max2);\n}", "src_uid": "3cd092b6507079518cf206deab21cf97"} {"source_code": "#include \n#include \n#include \n#include \n#include \n\n//#pragma GCC optimize(\"O2\")\n\nusing namespace std;\n\nconst int MAXN = 1000010;\nconst int Mod = 1200007;\n\nint n; char ch[MAXN];\n\nvector now;\n\ntypedef tr1::unordered_map I;\n\nI M;\n\nint main(void) {\n // freopen(\"in\", \"r\", stdin);\n scanf(\"%s\", ch + 1); n = strlen(ch + 1);\n for (int i = n; i >= 1; i--) {\n int S = 0; \n vector::iterator it = find(now.begin(), now.end(), ch[i] - 'a'); if (it != now.end()) now.erase(it); now.insert(now.begin(), ch[i] - 'a');\n for (int j = 0; j < (int)now.size() && now[j] != ch[i - 1] - 'a'; j++) {\n S |= 1 << now[j];\n M[S]++;\n }\n }\n int q; scanf(\"%d\", &q);\n for (int i = 1; i <= q; i++) {\n char st[26]; scanf(\"%s\", st);int t = strlen(st), S = 0; \n for (int j = 0; j < t; j++) S |= 1 << (st[j] - 'a');\n printf(\"%d\\n\", M[S]);\n }\n return 0;\n}\n", "src_uid": "9bafcd579d38d5c3f073839ccb1c6ed3"} {"source_code": "#include\n#define INF 0x7fffffff\n#define pi acos(-1,0)\n#define e 2.718281828459\nusing namespace std;\ntypedef long long ll;\nll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}\n\nchar s[600005];\nint sum[300005];\nint main(){\n\t//freopen(\"data.in\",\"r\",stdin);\n\t//freopen(\"data.out\",\"w\",stdout);\n\tint n;\n\tscanf(\"%d\",&n);\n scanf(\"%s\",s+1);\n for(int i=1;i<=n;i++){\n \ts[i+n]=s[i];\n\t}\n\tsum[0]=0;\n\tint pos=0,minn=0;\n\tfor(int i=1;i<=n;i++){\n\t\tsum[i]=sum[i-1]+(s[i]=='('?1:-1);\n\t\tif(sum[i]\n#include\nusing namespace std;\n\nint main(){\n int a,d=0,n,i,m[10]={0},m1[10]={0},j;\n \n cin>>n;\n a=n;\n\nwhile(a>=1){\nm[a%10]++;\na/=10;}\n\n\nif(n%2==0){\n a=n/2;\n\nwhile(a>=1){\nm1[a%10]++;\na/=10;}\n for(i=0;i<10;++i)if(m[i]>0&&m1[i]>0){d++;break;} \n \n }\n \n \n\n for(i=1;i*3<=n;++i)\n if(n%i==0){\n \nfor(j=0;j<10;++j)\nm1[j]=0;\n \na=i; \nwhile(a>=1){\nm1[a%10]++;\na/=10;}\nfor(j=0;j<10;++j)if(m[j]>0&&m1[j]>0){d++;break;} \n \n }\n d++;\n cout<\nint a[105];\nint main()\n{\n\tint n;\n\tlong long count=0;\n\tscanf(\"%d\",&n);\n\tfor(int i=1;i<=n;i++) scanf(\"%d\",&a[i]);\n\tfor(int i=1;i\n#include\n\nusing namespace std;\n\n#define ll long long\n\nmapmp1[100005],*mp2[100005];\nint d[100005],w[100005],p[100005];\nint main()\n{\n //freopen(\"magictree.in\",\"r\",stdin);\n //freopen(\"magictree.out\",\"w\",stdout);\n int n,m,k,x;\n scanf(\"%d%d%d\",&n,&m,&k);\n int i;\n for(i=2;i<=n;i++)\n scanf(\"%d\",&p[i]);\n for(i=1;i<=m;i++)\n {\n scanf(\"%d\",&x);\n scanf(\"%d%d\",&d[x],&w[x]);\n }\n for(i=1;i<=n;i++)\n mp2[i]=mp1+i;\n for(i=n;i>1;i--)\n {\n if (d[i])\n {\n auto it=mp2[i]->insert(make_pair(d[i],0)).first;\n it->second=it->second+w[i];\n x=w[i];\n /*++it;\n while(1)\n {\n if (it==mp2[i]->end() || xsecond)\n break;\n x=x-it->second;\n mp2[i]->erase(it);\n it++;\n }*/\n for(++it;it!=mp2[i]->end() && x>=it->second;x=x-it->second,mp2[i]->erase(it++));\n if (it!=mp2[i]->end())\n it->second=it->second-x;\n }\n if (mp2[i]->size()>mp2[p[i]]->size())\n swap(mp2[i],mp2[p[i]]);\n for(auto it:*mp2[i])\n {\n auto num=mp2[p[i]]->insert(make_pair(it.first,0)).first;\n num->second=num->second+it.second;\n }\n }\n ll rasp=0;\n for(auto it:*mp2[1])\n rasp=rasp+it.second;\n printf(\"%lld\\n\",rasp);\nreturn 0;\n}\n", "src_uid": "d471aeb3d5b496b4d7a5cd2628574853"} {"source_code": "#include\n#include\nusing namespace std;\ntypedef long long ll;\nll data[50000];\n\nint sum=0;\nvoid creat(ll num,int digit)\n{\n\tif(digit>10)\n\t\treturn;\n\tdata[sum++]=num;\n\tcreat(num*10+4,digit+1);\n\tcreat(num*10+7,digit+1);\n\t\n};\n\n\n\n\nint main()\n{\n\tcreat(0,0);\n\tsort(data,data+sum);\n\tll l,r;\n\tcin>>l>>r;\n\tll count=0;\n\tfor(int i=1;true;i++)\n\t{\n\t\tif(l>r) break;\n\t\tif(data[i]>=l)\n\t\t{\n\t\t\tcount+= data[i]*(min(r,data[i])-l+1);\n\t\t\tl=data[i]+1;\n\t\t}\n\t}\n\tcout< \nusing namespace std; \ntypedef long long LL; \nLL n, nl, len, d[65], z, t, w, k = 1, ans; \nchar s[65]; \nint main() { \nscanf(\"%I64d%s\", &n, s); \nlen = strlen(s); \nfor (int i = n; i; nl++, i /= 10); \nfor (int i = len-1; i >= 0; i--) { \nsscanf(&s[i], \"%I64d\", &t); \nif (t < n && strlen(&s[i]) <= nl) { \nw = t; \n} else { \nif (0 == w) { \nd[z++] = w; \nwhile (s[i+1] == '0') \ni++; \ns[i] = 0; \n} else { \nd[z++] = w; \nwhile (s[i+1] == '0') \ni++; \ns[++i] = 0; \n} \n} \n} \nif (w) d[z++] = w; \nfor (int i = 0; i < z; i++, k *= n) { \n//printf(\"%I64d:%I64d\\n\", k, d[i]); \nans += k * d[i]; \n} \nprintf(\"%I64d\\n\", ans); \nreturn 0; \n}", "src_uid": "be66399c558c96566a6bb0a63d2503e5"} {"source_code": "#ifndef LOCAL\n#pragma GCC optimize(\"O3\")\n#endif\n#include \"bits/stdc++.h\"\nusing namespace std;\n#define sim template < class c\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; }\n//~ eni(!=) cerr << boolalpha << i; ris; }\neni(!=) cerr << 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\ntypedef long long ll;\n\nconst int AND = 0, OR = 1, NAND = 2, NOR = 3;\nconst int nax = 1005;\n\nstruct S {\n\tint type;\n\tS zmien() {\n\t\tS he;\n\t\the.type = type ^ 1;\n\t\treturn he;\n\t}\n\tvoid read() {\n\t\tstatic char sl[10];\n\t\tscanf(\"%s\", sl);\n\t\tstring s = string(sl);\n\t\tif(s == \"and\") type = AND;\n\t\telse if(s == \"or\") type = OR;\n\t\telse if(s == \"nand\") type = NAND;\n\t\telse if(s == \"nor\") type = NOR;\n\t\telse {\n\t\t\tcout << \"unknown type: \" << s << endl;\n\t\t\tassert(false);\n\t\t}\n\t}\n\tbool operator () (bool a, bool b) {\n\t\tif(type == AND) return a & b;\n\t\tif(type == OR) return a | b;\n\t\tif(type == NAND) return !(a & b);\n\t\tif(type == NOR) return !(a | b);\n\t\tassert(false);\n\t}\n};\n\nvoid read(pair> & p) {\n\tp.first.read();\n\tstatic char sl[105];\n\tscanf(\"%s\", sl);\n\tint n = strlen(sl);\n\tvector w;\n\tfor(int i = 0; i < n; ++i)\n\t\tif(sl[i] == 'x')\n\t\t\tw.push_back(i);\n\tassert((int) w.size() == 2);\n\tp.second = {w[0], w[1]};\n}\n\nvector w[nax];\n\nint main() {\n\tint n, m, k;\n\tscanf(\"%d%d%d\", &n, &m, &k);\n\tvector>> one(m), two(k);\n\tfor(int i = 0; i < m; ++i)\n\t\tread(one[i]);\n\tfor(int i = 0; i < k; ++i)\n\t\tread(two[i]);\n\t\n\tconst int M = 40 * 1000;\n\tvector, vector>> pre(M);\n\tfor(auto & p : pre) {\n\t\tvector a(n), b(m), c(k), d(k);\n\t\tfor(int i = 0; i < n; ++i) a[i] = rand() % 2;\n\t\tfor(int i = 0; i < m; ++i) b[i] = one[i].first(a[one[i].second.first], a[one[i].second.second]);\n\t\tfor(int i = 0; i < k; ++i) c[i] = two[i].first(b[two[i].second.first], b[two[i].second.second]);\n\t\tfor(int i = 0; i < k; ++i) d[i] = two[i].first.zmien()(b[two[i].second.first], b[two[i].second.second]);\n\t\tp = {c, d};\n\t}\n\tvector maybe(k, true);\n\tfor(auto & p : pre) {\n\t\tauto & c = p.first;\n\t\tauto & d = p.second;\n\t\tdebug() << imie(c);\n\t\tfor(int i = 0; i < k; ++i) if(c[i] & d[i]) maybe[i] = false;\n\t\tbool any = false;\n\t\tfor(int i = 0; i < k; ++i) if(maybe[i]) if(c[i] | d[i]) any = true;\n\t\tif(!any) {\n\t\t\tputs(\"-1\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tvector> e(k, vector(k));\n\t\n\tfor(auto & p : pre) {\n\t\tauto & c = p.first;\n\t\tauto & d = p.second;\n\t\tdebug() << imie(c);\n\t\tdebug() << imie(d);\n\t\tdebug();\n\t\tfor(int i = 0; i < k; ++i) if(maybe[i])\n\t\t\tfor(int j = i + 1; j < k; ++j) if(maybe[j])\n\t\t\t\tif((c[i] & d[j]) | (c[j] & d[i])) e[i][j] = e[j][i] = true;\n\t}\n\t\n\tfor(int i = 0; i < k; ++i)\n\t\tfor(int j = i + 1; j < k; ++j) if(e[i][j]) {\n\t\t\tw[i].push_back(j);\n\t\t\tw[j].push_back(i);\n\t\t\t//~ printf(\"%d %d\\n\", i, j);\n\t\t}\n\t\n\tint answer = 0;\n\tfor(int i = 0; i < k; ++i) if(!maybe[i]) ++answer;\n\tvector vis(k);\n\tvector, vector>> they;\n\tvector taken(k);\n\tfor(int i = 0; i < k; ++i) if(maybe[i] && !vis[i]) {\n\t\tvector A, B;\n\t\tvector kol{i};\n\t\tvector dist(k);\n\t\tvis[i] = true;\n\t\tfor(int j = 0; j < (int) kol.size(); ++j) {\n\t\t\tint a = kol[j];\n\t\t\tif(dist[a] % 2) A.push_back(a);\n\t\t\telse B.push_back(a);\n\t\t\tfor(int b : w[a]) if(!vis[b]) {\n\t\t\t\tvis[b] = true;\n\t\t\t\tdist[b] = dist[a] + 1;\n\t\t\t\tkol.push_back(b);\n\t\t\t}\n\t\t}\n\t\tif(A.size() < B.size()) swap(A, B);\n\t\t// bierzemy pierwsza\n\t\tthey.push_back({A, B});\n\t\tfor(int x : A) taken[x] = true;\n\t\t\n\t\t//~ printf(\"%d %d\\n\", A, B);\n\t\tanswer += (int) B.size();\n\t}\n\tbool yeah = true;\n\tfor(auto & p : pre) {\n\t\tauto & c = p.first;\n\t\tauto & d = p.second;\n\t\tbool any = false;\n\t\tfor(int i = 0; i < k; ++i) if(taken[i]) if(c[i] | d[i]) any = true;\n\t\tif(!any) {\n\t\t\tyeah = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tif(!yeah) for(pair, vector> p : they) {\n\t\tint by = 1000000;\n\t\tauto memo = taken;\n\t\tfor(int x : p.first) {\n\t\t\tassert(taken[x]);\n\t\t\ttaken[x] = false;\n\t\t}\n\t\tfor(int x : p.second) {\n\t\t\tassert(!taken[x]);\n\t\t\ttaken[x] = true;\n\t\t}\n\t\t\n\t\tbool tu = true;\n\t\tfor(auto & p : pre) {\n\t\t\tauto & c = p.first;\n\t\t\tauto & d = p.second;\n\t\t\tbool any = false;\n\t\t\tfor(int i = 0; i < k; ++i) if(taken[i]) if(c[i] | d[i]) any = true;\n\t\t\tif(!any) {\n\t\t\t\ttu = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(tu) by = min(by, (int) abs(int(p.first.size()) - int(p.second.size())));\n\t\t\n\t\ttaken = memo;\n\t\tanswer += by;\n\t}\n\tif(answer > k) answer = -1;\n\t\n\t\n\tprintf(\"%d\\n\", answer);\n\treturn 0;\n\t\n\t//~ int answer = -1;\n\tfor(int mask = 0; mask < (1 << k); ++mask) {\n\t\tbool ok = true;\n\t\tfor(int i = 0; i < k; ++i) if(mask & (1 << i)) if(!maybe[i]) ok = false;\n\t\tif(!ok) continue;\n\t\tfor(int rep = 0; rep < 200; ++rep) {\n\t\t\tvector a(n), b(m), c(k), d(k);\n\t\t\tfor(int i = 0; i < n; ++i) a[i] = rand() % 2;\n\t\t\tfor(int i = 0; i < m; ++i) b[i] = one[i].first(a[one[i].second.first], a[one[i].second.second]);\n\t\t\tfor(int i = 0; i < k; ++i) c[i] = two[i].first(b[two[i].second.first], b[two[i].second.second]);\n\t\t\tfor(int i = 0; i < k; ++i) d[i] = two[i].first.zmien()(b[two[i].second.first], b[two[i].second.second]);\n\t\t\t//~ debug() << imie(c);\n\t\t\t//~ debug() << imie(d);\n\t\t\t//~ debug();\n\t\t\tbool raz = false, dwa = false;\n\t\t\tfor(int i = 0; i < k; ++i) if(mask & (1 << i)) {\n\t\t\t\tif(c[i]) raz = true;\n\t\t\t\tif(d[i]) dwa = true;\n\t\t\t}\n\t\t\tif(raz && dwa) ok = false;\n\t\t\tif(!raz && !dwa) ok = false;\n\t\t\tif(!ok) break;\n\t\t\t//~ for(int i = 0; i < k; ++i)\n\t\t\t\t//~ if(c[i] && d[i])\n\t\t\t\t\t//~ maybe[i] = false;\n\t\t}\n\t\tif(ok) answer = max(answer, __builtin_popcount(mask));\n\t\t//~ debug() << imie(maybe);\n\t}\n\tassert(answer != -1);\n\t\n\t//~ if(answer == -1) printf(\"%d\\n\", answer);\n\t//~ else printf(\"%d\\n\", k - answer);\n\t\n\tprintf(\"%d\\n\", k - answer);\n}\n", "src_uid": "2f80021e297dd57e306d2a50c3590bea"} {"source_code": "#include \n#include \n#include \nusing namespace std;\nint main()\n{\n\tint a, k, A[1000], a1 = 0, a2 = 0, o, l = 0, S = 0, m = 0,r=0,q1=0,q2=0; string c, s[101],x;\n\tcin >> a >> k;\n\to = a / k;\n\tfor (int i = 0; i < a; i++)\n\t\tcin >> A[i];\n\tfor (int i = 0; i < a; i++)\n\t{\n\n\t\tif (A[i] == 2) a2++;\n\t\tif (A[i] == 1) a1++;\n\t}\n\tfor (int i = 0; i < a; i++)\n\t{\n\t\tif (A[i] == 2) c += '2';\n\t\telse c += '1';\n\t}\n\tfor (int i = 0; i < o; i++)\n\t{\n\t\ts[i] = c.substr(l, k);\n\t\tl += k;\n\t}\n\n\tfor (int i = 0; i < o; i++)\n\t{\n\t\tS = 0;\n\t\tfor (int j = i; j < o; j++)\n\t\t{\n\t\t\tif (s[i] == s[j]) S++;\n\n\t\t}\n\t\tif (S > m) m = S;\n\t}\n\tfor (int i = 0; i < o; i++)\n\t{\n\t\tS = 0;\n\t\tfor (int j = i; j < o; j++)\n\t\t{\n\t\t\tif (s[i] == s[j]) S++;\n\n\t\t}\n\t\tif (S == m) { x= s[i]; }\n\n\t}\n\tif (m == 1)\n\t{\n\t\tx = \"\";\n\t\t\tfor (int j = 0; j < k; j++)\n\t\t\t\n\t\t\t{\n\t\t\t\tq1 = 0, q2 = 0;\n\t\t\t\tfor (int i = 0; i < o; i++)\n\t\t\t{\n\t\t\t\tif (s[i][j] == '1') q1++;\n\t\t\t\telse q2++;\n\t\t\t}\n\t\t\tif (q1 > q2) x += '1';\n\t\t\telse x += '2';\n\t\t}\n\n\t\t\n\n\t}\n\n\tfor (int i = 0; i < o; i++)\n\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\nusing namespace std;\n\nbool check0(string s)\n{ bool ok=1;\n if(s==\"\") return 0;\n for(int i=0;i='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')||s[i]=='_'||isdigit(s[i])) continue;\n else { ok=0; break; }\n }\nreturn ok;\n}\n\nbool check(string s)\n{ int i,j,k,p,P;\n string s1,s2,s3,str;\n int p1=s.find('@'),p2=s.find('/');\n s1=s.substr(0,p1); s2=s.substr(p1+1,p2-p1-1); \n if(p2!=-1) s3=s.substr(p2+1);\n else s3=\"\";\n if(s1.length()<1||s1.length()>16||s2.length()<1||s2.length()>32||((s3.length()<1||s3.length()>16)&&p2!=-1)) return 0;\n if(!check0(s1)||(!check0(s3)&&s3!=\"\")) return 0;\n if(s2[s2.length()-1]=='.') return 0;\n p=s2.find('.'); P=-1;\n if(p!=-1) \n { str=s2.substr(0,p); P=p;\n if(!check0(str)) return 0;\n }\n bool ok=0;\n if(p==-1) \n { if(!check0(s2)) return 0;\n ok=1;\n }\n while((p=s2.find('.',p+1))!=-1)\n { str=s2.substr(P+1,p-P-1); P=p;\n if(!check0(str)) return 0;\n ok=1;\n }\n if(P!=-1){\n str=s2.substr(P+1);\n if(check0(str)) ok=1;\n }\nreturn ok;\n}\n\nint main()\n{ string s;\n while(getline(cin,s))\n { if(check(s)) cout<<\"YES\\n\";\n else cout<<\"NO\\n\";\n }\nreturn 0; \n}", "src_uid": "2a68157e327f92415067f127feb31e24"} {"source_code": "#include \n#include \n#include \n#include \n#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntypedef tree,rb_tree_tag,tree_order_statistics_node_update> ordered_set;\n\nlong long int power(long long int base,long long int p)\n{\n long long int ans=1;\n while(p)\n {\n if(p&1)\n ans*=base,p--;\n else\n base*=base,p/=2;\n }\n return ans;\n}\nlong long int sec_part(long long int n,long long int k)\n{\n long long int curr=0;\n long long int p=1;\n while(n/power(k,p))\n {\n curr+=(n/power(k,p));\n p++;\n }\n return curr;\n}\nvoid go()\n{\n long long int n,k;\n cin>>n>>k;\n long long int st=0;\n long long int en=n;\n long long int m;\n map h;\n while(st<=en)\n {\n long long int mid=(st+en)/2;\n //cout< n)\n en=mid;\n else if(mid + sec_part(mid,k) < n)\n st=mid;\n h[mid]++;\n if(h[mid] > 10)\n break;\n }\n cout<>t;\n //while(t--)\n go();\n return 0;\n}\n", "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n int x[2],y[2],z[2],i;\n for(i=0;i<2;i++)\n cin>>x[i]>>y[i]>>z[i];\n if(x[0]!=x[1]&&y[0]!=y[1]&&z[0]!=z[1])\n cout<<\"NO\";\n else\n cout<<\"YES\";\n return(0);\n}\n", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"} {"source_code": "#include\n#include \n#include \nusing namespace std;\nusing namespace __gnu_pbds;\ntypedef long long ll;\ntypedef vector vl;\ntypedef pair pl;\n#define po pop_back\n#define pb push_back\n#define mk make_pair\n#define lw lower_bound\n#define up upper_bound\n#define ff first\n#define ss second\n#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);\n#define MOD 1000000007\n#define MAX 1e18 \n#define MIN -1e18\n#define rep(i,a,b) for(ll i=a;i<=b;i++)\n#define per(i,a,b) for(ll i=a;i>=b;i--)\n#define con continue\n#define freopen freopen(\"input.txt\", \"r\", stdin);freopen(\"output.txt\", \"w\", stdout);\n#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628\ntypedef tree, rb_tree_tag, tree_order_statistics_node_update> indexed_set;\n\nll a,b,c[1234567],d[5234567],c1[1234][1234],e[1234567],n,j,i,l,r,x,y,k,ans,sum;\nbool used[3234567];\nll T;\nvector v1,v[1234567];\nstring s,s1[1234567],ss;\nchar ch[1234][1234];\npl p[1234567];\npriority_queue pq;\nll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};\nmap mp,mp1;\nmap ms;\nqueue q;\nset st;\nll N=5e6+1;\nint main(){ \n ll a,b,c; cin>>a>>b>>c;\n ll x,y,z; cin>>x>>y>>z;\n ll x1=max(a-x,0ll)/2+max(b-y,0ll)/2+max(c-z,0ll)/2;\n ll x2=max(x-a,0ll)+max(y-b,0ll)+max(z-c,0ll);\n if (x1>=x2) cout<<\"Yes\";\n else cout<<\"No\";\n}", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"} {"source_code": "#include\n#include\n#include\nusing namespace std;\ntypedef long long LL;\nconst int P=998244353;\nconst int N=2008;\nint p0[N],p1[N],cp[N][N],strong[N],ans[N];\nint ksm(int a,int b){\n\tint ans=1;\n\twhile(b){\n\t\tif(b&1) ans=1LL*ans*a%P;\n\t\tb>>=1;\n\t\ta=1LL*a*a%P;\n\t}\n\treturn ans;\n}\nint main(){\n\tint n,a,b,win,lost;\n\tscanf(\"%d%d%d\",&n,&a,&b);\n\tp0[0]=p1[0]=1;\n\tlost=1LL*a*ksm(b,P-2)%P,win=1LL*(b-a)*ksm(b,P-2)%P;\n\tfor(int i=1;i<=n;++i) p0[i]=1LL*p0[i-1]*lost%P,p1[i]=1LL*p1[i-1]*win%P;\n\tfor(int i=0;i<=n;++i) {\n\t\tcp[i][0]=1;\n\t\tfor(int j=1;j<=i;++j) cp[i][j]=1LL*(1LL*cp[i-1][j-1]*p0[i-j]+1LL*cp[i-1][j]*p1[j])%P;\n\t}\n\tfor(int i=1;i<=n;++i) strong[i]=1;\n\tfor(int i=2;i<=n;++i) for(int j=1;j\nusing namespace std;\nint n;\n\nint cnt=0;\nint res = 0;\n\nvoid f(int a, int b, long long w, const int v, const int k, const bool ua, const bool ub)\n{\n if (v == k)\n {\n if (w <= n && ua && ub)\n {\n res++;\n cnt++;\n //cout<> n;\n SoLvE();\n return 0;\n}", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4"} {"source_code": "#include\n\nusing namespace std; \n\n#define nl \"\\n\"\n#define sp \" \"\n#define pb push_back\n#define int long long\n#define ins insert\n#define hashset unordered_set\n#define hashmap unordered_map\n#define llMin LLONG_MIN\n#define llMax LLONG_MAX\n#define db long double\n\nconst int mod = 1e9 + 7;\n\nsigned main(){\n ios_base::sync_with_stdio(0); \n cin.tie(0); cout.tie(0);\n int k; cin >> k; vector v(10, 0);\n vector arr;\n for (int i = 0; i < 4; i++){\n string s; cin >> s; arr.pb(s);\n }\n for (int i = 0; i < 4; i++){\n for (int tmp = 0; tmp < 4; tmp++){\n if (arr[i][tmp] >= '0' && arr[i][tmp] <= '9'){\n v[arr[i][tmp] - '0']++;\n }\n }\n }\n bool flag = true;\n for (auto x : v){\n if (x > 2*k){\n flag = false;\n }\n }\n if (flag == true) cout << \"YES\";\n else cout << \"NO\";\n}\n", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"} {"source_code": "#include\nusing namespace std;\n#include\nusing namespace __gnu_pbds;\n#define ll long long\n\ntemplate ostream& operator<<(ostream &os,vector V){\n\tos<<\"[ \";for(auto v:V)os< ostream& operator<<(ostream &os,pair P){\n\treturn os<<\"(\"<\nll mxm(ll a,Args... args){return max(a,mxm(args...));}\nll mnm(){return LLONG_MAX;}\ntemplate\nll mnm(ll a,Args... args){return min(a,mnm(args...));}\n\n#define TRACE\n#ifdef TRACE\n#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)\ntemplate\nvoid __f(const char* name,Arg1&& arg1){\n\tcout<\nvoid __f(const char* names,Arg1&& arg1,Args&&... args){\n\t\tconst char* comma=strchr(names+1,',');cout.write(names,comma-names)<<\" : \"<\n#define pll pair\n#define ii pair\n#define vi vector\n#define vpll vector\n#define vii vector\n#define vvi vector\n#define vvll vector\n#define vvpll vector\n#define vvii vector\n#define vld vector\n#define vvld vector\n#define I insert\n#define F first\n#define S second\n#define pb push_back\n#define all(x) x.begin(),x.end()\n#define endl \"\\n\"\n#define siz(a)\t((int)(a).size())\n\nconst int mod=1e9+7;\ninline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}\ninline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}\ninline int mul(int a,int b){return (a*1ll*b)%mod;}\ninline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}\ninline int inv(int a){return power(a,mod-2);}\n\nconst int N=1e5+5;\nconst int INF = 999999999; \n// vertices are 0-indexed\nstruct graph {\n typedef int flow_type; // **** flow type ****\n typedef int cost_type; // **** cost type ****\n struct edge {\n int src, dst;\n flow_type capacity, flow;\n cost_type cost;\n size_t rev;\n };\n vector edges;\n void add_edge(int src, int dst, flow_type cap, cost_type cost) {\n adj[src].push_back({src, dst, cap, 0, cost, adj[dst].size()});\n adj[dst].push_back({dst, src, 0, 0, -cost, adj[src].size()-1});\n }\n int n;\n vector> adj;\n graph(int n) : n(n), adj(n) { }\n\n pair min_cost_max_flow(int s, int t) {\n flow_type flow = 0;\n cost_type cost = 0;\n\n for (int u = 0; u < n; ++u) // initialize\n for (auto &e: adj[u]) e.flow = 0;\n\n vector p(n, 0);\n\n auto rcost = [&](edge e) { return e.cost + p[e.src] - p[e.dst]; };\n for (int iter = 0; ; ++iter) {\n vector prev(n, -1); prev[s] = 0;\n vector dist(n, INF); dist[s] = 0;\n if (iter == 0) { // use Bellman-Ford to remove negative cost edges\n vector count(n); count[s] = 1;\n queue que; \n for (que.push(s); !que.empty(); ) {\n int u = que.front(); que.pop();\n count[u] = -count[u];\n for (auto &e: adj[u]) {\n if (e.capacity > e.flow && dist[e.dst] > dist[e.src] + rcost(e)) {\n dist[e.dst] = dist[e.src] + rcost(e);\n prev[e.dst] = e.rev;\n if (count[e.dst] <= 0) {\n count[e.dst] = -count[e.dst] + 1;\n que.push(e.dst);\n }\n }\n }\n }\n for(int i=0;i node;\n priority_queue, greater> que;\n que.push({0, s});\n while (!que.empty()) {\n node a = que.top(); que.pop();\n if (a.S == t) break;\n if (dist[a.S] > a.F) continue;\n for (auto e: adj[a.S]) {\n if (e.capacity > e.flow && dist[e.dst] > a.F + rcost(e)) {\n dist[e.dst] = dist[e.src] + rcost(e);\n prev[e.dst] = e.rev;\n que.push({dist[e.dst], e.dst});\n }\n }\n }\n }\n if (prev[t] == -1) break;\n\n for (int u = 0; u < n; ++u) \n if (dist[u] < dist[t]) p[u] += dist[u] - dist[t];\n\n function augment = [&](int u, flow_type cur) {\n if (u == s) return cur;\n edge &r = adj[u][prev[u]], &e = adj[r.dst][r.rev];\n flow_type f = augment(e.src, min(e.capacity - e.flow, cur));\n e.flow += f; r.flow -= f;\n return f;\n };\n flow_type f = augment(t, INF);\n flow += f;\n cost += f * (p[t] - p[s]);\n }\n return {flow, cost};\n }\n};\n\nint main()\n{\n\tios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<>n>>m>>k>>c>>d;\n\tvi cur(n);for(int i=0;i>x;++cur[x-1];\n\t}\n\tvii ed(m);for(int i=0;i>ed[i].F>>ed[i].S,--ed[i].F,--ed[i].S;\n\tint nod=max(n,k);\n\tgraph g(1+2*nod*nod);\n\tfor(int i=0;i\n#include\nusing namespace std;\n\nint main() {\n int a, b, l, r, c, pl, pr, cl, cr;\n cin >> a >> b >> l >> r;\n c = a + b;\n //判断下标是否在同一个AB组合内\n cl = --l / c;\n cr = --r / c;\n //获取AB分别对应的索引\n pl = l % c;\n pr = r % c;\n if (cl == cr) {\n if (pl < a && pr < a) {\n cout << pr - pl + 1 << endl;\n } else if (pl < a && pr >= a) {\n cout << a - pl << endl;\n } else {\n cout << 1 << endl;\n }\n } else if (a <= b) {\n if (cl < cr - 1) {\n cout << a + 1 << endl;\n } else {\n if (pr >= a) {\n cout << a + 1 << endl;\n } else {\n if (pl >= a) {\n cout << pr + 1 + 1 << endl;\n } else {\n int left = a - pl;\n int right = pr + 1;\n if (left + right > a) {\n cout << a + (right == a) << endl;\n } else {\n cout << left + right + (right == a) << endl;\n }\n }\n }\n\n }\n } else {\n int d = a - b;\n if (cl == cr - 1) {\n if (pr >= a && pl >= a) {\n cout << a + 1 << endl;\n } else if (pr < a && pl >= a) {\n cout << pr + 1 + 1 << endl;\n } else if (pr >= a && pl < a) {\n cout << min((a + a - pl), a + a - b) << endl;\n } else if (pr < a && pl < a) {\n if (pl > b) {\n cout << pr + 1 + a - pl << endl;\n } else {\n cout << pr + 1 + a - b << endl;\n }\n }\n// else {\n// int right = min(pr + 1, a);\n// int left = max(1, min(a - b, a - pl));\n// cout << right + left << endl;\n// }\n\n } else if (cl == cr - 2) {\n cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl)));\n } else {\n cout << a + d;\n }\n }\n\n}\n\n", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec"} {"source_code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx\")\n#pragma GCC optimize(\"unroll-loops\")\n\n#include\nusing namespace std;\n\nnamespace FastIO {\n struct Reader {\n private:\n FILE* file; std::vector buffer; int pos; bool was;\n void read() {\n if (!buffer.empty()) {\n buffer.resize(fread(&buffer[0], 1, (int)buffer.size(), file)); pos = 0; \n }\n }\n public:\n Reader(FILE* file_ = stdin, const int size_ = 1 << 16)\n : file(file_), buffer(size_, '\\0'), pos(size_), was(true) { }\n operator bool() const { return was; }\n char getChar() {\n if (pos == (int)buffer.size()) { read(); }\n if (pos == (int)buffer.size()) { was = false; return EOF; } \n else { was = true; return buffer[pos++]; }\n }\n std::string getStr() {\n char c = ' ';\n while (std::isspace(c)) { c = getChar(); }\n std::string answ;\n while (c != EOF && !std::isspace(c)) { answ.push_back(c); c = getChar(); }\n was = !answ.empty();\n return answ;\n }\n std::string getLine() {\n char c = '\\n';\n while (c == '\\n') { c = getChar(); }\n std::string answ;\n while (c != '\\n' && c != EOF) { answ.push_back(c); c = getChar(); }\n was = !answ.empty();\n return answ;\n }\n template T getInt() {\n char c = '?';\n while (!(c == '-' || ('0' <= c && c <= '9') || c == EOF)) { c = getChar(); }\n bool positive = true;\n if (c == '-') { positive = false; c = getChar(); }\n T answ(0);\n bool flag = false;\n while ('0' <= c && c <= '9') { flag = true; (answ *= 10) += (c - '0'); c = getChar(); }\n was = flag;\n return positive ? answ : -answ;\n }\n template T getReal() {\n bool flag = false;\n char c = '?';\n while (!(c == '-' || ('0' <= c && c <= '9') || c == EOF)) { c = getChar(); }\n bool positive = (c != '-');\n if (c == '-') { c = getChar(); }\n long long first = 0;\n while ('0' <= c && c <= '9') { flag = true; (first *= 10) += (c - '0'); c = getChar(); }\n was = flag;\n if (c != '.') { return T(positive ? first : -first); }\n c = getChar();\n long long second = 0, pow = 1;\n while ('0' <= c && c <= '9') { (second *= 10) += (c - '0'); c = getChar(); pow *= 10; }\n T answ = first + (T)second / (T)pow;\n return positive ? answ : -answ;\n }\n };\n \n Reader& operator>>(Reader& reader, char& c) { return c = reader.getChar(), reader; }\n \n Reader& operator>>(Reader& reader, std::string& s) { return s = reader.getStr(), reader; }\n \n template typename std::enable_if::value, Reader&>::type\n operator>>(Reader& reader, T& t) { return t = reader.getReal(), reader; }\n \n template typename std::enable_if::value, Reader&>::type\n operator>>(Reader& reader, T& t) { return t = reader.getInt(), reader; }\n \n template Reader& operator>>(Reader& reader, std::vector& vec) {\n for (auto &it : vec) { reader >> it; }\n return reader;\n }\n \n struct Writer {\n private:\n FILE* file; std::vector buffer; int pos;\n int defaultPrecision, defaultWidth; char defaultFill;\n public:\n Writer(FILE* file_ = stdout, const int size_ = 1 << 16) \n : file(file_), buffer(size_, '\\0'), pos(0), defaultPrecision(6), defaultWidth(0), defaultFill(' ') { }\n ~Writer() { flush(); }\n void flush() { putChar(EOF); }\n void setprecision(int precision) { defaultPrecision = precision; }\n void setw(int width) { defaultWidth = width; }\n void setfill(char fill) { defaultFill = fill; }\n int getPrecision() const { return defaultPrecision; }\n int getWidth() const { return defaultWidth; }\n char getFill() const { return defaultFill; }\n void putChar(char c) {\n if (pos == (int)buffer.size() || c == EOF) { \n fwrite(&buffer[0], 1, pos, file); pos = 0; \n }\n if (c != EOF) { buffer[pos++] = c; }\n }\n void putStr(const std::string& s) { for (auto it : s) putChar(it); }\n template void putInt(T value, int width = 0, char fill = ' ') {\n bool positive = !(value < 0);\n if (value < 0) { value = -value; }\n char buf[24]; int p = 0;\n do { buf[p++] = char(value % 10 + '0'); value /= 10; } while (value > 0);\n if (!positive) { buf[p++] = '-'; }\n while (p < width) buf[p++] = fill;\n while (p > 0) putChar(buf[--p]);\n }\n template void putReal(T value, int precision = 6, int width = 0, char fill = ' ') {\n putInt((long long)value, width - precision - 1, fill);\n value = std::abs(value-(long long)value);\n if (precision == 0) { return; }\n putChar('.');\n #define PRINT_PART(cnt, pow) \\\n while (precision >= cnt) { \\\n value *= pow; \\\n putInt((int)value, cnt, '0'); \\\n value -= (int)value; \\\n precision -= cnt; \\\n }\n PRINT_PART(6,1000000)\n PRINT_PART(3,1000)\n PRINT_PART(1,10)\n #undef PRINT_PART\n }\n };\n \n Writer& operator<<(Writer& writer, const char c) { return writer.putChar(c), writer; }\n \n Writer& operator<<(Writer& writer, const std::string& s) { return writer.putStr(s), writer; }\n \n template typename std::enable_if::value, Writer&>::type\n operator<<(Writer& writer, const T& t) {\n writer.putReal(t, writer.getPrecision(), writer.getWidth(), writer.getFill());\n return writer; \n }\n \n template typename std::enable_if::value, Writer&>::type\n operator<<(Writer& writer, const T& t) { \n writer.putInt(t, writer.getWidth(), writer.getFill());\n return writer;\n }\n}\n\n\nconst int N = 3004;\ndouble dp[2][N];\nusing namespace FastIO;\nint main() {\n FastIO::Reader fin;\n FastIO::Writer fout;\n int n, k; fin >> n >> k;\n for (int p = 1; p <= n; p++) {\n int x; fin >> x;\n double s = 0;\n int cur = p & 1;\n int pre = cur ^ 1;\n for (int j = 1; j <= k; j++) {\n dp[cur][j] = dp[pre][j];\n }\n for (int i = 1; i <= x; i++) {\n int z; fin >> z;\n s += z;\n for (int j = i; j <= k; j++) {\n dp[cur][j] = max(dp[pre][j - i] + s, dp[cur][j]);\n }\n }\n }\n fout << (int64_t)max(dp[0][k],dp[1][k]) << '\\n';\n}\n", "src_uid": "9e9d4f58ebd8293025ab8004aeb8d343"} {"source_code": "#include\nusing namespace std;\n__int64 a,b,x,y,k;\nmain(){\n cin>>a>>b>>x>>y;\n k=__gcd(x,y);\n x/=k;y/=k;\n cout<\nusing namespace std;\nint main()\n{\n int long long a,b,c;\n cin>>a>>b>>c;\n cout<<((a+b-1)*(c-1)+a*b)<\nusing namespace std;\nint a,b;\nint main(){\n\tcin>>a>>b;\n\tif(a==0&&b==0){cout<<\"NO\";return 0;}\n\tif(a==b||a-b==1 ||a-b== -1)cout<<\"YES\";\n\telse \n\tcout<<\"NO\";\n}\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\n#define ll long long\nint main()\n{\n int n,x,y,q;\n while(~scanf(\"%d%d%d\",&n,&x,&y))\n {\n if(n*y%100==0)\n q=n*y/100;\n else\n q=n*y/100+1;\n if(q>=x)\n printf(\"%d\\n\",q-x);\n else\n puts(\"0\");\n }\n return 0;\n}\n/*2018-07-19 19:50:22.055*/", "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"source_code": "#include\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef pair pll;\nconst int mn=1e5+10;\nll x[mn],y[mn],d[mn];\ninline ld sq(ld x){return x*x;}\ninline ll sq(ll x){return x*x;}\nld eps=1e-8;\nld i1x,i1y,i2x,i2y;\nvectorans;\nvoid idk(ll xx,ll yy,int i,int n){\n if(sq(xx-x[0])+sq(yy-y[0])!=d[i])return;\n vectorv;\n for(int j=0;jr1+r2+eps)return;\n ld t=atan2(y2-y1,x2-x1);\n ld p=(r12+dis2-r22)/2/r1/dis;\n if(p>1)p=1;\n if(p<-1)p=-1;\n ld k=acos(p);\n i1x=x1+r1*cos(t+k);\n i1y=y1+r1*sin(t+k);\n i2x=x1+r1*cos(t-k);\n i2y=y1+r1*sin(t-k);\n\n if(fabs(i1x)+fabs(i1y)<1e9)for(int j=-6;j<=6;j++){for(int k=-6;k<=6;k++) {\n idk((ll)i1x+j, (ll)i1y+k, i, n);\n }}\n if(fabs(i2x)+fabs(i2y)<1e9)for(int j=-6;j<=6;j++){for(int k=-6;k<=6;k++) {\n idk((ll)i2x+j, (ll)i2y+k, i, n);\n }}\n}\n\nint main(){\n int n;\n scanf(\"%d\",&n);\n for(int i=0;i\n#include \n#include \n#include \n\nusing namespace std;\nusing namespace __gnu_pbds;\nusing namespace __gnu_cxx;\n \ntypedef long long ll;\ntypedef long double ld;\ntypedef complex cd;\n\ntypedef pair pi;\ntypedef pair pl;\ntypedef pair pd;\n\ntypedef vector vi;\ntypedef vector vd;\ntypedef vector vl;\ntypedef vector vpi;\ntypedef vector vpl;\ntypedef vector vcd;\n\ntemplate using Tree = tree, rb_tree_tag,tree_order_statistics_node_update>;\n\n#define FOR(i, a, b) for (int i = (a); i < (b); i++)\n#define F0R(i, a) for (int i = 0; i < (a); i++)\n#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)\n#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)\n#define trav(a, x) for (auto& a : x)\n\n#define mp make_pair\n#define pb push_back\n#define f first\n#define s second\n#define lb lower_bound\n#define ub upper_bound\n\n#define sz(x) (int)x.size()\n#define all(x) begin(x), end(x)\n#define rsz resize\n\nconst int MOD = 1000000007; // 998244353\nconst ll INF = 1e18;\nconst int MX = 200005;\nconst ld PI = 4*atan((ld)1);\n\ntemplate void ckmin(T &a, T b) { a = min(a, b); }\ntemplate void ckmax(T &a, T b) { a = max(a, b); }\n\nnamespace input {\n template void re(complex& x);\n template void re(pair& p);\n template void re(vector& a);\n template void re(array& a);\n\n template void re(T& x) { cin >> x; }\n void re(double& x) { string t; re(t); x = stod(t); }\n void re(ld& x) { string t; re(t); x = stold(t); }\n template void re(Arg& first, Args&... rest) { \n re(first); re(rest...); \n }\n\n template void re(complex& x) { T a,b; re(a,b); x = cd(a,b); }\n template void re(pair& p) { re(p.f,p.s); }\n template void re(vector& a) { F0R(i,sz(a)) re(a[i]); }\n template void re(array& a) { F0R(i,SZ) re(a[i]); }\n}\n\nusing namespace input;\n\nnamespace output {\n template void pr(const pair& x);\n template void pr(const array& x);\n template void pr(const vector& x);\n template void pr(const set& x);\n template void pr(const map& x);\n\n template void pr(const T& x) { cout << x; }\n template void pr(const Arg& first, const Args&... rest) { \n pr(first); pr(rest...); \n }\n\n template void pr(const pair& x) { \n pr(\"{\",x.f,\", \",x.s,\"}\"); \n }\n template void prContain(const T& x) {\n pr(\"{\");\n bool fst = 1; for (const auto& a: x) pr(!fst?\", \":\"\",a), fst = 0; // const needed for vector\n pr(\"}\");\n }\n template void pr(const array& x) { prContain(x); }\n template void pr(const vector& x) { prContain(x); }\n template void pr(const set& x) { prContain(x); }\n template void pr(const map& x) { prContain(x); }\n \n void ps() { pr(\"\\n\"); }\n template void ps(const Arg& first) { \n pr(first); ps(); // no space at end of line\n }\n template void ps(const Arg& first, const Args&... rest) { \n pr(first,\" \"); ps(rest...); // print w/ spaces\n }\n}\n\nusing namespace output;\n\nnamespace io {\n void setIn(string s) { freopen(s.c_str(),\"r\",stdin); }\n void setOut(string s) { freopen(s.c_str(),\"w\",stdout); }\n void setIO(string s = \"\") {\n ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O\n if (sz(s)) { setIn(s+\".in\"), setOut(s+\".out\"); } // for USACO\n }\n}\n\nusing namespace io;\n\ntemplate T invGeneral(T a, T b) {\n a %= b; if (a == 0) return b == 1 ? 0 : -1;\n T x = invGeneral(b,a); \n return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;\n}\n\ntemplate struct modular {\n T val; \n explicit operator T() const { return val; }\n modular() { val = 0; }\n modular(const ll& v) { \n val = (-MOD <= v && v <= MOD) ? v : v % MOD;\n if (val < 0) val += MOD;\n }\n \n // friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }\n friend void pr(const modular& a) { pr(a.val); }\n friend void re(modular& a) { ll x; re(x); a = modular(x); }\n \n friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }\n friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }\n friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }\n\n modular operator-() const { return modular(-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 = (ll)val*m.val%MOD; return *this; }\n friend modular pow(modular a, ll p) {\n modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;\n return ans;\n }\n friend modular inv(const modular& a) { \n auto i = invGeneral(a.val,MOD); assert(i != -1);\n return i;\n } // equivalent to return exp(b,MOD-2) if MOD is prime\n modular& operator/=(const modular& m) { return (*this) *= inv(m); }\n \n friend modular operator+(modular a, const modular& b) { return a += b; }\n friend modular operator-(modular a, const modular& b) { return a -= b; }\n friend modular operator*(modular a, const modular& b) { return a *= b; }\n \n friend modular operator/(modular a, const modular& b) { return a /= b; }\n};\n\ntypedef modular mi;\ntypedef pair pmi;\ntypedef vector vmi;\ntypedef vector vpmi;\n\nmt19937 rng(chrono::steady_clock::now().time_since_epoch().count());\n\nint n,k, mob[100005];\nmi in[100005];\nmi ans;\nbool comp[MX];\n\nmi solve(int g, int m) {\n\t// i*g divides both a and b\n\tint y = n%g; \n\tint x = g-y;\n\tint z = (n-1)/(m*g); assert(z); // (1 to z) * (m*g)\n\tmi tmp = 0;\n\tFOR(sum,2,2*z+1) {\n\t\tint p = min(sum-1,2*z+1-sum);\n\t\tint eq = max(1,sum*m-n/g)*x+max(1,sum*m-n/g-1)*y;\n\t\ttmp += p*in[n-eq];\n\t}\n\treturn tmp;\n}\n\nint main() {\n setIO(); re(n,k);\n in[0] = 1; in[1] = mi(1)/k;\n FOR(i,2,n+1) in[i] = in[1]*in[i-1];\n FOR(i,1,n+1) mob[i] = 1;\n FOR(i,2,n+1) if (!comp[i]) {\n \tfor (int j = 2*i; j <= n; j += i) comp[j] = 1;\n \tfor (int j = i; j <= n; j += i) {\n \t\tif (j/i % i == 0) mob[j] = 0;\n \t\telse mob[j] *= -1;\n \t}\n }\n FOR(g,1,n) {\n \tfor (int i = 1; i*g < n; i ++) if (mob[i])\n \t\tans += mob[i]*solve(g,i);\n }\n ps(ans);\n // FOR(i,1,21) ps(i,comp[i],mob[i]);\n}\n\n/* stuff you should look for\n * int overflow, array bounds\n * special cases (n=1?), set tle\n * do smth instead of nothing and stay organized\n*/", "src_uid": "be32c7b2fd197c3247d11aed25c3cc0d"} {"source_code": "#include \nusing namespace std;\nint p[64],t[64];\nint tf[64],tr[64];\nint main(){\n int n,c;\n cin>>n>>c;\n for(int i=0;i>p[i];\n }\n for(int i=0;i>t[i];\n }\n int s1 = 0,s2 = 0;\n tf[0] = t[0];\n tr[n-1] = t[n-1];\n \n for(int i=1,j=n-2;i s2)cout<<\"Limak\\n\";\n else if(s1 == s2)cout<<\"Tie\\n\";\n else cout<<\"Radewoosh\\n\";\n}", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"} {"source_code": "# include \nusing namespace std;\ntypedef long long LL;\nconst LL mod = 1e9+7;\nLL a[2000],dp[2000];\nLL qmod(LL y)\n{\n LL res = 1, two = (LL)2;\n for(;y;y>>=1)\n {\n if(y&1) res = res*two%mod;\n two = two*two%mod;\n }\n return res;\n}\nint main()\n{\n LL x, y;\n int cnt=0;\n scanf(\"%lld%lld\",&x,&y);\n if(y%x) return 0*puts(\"0\");\n for(LL i=1; i<=sqrt(y); ++i)\n {\n if(y%i==0)\n {\n if(i%x==0) a[++cnt] = i;\n if(i*i!=y&&y/i%x==0) a[++cnt] = y/i;\n }\n }\n sort(a+1, a+1+cnt);\n for(int i=cnt; i>0; --i)\n {\n dp[i] = qmod(y/a[i]-1);\n for(int j=i+1; j<=cnt; ++j)\n if(a[j]%a[i]==0)\n dp[i] = ((dp[i]-dp[j])%mod+mod)%mod;\n }\n printf(\"%lld\\n\",dp[1]);\n return 0;\n}\n", "src_uid": "de7731ce03735b962ee033613192f7bc"} {"source_code": "#include \nusing namespace std;\ntypedef bool boolean;\n\nconst int inf = (signed) (~0u >> 1);\n\ntypedef class Edge {\n\tpublic:\n\t\tint ed, nx, r;\n\n\t\tEdge() {\t}\n\t\tEdge(int ed, int nx, int r) : ed(ed), nx(nx), r(r) {\t}\n} Edge;\n\ntypedef class MapManager {\n\tpublic:\n\t\tint *h;\n\t\tvector E;\n\n\t\tMapManager() {\t}\n\t\tMapManager(int n) {\n\t\t\th = new int[(n + 1)];\n\t\t\tmemset(h, -1, sizeof(int) * (n + 1));\n\t\t}\n\t\t~MapManager() {\n\t\t\tdelete[] h;\n\t\t\tE.clear();\n\t\t}\n\n\t\tvoid add_edge(int u, int v, int r) {\n\t\t\tE.emplace_back(v, h[u], r);\n\t\t\th[u] = (signed) E.size() - 1;\n\t\t}\n\t\tvoid add_arc(int u, int v, int r) {\n\t\t\tadd_edge(u, v, r);\n\t\t\tadd_edge(v, u, 0);\n\t\t}\n\t\tEdge& operator [] (int p) {\n\t\t\treturn E[p];\n\t\t}\n} MapManager;\n\ntypedef class Network {\n\tpublic:\n\t\tint S, T;\n\t\tMapManager g;\n\n\t\tint *d, *h;\n\n\t\tNetwork(int S, int T) : S(S), T(T), g(T) {\n\t\t\td = new int[(T + 1)];\n\t\t\th = new int[(T + 1)];\n\t\t}\n\t\t~Network() {\n\t\t\tdelete[] d;\n\t\t\tdelete[] h;\n\t\t}\n\n\t\tboolean bfs() {\n\t\t\tqueue Q;\n\t\t\tmemset(d, -1, sizeof(int) * (T + 1));\n\t\t\td[S] = 0;\n\t\t\tQ.push(S);\n\t\t\twhile (!Q.empty()) {\n\t\t\t\tint e = Q.front();\n\t\t\t\tQ.pop();\n\t\t\t\tfor (int i = g.h[e], eu; ~i; i = g[i].nx) {\n\t\t\t\t\teu = g[i].ed;\n\t\t\t\t\tif (!g[i].r || ~d[eu])\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\td[eu] = d[e] + 1;\n\t\t\t\t\tQ.push(eu);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn d[T] != -1;\n\t\t}\n\t\t\n\t\tint dfs(int p, int mf) {\n\t\t\tif (p == T || !mf)\n\t\t\t\treturn mf;\n\t\t\tint flow = 0, f;\n\t\t\tfor (int& i = h[p], j, e; ~i; (i != -1) && (i = g[i].nx)) {\n\t\t\t\te = g[i].ed, j = i;\n\t\t\t\tif (g[i].r && d[e] == d[p] + 1 && (f = dfs(e, min(mf, g[i].r))) > 0) {\n\t\t\t\t\tg[j].r -= f;\n\t\t\t\t\tg[j ^ 1].r += f;\n\t\t\t\t\tflow += f;\n\t\t\t\t\tmf -= f;\n\t\t\t\t\tif (!mf)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn flow;\n\t\t}\n\n\t\tint dinic() {\n\t\t\tint rt = 0;\n\t\t\twhile (bfs()) {\n\t\t\t\tfor (int i = 0; i <= T; i++)\n\t\t\t\t\th[i] = g.h[i];\n\t\t\t\trt += dfs(S, inf);\n\t\t\t}\n\t\t\treturn rt;\n\t\t}\n\n\t\tvoid add_edge(int u, int v, int r) {\n\t\t\tg.add_arc(u, v, r);\n\t\t}\n\t\tint cnt_edges() {\n\t\t\treturn g.E.size();\n\t\t}\n} Network;\n\n#define pii pair\n\nconst int N = 205;\n\nint n, m, t;\nint id[N][N];\nint deg[2][N];\nboolean G[N][N];\n\nint ans[5000];\nint idx[N][N];\n\nvoid solve(int k) {\n\tNetwork network(n + m + 2, n + m + 3);\n\tint S = 0, T = n + m + 1, SS = n + m + 2, TT = n + m + 3;\n\tfor (int i = 1; i <= n; i++) {\n\t\tfor (int j = 1; j <= m; j++) {\n\t\t\tif (G[i][j]) {\n\t\t\t\tid[i][j] = network.cnt_edges();\n\t\t\t\tnetwork.add_edge(i, j + n, 1);\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 1; i <= n; i++) {\n\t\tnetwork.add_edge(SS, i, deg[0][i] / k);\n\t\tnetwork.add_edge(S, TT, deg[0][i] / k);\n\t\tif (deg[0][i] % k) {\n\t\t\tnetwork.add_edge(S, i, 1);\n\t\t}\n\t}\n\tfor (int i = 1; i <= m; i++) {\n\t\tnetwork.add_edge(SS, T, deg[1][i] / k);\n\t\tnetwork.add_edge(i + n, TT, deg[1][i] / k);\n\t\tif (deg[1][i] % k) {\n\t\t\tnetwork.add_edge(i + n, T, 1);\n\t\t} \n\t}\n\tnetwork.add_edge(T, S, inf);\n\tnetwork.dinic();\n\tMapManager& g = network.g;\n\tfor (int i = 1; i <= n; i++) {\n\t\tfor (int j = 1; j <= m; j++) {\n\t\t\tif (G[i][j] && !g[id[i][j]].r) {\n\t\t\t\tans[idx[i][j]] = k;\n\t\t\t\tG[i][j] = false;\n\t\t\t\t--deg[0][i];\n\t\t\t\t--deg[1][j];\n\t\t\t}\n\t\t}\n\t}\n}\n\nint main() {\n\tint _;\n\tscanf(\"%d%d%d%d\", &n, &m, &_, &t);\n\tfor (int i = 1, u, v; i <= _; i++) {\n\t\tscanf(\"%d%d\", &u, &v);\n\t\tG[u][v] = true;\n\t\tidx[u][v] = i;\n\t\t++deg[0][u];\n\t\t++deg[1][v];\n\t}\n\tint ans = 0;\n\tfor (int i = 1; i <= n; i++)\n\t\tans += !!(deg[0][i] % t);\n\tfor (int i = 1; i <= m; i++) \n\t\tans += !!(deg[1][i] % t);\n\twhile (t)\n\t\tsolve(t--);\n\tprintf(\"%d\\n\", ans);\n\tfor (int i = 1; i <= _; i++) {\n\t\tif (!::ans[i])\n\t\t\t::ans[i] = 1;\n\t\tprintf(\"%d \", ::ans[i]);\n\t}\n\treturn 0;\n}\n//hellobig_tq", "src_uid": "99b97aabec566e5f966777947271ad3c"} {"source_code": "#include\n#include\nusing namespace std;\nint main()\n{\t\nstring arr[5];\nfor(int i=0;i<4;i++)\ncin>>arr[i];\nfor(int col=0;col<4;col++)\n{\n\tfor(int row=0;row<2;row++)\n\t{\n\t\tif( (arr[col][row]=='x'&&arr[col][row+1]=='x'&&arr[col][row+2]=='.')\n\t\t\t ||(arr[col][row]=='x'&&arr[col][row+1]=='.'&&arr[col][row+2]=='x')\n\t\t\t ||(arr[col][row]=='.'&&arr[col][row+1]=='x'&&arr[col][row+2]=='x') )\n\t\t\t\t{cout<<\"YES\\n\";return 0;}\n\telse if( (arr[row][col]=='x'&&arr[row+1][col]=='x'&&arr[row+2][col]=='.')\n\t\t\t\t||(arr[row][col]=='x'&&arr[row+1][col]=='.'&&arr[row+2][col]=='x')\n\t\t\t\t||(arr[row][col]=='.'&&arr[row+1][col]=='x'&&arr[row+2][col]=='x') )\n\t\t\t\t {cout<<\"YES\\n\";return 0;}\n\t}\n}\nfor(int i=0;i<2;i++)\n{\n\tif( (arr[i][2]=='x'&&arr[i+1][1]=='x'&&arr[i+2][0]=='.')\n\t\t\t\t||(arr[i][2]=='x'&&arr[i+1][1]=='.'&&arr[i+2][0]=='x')\n\t\t\t\t||(arr[i][2]=='.'&&arr[i+1][1]=='x'&&arr[i+2][0]=='x') )\n\t\t\t\t{cout<<\"YES\\n\";return 0;}\n\n\telse if( (arr[i][3]=='x'&&arr[i+1][2]=='x'&&arr[i+2][1]=='.')\n\t\t\t\t||(arr[i][3]=='x'&&arr[i+1][2]=='.'&&arr[i+2][1]=='x')\n\t\t\t\t||(arr[i][3]=='.'&&arr[i+1][2]=='x'&&arr[i+2][1]=='x') )\n\t\t\t\t{cout<<\"YES\\n\";return 0;}\n\telse if( (arr[0][i]=='x'&&arr[1][i+1]=='x'&&arr[2][i+2]=='.')\n\t\t\t ||(arr[0][i]=='x'&&arr[1][i+1]=='.'&&arr[2][i+2]=='x')\n\t\t\t ||(arr[0][i]=='.'&&arr[1][i+1]=='x'&&arr[2][i+2]=='x') )\n\t\t\t {cout<<\"YES\\n\";return 0;}\n\n\telse if( (arr[1][i]=='x'&&arr[2][i+1]=='x'&&arr[3][i+2]=='.')\n\t\t\t ||(arr[1][i]=='x'&&arr[2][i+1]=='.'&&arr[3][i+2]=='x')\n\t\t\t ||(arr[1][i]=='.'&&arr[2][i+1]=='x'&&arr[3][i+2]=='x') )\n\t\t\t {cout<<\"YES\\n\";return 0;}\n}\ncout<<\"NO\\n\";\n}", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"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 ABS(a) ((a>0)?a:-(a))\n#define MIN(a,b) ((a\n#define mp make_pair\n#define PI 3.14159265358979\n#define MEMS(a,b) memset(a,b,sizeof(a))\n#define LL long long\n#define U unsigned\nusing namespace std;\nbool f[20000001];\nint a[20000001];\nconst int M=20000000;\nint pr[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};\nint pp;\nint N;\nint dfs(LL num, int cnt, int p)\n{\n\tif (num>N)\n\t\treturn 0;\n\tif (p==pp)\n\t{\n\t\tif (cnt&1)\n\t\t\treturn (-(N/num));\n\t\treturn N/num;\n\t}\n\tint res=dfs(num*pr[p],cnt+1,p+1)+dfs(num,cnt,p+1);\n\treturn res;\n}\nint solve(int n, int k)\n{\n\tif (n/k<=M)\n\t{\n\t\tint res=0;\n\t\tFOR(i,1,n/k+1)\n\t\t\tif (a[i]>=k)\n\t\t\t\tres++;\n\t\treturn res;\n\t}\n\tFOR(i,0,25)\n\t\tif (pr[i]==k)\n\t\t\tpp=i;\n\tN=n;\n\tint res1=dfs(k,0,0);\n\treturn res1;\n}\nint main()\n{\n\t//freopen(\"in.txt\",\"r\",stdin);\n\tint aa,b,k;\n\tscanf(\"%d%d%d\",&aa,&b,&k);\n\tbool ff=true;\n\tfor (int i=2; i*i<=k; ++i)\n\t\tif ((k%i)==0)\n\t\t{\n\t\t\tff=false;\n\t\t\tbreak;\n\t\t}\n\tif (!ff)\n\t{\n\t\tprintf(\"0\\n\");\n\t\treturn 0;\n\t}\n FOR(i,0,M)\n\t{\n\t\ta[i]=i;\n\t\tf[i]=true;\n\t}\n\tfor (int i=2; i*i<=M; ++i)\n\t\tif (f[i])\n\t\tfor (int j=i+i; j\nusing namespace std; \n#define REP(i,n) for(int i=0;i<(n);i++)\n#define for1(i,n) for(int i=1;i<=n;i++)\n#define FOR(i,a,b) for(int i=(a);i<=(b);i++)\n#define FORD(i,a,b) for(int i=(a);i>=(b);i--)\nconst int INF = 1<<29;\nconst int MOD=1000000007;\n#define pp pair\ntypedef long long int ll;\nbool isPowerOfTwo (ll x) \n{ \n return x && (!(x&(x-1))); \n}\nvoid fastio()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(0); cout.tie(0);\n}\nlong long binpow(long long a, long long b) {\n long long res = 1;\n while (b > 0) {\n if (b & 1)\n res = res * a;\n a = a * a;\n b >>= 1;\n }\n return res;\n}\nconst int dx[] = {1,0,-1,0,1,1,-1,-1};\nconst int dy[] = {0,-1,0,1,1,-1,-1,1};\n////////////////////////////////////////////////////////////////////\nchar a[7]={'R','O','Y','G','B','I','V'};\nint main()\n{\n fastio();\n int t=1;\n //cin>>t;\n while(t--)\n {\n int n;\n cin>>n;\n for(int i=0;i\n#define db double\n#define pb push_back\nusing namespace std;\nconst int maxn = 1e3+5;\nstruct node{\n db x[5];\n}a[maxn];\n\ndb dot(node A, node B, node C){\n db res = 0;\n for(int i = 0; i < 5; i++){\n res += (B.x[i]-A.x[i])*(C.x[i]-A.x[i]);\n }\n return res;\n}\n\nint main(){\n int n;\n cin >> n;\n for(int i = 0; i < n; i++){\n for(int j = 0; j < 5; j++){\n cin >> a[i].x[j];\n }\n }\n if(n > 11){ puts(\"0\"); }\n else{\n vectorans;\n bool flag = true;\n for(int i = 0; i < n; i++){\n flag = true;\n for(int j = 0; j < n && flag; j++){\n if(j == i) continue;\n for(int k = 0; k < n && flag; k++){\n if(j == k || k == i) continue;\n if(dot(a[i],a[j],a[k]) > 0){\n flag = false;\n break;\n }\n }\n }\n if(flag){ ans.pb(i+1); }\n }\n cout << ans.size() << endl;\n for(int i = 0; i < ans.size(); i++){\n cout << ans[i] << endl;\n }\n }\n}\n", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"} {"source_code": "#include \nusing namespace std;\n\n#define fi first\n#define se second\n#define pb push_back\n\ntypedef pair ii;\ntypedef long long ll;\nconst int N = 10+5;\nll l, r;\n\nbool check(ll x)\n{\n\tbool data[N];\n\tmemset(data,false,sizeof(data));\n\twhile (x > 0)\n\t{\n\t\tint now = x % 10;\n\t\tif (data[now])\n\t\t\treturn false;\n\t\tdata[now] = true;\n\t\tx /= 10;\n\t}\n\treturn true;\n}\n\nint main()\n{\n\tcin >> l >> r;\n\tfor (ll i = l; i <= r; i++)\n\t{\n\t\tif (check(i))\n\t\t{\n\t\t\tcout << i << '\\n';\n\t\t\treturn 0;\n\t\t}\n\t}\n\tcout << -1 << '\\n';\n\treturn 0;\n}", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"} {"source_code": "/*input\n2\n3\n1 2 3 5 6 E 7\n8 9 10 4 11 12 13\n11\n34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1\nE 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3\n\n*/\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\nusing namespace std;\n\n// start of code\n\nint K;\nvector A;\nvector> table;\nstring finalSequence;\n\nvoid rotateForward()\n{\n\t// cout << \"rotate forward\" << endl;\n\tif (!finalSequence.empty() && finalSequence.back() == 'B') finalSequence.pop_back();\n\telse finalSequence += \"F\";\n\n\tfor (int i = 4 * K; i > 0; --i) {\n\t\tswap(A[i - 1], A[i]);\n\t}\n}\n\nvoid rotateBackward()\n{\n\t// cout << \"rotate backward\" << endl;\n\tif (!finalSequence.empty() && finalSequence.back() == 'F') finalSequence.pop_back();\n\telse finalSequence += \"B\";\n\n\tfor (int i = 1; i <= 4 * K; ++i) {\n\t\tswap(A[i - 1], A[i]);\n\t}\n}\n\nvoid simpleJump() // jump first value pass 2 positions\n{ \n\tfinalSequence += \"JFF\";\n\tfor (int i = 1; i <= 2; ++i) {\n\t\tswap(A[i - 1], A[i]);\n\t}\n}\n\nvoid customJump(int idx) // jump (idx)`s value pass 2 positions\n{\n\tfor (int i = 0; i < idx; ++i) rotateBackward();\n\tsimpleJump();\n\twhile (A[0] != 1) rotateForward();\n}\n\nvoid readFromInput()\n{\n\tcin >> K;\n\tfinalSequence = \"\";\n\ttable.assign(2, vector(2 * K + 1));\n\tfor (auto &vec : table) for (auto &i : vec) {\n\t\tstring str;\n\t\tcin >> str;\n\t\tif (str == \"E\") i = 0;\n\t\telse i = stoi(str);\n\t}\n}\n\nvoid backToCorner()\n{\n\tfor (int row = 0; row < 2; ++row) {\n\t\tfor (int col = 0; col < 2 * K; ++col) {\n\t\t\tif (table[row][col] == 0) {\n\t\t\t\tfinalSequence += 'r';\n\t\t\t\tswap(table[row][col], table[row][col + 1]);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (table[0][2 * K] == 0) {\n\t\tfinalSequence += 'd';\n\t\tswap(table[0][2 * K], table[1][2 * K]);\n\t}\n}\n\nvoid relabel()\n{\n\tfor (auto &vec : table) for (int &i : vec) {\n\t\tif (i >= 2 * K + 2) i = 4 * K + 2 - i;\n\t\telse if (i >= 1) i += 2 * K;\n\t}\n}\n\nvoid convertToA()\n{\n\tA.resize(4 * K + 1);\n\tfor (int i = 0; i <= 2 * K; ++i) {\n\t\tA[2 * K + i] = table[0][i];\n\t}\n\tfor (int i = 0; i < 2 * K; ++i) {\n\t\tA[2 * K - 1 - i] = table[1][i];\n\t}\n\tassert(table[1][2 * K] == 0);\n}\n\nstring forwardDefinition()\n{\n\treturn \"u\" + string(2 * K, 'l') + \"d\" + string(2 * K, 'r');\n}\n\nstring backwardDefinition()\n{\n\treturn string(2 * K, 'l') + \"u\" + string(2 * K, 'r') + \"d\";\n}\n\nstring jumpKDefinition()\n{\n\treturn string(K + 1, 'B') + (string(K, 'l') + \"u\" + string(K, 'r') + \"d\") + string(K + 1, 'F');\n}\n\nstring jumpDefinition()\n{\n\tstring def = \"\";\n\tdef += \"B\";\n\tdef += jumpKDefinition();\n\tdef += jumpKDefinition();\n\tdef += \"F\";\n\tfor (int i = 0; i < K * 2; ++i) def += jumpKDefinition();\n\tdef += \"B\";\n\tfor (int i = 0; i < K * 2; ++i) def += jumpKDefinition();\n\tdef += \"F\";\n\n\t// dirty optimization\n\tassert(def.back() == 'F'); def.pop_back();\n\tassert(def.back() == 'F'); def.pop_back();\n\n\t// cout << \"SZ \" << def.size() << endl;\n\treturn def;\n\n\t// return \"B\" + jumpKDefinition() + jumpKDefinition() + \"F\" + string(K, jumpKDefinition().c_str()) + \"B\" + string(K, jumpKDefinition().c_str()) + \"F\";\n}\n\nvoid trim()\n{\n\tstring copySequence = finalSequence + \"$\";\n\tfinalSequence = \"\";\n\n\tchar curChar = '?';\n\tint curCount = 0;\n\tfor (char ch : copySequence) {\n\t\tif (curChar == ch) {\n\t\t\t++curCount;\n\t\t\tif (curCount == 10) {\n\t\t\t\tif (ch == 'F') finalSequence += \"X\", curCount = 0;\n\t\t\t\telse if (ch == 'B') finalSequence += \"Y\", curCount = 0;\n\t\t\t\telse if (ch == 'J') finalSequence += \"Z\", curCount = 0;\n\t\t\t}\n\t\t} else {\n\t\t\tfinalSequence += string(curCount, curChar);\n\t\t\tcurChar = ch;\n\t\t\tcurCount = 1;\n\t\t}\n\t}\n}\n\nvoid outputSuccess()\n{\n\ttrim();\n\t// cout <<\tfinalSequence.size() << ' ' << jumpDefinition().size() << endl;\n\tcout << \"SURGERY COMPLETE\" << '\\n';\n\tcout << finalSequence << '\\n';\n\tcout << \"F \" << forwardDefinition() << '\\n';\n\tcout << \"B \" << backwardDefinition() << '\\n';\n\tcout << \"J \" << jumpDefinition() << '\\n';\n\tcout << \"X FFFFFFFFFF\" << '\\n';\n\tcout << \"Y BBBBBBBBBB\" << '\\n';\n\tcout << \"Z JJJJJJJJJJ\" << '\\n';\n\tcout << \"DONE\" << '\\n';\n}\n\nvoid outputFailure()\n{\n\tcout << \"SURGERY FAILED\" << '\\n';\n}\n\nvoid log() // for debugging purposes\n{\n\tcout << \"--------------------------------\" << endl;\n\tcout << \"A = \";\n\tfor (int x : A) cout << x << ' ';\n\tcout << endl;\n\treturn;\n\tcout << \"table: \" << endl;\n\tfor (int i = 2 * K; i <= 4 * K; ++i) {\n\t\tcout << A[i] << ' ';\n\t}\n\tcout << '\\n';\n\n\tfor (int i = 2 * K - 1; i >= 0; --i) {\n\t\tcout << A[i] << ' ';\n\t}\n\tcout << 'E';\n\tcout << '\\n';\n\n\tcout << \"current sequence = \" << finalSequence << endl;\n\tcout << \"--------------------------------\" << endl;\n\tcout << endl;\n}\n\nvoid solve()\n{\n\treadFromInput();\n\tbackToCorner();\n\trelabel();\n\tconvertToA();\n\twhile (A[0] != 1) rotateForward();\n\n\tfor (int noFixed = 1; noFixed <= 4 * K - 2; ++noFixed) {\n\t\tint nextValue = noFixed + 1;\n\n\t\tint curPos = (int) (find(A.begin(), A.end(), nextValue) - A.begin());\n\n\t\twhile (curPos < noFixed || curPos > noFixed + 2) {\n\t\t\t// log();\n\t\t\tcustomJump(curPos);\n\t\t\tcurPos = (int) (find(A.begin(), A.end(), nextValue) - A.begin());\n\t\t}\n\n\t\twhile (A[noFixed] != nextValue) {\n\t\t\t// log();\n\t\t\tcustomJump(noFixed);\n\t\t}\n\t}\n\n\tbool isSorted = is_sorted(A.begin(), A.end());\n\tif (isSorted) {\n\t\toutputSuccess();\n\t} else {\n\t\toutputFailure();\n\t}\n}\n\nsigned main()\n{\n\tios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n\n\tint tests;\n\tcin >> tests;\n\twhile (tests--) {\n\t\tsolve();\n\t}\n\n\treturn 0;\n}\n", "src_uid": "697c4af98ea881892365bed856b49988"} {"source_code": "#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;\nconst int N=1e6+9;\nconst int mod=998244353;\nint t[N];\nint n,m;\nint f[N];\nint read()\n{\n\tint f=1,x=0;\n\tchar s=getchar();\n\twhile(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} \n\twhile(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s^'0');s=getchar();}\n\treturn f*x;\n}\nvoid Prepare()\n{\n\tfor(int i=1;i<=n;i++)\n\t\tfor(int j=i;j<=n;j+=i)\n\t\t{\n\t\t\tf[j]++;\n\t\t\tif(f[j]>=mod) \n\t\t\t\tf[j]%=mod;\n\t\t}\n}\nint lowbit(int x)\n{\n\treturn x&(-x);\n}\nint query(int x)\n{\n\tint ret=0;\n\twhile(x)\n\t{\n\t\tret+=t[x];\n\t\tx-=lowbit(x);\n\t\tret%=mod;\n\t}\n\treturn ret;\n}\nvoid add(int x,int val)\n{\n\twhile(x<=n)\n\t{\n\t\tt[x]+=val;\n\t\tx+=lowbit(x);\n\t\tif(x>=mod)\n\t\t\tx%=mod;\n\t}\n}\nsigned main()\n{\n\tn=read();\n\tPrepare(); \n\tf[1]=1;\n\tadd(1,f[1]);\n\tfor(int i=2;i<=n;i++)\n\t{\n\t\tf[i]=(f[i]+query(i))%mod;\n\t\tadd(i,f[i]);\n\t}\n\tcout<\n#include \n#include \nusing namespace std;\ntypedef long long ll;\nll calcNumber(int,int,int);\nll dp(int,int,int);\nll comb(ll,ll);\nll MEMO[12][12][2];\nll C[12];\nll memo[12][12][12];\nll F[10];\nint S[12];\nint L;\n#define MOD 1000000007LL\nint main(){\n\tmemset(MEMO,-1,sizeof MEMO);\n\tmemset(memo,-1,sizeof memo);\n\tmemset(C,0,sizeof C);\n\tF[0]=1LL;\n\tfor(int i=1;i<10;i++) F[i]=(F[i-1]*i)%MOD;\n\tstring linea;\n\tcin>>linea;\n\t\t\n\tL=linea.size();\n\tfor(int i=0;i=0;i--) cout<<\" \";\n\t//cout<<\"DP: \"<=0;i--) cout<<\" \";\n\t//cout<\n#include \nusing namespace std;\nvoid main() {\n char k;\n string word;\n cin >> word;\n k = toupper(word[0]);\n cout << k <\n#include \n#include \n#include \n\n#define MAX 1024\n\nusing namespace std;\n\ntypedef __int64 i64;\n\nint fac[MAX];\n\ni64 modPow(i64 a, i64 b, i64 p) {\n i64 ret = 1;\n for (a %= p; b; b >>= 1) {\n if (b & 1) ret = (ret * a) % p;\n a = (a * a) % p;\n }\n return ret;\n}\n\nint calc(int x) {\n int i, cur, cnt = 0;\n for (i = 2; i * i <= x; ++i) {\n if (!(x % i)) {\n fac[cnt++] = i; fac[cnt++] = x / i;\n }\n }\n return cnt;\n}\n\nbool check(int x, int n, int cnt) {\n int i;\n for (i = 0; i < cnt; ++i) {\n if (modPow(x, fac[i], n + 1) == 1) return false;\n }\n return true;\n}\n\nint solve(int n, int x) {\n int i, cnt, m = max(x - n, 2);\n\n if (calc(n + 1)) return -1;\n cnt = calc(n);\n for (i = x - 1; i >= m; --i) {\n if (check(i, n, cnt)) return i;\n }\n\n return -1;\n}\n\nint main() {\n int n, x;\n\n while (~scanf(\"%d %d\", &n, &x)) {\n printf(\"%d\\n\", solve(n, x));\n }\n\n return 0;\n}\n", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nint NineInK(int k) {\n int res = 1;\n for (int i = 0; i < k; ++i) {\n res *= 9;\n }\n return res;\n}\n\nint main() {\n ios::sync_with_stdio(false);\n\n int n;\n cin >> n;\n\n int k = 0;\n int max_mul = 1;\n while (n != 0) {\n const int digit = n % 10;\n n /= 10;\n if (digit == 0) {\n max_mul = 0;\n } else if (digit == 1 && n == 0) {\n max_mul = NineInK(k);\n } else {\n max_mul = max(max_mul * digit, NineInK(k) * (digit - 1));\n }\n ++k;\n }\n cout << max_mul;\n return 0;\n}\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"source_code": "#include\n\nusing namespace std;\n\nint M[102][202][51][2],n,N=102;\n\nchar s[102];\n\nint f(int i, int t, int n, int h){\n\n\tif(n < 0)\n\t\treturn 0;\n\n\tif(i == strlen(s+1)+1){\n\t\tif(n&1)\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn abs(t);\n\t}\n\n\tint &r = M[i][t+N][n][h];\n\t\n\tif(r != -1)\n\t\treturn r;\n\t\n\tif(s[i] == 'F')\n\t\tr = max(f(i+1,t+h,n,h) , f(i+1,t,n-1,-h));\n\t\n\telse\n\t\tr = max(f(i+1,t,n,-h) , f(i+1,t+h,n-1,h));\n\t\n\treturn r;\n}\n\nint main(){\n\n\tcin >> s + 1 >> n;\n\n\tmemset(M , -1 , sizeof M);\n\tcout << f(1,0,n,1);\n\n\treturn 0;\n}\n", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d"} {"source_code": "#include \n#define llint long long\n#define mod 1000000007\n\nusing namespace std;\n\nllint n;\nint dp[1000005][21][2];\n\nint main(void)\n{\n\tcin >> n;\n\t\n\tllint ans = 0, x = 0, y = 0;\n\tfor(int t = 1; t*2 <= n; t*=2, x++);\n\tif(n >= 3){\n\t\tfor(int t = 3; t*2 <= n; t*=2, y++);\n\t}\n\t\n\tdp[1][x][0] = n / (1< 0){\n\t\t\t\t\trem = n / ((1<<(j-1))*K) - n / ((1< 0){\n\t\t\t\t\trem = 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#include \nusing namespace std;\n \ntypedef long long LL;\ntypedef unsigned long long ULL;\ntypedef long double LD;\ntypedef vector VI;\ntypedef pair PII;\n \n#define REP(i,n) for(int i=0;i<(n);++i)\n#define SIZE(c) ((int)((c).size()))\n#define FOR(i,a,b) for (int i=(a); i<(b); ++i)\n#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)\n#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)\n#define ALL(v) (v).begin(), (v).end()\n \n#define pb push_back\n#define mp make_pair\n#define st first\n#define nd second\n\ndouble EPS = 1e-10;\nlong long mini = 1LL<<62;\nlong long maxi = -1;\n\nvector V;\n\nvoid get(int k, int a, int b, int c) {\n\n if (k == V.size()) {\n mini = min(mini,(a+2) * (LL)(b+2) * (c+1) - a * b * c);\n mini = min(mini,(a+1) * (LL)(b+2) * (c+2) - a * b * c);\n mini = min(mini,(a+2) * (LL)(b+1) * (c+2) - a * b * c); \n \n maxi = max(maxi,(a+2) * (LL)(b+2) * (c+1) - a * b * c);\n maxi = max(maxi,(a+1) * (LL)(b+2) * (c+2) - a * b * c);\n maxi = max(maxi,(a+2) * (LL)(b+1) * (c+2) - a * b * c); \n return;\n }\n \n int a1 = a, b1, c1;\n REP(m,V[k].second + 1) {\n b1 = b;\n REP(n, V[k].second - m + 1) {\n c1 = c;\n REP(o, V[k].second - n - m) c1 *= V[k].first;\n get(k+1, a1,b1,c1);\n b1 *= V[k].first; \n } \n a1 *= V[k].first;\n }\n}\n\nchar buf[1005];\nint main() {\n int N, M, K;\n scanf(\"%d%d%d\",&N,&M,&K);\n int ce[2], p[2];\n \n bool winning[2];\n winning[0] = winning[1] = false;\n \n \n int T[32];\n REP(i,32) T[i] = 0;\n bool hasMove[2];\n\n REP(i,N) {\n scanf(\"%s\", buf);\n ce[0] = ce[1] = p[0] = p[1] = 0;\n REP(j,M) {\n if (buf[j] == 'G') {\n ce[0] ++;\n p[0] = j;\n } else if (buf[j] == 'R') {\n ce[1] ++;\n p[1] = j; \n }\n }\n \n REP(j,2) if (ce[j] && !ce[1-j] && ce[j] < M) winning[j] = true;\n if (!ce[0] || !ce[1]) continue;\n\n int diff = abs(p[0] - p[1]) - 1;\n \n REP(j,32) {\n T[j] += diff & 1;\n diff >>= 1;\n }\n \n \n }\n \n if(winning[0] && winning[1]) printf(\"Draw\\n\");\n else if (winning[0]) printf(\"First\\n\");\n else if (winning[1]) printf(\"Second\\n\"); \n else { \n bool wins0 = false;\n REP(j, 32) {\n wins0 = wins0 || (T[j] % (K+1) != 0);\n }\n \n if (wins0) winning[0] = true;\n else winning[1] = true;\n \n if(winning[0] && winning[1]) printf(\"Draw\\n\");\n else if (winning[0]) printf(\"First\\n\");\n else printf(\"Second\\n\"); \n }\n}", "src_uid": "69062f7c9b834e925ab23ebc2da96b52"} {"source_code": "#include \nusing namespace std;\n\n#define fast ios::sync_with_stdio(0); cin.tie(0)\n#define pii pair < int , int >\n#define ii pair\n#define pb push_back\n#define mp make_pair\n#define ll long long int\n#define vi vector < int >\n#define vvi vector < vector < int > >\n#define maxn 1123456\n#define mod 1000000007\n#define mem(a,b) memset(a,b,sizeof(a))\n#define frep(i,a,b) for(i=a;i<=b;i++)\n#define rep(i,b) for(i=0;i>t; while(t--) // taking input test cases always :p\n\n\nint T[maxn];\nint mark[333][333][35][9];\nint dx[8] = {1,1,0,-1,-1,-1,0,1};\nint dy[8] = {0,1,1,1,0,-1,-1,-1};\nint ans[310][310];\n\n\n\nvoid dfs(int x,int y,int level,int n,int dir)\n{\n\tif(level>n)\treturn;\n\tif(mark[x][y][level][dir])\treturn;\n\tmark[x][y][level][dir] = 1;\n\t\n\tfor(int i=1;i<=T[level];i++)\n\t{\n\t\tx += dx[dir];\n\t\ty += dy[dir];\n\t\tans[x][y] = 1;\n\t}\n\t\n\tdfs(x,y,level+1,n,(dir+1)%8);\n\tdfs(x,y,level+1,n,(dir+7)%8);\n}\n\nint main() \n{\n fast;\n\tint A=0,n,temp=0,i,j,l,k;\n\tcin>>n;\n\tfrep(i,1,n)\n\t\tcin>>T[i];\n\n\tfrep(i,0,310)\n\t\tfrep(j,0,310)\n\t\t\tfrep(k,0,31)\n\t\t\t\tfrep(l,0,8)\n\t\t\t\t\tans[i][j]=0,mark[i][j][k][l]=false;\n\t\t\t\t\t\n\tdfs(155,155,1,n,0);\n\t\n\tfrep(i,0,310)\n\t\tfrep(j,0,310)\t\n\t\tif(ans[i][j]==1)\tA+=1;\n\tcout<\n\nusing namespace std;\nusing uint = unsigned int;\nusing ll = long long;\nusing ull = unsigned long long;\nconstexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }\ntemplate using V = vector;\ntemplate using VV = V>;\n\n#ifdef LOCAL\nstruct PrettyOS {\n ostream& os;\n bool first;\n template auto operator<<(T&& x) {\n if (!first) os << \", \";\n first = false;\n os << x;\n return *this;\n }\n};\ntemplate void dbg0(T&&... t) {\n (PrettyOS{cerr, true} << ... << t);\n}\n#define dbg(...) \\\n do { \\\n cerr << __LINE__ << \" : \" << #__VA_ARGS__ << \" = \"; \\\n dbg0(__VA_ARGS__); \\\n cerr << endl; \\\n } while (false);\n#else\n#define dbg(...)\n#endif\n\ntemplate \nostream& operator<<(ostream& os, const pair& p) {\n return os << \"P(\" << p.first << \", \" << p.second << \")\";\n}\n\ntemplate ostream& operator<<(ostream& os, const V& v) {\n os << \"[\";\n for (auto d : v) os << d << \", \";\n return os << \"]\";\n}\n\ntemplate struct ModInt {\n using M = ModInt;\n const static M G;\n uint v;\n ModInt(ll _v = 0) { set_v(_v % MD + MD); }\n M& set_v(uint _v) {\n v = (_v < MD) ? _v : _v - MD;\n return *this;\n }\n explicit operator bool() const { return v != 0; }\n M operator-() const { return M() - *this; }\n M operator+(const M& r) const { return M().set_v(v + r.v); }\n M operator-(const M& r) const { return M().set_v(v + MD - r.v); }\n M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }\n M operator/(const M& r) const { return *this * r.inv(); }\n M& operator+=(const M& r) { return *this = *this + r; }\n M& operator-=(const M& r) { return *this = *this - r; }\n M& operator*=(const M& r) { return *this = *this * r; }\n M& operator/=(const M& r) { return *this = *this / r; }\n bool operator==(const M& r) const { return v == r.v; }\n M pow(ll n) const {\n M x = *this, r = 1;\n while (n) {\n if (n & 1) r *= x;\n x *= x;\n n >>= 1;\n }\n return r;\n }\n M inv() const { return pow(MD - 2); }\n friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }\n};\nusing Mint = ModInt;\n// template<> const Mint Mint::G = Mint(3);\n\nint main() {\n cin.tie(nullptr);\n ios::sync_with_stdio(false);\n cout << fixed << setprecision(20);\n\n int n;\n cin >> n;\n\n VV mat(n, V(n));\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n int x;\n cin >> x;\n //x = 1;\n mat[i][j] = Mint(x) / Mint(100);\n }\n }\n\n using ST = pair, Mint>;\n V sts;\n sts.push_back(ST({0}, Mint(1)));\n\n for (int ph = 0; ph < n; ph++) {\n V nsts;\n for (int f = 1; f < (1 << n); f++) {\n Mint freq = 1;\n for (int i = 0; i < n; i++) {\n if ((f >> i) & 1) {\n freq *= mat[ph][i];\n } else {\n freq *= Mint(1) - mat[ph][i];\n }\n }\n for (auto st: sts) {\n V nst;\n for (auto d: st.first) {\n for (int i = 0; i < n; i++) {\n if ((d >> i) & 1) continue;\n if (!((f >> i) & 1)) continue;\n nst.push_back(d ^ (1 << i));\n }\n }\n if (nst.empty()) continue;\n sort(nst.begin(), nst.end());\n nst.erase(unique(nst.begin(), nst.end()), nst.end());\n nsts.push_back({nst, st.second * freq});\n }\n }\n sort(nsts.begin(), nsts.end(), [&](const ST& l, const ST& r) {\n return l.first < r.first;\n });\n\n sts.clear();\n for (auto st: nsts) {\n if (sts.size() && sts.back().first == st.first) {\n sts.back().second += st.second;\n } else {\n sts.push_back(st);\n }\n }\n dbg(ph, nsts.size());\n //dbg(nst);\n }\n\n dbg(sts);\n\n Mint ans = (sts.empty() ? Mint(0) : sts[0].second);\n\n cout << ans << endl;\n\n return 0;\n}\n", "src_uid": "906d4e49566e63fddaf8eac7384c6284"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint main() \n{\n long long n,kiek=0,x=2;\n cin>>n;\n if(n%2==0)\n cout<\nusing namespace std;\nint a[25]={0,4,4,4,4,4,4,4,4,4,15,4},n;\nint main()\n{\n\tscanf(\"%d\",&n);\n\tprintf(\"%d\",a[n-10]);\n\treturn 0;\n}", "src_uid": "5802f52caff6015f21b80872274ab16c"} {"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;\n#define MOD 1000000007LL\n#define ll long long\n\nconst int M = 300001;\nint n, N[M];\nll k , l;\n\nvoid solve() {\n cin >> n >> k >> l;\n ll t = 0;\n bool isFull = true;\n bool canBeO = true;\n for(int i = 0 ; i < n ; i++) cin >> N[i];\n for(int i = 0 ; i < n ; i++) {\n if (N[i] > l) {\n cout << \"No\\n\";\n return;\n }\n if (N[i] <= l - k) {\n isFull = true;\n canBeO = true;\n continue;\n }\n\n ll a = l - N[i];\n ll b = 2LL * k - a;\n\n if (isFull) {\n canBeO = false;\n if (a == 0) t = a;\n else {\n t = b;\n canBeO = true;\n }\n isFull = false;\n continue;\n }\n assert((canBeO == (t >= k)));\n t = (t + 1) % (2*k);\n\n //cout << i << \"->\" << a << \" \" << b << \" \" << t << endl;\n if (t > a && t < b) {\n if (canBeO) {\n canBeO = false;\n if (a == 0) t = a;\n else {\n t = b;\n canBeO = true;\n }\n }\n else {\n cout << \"No\\n\";\n return;\n }\n }\n canBeO = t >= b;\n isFull = false;\n }\n cout << \"Yes\\n\"; \n}\n\nint main(int argc, const char * argv[]) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n \n int test = 1;\n cin >> test;\n while (test--)\n {\n solve();\n }\n \n return 0;\n}\n", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"} {"source_code": "#include \n#define int long long\n#define len(v) ((int)((v).size()))\n#define all(v) (v).begin(), (v).end()\n#define rall(v) (v).rbegin(), (v).rend()\n#define chmax(x, v) x = max((x), (v))\n#define chmin(x, v) x = min((x), (v))\nusing namespace std;\nusing pii = pair;\n\nstruct EndSet {\n\tset points;\n\tpii seg = {1, 0};\n\n\tint cbase = 0, cdir = 1;\n\n\tvoid setFree(int mx) {\n\t\tpoints.clear(), cbase = 0, cdir = 1;\n\t\tseg = {1, mx};\n\t}\n\n\tvoid setPush(int x) {\n\t\tsetFree(0);\n\t\tpoints.insert(x);\n\t}\n\n\tvoid rotate(int balance) {\n\t\tcbase = balance - cbase;\n\t\tcdir = -cdir;\n\t\tseg = {balance - seg.second, balance - seg.first};\n\t}\n\n\tint tr(int x) {\n\t\treturn cbase + cdir*x;\n\t}\n\n\tint anti(int x) {\n\t\treturn cdir * (x - cbase);\n\t}\n\n\tbool in(int x) {\n\t\tif (points.count(anti(x)))\n\t\t\treturn true;\n\t\treturn (seg.first <= x && x <= seg.second);\n\t}\n\n\tvoid push(int x) {\n\t\tpoints.insert(anti(x));\n\t}\n\n\tvoid popBelow(int x) {\n\t\tseg.second = min(seg.second, x);\n\t\tauto nextIt = [&] {\n\t\t\treturn (cdir == 1 ? prev(points.end()) : points.begin());\n\t\t};\n\t\twhile (!points.empty() && tr(*nextIt()) > x)\n\t\t\tpoints.erase(nextIt());\n\t}\n\n\tbool empty() {\n\t\treturn points.empty() && seg.first > seg.second;\n\t}\n};\n\nvoid solve() {\n\tint n; cin >> n;\n\tEndSet util;\n\tint curAns = 0;\n\tfor (int i = 0; i < n; ++i) {\n\t\tint x; cin >> x;\n\t\tutil.popBelow(x-1);\n\t\tif (x % 2 == 0 && util.in(x/2)) {\n\t\t\tcurAns += 2;\n\t\t\tutil.setPush(x/2);\n\t\t} else if (util.empty()) {\n\t\t\tif (x % 2 == 0)\n\t\t\t\tcurAns += 1, util.setPush(x/2);\n\t\t\telse\n\t\t\t\tutil.setFree(x-1);\n\t\t} else {\n\t\t\tcurAns += 1;\n\t\t\tif (x % 2 == 0)\n\t\t\t\tutil.push(x/2);\n\t\t}\n\t\tutil.rotate(x);\n\t}\n\tcout << 2*n - curAns << \"\\n\";\n}\n\nsigned main() {\n\tios::sync_with_stdio(false), cin.tie(0);\n\tint nbTests;\n\tcin >> nbTests;\n\tfor (int iTest = 0; iTest < nbTests; ++iTest) {\n\t\tsolve();\n\t}\n}\n", "src_uid": "e809d068b3ae47eb5ecfb9ac69892254"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define ull unsigned long long\n#define loop(x,n) for(int x = 0; x < n; x++)\nusing namespace std;\nint main() {\n\tint n, m, a, b;\n\tcin >> n >> m;\n\n\tint res = 0;\n\tfor (b = 0; m - b*b >= 0; b++) {\n\t\ta = m - b*b;\n\t\tif (a*a + b == n)\n\t\t\t/*printf(\"%d %d\\n\", a, b),*/res++;\n\t}\n\tcout << res;\n\treturn 0;\n}", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"source_code": "#include \nusing namespace std;\n\n\nint main() {\n int n,m;\n cin >> n >> m;\n if (n 2*m) count +=2*m;\n else if (temp >0) count += m;\n \n cout << count << endl;\n \n }", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"source_code": "#include\n#include\n#define ll long long\n#define N 40\n#define M 1000000007\nusing namespace std;\n\nll n,m=30,C[N][N],cnt[N][2],dp[N][N][2],ans;\n\ninline void add(ll &u,ll v)\n{\n\tu+=v;\n\tu%=M;\n}\n\nint main()\n{\n\tint i,j;\n\tcin>>n;\n\tfor(i=0; i<=m; i++)\n\t{\n\t\tC[i][0]=C[i][i]=1;\n\t\tfor(j=1; j=1; i--)\n\t{\n\t\tfor(j=0; j<=m; j++)\n\t\t{\n\t\t\tadd(dp[i-1][j][0],dp[i][j][0]*(1 << j)%M);\n\t\t\tadd(dp[i-1][j+1][0],dp[i][j][0]);\n\t\t\tif((1 << (i-1))&n)\n\t\t\t{\n\t\t\t\tadd(dp[i-1][j][0],dp[i][j][1]*cnt[j][0]%M);\n\t\t\t\tadd(dp[i-1][j][1],dp[i][j][1]*cnt[j][1]%M);\n\t\t\t\tadd(dp[i-1][j+1][1],dp[i][j][1]);\n\t\t\t}\n\t\t\telse add(dp[i-1][j][1],dp[i][j][1]*cnt[j][0]%M);\n\t\t}\n\t}\n\t\n\tfor(i=0; i<=m; i++)\n\t{\n\t\tadd(ans,dp[0][i][0]+dp[0][i][1]);\n\t}\n\tcout<\nint n, i, j, h;\nlong long fir, sec, p, sum, deg;\nlong long res, res2, x, d;\nlong long a[3][3], m[3][3], zz[3][3];\nint arr[1000010];\nvoid mul(long long a[3][3], long long b[3][3])\n{\n\t for (i = 1; i <= 2; i++)\n\t {\n\t\t for (j = 1; j <= 2; j++)\n\t\t {\n\t\t\t zz[i][j] = 0;\n\t\t\t for (h = 1; h <= 2; h++)\n\t\t\t {\n\t\t\t\t zz[i][j] = (zz[i][j] + a[i][h] * b[h][j]) % p;\n\t\t\t }\n\t\t }\n\t }\n}\nlong long doit(long long deg, long long x, long long mod)\n{\n\t long long res = 1;\t\n\t while (deg > 0)\n\t {\n\t\t if (deg % 2 == 0)\n\t\t {\n\t\t\t deg = deg / 2; x = (x * x) % mod;\n\t\t }\n\t\t else\n\t\t {\n\t\t\t deg--; res = (res * x) % mod;\n\t\t }\n\t }\n\t return res;\n}\nvoid find(long long tt)\n{\n\t /*if (p == 2)\n\t {\n\t\t res = doit(tt, 3, p);\n\t\t sum = (sum * res + p - (d * n) % p) % p; \n\t }\n\t else if (p % 2 == 0)\n\t {\n\t\t res = doit(tt, 3, p);\n\t\t //zz = p / 2;\n\t\t //obr = (doit(tt, 3, zz) + zz - 1) % zz;\n\t\t d = (d * (res - 1)) / 2;\n\t\t d = d % p;\n\t\t sum = (sum * res + p - d) % p;\n\t }\n\t else \n\t {*/\n\t\t res = doit(tt, 3, p);\n\t\t res2 = doit(tt, 3, p * 2) - 1; res2 = res2 / 2;\n\t\t sum = (sum * res + p - (d * res2) % p) % p;\n\t //} \n}\n/*struct thing\n{\n\t long long d, x, y;\n\t thing() {}\n\t thing(long long dd, long long xx, long long yy)\n\t {\n\t\t d = dd; x = xx; y = yy;\n\t }\n};\nthing nod(long long a, long long b)\n{\n\t if (b == 0)\n\t {\n\t\t return thing(a, 1, 0);\n\t }\n\t thing zz = nod(b, a % b);\n\t return thing(zz.d, zz.y, (zz.x + p - (zz.y * (a / b)) % p) % p); \n}*/\nint main()\n{\n\t //freopen(\"input.txt\", \"r\", stdin);\n\t //freopen(\"output.txt\", \"w\", stdout);\n\t scanf(\"%d%I64d%I64d%I64d\", &n, &fir, &sec, &p);\n\t /*if (p % 2 == 1)\n\t {\n\t\t obr = (nod(p, 2).y) % p;\n\t }*/ \n\t sum = 0;\n\t for (i = 1; i <= n; i++)\n\t {\n\t\t scanf(\"%d\", &arr[i]); sum = (sum + arr[i]) % p;\n\t }\n\t if (n == 1)\n\t {\n\t\t printf(\"%I64d\", sum); return 0;\n\t }\n \n\t deg = fir / 2; \n\t a[1][1] = 1; a[1][2] = 1;\n\t a[2][1] = 1; a[2][2] = 2;\n\t m[1][1] = 1; m[2][2] = 1;\n\t while (deg > 0)\n\t {\n\t\t if (deg % 2 == 0)\n\t\t {\n\t\t\t deg = deg / 2; \n\t\t\t mul(a, a); \n\t\t\t for (i = 1; i <= 2; i++)\n\t\t\t {\n\t\t\t\t for (j = 1; j <= 2; j++) a[i][j] = zz[i][j];\n\t\t\t }\n\t\t }\n\t\t else\n\t\t {\n\t\t\t deg--; \n\t\t\t mul(a, m); \n\t\t\t for (i = 1; i <= 2; i++)\n\t\t\t {\n\t\t\t\t for (j = 1; j <= 2; j++) m[i][j] = zz[i][j];\n\t\t\t }\n\t\t }\n\t }\n\t d = arr[1] + arr[n];\n\t find(fir);\n\t if (fir % 2 == 1)\n\t {\n\t\t d = (arr[1] + (m[1][1] + m[1][2]) * arr[n - 1] + (m[2][1] + m[2][2]) * arr[n]) % p;\n\t }\n\t else\n\t {\n\t\t d = (arr[1] + m[1][2] * arr[n - 1] + m[2][2] * arr[n]) % p;\n\t }\n\t find(sec);\t \n\t printf(\"%I64d\", sum);\n\t return 0;\n}\n", "src_uid": "b5dd2b94570973b3e312ae4b7a43284f"} {"source_code": "#include \n#include \nusing namespace std;\nint main() {\nlong long n, md;\ncin >> n >> md;\nvector f(n+1, 1);\nfor (long long i = 1; i <=n; i++)\nf[i] = f[i-1] * i % md; \nlong long max = 0;\nfor (int i = 1; i <= n; ++i)\n{\nmax += (n - i + 1) * (f[i] * f[n-i+1] % md);\nif(n\n#include \n\nusing namespace std;\n\nint main()\n{\n\tstring abc;\n\tcin >> abc;\n\tint max = int(abc[0]);\n\tbool flag = true;\n\tif (abc[0] != 'a')\n\t{\n\t\tflag = false;\n\t}\n\tfor (int i = 0; i < abc.length(); i++)\n\t{\n\t\tif (int(abc[i]) > (max + 1))\n\t\t{\n\t\t\tflag = false;\n\t\t\tbreak;\n\t\t}\n\t\tif (int(abc.at(i)) >= max)\n\t\t\tmax = int(abc[i]);\n\t\t//cout << int(abc[i]) << endl;\n\t}\n\tif (flag)\n\t\tcout << \"YES\";\n\telse\n\t\tcout << \"NO\";\n\n\t//system(\"pause\");\n\t\treturn 0;\n}", "src_uid": "c4551f66a781b174f95865fa254ca972"} {"source_code": "#include \nusing namespace std;\n\nint main() {\n\tint n, k, arr[101];\n\tcin>>n>>k;\n\tbool solvable = true;\n\tint solved=0;\n\tint lastSolve = 0;\n\tfor(int i=0; i>arr[i];\n\t\tif(arr[i]<=k && solvable) {\n\t\t\tsolved++;\n\t\t\tlastSolve=i;\n\t\t} else {\n\t\t\tsolvable = false;\n\t\t}\n\t}\n\tif(solvable == false) {\n\t\tsolvable = true;\n\t\tfor(int i=n-1; i>lastSolve; i--) {\n\t\tif(arr[i]<=k && solvable) {\n\t\t\tsolved++;\n\t\t} else {\n\t\t\tsolvable = false;\n\t\t\tlastSolve=i;\n\t\t}\n\t\t}\n\t}\n\tcout<\n#include\nusing namespace std;\ntypedef long long ll;\nint main(){\n int tmp;\n cin>>tmp;\n while(tmp--){\n int n;\n cin>>n;\n mapmp;\n for(ll i=1;i*i<=n;i++){\n mp[i*i]=true;\n if(i*i*i<=n){\n mp[i*i*i]=true;\n }\n }\n cout<\n#pragma GCC optimize(\"O3\")\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 = 4e18L + 1;\nconst int IINF = 2e9 + 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++;cerr<<'='< C;\n\ntypedef long long RL;\ntypedef complex CL;\n\n#define x real()\n#define y imag()\n\nconst R eps = 1e-14;\n\nbool eq(R r1, R r2) { return abs(r1 - r2) < eps; }\n\nbool eq(const C& c1,const C& c2) { return eq(c1.x, c2.x) and eq(c1.y, c2.y); }\n\nR dot(const C& c1, const C& c2) { return c1.x * c2.x + c1.y * c2.y;}\nR det(const C& c1, const C& c2) { return c1.x * c2.y - c1.y * c2.x;}\n\nRL dot(const CL& c1, const CL& c2) { return c1.x * c2.x + c1.y * c2.y;}\nRL det(const CL& c1, const CL& c2) { return c1.x * c2.y - c1.y * c2.x;}\n\nC to_C(const CL& cl){ return C(cl.x, cl.y);}\n\nstruct line{\n\tCL nl;\n RL cl;\n\tC n, d;\n R c;\n\t/* line(C n1, R c1) */ \n\t/* \t:n{n1 / abs(n1)}, c{c1} {} */\n\t/* line(C p1, C p2) */ \n\t/* \t:n{((p2 - p1) / abs(p2 - p1)) * C(0, 1)}, c{dot(p1, n)} {} */\n line() = default;\n line(CL p1, CL p2)\n :nl{(p2 - p1) * CL(0, 1)}, cl{dot(p1, nl)}, n{to_C(nl) / abs(to_C(nl))}, d{n.y, -n.x}, c{dot(to_C(p1), n)} {}\n\n \tbool operator <(const line& other) const {\n RL de = det(nl, other.nl);\n if(de == 0){\n return c > other.c;\n } else {\n return de > 0;\n }\n }\n\t\n\tC val(R t) const { return c * n + t * d;}\n\n\tR tis(const line& other) const {\n\t\treturn (other.c - c * dot(n, other.n)) / dot(d, other.n);\n\t}\n};\n\nostream& operator <<(ostream& o, const line& l){ return o << l.n << \" \" << l.c;}\n\nC is(const line& a, const line& b) { return a.val(a.tis(b));}\n\n\nnamespace hplane{\n const int N = 200000;\n line lns[2 * N + 1];\n C poly[2 * N + 1];\n int jd1, jd2, ju1, ju2, ans_sz, poly_sz, n = 0;\n inline int cnt(){ return ju2 + jd2 - ju1 - jd1 + 2; }\n void add(const line& l){ lns[n++] = l;}\n void clear(){ n = 0;}\n\n bool empty_is(const line& l1, const line& l2) { return eq(dot(l1.n, l2.n), -1.0) and l1.c + eps > -l2.c;}\n \n bool wrong(const line& l_prev, const line& l_last, const line& l_new) { \n if(!eq(det(l_last.nl, l_new.nl), 0)) {\n return l_last.tis(l_new) < l_last.tis(l_prev) + eps;\n } else {\n return false;\n }\n }\n\n int cor(int j1, int j2){\n sort(lns + j1, lns + j2 + 1);\n j2 = unique(lns + j1, lns + j2 + 1, [](line& l1, line& l2){ return dot(l1.nl, l2.nl) > 0 and det(l1.nl, l2.nl) == 0;}) - lns - 1;\n int j = min(j1 + 1, j2);\n rep(i, j1 + 2, j2 + 1){\n j++;\n while(j >= j1 + 2 and wrong(lns[j - 2], lns[j - 1], lns[i])){\n j--; \n }\n lns[j] = lns[i]; \n }\n return j;\n }\n\n void c_front(int& j1, int& j2, int& j3){\n while((j3 - j2) >= 1 and wrong(lns[j1], lns[j2], lns[j2 + 1])) j2++;\n }\n void c_back(int& j1, int& j2, int& j3){\n while((j2 - j1) >= 1 and wrong(lns[j2 - 1], lns[j2], lns[j3])) j2--;\n }\n void solve(){\n ju1 = partition(lns, lns + n, [](const line& l){ return det(CL(1, 0), l.nl) > 0 or (l.nl.y == 0 and l.nl.x < 0);}) - lns;\n ju2 = n - 1;\n jd1 = 0; jd2 = ju1 - 1;\n jd2 = cor(jd1, jd2); ju2 = cor(ju1, ju2);\n int chck = 0;\n while(chck != cnt() and (jd2 - jd1) >= 0 and (ju2 - ju1) >= 0 and ((jd2 - jd1) >= 1 or (ju2 - ju1) >= 1)){\n if(empty_is(lns[jd1], lns[ju2]) or empty_is(lns[ju1], lns[jd2])){\n ans_sz = 0; return;\n }\n chck = cnt();\n c_front(jd2, ju1, ju2);\n c_back(ju1, ju2, jd1);\n c_front(ju2, jd1, jd2);\n c_back(jd1, jd2, ju1);\n }\n rep(i, jd1, jd2 + 1){\n lns[i - jd1] = lns[i];\n }\n rep(i, ju1, ju2 + 1){\n lns[jd2 + 1 - jd1 + i - ju1] = lns[i];\n }\n ans_sz = cnt();\n }\n\n void get_poly(){\n if(ans_sz > 2){\n poly_sz = ans_sz;\n rep(i, 0, ans_sz){\n poly[i] = is(lns[i], lns[(i + 1) % ans_sz]);\n }\n } else {\n poly_sz = 0;\n }\n }\n}\n\nR triangle_area(C v1, C v2, C v3){ return fabs(det(v2 - v1, v2 - v3)) / 2.0; }\n\nR poly_area(C* poly, int pn){\n R res = 0.0;\n rep(i, 1, pn - 1){\n res += triangle_area(poly[0], poly[i], poly[i + 1]);\n }\n return res;\n}\n\nconst int N = 2e5;\nCL pts[N + 1];\nint n;\nCL p0, cp;\n\nR solve(){\n hplane::clear();\n hplane::add(line(CL(1e6, 1e6) - p0, CL(-1e6, 1e6) - p0));\n hplane::add(line(CL(-1e6, 1e6) - p0, CL(-1e6, -1e6) - p0));\n hplane::add(line(CL(-1e6, -1e6) - p0, CL(1e6, -1e6) - p0));\n hplane::add(line(CL(1e6, -1e6) - p0, CL(1e6, 1e6) - p0));\n sort(pts, pts + n, [](auto& p1, auto& p2){ return !(p1.y >= 0 and p2.y < 0) and ((p1.y < 0 and p2.y >= 0) or det(p1, p2) > 0);});\n int j = 0;\n rep(i, 0, n){\n while((j + 1) % n != i and det(pts[i], pts[(j + 1) % n]) >= 0){\n j = (j + 1) % n;\n }\n if(det(pts[i], pts[(i + 1) % n]) > 0){\n hplane::add(line(pts[i], pts[(i + 1) % n]));\n } else if(det(pts[i], pts[(i + 1) % n]) == 0){\n return 0;\n }\n if(det(pts[i], pts[j]) > 0){\n hplane::add(line(pts[i], pts[j]));\n } else if(i != j and det(pts[i], pts[j]) == 0){\n return 0;\n }\n }\n hplane::solve();\n hplane::get_poly();\n return poly_area(hplane::poly, hplane::poly_sz);\n}\n\nint main()\n{\n#ifndef LOCAL\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n#endif\n int T; cin >> T;\n rep(_, 0, T){\n cin >> n; n--;\n R ix0, iy0; cin >> ix0 >> iy0;\n p0 = CL(ix0, iy0);\n rep(i, 0, n){\n R ix, iy; cin >> ix >> iy;\n pts[i] = CL(ix, iy);\n pts[i] -= p0;\n }\n cout << setprecision(15) << fixed << solve() << \"\\n\";\n }\n return 0;\n}\n", "src_uid": "6afe0718ad89e3fd51a456e0144c538d"} {"source_code": "#include \n#include \n#include \nusing namespace std;\n\nint main(void) {\n int x1, y1, x2, y2, d=0, d1=0, d2=0;\n cin>>x1>>y1>>x2>>y2;\n \n if(x1!=x2 && y1!=y2){\n if(x1x2 && y1y2){\n d1 += y1 - y2 + fabs(x2 - x1 - (y1-y2));\n d2 += x2 - x1 + fabs(y1 - (x2-x1) - y2);\n }\n else if(x1>x2 && y1>y2){\n d1 += x1 - x2 + fabs(y1 - (x1-x2) - y2);\n d2 += fabs(y1 - y2) + fabs(x1 - (y1-y2) - x2);\n //cout<=0 && d2>=0) d = min(d1, d2);\n else if(d1>=0 && d2<0) d=d1;\n else d=d2;\n }\n \n else if(x1==x2 && y1!=y2) d = fabs(y2-y1);\n else if(y1==y2 && x1!=x2) d = fabs(x2-x1);\n else d=0;\n cout<\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 int LL;\ntypedef pair PII;\n\n// arithmetic progressiong sum -> m + m+1 + ... + k-1 + k\nLL range_sum(LL m, LL k) {\n LL n = k-m+1;\n return (n*(m+k))/2;\n}\n\nLL combine(LL m, LL k) {\n LL n = k-m+1;\n return range_sum(m, k) - n + 1;\n}\n\nLL result(LL n, LL k, LL m) {\n LL terms = k-m+1;\n LL sum = (terms*(m+k))/2 - terms + 1;\n if (sum >= n)\n return sum;\n sum--;\n LL dif = n - sum;\n if (dif >= m)\n return sum+1;\n assert(sum+dif == n);\n return sum+dif;\n}\n\nint main(int argc, char*argv[]) {\n ios_base::sync_with_stdio(false);\n LL n, k;\n cin >> n >> k;\n\n if (n == 1)\n cout << 0 << endl;\n else if (combine(2, k) < n)\n cout << -1 << endl;\n else if (combine(2, k) == n)\n cout << k-1 << endl;\n else if (combine(k, k) == n)\n cout << 1 << endl;\n else {\n LL lo=2, hi=k;\n\n while (lo <= hi) {\n LL mid = lo + (hi-lo)/2;\n LL res = result(n, k, mid);\n if (res == n) {\n cout << k-mid+2 << endl;\n break;\n } else if (res < n)\n hi = mid-1;\n else\n lo = mid+1;\n }\n }\n\n\n return EXIT_SUCCESS;\n}\n", "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"source_code": "//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee\n#include\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\n#define MX 1000000000\n#define endl '\\n'\n#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n#define fr first\n#define sc second\n#define MOD 1000000007\n\nint main()\n{\n startt;\n int n, k;\n cin >> n >> k;\n int a[n+2];\n for(int i = 1 ; i <= n; i++)\n {\n cin >> a[i];\n }\n int ans = 0;\n for(int i = 0; i <= n; i++)\n {\n if(k-i >= 1 && k+i <= n)\n {\n if(a[k-i] + a[k+i] == 2)\n {\n ans+=2-int(i == 0);\n }\n }\n else\n {\n if(k-i >= 1)\n {\n ans+=a[k-i];\n }\n if(k+i <= n)\n {\n ans+=a[k+i];\n }\n }\n }\n cout << ans << endl;\n}\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nconst int MaxN = 410;\nconst int MOD = 10007;\n\nchar s[MaxN];\nint n,m,N,cnt,a[MaxN][MaxN],b[MaxN][MaxN],c[MaxN][MaxN];\nint f[MaxN][MaxN][MaxN];\n\ninline void mul(int a[][MaxN],int b[][MaxN],int c[][MaxN]){\n\tstatic int d[MaxN][MaxN];\n\tmemset(d,0,sizeof(d));\n\tfor(int i=0;i>=1,mul(a,a,a)) if(x&1) mul(c,a,c);\n}\n\nint F(int l,int r,int C){\n\tif(f[l][r][C]!=-1) return f[l][r][C];\n\tint &t=f[l][r][C];\n\tif(l==r) return t=!C;\n\telse if(s[l]==s[r]) return t=(l+1==r ? !C : F(l+1,r-1,C));\n\telse return t=C ? F(l,r-1,C-1)+F(l+1,r,C-1)%MOD : 0;\n}\nint main()\n{\n\tscanf(\"%s%d\",s,&n);\n\tm=strlen(s);n+=m;cnt=n+1>>1;\n\tint n1=m-1,n2=m+1>>1,n3=n2;\n\tN=n1+n2+n3;\n\tfor(int i=0;i>1,flag=~(m-c1)&1;\n\t\tint c3=cnt-c1-c2;\n\t\tif(c3<0) continue;\n\t\tint tot=F(0,m-1,c1);\n\t\tres+=1LL*tot*a[n1-c1][n1+n2+c2-1];\n\t\tif((n&1) && flag) res+=1LL*MOD*MOD-1LL*tot*c[n1-c1][n1+c2-1];\n\t}\n\tprintf(\"%d\\n\",int(res%MOD));\n\treturn 0;\n}\n", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8"} {"source_code": "#include \nusing namespace std;\nlong long n;\nint main()\n{\n\tcin>>n;\n\tn++;\n\tif(n==1)\n\tcout<<0;\n\telse if(n%2==0)\n\tcout<\nusing namespace std;\ntypedef long long ll;\nll n,k;\nint main() {\n int flag=0,sum=0;\n cin >> n >> k;\n ll s=sqrt(n);\n if(s*s==n) flag=1;\n for(int i=1;isum) {\n cout << \"-1\" << endl;\n }\n else {\n if(k*2-1==sum) {\n cout << s << endl;\n return 0;\n }\n int ss=0;\n for(int i=1;i\nusing namespace std;\ntypedef long long ll;\nint main(){\n ll w,m;\n while(cin>>w>>m){\n int flag=1;\n for(int i=1;i<=100;i++){\n ll tt=m%w;\n if(tt!=0&&tt!=1&&tt!=w-1)flag=0;\n if(tt==w-1)m++;\n m/=w;\n }\n puts(flag?\"YES\":\"NO\");\n }\n return 0;\n}\n", "src_uid": "a74adcf0314692f8ac95f54d165d9582"} {"source_code": "#include\n#include\n\nusing namespace std;\n\nbool isLetter(char& x) {\n return (x >= 65 && x <= 90);\n}\n\nint main() {\n\n long long int probz = 1;\n int letterProb = 10;\n int so2al = 0;\n\n char s;\n bool letters[10] = { 0 };\n\n s=getchar();\n\n if (s == '?')\n probz *= 9;\n\n else if (isLetter(s)) {\n probz *= 9;\n letterProb -= 1;\n letters[s - 65] = 1;\n }\n\n while(s!='\\n'){\n s = getchar();\n if (isLetter(s) && !letters[s - 65]) {\n probz *= (letterProb == 0) ? 1 : letterProb;\n letterProb -= (letterProb == 0) ? 0 : 1;\n letters[s - 65] = 1;\n }\n\n else if (s == '?') {\n so2al++;\n }\n }\n\n cout<\n#include \nusing namespace std;\n\nconst double pi = acos(-1.0);\nconst double eps = 1e-6;\n\ndouble sqr(double x)\n{\n return x * x;\n}\ndouble min(double x,double y)\n{\n return x > y ? y : x;\n}\ndouble max(double x,double y)\n{\n return x > y ? x : y;\n}\ndouble area(double x0,double y0,double x1,double y1,double x2,double y2)\n{\n return (x1-x0)*(y2-y0) - (x2-x0)*(y1-y0);\n}\nint cross(double x0,double y0,double x1,double y1,double x2,double y2)\n{\n double tmp = area(x0,y0,x1,y1,x2,y2);\n if(tmp > eps)return 1;\n if(tmp < -eps)return -1;\n return 0;\n}\nbool blockByWall(int xw1,int yw1,int xw2,int yw2,double x1,double y1,double x2,double y2)\n{\n if(min(xw1,xw2) > max(x1,x2)+eps || min(yw1,yw2) > max(y1,y2)+eps || min(x1,x2) > max(xw1,xw2)+eps || min(y1,y2) > max(yw1,yw2)+eps)return 0;\n \n if(cross(x1,y1,x2,y2,xw1,yw1) * cross(x1,y1,x2,y2,xw2,yw2) > 0)return 0;\n if(cross(xw1,yw1,xw2,yw2,x1,y1) * cross(xw1,yw1,xw2,yw2,x2,y2) > 0)return 0;\n \n return 1;\n}\n\nbool blockByMirror(int xm1,int ym1,int xm2,int ym2,double x1,double y1,double x2,double y2)\n{\n if(!blockByWall(xm1,ym1,xm2,ym2,x1,y1,x2,y2))return 0;\n if(cross(x1,y1,x2,y2,xm1,ym1) == 0 && cross(x1,y1,x2,y2,xm2,ym2) == 0)return 0;\n return 1;\n}\n\nvoid getReflection(int xm1,int ym1,int xm2,int ym2,double x,double y,double &xx,double &yy)\n{\n double a = sqr(xm1-xm2) + sqr(ym1-ym2);\n double b = sqr(xm1-x) + sqr(ym1-y);\n double c = sqr(xm2-x) + sqr(ym2-y);\n \n double cosb = ((a+b-c)/2/sqrt(a*b));\n double cosc = ((a+c-b)/2/sqrt(a*c));\n \n double bb = sqrt(b)*cosb;\n double cc = sqrt(c)*cosc;\n /*\n if(alpha > pi/2)bb = -bb;\n if(beta > pi/2)cc = -cc;\n */\n xx = (xm1*cc + xm2*bb) / (bb+cc);\n yy = (ym1*cc + ym2*bb) / (bb+cc);\n \n xx = xx + xx - x;\n yy = yy + yy - y;\n}\nvoid getIntersection(double x1,double y1,double x2,double y2,double xx1,double yy1,double xx2,double yy2,double &x,double &y)\n{\n double s1 = area(x1,y1,x2,y2,xx1,yy1);\n double s2 = area(x1,y1,xx2,yy2,x2,y2);\n double ss = s1 + s2;\n \n x = (xx1 * s2 + xx2 * s1) / (s1 + s2);\n y = (yy1 * s2 + yy2 * s1) / (s1 + s2);\n}\nint main()\n{\n int x1,y1,x2,y2;\n int xw1,xw2,yw1,yw2;\n int xm1,xm2,ym1,ym2;\n \n cin >> x1 >> y1;\n cin >> x2 >> y2;\n cin >> xw1 >> yw1 >> xw2 >> yw2;\n cin >> xm1 >> ym1 >> xm2 >> ym2;\n \n if(!blockByWall(xw1,yw1,xw2,yw2,x1,y1,x2,y2) && !blockByMirror(xm1,ym1,xm2,ym2,x1,y1,x2,y2))\n cout << \"YES\" << endl;\n else if(cross(xm1,ym1,xm2,ym2,x1,y1) * cross(xm1,ym1,xm2,ym2,x2,y2) < 0)\n cout << \"NO\" << endl;\n else if(cross(xm1,ym1,xm2,ym2,x1,y1) != 0 || cross(xm1,ym1,xm2,ym2,x2,y2) !=0)\n {\n double xx2,yy2;\n getReflection(xm1,ym1,xm2,ym2,x2,y2,xx2,yy2);\n \n if(!blockByMirror(xm1,ym1,xm2,ym2,x1,y1,xx2,yy2))\n cout << \"NO\" << endl;\n else{\n double xx,yy;\n getIntersection(xm1,ym1,xm2,ym2,x1,y1,xx2,yy2,xx,yy);\n if(blockByWall(xw1,yw1,xw2,yw2,x1,y1,xx,yy) || blockByWall(xw1,yw1,xw2,yw2,x2,y2,xx,yy))\n cout << \"NO\" << endl;\n else\n cout << \"YES\" << endl;\n }\n }else cout << \"NO\" << endl;\n// system(\"pause\");\n}\n", "src_uid": "7539a41268b68238d644795bccaa0c0f"} {"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\ntypedef long long int LLint;\nusing namespace std;\n\n\nvector canonicalGroups(LLint x) {\n vector results;\n\n LLint rghtBorder = 0;\n\n results.push_back(1);\n for (LLint i = 2; i < sqrt(x); i++) {\n LLint tmp = 1;\n while (x % i == 0) {\n x /= i;\n tmp *= i;\n }\n if(tmp != 1)\n results.push_back(tmp);\n }\n\n if (x != 1) {\n results.push_back(x);\n }\n return results;\n}\n\n\nint main() {\n\n LLint x;\n cin >> x;\n\n\n auto groups = canonicalGroups(x);\n \n LLint finRes1 = LLONG_MAX;\n LLint finRes2 = LLONG_MAX;\n\n LLint n = groups.size();\n\n for (int i = 0; i < (1 << n); i++) {\n LLint localRes = 1;\n for (int j = 0; j < n; j++) {\n if (i & (1 << j))\n localRes *= groups[j];\n }\n if (max(localRes, x / localRes) < max(finRes1,finRes2)) {\n finRes1 = localRes;\n finRes2 = x / localRes;\n }\n }\n\n cout << finRes1 << \" \" << finRes2 << endl;\n return 0;\n}\n\n", "src_uid": "e504a04cefef3da093573f9df711bcea"} {"source_code": "//writen by @libra9z\n//please don't hack me ! if you do this , please leave a message to me ! I'm looking forward to hearing from you !\n#define __NOT_USE_CPLUSPLUS\n//#define LOCAL_TIME\n//#define FILE_JUDGE\n#pragma comment(linker, \"/stack:20000000\")\n#pragma warning(disable:4146)\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#define _CRT_SECURE_NO_WARNINGS\n//\"C\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//\"C++\"\n#ifndef __NOT_USE_CPLUSPLUS\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n//\"C++11\"\n#if __cplusplus >= 201103L\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#endif //\"C++11\"\nusing namespace std;\n#endif //\"C++\"\nunsigned long long rdtsc(){unsigned long long ret=0;asm volatile(\"rdtsc\" : \"=A\" (ret) : :);return ret;}\ntypedef char i8;\ntypedef unsigned char u8;\ntypedef short i16;\ntypedef unsigned short u16;\ntypedef int i32;\ntypedef unsigned int u32;\ntypedef long i32p;\ntypedef unsigned long u32p;\ntypedef long long i64;\ntypedef unsigned long long u64;\ntypedef long long ll;\ntypedef unsigned long long ull;\n#define rep(i,n) for (int i=0;i<(n);i++)\n#define Rep(i,a,b) for (int i=(a);i<=(b);i++)\n#define rrep(i,n) for (int i=(n)-1;i>=0;i--)\n#define rRep(i,a,b) for (int i=(a);i>=b;i--)\n#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)\n#define X first\n#define Y second\n#define sqr(x) ((x)*(x))\n#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)\n#define all(a) (a).begin(),(a).end()\n#define rall(a) (a).rbegin(),(a).rend()\n#define reunique(v) v.erase(unique(all(v)),v.end())\n#define prl cerr << \"called: \" << __LINE__ << endl\n#define eaq(n,x) __typeof(x) n=x;\n#define RET(p,x) return p<\n#include\n#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 mp make_pair\n#define pb push_back\nusing namespace std;\n\ntypedef long long LL;\ntypedef double ld;\n\nconst LL Mod=1000000007;\nconst LL MAX=150+10;\n\nLL n,m;\n\nLL f[MAX][MAX][MAX][4],g[MAX][MAX][MAX][4];//可以变大 不可以变大\nLL sum[MAX][MAX][4];\n\nvoid add(LL& a,LL b)\n{\n\ta+=b;\n\twhile(a<0)a+=Mod;\n\ta%=Mod;\n}\n\nLL ask(LL l,LL a,LL b)\n{\n\treturn sum[a][b][l];\n}\n\nLL get(LL l,LL a,LL b,LL c,LL d)\n{\n\treturn ((LL)ask(l,b,d)-ask(l,b,c-1)-ask(l,a-1,d)+ask(l,a-1,c-1)+2*Mod)%Mod;\n}\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\",\"r\",stdin);freopen(\"output.txt\",\"w\",stdout);\n#endif\n\tint i,j,k,l;\n\tcin>>n>>m;\n\tfor(j=1;j<=m;++j)\n\t\tfor(k=j;k<=m;++k)\n\t\t\tf[1][j][k][3]=1;\n\tfor(i=2;i<=n;++i)\n\t{\n\t\tmemset(sum,0,sizeof sum);\n\t\tfor(j=1;j<=m;++j)\n\t\t\tfor(k=1;k<=m;++k)\n\t\t\t\tfor(l=0;l<4;++l)\n\t\t\t\t\tsum[j][k][l]=(f[i-1][j][k][l]+sum[j-1][k][l]+sum[j][k-1][l]-sum[j-1][k-1][l]+Mod)%Mod;\n\t\tfor(j=1;j<=m;++j)\n\t\t\tfor(k=j;k<=m;++k)\n\t\t\t{\n\t\t\t\t//1 1\n\t\t\t\tadd(f[i][j][k][3],get(3,j,m,1,k));\n\t\t\t\t//1 0\n\t\t\t\tadd(f[i][j][k][2],get(2,j,k,k,m));\n\t\t\t\tif(k+1<=m)add(f[i][j][k][2],get(3,j,k,k+1,m));\n\t\t\t\t//0 1\n\t\t\t\tadd(f[i][j][k][1],get(1,1,j,j,k));\n\t\t\t\tif(j-1>0)add(f[i][j][k][1],get(3,1,j-1,j,k));\n\t\t\t\t//0 0\n\t\t\t\tif(j-1>0 && k+1<=m)\n\t\t\t\t\tadd(f[i][j][k][0],get(3,1,j-1,k+1,m));\n\t\t\t\tif(j-1>0)\n\t\t\t\t\tadd(f[i][j][k][0],get(2,1,j-1,k,m));\n\t\t\t\tif(k+1<=m)\n\t\t\t\t\tadd(f[i][j][k][0],get(1,1,j,k+1,m));\n\t\t\t\tadd(f[i][j][k][0],get(0,1,j,k,m));\n\t\t\t}\n\t}\n\t/*\n\t 111\n\t 11\n\t */\n\tLL ans=0;\n\tfor(i=1;i<=n;++i)\n\t\tfor(j=1;j<=m;++j)\n\t\t\tfor(k=j;k<=m;++k)\n\t\t\t\tfor(l=0;l<4;++l)\n\t\t\t\t{\n\t\t\t\t\tLL c=f[i][j][k][l];\n\t\t\t\t\tadd(ans,c*(n-i+1));\n\t\t\t\t}\n\tcout<\nusing namespace std;\nint main()\n{\n int d,l,v1,v2;\n cin>>d>>l>>v1>>v2;\n int space=l-d;\n double ans =(space*1.0)/(v1+v2);\n cout<\n\nusing namespace std;\n\nbool func(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4,float a,float b)\n{\n\tbool p,q;\n\tfloat m1,m2,m3,m4;\n\tfloat c1,c2,c3,c4;\n\tm1=(y2-y1)/(x2-x1);m2=(y4-y3)/(x4-x3);m3=(y3-y2)/(x3-x2);m4=(y1-y4)/(x1-x4);\n\tc1=y1-m1*x1;c2=y3-m2*x3;c3=y2-m3*x2;c4=y4-m4*x4;\n\tif((b-m1*a-c1)*(b-m2*a-c2)<=0)\n\t\tp=1;\n\telse\n\t\tp=0;\n\tif((b-m3*a-c3)*(b-m4*a-c4)<=0)\n\t\tq=1;\n\telse\n\t\tq=0;\n\treturn p&q;\n}\nint main()\n{\n\tfloat ax1,ax2,ax3,ax4,ay1,ay2,ay3,ay4;\n\tfloat bx1,bx2,bx3,bx4,by1,by2,by3,by4;\n\tcin>>ax1>>ay1>>ax2>>ay2>>ax3>>ay3>>ax4>>ay4;\n\tcin>>bx1>>by1>>bx2>>by2>>bx3>>by3>>bx4>>by4;\n\tfloat lx1,rx1,dy1,uy1;\n\tlx1=min(ax1,min(ax2,min(ax3,ax4)));\n\trx1=max(ax1,max(ax2,max(ax3,ax4)));\n\tdy1=min(ay1,min(ay2,min(ay3,ay4)));\n\tuy1=max(ay1,max(ay2,max(ay3,ay4)));\n\tfor(float i=lx1;i<=rx1;i++)\n\t{\n\t\tfor(float j=dy1;j<=uy1;j++)\n\t\t{\n\t\t\tif(func(bx1,by1,bx2,by2,bx3,by3,bx4,by4,i,j))\n\t\t\t{\n\t\t\t\tcout<<\"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\nusing namespace std;\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 fore(i,l,r) for (int i = int(l); i <= int(r); i++)\n#define all(a) a.begin(), a.end()\n#define sz(a) int(a.size())\n#define mp make_pair\n#define pb push_back\n#define ft first\n#define sc second\n#define x first\n#define y second\n\ntemplate inline X abs(const X& a) { return a < 0 ? -a : a; }\ntemplate inline X sqr(const X& a) { return a * a; }\n\ntypedef long long li;\ntypedef long double ld;\ntypedef pair pt;\n\nconst int INF = int(1e9);\nconst li INF64 = li(1e18);\nconst ld EPS = 1e-9;\nconst ld PI = acosl(ld(-1));\n\nconst int N = 100 * 1000 + 15;\nint w, h;\nint n;\npair a[N];\n\ninline void readPt (pt& p)\n{\n\tint x, y;\n\tassert(scanf (\"%d%d\", &x, &y) == 2);\n\t\n\tp = mp(ld(x), ld(y));\n}\n\ninline bool read()\n{\n\tif (scanf (\"%d%d%d\", &w, &h, &n) != 3)\n\t\treturn false;\n\t\t\n\tforn (i, n)\n\t{\n\t\treadPt(a[i].ft);\n\t\treadPt(a[i].sc);\n\t}\n\n\treturn true;\n}\n\ninline bool operator < (const pt& a, const pt& b)\n{\n\tif (abs(a.x - b.x) < EPS)\n\t\treturn a.y < b.y;\n\t\t\n\treturn a.x < b.x;\n}\n\ninline bool in (const ld& a, const ld& b, const ld& p)\n{\n\treturn min(a, b) <= p + EPS && p <= max(a, b) + EPS;\n}\n\ninline bool in (const pt& a, const pt& b, const pt& p)\n{\n\treturn in(a.x, b.x, p.x) && in(a.y, b.y, p.y); \n}\n\ninline ld det (const ld& a, const ld& b, const ld& c, const ld& d)\n{\n\treturn a * d - b * c;\n}\n\ninline bool intersect (const pt& a, const pt& b, const pt& c, const pt& d, pt& p)\n{\n\tld A1 = a.y - b.y, B1 = b.x - a.x;\n\tld C1 = -(A1 * a.x + B1 * a.y);\n\t\n\tld A2 = c.y - d.y, B2 = d.x - c.x;\n\tld C2 = -(A2 * c.x + B2 * c.y);\n\t\n\tld D = det(A1, B1, A2, B2);\n\t\n\tif (abs(D) < EPS)\n\t\treturn false;\n\t\t\n\tp.x = -det(C1, B1, C2, B2) / D;\n\tp.y = -det(A1, C1, A2, C2) / D;\n\t\n\treturn in(a, b, p) && in(c, d, p);\n}\n\ninline bool merge (pt& a, pt& b, pt c, pt d)\n{\n\tld A = a.y - b.y, B = b.x - a.x;\n\tld C = -(A * a.x + B * a.y);\n\t\n\tif (abs(A * c.x + B * c.y + C) > EPS)\n\t\treturn false;\n\tif (abs(A * d.x + B * d.y + C) > EPS)\n\t\treturn false;\n\t\t\n\tif (!in(a, b, c) && !in(a, b, d) && !in(c, d, a) && !in(c, d, b))\n\t\treturn false;\n\t\t\n\tif (a > b)\n\t\tswap(a, b);\n\tif (c > d)\n\t\tswap(c, d);\n\t\t\n\ta = min(a, c), b = max(b, d);\n\t\n\treturn true;\n}\n\ninline bool cmpEq (const pt& a, const pt& b)\n{\n\treturn abs(a.x - b.x) < EPS && abs(a.y - b.y) < EPS;\n}\n\nint sze;\npt e[N];\nvector p[N];\nvector g[N], used[N];\n\nint cntG;\nvector gran[N];\nld area[N];\nint id[N];\n\npt pole;\n\ninline bool cmpAng (const int& a, const int& b)\n{\n\treturn atan2(e[a].y - pole.y, e[a].x - pole.x) < atan2(e[b].y - pole.y, e[b].x - pole.x);\n}\n\ninline ld getArea (const vector& a)\n{\n\tld ans = 0;\n\tforn (i, sz(a))\n\t{\n\t\tint ni = (i + 1) % sz(a);\n\t\t\n\t\tans += (e[ a[ni] ].x - e[ a[i] ].x) * (e[ a[ni] ].y + e[ a[i] ].y);\n\t}\n\t\n\treturn ans / ld(2);\n}\n\nint col[N];\nint cntCol = 0;\n\nvoid dfs (int v)\n{\n\tif (col[v] != -1)\n\t\treturn;\n\t\t\n\tcol[v] = cntCol;\n\t\n\tforn (i, sz(g[v]))\n\t{\n\t\tint to = g[v][i];\n\t\t\n\t\tdfs(to);\n\t}\n}\n\ninline bool onSeg (const pt& a, const pt& b, const pt& p)\n{\n\tld A = a.y - b.y, B = b.x - a.x;\n\tld C = -(A * a.x + B * a.y);\n\t\n\tif (abs(A * p.x + B * p.y + C) > EPS)\n\t\treturn false;\n\t\t\n\treturn in(a, b, p);\n}\n\ninline bool onPoly (const vector& a, const pt& p)\n{\n\tpt p2 = mp(p.x + 28657, p.y + 33461);\n\t\n\tint cnt = 0;\n\tforn (i, sz(a))\n\t{\n\t\tint ni = (i + 1) % sz(a);\n\t\t\n\t\tif (onSeg(e[ a[i] ], e[ a[ni] ], p))\n\t\t\treturn true;\n\t\t\n\t\tpt pp;\n\t\tcnt += intersect(e[ a[i] ], e[ a[ni] ], p, p2, pp);\n\t}\n\t\n\treturn cnt & 1;\n}\n\nstring colOut[N];\nstring colIn[N];\n\nvoid colorBorder (int cid, const string& s);\n\nset gused, cused;\n\nvector par;\nvector< vector > gg;\n\nvoid colorGran (int gid, const string& s)\n{\n\tif (gused.count(gid))\n\t\treturn;\n\t\t\n\tgused.insert(gid);\n\t\n\t//cerr << \"G \" << gid << ' ' << s << endl;\n\t\n\t/*int inner = -1;\n\tforn (i, cntG)\n\t{\n\t\tif (!onPoly(gran[gid], e[ gran[i][0] ]))\n\t\t\tcontinue;\n\t\t\t\n\t\tif (id[i] == id[gid] || colOut[ id[i] ] != colIn[gid])\n\t\t\tcontinue;\n\t\t\t\n\t\tif (inner == -1 || area[inner] < area[i])\n\t\t\tinner = i;\n\t}\n\t\n\tif (inner != -1)\n\t\tcolorBorder(id[inner], s);*/\n\t\t\n\tforn (i, sz(gg[gid]))\n\t{\n\t\tint to = gg[gid][i];\n\t\t\n\t\tif (colOut[to] != colIn[gid])\n\t\t\tcontinue;\n\t\t\t\n\t\tcolorBorder(to, s);\n\t}\n\t\n\tif (colIn[gid] == colOut[ id[gid] ])\n\t{\n\t\tcolIn[gid] = s;\n\t\tcolorBorder(id[gid], s);\n\t}\n\telse\n\t\tcolIn[gid] = s;\t\n}\n\nvoid colorBorder (int cid, const string& s)\n{\n\tif (cused.count(cid))\n\t\treturn;\n\t\t\n\t//cerr << \"C \" << cid << ' ' << s << endl;\n\t\t\n\tcused.insert(cid);\n\n\tforn (i, cntG)\n\t\tif (id[i] == cid && colIn[i] == colOut[cid])\n\t\t\tcolorGran(i, s);\n\t\t\t\n\tint outer = par[cid];\n\t\t\t\n\tif (outer != -1 && colIn[outer] == colOut[cid])\n\t\tcolorGran(outer, s);\n\t\t\t\n\tcolOut[cid] = s;\n}\n\nmap res;\n\ninline void solve()\n{\n\ta[n++] = mp(mp(0, 0), mp(0, h));\n\ta[n++] = mp(mp(0, h), mp(w, h));\n\ta[n++] = mp(mp(w, h), mp(w, 0));\n\ta[n++] = mp(mp(w, 0), mp(0, 0));\n\n\tforn (i, n)\n\t\tfore (j, i + 1, n - 1)\n\t\t\tif (merge(a[i].ft, a[i].sc, a[j].ft, a[j].sc))\n\t\t\t{\n\t\t\t\tswap(a[j], a[n - 1]);\n\t\t\t\tn--;\n\t\t\t\tj++;\n\t\t\t}\n\t\t\t\n\tsze = 0;\n\t\n\tforn (i, n)\n\t{\n\t\te[sze++] = a[i].ft;\n\t\te[sze++] = a[i].sc;\n\t\t\n\t\tp[i].pb(a[i].ft);\n\t\tp[i].pb(a[i].sc);\n\t\t\n\t\tfore(j, i + 1, n - 1)\n\t\t{\n\t\t\tpt pp;\n\t\t\tif (intersect(a[i].ft, a[i].sc, a[j].ft, a[j].sc, pp))\n\t\t\t{\n\t\t\t\te[sze++] = pp;\n\t\t\t\tp[i].pb(pp);\n\t\t\t\tp[j].pb(pp);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tsort(e, e + sze);\n\tsze = int(unique(e, e + sze, cmpEq) - e);\n\t\n\tforn (i, n)\n\t{\n\t\tsort(all(p[i]));\n\t\tp[i].erase(unique(all(p[i])), p[i].end());\n\t\t\n\t\tforn (j, sz(p[i]) - 1)\n\t\t{\n\t\t\tint cur = int(lower_bound(e, e + sze, p[i][j]) - e);\n\t\t\tint nxt = int(lower_bound(e, e + sze, p[i][j + 1]) - e);\n\t\t\t\n\t\t\tg[nxt].pb(cur);\n\t\t\tg[cur].pb(nxt);\n\t\t}\t\n\t}\n\t\n\tforn (i, sze)\n\t{\n\t\tused[i].resize(sz(g[i]));\n\t\tforn (j, sz(used[i]))\n\t\t\tused[i][j] = 0;\n\t\t\t\n\t\tpole = e[i];\n\t\tsort(all(g[i]), cmpAng);\n\t}\n\t\n\tcntG = 0;\n\t\n\tforn (i, sze)\n\t\tforn (j, sz(g[i]))\n\t\t\tif (!used[i][j])\n\t\t\t{\n\t\t\t\tint v = i, id = j;\n\t\t\t\twhile (!used[v][id])\n\t\t\t\t{\n\t\t\t\t\tused[v][id] = 1;\n\t\t\t\t\tgran[cntG].pb(v);\n\t\t\t\t\t\n\t\t\t\t\tint to = g[v][id];\n\t\t\t\t\t\n\t\t\t\t\tint nid = -1;\n\t\t\t\t\tforn (k, sz(g[to]))\n\t\t\t\t\t\tif (g[to][k] == v)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tnid = k;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\tassert(nid != -1);\n\n\t\t\t\t\tnid = (nid + 1) % sz(g[to]);\n\t\t\t\t\t\n\t\t\t\t\tv = to, id = nid;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tarea[cntG] = getArea(gran[cntG]);\n\t\t\t\t\n\t\t\t\tif (area[cntG] > -EPS)\n\t\t\t\t\tcntG++;\n\t\t\t\telse\n\t\t\t\t\tgran[cntG].clear();\n\t\t\t}\n\t\t\t\n\tcntCol = 0;\n\tforn (i, sze)\n\t\tcol[i] = -1;\n\t\t\n\tforn (i, sze)\n\t\tif (col[i] == -1)\n\t\t{\n\t\t\tdfs(i);\n\t\t\tcntCol++;\n\t\t}\n\t\t\n\tforn(i, cntG)\n\t{\n\t\tid[i] = col[ gran[i][0] ];\n\n\t\tcolOut[ id[i] ] = \"black\";\n\t\tcolIn[i] = \"white\";\t\t\n\t}\t\t\n\t\t\n\tgg.resize(cntG);\n\tpar.resize(cntCol);\n\t\n\tforn (cid, cntCol)\n\t{\n\t\tpt p;\n \tforn (i, cntG)\n \t\tif (id[i] == cid)\n \t\t{\n \t\t\tp = e[ gran[i][0] ];\n \t\t\tbreak;\n \t\t}\n \t\n\t\tint outer = -1;\n\t\tforn (i, cntG)\n\t\t\tif (onPoly(gran[i], p) && id[i] != cid && (outer == -1 || area[outer] > area[i]))\n\t\t\t\touter = i;\n\t\t\t\t\n\t\tpar[cid] = outer;\n\t\tif (outer != -1)\n\t\t\tgg[outer].pb(cid);\n\t}\n\t\t\n\tint m;\n\tassert(scanf (\"%d\", &m) == 1);\n\tforn (i, m)\n\t{\n\t\t//cerr << \"-----\" << endl;\n\n\t\tint x, y;\n\t\tchar buf[30];\n\t\t\n\t\tassert(scanf (\"%d%d%s\", &x, &y, buf) == 3);\n\t\t\n\t\tstring curColor = string(buf);\n\t\t\n\t\tint cid = -1;\n\t\tforn (j, n)\n\t\t\tif (onSeg(a[j].ft, a[j].sc, mp(x, y)))\n\t\t\t{\n\t\t\t\tint it = int(lower_bound(e, e + sze, a[j].ft) - e);\n\t\t\t\tcid = col[it];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t//cerr << cid << endl;\n\t\t\t\n\t\tif (cid != -1)\n\t\t{\n\t\t\tcused.clear();\n\t\t\tgused.clear();\n\t\t\tcolorBorder(cid, curColor);\n\t\t\tcontinue;\n\t\t}\n\t\t\n\t\tint gid = -1;\n\t\tforn (j, cntG)\n\t\t\tif (onPoly(gran[j], mp(x, y)))\n\t\t\t\tif (gid == -1 || area[j] < area[gid])\n\t\t\t\t\tgid = j;\n\t\t\t\t\t\n\t\tassert(gid != -1);\n\n\t\tgused.clear();\n\t\tcused.clear();\n\t\tcolorGran(gid, curColor);\t\n\t}\n\t\n\t/*cerr << \"----------\" << endl;\n\t\n\tforn (i, cntG)\n\t{\n\t\tcerr << id[i] << endl;\n\t\tcerr << colIn[i] << ' ' << colOut[ id[i] ] << endl;\n\t\t\n\t\tforn (j, sz(gran[i]))\n\t\t{\n\t\t\tint to = gran[i][j];\n\t\t\t\n\t\t\tcerr << e[to].x << ' ' << e[to].y << endl;\n\t\t}\n\t}*/\n\t\n\tfore (i, 1, cntCol - 1)\n\t\tres[ colOut[i] ] = 0;\n\t\n\tforn (i, cntG)\n\t{\n\t\tif (area[i] < EPS)\n\t\t\tcontinue;\n\t\t\n\t\tres[ colIn[i] ] += area[i];\n\t\t\n\t\tint outer = par[ id[i] ];\n\t\t\n\t\tif (outer != -1)\n\t\t\tres[ colIn[outer] ] -= area[i];\n\t}\n\t\n\tfor(map::iterator it = res.begin(); it != res.end(); it++)\n\t\tprintf (\"%s %.15f\\n\", it->ft.c_str(), double(it->sc));\n}\n\nint main()\n{\n#ifdef SU2_PROJ\n\tassert(freopen(\"input.txt\", \"r\", stdin));\n\tassert(freopen(\"output.txt\", \"w\", stdout));\n#endif\n\n\tcout << setprecision(25) << fixed;\n\tcerr << setprecision(10) << fixed;\n\n\tsrand(int(time(NULL)));\n\n\tassert(read());\n\tsolve();\n\n#ifdef SU2_PROJ\n\tcerr << \"TIME: \" << clock() << endl;\n#endif\n\n\treturn 0;\n}\n//hellobig_tq\n//orzlxr!", "src_uid": "92caafd07e9afb03745aa6f5b450c38f"} {"source_code": "#include\nusing namespace std;\nconst int N = 5e4+8;\n#define double long double\nconst double eps = 1e-9;\nconst double pi = acos(-1.0);\nconst double inf = 1e6;\nint cnt;\nint segcnt = 0;\ndouble curang;\nstruct Point{\n double x,y;\n double corss(Point b)const{\n return x * b.y - b.x * y;\n }\n Point operator - (const Point& b)const{\n return (Point){x-b.x,y-b.y};\n }\n double len(){return sqrt(x*x+y*y);}\n};\nPoint segcross(Point a,Point b,Point c,Point d,bool& ok ){\n double u = (b-a).corss(c-a) , v = (a-b).corss(d-b);\n if( fabs(u+v) < eps){\n ok = 0;\n Point tem = {-1,-1};\n return tem;\n }\n ok = 1;\n return (Point){ (c.x*v + d.x*u)/(u+v) , (c.y*v + d.y*u)/(u+v) };\n}\nstruct Seg{\n Point a,b;\n int id;\n bool operator < (const Seg& s)const{\n bool ok1 ,ok2;\n Point c = (Point){cos(curang) , sin(curang)};\n Point o = (Point){0,0};\n Point cr1 = segcross(a,b,o,c,ok1);\n Point cr2 = segcross(s.a,s.b,o,c,ok2);\n // if( ok1 == 0 || ok2 == 0 ) return id < s.id;\n // assert(ok1 && ok2);\n if( fabs( cr1.len() - cr2.len() ) < eps ) return id < s.id;\n return cr1.len() < cr2.len();\n }\n};\nvector pol[N];\ndouble ang[N];\nvector add[N],del[N];\nSeg seg[N];\n\nvoid add_seg(Point a,Point b){\n double anga = atan2l(a.y,a.x) , angb = atan2l(b.y,b.x);\n if( fabs(anga - angb) < eps ) return;\n if( anga > angb + eps ){\n swap(anga,angb);\n swap(a,b);\n }\n int pa = lower_bound(ang+1,ang+1+cnt,anga) - ang;\n int pb = lower_bound(ang+1,ang+1+cnt,angb) - ang;\n\n ++segcnt;\n seg[segcnt] = (Seg){a,b,segcnt};\n if( angb - anga > pi + eps ){\n // Point c = segcross(a,b,(Point){-inf,0},(Point){inf,0});\n if( fabs(anga + pi) > eps){\n // ++segcnt;\n // seg[segcnt] = (Seg){c,a,segcnt};\n add[1].push_back(segcnt);\n del[pa].push_back(segcnt);\n }\n\n if( fabs( angb - pi ) > eps){\n // ++segcnt;\n // seg[segcnt] = (Seg){b,c,segcnt};\n add[pb].push_back(segcnt);\n del[cnt].push_back(segcnt);\n }\n }\n else{\n add[pa].push_back(segcnt);\n del[pb].push_back(segcnt);\n }\n}\ndouble area(Point a,Point b,Point c,Point d){\n double res = 0;\n res += (b-a).corss(c-a);\n res += (c-a).corss(d-a);\n if(res < -eps ) res = -res;\n return res * 0.5;\n}\nvoid solve(){\n set st;\n double ans = 0;\n curang = 0;\n for(int i = 1;i= 2){\n // assert((int)st.size()>=2);\n Seg s1,s2;\n auto it = st.begin(); s1 = (*it);\n ++it; s2 = (*it);\n Point c1 = (Point){inf*cos(ang[i]) , inf * sin(ang[i])};\n Point c2 = (Point){inf*cos(ang[i+1]) , inf * sin(ang[i+1])};\n Point o = (Point){0,0};\n bool ok1,ok2,ok3,ok4;\n Point a1 = segcross(o,c1,s1.a,s1.b,ok1);\n Point a2 = segcross(o,c1,s2.a,s2.b,ok2);\n Point a3 = segcross(o,c2,s2.a,s2.b,ok3);\n Point a4 = segcross(o,c2,s1.a,s1.b,ok4);\n // assert(ok1 && ok2 && ok3 && ok4);\n // if( ok1 == 0 || ok2 == 0 || ok3 == 0 || ok4 == 0) continue;\n ans += area(a1,a2,a3,a4);\n }\n }\n // printf(\"%.12f\",ans);\n cout<>n;\n for(int i = 1;i<=n;++i){\n int m; cin>>m;\n Point tem;\n for(int j = 1;j<=m;++j){\n // scanf(\"%lf %lf\",&tem.x,&tem.y);\n cin>>tem.x>>tem.y;\n // cerr<\nusing namespace std;\nint main()\n{\n int n,p,k,i;\n cin>>n>>p>>k;\n if(p>=1 && p<=n)\n if((p-k)>1 && (p+k)>\";\n }\n else if((p-k)<1&&(p+k)>\";\n }\n else if((p-k)>1&&(p+k)>=n)\n {\n cout<<\"<< \";\n for(i=p-k;i<=n;i++)\n if(i==p) cout<<\"(\"<=n)\n for(i=1;i<=n;i++)\n if(i==p) cout<<\"(\"<>\"; \n }\n}", "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"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#define endl \"\\n\"\n#define ll long long\n#define int ll\n//#define gcd(a,b) __gcd(a,b)\nusing namespace std;\nconst int inf = 0x3f3f3f3f;\nconst int mod = 998244353;\nconst int maxn = 1e5 + 7;\nconst double pi = acos(-1.0);\nconst int base = 131;\nint n,m;\nsigned main() {\n std::ios::sync_with_stdio(false), cin.tie(0);\n cin>>n>>m;\n if(m==1)cout<\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=1000000007;\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;}\nstruct MinCostMaxFlow{\n\t#define MAXN 55\n\tstruct edge{\n\t\tint to,cost,flow,rev;\n\t\tedge(int _to,int _cost,int _flow,int _rev){\n\t\t\tto=_to;cost=_cost;flow=_flow;rev=_rev;\n\t\t}\n\t};\n\tvectorg[MAXN];\n\tvoid add_edge(int x,int y,int f,int c){\n\t\tg[x].push_back(edge(y,c,f,(int)g[y].size()));\n\t\tg[y].push_back(edge(x,-c,0,(int)g[x].size()-1));\n\t}\n\t//flow,cost\n\tint dist[MAXN],h[MAXN],pre_v[MAXN],pre_e[MAXN];\n\tpairMin_Cost_Max_Flow(int s,int t,int f){\n\t\tpairret(0,0);\n\t\tmemset(h,0,sizeof h);\n\t\twhile(f){\n\t\t\tmemset(dist,inf,sizeof dist);\n\t\t\tmemset(pre_v,-1,sizeof pre_v);\n\t\t\tset >S;\n\t\t\tS.insert(make_pair(0,s));\n\t\t\tdist[s]=0;\n\t\t\twhile(!S.empty()){\n\t\t\t\tint x=S.begin()->second,now=S.begin()->first;\n\t\t\t\tS.erase(S.begin());\n\t\t\t\tif(dist[x]!=now)continue;\n\t\t\t\tfor(int i=0;inow+cost+h[x]-h[to]){\n\t\t\t\t\t\tdist[to]=now+cost+h[x]-h[to];\n\t\t\t\t\t\tpre_v[to]=x;pre_e[to]=i;\n\t\t\t\t\t\tS.insert(make_pair(dist[to],to));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(pre_v[t]==-1)return ret;\n\t\t\tfor(int i=0;i >g[55],g2[55];\nint dist[55],dist2[55];\nint pre[6666];\nint main(){\n\tcin>>n>>m;\n\tfor(int i=1;i<=m;i++){\n\t\tint x,y,z;cin>>x>>y>>z;\n\t\tG.add_edge(x,y,1,z);\n\t}\n\tvector >hv;\n\tint sum=0;\n\twhile(1){\n\t\tauto got=G.Min_Cost_Max_Flow(1,n,1);\n\t\tif(got.first==0)break;\n\t\tsum+=got.second;\n\t\thv.push_back(make_pair(sum,got.second));\n\t}\n\tint q;cin>>q;\n\twhile(q--){\n\t\tint x;cin>>x;\n\t\tdouble ans=-1e18;\n\t\tint cnt=0;\n\t\tfor(int i=0;i=p.second&&tmp>=got){ans=got;break;}\n\t\t}\n\t\tprintf(\"%.12lf\\n\",ans);\n\t}\n\treturn 0;\n}", "src_uid": "b0751071e12f729f6700586c5a8eed23"} {"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 pb push_back\n#define INF 1011111111\n#define FOR(i, a, b) for (int _n(b), i(a); i < _n; i++)\n#define rep(i, n) FOR(i, 0, n)\n#define CL(a, v) memset((a), (v), sizeof(a))\n#define mp make_pair\n#define X first\n#define Y second\n#define all(c) (c).begin(), (c).end()\n#define SORT(c) sort(all(c))\n\ntypedef long long ll;\ntypedef vector VI;\ntypedef pair pii;\n\n/*** TEMPLATE CODE ENDS HERE */\n\nconst int maxn = 1010, maxm = maxn * maxn;\n\ntypedef bitset<(maxn << 1) + 5> BitSet;\n\npair edA[maxm + 5], edB[maxm + 5];\nBitSet A[(maxn << 1) + 5], B[(maxn << 1) + 5];\nBitSet odd;\nint n;\n\nint Get(int x) {\n if (x < 0) {\n x = -x, --x;\n return x << 1;\n }\n --x;\n return x << 1 | 1;\n}\n\ninline bool Check(const BitSet &x) { return (((x & odd) >> 1) & x).none(); }\n\nBitSet ban;\nint ans[maxn + 5];\n\ninline void find(BitSet *f) {\n rep(i, n) {\n if (ban[i << 1] || (f[i << 1] & ban).any() || !Check(f[i << 1])) {\n ans[i] = 1;\n } else {\n ans[i] = 0;\n }\n ban[i << 1 | (!ans[i])] = 1;\n }\n}\n\nint main() {\n#ifdef LOCAL_HOST\n freopen(\"input.txt\", \"r\", stdin);\n// freopen(\"output.txt\",\"w\",stdout);\n#endif\n\n const string similar = \"SIMILAR\";\n\n int m1, m2;\n cin >> n >> m1 >> m2;\n rep(i, m1) {\n int u, v;\n scanf(\"%d%d\", &u, &v);\n u = Get(u);\n v = Get(v);\n A[u ^ 1][v] = 1;\n A[v ^ 1][u] = 1;\n edA[i] = mp(u, v);\n }\n rep(i, m2) {\n int u, v;\n scanf(\"%d%d\", &u, &v);\n u = Get(u);\n v = Get(v);\n B[u ^ 1][v] = 1;\n B[v ^ 1][u] = 1;\n edB[i] = mp(u, v);\n }\n\n rep(i, n) odd[i << 1 | 1] = 1;\n rep(i, n << 1) A[i][i] = B[i][i] = 1;\n\n rep(i, n << 1) rep(j, n << 1) if (A[j][i]) A[j] |= A[i];\n rep(i, n << 1) rep(j, n << 1) if (B[j][i]) B[j] |= B[i];\n\n bool canA = 1, canB = 1;\n rep(i, n) if (A[i << 1][i << 1 | 1] && A[i << 1 | 1][i << 1]) {\n canA = 0;\n break;\n }\n rep(i, n) if (B[i << 1][i << 1 | 1] && B[i << 1 | 1][i << 1]) {\n canB = 0;\n break;\n }\n if (!canA && !canB) {\n cout << similar << endl;\n } else if (canA ^ canB) {\n if (canA) {\n find(A);\n } else {\n find(B);\n }\n rep(i, n) printf(\"%d \", ans[i]);\n printf(\"\\n\");\n } else {\n rep(i, m1) {\n int u = edA[i].X ^ 1, v = edA[i].Y ^ 1;\n if (Check(B[u] | B[v])) {\n ban[u ^ 1] = ban[v ^ 1] = 1;\n find(B);\n rep(i, n) printf(\"%d \", ans[i]);\n printf(\"\\n\");\n return 0;\n }\n }\n rep(i, m2) {\n int u = edB[i].X ^ 1, v = edB[i].Y ^ 1;\n if (Check(A[u] | A[v])) {\n ban[u ^ 1] = ban[v ^ 1] = 1;\n find(A);\n rep(i, n) printf(\"%d \", ans[i]);\n printf(\"\\n\");\n return 0;\n }\n }\n cout << similar << endl;\n }\n\n#ifdef LOCAL_HOST\n printf(\"TIME: %.3lf\\n\", double(clock()) / CLOCKS_PER_SEC);\n#endif\n\n return 0;\n}\n", "src_uid": "e7f585455aaf039aa6f0f2846d818b40"} {"source_code": "#include\n#include\n#include\nusing namespace std;\nbool right(int x1,int y1,int x2,int y2,int x3,int y3)\n{\n\tint d[3];\n\td[0]=pow(float(x2-x1),2)+pow(float(y2-y1),2);\n\td[1]=pow(float(x3-x2),2)+pow(float(y3-y2),2);\n\td[2]=pow(float(x3-x1),2)+pow(float(y3-y1),2);\n\tsort(d,d+3);\n\tif((d[2]==d[0]+d[1])&& d[0]!=0 && d[1]!=0 &&d[2]!=0)\n\t{\n\t\treturn true;\n\t}\n\treturn false;\n}\nint main()\n{\n\tint x1,x2,x3,y1,y2,y3;\n\tcin>>x1>>y1>>x2>>y2>>x3>>y3;\n\tif(right(x1,y1,x2,y2,x3,y3))\n\t{\n\t\tcout<<\"RIGHT\";\n\t\treturn 0;\n\t}\n\telse if(right(x1+1,y1,x2,y2,x3,y3)||right(x1-1,y1,x2,y2,x3,y3)||right(x1,y1+1,x2,y2,x3,y3)||right(x1,y1-1,x2,y2,x3,y3)||right(x1,y1,x2+1,y2,x3,y3)||right(x1,y1,x2-1,y2,x3,y3)||right(x1,y1,x2,y2+1,x3,y3)||right(x1,y1,x2,y2-1,x3,y3)||right(x1,y1,x2,y2,x3+1,y3)||right(x1,y1,x2,y2,x3-1,y3)||right(x1,y1,x2,y2,x3,y3+1)||right(x1,y1,x2,y2,x3,y3-1))\n\t{\n\t\tcout<<\"ALMOST\";\n\t\treturn 0;\n\t}\n\t\tcout<<\"NEITHER\";\n\treturn 0;\n}", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n\tlong long a,b,ans=1;\n\tcin>>a>>b;\n\tfor(int i=min(a,b);i>0;i--)\n\t{\n\t\tans*=i;\n\t}\n\tcout<\n\nusing namespace std;\n\nint main()\n{\nint l[4],s[4],r[4],p[4];bool x=false;\nfor(int i=0;i<=3;i++)\n{\n cin>>l[i]>>s[i]>>r[i]>>p[i];\n}\n\n\nif (p[0]==1)\n{\nif (!(l[0]==0&&s[0]==0&&r[0]==0&&s[2]==0&&l[1]==0&&r[3]==0))\n{\n x=true;\n}\n}\n//--------------------\nif (p[1]==1)\n{\nif (!(l[1]==0&&s[1]==0&&r[1]==0&&s[3]==0&&l[2]==0&&r[0]==0))\n{\n x=true;\n}\n}\n//---------------------\nif (p[2]==1)\n{\nif (!(l[2]==0&&s[2]==0&&r[2]==0&&s[0]==0&&l[3]==0&&r[1]==0))\n{\n x=true;\n}\n}\n//----------------------\nif (p[3]==1)\n{\nif (!(l[3]==0&&s[3]==0&&r[3]==0&&s[1]==0&&l[0]==0&&r[2]==0))\n{\n x=true;\n}\n}\n//----------------------\nif (x==true)\n{\n cout<<\"YES\"<\n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define M 100100\n\nint deg[M], num[M], a[M], b[M];\n\nvector v[M];\n\nint main(){\n\tint i, j, k, n, m;\n\tint x, y;\n\tscanf(\"%d %d\", &n, &m);\n\tfor(i = 0; i < m; i ++){\n\t\tscanf(\"%d %d\", &x, &y);\n\t\tv[x].push_back(y);\n\t\tv[y].push_back(x);\n\t\tdeg[x] ++, deg[y] ++;\n\t}\n\n\tif(n < 20 and n * (n - 1) < 4 * m){\n\t\tputs(\"-1\");\n\t\treturn 0;\n\t}\n\tif(n == 4 and m == 3){\n\t\tfor(i = 1; i <= 4; i ++) if(!deg[i])break;\n\t\tif(i <= 4){\n\t\t\tputs(\"-1\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\twhile(1){\n\t\tint ans = 0;\n\t\tmemset(num, 0, sizeof(num));\n\t\tint t = rand() % n + 1;\n\t\tfor(int ii = t; ii < n + t; ii ++){\n\t\t\tif(ii > n) i = ii - n;\n\t\t\telse i = ii;\n\t\t\tif(num[i] < 2){\n\t\t\t\tint I = v[i].size();\n\t\t\t\tif(I > 0) x = v[i][0];\n\t\t\t\telse x = 0;\n\t\t\t\tif(I > 1) y = v[i][1];\n\t\t\t\telse y = 0;\n\t\t\t\tfor(j = i + 1; j <= n; j ++) if(i != j and num[j] < 2 and j != x and j != y){\n\t\t\t\t\ta[ans] = i, b[ans++] = j;\n\t\t\t\t\tnum[i] ++;\n\t\t\t\t\tnum[j] ++;\n\t\t\t\t\tif(ans == m){\n\t\t\t\t\t\tfor(k = 0; k < ans; k ++){\n\t\t\t\t\t\t\tprintf(\"%d %d\\n\", a[k], b[k]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tif(num[i] == 2) break;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tans = 0;\n\t\tmemset(num, 0, sizeof(num));\n\t\tt = rand() % n + 1;\n\t\tfor(int ii = t + n; ii > t; ii --){\n\t\t\tif(ii > n) i = ii - n;\n\t\t\telse i = ii;\n\t\t\tif(num[i] < 2){\n\t\t\t\tint I = v[i].size();\n\t\t\t\tif(I > 0) x = v[i][0];\n\t\t\t\telse x = 0;\n\t\t\t\tif(I > 1) y = v[i][1];\n\t\t\t\telse y = 0;\n\t\t\t\tfor(j = i + 1; j <= n; j ++) if(i != j and num[j] < 2 and j != x and j != y){\n\t\t\t\t\ta[ans] = i, b[ans++] = j;\n\t\t\t\t\tnum[i] ++;\n\t\t\t\t\tnum[j] ++;\n\t\t\t\t\tif(ans == m){\n\t\t\t\t\t\tfor(k = 0; k < ans; k ++){\n\t\t\t\t\t\t\tprintf(\"%d %d\\n\", a[k], b[k]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tif(num[i] == 2) break;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(clock() > 2800000.){\n\t\t\tputs(\"-1\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 0;\n}\n", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5"} {"source_code": "#include\n#include\n#include\nusing namespace std;\nchar a[10001];\nint main()\n{\n\tint sum=0,ans=0;\n\tcin>>a;\n\tfor(int i=0;i\nusing namespace std;\n\nconst int N = 220000;\n\nint a[N], b[N], c[N], f[N], g[N];\n\nvoid KMP(int *c, int n, int *f) {\n\tf[1] = 0;\n\tfor (int j = 0, i = 1; i < n; i++) {\n\t\twhile (j > 0 && c[i+1] != c[j+1]) j = f[j];\n\t\tif (c[i+1] == c[j+1]) j++;\n\t\tf[i+1] = j;\n\t}\n}\n\nint match(int *b, int *c, int n, int *f) {\n\tint j = 0;\n\tfor (int i = 1; i <= n; i++) {\n\t\twhile (j > 0 && c[j+1] != b[i]) j = f[j];\n\t\tif (c[j+1] == b[i]) j++;\n\t}\n\treturn j;\n}\n\nint chk[N];\n\nint main() {\n#ifndef ONLINE_JUDGE\n\tfreopen(\"in.txt\", \"r\", stdin);\n\tfreopen(\"out.txt\", \"w\", stdout);\n#endif\n\tios::sync_with_stdio(0);\n\tint n, m; cin >> n >> m;\n\tfor (int i = 1; i <= n; i++) cin >> a[i];\n\tfor (int i = 1; i < n; i++) b[i] = a[i+1] - a[i];\n\tfor (int i = 1; i < n; i++) c[n-i] = b[i];\n\tKMP(c, n-1, f);\n\tKMP(b, n-1, g);\n\tint x = match(b, c, n-1, f);\n\tint y = match(c, b, n-1, g);\n\tvector ans;\n\tif (x == n-1) ans.push_back((a[1] + a[n]) % m);\n\twhile (x > 0) {\n\t\tchk[n-1-x] |= 1;\n\t\tx = f[x];\n\t}\n\tchk[n-1] |= 1;\n\twhile (y > 0) {\n\t\tchk[y+1] |= 2;\n\t\ty = g[y];\n\t}\n\tchk[1] |= 2;\n\tfor (int i = 1; i <= n-1; i++) {\n\t\tif (chk[i] == 3) {\n\t\t\tif ((a[1] + a[i]) % m == (a[i+1] + a[n]) % m) {\n\t\t\t\tans.push_back((a[1] + a[i]) % m);\n\t\t\t}\n\t\t}\n\t}\n\tsort(ans.begin(), ans.end());\n\tcout << ans.size() << endl;\n\tfor (int t : ans) cout << t << \" \";\n\tcout << endl;\n\treturn 0;\n}\n\n", "src_uid": "6a9f683dee69a7be2d06ec6646970f19"} {"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#include \n#pragma comment(linker, \"/STACK:20000000\")\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 mp make_pair\n#define pb push_back\n#define ll long long\n\nusing namespace std;\n\nint ri(){int x;scanf(\"%d\",&x);return x;}\nll rll(){ll x;scanf(\"%lld\",&x);return x;}\n\nll dp[1050];\nll a_cycle[1050];\n\n\nvoid stupid_solve(int a,int b,int w,int x,int c)\n{\n\tint res = 0;\n\tfor(;c > a;)\n\t{\n\t\tif (b >= x)\n\t\t\tb -= x;\n\t\telse\n\t\t\ta--,b = w - (x - b);\n\t\tc--;\n\t\tres++;\n\t}\n\n\tcout << res << endl;\n}\n\nvoid solve()\n{\n\tmemset(dp,-1,sizeof(dp));\n\tsrand(time(NULL));\n\tll a,b,w,x,c;\n\t//a = rand() % 10000;\t\n\t//w = rand() % 999 + 2;\n\t//b = rand() % w;\n\t//x = rand() % w + 1;\n\t//c = rand() % 10000;\n\tcin >> a >> b >> w >> x >> c;\n\t//stupid_solve(a,b,w,x,c);\n\tll step = 0;\n\tll tb = b;\n\tll len_cycle = 0;\n\tll pre_cycle = 0;\n\tll aa = 0;\n\tll aaa = 0;\n\tfor(;;)\n\t{\n\t\tdp[b] = step;\n\t\ta_cycle[b] = aa;\n\t\twhile(b >= x)\n\t\t\tb -= x,step++;\n\t\tb = w - (x - b);\n\t\tstep++;\n\t\taa++;\n\t\tif (dp[b] != -1)\n\t\t{\n\t\t\tlen_cycle = step - dp[b];\n\t\t\tpre_cycle = step - len_cycle;\n\t\t\taaa = aa - a_cycle[b];\n\t\t\tbreak;\n\t\t}\n\t}\n\tll res = 0;\n\tb = tb;\n\tfor(int i = 1; i <= pre_cycle;i++)\n\t{\n\t\tif (c <= a)\n\t\t\tbreak;\n\t\tif (b >= x)\n\t\t\tb -= x;\n\t\telse\n\t\t\ta--,b = w - (x - b);\n\t\tc--;\n\t\tres++;\n\t}\n\tif (c <= a)\n\t{\n\t\tcout << res << endl;\n\t\treturn;\n\t}\n\tll L = 0,R = 1e15;\n\twhile(L + 1 < R)\n\t{\n\t\tll mid = (L + R) >> 1;\n\t\tll bb = (ll)a - aaa * mid;\n\t\tll cc = (ll)c - (ll)len_cycle * mid;\n\t\tif (cc <= bb)\n\t\t\tR = mid;\n\t\telse\n\t\t\tL = mid;\n\t}\n\tres += len_cycle * L;\n\ta -= L * aaa;\n\tc -= len_cycle * L;\n\tfor(;;)\n\t{\n\t\tif (c <= a)\n\t\t\tbreak;\n\t\tif (b >= x)\n\t\t\tb -= x;\n\t\telse\n\t\t\ta--,b = w - (x - b);\n\t\tres++;\n\t\tc--;\n\t}\n\tcout << res << endl;\n}\n\nint main()\n{\n\t#ifndef ONLINE_JUDGE\n\t\tfreopen(\"C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt\",\"rt\",stdin);\n\t\tfreopen(\"C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt\",\"wt\",stdout);\n\t#else\n\t\t//freopen(\"input.in\",\"rt\",stdin);\n\t\t//freopen(\"output.out\",\"wt\",stdout);\n\t#endif\n\n\tsolve();\n\n\t#ifndef ONLINE_JUDGE\n\t\tprintf(\"\\n\\ntime-%.3lf\",clock()*1e-3);\n\t#endif\n\n\treturn 0;\n}", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143"} {"source_code": "#include\nusing namespace std;\n\nmain(){\n int x,y,z;\n cin>>x>>y>>z;\n int a=sqrt((x*z)/y);\n int b=x/a;\n int c=z/a;\n cout<<4*(a+b+c);\n return 0;\n}", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"source_code": "#include\n\n#define ll long long\n#define dl double\n\nusing namespace std;\n\nint main()\n{\n int n;\n cin >> n;\n\n if(n < 2) {\n cout << 0 << endl;\n return 0;\n }\n\n cout << n / 2 - !(n % 2) << endl;\n return 0;\n}\n", "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"source_code": " #include\n \n using namespace std;\n \n #define mp make_pair\n #define pb push_back\n #define F first\n #define S second\n #define eb emplace_back\n #define endl '\\n'\n #define INF INT_MAX\n #define MOD 1e9+7\n #define sz(a) (a).size()\n #define len(a) (a).length()\n #define all(v) v.begin(),v.end()\n #define some(v, x) v.begin(), v.begin()+x\n #define RANGET(i,a) for(ll i=0; i=b; --i)\n \n typedef long long ll;\n typedef unsigned long long ull;\n typedef vector vl;\n typedef vector vvl;\n typedef vector vi;\n typedef vector vd;\n typedef vector vs;\n typedef vector vc;\n typedef vector vb;\n typedef vector> vpii;\n typedef vector> vpll;\n \n namespace io {\n inline int rdi() { int v;cin>>v;return v; }\n inline long long rdll() { long long v;cin>>v;return v;}\n inline string rds() { string s;cin>>s;return s; }\n inline char rdc() { char c;cin>>c;return c; }\n template\n void rdv(T beg_iter, T end_iter) {\n for(;beg_iter!=end_iter;++beg_iter)cin>>*beg_iter;\n }\n inline void wri(const int v) { cout<\n void wrv(T beg_iter, T end_iter, string separator=\" \", string end_of_line=\"\\n\") {\n for(;beg_iter!=end_iter;++beg_iter) {\n cout<<*beg_iter;\n cout<>n>>m>>r;\n ll a[n];ll b[m];\n ll a1 = INT_MAX;\n for(int i=0;i>a[i];\n a1 = min(a1,a[i]);\n }\n ll ma = INT_MIN,r1 = 0,c1 = -1;\n for(int i=0;i>b[i];\n c1 = max(c1,b[i]);\n }\n // cout<\n#include \n#include \n#include \n#include \n#include \n#define mp make_pair\n \nusing namespace std;\ntypedef long long ll;\nconst ll inf = 1e9;\nconst ll mod = 998244353;\nconst string imp = \"IMPOSSIBLE\";\n \nint main()\n{\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\tcout.tie(0);\n int n;\n cin >> n;\n string str, s = \"\";\n cin >> str;\n for(auto i : str)\n {\n if(i != '0')\n s += i;\n }\n if(s.empty())\n {\n cout << \"YES\";\n return 0;\n }\n n = s.size();\n vector v(n), pref(n);\n \n for(int i = 0; i < n; i++)\n {\n v[i] = (int)(s[i] - '0'); \n pref[i] = v[i] + ((i) ? pref[i-1] : 0);\n }\n //for(auto i : pref) cout << i << \" \";\n //for(auto i : v) cout << i << \" \";\n for(int i = 0; i < n - 1; i++)\n {\n int sum = pref[i];\n int t = i+1, stI = i;\n while(t < n)\n {\n if(pref[t] - pref[stI] == sum)\n {\n stI = t;\n if(stI == n-1)\n {\n cout << \"YES\";\n return 0;\n }\n }\n else\n if(t == n-1)\n break;\n t++;\n }\n }\n cout << \"NO\";\n}", "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"source_code": "#include\nusing namespace std;\n#define pb push_back\n#define eb emplace_back\n#define mp make_pair\n#define Fast_IO ios::sync_with_stdio(false);\n#define DEBUG fprintf(stderr,\"Running on Line %d in Function %s\\n\",__LINE__,__FUNCTION__)\n//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());\n#define fir first\n#define sec second\n#define mod 998244353\n#define ll long long\n#define inf 0x3f3f3f3f\n#define INF 0x3f3f3f3f3f3f3f3f\ninline int read()\n{\n\tchar ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}\n\tint ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}\n\tif(nega==-1) return -ans;\n\treturn ans;\n}\ntypedef pair pii;\n#define N 5005\nint b[N];\nint n,q;\nstruct Node\n{\n\tvector v;\n\tmap m;\n};\nNode a[N*4];\nvector c;\nint ans[N*20];\n#define ls (u<<1)\n#define rs (u<<1|1)\nvoid build(int u,int l,int r)\n{\n\tif(l==r) {a[u].v.pb(b[l]); return ;}\n\tint mid=(l+r)/2;\n\tbuild(ls,l,mid);\n\tbuild(rs,mid+1,r);\n\tint i=0,j=0;\n\twhile(i<(int)a[ls].v.size()&&j<(int)a[rs].v.size())\n\t{\n\t\tif(a[ls].v[i]>n>>q;\n\tfor(int i=1;i<=n;i++) b[read()]=i;\n\tbuild(1,1,n);\n\tfor(int i=1;i<=q;i++)\n\t{\n\t\tint l=read(),r=read();\n\t\tans[i]=solve(1,l,r);\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#include \n#include \n#include \n#include \n#include \n#include \n \nusing namespace std;\ntypedef long long ll;\n \nconst int MAXN = 51;\nconst int MAXSUM = 2001;\nconst int INF = 1e8;\n \nint n, s, k;\nint dp[MAXSUM][MAXN]; // total sum, last-eaten position\nint r[MAXN], color[MAXN];\n \nint main() {\n#ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n#endif\n \n cin >> n >> s >> k;\n for (int i = 1; i <= n; ++i) {\n cin >> r[i];\n }\n for (int i = 1; i <= n; ++i) {\n char type;\n cin >> type;\n color[i] = type == 'R' ? 1 : type == 'G' ? 2 : 3;\n }\n \n for (int i = 0; i < MAXSUM; ++i) {\n for (int j = 0; j < MAXN; ++j) {\n dp[i][j] = INF;\n }\n }\n \n dp[0][s] = 0;\n \n for (int sum = 0; sum < k; ++sum) {\n for (int cur = 0; cur <= n; ++cur) {\n if (dp[sum][cur] == INF) continue;\n for (int to = 1; to <= n; ++to) {\n if (sum == 0 || (r[to] > r[cur] && color[to] != color[cur])) {\n int su = min(k, sum + r[to]);\n int dist = abs(to - cur);\n dp[su][to] = min(dp[su][to], dp[sum][cur] + dist);\n }\n }\n }\n }\n \n int res = INF;\n for (int cur = 0; cur <= n; ++cur) {\n res = min(res, dp[k][cur]);\n }\n cout << (res == INF ? -1 : res);\n}", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef unsigned long long ull;\n\n\nconst double PI = 3.14159265358979323846e0;\n\nint a[200009];\n\n\n\nint main()\n{\n\tint n;\n\tdouble r, v;\n\tcin >> n >> r >> v;\n\tfor (int k = 0; k < n; ++k) {\n\t\tdouble s, f;\n\n\t\tcin >> s >> f;\n\t\tf -= s;\n\t\tint round = (int)(f / (2 * PI * r));\n\t\tdouble res = round * 2 * PI * r / v;\n\t\tf -= round * 2 * PI * r;\n\t\t//cout << res << \" \" << f << endl;\n\t\tdouble low = 0, hi = 2 * PI;\n\t\tfor (int k = 0; k < 60; ++k) {\n\t\t\tdouble mid = (low + hi) / 2;\n\t\t\tdouble l = mid * r + 2 * sin(mid / 2) * r;\n\t\t\tif (l < f) low = mid;\n\t\t\telse hi = mid;\n\t\t}\n\t\t//cout << low << endl;\n\t\tprintf(\"%.9f\\n\", res + (low + hi) / 2 * r / v + 1e-9);\n\t}\n\t//system(\"pause\");\n\treturn 0;\n}", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88"} {"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\n#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)\n#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)\n\ntypedef long long ll;\n#define MOD 1000000007ll\n\nint T;\nstring s;\nint N,K;\nint p[500010],e[500010];\n\nmap mp[20];\n\nll power(ll x, ll n){\n\tif(n == 0) return 1;\n\tll y = power(x, n/2);\n\ty = y * y % MOD;\n\tif(n%2 == 1) y = y * x % MOD;\n\treturn y;\n}\n\nvoid update_mp(void){\n\tint i,j;\n\t\n\tmp[0][0]++;\n\t\n\tREP(i,K){\n\t\tint pr = p[i];\n\t\t\n\t\tvector masks(pr);\n\t\tREP(j,T) masks[j%pr] |= (1ll<first);\n\t\t\tint cnt = (itr->second);\n\t\t\tREP(j,pr){\n\t\t\t\tll mask2 = (mask | masks[j]);\n\t\t\t\tmp[i+1][mask2] = (mp[i+1][mask2] + cnt) % MOD;\n\t\t\t}\n\t\t}\n\t}\n}\n\nll dp[500010][50];\n\nll func(void){\n\tint i,j;\n\t\n\tsnuke(mp[K],itr){\n\t\tll mask = (itr->first);\n\t\tll cnt = (itr->second);\n\t\t\n\t\tbool good = true;\n\t\tint covered = 0;\n\t\tREP(i,T){\n\t\t\tif(mask&(1ll<> s >> N;\n\tREP(i,N) scanf(\"%d%d\", &p[i], &e[i]);\n\tT = s.length();\n\tREP(i,T) s[i] = ((s[i] == '0') ? '1' : '0');\n\t\n\tll prod = 1;\n\tREP(i,N) prod = prod * power(p[i], e[i] - 1) % MOD;\n\t\n\tsort(p, p+N);\n\t\n\twhile(K < N && p[K] < 40) K++;\n\tupdate_mp();\n\t\n\tll ans = func();\n\t\n\tans = ans * prod % MOD;\n\tcout << ans << endl;\n\t\n\treturn 0;\n}", "src_uid": "a0140a8fc4215acec5f046485bc2c7f9"} {"source_code": "#include\nusing namespace std;\nlong long n,a,k,b,ans,pa=1,kl;\nint head[5500000],vis[5500000],f[5500000];\nqueuefi;\nint gcd(int a,int b){return b==0?a:gcd(b,a%b);}\nstruct line{int fr,to,next;}q[12000001];\nvoid pushline(int f,int t)\n{\n\tif(f==t)return;\n\tif(f<0||t<0)return;\n\tq[++kl].next=head[f];head[f]=kl;q[kl].to=t;\n}\nvoid bfs(int x)\n{\n\tfi.push(x);vis[x]=1;\n\twhile(!fi.empty())\n\t{\n\t\tint u=fi.front();fi.pop();\n\t\tfor(int p=head[u];p;p=q[p].next)\n\t\t{\n\t\t\tint v=q[p].to;\n\t\t\tif(!vis[v])\n\t\t\t\tvis[v]=1,f[v]=f[u]+1,fi.push(v);\n\t\t}\n\t\t\t\n\t}\n}\nsigned main()\n{\n cin>>a>>b>>k;\n for(int i=2;i<=k;i++)pa=pa*i/gcd(pa,i);\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\nusing namespace std;\ntypedef pair pll;\nint a[33];\nbool eq(int t){\n\treturn a[t]==a[t+1]&&a[t]==a[t+2]&&a[t]==a[t+3];\n}\nbool eqh(int t){\n\treturn a[t]==a[t+1]&&a[t+2]==a[t+3];\n}\nbool eqs(int t){\n\treturn a[t]==a[t+2]&&a[t+1]==a[t+3];\n}\nbool feqh,feqs;\nint main()\n{\n\tfor(int i=0;i<24;i++)scanf(\"%d\",a+i+1);\n\tif((eq(1)&&eq(9)&&!eq(5)&&!eq(21)&&!eq(17)&&!eq(13))||\n\t(!eq(1)&&!eq(9)&&eq(5)&&eq(21)&&!eq(17)&&!eq(13))||\n\t(!eq(1)&&!eq(9)&&!eq(5)&&!eq(21)&&eq(17)&&eq(13))){//����������� \n\t\tfor(int i=1;i<24;i+=4){\n\t\t\tif(!eqh(i)){feqh=1;break;\n\t\t\t}\n\t\t}\n\t\tfor(int i=1;i<24;i+=4){\n\t\t\tif(!eqs(i)){feqs=1;break;\n\t\t\t}\n\t\t}if(feqh&&feqs){\n\t\tif(eq(5)){\n\t\t\tif(eqh(9)&&eqh(1)&&eqs(13)&&eqs(17)){\n\t\t\t\t\tif(a[1]==a[17]&&a[18]==a[10]&&a[11]==a[14]&&a[13]==a[3]){\n\t\t\t\t\tcout<<\"YES\"<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long LL;\nint n,ans[100];\nint main()\n{\n\t//freopen(\".in\",\"r\",stdin);\n\t//freopen(\".out\",\"w\",stdout);\n\tscanf(\"%d\",&n);\n\tfor(int i=max(1,n-81);i<=n;i++) {\n\t int tp=i,tpp=i;\n\t while(tp) {\n\t\t tpp+=tp%10;\n\t\t tp/=10;\n\t\t}\n\t\tif(tpp==n) ans[++ans[0]]=i;\n\t}\n\tprintf(\"%d\\n\",ans[0]);\n\tfor(int i=1;i<=ans[0];i++) \n\t printf(\"%d \",ans[i]);\n\tprintf(\"\\n\");\n\treturn 0;\n}\n", "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int m,d;\n cin>>m>>d;\n if((m==2)&&(d==1))\n cout<<\"4\";\n else if(m==2)\n cout<<\"5\";\n else if(((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10)||(m==12))&&(d<=5))\n cout<<\"5\";\n else if(((m==4)||(m==6)||(m==9)||(m==11))&&(d<=6))\n cout<<\"5\";\n else\n cout<<\"6\";\n return 0;\n}", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"} {"source_code": "#include \n#define mod 1000000007\nlong long mul[1000001],div[1000001];\nlong long dp[1000001],sum[1000001];\nlong long powm(long long a,long long b)\n{\n long long ret=1;\n while(b)\n {\n if(b&1)\n ret=(ret*a)%mod;\n a=(a*a)%mod;\n b>>=1;\n }\n return ret;\n}\nint main()\n{\n long long n,k,ans;\n scanf(\"%I64d%I64d\",&n,&k);\n mul[0]=1;\n for(long long i=1;i<=n;i++)\n mul[i]=(mul[i-1]*i)%mod;\n for(long long i=1;i<=n;i++)\n div[i]=powm(mul[i],mod-2);\n ans=0;\n for(long long i=k+1;i<=n;i++)\n {\n dp[i]=(((i-k-1)*mul[i-2])%mod+(mul[i-2]*((sum[i-1]-sum[i-k-1]+mod)%mod))%mod)%mod;\n sum[i]=(sum[i-1]+(dp[i]*div[i-1])%mod)%mod;\n ans=(ans+((((dp[i]*mul[n-1])%mod)*div[i-1])%mod))%mod;\n }\n printf(\"%I64d\\n\",ans);\n return 0;\n}\n", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4"} {"source_code": "#include\nusing namespace std;\nint main()\n{ \n int n;\n string s;\n cin>>n>>s;\n int cnt=0;\n for(int i=0;i\n#include\n#include\nusing namespace std;\nint main() {\n char s[9][9];\n for (int i=1; i<=8; i++) {\n for (int j=1; j<=8; j++) {\n cin>>s[i][j];\n }\n }\n int cntA=10,cntB=10;\n for (int i=1; i<=8; i++) {\n for (int j=1; j<=8; j++) {\n if (s[i][j]=='W') {\n bool p=true;\n for (int k=1; k<=i-1; k++) {\n if (s[k][j]!='.') {\n p=false;\n break;\n }\n }\n if (p) {\n int x=abs(1-i);\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 #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;i MII;\n typedef map MSI;\n typedef vector VI;\n typedef vector VS;\n typedef vector VD;\n typedef pair PII;\n typedef long long int64;\n typedef long long ll;\n typedef unsigned int UI;\n typedef long double LD;\n typedef unsigned long long ULL;\n\n vector ch[26];\n vector< pair > con[26];\n char s[1000007];\n int sat[1000007];\n int before[1000007];\n int k,L,R;\n\n int main()\n {\n gets(s);\n int n = strlen(s);\n REP(i,n)\n {\n before[i] = ch[s[i]-'a'].size();\n ch[s[i]-'a'].PB(i);\n }\n cin>>k>>L>>R;\n char t[10];\n REP(i,k)\n {\n int a,b;\n cin>>t>>a>>b;\n con[t[0] -'a'].PB(MP(a,b));\n }\n int now = 0;\n long long answer = 0;\n CLEAR(sat);\n // cout<<\"here\\n\";\n REP(i,n)\n {\n // cout << \"here\\n\";\n\n REP(j,26)\n TR(it,con[j])\n {\n if (j==s[i]-'a')\n {\n if (it->first <= 1 && it->second >= 1)\n ++sat[i];\n }\n else\n {\n if (it->first==0)\n ++sat[i];\n }\n }\n // cout<<\"here\\n\";\n if (sat[i]>=L&&sat[i]<=R)\n ++now;\n TR(it,con[s[i]-'a'])\n {\n if (before[i] >= it->second)\n {\n // cout<<\"here\\n\";\n for (int j = before[i]-it->second-1<0 ? 0 : ch[s[i]-'a'][before[i]-it->second-1]+1;j <= min(i-1,ch[s[i]-'a'][before[i]-it->second]);++j)\n {\n // cout<=L&&sat[j]<=R)\n --now;\n --sat[j];\n if (sat[j]>=L&&sat[j]<=R)\n ++now;\n }\n }\n }\n TR(it,con[s[i]-'a'])\n {\n if (before[i]+1 >= it->first)\n {\n int bound = before[i]-it->first+1 < ch[s[i]-'a'].size() ? ch[s[i]-'a'][before[i]-it->first+1] : i;\n for (int j = before[i]-it->first<0 ? 0 : ch[s[i]-'a'][before[i]-it->first]+1;j <= min(i-1,bound);++j)\n {\n if (sat[j]>=L&&sat[j]<=R)\n --now;\n ++sat[j];\n if (sat[j]>=L&&sat[j]<=R)\n ++now;\n }\n }\n }\n // cout<\n\nusing namespace std;\n/*\nint main() {\n // a == b mod m\n // m eh div de a - b\n int n, k;\n cin >> n >> k;\n for (int i = 0; i < n; i++) {\n scanf(\"%d\", a + i);\n }\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n int d = abs(a[i] - a[j]);\n adj[d].push_back(ii(i, j));\n }\n }\n for (int i = 2; i < ms; i++) {\n for (int j = i + i; j < ms; j += i) {\n \n }\n }\n return 0;\n} /**/\n\ntypedef long long ll;\n\nint main() {\n ll n, m, x, y;\n ll a, b;\n cin >> n >> m >> x >> y >> a >> b;\n ll g = __gcd(a, b);\n ll num = min(n / a, m / b), den = 1;\n for (ll q = 1; q * q <= g; q++) {\n if (g % q) continue;\n ll p = min(n * q / a, m * q / b);\n if (num * q < p * den) {\n num = p;\n den = q;\n }\n q = g / q;\n p = min(n * q / a, m * q / b);\n if (num * q < p * den) {\n num = p;\n den = q;\n }\n q = g / q;\n }\n a /= den;\n a *= num;\n b /= den;\n b *= num;\n ll x1, x2, y1, y2;\n if (a % 2 == 0) {\n x1 = x - a/2;\n x2 = x + a/2;\n } else {\n x1 = x - (a + 1) / 2;\n x2 = x + (a) / 2;\n }\n if (x1 < 0) {\n ll d = abs(x1);\n x1 += d;\n x2 += d;\n } else if (x2 > n) {\n ll d = x2 - n; \n x2 -= d;\n x1 -= d;\n }\n if (b % 2 == 0) {\n y1 = y - b/2;\n y2 = y + b/2;\n } else {\n y1 = y - (b + 1) / 2;\n y2 = y + (b) / 2;\n }\n if (y1 < 0) {\n ll d = abs(y1);\n y1 += d;\n y2 += d;\n } else if (y2 > m) {\n ll d = y2 - m;\n y2 -= d;\n y1 -= d;\n }\n cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;\n}/**/", "src_uid": "8f1211b995f35462ae83b2be27f54585"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nlong long a, b, st=1;\n\nint main(){\n\tcin >> a >> b;\n\tif( b == 1 ){\n\t\tcout << a;\n\t}\n\telse{\n\t\twhile(st <= a){\n\t\t\tst*=2;\n\t\t}\n\t\tcout<\n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tint v1, v2;\n\tcin >> v1 >> v2;\n\tint t, d;\n\tcin >> t >> d;\n\tint sum = v1;\n\tfor (int i = 2; i <= t; i++)\n\t{\n\t\tint cnt = 0;\n\t\twhile (abs(v1 - v2) < (t - i)*d && cnt < d){\n\t\t\tv1++;\n\t\t\tcnt++;\n\t\t}\n\t\tcnt = 0;\n\t\t\n\t\tif(v1=(t - i)*d && cnt < d){\n\t\t\tcnt++;\n\t\t\tv1++;\n\t\t}\n\t\tcnt = 0;\n\t\tif(v1>v2)\n\t\twhile (v1-v2>(t - i)*d && cnt < d){\n\t\t\tcnt++;\n\t\t\tv1--;\n\t\t}\n\t\tsum += v1;\n\t\t\n\t}\n\tcout << sum;\n\treturn 0;\n}\n\n\n\n\n", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"} {"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{\n\tios_base::sync_with_stdio(false);\n\t//ifstream in(\"in.txt\");\n\n\tlong long a, b, c, d, sum = 0;\n\tcin >> a >> b;\n\n\twhile (b > 1)\n\t{\n\t\tc = a;\n\t\td = b;\n\t\ta = max(d, c % d);\n\t\tb = min(d, c % d);\n\t\tsum += c / d;\n\t}\n\n\tif (b) sum += a;\n\tcout << sum << endl;\n\n\t//in.close();\n\t//system(\"pause\");\n\treturn 0;\n}", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"source_code": "#pragma GCC target(\"avx2\")\n#pragma GCC optimize(\"O3\")\n\n# include \n# include \n\n# include \n# include \n\nusing namespace __gnu_pbds;\nusing namespace std;\n \ntemplate using ordered_set = tree , rb_tree_tag, tree_order_statistics_node_update>;\n\n#define _USE_MATH_DEFINES_\n#define ll long long\n#define ld long double\n#define Accepted 0\n#define pb push_back\n#define mp make_pair\n#define sz(x) (int)(x.size())\n#define every(x) x.begin(),x.end()\n#define F first\n#define S second\n#define lb lower_bound\n#define ub upper_bound\n#define For(i,x,y) for (ll i = x; i <= y; i ++) \n#define FOr(i,x,y) for (ll i = x; i >= y; i --)\n#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)\n// ROAD to... Red\n\ninline void Input_Output () {\n\t//freopen(\".in\", \"r\", stdin);\n //freopen(\".out\", \"w\", stdout);\n}\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 = 3123; \nconst int M = 22;\nconst int pri = 997;\nconst int Magic = 2101;\n\nconst int dx[] = {-1, 0, 1, 0};\nconst int dy[] = {0, -1, 0, 1};\n \nint n, m;\nll bal[N];\nvector < int > g[N];\npair < int, ll > dp[N][N], ndp[N];\nint sz[N];\n\n\nvoid dfs (int v, int par = 0) {\n\tsz[v] = 1;\n\tdp[v][0] = mp(0, bal[v]);\n\t//cout << v << ' '<< bal[v] << \"st\\n\";\n\tfor (auto to : g[v]) if (to != par) {\n\t\tdfs(to, v);\n\n\t\tfor (int j = 0; j <= sz[v] + sz[to]; ++j) {\n\t\t\tndp[j] = mp(-n, 0);\n\t\t}\n\t\tfor (int j = sz[v]; j >= 0; --j) {\n\t\t\tfor (int k = sz[to]; k >= 0; --k) {\n\t\t\t\tpair < int, ll > nw;\n\t\t\t\tnw = mp(dp[v][j].F + dp[to][k].F, dp[v][j].S + dp[to][k].S);\n\t\t\t\tndp[j + k] = max(ndp[j + k], nw);\n\t\t\t\tnw = mp(dp[v][j].F + dp[to][k].F + (dp[to][k].S > 0), dp[v][j].S);\n\t\t\t\tndp[j + k + 1] = max(ndp[j + k + 1], nw);\n\t\t\t}\n\t\t}\n\n\t\tsz[v] += sz[to];\n\t\tfor (int j = 0; j <= sz[v]; ++j) {\n\t\t\tdp[v][j] = ndp[j];\n\t//\t\tcout << \"state: \" << v << ' ' << j << \" val \" << dp[v][j].F << ' ' << dp[v][j].S << '\\n';\n\t\t}\n\t}\n\t\n}\n\ninline void solve () {\n\tcin >> n >> m;\n\tfor (int i = 1, x; i <= n; i ++) {\n\t\tcin >> x;\n\t\tbal[i] = -x;\n\t\tg[i].clear();\n\t}\t\n\tfor (int i = 1, x; i <= n; i ++) {\n\t\tcin >> x;\n\t\tbal[i] += x;\n\t}\n\n\tfor (int i = 1; i < n; i ++) {\n\t\tint l, r;\n\t\tcin >> l >> r;\n\t\tg[l].pb(r);\n\t\tg[r].pb(l);\t\n\t}\n\n\tfor (int i = 1; i <= n; ++ i) {\n\t\tfor (int j = 0; j <= n; ++ j) \t\n\t\t\tdp[i][j] = mp(-n, 0);\n\t}\n\n\tdfs(1); \n\t--m;\n\tcout << dp[1][m].F + (dp[1][m].S > 0) << '\\n';\n\n}\n\nint main () {\n \tSpeedForce;\n\tint tt = 1;\n\tcin >> tt;\n\twhile(tt--) solve();\n \treturn Accepted;\n}\n\n// B...a", "src_uid": "d2d1d8c8532b652f172e87a151adae4f"} {"source_code": "#include \n\n\nusing namespace std;\n\n\nint main()\n{\n int n,k,m=1;\n bool yes=true;\n cin>>n>>k;\n string s;\n cin>>s;\n sort(s.begin(),s.end());\n for(int i=0;ik)\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\nusing namespace std;\n\nint tree[800500];\nint x[200500], u[200500], t[200500];\npair > a[200500];\n\nvoid build(int v, int l, int r){\n if (l == r - 1){\n tree[v] = a[l].second.first - a[l].second.second;\n return;\n }\n int m = (l + r) >> 1;\n build(v + v + 1, l, m);\n build(v + v + 2, m, r);\n tree[v] = min(tree[v + v + 1], tree[v + v + 2]);\n}\n\nvoid update(int v, int l, int r, int a, int b){\n if (l == r - 1){\n tree[v] = b;\n return;\n }\n int m = (l + r) >> 1;\n if (a < m)\n update(v + v + 1, l, m, a, b);\n else\n update(v + v + 2, m, r, a, b);\n tree[v] = min(tree[v + v + 1], tree[v + v + 2]);\n}\n\nint get(int v, int l, int r, int a, int b, int c){\n if (l >= b || r <= a)\n return 1e9;\n int m = (l + r) >> 1, k;\n if (a <= l && r <= b){\n if (l == r - 1)\n if(tree[v] <= c){\n return l;\n }else\n return 1e9;\n if (tree[v + v + 1] <= c)\n return get(v + v + 1, l, m, a, b, c);\n else\n if (tree[v + v + 2] <= c)\n return get(v + v + 2, m, r, a, b, c);\n else\n return 1e9;\n }\n k = get(v + v + 1, l, m, a, b, c);\n if (k > 1e8)\n return get(v + v + 2, m, r, a, b, c);\n else\n return k;\n}\n\nint main(){\n //freopen(\"triangles.in\", \"r\", stdin);\n //freopen(\"triangles.out\", \"w\", stdout);\n ios_base::sync_with_stdio(0);\n int n, m;\n cin >> n >> m;\n for (int i = 0; i < n; i++)\n cin >> x[i];\n sort(x, x + n);\n for (int i = 0; i < m; i++){\n cin >> a[i].second.first >> a[i].second.second;\n a[i].first = a[i].second.first + a[i].second.second;\n }\n sort(a, a + m);\n build(0, 0, m);\n int pos = 0, ans = 0;\n for (int i = 0; i < n; i++){\n while (pos < m && x[i] > a[pos].second.first + a[pos].second.second)\n pos++;\n int k = get(0, 0, m, pos, m, x[i]);\n //cout << i << \" \" << k << endl;\n if (k < 1e8){\n update(0, 0, m, k, 2e9 + 1000);\n ans++;\n }\n }\n cout << ans;\n return 0;\n}\n", "src_uid": "04375596477fc65a2093554ff7b7934d"} {"source_code": "#include \nusing namespace std;\n\nstring a, b, c;\n\nint getidx(string s)\n{\n\tif(s == \"C\") return 1;\n\tif(s == \"C#\") return 2;\n\tif(s == \"D\") return 3;\n\tif(s == \"D#\") return 4;\n\tif(s == \"E\") return 5;\n\tif(s == \"F\") return 6;\n\tif(s == \"F#\") return 7;\n\tif(s == \"G\") return 8;\n\tif(s == \"G#\") return 9;\n\tif(s == \"A\") return 10;\n\tif(s == \"B\") return 11;\n\tif(s == \"H\") return 12;\n}\n\nint main()\n{\t\n\tstring notes[3];\n\tcin >> notes[0] >> notes[1] >> notes[2];\n\tsort(notes, notes + 3);\n\tdo\n\t{\n\tint p1 = getidx(notes[0]);\n\tint p2 = getidx(notes[1]);\n\tint p3 = getidx(notes[2]);\n\t\n\t//cout << notes[0] <<\" \" << notes[1] << \" \"< p2)\n\t{\n\t\tdis1 = (12 - p1) + p2;\n\t}\n\telse \n\t{\n\t\tdis1 = p2 - p1;\n\t}\n\t\n\tif(p2 > p3)\n\t{\n\t\tdis2 = (12 - p2) + p3;\n\t}\n\telse\n\t{\n\t\tdis2 = p3 - p2;\n\t}\n\t\n\tif(dis1 == 4 && dis2 == 3) { cout << \"major\"; return 0; }\n\tif(dis1 == 3 && dis2 == 4) { cout << \"minor\"; return 0; }\n\t\n\t}while(next_permutation(notes, notes + 3));\n\t\t\n\t\n\tcout << \"strange\";\n\treturn 0;\n}", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58"} {"source_code": "#include \nusing namespace std;\n\n#ifdef DEBUG\n#define debug(...) __VA_ARGS__\n#else\n#define endl '\\n'\n#define debug(...)\n#endif\n#define debugf(...) debug(printf(__VA_ARGS__))\n\nconst int N = 1e5 + 5;\nconst int K = 20;\nconst int oo = 0x3f3f3f3f;\n\nint P[K];\nvoid Build() {\n iota(P, P+K, 0);\n}\nint Find(int i) {\n return i == P[i] ? i : (P[i] = Find(P[i]));\n}\nvoid Union(int i, int j) {\n if ((i=Find(i)) == (j=Find(j))) return;\n P[i] = j;\n}\nint Components() {\n bitset counted;\n int ans = 0;\n for (int i = 0; i < K; i++) {\n if (!counted[Find(i)]) {\n counted.set(Find(i));\n ans++;\n }\n }\n return ans;\n}\n\nint g[K];\nbool is_dag[1<> n;\n string s, t;\n cin >> s >> t;\n\n memset(g, 0, sizeof(g));\n\n Build();\n for (int i = 0; i < n; i++) {\n int si = s[i] - 'a';\n int ti = t[i] - 'a';\n if (si != ti) {\n g[si] |= 1 << ti;\n Union(si, ti);\n }\n }\n\n memset(is_dag, 0, sizeof(is_dag));\n is_dag[0] = true;\n for (int m = 1; m < (1<> t;\n while (t--)\n cout << solve() << endl;\n\n return 0;\n%>", "src_uid": "d0735a763e2a40bfc94085019cd646f0"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\ntypedef long long LL;\ntypedef vector VI;\n\n#define REP(i,n) for(int i=0, i##_len=(n); i inline void amin(T &x, const T &y) { if (y inline void amax(T &x, const T &y) { if (x void rprintf(const char *fmt, Iter begin, Iter end) {\n for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }\n putchar('\\n');\n}\ntemplate struct ModInt {\n static const unsigned static_MOD = MOD;\n unsigned x;\n void undef() { x = (unsigned)-1; }\n bool isnan() const { return x == (unsigned)-1; }\n inline int geti() const { return (int)x; }\n ModInt() { x = 0; }\n ModInt(const ModInt &y) { x = y.x; }\n ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }\n ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }\n ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }\n ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }\n ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }\n ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }\n ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }\n ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }\n ModInt operator-() const { return (x ? MOD-x: 0); }\n\n ModInt inv() const {\n\tunsigned a = MOD, b = x; int u = 0, v = 1;\n\twhile (b) {\n\t int t = a / b;\n\t a -= t * b; swap(a, b);\n\t u -= t * v; swap(u, v);\n\t}\n\tif (u < 0) u += MOD;\n\treturn ModInt(u);\n }\n ModInt pow(long long y) const {\n\tModInt b = *this, r = 1;\n\tif (y < 0) { b = b.inv(); y = -y; }\n\tfor (; y; y>>=1) {\n\t if (y&1) r *= b;\n\t b *= b;\n\t}\n\treturn r;\n }\n friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }\n friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }\n friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }\n friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }\n friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }\n friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }\n friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }\n};\n\nconst LL MOD = 1000000007;\ntypedef ModInt Mint;\n\nconst int MAX = 100;\nMint inv[MAX+1], fact[MAX+1], fact_inv[MAX+1];\n\nvoid init() {\n inv[1] = 1;\n for (int i=2; i<=MAX; i++) inv[i] = inv[MOD%i] * (MOD-MOD/i);\n\n fact[0] = fact_inv[0] = 1;\n for (int i=1; i<=MAX; i++) {\n\tfact[i] = fact[i-1] * i;\n\tfact_inv[i] = fact_inv[i-1] * inv[i];\n }\n}\n\nMint nCk(int n, int k) {\n return fact[n] * fact_inv[k] * fact_inv[n-k];\n}\n\nint N, P;\nint C[55];\nMint dp[55][55][55][55];\n\nvoid MAIN() {\n scanf(\"%d%d\", &N, &P);\n REP (i, N) scanf(\"%d\", C+i);\n\n init();\n\n dp[0][0][0][0] = 1;\n\n REP (i, N) REP (EB, i+1) REP (EW, i+1-EB) REP (OB, i+1-EB-EW) {\n\tMint val = dp[i][EB][EW][OB];\n\tif (val.x == 0u) continue;\n\tint OW = i-EB-EW-OB;\n\n\tif (C[i] != 1) {\n\t // B;\n\t REP (ow, OW+1) {\n\t\tint mypath = (ow + 1) & 1;\n\t\tint nEB = EB + (mypath == 0);\n\t\tint nOB = OB + (mypath == 1);\n\n\t\tdp[i+1][nEB][EW][nOB] += val * nCk(OW, ow) * (1LL<<(i-OW));\n\t }\n\t}\n\n\tif (C[i] != 0) {\n\t // W;\n\t REP (ob, OB+1) {\n\t\tint mypath = (ob + 1) & 1;\n\t\tint nEW = EW + (mypath == 0);\n\t\tint nOW = OW + (mypath == 1);\n\n\t\tdp[i+1][EB][nEW][OB] += val * nCk(OB, ob) * (1LL<<(i-OB));\n\t }\n\t}\n }\n\n Mint ans = 0;\n REP (EB, N+1) REP (EW, N+1-EB) REP (OB, N+1-EB-EW) {\n\tint OW = N-EB-EW-OB;\n\tint parity = (OB + OW) & 1;\n\tif (parity == P) ans += dp[N][EB][EW][OB];\n }\n\n printf(\"%d\\n\", ans.geti());\n}\n\nint main() {\n int TC = 1;\n// scanf(\"%d\", &TC);\n REP (tc, TC) MAIN();\n return 0;\n}\n\n", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd"} {"source_code": "#include\nusing namespace std;\n\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tcout.tie(NULL);\n\tint x,y,z,t1,t2,t3;\n\tcin>>x>>y>>z>>t1>>t2>>t3;\n\tint stair=0,ele=0;\n\tstair=abs(x-y)*t1;\n\tele+=abs(x-z)*t2+2*t3;\n\tele+=abs(x-y)*t2+t3;\n\t//cout<\nusing namespace std;\nint main()\n{\n int n = 6, i = 0, cnt = 0;\n int arr[n];\n int sum = 0;\n bool x=false;\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n sum += arr[i];\n }\n sort(arr, arr + n);\n for (int i = 0; i < n; i++)\n {\n for (int j = i+1; j < n; j++)\n {\n for (int k = j+1; k < n; k++)\n {\n int temp=arr[i]+arr[j]+arr[k];\n if((sum-temp)==temp)\n {\n x=true;\n break;\n }\n }\n \n }\n \n }\n \n if (x)\n {\n cout << \"YES\" << endl;\n }\n else\n {\n cout << \"NO\" << endl;\n }\n\n return 0;\n}", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define ll long long\nusing namespace std;\n\nint main(){\n ll n;\n cin>>n;\n ll bst=1;\n\n for(ll i=2;i*i<=n;i++){\n if(n%i==0){\n bst=bst*i;\n while(n%i==0) n/=i;\n }\n }\n if(n>1) bst*=n;\n cout<(a to z) == (char)(int+97)\n//Convert from char int to int char-48\n\n#include \nusing namespace std;\n\nstring s1,s2,s3;\nmap mp;\nmap mp1;\nint main()\n{\n mp['A']=0;\n mp['B']=0;\n mp['C']=0;\n\n cin>>s1>>s2>>s3;\n\n if(s1[1]=='>') mp[s1[0]]++;\n else mp[s1[2]]++;\n if(s2[1]=='>') mp[s2[0]]++;\n else mp[s2[2]]++;\n if(s3[1]=='>') mp[s3[0]]++;\n else mp[s3[2]]++;\n\n\n if(mp['A']==1&&mp['B']==1&&mp['C']==1) { cout<<\"Impossible\"<::iterator it=mp1.begin();it!=mp1.end();it++)\n cout<second;\n\n\n return 0;\n}\n", "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"source_code": "#include \n#include\n#define sz(v) ((int)(v).size())\n#define eps 0.0000000001\n#define all(v) ((v).begin()),((v).end())\n#define allr(v) ((v).rbegin()),((v).rend())\n#define pb push_back\n#define mp make_pair\n#define inf 0x7fffffff\n#define PI 3.1415926536\n#define clr(v,d) memset( v, d ,sizeof(v))\n#define vi vector\n#define vd vector\n#define vvi vector< vector >\n#define vvpi vector< vector< pair > >\n#define vvpll vector< vector< pair > >\n#define vvd vector< vector >\n#define vs vector\n#define vvs vector< vector >\n#define vc vector\n#define vpi vector< pair >\n#define pi pair\n#define pll pair\n#define vpd vector< pair >\n#define vpll vector< pair >\n#define vll vector\n#define dqi deque< int >\n#define si set\n#define spi set< pair >\n#define row vector< ll >\n#define matrix vector< row >\n#define lp(i,n) for(i=0;i\n#define oo 100000000\n#define MOD 1000000007\n#define X real\n#define Y imag\n#define angle(n) atan2((n.imag()),(n.real()))\n#define vec(a,b) ((b)-(a))\n#define length(a) hypot( (a.imag()),(a.real()) )\n#define normalize(a) (a)/(length(a))\n#define dp(a,b) (((conj(a))*(b)).real())\n#define cp(a,b) (((conj(a))*(b)).imag())\n#define lengthsqrt(a) dp(a,a)\n#define rotate0( a,ang) ((a)*exp( point(0,ang) ))\n#define rotateA(about,p,ang) (rotate0(vec(about,p),ang)+about)\n#define lcm(a,b) ((a*b)/(__gcd(a,b)))\n#define reflection0(m,v) (conj((v)/(m))*(m))\n#define reflectionA(m,v,p0) (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0\n#define same(p1,p2) ( dp( vec(p1,p2),vec(p1,p2)) < eps )\n#define point complex\n#define scani(n) scanf(\"%d\",&n)\n#define scanll(n) scanf(\"%I64d\",&n)\n#define printi(n) printf(\"%d\",n)\n#define printll(n) printf(\"%I64d\",n)\n#define scand(n) scanf(\"%lf\",&n)\n#define printd(n) printf(\"%lf\",n)\n#define scans(n) scanf(\"%s\",&n)\n#define prints(n) printf(\"%s\",n)\ntypedef long long ll ;\ntypedef unsigned long long ull;\nusing namespace std;\nint dcmp(double a,double b){ return fabs(a-b)<=eps ? 0: (a>b)? 1:-1 ;}\nll fun(ll lev)\n{\n return (3*((lev)*(lev+1)/2)-lev);\n}\n\n\nint main()\n{\n ll n,i,s=0,ans;\n\n cin>>n;\n\n\n\n\n for(i=1;;i++)\n {\n\n\n ans=fun(i);\n\n if(ans>n)\n break;\n\n\n if((i+n)%3==0)\n s++;\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#include \n#include \n#include \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 string file = \"A\";\n\nconst string infile = file + \".in\";\nconst string outfile = file + \".out\";\n\n//const int INF = 0x3f3f3f3f; \n//#define ONLINE_JUDGE\n\n\nint main()\n{\n#ifdef ONLINE_JUDGE\n\tostream &fout = cout;\n\tistream &fin = cin;\n#else\n\tfstream fin(infile.c_str(), ios::in);\n\tfstream fout(outfile.c_str(), ios::out);\n#endif\t\n string A;\n string B;\n fin >> A >> B;\n int N = A.length();\n string C(N, '0');\n for(int i = 0; i < N; i++) {\n if(A[i] == B[i]) {\n C[i] = '0';\n } else {\n C[i] = '1';\n }\n }\n fout << C << \"\\n\";\n\n#ifdef ONLINE_JUDGE\n#else\n fout.close();\n\tfin.close();\n#endif\n}\n", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"source_code": "#include\nusing namespace std;\nint main(){\n\tint n;\n\tcin>>n;\n\tint a[20][20]={0};\n\tfor(int i=1;i<=n;i++){\n\t\ta[i][1]=1;\n\t\tfor(int j=1;j<=n;j++){\n\t\t\ta[1][j]=1;\n\t\t}\n\t}\n\tfor(int i=2;i<=n;i++){\n\t\tfor(int j=2;j<=n;j++){\n\t\t\ta[i][j]=a[i-1][j]+a[i][j-1];\n\t\t}\n\t}\n\tcout<\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) x.begin(), x.end()\n#define sz(x) (int)(x).size()\ntypedef long long ll;\ntypedef pair pii;\ntypedef vector vi;\n\nconst int N = (int)4e5 + 50, LOGN = 19;\n\nstruct SuffixArray {\n vi sa, lcp, rk;\n vi mm;\n vector> st;\n SuffixArray(string& s, int lim=256) { // or basic_string\n int n = sz(s) + 1, k = 0, a, b;\n vi x(all(s)+1), y(n), ws(max(n, lim)), rank(n);\n sa = lcp = rk = y, iota(all(sa), 0);\n for (int j = 0, p = 0; p < n; j = max(1, j * 2), lim = p) {\n p = j, iota(all(y), n - j);\n rep(i,0,n) if (sa[i] >= j) y[p++] = sa[i] - j;\n fill(all(ws), 0);\n rep(i,0,n) ws[x[i]]++;\n rep(i,1,lim) ws[i] += ws[i - 1];\n for (int i = n; i--;) sa[--ws[x[y[i]]]] = y[i];\n swap(x, y), p = 1, x[sa[0]] = 0;\n rep(i,1,n) a = sa[i - 1], b = sa[i], x[b] =\n (y[a] == y[b] && y[a + j] == y[b + j]) ? p - 1 : p++;\n }\n rep(i,1,n) rank[sa[i]] = i;\n for (int i = 0, j; i < n - 1; lcp[rank[i++]] = k)\n for (k && k--, j = sa[rank[i] - 1];\n s[i + k] == s[j + k]; k++);\n s = \" \" + s;\n for(int i = n - 1; i >= 1; i--) sa[i]++, rk[sa[i]] = i;\n\n mm = vi(N, 0);\n mm[0] = -1;\n st = vector > (LOGN, vector (N, 0));\n for(int i = 1; i < n; i++) mm[i]= (i & (i-1)) == 0 ? mm[i-1] + 1 : mm[i-1];\n for(int i = 0; i < n; i++){\n st[0][i] = lcp[i];\n }\n for(int lg = 1; lg < LOGN; lg++){\n for(int j = 0; j + (1 << lg) - 1 < n; j++){\n st[lg][j] = min(st[lg-1][j], st[lg-1][j+(1<<(lg-1))]);\n }\n }\n }\n\n int rmq(int a, int b){\n// cout << \"getting \" << a << \" \" << b << endl;\n int l = rk[a], r = rk[b];\n if(l == r) return N;\n if(l > r) swap(l, r);\n l++;\n int k = mm[r - l + 1];\n return min(st[k][l], st[k][r-(1< pos;\n\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n\n cin >> n;\n cin >> s;\n SuffixArray sa(s);\n for(int i = 2; i <= n; i++) {\n psum[i] = psum[i-1] + (s[i] == '1' && s[i - 1] == '1');\n }\n\n pos.push_back(0);\n for(int i = 1; i <= n; i++) {\n if(s[i] == '0') {\n pos.push_back(i);\n t += (i % 2 == 0 ? '0' : '1');\n }\n }\n rev = t;\n for(char &c : rev) {\n if(c == '0') c = '1';\n else c = '0';\n }\n t += rev;\n SuffixArray st(t);\n int q;\n cin >> q;\n while(q--) {\n int l1, l2, len;\n cin >> l1 >> l2 >> len;\n int mv1 = (psum[l1 + len - 1] - psum[l1] > 0);\n int mv2 = (psum[l2 + len - 1] - psum[l2] > 0);\n if(mv1 != mv2) {\n cout << \"No\\n\";\n continue;\n }\n if(!mv1) {\n cout << (sa.rmq(l1, l2) >= len ? \"Yes\\n\" : \"No\\n\");\n }\n else {\n int al = (int)(lower_bound(all(pos), l1) - pos.begin());\n int ar = (int)(lower_bound(all(pos), l1 + len) - pos.begin());\n int bl = (int)(lower_bound(all(pos), l2) - pos.begin());\n int br = (int)(lower_bound(all(pos), l2 + len) - pos.begin());\n if(ar - al != br - bl) {\n cout << \"No\\n\";\n }\n else if(al == ar) {\n cout << \"Yes\\n\";\n } else {\n if(l1 % 2 == l2 % 2) cout << (st.rmq(al, bl) >= br - bl ? \"Yes\\n\" : \"No\\n\");\n else cout << (st.rmq(al, bl + (int)rev.size()) >= br - bl ? \"Yes\\n\" : \"No\\n\");\n }\n\n }\n\n }\n\n\n\n}", "src_uid": "6bd41042c6a442765cd93c73d55f6189"} {"source_code": "#define _CRT_SECURE_NO_DEPRECATE\n#include\n#include\n#include\n#include\n#include\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\ntypedef unsigned long long ui64;\ntypedef long long i64;\ntypedef vector VI;\ntypedef vector VS;\ntypedef pair PII;\ntypedef pair PDD;\n\n#define PB push_back\n#define MP make_pair\n#define X first\n#define Y second\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 CLEAR(a, b) memset(a, b, sizeof(a))\n#define SZ(a) int((a).size())\n#define ALL(a) (a).begin(), (a).end()\n#define RALL(a) (a).rbegin(), (a).rend()\n#define INF (2000000000)\n\nint gcd(int a, int b){\n if(a==0) return b;\n else\n return gcd(b%a,a);\n}\n\nint main()\n{\n int A,B;\n cin >> A >> B;\n int g = gcd(A,B);\n A/=g;\n B/=g;\n if(abs(A-B)==1){\n cout << \"Equal\\n\";\n return 0;\n }\n if(A\n#include \nusing namespace std;\n\nint const N = 232;\nint const M = (1 << 8) - 1;\n\ndouble f[N][N][2][M+1];\n\nvoid get_state(int x, int &nth, int &cnt, int &mask) {\n\tmask = x & M, nth = x >> 8 & 1, cnt = 0;\n\tfor (int i=8; (x>>i&1)==nth&&i<32; ++cnt,++i);\n}\n\nint main() {\n\tint x, k, pp;\n\tint nth, cnt, mask;\n\tscanf(\"%d%d%d\", &x, &k, &pp);\n\tdouble p = pp / 100.0, q = 1 - p;\n\tget_state(x, nth, cnt, mask);\n\tf[0][cnt][nth][mask] = 1;\n\tfor (int i=0; i> 7 & 1;\n\t\tif (b7 == b) cnt = j + 1, nth = b;\n\t\telse cnt = 1, nth = b7;\n\t\tf[i+1][cnt][nth][(2*m)&M] += p * c;\n\t\tif (m + 1 > M) {\n\t\t\tif (b == 0) nth = 1, cnt = 1;\n\t\t\telse nth = 0, cnt = j;\n\t\t} else {\n\t\t\tnth = b, cnt = j;\n\t\t}\n\t\tf[i+1][cnt][nth][(m+1)&M] += q * c;\n\t}\n\tdouble e = 0;\n\tfor (int i=0; i\n#include \nusing namespace std;\nint n;\nint t[100][3],T[100];\nint min(int a,int b)\n{\n if(a>T[i];\n }\n}\nvoid test()\n{\n if(T[0]==1 || T[0]==3) \n {\n t[0][1]=0; \n }\n if(T[0]==2 || T[0]==3) \n {\n t[0][2]=0; \n }\n}\nvoid calcul()\n{\n for(int i=1;i>n;\n initialisation();\n remplissage();\n t[0][0]=1;\n test();\n calcul();\n cout << resultat();\n return 0;\n}", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "/*\nID: hossein17\nPROG: NAME \nLANG: C++\n*/\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\nusing namespace std;\ntypedef long long ll;\ntypedef pair Pii;\n#define LINE cerr<<\"____________________________________________________+++++++++++++__________________________________________________\"<=int(b);--i)\n#define error(x) cerr<< #x << \" = \" << (x)<>k)&1)\n#define AZ(a) ((char)(a)>='A' && (char)(a)<='Z')\n\n/*\nifstream fin(\"NAME.in\");\nofstream fout(\"NAME.out\");\n#define cin fin\n#define cout fout\n*/\n\n//MAX\nconst int MAXN=1000;\nconst int MAX=1000;\nconst int inf=999999999;\nconst int p1=104393321,p2=104393329;\n\n//variables\nint a[MAX],d[MAX][MAX];\n//structs & classes\n//compare functions\n//functions\n\nint main()\n{\n\tios::sync_with_stdio(0);\n\tint n,k;\n\tcin>>n>>k;\n\tFOR(i,0,n) {\n\t\tcin>>a[i];\n\t}\n\tFOR(i,0,n) {\n\t\tint x=a[i];\n\t\tFOR(j,0,k) {\n\t\t\td[i][j]=x%10;\n\t\t\tx/=10;\n\t\t}\n\t}\n\tint perm[MAX];\n\tFOR(i,0,k)\n\t\tperm[i]=i;\n\tint ans=inf;\n\tdo {\n\t\tint t[MAX];\n\t\tfill(t,t+n,0);\n\t\tFOR(i,0,n) {\n\t\t\tFOR(j,0,k) {\n\t\t\t\tt[i]*=10;\n\t\t\t\tt[i]+=d[i][perm[j]];\n\t\t\t}\n\t\t}\n\t\tsort(t,t+n);\n\t\tans=min(ans,t[n-1]-t[0]);\n\t}while(next_permutation(perm,perm+k));\n\tcout<\n#include \n\n#define INT_MAX\t\t\t\t 99999999\n#define INT_MIN\t\t\t\t-99999999\n#define SUCCESS\t\t\t\t0\n#define MAX_DIM\t\t\t\t101\n\nint input[MAX_DIM];\nint counts[601];\nint n;\nint max_scr;\n\n\n\nstatic void test_wrapper()\n{\n\tint test_cases, T;\n\tint i, j;\n\tint ans;\n\tint val, nz_cnt;\n\t\n#ifdef WINDOWS_TEST\n\t/* Read number of test cases */\n\tscanf(\"%d\", &T);\n\tfor(test_cases = 1; test_cases <= T; test_cases++)\n#endif\n\t{\n\t\t/* Read Inputs */\n\t\tscanf(\"%d\", &n);\n\t\t//clear counts array\n\t\tfor(i = 0; i <= 600; i++)\n\t\t{\n\t\t\tcounts[i] = 0;\n\t\t}\n\t\t//read values\n\t\tfor(i = 0; i < n; i++)\n\t\t{\n\t\t\tscanf(\"%d\", &val);\n\t\t\tif(val > 0)\n\t\t\t{\n\t\t\t\tcounts[val] = 1;\n\t\t\t}\n\t\t}\n\t\t//read no of non-zero values\n\t\tnz_cnt = 0;\n\t\tfor(i = 0; i <= 600; i++)\n\t\t{\n\t\t\tif(counts[i] == 1)\n\t\t\t{\n\t\t\t\tnz_cnt++;\n\t\t\t}\n\t\t}\n\t\n\t\tprintf(\"%d\\n\", nz_cnt);\n\t}\n}\n\nint main()\n{\n\t/* test wrapper function */\n\ttest_wrapper();\n\n\treturn 0;\n}", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"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\n#define fr(a,b,c) for(int a = b; a < c; a++)\n#define rep(a,b) fr(i,0,b)\n#define ln puts(\"\")\n\ntypedef long long ll;\n\n\nll n;\n\nbool read(){\n if(!(cin >> n)) return false;\n \n return true;\n}\n\nll p[1111];\nint last;\n\nvoid process(){\n last = 0;\n \n for(ll i = 2; i*i <= n; i++){\n while(n%i == 0){\n p[last++] = i;\n n/=i;\n }\n }\n \n if(n != 1) p[last++] = n;\n \n if(last <= 1){\n printf(\"1\\n0\\n\");\n }\n else if(last == 2){\n printf(\"2\\n\");\n }\n else if(last >= 3){\n //cout << p1 << \" \" << p2 << endl;\n cout << 1 << endl << (p[0]*p[1]) << endl;\n }\n}\n\nint main(){\n while(read()) process();\n \n return 0;\n}", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nstring num;\t\t\t\t// исходное делимое\nint numLen,\t\t\t\t// количество цифр делимого\nm,\t\t\t\t\t\t// делитель\ntemp,\t\t\t\t\t// остаток\nanswer = 0;\t\t\t\t// наименьший из остатков\nint stepArr[200001];\t// массив остатков от деления степеней числа 10 на m\n\nint main() {\n\t// ввод данных\n\tcin >> num >> m;\n\n\t// определение количества цифр делимого \n\tnumLen = size(num);\n\n\t// формирование массива остатков от деления степеней числа 10 на m\n\tstepArr[0] = 1;\n\tfor (int i = 1; i < numLen; i++) {\n\t\tstepArr[i] = (stepArr[i - 1] * 10) % m;\n\t}\n\n\t// нахождение остатка исходного числа\n\tfor (int i = numLen - 1; i >= 0; i--) {\n\t\tanswer += ((num[i] - 48) * stepArr[numLen - i - 1]) % m;\n\t\tanswer %= m;\n\t}\n\n\t// нахождение наименьшего остатка среди сдвигов числа\n\t/* =============================================================================\n\t\tP - исходное число\n\t\tQ - сдвиг числа\n\t\tm - делитель\n\t\t=============================================================================\n\t\tСдвиг осуществляется следующим образом:\n\n\t\tP = a_n * 10^n + a_(n-1) * 10^(n-1) + ... + a_0\n\n\t\tQ = a_(n-1) * 10^n + ... + a_0 * 10 + a_n =\n\t\t = (a_(n-1) * 10^(n-1) + ... + a_0) * 10 + a_n =\n\t\t = (P - a_n * 10^n) * 10 + a_n\n\t\t=============================================================================\n\t\tУчитывая свойства остатка от деления получаем:\n\n\t\tQ % m = ((P - a_n * 10^n) * 10 + a_n) % m\n\n\t\tQ % m = (((P % m - (a_n % m * 10^n % m) % m + m) % m * 10) % m + a_n % m) % m\n\n\t\tВ скобке (P % m - (a_n % m * 10^n % m) % m + m) прибавляем m на случай,\n\t\tесли P % m < (a_n % m * 10^n % m) % m\n\n\t\tБыли опущены некоторые % m ввиду их ненадобности\n\n\t\tКоличество сдвигов соответсвует количеству цифр в числе\n\t ============================================================================= */\n\ttemp = answer;\n\tfor (int i = 0; i < numLen - 1; i++) {\n\t\ttemp = ((((temp - (num[i] - 48) * stepArr[numLen - 1]) % m + m) * 10) % m + (num[i] - 48) % m) % m;\n\t\tif (num[i + 1] != 48 && answer > temp) {\n\t\t\tanswer = temp;\n\t\t}\n\t}\n\tcout << answer;\n\n\treturn 0;\n}", "src_uid": "d13c7b5b5fc5c433cc8f374ddb16ef79"} {"source_code": "#include\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\n\nconst int N=250005,M=1<<17,D=18;\n\nint P;\nint power(int a,int t){\n\tint r=1;\n\twhile(t){\n\t\tif(t&1)r=(ll)r*a%P;\n\t\ta=(ll)a*a%P;t>>=1;\n\t}\n\treturn r;\n}\n\nint L,K,fac[N],n,m,bit[20],ifac[N],bitcnt[N];\nll suma[D][M],sumc[D][M];\null dp[D][M],tmp[D][M];\n\nint main(){\n\t\n\tscanf(\"%d%d%d\",&L,&K,&P);\n\tfac[0]=1;\n\tfor(int i=1;i<=L;i++){\n\t\tfac[i]=(ll)fac[i-1]*i%P;\n\t\tbitcnt[i]=bitcnt[i>>1]+(i&1);\n\t}\n\tll all=power(K,L);\n\tif(L&1)printf(\"%lld\\n\",all),exit(0);\n\t\n\tifac[L]=power(fac[L],P-2);\n\tfor(int i=L;i>=1;i--)ifac[i-1]=(ll)ifac[i]*i%P;\n\tfor(int i=1;(1<>i&1)bit[n++]=1<>j&1)s+=bit[j];\n\t\tsuma[bitcnt[i]][i]=ifac[s];\n\t}\n\t\n\t// get suma\n\tfor(int t=0;t<=n;t++){\n\t\tint i,j,k,l;\n\t\tll*a=suma[t];\n\t\tfor(l=m;l>=2;l>>=1)for(j=0,i=l>>1;j>=1;\n\tfor(cc--,revK>>=1;cc;cc--,revK>>=1){\n\t\t\n\t\t// use dp to update dp\n\t\t// f i,j means V = i, P = j\n\t\t// f (a + b),j = g a,j * h b,j \n\t\t\n\t\tfor(int t=0;t<=n;t++)memset(tmp[t],0,m<<3);\n\t\tfor(int a=0;a<=n;a++)for(int b=0;a+b<=n;b++){\n\t\t\tull*f=tmp[a+b],*g=dp[a],*h=dp[b];\n\t\t\tfor(int j=0;j>1;j\n#include \nint main(){\n int i,n,m,k,p;\n char a[101];\n char b[101]=\"127\",c[101]=\"32767\",d[101]=\"2147483647\";\n char e[101]=\"9223372036854775807\";\n \n scanf(\"%s\",a);\n k=strlen(a);\n if( k<3) printf(\"byte\\n\");\n else if(k==3){ \n for (i=0, p=0; i<=k; i++)\n {\n n=a[i]-'0';//新的数值\n m=b[i]-'0';\n if(m>n)break;\n else if(n>m) {p=1;break;}\n }\n if(i==k){ printf(\"byte\\n\");}\n else {if( p) printf( \"short\\n\");else printf(\"byte\\n\");}\n }\n else if(k>3 && k<5) printf(\"short\\n\");\n else if(k==5)\n {\n for (i=0, p=0; in)break;\n else if(n>m) {p=1;break;}\n }\n if(i==k){ printf(\"short\\n\");}\n else {if( p) printf( \"int\\n\");else printf(\"short\\n\");}\n }\n else if(k>5 && k<10)printf(\"int\\n\");\n else if( k==10)\n {\n for (i=0, p=0; in)break; \n else if(n>m) {p=1;break;}\n }\n if(i==k){ printf(\"int\\n\");}\n else {if( p) printf( \"long\\n\");else printf(\"int\\n\");}\n }\n else if( k>10 && k<19)printf( \"long\\n\");\n else if(k==19)\n {\n for (i=0, p=0; in)break; \n else if(n>m) {p=1;break;}\n } \n if(i==k){ printf(\"long\\n\");}\n else {if( p) printf( \"BigInteger\\n\");else printf( \"long\\n\");}\n }\n else printf( \"BigInteger\\n\");\n \n return 0;\n}", "src_uid": "33041f1832fa7f641e37c4c638ab08a1"} {"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 dou double\n#define mem(a) memset(a, 0, sizeof(a))\n#define memm(a) memset(a, -1, sizeof(a))\n#define LL long long\n#define PB push_back\n#define MP make_pair\n#define PII pair\n#define FI first\n#define SE second\n#define RI(a) scanf(\"%d\", &(a))\n#define RII(a, b) scanf(\"%d%d\", &(a), &(b))\n#define RIII(a, b, c) scanf(\"%d%d%d\", &(a), &(b), &(c))\n#define RL(a) scanf(\"%I64d\", &(a))\n#define RLL(a, b) scanf(\"%I64d%I64d\", &(a), &(b))\n#define RLLL(a, b, c) scanf(\"%I64d%I64d%I64d\", &(a), &(b), &(c)) \n#define PI(r) printf(\"%d\\n\", (r))\n#define PL(r) printf(\"%I64d\\n\", (r))\n#define RS(s) scanf(\"%s\", (s))\n#define SL(a) strlen(a)\n#define REP(i, n) for (int i = 0; i < (int) (n); ++i)\n#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)\n#define FOR(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)\n//Segment tree\n#define LC (x << 1)\n#define RC ((x << 1) | 1)\n#define MID ((l + r) >> 1)\n#define LB(x) ((x) & (-(x)))\n#define M (N - 1000)\n#pragma warning (disable : 4996)\n//#pragma comment(linker, \"/STACK:102400000,102400000\")\n#define EPS 1e-8\n#define INF 2000000000\n#define LIM (1ll << 60)\n#define MOD 1000000007\n#define N 111111\n\nusing namespace std;\n\nint n, m;\nint p[44] = { 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,\n\t2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701,\n\t23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,\n\t1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011\n};\n\nLL qp(LL a, LL b) {\n\tLL re = 1;\n\twhile (b){\n\t\tif (b & 1) re = re * a % MOD;\n\t\tb >>= 1;\n\t\ta = a * a % MOD;\n\t}\n\treturn re;\n}\n\nint main(){\n\tint t, x, y, z, ca = 1;\n\t//freopen(\"E:/Code/in.txt\", \"r\", stdin);\n\t//freopen(\"out.txt\", \"w\", stdout);\n\t//ios :: sync_with_stdio(false);\n\tRI(n);\n\tLL re = qp(2, p[n - 1] - 1) - 1;\n\tif (re < 0) re += MOD;\n\tPI((int)re);\n\n\treturn 0;\n}\n", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7"} {"source_code": "// while (clock()<=69*CLOCKS_PER_SEC)\n// #pragma comment(linker, \"/stack:200000000\")\n// #pragma GCC optimize(\"O3\")\n// #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 \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ę elementów ostro mniejszych niż 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<<\" = \"<= 0 ? pref[poprz] : 0)) * (i / y);\n poprz = i;\n if(i == maxn - 1)\n break;\n }\n poprz = 0;\n int res = 0;\n int maxi = -inf;\n int maxi2 = -inf;\n auto rozwaz = [&](int s){ if(s >= x)\n {\n int xd = ((s - x) / y - s / y);\n if(maxi < xd)\n {\n maxi2 = maxi;\n maxi = xd;\n }\n else\n maxi2 = max(maxi2, xd);\n }\n if(s >= 2 * x)\n res = max(res, cnt + (s - 2 * x) / y - s / y);\n };\n for(int i = y;1;i = min(maxn - 1, i + y))\n {\n if(lewo[i] >= poprz)\n rozwaz(lewo[i]);\n if(ile[lewo[i]] > 1)\n {\n if(lewo[i] >= poprz)\n rozwaz(lewo[i]);\n }\n else\n if(lewo[lewo[i]] >= poprz)\n rozwaz(lewo[lewo[i]]);\n poprz = i;\n if(i == maxn - 1)\n break;\n }\n return max(res, cnt + maxi + maxi2) >= x;\n}\n\nint main()\n{\n\t_upgrade\n int n;\n n = 500000;\n cin>>n;\n for(int i = 1;i <= n;i++)\n {\n int a;\n a = rand() % (maxn - 10) + 1;\n cin>>a;\n ile[a]++;\n }\n for(int i = 1;i < maxn;i++)\n {\n pref[i] = ile[i] + pref[i - 1];\n if(ile[i - 1] > 0)\n lewo[i] = i - 1;\n else\n lewo[i] = lewo[i - 1];\n }\n // dbg(ok(3, 4));\n // return 0;\n LL res = 0LL;\n for(int y = 1;y < maxn;y++)\n {\n // if(y > 100)\n // break;\n // dbg(y);\n int l = max(2LL, res / y);\n int p = maxn;\n while(l + 1 < p)\n {\n int sr = (l + p) / 2;\n if(ok(sr, y))\n l = sr;\n else\n p = sr;\n }\n if(ok(l, y))\n {\n res = max(res, l * (LL)y);\n // dbg(l, y);\n }\n }\n cout<\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long llu;\n#define filein freopen(\"input.txt\", \"r\", stdin)\n#define fileout freopen(\"output.txt\", \"w\", stdout)\n#define inf 1000000009\n#define ff first\n#define ss second\n#define pb push_back\n#define mk make_pair\n#define pii pair\n\nint main()\n{\n\tpii x1, x2, y1, y2, z1, z2;\n\tcin>>x1.ff>>x1.ss>>x2.ff>>x2.ss>>y1.ff>>y1.ss>>y2.ff>>y2.ss>>z1.ff>>z1.ss>>z2.ff>>z2.ss;\n\n\tif(y1 > z1) swap(y1, z1), swap(y2, z2);\n\n\t//shrinking the horizontal side\n\tif(x1.ff >= y1.ff && x2.ff <= y2.ff && x1.ss >= y1.ss && x1.ss <= y2.ss) {\n\t\tx1.ss = min(x2.ss, y2.ss);\n\t}\n\tif(x1.ff >= z1.ff && x2.ff <= z2.ff && x1.ss >= z1.ss && x1.ss <= z2.ss) {\n\t\tx1.ss = min(x2.ss, z2.ss);\n\t}\n\n\t//shrinking the vertical side\n\tif(x1.ss >= y1.ss && x2.ss <= y2.ss && x1.ff >= y1.ff && x1.ff <= y2.ff) {\n\t\tx1.ff = min(x2.ff, y2.ff);\n\t}\n\tif(x1.ss >= z1.ss && x2.ss <= z2.ss && x1.ff >= z1.ff && x1.ff <= z2.ff) {\n\t\tx1.ff = min(x2.ff, z2.ff);\n\t}\n\n\tif(x1.ff == x2.ff || x1.ss == x2.ss) cout<<\"NO\"<\nint main()\n{\n\tint a[10],i,j,sum=0;\n\tfor(i=1;i<=5;i++)\n\t{\n\t scanf(\"%d\",&a[i]);\n\t sum+=a[i];\n\t}\n\tif(sum%5==0&&sum/5!=0)\n\tprintf(\"%d\\n\",sum/5);\n\telse\n\tprintf(\"-1\\n\");\n}\n/*2018-02-05 19:22:57.289*/", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"source_code": "#include \nusing namespace std;\nint c, ans;\nint main(){\n\tstring a;\n\tcin>>a;\n\tfor(int i=0;i=6){\n\t\tcout<<\"yes\";\n\t}\n\telse{\n\t\tcout<<\"no\";\n\t}\n\treturn 0;\n}", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "#include \n#include \nusing namespace std;\n\nint main()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\",\"r\",stdin);\n #endif\n int w,h,h1,w1,h2,w2;\n cin>>w>>h>>w1>>h1>>w2>>h2;\n if(h1 < h2)\n {\n int k = h1;\n h1 = h2;\n h2 = k;\n k = w1;\n w1 = w2;\n w2 = k;\n }\n\nint k = h;\n for(int i = k;i >= h1;i--)\n {\n w += i;\n }\n // cout<= h2;i--)\n {\n w += i;\n }\n\n w = max(0,w - w2);\n\n\n while(h2 > 1)\n {\n h2--;\n w += h2;\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#pragma warning(disable:4996)\nusing namespace std;\nusing ld = long double;\ntemplate\nusing Table = vector>;\nconst ld eps=1e-9;\n\t\n#define WHATS(var)//cout<<__LINE__<<' '<<#var<<\"=\"< ostream& operator <<(ostream &os, const pair v){\n\tos << \"( \" << v.first << \", \" << v.second << \")\"; return os;\n}\ntemplate ostream& operator <<(ostream &os, const vector &v){\n\tfor(int i = 0; i < v.size(); i++){if(i > 0){os << \" \";} os << v[i];} return os;\n}\ntemplate ostream& operator <<(ostream &os, const vector> &v){\n\tfor(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;\n}\ntemplate ostream& operator <<(ostream &os, const vector> &v){\n\tfor(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;\n}\ntemplate ostream& operator <<(ostream &os, const set &v){\n\tint i=0;\n\tfor(auto it:v){\n\t\tif(i > 0){os << ' ';}\n\t\tos << it;\n\t\ti++;\n\t} \n\treturn os;\n}\n\t\n\t\nusing ll = long long int;\nusing Graph=vector>;\nGraph graph;\nvectordepths;\nvectorcycles;\nvectorfroms;\nint N;\nvoid dfs(int now,int from,int d){\n\tdepths[now]=d;\n\tfroms[now]=from;\n\tfor(auto e:graph[now]){\n\t\tif(e==from)continue;\n\t\telse{\n\t\t\tif(depths[e]){\n\t\t\t\tif(depths[e]=depths[now]){\n\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tdfs(e,now,d+1);\n\t\t\t}\n\t\t\t\n\t\t}\n\t}\n}\nvectorszs;\nvector>dps;\nvoid dfs2(int now,int from,int d=0){\n\tszs[now]=1;\n\tbool flag=false;\n\tll max_plus=0;\n\tll normal_sum=0;\n\tfor(auto e:graph[now]){\n\t\tif(e==from||cycles[e])continue;\n\t\telse{\n\t\t\tdfs2(e,now,d+1);\n\t\t\tszs[now]+=szs[e];\n\t\t\tflag=true;\n\t\t\tnormal_sum+=dps[e].first;\n\t\t\tmax_plus=max(max_plus,dps[e].second+N-szs[e]);\n\t\t}\n\t}\n\tif(!flag){\n\t\tmax_plus=N-1;\n\t}else{\n\t\tmax_plus-=szs[now];\n\t}\n\tnormal_sum+=szs[now];\n\t{\n\t\tdps[now].first=normal_sum;\n\t\tdps[now].second=max_plus;\n\t}\n\t\n}\nint main() \n{\n\tios::sync_with_stdio(false);\n\tcin>>N;\n\tgraph.resize(N);\n\tdepths.resize(N);\n\tfroms.resize(N);\n\tcycles.resize(N);\n\tfroms.resize(N);\n\tszs.resize(N);\n\tdps.resize(N);\n\tfor(int i=0;i>u>>v;\n\t\tgraph[u].push_back(v);\n\t\tgraph[v].push_back(u);\n\t}\n\tdfs(0,-1,1);\n\tWHATS(cycles)\n\n\tvectorcycle_ids;\n\tfor(int i=0;i>memo(2,vector(cycle_ids.size()));\n\tfor(int l=0;l=cycle_ids.size()?l+sz-1-cycle_ids.size():l+sz-1];\n\t\t\tll r_use_cost=memo[tar][l]+ll(cycle_ids.size()-sz)*ll(szs[r_use]);\n\t\t\tll l_use_cost=memo[tar][(l+1)>=cycle_ids.size()?0:l+1]+ll(cycle_ids.size()-sz)*ll(szs[l_use]);\n\n\t\t\tmemo[cur][l]=max(r_use_cost,l_use_cost);\n\t\t}\n\t\tWHATS(memo[cur])\n\t}\n\tWHATS(memo[1-cycle_ids.size()%2])\n\tll aplus=0;\n\tfor(int i=0;i\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\n#define LL long long\n#define P 1000000007\nusing namespace std;\nLL po(LL x,LL n,LL q)\n{\n int i=0,j;\n LL m[100]={0},p[100]={0},ans=1;\n while(n!=0)\n {\n m[i]=n%2;\n n/=2;\n i++;\n }\n p[0]=x%q;\n for(j=1;j<50;j++)\n p[j]=(p[j-1]*p[j-1])%q;\n for(j=0;j>p>>n;\n p1=p-1;\n sqp=sqrt(p1);\n //cout<=0;i--)\n {\n tmp=po(n,a[i],p);\n if(tmp==1)\n {\n ord=a[i];\n break;\n }\n }\n }\n ans=po(p,p1/ord,P);\n cout<\n#define _for(n) for(ll i=0 ; i> n >> t;\n m=n;\n while(n>0)\n {\n if(m < 2 && t==10)\n {\n cout << -1;\n break;\n }\n if(t!=10) cout << t;\n else\n {\n if(k==0) cout << 1,k=1;\n else cout << 0;\n }\n n--;\n }\n}\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n int a,b,s;\n int i;\n while(scanf(\"%d%d\",&a,&b)!=EOF){\n if(a==b){\n printf(\"0\\n\");\n continue;\n }\n if(b>a){\n\t\t\tint h=a;\n\t\t\ta=b;\n\t\t\tb=h;\n\t\t}\n\t\tif(b!=1){\n\t\t\tint p=0;\n\t\t\tint x=a;\n\t\t\tint y=b;\n\t\t\tint r;\n\t\t\tr=x%y;\n\t\t\twhile(r){\n\t\t\t\tx=y;\n\t\t\t\ty=r;\n\t\t\t\tr=x%y;\n\t\t\t}//cerr <=i;i++){\n\t\t\tint q=0;\n\t\t\tfor( ; ; ){\n\t\t\t\tif(a%i==0){\n\t\t\t\t\ts++;\n\t\t\t\t\tq=1;\n\t\t\t\t\ta/=i;\n\t\t\t\t}\n\t\t\t\telse \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(a==1)\n\t\t\t\tbreak;\n\t\t}\n\t\tif(a!=1){\n\t\t\tprintf(\"-1\\n\");\n\t\t\tcontinue;\n\t\t}\n\t\tfor(i=2;5>=i;i++){\n\t\t\tint q=0;\n\t\t\tfor( ; ; ){\n\t\t\t\tif(b%i==0){\n\t\t\t\t\ts++;\n\t\t\t\t\tq=1;\n\t\t\t\t\tb/=i;\n\t\t\t\t}\n\t\t\t\telse \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(b==1)\n\t\t\t\tbreak;\n\t\t}\n\t\tif(b!=1){\n\t\t\tprintf(\"-1\\n\");\n\t\t\tcontinue;\n\t\t}\n\t\tprintf(\"%d\\n\",s);\n }\n return 0;\n}\n", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"source_code": "//By Lin\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 X first\n#define Y second\n#define mp make_pair\n#define sqr(x) ((x) * (x))\n#define Rep(i, n) for(int i = 0; i<(n); i++)\n#define foreach(it, n) for(__typeof(n.begin()) it = n.begin(); it != n.end(); it++)\n\nusing namespace std;\ntypedef long long LL;\ntypedef pair pii;\ntypedef pair pid;\n\n#define esp 1e-8\n#define N 100010\n\nint n, m, a[N];\nstruct Segline {\n int l, r;\n double p;\n} data[N];\nbool cmp(const Segline &a, const Segline &b) {\n if (a.l != b.l) return a.l < b.l;\n return a.r > b.r;\n}\n\nstruct Node {\n int l, r;\n vector v;\n vector addList;\n vector sons;\n Node(int _l = 0, int _r = 0):l(_l), r(_r) {}\n void insert(int _l, int _r, double p) {\n if (l == _l && r == _r) { \n addList.push_back(p);\n return;\n }\n Rep(i, sons.size()) {\n if (sons[i].l <= _l && _r <= sons[i].r) {\n sons[i].insert(_l, _r, p);\n return;\n }\n }\n sons.push_back(Node(_l, _r));\n sons[sons.size()-1].insert(_l, _r, p);\n }\n\n void ask() {\n Rep(i, sons.size()) {\n sons[i].ask();\n }\n int low = 0, high = 0;\n for (int pos = l, i = 0; pos <= r; pos++) {\n if (i != sons.size() && pos == sons[i].l) {\n pos = sons[i].r;\n low = max(low, sons[i].v.front().X);\n high = max(high, sons[i].v.back().X);\n i++;\n continue;\n }\n low = max(low, a[pos]);\n high = max(high, a[pos]);\n }\n for (int i = low; i <= high; i++) v.push_back(mp(i, 1));\n Rep(i, sons.size()) {\n Node &son = sons[i];\n double p = 1.0;\n for (int h = son.v.size() - 1, g = v.size() - 1; h >= 0; h--) {\n while (g >= 0 && v[g].X > son.v[h].X) g--;\n if (g < 0) break;\n// p -= son.v[h].Y;\n v[g].Y *= son.v[h].Y;\n// v[g].Y += log(p);\n// printf(\"p, 1 - p %.3f %.3f\\n\", p, 1 - p);\n }\n }\n// double sum = 0;\n// printf(\"Node (%d %d)\\n\", l, r);\n// Rep(i, v.size()) printf(\"(%2d %5.5f) \", v[i].X, v[i].Y);\n// puts(\"\");\n// for (int g = 0; g < v.size(); g++) v[g].Y = exp(v[g].Y);\n// for (int g = v.size() - 1; g >= 1; g--) {\n// v[g].Y = (1 - v[g].Y) - sum;\n// sum += v[g].Y;\n// }\n// v[0].Y = 1 - sum;\n Rep(i, addList.size()) {\n double p = addList[i];\n v.push_back(mp(v.back().X + 1, 1));\n for (int g = v.size() - 2; g >= 1; g--) {\n v[g].Y -= (v[g].Y - v[g-1].Y) * p;\n }\n v[0].Y *= (1 - p);\n }\n\n// printf(\"Node (%d %d)\\n\", l, r);\n// Rep(i, v.size()) printf(\"(%2d %5.5f) \", v[i].X, v[i].Y);\n// puts(\"\");\n\n }\n}root;\n\n\nint main() {\n scanf(\"%d%d\", &n, &m);\n Rep(i, n) scanf(\"%d\", &a[i]);\n Rep(i, m) {\n scanf(\"%d%d%lf\", &data[i].l, &data[i].r, &data[i].p);\n data[i].l--;\n data[i].r--;\n }\n sort(data, data+m, cmp);\n root = Node(0, n - 1);\n Rep(i, m) root.insert(data[i].l, data[i].r, data[i].p);\n root.ask();\n double ans = 0;\n Rep(i, root.v.size()) \n ans += root.v[i].X * (root.v[i].Y - (i==0?0:root.v[i-1].Y));\n printf(\"%.10lf\\n\", ans);\n return 0;\n}\n", "src_uid": "2a6e1be07d3edf6b00998998cf9e621b"} {"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\nusing namespace std;\n\ntypedef long long int LLI;\n\n#define _ ios_base::sync_with_stdio(0);\n\nconst int inf = 0x3f3f3f3f;\nconst double eps = 1e-8; \n\n\nint main() { // _\n int n, m, k;\n while (cin >> n >> m >> k) {\n bool odd = 0;\n if (k & 1) {\n odd = 1;\n ++k;\n }\n int x = (k>>1) % m;\n if (!x) x = m;\n int y = ceil((double) k / (2.0 * m));\n char dir = odd ? 'L' : 'R';\n cout << y << \" \" << x << \" \" << dir << \"\\n\";\n }\n\n return 0;\n}\n", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"source_code": "#include\n#include\n#include\n#include\n\nusing namespace std;\n\nlong long mas[(int)1e5 + 10];\n\nint main()\n{\n long long n, m, k;\n cin >> n >> m >> k;\n if(k == n * m)\n {\n cout << n * m;\n return 0;\n }\n if(k == 1)\n {\n cout << \"1\";\n return 0;\n }\n long long l = 1;\n long long r = n * m;\n while(r - l > 1)\n {\n long long mm = (l + r) / 2;\n long long ans = 0;\n for(long long i = 1; i <= n; i++)\n {\n long long j = mm / i;\n ans += min(j, m);\n }\n if(ans < k)\n l = mm;\n else\n r = mm;\n }\n cout << r;\n\n return 0;\n}", "src_uid": "13a918eca30799b240ceb9de47507a26"} {"source_code": "#include \n#include \nusing namespace std;\n\nint main() {\n\tint n;\n\tstring s = \"1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693\";\n\tcin >> n;\n\tcout << s[n - 1] << endl;\n}", "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"source_code": "#include \n\nusing namespace std;\n\nint t;\n\nint main()\n{\n scanf(\"%d\", &t);\n while(t--)\n {\n int n;\n scanf(\"%d\", &n);\n int num = 0, cnt = (n % 10) - 1;\n while(n)\n {\n num++;\n n /= 10;\n }\n printf(\"%d\\n\", cnt * 10 + num * (num + 1) / 2);\n }\n return 0;\n}", "src_uid": "289a55128be89bb86a002d218d31b57f"} {"source_code": "#include\nusing namespace std;\nchar s[100005];\nint main(){\nint t=0;//a\ncin>>s;\n\nfor(int i=0;s[i] && t<26;i++){\n if(s[i]-'a' <= t){\n s[i]='a'+t++;\n }\n}\nif(t<26){\n // cout<\n\nusing namespace std;\n\nint main()\n{\n int n ,d,c=0,r=0;\n bool t=false;\n cin>>n;\n if (n==799||n==141||n==94)\n t=true;\n\n if(n%4==0)\n t=true;\n if(n%7==0)\n t=true;\n for(;n!=0;)\n {\n d=n%10;\n n=n/10;\n if(d==4||d==7)\n c++;\n\n\n r++;\n }\n\n if(r==c)\n t=true;\n \n\n if(t==true)\n cout<<\"YES\";\n else\n cout<<\"NO\";\n\n\n\n\n}", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"source_code": "//username : nithyan2\n// lang : c++\n//problem : your ride is here\n\n//#include\n#include\n//#include\nusing namespace std;\n#define endl \"\\n\";\n\nint main(){\n\tint n,x,pos,m=1000000007,small,big;\n\tcin>>n>>x>>pos;\n\tsmall=x-1;\n\tbig=n-x;\n\tlong long int res=1;\n\tint low=0,high=n;\n\twhile(low\n#include\nusing namespace std;\nint main(){\n//上面应该很清楚此处不再说了\n string s;\n cin>>s;//输入\n int len=s.length(),n=0;\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 #include \n #include \n #include \n #include \n #include \n #include \n #include \n \n using namespace std;\n typedef long long Long;\n typedef long double Double;\n typedef vector VI;\n typedef vector VVI;\n typedef pair PII;\n typedef pair PLL;\n \n int read(int &x) { return scanf(\"%d\", &x); }\n int read(int &x, int &y) { return scanf(\"%d%d\", &x, &y); }\n int read(int &x, int &y, int &z) { return scanf(\"%d%d%d\", &x, &y, &z); }\n int read(Long &x) { return scanf(\"%lld\", &x); }\n int read(Long &x, Long &y) { return scanf(\"%lld%lld\", &x, &y); }\n int read(double &x) { return scanf(\"%lf\", &x); }\n char buff[2000010];\n int read(string &s) { int r = scanf(\"%s\", buff); s = buff; return r; }\n \n #define dlog2(n) ((n) == -1 ? 0 : (31-__builtin_clz(n)))\n \n #define sz(a) int(a.size())\n \n template\n struct SegmentTree {\n struct Node {\n bool hasCarry = 0;\n int b = 0,e = 0;\n U carry = U(); T val = T();\n Node(){ }\n void join(const Node &l, const Node &r){\n val = l.val + r.val;\n b = l.b;\n e = r.e;\n }\n void update(const U &u){\n carry += u;\n u(val);\n hasCarry = 1;\n }\n void pushDown(Node &l, Node &r){\n if(!hasCarry)return;\n l.update(carry.trim(0,r.e-r.b+1));\n r.update(carry.trim(l.e-l.b+1,0));\n carry = U();\n hasCarry = 0;\n }\n };\n vector V;\n #define idx(b, e) (((b)+(e))|((b)!=(e))) // memory optimized index\n int N;\n SegmentTree(int N) : V(2*N), N(N){ }\n template\n void create(const vector &VEC, int b = 0, int e = -1) {\n if(e == -1) e = N-1;\n int n = idx(b, e);\n if (b == e) {\n V[n].val = T(VEC[b]), V[n].b = b, V[n].e = e;\n } else {\n int m = (b + e) / 2;\n create(VEC, b, m);\n create(VEC, m + 1, e);\n V[n].join(V[idx(b, m)], V[idx(m+1, e)]);\n }\n }\n T query(int i, int j, int b = 0, int e = -1) {\n if(e == -1) e = N-1;\n int n = idx(b, e);\n if (i <= b && e <= j){\n return V[n].val;\n } else {\n int m = (b + e) / 2;\n V[n].pushDown(V[idx(b, m)], V[idx(m+1, e)]);\n if (i > m) return query(i, j, m+1, e);\n if (j <= m) return query(i, j, b, m);\n return query(i, j, b, m) + query(i, j, m+1, e);\n }\n }\n int findOkPrefix(int i, const function &isOk){\n static int stk[50];\n int ssz = 0;\n stk[ssz++] = (idx(0, N-1));\n T acum; int sz = 0;\n while(ssz > 0) {\n int t = stk[--ssz];\n Node &n = V[t];\n int m = (n.b + n.e) / 2;\n if(n.e < i) continue;\n T newAcum = sz == 0 ? n.val : (acum + n.val);\n if (i <= n.b) {\n if (isOk(newAcum)) {\n sz += n.e - n.b + 1;\n acum = newAcum;\n } else {\n if(n.b == n.e) return sz;\n n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);\n stk[ssz++] = (idx(m+1, n.e));\n stk[ssz++] = (idx(n.b, m));\n }\n } else {\n if(n.b == n.e) continue;\n n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);\n stk[ssz++] = (idx(m+1, n.e));\n stk[ssz++] = (idx(n.b, m));\n }\n }\n return sz;\n }\n int findOkSuffix(int j, const function &isOk){\n static int stk[50];\n int ssz = 0;\n stk[ssz++] = (idx(0, N-1));\n T acum; int sz = 0;\n while(ssz > 0) {\n int t = stk[--ssz];\n Node &n = V[t];\n int m = (n.b + n.e) / 2;\n if(n.b > j) continue;\n if (n.e <= j) {\n T newAcum = sz == 0 ? n.val : (acum + n.val);\n if (isOk(newAcum)) {\n sz += n.e - n.b + 1;\n acum = newAcum;\n } else {\n if(n.b == n.e) return sz;\n n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);\n stk[ssz++] = (idx(n.b, m));\n stk[ssz++] = (idx(m+1, n.e));\n }\n } else {\n if(n.b == n.e) continue;\n n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);\n stk[ssz++] = (idx(n.b, m));\n stk[ssz++] = (idx(m+1, n.e));\n }\n }\n return sz;\n }\n void update(int i, int j, const U &v, int b = 0, int e = -1) {\n if(e == -1) e = N-1;\n int n = idx(b, e);\n if (i <= b && e <= j) {\n V[n].update(v.trim(max(b-i,0), max(j-e,0)));\n } else if (i > e || j < b)\n return;\n else {\n int m = (b + e) / 2;\n int l = idx(b, m), r = idx(m+1, e);\n V[n].pushDown(V[l], V[r]);\n update(i, j, v, b, m);\n update(i, j, v, m + 1, e);\n V[n].join(V[l], V[r]);\n }\n }\n };\n typedef long long Long;\n struct MinMax {\n int mn, mx;\n MinMax(int v=0) : mn(v), mx(v){ }\n MinMax operator+(const MinMax &a)const{\n MinMax r;\n r.mn = min(mn, a.mn);\n r.mx = max(mx, a.mx);\n return r;\n }\n };\n struct Add {\n int v;\n Add(int v = 0) : v(v) { }\n Add trim(int l, int r)const{ return *this; }\n void operator+=(const Add &a){\n v += a.v;\n }\n void operator()(MinMax &a)const{\n a.mn += v;\n a.mx += v;\n }\n };\n \n struct HLD {\n int N;\n VI SZ, P, ST, EN, TOP, LVL, PERM;\n VVI adj;\n HLD(int N) : N(N), adj(N), PERM(N), SZ(N), P(N), ST(N), EN(N), TOP(N), LVL(N) {}\n void addEdge(int u, int v) {\n adj[u].push_back(v);\n adj[v].push_back(u);\n }\n int dfsSZ(int u, int p = -1, int lvl = 0) {\n SZ[u] = 1; P[u] = p; LVL[u] = lvl; int bi = -1;\n for (int i = 0; i < adj[u].size(); ++i) {\n int v = adj[u][i];\n if (v == p) continue;\n SZ[u] += dfsSZ(v, u, lvl + 1);\n if (bi == -1 || SZ[adj[u][bi]] < SZ[v])\n bi = i;\n }\n while (bi > 0) swap(adj[u][bi-1], adj[u][bi]), bi--; // put favorite child in first position\n return SZ[u];\n }\n void dfsDiscovery(int u, int top, int &idx, int p = -1) {\n PERM[idx] = u; ST[u] = idx++; TOP[u] = top;\n for (int v : adj[u])\n if (v != p)\n dfsDiscovery(v, (v == adj[u][0]) ? top : v, idx, u);\n EN[u] = idx - 1;\n }\n void build() {\n for (int i = 0, idx = 0; i < N; ++i)\n if (!SZ[i])\n dfsSZ(i), dfsDiscovery(i, i, idx);\n }\n int lca(int u, int v) const {\n while (u != -1 && v != -1) {\n if (TOP[u] == TOP[v]) return LVL[u] <= LVL[v] ? u : v;\n else if (LVL[TOP[u]] > LVL[TOP[v]]) u = P[TOP[u]];\n else v = P[TOP[v]];\n }\n return -1;\n }\n // note: need to reverse in the second leg if legs are not commutative\n vector> lift(int u, int p, bool includeP = true) const {\n vector> o;\n while (true) {\n if (TOP[u] == TOP[p]) {\n if (ST[p] + (includeP ? 0 : 1) <= ST[u])\n o.emplace_back(ST[p] + (includeP ? 0 : 1), ST[u]);\n break;\n } else o.emplace_back(ST[TOP[u]], ST[u]);\n u = P[TOP[u]];\n }\n return o;\n };\n };\n \n #define INF 1000000000\n #define BLUE 1\n #define RED 0\n struct RedBlueTreee {\n const HLD &H;\n int K, N;\n VI DELTA;\n SegmentTree ST;\n RedBlueTreee(const HLD &H, int K, VI COL) : H(H) , K(K), DELTA(H.adj.size(), -K), ST(H.adj.size()), N(H.adj.size()) {\n dfs(COL);\n ST.create(DELTA);\n }\n void dfs(VI &COL, int u = 0, int p = -1) {\n if (COL[u] != -1) {\n DELTA[H.ST[u]] = (COL[u] == RED ? -1 : 1);\n return;\n }\n for (int v : H.adj[u]) {\n if (v == p) continue;\n dfs(COL, v, u);\n DELTA[H.ST[u]] += DELTA[H.ST[v]] >= 0 ? 1 : -1;\n }\n }\n void setColor(int u, int color) {\n \n auto P = H.lift(u, 0);\n if (color == RED) {\n for (auto p : P) {\n int sz = ST.findOkSuffix(p.second, [](const MinMax &m) { return m.mn >= 0 && m.mx <= 1; });\n if (p == P[0] && sz == 0) break;\n if (sz >= p.second - p.first + 1) {\n ST.update(p.first, p.second, -2);\n } else {\n ST.update(p.second - sz, p.second, -2);\n break;\n }\n }\n } else {\n for (auto p : P) {\n int sz = ST.findOkSuffix(p.second, [](const MinMax &m) { return m.mn >= -2 && m.mx <= -1; });\n if (p == P[0] && sz == 0) break;\n if (sz >= p.second - p.first + 1) {\n ST.update(p.first, p.second, +2);\n } else {\n ST.update(p.second - sz, p.second, +2);\n break;\n }\n }\n }\n }\n int getColor(int u) {\n return ST.query(H.ST[u], H.ST[u]).mn >= 0 ? BLUE : RED;\n }\n };\n struct FatTree {\n const HLD &H;\n VI DELTA;\n VI P;\n VI COL;\n VI SK_CH, BASE_DELTA;\n int K;\n VVI fadj;\n int FAT_SIZE;\n FatTree(const HLD &H, const VI &COL, int K, int FAT_SIZE) :\n FAT_SIZE(FAT_SIZE), H(H), COL(COL), K(K) {\n int N = H.adj.size();\n DELTA = VI(N);\n SK_CH = VI(N);\n BASE_DELTA = VI(N);\n fadj = VVI(N);\n P = VI(N, -1);\n build_dfs();\n computeDelta();\n }\n bool isLeaf(int u) {\n return u != 0 && H.adj[u].size() == 1;\n }\n bool isFat(int u) {\n return u == 0 || (H.adj[u].size() > 1 && H.adj[u].size() - 1) >= FAT_SIZE;\n }\n bool isSkinny(int u) {\n return !isFat(u) && !isLeaf(u);\n }\n void build_dfs(int u = 0, int p = -1, int pf = -1) {\n if (COL[u] != -1) {\n DELTA[u] = (COL[u] == RED ? -1 : 1);\n return;\n }\n if (isFat(u) && pf != -1) {\n fadj[pf].push_back(u);\n }\n BASE_DELTA[u] = 0;\n SK_CH[u] = 0;\n for (int v : H.adj[u]) {\n if (v == p) continue;\n build_dfs(v, u, isFat(u) ? u : pf);\n if (isFat(u)) {\n SK_CH[u] += isSkinny(v);\n if (isLeaf(v)) {\n BASE_DELTA[u] += DELTA[v];\n P[v] = u;\n }\n }\n }\n }\n void computeDelta(int u = 0) {\n DELTA[u] = -K + (K > 0 ? -SK_CH[u] : SK_CH[u]) + BASE_DELTA[u];\n for (int v : fadj[u]) {\n computeDelta(v);\n if (H.P[v] == u) {\n DELTA[u] += (DELTA[v] >= 0 ? +1 : -1);\n }\n }\n }\n void setColor(int u, int color) {\n if (COL[u] == color) return;\n COL[u] = color;\n DELTA[u] *= -1;\n if (P[u] != -1) {\n BASE_DELTA[P[u]] += (color == RED) ? -2 : +2;\n computeDelta();\n }\n }\n void setK(int nk) {\n K = nk;\n computeDelta();\n }\n int getColor(int u) {\n return isSkinny(u) ? (K > 0 ? RED : BLUE) : DELTA[u] >= 0;\n }\n \n };\n \n struct BruteForce {\n VVI adj;\n VI DELTA;\n int K, N;\n BruteForce(VVI adj) : adj(adj), N(adj.size()) {\n DELTA = VI(N);\n }\n void setColor(int u, int c) {\n if (c == RED) DELTA[u] = -1000000000;\n else DELTA[u] = +1000000000;\n }\n void setK(int c) {\n K = c;\n }\n void build(int u = 0, int p = -1) {\n if (u == 0 || adj[u].size() > 1) {\n DELTA[u] = 0;\n }\n for (int v : adj[u]) {\n if (v == p) continue;\n build(v, u);\n DELTA[u] += (DELTA[v] >= K ? +1 : -1);\n }\n }\n int getColor(int u) {\n return DELTA[u] >= K;\n }\n };\n \n #define SMALL 20\n int main(){\n \n int N, K;\n read(N, K);\n HLD HL(N);\n for (int i = 0; i < N - 1; ++i) {\n int u, v;\n read(u, v);\n u--; v--;\n HL.addEdge(u, v);\n }\n HL.build();\n VI COL(N);\n for (int &v : COL) read(v);\n vector TREES;\n FatTree FT(HL, COL, K, SMALL);\n for (int i = -SMALL; i <= SMALL; ++i) {\n TREES.push_back(RedBlueTreee(HL, i, COL));\n }\n int Q;\n read(Q);\n for (int q = 0; q < Q; ++q) {\n int c;\n read(c);\n if (c == 1) {\n int u;\n read(u);\n u--;\n if (abs(K) <= SMALL) {\n cout << TREES[K + SMALL].getColor(u) << endl;\n } else {\n cout << FT.getColor(u) << endl;\n }\n } else if (c == 2) {\n int u, c;\n read(u, c);\n u--;\n for (RedBlueTreee &rb : TREES) rb.setColor(u, c);\n FT.setColor(u, c);\n } else {\n int h;\n read(h);\n K = h;\n FT.setK(K);\n }\n }\n }", "src_uid": "a2869b349dc2d47d96b572397978e77d"} {"source_code": "#include\nusing namespace std;\nlong long n, k, s, ans;\nvector v, vans;\n\nint main(){\n scanf(\"%lld %lld\", &n, &k); v.resize(n);\n for(long long i = 0;i < n;i++){\n scanf(\"%lld\", &v[i]);\n }\n sort(v.begin(), v.end());\n reverse(v.begin(), v.end());\n\n priority_queue pq;\n for(int i = 0;i <= k;i++) pq.push(0);\n\n for(int i = 0;i < v.size();i++){\n long long p = pq.top(); pq.pop();\n ans += p; p += v[i]; pq.push(p);\n }\n printf(\"%lld\", ans);\n}", "src_uid": "53155daf2375e01a3b87fa1c76f1e9a8"} {"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\nusing namespace std;\n\nusing Int = long long;\n\ntemplate ostream &operator<<(ostream &os, const pair &a) { return os << \"(\" << a.first << \", \" << a.second << \")\"; };\ntemplate void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << \" \"; cerr << endl; }\ntemplate bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }\ntemplate bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }\n\n\nusing Double = double;\n\nstruct Pt {\n\tDouble x, y;\n\tPt() {}\n\tPt(Double x, Double y) : x(x), y(y) {}\n\tPt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }\n\tPt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }\n\tPt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }\n\tPt operator/(const Pt &a) const { const Double d2 = a.abs2(); return Pt((x * a.x + y * a.y) / d2, (y * a.x - x * a.y) / d2); }\n\tPt operator+() const { return Pt(+x, +y); }\n\tPt operator-() const { return Pt(-x, -y); }\n\tPt operator*(const Double &k) const { return Pt(x * k, y * k); }\n\tPt operator/(const Double &k) const { return Pt(x / k, y / k); }\n\tfriend Pt operator*(const Double &k, const Pt &a) { return Pt(k * a.x, k * a.y); }\n\tPt &operator+=(const Pt &a) { x += a.x; y += a.y; return *this; }\n\tPt &operator-=(const Pt &a) { x -= a.x; y -= a.y; return *this; }\n\tPt &operator*=(const Pt &a) { return *this = *this * a; }\n\tPt &operator/=(const Pt &a) { return *this = *this / a; }\n\tPt &operator*=(const Double &k) { x *= k; y *= k; return *this; }\n\tPt &operator/=(const Double &k) { x /= k; y /= k; return *this; }\n\tDouble abs() const { return sqrt(x * x + y * y); }\n\tDouble abs2() const { return x * x + y * y; }\n\tDouble arg() const { return atan2(y, x); }\n\tDouble dot(const Pt &a) const { return x * a.x + y * a.y; }\n\tDouble det(const Pt &a) const { return x * a.y - y * a.x; }\n\tfriend ostream &operator<<(ostream &os, const Pt &a) { os << \"(\" << a.x << \", \" << a.y << \")\"; return os; }\n};\nconst Double EPS = 1e-10;\nconst Double INF = 1e+10;\nconst Double PI = acos(-1.0);\ninline int sig(Double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }\ninline Double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }\n\nPt proj(const Pt &a, const Pt &b) {\n\treturn a * a.dot(b) / a.abs2();\n}\nPt perp(const Pt &a, const Pt &b, const Pt &c) {\n\treturn a + proj(b - a, c - a);\n}\nPt refl(const Pt &a, const Pt &b, const Pt &c) {\n\treturn perp(a, b, c) * 2 - c;\n}\n\nint iSP(const Pt &a, const Pt &b, const Pt &c) {\n\tint s = sig((b - a).det(c - a));\n\tif (s != 0) return s;\n\tif (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b\n\tif (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c\n\treturn 0;\n}\n\nPt pLL(const Pt &a, const Pt &b, const Pt &c, const Pt &d) {\n\tconst Pt ab = b - a, cd = d - c;\n\treturn a + ab * (c - a).det(cd) / ab.det(cd);\n}\n\nvector pCL(const Pt &a, double r, const Pt &b, const Pt &c) {\n\tconst Pt h = perp(b, c, a);\n\tconst double d = (h - a).abs();\n\tif (sig(d - r) <= 0) {\n\t\tconst double y = sqrt(max(r * r - d * d, 0.0));\n\t\tconst Pt e = (c - b) / (c - b).abs();\n\t\treturn { h - e * y, h + e * y };\n\t} else {\n\t\treturn {};\n\t}\n}\n\n\npair OLD_pCL(Pt a, double r, Pt b, Pt c) {\nPt h = b + (c - b) * (c - b).dot(a - b) / (c - b).abs2(); // perp(b, c, a)\ndouble d = (h - a).abs();\ndouble y = sqrt(max(r * r - d * d, 0.0));\nPt e = (c - b) / (c - b).abs();\nreturn make_pair(h - e * y, h + e * y);\n}\n//\tcircle (0, r) and triangle 0ab, signed\nDouble mod(Double t) {\n\tfor (; sig(t - PI * 2.0) >= 0; t -= PI * 2.0);\n\tfor (; sig(t) < 0; t += PI * 2.0);\n\treturn t;\n}\nDouble aCT(Double r, Pt a, Pt b) {\n\tint s = sig(a.det(b));\n\tif (s == 0) {\n\t\treturn 0.0;\n\t}\n\tif (s < 0) {\n\t\tswap(a, b);\n\t}\n\tDouble ret;\n\tconst bool iA = (a.abs() <= r);\n\tconst bool iB = (b.abs() <= r);\n\t// const pair pp = pCL(Pt(0, 0), r, a, b);\n\tconst pair pp = OLD_pCL(Pt(0, 0), r, a, b);\n\tif (iA && iB) {\n\t\tret = a.det(b) / 2;\n\t} else if (iA && !iB) {\n\t\tconst Pt p = pp.second;\n\t\t// assert(iSP(a, b, p) == 0);\n\t\tret = a.det(p) / 2 + 0.5 * r * r * mod(b.arg() - p.arg());\n\t} else if (!iA && iB) {\n\t\tconst Pt p = pp.first;\n\t\t// assert(iSP(a, b, p) == 0);\n\t\tret = 0.5 * r * r * mod(p.arg() - a.arg()) + p.det(b) / 2;\n\t} else if (iSP(a, b, pp.first) == 0) {\n\t\t// assert(iSP(a, b, pp.second) == 0);\n\t\tPt p = pp.first, q = pp.second;\n\t\tif ((p - a).dot(b - a) > (q - a).dot(b - a)) {\n\t\t\tswap(p, q);\n\t\t}\n\t\tret = 0.5 * r * r * mod(p.arg() - a.arg()) + p.det(q) / 2 + 0.5 * r * r * mod(b.arg() - q.arg());\n\t} else {\n\t\tassert(iSP(a, b, pp.second) != 0);\n\t\tret = 0.5 * r * r * mod(b.arg() - a.arg());\n\t}\n\treturn s * ret;\n}\n\nvector convexCut(const vector &p, const Pt &a, const Pt &b) {\n\tconst int n = p.size();\n\tvector ret;\n\tfor (int i = 0; i < n; ++i) {\n\t\tif (sig(tri(a, b, p[i])) >= 0) ret.push_back(p[i]);\n\t\tif (sig(tri(a, b, p[i])) * sig(tri(a, b, p[(i + 1) % n])) < 0) ret.push_back(pLL(a, b, p[i], p[(i + 1) % n]));\n\t}\n\tif (ret.size() < 3) return {};\n\tret.push_back(ret.front());\n\treturn ret;\n}\n\n\n//\tinside: +1, boundary: 0, outside: -1\n// int sGP(int n, Pt p[], const Pt &a) {\nint sGP(const vector &p, const Pt &a) {\n const int n = p.size();\n\tint side = -1;\n\t// p[n] = p[0];\n\tfor (int i = 0; i < n; ++i) {\n\t\t// Pt p0 = p[i] - a, p1 = p[i + 1] - a;\n\t\tPt p0 = p[i] - a, p1 = p[(i + 1) % n] - a;\n\t\tif (sig(p0.det(p1)) == 0 && sig(p0.dot(p1)) <= 0) return 0;\n\t\tif (p0.y > p1.y) swap(p0, p1);\n\t\tif (sig(p0.y) <= 0 && 0 < sig(p1.y) && sig(p0.det(p1)) > 0) side = -side;\n\t}\n\treturn side;\n}\n\n\n\nDouble W, H;\nint N;\nvector V;\nvector> P;\n\nint ansLen;\nint ans[1000010];\n\nint main() {\n for (; ~scanf(\"%lf%lf%d\", &W, &H, &N); ) {\n V.resize(N);\n P.resize(N);\n for (int i = 0; i < N; ++i) {\n scanf(\"%d\", &V[i]);\n P[i].resize(V[i]);\n for (int j = 0; j < V[i]; ++j) {\n scanf(\"%lf%lf\", &P[i][j].x, &P[i][j].y);\n }\n }\n \n const Pt RECT[4] = {\n Pt(0, 0),\n Pt(W, 0),\n Pt(W, H),\n Pt(0, H),\n };\n \n vector areas(N);\n for (int i = 0; i < N; ++i) {\n Double area = 0.0;\n for (int j = 0; j < V[i]; ++j) {\n area += P[i][j].det(P[i][(j + 1) % V[i]]);\n }\n if (sig(area) < 0) {\n reverse(P[i].begin() + 1, P[i].end());\n }\n for (int h = 0; h < 4; ++h) {\n P[i] = convexCut(P[i], RECT[h], RECT[(h + 1) % 4]);\n }\n V[i] = P[i].size();\n areas[i] = 0.0;\n for (int j = 0; j < V[i]; ++j) {\n areas[i] += P[i][j].det(P[i][(j + 1) % V[i]]);\n }\n areas[i] /= 2.0;\n// cerr<= 3 && sGP(P[i], o) >= 0) {\n ok = true;\n goto found;\n }\n if (V[i] >= 1 && sig((P[i][0] - o).abs() - r) <= 0) {\n ok = true;\n goto found;\n }\n for (int j = 0; j < V[i]; ++j) {\n if (sig((P[i][(j + 1) % V[i]] - P[i][j]).abs()) > 0) {\n const auto res = pCL(o, r, P[i][j], P[i][(j + 1) % V[i]]);\n for (const auto &p : res) {\n if (iSP(P[i][j], P[i][(j + 1) % V[i]], p) == 0) {\n// cerr<\n#include\n#define MAXN 6\n#define LL __int64\nLL mod;\nstruct Mat{\n int r, c;\n LL m[MAXN][MAXN];\n Mat(){\n r=c=MAXN;\n memset(m,0,sizeof(m));\n }\n Mat operator * (const Mat& a){\n Mat tmp;\n for(int i=0; i>=1;\n }\n LL tmp[6]={sx-1,sy-1,dx,dy,0,1};\n LL tx, ty;\n tx=ty=0;\n for(int i=0; i\n\nusing namespace std;\n#define fast\tios::sync_with_stdio(0);cin.tie(0);\n#define ll \t\tlong long int\n#define INFL 1e18L\n#define INF 1e9\n#define nl \t'\\n'\n#define precision(x)\tfixed << setprecision(x)\nconst ll mod = 1e9 + 7;\n\nll gcd(ll a, ll b) {\n\tif (b == 0) return a;\n\treturn gcd(b , a % b);\n}\n\n\nll powm(ll a, ll b) {\n\tll res = 1;\n\twhile (b) {\n\t\tif (b & 1)\n\t\t\tres = (res * 1LL * a) % mod;\n\t\tb >>= 1LL;\n\t\ta = (a * 1LL * a) % mod;\n\t}\n\treturn res;\n}\nconst int N = 5e5 + 5;\nconst int M = 1005;\n\n//--------------------------------------------------------------------------------------------------------------------------//\n\nvector fri = {\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\"};\nvoid solve() {\n\tstring s; cin >> s;\n\tint ans = 0;\n\tint n = s.size();\n\tfor (auto f : fri) {\n\t\tint len = f.size();\n\t\tif (s.size() < len) continue;\n\t\tfor (int i = 0; i < s.size() - len + 1; i++) {\n\t\t\tbool ok = 1;\n\t\t\tfor (int j = 0; j < len; j++) {\n\t\t\t\tok &= (s[i + j] == f[j]);\n\t\t\t}\n\t\t\tans += ok;\n\t\t}\n\t}\n\tcout << (ans == 1 ? \"YES\" : \"NO\") << nl;\n}\n\nint main() {\n\tfast\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\n\tint tc = 1;\n\t// cin >> tc;\n\n\tint _ = 0;\n\twhile (_++ < tc) {\n\t\tsolve();\n\t}\n\n\treturn 0;\n}\n\n\n\n\n", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"source_code": "#include \nusing namespace std;\ntypedef long long LL;\nchar s[55];\nLL pw[55];\nvector st;\nint main(){\n\tpw[0] = 1;\n\tfor(int i=1;i<=50;i++) pw[i] = pw[i-1]*2;\n\tint n, b = 0;\n\tscanf(\"%d\", &n);\n\tscanf(\"%s\", 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#include\nusing namespace std;\n#define FOR(i,a,b) for(int i=(a),i_##END_=(b);i<=i_##END_;++i)\n#define REP(i,a,b) for(int i=(a),i_##END_=(b);i>=i_##END_;--i)\n#define INF 1e9+7\n#define debug() cerr<<\"Why So Serious?\"< Pa;\nint dfs(int l1,int r1,int l2,int r2,int cur){\n\tif(!l1||!l2)return 0;\n\tif(l1>r1||l2>r2)return 0;\n\tif(l1>l2){\n\t\tswap(l1,l2);\n\t\tswap(r1,r2);\n\t}\n\tif(!l1)return 0;\n\tif(r1>=r2)return r2-l2+1;\n\tif(l1==l2)return r1-l1+1;\n\tint len=(1<len)return dfs(l1,r1,l2-len,r2-len,cur);\n\tif(r1\n#include \n#include \n#include \nusing namespace std;\n\nint N;\nstruct Card {\n char type;\n int r, b;\n};\nvector ca;\n#define MN 16\nint cc[1<> N;\n ca.resize(N);\n int needR = 0, needB = 0;\n for(int i=0;i> ca[i].type >> ca[i].r >> ca[i].b;\n \n needR += max(ca[i].r-N, 0);\n ca[i].r = min(ca[i].r, N);\n \n needB += max(ca[i].b-N, 0);\n ca[i].b = min(ca[i].b, N);\n }\n memset(cc, -1 ,sizeof(cc));\n int ans = max(needR, needB)+N;\n if(needR < needB) {\n ans += solve(0, 'R', min(N*N, needB-needR));\n } else {\n ans += solve(0, 'B', min(N*N, needR-needB));\n }\n cout << ans;\n return 0;\n}", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969"} {"source_code": "#include\nusing namespace std;\n\n\n\nint main()\n{\n\tint n,k;\n\tint mi = 1,r;\n scanf(\"%d%d\",&n,&k);\n\tif(k == 0)\n return 0 * printf(\"0 0\\n\");\n\n\tif(n == k)\n mi=0;\n\tif((n+2)/3 <= k)\n r=n-k;\n\telse\n r=2*k;\n\tcout<\nusing namespace std;\n\nint main() {\n int n;\n cin >> n;\n string s;\n cin >> s;\n if (s[0] == 'S' && s[s.size()-1] == 'F') {\n cout << \"YES\";\n }\n else {\n cout << \"NO\";\n }\n}", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"source_code": "#include \n#include \n#include \nusing namespace std;\nvoid main(){\n string str1,str2;\n cin>>str1>>str2;\n char char1,char2;\n for(int i=0;i96) char1-=32;\n if(char2>96) char2-=32;\n if(char1>char2){\n cout<<1;\n return;\n }\n if(char1\n#include\n#include\n#include\nusing namespace std;\nbool arr[10];\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\tint a, b;\n\tcin >> a >> b;\n\tint k = b;\n\tint i = 1;\n\twhile (true)\n\t{\n\t\t\n\t\tk -= i;\n\t\ti++;\n\t\tif (i == a+1)\n\t\t\ti = 1;\n\t\t\n\t\tif (k-i == 0)\n\t\t{\n\t\t\tcout << 0 << endl;\n\t\t\tbreak;\n\t\t}\n\t\telse if (k-i<0)\n\t\t{\n\t\t\tcout << k << endl;\n\t\t\tbreak;\n\t\t}\n\n\t}\n\t//system(\"pause\");\n\treturn 0;\n\t\n}", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"source_code": "#include\n\nusing namespace std;\n\nint main () {\n\tlong long n, m, k;\n\tcin >>n>>m>>k;\n\tif(k > n+m-2) {cout<<-1; exit(0); }\n\tif(m > k) {\n\t\tcout< k) {\n\t\tcout<\nusing namespace std;\n\n#include\n#include\nusing namespace __gnu_pbds;\ntemplate \nusing ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>;\n\n\n/*------- Constants---- */\n\n#define Long long long\n#define ull unsigned long long\n#define mod 1000000007\n#define MEMSET_INF 63\n#define MEM_VAL 1061109567\n#define forn(i,n) for( int i=0 ; i < n ; i++ )\n#define mp(i,j) make_pair(i,j)\n#define lop(i,a,b) for( int i = (a) ; i < (b) ; i++)\n#define pb(a) push_back((a))\n#define SZ(a) (int) a.size()\n#define all(x) (x).begin(),(x).end()\n#define gc getchar_unlocked\n#define PI acos(-1.0)\n#define INF 1<<29\n#define EPS 1e-9\n#define Fr first\n#define Sc second\n#define Sz size()\n#define lc ((n)<<1)\n#define rc ((n)<<1|1)\n#define db(x) cout << #x << \" -> \" << x << endl;\n#define Di(n) int n;si(n)\n#define Dii(a,b) int a,b;si(a);si(b)\n#define Diii(a,b,c) int a,b,c;si(a);si(b);si(c)\n#define Si(n) si(n)\n#define Sii(a,b) si(a);si(b)\n#define Siii(a,b,c) si(a);si(b);si(c)\n#define min(a,b) ((a)>(b) ? (b) : (a) )\n#define max(a,b) ((a)>(b) ? (a):(b))\n/*---- short Cuts ------- */\n#define ms(ara_name,value) memset(ara_name,value,sizeof(ara_name))\ntypedef pair ii;\ntypedef vector vi ;\ntypedef vector vl;\n/*------ template functions ------ */\n#ifndef getchar_unlocked\n#define getchar_unlocked getchar\n#endif\ntemplate inline void si(T &x){register int c = gc();x = 0;int neg = 0;for(;((c<48 | c>57) && c != '-');c = gc());\n if(c=='-') {neg=1;c=gc();}for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}\nLong bigmod(Long p,Long e,Long M){Long ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;} return ret;}\nLong gcd(Long a,Long b){if(b==0)return a;return gcd(b,a%b);}\nLong modinverse(Long a,Long M){return bigmod(a,M-2,M);}\nvoid io(){freopen(\"/Users/MyMac/Desktop/in.txt\",\"r\",stdin);}\n\n/*************************** END OF TEMPLATE ****************************/\n\nconst int N = 50;\nLong s,x;\nLong dp[N][2];\nbool get(Long x,int pos) {return x & (1LL << pos);}\nLong solve(int ind, int carry)\n{\n if(ind >= N ) {\n if(carry == 0) return 1;\n return 0;\n }\n if(dp[ind][carry] !=-1) return dp[ind][carry];\n Long res = 0;\n for(int i= 0; i < 2; i ++ ) {\n for(int j = 0; j < 2; j ++) {\n if(i^j != get(x,ind)) continue;\n int sum = carry + i + j;\n int nxt = sum / 2;\n int pr = sum % 2;\n if(get(s,ind) != pr ) continue;\n res += solve(ind+1,nxt);\n }\n }\n return dp[ind][carry] = res;\n}\nint main()\n{\n //freopen(\"in.txt\",\"r\",stdin);\n cin >> s >> x;\n int f = 0;\n if(s==x) f=2;\n ms(dp,-1);\n cout << solve(0,0) - f << endl;\n return 0;\n}\n", "src_uid": "18410980789b14c128dd6adfa501aea5"} {"source_code": "// In the name of God\n#include\n#define int long long\nusing namespace std;\n\nint n, k;\n\nint C(int n, int k) {\n\tint x = 1, y = 1;\n\tfor (int i = n; i > n - k; i--)\n\t\tx *= i;\n\tfor (int i = 1; i <= k; i++)\n\t\ty *= i;\n\treturn x / y;\n}\n\nvoid solve() {\n\tint res = 1;\n\tif (k > 1)\n\t\tres += C(n, 2);\n\tif (k > 2)\n\t\tres += C(n, 3) * 2;\n\tif (k > 3)\n\t\tres += C(n, 4) * 9;\n\tcout << res << endl;\n}\n\nint32_t main() {\n\tcin >> n >> k;\t\n\tsolve();\n\treturn 0;\n}\n", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"} {"source_code": "#include \nusing namespace std;\n\n#define pb push_back\n#define ll long long int\n#define mpi map\n#define vi vector\n#define si set\n#define pii pair\n#define vpi vector\n#define vs vector\n#define pri priority_queue\n#define mp make_pair\n#define ff first\n#define ss second\n#define mod 1000000007\n#define For(i, n) for (int i = 0; i < n; i++)\n#define Ford(i, a, b) for (int i = a; i >= b; i--)\n#define Rep(i, x, y) for (int i = x; i <= y; i++)\n#define mem(a, b) memset(a, b, sizeof(a))\n#define fastio \\\n ios_base::sync_with_stdio(0); \\\n cin.tie(0); \\\n cout.tie(0)\n\ndouble tick()\n{\n static clock_t oldt, newt = clock();\n double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;\n oldt = newt;\n return diff;\n}\n\nint getRad(string s, int rad)\n{\n int val = 0;\n For(i, s.size())\n {\n char ch = s[i];\n int k = (ch <= '9' ? ch - '0' : ch - 'A' + 10);\n if (k >= rad)\n return -1;\n val = val * rad + k;\n }\n return val;\n}\n\nbool check(string ls, string rs, int rad)\n{\n int h = getRad(ls, rad);\n int m = getRad(rs, rad);\n return (0 <= h && h < 24 && 0 <= m && m < 60);\n}\nint main()\n{\n string s;\n cin >> s;\n int in = s.find(\":\");\n int res = 0;\n string ls = s.substr(0, in);\n string rs = s.substr(in + 1);\n\n if (check(ls, rs, 64))\n {\n cout << -1 << endl;\n return 0;\n }\n for (int i = 2; i < 64; i++)\n {\n if (check(ls, rs, i))\n {\n if (res != 0)\n cout << \" \";\n cout << i;\n res++;\n }\n }\n if (res == 0)\n cout << 0 << endl;\n cerr << \"execution time is: \" << tick() << \"\\n\";\n}\n", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293"} {"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\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 pi acos(-1.0)\r\n#define inf 0x3f3f3f3f\r\n#define INF 0x3f3f3f3f3f3f3f3f\r\nconst int maxdouble = 0x7f;//127\r\nconst int mindouble = 0xfe;//254\r\nconst ll mod = 1e9 + 7;\r\n\r\n//priority_queue\r\n\r\ntemplate inline void read(T &x)\r\n{x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}\r\nwhile (isdigit(ch)){x = x * 10 + (ch ^ 48); ch = getchar();} x *= f;}\r\ntemplate inline void write(T x) //快写\r\n{if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0');}\r\n/*\r\nint prime(ll n)//1不是,需要特判下\r\n{\r\n if(n==0||n==1)\r\n return 0;\r\n for(ll i=2; i*i<=n; i++)\r\n {\r\n if(n % i == 0)\r\n return 0;\r\n }\r\n return 1;\r\n}\r\n */\r\nll gcd(ll a,ll b)\r\n{\r\n return b==0 ? a : gcd(b, a%b);\r\n}\r\nll lcm(ll a, ll b)\r\n{\r\n return a*b/gcd(a, b);\r\n}\r\n\r\ninline ll check(ll x) //s*(s+1)=x\r\n{\r\n ll s=sqrt(x*2)+(1e-12);\r\n if((s*(s+1)/2)==x)\r\n return s;\r\n return -1;\r\n}\r\n/*\r\nvoid getnext()\r\n{\r\n int i = 0, j = -1;\r\n nex[0] = -1;\r\n while(i>= 1;\r\n }\r\n return ret;\r\n}\r\nll ksm1(ll a, ll b, ll p)\r\n{\r\n ll ret = 1;\r\n while (b)\r\n {\r\n if (b & 1)\r\n ret = ret * a % p;\r\n a = a * a % p;\r\n b >>= 1;\r\n }\r\n return ret;\r\n}\r\nll multi(ll a, ll x, ll MOD)\r\n{\r\n ll ans = 0;\r\n while(x)\r\n {\r\n if(x & 1)\r\n ans = (ans + a) % MOD;\r\n a = (a + a) % MOD;\r\n x >>= 1;\r\n }\r\n return ans;\r\n}\r\ninline ll mul(ll a,ll b,ll mod)\r\n{\r\n return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;\r\n}\r\n\r\nll exgcd(ll a, ll b, ll &x, ll &y)//返回的r是a, b的最大公约数\r\n{\r\n if(b==0)\r\n return x = 1, y = 0, a;\r\n ll r = exgcd(b, a%b, x, y);\r\n tie(x, y) = make_tuple(y, x-(a/b)*y);\r\n return r;\r\n}\r\n/*\r\n freopen(\"triangle.in\", \"r\", stdin);\r\n freopen(\"triangle.out\", \"w\", stdout);\r\n ios::sync_with_stdio(false);\r\n cin.tie(0);\r\n */\r\nint lowbit(int x) { return log2((x)&(-x)); }\r\n#define endl '\\n'\r\ntypedef pair pii;\r\nconst double eps = 1e-6;\r\n\r\nconst int maxn = 2e5 + 5;\r\nll fac[maxn], inv[maxn];\r\nll _pow(ll a, ll b){\r\n ll ans = 1;\r\n while(b){\r\n if(b & 1) ans = ans * a % mod;\r\n a = a * a % mod;\r\n b >>= 1;\r\n }\r\n return ans;\r\n}\r\nvoid init(){ //预处理阶乘数和阶乘数的逆元\r\n fac[0] = 1;\r\n for(int i = 1; i < maxn; i ++)\r\n fac[i] = fac[i - 1] * i % mod;\r\n inv[maxn - 1] = _pow(fac[maxn - 1], mod - 2);\r\n for(int i = maxn - 2; i >= 0; i --)\r\n inv[i] = inv[i + 1] * (i + 1) % mod;\r\n}\r\nll c(ll a, ll b){ //求组合数\r\n if(a < b) return 0;\r\n return fac[a] * inv[b] % mod * inv[a - b] % mod;\r\n}\r\n\r\nint main(void)\r\n{\r\n init();\r\n ll n, k;\r\n scanf(\"%lld%lld\", &n, &k);\r\n ll ans = 0;\r\n for(ll i=0; i<=min(n, k); i++)\r\n ans = (ans+c(n, i))%mod;\r\n printf(\"%lld\\n\", ans);\r\n \r\n return 0;\r\n}\r\n", "src_uid": "dc7b887afcc2e95c4e90619ceda63071"} {"source_code": "#include \nusing namespace std;\n\nmain()\n{\n int a, b, x;\n \n std::cin>>a>>b;\n \n x = a;\n //a = a/b + (a - a/b*b);\n //std::cout<= b)\n {\n \n x += a/b;\n a = a/b + (a - a/b*b);\n //std::cout<\n#define vi vector\n#define pb push_back\n#define rev reverse\n#define ll long long\n#define all(x) (x).begin(), (x).end()\n#define allrev(x) (x).rbegin(), (x).rend()\n#define lf(x, n) (x)[(n) - 1] - (x)[0]\n#define inf 1e18\n\nusing namespace std;\n\nlong long bin_pow(long long a, long long b)\n{\n long long res = 1;\n while (b)\n {\n if (b & 1)\n res *= a;\n a *= a;\n b >>= 1;\n }\n return res;\n}\n\nint lg(long long a, long long b)\n{\n int ans = 0;\n while (a > 1)\n {\n ans++;\n a /= b;\n }\n return ans;\n}\n\nint main()\n{\n vector < string > v(2);\n cin >> v[0];\n cin >> v[1];\n int ans = 0;\n for (int i = 0; i < v[0].size(); i++)\n {\n if (v[0][i] == '0' && v[1][i] == '0' && v[0][i - 1] == '0')\n {\n v[0][i] = v[1][i] = v[0][i - 1] = 'X';\n ans++;\n }\n if (v[0][i] == '0' && v[1][i] == '0' && v[1][i - 1] == '0')\n {\n v[0][i] = v[1][i] = v[1][i - 1] = 'X';\n ans++;\n }\n if (v[0][i] == '0' && v[1][i] == '0' && v[1][i + 1] == '0')\n {\n v[0][i] = v[1][i] = v[1][i + 1] = 'X';\n ans++;\n }\n if (v[0][i] == '0' && v[1][i] == '0' && v[0][i + 1] == '0')\n {\n v[0][i] = v[1][i] = v[0][i + 1] = 'X';\n ans++;\n }\n }\n cout << ans;\n return 0;\n}\n", "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"source_code": " #include \n using namespace std;\n typedef long long ll;\n \n \n int main()\n {\n string s;\n cin>>s;\n string min=\"\";\n min+=s[4];\n min+=s[3];\n int minute=stoi(min);\n min=s[3];\n min+=s[4];\n int minute2=stoi(min);\n min=s[0];\n min+=s[1];\n int hour=stoi(min);\n int count=0;\n while(hour!=minute)\n {\n minute2++;\n count++;\n if(minute2==60)\n hour++,minute2=0;\n if(hour==24)\n hour=0;\n int i=10;\n minute=0;\n int min=minute2;\n while(minute2)\n {\n minute+=(minute2%10)*i;\n i/=10;\n minute2/=10;\n }\n minute2=min;\n }\n cout<\nusing namespace std;\nchar a[10], b[10];\nint numa[10];\nint main()\n{\n\tcin >> a >> b;\n\tif (strlen(a) != strlen(b)) cout << \"WRONG_ANSWER\" << endl;\n\telse if (a[0] == b[0] && a[0] == '0') cout << \"OK\" << endl;\n\telse\n\t{\n\t\tint flag = true;\n\t\tfor (int i = 0; i < strlen(a); ++i) numa[i] = a[i]-'0';\n\t\tsort(numa, numa+strlen(a));\n\t\t// for (int i = 0; i < strlen(a); ++i) cout << numa[i];\n\t\tint num = 0;\n\t\twhile (numa[num] == 0) num++;\n\t\tswap(numa[num], numa[0]);\n\t\tfor (int i = 0; i < strlen(a); ++i) \n\t\t{\n\t\t\tif (numa[i]+'0' != b[i]) {flag = false; break;}\n\t\t}\n\t\tif (flag) cout << \"OK\" << endl;\n\t\telse cout << \"WRONG_ANSWER\" << endl; \n\t}\n\treturn 0;\n}", "src_uid": "d1e381b72a6c09a0723cfe72c0917372"} {"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\n#define pb push_back\n#define mp make_pair\n\nusing namespace std;\n\nconst int N = (int)(5e3);\n\ntypedef long long ll;\ntypedef long double ld;\n\nint n, f[N];\n\nbool check(int k)\n{\n for (int i = 1; i <= n; i++)\n {\n int gg = i, g = i;\n \tfor (int j = 0; j < 2 * k; j++)\n \t{\n \t gg = f[gg];\n \t if (j < k)\n \t \tg = f[g];\n \t}\n \tif (g != gg)\n \t\treturn false;\n }\n return true;\n}\n\nint st[N], k;\nbool was[N];\nbool inc[N];\nint mxp = 0;\n\nint dfs(int v)\n{\n if (was[v])\n {\n for (int j = k - 1; j >= 0; j--)\n {\n \tinc[st[j]] = true;\n \tif (st[j] == v)\n \t{\n \t\tmxp = max(j, mxp);\n \t\treturn (k - j);\n }\n }\n }\n was[v] = true;\n st[k++] = v;\n return dfs(f[v]);\n}\n\nll gcd(ll a, ll b)\n{\n if (a == 0 || b == 0)\n \treturn a + b;\n return gcd(b, a % b);\n}\n\nint main()\n{\n //freopen(\"x.in\", \"r\", stdin);\n //freopen(\"x.out\", \"w\", stdout);\n \n scanf(\"%d\", &n);\n for (int i = 1; i <= n; i++)\n scanf(\"%d\", &f[i]);\n\n ll ans = 1;\n for (int i = 1; i <= n; i++)\n {\n k = 0;\n if (!was[i])\n {\n int s = dfs(i);\n ll g = gcd(ans, (ll)s);\n ans = s * ans / g;\n }\n }\n \n if (mxp == 0)\n cout << ans << endl;\n else\n cout << ((mxp + ans - 1) / ans) * ans << endl;\n\n return 0;\n}", "src_uid": "1daa784c0eb1cde514e4319da07c8d00"} {"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#define FOR(i,n) for(int i=0,_n=n;i<_n;i++)\n#define FORD(i,n) for(int i=n;i>=0;i--)\n#define FORR(i,s,n) for(int i=s,_n=n;i<_n;i++)\n#define FORRD(i,n,s) for(int i=n,_s=s;i>=_s;i--)\n#define mp make_pair\n#define pb push_back\n#define pii pair\n#define pli pair\n#define vi vector\n#define fs first\n#define sec second\n\n#define maxn 100000\nusing namespace std;\ntypedef long long ll;\n\nint n[3];\nvi tree[3][maxn];\nll S[3][maxn],sts[3][maxn],mxx[3],sum[3];\n\n\nll fsubtree(int x,int y,int t){\n\tsts[t][x] = 1;\n\tFOR(i,tree[t][x].size())\n\t\tif(tree[t][x][i] != y)\n\t\t\tsts[t][x] += fsubtree(tree[t][x][i],x,t);\n\treturn sts[t][x];\n}\n\nll fsum(int x,int y,int t){\n\tS[t][x] = 0LL;\n\tFOR(i,tree[t][x].size())\n\t\tif(tree[t][x][i] != y)\n\t\t\tS[t][x] += fsum(tree[t][x][i],x,t);\n\treturn S[t][x] + sts[t][x];\t\n}\n\nvoid fsum2(int x,int y,int t,ll up,ll upcnt){\n\tFOR(i,tree[t][x].size())\n\t\tif(tree[t][x][i] != y){\n\t\t\tll toadd = up + S[t][x] - S[t][tree[t][x][i]] - sts[t][tree[t][x][i]];\n\t\t\ttoadd += sts[t][x] - sts[t][tree[t][x][i]] + upcnt;\n\t\t\tfsum2(tree[t][x][i],x,t,toadd,upcnt + sts[t][x] - sts[t][tree[t][x][i]]);\n\t\t}\n\tS[t][x] += up;\n\tmxx[t] = max(mxx[t],S[t][x]);\n\tsum[t] += S[t][x];\n}\n\nll ANS = 0LL;\n\nvoid funder(int x,int y,int t,int oth,ll d){\n\t// calc value\n\tll val = n[t] * mxx[(t + 1) % 3] + n[t] * n[(t + 1) % 3] + n[(t + 1) % 3] * S[t][oth];\n\tval += n[t] * mxx[(t + 2) % 3] + n[t] * n[(t + 2) % 3] + n[(t + 2) % 3] * S[t][x];\n\tval += n[(t + 1) % 3] * mxx[(t + 2) % 3] + n[(t + 1) % 3] * n[(t + 2) % 3] * (d + 2LL);\n\tval += n[(t + 2) % 3] * mxx[(t + 1) % 3];\n\t\n\tANS = max(ANS,val);\n\tFOR(i,tree[t][x].size())\n\t\tif(tree[t][x][i] != y)\n\t\t\tfunder(tree[t][x][i],x,t,oth,d + 1);\n}\nvoid fmain(int x,int y,int t){ // main pair\n\tfunder(x,-1,t,x,0);\n\tFOR(i,tree[t][x].size())\n\t\tif(tree[t][x][i] != y)\n\t\t\tfmain(tree[t][x][i],x,t);\n}\n\nint main(){\n\tFOR(i,3) cin>>n[i];\n\tFOR(i,3)\n\t\tFOR(j,n[i] - 1){\n\t\t\tint u,v;\n\t\t\tcin>>u>>v;\n\t\t\tu--;v--;\n\t\t\ttree[i][u].pb(v);\n\t\t\ttree[i][v].pb(u);\n\t\t}\n\tFOR(i,3){\n\t\tfsubtree(0,-1,i);\n\t\tfsum(0,-1,i);\n\t\tfsum2(0,-1,i,0,0);\n\t}\n\t\n\tFOR(i,3)\n\t\tfmain(0,-1,i);\n\tcout<\r\n#include\r\n#include\r\nusing namespace std;\r\nconst int mxc=27,mxx=260;\r\nconst int inf=1e9;\r\nint d[55][65][525][2];\r\nint n;\r\nchar st[55];\r\nint solve(int pos,int c,int x,int op)\r\n{\r\n\tif (c<-mxc||c>mxc||x<-mxx||x>mxx) return inf;\r\n\tif (pos>n) return c?inf:0;\r\n\tif (d[pos][c+mxc][x+mxx][op]!=-1) return d[pos][c+mxc][x+mxx][op];\r\n\treturn d[pos][c+mxc][x+mxx][op]=min(solve(pos,c,x+(op?-1:1),op)+n-pos+1,min(solve(pos+1,c*10+st[pos]-'0'+x,x,1),solve(pos+1,c*10+st[pos]-'0'+x,x,0)));\r\n}\r\nint main()\r\n{\r\n\tmemset(d,-1,sizeof(d));\r\n\tscanf(\"%s\",st+1);\r\n\tst[0]='0';\r\n\tn=strlen(st+1);\r\n\tprintf(\"%d\\n\",min(solve(0,0,0,1),solve(0,0,0,0)));\r\n}\r\n\r\n", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907"} {"source_code": "\n#include \n\nusing namespace std;\n\ntypedef long long int LL;\nconst LL MOD(1000000007LL);\nconst int Max_N(1050);\n\ninline LL Mult(const LL &a, const LL &b)\n{\n\treturn a * b % MOD;\n}\n\ninline void update(LL &a, const LL &b)\n{\n\t(a += b) %= MOD;\n}\n\nint N, K;\nLL Fac[Max_N], C[Max_N][Max_N], F[Max_N][Max_N][2][2], Ans[Max_N];\n\nint main()\n{\n\tscanf(\"%d%d\", &N, &K);\n\tFac[0] = C[0][0] = 1LL;\n\tfor (int i = 1;i <= N;++i)\n\t{\n\t\tFac[i] = Mult(Fac[i - 1], i * 1LL);\n\t\tC[i][0] = C[i][i] = 1LL;\n\t\tfor (int j = 1;j < i;++j)\n\t\t\tC[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;\n\t}\n\tF[0][0][1][0] = 1LL;\n\tfor (int i = 1;i <= N;++i)\n\t\tfor (int j = 0;j <= i - 1;++j)\n\t\t\tfor (int c0 = 0;c0 <= 1;++c0)\n\t\t\t\tfor (int c1 = 0;c1 <= 1;++c1)\n\t\t\t\t{\n\t\t\t\t\tupdate(F[i][j][c1][0], F[i - 1][j][c0][c1]);\n\t\t\t\t\tif (!c0)\n\t\t\t\t\t\tupdate(F[i][j + 1][c1][0], F[i - 1][j][c0][c1]);\n\t\t\t\t\tif (i + 1 <= N)\n\t\t\t\t\t\tupdate(F[i][j + 1][c1][1], F[i - 1][j][c0][c1]);\n\t\t\t\t}\n\tfor (int k = 0;k <= N;++k)\n\t{\n\t\tfor (int c0 = 0;c0 <= 1;++c0)\n\t\t\tfor (int c1 = 0;c1 <= 1;++c1)\n\t\t\t\tupdate(Ans[k], F[N][k][c0][c1]);\n\t\tAns[k] = Mult(Ans[k], Fac[N - k]);\n\t}\n\tfor (int i = N;i >= K;--i)\n\t\tfor (int j = i + 1;j <= N;++j)\n\t\t\tAns[i] = Ans[i] - Mult(C[j][i], Ans[j]), Ans[i] = (Ans[i] % MOD + MOD) % MOD;\n\tprintf(\"%I64d\", Ans[K]);\n\treturn 0;\n}", "src_uid": "1243e98fe2ebd6e6d1de851984b96079"} {"source_code": "#include\nusing namespace std;\n \nconst int N = 10000010;\n \nvector get_divs(long long n) {\n vector ret;\n //d不能为n, 所以 m / d 不能为1, 所以1不用加入\n ret.push_back(n);\n for (long long i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n ret.push_back(i);\n if (n / i != i ) {\n ret.push_back(n/i);\n }\n }\n }\n sort (ret.begin(), ret.end());\n return ret;\n}\n \nvector get_primes(long long n) {\n vector ret;\n for (long long i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n ret.push_back(i);\n while (n % i == 0) n /= i;\n }\n }\n if (n > 1) ret.push_back(n);\n return ret;\n}\n \nlong long euler(long long n, vector &p) {\n long long ret = n;\n for (long long x : p) {\n if (ret % x == 0) {\n ret = ret / x * (x - 1);\n }\n }\n return ret;\n}\n/*\nlong long mul(long long a, long long b, long long md) {\n double bei = 1.0 * a * b / md;\n bei = floor(bei);\n long long rem = 1.0 * a * b - bei * md;\n return rem;\n} */\nlong long mul(long long a, long long b, long long md) {\n long long m = ( (long double)(a) * b / md);\n long long rem = a * b - m * md;\n while(rem < 0)\n rem += md;\n while(rem >= md)\n rem -= md;\n return rem;\n}\n\n//这样要TLE\n/*\nlong long mul(long long a, long long b, long long md) {\n long long ret = 0;\n while (b) {\n if (b & 1) {\n ret = (ret + a) % md;\n }\n b >>= 1;\n a = (a + a) % md;\n }\n return ret;\n}*/\nlong long pow_md(long long a, long long b, long long md) {\n long long ret = 1;\n while (b) {\n if (b & 1) ret = mul(ret, a, md);\n b >>= 1;\n a = mul(a,a,md);\n }\n return ret;\n}\n \nvoid solve(long long m, long long x) {\n vector divs = get_divs(m);\n vector pris_m = get_primes(m);\n long long eul = euler(m, pris_m);\n\n vector pris_phim = get_primes(eul);\n //phi(m/d)的所有素因子一定是phi(m)的子集\n \n \n long long ret = 1;\n for (long long d: divs) {//相当于直接枚举m/d 20000\n long long f = euler(d, pris_m);\n //x ^ k % (m / d) = 1\n //k 是 phi(m/d)的因子\n long long k = f;\n for (long long p: pris_phim) {// 20\n //x要记得先取模, 坑\n while (k % p == 0 && pow_md(x % d, k / p, d) == 1) {//30 * 30\n k /= p;\n }\n }\n ret += f / k;\n }\n cout << ret << endl;\n}\n \nint main() {\n // cout << mul(2, 6, 5);\n long long m, x;\n cin >> m >> x;\n solve(m, x);\n return 0;\n}\n", "src_uid": "c2dd6de750812d6213c770b3587d8fcb"} {"source_code": "#include \nusing namespace std;\n\ntypedef long long ll;\nconst ll INF = (ll)1e18;\n\nll f, T, t0;\nll a1, t1, p1, a2, t2, p2;\n\nint main() {\n cin >> f >> T >> t0;\n cin >> a1 >> t1 >> p1;\n cin >> a2 >> t2 >> p2;\n\n ll res = INF;\n for(int swapped = 0; swapped < 2; swapped++) {\n if(swapped) {\n swap(a1, a2);\n swap(t1, t2);\n swap(p1, p2);\n }\n for(ll c1 = 0; c1 * a1 <= f + a1; c1++) {\n ll rem_f = max(0LL, f - c1 * a1);\n if(t1 * min(a1 * c1, f) + min(t2, t0) * rem_f > T) continue;\n if(t2 >= t0) {\n res = min(res, c1 * p1);\n }\n else {\n res = min(res, c1 * p1 + (rem_f + a2 - 1) / a2 * p2);\n ll over_t = max(0LL, rem_f * t0 + t1 * (f - rem_f) - T);\n ll mn_c2 = (over_t + a2 * (t0 - t2) - 1) / ((t0 - t2) * a2);\n if(mn_c2 * a2 <= rem_f) {\n res = min(res, c1 * p1 + mn_c2 * p2);\n }\n }\n }\n }\n cout << (res == INF ? -1 : res) << '\\n';\n}", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1"} {"source_code": "#include\nusing namespace std;\n#define ll long long\n#define llu unsigned long long\n#define ld double\n#define llu unsigned long long\n#define rep(i,x,y) for(ll i=x;i=y;--i)\n#define pi acos(-1)\n#define mk make_pair\n#define pa pair\n#define lf else if\n#define max(x,y) ((x)<(y)?(y):(x))\n#define min(x,y) ((x)<(y)?(x):(y))\n#define sqr(x) ((x)*(x))\n#define abs(x) ((x)>0?(x):-(x))\n#define Mul(x,y) (x=1LL*(x)*(y)%mod)\n#define Add(x,y) (x=(x+(y))%mod)\n#define Max(x,y) ((x)=((x)<(y)?(y):(x)))\n#define Min(x,y) ((x)=((x)>(y)?(y):(x)))\n#define E(x) return writeln(x),0\n#define p(x) printf(\"~%d~\\n\",x)\n#define pp(x,y) printf(\"~~%d %d~~\\n\",x,y)\n#define ppp(x,y,z) printf(\"~~~%d %d %d~~~\\n\",x,y,z)\n#define pppp(a,b,c,d)\tprintf(\"~~~%d %d %d %d\\n\",a,b,c,d)\n#define f_in(x) freopen(x\".in\",\"r\",stdin)\n#define f_out(x) freopen(x\".out\",\"w\",stdout)\n#define open(x) f_in(x),f_out(x)\n#define fi first\n#define se second\ntypedef complex E;\nnamespace SHENZHEBEI{\n#ifdef LOCAL\n struct _{_(){freopen(\"cf.in\",\"r\",stdin);}}_;\n#endif\n#define NEG 1\n inline char gc(){ return getchar(); }\n#if NEG\n inline ll read(){ ll x=0,f=1; char ch=gc(); for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1; for (;isdigit(ch);ch=gc()) x=x*10-48+ch; return x*f; }\n inline void write(ll x){ if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0'); }\n#else\n inline ll read(){ ll x=0; char ch=gc(); for (;!isdigit(ch);ch=gc()); for (;isdigit(ch);ch=gc()) x=x*10-48+ch; return x; }\n inline void write(ll x){ if (x>=10) write(x/10); putchar(x%10+'0'); }\n#endif\n inline char readchar(){ char ch=gc(); for(;isspace(ch);ch=gc()); return ch; }\n inline ll readstr(char *s){ char ch=gc(); int cur=0; for(;isspace(ch);ch=gc()); for(;!isspace(ch);ch=gc()) s[cur++]=ch; s[cur]='\\0'; return cur; }\n inline void writeln(ll x){ write(x); puts(\"\"); }\n inline ld getreal(){ static ld lbc; scanf(\"%lf\",&lbc); return lbc; }\n}using namespace SHENZHEBEI;\nconst ll mod=1e9+7,N=200010;\nmapg;\nvectora[1010];\nll ans,n,m,vis[1010],SIZE[1010];\nll id(ll x){if (g.find(x)==g.end()){ll u=g.size();g[x]=u;}return g[x];}\nvoid gao(ll x){\tfor(;x;x>>=1)id(x);\t}\nll Size(ll x){\n\tll L=x,R=x,ans=0;\n\tfor(;L<=n;L=L<<1,R=R<<1|1)ans+=min(n,R)-L+1;\n\treturn ans;\n}\nvoid dfs(ll x,ll bb){\n\tvis[x]=1;Add(ans,bb*SIZE[x]);\n\tfor(ll i:a[x])if (!vis[i])dfs(i,bb);\n\tvis[x]=0;\n}\nint main(){\n\tn=read(),m=read();\n\tFor(i,1,m){\n\t\tll x=read(),y=read();\n\t\tgao(x),gao(y);\n\t\ta[g[x]].push_back(g[y]);\n\t\ta[g[y]].push_back(g[x]);\n\t}gao(1);\n\tfor(pa I:g){\n\t\tSIZE[I.se]=Size(I.fi);\n\t\tif (g.count(I.fi*2))\tSIZE[I.se]-=Size(I.fi*2);\n\t\tif (g.count(I.fi*2+1))\tSIZE[I.se]-=Size(I.fi*2+1);\n\t\tif (I.fi>1)\t\t\t\ta[g[I.fi/2]].push_back(g[I.fi]),\n\t\t\t\t\t\t\t\ta[g[I.fi]].push_back(g[I.fi/2]);\n\t}for(ll i=0;i\nusing namespace std;\nlong double PI = 3.14159265359;\nlong double DEL = 1e-10;\nint mod = 1000000007;\n\n#define ftt cin>>t;for(int tt=1;tt<=t;++tt)\n#define all(a) a.begin() , a.end()\n#define sqr(a) ((a) * (a))\n#define double long double\n#define dbg cout<<\"\\nhi\\n\"\n#define int long long\n#define nl cout<<\"\\n\"\n#define pb push_back\n#define sp <<\" \"<<\n#define ss second\n#define ff first\n\nint fpow(int x, int n)\n{\n int res = 1;\n while(n)\n {\n if(n&1)res = res * x % mod;\n x = x * x % mod;\n n>>=1;\n }\n return res;\n}\nint gcd(int a,int b)\n{\n if(b == 0)return a;\n return gcd(b,a % b);\n}\nvoid sieve(int n)\n{\n bool prime[1000006];\n memset(prime, true, sizeof(prime));\n int rootn = (int)sqrt(n);\n \n for (int p = 2; p <= rootn; p++)\n if(prime[p] == true)\n for(int i = p*p; i <= n; i += p)\n prime[i] = false;\n prime[1] = 0;\n}\nconst int N = 1000050;\nint cnt, sum, mid, mx, mn, ans, a[N], b[N];\nint n, m, d, i, j, k, l, p, q, r, t, w, x, y, z;\nbool f, f1, f2;\nstring s;\n// you can also use __int128\n// priority_queue,greater>\n// bitset<100>(x).count()\n//******************************************* CHECK CONSTRAINTS **************************************************\n\n\nint32_t main()\n{\n ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n cin>>n;\n for(int i=1;i<=n;i++)cin>>a[i];\n cin>>k;\n vector neg(n+2);\n for(int i=1;i<=k;i++)\n {\n cin>>x;\n neg[x] = 1;\n }\n stack s;\n for(int i=n;i>0;i--)\n {\n if(s.empty() || neg[i])\n {\n s.push(a[i]);\n a[i] = -a[i];\n continue;\n }\n if(s.top() == a[i])\n {\n s.pop();\n }\n else\n {\n s.push(a[i]);\n a[i] = -a[i];\n }\n }\n if(!s.empty())\n {\n cout<<\"NO\\n\";\n return 0;\n }\n cout<<\"YES\\n\";\n for(int i=1;i<=n;i++)\n {\n cout<\r\nusing namespace std;\r\n#define ll long long\r\nint n,m,a[10],b[10],c[10][10],len,sum[10][1<<10],sk[10],ac[1<<10];\r\nll ans=1e9;\r\nbool check(){\r\n\tfor(int i=0;i0)return 0;\r\n\t}return 1;\r\n}\r\nvoid dfs(int x,ll w){\r\n\tif(w>=ans)return;\r\n\tif(x>=n){\r\n\t\tif(check())ans=w;\r\n\t\treturn;\r\n\t}ll tp=w;\r\n\tfor(int i=x;i\n\nint min(int a,int b){return(a\n#include \n#include \n#include \n#define m1 998244353\n#define m2 1000000007\n#define MS 2000010\n#define ll long long\nusing namespace std;\nstruct Set\n{\n int sz[MS],n;ll H;\n void init(vector ve)\n {\n n=ve.size();H=0;\n for(int i=0;i>1;\n if(x+sz[m]>=m1)r=m;\n else l=m+1;\n }\n ll rt=H+1ll*x*n-1ll*m1*(n-l);\n return (rt%m2+m2)%m2;\n }\n}se[15];ll tm,tt,mi[15],su[15];vector v0;\nint sz[15];char zf[15];\nvoid dfs0(int u,int s,int d)\n{\n tm+=1;\n if(s==6)\n {\n v0.push_back(tm-u);\n tm+=su[d]-1;return;\n }\n for(int i=0;i<10;i++)\n dfs0(u*10+i,s+1,d);\n}\nint ans=0;\nll count(ll u,int s,int n,int eq)\n{\n if(s>n||(s==n&&eq>0))return 0;\n if(eq>0)return su[n-s-1];\n if(eq<0)return su[n-s];\n ll rt=1;\n for(int i=0;i<10;i++)\n rt+=count(u*10+i,s+1,n,eq==0?i-sz[s]:eq);\n return rt;\n}\nvoid dfs3(ll u,int s,int d,int n,int eq)\n{\n if(s>n||(s==n&&eq>0))return;\n tt+=1;\n if(d==6)\n {\n ans=(ans+((tt-u)%m1+m1)%m1)%m2;\n tt+=count(u,s,n,eq)-1;return;\n }\n for(int i=0;i<10;i++)\n dfs3(u*10+i,s+1,d+1,n,eq==0?i-sz[s]:eq);\n}\nvoid dfs1(int u,int s,int n,int eq)\n{\n if(s>n||(s==n&&eq>0))return;\n tm+=1;\n if(s+6<=n)\n {\n if(eq>0)\n ans=(ans+(n>=s-7?se[n-s-7].ask(tm-1ll*u*1000000):0))%m2;\n else if(eq<0)\n ans=(ans+se[n-s-6].ask(tm-1ll*u*1000000))%m2;\n else\n {\n tt=tm-1;\n dfs3(u,s,0,n,eq);\n }\n }\n ans=(ans+((tm-u)%m1+m1)%m1)%m2;\n if(s==6)\n {\n tm+=count(u,s,n,eq)-1;\n return;\n }\n if(s==n)return;\n for(int i=0;i<10;i++)\n dfs1(u*10+i,s+1,n,eq==0?i-sz[s]:eq);\n}\nint main()\n{\n mi[0]=su[0]=1;\n for(int i=1;i<=12;i++)\n {\n mi[i]=10*mi[i-1];\n su[i]=su[i-1]+mi[i];\n }\n scanf(\"%s\",zf);int n=strlen(zf);\n if(n==13)\n {\n printf(\"289817887\");\n return 0;\n }\n for(int i=0;i\n#include \nusing namespace std;\n#define MAXN 45\n#define ll long long\n\nll dp[MAXN][4][4][4];\nll c[4][4];\n\nll dfs(int n, int from, int to, int aux) {\n if(n == 1) {\n return min(c[from][to], c[from][aux] + c[aux][to]);\n }\n if(dp[n][from][to][aux] != -1) return dp[n][from][to][aux];\n\n ll t1 = dfs(n-1, from, aux, to) + c[from][to] + dfs(n-1, aux, to, from);\n ll t2 = dfs(n-1, from, to, aux) + c[from][aux] + dfs(n-1, to, from, aux) + c[aux][to]+ dfs(n-1, from, to, aux);\n\n dp[n][from][to][aux] = min(t1,t2);\n return dp[n][from][to][aux];\n}\n\nint main()\n{\n for(int i=0; i<3; ++i) {\n for(int j=0; j<3; ++j) {\n cin >> c[i][j];\n }\n }\n\n int n;\n cin >> n;\n memset(dp, -1, sizeof(dp));\n cout << dfs(n, 0, 2, 1) << endl;\n}", "src_uid": "c4c20228624365e39299d0a6e8fe7095"} {"source_code": "#include\n#include\n#define rep(i,x,y) for(int i=(x);i<=(y);i++)\nusing namespace std;\nint x1,x2,x,a,b,u;\nint main(){\n\tscanf(\"%d%d%d%d\",&x1,&x2,&a,&b);\n\tif(x1+a<=x2&&x1+b>=x2){\n\t\tprintf(\"FIRST\\n%d\\n\",x2);return 0;\n\t}x=x2-x1;\n\tif(a<0&&b<0){\n\t\tu=1;a=-a;b=-b;x=-x;swap(a,b);\n\t}\n\tif(a<=0||x<0){\n\t\tprintf(\"DRAW\\n\");return 0;\n\t}\n\tif(x%(a+b)==0)printf(\"SECOND\\n\");\n\telse{\n\t\tif(x%(a+b)b){\n\t\t\tprintf(\"DRAW\\n\");return 0;\n\t\t}\n\t\tprintf(\"FIRST\\n\");\n\t\tif(u)printf(\"%d\\n\",x1-x%(a+b));\n\t\telse printf(\"%d\\n\",x1+x%(a+b));\n\t}\n}", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6"} {"source_code": "#pragma GCC optimize(\"Ofast,unroll-loops\")\r\n#pragma GCC target(\"avx,avx2,fma\")\r\n#include \r\n#include \r\n#include \r\nusing namespace __gnu_pbds;\r\nusing namespace std;\r\n#define ll long long\r\n#define pb push_back \r\n#define mp make_pair \r\n#define nline \"\\n\" \r\nconst ll INF_MUL=1e13; \r\nconst ll INF_ADD=1e18; \r\n#define f first \r\n#define s second \r\n#define pll pair \r\n#define vl vector \r\n#define vvl vector>\r\n#define vvvl vector>> \r\n#ifndef ONLINE_JUDGE \r\n#define debug(x) cerr<<#x<<\" \"; _print(x); cerr< void _print(pair p) {cerr<<\"{\"; _print(p.first);cerr<<\",\"; _print(p.second);cerr<<\"}\";}\r\ntemplatevoid _print(vector v) {cerr<<\" [ \"; for (T i:v){_print(i);cerr<<\" \";}cerr<<\"]\";}\r\ntemplatevoid _print(set v) {cerr<<\" [ \"; for (T i:v){_print(i); cerr<<\" \";}cerr<<\"]\";}\r\ntemplatevoid _print(multiset v) {cerr<< \" [ \"; for (T i:v){_print(i);cerr<<\" \";}cerr<<\"]\";}\r\ntemplatevoid _print(map v) {cerr<<\" [ \"; for(auto i:v) {_print(i);cerr<<\" \";} cerr<<\"]\";} \r\ntypedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\r\ntypedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;\r\n//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\nconst ll MOD=998244353; \r\nconst ll MAX=500500;\r\nll dig(char c){\r\n ll x=c-'0';\r\n return x;\r\n}\r\nvoid solve(){ \r\n string s; cin>>s;\r\n ll n=s.size();\r\n s=\" \"+s;\r\n ll ans=0; \r\n for(ll j=1;j<=n;j++){\r\n if(s[j]=='_')\r\n s[j]='.';\r\n }\r\n if(n==1){\r\n ans+=((s[1]=='0')||(s[1]=='.')||(s[1]=='X'));\r\n cout<=(n-1)) \r\n continue;\r\n options*=(10-(j==1));\r\n }\r\n } \r\n debug(options);\r\n if(now[1]=='0')\r\n continue;\r\n for(ll j=0;j<=9;j++){ \r\n for(ll k=0;k<=9;k++){\r\n ll rem=j*10+k;\r\n if(rem%25)\r\n continue;\r\n if((j==0)&&(n==2))\r\n continue;\r\n if((now[n-1]!='.')&&(dig(now[n-1])!=j))\r\n continue;\r\n if((now[n]!='.')&&(dig(now[n])!=k))\r\n continue;\r\n ans+=options;\r\n }\r\n }\r\n if(freq==0)\r\n break;\r\n }\r\n cout<>test_cases; \r\n while(test_cases--){ \r\n solve(); \r\n }\r\n cerr<<\"Time:\"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<\"ms\\n\"; \r\n} ", "src_uid": "4a905f419550a6c839992b40f1617af3"} {"source_code": "//careful references in recursion\n//careful long long int and mod always\n//careful return types of std such as int(ceil)\n//io manip lookup for decimal control\n//WATCH OUT GOING OVER MAX thru operations spam mod\n// vectors overflow arrays do NOT\n//lower bound is first greater or equal\n//uper is first greater\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#define loop(i, n) for(int i = 0; i < n; i++)\ntypedef long long ll; //can be modified to long/int in emergencies.\ntypedef long long lll;\ntemplate \nvoid cprintv(vector& v){\n for(int i=0; i\nvoid cprintd(unordered_map& tp){\n for (auto i=tp.begin(); i!=tp.end(); i++){\n cout<first<<\" : \"<second<\nvector clist(int n){\n std::vector v;\n while(n--){\n T k;\n cin>>k;\n v.push_back(k);\n }\n return v;\n}\nvector cstrtv(string& s){\n vector v;\n for(int i=0; i\nunordered_map ccount(vector& v){\n unordered_map m;\n for(int i=0; i\nostream& operator<<(ostream& os, vector& dt){\n cprintv(dt);\n return os;\n}\ntemplate\nostream& operator<<(ostream& os, unordered_map& dt){\n cprintd(dt);\n return os;\n}\ntemplate\nostream& operator<<(ostream& os, pair& dt){\n cout<\nint maxind(vector& v){\n int maxi=0;\n for(int i=1; i\nT maxel(vector& v){\n return v[maxind(v)];\n}\ntemplate\nint minind(vector& v){\n int mini=0;\n for(int i=1; iv[i])? i:mini;\n }\n return mini;\n}\ntemplate\nT minel(vector& v){\n return v[minind(v)];\n}\ntemplate\nvector partialsums(vector& v){\n vector ps(v.size());\n ps[0]=v[0];\n for(int i=1; i\nll sumy(vector& v){\n ll s=0;\n for(int i=0; i> indexify(string s){\n vector> ret;\n for(int i=0; i<26; i++){\n vector k;\n ret.push_back(k);\n }\n for(int i=0; i>n;\n int k;\n cin>>k;\n vector v=clist(n);\n static pair,lll> ar[200001];\n loop(i,200001){\n ar[i].second=0;\n }\n int steps=0;\n loop(i,n){\n int el=v[i];\n lll steps=0;// add to 0 at end\n while(true){\n ar[el].first.insert(steps);\n ar[el].second=ar[el].second+steps;\n //cout<k){\n auto out=ar[el].first.end();\n out--;\n ar[el].second-=*out;\n //cout<<\"tbrm \"<<*out<\n#include \n#include \n\nusing namespace std;\ntypedef long long LL;\n\nconst int MAXN = 1e7 + 5;\nconst LL Inf = 1e15 + 7;\n\nint N;\nLL a, b;\nLL D[MAXN], Side[MAXN], F[MAXN];\n\nint main() {\n\tscanf(\"%I64d%I64d%I64d\", &N, &a, &b);\n\tD[1] = Inf;\n\tint l = 1, r = 0;\n\tfor (int i = 1; i <= N; i ++) {\n\t\tF[i] = F[i - 1] + a;\n\t\twhile (Side[l] * 2 < i && l <= r) l ++;\n\t\tF[i] = min(F[i], D[l] - 1ll * i * a);\n\t\tLL Num = F[i] + b + 2ll * i * a;\n\t\twhile (r >= l && D[r] > Num) r --;\n\t\tD[++ r] = Num;\n\t\tSide[r] = i;\n\t}\n\tprintf(\"%I64d\\n\", F[N]);\n}", "src_uid": "0f270af00be2a523515d5e7bd66800f6"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tint a,b,c;\n\tscanf(\"%d:%d\",&a,&b);\n\tcin>>c; \n\tb+=c%60;\n\tif (b>=60)\n\t{\n\t\tb-=60;\n\t\ta++;\n\t}\n\ta+=((c-(c%60))/60);\n\twhile(a>=24)\n\t{\n\t\tif (a>=24)\n\t\t{\n\t\t\ta-=24;\n\t\t}\n\t}\n\tprintf(\"%02d:%02d\",a,b);\n\treturn 0;\n}", "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"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;\n\nconst int N = 1e3+9;\n\nint a[N];\nint main() {\n int i, j, n, q, L, R, x;\n while(~scanf(\"%d\", &n)) {\n scanf(\"%d\", &x);\n for(i=0; i\nusing namespace std;\nmain(){\n int a,b;\n cin>>a;\n b=(a+4)/5;\n cout<\n#include \n#include \nusing namespace std;\n\nint t[] = { 0,3,7,12,16 };\nint n[] = { 3,4,5,4,3 };\n\nint dp[1<<19][2];\nint arr[5][10];\n\nint solve (int mask , bool p)\n{\n if (mask == (1<<19)-1) return !p;\n if (dp[mask][p] != -1) return dp[mask][p];\n\n int l;\n int m;\n\n if (p == 0)\n {\n l = 1;\n\n for (int i=0; i<5; i++)\n {\n for (int j=0; j= 3) q --;\n if (q >= n[k]) break;\n if (mask & (1<<(q+t[k]))) break;\n m |= (1<<(q+t[k]));\n l = min (l , solve (m , !p));\n }\n }\n }\n }\n else\n {\n l = 0;\n\n for (int i=0; i<5; i++)\n {\n for (int j=0; j= 3) q --;\n if (q >= n[k]) break;\n if (mask & (1<<(q+t[k]))) break;\n m |= (1<<(q+t[k]));\n l = max (l , solve (m , !p));\n }\n }\n }\n }\n\n return dp[mask][p] = l;\n}\n\nint main ()\n{\n char s[15];\n int m = (1<<19)-1;\n char c;\n\n for (int i=0; i<5; i++)\n {\n int j = 0;\n while (1)\n {\n scanf (\"%c\",&c);\n\n if (c == '\\n') break;\n if (c == ' ') continue;\n if (c == '.') arr[i][j ++] = 0;\n if (c == 'O') arr[i][j ++] = 1;\n }\n }\n\n for (int i=0; i<5; i++)\n {\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 \ntypedef long double LD;\ntypedef long long LL;\n \nusing namespace std;\n \n#define sz(A) (int)(A).size()\n#define mp make_pair\n#define pb push_back\n \nstruct vect {\n int x, y;\n \n vect() {}\n \n vect(int a, int b) {\n x = a, y = b;\n }\n \n void read() {\n cin >> x >> y;\n }\n};\n \nvect operator - (vect a, vect b) {\n return vect(a.x - b.x, a.y - b.y);\n}\n \nLL operator % (vect a, vect b) {\n return LL(a.x) * b.y - LL(a.y) * b.x;\n}\n \nint main() {\n vect a, b, c;\n a.read();\n b.read();\n c.read();\n \n vect ab = b - a, bc = c - b;\n \n if (ab % bc == 0) {\n puts(\"TOWARDS\");\n } \n else {\n if (ab % bc > 0) {\n puts(\"LEFT\");\n }\n else {\n puts(\"RIGHT\");\n }\n }\n \n return 0;\n}", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"} {"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 long long int k,b,n,t;\n cin>>k>>b>>n>>t;\n if(k==1)\n {\n long long int X=1+n*b-t;\n long long int m=X/b;\n //cout<\n#include\n#include\n#define it register int\n#define ct const int\n#define il inline\nusing namespace std;\nnamespace io{\n\til char nc(){\n\t\tstatic char buf[100000],*p1=buf,*p2=buf;\n\t\treturn p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; \n\t}\n\ttemplate \n\til void fr(I &num){\n\t\tnum=0;register char c=nc();it p=1;\n\t\twhile(c<'0'||c>'9') c=='-'?p=-1,c=nc():c=nc();\n\t\twhile(c>='0'&&c<='9') num=num*10+c-'0',c=nc();\n\t\tnum*=p;\n\t} \n};\nusing io :: fr;\nconst int N=20005;\ntypedef long long ll;\n#define rll register ll\n#define cll const ll\nint a[N],n,m,mx[N][20],pw[40],lg[N],st[N],top,s[N<<2],cn,now;\nll k[N],b[N],f[105][N],mn[N<<2];\nstruct ky{\n\tint x;ll y;\n};\ndeque vec[N];\ntemplate\nil I Min(I p,I q){return pa[q]?p:q;}\nil void Pre(){\n\tit i,j;lg[0]=-1,pw[0]=1;\n\tfor(i=1;i<=n;++i) lg[i]=lg[i>>1]+1;lg[0]=0;\n\tfor(i=1;i<=30;++i) pw[i]=pw[i-1]<<1;\n\tfor(i=1;i<=n;++i) mx[i][0]=i;\n\tfor(j=1;pw[j]<=n;++j)\n\t\tfor(i=1;i+pw[j]-1<=n;++i)\n\t\t\tmx[i][j]=MAX(mx[i][j-1],mx[i+pw[j-1]][j-1]);\n}\nil int qmx(ct l,ct r){\n\tct k=lg[r-l+1];\n\treturn MAX(mx[l][k],mx[r-pw[k]+1][k]);\n}\nil ll cal(ct id,ct x){return k[id]*x+b[id];}\nil void B(ct rt,ct l,ct r){\n\ts[rt]=0,mn[rt]=1e18;\n\tif(l^r){\n\t\tct mid=l+r>>1;\n\t\tB(rt<<1,l,mid),B(rt<<1|1,mid+1,r);\n\t}\n}\nil void upd(ct rt,ct l,ct r,ct u,ct v,ct x){\n\t//printf(\"u=%d v=%d\\n\",u,v);\n\t//printf(\"%d %lld %lld\\n\",rt,k[x],b[x]);\n\tct mid=l+r>>1,ls=rt<<1,rs=ls|1;\n//\tif(l==r) return (cal(x,l)=u&&r<=v){\n\t\t//printf(\"s : %d %lld %lld\\n\",rt,k[s[rt]],b[s[rt]]);\n\t\tif(!s[rt]) return s[rt]=x,mn[rt]=cal(x,l),void();\n\t\tcll l0=cal(s[rt],l),l1=cal(x,l),r0=cal(s[rt],r),r1=cal(x,r);\n\t\t//printf(\"L : %lld %lld %lld %lld\\n\",l1,l0,r1,r0);\n\t\tif(l0<=l1&&r0<=r1) return;\n\t\tif(l1<=l0&&r1<=r0) return s[rt]=x,mn[rt]=Min(mn[rt],l1k[s[rt]]) cal(x,mid)<=cal(s[rt],mid)?upd(rs,mid+1,r,u,v,s[rt]),s[rt]=x,void():upd(ls,l,mid,u,v,x);\n\t\t/*double pos=(b[x]-b[s[rt]])/(k[s[rt]]-k[x]);\n\t\t//printf(\"%.6lf\\n\",pos);\n\t\tif(pos<=mid) l1>l0?upd(ls,l,mid,u,v,s[rt]),s[rt]=x,void():upd(ls,l,mid,u,v,x);\n\t\telse l1>l0?upd(rs,mid+1,r,u,v,x):(upd(rs,mid+1,r,u,v,s[rt]),s[rt]=x,void());*/\n\t\tmn[rt]=Min(mn[rt],l1mid) upd(rs,mid+1,r,u,v,x);\n\tmn[rt]=Min(mn[rt],mn[ls]>1,ls=rt<<1,rs=ls|1;\n\treturn Min(cal(s[rt],pos),pos<=mid?que(ls,l,mid,pos):que(rs,mid+1,r,pos));\n}\nil double slope(const ky a,const ky b){return 1.0*(b.y-a.y)/(b.x-a.x);}\nil void calc(ct x,ct y){\n\tif(!vec[x].size()) return k[++cn]=0,b[cn]=1e18,void();\n\twhile(vec[x].size()>1&&slope(vec[x][0],vec[x][1])<=y) vec[x].pop_front();\n\t//printf(\"vec : %d %lld %d %d\\n\",vec[x].size(),vec[x][0].y,vec[x][0].x,y);\n\tk[++cn]=y,b[cn]=vec[x][0].y-(0ll+vec[x][0].x)*y;\n}\nil void pf(ct x,const ky y){\n\tit sz=vec[x].size();\n\twhile(sz>1){\n\t\tif(slope(y,vec[x][1])>slope(y,vec[x][0])) break;\n\t\tvec[x].pop_front(),--sz;\n\t}\n\tvec[x].push_front(y);\n}\nil void pb(ct x,const ky y){\n\tit sz=vec[x].size();\n\twhile(sz>1){\n\t\tif(slope(vec[x][sz-2],y)>slope(vec[x][sz-2],vec[x][sz-1])) break;\n\t\tvec[x].pop_back(),--sz;\n\t}\n\tvec[x].push_back(y);\n}\nil int solve(ct l,ct r){\n\tif(l==r) return vec[st[top]].push_back((ky){l,f[now-1][l]}),st[top--];\n\tct pos=qmx(l+1,r),lpos=solve(l,pos-1);calc(lpos,a[pos]),upd(1,1,n,pos,r,cn),f[now][pos]=que(1,1,n,pos);\n\t//printf(\"pos=%d f[now][pos]=%lld\\n\",pos,f[now][pos]);\n\tct rpos=solve(pos,r);\n\tif(vec[rpos].size()<=vec[lpos].size()){\n\t\twhile(vec[rpos].size()) pb(lpos,vec[rpos][0]),vec[rpos].pop_front();\n\t\treturn st[++top]=rpos,lpos;\n\t}\n\twhile(vec[lpos].size()) pf(rpos,vec[lpos].back()),vec[lpos].pop_back();\n\treturn st[++top]=lpos,rpos;\n}\nint main(){ \n\tfr(n),fr(m);it i;b[0]=1e18;\n\tfor(i=1;i<=n;++i) fr(a[i]),st[i]=i;\n\tPre(),now=2,top=n;\n\tfor(i=1;i<=n;++i) f[1][i]=(0ll+i)*a[qmx(1,i)];//printf(\"%lld \",f[1][i]);puts(\"\");\n\twhile(now<=m) cn=0,B(1,1,n),solve(now-1,n),++now;/**/\n\tprintf(\"%lld\",f[m][n]);\n\treturn 0;\n}\n", "src_uid": "f42faaaa88628748a8da49111936be00"} {"source_code": "#include \nint t[1005],n,a[55],ans[55],cnt;\nint main(){\n scanf(\"%d\",&n);\n for(int i=1;i<=n;i++)\n scanf(\"%d\",&a[i]);\n for(int i=n;i>=1;i--){\n t[a[i]]++;\n if(t[a[i]]==1)ans[++cnt]=a[i];\n }\n printf(\"%d\\n\",cnt);\n for(int i=cnt;i>=1;i--)\n printf(\"%d \",ans[i]);\n return 0;\n}", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"source_code": "#include\nusing namespace std;\nint a,b,p1,p2,p3,p4,p5,ans;\nint main()\n{\n\tcin>>p1>>p2>>p3>>p4>>a>>b;\n\tfor(;a<=b;a++)\n\t\tif(a%p1%p2%p3%p4==a)\n\t\t\tans++;\n\tcout<\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\nconst LL MAX = 105;\n\nLL n, cap;\n\nint main(void)\n{\n cin >> n >> cap;\n LL cur = 1, ans = 0;\n LL dist = n - cur;\n if(cap >= dist)cout << dist << endl;\n else\n {\n ans = cap;\n cur += cap;\n LL cost = 2;\n while(cur < n)\n {\n ans += cost;\n cost++;\n cur++;\n }\n cout << ans << endl;\n }\n return 0;\n}\n", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"source_code": "#include \nusing namespace std ; \n#define ll long long int \n#define pb push_back\n#define ff first \n#define dobara(i,a,b) for(int (i) = (a); (i) < (b); (i)++)\n#define ss second \n#define S(x) scanf(\"%d\",&x) \n#define SL(x) scanf(\"%lld\",&x)\n#define M 1000000007\n#define sz(x) (int)x.size()\n#define all(a) (a).begin(),(a).end()\n\nint main(){\n\tll dp[105] = {0} , cnt[105] = {0} ; \n\n\tll n ; \n\tcin>>n ; \n dp[1] = 1 ; dp[2] = 5 ; \n \n for(ll i=3;i<=103;i++){\n \tdp[i] = (i -1)*4LL + dp[i - 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 \n#include \n#include \n#include \n\n#define rep(i,n) for(int i=0; i\n#define vi vector\n#define vs vector\n#define sstr stringstream \n#define fnd(v,x) (find(all((v)),(x))!=(v).end())\n#define itr(A,B) typeof(B) A = B\ntypedef long long ll;\nusing namespace std;\n\nconst int size = 100002;\nint states[size];\nvi g[size],revg[size];\nbool mark1[size],mark2[size];\n\nvoid DFS(int idx){\n mark1[idx] = 1;\n// if(states[idx]==2) return;\n rep(i,sz(g[idx])){\n if(!mark1[g[idx][i]])\n DFS(g[idx][i]);\n }\n}\n\nvoid DFS2(int idx){\n mark2[idx] = 1;\n if(states[idx]==1) return;\n rep(i,sz(revg[idx])){\n if(!mark2[revg[idx][i]])\n DFS2(revg[idx][i]);\n }\n}\nint main(){\n#ifndef ONLINE_JUDGE\n freopen(\"in\",\"rt\",stdin);\n freopen(\"out\",\"wt\",stdout);\n#endif\n\n\n\n int n,m,a,b;\n scanf(\"%d%d\",&n,&m);\n rep(i,n){\n scanf(\"%d\",states+i);\n }\n rep(i,m){\n scanf(\"%d%d\",&a,&b);\n --a, --b;\n g[a].push_back(b);\n revg[b].push_back(a);\n }\n\n rep(i,n){\n if(states[i]==1) DFS(i);\n if(states[i]==2) DFS2(i);\n }\n\n rep(i,n)\n printf(mark1[i] && mark2[i]?\"1\\n\":\"0\\n\");\n\n\n\n}\n\n\n\n\n\n", "src_uid": "87d869a0fd4a510c5e7e310886b86a57"} {"source_code": "#include \nusing namespace std;\n\nint main()\n{\n string x;\n cin >> x;\n for(int i=0;i=0;i--)\n {\n if(x[i]=='0') x.erase(i,1);\n else break;\n }\n bool v =true;\n for(int i=0;i\n#include \nusing namespace std;\nint n,tot=0,i,j,k,o[30],g[30],f[30];\nvoid U(int x,int a,int b,int c)\n{\n\tif (x>n) return;\n\tint i;\n\tU(x+1,a,c,b);\n\tfor (i=1;i<=o[x];i++)\n\t\tprintf(\"%d %d\\n\",a,b);\n\tU(x+1,c,b,a);\n\treturn;\n}\nvoid C(int x,int a,int b,int c)\n{\n\tint i;\n\tif (o[x]==1)\n\t\tU(x,a,b,c);\n\telse if (x==n)\n\t{\n\t\tfor (i=1;i\n\nusing namespace std;\n\ntypedef long long ll;\n\n#define MAXN 105\n\nll n, k;\nstring s;\n\nll dp[MAXN][MAXN][26];\nll cnt[MAXN];\n\nint main() {\n\tcin >> n >> k;\t\n\tcin >> s;\n\tmemset(dp, 0, sizeof (dp));\n\tdp[1][1][s[0]-'a'] = 1;\n\tfor (int i = 2; i <= n; i++) {\n\t\tfor (int j = 1; j <= n; j++) {\n\t\t\tint d = s[i-1] - 'a';\n\t\t\tfor (int l = 0; l < 26; l++) {\n\t\t\t\tif (d != l) {\n\t\t\t\t\tdp[i][j][l] = dp[i-1][j][l];\n\t\t\t\t} else {\n\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\tdp[i][j][l] = 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfor (int p = 0; p < 26; p++) {\n\t\t\t\t\t\t\tdp[i][j][l] += dp[i-1][j-1][p];\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\n\tcnt[0] = 1;\n\tfor (int i = 1; i <= n; i++) {\n\t\tfor (int j = 0; j < 26; j++) {\n\t\t\tcnt[i] += dp[n][i][j];\n\t\t}\n\t\t//cout << \"cnt[\" << i << \"]=\" << cnt[i] << endl;\n\t}\n\tll ans = 0;\n\tfor (int i = n; k > 0 && i >= 0; i--) {\n\t\tll t = min(k, cnt[i]);\n\t\tk -= t;\n\t\tans += t * (ll)(n-i);\n\t}\n\tif (k > 0) {\n\t\tans = -1;\n\t}\n\tcout << ans << endl;\n\treturn (0);\n}\n", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#define inff 0x3fffffff \n#define nn 6100 \n#define mod 1000000007 \ntypedef long long LL; \nconst LL inf64=inff*(LL)inff; \nusing namespace std; \nLL a1,b1,a2,b2; \nint main() \n{ \n while(scanf(\"%I64d%I64d%I64d%I64d\",&a1,&b1,&a2,&b2)!=EOF) \n { \n LL ix=a1*b1; \n int n2,n3,m2,m3; \n n2=n3=m2=m3=0; \n while(ix%2==0) \n { \n ix/=2; \n n2++; \n } \n while(ix%3==0) \n { \n ix/=3; \n n3++; \n } \n LL fc=a2*b2; \n while(fc%2==0) \n { \n fc/=2; \n m2++; \n } \n while(fc%3==0) \n { \n fc/=3; \n m3++; \n } \n if(ix!=fc) \n { \n puts(\"-1\"); \n } \n else \n { \n int ans=abs(m3-n3); \n if(m3>n3) \n { \n m3-=ans; \n m2+=ans; \n int my=ans; \n while(a2%3==0&&my) \n { \n a2=a2/3*2; \n my--; \n } \n while(b2%3==0&&my) \n { \n b2=b2/3*2; \n my--; \n } \n } \n else \n { \n n3-=ans; \n n2+=ans; \n int my=ans; \n while(a1%3==0&&my) \n { \n a1=a1/3*2; \n my--; \n } \n while(b1%3==0&&my) \n { \n b1=b1/3*2; \n my--; \n } \n } \n ans+=abs(n2-m2); \n if(n2>m2) \n { \n int my=abs(n2-m2); \n while(a1%2==0&&my) \n { \n a1/=2; \n my--; \n } \n while(b1%2==0&&my) \n { \n b1/=2; \n my--; \n } \n } \n else \n { \n int my=abs(n2-m2); \n while(a2%2==0&&my) \n { \n a2/=2; \n my--; \n } \n while(b2%2==0&&my) \n { \n b2/=2; \n my--; \n } \n } \n printf(\"%d\\n\",ans); \n printf(\"%I64d %I64d\\n\",a1,b1); \n printf(\"%I64d %I64d\\n\",a2,b2); \n } \n } \n return 0; \n} ", "src_uid": "4fcd8c4955a47661462c326cbb3429bd"} {"source_code": "#include \n\nusing namespace std;\n\nconst int MOD = 998244853;\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\nstruct Comb {\n int n;\n vector fac, ifac, inv;\n\n Comb(int _n=1) {\n resize(2);\n fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;\n n = 1; grow(_n);\n }\n\n void resize(int _s) {\n fac.resize(_s); ifac.resize(_s); inv.resize(_s);\n }\n bool grow(int _n) {\n if (_n <= n) return false;\n resize(_n+1);\n for (int i = n+1; i <= _n; i++) {\n fac[i] = fac[i-1] * i;\n inv[i] = (-MOD/i) * inv[MOD%i];\n ifac[i] = ifac[i-1] * inv[i];\n }\n n = _n;\n return true;\n }\n // choose\n mint c(int N, int K) {\n if (N < K || K < 0) return 0;\n if (N > n) grow(N);\n return fac[N] * ifac[N-K] * ifac[K];\n }\n // sum x = S, x > 0\n mint p(int S, int K) {\n return c(S-1, K-1);\n }\n // sum x = S, x >= 0\n mint z(int S, int K) {\n return p(S+K, K);\n }\n};\n\nconst int N = 2003;\nmint z[N][N];\nmint dp[N][N];\n\nvoid solve() {\n int n, m;\n cin >> n >> m;\n Comb c(n+m);\n for (int j = 0; j <= m; j++) {\n z[0][j] = 1;\n }\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= m; j++) {\n if (i > j) {\n z[i][j] = 0; continue;\n }\n z[i][j] = z[i-1][j] + z[i][j-1];\n }\n }\n for (int j = 0; j <= m; j++) {\n dp[0][j] = 0;\n }\n for (int i = 1; i <= n; i++) {\n dp[i][0] = i;\n }\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n dp[i][j] = (c.c(i+j-1, j) + dp[i-1][j]) + (dp[i][j-1] - (c.c(i+j-1,i) - z[i][j-1]));\n }\n }\n cout << dp[n][m];\n}\n\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n solve();\n cout << endl;\n}\n", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb"} {"source_code": "#include \"bits/stdc++.h\"\n//#include \"ext/pb_ds/tree_policy.hpp\"\n//#include \"ext/pb_ds/assoc_container.hpp\"\n#define PB push_back\n#define PF push_front\n#define LB lower_bound\n#define UB upper_bound\n#define fr(x) freopen(x,\"r\",stdin)\n#define fw(x) freopen(x,\"w\",stdout)\n#define iout(x) printf(\"%d\\n\",x)\n#define lout(x) printf(\"%lld\\n\",x)\n#define REP(x,l,u) for(ll x = l;x=u;x--)\n#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())\n#define mst(x,a) memset(x,a,sizeof(x))\n#define all(a) a.begin(),a.end()\n#define PII pair\n#define PLL pair\n#define MP make_pair\n#define sqr(x) ((x)*(x))\n#define lowbit(x) (x&(-x))\n#define lson (ind<<1)\n#define rson (ind<<1|1)\n#define se second\n#define fi first\n#define dbg(x) cerr<<#x<<\" = \"<<(x)< point;\nconst ll mod = 1e9+7;\nconst ll inf = 1e9+7;\nconst ld eps = 1e-9;\nconst db PI = atan(1)*4;\ntemplate\ninline int sign(const T&a) {\n if(a<0)return -1;\n if(a>0)return 1;\n return 0;\n}\n\ntemplateinline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}\ntemplateinline bool upmax(T&a,const S&b){return a inline void in(T &x) {\n x = 0;\n T f = 1;\n char ch = getchar();\n while (!isdigit(ch)) {\n if (ch == '-') f = -1;\n ch = getchar();\n }\n while (isdigit(ch)) {\n x = x * 10 + ch - '0';\n ch = getchar();\n }\n x *= f;\n}\n\nll twop(int x) {\n return 1LL< inline void in(A&x,B&y) {\n in(x);\n in(y);\n}\ntemplateinline void in(A&x,B&y,C&z) {\n in(x);\n in(y);\n in(z);\n}\ntemplate inline void in(A&x,B&y,C&z,D&d) {\n in(x);\n in(y);\n in(z);\n in(d);\n}\n\n\nll fast(ll a,ll b){\n ll ans = 1;\n while(b){\n if(b&1){\n b--;\n ans = ans * a;\n }else{\n a = a * a;\n b/=2;\n }\n }\n return ans;\n}\n\n\nll fast(ll a,ll b,ll mod){\n ll ans = 1;\n while(b){\n if(b&1){\n b--;\n ans = ans * a % mod;\n }else{\n a = a * a % mod;\n b/=2;\n }\n }\n return ans;\n}\n\n// m must be positive\ntemplate\nstatic T MOD(T a, T m)\n{\n a %= m;\n if (a < 0)\n a += m;\n return a;\n}\n\n// a must be relatively prime to m\ntemplate\nstatic T inverse(T a, T m)\n{\n a = MOD(a, m);\n if (a <= 1)\n return a;\n return MOD((1 - inverse(m, a) * m) / a, m);\n}\n\nconst ll maxn = 20010;\nll fac[maxn],inv[maxn];\nvoid init(){\n fac[0] = 1;\n REP(i,1,maxn)fac[i] = i*(fac[i-1])%mod;\n inv[maxn-1]=inverse(fac[maxn-1], mod);\n RREP(i,maxn-2,0){\n inv[i] = inv[i+1]*(i+1)%mod;\n }\n}\n\nll combi(int n,int m){\n if(n<0 || m<0 || n\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint a[50010], n, b[50010], t;\nint check(long long x)\n{\n\tint i;\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tlong long y = (x - i) / n + bool((x - i) % n);\n\t\tlong long z;\n\t\tif (b[i] == 0) z = 0; else z = (t + x - b[i]) / t;\n\t\tif (y - z >= a[i]) return i + 1;\n\t}\n\treturn 0;\n}\nint main()\n{\n\tint i;\n\tscanf(\"%d\", &n);\n\tfor (i = 0; i < n; i++) scanf(\"%d\", &a[i]);\n\tint x = n - 1;\n\tfor (i = 1; i <= n; i++)\n\t{\n\t\tif (b[(x + 7) % n]) break;\n\t\tb[(x + 7) % n] = i * 7;\n\t\tx = (x + 7) % n;\n\t}\n\tt = 7 * (i - 1);\n\tlong long l = 1, r = 1e14, m, ans;\n\twhile (l <= r)\n\t{\n\t\tm = (l + r) / 2;\n\t\tint z = check(m);\n\t\tif (!z) l = m + 1; else\n\t\t{\n\t\t\tans = z;\n\t\t\tr = m - 1;\n\t\t}\n\t}\n\tprintf(\"%d\\n\", ans);\n\treturn 0;\n}", "src_uid": "8054dc5dd09d600d7fb8d9f5db4dcaca"} {"source_code": "#include \n\nusing namespace std;\n\ntemplate\nstruct dinic\n{\n\ttypedef C flow_type;\n\ttypedef R result_type;\n\n\tstatic_assert(std::is_arithmetic::value, \"flow_type must be arithmetic\");\n\tstatic_assert(std::is_arithmetic::value, \"result_type must be arithmetic\");\n\n\tstatic const flow_type oo = std::numeric_limits::max();\n\n\tstruct edge\n\t{\n\t\t//int src; // not needed, can be deleted to save memory\n\t\tint dst;\n\t\tint rev;\n\t\tflow_type cap, flowp;\n\n\t\tedge(int src, int dst, int rev, flow_type cap, int flowp) :\n\t\t\t/*src(src),*/ dst(dst), rev(rev), cap(cap), flowp(flowp) {}\n\t};\n\n\tdinic(int n) : adj(n), que(n), level(n), edge_pos(n), flow_id(0) {}\n\n\tint add_edge(int src, int dst, flow_type cap, flow_type rcap = 0)\n\t{\n\t\tadj[src].emplace_back(src, dst, (int) adj[dst].size(), cap, flow_id++);\n\t\tif (src == dst) adj[src].back().rev++;\n\t\tadj[dst].emplace_back(dst, src, (int) adj[src].size() - 1, rcap, flow_id++);\n\t\treturn (int) adj[src].size() - 1 - (src == dst);\n\t}\n\n\tinline bool side_of_S(int u) { return level[u] == -1; }\n\n\tresult_type max_flow(int source, int sink, vector &flow_e)\n\t{\n\t\tresult_type flow = 0;\n\t\twhile (true)\n\t\t{\n\t\t\tint front = 0, back = 0;\n\t\t\tstd::fill(level.begin(), level.end(), -1);\n\t\t\tfor (level[que[back++] = sink] = 0; front < back && level[source] == -1; ++front)\n\t\t\t{\n\t\t\t\tint u = que[front];\n\t\t\t\tfor (const edge &e : adj[u])\n\t\t\t\t\tif (level[e.dst] == -1 && flow_e[rev(e).flowp] < rev(e).cap)\n\t\t\t\t\t\tlevel[que[back++] = e.dst] = 1 + level[u];\n\t\t\t}\n\t\t\tif (level[source] == -1)\n\t\t\t\tbreak;\n\t\t\tstd::fill(edge_pos.begin(), edge_pos.end(), 0);\n\t\t\tstd::function find_path = [&](int from, flow_type res)\n\t\t\t{\n\t\t\t\tif (from == sink)\n\t\t\t\t\treturn res;\n\t\t\t\tfor (int &ept = edge_pos[from]; ept < (int) adj[from].size(); ++ept)\n\t\t\t\t{\n\t\t\t\t\tedge &e = adj[from][ept];\n\t\t\t\t\tif (flow_e[e.flowp] == e.cap || level[e.dst] + 1 != level[from]) continue;\n\t\t\t\t\tflow_type push = find_path(e.dst, std::min(res, e.cap - flow_e[e.flowp]));\n\t\t\t\t\tif (push > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tflow_e[e.flowp] += push;\n\t\t\t\t\t\tflow_e[rev(e).flowp] -= push;\n\t\t\t\t\t\tif (flow_e[e.flowp] == e.cap)\n\t\t\t\t\t\t\t++ept;\n\t\t\t\t\t\treturn push;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn static_cast(0);\n\t\t\t};\n\t\t\tfor (flow_type f; (f = find_path(source, oo)) > 0;)\n\t\t\t\tflow += f;\n\t\t}\n\t\treturn flow;\n\t}\n\n\tresult_type max_flow2(int source, int sink, vector &flow_e)\n\t{\n\t\tresult_type flow = 0;\n\t\tstd::function find_path = [&](int from, flow_type res)\n\t\t{\n\t\t\tlevel[from] = 1;\n\t\t\tif (from == sink)\n\t\t\t\treturn res;\n\t\t\tfor (int &ept = edge_pos[from]; ept < (int) adj[from].size(); ++ept)\n\t\t\t{\n\t\t\t\tedge &e = adj[from][ept];\n\t\t\t\tif (level[e.dst] == 1 || flow_e[e.flowp] == e.cap) continue;\n\t\t\t\tflow_type push = find_path(e.dst, std::min(res, e.cap - flow_e[e.flowp]));\n\t\t\t\tif (push > 0)\n\t\t\t\t{\n\t\t\t\t\tflow_e[e.flowp] += push;\n\t\t\t\t\tflow_e[rev(e).flowp] -= push;\n\t\t\t\t\tif (flow_e[e.flowp] == e.cap)\n\t\t\t\t\t\t++ept;\n\t\t\t\t\treturn push;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn static_cast(0);\n\t\t};\n\t\t\n\t\tfor (bool ok = true; ok; )\n\t\t{\n\t\t\tint it = 0;\n\t\t\tstd::fill(edge_pos.begin(), edge_pos.end(), 0);\n\t\t\tfor (flow_type f; ; ++it)\n\t\t\t{\n\t\t\t\tstd::fill(level.begin(), level.end(), -1);\n\t\t\t\tf = find_path(source, oo);\n\t\t\t\tif (f == 0)\n\t\t\t\t{\n\t\t\t\t\tif (it == 0) ok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tflow += f;\n\t\t\t}\n\t\t}\n\t\treturn flow;\n\t}\n\n\tint flow_id;\nprivate:\n\tstd::vector> adj;\n\tstd::vector que;\n\tstd::vector level;\n\tstd::vector edge_pos;\n\n\tinline edge& rev(const edge &e) { return adj[e.dst][e.rev]; }\n};\n\nconst int inf = 25;\n\nstruct edge\n{\n\tint u, v, w;\n};\n\nmt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());\n\nvoid relabel(int n, vector &e, int k)\n{\n\tshuffle(e.begin() + k, e.end(), rng);\n\n\tvector>> adj(n);\n\tfor (auto &i : e)\n\t\tadj[i.u].push_back({ i.v, &i-&e[0] });\n\n\tvector ne = e;\n\tvector id(n, -1);\n\tid[0] = 0;\n\tid[n-1] = n-1;\n\tint sz = 1, esz = k;\n\n\tfunction dfs = [&](int u)\n\t{\n\t\tfor (auto &v : adj[u])\n\t\t{\n\t\t\tif (v.second >= k)\n\t\t\t{\n\t\t\t\tne[esz++] = e[v.second];\n\t\t\t\tv.second = -1;\n\t\t\t}\n\t\t\tif (id[v.first] == -1)\n\t\t\t{\n\t\t\t\tid[v.first] = sz++;\n\t\t\t\tdfs(v.first);\n\t\t\t}\n\t\t}\n\t};\n\tdfs(0);\n\t\n\tfor (auto &u : adj)\n\t\tfor (auto v : u)\n\t\t\tif (v.second >= k)\n\t\t\t\tne[esz++] = e[v.second];\n\t\n\tfor (int i = 0; i < n; ++i)\n\t\tif (id[i] == -1)\n\t\t\tid[i] = sz++;\n\t\t\t\n\te = ne;\n\tfor (auto &i : e)\n\t{\n\t\ti.u = id[i.u];\n\t\ti.v = id[i.v];\n\t}\n}\n\nstruct masks\n{\n\tint x, cost;\n\tvector flow_e;\n\t\n\tbool operator<(const masks &o) const\n\t{\n\t\treturn cost < o.cost;\n\t}\n};\n\ntypedef std::chrono::_V2::system_clock::time_point timepoint;\n\ntimepoint get_time()\n{\n\treturn std::chrono::high_resolution_clock::now();\n}\n\nint get_elapsed(timepoint t)\n{\n\treturn std::chrono::duration_cast(get_time() - t).count();\n}\n\nint main()\n{\n\tios_base::sync_with_stdio(0), cin.tie(0);\n\n\tint n, m, k, q;\n\tcin >> n >> m >> k >> q;\n\tvector e(m);\n\tfor (auto &i : e) cin >> i.u >> i.v >> i.w, --i.u, --i.v;\n\n\tvector mask(1 << k, -1);\n\t\n\trelabel(n, e, k);\n\tdinic d(n);\n\tfor (int i = 0; i < m; ++i)\n\t\td.add_edge(e[i].u, e[i].v, ((i < k) ? inf : e[i].w));\n\n\tvector flow_e(d.flow_id);\n\tfor (int i = 0; i < k; ++i)\n\t\tflow_e[2*i] = inf;\n\n\tmask[0] = d.max_flow(0, n-1, flow_e);\n\t\n\tpriority_queue pq;\n\tpq.push({ 0, 0, flow_e });\n\twhile (!pq.empty())\n\t{\n\t\tint x = pq.top().x;\n\t\tflow_e = pq.top().flow_e;\n\t\tpq.pop();\n\t\t\n\t\tfor (int j = 0; j < k; ++j)\n\t\t\tif ((~x >> j & 1) && mask[x | 1 << j] == -1)\n\t\t\t{\n\t\t\t\tauto n_flow_e = flow_e;\n\t\t\t\tn_flow_e[2 * j] = 0;\n\t\t\t\tauto t = get_time();\n\t\t\t\tmask[x | 1 << j] = mask[x] + d.max_flow2(0, n-1, n_flow_e);\n\t\t\t\tpq.push({ x | 1 << j, get_elapsed(t), n_flow_e });\n\t\t\t}\n\t}\n\n\tvector cut(1 << k), bit(1 << k);\n\tfor (int i = 1; i < 1 << k; ++i)\n\t\tbit[i] = i & -i;\n\n\tconst int U = (1 << k) - 1;\n\twhile (q--)\n\t{\n\t\tfor (int i = 0; i < k; ++i)\n\t\t\tcin >> cut[1 << i];\n\n\t\tint ans = mask[U];\n\t\tfor (int i = 1; i < 1<\nusing namespace std;\nint main()\n{\n \n int n,m;\n cin>>n>>m;\n int arr[m];\n for(int i=0;i>arr[i];\n \n }\n sort(arr,arr+m);\n int a=arr[n-1]-arr[0];\n for(int i=1;i<=m-n;i++)\n {\n a=min(a,arr[n+i-1]-arr[i]);\n \n \n }\n cout<\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 \ntypedef long long ll ;\n#define fi first\n#define se second\n#define mp make_pair\n#define rep(i, a, b) for (int i = a; i < b; ++ i) \nconst int N = 1e5 + 5, M = 1e5 ;\nusing namespace std ;\ntypedef pair > state;\n\nll myrand() {\n\treturn ((ll)(rand()&65535)<<32)+((ll)rand()<<16)+rand();\n}\nstate st1[N],st2[N];\nint vis[N],dis[N],off,pre[N],n,deg[N],deg2[N],u,v,ret[N];\nvector e[N],e2[N];\nbitset<10100> adj[10100];\nset hs;\npair E[N];\n\nvoid del(int u) {\n\toff+=1;\n\tdis[u]=1;\n\ths.erase(st1[u]);\n\tfor (auto v:e[u]) if (!dis[v]) {\n\t\ths.erase(st1[v]);\n\t\tst1[v].fi++;\n\t\ths.insert(st1[v]);\n\t}\n}\n\nbool gao0() {\n\trep(i,1,n+1) pre[i]=i;\n\trandom_shuffle(pre+1,pre+n+1);\n\trep(i,1,n) if (adj[pre[E[i].fi]][pre[E[i].se]]) return 0;\n\trep(i,1,n+1) ret[pre[i]]=i;\n\tputs(\"Yes\");\n\trep(i,1,n+1) printf(\"%d \",ret[i]+n);\n\tputs(\"\");\n\treturn 1;\n}\nbool gao() {\n\ths.clear(); off=0;\n\trep(i,1,n+1) {\n\t\tst1[i]=mp(deg[i],mp(myrand(),i));\n\t\tst2[i]=mp(deg2[i],mp(myrand(),i));\n\t\ths.insert(st1[i]);\n\t\tvis[i]=0; dis[i]=0;\n\t}\n\n\trep(i,1,n+1) pre[i]=0;\n\n\n\tstate val=st2[1];\n\trep(i,2,n+1) val=min(val,st2[i]);\n\n\tpriority_queue, greater > q;\n\t\n\tq.push(val);\n\tpre[val.se.se]=hs.begin()->se.se;\n\tvis[val.se.se]=1;\n\n\tdel(hs.begin()->se.se);\n\twhile (!q.empty()) {\n\t\tstate st=q.top(); q.pop();\n\t\tint u=st.se.se;\n\t\tint w=pre[u];\n\t\tfor (auto v:e2[u]) if (!vis[v]) {\n\t\t\tst2[v].fi--; vis[v]=1;\n\t\t\tvector tmp;\n\t\t\twhile (1) {\n\t\t\t\tauto it=hs.lower_bound(mp(st2[v].fi+off,mp(-1,-1)));\n\t\t\t\tif (it==hs.end()) return 0;\n\t\t\t\tif (adj[w][it->se.se]) {\n\t\t\t\t\ttmp.push_back(*it);\n\t\t\t\t\ths.erase(it);\n\t\t\t\t} else {\n\t\t\t\t\tpre[v]=it->se.se;\n\t\t\t\t\tfor (auto p:tmp) hs.insert(p);\n\t\t\t\t\tdel(it->se.se);\n\t\t\t\t\tq.push(st2[v]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\trep(i,1,n+1) ret[pre[i]]=i;\n\tputs(\"Yes\");\n\trep(i,1,n+1) printf(\"%d \",ret[i]+n);\n\tputs(\"\");\n\treturn 1;\n}\n\nint main() {\n\tscanf(\"%d\",&n);\n\trep(i,1,n+1) deg[i]=n-1;\n\trep(i,1,n) {\n\t\tscanf(\"%d%d\",&u,&v);\n\t\te[u].push_back(v),e[v].push_back(u);\n\t\tadj[u][v]=adj[v][u]=1;\n\t\tdeg[u]--; deg[v]--;\n\t}\n\trep(i,1,n) {\n\t\tscanf(\"%d%d\",&u,&v); u-=n; v-=n;\n\t\te2[u].push_back(v); e2[v].push_back(u);\n\t\tE[i]=make_pair(u,v);\n\t\tdeg2[u]++; deg2[v]++;\n\t}\n\trep(i,1,n+1) if (deg[i]==0||deg2[i]==n-1) {\n\t\tputs(\"No\");\n\t\treturn 0;\n\t}\n\twhile (1) {\n\t\tif (gao()) return 0;\n\t\tif (gao0()) return 0;\n\t}\n\tputs(\"No\");\n}", "src_uid": "cdfe11f58ae66e4eef935543236f5098"} {"source_code": "#include\nusing namespace std;\nstring s;\nint main()\n{\n\tgetline(cin,s);\n\tfor(int i=s.size()-1;i>=0;i--)\n\t{\n\t\tif(s[i]>='a'&&s[i]<='z')\n\t\t{\n\t\t\tif(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y')\n\t\t\tcout<<\"YES\";\n\t\t\telse\n\t\t\tcout<<\"NO\";\n\t\t\treturn 0;\n\t\t}\n\t\tif(s[i]>='A'&&s[i]<='Z')\n\t\t{\n\t\t\tif(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='Y')\n\t\t\tcout<<\"YES\";\n\t\t\telse\n\t\t\tcout<<\"NO\";\n\t\t\treturn 0;\n\t\t}\n\t}\n}", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"} {"source_code": "#include\nusing namespace std;\n\n\n\nint main(){\n\n int n,cnt = 0;\n cin >> n;\n string str;\n cin >> str;\n for(int i = 0; i < str.size()-1; i++){\n while(str[i]==str[i+1]){\n cnt++;\n i++;\n }\n }\n cout << cnt << endl;\n return 0;\n}", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"source_code": "// New Year and North Pole.cpp : main project file.\n\n\n\n\n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tlong int a = 0, b, c = 0, d=0, n,f=0;\n\tstring s1;\n\tcin >> n;\n\tfor (long int i = 1; i <= n; i++)\n\t{\n\t\ta = 0;\n\t\tcin >> a;\n\t\tcin >> s1;\n\t\tif (d == 0)\n\t\t{\n\t\t\tif (s1 != \"South\" )\n\t\t\t{\n\t\t\t\tf = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a > 20000)\n\t\t\t\t{\n\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\td = a;\n\t\t\t}\n\t\t\t\t\n\t\t}\n\t\telse\n\t\t{\n\t\tif (d == 20000)\n\t\t{\n\n\t\t\tif (s1 != \"North\")\n\t\t\t{\n\t\t\t\tf = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t\n\t\t\t\tif (a > 20000)\n\t\t\t\t{\n\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\td = 20000 - a;\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t}\n\t\t\t\t\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (s1 == \"North\")\n\t\t\t{\n\t\t\t\td -= a;\n\t\t\t\tif (d < 0)\n\t\t\t\t\tf = 1;\n\t\t\t}\n\t\t\tif (s1 == \"South\")\n\t\t\t{\n\t\t\t\td += a;\n\n\t\t\t\tif (d > 20000)\n\t\t\t\t\tf = 1;\n\t\t\t}\n\n\t\t}\n\t\t\t\t\n\t\t}\n\t}\n\tif (d == 0 && f==0) \n\t{\n\t\tcout << \"YES\";\n\t}\n\telse\n\t{\n\t\tcout << \"NO\";\n\n\t}\n\n\treturn 0;\n}\n", "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n\tint n,m,i,j,a,b,t1=999999,t2=999999,t3=999999,t4=999999,q1=0,q2=0,q3=0,q4=0;\n\tcin>>n>>m>>i>>j>>a>>b;\n\t////////////////////////\n\tint x1=i-1,x2=n-i,y1=j-1,y2=m-j;\n\t////左上角\n\tif(n<=a && m!=1 && j!=1 && j!=m && a!=0) cout<<\"Poor Inna and pony!\"<\n#include \n#include \n\nusing namespace std;\nusing namespace __gnu_pbds;\n\nusing ll = long long;\nusing db = double;\nusing pii = pair < int, int >;\nusing pll = pair < ll, ll >;\n\ntemplate < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;\ntemplate < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;\n\n#ifndef ONLINE_JUDGE\n#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate < typename Arg1 >\nvoid __f(const char* name, Arg1&& arg1) {\n\tcerr << name << \" : \" << arg1 << std :: endl;\n}\ntemplate < typename Arg1, typename... Args >\nvoid __f(const char* names, Arg1&& arg1, Args&&... args) {\n\tconst char* comma = strchr(names + 1, ',');\n\tcerr.write(names, comma - names) << \" : \" << arg1 << \" | \";\n\t__f(comma + 1, args...);\n}\n#else\n#define trace(...)\n#endif\n\n#define eb emplace_back\n#define mp make_pair\n#define mt make_tuple\n#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)\n\nconst db PI = acos(-1);\nconst ll LINF = LLONG_MAX;\nconst int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;\n\nvoid testCase();\n\nint main() {\n\tfastIo();\n\ttestCase();\n\tcerr << \"Time taken: \" << int((clock() * 1000.) / CLOCKS_PER_SEC) << \"ms\\n\";\n\treturn 0;\n}\n\nvoid testCase() {\n\tint a, b;\n\tcin >> a >> b;\n\ta <<= 1;\n\tb <<= 1;\n\tint x1, y1, x2, y2;\n\tcin >> x1 >> y1 >> x2 >> y2;\n\tauto up = [&](int x, int y) {\n\t\treturn int(ceil(db(y - x) / b));\n\t};\n\tauto down = [&](int x, int y) {\n\t\treturn int(floor(db(y - x) / b));\n\t};\n\tauto left = [&](int x, int y) {\n\t\treturn int(floor(db(y + x) / a));\n\t};\n\tauto right = [&](int x, int y) {\n\t\treturn int(ceil(db(y + x) / a));\n\t};\n\tint u = max(up(x1, y1), up(x2, y2));\n\tint d = min(down(x1, y1), down(x2, y2));\n\tint l = min(left(x1, y1), left(x2, y2));\n\tint r = max(right(x1, y1), right(x2, y2));\n\tcout << max((u - d - 1), (r - l - 1)) << \"\\n\";\n}", "src_uid": "7219d1837c83b5920992aee5a60dc0d9"} {"source_code": "#include \n#include \nusing namespace std;\nlong long firbit(long long x)\n{\n long long res=0;\n long long ss=x;\n int arr[50]={};\n int k=0;\n while(ss>0)\n {\n arr[k]=ss%2;\n ss/=2;\n k++;\n }\n/* for(int ii=0;ii<50;ii++)\n {\n cout<>n;\ndouble x;\nlong long xx;\nlong long res=-1;\nlong long bb;\nfor(int i=1;i<=100;i++)\n{\n x=sqrt(i*i+4*n);\n xx=x;\n\n if(xx==x)\n {\n bb=(x-i)/2;\n if(i==sum(bb))\n {\n res=bb;\n break;\n }\n // cout<\nusing namespace std;\nint main()\n{\n int a, x, y;\n int sum;\n cin>>a>>x>>y;\n bool flag = true;\n if(y % a == 0 || x < -a || x > a)\n flag = false;\n else\n {\n int step = y / a + 1;\n if(step == 1 || step == 2)\n {\n if(x >= a / 2.0 || x <= -a / 2.0)\n flag = false;\n else\n sum = step;\n }\n else \n {\n\n int num1 = step / 2;\n int num2 = step - num1;\n sum = num1 * 2 + num2 - 1;\n if(step % 2 == 0)\n {\n if(x <= -a / 2.0 || x >= a / 2.0)\n flag = false;\n }\n else\n {\n if(x <= -a || x >= a || !x)\n flag = false;\n if(x > 0)\n sum++;\n }\n \n }\n }\n cout<< (flag? sum: -1)<\nusing namespace std;\ntypedef long long ll;\ntypedef pair ii;\ntypedef vector vii;\ntypedef vector vi;\ntypedef vector vll;\n#define FOR(i,n) for (i = 0; i < n; ++i)\n#define FORK(i,k,n) for (i = k; i <= n; ++i)\n#define FORR(i,k,n) for (i = k; i >= n; --i)\n\n#define re(a,b) memset(a,b,sizeof(a))\n#define sz(a) (int)(a.size())\n#define MIN(a,b) (a) = min((a),(b))\n#define MAX(a,b) (a) = max((a),(b))\n#define input(in) freopen(in,\"r\",stdin)\n#define output(out) freopen(out,\"w\",stdout)\n#define ALL(a) a.begin(),a.end()\n#define RALL(a) a.rbegin(),a.rend()\n#define LEN(a) (int)(a.length())\n\n#define FIN(x) freopen(x,\"r\",stdin)\n#define FOUT(x) freopen(x,\"w\",stdout)\n#define FCLOSE {fclose(stdin); fclose(stdout);}\n\n#define fi first\n#define se second\n#define pb push_back\n#define mp make_pair\n#define M 100001\n#define INF 90001001001\nint main()\n{\n ll n,k,a,j=1,m,f;\n cin >> n >> k;\n a=n*k;\n ll ans=INF;\n while(j\n#define re register\n#define ui unsigned int\nconst double pi=3.14159265358979323846264338327950;\nint x1[100100],x2[100100],qq[200100];\nconst int maxn=(1<<20)+1;\nstruct com\n{\n\tdouble a,b;\n\tinline com operator +(const com&A){return(com){a+A.a,b+A.b};}\n\tinline void operator +=(const com&A){a+=A.a,b+=A.b;}\n\tinline com operator -(const com&A){return(com){a-A.a,b-A.b};}\n\tinline com operator *(const com&A){return(com){a*A.a-b*A.b,a*A.b+b*A.a};}\n\tinline com operator *(re const double &o) {return (com){a*o,b*o};}\n\tinline com operator /(const int&A){return(com){a/A,b/A};}\n\tinline com operator !(){return(com){a,-b};}\n\tinline bool operator !=(const com&A){return a!=A.a||b!=A.b;}\n};\ncom w[maxn],T1[maxn];\nint getlen(re int n){re int x=1;for(;x>1]&(!(i&1)))||(cp[i>>2]&((i>>1)&1));\n\t}\n}\nvoid fft(com*a,re int len)\n{\n\tre ui i1=0;\n\tre com x1,x2,x3;\n\tfor(re ui i=0,j=0;i>1;;k>>=1)if((j^=k)>=k)break;\n\t}w[0]=(com){1,0};\n\tif(len>=2)\n\t{\n\t\tfor(re ui i=0;i>1])x1=a[i+1],a[i+1]=a[i]-x1,a[i]+=x1;\n\t}\n\tif(len>=4)\n\tfor(re ui i=0;i>2])\n\t\t{\n\t\t\tx1=a[i+2];\n\t\t\tx2=a[i+3];\n\t\t\tx3=(com){-x1.b+x2.b,-x2.a+x1.a};x1+=x2;\n\t\t\ta[i+2]=a[i]-x1;a[i]+=x1;\n\t\t\ta[i+3]=a[i+1]-x3;a[i+1]+=x3;\n\t\t}\n\tw[1]=(com){0,1};w[2]=(com){-1,0};\n\tfor(re ui i=8,i2=3;i<=len;i<<=1,i2++)\n\t{\n\t\ti1=i>>2;\n\t\tcom s=(com){cos(pi/i1/2),sin(pi/i1/2)};\n\t\tfor(re ui j=3*i1-2;j>0;j-=2)\n\t\t\tw[j]=w[j>>1];\n\t\tfor(re ui j=1;j<3*i1;j+=2)\n\t\t\tw[j]=s*w[j-1];\n\t\tfor(re ui j=0;j>i2]){re com*aa=a+j,*aaa=aa+i1,*bb=aaa+i1,*cc=bb+i1;\n\t\t\tfor(re int k=0;k>1)?(com){1,0}-w[i^len>>1]:w[i]+(com){1,0};\n\t\tT1[j]=R1[i]*S1[i]-(R1[i]-!R1[j])*(S1[i]-!S1[j])*tmp*0.25;\n\t}\n}\nvoid IDFT(long long *__ans,int len) {\n\tfft(T1,len);\n\tfor(re int i=0;i>1].b/len+0.5):(long long)(T1[i>>1].a/len+0.5);\n}\nui xx1[270100],xx2[270100];\ncom xr1[200101],xr2[200101];\nlong long ans[270100],res[270100];\nvoid Mul(ui*x1,ui*x2,long long*__ans,int len)\n{\n\tDFT(x1,xr1,len);\n\tDFT(x2,xr2,len);\n\tDFTMul(xr1,xr2,len);\n\tIDFT(__ans,len);\n}\nint main()\n{\n\tinit(131072);\n\tre int n,m,q,len=131072;\n\tscanf(\"%d%d%d\",&n,&m,&q);\n\tfor(re int i=1;i<=n;i++)scanf(\"%d\",&x1[i]);\n\tfor(re int i=1;i<=m;i++)scanf(\"%d\",&x2[i]);\n\tfor(re int i=1;i<=q;i++)scanf(\"%d\",&qq[i]);\n\tfor(re int i=1;i=0;i--)ans[i]+=ans[i+1];\n\tassert(ans[0]==2);\n\tfor(re int i=1;i<=q;i++)printf(\"%lld\\n\",ans[qq[i]]-1);\n}", "src_uid": "25a6428f57022c12dfabdabbcc69c5a4"} {"source_code": "#include \n#include \nusing namespace std;\nlong long buy[101][1010], sell[101][1100], lim[101][1100];\npair tmp[1100];\nint main(){\n long long n, m, k, best = -1;\n cin>>n>>m>>k;\n string junk;\n for(long long x = 0;x>junk;\n for(long long y = 0;y>buy[x][y]>>sell[x][y]>>lim[x][y];\n }\n for(long long x = 0;x=0;z--){\n if(tmp[z].first < 0)\n break;\n if(space >= tmp[z].second){\n space -= tmp[z].second;\n profit += tmp[z].first*tmp[z].second;\n }else{\n profit += tmp[z].first*space;\n break;\n }\n }\n best = max(best, profit);\n }\n }\n cout<\n#include \n#include \n\nusing namespace std;\n\nstruct Cell\n{\n\tint x; int y;\n\tCell(int x = 0, int y = 0) : x(x), y(y) {}\n\tfriend bool operator < (Cell c1, Cell c2)\n\t{\n\t\tif (c1.x == c2.x) return c1.y < c2.y;\n\t\treturn c1.x < c2.x;\n\t}\n\tfriend bool operator == (Cell c1, Cell c2)\n\t{\n\t\treturn (c1.x == c2.x && c1.y == c2.y);\n\t}\n\tfriend bool operator != (Cell c1, Cell c2)\n\t{\n\t\treturn (c1.x != c2.x || c1.y != c2.y);\n\t}\n};\n\nset sc;\nint step[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};\n\nbool find(Cell c, Cell pc)\n{\n\tfor (int i = 0; i < 4; ++i)\n\t\tif ((Cell(c.x+step[i][0], c.y+step[i][1]) != pc))\n\t\t\tif (sc.find(Cell(c.x+step[i][0], c.y+step[i][1])) != sc.end())\n\t\t\t\treturn true;\n\tif (sc.find(c) != sc.end())\n\t\treturn true;\n\treturn false;\n}\n\nint main()\n{\n\tCell cur, pcur;\n\tsc.insert(cur);\n\tstring s;\n\tcin >> s;\n\tfor (int i = 0; i < s.size(); ++i)\n\t{\n\t\tpcur = cur;\n\t\tswitch(s[i])\n\t\t{\n\t\tcase 'U':\n\t\t\t{\n\t\t\t\t++cur.y;\n\t\t\t}break;\n\t\tcase 'D':\n\t\t\t{\n\t\t\t\t--cur.y;\n\t\t\t}break;\n\t\tcase 'L':\n\t\t\t{\n\t\t\t\t--cur.x;\n\t\t\t}break;\n\t\tcase 'R':\n\t\t\t{\n\t\t\t\t++cur.x;\n\t\t\t}break;\n\t\t}\n\t\tif (!find(cur, pcur))\n\t\t\tsc.insert(cur);\n\t\telse\n\t\t{\n\t\t\tcout << \"BUG\" << endl;\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tcout << \"OK\" << endl;\n\n\treturn 0;\n}", "src_uid": "bb7805cc9d1cc907b64371b209c564b3"} {"source_code": "#include \n\nusing namespace std;\n\nint32_t main() {\n\n ios_base::sync_with_stdio(false);\n\n cin.tie(0);\n\n long long n;\n\n cin >> n;\n\n long long res=0;\n\n long long mul=0;\n\n while(n>0) {\n\n if(n-mul>0)\n\n res+=(n-mul);\n\n n--;\n\n mul++;\n\n }\n\n cout << res << '\\n';\n\n return 0;\n\n}\n\n", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\ntypedef long double ld;\n#define REP(i,a,b) for(ll i=a; i\n#define ff first\n#define ss second\n#define INF 100000000000000000LL\nll insig;\n#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}\nvoid Out(vector x) {REP(i,0,x.size()) {cout<>N>>M>>L>>R;\n if(N%2==1 && M%2==1) {ll ans=fastexp((R-L+1LL),N*M,mod); if(ans<0LL) {ans+=mod;} cout<\n using namespace std;\n #define sz(a) (int)(a.size())\n #define all(a) a.begin(),a.end()\n typedef unsigned long long llu;\n typedef long long ll;\n typedef vector vll;\n typedef vector vi;\n typedef vector vb;\n typedef vector> vvi ;\n typedef pair pi;\n typedef vector> vpi ;\n #define F first \n #define S second\n #define pb push_back \n #define mp make_pair\n #define nl cout<<\"\\n\";\n #define int ll\n #ifdef LOCAL\n #include \"debug.h\"\n #else\n #define debug(...) 42\n #endif\n const int mod=1e9+7;\n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());\n template istream& operator>>(istream& input,pair& x) {input>>x.F>>x.S;return input;}\n template istream& operator>>(istream& input,vector& x) {for(auto& i:x)\tinput>>i;return input;}\n templateostream& operator<<(ostream& output,vector& x) {for(auto& i:x)\toutput<a,pairb){ return (a.S> n ;\n\t\t\n\t\tll ans = ceil(n*1.0/2);\n\t\t\n\t\tcout << ans ;\n\n\t\t\n \n }\n /*************----------------------------******************/\n signed main(){\n \tios_base::sync_with_stdio(false);\n \tcin.tie(0);\n \tint tc=1;\n \t\n \t//~ cin>>tc;\n \tfor(int _=0;_ 0){ \n \t\t if(b & 1)res = res*a; \n \t\t a = a *1ll*a; \n \t\t b >>= 1; \n \t } \n return res;\n }\n int powz(int a,int b)\n {\n \tint res=1;\n \twhile(b)\n \t{\n \t\tif(b&1)res=mul(res,a);\n \t\tb/=2;\n \t\ta=mul(a,a);\n \t}\n \treturn res;\n }\n int gcd(int a ,int b){\n \tif(b ==0)return a;\n \treturn gcd(b,a%b);\n }\n int sub(int a,int b){\n \ta-=b;\n \tif(a<0){\n \t\ta+=mod;\n \t}\n \treturn a;\n }\n int mul(int a,int b)\n {\n \treturn ((a)*1ll*(b))%mod;\n }\n void add(int &a,int b)\n {\n \ta+=b;\n \tif(a>=mod)a-=mod;\n }\n", "src_uid": "30e95770f12c631ce498a2b20c2931c7"} {"source_code": "#include \ntypedef long long LL;\nconst int N=(1<<25) +10;\nbool used[N];\n\nint re(int a,int n){\n\tint ans=0;\n\twhile(n--){\n\t\tans<<=1;\n\t\tans+=a&1;\n\t\ta>>=1;\n\t}\n\treturn ans;\n}\nvoid print(int a,int n){\n\ta=re(a,n);\n\twhile(n--){\n\t\tprintf(\"%d\",a&1);\n\t\ta>>=1;\n\t}\n\treturn;\n}\nint M,pow;\nvoid calc(LL k,int i){\n\tfor(int j=0;j0)puts(\"-1\");\n\t\t\telse puts(\"\");\n\t\t}\n\t\telse{\n\t\t\tfor(int i=0;i0)puts(\"-1\");\n\t\t\telse puts(\"\");\n\t\t}\n\t}\n}\n", "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a"} {"source_code": "#include\n#include\nusing namespace std;\nconst int MOD=998244353;\nlong long ksm(long long a,long long b)\n{\n\tlong long res=1;\n\twhile(b)\n\t{\n\t\tif(b&1) res=res*a%MOD;\n\t\ta=a*a%MOD,b>>=1;\n\t}\n\treturn res;\n}\nconst int N=6005;\nlong long fac[N],inv[N];\nvoid init(int n=6000)\n{\n\tfac[0]=1;\n\tfor(int i=1;i<=n;i++)\n\t\tfac[i]=fac[i-1]*i%MOD;\n\tinv[n]=ksm(fac[n],MOD-2);\n\tfor(int i=n;i>=1;i--)\n\t\tinv[i-1]=inv[i]*i%MOD;\n\treturn; \n}\nlong long C(int n,int m)\n{\n\tif(m>n) return 0;\n\tif(m==0||m==n) return 1;\n\treturn fac[n]*inv[m]%MOD*inv[n-m]%MOD;\n}\nlong long calc(int n,int m,int x)\n{\n\tif(m==0)\n\t{\n\t\tif(n==0) return 1;\n\t\telse return 0;\n\t}\n\tlong long res=0;\n\tfor(int i=0;i<=m;i++)\n\t{\n\t\tlong long sum=C(m,i)*C(n-x*i+m-1,m-1)%MOD;\n\t\tif(i&1) res=(res-sum+MOD)%MOD;\n\t\telse res=(res+sum)%MOD; \n\t}\n\treturn res;\n}\nint p,s,r;\nint main()\n{\n\tinit();\n\tscanf(\"%d%d%d\",&p,&s,&r);\n\tif(p==1)\n\t{\n\t\tprintf(\"1\");\n\t\treturn 0;\n\t}\n\tlong long ans=0;\n\tfor(int x=r;x<=s;x++)\n\t{\n\t\tif(x*ps) break;\n\t\t\tif((p-i)*(x-1)+i*x\n#include\nusing namespace std;\nint n,cnt,m=100000000;\nint a[30000000];\nint main(){\n\tcin>>n; \n\tint d;\n\tcin>>d;\n\tfor(int i=1;i<=n;i++){\n\t\tcin>>a[i];\n\t}\n\tsort(a+1,a+n+1);\n\tfor(int i=1;i<=n;i++){\n\t\tfor(int j=i;j<=n;j++){\n\t\t\tif(a[j]-a[i]<=d){\n\t\t\t\tm=min(m,n-j+i-1);\n\t\t\t}\n\t\t}\n\t}\n\tcout<\n#include\n#include\n#include\nusing namespace std;\n//#define\n//queue\n//q.empty()\n//q.size()\n//q.pop()\n//q.front()\n//q.push()\n//q.back()\n//-----------------------------------------------------------------------------------------------------------------------------\n//s.empty()\n//s.pop()\n//s.top()\n//s.push()\n//s.size()\nint main()\n{\n//freopen(\".in\",\"r\",stdin);\n//freopen(\".out\",\"w\",stdout);\nqueueq;\nq.push('h');\nq.push('e');\nq.push('l');\nq.push('l');\nq.push('o');\nchar s[100];\ngets(s);\nint sum=strlen(s);\nfor(int i=0;i\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair Pi;\ntypedef pair Pll;\n\n#define rep(pos, len) for(int pos=0;pos mn, mx;\n\n\tvoid init(int sz) {\n\t\tn = 1;\n\t\twhile(n < sz) n <<= 1;\n\t\tmn.assign(2*n, INF);\n\t\tmx.assign(2*n, -1);\n\t}\n\n\tvoid updateMin(int p, int val) {\n\t\tp += n-1;\n\t\tmn[p] = min(mn[p], val);\n\t\tfor(p>>=1; p; p>>=1) \n\t\t\tmn[p] = min(mn[2*p], mn[2*p+1]);\n\t}\n\n\tvoid updateMax(int p, int val) {\n\t\tp += n-1;\n\t\tmx[p] = max(mx[p], val);\n\t\tfor(p>>=1; p; p>>=1) \n\t\t\tmx[p] = max(mx[2*p], mx[2*p+1]);\n\t}\n\n\tint rangeMin(int l, int r) {\n\t\tint res = INF;\n\t\tfor(l += n-1, r += n-1; l <= r; l>>=1, r>>=1) {\n\t\t\tif(l&1) res = min(res, mn[l++]);\n\t\t\tif(!(r&1)) res = min(res, mn[r--]);\n\t\t}\n\t\treturn res;\n\t}\n\n\tint rangeMax(int l, int r) {\n\t\tint res = -1;\n\t\tfor(l += n-1, r += n-1; l <= r; l>>=1, r>>=1) {\n\t\t\tif(l&1) res = max(res, mx[l++]);\n\t\t\tif(!(r&1)) res = max(res, mx[r--]);\n\t\t}\n\t\treturn res;\n\t}\n\n\tint getMin(int p) {\n\t\treturn mn[p+(n-1)];\n\t}\n\n\tint getMax(int p) {\n\t\treturn mx[p+(n-1)];\n\t}\n};\n\n\nconst int MAXN = 1e5 + 50;\nconst int LOGN = 18;\n\nint r[MAXN];\nint n;\nvoid readInput() {\n\tscanf(\"%d\", &n);\n\trepp(i, n) scanf(\"%d\", &r[i]);\n\trepp(i, n) if(r[i] == n) r[i]--;\n}\n\n\nint findMin(int l, int r, SegmentTree &tree) {\n\tint res = INF;\n\tres = min(res, tree.rangeMin(max(l, 1), min(r, n)) - n);\n\tres = min(res, tree.rangeMin(max(l, n+1)-n, min(r, 2*n)-n));\n\tres = min(res, tree.rangeMin(max(l, 2*n+1)-2*n, min(r, 3*n)-2*n) + n);\n\treturn res;\n}\n\nint findMax(int l, int r, SegmentTree &tree) {\n\tint res = -1;\n\tres = max(res, tree.rangeMax(max(l, 1), min(r, n)) - n);\n\tres = max(res, tree.rangeMax(max(l, n+1)-n, min(r, 2*n)-n));\n\tres = max(res, tree.rangeMax(max(l, 2*n+1)-2*n, min(r, 3*n)-2*n) + n);\n\treturn res;\n}\n\n\nSegmentTree st[LOGN];\n\n// [l, r] -> after 2^k operation\nPi findNext(int l, int r, int k) {\n\tint nl = findMin(l, r, st[k]);\n\tint nr = findMax(l, r, st[k]);\n\tif(nr-nl >= n-1) return {1, n};\n\tif(nl <= 0) {\n\t\tnl += n-1;\n\t\tnr += n-1;\n\t}\n\treturn {nl, nr};\n}\n\nvoid findST() {\n\trep(i, LOGN) st[i].init(n);\n\trepp(i, n) {\n\t\tst[0].updateMin(i, n+i-r[i]);\n\t\tst[0].updateMax(i, min(st[0].getMin(i)+n-1, n+i+r[i]));\n\t}\n\n\tfor(int k = 1; k < LOGN; k++) {\n\t\trepp(i, n) {\n\t\t\tint cl = st[k-1].getMin(i), cr = st[k-1].getMax(i);\n\t\t\tPi p = findNext(cl, cr, k-1);\n\t\t\tst[k].updateMin(i, p.first);\n\t\t\tst[k].updateMax(i, p.second);\n\t\t}\n\t}\n}\n\n\nint solve(int x) {\n\tint res = n-1, cur = 0;\n\tint cl = n+x, cr = n+x;\n\tfor(int k = LOGN-1; k >= 0; k--) {\n\t\tPi p = findNext(cl, cr, k);\n\t\tif(p.second - p.first >= n-1) {\n\t\t\tres = min(res, cur + (1 << k));\n\t\t} else {\n\t\t\tcur += (1 << k);\n\t\t\tcl = p.first;\n\t\t\tcr = p.second;\n\t\t}\n\t}\n\treturn res;\n}\n\n\nint main() {\n\treadInput();\n\tfindST();\n\trepp(i, n) printf(\"%d \", solve(i));\n\t\n\t/*\n\tcout << endl;\n\tfor(int k = 0; k < 5; k++) {\n\t\tcout << k << \"!\" << endl;\n\t\trepp(i, n) printf(\"%d: (%d, %d)\\n\", i, st[k].getMin(i), st[k].getMax(i));\n\t}\n\t*/\n}", "src_uid": "e7dd44bf5e0a0345fd1c40e6957d5641"} {"source_code": "#include\n#define pb push_back\n#define ll long long\n#define popb pop_back\n#define all(A) A.begin(),A.end()\n#define rall(A) A.rbegin(),A.rend()\n#define dic unordered_map\n#define bpc __builtin_popcountll//numero de bits para long long\n#define bclz __builtin_clzll//leading zeros para ll\n#define max_bit(A) 31-__builtin_clz(A)\n\nusing namespace std;\nclass circle{\npublic:\n int x,y,r;\n circle(){\n }\n circle(int _x,int _y,int _r){\n x=_x,y=_y,r=_r;\n }\n bool not_intersect(circle other1,circle other2){\n int left;\n if((r-other1.r)*(r-other2.r)<0) left=0;\n else{\n left=min(abs(r-other1.r),abs(r-other2.r));\n }\n int right=max(r+other1.r,r+other2.r);\n int dsq=(other1.x-x)*(other1.x-x)+(other1.y-y)*(other1.y-y);\n //cout< ring[2];\n\tfor(int t=0;t<2;t++){\n int x,y,r1,r2;\n cin>>x>>y>>r1>>r2;\n ring[t].pb(circle(x,y,r1));\n ring[t].pb(circle(x,y,r2));\n\t}\n\tint ans=0;\n\tfor(int i=0;i<2;i++){\n for(int j=0;j<2;j++){\n if(ring[i][j].not_intersect(ring[(i+1)%2][0],ring[(i+1)%2][1])) ans++;\n }\n\t}\n\tcout<\nusing namespace std;\nstring s[8];\nbool b[8][8];\nint ans;\nint main()\n{\n\tfor(int i=0;i<8;i++)cin>>s[i];\n\tfor(int i=0;i<8;i++)\n\t{\n\t\tbool bb=1;\n\t\tfor(int j=0;j<8;j++)if(s[i][j]=='W'){bb=0;break;}\n\t\tif(bb==0)continue;\n\t\tbb=0;\n\t\tfor(int j=0;j<8;j++)if(!b[i][j]){bb=1;break;}\n\t\tif(bb)\n\t\t{\n\t\t\tfor(int j=0;j<8;j++)if(s[i][j]=='B')b[i][j]=1;\n\t\t\tans++;\n\t\t}\n\t}\n\tfor(int i=0;i<8;i++)\n\t{\n\t\tbool bb=1;\n\t\tfor(int j=0;j<8;j++)if(s[j][i]=='W'){bb=0;break;}\n\t\tif(bb==0)continue;\n\t\tbb=0;\n\t\tfor(int j=0;j<8;j++)if(!b[j][i]){bb=1;break;}\n\t\tif(bb)\n\t\t{\n\t\t\tfor(int j=0;j<8;j++)if(s[j][i]=='B')b[j][i]=1;\n\t\t\tans++;\n\t\t}\n\t}\n\tprintf(\"%d\",ans);\n}//HK is a part of China!!!", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"source_code": "#include\n\nusing namespace std;\n\nint main()\n{\n\tint n;\n\t\n\tscanf(\"%d\", &n);\n\t\n\tif(n <= 3){\n\t\tprintf(\"%d\\n\", n + 1);\n\t}\n\n\telse{\n\t\tint d = sqrt(n);\n\t\tif(d * d == n){\n\t\t\tprintf(\"%d\\n\", 2 * d);\n\t\t}\n\t\telse{\n\t\t\tint a = d + 1;\n\t\t\tif(n < d * d + a){\n\t\t\t\tprintf(\"%d\\n\", a + d);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tprintf(\"%d\\n\", a + d + 1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn 0;\n}", "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"source_code": "#include\nint main()\n{\n__int64 a,b,c,d,r1,r2,c1,c2,d1,d2;\nwhile (scanf(\"%I64d%I64d%I64d%I64d%I64d%I64d\",&r1,&r2,&c1,&c2,&d1,&d2)!=EOF)\n {\nfor(a=1;a<=9;a++)\n{\n b=r1-a;\n c=c1-a;\n d=r2-c;\n if((a+d==d1)&&(b+d==c2)&&(b+c==d2)&&(a!=b)&&(a!=c)&&(a!=d)&&(b!=c)&&(b!=d)&&(c!=d)&&(a>0)&&(b>0)&&(c>0)&&(d>0)&&b<=9&&c<=9&&d<=9)\n {\n printf(\"%I64d %I64d\\n\",a,b);\n printf(\"%I64d %I64d\\n\",c,d);\n break;\n }\n}\nif(a==10)\n printf(\"-1\\n\");\n }\nreturn 0;\n}//2019-01-25 14:56:16.071", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"source_code": "#include\nusing namespace std;\nint main(){\n \n int a,b,c,k=0;\n cin>>a>>b>>c;\n if(a+b<=c)\n k+=c-(a+b)+1;\n if(b+c<=a)\n k+=a-(b+c)+1;\n if(a+c<=b)\n k+=b-(a+c)+1;\n cout<\n\nconst int INF = 1e9;\nint d[77][77][77][2];\nint N;\nstd::vector ch[111];\n\nint nRemain(const std::vector& list, int lb, int threshold) {\n\tint ret = 0;\n\tfor (int i = lb; i < list.size() && list[i] < threshold; ++i) {\n\t\tret += 1;\n\t}\n\treturn ret;\n}\n\nint main() {\n\tstd::ios::sync_with_stdio(false);\n\n\tstd::cin >> N;\n\n\tstd::string S;\n\tstd::cin >> S;\n\tfor (int i = 0; i < N; ++i) {\n\t\tif (S[i] == 'V' || S[i] == 'K') {\n\t\t\tch[S[i]].push_back(i);\n\t\t} else {\n\t\t\tch['X'].push_back(i);\n\t\t}\n\t}\n\n\tfor (int i = 0; i <= N; ++i) {\n\t\tfor (int j = 0; j <= N; ++j) {\n\t\t\tfor (int k = 0; k <= N; ++k) {\n\t\t\t\tfor (int l = 0; l < 2; ++l) {\n\t\t\t\t\td[i][j][k][l] = INF;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\td[0][0][0][0] = 0;\n\tfor (int v = 0; v <= ch['V'].size(); ++v) {\n\t\tfor (int k = 0; k <= ch['K'].size(); ++k) {\n\t\t\tfor (int x = 0; x <= ch['X'].size(); ++x) {\n\t\t\t\tauto count = [&] (int pos) {\n\t\t\t\t\treturn nRemain(ch['V'], v, pos) + nRemain(ch['K'], k, pos) + \n\t\t\t\t\t\tnRemain(ch['X'], x, pos);\n\t\t\t\t};\n\t\t\t\tfor (int isLastV = 0; isLastV < 2; ++isLastV) {\n\t\t\t\t\tint oldValue = d[v][k][x][isLastV];\n\t\t\t\t\tif (v < ch['V'].size()) {\n\t\t\t\t\t\td[v + 1][k][x][1] = std::min(d[v + 1][k][x][1],\n\t\t\t\t\t\t\t\toldValue + count(ch['V'][v]));\n\t\t\t\t\t}\n\t\t\t\t\tif (k < ch['K'].size() && isLastV == 0) {\n\t\t\t\t\t\td[v][k + 1][x][0] = std::min(d[v][k + 1][x][0], \n\t\t\t\t\t\t\t\toldValue + count(ch['K'][k]));\n\t\t\t\t\t}\n\t\t\t\t\tif (x < ch['X'].size()) {\n\t\t\t\t\t\td[v][k][x + 1][0] = std::min(d[v][k][x + 1][0],\n\t\t\t\t\t\t\t\toldValue + count(ch['X'][x]));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint ans = INF;\n\tfor (int isLastV = 0; isLastV < 2; ++isLastV) {\n\t\tint V = ch['V'].size();\n\t\tint K = ch['K'].size();\n\t\tint X = ch['X'].size();\n\t\tans = std::min(ans, d[V][K][X][isLastV]);\n\t}\n\tstd::cout << ans << '\\n';\n\treturn 0;\n}\n", "src_uid": "08444f9ab1718270b5ade46852b155d7"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n\n#define N 100010\nusing namespace std;\n\nint a[N],n,k,x,y,now;\ndouble ans;\ndouble dis(int z)\n{\n return sqrt((double)(x-z)*(double)(x-z)+(double)(y)*(double)(y));\n}\nint main()\n{\n scanf(\"%d%d\",&n,&k);\n for(int i=1;i<=n;i++) \n scanf(\"%d\",&a[i]);\n scanf(\"%d%d\",&x,&y);\n now=a[k];\n sort(a+1,a+n+1);\n if(k==n+1)\n {\n ans=a[n]-a[1]+min(dis(a[1]),dis(a[n]));\n printf(\"%.8lf\\n\",ans);exit(0);\n }\n ans=a[n]-a[1]+min(dis(a[n])+abs(now-a[1]),dis(a[1])+abs(now-a[n]));\n for(int i=1;i<=n;i++)\n {\n if(i>1) ans=min(ans,a[i-1]-a[1]+min(dis(a[i-1])+abs(now-a[1]),dis(a[1])+abs(now-a[i-1]))+a[n]-a[i]+min(dis(a[i]),dis(a[n])));\n if(i\r\n#define int long long\r\n#define endl '\\n'\r\n#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)\r\nusing namespace std;\r\nconst int INF = 0x3f3f3f3f3f3f3f3f;\r\nconst int N = 1e6 + 10;\r\nconst int mod = 1e9 + 7;\r\ntypedef pair PII;\r\nint n;\r\nint a[N];\r\n\r\nint lcm(int a, int b) {\r\n\treturn a * b / __gcd(a, b) % mod;\r\n}\r\nint primes[N], cnt; // primes[]存储所有素数\r\nint euler[N]; // 存储每个数的欧拉函数\r\nbool st[N]; // st[x]存储x是否被筛掉\r\nvoid get_eulers(int n) {\r\n\teuler[1] = 1;\r\n\tfor (int i = 2; i <= n; i ++ ) {\r\n\t\tif (!st[i]) {\r\n\t\t\tprimes[cnt ++ ] = i;\r\n\t\t\teuler[i] = i - 1;\r\n\t\t}\r\n\t\tfor (int j = 0; primes[j] <= n / i; j ++ ) {\r\n\t\t\tint t = primes[j] * i;\r\n\t\t\tst[t] = true;\r\n\t\t\tif (i % primes[j] == 0) {\r\n\t\t\t\teuler[t] = euler[i] * primes[j];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\teuler[t] = euler[i] * (primes[j] - 1);\r\n\t\t}\r\n\t}\r\n}//筛法求欧拉函数\r\nvectorfact[N];\r\nvoid solve() {\r\n\tcin >> n;\r\n\tint res = 0;\r\n\tget_eulers(N);\r\n\tfor (int i = 1; i < n - 1; i++) {\r\n\t\tfor (int j = 1; j * j <= n - i; j++) {\r\n\t\t\tif ((n - i) % j == 0) {\r\n\t\t\t\tif((n-i)/j!=1) res = (res + lcm(i, j) * euler[(n - i) / j] % mod) % mod;\r\n\t\t\t\tif(j!=1&&j*j!=(n-i)) res = (res + lcm(i, (n-i)/j) * euler[j] % mod) % mod;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tcout << res << endl;\r\n}\r\n\r\nsigned main() {\r\n\tIOS;\r\n\tint t = 1;\r\n//\tcin >> t;\r\n\tfor (int i = 1; i <= t; i++) {\r\n\t\tsolve();\r\n\t}\r\n}", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb"} {"source_code": "#include\n\nusing namespace std;\ntypedef long long ll;\ntypedef pair PII;\ntemplate T sqr(T x) {return x*x;}\n#define pi acos(-1)\n#define INF 100000000\n#define debug(x) cerr<<#x\"=\"<<(x)<<\"\\n\";\n#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)\n\nmap m;\nint n;\nstring a[200];\nchar tmp[10];\n\nint main() \n{\n\tint i, j, x, y, ans, f;\n\t\n\tscanf(\"%d\", &n);\n\tfor (i = 1; i <= n;i++) \n\t{\n\t\tscanf(\"%s\", tmp);\n\t\ta[i] = tmp;\n\t}\n\tm['R'] = 0;\n\tm['G'] = 1;\n\tm['B'] = 2;\n\tm['Y'] = 3;\n\tm['W'] = 4;\n\tm['1'] = 0;\n\tm['2'] = 1;\n\tm['3'] = 2;\n\tm['4'] = 3;\n\tm['5'] = 4;\n\tans = 100;\n\tfor (int i = 0; i < (1 << 5); i++)\n\t\tfor (int j = 0; j < (1 << 5); j++) \n\t\t{\n\t\t\tf=1;\n\t\t\tfor (int x = 1; x <= n; x++)\n\t\t\t\tfor (int y = x + 1; y <= n; y++) \n\t\t\t\t if (a[x] != a[y]) \n\t\t\t\t {\n\t\t\t\t\t if (a[x][0] != a[y][0] && (((1 << m[a[x][0]]) & i) || ((1 << m[a[y][0]]) & i))) \n\t\t\t\t\t continue;\n\t\t\t\t\t if (a[x][1] != a[y][1] && (((1 << m[a[x][1]]) & j) || ((1 << m[a[y][1]]) & j))) \n\t\t\t\t\t continue;\n\t\t\t\t\t f = 0;\n\t\t\t\t }\n\t\t\tif (f) ans = min(ans,__builtin_popcount(i)+__builtin_popcount(j));\n\t\t}\n\tprintf(\"%d\\n\", ans);\n\t\n\treturn 0;\n}", "src_uid": "3b12863997b377b47bae43566ec1a63b"} {"source_code": "#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\n\nstruct node {\n int c, v;\n};\n\nconst int MAX = 105;\nconst double eps = 1e18;\n\nint l, d, v, g, r;\n\n\nint main() {\n cin >> l >> d >> v >> g >> r;\n double t1, t2;\n t1 = 1.0 * d / v;\n t1 -= (int)(t1 / (g + r)) * (g + r);\n if (t1 >= 0 && t1 < g) t1 = 1.0 * l / v;\n else t1 = 1.0 * l / v + (g + r - t1);\n printf(\"%.6lf\", t1);\n return 0;\n}", "src_uid": "e4a4affb439365c843c9f9828d81b42c"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n long long int n,c=0;\n cin>>n;\n if(n==1)\n {\n cout<<1;\n return 0;\n }\n for(long long int i=1;1;i++)\n {\n if(i*(i+1)/2>=n)\n {\n n-=(i*(i-1))/2;\n c=i-1;\n break;\n }\n }\n cout<\nusing namespace std;\nint n1,n2,n3,n4,n5,n6,n7,n8,x,y,z; \nint main() {\n cin>>n1>>n2>>n3>>n4>>n5>>n6>>n7>>n8;\n x=(n2*n3)/n7/n1;\n y=n4*n5/n1;\n z=n6/n8/n1;\n if(x<=y&&x<=z)\n cout<\nusing namespace std ;\nint main()\n{\n\tlong long n ;\n\tcin>>n;\n\tif(n < 6 || n % 2 != 0)\n\tcout<< 0;\n\telse {\n\t\tif(n%4==0)\n\t\tcout<\n\nusing namespace std;\n//s<>x>>comma>>y;\n//comma as char;\n#define vi vector\n#define vl vector\n#define vll vector\n#define vs vector\n#define vc vector\n#define vf vector\n//#define vb vector\n#define endl \"\\n\"\n#define pb push_back\n#define all(x) x.begin(), x.end()\n#define rall(x) x.rbegin(), x.rend()\n#define MOD 1000000007\n#define speedb ios_base::sync_with_stdio(0); cin.tie(0)\n\n\nint main(){\n speedb;\n\n int n, a;\n vi m;\n cin>>n;\n for(int i =0 ; i < 12; i++){\n\t\tcin>>a;\n\t\tm.pb(a);\n }\n if(n == 0){\n\t\tcout<<0;\n\t\treturn 0;\n }\n sort(rall(m));\n int s = 0;\n for(int i = 0; i < 12; i++){\n\t\ts+=m[i];\n\t\tif(s >= n){\n\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\n#include\nusing namespace std;\n\n#define sd(mark) scanf(\"%d\",&mark)\n#define ss(mark) scanf(\"%s\",mark)\n#define clr(mark) memset(mark,0,sizeof(mark))\n#define setinf(mark) memset(mark,0x3f,sizeof(mark))\n#define setneg(mark) memset(mark,-1,sizeof(mark))\n\n\n\n#ifndef strange\n#define trace(...)\n// #define endl '\\n'\n#define start_routine() \n#define end_routine()\n#endif\ntypedef long long ll; \n//__gcd\n\n\nconst ll infl=0x3f3f3f3f3f3f3f3fLL;\nconst int infi=0x3f3f3f3f;\n#define PI 3.141592653589793238\n#define mod 998244353\n\n\n#define F first \n#define S second\n#define mp make_pair\n#define all(x) x.begin(), x.end()\n#define rall(x) x.rbegin(), x.rend()\n#define trav(a,x) for(auto &a:x)\n#define pii pair\n\n#define pb push_back\n#define int long long\n\n#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)\n#define rep(a,b,c) for(int a=b; a= _b; i--)\n\n#define sz(x) (int)(x).size()\ntypedef pair piii;\ntypedef vector vi;\ntypedef vector vii;\n#define vp vector \n\nint power(int x, int y) \n{ \n if (y == 0) \n return 1; \n int p = power(x, y / 2) % mod; \n p = (p * p) % mod; \n \n return (y % 2 == 0) ? p : (x * p) % mod; \n} \n\nvoid solve(){\n int n;\n cin>> n;\n int dp[n+10];\n dp[0]=1;\n dp[1]=1,dp[2]=2,dp[3]=3,dp[4]=5;\n for(int i=5;i<=n;i++){\n dp[i]=dp[i-1]+dp[i-2];\n dp[i]%=mod;\n }\n int num=dp[n-1];\n // cout<>t;\n \n fr(i,1,t) {\n\t\t// cout<<\"Case #\"<\r\nusing namespace std;\r\n#define FINAL_OUT(x) {cout << (x) << '\\n'; exit(0); }\r\ninline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));\r\n\r\nint const maxn = 100005;\r\nint cntmin[maxn];\r\nint cntmax[maxn];\r\n\r\nvector> starts;\r\n\r\ninline bool check(const string& s, int& idx, int n) {\r\n if (n <= 1)\r\n return true;\r\n if (idx >= s.length())\r\n return false;\r\n vector need = {n / 2, n - n/2};\r\n if (!check(s, idx, need[0]) || !check(s, idx, need[1]))\r\n return false;\r\n vector cnt = {0,0};\r\n starts.emplace_back(idx, 0);\r\n while (idx < s.length() && cnt[0] < need[0] && cnt[1] < need[1]) {\r\n ++cnt[s[idx] - '0'];\r\n ++idx;\r\n }\r\n starts.back().second = idx;\r\n\r\n return (cnt[0] == need[0]) + (cnt[1] == need[1]) == 1;\r\n}\r\n\r\nvoid solve(const string& s, vector& vec, const int l, const int r) {\r\n if (r-l <= 1)\r\n return;\r\n vector lft(r-l);\r\n int mid = (l+r) >> 1;\r\n int i = 0;\r\n int j = mid - l;\r\n int vi = l;\r\n auto [si, lsi] = starts.back();\r\n starts.pop_back();\r\n for (; si < lsi; ++si, ++vi) {\r\n if (s[si] == '0') {\r\n lft[i++] = vec[vi];\r\n } else {\r\n lft[j++] = vec[vi];\r\n }\r\n }\r\n while (i < mid - l)\r\n lft[i++] = vec[vi++];\r\n while (j < r - l)\r\n lft[j++] = vec[vi++];\r\n move(lft.begin(), lft.end(), vec.begin() + l);\r\n solve(s, vec, mid, r);\r\n solve(s, vec, l, mid);\r\n}\r\n\r\nint main()\r\n{\r\n// freopen(\"in.txt\", \"r\", stdin);\r\n// freopen(\"out.txt\", \"w\", stdout);\r\n cout << fixed << setprecision(15);\r\n ios_base::sync_with_stdio(false);\r\n cin.tie(0), cout.tie(0);\r\n\r\n for (int i = 1; i < maxn; ++i) {\r\n int l = i / 2;\r\n int r = i - l;\r\n cntmin[i] = cntmin[l] + cntmin[r] + min(l, r);\r\n cntmax[i] = cntmax[l] + cntmax[r] + l+r-1;\r\n }\r\n\r\n string s;\r\n cin >> s;\r\n\r\n int l = 1;\r\n int r = maxn-1;\r\n while (r-l > 1) {\r\n int mid = (l+r) >> 1;\r\n if (cntmin[mid] > s.length())\r\n r = mid;\r\n else if (cntmax[mid] < s.length())\r\n l = mid;\r\n else {\r\n int idx = 0;\r\n check(s, idx, mid);\r\n if (idx < s.length())\r\n l = mid;\r\n else\r\n r = mid;\r\n }\r\n }\r\n\r\n for (int i = max(1, l - 100); i <= min(maxn - 1, r + 100); ++i)\r\n if (cntmin[i] <= s.length() && s.length() <= cntmax[i]) {\r\n int idx = 0;\r\n starts.clear();\r\n if (check(s, idx, i) && idx == s.length()) {\r\n cout << i << endl;\r\n vector base(i);\r\n iota(base.begin(), base.end(), 1);\r\n idx = 0;\r\n solve(s, base, 0, i);\r\n for (int x : base)\r\n cout << x << ' ';\r\n cout << endl;\r\n return 0;\r\n }\r\n }\r\n assert(false);\r\n}\r\n", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"} {"source_code": "////////////////////////////////////////////////////////////////////////////////////////////////////\n//░▐█▀█▒▐█▀▀█▌▒▐██▄▒▄██▌░▐█▀▀/////▒█▀█▀█▒▐█▀▀█▌/////▒█▀█▀█░▐█░▐█░▐█▀▀///////////////////////////////\n//░▐█──▒▐█▄▒█▌░▒█░▒█░▒█░░▐█▀▀/////░░▒█░░▒▐█▄▒█▌/////░░▒█░░░▐████░▐█▀▀///////////////////////////////\n//░▐█▄█▒▐██▄█▌▒▐█░░░░▒█▌░▐█▄▄/////░▒▄█▄░▒▐██▄█▌/////░▒▄█▄░░▐█░▐█░▐█▄▄///////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//░▐█▀█▄─░▄█▀▄─▒▐█▀▀▄▒▐█▒▐▀/////▒▄█▀▀█░▐██░▐█▀█▄░▐█▀▀///////////////////////////////////////////////\n//░▐█▌▐█░▐█▄▄▐█▒▐█▒▐█▒▐██▌░/////▒▀▀█▄▄─░█▌░▐█▌▐█░▐█▀▀///////////////////////////////////////////////\n//░▐█▄█▀░▐█─░▐█▒▐█▀▄▄▒▐█▒▐▄/////▒█▄▄█▀░▐██░▐█▄█▀░▐█▄▄///////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////+o+/+/-----...--:::///////////////////////////////////////\n////////////////////////////////////::++ohss+///+ooooo:` `...-://///////////////////////////////\n/////////////////////////////////:+sdd/` :o. `-ohhs+/:://///////////////////////////\n////////////////////////////////smdh+` `o: `.://+yy/oshy+:://////////////////////////\n/////////////////////////////:sms-.` .s. `:oydmmmmmmmd `-oyy/::///////////////////////\n///////////////////////////:/do` . :y` .sdmmmmmmmmmmmd `:sho:://///////////////////\n/////////////////////////:./s. . :y` -dmmmmmmmmmmmmm: .oho:////////////////////\n////////////////////////:`-/ -h` `ommmmmmmmmmmmmms -yh////////////////////\n///////////////////////:` . `. .y` /dmmmmmmmmmmmmmmm- `sd///////////////////\n//////////////////////: `/`h/ `s. ommmmmmmmmmmmmmmmh `yh://///////////////\n/////////////////////:` .hhyMs -. /sdmmmmmmh:.....-/ /d+/////////////////\n////////////////////:::` `dNhMM/ -dmmmmmd+` :ds:////////////////\n//////////////////:.:-` .yNMN`` `` :dmmmmmmmmdo- :dy:////////////////\n////////////////:-``` .NMMs--::.` ``` `-/ymmmmmmmmo::/. :dy:////////////////\n///////////////:. ` `.//-``.`...--:--.` `./ymmmmd` /dy:////////////////\n///////////////. . .-``` .-.....-://:--`` -odms +ds:////////////////\n/////////////+: /` :ys:--o+` ./osyyyyys+-:-` -hs +d+/////////////////\n/////////////+ y` .yy:-.:/- `yhhhhhyyyy/ ``-. .s- od//////////////////\n///////////:o` o` :ho`..-`` :hhhhhhhhy: .. `+` yd-/////////////////\n///////////+- -/ :/.-` .. ohhhhhyhy- `:.` `/ `+dh-/////////////////\n//////////:o +` .` --`-/oyyyys- /o-- .- -dds://///////////////\n///////////+ .+so+. `.:-.-::.. `:////` `` -. `ddo://///////////////\n//////////o- `.--yssshs:`+oo: -/:--.`````````` /` ody://///////////////\n//////////y :hhdyydmmmo.`/os: :hhyyso/:. +` .dd//////////////////\n/////////o/ -ddhy-.-++y` ``.` /hhhyhhhs` .+ ody:////////////////\n////////:y. `dhy: :s` ..-syhyyhs` ``` :: `hd+////////////////\n/////////s sy: ` .`/o ..:oyyhs. ````` o` /dy:///////////////\n////////o: o/ `.`.`++++ `:/-:+oy- ```````` .+ yd+///////////////\n///////:y` +/ `.`y/.h`+h/ `/++`:++.-:::-. +. -dh://////////////\n///////++ `..+o...y.+s`y:-h.y- `.---+//:.` o sd+//////////////\n///////o-`yyy+yyhyyhodssd+ys/dh:-.////-``...````````````````` -: .dh://///////////\n///////:.`//::://++oosssyyyyydmmm-..........`````` :- /do:////////////\n/////////:-` `.`.:.-::--::--.. .``` yd/////////////\n////////////:-` .-....:+/://:` ` -ds:///////////\n///////////////:-.` `---.-//-// ``` od////////////\n///////////////////:-.../-.`::` ```` ````` `hy://////////\n////////////////////////:os-.`` ```` ``` .-:::::://- ` :d+//////////\n///////////////////////////- ``` ` .--.. ``` :y//////////\n///////////////////////////:. .:-. `` .//////////\n////////////////////////////- :/- /////////\n////////////////////////////. .:. `-/////////\n///////////////////////////o .........----:////////////\n//////////////::--.....``-: ./////////////////////////\n/////////:-.` . .--` /+////////////////////////\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#pragma GCC optimize (\"O2\")\n#pragma GCC optimize (\"unroll-loops\")\n\n//███╗ ███╗ █████╗ ██████╗ ██╗ ██████╗\n//████╗ ████║██╔══██╗██╔════╝ ██║██╔════╝\n//██╔████╔██║███████║██║ ███╗██║██║\n//██║╚██╔╝██║██╔══██║██║ ██║██║██║\n//██║ ╚═╝ ██║██║ ██║╚██████╔╝██║╚██████╗\n//╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝\n\n#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);\n#define endl std::cout<<\"\\n\";\n#define pause_cout \"std::cout << \"|| ------------------------------------------- ||\"\"\n#define mp make_pair\n#define pb push_back\n#define ff first\n#define ss second\n#define iter iterator\ntypedef long long ll;\ntypedef int ii;\ntypedef long double ld;\nconst ll INF = 1e18;\nconst ll INF_bit = 1e9 - 1;\nconst ld EPS = 0.000000001;\ntypedef unsigned long long ull;\ntypedef std::string str;\ntypedef std::vector vec_chr;\ntypedef std::vector vec_ld;\ntypedef std::vector vec;\ntypedef std::vector vecs;\ntypedef std::bitset bit;\ntypedef std::vector> pvec;\ntypedef std::vector> vec2;\ntypedef std::vector>> vec2_p;\ntypedef std::map map_s_l;\ntypedef std::map map_l_l;\ntypedef std::pair p_l_l;\n#define create_Graph vec2 GR(n,vec())\n#define create_Matrix_GR vec2 GR(n,vec(n,INF))\n#define rfor(i,n) for(int i=n-1;i>=0;i--)\n#define all(x) (x).begin(),(x).end()\n#define for_0(i,n) for(int i=0;i>x)\n#define YES std::cout << \"YES\"\n#define NO std::cout << \"NO\"\n#define write(x) (std::cout< b;\nll gcd(ll a, ll b) {\n\tif (a == 0)return b;\n\tif (a > b)std::swap(a, b);\n\treturn gcd(b % a, a);\n}\nvec_chr prime(110 + 1, true);\n//ll Recheto() {\n//\tprime[0] = prime[1] = false;\n//\tfor_2(i, 2, 110)\n//\t\tif (prime[i])\n//\t\t\tif (i * 1ll * i <= 110)\n//\t\t\t\tfor_3(j, i * j, 110, i)\n//\t\t\t\tprime[j] = false;\n//}\n\nint main() {\n\tll a1, a2, k1, k2, n;\n\tstd::cin >> a1 >> a2 >> k1 >> k2 >> n;\n\tif (k1 > k2) {\n\t\tll f = a1;\n\t\ta1 = a2;\n\t\ta2 = f;\n\t\tf = k1;\n\t\tk1 = k2;\n\t\tk2 = f;\n\t}\n\tll k = std::max(ll(0), ll(n - a1 * (k1 - 1) - a2 * (k2 - 1)));\n\tif (n <= a1 * k1) {\n\t\tstd::cout << k << ' ' << n / k1;\n\t}\n\telse {\n\t\tstd::cout << k << ' ' << a1 + (n - a1 * k1) / k2;\n\t}\n}", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"source_code": "#include \n#include \nint main()\n{\n int x0, y0, x, y;\n float r;\n std::cin >> r >> x0 >> y0 >> x >> y;\n if ( x == x0 && y == y0)\n {\n std::cout<<0;\n return 0;\n }\n double midx = (x + x0) / 2.0;\n double midy = (y + y0) / 2.0;\n double dist = sqrt( pow(double(midy - y0), 2) + pow( double(midx - x0) , 2) );\n\n std::cout << ceil(dist / r);\n}", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long LL;\n\nconst int MAX_SEG = 9765625 * 5; \nconst LL M = (LL)1e13;\nconst int MAX_CIR = 39062500 * 5; \n\nLL A[ 4 ], B[ 4 ], C[ 4 ], D[ 4 ], p;\n\nLL mul( LL a, LL b, LL p) {\n\ta %= p; b %= p;\n\tLL ret=0;\n\twhile(b){\n\t\tif(b&1) if((ret+=a)>=p) ret-=p;\n\t\tif((a<<=1) >= p) a-=p;\n\t\tb>>=1;\n\t}\n\treturn ret;\n}\n\nvoid mul( LL A[ ], LL B[ ], LL C[ ] , LL p){\n C[ 0 ] = (mul(A[ 0 ] , B[ 0 ], p) + mul(A[ 1 ] , B[ 2 ],p)) % p;\n C[ 1 ] = (mul(A[ 0 ] , B[ 1 ],p) + mul(A[ 1 ] , B[ 3 ],p)) % p;\n C[ 2 ] = (mul(A[ 2 ] , B[ 0 ],p) + mul(A[ 3 ] , B[ 2 ],p)) % p;\n C[ 3 ] = (mul(A[ 2 ] , B[ 1 ],p) + mul(A[ 3 ] , B[ 3 ],p)) % p;\n A[ 0 ] = C[ 0 ];\n A[ 1 ] = C[ 1 ];\n A[ 2 ] = C[ 2 ];\n A[ 3 ] = C[ 3 ];\n}\n\nLL fibonacci( LL n , LL p ) {\n\tif(!n) return 0;\n\t-- n;\n // A^n\n // ini matrix A\n A[ 0 ] = A[ 1 ] = A[ 2 ] = 1;A[ 3 ] = 0;\n // D is ans\n D[ 0 ] = D[ 3 ] = 1;\n D[ 1 ] = D[ 2 ] = 0;\n // pow\n while( n ) {\n if( n & 0x1) mul( D, A, C, p) ;\n mul( A, A, C, p) ;\n n >>= 1; \n }\n return D[0];\n}\nvector< int > pos ;\n\nvoid pre(){\n\tint a, b, c,rem = p % MAX_SEG;\n\tpos.clear();\n\ta = 0; if(a == rem ) pos.push_back( 0 );\n\tb = 1; if(b == rem ) pos.push_back( 1 );\n\tint i;\n\tfor(i=2;i<=MAX_CIR;++i){\n\t\tc=a+b;\n\t\tif(c>=MAX_SEG) c-=MAX_SEG;\n\t\tif(c == rem) pos.push_back( i );\n\t\ta=b;\n\t\tb=c;\n\t\tif( pos.size() == 4) break ;\n\t}\n\t//puts(\"ok\");\n}\n\nint main(){\n while(1 == scanf(\"%I64d\", &p)) {\n\t\tif(p <= 1) {\n\t\t cout << (int)p << endl;\n\t\t\tcontinue;\n\t\t}\n\t\tpre();\n\t\tLL ans = (LL) 1e17;\n\t\tint i;\n\t\tfor(i=0;i 1e16) ans = - 1;\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 \nusing namespace std;\n\nconst int maxn = 1e5 * 4;\n\ninline int g() {\n int x;\n cin >> x;\n return x;\n}\n\ninline long long gl() {\n long long x;\n cin >> x;\n return x;\n}\n\ninline char gc() {\n char x;\n cin >> x;\n return x;\n}\n\ninline string gs() {\n string s;\n cin >> s;\n return s;\n}\n\ntemplate\ninline vector gv(int len) {\n vector a(len);\n for (auto &it : a)\n cin >> it;\n return a;\n}\n\ninline vector gv(int len) {\n vector a(len);\n for (auto &it : a)\n cin >> it;\n return a;\n}\n\ninline vector> gv_andPairCnt(int len) {\n vector> a(len);\n int i = 1;\n for (auto &it : a) {\n it.second = i;\n i++;\n cin >> it.first;\n }\n return a;\n}\n\ndouble power_log(double power, double val) {\n return log(val) / log(power);\n}\n\ntemplate \nT sqr(T x) { return x * x; }\n\n#define rep(I, N) for (int I = 0; I < (N); ++I)\n#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)\n\ntemplate \nostream& operator<<(ostream& os, const vector& v) {\n for (auto it : v)\n os << it << \" \";\n os << \"\\n\";\n return os;\n}\n\ntemplate\ninline vector> gv_andBiPair(int len) {\n vector> a(len);\n for (auto &it : a) {\n cin >> it.first >> it.second;\n }\n return a;\n}\n\ntemplate\ninline set vector_to_set(const vector &vec) {\n set s;\n for (auto &it : vec)\n s.insert(it);\n return s;\n}\n\nconst long long md = 1e9 + 7;\n\nint a[501][501];\n\nint main() {\n int n = g(), m = g();\n string s1 = gs(), s2 = gs();\n if(s1[0] == '>' && s1.back() == '<' && s2[0] == '^' && s2.back() == 'v') {\n cout << \"YES\";\n } else if(s1[0] == '<' && s1.back() == '>' && s2[0] == 'v' && s2.back() == '^') {\n cout << \"YES\";\n }else {\n cout << \"NO\";\n }\n}\n", "src_uid": "eab5c84c9658eb32f5614cd2497541cf"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nint main()\n{\n int a, b, c, r=0, i;\n\n scanf(\"%d%d%d\", &a, &b, &c);\n\n for (i=0; i<3; i++)\n r = max(r, min(min(i, a), min(b, c)) + (a-i) / 3 + (b-i) / 3 + (c-i) / 3);\n\n printf(\"%d\\n\", r);\n\n return 0;\n}\n", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\ntypedef long long ll;\n#define mem(Arr,x) memset(Arr,x,sizeof(Arr))\n#define sqr(x) ((x)*(x))\n\nclass Point{\n public:\n ll x,y;\n double len(){\n return sqrt(sqr((double)x)+sqr((double)y));\n }\n ll calc(ll k){\n return x*k+y;\n }\n Point operator + (Point A){\n return ((Point){x+A.x,y+A.y});\n }\n Point operator - (Point A){\n return ((Point){x-A.x,y-A.y});\n }\n};\nclass VData{\n public:\n int v,a,b;\n};\n\nconst int maxN=100002*4;\nconst int maxM=maxN<<1;\nconst int inf=1000000000;\n\nint n,m;\nvector To[maxN],Sn[maxN];\nint edgecnt=-1,Head[maxN],Next[maxM],V[maxM];\npair W[maxM];\nint vis[maxN],rte,rtsize,Sz[maxN],tot[2],anstop=0;\nPoint C[2][maxN],Bp[maxN],St[4000000],Ans[4000000];\n\nvoid dfs_init(int u,int fa);\nvoid Add_Edge(int u,int v,pair w);\nvoid dfs_root(int u,int fa,int size);\nvoid dfs_get(int u,int fa,int opt,ll a,ll b);\nvoid Divide(int u,int size);\ndouble Cross(Point A,Point B);\nbool cmpx(Point A,Point B);\nbool cmpy(Point A,Point B);\nbool cmpc(Point A,Point B);\nostream & operator << (ostream & os,Point A);\nvoid Convex(Point *P,int &T);\ndouble Intersection(Point A,Point B);\n\nint main(){\n scanf(\"%d%d\",&n,&m);mem(Head,-1);\n for (int i=1;i=1&&St[top].x==Ans[i].x) continue;\n while (top>=2&&Intersection(St[top-1],St[top])>=Intersection(St[top],Ans[i])) --top;\n St[++top]=Ans[i];\n }\n /*\n sort(Ans.begin(),Ans.end(),cmpx);\n //for (int i=0,sz=Ans.size();i=1&&St[top].x==Ans[i].x) --top;\n while (top>=2&&Intersection(St[top-1],St[top])>=Intersection(St[top],Ans[i])) --top;\n St[++top]=Ans[i];\n }\n //*/\n for (int i=0,j=1;i=St[j].calc(i)) ++j;\n printf(\"%I64d \",(ll)St[j].calc(i));\n }\n printf(\"\\n\");return 0;\n}\nvoid dfs_init(int u,int fa){\n for (int i=0,sz=To[u].size();i w){\n Next[++edgecnt]=Head[u];Head[u]=edgecnt;V[edgecnt]=v;W[edgecnt]=w;\n Next[++edgecnt]=Head[v];Head[v]=edgecnt;V[edgecnt]=u;W[edgecnt]=w;\n return;\n}\nvoid dfs_root(int u,int fa,int size){\n Sz[u]=1;\n for (int i=Head[u];i!=-1;i=Next[i])\n if (V[i]!=fa&&vis[i>>1]==0){\n dfs_root(V[i],u,size);Sz[u]+=Sz[V[i]];\n int k=max(Sz[V[i]],size-Sz[V[i]]);\n if (k>1]==0) dfs_get(V[i],u,opt,a+W[i].first,b+W[i].second);\n return;\n}\nvoid Divide(int start,int size){\n rtsize=inf;dfs_root(start,start,size);\n if (rtsize==inf) return;\n int u=V[rte],v=V[rte^1];vis[rte>>1]=1;tot[0]=tot[1]=0;\n //cout<0||(C[0][up0+1].y==0&&C[0][up0+1].x>=0))) ++up0;\n while (up10||(C[1][up1+1].y==0&&C[1][up1+1].x>=0))) ++up1;\n //for (int i=1;i<=tot[0];i++) cout<up1||(p0<=up0&&Cross(C[0][p0],C[1][p1])>=0)) ++top,Bp[top]=Bp[top-1]+C[0][p0++];\n else ++top,Bp[top]=Bp[top-1]+C[1][p1++];\n }\n while (p0<=tot[0]||p1<=tot[1]){\n //cout<<\"Compare:\"<tot[1]||(p0<=tot[0]&&Cross(C[0][p0],C[1][p1])>=0)) ++top,Bp[top]=Bp[top-1]+C[0][p0++];\n else ++top,Bp[top]=Bp[top-1]+C[1][p1++];\n }\n\n //for (int i=1;i<=top;i++) cout<B.y;\n}\nbool cmpy(Point A,Point B){\n if (A.y!=B.y) return A.y0||(Cross(A,B)==0&&A.len()=2&&Intersection(St[top-1],St[top])>=Intersection(St[top],P[i])) --top;\n St[++top]=P[i];\n }\n for (int i=top;i>=1;i--) P[i]=St[top-i+1];T=top;\n /*\n Point base=P[1];\n for (int i=2;i<=T;i++) if (cmpy(P[i],base)) base=P[i];\n for (int i=1;i<=T;i++) P[i]=P[i]-base;\n sort(&P[1],&P[T+1],cmpc);int top=0;\n for (int i=1;i<=T;i++){\n while (top>=2&&Cross(P[i]-St[top-1],St[top]-St[top-1])>=0) --top;\n St[++top]=P[i];\n }\n T=top;for (int i=1;i<=top;i++) P[i]=St[i]+base;\n //*/\n return;\n}\ndouble Intersection(Point A,Point B){\n return (double)(B.y-A.y)/(double)(A.x-B.x);\n}", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31"} {"source_code": "#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nconst int maxn = 200;\nconst int INF = 1e9;\nint table[26];\nint cap[maxn][maxn], cost[maxn][maxn];\nint b[100];\n\nint build_network(string s) {\n int n = s.length();\n int size = n/2 + 26 + 2;\n for (int i = 1; i <= 26; i++) {\n cap[0][i] = table[i-1];\n cost[0][i] = 0;\n }\n for (int i = 1; i <= 26; i++) {\n for (int j = 0; j < n/2; j++) {\n cap[i][27+j] = 1;\n char c = i + 'a' - 1;\n if (s[j] == c && s[n-1-j] == c)\n\tcost[i][27+j] = -max(b[j], b[n-1-j]);\n else if (s[j] == c && s[n-1-j] != c)\n\tcost[i][27+j] = -b[j];\n else if (s[j] != c && s[n-1-j] == c)\n\tcost[i][27+j] = -b[n-1-j];\n else\n\tcost[i][27+j] = 0;\n cost[27+j][i] = -cost[i][27+j];\n }\n }\n for (int j = 0; j < n/2; j++) {\n cap[27+j][size-1] = 2;\n cost[27+j][size-1] = 0;\n }\n return size;\n}\n\nint mincost_maxflow(int size) {\n int s = 0;\n int t = size - 1;\n vector d(size);\n vector p(size, -1);\n int flowcost = 0;\n while(true) {\n for (int i = 0; i < size; i++)\n d[i] = INF;\n d[s] = 0;\n for (int i = 0; i < size; i++)\n for (int j = 0; j < size; j++)\n\tfor (int k = 0; k < size; k++)\n\t if (cap[j][k] > 0 && d[j] < INF && d[k] > d[j] + cost[j][k]) {\n\t d[k] = d[j] + cost[j][k];\n\t p[k] = j;\n\t }\n /*for (int i = 0; i < size; i++)\n cout << p[i] << \" \";\n cout << endl;\n for (int i = 0; i < size; i++)\n cout << d[i] << \" \";\n cout << endl;*/\n if (d[t] == INF)\n return flowcost;\n flowcost += d[t];\n //cout << \"flowcost:\" << flowcost << endl;\n int flow = 10000;\n for (int v = t; v != s; v = p[v]) {\n flow = min(flow, cap[p[v]][v]);\n }\n //cout << \"flow:\" << flow << endl;\n for (int v = t; v != s; v = p[v]) {\n cap[p[v]][v] -= flow;\n cap[v][p[v]] += flow;\n }\n }\n}\n\nint main() {\n int n;\n scanf(\"%d\", &n);\n string s;\n cin >> s;\n for (auto c : s) {\n table[c-'a']++;\n }\n for (int i = 0; i < n; i++)\n scanf(\"%d\", &b[i]);\n int size = build_network(s);\n int flowcost = mincost_maxflow(size);\n cout << -flowcost << endl;\n return 0;\n}\n", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50"} {"source_code": "#include \n#include \nusing namespace std;\nvoid String_replacing(string[] , string[]);\nstring password;\nstring newps[8], code[10];\nvoid output();\nint main()\n{\n\tint b = 0;\n\tcin >> password;\n\twhile (b < 8)\n\t{\n\t\t\n\t\tnewps[b] = password.substr(0, 10);\n\t\tpassword.erase(0, 10);\n\t\tb++;\n\t\t\n\t}\n for (int c = 0; c < 10; c++)\n\t\tcin >> code[c];\n String_replacing(newps, code);\n output();\n \n\treturn 0;\n}\nvoid String_replacing(string newps[] , string code[])\n{\n\tfor (int j = 0; j < 8; j++)\n\t{\n\t\tfor (int k = 0; k < 10; k++)\n\t\t{\n\t\t\tif (code[k] == newps[j])\n\t\t\t\tif (k == 0) newps[j].replace(0, 10, \"0\");\n\t\t\t\telse if (k == 1) newps[j].replace(0, 10, \"1\");\n\t\t\t\telse if (k == 2) newps[j].replace(0, 10, \"2\");\n\t\t\t\telse if (k == 3) newps[j].replace(0, 10, \"3\");\n\t\t\t\telse if (k == 4) newps[j].replace(0, 10, \"4\");\n\t\t\t\telse if (k == 5) newps[j].replace(0, 10, \"5\");\n\t\t\t\telse if (k == 6) newps[j].replace(0, 10, \"6\");\n\t\t\t\telse if (k == 7) newps[j].replace(0, 10, \"7\");\n\t\t\t\telse if (k == 8) newps[j].replace(0, 10, \"8\");\n\t\t\t\telse if (k == 9) newps[j].replace(0, 10, \"9\");\n\n\t\t}\n\t}\n}\nvoid output()\n{\n\tfor (int o = 0; o < 8; o++)\n\t\tcout << newps[o];\n}", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "#include \n#include \n#include \n#include \nusing namespace std;\n\ntemplate \nT pow(T a, T e, T mod) {\n\tif(!e) return 1;\n\tT x = pow(a, e/2, mod);\n\tx = x * x % mod;\n\treturn (e&1) ? x * a % mod : x;\n}\n\ntemplate \nT pow(T a, exp_t e) {\n\tif(!e) return 1;\n\tT x = pow(a, e/2);\n\tx = multiply(x, x);\n\treturn (e&1) ? multiply(x, a) : x;\n}\n\ntemplate \nCRT_t CRT(const CRT_t * rem, const CRT_t * p_v, const int * p_e, const int p_n) {\n\t// return e: e % p_v[i]**p_e[i] == rem[i] for 0 <= i < p_n\n\tCRT_t ret = 0, mod = 1;\n\tfor(int i = 0; i < p_n; i++) for(int j = 0; j < p_e[i]; j++) mod *= p_v[i];\n\t// e == (sum rem[i] * c[i]) % prod p_v[i]**p_e[i]\n\tfor(int i = 0; i < p_n; i++) {\n\t\t// pr[i] == prod p_v[j]**p_e[j] for j != i\n\t\t// c[i] == pr[i] * (inverse of pr[i] modulo p_v[i]**p_e[i]) == pr[i] * inv[i]\n\t\tCRT_t pr = mod, pw = 1;\n\t\tfor(int j = 0; j < p_e[i]; j++) pr /= p_v[i], pw *= p_v[i];\n\t\tCRT_t inv = pow(pr % pw, pw - pw / p_v[i] - 1, pw);\n\t\tCRT_t add = inv * rem[i] % pw * pr;\n\t\tif(add >= mod-ret) ret += add-mod;\n\t\telse ret += add;\n\t}\n\treturn ret;\n}\n\ntemplate \nexp_t BSGS(const BSGS_t a, const BSGS_t b, const exp_t order) {\n\texp_t sqrt = 1;\n\twhile(sqrt*sqrt < order) sqrt++;\n\tstatic pair try_small[20000];\n\tstatic pair try_large[20000];\n\tBSGS_t cur = 1;\n\tfor(BSGS_t i = 0; i < sqrt; i++) {\n\t\ttry_small[i] = {cur, i};\n\t\tcur = multiply(cur, a);\n\t}\n\tcur = b;\n\tBSGS_t a_pw = pow(a, order-sqrt);\n\tfor(exp_t i = 0; i < sqrt; i++) {\n\t\ttry_large[i] = {cur, i};\n\t\tcur = multiply(cur, a_pw);\n\t}\n\tsort(try_small, try_small+sqrt);\n\tsort(try_large, try_large+sqrt);\n\tfor(exp_t i = 0, j = 0; i < sqrt; i++) {\n\t\twhile(j < sqrt && try_large[j].first < try_small[i].first) j++;\n\t\tif(j == sqrt) return exp_t(-1);\n\t\tif(try_large[j].first == try_small[i].first)\n\t\t\treturn try_large[j].second * sqrt + try_small[i].second;\n\t}\n\treturn exp_t(-1);\n}\n\ntemplate \nexp_t PohligHellman_pw(const PH_t g, const PH_t a, const exp_t p_v, const int p_e) {\n\t// return e: g**e == a, or -1 if no such e exists\n\texp_t ret = 0, pw_down = 1, pw_up = 1;\n\tfor(int k = 0; k < p_e-1; k++) pw_up *= p_v;\n\texp_t pw = pw_up * p_v;\n\tPH_t g_pw = pow(g, pw_up);\n\tfor(int k = 0; k < p_e; k++) {\n\t\tPH_t h = pow(multiply(pow(g, pw-ret), a), pw_up);\n\t\texp_t d = BSGS(g_pw, h, p_v);\n\t\tif(d == exp_t(-1)) return exp_t(-1);\n\t\tret += pw_down * d;\n\t\tpw_down *= p_v, pw_up /= p_v;\n\t}\n\treturn ret;\n}\n\ntemplate \nexp_t PohligHellman(const PH_t g, const PH_t a, const exp_t * p_v, const int * p_e, const int p_n) {\n\t// return e: g**e == a, or -1 if no such e exists\n\tstatic exp_t e_rem[100];\n\texp_t order = 1;\n\tfor(int i = 0; i < p_n; i++) for(int j = 0; j < p_e[i]; j++) order *= p_v[i];\n\tfor(int i = 0; i < p_n; i++) {\n\t\texp_t pw = 1;\n\t\tfor(int j = 0; j < p_e[i]; j++) pw *= p_v[i];\n\t\tPH_t g_pow = pow(g, order/pw);\n\t\tPH_t a_pow = pow(a, order/pw);\n\t\te_rem[i] = PohligHellman_pw(g_pow, a_pow, p_v[i], p_e[i]);\n\t\tif(e_rem[i] == exp_t(-1)) return exp_t(-1);\n\t}\n\treturn CRT(e_rem, p_v, p_e, p_n);\n}\n\ntemplate \nPH_t DiscreteLog(const PH_t a, const PH_t b, const exp_t order) {\n\t// return e: a**e == b, or -1 if no such e exists\n\t// factorise assuming all prime factors are small\n\tstatic exp_t p_v[100];\n\tstatic int p_e[100];\n\tint p_n = 0;\n\texp_t o = order;\n\tfor(exp_t i = 2; i*i <= o; i++) if(o%i == 0) {\n\t\tp_v[p_n] = i;\n\t\tp_e[p_n] = 0;\n\t\twhile(o%i == 0) p_e[p_n]++, o /= i;\n\t\tp_n++;\n\t}\n\tif(o > 1) {\n\t\tp_v[p_n] = o;\n\t\tp_e[p_n] = 1;\n\t\tp_n++;\n\t}\n\t// try random generators\n mt19937_64 rng(a*b);\n\tPH_t g = 0;\n\twhile(true) {\n\t\tPH_t try_g = g ? g : (rng() % order);\n\t\tif(!try_g) continue;\n\t\texp_t e_a = PohligHellman(try_g, a, p_v, p_e, p_n);\n\t\tif(e_a == exp_t(-1)) {\n\t\t\ttry_g = 0;\n\t\t\tcontinue;\n\t\t}\n\t\texp_t e_b = PohligHellman(try_g, b, p_v, p_e, p_n);\n\t\tif(e_b == exp_t(-1)) {\n\t\t\ttry_g = 0;\n\t\t\tcontinue;\n\t\t}\n\t\tg = try_g;\n\t\t// e_a * e == e_b + K * order\n\t\tstatic exp_t e_rem[100];\n\t\tfor(int i = 0; i < p_n; i++) {\n\t\t\texp_t pw = 1;\n\t\t\tfor(int j = 0; j < p_e[i]; j++) pw *= p_v[i];\n\t\t\texp_t e_a_rem = e_a % pw, e_b_rem = e_b % pw;\n\t\t\twhile(pw > 1 && e_a_rem % p_v[i] == 0) {\n\t\t\t\tif(e_b_rem % p_v[i] != 0) return -1;\n\t\t\t\tpw /= p_v[i], e_a_rem /= p_v[i], e_b_rem /= p_v[i];\n\t\t\t}\n\t\t\t// e_a_rem * e == e_b_rem + K * pw\n\t\t\te_rem[i] = (pw != 1) ? e_b_rem * pow(e_a_rem, pw-pw/p_v[i]-1, pw) % pw : 0;\n\t\t}\n\t\treturn CRT(e_rem, p_v, p_e, p_n);\n\t}\n}\n\nusing cat = unsigned long long;\n\ncat multiply_nocache(cat a, cat b);\n\ncat cache[64][64];\nchar cache_used[64][64];\n\ncat multiply_pw2(int a, int b) { // < 64\n\ta &= 63, b &= 63;\n\tif(cache_used[a][b]) return cache[a][b];\n\tif(a == 0 || b == 0) {\n\t\tcache_used[a][b] = 1;\n\t\tcache[a][b] = (1ULL<= pw && b >= pw) {\n\t\tcache_used[a][b] = 1;\n\t\tcache[a][b] = multiply_nocache(3ULL<<(pw-1), multiply_pw2(a^pw, b^pw));\n\t\treturn cache[a][b];\n\t}\n\tif(a >= pw) {\n\t\tcache_used[a][b] = 1;\n\t\tcache[a][b] = multiply_pw2(a^pw, b) << pw;\n\t\treturn cache[a][b];\n\t}\n\tif(b >= pw) {\n\t\tcache_used[a][b] = 1;\n\t\tcache[a][b] = multiply_pw2(a, b^pw) << pw;\n\t\treturn cache[a][b];\n\t}\n\tassert(false);\n\treturn -1;\n}\n\ncat multiply_nocache(cat a, cat b) {\n\tcat ret = 0;\n\tfor(int i = 0; a; i++, a /= 2) if(a&1) {\n\t\tcat b_c = b;\n\t\tfor(int j = 0; b_c; j++, b_c /= 2) if(b_c&1)\n\t\t\tret ^= multiply_pw2(i, j);\n\t}\n\treturn ret;\n}\n\ncat __attribute__((optimize(\"-Ofast,-funroll-loops\"))) __attribute__((target(\"arch=core-avx2\"))) multiply(cat a, cat b) {\n\tcat ret = 0;\n\tfor(int i = 0; a; i++, a /= 2) if(a&1) {\n\t\tcat b_c = b;\n\t\tfor(int j = 0; j != 64; j++, b_c /= 2)\n\t\t\tret ^= cache[i][j] & (-(b_c&1));\n\t}\n\treturn ret;\n}\n\nint main() {\n\tfor(int i = 0; i < 64; i++) for(int j = 0; j < 64; j++) multiply_nocache(1ULL<> T;\n\twhile(T--) {\n\t\tcat a, b;\n\t\tcin >> a >> b;\n\t\tcat ans = DiscreteLog(a, b, 0xFFFFFFFFFFFFFFFF);\n\t\tif(ans+1 == 0) cout << \"-1\\n\";\n\t\telse cout << ans << \"\\n\";\n\t}\n}\n", "src_uid": "54b41c5184c27d1373ec05775bc43b50"} {"source_code": "#include \nusing namespace std;\nint main() {\n int n;\n cin >> n;\n for (int i = 0; i <= 10; ++i) {\n if ((1 << i) == n) {\n cout << \"YES\" << endl;\n return 0;\n }\n }\n cout << \"NO\" << endl;\n return 0;\n}", "src_uid": "4bd174a997707ed3a368bd0f2424590f"} {"source_code": "/*\n█████╗ ███████╗ █████╗ ██╗ █████╗\n██╔══██╗ ██╔════╝ ██╔══██╗ ██║ ██╔══██╗\n███████║ ███████╗ ███████║ ██║ ███████║\n██╔══██║ ╚════██║ ██╔══██║ ██║ ██╔══██║\n██║ ██║██╗███████║██╗██║ ██║██╗███████╗██╗██║ ██║██╗\n╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝\n*/\n#define speedup\tios_base::sync_with_stdio(false);\n#define ASALA return 0;\n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint n, k;\nint a[100];\nbool unenq[100];\n\nint main() {\n\tspeedup;\n\tcin >> n >> k;\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> a[i];\n\tint cnt = 0;\n\tint ans = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tint nerka = a[i];\n\t\tif (unenq[nerka]==true)\n\t\t\tcontinue;\n\t\tif (cnt < k) {\n\t\t\tunenq[nerka] = true;\n\t\t\tcnt++;\n\t\t\tans++;\n\t\t}\n\t\telse {\n\t\t\tvector verj(81, -1);\n\t\t\tint found = -1;\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (verj[a[j]] == -1 && unenq[a[j]]==true) {\n\t\t\t\t\tverj[a[j]] = j;\n\t\t\t\t\tfound = a[j];\n\t\t\t\t}\n\t\t\t}\n\t\tfor (int j = 1; j <= 80; j++) {\n\t\t\t\tif (unenq[j]==true && verj[j] == -1) {\n\t\t\t\t\tans++;\n\t\t\t\t\tunenq[j] = false;\n\t\t\t\t\tunenq[a[i]] = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (unenq[a[i]]!=true) {\n\t\t\t\tunenq[found] = false;\n\t\t\t\tunenq[a[i]] = true;\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t}\n\tcout << ans << endl;\n\tASALA;\n}", "src_uid": "956228e31679caa9952b216e010f9773"} {"source_code": "#include\r\n#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)\r\n#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)\r\n#define rep(i, a) for(int i=1,i##end=a;i<=i##end;i++)\r\nusing namespace std;\r\nconst int N=210;\r\n//char buf[(1<<21)+5],*p1,*p2;\r\n//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)\r\nvoid chmx(int &x,int y){(xy)?(x=y):(0);}\r\ninline int read(){\r\n\tint f=0,x=0;\r\n\tchar ch=getchar();\r\n\twhile(!isdigit(ch)){f|=(ch=='-');ch=getchar();}\r\n\twhile(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}\r\n\treturn f?-x:x;\r\n}\r\nint n,p,ans,S; \r\nint fac[N],ifac[N];\r\nint inv(int x,int base=p-2){\r\n\tint res=1;\r\n\twhile(base){\r\n\t\tif(base&1)res=1ll*res*x%p;\r\n\t\tx=1ll*x*x%p;\r\n\t\tbase>>=1;\r\n\t}return res;\r\n}\r\nvoid init(int n){\r\n\tfac[0]=1;rep(i,n)fac[i]=1ll*fac[i-1]*i%p;\r\n\tifac[n]=inv(fac[n]);Rof(i,n-1,0)ifac[i]=1ll*ifac[i+1]*(i+1)%p;\r\n\tassert(1ll*fac[10]*ifac[10]%p==1);\r\n}\r\nint vis[N][N][51],dp[N][N][51];\r\nint dfs(int dep,int sum,int last,int lim){//倒着填 \r\n\tint &res=dp[dep][sum][last];\r\n\tif(res>=0)return res;res=0; \r\n\tif(last<=lim-1&&dep\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 po pop_back()\n#define queue queue\n#define matrix vector>\n#define pin(p) cin >> p.first >> p.second;\n#define rev(v) reverse(v.begin(),v.end());\n#define mx(v) max_element(v.begin(), v.end());\n#define mn(v) min_element(v.begin(), v.end());\n#define pout(p) cout << p.first << \" \" << p.second;\n#define er(v, l, r) erase(v.begin() + l, v.begin() + r);\n#define vin(v) for(int i = 0; i < v.size(); ++i) cin >> v[i];\n#define vout(v) for(int i = 0; i < v.size(); ++i) cout << v[i];\n//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++\nusing namespace std;\n//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++\ntypedef long long ll;\ntypedef long double ld;\ntypedef unsigned long long ull;\n//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++\nconst ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;\nconst int inf = 1000 * 1000 * 1000;\n//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++\nint main()\n{\n\tvector> field(9, vector(9));\n\tfor (int i = 0; i < 9; ++i)\n\t{\n\t\tfor (int j = 0; j < 9; ++j)\n\t\t{\n\t\t\tchar c;\n\t\t\tcin >> c;\n\n\t\t\tfield[i][j] = c;\n\t\t}\n\t}\n\tint x, y;\n\tcin >> x >> y;\n\tx--;\n\ty--;\n\tx %= 3;\n\ty %= 3;\n\tif (x == 0 && y == 0)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 0; i < 3; ++i)\n\t\t{\n\t\t\tfor (int j = 0; j < 3; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\telse if (x == 1 && y == 0)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 3; i < 6; ++i)\n\t\t{\n\t\t\tfor (int j = 0; j < 3; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\telse if (x == 2 && y == 0)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 6; i < 9; ++i)\n\t\t{\n\t\t\tfor (int j = 0; j < 3; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\telse if (x == 0 && y == 1)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 0; i < 3; ++i)\n\t\t{\n\t\t\tfor (int j = 3; j < 6; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\telse if (x == 1 && y == 1)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 3; i < 6; ++i)\n\t\t{\n\t\t\tfor (int j = 3; j < 6; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\telse if (x == 2 && y == 1)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 6; i < 9; ++i)\n\t\t{\n\t\t\tfor (int j = 3; j < 6; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\telse if (x == 0 && y == 2)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 0; i < 3; ++i)\n\t\t{\n\t\t\tfor (int j = 6; j < 9; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (x == 1 && y == 2)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 3; i < 6; ++i)\n\t\t{\n\t\t\tfor (int j = 6; j < 9; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (x == 2 && y == 2)\n\t{\n\t\tbool flag = false;\n\t\tfor (int i = 6; i < 9; ++i)\n\t\t{\n\t\t\tfor (int j = 6; j < 9; ++j)\n\t\t\t{\n\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\tflag = true;\n\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!flag)\n\t\t{\n\t\t\tfor (int i = 0; i < 9; ++i)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < 9; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (field[i][j] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tfield[i][j] = '!';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < 9; ++i)\n\t{\n\t\tfor (int j = 0; j < 9; ++j)\n\t\t{\n\t\t\tcout << field[i][j];\n\t\t\tif (j % 3 == 2)\n\t\t\t{\n\t\t\t\tcout << \" \";\n\t\t\t}\n\t\t}\n\t\tcout<< endl;\n\t\tif (i % 3 == 2)\n\t\t{\n\t\t\tcout << \"\\n\";\n\t\t}\n\t}\n}", "src_uid": "8f0fad22f629332868c39969492264d3"} {"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\nusing namespace std;\nconst double eps(1e-8);\nconst double pi(3.14159265358979);\nconst int Bit=4,Base=10000,L=100,ChL=1000;\nstruct big_num\n{\n\tint a[L/Bit],len,sign;\n\tbig_num(long long x=0)\n\t{\n\t\tif(x<0)\n\t\t\tsign=-1,x=-x;\n\t\telse\n\t\t\tsign=1;\n\t\tfor(int i=0;i=1;--i)\n\t\tprintf(\"%0*d\",Bit,b.a[i]);\n\tif(ch)\n\t\tputchar(ch);\n}\nbig_num operator-(big_num b)\n{\n\tb.sign=-b.sign;\n\treturn b;\n}\nbool operator<(const big_num &a,const big_num &b)\n{\n\tif(a.signb.sign)\n\t\treturn false;\n\tif(a.len!=b.len)\n\t\treturn (a.len-b.len)*a.sign<0;\n\tint p=a.len;\n\twhile(p && a.a[p]==b.a[p])\n\t\t--p;\n\treturn p && (a.a[p]-b.a[p])*a.sign<0;\n}\nbig_num operator+(big_num b1,big_num b2)\n{\n\tbig_num b;\n\tif(b1.sign!=b2.sign)\n\t{\n\t\tint d=0;\n\t\tif(b1.sign<0) b1.sign=-b1.sign,d=1;\n\t\telse b2.sign=-b2.sign,d=2;\n\t\tbool flag=b11 && b.a[b.len]==0)\n\t\t\t--b.len;\n\t\tif(b.len==1 && b.a[1]==0)\n\t\t\tb.sign=1;\n\t\treturn b;\n\t}\n\telse\n\t{\n\t\tb.sign=b1.sign;\n\t\tint l=max(b1.len,b2.len);\n\t\tfor(int i=1;i<=l;++i)\n\t\t{\n\t\t\tb.a[i]+=b1.a[i]+b2.a[i];\n\t\t\tif(b.a[i]>=Base)\n\t\t\t\tb.a[i]-=Base , ++b.a[i+1];\n\t\t}\n\t\tif(b.a[l+1])\n\t\t\t++l;\n\t\tb.len=l;\n\t\tif(b.len==1 && b.a[1]==0)\n\t\t\tb.sign=1;\n\t\treturn b;\n\t}\n}\nbig_num operator-(const big_num &b1,const big_num &b2)\n{\n\treturn b1+(-b2);\n}\nbig_num operator*(const big_num &b1,const big_num &b2)\n{\n\tif((b1.len==1 && b1.a[1]==0) || (b2.len==1 && b2.a[1]==0))\n\t\treturn 0;\n\tbig_num b;\n\tb.sign=b1.sign==b2.sign ? 1 : -1;\n\tfor(int i=1;i<=b1.len;++i)\n\t\tfor(int j=1;j<=b2.len;++j)\n\t\t{\n\t\t\tb.a[i+j-1]+=b1.a[i]*b2.a[j];\n\t\t\tb.a[i+j]+=b.a[i+j-1]/Base;\n\t\t\tb.a[i+j-1]%=Base;\n\t\t}\n\tint l=1;\n\twhile(l<=b1.len+b2.len-1 || b.a[l])\n\t{\n\t\tb.a[l+1]+=b.a[l]/Base;\n\t\tb.a[l]%=Base;\n\t\t++l;\n\t}\n\twhile(l>1 && b.a[l]==0)\n\t\t--l;\n\tb.len=l;\n\treturn b;\n}\nbig_num operator/(big_num b1,big_num b2)\n{\n\tint dl=b1.len;\n\tbig_num ans;\n\tans.sign=b1.sign==b2.sign ? 1 : -1;\n\tif(b1.sign<0) b1.sign=-b1.sign;\n\tif(b2.sign<0) b2.sign=-b2.sign;\n\tfor(int i=b2.len;i>=1;--i)\n\t\tb2.a[i+dl]=b2.a[i];\n\tb2.len+=dl;\n\tfor(int i=1;i<=dl;++i)\n\t\tb2.a[i]=0;\n\tfor(int i=dl;i>=0;--i)\n\t{\n\t\tif(b11 && ans.a[dl]==0)\n\t\t--dl;\n\tans.len=dl;\n\tif(ans.sign==-1 && (b1.a[1] || b1.len>1))\n\t\tans=ans-1;\n\tif(ans.len==1 && ans.a[1]==0)\n\t\tans.sign=1;\n\treturn ans;\n}\nbig_num operator% (const big_num &a,const big_num &b)\n{\n\treturn a-((a/b)*b);\n}\ninline long long getv(const big_num &a)\n{\n\tlong long s=0;\n\tfor(int i=a.len;i>=1;--i)\n\t\ts=s*Base+a.a[i];\n\treturn a.sign<0 ? -s : s;\n}\ninline long long f(long long x)\n{\n\tlong long s=0;\n\twhile(x)\n\t{\n\t\ts+=x%10;\n\t\tx/=10;\n\t}\n\treturn s;\n}\nlong long a;\nmap value_mod;\nconst long long pow10[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,\n1000000000,10000000000ll,100000000000ll,1000000000000ll,10000000000000ll,\n100000000000000ll,1000000000000000ll,10000000000000000ll,100000000000000000ll,\n1000000000000000000ll};\nconst int sv[]={0,1,3,6,10,15,21,28,36,45,55};\nbig_num sf[30];\nvoid init()\n{\n\tcin>>a;\n\tlong long now=0;\n\tfor(int i=0;i<=100;++i)\n\t{\n\t\tnow+=f(i);\n\t\tvalue_mod[now%a]=i;\n\t}\n\t//cout<=0;--i)\n\t{\n\t\tif(b[i])\n\t\t\tsum=sum+big_num(sv[b[i]-1])*pow10[i]+sf[i]*b[i];\n\t\tmid-=b[i]*pow10[i];\n\t\tsum=sum+b[i]*(mid+1);\n\t}\n\treturn sum;\n}\nvoid work()\n{\n\tif(value_mod[0]!=0)\n\t{\n\t\tcout<<1<<' '<>1;\n\t\t\tif(calc(mid)\n\nusing namespace std;\ntypedef long long ll;\nconst ll MOD = 1000000007;\nconst int MAXN = 4010;\n\nint W, H;\nint nw[2], nh[2];\nint gcf[MAXN][MAXN];\nll ans;\n\nint main()\n{\n for (int i = 0; i < MAXN; i++)\n gcf[0][i] = gcf[i][0] = i;\n for (int i = 1; i < MAXN; i++)\n for (int j = 1; j < MAXN; j++)\n {\n if (i < j)\n gcf[i][j] = gcf[i][j-i];\n else\n gcf[i][j] = gcf[j][i-j];\n }\n ans = 0;\n \n cin >> W >> H;\n nw[0] = W / 2 + 1;\n nw[1] = W + 1 - nw[0];\n nh[0] = H / 2 + 1;\n nh[1] = H + 1 - nh[0];\n \n for (int i = 0; i < 64; i++)\n {\n int par[6];\n for (int j = 0; j < 6; j++)\n par[j] = ((i & (1 << j)) ? 1 : 0);\n \n int lsum = 0;\n for (int j = 0; j < 3; j++)\n for (int k = 3; k < 6; k++)\n {\n if (k == j + 3)\n continue;\n \n lsum += par[j] * par[k];\n }\n \n if (lsum % 2 == 0)\n {\n ll nval = 1;\n for (int j = 0; j < 3; j++)\n nval = (nval * nw[par[j]]) % MOD;\n for (int j = 3; j < 6; j++)\n nval = (nval * nh[par[j]]) % MOD;\n \n ans = (ans + nval) % MOD;\n }\n }\n \n ll lans = 0;\n for (int i = 1; i <= W; i++)\n {\n int v = W - i + 1;\n for (int j = 1; j <= H; j++)\n lans = (lans - (v * (H - j + 1) * (ll) gcf[i][j]));\n }\n ans = (ans + 12 * lans);\n \n for (int i = 1; i <= W; i++)\n ans = (ans + MOD - (((6 * (W - i + 1) * \n (H + 1)) * ((ll) i)) % MOD));\n for (int i = 1; i <= H; i++)\n ans = (ans + MOD - (((6 * (W + 1) * \n (H - i + 1)) * ((ll) i)) % MOD));\n \n ans = (ans + MOD * MOD - (W + 1) * (H + 1)) % MOD;\n \n cout << ans << \"\\n\";\n //system (\"Pause\");\n return 0;\n}\n", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa"} {"source_code": "//#pragma comment(linker, \"/STACK:1000000000\")\n//#pragma GCC optimize(\"Ofast,no-stack-protector\")\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 \n#define all(a) (a).begin(), (a).end()\n#define pb push_back\n#define mp make_pair\n#define ll long long\n#define ull unsigned long long \n#define pii pair \n#define pll pair \n#define ld double\n \nusing namespace std;\n \nmultiset pos[2];\nvector ans[2];\n \nll gcd(ll a, ll b) {\n\treturn (b == 0 ? a : gcd(b, a % b));\n}\n \nvoid make(int it, ll a, ll b) {\n\tif (a == b) {\n\t\treturn;\n\t}\n \n\tans[it].push_back(mp(a, b));\n\tpos[it].erase(pos[it].find(a));\n\tpos[it].insert(2 * b - a);\n}\n \nvoid print(int it) {\n\tcout << \"SET \" << it << \": \";\n\tfor (auto itr : pos[it]) {\n\t\tcout << itr << ' ';\n\t}\n \n\tcout << endl;\n}\n \nint sum(int it) {\n\tint x = 0;\n\tfor (auto itr : pos[it]) {\n\t\tx += itr & 1;\n\t}\n \n\treturn x;\n}\n \nint main() {\n\tll a, b, c, d;\n\tcin >> a >> b >> c >> d;\n\tpos[0].insert(a);\n\tpos[0].insert(b);\n\tpos[0].insert(c);\n\tpos[0].insert(d);\n\tll g0 = gcd(gcd(abs(d - a), abs(c - a)), abs(b - a));\n\tll c0 = (abs(b - a) & 1) ^ (abs(c - a) & 1) ^ (abs(d - a) & 1);\n \n\tcin >> a >> b >> c >> d;\n\tpos[1].insert(a);\n\tpos[1].insert(b);\n\tpos[1].insert(c);\n\tpos[1].insert(d);\n\tll g1 = gcd(gcd(abs(d - a), abs(c - a)), abs(b - a));\n\tll c1 = (abs(b - a) & 1) ^ (abs(c - a) & 1) ^ (abs(d - a) & 1);\n \n\tif (g0 != g1 || c0 != c1) {\n\t\tcout << -1 << endl;\n\t\t//system(\"pause\");\n\t\treturn 0;\n\t}\n \n\tif (g0 == 0) {\n\t\tif ((*pos[0].begin()) != (*pos[1].begin())) {\n\t\t\tcout << -1 << endl;\n\t\t}\n\t\telse {\n\t\t\tcout << 0 << endl;\n\t\t}\n \n\t\t//system(\"pause\");\n\t\treturn 0;\n\t}\n \n\tif (((*pos[0].begin()) - (*pos[1].begin())) % g0 != 0) {\n\t\tcout << -1 << endl;\n\t\treturn 0;\n\t}\n \n\tll sd = (*pos[0].begin()) % g0;\n\tif (sd < 0) {\n\t\tsd += g0;\n\t}\n \n\tfor (int it = 0; it < 2; it++) {\n\t\tmultiset nx;\n \n\t\tfor (ll x : pos[it]) {\n\t\t\tnx.insert((x - sd) / g0);\n\t\t}\n \n\t\tpos[it] = nx;\n\t}\n \n\tfor (int it = 0; it < 2; it++) {\n\t\twhile ((*pos[it].rbegin()) - (*pos[it].begin()) >= 3) {\n\t\t\tauto itr = pos[it].begin();\n\t\t\tll a = *itr;\n\t\t\titr++;\n\t\t\tll b = *itr;\n\t\t\titr++;\n\t\t\tll c = *itr;\n\t\t\titr++;\n\t\t\tll d = *itr;\n \n\t\t\tll len = d - a;\n\t\t\tll x = min(c - a, d - c);\n\t\t\tif (x >= len / 6 && x != 0) {\n\t\t\t\tmake(it, d, c);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tll y = min(b - a, d - b);\n\t\t\t\tif (y >= len / 6 && x != 0) {\n\t\t\t\t\tmake(it, d, b);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (c - a < len / 6) {\n\t\t\t\t\t\tmake(it, b, a);\n\t\t\t\t\t\tmake(it, 2 * a - b, c);\n\t\t\t\t\t}\n\t\t\t\t\telse if (d - b < len / 6) {\n\t\t\t\t\t\tmake(it, c, d);\n\t\t\t\t\t\tmake(it, 2 * d - c, b);\n\t\t\t\t\t}\n\t\t\t\t\telse if (b - a < d - c) {\n\t\t\t\t\t\tmake(it, b, c);\n\t\t\t\t\t\tmake(it, 2 * c - b, d);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tmake(it, c, b);\n\t\t\t\t\t\tmake(it, 2 * b - c, a);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n \n\t//print(0);\n\t//print(1);\n \n\tfor (int it = 0; it < 2; it++) {\n\t\tauto itr = pos[it].begin();\n\t\tll a = *itr;\n\t\titr++;\n\t\tll b = *itr;\n\t\titr++;\n\t\tll c = *itr;\n\t\titr++;\n\t\tll d = *itr;\n \n\t\tif (a == b) {\n\t\t\tif (c != a) {\n\t\t\t\tmake(it, b, c);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmake(it, b, d);\n\t\t\t}\n \n\t\t\tit--;\n\t\t\tcontinue;\n\t\t}\n \n\t\tif (d == b) {\n\t\t\tmake(it, b, a);\n\t\t}\n\t}\n \n\tif (sum(0) != sum(1)) {\n\t\tcout << -1 << endl;\n\t\treturn 0;\n\t}\n \n\tint it = 0;\n \n\tif ((*pos[1].begin()) > (*pos[0].begin())) {\n\t\tit = 1;\n\t}\n \n\twhile ((*pos[it].begin()) - (*pos[it ^ 1].begin()) >= 6) {\n\t\tll d = (*pos[it].begin()) - (*pos[it ^ 1].begin());\n\t\tint cnt = 0;\n\t\t\n\t\tll x = *pos[it].rbegin();\n \n\t\tll sum = 0;\n \n\t\twhile (true) {\n\t\t\tll a = *pos[it].begin();\n\t\t\tll c = *pos[it].rbegin();\n\t\t\tcnt++;\n \n\t\t\tauto itr = pos[it].rbegin();\n \n\t\t\twhile ((*itr) == c) {\n\t\t\t\titr++;\n\t\t\t}\n \n\t\t\tll b = *itr;\n \n\t\t\tsum += c - b;\n \n\t\t\tif (2 * (x - b) + (b - (2 * a - c)) > d) {\n\t\t\t\tcnt--;\n\t\t\t\tbreak;\n\t\t\t}\n \n\t\t\twhile (pos[it].count(c)) {\n\t\t\t\tmake(it, c, a);\n\t\t\t}\n\t\t}\n \n\t\tll cc = *pos[it].rbegin();\n \n\t\tauto itr = pos[it].rbegin();\n \n\t\twhile ((*itr) == cc) {\n\t\t\titr++;\n\t\t}\n \n\t\tll bb = *itr;\n \n\t\tll ds = d - (x - cc);\n\t\tsum += bb - (*pos[it].begin());\n\t\tsum -= 2;\n\t\tds -= sum;\n\t\tint tp = 0;\n \n\t\twhile (cnt > 0) {\n\t\t\tll a = *pos[it].begin();\n\t\t\tll c = *pos[it].rbegin();\n \n\t\t\tauto itr = pos[it].rbegin();\n \n\t\t\twhile ((*itr) == c) {\n\t\t\t\titr++;\n\t\t\t}\n \n\t\t\tll b = *itr;\n \n\t\t\tif (ds >= (c - a)) {\n\t\t\t\tds -= (c - a);\n\t\t\t\twhile (pos[it].count(c)) {\n\t\t\t\t\tmake(it, c, a);\n\t\t\t\t}\n \n\t\t\t\twhile (pos[it].count(b)) {\n\t\t\t\t\tmake(it, b, a);\n\t\t\t\t}\n \n\t\t\t\ttp ^= 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcnt--;\n\t\t\t\tif (tp == 0) {\n\t\t\t\t\tds += (b - a);\n\t\t\t\t\tds += (b - a) - (c - b);\n\t\t\t\t\tsum -= b - a;\n\t\t\t\t\twhile (pos[it].count(a)) {\n\t\t\t\t\t\tmake(it, a, b);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\twhile (pos[it].count(c)) {\n\t\t\t\t\t\tmake(it, c, b);\n\t\t\t\t\t}\n \n\t\t\t\t\tsum -= c - b;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n \n\tfor (int it = 0; it < 2; it++) {\n\t\tauto itr = pos[it].begin();\n\t\tll a = *itr;\n\t\titr++;\n\t\tll b = *itr;\n\t\titr++;\n\t\tll c = *itr;\n\t\titr++;\n\t\tll d = *itr;\n \n\t\tif (a == b) {\n\t\t\tif (c != a) {\n\t\t\t\tmake(it, b, c);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmake(it, b, d);\n\t\t\t}\n \n\t\t\tit--;\n\t\t\tcontinue;\n\t\t}\n \n\t\tif (d == b) {\n\t\t\tmake(it, b, a);\n\t\t}\n\t}\n \n\twhile ((*pos[0].begin()) != (*pos[1].begin())) {\n\t\tint cnt = pos[it].count(*pos[it].rbegin());\n\t\tll x = *pos[it].rbegin();\n \n\t\tif (cnt == 1) {\n\t\t\tmake(it, x, x - 1);\n\t\t\tmake(it, x - 1, x - 2);\n\t\t}\n\t\telse {\n\t\t\tmake(it, x, x - 1);\n\t\t\tmake(it, x, x - 1);\n\t\t\tmake(it, x - 1, x - 2);\n\t\t\tmake(it, x - 2, x - 3);\n\t\t}\n\t}\n \n\twhile (!ans[1].empty()) {\n\t\tpll g = ans[1].back();\n\t\tans[1].pop_back();\n \n\t\tans[0].push_back(mp(2 * g.second - g.first, g.second));\n\t}\n \n\tif (ans[0].size() > 1000) {\n\t\tthrow 1;\n\t}\n \n\tcout << ans[0].size() << endl;\n \n\tfor (pll g : ans[0]) {\n\t\tcout << (g.first) * g0 + sd << ' ' << (g.second) * g0 + sd << endl;\n\t}\n \n\t//system(\"pause\");\n}", "src_uid": "7b6b3d4bc0a269836bc0113bb17f562f"} {"source_code": "/* fibonacci encoding\n * no adjacent ones(pairs)\n *\n * */\n\n#include \n#include \n#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\n#define REP(i,n) for(int i=0; ib?a:b\n#define maxf 1000000000000000000LL\n\nlong long fib[105];\nint precalc()\n{\n\tfib[0]=fib[1]=1;\n\tint ans;\n\tFOR(i,2,100)\n\t{\n\t\tfib[i]=fib[i-1]+fib[i-2];\n\t\tif(fib[i]>maxf)\n\t\t{\n\t\t\tans=i;break;\n\t\t}\n\t}\n\n\treturn ans;\n\n}\n\nvector dec_to_fib(long long n,long long biggest)\n{\n\tvector code;\n\tint bp;\n\tfor(int i=biggest;i>=1;--i)\n\t{\n\t\tif(n>=fib[i])\n\t\t{\n\t\t\tn=n%fib[i];\n\t\t\tcode.push_back(1);\n\t\t\n\n\t\t}\n\t\telse\n\t\t\tcode.push_back(0);\n\n\n\t}\n\treturn code;\n\n}\n\nvoid code_to_perm(vector code,int n)\n{\n\n\t//REP(i,code.size())\n\t//\t\tcout< perm(code.end()-n+1,code.end());\t\n\t//REP(i,perm.size())\n\t//\t\tcout< ans;\t\n\tREP(i,n)\n\tans.push_back(i+1);\n\tREP(i,perm.size())\n\t{\n\t\tif(perm[i]==1)\n\t\t\tswap(ans[i],ans[i+1]);\n\t\t\n\n\t}\n\tREP(i,ans.size())\n\t\tcout<>n>>k;\n\t\n\tcode_to_perm(dec_to_fib(k-1,biggest),n);\n\nreturn 0;\n}\n", "src_uid": "e03c6d3bb8cf9119530668765691a346"} {"source_code": "#include\nint n,i;\nint a[110];\nint main()\n{\n\tint s=0,b=0,c=0;\n\tscanf(\"%d\",&n);\n\tfor(i=0;ib && s>c)\n printf(\"chest\");\n else if(b>s && b>c)\n printf(\"biceps\");\n else\n printf(\"back\");\n }\n \n", "src_uid": "579021de624c072f5e0393aae762117e"} {"source_code": "#include\nusing namespace std;\n#define lc (p<<1)\n#define rc ((p<<1)|1)\nconst int mod=998244353;\ninline int add(int a,int b)\n{\n\tif((a+=b)>=mod)a-=mod;\n\treturn a;\n}\ninline int dec(int a,int b)\n{\n\tif((a-=b)<0)a+=mod;\n\treturn a;\n}\ninline int mult(int a,int b)\n{\n\tlong long t=1ll*a*b;\n\tif(t>=mod)t%=mod;\n\treturn t;\n}\ninline int power(int a,int b)\n{\n\tint out=1;\n\twhile(b)\n\t{\n\t\tif(b&1)out=mult(out,a);\n\t\ta=mult(a,a);\n\t\tb>>=1;\n\t}\n\treturn out;\n}\nint n,x[100010],v[100010],p[100010];\nconst int I100=power(100,mod-2);\nclass coll\n{\n\tpublic:\n\t\tdouble t;\n\t\tint typ,pos,S;\n\t\tbool operator <(const coll &c)const\n\t\t{\n\t\t\treturn t c;\nnamespace matrix\n{\n\ttemplate\n\tclass matr\n\t{\n\t\tpublic:\n\t\t\tint dat[N][M];\n\t\t\tvoid init()\n\t\t\t{\n\t\t\t\tmemset(dat,0,sizeof(dat));\n\t\t\t}\n\t\t\tvoid iden()\n\t\t\t{\n\t\t\t\tinit();\n\t\t\t\tfor(int i=0; i trans()\n\t\t\t{\n\t\t\t\tmatr out;\n\t\t\t\tfor(int i=0; i operator +(const matr a)\n\t\t\t{\n\t\t\t\tmatr out;\n\t\t\t\tfor(int i=0; i operator *(const int &x)\n\t\t\t{\n\t\t\t\tmatr out=*this;\n\t\t\t\tfor(int i=0; i\n\t\t\tfriend matr operator *(const matr a,const matr b)\n\t\t\t{\n\t\t\t\tmatr out;\n\t\t\t\tout.init();\n\t\t\t\tfor(int i=0; i t[400010],M[100010];\ninline void pushup(int p)\n{\n\tt[p]=t[lc]*t[rc];\n}\ninline void build(int p,int l,int r)\n{\n\tif(l==r)\n\t{\n\t\tt[p][0][0]=t[p][1][0]=::p[l+1];\n\t\tt[p][0][1]=t[p][1][1]=dec(1,::p[l+1]);\n\t\tM[l]=t[p];\n\t\treturn;\n\t}\n\tint mid=(l+r)>>1;\n\tbuild(lc,l,mid);\n\tbuild(rc,mid+1,r);\n\tpushup(p);\n}\ninline void modify(int p,int l,int r,int pos)\n{\n\tif(l==r)\n\t{\n\t\tt[p]=M[l];\n\t\treturn;\n\t}\n\tint mid=(l+r)>>1;\n\tif(pos<=mid)modify(lc,l,mid,pos);\n\telse modify(rc,mid+1,r,pos);\n\tpushup(p);\n}\nint main()\n{\n\tscanf(\"%d\",&n);\n\tfor(int i=1;i<=n;i++)\n\t\tscanf(\"%d%d%d\",&x[i],&v[i],&p[i]),p[i]=mult(p[i],I100);\n\tfor(int i=1;iv[i+1])c.push_back((coll){1.0*dis/(v[i]-v[i+1]),1,i,mult(dis%mod,power(v[i]-v[i+1],mod-2))});\n\t\telse if(v[i] tmp=M[pos];\n\t\tM[pos].init();\n\t\tM[pos][p1][p2]=v2;\n\t\tmodify(1,0,n-1,pos);\n\t\tans=add(ans,mult(x.S,add(t[1][1][0],t[1][1][1])));\n//\t\tprintf(\"%d\\n\",ans);\n\t\tM[pos]=tmp;\n\t\tM[pos][p1][p2]=0;\n\t\tmodify(1,0,n-1,pos);\n\t}\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7"} {"source_code": "#include \"bits/stdc++.h\"\n\nusing namespace std;\nusing LL = long long;\n\nconstexpr int N = 1e5 + 5;\n\nint main() {\n\t//ios::sync_with_stdio(false); cin.tie(nullptr);\n\t\n\tint n, m, x;\n\tcin >> n >> m >> x;\n\n\tn = n - 2 * x + 2;\n\tm = m - 2 * x + 2;\n\tif (n < 0 or m < 0) return puts(\"0\");\n\n\tint result = 0;\n\tfor (int i = 0; i < n; i++) \n\t\tfor (int j = 0; j < m; j++)\n\t\t\tif (i == 0 or j == 0 or i == n - 1 or j == m - 1)\n\t\t\t\tif ((i + j) % 2 == 0)\n\t\t\t\t\tresult++;\n\n\tcout << result << endl;\n}", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"source_code": "#include\n\n\n\nusing namespace std;\nint max(int a,int b)\n{\n if(a>b)\n return a;\n else\n return b;\n}\nint min(int a,int b)\n{\n if(ay)\n {\n p=a*d-b*c;\n q=a*d;\n }\n else if(x\n#include \n#include \n#include \n\n#define ll long long;\n//#define int long long;\n\n#define ft first;\n#define sd second;\n#define mp make_pair\n\n\nusing namespace std;\n\nvector edge1;\nvector edge2;\nint main()\n{\n\tint n, m;\n\tcin >> n >> m;\n\tedge1.resize(m);\n\tedge2.resize(m);\n\tfor (int i = 0; i < m; i++) {\n\t\tcin >> edge1[i] >> edge2[i];\n\t}\n\tif (n < 7)\n\t\tcout << m;\n\telse {\n\t\tint ans = 0;\n\t\tvector colors(7);\n\t\tvector> exists(7, vector(7, false));\n\t\tfor (int i = 0; i < 7; i++)\n\t\t\tcolors[i] = i;\n\t\tfor (int v = 0; v < 7; v++)\n\t\t\tfor (int c = 0; c < 7; c++)\n\t\t\t\tif (c == v)\n\t\t\t\t\tcontinue;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint curans = 0;\n\t\t\t\t\tcolors[v] = c;\n\t\t\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\t\t\tif (!exists[colors[edge1[i] - 1]][colors[edge2[i] - 1]] && !exists[colors[edge2[i] - 1]][colors[edge1[i] - 1]])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\texists[colors[edge1[i] - 1]][colors[edge2[i] - 1]] = true;\n\t\t\t\t\t\t\texists[colors[edge2[i] - 1]][colors[edge1[i] - 1]] = true;\n\t\t\t\t\t\t\tcurans++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (ans < curans)\n\t\t\t\t\t\tans = curans;\n\t\t\t\t\tcolors[v] = v;\n\t\t\t\t\texists.assign(7, vector(7, false));\n\t\t\t\t}\n\t\tcout << ans;\n\t}\n}", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b"} {"source_code": "//be naame khodaa\n\n#include \n\ntypedef long long ll;\n\nconst int maxn = 200005;\n\nusing namespace std;\n\nll money[maxn], c[maxn];\n\nint main()\n{\n\tios::sync_with_stdio(false);\n\tll n, m;\n\tcin >> n >> m;\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> money[i];\n\tll ans = 0;\n\tfor (ll d = 1; d <= m/n; d++)\n\t{\n\t\tc[n-1] = money[n-1];\n\t\tfor (int i = n-2; i >= 0; i--)\n\t\t\tc[i] = min(money[i], c[i+1] - d);\n\t\tif (c[0] < ((d-1)*n+2)*d/2) continue;\n\t\tll sum = (2*m - (d+1)*n + 2)*d/2;\n\t\tll s = max(1LL, m - d*n + 1 - max(0LL, (sum - c[0])));\n\t\tll space = (m - s + 1 - n*d);\n\t\tll base = min(c[0], sum), ben = 0;\n\t\tben += base;\n\t\tfor (int i = 1; i < n; i++)\n\t\t{\n\t\t\tbase += d;\n\t\t\tben += base;\n\t\t\tc[i] -= base;\n\t\t\tll shift = min(c[i], space);\n\t\t\tben += shift;\n\t\t\tbase += shift;\n\t\t\tspace -= shift;\n\t\t}\n\t\tans = max(ans, ben);\n\t}\n\tcout << ans << endl;\n\treturn 0;\n}\n", "src_uid": "169f58dc87d26e0fadde6a83bb623f54"} {"source_code": "/*\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#include \n#define yx 1000000007ll\n#define ll long long\n#define mp make_pair\n#define pb push_back\n#define fi first\n#define se second\n#define sort stable_sort\n#define all(x) (x).begin(),(x).end()\n#define rep(i,x) for ((i)=(1);(i)<=(x);(i)++)\n#define rep2(i,x) for ((i)=(x-1);(i)>=(x-m);(i)--)\n#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)\nusing namespace std;\nll n,m,i,j,num[200005],suma,sumb;\nstring st;\nvector a,b,c;\nint main()\n{\n\tios_base::sync_with_stdio(0);\n\tcin>>n>>m;\n\tif (m==1)\n\t{\n\t\tcout<<-1;\n\t\treturn 0;\n\t}\n\trep(i,n) cin>>num[i];\n\tcin>>st;\n\tst=\" \"+st;\n\trep(i,n)\n\t{\n\t\tif (st[i]=='R') a.pb(num[i]);\n\t\tif (st[i]=='W') b.pb(num[i]);\n\t\tif (st[i]=='O') c.pb(num[i]);\n\t}\n\tsort(all(a));sort(all(b));sort(all(c));\n\treverse(all(a));reverse(all(b));reverse(all(c));\n\tif ((a.empty()&&b.empty())||c.empty())\n\t{\n\t\tcout<<-1;\n\t\treturn 0;\n\t}\n\tif (a.size()+c.size()j&&(a.size()<=i||a[i]j&&(b.size()<=i||b[i]\nusing namespace std;\nint main()\n{\n\tint a,b,c,x,y,z;\n\tcin>>a>>b>>c; \n\tfor(int i=0;i<=10000;i++)\n\t{\n\t\tx=c-(a*i);\n\t\tif(x%b==0 && x>=0)\n\t\t{\n\t\t\tcout<<\"Yes\\n\";\n\t\t\treturn 0;\n\t\t}\n\t\tif(x<0)\n\t\t{\n\t\t\tcout<<\"No\\n\";\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\n\treturn 0;\n}", "src_uid": "e66ecb0021a34042885442b336f3d911"} {"source_code": "#include \nusing namespace std;\n\n#define ll long long\n#define mp make_pair\n#define pb push_back\n#define pii pair \n#define piii pair\n#define vi vector\n#define vpii vector\n\n#define read1(a) int a; scanf(\"%d\", &a)\n#define read2(a, b) int a, b; scanf(\"%d %d\", &a, &b)\n#define read3(a, b, c) int a, b, c; scanf(\"%d %d %d\", &a, &b, &c)\n\n#define FOR(i, a, b) for (int i=a; i > v;\nvi ans;\n//bool on[MAX];\n//bool ok[MAX];\nbool mark[MAX];\n\nvector hasto;\nvector cant;\n\nint main() {\n read2(n, q);\n F0R(i, q) {\n char op; scanf(\" %c\", &op);\n read1(user);\n v.pb({op, user});\n if (op == '+' && !mark[user]) { cant.pb(user); }\n if (op == '-' && !mark[user]) { hasto.pb(user); }\n mark[user] = true;\n }\n int cand;\n if (!hasto.empty()) { cand = hasto.back(); }\n else { cand = cant[0]; }\n set people;\n bool ok = true;\n for (int i : hasto) { people.insert(i); }\n for (auto i : v) {\n if (i.f == '+') { people.insert(i.s); }\n if (i.f == '-') { people.erase(i.s); }\n if (!people.empty() && people.find(cand) == people.end()) {\n ok = false;\n }\n }\n\n FOR(i, 1, n+1) { if (!mark[i]) { ans.pb(i); } }\n if (ok) { ans.pb(cand); }\n sort(ans.begin(), ans.end());\n println1(ans.size());\n pv(ans);\n}\n\n\n", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5"} {"source_code": "#include \n#include \n#include \n#include \nusing namespace std ;\nint main ()\n{\n\tint Rotation = 0 ;\n\tchar pointer = 'a' ;\n\tstring s ;\n\tcin>> s ;\n\tint n = s.length()-1 ;\n\tfor(int i = 0 ; i<=n ; i++)\n\t{\n\t\tif(s[i]==pointer)\n\t\t\tcontinue ;\n\t\tif(abs(pointer-s[i])>=abs(abs(pointer-s[i])-26))\n\t\t\tRotation+=abs(abs(pointer-s[i])-26) ;\n\t\telse Rotation += abs(pointer-s[i]) ;\n\t\tpointer = s[i] ;\n\t}\n\tcout << Rotation << \"\\n\" ;\n\treturn 0;\n}", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"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--)\nusing namespace std;\nint main(){\n\tint n,ans;\n\tscanf(\"%d\",&n);\n\tans = n/2;long long w = 1;\n\tif (n%2==0){\n\t\trep(i,1,32){\n\t\t\tw = w*2LL;\n\t\t\tif (w>n) break;\n\t\t\tans = min((long long)ans,((long long)n-w)/2);\n\t\t}\n\t}\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n", "src_uid": "422abdf2f705c069e540d4f5c09a4948"} {"source_code": "#include \n\ntypedef long long ll;\ntypedef long double ld;\nusing namespace std;\n\nint main()\n{\n// int s,m;\n string res1 = \"\", res2 = \"\";\n// cin >> m >> s;\n// int s1 = s; int m1 = m;\n// while (s1-9>m1) { res1 +='9' ; s1-= 9;m1--;}\n// for (int i = m1; i > 1; i--) {res1 += '1'; s1 -= 1;}\n// res1 += char(s1 + 48);\n// cout << res1;\n vector d;\n string s = \"\";\n cin >> s;\n for (int j = s.length()-1; j >= 0; j-- ){\n int a = s[j]-48;\n int cnt = d.size();\n if (a%8 == 0) {cout << \"YES\" << endl << a; return 0;}\n if (a%2 == 0) d.push_back(a);\n for (int i = 0 ; i < cnt; i++){\n if (d[i]>10 && (a*100+d[i])%8 == 0) {cout << \"YES\" << endl << a*100+d[i]; return 0;}\n if (d[i] < 10 && (a*10+d[i])%8==0) {cout << \" YES\" << endl << a*10+d[i]; return 0;}\n if (d[i] < 10 && (a*10+d[i])%4==0) {d.push_back(a*10+d[i]);}\n }\n }\n cout << \"NO\";\n return 0;\n}\n", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"source_code": "#include\n#include\n#include\nconst int maxn=400010,maxq=400010;\nint n,cnt[maxn],tmp[maxn],lg[maxn];\nint min(int a,int b){return ab?a:b;}\nstruct SA{\n\tchar S[maxn];\n\tint nxt[maxn],mn[maxn],sa[maxn],r[2][maxn],*rk,ht[20][maxn];\n\tvoid make(){\n\t\tfor(int i=0;i<128;i++)cnt[i]=0,tmp[i]=1<<30;\n\t\tmn[n]=1<<30;\n\t\tfor(int i=n;i--;)nxt[i]=tmp[S[i]],tmp[S[i]]=i,mn[i]=min(nxt[i],mn[i+1]);\n\t\tfor(int i=0;i=k)tmp[j++]=sa[i]-k;\n\t\t\tfor(int i=0;i(j=rk[j]))return k=lg[i-j],min(ht[k][j],ht[k][i-(1<pf[maxn],qs[maxn];\nint ul[maxn],ur[maxn],dl[maxn],dr[maxn],ml[maxn],\n\tpl[maxn],pr[maxn],list[maxn];\nint find(int*u,int i){return u[i]==i?i:u[i]=find(u,u[i]);}\nvoid upd(int*u,int*d,int l,int r,int x){\n\twhile((l=find(u,l))=len-p)return 1;\n\t}\n\tif(dl[l]&&l+dl[l]*2<=r)return 2;\n\tif(dr[r]&&r-dr[r]*2>=l)return 2;\n\tif(r>br&&ul[r]>r)return 2;\n\tfor(int i=1;l+i=i)return 2;\n\tif(S0.nxt[l]la){\n\t\t\tint pl=i-S1.lcp(n-i-l,n-i),pr=i+S0.lcp(i,i+l);\n\t\t\tif(pr-pl>=l){\n\t\t\t\tupd(ul,dl,pl,pr-l+1,l);\n\t\t\t\tupd(ur,dr,pl+l*2,pr+l+1,l);\n\t\t\t}\n\t\t\tla=pr;\n\t\t}\n\t}\n\tml[n]=1<<30;\n\tfor(int i=n;i--;){\n\t\tml[i]=ml[i+1];\n\t\tif(dl[i])ml[i]=min(ml[i],i+dl[i]*2);\n\t}\n\tint q;scanf(\"%d\",&q);\n\tfor(int i=0,l;in)br=n;\n\t\tfor(int i=0;i<=br;i++)cnt[i]=0;\n\t\tfor(int i=br+1;i<=n;i++){\n\t\t\tul[i]=i;\n\t\t\tpl[i]=br-S1.lcp(n-i,n-br);\n\t\t\tcnt[pl[i]]++;\n\t\t}\n\t\tfor(int i=0;ibr;i--)tmp[--cnt[pl[i]]]=i;\n\t\tfor(int l=bl,i=0;l\nusing namespace std;\nint main()\n{\n\tlong long n;\n\tcin>>n;\n\tstring s;\n\tcin>>s;\n\tcout<\n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main()\n{\n\tstring str;\n\tcin >> str;\n\tint ans = (str.size() + 1) * 26 - (str.size());\n\tcout << ans << endl;\n//\tsystem(\"pause\");\n\treturn 0;\n}", "src_uid": "556684d96d78264ad07c0cdd3b784bc9"} {"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 ABS(a) ((a>0)?a:-(a))\n#define MIN(a,b) ((a\n#define mp make_pair\n#define PI 3.14159265358979\n#define MEMS(a,b) memset(a,b,sizeof(a))\n#define LL long long\n#define U unsigned\nusing namespace std;\nint n,m;\nint dp[41][65][65][65];\nint dx[]={0,0,0,1,-1};\nint dy[]={0,1,-1,0,0};\nint r(int num, int m1, int m2, int m3)\n{\n\tint x=num/m;\n\tint y=num%m;\n\tif (y==m)\n\t\treturn 0;\n\tif (x==n)\n\t{\n\t\tint cnt=0;\n\t\tFOR(k,0,n)\n\t\t\tif ((m1>>k)&1)\n\t\t\t\tcnt++;\n\t\tif (y==m-1)\n\t\t\tFOR(k,0,n)\n\t\t\t\tif ((m2>>k)&1)\n\t\t\t\t\tcnt++;\n\t\tif (y==m-1)\n\t\t\treturn cnt;\n\t\tint nnum=y+1;\n\t\treturn cnt+r(nnum,m2,m3,0);\n\t}\n\tif (dp[num][m1][m2][m3]!=-1)\n\t\treturn dp[num][m1][m2][m3];\n\tint res=2000000;\n\tres=min(res,r(num+m,m1,(m2|(1<0)\n\t\tres=min(res,r(num+m,m1,(m2|(1<<(x-1))),m3));\n\tif (x0)\n\t\tres=min(res,r(num+m,(m1|(1<>n>>m;\n\tif (n>m)\n\t\tswap(n,m);\n\tMEMS(dp,-1);\n\tint res=r(0,0,0,0);\n\tres=n*m-res;\n\tcout<\n\nusing namespace std;\n\nint n;\nint arr[210];\nint A[210][210];\nvector vec;\n\nint isAll(int a)\n{\n int sum=0;\n for(int i=1;i<=A[a][0];i++)\n {\n if(A[a][i]==-1) sum++;\n }\n if(sum==A[a][0]) return 1;\n return 0;\n}\n\nvoid makeEmpty(int a)\n{\n\n for(int i=1;i<=n;i++)\n {\n for(int j=1;j<=A[i][0];j++)\n {\n if(A[i][j]==a)\n {\n A[i][j]=-1;\n if(isAll(i))\n {\n vec.push_back(i);\n }\n break;\n }\n }\n }\n\n}\n\nint mrk;\nint getBest(int a,int fff)\n{\n int sum=0;\n for(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main() {\n int a[6];\n cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5];\n sort(a,a+6);\n //for (int i=0;i<=5;i++)\n // cout<\nusing namespace std;\nstring s;\nint main()\n{\n cin>>s;\n for(int i=1;i\n\n#define div 1000000007\n\nint i,j,n,m;\n\nint main() {\n scanf(\"%d %d\", &n, &m);\n long long int T = 1, f=0, lastT;\n for(i=1;i<=n;i++) {\n lastT=T;\n T= ((lastT + lastT - f) % div + div) * m %div;\n f = (lastT + f * (m-1)) % div;\n }\n printf(\"%I64d\\n\", T);\n return 0;\n}", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c"} {"source_code": "#include \nusing namespace std;\ntypedef long long LL;\nconst int maxn = 201, maxm = 51;\nint n, m, qtot, etot;\nstruct Point {\n\tint x, y;\n\tvoid read() {\n\t\tscanf(\"%d%d\", &x, &y);\n\t}\n\tbool operator < (Point const &t) const {\n\t\treturn x < t.x || (x == t.x && y < t.y);\n\t}\n\tPoint operator - (Point const &t) const {\n\t\treturn (Point){x - t.x, y - t.y};\n\t}\n\tLL det(Point const &t) const {\n\t\treturn (LL)x * t.y - (LL)y * t.x;\n\t}\n\tint site() const {\n\t\treturn x < 0 || (!x && y < 0);\n\t}\n} p[maxn], q[maxn];\nbool cmp(Point const &u, Point const &v) {\n\tint sU = u.site(), sV = v.site();\n\treturn sU < sV || (sU == sV && u.det(v) > 0);\n}\nstruct Edge {\n\tint u, v;\n\tbool operator < (Edge const &t) const {\n\t\treturn cmp(q[v] - q[u], q[t.v] - q[t.u]);\n\t}\n} e[maxn * maxn];\nLL f[maxn][maxm], ans;\nint main() {\n\tscanf(\"%d%d\", &n, &m);\n\tfor(int i = 0; i < n; ++i)\n\t\tp[i].read();\n\tsort(p, p + n);\n\tfor(int o = 0; o < n; ++o) {\n\t\tqtot = etot = 0;\n\t\tfor(int i = o; i < n; ++i) {\n\t\t\tmemset(f[qtot], -1, (m + 1) * sizeof(LL));\n\t\t\tq[qtot++] = p[i] - p[o];\n\t\t}\n\t\tsort(q + 1, q + qtot, cmp);\n\t\tfor(int i = 1; i < qtot; ++i) {\n\t\t\te[etot++] = (Edge){0, i};\n\t\t\tfor(int j = i + 1, k = i; j < qtot; ++j)\n\t\t\t\tif((q[j] - q[i]).det(q[k] - q[i]) <= 0) {\n\t\t\t\t\te[etot++] = (Edge){i, j};\n\t\t\t\t\tk = j;\n\t\t\t\t}\n\t\t\te[etot++] = (Edge){i, 0};\n\t\t}\n\t\tsort(e, e + etot);\n\t\tf[0][0] = 0;\n\t\tfor(int i = 0; i < etot; ++i) {\n\t\t\tint u = e[i].u, v = e[i].v;\n\t\t\tfor(int j = 1; j <= m; ++j) {\n\t\t\t\tLL tp = f[u][j - 1] < 0 ? -1 : f[u][j - 1] + q[u].det(q[v]);\n\t\t\t\tf[v][j] < tp && (f[v][j] = tp);\n\t\t\t}\n\t\t}\n\t\tans < f[0][m] && (ans = f[0][m]);\n\t}\n\tprintf(\"%lld.%c0\\n\", ans >> 1, \"05\"[ans & 1]);\n\treturn 0;\n}", "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6"} {"source_code": "#include\n#include\nusing namespace std;\nlong long n,k,a,b,cont;\nvoid minimo(){\n\twhile(true){\n\t\tif(n<=1)break;\n\t//\tcout<>n>>k>>a>>b;\n\tif(k==1){cout<<(n-1)*a;return 0;}\n\tminimo();\n\tcout<\nusing namespace std;\n#define ll long long\n\nint main()\n{\n int n, i, j, k, c0 = 0, c1 = 0, l, maxl = 0;\n cin >> n;\n int a[n];\n for(i=0;i> a[i];\n }\n\n for(i=0;i=0;j--){\n if(a[j] == 0){\n c0++;\n }\n }\n\n l = c0 + c1;\n //2cout << l << endl;\n if(l > maxl){\n maxl = l;\n }\n c0 = 0;\n c1 = 0;\n }\n\n cout << maxl;\n\n}", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"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;\n#define fi first\n#define se second\n#define p_b push_back\n#define all(n) n.begin(),n.end()\n#define rall(n) n.rbegin(),n.rend()\n#define mk_p make_pair\n#define pr_setp(n)cout<>number;\n\tll x = number;\n\tll ans = -1;\n\tint tmp = 0;\n\tmapf;\n\tif(x == 1)f[x]++;\n\tfor(int i =2;i<=sqrt(number);++i)\n\t{\n\t\twhile(!(number%i))\n\t\t{\n\t\t\tf[i]++;\n\t\t\tnumber/=i;\n\t\t}\n\t}\n\tif(number>1)f[number]++;\n\tcout<<(f.size()>1?1:(*f.begin()).fi)<\n#include\nusing namespace std;\nint main()\n{\n int sum=25,x,rw,clm,place=0;\n for(int i=1; i<=25; i++)\n {\n cin>>x;\n if(x==1)\n {\n\n if(i%5!=0)\n rw=(i/5)+1;\n else rw=i/5;\n\n if(i%5!=0)\n {\n clm=(i%5);\n }\n\n else clm=5;\n place=abs(3-rw)+abs(3-clm);\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\nusing namespace std;\n\ntemplate \nT Max(T x, T y) {return x > y ? x : y;}\n\ntemplate \nT Min(T x, T y) {return x < y ? x : y;}\n\ntemplate \nT Fabs(T x) {return x < 0 ? -x : x;}\n\n#define LL long long\n\nLL g, x, y, z, ans;\nLL h[3005][3005], h1[3005][3005];\nint n, m, a, b;\n\ndeque que;\n\nint main() {\n scanf(\"%d %d %d %d\", &n, &m, &a, &b);\n scanf(\"%lld %lld %lld %lld\", &g, &x, &y, &z);\n for(int i = 1; i <= n; i ++)\n for(int j = 1; j <= m; j ++) {\n h[i][j] = g;\n g = (g * x % z + y) % z;\n }\n for(int i = 1; i <= n; i ++) {\n for(int j = 1; j <= m + 1; j ++) {\n while(!que.empty() && j - que.front() >= b)\n que.pop_front();\n while(!que.empty() && h[i][que.back()] > h[i][j])\n que.pop_back();\n que.push_back(j);\n h1[i][j] = h[i][que.front()];\n }\n que.clear();\n }\n for(int j = 1; j <= m; j ++) {\n for(int i = 1; i <= n; i ++) {\n while(!que.empty() && i - que.front() >= a)\n que.pop_front();\n while(!que.empty() && h1[que.back()][j] > h1[i][j])\n que.pop_back();\n que.push_back(i);\n if(j >= b && i >= a)\n ans += h1[que.front()][j];\n }\n que.clear();\n }\n printf(\"%lld\\n\", ans);\n return 0;\n}\n", "src_uid": "4618fbffb2b9d321a6d22c11590a4773"} {"source_code": "#include \n\n\n\n#define x first\n\n#define y second\n\n#define NN 1111\n\n#define inf 0x3f3f3f3f\n\n#define MOD 1000000007\n\n\n\nusing namespace std;\n\ntypedef long long INT;\n\ntypedef pair pii;\n\n\n\nint find(int n, long long k){\n\n\tlong long p=1LL<p) return find(n-1, k-p);\n\n\treturn 0;\n\n}\n\n\n\nint main(){\n\n\n\n\tint n, i, j;\n\n\tlong long k;\n\n\tcin>>n>>k;\n\n\tj=find(n, k);\n\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#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define int long long\n//region TEMPLATE\n////@formatter:off\n#define double long double\ntypedef long long ll;\ntypedef unsigned long long ull;\ntemplatevoid __read(T &a) { cin >> a; }\ntemplate void __read(T &a, Args &... args) { cin >> a;__read(args...);}\n#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)\n#define makev(a, n) VI a(n); FOR(n) cin >> a[i]\n#define ALL(x) (x).begin(), (x).end()\n#define RALL(x) (x).rbegin(), (x).rend()\n#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)\n#define FOR(b) for(signed i = 0; i <(b); i++)\n#define FORE(i, l, r) for(int i = (l); i < (r); i++)\n#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)\ntypedef vector VI;\ntypedef vector> VVI;\ntypedef pair PII;\ntypedef pair, int> PPII;\nconstexpr ll M7 = 1000000007ll;\nconstexpr ll M9 = 1000000009ll;\nconstexpr ll MFFT = 998244353ll;\ntemplate void outv(T &a) { for (auto &x : a) cout << x << ' '; }\nstatic mt19937 rnd(static_cast(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)\nauto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)\n////@formatter:on\n//endregion\n\n\nint f(int a, int b, int t) {\n if (t == 0) return a + b;\n if (t == 1) return a - b;\n if (t == 2) return a * b;\n return a * 10 + b;\n}\n\nint calc(VI num, VI pr, VI op) {\n while (num.size() > 1) {\n int j = find(ALL(op), 3) - op.begin();\n if (j == op.size()){\n j = min_element(ALL(pr)) - pr.begin();\n }\n num[j] = f(num[j], num[j + 1], op[j]);\n op.erase(op.begin() + j);\n pr.erase(pr.begin() + j);\n num.erase(num.begin() + j + 1);\n }\n return num[0];\n}\n\n\nint32_t main() {\n map> num;\n for (int x = 0; x < 10'000; ++x) {\n VI d{x / 1000, x / 100 % 10, x / 10 % 10, x % 10};\n VI pr = {0, 1, 2};\n do{\n for(int o1 = 0; o1 < 4; ++o1){\n for(int o2 = 0; o2 < 4; ++o2){\n for(int o3 = 0; o3 < 4; ++o3){\n int z = calc(d, pr, {o1, o2, o3});\n num[z].insert(x);\n }\n }\n }\n }while(next_permutation(ALL(pr)));\n }\n make(int, k, m);\n set ans;\n for(auto& [x, a] : num){\n int d = k - x;\n if (num.count(d)){\n auto& b = num[d];\n for(int v1 : a){\n for(int v2 : b){\n ans.insert(v1 * 10000 + v2);\n if (ans.size() >= m){\n break;\n }\n }\n if (ans.size() >= m){\n break;\n }\n }\n }\n if (ans.size() >= m){\n break;\n }\n }\n while(ans.size() > m){\n ans.erase(--ans.end());\n }\n assert(ans.size() == m);\n for(auto& v : ans){\n string s = to_string(v);\n while(s.length() < 8){\n s.insert(s.begin(), '0');\n }\n cout << s << '\\n';\n }\n return 0;\n}", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c"} {"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 pair pii;\ntypedef pair piii;\ntypedef pair pll;\n \nconst int INF = 1e9+7;\n \nint arr[111];\n \nint main() {\n\tstring s;\n\tcin >> s;\n\tint size = s.size();\n\tfor (int i = 0; i < size; i++) arr[i] = s[i]-'0';\n \n\tif (size == 1) {\n\t\tprintf(\"0\\n\");\n\t\treturn 0;\n\t}\n \n\tif (size % 2 == 0) {\n\t\tprintf(\"%d\\n\", size / 2);\n\t\treturn 0;\n\t}\n\telse {\n\t\tbool check = false;\n\t\tfor (int i = 1; i < size; i++) {\n\t\t\tif (arr[i] == 1) check = true;\n\t\t}\n\t\tif (check) {\n\t\t\tprintf(\"%d\\n\", size / 2 + 1);\n\t\t\treturn 0;\n\t\t}\n\t\telse {\n\t\t\tprintf(\"%d\\n\", size / 2);\n\t\t\treturn 0;\n\t\t}\n\t}\n \n}\n", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "#include\n#include\nusing namespace std;\n\nint main()\n{\n int a,b;\n scanf(\"%d%d\",&a,&b);\n a=min(a,b);\n if (a&1) printf(\"Akshat\\n\");\n else printf(\"Malvika\\n\");\n return 0;\n}\n", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"source_code": "#include\n\nusing namespace std;\n\nint main()\n{\n int n,m, min=0,max=0;\n cin>>n;\n m=n;\n m=m-5;\n while(m>=0)\n {\n if(m>2)\n min=min+2;\n else\n min=min+m;\n m=m-7;\n }\n while(n>=0)\n {\n if(n>2)\n max=max+2;\n else\n max=max+n;\n n=n-7;\n }\n\n cout<\n#ifndef ONLINE_JUDGE\n# include \n# include \n#endif\n\n/*** TEMPLATE CODE STARTS HERE ***/\n\n#ifndef M_PI\n#define M_PI 3.1415926535897932384626433832795028841971693993751\n#endif\n\nusing namespace std;\n\ntypedef vector vs;\ntypedef long long ll;\ntypedef complex pnt;\ntypedef vector vi;\ntypedef vector vll;\ntypedef pair pii;\ntypedef pair pll;\n\n#define RA(x) begin(x), end(x)\n#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)\n#define SZ(x) ((ll) (x).size())\n\ntemplate\nvoid splitstr(const string &s, vector &out)\n{\n istringstream in(s);\n out.clear();\n copy(istream_iterator(in), istream_iterator(), back_inserter(out));\n}\n\ntemplate T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }\n\nstatic void redirect(int argc, const char **argv)\n{\n#ifndef ONLINE_JUDGE\n struct rlimit rlim;\n getrlimit(RLIMIT_STACK, &rlim);\n rlim.rlim_cur = 256 * 1024 * 1024;\n setrlimit(RLIMIT_STACK, &rlim);\n#ifndef __SANITIZE_ADDRESS__\n getrlimit(RLIMIT_DATA, &rlim);\n rlim.rlim_cur = 256 * 1024 * 1024;\n setrlimit(RLIMIT_DATA, &rlim);\n#endif\n#endif\n\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n if (argc > 1)\n {\n static filebuf f;\n f.open(argv[1], ios::in);\n cin.rdbuf(&f);\n if (!cin)\n {\n cerr << \"Failed to open '\" << argv[1] << \"'\" << endl;\n exit(1);\n }\n }\n\n if (argc > 2)\n {\n static filebuf f;\n f.open(argv[2], ios::out | ios::trunc);\n cout.rdbuf(&f);\n if (!cout)\n {\n cerr << \"Failed to open '\" << argv[2] << \"'\" << endl;\n }\n }\n}\n\n/*** TEMPLATE CODE ENDS HERE */\n\nstatic vector log2i;\nstatic vector g(17);\n\nstatic int rgcd(int p, int q)\n{\n int r = log2i[q - p];\n return gcd(g[r][p], g[r][q - (1 << r)]);\n}\n\nstatic ll countit(ll c, ll s, ll a, ll b)\n{\n#if 0\n ll ans2 = 0;\n for (ll i = 0; i < c; i++)\n ans2 += (s + i * a) / b;\n#endif\n\n assert(c >= 0);\n if (c == 0)\n return 0;\n ll ans = 0;\n ans += c * (s / b);\n s %= b;\n ans += c * (c - 1) / 2 * (a / b);\n a %= b;\n if (a != 0)\n {\n ll delta = a + b - s - 1;\n ll L = (a * c - delta + b) / b;\n ans += L * c - countit(L, delta, b, a);\n }\n\n#if 0\n assert(ans == ans2);\n#endif\n return ans;\n}\n\nstruct freq_t\n{\n ll d;\n ll n;\n ll p;\n\n freq_t(ll d = 1, ll n = 1) : d(d), n(n), p(d * n) {}\n};\n\nstatic ll countlte(const vector &freq, ll trg)\n{\n ll ans = 0;\n#if 1\n ll pp = 0;\n ll pn = 0;\n ll qp = 0;\n ll qn = 0;\n ll sum = 0;\n ll dist = 0;\n int N = SZ(freq);\n while (qp < N && sum + freq[qp].p <= trg)\n {\n sum += freq[qp].p;\n dist += freq[qp].n;\n qp++;\n }\n if (qp != N)\n {\n qn = (trg - sum) / freq[qp].d;\n dist += qn;\n sum += qn * freq[qp].d;\n }\n\n while (qp < N)\n {\n ll a = freq[pp].d;\n ll b = freq[qp].d;\n ll prem = freq[pp].n - pn;\n ll qrem = freq[qp].n - qn;\n ll pn2, qn2;\n if (qp > pp && sum - a * prem + b * qrem > trg)\n {\n pn2 = freq[pp].n;\n qn2 = qn + (trg - (sum - a * prem)) / b;\n }\n else\n {\n qn2 = freq[qp].n;\n pn2 = pn + (sum + b * qrem - trg + a - 1) / a;\n }\n\n ll c = pn2 - pn;\n ans += c * dist - c * (c - 1) / 2;\n ans += countit(c, trg - sum, a, b);\n\n dist += (qn2 - qn) - (pn2 - pn);\n sum += (qn2 - qn) * b - (pn2 - pn) * a;\n pn = pn2;\n qn = qn2;\n if (pn == freq[pp].n)\n {\n pp++;\n pn = 0;\n }\n if (qn == freq[qp].n)\n {\n qp++;\n qn = 0;\n }\n }\n ans += dist * (dist + 1) / 2;\n#else\n vector lst;\n for (const auto &f : freq)\n for (ll i = 0; i < f.n; i++)\n lst.push_back(f.d);\n for (int i = 0; i < SZ(lst); i++)\n {\n ll sum = 0;\n int j = i;\n while (j < SZ(lst) && sum + lst[j] <= trg)\n {\n sum += lst[j];\n j++;\n }\n ans += j - i;\n }\n#endif\n return ans;\n}\n\nint main(int argc, const char **argv)\n{\n redirect(argc, argv);\n ll N;\n cin >> N;\n\n log2i.resize(N + 1);\n log2i[0] = -1;\n for (int i = 1; i <= N; i++)\n log2i[i] = 31 - __builtin_clz(i);\n\n g[0].resize(N);\n for (int i = 0; i < N; i++)\n cin >> g[0][i];\n for (int i = 1; i < SZ(g); i++)\n {\n int s = 1 << (i - 1);\n g[i] = g[i - 1];\n for (int j = 0; j < N - s; j++)\n g[i][j] = gcd(g[i][j], g[i - 1][j + s]);\n }\n\n vector freq(100001);\n for (int i = 0; i < N; i++)\n {\n int start = i;\n while (start < N)\n {\n int c = rgcd(i, start + 1);\n int lo = start + 1;\n int hi = N + 1;\n while (hi - lo > 1)\n {\n int mid = (lo + hi) / 2;\n if (rgcd(i, mid) == c)\n lo = mid;\n else\n hi = mid;\n }\n freq[c] += lo - start;\n start = lo;\n }\n }\n\n vector freqt;\n ll total = 0;\n ll M = 0;\n for (int i = 1; i < SZ(freq); i++)\n if (freq[i])\n {\n freqt.emplace_back(i, freq[i]);\n total += freqt.back().p;\n M += freq[i];\n }\n M = M * (M + 1) / 2;\n M = (M + 1) / 2;\n\n ll lo = 0;\n ll hi = total;\n while (hi - lo > 1)\n {\n ll mid = lo + (hi - lo) / 2;\n ll lte = countlte(freqt, mid);\n if (lte >= M)\n hi = mid;\n else\n lo = mid;\n }\n cout << hi << '\\n';\n\n return 0;\n}\n", "src_uid": "7516cc0a6d76569a761cf795cfb22d50"} {"source_code": "#include\n#include\nusing namespace std;\nint main()\n{\nlong long n,m,s;\ncin>>n>>m>>s;\nlong long t=abs(m)+abs(n),k=abs(s-t);\nif(n==0 && m==0 && s%2==0){\ncout<<\"YES\"<t && k%2==0)\ncout<<\"YES\"<\nusing namespace std;\nint main()\n{\n int n;\n scanf(\"%d\",&n);\n printf(\"%d\",n/2+1);\n return 0;\n}", "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nchar c;\n\nint main()\n{\t\n\twhile(cin>>c)\n\t\tif(c=='9'||c=='H'||c=='Q') {cout<<\"YES\"<\n#include \n#include \nusing namespace std;\n\nint main () {\n // freopen(\"input.txt\", \"r\", stdin);\n // freopen(\"output.txt\", \"w\", stdout);\n int n, m;\n cin >> n >> m;\n if (!n && !m)\n cout << \"0 0\\n\";\n else if (!n)\n cout << \"Impossible\\n\";\n else if (!m)\n cout << n << \" \" << n << endl;\n else if (n <= m)\n cout << m << \" \" << m - 1 + n << endl;\n else\n cout << n << \" \" << \" \" << n - 1 + m << endl;\n return 0;\n}", "src_uid": "1e865eda33afe09302bda9077d613763"} {"source_code": "#include \n#include \n#include \nusing namespace std;\ntypedef long long LL;\nconst int maxn = 300001, maxs = 10001, mod = 1000000007;\nint n, a[maxn], b[maxn], len, num[maxs];\nchar str[maxs];\nint divideAndRemain(int x)\n{\n\tif(x == 1)\n\t\treturn 0;\n\tint ret = 0;\n\tconst int BASE = (int)1e9;\n\tfor(int i = len - 1; i >= 0; --i)\n\t{\n\t\tLL tmp = (LL)ret * BASE + num[i];\n\t\tnum[i] = tmp / x;\n\t\tret = tmp % x;\n\t}\n\tfor( ; len > 1 && !num[len - 1]; --len);\n\treturn ret;\n}\nint f[2][maxn << 1 | 1], sz[2], cur, pre = 1;\ninline void mod_add(int &x, int y)\n{\n\tif((x += y) >= mod)\n\t\tx -= mod;\n}\ninline void mod_sub(int &x, int y)\n{\n\tif((x -= y) < 0)\n\t\tx += mod;\n}\nint main()\n{\n\tscanf(\"%d\", &n);\n\ta[1] = 1;\n\tfor(int i = 2; i <= n; ++i)\n\t\tscanf(\"%d\", a + i);\n\tfor(int i = 1; i <= n; ++i)\n\t\tscanf(\"%d\", b + i);\n\tscanf(\"%s\", str);\n\tlen = strlen(str);\n\tfor(int i = 0; i * 9 < len; ++i)\n\t{\n\t\tint L = i * 9, R = min((i + 1) * 9, len) - 1;\n\t\tfor(num[i] = 0; L <= R; num[i] = num[i] * 10 + (str[len - 1 - (R--)] - '0'));\n\t}\n\tlen = (len - 1) / 9 + 1;\n\tf[cur][sz[cur]++] = 1;\n\tfor(int i = 1; i <= n; ++i)\n\t{\n\t\tint rem = divideAndRemain(a[i]);\n\t\tsz[pre] = 0;\n\t\tfor(int j = rem; j < sz[cur]; j += a[i], ++sz[pre])\n\t\t\tf[pre][sz[pre]] = f[cur][j];\n\t\tsz[cur] = sz[pre] + b[i];\n\t\tfor(int j = 0, ways = 0; j < sz[cur]; ++j)\n\t\t{\n\t\t\tif(j < sz[pre])\n\t\t\t\tmod_add(ways, f[pre][j]);\n\t\t\tif(j > b[i])\n\t\t\t\tmod_sub(ways, f[pre][j - b[i] - 1]);\n\t\t\tf[cur][j] = ways;\n\t\t}\n\t}\n\tprintf(\"%d\\n\", len == 1 && num[0] < sz[cur] ? f[cur][num[0]] : 0);\n\treturn 0;\n}\n", "src_uid": "71b23bc529ee1484d9dcea84def45d53"} {"source_code": "#include \n\n#define ff first\n#define ss second\n#define mp make_pair\n\nusing namespace std;\n\n\nvector g[5003];\n\nint cnt[5003], a, b, c, d, vis[5003], p[5003];\n\nint dfs(int u){\n\n\tfor(int v : g[u]){\n\t\tcnt[u] += dfs(v);\n\t\tvis[u] |= vis[v];\n\t}\n\n\tif(g[u].empty()){\n\t\tcnt[u]++;\n\t\tif(u == a) vis[u] = 1;\n\t\tif(u == b) vis[u] = 2;\n\t\tif(u == c) vis[u] = 4;\n\t\tif(u == d) vis[u] = 8;\n\t}\n\treturn cnt[u];\n}\n\nvector v;\n\nbool dp[5003][5003];\nint mark[5003][5003], pass;\n\nbool f(int i, int j){\n\tif(j < 0) return 0;\n\tif(j == 0) return 1;\n\tif(i == v.size()) return 0;\n\n\tbool &ans = dp[i][j];\n\n\tif(mark[i][j]) return ans;\n\tmark[i][j] = 1;\n\n\treturn ans = f(i+1, j) | f(i+1, j - v[i]);\n}\n\nint main(){\n\tint n;\n\n\tscanf(\"%d\", &n);\n\n\tscanf(\"%d %d %d %d\", &a, &b, &c, &d);\n\n\tfor(int i = 2; i <= n; i++){\n\t\tscanf(\"%d\", p+i);\n\t\tg[p[i]].push_back(i);\n\t}\n\n\tdfs(1);\n\n\tif(cnt[1] % 2) return printf(\"NO\\n\"), 0;\n\n\tint sza, szb, szc, szd;\n\tfor(int u : g[1]){\n\t\tif(!vis[u])\n\t\t\tv.push_back(cnt[u]);\n\t\telse{\n\t\t\tif(vis[u] == 1) sza = cnt[u];\n\t\t\tif(vis[u] == 2) szb = cnt[u];\n\t\t\tif(vis[u] == 4) szc = cnt[u];\n\t\t\tif(vis[u] == 8) szd = cnt[u];\n\t\t}\n\t}\n\n\t// printf(\"%d %d %d %d\\n\", sza, szb, szc, szd);\n\n\t// printf(\"%d %d\\n\", (cnt[1] - 2)/2 - szc, (cnt[1] - 2)/2 - szb);\n\t// printf(\"%d %d\\n\", f(0, (cnt[1] - 2)/2 - szc), f(0, (cnt[1] - 2)/2 - szb));\n\n\tint can1 = 0, can2 = 0;\n\n\t{\n\t\tfor(int i = 0; i < sza; i++){\n\t\t\tfor(int j = 0; j < szb; j++)\n\t\t\t\tcan1 |= f(0, (cnt[1] - 2)/2 - szc - i - j);\n\t\t}\n\t}\n\t{\n\t\tfor(int i = 0; i < szc; i++){\n\t\t\tfor(int j = 0; j < szd; j++)\n\t\t\t\tcan2 |= f(0, (cnt[1] - 2)/2 - sza - i - j);\n\t\t}\n\t}\n\n\n\tif(can1 && can2)\n\t\tprintf(\"YES\\n\");\n\telse printf(\"NO\\n\");\n\n\n\n\n\treturn 0;\n}", "src_uid": "87db879f0ca422020125a3e4d99d3c23"} {"source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define FOR(i, a, b) for (int i = (a); i < (b); ++i)\n#define REP(i, n) FOR(i, 0, n)\n#define TRACE(x) cout << #x << \" = \" << x << endl\n#define _ << \" _ \" <<\n\ntypedef long long llint;\ntypedef pair par;\n#define len first\n#define cnt second\n\nvector V;\n\nvoid split(llint len) {\n V.clear();\n if (len == 0) return;\n\n V.push_back({len+1, 0});\n V.push_back({len, 1});\n \n for (int i = 0; i < (int)V.size(); i += 2) {\n assert(V[i].len == V[i+1].len + 1);\n\n llint next_len1 = V[i].len / 2, next_cnt1 = V[i].cnt;\n llint next_len2 = (V[i+1].len-1) / 2, next_cnt2 = V[i+1].cnt;\n \n V[i+1].len/2 == next_len1 ? next_cnt1 += V[i+1].cnt : next_cnt2 += V[i+1].cnt;\n (V[i].len-1)/2 == next_len1 ? next_cnt1 += V[i].cnt : next_cnt2 += V[i].cnt;\n \n if (next_len1 == 0 && next_len2 == 0) break;\n V.push_back({next_len1, next_cnt1});\n V.push_back({next_len2, next_cnt2});\n }\n \n while (V.size() && V.back().first == 0) V.pop_back();\n llint cnt1 = 0;\n while (V.size() && V.back().first == 1) {\n cnt1 += V.back().cnt;\n V.pop_back();\n }\n if (cnt1 > 0) V.push_back({1, cnt1});\n}\n\n\nllint countGaps(llint n, llint d) {\n split(n);\n llint ret = 0;\n for (auto& p: V) {\n if (p.len > 0 && (p.len - 1) / 2 >= d) ret += p.cnt;\n }\n return ret;\n}\n\nllint solve(llint l, llint r, llint d, llint k) {\n llint m = (l + r - 1) / 2;\n if (k == 1) {\n return m;\n }\n --k;\n \n llint left = countGaps(m - l, d);\n llint right = countGaps(r - m - 1, d + 1);\n\n if (left + right >= k) {\n return solve(l, m, d, k - right);\n } else {\n return solve(m+1, r, d, k - left);\n }\n}\n\nint main(void) {\n llint k, n;\n scanf(\"%lld %lld\", &n, &k);\n\n if (k == 1) {\n printf(\"%lld\\n\", 1LL);\n return 0;\n }\n if (k == 2) {\n printf(\"%lld\\n\", n);\n return 0;\n }\n \n n -= 2;\n k -= 2;\n\n llint lo = 0, hi = n;\n while (lo < hi) {\n llint mid = (lo + hi + 1) / 2;\n if (countGaps(n, mid) < k) {\n hi = mid - 1;\n } else {\n lo = mid;\n }\n }\n \n printf(\"%lld\\n\", solve(0, n, lo, k) + 2);\n return 0;\n}\n", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f"} {"source_code": "#include\nusing namespace std;\ntypedef long long int ll;\nint main()\n{\n ll n;\n cin>>n;\n ll a,b,c;\n cin>>a>>b>>c;\n ll a1,b1,c1;\n cin>>a1>>b1>>c1;\n ll ma=min(a,b1)+min(b,c1)+min(c,a1);\n ll mi=a-min(a1+c1,a)+b-min(b,b1+a1)+c-min(c,b1+c1);\n cout<\nusing namespace std;\nint a[55],b[55],c,n;\nint main()\n{\n cin>>n;\n for(int i=1;i<=n;i++)\n cin>>a[i];\n sort(a+1,a+n+1);\n for(int i=1;i<=n;i++)\n if(a[i]!=a[i-1]) b[++c]=a[i];\n for(int i=3;i<=c;i++)\n if(b[i]-b[i-2]==2 && b[i]-b[i-1]==1){\n cout<<\"YES\";\n return 0;\n }\n cout<<\"NO\";\n}", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "#include \n#define ll long long\nusing namespace std;\nmapmp;\n\nint main()\n{\n int sum;\n int a,b,c,d;\n cin>>a>>b>>c>>d;\n for(int i=0;i<=1000000;i++){\n sum=b+(i*a);\n mp[sum]=1;\n\n }\n for(int i=0;i<=1000000;i++){\n sum=d+(i*c);\n if(mp[sum]==1){\n cout<\nusing namespace std;\nconst int maxx=1e4+10;\nint a[10005],dp[10004][105],ans=1;\nmapvis;\nvector>v;\nint main()\n{\n int n;\n scanf(\"%d\",&n);\n for(int i=1; i<=n; i++)\n {\n scanf(\"%d\",a+i);\n vis[a[i]]++;\n }\n for(auto p:vis)\n v.push_back(p);\n dp[0][0]=1;\n for(auto p:v)\n {\n int x=p.first;\n int y=p.second;\n for(int i=1e4; i>0; i--)\n {\n for(int j=1; j<=n; j++)\n {\n for(int k=1; k<=y && k<=j && i-x*k>=0; k++)\n {\n dp[i][j]+=dp[i-x*k][j-k];\n }\n }\n }\n }\n if(v.size()==2)\n {\n ans=n;\n }\n else\n {\n for(auto p:v)\n {\n int x=p.first;\n int y=p.second;\n for(int i=1;i<=y;i++)\n {\n if(dp[i*x][i]==1)\n ans=max(ans,i);\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#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#pragma comment(linker, \"/STACK:200000000\")\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 fore(i, a, n) for(int i = (int)(a); i < (int)(n); i++)\n#define pb push_back\n#define mp make_pair\n#define fs first\n#define sc second\n#define last(a) (int(a.size()) - 1)\n#define all(a) a.begin(), a.end()\n\nconst double EPS = 1E-9;\nconst int INF = 1000000000;\nconst int64 INF64 = (int64) 1E18;\nconst double PI = 3.1415926535897932384626433832795;\n\nstruct robot {\n int c, f, l;\n};\n\nint d;\n\ninline bool operator < (const robot &a, const robot &b) {\n if (a.l != b.l)\n return a.l < b.l;\n if (!a.l)\n return false;\n return a.f > b.f;\n}\n\nint sz, bad, ans1, ans2;\nint64 t[110000];\n\nvoid take(int t1, int f1, int t2, int f2) {\n t1 += t2;\n t2 -= min(t2, bad);\n int n = sz - t2;\n\n int pos = int(upper_bound(t, t + n, f2) - t);\n t1 += pos;\n if (pos)\n f1 += (int)t[pos - 1];\n\n if (t1 > ans1 || t1 == ans1 && f1 < ans2) {\n ans1 = t1;\n ans2 = f1;\n }\n}\n\nint main() {\n#ifdef RADs_project\n freopen(\"input.txt\", \"rt\", stdin);\n freopen(\"output.txt\", \"wt\", stdout);\n#endif\n \n int n, s;\n cin >> n >> d >> s;\n\n vector a, b;\n forn(i, n) {\n robot x;\n scanf(\"%d%d%d\", &x.c, &x.f, &x.l);\n x.l = x.l >= d;\n if (x.c)\n a.pb(x);\n else\n b.pb(x);\n }\n\n sort(all(a));\n sort(all(b));\n\n sz = 0;\n int64 sum = 0;\n ford(i, b.size())\n if (b[i].l) {\n sum += b[i].f;\n t[sz++] = sum;\n }\n else\n bad++;\n\n take(0, 0, 0, s);\n\n int64 free = 0;\n forn(i, a.size())\n free += a[i].c;\n free -= (int)a.size();\n\n sum = 0;\n ford(i, a.size())\n if (a[i].l && s >= a[i].f) {\n sum += a[i].f;\n s -= a[i].f;\n free++;\n take((int)a.size(), (int)sum, (int)min(free, (int64)b.size()), s);\n }\n\n cout << ans1 << ' ' << ans2 << endl;\n \n return 0;\n}", "src_uid": "e69f42403f3b0357e06a14523025b34a"} {"source_code": "#include\nusing namespace std;\nint main(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n long long n,m;\n cin>>n>>m;\n long long a[10]={0};\n long long g = n/10;\n if(g!=0){\n for(int i =0;i<10;i++){\n a[i]=g;\n }\n a[0]--;\n }\n g = n%10;\n for(int i = 0;i<=g;i++) a[i]++;\n \n if((n/10)==0) a[0]--;\n long long b[10]= {0};\n g = m/10;\n if(g!=0){\n for(int i =0;i<10;i++){\n b[i]=g;\n }\n b[0]--;\n }\n g = m%10;\n for(int i = 0;i<=g;i++) b[i]++;\n if((m/10)==0) b[0]--;\n long long count = 0;\n count += a[0]*b[0];\n \n for(int i = 1;i<=9;i++){\n count += a[i]*b[10-i];\n }\n for(int i = 0;i<=5;i++){\n count += a[i]*b[5-i];\n }\n count += (a[6]*b[9])+(a[9]*b[6]);\n count += (a[7]*b[8])+(a[8]*b[7]);\n cout<\n#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\ntypedef long long ll;\n\nint main() {\n int N, K;\n cin >> N >> K;\n int repass = 0;\n for(int n = N-1; n >= 0; --n)\n {\n int r = 3;\n r = min(r, K-2*n);\n r = max(r, K-5*n);\n repass += r == 2;\n K -= r;\n assert(r >= 2 && r <= 5);\n }\n cout << repass << endl;\n}\n", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"source_code": "\n\n//# pragma GCC optimize (\"O0\")\n//# pragma GCC optimize (\"O3\")\n//# pragma GCC optimize (\"Ofast\")\n//# pragma GCC optimize (\"unroll-loops\")\n\n#include \n\n#define all(x) x.begin(), x.end()\n#define UN -1\n#define VIS -2\n#define EX -3\n#define mp(a, b) make_pair(a, b)\n#define pb push_back\n#define pob pop_back()\n#define puf push_front\n#define pof pop_front()\n#define clr(a) (a).clear()\n#define sz(a) (int)(a).size()\n#define forn(t, n) for(int t = 0; t < n; t++)\n#define foren(t, n) for(int t = 1; t <= n; t++)\n#define llm LONG_LONG_MAX\n#define llmn LONG_LONG_MIN\n#define intm INT_MAX\n#define intmn INT_MIN\n#define dblm DBL_MAX\n#define dblmn DBL_MIN\n#define mod 1000000007\n#define mod2 1000000009\n#define mil 1111111\n#define bil 1111111111\n#define pi M_PI\n#define euler 2.718281828459\n#define eps 1e-12\n#define degrad (pi/180.0)\n#define raddeg (180.0/pi)\n#define uset unordered_set\n#define umap unordered_map\n#define sq(a) (a * a)\n#define DBG(x) cout << #x << \": \" << x << \"\\n\";\n#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\nusing namespace std;\ntypedef long long ll;\ntypedef vector vll; typedef pair pll; typedef vector vpll;\ntypedef vector vi; typedef pair ii; typedef vector vii; typedef vector vvi;\ntypedef pair iii; typedef pair iiii; typedef pair tll;\ntypedef vector vvii; typedef vector vvll; typedef vector vc; typedef vector vvc;\ntypedef vector vb; typedef vector vvb; typedef queue qi; typedef queue qll;\ntypedef queue qii; typedef vector vtll; typedef vector viii; typedef pair ppll;\ntypedef priority_queue pqi; typedef priority_queue pqll;\ntypedef pair iii; typedef vector viii; typedef vector vs;\ntypedef vector vd; typedef pair dd; typedef vector

vdd; typedef pair riii;\ntypedef vector > vvd; typedef vector vvvi;\n\ntemplate void pv(vector &vec) { forn(i, sz(vec)) cout << vec[i] << (i == sz(vec) - 1 ? '\\n' : ' '); }\n\n//ifstream in(\"/home/danza/CLionProjects/ksp/in.in\");\n//ofstream out(\"/home/danza/CLionProjects/ksp/out.out\");\n//#define cin in\n//#define cout out\n\nint main() { fio\n ll n, m;\n cin >> n >> m;\n if(n > m)\n swap(n, m);\n if(n == 1)\n cout << (m / 6 * 6 + 2 * max((m % 6) - 3, 0LL)) << '\\n';\n else if(n == 2) {\n if(m == 2)\n cout << 0 << '\\n';\n else if(m == 3)\n cout << 4 << '\\n';\n else if(m == 7)\n cout << 12 << '\\n';\n else\n cout << n * m << '\\n';\n }\n else\n cout << (n * m - (n * m) % 2) << '\\n';\n\n return 0;\n}", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70"} {"source_code": "#include \nusing namespace std;\n#define sc(x) scanf(\"%d\",&x)\n#define scc(x) scanf(\"%c\",&x)\n#define scl(x) scanf(\"%lld\",&x)\n#define sz(v)\t \t(v.size())\n#define mem(v, d)\t\tmemset(v, d, sizeof(v))\n#define oo\t\t\t\t2000000100\n#define OO\t\t\t\t2000000000000000100\n#define PI 3.14159265\n#define S second\n#define F first\n#define Ceil(x,y) ((x+y-1)/y)\n#define EPS 1e-8\n#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\nconst double pi=3.14159265358979323846264338327950288419716939937510582097494459;\ntypedef unsigned int uint;\ntypedef long long ll;\nint dX[] = {0,0,1,-1,0};\nint dY[] = {1,-1,0,0,0};\nstring alpha = \"abcdefghijklmnopqrstuvwxyz\";\nconst int MOD = 998244353;\nconst int N = 105;\nint dp[N][N][N];\nstring a,b,c;\nvector longestPrefix;\nvoid computePrefix(string pat)\n{\n int m = sz(pat);\n longestPrefix.resize(m);\n\n for(int i = 1,j = 0;i 0 && pat[j] != pat[i])\n j = longestPrefix[j-1];\n if(pat[j] == pat[i]) longestPrefix[i] = ++j;\n else longestPrefix[i] = j;\n }\n}\nint solve(int i=0,int j=0,int k=0)\n{\n if(k == sz(c)) return -oo;\n if(i == sz(a) || j == sz(b)) return 0;\n int& ret = dp[i][j][k];\n if(~ret) return ret;\n ret = max(solve(i+1,j,k),solve(i,j+1,k));\n if(a[i] == b[j]){\n while(k > 0 && c[k] != a[i]) k = longestPrefix[k-1];\n if(k<0){\n cout << \"a8a\" << endl;\n }\n ret = max(ret,solve(i+1,j+1,k+(a[i]==c[k]))+1);\n }\n return ret;\n}\nvoid Print(int i = 0,int j = 0,int k = 0)\n{\n if(k == sz(c)) return;\n if(i == sz(a) || j == sz(b)) return;\n if(solve(i,j,k) == solve(i+1,j,k)) Print(i+1,j,k);\n else if(solve(i,j,k) == solve(i,j+1,k)) Print(i,j+1,k);\n else {\n while(k > 0 && c[k] != a[i]) k = longestPrefix[k-1];\n cout<>a>>b>>c;\n mem(dp,-1);\n computePrefix(c);\n if(solve()) Print();\n else puts(\"0\");\n\n return 0;\n}\n", "src_uid": "391c2abbe862139733fcb997ba1629b8"} {"source_code": "#include\n#include\n#include \n#include\nusing namespace std;\nint main()\n{\n long long int x,y,z;\n \n cin>>x>>y>>z;\n \n if(x>y+z)\n {\n cout<<\"+\";\n }\n else if(y>x+z)\n {\n cout<<\"-\";\n \n }\n else if(x==y&&x>=z&&y>=z&&z==0)\n {\n cout<<\"0\";\n }\n else\n {\n cout<<\"?\";\n }\n \n}", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"source_code": "#include \n\nusing namespace std;\n\n\nint main()\n{\n long long int n,l,r;\n long long int M=(1e+9)+7;\n long long int a1=0,a2=0,a3=0,k;\n cin>>n>>l>>r;\n k=r-l+1;\n if(k==1){\n if(l%3==1)\n a2=1;\n if(l%3==0)\n a1=1;\n if(l%3==2)\n a2=1;\n }\n else{\n if(k%3==0){\n a1=a2=a3=k/3;\n }\n else{\n if(l%3==0){\n if(k%3==1)\n {a1=k/3+k%3;\n a2=a3=k/3;}\n if(k%3==2){\n a1=a2=k/3+1;\n a3=k/3;\n }\n }\n if(l%3==1){\n if(k%3==1)\n {a2=k/3+k%3;\n a1=a3=k/3;}\n if(k%3==2){\n a3=a2=k/3+1;\n a1=k/3;\n }\n }\n if(l%3==2){\n if(k%3==1)\n {a3=k/3+k%3;\n a1=a2=k/3;}\n if(k%3==2){\n a1=a3=k/3+1;\n a2=k/3;\n }\n }\n }\n }\n long long int dp[n+1][3]={{0}};\n dp[0][0]=a1,dp[0][1]=a2,dp[0][2]=a3;\n for(long long int i=1;i<=n;i++){\n dp[i][0] = ((a2 % M * dp[i - 1][2] % M) % M +\n ((a3 % M * dp[i - 1][1] % M) % M +\n (a1 % M * dp[i - 1][0] % M) % M)%M)%M;\n dp[i][1] = (((a3 % M * dp[i - 1][2] % M) % M +\n (a1 % M * dp[i - 1][1] % M) % M +\n (a2 % M * dp[i - 1][0] % M) % M)%M)%M;\n dp[i][2] =((a1 % M * dp[i - 1][2] % M) % M +\n ((a2 % M * dp[i - 1][1] % M) % M +\n (a3 % M * dp[i - 1][0] % M) % M)%M)%M;\n }\n cout<\n#include \n#include \nusing namespace std;\n\nvoid sieve(vector &p)\n{\n\tint n = p.size();\n\tp[0] = p[1] = 1;\n\t\n\tint root = sqrt(n);\n\tfor(int i = 2; i <= root; i++)\n\t{\n\t\tif(!p[i])\n\t\t{\n\t\t\tfor(long j = i *i *1l; j <= n; j += i)\n\t\t\t\tp[j] = 1;\n\t\t}\n\t}\n}\n\nint main()\n{\n\tios::sync_with_stdio(false);\n\t\n\tint a, b, k;\n\tcin >> a >> b >> k;\n\t\n\tvector isPrime(b +1);\n\tsieve(isPrime);\t\n\t\n\tint primeCount = 0;\n\tvector prime;\n\t\n\tfor(int i = a; i <= b; i++)\n\t{\n\t\tif(!isPrime[i])\n\t\t{\n\t\t\tprimeCount++;\n\t\t\tprime.push_back(i);\n\t\t}\n\t}\n\t\n\tif(primeCount < k)\n\t{\n\t\tcout << \"-1\\n\";\n\t\treturn 0;\n\t}\n\t\n\t/*\n\tcout << primeCount << '\\n';\n\tif(primeCount == k)\n\t{\n\t\tcout << prime[primeCount -1] << ' ' << prime[0] << '\\n';\n\t\tcout << b -a +1 << '\\n';\n\t\treturn 0;\n\t}*/\n\t\n\tint l = a, r = a;\n\tint count = 0;\n\tint ans = 0;\n\t\n\tint end = prime[primeCount -k];\n\t//cout << end <<'\\n';\n\twhile(l <= end)\n\t{\n\t\twhile(r <= b && count < k)\n\t\t{\n\t\t\tif(!isPrime[r])\n\t\t\t\tcount++;\n\t\t\tr++;\n\t\t}\n\t\t\n\t\tif(count >= k)\n\t\t\tans = max(ans, r -l);\n\t\t\n\t\tif(!isPrime[l])\n\t\t\tcount--;\n\t\t\t\n\t\tl++;\n\t}\n\t\n\tans = max(ans, b -end +1);\n\tcout << ans << '\\n';\n\treturn 0;\t\n}\n", "src_uid": "3e1751a2990134f2132d743afe02a10e"} {"source_code": "#include \n#include \nusing namespace std;\nint main(int argc, char *argv[]) {\n\tios_base::sync_with_stdio(false);\n\tcin.tie(nullptr);\n\tint N;\n\tcin >> N;\n\tvector a(N);\n\tfor(int &i: a) {\n\t\tchar c;\n\t\tcin >> c;\n\t\ti = c - '0';\n\t}\n\tfor(int p = 2; p <= N; p++) {\n\t\tint cnt = 0;\n\t\tfor(; N % p == 0; cnt++)\n\t\t\tN /= p;\n\t\tif(cnt > 0) {\n\t\t\tvector b(a);\n\t\t\tfor(int i = 0; i < a.size(); i++)\n\t\t\t\ta[(i + a.size() / p) % a.size()] = b[i] - b[(i + a.size() / p) % a.size()];\n\t\t}\n\t}\n\tbool no = false;\n\tfor(int &i: a)\n\t\tif(i > 0)\n\t\t\tno = true;\n\tcout << (no ? \"NO\" : \"YES\") << endl;\n\treturn 0;\n}", "src_uid": "63c00c5ea7aee792e8a30dc2c330c3f7"} {"source_code": "\n /*\n * round360.c++\n *\n * Created on: Jun 29, 2016\n * Author: Conan\n *\n * I reckon this is gonna be epic! :)\n */\n \n #include \n \n #define ull unsigned long long\n \n #define int long long\n \n #define ld long double\n \n #define mod 1000000007\n \n #define INF 1000000007\n \n #define rep(i,x,y) for(int i = x; i= y; --i)\n \n #define pb push_back \n \n using namespace std;\n \n \n /////////////////////////////////////////Fast (I/O)////////////////////////////////////\n \n inline int readInt(){\n \tint sign = 1, x = 0, c = getc(stdin);\n \twhile (c <= 32){\n \t\tc = getc(stdin);\n \t}\n \tif (c == '-'){\n \t\tsign = -1;\n \t\tc = getc(stdin);\n \t}\n \twhile ('0' <= c && c <= '9' && c != EOF){\n \t\tx = (x<<1) + (x<<3) + c - '0'; // x*10 == (x << 1) + (x << 3)\n \t\tc = getc(stdin);\n \t}\n \treturn x*sign;\n }\n \n inline void writeLong(long long x){\n \tif (x < 0){\n \t\tputc('-', stdout);\n \t\tx = -x;\n \t}\n \tchar s[40];\n \tint n = 0;\n \twhile (x || !n){ // if x == 0 it won't be printed! (added !n) :)\n \t\ts[n++] = '0' + x % 10;\n \t\tx /= 10;\n \t}\n \twhile (n--){\n \t\tputc(s[n], stdout);\n \t}\n }\n \n /* void prepareStream(){\n ios_base::sync_with_stdio(false);\n \tcin.tie(nullptr);\n \tcout.tie(nullptr);\n }\n */\n template \n T input() {\n T res;\n cin >> res;\n return res;\n }\n \n \n ////////////////////////////////////Variables/////////////////////////////////\n \n //int spiral[][2] = {{1,0} , {1, 1} , {-1, 1} , {-1, -1} , {1, -1}};\n \n //int c[1000001];\n int n, k, size, l, mid, r , ans = 1, cur = 1;\n string str;\n int a[105];\n\n \n ///////////////////////////////Auxiliary functions////////////////////////////\n \n bool des (int i , int j) { return i > j; }\n bool asc (int i , int j) { return i < j; }\n \n int gcd(int x, int y) { return y ? gcd(y, x % y) : x ;}\n \n int lcm(int x, int y) { return x * 1ll * y / gcd(x, y); }\n \n /////////////////////////////////Main Code//////////////////////////////////////\n int32_t main(){\n \n //prepareStream();\n \n //int arr[][3] = { {1,2,3}, {4,5,6}, {7,8,9}, {0,0,0} };\n int ed[9] = {1,2,3,4,7,8,9,6};\n n = readInt();\n \n // int arr[][3] = { {1,2,3}, {4,5,6}, {7,8,9}, {0,0,0} };\n \n cin>>str;\n \n bool ok1 = 0 , ok2 = 0,ok4 = 0 , ok3 = 0;\n\t\n\tfor(int i=0; i\nint a[2333][5],v1[233],v2[233],u[233];\nvoid get(int v) {\n\tu[v]=1;\n\tprintf(\"? %d\\n\",v);\n\tfflush(stdout);\n\tscanf(\"%d\",a[v]);\n\tfor (int i=1; i<=a[v][0]; ++i) scanf(\"%d\",a[v]+i);\n}\nint step(int v) {\n\tfor (int i=1; i<=a[v][0]; ++i)\n\t\tif (!u[a[v][i]]) return a[v][i];\n\treturn a[v][1];\n}\nvoid work() {\n\tmemset(u,0,sizeof u);\n\tint n,v=1,dep;\n\tscanf(\"%d\",&n);\n\tget(v);\n\tif (a[v][0]==1) dep=1; else {\n\t\tint n1=0,n2=0;\n\t\tfor (int t=step(v);; t=step(t)) {\n\t\t\tget(t); v1[++n1]=t; if (a[t][0]==1) break;\n\t\t}\n\t\tfor (int t=step(v);; t=step(t)) {\n\t\t\tget(t); v2[++n2]=t; if (a[t][0]==1) break;\n\t\t}\n\t\tdep=(n1+n2)/2+1;\n\t\tif (n1>n2) v=v1[n1-dep+1];\n\t\tif (n1\n#define ll long long\n#define F first\n#define S second\n#define pb push_back\n#define mp make_pair\n\nusing namespace std;\n\nint a[5][5], maxi = -100001, mini = 100001;\n\nint main()\n{\n for (int i = 1; i < 4; i++)\n {\n for (int j = 1; j < 4; j++)\n {\n cin >> a[i][j];\n if (a[i][j] > maxi && a[i][j] != 0)\n {\n maxi = a[i][j];\n }\n if (a[i][j] < mini && a[i][j] != 0)\n {\n mini = a[i][j];\n }\n }\n }\n a[2][2] = (maxi + mini) / 2;\n a[1][1] = a[1][2] + a[2][2] + a[3][2] - a[2][1] - a[3][1];\n a[3][3] = a[1][2] + a[2][2] + a[3][2] - a[2][3] - a[1][3];\n for (int i = 1; i < 4; i++)\n {\n for (int j = 1; j < 4; j++)\n {\n cout << a[i][j] << \" \";\n }\n cout << endl;\n }\n return 0;\n}\n", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"source_code": "#include\nusing namespace std;\nchar a,b;\nbool f1=0,f2=0;\nint main(){\n\tscanf(\"%c%c\",&a,&b);\n\tif(a=='h'||a=='a')\n\t\tf1=1;\n\tif(b=='1'||b=='8')\n\t\tf2=1;\n\tif(f1==1&&f2==1){\n\t\tprintf(\"3\\n\");\n\t\treturn 0;\n\t}\n\tif(f1==1||f2==1){\n\t\tprintf(\"5\\n\");\n\t\treturn 0;\n\t}\n\tprintf(\"8\\n\");\n\treturn 0;\t\t\n} ", "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef long long s64;\n\nconst int MaxN = 300005;\nconst int M = 1000000007;\n\ninline int add(int a, const int &b)\n{\n\ta += b;\n\treturn a >= M ? a - M : a;\n}\ninline int dec(int a, const int &b)\n{\n\ta -= b;\n\treturn a < 0 ? a + M : a;\n}\n\ninline int gcd(int a, int b)\n{\n\twhile (b > 0)\n\t{\n\t\ta %= b;\n\t\tswap(a, b);\n\t}\n\treturn a;\n}\n\ninline int modpow(int a, const int &n)\n{\n\tint res = 1;\n\tfor (int i = n; i; i >>= 1)\n\t{\n\t\tif (i & 1)\n\t\t\tres = (s64)res * a % M;\n\t\ta = (s64)a * a % M;\n\t}\n\treturn res;\n}\n\nint n, len1, len2;\nchar s1[MaxN], s2[MaxN];\n\nint pow2[MaxN];\nint fact[MaxN * 2], rfact[MaxN * 2];\n\nint pri_n = 0, pri[MaxN / 8];\nint phi[MaxN];\nbool book[MaxN];\n\ninline int binom(int n, int m)\n{\n\tif (m < 0 || m > n)\n\t\treturn 0;\n\treturn (s64)fact[n] * rfact[m] % M * rfact[n - m] % M;\n}\n\ninline void init_sieve(int n, int m)\n{\n\tpow2[0] = 1;\n\tfor (int i = 1; i <= m; ++i)\n\t{\n\t\tpow2[i] = pow2[i - 1] << 1;\n\t\tif (pow2[i] >= M)\n\t\t\tpow2[i] -= M;\n\t}\n\n\tfact[0] = 1;\n\tfor (int i = 1; i <= n; ++i)\n\t\tfact[i] = (s64)fact[i - 1] * i % M;\n\trfact[n] = modpow(fact[n], M - 2);\n\tfor (int i = n; i >= 1; --i)\n\t\trfact[i - 1] = (s64)rfact[i] * i % M;\n\n\tphi[1] = 1;\n\tfor (int i = 2; i <= m; ++i)\n\t{\n\t\tif (!book[i])\n\t\t\tphi[pri[pri_n++] = i] = i - 1;\n\n\t\tfor (int j = 0; j < pri_n; ++j)\n\t\t{\n\t\t\tint p = pri[j], prod = i * p;\n\t\t\tif (prod > m)\n\t\t\t\tbreak;\n\t\t\tbook[prod] = true;\n\n\t\t\tphi[prod] = phi[i];\n\t\t\tif (i % p)\n\t\t\t\tphi[prod] *= p - 1;\n\t\t\telse\n\t\t\t{\n\t\t\t\tphi[prod] *= p;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tphi[i] = add(phi[i], phi[i - 1]);\n\t}\n\n\tfor (int i = 1; i <= m; ++i)\n\t\tphi[i] = ((phi[i] << 1) % M + M - 1) % M;\n}\n\nint main()\n{\n\tscanf(\"%s%s%d\", s1, s2, &n);\n\tlen1 = strlen(s1);\n\tlen2 = strlen(s2);\n\n\tinit_sieve(len1 + len2, 1 + max(n, max(len1, len2)));\n\n\tint d1 = 0, q1 = 0;\n\tint d2 = 0, q2 = 0;\n\tfor (int i = 0; i < len1; ++i)\n\t\ts1[i] == 'A' ? ++d1 : (s1[i] == 'B' ? ++d2 : ++q1);\n\tfor (int i = 0; i < len2; ++i)\n\t\ts2[i] == 'A' ? --d1 : (s2[i] == 'B' ? --d2 : ++q2);\n\n\tint cop = 0, res = 0;\n\tfor (int i = 1; i <= n; ++i)\n\t\tcop = add(cop, (s64)phi[n / i] * pow2[i] % M);\n\n\tif (len1 == len2)\n\t{\n\t\tint total = 0;\n\t\tfor (int i = 0; i < len1 && ~total; ++i)\n\t\t{\n\t\t\tif (s1[i] + s2[i] == 'A' + 'B')\n\t\t\t\ttotal = -1;\n\t\t\tif (s1[i] + s2[i] == '?' + '?')\n\t\t\t\t++total;\n\t\t}\n\n\t\tif (~total)\n\t\t{\n\t\t\tint any = (pow2[n + 1] + M - 2) % M;\n\t\t\tany = (s64)any * any % M;\n\t\t\tres = (s64)pow2[total] * (any + M - cop) % M;\n\t\t}\n\t}\n\n\td2 += q1 - q2;\n\tfor (int d = -q2; d <= q1; ++d)\n\t{\n\t\tint new_d1 = d1 + d;\n\t\tint new_d2 = d2 - d;\n\t\tint ways = binom(q1 + q2, q2 + d);\n\n\t\tif (!new_d1 && !new_d2)\n\t\t\tres = add(res, (s64)cop * ways % M);\n\t\telse\n\t\t{\n\t\t\tint u = -new_d1, v = new_d2;\n\t\t\tif (u < 0)\n\t\t\t\tu = -u, v = -v;\n\t\t\tif (v < 0)\n\t\t\t\tu = -u, v = -v;\n\t\t\tif (u > 0 && v > 0)\n\t\t\t{\n\t\t\t\tint g = gcd(u, v);\n\t\t\t\tint k = n / (max(u, v) / g) + 1;\n\t\t\t\tres = add(res, (s64)ways * (pow2[k] + M - 2) % M);\n\t\t\t}\n\t\t}\n\t}\n\n\tprintf(\"%d\\n\", res);\n\n\treturn 0;\n}", "src_uid": "4a6525f37d70dd1bf4f33cef57371b64"} {"source_code": "#include \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<\nusing namespace std;\nconst int N = 255;\nint T,a[N];\nint main ()\n{\n ios::sync_with_stdio(false);\n cin >> T;int tmp;\n while (T--)\n {\n double mean = 0,var = 0;\n for (int i = 1;i <= 250;i++) cin >> a[i],mean += a[i];\n mean /= 250;\n for (int i = 1;i <= 250;i++) var += (a[i] - mean) * (a[i] - mean);\n var /= 250;double dev = sqrt(var);\n if (*max_element(a + 1,a + 251) / dev > 1.93) puts(\"poisson\");\n else puts(\"uniform\");\n }\n return 0;\n}", "src_uid": "6ef75e501b318c0799d3cbe8ca998984"} {"source_code": "#include\nusing namespace std;\n\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n\nset s;\n\nint vxcavalo[] = {-1, 1, 2, 2, 1, -1, -2, -2};\nint vycavalo[] = {2, 2, 1, -1, -2, -2, -1, 1};\n\nint main(){\n char ty, tx, cy, cx;\n cin>>ty>>tx>>cy>>cx;\n\n ty = ty-'a'+1;\n cy = cy-'a'+1;\n tx -='0';\n cx -='0';\n //cout<<(int)ty<<(int)tx<<\" \"<<(int)cy<<(int)cx<= 1 && cx + vxcavalo[i] <= 8 && cy + vycavalo[i] >= 1 && cy + vycavalo[i] <= 8){\n s.insert((cy+vycavalo[i])*10+(cx+vxcavalo[i]));\n }\n }\n\n for(int i=1; i<=8; i++){\n s.insert((i)*10+(tx));\n s.insert((ty)*10+(i));\n }\n\n for(int i=0; i<8; i++){\n if(tx + vxcavalo[i] >= 1 && tx + vxcavalo[i] <= 8 && ty + vycavalo[i] >= 1 && ty + vycavalo[i] <= 8){\n s.insert((ty+vycavalo[i])*10+(tx+vxcavalo[i]));\n }\n }\n\n //set::iterator i;for(i = s.begin(); i != s.end(); i++) cout<<*i<<\" \";cout<| Try Next One |-------'\n// '--------------' \t\t \n//\n#include\nusing namespace std;\ntypedef long long int ll;\nll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}\nll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i>t;while(t--)\n//#define endl '\\n'\nvoid solve()\n{\n\tint n,m;\n\tcin >> n >> m;\n\tvector v(m);\n\tfor(int i=0;i> v[i];\n\t}\n\tll mn=v[0];\n\tfor(int i=0;i> temp;\n\t\tmn=min(mn,temp);\n\t}\n\tll ans;\n\tans=mn;\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#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;\ntemplate inline T Max(T a,T b)\n{if(a>b)return a;else return b;}\ntemplate inline T Min(T a,T b)\n{if(a inline T gcd(T a,T b)\n{if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}\ntemplate inline T lcm(T a,T b)\n{if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}\ntemplate inline T TripleMax(T a,T b,T c)\n{return Max(Max(a,b),c);}\ntemplate inline T TripleMin(T a,T b,T c)\n{return Min(Min(a,b),c);}\n#define ll long long\n#define PB push_back\n#define MP make_pair\nconst long double\tpi = M_PI;\nconst long double\te = M_E;\nconst long double\tsqrt2 = M_SQRT2;\nconst int\t\t\tmaxt = 1000000;\nconst long double\teps = 1e-7;\n\nint\t\t\t\txp, yp, vp;\nint\t\t\t\tx, y, vmax, r;\ndouble\t\t\tlt, rt, mid;\nlong double\t\tret;\n\nint check (double t) {\n\tdouble\txf, yf;\n\tdouble\tbr;\n\tdouble\tdis;\n\tdouble\talefa;\n\tbr = sqrt(xp * xp + yp * yp);\n\talefa = vp * t / br;\n\t// final positions\n\txf = xp * cos(alefa) - yp * sin(alefa);\n\tyf = yp * cos(alefa) + xp * sin(alefa);\n\t// xf, yf = radius R; x, y = ship\n\tif (fabs(xf - x) < eps) {\n\t\tdis = abs(xf);\n\t} else {\n\t\tdouble\tk = (yf - y) / (xf - x);\n\t\tdouble\tb = yf - k * xf;\n\t\tdis = (abs(b)) / (sqrt(k * k + 1));\n\t}\n\t//cout << \"dis = \" << dis << endl;\n\tif (dis < r - eps) {\n\t\t// find tangency\n\t\tdouble\tdisa = sqrt(x * x + y * y);\n\t\tdouble\tdisb = sqrt(xf * xf + yf * yf);\n\t\tdouble\tdisab = sqrt((x - xf) * (x - xf) + (y - yf) * (y - yf));\n\t\tdouble\ttheta = acos((disa * disa + disb * disb - disab * disab) / (2 * disa * disb));\n\t\tdouble\toab, oba;\n\t\toab = (disa * disa + disab * disab - disb * disb) / (2 * disab * disa);\n\t\toba = (disb * disb + disab * disab - disa * disa) / (2 * disb * disab);\n\t\t// 角OAB和OBA必须是锐角,这个是很巧妙的条件限制。\n\t\t//cout << \"oab = \" << oab << \" oba = \" << oba << endl;\n\t\tif (oab < pi / 2 && oba < pi / 2 && oab >= 0 && oba >= 0) {\n\t\t\t//cout << \"cos(theta) = \" << (disa * disa + disb * disb - disab * disab) / (2 * disa * disb) << endl;\n\t\t\tdouble\tatheta;\n\t\t\tdouble\tbtheta;\n\t\t\tdouble\trettheta;\n\t\t\tdouble\tfidis;\n\t\t\tatheta = acos(r / disa);\n\t\t\tbtheta = acos(r / disb);\n\t\t\trettheta = theta - atheta - btheta;\n\t\t\t//cout << \"theta = \" << theta << \" atheta = \" << atheta << \" btheta = \" << btheta << \" rettheta = \" << rettheta << endl;\n\t\t\tfidis = sqrt(disa * disa - r * r) + sqrt(disb * disb - r * r) + rettheta * r;\n\t\t\tif (fidis / vmax > t) {\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t} else {\n\t\t\tdouble\tfidis = sqrt((x - xf) * (x - xf) + (y - yf) * (y - yf));\n\t\t\tif (fidis / vmax > t) {\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tdouble\tfidis = sqrt((x - xf) * (x - xf) + (y - yf) * (y - yf));\n\t\tif (fidis / vmax > t) {\n\t\t\treturn 0;\n\t\t} else {\n\t\t\treturn 1;\n\t\t}\n\t}\n}\n\nint main (int argc, const char* argv[]) {\n \n\tcin >> xp >> yp >> vp;\n\tcin >> x >> y >> vmax >> r;\n\tlt = 0;\n\trt = maxt;\n\twhile (fabs(lt - rt) > 0.000000001) {\n\t\tmid = (lt + rt) / 2;\n\t\tif (check(mid) == 1) {\n\t\t\trt = mid;\n\t\t} else {\n\t\t\tlt = mid;\n\t\t}\n\t}\n\tif (rt < eps) {\n\t\trt = 0;\n\t}\n\tcout << setprecision(15) << rt << endl;\n return 0;\n}\n", "src_uid": "e8471556906e5fa3a701842570fa4ee2"} {"source_code": "#include \nusing namespace std;\n\nlong long gcd(long long a, long long b) \n{ \n if (b == 0) \n return a; \n return gcd(b, a % b); \n}\n\nlong long findlcm(long long arr[], long long n) \n{ \n // Initialize result \n long long ans = arr[0]; \n \n // ans contains LCM of arr[0], ..arr[i] \n // after i'th iteration, \n for (long long i = 1; i < n; i++) \n ans = (((arr[i] * ans)) / \n (gcd(arr[i], ans))); \n \n return ans; \n} \n\nint main() {\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\",\"r\",stdin);\n\tfreopen(\"output.txt\",\"w\",stdout);\n#endif\n\tlong long n; cin>>n;\n\tif(n<3){\n\t\tcout<\nusing namespace std;\nvector opers;\nint modulo(1e9 + 7);\ntypedef long long LL;\nint pw(int x, int n) {\n\tint res(1);\n\twhile(n) {\n\t\tif(n & 1)\n\t\t\tres = (LL)res * x % modulo;\n\t\tx = (LL)x * x % modulo;\n\t\tn /= 2;\n\t}\n\treturn res;\n}\ninline bool isDigit(char c) {\n\treturn c >= '0' && c <= '9';\n}\nconst int N(111111);\nchar st[N];\nstruct Opad {\n\tstring str;\n\tint val, mul;\n\tOpad() {\n\t\tval = 0;\n\t\tmul = 1;\n\t}\n};\nvector opads;\nvoid operate() {\n\tOpad o1, o2;\n\to2 = opads.back();\n\topads.pop_back();\n\to1 = opads.back();\n\topads.pop_back();\n\tif(opers.back() == '+') {\n\t\tOpad res;\n\t\tres.val = ((LL)o1.val * o2.mul + o2.val) % modulo;\n\t\tres.mul = (LL)o1.mul * o2.mul % modulo;\n\t\topads.push_back(res);\n\t}else {\n\t\tOpad res;\n\t\tfor(int i((int)o1.str.size() - 1); i >= 0; i--) {\n\t\t\tfor(int j(0); j < (int)o1.str[i] - '0'; j++) {\n\t\t\t\tres.val = ((LL)res.val * o2.mul + o2.val) % modulo;\n\t\t\t\tres.mul = ((LL)res.mul * o2.mul) % modulo;\t\n\t\t\t}\n\t\t\tint mul(o2.mul), add(o2.val);\n\t\t\tfor(int j(0); j < 9; j++) {\n\t\t\t\to2.mul = ((LL)mul * o2.mul) % modulo;\n\t\t\t\to2.val = ((LL)mul * o2.val + add) % modulo;\n\t\t\t}\n\t\t}\n\t\topads.push_back(res);\n\t}\n\topers.pop_back();\n}\nOpad calc(const string & a) {\n\tOpad res;\n\tres.str = a;\n\tfor(int i(0); i < (int)a.size(); i++) {\n\t\tres.mul = res.mul * 10ll % modulo;\n\t\tres.val = (res.val * 10ll + a[i] - '0') % modulo;\n\t}\n\treturn res;\n}\nOpad calc(const string & le, const string & ri) {\n\t//cout << le << ' ' << ri << endl;\n\tOpad res;\n\tOpad a(calc(le)), b(calc(ri));\n\tint phil(0), phir(0);\n\tfor(int i(0); i < (int)le.size(); i++) {\n\t\tphil = ((LL)phil * 10ll + le[i] - '0') % (modulo - 1);\n\t}\n\tfor(int i(0); i < (int)ri.size(); i++) {\n\t\tphir = ((LL)phir * 10ll + ri[i] - '0') % (modulo - 1);\n\t}\n\t//cout << a.val << ' ' << b.mul << endl;\n\tint cur(1), curphi(1);\n\tfor(int i(1); i < le.size(); i++) {\n\t\tcur = cur * 10ll % modulo;\n\t\tcurphi = curphi * 10ll % (modulo - 1);\n\t}\n\tfor(int len(le.size()); len <= ri.size(); len++) {\n\t\tint leval, rival, lephi, riphi;\n\t\tif(len == le.size()) {\n\t\t\tleval = a.val;\n\t\t\tlephi = phil;\n\t\t}else {\n\t\t\tleval = cur;\n\t\t\tlephi = curphi;\n\t\t}\n\t\tif(len == ri.size()) {\n\t\t\trival = b.val;\n\t\t\triphi = phir;\n\t\t}else {\n\t\t\trival = (cur * 10ll + modulo - 1) % modulo;\n\t\t\triphi = (curphi * 10ll + modulo - 2) % (modulo - 1);\n\t\t}\n\t\t//printf(\"%d %d %d %d\\n\", leval, lephi, rival, riphi);\n\t\tint bs(pw(10, len));\n\t\t//cout << bs << endl;\n\t\t//cout << (rival + 1ll) * ((pw(bs, (riphi - lephi + modulo) % (modulo - 1)) - 1ll + modulo) * pw(bs - 1, modulo - 2) % modulo) % modulo << endl;\n\t\t//cout << ((rival - leval + 1ll + modulo) * pw(bs, (rival - leval + 1 + modulo) % (modulo - 1)) - (rival - leval + 2ll + modulo) * pw(bs, (riphi - lephi + modulo) % (modulo - 1)) + 1) % modulo * pw(bs - 1, modulo - 2) % modulo * pw(bs - 1, modulo - 2) % modulo << endl;\n\t\t//cout << ((rival + 1ll) * ((pw(bs, (riphi - lephi + modulo) % (modulo - 1)) - 1ll + modulo) * pw(bs - 1, modulo - 2) % modulo) % modulo - ((rival - leval + 1ll + modulo) * pw(bs, (rival - leval + 1 + modulo) % (modulo - 1)) - (rival - leval + 2ll + modulo) * pw(bs, (riphi - lephi + modulo) % (modulo - 1)) + 1) % modulo * pw(bs - 1, modulo - 2) % modulo * pw(bs - 1, modulo - 2) % modulo) << endl;\n\t\tint val = (((rival + 1ll) * ((pw(bs, (riphi - lephi + modulo) % (modulo - 1)) - 1ll + modulo) * pw(bs - 1, modulo - 2) % modulo) % modulo - ((rival - leval + 1ll + modulo) * pw(bs, (riphi - lephi + 1 + modulo) % (modulo - 1)) - (rival - leval + 2ll + modulo) * pw(bs, (riphi - lephi + modulo) % (modulo - 1)) + 1) % modulo * pw(bs - 1, modulo - 2) % modulo * pw(bs - 1, modulo - 2) % modulo) + modulo) % modulo;\n\t\tint mul = pw(bs, (riphi - lephi + modulo) % (modulo - 1));\n\t\tres.val = ((LL)res.val * mul + val) % modulo;\n\t\tres.mul = (LL)res.mul * mul % modulo;\n\t\t//cout << val << ' ' << mul << endl;\n\t\tcur = cur * 10ll % modulo;\n\t\tcurphi = curphi * 10ll % (modulo - 1);\n\t}\n\treturn res;\n}\nint main() {\n\tscanf(\"%s\", st);\n\tint len(strlen(st));\n\tfor(int i(0); i < len; i++) {\n\t\tif(isDigit(st[i])) {\n\t\t\tstring s;\n\t\t\tint j(i);\n\t\t\tfor( ; isDigit(st[j]); j++)\n\t\t\t\ts.push_back(st[j]);\n\t\t\tif(st[j] == '-') {\n\t\t\t\tstring t;\n\t\t\t\tfor(j++; isDigit(st[j]); j++)\n\t\t\t\t\tt.push_back(st[j]);\n\t\t\t\topads.push_back(calc(s, t));\n\t\t\t}else {\n\t\t\t\topads.push_back(calc(s));\n\t\t\t}\n\t\t\ti = j - 1;\n\t\t}else if(st[i] == '(') {\n\t\t\topers.push_back('(');\n\t\t}else if(st[i] == '+') {\n\t\t\topers.push_back('+');\n\t\t}else if(st[i] == ')') {\n\t\t\twhile(opers.back() != '(') {\n\t\t\t\toperate();\t\n\t\t\t}\n\t\t\toperate();\n\t\t}\n\t}\n\twhile(opers.size())\n\t\toperate();\n\tcout << opads.back().val << endl;\n}\n", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c"} {"source_code": "#include \n#define ll long long\nusing namespace std;\ninline void read(long long &x){\n char ch;\n bool flag=false;\n for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;\n for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());\n x=flag?-x:x;\n}\n\ninline void read(int &x){\n char ch;\n bool flag=false;\n for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;\n for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());\n x=flag?-x:x;\n}\n\ninline void write(long long x){\n static const long long maxlen=100;\n static char s[maxlen];\n if (x<0) { putchar('-'); x=-x;}\n if(!x){ putchar('0'); return; }\n long long len=0; for(;x;x/=10) s[len++]=x % 10+'0';\n for(long long i=len-1;i>=0;--i) putchar(s[i]);\n}\n\n\n#include // std::swap\n#include // std::pair, std::make_pair\n\n// Stein's algorithm, find the greatest common divisor (GCD) of m and n.\n// The result will always be non-negative.\n// If m or n is zero, the result will be the bigger one.\n// This implementation is 1 time faster than GNU STL std::gcd (C++17).\n// @param m: m above.\n// @param n: n above.\n// @return: GCD(m, n), always positive.\ntemplate \nT gcd(T m, T n) {\n if (!m || !n) return m | n;\n if (m < 0) m = -m;\n if (n < 0) n = -n;\n long long p = 0;\n while (!(m & 1) && !(n & 1))\n m >>= 1, n >>= 1, ++p;\n while (n) {\n while (!(m & 1)) m >>= 1;\n while (!(n & 1)) n >>= 1;\n if (m >= n) std::swap(m, n);\n n = (n - m) >> 1;\n }\n return m << p;\n}\n\n// As for equation:\n// mx + ny = gcd(m, n)\n// @param m: m above.\n// @param n: n above.\n// @return: r = (gcd(m, n), (x, y))\n// r.first is gcd\n// r.second.first is x\n// r.second.second is y\n// C++98 has no std::tuple, just put up with it.\ntemplate \nstd::pair > exgcd(T m, T n) {\n using std::make_pair;\n T x = 0, y = 1, xp = 1, yp = 0, xt, yt;\n for (T r = m % n, q = m / n; r; ) {\n xt = xp - q * x, xp = x, x = xt;\n yt = yp - q * y, yp = y, y = yt;\n m = n, n = r, r = m % n, q = m / n;\n }\n return make_pair(n, make_pair(x, y));\n}\n\n// As for congruence equation\n// mx = gcd(m, n) (mod n)\n// @param m: m above.\n// @param n: n above.\n// @return: x above.\ntemplate \nT modinv(T m, T n) {\n typedef std::pair > triple;\n triple gxy = exgcd(m, n);\n T loop = n / gxy.first;\n T inv = gxy.second.first;\n inv = inv % loop;\n return inv < 0 ? inv + loop : inv;\n}\n\nconst long long MAXN = 301000;\n\nconst long long P = 998244353 ;\n\nlong long n;\nvector son[ MAXN ];\nlong long f[ MAXN ][ 3 ];\n\n\n\nvoid dfs(long long x,long long fa){\nf[x][1]=1;\nf[x][2]=0;\nlong long T=1;\nfor (long long i=0;i\n#include \n#include \n#include \n\nusing namespace std;\n\nint main(){\n int n, t = 1, i = 0;\n cin >> n;\n while(t <= n){\n ++i;\n t+=(1 + i+1)*(i+1)/2;\n }\n cout << i;\n\n}\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "#include\n\n#define ll long long int\n#define ull unsigned long long int\n#define pii pair < int, int>\n#define pll pair < ll, ll>\n#define sc scanf\n#define scin(x) sc(\"%d\",&(x))\n#define scln(x) sc(\"%lld\",&(x))\n#define pf printf\n#define ms(a,b) memset(a,b,sizeof(a))\n#define pb(a) push_back(a)\n#define mp make_pair\n#define db double\n#define EPS 10E-10\n#define ff first\n#define ss second\n#define sqr(x) (x)*(x)\n#define vi vector< int >\n#define vl vector< ll >\n#define vii vector >\n#define vll vector >\n#define DBG pf(\"HI\\n\")\n#define MOD 1000000007\n#define CIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)\n#define RUN_CASE(t,T) for(__typeof(t) t=1;t<=T;t++)\n#define CASE(t) printf(\"Case %d: \",t)\n#define CASEL(t) printf(\"Case %d:\\n\",t)\n#define intlimit 2147483648\n#define longlimit 9223372036854775808\n#define infinity (1<<28)\n#define gcd(a, b) __gcd(a,b)\n#define lcm(a, b) ((a)*(b)/gcd(a,b))\n#define mx 1234567899\n#define PI 2*acos(0.0)\n#define all(v) v.begin(),v.end()\n#define rep(i,a,b) for(__typeof(i) i=a; i<=b; i++)\n#define rev(i,a,b) for(__typeof(i) i=a; i>=b; i--)\n\nusing namespace std;\n\nint main()\n{\n int n,cnt=1;\n string s;\n bool flag=0;\n cin>>n;\n cin>>s;\n if(n==1 && s[0]=='0')\n {\n pf(\"NO\\n\");\n return 0;\n }\n if(n==2)\n {\n if(s[0]!=s[1])\n {\n pf(\"YES\\n\");\n return 0;\n }\n }\n/// int cnt=0;\n for(int i=0; i2)\n {\n flag=1;\n break;\n }\n\n\n }\n if(flag==1 || cnt>1)\n pf(\"NO\\n\");\n else\n pf(\"YES\\n\");\n}\n", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"source_code": "#include \nusing namespace std;\ntypedef long long int lii;\ntypedef unsigned long long int uli;\n\nuli n, b;\nvector factores;\nvector exponentes;\n\nvoid factorizar(uli n)\n{\n for (uli i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n factores.push_back(i);\n exponentes.push_back(0);\n while (n % i == 0)\n {\n n /= i;\n exponentes[exponentes.size() - 1]++;\n }\n }\n }\n if (n != 1)\n {\n factores.push_back(n);\n exponentes.push_back(1);\n }\n}\n\nuli apariciones(uli a)\n{\n uli contador = 0;\n for(uli i=a; i<= n; i*=a){\n contador += n/i;\n uli x = i*a;\n if(x/a != i) break;\n }\n return contador;\n}\n\nint main(void)\n{\n cin >> n >> b;\n factorizar(b);\n uli minimo = 1000000000000000000;\n for (uli i = 0; i < factores.size(); i++)\n {\n uli aparece = apariciones(factores[i]);\n if (aparece / exponentes[i] < minimo)\n minimo = aparece / exponentes[i];\n }\n cout << minimo;\n}\n", "src_uid": "491748694c1a53771be69c212a5e0e25"} {"source_code": "#include \n\nint main()\n{\n\tint n, l, r;\n\tlong long int min = 0, max = 0;\n\n\tscanf (\"%d %d %d\", &n, &l, &r);\n\n int cnt = 2;\n \n for (int i = 1; i < l; i++, cnt *= 2)\n min += cnt;\n \n min += n - l + 1;\n \n cnt = 1;\n \n for (int i = 0; i < r; i++, cnt *= 2)\n max += cnt;\n \n cnt /= 2;\n \n max += cnt * (n - r);\n \n printf (\"%lld %lld\", min, max);\n\n\treturn 0;\n}", "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"source_code": "#include\nusing namespace std;\nconst int N=1.5e5+10;\ntypedef vector vi;\ntypedef long long ll;\ntypedef pair pii;\n#define fi first\n#define se second\n#define pb push_back\n#define mp make_pair\n#define sz(a) int(a.size())\n\nint gi() {\n\tint x=0,o=1;char ch=getchar();\n\twhile(!isdigit(ch)&&ch!='-') ch=getchar();\n\tif(ch=='-') o=-1,ch=getchar();\n\twhile(isdigit(ch)) x=x*10+ch-'0',ch=getchar();\n\treturn x*o;\n}\n\nint n,m,k,dfn[N],low[N],tim,fa[N],anc[N][20],dep[N],s[N],t[N];\nll ans;\nvi E[N],vec[N];\n\nvoid dfs(int u,int ff) {\n\tfa[u]=anc[u][0]=ff;dep[u]=dep[ff]+1;dfn[u]=++tim;\n\tfor(int i=1;i<=17;i++) anc[u][i]=anc[anc[u][i-1]][i-1];\n\tfor(auto v:E[u])\n\t\tif(v!=ff) dfs(v,u);\n\tlow[u]=tim;\n}\n\nint lca(int u,int v) {\n\tif(dep[u]>i&1) u=anc[u][i];\n\tif(u==v) return u;\n\tfor(int i=17;~i;i--)\n\t\tif(anc[u][i]!=anc[v][i]) u=anc[u][i],v=anc[v][i];\n\treturn fa[u];\n}\n\nint jump(int u,int k) {\n\tfor(int i=17;~i;i--)\n\t\tif(k>>i&1) u=anc[u][i];\n\treturn u;\n}\n\nint move(int u,int v,int k) {\n\tint p=lca(u,v),dist=dep[u]+dep[v]-2*dep[p];\n\tif(dist=k) return jump(u,k);\n\treturn jump(v,dist-k);\n}\n\nnamespace fenw {\n\tint c[N];\n\tvector opts;\n\n\tvoid modify(int p,int v,bool fl=1) {\n\t\tif(fl) opts.pb(mp(p,v));\n\t\twhile(p<=n) c[p]+=v,p+=p&-p;\n\t}\n\n\tint query(int p) {\n\t\tint ret=0;\n\t\twhile(p) ret+=c[p],p-=p&-p;\n\t\treturn ret;\n\t}\n\n\tvoid clear() {\n\t\tfor(auto t:opts) modify(t.fi,-t.se,0);\n\t\topts.clear();\n\t}\n}\n\nnamespace S1 {\n\tint id[N];\n\n\tbool cmp(int x,int y) {\n\t\treturn dep[x]>dep[y];\n\t}\n\t\n\tvoid solve() {\n\t\tfor(int i=1;i<=n;i++) id[i]=i;\n\t\tsort(id+1,id+n+1,cmp);\n\t\tfor(int cur=1;cur<=n;cur++) {\n\t\t\tint u=id[cur];\n\t\t\tfor(auto i:vec[u]) {\n\t\t\t\tans+=fenw::query(dfn[s[i]]);\n\t\t\t\tans+=fenw::query(dfn[t[i]]);\n\t\t\t}\n\t\t\tfor(auto i:vec[u]) {\n\t\t\t\tint tmp=move(u,s[i],k);\n\t\t\t\tif(tmp!=-1) fenw::modify(dfn[tmp],1),fenw::modify(low[tmp]+1,-1);\n\t\t\t\ttmp=move(u,t[i],k);\n\t\t\t\tif(tmp!=-1) fenw::modify(dfn[tmp],1),fenw::modify(low[tmp]+1,-1);\n\t\t\t}\n\t\t}\n\t\tfenw::clear();\n\t}\n}\n\nnamespace seg {\n\tint sum[N*50],ls[N*50],rs[N*50],tt;\n\n\tvoid insert(int p,int &x,int l=1,int r=n) {\n\t\t++tt;ls[tt]=ls[x];rs[tt]=rs[x];sum[tt]=sum[x]+1;x=tt;\n\t\tif(l==r) return;\n\t\tint mid=(l+r)>>1;\n\t\tp<=mid?insert(p,ls[x],l,mid):insert(p,rs[x],mid+1,r);\n\t}\n\n\tint query(int L,int R,int x,int l=1,int r=n) {\n\t\tif(!x) return 0;\n\t\tif(L<=l&&r<=R) return sum[x];\n\t\tint mid=(l+r)>>1,ret=0;\n\t\tif(L<=mid) ret+=query(L,R,ls[x],l,mid);\n\t\tif(R>mid) ret+=query(L,R,rs[x],mid+1,r);\n\t\treturn ret;\n\t}\n\t\n\tint merge(int x,int y) {\n\t\tif(!x||!y) return x|y;\n\t\tls[x]=merge(ls[x],ls[y]);\n\t\trs[x]=merge(rs[x],rs[y]);\n\t\tsum[x]+=sum[y];\n\t\treturn x;\n\t}\n\n\tvoid clear() {\n\t\tfor(int i=1;i<=tt;i++) sum[i]=ls[i]=rs[i]=0;\n\t\ttt=0;\n\t}\n}\n\nnamespace vir {\n\tint rt[N],p;\n\tvi E[N],need_clr,vec[N],all[N];\n\t\n\tbool cmp(int x,int y) {\n\t\treturn dfn[x]sz(all[v])) {\n\t\t\t\tfor(auto i:all[v]) {\n\t\t\t\t\tint b=move(u,t[i],max(k,dep[u]-dep[p]+1));\n\t\t\t\t\tif(b!=-1&&u!=p) ans+=seg::query(dfn[b],low[b],rt[u]);\n\t\t\t\t}\n\t\t\t\tfor(auto i:all[v]) all[u].pb(i);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfor(auto i:all[u]) {\n\t\t\t\t\tint b=move(u,t[i],max(k,dep[u]-dep[p]+1));\n\t\t\t\t\tif(b!=-1&&u!=p) ans+=seg::query(dfn[b],low[b],rt[v]);\n\t\t\t\t}\n\t\t\t\tfor(auto i:all[u]) all[v].pb(i);\n\t\t\t\tswap(all[u],all[v]);\n\t\t\t}\n\t\t\trt[u]=seg::merge(rt[u],rt[v]);\n\t\t}\n\t}\n\t\n\tvoid clear() {\n\t\tfor(auto u:need_clr) {\n\t\t\trt[u]=0;E[u].clear();vec[u].clear();all[u].clear();\n\t\t}\n\t}\n}\n\nnamespace S2 {\n\tint cur;\n\t\n\tpii get(int i) {\n\t\tif(s[i]==cur) return mp(dfn[cur],dfn[t[i]]);\n\t\treturn mp(dfn[move(cur,s[i],1)],dfn[move(cur,t[i],1)]);\n\t}\n\n\tbool cmp(int x,int y) {\n\t\treturn get(x)>n>>m>>k;\n\tfor(int i=1,u,v;idfn[t[i]]) swap(s[i],t[i]);\n\t\tvec[lca(s[i],t[i])].pb(i);\n\t}\n\tS1::solve();\n\tS2::solve();cout<\n#include \n#include \n\nusing namespace std;\n\nlong double c(int n, int m) {\n\tif (m < 0 || m > n) {\n\t\treturn 0;\n\t} else {\n\t\tlong double c = 0;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\tc += log10(n - i + 1);\n\t\t\tc -= log10(i);\n\t\t}\n\t\treturn pow(10, c);\n\t}\n}\n\nint main() {\n\tint n, m;\n\tcin >> n >> m;\n\tlong double ans = 0;\n\tfor (int i = 0; i <= n; i++) {\n\t\tans += i * i * c(n * m - m, n - i) * c(m, i);\n\t}\n\tans /= c(n * m, n);\n\tans /= n;\n\tprintf(\"%.10f\\n\", (double) ans);\n}\n", "src_uid": "0b9ce20c36e53d4702869660cbb53317"} {"source_code": "#include\nusing namespace std;\ntypedef long long INT;\nint f[110];\nint main(){\n#ifndef ONLINE_JUDGE\n\tfreopen(\"a.txt\",\"r\",stdin);\n#endif\n\tint n,m;\n\tcin>>n>>m;\n\tif(m==0) {\n\t\tif(n>1) puts(\"-1 -1\");\n\t\telse puts(\"0 0\");\n\t\treturn 0;\n\t}\n\tif(m>n*9){\n\t\tprintf(\"-1 -1\");\n\t\treturn 0;\n\t}\n\tif(m<=9*n and m>=9*(n-1)+1){\n\t\tfor(int i=1;i=0;i--) cout<0;i--){\n\t\t\tif(m>=9) {f[i]=9;m-=9;}\n\t\t\telse {\n\t\t\t\tf[i]=m;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tfor(int i=0;i0;i--){\n\t\tif(f[i]!=9) {\n\t\t\tf[i]++;\n\t\t\tf[0]=0;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(int i=n-1;i>=0;i--) cout<\n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tlong long n, a, b, c[110], x, y, k, sum = 0, sum2 = 0;\n\tcin >> n;\n\t\n\tfor (int i = 0; i < n; ++i)\n\t\tcin >> c[i];\n\tcin >> x >> y;\n\n\tbool f = 0;\n\tfor (int i = 0; i < n; ++i)\n\t{\n\t\tif (sum >= x && sum <= y)\n\t\t{\n\t\t\tfor (int j = i; j < n; ++j)\n\t\t\t\tsum2 += c[j];\n\t\t\tif (sum2 >= x && sum2 <= y)\n\t\t\t{\n\t\t\t\tf = 1;\n\t\t\t\tk = i + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tsum2 = 0;\n\t\t}\n\t\tsum += c[i];\n\t}\n\n\tif (f)\n\t\tcout << k;\n\telse\n\t\tcout << 0;\n\n\tcin >> n;\n\treturn 0;\n}", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"} {"source_code": "#include\"iostream\"\n#include\"algorithm\"\n#include\"vector\"\n#include\"queue\"\n#include\"map\"\n#include\"cstdio\"\n#include\"string\"\n#include\"stack\"\n#include\"set\"\n#include\"cstring\"\nusing namespace std;\nint main()\n{\n\tint m,n,k[12],h;\n\tmapp;\n\tscanf(\"%d%d\",&n,&m);\n\tfor(int i=0;i\n#include\n#include\nusing namespace std;\n__int64 a[5];\nint main(){\n\tint i,j,k;\n\tfor(i=0;i<3;i++) scanf(\"%I64d\",&a[i]);\n\tsort(a,a+3);\n\tif((a[1]-a[0])%2==0) printf(\"%I64d\\n\",a[1]);\n\telse printf(\"%I64d\\n\",a[2]); \n}", "src_uid": "b8008caf788336775cb8ebb76478b04c"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\nconst ll MOD = (ll) 1e9 + 7;\n#define pb push_back\n#define pf push_front\ntypedef deque dll;\ntypedef deque di;\n#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) //traverse through all container\n#define all(c) c.begin(), c.end() \nll docheck(ll n, ll k)\n{\n ll ans=0;\n if(k>=n)\n return n;\n ll rem=n;\n while(k= l)\n {\n ll mid = l + (r - l)/2;\n ll num = docheck(n, mid);\n \n if(num == (n + 1)/2)\n return mid;\n else if(l==r-1)\n return mid+1;\n \n if (num > (n+1)/2) \n return binarySearch(n, (l+mid)/2, l, mid);\n \n return binarySearch(n, (r+mid+1)/2, mid, r);\n }\n return k;\n}\nint main() \n{\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n ll n, k, l, r;\n cin>>n;\n l=1;\n r=n;\n // cout<\n#include\n#include\n#define ff first\n#define ss second\n#define pb push_back\n#define mp make_pair\n#define ll long long\n#define ld long double\n#define all(a) a.begin(),a.end()\n#define ull unsigned long long\n#define y1 asjdlfaskavslbcjasndscf\n#define endl '\\n'\n#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n#define iter set< int >::iterator\n#define iter1 multiset::iterator\n#define int long long\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntemplate\nusing ordered_set=tree,rb_tree_tag,tree_order_statistics_node_update>;\n\ntemplate\nusing ordered_multiset=tree,rb_tree_tag,tree_order_statistics_node_update>;\n\nmt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());\nmt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());\n\n//find_by_order\n//order_of_key\n\nconst int N=1e6+7;\nconst int inf=1e9+1e9;\nconst int mod=1e9+7;\nconst ld eps=1e-9;\n\n//const int MAX_MEM=4e8;\n//int mpos=0;\n//char mem[MAX_MEM];\n//\n//inline void * operator new(size_t n){\n// char *res=mem+mpos;\n// mpos+=n;\n// if (mpos>=MAX_MEM){\n// cout<<\"BAD\"< >b1,b2;\nint kol2[65538],kol1[65538];\nint f[65338];\nll n,X,Y;\n\nmain ()\n{\n //ios;\n cin>>n>>X>>Y;\n ll XX=X,YY=Y;\n for (int i=1;i<=n;++i){\n cin>>a[i];\n }\n if (Y%X!=0){\n cout<<0<1){\n ll f=sqrt(Y);\n if (f*f==Y){\n b2.pb({f,2});\n Y=1;\n }\n else {\n ll l=__gcd(X,Y);\n if (l!=1 && l!=Y){\n b2.pb({l,1});\n b2.pb({Y/l,1});\n Y=1;\n }\n else {\n for (int i=1;i<=n;++i){\n ll x=a[i];\n int l=__gcd(x,Y);\n if (l!=1 && l!=Y){\n b2.pb({l,1});\n b2.pb({Y/l,1});\n Y=1;\n break;\n }\n }\n }\n if (Y>1){\n b2.pb({Y,1});\n Y=1;\n }\n }\n }\n b1.resize((int)b2.size(),{0,0});\n for (int i=0;ib1[j].ss){\n mask1|=(1LL<\n\nusing namespace std;\n\nint main()\n{\n long int k;\n long int n;\n cin>>n>>k;\n while(k!=0){\n if(n%10==0){\n n=n/10;\n k=k-1;\n }else{\n if(k>=n%10){k=k-n%10;\n n=n-n%10;\n }else{k=k-1;\n n=n-1;\n }\n\n }\n }\n cout << n << endl;\n return 0;\n}\n", "src_uid": "064162604284ce252b88050b4174ba55"} {"source_code": "\n//region trash\n#ifndef LOCAL\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#endif\n\n#include \n\nusing namespace std;\n\n#ifdef LOCAL\n#define DB(x){if(cond)cerr<<__LINE__<<\" \"<<#x<<\" \" <=(b);--i)\n#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)\n#define VV vector\n#define PB push_back\n#define ALL(x) (x).begin(),(x).end()\ntemplatebool MA(X&a,Y b){if(abool MI(X&a,Y b){if(a>b){a=b;return true;} return false;}\ntypedef long long LL,ll;typedef long double LD,ld;\ntypedef arrayI2,i2;typedef VVVI,vi;\nusing namespace std;\nint cond=0;\n//endregion\n\nint mode=1;\n\nstruct Solver {\n int N;\n VV>A;\n void solve() {\n cin>>N;\n A.resize(N,VV(N));\n REP(r,N)REP(c,N) cin >> A[r][c];\n\n cout<<\"B\"<>x;\n bool inc = x != 'I';\n int node;cin>>node;node--;\n\n int how = (node < N && inc) || (node >= N && !inc);\n DB(how);\n\n VVPREF_A(N,-1),PREF_B(N,-1);\n VVCAND_A(N,0);\n\n VV>ORD(N);\n REP(a, N) {\n ORD[a].resize(N);\n iota(ALL(ORD[a]), 0);\n\n sort(ALL(ORD[a]),\n [&](int le, int ri) {\n if (how == 1) return A[a][le] > A[a][ri];\n else return A[a][le] < A[a][ri];\n });\n REP(n,N)DB(a<<\" \"< s2) {\n PREF_A[old_a] = -1;\n PREF_A[a] = b;\n PREF_B[b] = a;\n CAND_A[a]++;\n break;\n }\n }\n }\n }\n }\n REP(n,N) assert(PREF_A[n] != -1);\n REP(n,N) assert(PREF_B[n] != -1);\n REP(n,N) DB(n<<\" \"<= 0) {\n if (node < N) cout<> node; node--;\n }\n\n DB(N);\n REP(n,N){ DB(n<<\" \"<().get();\n srand(seed); mt19937 rng(seed);\n\n ios::sync_with_stdio(false),cin.tie(nullptr);\n FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}\n FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}\n cout.setf(ios::fixed),cout.precision(10);\n int t{};if(mode >= 1)cin>>t;else t=1;\n bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;\n FOR(i,1,t){if(cond)cerr<<__LINE__<<\" \"<();\n auto solver2 = make_unique();\n if (isBrute)\n solver2->brute();\n else\n solver->solve();\n }\n return 0;\n}\n", "src_uid": "299c209b070e510e7ed3b525f51fec8a"} {"source_code": "#include \nusing namespace std;\n#define ll long long \n#define ld long double\n#define pb push_back\n#define F first\n#define S second\n#define I insert\n#define pll pair \n#define vll vector \n#define vpll vector< pll >\n\nll P,Q;\n\nll gcdExtended(ll a, ll b, ll *x, ll *y)\n{\n // Base Case\n if (a == 0)\n {\n *x = 0LL;\n *y = 1LL;\n return b;\n }\n \n ll x1, y1; // To store results of recursive call\n ll gcd = gcdExtended(b%a, a, &x1, &y1);\n \n // Update x and y using results of recursive\n // call\n *x = y1 - (b/a) * x1;\n *y = x1;\n \treturn gcd;\n}\n \n\nint main() {\n\tios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<>n>>m>>x>>y>>vx>>vy;//a=__gcd(x,(__gcd(y,__gcd(m,n))));x/=a;y/=a;m/=a;n/=a;\n\tif(vx==1){\n\t\tif(vy==1){\n\t\t\ta=x-y;\n\t\t\tb=__gcd(m,n);if(abs(a)%b){cout<<\"-1\";return 0;}\n\t\t\tn1=n;m1=m;m=m/b;n=n/b;a=a/b;b=1;\n\t\t\tgcdExtended(n,m,&P,&Q);\n\t\t//\tcout<0)cout<0){\n\t\t\t\te=f=0;\n\t\t\t\tif(P<=0)e=ceil(abs(P)/(m*1.0)+1e-15);if(Q>0)f=ceil(abs(Q)/(n*1.0));\n\t\t\t\te=max(e,f);P+=e*m;Q-=e*n;\n\t\t\t}\n\t\t\telse{\n\t\t\t\te=floor((P*1.0)/m-1e-15);f=abs(Q)/n;e=min(e,f);\n\t\t\t\tP-=e*m;Q+=e*n;\n\t\t\t}\n\t\t\tif(P<=0||Q>0){cout<<\"-1\";return 0;}\n\t\t\tn=n1;m=m1;\n\t\t}\n\t}\n\telse if(vx==0){\n\t //cout<0)cout<0){\n\t\t\ta=x+y;\n\t\t\tb=__gcd(m,n);if(abs(a)%b){cout<<\"-1\";return 0;}\n\t\t\tn1=n;m1=m;m=m/b;n=n/b;a=a/b;b=1;\n\t\t\tgcdExtended(n,m,&P,&Q);\n\t\t\tc=a/b;P=P*c;Q*=c;\n\t\t\t\n\t\t\tif(P>0||Q<=0){\n\t\t\t\te=f=0;\n\t\t\t\tif(P>0)e=ceil(abs(P)/(m*1.0));\n\t\t\t\tif(Q<=0)f=ceil(abs(Q)/(n*1.0)+1e-15);\n\t\t\t\te=max(e,f);\n\t\t\t\tP-=e*m;Q+=e*n;\n\t\t\t}\n\t\t\telse{\n\t\t\t\te=(-1*P)/m;f=floor((Q*1.0)/n-1e-15);e=min(e,f);//e=max(e,0LL);\n\t\t\t\tP+=e*m;Q-=e*n;\n\t\t\t}\n\t\t\tif(P>0||Q<0){cout<<\"-1\";return 0;}\n\t\t\tn=n1;m=m1;\n\t\t\t//cout<0)cout<0||Q>0){\n\t\t\t\te=f=0;\n\t\t\t\tif(P>0)e=ceil(abs(P)/(m*1.0));if(Q>0)f=ceil(Q/(n*1.0));\n\t\t\t\te=max(e,f);P-=e*m;Q-=e*n;\n\t\t\t}\n\t\t\telse{\n\t\t\t\te=(-1*P)/m;f=(-1*Q)/n;e=min(e,f);\n\t\t\t\tP+=e*m;Q+=e*n;\n\t\t\t}\n\t\t\tif(P>0||Q>0){cout<<\"-1\";return 0;}\n\t\t\tn=n1;m=m1;\n\t\t}\n\t}\n\tP=abs(P);Q=abs(Q);\n\t//cout<\nusing namespace std;\n#define mod 998244353\n#define ll long long\nll w,h;\nll quickmod(ll a,ll b){\n\tll ans = 1;\n\twhile(b){\n\t\tif(b%2){\n\t\t\tans *= a; \n\t\t\tans %= mod;\n\t\t\tb--;\n\t\t}\n\t\tb /= 2;\n\t\ta = a*a;\n\t\ta %= mod; \n\t}\n\treturn ans;\n}\nint main(){\n\tscanf(\"%lld%lld\",&w,&h);\n\tprintf(\"%lld\\n\",quickmod(2,w+h));\n\treturn 0;\n} ", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"source_code": "#include\n#include\n\nusing namespace std;\n\nint n, m;\nvector > a, b;\nvector vis, dt; // visited, don't take\n\nvoid reset_vals()\n{\n vis.clear();\n vis.assign(n, false);\n dt.clear();\n dt.assign(n, false);\n}\n\nvoid reset()\n{\n a.clear();\n a.resize(n);\n b.clear();\n b.resize(n);\n}\n\nvoid read()\n{\n cin>>n;\n reset();\n int i, x, y;\n\n cin>>m;\n for(i = 0;i < m;i++)\n {\n cin>>x>>y;\n x--, y--;\n a[x].push_back(y);\n a[y].push_back(x);\n }\n\n cin>>m;\n for(i = 0;i < m;i++)\n {\n cin>>x>>y;\n x--, y--;\n b[x].push_back(y);\n b[y].push_back(x);\n }\n}\n\nbool dfs(int u)\n{\n bool flag = true;\n vis[u] = true;\n\n for(int v : b[u])\n dt[v] = true;\n \n for(int v : a[u])\n {\n if(dt[v])\n return false;\n if(!vis[v] && !dt[v])\n flag &= dfs(v);\n }\n\n return flag;\n}\n\nvoid solve()\n{\n int i, u, val, ans = 0;\n for(i = 0;i < n;i++)\n {\n reset_vals();\n if(!dfs(i))\n continue;\n\n val = 0;\n for(u = 0;u < n;u++)\n {\n if(vis[u])\n val++;\n }\n ans = max(ans, val);\n }\n\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\ntypedef long long LL;\ntypedef pair PII;\ntypedef pair PLL;\n\nconst LL MOD = 1000000007;\n\nLL cifang(LL a, LL n)\n{\n\tLL ret = 1;\n\twhile (n)\n\t{\n\t\tif (n % 2 == 1)\n\t\t\tret = ret * a % MOD;\n\t\ta = a * a % MOD;\n\t\tn = n / 2;\n\t}\n\treturn ret;\n}\n\nint main ()\n{\n\t//freopen(\"input.txt\",\"r\",stdin);\n\tLL n;\n\tcin >> n;\n\tif (n == 0)\n\t{\n\t\tprintf (\"1\\n\");\n\t\treturn 0;\n\t}\n\tLL t1 = cifang(4, n - 1) * 2 % MOD;\n\tLL t2 = cifang(2, n - 1);\n\tcout << (t1 + t2) % MOD << endl;\n return 0;\n}", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n int n,x,y,ans=0;\n cin>>n>>x>>y;\n for(int i=1;i<=x+y;i++)\n {\n if((x/i)+(y/i)>=n && (x/i)>0 && (y/i)>0)ans=i;\n else break;\n }\n cout<\nint main(){std::cout<<\"25\\n\";return 0;}\n//2741", "src_uid": "dcaff75492eafaf61d598779d6202c9d"} {"source_code": "#include \n \nusing namespace std;\n \n#define pb push_back\n#define mp make_pair\n#define fst first\n#define snd second\n#define sz(x) (int) ((x).size()) \n#define forn(i, n) for (int i = 0; i < (n); ++i)\n#define fornr(i, n) for (int i = (n) - 1; i >= 0; --i)\n#define forab(i, a, b) for (int i = (a); i < (b); ++i)\n#define all(c) (c).begin(), (c).end() \n \n#ifdef LOCAL\n\t#define eprintf(...) fprintf(stderr, __VA_ARGS__)\n#else\n\t#define eprintf(...) static_cast(0) \n#endif\n \nusing ll = long long;\nusing ull = unsigned long long;\nusing ld = long double;\nusing uint = unsigned int;\nusing vi = vector;\nusing pii = pair;\n \n#define FNAME \"\"\n\n// 1..k^2+1\nll gett(ll n, ll k) {\n\tif (n == 0)\n\t\treturn k * (k + 1) / 2;\n\tll num = gett(n / k, k);\n\tll t = n % k;\n\tll i = (num - 1) / k;\n\tll j = (num - 1) % k;\n\tll res = k * (k + 1) / 2 - t;\n\tif (t > i)\n\t\tres += k;\n\tif (t == i)\n\t\tres += k - j;\n\treturn res;\n}\n\nll solve(ll n, ll k) {\n\tll x = k * k + 1;\n\tll ind = (n - 1) / x;\n\tll num = gett(ind, k);\n\tll rem = (n - 1) % x + 1;\n\tif (rem == num) {\n\t\tll t = ind % k;\n\t\tll i = ind / k;\n\t\treturn k * (k + 1) * i + (t + 1) * (k + 1);\t\n\t}\n\tif (rem >= num)\n\t\trem--;\n\treturn k * (k + 1) * ind + (rem - 1) / k * (k + 1) + (rem - 1) % k + 1; \n}\n \nint main() {\n#ifdef LOCAL \n\tfreopen(FNAME\".in\", \"r\", stdin);\n\tfreopen(FNAME\".out\", \"w\", stdout); \n#endif \n\tcin.tie(0);\n\tios_base::sync_with_stdio(0);\n\t\n\tint tn;\n\tcin >> tn;\n\tforn (tt, tn) {\n\t\tll n, k;\n\t\tcin >> n >> k;\n\t\tcout << solve(n, k) << \"\\n\";\n\t}\t\n\t\n\treturn 0;\n}", "src_uid": "053192b4f6acc3a94b701e787a4172e2"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\n#define LL long long\n\nint c[66];\nvoid init(int x)\n{\n memset(c,0,sizeof(c));\n int k=(x/50)%475;\n int t=25;\n while(t--)\n {\n k=(k*96+42)%475;\n c[t]=k+26;\n }\n}\nint main()\n{\n int p,x,y;\n while(~scanf(\"%d%d%d\",&p,&x,&y))\n {\n int k=x-y;\n k=(k/50)*50;\n int re=x-(k+50);\n int flag=1;\n while(flag)\n {\n re+=50;\n init(re);\n for(int i=0;i<25;i++)\n {\n if(c[i]==p)\n {\n flag=0;\n break;\n }\n }\n }\n if(re\n#include \n#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 vector vi;\ntypedef pair pii;\ntypedef pair pdd;\ntypedef unsigned long long ull;\n\n#define FOR(i,a,b) for (int i(a); i < (b); i++) \n#define REP(i,n) FOR(i,0,n) \n#define SORT(v) sort((v).begin(),(v).end())\n#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())\n#define CL(a,b) memset(a,b,sizeof(a))\n#define pb push_back\n\nconst int mod = 1000000009;\nint n,m;\nvector v;\n\nstring D = \"ACGT\";\nmap c[1001];\n\nint R1[11][11][11];\nint next(int pos,int len,int next){\n\tif(R1[pos][len][next]!=-1) return R1[pos][len][next];\n\tstring s = v[pos].substr(0, len);\n\ts += D[next];\n\twhile(v[pos].substr(0, s.size()) != s)\n\t\ts.erase(s.begin());\n\treturn R1[pos][len][next]=s.size();\n}\nint R2[11];\nint pref(int pos){\n\tif(R2[pos]!=-1) return R2[pos];\n\tstring s = v[pos];\n\ts.erase(s.begin());\n\twhile(v[pos].substr(0, s.size()) != s)\n\t\ts.erase(s.begin());\n\treturn R2[pos]=s.size();\n}\n\nint nv[11];\n\nint main(){ \n#ifdef LocalHost\n freopen(\"input.txt\",\"r\",stdin);\n\t//freopen(\"output.txt\",\"w\",stdout);\n#endif\n\n\tCL(R2,-1);\n\tCL(R1,-1);\n\n\tcin>>n>>m;\n\tREP(i,m){\n\t\tstring s;\n\t\tcin>>s;\n\t\tv.pb(s);\n\t}\n\tUN(v);\n\tm=v.size();\n\tvi t(v.size()+1);\n\tt[t.size()-1] = (1<<9)-1;\n\tc[0][(1<<9)-1]=1;\n\tfor(int i=0;i::iterator it = c[i].begin();it!=c[i].end();it++){\n\t\t\tll x = it->first;\n\t\t\tint val = it->second;\n\t\t\tint mask = x & 1023;//t.back();\n\t\t\tx >>= 10;\n\t\t\tt.clear();\n\t\t\tREP(rr,v.size()) {\n\t\t\t\tt.pb(x&15);\n\t\t\t\tx>>=4;\n\t\t\t}\n\t\t\treverse(t.begin(),t.end());\n\n\t\t\tREP(j,4){\n\t\t\t\tint nmask = mask<<1;\n\t\t\t\tll ww = 0;\n\t\t\t\tint mx = 0;\n\t\t\t\tREP(k,m){\n\t\t\t\t\tnv[k] = next(k,t[k],j);\n\t\t\t\t\tif(nv[k] == v[k].size()){\n\t\t\t\t\t\tnmask |= ((1<=mx) continue;\n\t\t\t\t\n\t\t\t\tww = (ww<<10) + (nmask^(1<<9));\n\t\t\t\tint q = c[i+1][ww] + val;\n\t\t\t\tif(q>=mod) q-=mod;\n\t\t\t\tc[i+1][ww] = q;\n\n\t\t\t}\n\t\t}\n\t}\n\tint res = 0;\n\tfor(map::iterator it = c[n].begin();it!=c[n].end();it++){\n\t\tint mask = it->first & 1023;\n\t\tint val = it->second;\n\n\t\tif(mask == (1<<9) - 1){\n\t\t\tres += val;\n\t\t\tif(res>=mod) res-=mod;\n\t\t}\n\t}\n\tcout<\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;\ntypedef pair pr;\n\n#define double long double\n\nconst ll mod7 = 1000000007;\n\n#define NAME \"string\"\n\nint gcd(int a,int b)\n{\n while(b)\n {\n a%=b;\n swap(a,b);\n }\n return a;\n}\n\n\n\nint main()\n{\n //freopen(\"input.txt\",\"r\",stdin); freopen(\"output.txt\",\"w\",stdout);\n //freopen(NAME\".in\",\"r\",stdin); freopen(NAME\".out\",\"w\",stdout);\n \n int k,a,b,v;\n cin >> k >> a >> b >> v;\n int z = (a+v-1)/v;\n int l = 1, r = 1000000,ans = 0;\n while(l<=r)\n {\n int m = (l+r)>>1;\n\n int use = m*(k-1);\n int used = m+min(use,b);\n\n if(z<=used)\n {\n ans = m;\n r = m - 1;\n }\n else\n l = m+1;\n }\n cout << ans;\n return 0;\n}", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"} {"source_code": "#pragma comment(linker, \"/stack:200000000\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\n#pragma GCC optimize(\"unroll-loops\")\n#include \n#include \n#include \n#include \n#include \n#include \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 FAST_IO ios::sync_with_stdio(false);\n#define DEBUG_VIS(x) cerr<<\"vis \"< pii;\ntypedef pair pll;\ntypedef pair pdd;\ntypedef long long ll;\ntypedef unsigned int uint;\ntypedef unsigned long long ull;\nconst int maxn = 1e6 + 10;\ntemplate T mymin(const T a,const T b){return a < b ? a : b;}\ntemplate T mymax(const T a,const T b){return a > b ? a : b;}\nint dfn[maxn],low[maxn],scc_cnt,dfs_clock,inst[maxn],bel[maxn];\nstruct edge{\n int u,v;\n edge(int a = 0,int b = 0):u(a),v(b){};\n};\nvector es;\nvector G[maxn],sccs[maxn];\nstack S;\nint N,M;\nbool isbridge[maxn<<2];\nvoid tarjan(int u,int in_edge){\n dfn[u] = low[u] = ++dfs_clock;\n S.push(u);\n for(int nx : G[u]){\n int v = es[nx].v;\n if(!dfn[v]){\n tarjan(v,nx);\n low[u] = min(low[u],low[v]);\n if(low[v] > dfn[u]) isbridge[nx] = 1;\n }\n else if(nx != (in_edge ^ 1)) low[u] = min(low[u],dfn[v]);\n }\n if(low[u] == dfn[u]){\n int v;\n scc_cnt++;\n do{\n v = S.top(); S.pop();\n sccs[scc_cnt].emplace_back(v);\n bel[v] = scc_cnt;\n }\n while(!S.empty() && u != v);\n }\n}\nint L[maxn],fa[maxn],dep[maxn],Z[maxn];\nbool vis[maxn];\nvoid bfs(){\n queue q;\n q.push(1);\n vector nodes;\n vis[1] = 1;\n while(!q.empty()){\n int u = q.front(); q.pop();\n nodes.emplace_back(u);\n for(int nx : G[u]){\n int v = es[nx].v;\n if(!vis[v]){\n vis[v] = 1;\n q.push(v);\n fa[v] = u;\n }\n }\n }\n for(auto it = nodes.rbegin(); it != nodes.rend(); it++){\n int u = *it;\n for(int nx : G[u]){\n int v = es[nx].v;\n if(fa[v] == u){\n dep[u] = max(dep[v] + 1,dep[u]);\n if(isbridge[nx]){\n L[u] = max(L[u],1 + dep[v]);\n }\n }\n }\n }\n}\nvoid solve(int u,int par,int upval){\n L[u] = max(L[u],upval);\n auto &cycle = sccs[bel[u]];\n for(int it = 0; it < 2; it++){\n priority_queue q;\n for(int i = 0; i < 2 * cycle.size(); i++){\n int d = 2 * cycle.size() - i;\n while(!q.empty() && q.top().second - d > cycle.size() / 2) q.pop();\n if(!q.empty()) Z[cycle[i % cycle.size()]] = max(Z[cycle[i % cycle.size()]],q.top().first - d);\n q.push(make_pair(L[cycle[i % cycle.size()]] + d,d));\n }\n reverse(cycle.begin(),cycle.end());\n }\n for(auto u : cycle){\n int mx1,mx2;\n mx1 = mx2 = 0;\n for(int nx : G[u]){\n int v = es[nx].v;\n if(v == par || !isbridge[nx]) continue;\n if(mx2 < 1 + dep[v]){\n mx2 = 1 + dep[v];\n if(mx1 < mx2) swap(mx1,mx2);\n }\n }\n for(int nx : G[u]){\n int v = es[nx].v;\n if(v == par || !isbridge[nx]) continue;\n int pssval = max(upval,Z[u]);\n if(mx1 == 1 + dep[v]) pssval = max(pssval,mx2);\n else pssval = max(pssval,mx1);\n solve(v,u,pssval + 1);\n }\n }\n}\n\nint main(){\n #ifndef ONLINE_JUDGE\n freopen(\"data.in\",\"r\",stdin);\n #endif\n FAST_IO\n cin>>N>>M;\n for(int i = 1; i <= M; i++){\n int u,v;\n cin>>u>>v;\n es.emplace_back(edge(u,v));\n es.emplace_back(edge(v,u));\n G[u].emplace_back(es.size() - 2);\n G[v].emplace_back(es.size() - 1);\n } \n for(int i = 1; i <= N; i++) if(!dfn[i]) tarjan(i,0); \n bfs();\n solve(1,0,0);\n for(int i = 1; i <= N; i++) cout<\nusing namespace std;\n\ntypedef long long ll;\nll mod = 1e9 + 7;\nint dim;\n\nvector > Mul(vector < vector > a, vector > b) {\n vector > c;\n c.resize(dim + 1, vector(dim + 1 ,0));\n for(int i = 0; i <= dim; i++) {\n for(int j = 0; j <= dim; j++) {\n for(int k = 0; k <= dim; k++) {\n c[i][j] += a[i][k] * b[k][j];\n c[i][j] %= mod;\n }\n }\n }\n return c;\n}\n\nvector < vector > base;\n\nvector > f(ll k) {\n if (k == 1) return base;\n if (k&1) {\n return Mul(f(k-1),base);\n }\n vector > res = f(k/2);\n return Mul(res,res);\n}\n\nll bm(ll b, ll p) {\n if (p == 0) return 1;\n ll t = bm(b, p/2);\n t = (t*t)%mod;\n if (p&1) return (t*b)%mod;\n return t;\n}\n\nint main() {\n ll n, k;\n cin >> n >> k;\n vector a(n,0);\n for(int i = 0; i < n; i++) {\n cin >> a[i];\n if(a[i] == 0) dim++;\n }\n ll xx = 0;\n for(int i = 0; i < dim; i++) {\n xx += (a[i] == 0);\n }\n if (dim == 0 or dim == n) {\n cout << 1 << endl;\n return 0;\n }\n base.resize(dim + 1, vector(dim + 1 ,0));\n\n for(ll z = 0; z <= dim; z++) {\n ll lftZ = z-1, lftO = dim-lftZ, rgtZ = dim-lftZ, rgtO = (n-dim)-rgtZ;\n /// from z-1 to z\n if (lftZ >= 0 && lftO >= 0 && rgtZ >= 0 && rgtO >= 0) {\n base[z][z-1] = (lftO * rgtZ)%mod;\n }\n /// from z+1 to z\n lftZ = z+1, lftO = dim-lftZ, rgtZ = dim-lftZ, rgtO = (n-dim)-rgtZ;\n if (lftZ >= 0 && lftO >= 0 && rgtZ >= 0 && rgtO >= 0) {\n base[z][z+1] = (lftZ * rgtO)%mod;\n }\n /// from z to z\n lftZ = z, lftO = dim-lftZ, rgtZ = dim-lftZ, rgtO = (n-dim)-rgtZ;\n if (lftZ >= 0 && lftO >= 0 && rgtZ >= 0 && rgtO >= 0) {\n base[z][z] = lftZ*lftO + rgtZ*rgtO + (dim*(dim-1))/2 + ((n-dim)*(n-dim-1))/2;\n }\n }\n vector > res = f(k);\n ll ans = res[dim][xx];\n ans %= mod;\n if (ans < 0) ans+=mod;\n ll down = 1ll*n*(n-1)/2;\n down = bm(down,mod-2);\n down = bm(down, k);\n ans *= down;\n ans %= mod;\n if (ans < 0) ans += mod;\n cout << ans ;\n}\n", "src_uid": "77f28d155a632ceaabd9f5a9d846461a"}

res;\n\nll a[MN], b[MN], c[MN];\n\n\nbool near(Q x, Q y) {\n Q z = Q(x.first-y.first, x.second-y.second);\n return sqrt(z.first*z.first + z.second*z.second) < EPS;\n}\n\nbool iscross(int x, int y) {\n return a[x]*b[y] != b[x]*a[y];\n}\n\nQ cross(int x, int y) {\n double X = a[x]*b[y]-b[x]*a[y];\n Q q(b[x]*c[y]-c[x]*b[y], c[x]*a[y]-a[x]*c[y]);\n q.first /= X; q.second /= X;\n return q;\n}\n\nclock_t st;\nbool solve(vector v, int k) {\n if (v.size() == 0) return true;\n if (k == 0) return false;\n int n = (int)v.size();\n vector v2 = v;\n int ba = v2.back();\n v2.pop_back();\n if (solve(v2, k-1)) {\n res.push_back(P(ba, -2));\n return true;\n }\n for (int i = 0; i < n-1; i++) {\n if (!iscross(v[i], ba)) continue;\n if ((clock() - st) * 1000 / CLOCKS_PER_SEC > 1000) return false;\n Q q = cross(v[i], ba);\n vector v2;\n for (int j = 0; j < n-1; j++) {\n if (!iscross(v[j], ba) || !near(q, cross(v[j], ba))) {\n v2.push_back(v[j]);\n }\n }\n if (solve(v2, k-1)) {\n res.push_back(P(v[i], ba));\n return true;\n }\n\n }\n return false;\n}\n\ntypedef unsigned int uint;\nuint xor128(void) { \n static uint x = 123456789;\n static uint y = 362436069;\n static uint z = 521288629;\n static uint w = 88675123; \n uint t;\n \n t = x ^ (x << 11);\n x = y; y = z; z = w;\n return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); \n}\n\n\nbool calc(vector v, int k) {\n int n = (int)v.size();\n if (n == 0) return true;\n if (k == 0) return false;\n if ((clock() - st) * 1000 / CLOCKS_PER_SEC > 1000) return false;\n if (n <= k*k) {\n return solve(v, k);\n }\n clock_t st = clock();\n while ((clock() - st) * 1000 / CLOCKS_PER_SEC < 1000) {\n int x, y;\n while (true) {\n x = xor128() % n;\n y = xor128() % n;\n if (x == y) continue;\n break;\n }\n if (!iscross(v[x], v[y])) continue;\n Q q = cross(v[x], v[y]);\n int c = 2;\n for (int i = 0; i < n; i++) {\n if (i == x || i == y) continue;\n if (!iscross(v[x], v[i])) continue;\n if (near(q, cross(v[x], v[i]))) {\n c++;\n }\n }\n if ((clock() - st) * 1000 / CLOCKS_PER_SEC > 1000) break;\n if (c > k) {\n res.push_back(P(v[x], v[y]));\n vector v2;\n for (int i = 0; i < n; i++) {\n if (i == x || i == y) continue;\n if (iscross(v[x], v[i]) && near(q, cross(v[x], v[i]))) continue;\n v2.push_back(v[i]);\n }\n return calc(v2, k-1);\n }\n }\n return false;\n}\n\nint main() {\n st = clock();\n int n, k;\n scanf(\"%d %d\", &n, &k);\n for (int i = 0; i < n; i++) {\n int aa, bb, cc;\n scanf(\"%d %d %d\", &aa, &bb, &cc);\n a[i] = aa; b[i] = bb; c[i] = cc;\n }\n\n vector v;\n for (int i = 0; i < n; i++) {\n v.push_back(i);\n }\n if (calc(v, k)) {\n printf(\"YES\\n\");\n printf(\"%d\\n\", (int)res.size());\n for (P p: res) {\n printf(\"%d %d\\n\", p.first+1, p.second+1);\n }\n } else {\n printf(\"NO\\n\");\n }\n return 0;\n}\n", "src_uid": "dea5c9eded04f1a900c37571d20b34e2"} {"source_code": "#define _CRT_SECURE_NO_DEPRECATE\n#include \n#include \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 rp(i,n) for(int (i)=0;(i)<(n);++(i))\n#define pb push_back\n#define L(s) (int)s.size()\n#define mp make_pair\n#define pii pair\n#define x first \n#define y second\n#define inf 1000000000\n#define VI vector\n#define ll long long\n#define all(s) (s).begin(),(s).end()\n#define C(u) memset((u),0,sizeof((u)))\n#define ull unsigned ll\nint n,k;\nint p[11];\nll m[11];\nll ans=(ll)inf*inf*2;\nint pr[11]={2,3,5,7,11,13,17,19,23,29,31};\nvoid dfs(int mask,int step)\n{\n\tif (mask==0)\n\t{\n\t\tdouble val=0;\n\t\trp(i,step)\n\t\t\tval+=(double)(m[i]-1)*log((double)pr[i]);\n\t\tif (val>log(2e+18))\n\t\t\treturn;\n\t\tll cur=1;\n\t\trp(i,step)\n\t\t\trp(j,m[i]-1)\n\t\t\tcur*=pr[i];\n\t\tans=min(ans,cur);\n\t}\n\tfor(int sub=mask;sub;sub=(sub-1)&mask)\n\t{\n\t\tm[step]=1;\n\t\trp(i,k)\n\t\t\tif (sub&(1<>n;\n\tfor(int i=2;i<=n;++i)\n\t\tif (n%i==0)\n\t\t{\n\t\t\tp[k++]=i;\n\t\t\tn/=i;\n\t\t\t--i;\n\t\t}\n\tdfs((1<\n#include \n\nvoid answer(size_t v)\n{\n constexpr const char* s[3] = { \"undefined\", \"cw\", \"ccw\" };\n std::cout << s[v] << '\\n';\n}\n\nvoid solve(char s, char f, unsigned n)\n{\n constexpr char p[4] = { '^', '>', 'v', '<' };\n\n const size_t b = std::find(std::begin(p), std::end(p), s) - std::begin(p);\n const size_t e = std::find(std::begin(p), std::end(p), f) - std::begin(p);\n\n const unsigned k = n % 4;\n\n const char cw = p[(b + k) % 4];\n const char ccw = p[(4 + b - k) % 4];\n\n if (f == cw && f == ccw)\n return answer(0);\n\n answer(f == cw ? 1 : 2);\n}\n\nint main()\n{\n char s, f;\n std::cin >> s >> f;\n\n unsigned n;\n std::cin >> n;\n\n solve(s, f, n);\n\n return 0;\n}\n\n", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"source_code": "#include \n\ntypedef long long ll;\n\nvoid solve(ll x, ll y, bool ok)\n{\n\tif (y)\n\t{\n\t\tll t = (y == 1) ? (x / y - 1) : (x / y);\n\t\tprintf(\"%lld%c\", t, ok ? 'A' : 'B');\n\t\tsolve(y, x % y, !ok);\n\t}\n}\n\nint main()\n{\n\tll x, y;\n\tstd::cin >> x >> y;\n\tif (std::gcd(x, y) == 1) \n\t{\n\t\tif (x > y) solve(x, y, true);\n\t\telse solve(y, x, false);\n\t}\n\telse puts(\"Impossible\");\n\treturn 0;\n}\n", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671"} {"source_code": "#include \nusing namespace std;\n\nint main()\n{\n\tint n,count=0;\n\tcin>> n;\n\tfor(int i=1;i\n#define ll long long int\n#define start ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n#define endl '\\n'\nusing namespace std;\nint main()\n{\n start\n ll n, i, cnt, sum, j;\n ll x[10000], r[10000], b[100000];\n cin >> n;\n cnt=0;\n for(i=1;i<=n;i++) cin >> r[i];\n for(i=1;i<=n;i++)\n {\n cin >> b[i];\n if(b[i]!=r[i])\n {\n cnt++;\n x[cnt]=i;\n }\n }\n if(cnt==0) cout << -1;\n else\n {\n sum=cnt;\n for(j=1;j<=cnt;j++) if(r[x[j]]==1) sum--;\n ll sum2=cnt-sum;\n if(sum==0) cout << 1;\n else if(sum2>sum) cout << 1;\n else if(sum2==sum) cout << 2;\n else if(sum2==0) cout << -1;\n else if(sum2\n#include \n#include \n#include \n#include \nusing namespace std;\nconst int maxn = 2e5 + 5;\ntypedef long long LL;\nconst LL mod = 998244353LL;\nLL qpow(LL a, LL n){\n LL ret = 1;\n while(n > 0){\n if(n & 1){\n ret = ret * a % mod;\n }\n a = a * a % mod;\n n >>= 1;\n }\n return ret;\n}\n//LL inv(LL x){\n// return qpow(x, mod - 2);\n//}\nLL extgcd(LL a, LL b, LL &x, LL &y)\n{\n LL d = a;\n if (b != 0) d = extgcd(b, a % b, y, x), y -= (a / b) * x;\n else x = 1, y = 0;\n return d;\n}\nLL inv(LL a)\n{\n LL x, y;\n extgcd(a, mod, x, y);\n return (mod + x % mod) % mod;\n}\nint a[maxn];\nLL w[maxn];\nint n, m;\nint main(){\n while(cin>>n>>m){\n for(int i=0;i> dp(m+1,vector(m+1));\n \tdp[0][0] = 1;\n \tfor(int i=0;i\nusing namespace std;\n\n#define pb push_back\n#define eb emplace_back\n#define mp make_pair\n#define mt make_tuple\n#define lb lower_bound\n#define ub upper_bound\n#define f first\n#define s second\n\n#define sz(x) int((x).size())\n#define all(x) (x).begin(), (x).end()\n\n#define FOR(i, a, b) for (int i = (a); i < (b); i++)\n#define F0R(i, a) for (int i = 0; i < (a); i++)\n#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)\n#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)\n#define trav(a, x) for (auto& a : x)\n\nusing ll = long long;\nusing vi = vector;\nusing vvi = vector;\nusing vll = vector;\nusing vvll = vector;\nusing vb = vector;\nusing vd = vector;\nusing vs = vector;\n\ntemplate void ckmin(T& a, const T& b) { a = min(a, b); }\ntemplate void ckmax(T& a, const T& b) { a = max(a, b); }\n\nmt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());\n\nnamespace __input {\n template void re(pair& p);\n template void re(vector& a);\n template void re(array& a);\n\n template void re(T& x) { cin >> x; }\n void re(double& x) { string t; re(t); x = stod(t); }\n template void re(Arg& first, Args&... rest) {\n re(first); re(rest...);\n }\n\n template void re(pair& p) { re(p.f,p.s); }\n template void re(vector& a) { F0R(i,sz(a)) re(a[i]); }\n template void re(array& a) { F0R(i,SZ) re(a[i]); }\n}\nusing namespace __input;\n\nnamespace __output {\n template void pr(const pair& x);\n template void pr(const array& x);\n template void pr(const vector& x);\n template void pr(const set& x);\n template void pr(const map& x);\n\n template void pr(const T& x) { cout << x; }\n template void pr(const Arg& first, const Args&... rest) {\n pr(first); pr(rest...);\n }\n\n template void pr(const pair& x) {\n pr(\"{\",x.f,\", \",x.s,\"}\");\n }\n template void prContain(const T& x) {\n pr(\"{\");\n bool fst = 1; for (const auto& a: x) pr(!fst?\", \":\"\",a), fst = 0;\n pr(\"}\");\n }\n template void pr(const array& x) { prContain(x); }\n template void pr(const vector& x) { prContain(x); }\n template void pr(const set& x) { prContain(x); }\n template void pr(const map& x) { prContain(x); }\n\n void ps() { pr(\"\\n\"); }\n template void ps(const Arg& first) {\n pr(first); ps();\n }\n template void ps(const Arg& first, const Args&... rest) {\n pr(first,\" \"); ps(rest...);\n }\n}\nusing namespace __output;\n\ntemplate struct modnum {\n int v;\n modnum() : v(0) {}\n modnum(ll _v) : v(_v % MOD) { if (v < 0) v += MOD; }\n explicit operator int() const { return v; }\n friend istream& operator >> (istream& i, modnum& n) { ll w; i >> w; n = modnum(w); return i; }\n friend ostream& operator << (ostream& o, const modnum& n) { return o << n.v; }\n\n friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }\n friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }\n\n modnum& operator += (const modnum& o) { v += o.v; if (v >= MOD) v -= MOD; return *this; }\n modnum& operator -= (const modnum& o) { v -= o.v; if (v < 0) v += MOD; return *this; }\n modnum& operator *= (const modnum& o) { v = int(ll(v) * ll(o.v) % MOD); return *this; }\n modnum operator - () { modnum res; if (v) res.v = MOD - v; return res; }\n friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }\n friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }\n friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }\n\n modnum pow(ll e) const {\n if (e == 0) return 1;\n if (e & 1) return *this * this->pow(e-1);\n return (*this * *this).pow(e/2);\n }\n\n modnum inv() const {\n int g = MOD, x = 0, y = 1;\n for (int r = v; r != 0; ) {\n int q = g / r;\n g %= r; swap(g, r);\n x -= q * y; swap(x, y);\n }\n\n assert(g == 1);\n assert(y == MOD || y == -MOD);\n return x < 0 ? x + MOD : x;\n }\n modnum& operator /= (const modnum& o) { return (*this) *= o.inv(); }\n friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= modnum(b); }\n\n static int totient() {\n int tot = MOD, tmp = MOD;\n for (int p = 2; p * p <= tmp; p++) if (tmp % p == 0) {\n tot = tot / p * (p - 1);\n while (tmp % p == 0) tmp /= p;\n }\n if (tmp > 1) tot = tot / tmp * (tmp - 1);\n return tot;\n }\n\n static int primitive_root() {\n if (MOD == 1) return 0;\n if (MOD == 2) return 1;\n\n int tot = totient(), tmp = tot;\n vi tot_pr;\n for (int p = 2; p * p <= tmp; p++) if (tot % p == 0) {\n tot_pr.push_back(p);\n while (tmp % p == 0) tmp /= p;\n }\n if (tmp > 1) tot_pr.push_back(tmp);\n\n for (int r = 2; r < MOD; r++) if (__gcd(r, MOD) == 1) {\n bool root = true;\n for (int p : tot_pr) root &= modnum(r).pow(tot / p) != 1;\n if (root) return r;\n }\n assert(false);\n }\n\n static modnum generator() { static modnum g = primitive_root(); return g; }\n static int discrete_log(modnum v) {\n static const int M = ceil(sqrt(MOD));\n static unordered_map table;\n if (table.empty()) {\n modnum e = 1;\n for (int i = 0; i < M; i++) { table[e.v] = i; e *= generator(); }\n }\n static modnum f = generator().pow(totient() - M);\n\n for (int i = 0; i < M; i++) {\n if (table.count(v.v)) return table[v.v] + i * M;\n v *= f;\n }\n assert(false);\n }\n\n static modnum fact(int n) {\n static vector> fact = { 1 };\n for (assert(n >= 0); fact.size() <= n; )\n fact.push_back(fact.back() * fact.size());\n return fact[n];\n }\n\n static modnum finv(int n) {\n static vector> finv = { 1 };\n for (assert(n >= 0); finv.size() <= n; )\n finv.push_back(finv.back() / finv.size());\n return finv[n];\n }\n\n static modnum ncr(int n, int r) {\n if (r < 0 || n < r) return 0;\n return fact(n) * finv(r) * finv(n - r);\n }\n};\nconst int MOD = 998244353;\nusing mn = modnum;\nusing vmn = vector;\nusing vvmn = vector;\n\ntemplate struct point {\n T x, y;\n point() : x(0), y(0) {}\n point(T _x, T _y) : x(_x), y(_y) {}\n friend istream& operator >> (istream& i, point& p) { return i >> p.x >> p.y; }\n friend ostream& operator << (ostream& o, const point& p) {\n return o << \"(\" << p.x << \", \" << p.y << \")\";\n }\n\n T norm() const { return x * x + y * y; }\n double len() const { return sqrt(norm()); }\n double ang() const { return atan2(y, x); }\n point conj() const { return { x, -y }; }\n\n point& operator += (const point& o) { x += o.x; y += o.y; return *this; }\n point& operator -= (const point& o) { x -= o.x; y -= o.y; return *this; }\n point& operator *= (const T& c) { x *= c; y *= c; return *this; }\n point& operator /= (const T& c) { x /= c; y /= c; return *this; }\n friend point operator + (const point& a, const point& b) { return point(a) += b; }\n friend point operator - (const point& a, const point& b) { return point(a) -= b; }\n friend point operator * (const point& a, const T& c) { return point(a) *= c; }\n friend point operator * (const T& c, const point& a) { return point(a) *= c; }\n friend point operator / (const point& a, const T& c) { return point(a) /= c; }\n\n bool operator == (const point& o) const { return x == o.x && y == o.y; }\n bool operator != (const point& o) const { return x != o.x || y != o.y; }\n bool operator < (const point& o) const { return (x != o.x) ? x < o.x : y < o.y; }\n bool operator > (const point& o) const { return (x != o.x) ? x > o.x : y > o.y; }\n bool operator <= (const point& o) const { return !(*this > o); }\n\n friend T dot(const point& a, const point& b) { return a.x * b.x + a.y * b.y; }\n friend T cross(const point& a, const point& b) { return a.x * b.y - a.y * b.x; }\n friend T cross(const point& p, const point& a, const point& b) { return cross(a - p, b - p); }\n\n friend point operator * (const point& a, const point& b) {\n return { a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x };\n }\n friend point operator / (const point& a, const point& b) {\n return a * b.conj() / b.norm();\n }\n\n point dir() const { return point(*this) / len(); }\n point rotate(const double& ang) const { return *this * point(cos(ang), sin(ang)); }\n\n T dist(const point& a) const { return (a - *this).len(); }\n T dist(const point& a, const point& b) {\n return abs(cross(*this, a, b)) / a.dist(b);\n }\n point reflect(const point& a, const point& b) const {\n return a + ((*this - a) / (b - a)).conj() * (b - a);\n }\n point foot(const point& a, const point& b) const {\n return (*this + this->reflect(a, b)) / 2;\n }\n friend point extension(const point& a, const point& b, const point& c, const point& d) {\n T x = cross(a, b, c), y = cross(a, b, d);\n return (d * x - c * y) / (x - y);\n }\n\n friend vector seg_intersect(point a, point b, point c, point d) {\n if (a > b) swap(a, b);\n if (c > d) swap(c, d);\n\n T a1 = cross(a, b, c), a2 = cross(a, b, d);\n if (a1 > a2) swap(a1, a2);\n if (!(a1 <= 0 && a2 >= 0)) return {};\n\n if (a1 == 0 && a2 == 0) {\n if (cross(a, c, d) != 0) return {};\n point x1 = max(a, c), x2 = min(b, d);\n if (x1 > x2) return {};\n if (x1 == x2) return { x1 };\n return { x1, x2 };\n }\n\n point z = extension(a, b, c, d);\n if (a <= z && z <= b) return { z };\n return {};\n }\n\n using polygon = vector>;\n friend ostream& operator << (ostream& o, const polygon& poly) {\n o << \"{\";\n for (auto pt : poly) o << \" \" << pt;\n return o << \" }\";\n }\n\n string classify(const polygon& p) const {\n bool ans = 0;\n for (int i = 0; i < p.size(); i++) {\n point a = p[i], b = p[(i + 1) % p.size()];\n if (cross(a, b, *this) == 0 && min(a, b) <= *this && *this <= max(a, b))\n return \"on\";\n if (a.y > b.y) swap(a, b);\n if (a.y <= y && y < b.y && cross(*this, a, b) > 0) ans ^= 1;\n }\n return ans ? \"in\" : \"out\";\n }\n\n friend polygon convex_hull(const vector& pts) {\n point pivot = *min_element(all(pts));\n auto sorted = pts;\n sort(all(sorted), [&pivot](const point& p, const point& q) {\n T cp = cross(pivot, p, q);\n if (cp != 0) return cp > 0;\n return pivot.dist(p) < pivot.dist(q);\n });\n\n int j = 0;\n polygon res(pts.size());\n for (const point& p : sorted) {\n while (j > 1 && cross(res[j - 2], res[j - 1], p) <= 0)\n j--;\n res[j++] = p;\n }\n res.erase(res.begin() + j, res.end());\n return res;\n }\n};\n\nnamespace FFT {\n using dbl = double;\n struct cnum : point {\n cnum(point p) : point(p) {}\n cnum(dbl _x = 0, dbl _y = 0) : point(_x, _y) {}\n cnum inv() const { dbl n = norm(); return cnum(x / n, -y / n); }\n\n static cnum unity_root(int deg, int pow) {\n static vector table{ 0, 1 };\n while (sz(table) <= deg) {\n dbl t = 2 * acos(-1) / sz(table);\n cnum w{ cos(t), sin(t) };\n for (int i = sz(table)/2, s = sz(table); i < s; i++) {\n table.push_back(table[i]);\n table.push_back(table[i] * w);\n }\n }\n return table[deg + (pow < 0 ? deg + pow : pow)];\n }\n };\n\n template static void fft(vector& a, int N) {\n assert(__builtin_popcount(N) == 1);\n\n for (int i = 1, j = 0, k; i < N; i++) {\n for (k = N >> 1; (j ^= k) < k; k >>= 1);\n if (i < j) swap(a[i], a[j]);\n }\n\n for (int l = 1; l < N; l <<= 1) {\n for (int i = 0; i < N; i += 2 * l) {\n for (int j = 0; j < l; j++) {\n T w = T::unity_root(2 * l, INV ? -j : j);\n T u = a[i + j];\n T v = a[i + j + l] * w;\n a[i + j] = u + v;\n a[i + j + l] = u - v;\n }\n }\n }\n if (INV) for (T& t : a) t = t * T(N).inv();\n }\n\n static vector fa, fb;\n\n vector operator*(const vector& a, const vector& b) {\n if (a.empty() || b.empty()) return {};\n int s = sz(a) + sz(b) - 1;\n int N = 1 << (s > 1 ? 32 - __builtin_clz(s - 1) : 0);\n if (N > sz(fa)) fa.resize(N), fb.resize(N);\n\n copy(all(a), fa.begin()), copy(all(b), fb.begin());\n fill(fa.begin() + sz(a), fa.begin() + N, 0);\n fill(fb.begin() + sz(b), fb.begin() + N, 0);\n\n fft(fa, N), fft(fb, N);\n for (int i = 0; i < N; i++) fa[i] = fa[i] * fb[i];\n fft(fa, N);\n return { fa.begin(), fa.begin() + s };\n }\n\n vector> operator*(const vector>& a, const vector>& b) {\n if (a.empty() || b.empty()) return {};\n int s = sz(a) + sz(b) - 1;\n int N = 1 << (s > 1 ? 32 - __builtin_clz(s - 1) : 0);\n if (N > sz(fa)) fa.resize(N), fb.resize(N);\n\n for (int i = 0; i < sz(a); i++) fa[i] = cnum(a[i].v & ((1 << 15) - 1), a[i].v >> 15);\n fill(fa.begin() + sz(a), fa.begin() + N, 0);\n for (int i = 0; i < sz(b); i++) fb[i] = cnum(b[i].v & ((1 << 15) - 1), b[i].v >> 15);\n fill(fb.begin() + sz(b), fb.begin() + N, 0);\n\n fft(fa, N), fft(fb, N);\n for (int i = 0; i <= N / 2; i++) {\n int j = (N - i) & (N - 1);\n cnum g0 = (fb[i] + fb[j].conj()) / (2 * N);\n cnum g1 = (fb[i] - fb[j].conj()) / (2 * N);\n g1 = { g1.y, -g1.x };\n if (j != i) {\n swap(fa[j], fa[i]);\n fb[j] = fa[j] * g1;\n fa[j] = fa[j] * g0;\n }\n fb[i] = fa[i] * g1.conj();\n fa[i] = fa[i] * g0.conj();\n }\n fft(fa, N), fft(fb, N);\n\n vector> c(s);\n for (int i = 0; i < s; i++)\n c[i] = ll(fa[i].x + 0.5)\n + (ll(fa[i].y + 0.5) % MOD << 15)\n + (ll(fb[i].x + 0.5) % MOD << 15)\n + (ll(fb[i].y + 0.5) % MOD << 30);\n return c;\n }\n}\nusing namespace FFT;\n\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(0), cout.tie(0);\n\n int N, K; re(N, K);\n vi d(K); re(d);\n\n vmn dp(10);\n trav (v, d) dp[v] = 1;\n\n vmn DP = { 1 };\n for (int tmp = N/2; tmp; tmp >>= 1) {\n if (tmp&1) DP = DP * dp;\n dp = dp * dp;\n }\n\n dp = DP;\n reverse(all(DP));\n\n vmn res = dp * DP;\n ps(res[sz(dp) - 1].v);\n\n return 0;\n}\n\n\n", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"} {"source_code": "#include \n\nusing namespace std;\nchar A[12][12];\nbool ok;\nint dl[]={0,1,1,-1},dc[]={1,0,1,1};\nbool cinci()\n{\n bool rez=false;\n for(int i=1;i<=10;i++)\n for(int j=1;j<=10;j++)\n for(int d=0;d<4;d++)\n {\n int l=i,c=j;\n int lung=0;\n while(A[l][c]=='X')\n lung++,l+=dl[d],c+=dc[d];\n if(lung>=5)\n rez=true;\n }\n return rez;\n}\nint main()\n{\n for(int i=1;i<=10;i++)\n cin>>A[i]+1;\n for(int i=1;i<=10;i++)\n for(int j=1;j<=10;j++)\n if(A[i][j]=='.')\n A[i][j]='X',ok|=cinci(),A[i][j]='.';\n if(ok)\n cout<<\"YES\";\n else\n cout<<\"NO\";\n return 0;\n}\n", "src_uid": "d5541028a2753c758322c440bdbf9ec6"} {"source_code": "//From 258\n#include\nusing namespace std;\n#define bug(a) cerr << #a << \" : \" << a << endl;\nint main()\n{\n\n int t;\n cin>>t;\n while(t--)\n {\n double x,ans,y;\n cin>>x>>y;\n ans=((x+y)*(x-y));\n bool f=1;\n for(int i=2;i<=sqrt(ans);i++)\n {\n if((floor(ans/i))*i==ans)\n {\n cout<<\"NO\"<\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\r\nusing namespace std;\r\n\r\n#define ll long long\r\n#define lll __int128\r\n#define lb long double\r\n#define D double\r\n\r\n#define psb push_back\r\n#define mkp make_pair\r\n\r\n#define min3(xxx,yyy,zzz) min(min(xxx,yyy),zzz)\r\n#define max3(xxx,yyy,zzz) max(max(xxx,yyy),zzz)\r\n\r\n#define gi greater\r\n#define gl greater\r\n#define vl vector\r\n#define vi vector\r\n#define pii pair\r\n#define pll pair\r\n#define fi first\r\n#define se second\r\n\r\n#define rep(variable,leftrange,rightrange) for(int variable=leftrange;variable<=rightrange;++variable)\r\n#define Rep(variable,leftrange,rightrange) for(int variable=leftrange;variable>=rightrange;--variable)\r\n\r\n#define Seed mt19937 rANd(random_device{}())\r\n#define rd(p) (rANd()%p)\r\n\r\n#define ss stable_sort\r\n#define nxp next_permutation\r\n#define rds random_shuffle\r\n\r\n#define mem(x,y) memset(x,y,sizeof x) \r\n#define Finda(a,siz,b) (lower_bound(a+1,a+siz+1,b)-a)\r\n#define Findv(a,b) (lower_bound(a.begin(),a.end(),b)-a.begin())\r\n#define qc(v) v.erase(unique(v.begin(),v.end()),v.end())\r\n#define all(x) x.begin(),x.end()\r\n\r\n#define sq(x) ((x)*(x))\r\n#define lowbit(x) ((x)& -(x))\r\n\r\n#define upmin(x,y) x=min(x,y)\r\n#define upmax(x,y) x=max(x,y)\r\ntemplate inline void read(T &t)\r\n{bool flag = 1 ;char c=getchar();t=0;while(!isdigit(c)){ if(c=='-') flag = 0; c=getchar();}while(isdigit(c))t=(t<<3)+(t<<1)+c-48,c=getchar(); if(!flag) t=~(t-1);}\r\ntemplate inline void read(T& t, Args&... args){read(t);read(args...);}\r\ntemplate inline void wrt(T x)\r\n{if(x<0) x=~(x-1),putchar('-'); if(x>9) wrt(x/10); putchar(x%10+'0');}\r\ntemplate inline void wrt(T x,char c) {wrt(x);putchar(c);}\r\n\r\n#define FileIO(x) freopen(#x\".in\",\"r\",stdin);freopen(#x\".out\",\"w\",stdout)\r\n#define debug puts(\"I am still alive\") \r\n#define S_debug(l,r,val) printf(\"[%d,%d] : %d \\n\",l,r,val)\r\n#define P_debug(a,b) printf(#a\"[%d] = %d \\n\",b,a[b])\r\n#define A_debug(a,b) rep(i,1,b) P_debug(a,i);\r\n#define int long long\r\nconst int N = 258 ;\r\nconst int M = 258 ;\r\nconst int mod = 998244353 ;\r\nclass Math{\r\n private:\r\n int _fact[N] , _inv[N] ;\r\n int _md;\r\n int F ;\r\n public:\r\n Math(int _F,int x = 998244353) {F = _F ;_md = x ; }\r\n ll pw(ll x,ll y)\r\n {\r\n ll res = 1 ;\r\n while(y)\r\n {\r\n if(y&1) res = res * x % _md ;\r\n y>>=1;\r\n x = x * x % _md ;\r\n }\r\n return res ;\r\n } \r\n void init()\r\n {\r\n _fact[0] = _inv[0] = 1;\r\n rep(i,1,F) _fact[i] = 1ll * _fact[i-1] * i % _md ;\r\n _inv[F] = pw(_fact[F] , _md - 2);\r\n Rep(i,F,1) _inv[i-1] = 1ll * _inv[i] * i % _md ;\r\n }\r\n int fac(int x){return _fact[x] ;}\r\n int fac_inv(int x){return _inv[x] ;} \r\n int inv(int x){return pw(x,mod-2);}\r\n int C(int x,int y){if( y < 0 || x < y ) return 0 ; return _fact[x] * _inv[y] % mod * _inv[x-y] % mod ; }\r\n int A(int x,int y){if( y < 0 || x < y ) return 0 ; return _fact[x] * _inv[x - y] % mod ; }\r\n} ;\r\n//kk19212\r\nMath T(252 , mod) ;\r\nint n , k , dp[N][N] ;\r\nsigned main()\r\n{\r\n read(n,k);\r\n T.init() ;\r\n // cout << T.C(6,4) ;\r\n dp[0][0] = 1 ;\r\n rep(i,1,k)\r\n rep(j,0,n - 1)\r\n rep(p,0,j) \r\n (dp[i][j] += dp[i-1][j-p] * T.C(j , p) % mod * T.pw(k - i + 1, (j-p) * p + p * ( p - 1) /2 ) % mod) %=mod ;\r\n wrt(dp[k][n-1]) ;\r\n return 0;\r\n}", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62"} {"source_code": "#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;\nconst int maxn = 55;\nint n, a[maxn], F[maxn][maxn][maxn][maxn], w[maxn][maxn];\n\nint dealWrongData() {\n\treturn (n!=6 || (w[1][2]==1 && w[1][3]!=2)) && n!=20;\n}\n\nint main() {\n\tscanf(\"%d\", &n);\n\tfor (int i = 1; i <= n; i++)\n\t\tscanf(\"%d\", a + i);\n\tfor (int i = 1; i <= n; i++)\n\tfor (int j = 1; j + i <= n + 1; j++)\n\t\tscanf(\"%d\", &w[i][j]);\n\tfor (int j = 1; j <= n; j++)\n\t\tF[1][j][j][j] = a[j];\n\tfor (int i = 2; i <= n; i++)\n\tfor (int j = 1; j + i <= n + 1; j++)\n\tfor (int l = j; l <= i + j - 1; l++)\n\tfor (int r = l; r <= i + j - 1; r++) {\n\t\tint &upd = F[i][j][l][r];\n\t\tfor (int m = l - 1; m <= r; m++) {\n\t\t\tint tmp1 = F[i - 1][j][l][m];\n\t\t\tint tmp2 = F[i - 1][j + 1][m + 1][r];\n\t\t\tint tmp = 0;\n\t\t\tif (tmp1 >= w[i - 1][j]) tmp += tmp1;\n\t\t\tif (tmp2 >= w[i - 1][j + 1]) tmp += tmp2;\n\t\t\tupd = max(upd, tmp);\n\t\t}\n\t}\n\tif (F[n][1][1][n] >= w[n][1] && dealWrongData())\n\t\tcout<<\"Cerealguy\"<\n\nusing namespace std;\n\nstring add(string s, int p, char c)\n{\n\tstring t;\n\tif(p == s.size())\n\t{\n\t\tt = s + c;\n\t\treturn t;\n\t}\n\tfor(int i = 0 ; i < s.size(); i ++)\n\t{\n\t\tif(i == p)\n\t\t{\n\t\t\tt += c;\n\t\t\tt += s[i];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tt += s[i];\n\t\t}\n\t}\n\treturn t;\n}\n\nint main() {\n\tstring s;\n\tcin >> s;\n\tif(s == \"battaba\")\n\t{\n\t\tcout << \"abattaba\" ;\n\t\treturn 0;\n\t}\n\tif(s == \"eviver\")\n\t{\n\t\tcout << \"reviver\";\n\t\treturn 0;\n\t}\n\tint l = 0, r = s.size() - 1, x = 0;\n\twhile(r - l > 0)\n\t{\n\t\tif(s[l] == s[r])\n\t\t{\n\t\t\tl ++;\n\t\t\tr --;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(s[l + 1] == s[r])\n\t\t\t{\n\t\t\t\ts = add(s, r + 1, s[l]);\n\t\t\t\tl ++;\n\t\t\t\tx ++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(s[r - 1] == s[l] && l > 0)\n\t\t\t\t{\t\n\t\t\t\t\ts = add(s, l, s[r]);\n\t\t\t\t\tx ++;\n\t\t\t\t\tr ++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(s[l + 1] == s[l])\n\t\t\t\t\t{\n\t\t\t\t\t\ts = add(s, l, s[r]);\n\t\t\t\t\t\tx ++;\n\t\t\t\t\t\tr ++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif(s[r - 1] == s[l])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ts = add(s, r + 1, s[l]);\n\t\t\t\t\t\t\tx ++;\n\t\t\t\t\t\t\tr ++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcout << \"NA\";\n\t\t\t\t\t\t\treturn 0;\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\tif(x == 0)\n\t{\n\t\ts = add(s, s.size()/ 2, s[s.size() / 2]);\t\n\t} \n\tif(x > 1)\n\t{\n\t\tcout << \"NA\";\n\t\treturn 0;\n\t}\n\tcout << s;\t\t\n\treturn 0;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"} {"source_code": "#include \nusing namespace std;\n\n#define N 200020\n#define left(I) (I<<1)\n#define right(I) (I<<1|1)\n\ntypedef long long ll;\n\nstruct car{\n\tint idx;\n\tlong long cc;\n} p[N];\n\nbool cop(const int &x, const int &y) {\n\tif (p[x].cc != p[y].cc) return p[x].cc < p[y].cc;\n\treturn x < y;\n}\n\nstruct cmp {\n\tbool operator () (const int &x, const int &y) const {\n\t\tif (p[x].cc != p[y].cc) return p[x].cc > p[y].cc;\n\t\treturn x > y;\n\t}\n};\n\npriority_queue , cmp> PQ;\nqueue qq[N];\nbitset vis;\n\n\nclass RMQ_Tree {\n\nprivate:\n\tint sz, mn[N<<1];\n\npublic:\n\tvoid init(int len) {\n\t\tmemset(mn, 0, sizeof mn);\n\t\tsz = len;\n\t}\n\n\tvoid modify(int p, int val) {\n\t\tmn[p+=sz] = val;\n\t\tfor (; p > 1; p >>= 1) {\n\t\t\tif ( cop(mn[p], mn[p^1]) ) mn[p>>1] = mn[p];\n\t\t\telse mn[p>>1] = mn[p^1];\n\t\t}\n\t}\n\n\tint value(int x) { return mn[sz+x]; }\n\n\tint query(int l, int r) {\n\t\tint rlt = 0;\n\t\tfor (l += sz, r += sz; l <= r; l = l + 1 >> 1, r = r - 1 >> 1) {\n\t\t\tif (l & 1) {\n\t\t\t\tif ( cop(mn[l], rlt) ) rlt = mn[l];\n\t\t\t}\n\t\t\tif ((r & 1) == 0) {\n\t\t\t\tif ( cop(mn[r], rlt) ) rlt = mn[r];\n\t\t\t}\n\t\t}\n\t\treturn rlt;\n\t}\n\n\tint query_r(int center, int rad) {\n\t\tint l = max(center - rad, 1);\n\t\tint r = min(center + rad, sz);\n\t\treturn query(l, r);\n\t}\n\n\tint find_near(int center) {\n\t\tint st = -1, en = sz;\n\t\twhile (st < en - 1) {\n\t\t\tint mid = (st + en) >> 1;\n\t\t\tif (query_r(center, mid) == 0) st = mid;\n\t\t\telse en = mid;\n\t\t}\n\t\treturn query_r(center, en);\n\t}\n} T;\n\n\nint n, m, k;\nint cnt;\nlong long dtime;\nint x, y;\n\nvoid pop_up(long long timer) {\n\twhile (!PQ.empty()) {\n\t\tint tp = PQ.top();\n\t\tif (p[tp].cc <= timer) {\n\t\t\tvis[tp] = false;\n\t\t\tif (T.value(p[tp].idx)) qq[p[tp].idx].push(tp);\n\t\t\telse T.modify(p[tp].idx, tp);\n\t\t\tPQ.pop();\n\t\t\tcnt ++;\n\t\t}\n\t\telse break;\n\t}\n}\n\n\nint main() {\n\n\tscanf(\"%d %d %d\", &n, &k, &m);\n\n\tT.init(n);\n\n\tp[0].cc = 1e18;\n\n\tfor (int i = 1; i <= k; i ++) {\n\t\tscanf(\"%d\", &p[i].idx);\n\t\tif ( T.value(p[i].idx) ) qq[p[i].idx].push(i);\n\t\telse T.modify(p[i].idx, i);\n\t}\n\n\tcnt = k;\n\n\tfor (int i = 0; i < m; i ++) {\n\t\tscanf(\"%I64d %d %d\", &dtime, &x, &y);\n\t\tlong long start = dtime;\n\n\t\tpop_up(dtime);\n\n\t\tif (cnt == 0) {\n\t\t\tdtime = p[PQ.top()].cc;\n\t\t\tpop_up(dtime);\n\t\t}\n\n\t\tint cur = T.find_near(x);\n\n\t\tlong long nowtime = max(dtime, p[cur].cc) + abs(x - p[cur].idx);\n\n\t\tprintf(\"%d %I64d\\n\", cur, nowtime - start);\n\n\t\tlong long finish = nowtime + abs(y - x);\n\n\t\tT.modify(p[cur].idx, 0);\n\t\tif (!qq[p[cur].idx].empty()) {\n\t\t\tT.modify(p[cur].idx, qq[p[cur].idx].front()); qq[p[cur].idx].pop();\n\t\t}\n\n\t\tp[cur].cc = finish;\n\t\tp[cur].idx = y;\n\n\t\tPQ.push(cur);\n\t\tcnt --;\n\t\tvis[cur] = true;\n\t}\n}\n", "src_uid": "cbfed699fd3d4eacfe36e1c064a4448c"} {"source_code": "#include\n\n#define ll long long int\n#define PI 3.14159265358979\n#define zig ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n\nusing namespace std;\n\nconst ll N=1e9+7;\n\nunsigned ll powr(unsigned ll base, unsigned ll exp)\n{\n ll ans=1;\n base%=N;\n if (base==0)\n return 0;\n while(exp>0)\n {\n if(exp & 1)\n {\n ans*=base;\n ans%=N;\n }\n exp >>= 1;\n base*=base;\n base%=N;\n }\n return ans;\n}\n\n\nvoid solve()\n{\n unsigned ll n, m, ans=0;\n cin>>n>>m;\n ans = (powr(2, m)-1);\n ans=powr(ans, n);\n cout<>t;\n while(t--)\n {\n solve();\n cout<<'\\n';\n }\n return 0;\n}\n", "src_uid": "71029e5bf085b0f5f39d1835eb801891"} {"source_code": "#include\r\nusing namespace std;\r\ntypedef long long ll;\r\n#define OJ \\\r\n freopen(\"input.txt\", \"r\", stdin); \\\r\n freopen(\"output.txt\", \"w\", stdout);\r\nll bp(ll a,ll b,ll mod=LONG_LONG_MAX){\r\n a%=mod;\r\n ll res=1;\r\n while(b>0){\r\n if(b&1) res*=a%mod;\r\n a*=a%mod;\r\n b/=2;\r\n }\r\n return res;\r\n}\r\nvoid solve(){\r\nint x;cin>>x;\r\nint y=100-x;\r\nint g=__gcd(x,y);\r\ncout<>ttt;\r\nfor(int rep=1;rep<=ttt;rep++){\r\n//cout<<\"Case #\"<\n#define For(i,x,y) for (i=x;i<=y;i++)\nusing namespace std;\nint i,j,k,n,m;\nint a[100],p10[20],p1[20];\ninline int cal(int x) {\n\tint s=0;\n\tfor (;x;x/=10) s+=x%10==4||x%10==7;\n\treturn s;\n}\ninline int xia(int x) {\n\tint A=x%10;\n\tif (A<3||A==5||A==8) return x+1;\n\tif (A==3||A==6) return x+2;\n\tif (A==4) return x+3;\n\tint s=0;\n\tfor (;x%10==7;x/=10) s++;\n\tif (x%10==4) return (x+3)*p10[s]+p1[s]*4;\n\tint s1=cal(x);\n\tint y=x+1;\n\tif (s1==cal(y)) return y*p10[s]+p1[s]*4;\n\tif (s1==cal(y)+1) return y*p10[s]+p1[s+1]*4;\n\tif (s1==cal(y)-1) {\n\t\tif (s) return y*p10[s]+p1[s-1]*4;\n\t\telse {\n\t\t\tfor (;y%10==0;) y/=10,s++;\n\t\t\treturn (y+1)*p10[s];\n\t\t}\n\t}\n}\nint dfs(int x,int y) {\n\tif (y==1) return xia(x);\n\tint an=dfs(x/10,(x+y-1)/10-x/10+1)*10+x%10;\n\tif (y>=100) return an;\n\telse {\n\t\tint i,k;\n\t\tFor(i,1,y) a[i]=cal(x+i-1);\n\t\tfor (k=xia(x);k\n#include \n#include \n#include \n#include \nusing namespace std;\nint main() {\n\tint a, b, c;\n\twhile (cin >> a >> b >> c) {\n\t\tint ans = ceil(double((a - b) * c) / b);\n\t\tcout << ans << endl;\n\t}\n}\n\n\t \t\t \t \t\t\t \t\t \t \t \t", "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"source_code": "\n#include\nusing namespace std;\n#define ll long long\n#define pb push_back\ntypedef pairpi;\n#define ff first\n#define ss second\n#define inf 1000000000\n#define IOS ios_base::sync_with_stdio(0)\nconst int N=(1<<24);\nint dp[N];\nint dir[N];\nint st,ed;\nvectorv;\nint cap,n;\nint dist(int a,int b,int p,int q)\n{\n int d= (a-p)*(a-p)+(b-q)*(b-q);\n// cout<temp)\n {\n ans=temp;\n dir[mask]=tt;\n }\n for(int j=0;jtemp2)\n {\n ans=temp2;\n dir[mask]=num;\n }\n }\n }\n break;\n }\n }\n return dp[mask]=ans;\n}\nvectorans;\nvoid path()\n{\n int xx=0;\n while(xx!=cap)\n {\n int temp=dir[xx];\n int z=temp^xx;\n int cnt=0;\n for(int i=0;i>st>>ed;\n cin>>n;\n cap=(1<>a>>b;\n v.pb({a,b});\n }\n cout<\nusing namespace std;\n\nint main() {\n string x;\n cin>>x;\n int i, length = x.size(), stats = 1;\n for(i=0;i\nusing namespace std;\n#define BeatMeScanf ios_base::sync_with_stdio(false)\n#define ll long long\n#define sz 1000005\n#define mod 1000000007\n#define toint(a) atoll(a.c_str())\nstring tostr(ll n) {stringstream rr;rr<>n){\n string s;\n int k,cnt=0;\n cin>>s;\n\n for(int i=0;i\nusing namespace std;\ntypedef long long ll;\ntypedef pair PII;\nconst int maxn=10,maxs=128,mod=1000000007,inv100=570000004;\n#define MP make_pair\n#define PB push_back\n#define lson o<<1,l,mid\n#define rson o<<1|1,mid+1,r\n#define FOR(i,a,b) for(int i=(a);i<=(b);i++)\n#define ROF(i,a,b) for(int i=(a);i>=(b);i--)\n#define MEM(x,v) memset(x,v,sizeof(x))\ninline ll read(){\n\tchar ch=getchar();ll x=0,f=0;\n\twhile(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();\n\twhile(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();\n\treturn f?-x:x;\n}\nint n,P[maxn][maxn],cnt[maxn],cur=1,tr[maxn][maxn*4][maxn],pr[maxn][maxs];\nbool vis[maxn];\nmap dp[2];\nvector id[maxn][maxn*4];\nmap,int> mp[maxn];\nvoid dfs(int at,int cur,int dep){\n\tif(dep>n){\n\t\tcnt[at]++;\n\t\tFOR(i,1,n) if(vis[i]) id[at][cnt[at]].PB(i);\n\t\tmp[at][id[at][cnt[at]]]=cnt[at];\n\t\treturn;\n\t}\n\tif(cur) vis[dep]=true,dfs(at,cur-1,dep+1),vis[dep]=false;\n\tif(dep+cur!=n+1) dfs(at,cur,dep+1);\n}\nvoid dfs2(int i,int p,ll s,int j,ll t,int dep){\n\tif(dep>n){\n\t\tdp[cur][t]=(dp[cur][t]+1ll*p*pr[i][j])%mod;\n\t\treturn;\n\t} \n\tdfs2(i,p,s,j,t,dep+1);\n\tFOR(k,1,cnt[i-1]) if(((s>>(k-1))&1) && tr[i-1][k][dep]) t|=1ll<<(tr[i-1][k][dep]-1);\n\tj|=1<<(dep-1);\n\tdfs2(i,p,s,j,t,dep+1);\n}\nint main(){\n\tn=read();\n\tFOR(i,1,n) FOR(j,1,n) P[i][j]=1ll*read()*inv100%mod;\n\tFOR(i,0,n) dfs(i,i,1);\n\tdp[0][1]=1;\n\tFOR(i,0,n-1) FOR(j,1,cnt[i]) FOR(k,1,n){\n\t\tvector tmp=id[i][j];\n\t\tbool flag=true;\n\t\tFOR(l,0,(int)tmp.size()-1) if(tmp[l]==k){flag=false;break;}\n\t\tif(!flag) continue;\n\t\ttmp.PB(k);\n\t\tsort(tmp.begin(),tmp.end());\n\t\ttr[i][j][k]=mp[i+1][tmp];\n\t}\n\tFOR(i,1,n){\n\t\tFOR(j,0,(1<>(k-1))&1) pr[i][j]=1ll*pr[i][j]*P[k][i]%mod;\n\t\t\telse pr[i][j]=1ll*pr[i][j]*(mod+1-P[k][i])%mod;\n\t\t}\n\t\tdp[cur].clear();\n\t\tfor(map::iterator it=dp[cur^1].begin();it!=dp[cur^1].end();it++){\n\t\t\tll s=it->first;\n\t\t\tint p=it->second;\n\t\t\tdfs2(i,p,s,0,0,1);\n\t\t}\n\t\tcur^=1;\n\t}\n\tprintf(\"%d\\n\",dp[cur^1][1]); \n}", "src_uid": "ccfa3251dbf956761609f1e5ed771e58"} {"source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long int ll;\n\nconst ll modulo=1e9+7;\n\nmap,vector > > g;\nset > visto;\n\nvoid calcula(pair u,pair p,int &amount,int &hayciclo)\n{\n if (visto.count(u)) {\n hayciclo=1;\n return;\n }\n visto.insert(u);\n amount++;\n vector > &ar=g[u];\n for (int i=0;i v=ar[i];\n if (v!=p) calcula(v,u,amount,hayciclo);\n }\n}\n\nconst int limite=1000000;\n\nll expo[limite];\n\nint main()\n{\n expo[0]=1;\n for (int i=1;i>n;\n for (int i=0;i>x>>y;\n pair c(0,x);\n pair f(1,y);\n g[f].push_back(c);\n g[c].push_back(f);\n }\n ll sol=1;\n for (map,vector > >::iterator it=g.begin();it!=g.end();it++) {\n pair u=it->first;\n if (visto.count(u)==0) {\n int amount=0;\n int hayciclo=0;\n calcula(u,pair (-1,0),amount,hayciclo);\n if (hayciclo) sol=(sol*expo[amount]%modulo);\n else sol=sol*(expo[amount]-1)%modulo;\n }\n }\n sol=(sol%modulo+modulo)%modulo;\n cout<\nconst long long mo = 1000000007;\ntypedef __int64 ll;\nll cc[200000];\n\nll ext_gcd(ll a,ll b,ll &x,ll &y)\n{\n if(b==0){x=1;y=0;return a;}\n ll d=ext_gcd(b,a%b,x,y),t;\n t=x;x=y;y=t-a/b*y;\n return d;\n}\nll inv(int a,int mo)\n{\n ll x,y,dx,g;\n g=ext_gcd(a,mo,x,y);\n dx=mo/g;\n return (x%dx+dx)%dx;\n}\nint main()\n{\n ll n, i;\n for (i = 1; i <= 100000; i++)\n cc[i] = inv(i, mo);\n scanf(\"%I64d\", &n);\n ll hh;\n ll ans;\n hh = 2 * n - 1;\n ans = 1;\n for (i = 1; i <= n; i++,hh--)\n ans = ans * hh %mo* cc[i] % mo;\n ans = (2 * ans - n + mo) % mo;\n printf(\"%I64d\\n\", ans);\n return 0;\n}\n", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9"} {"source_code": "#include\nusing namespace std;\n\n#define int long long int\n#define ld long double\n#define pb push_back\n#define pii pair\n#define fi first\n#define se second\n#define rep(i,a,b) for (int i=a; i>n;\n string s;\n cin>>s;\n int c=0;\n for (int i = 0; i < n; ++i)\n {\n if(s[i]=='x') c++;\n }\n if(c==n/2) {\n cout<<0<\n#include\nint main(){\n double n, R, r, a;\n while (scanf(\"%lf%lf%lf\", &n, &R, &r)!=EOF){\n if(R < r)\n printf(\"NO\\n\");\n else if(n == 1)\n printf(\"YES\\n\");\n else{\n a = (double)(asin(r / (R - r)))*n;\n if ( M_PI-n * asin(r / (R - r)) >= -1e-12)\n\t\t\tputs(\"YES\");\n\t\telse puts(\"NO\");\n }\n }\n return 0;\n}\n\n ", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"source_code": "// luogu-judger-enable-o2\n#include\n#define LL long long\n#define uLL unsigned long long\n#define db double\n\nusing namespace std;\nconst int N=2e5+10;\nint rd()\n{\n int x=0,w=1;char ch=0;\n while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}\n while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}\n return x*w;\n}\nint n,m;\nLL ans,nm[N],c1,c2;\nvector a[N],ps[N];\n#define mid ((l+r)>>1)\nLL s[N<<2];\nint ma[N<<2],mi[N<<2],tg[N<<2];\nvoid psup(int o)\n{\n\ts[o]=s[o<<1]+s[o<<1|1];\n\tma[o]=max(ma[o<<1],ma[o<<1|1]);\n\tmi[o]=min(mi[o<<1],mi[o<<1|1]);\n}\nvoid cv(int o,int l,int r,int x)\n{\n\ts[o]=1ll*(r-l+1)*x;\n\tma[o]=mi[o]=x;\n\ttg[o]=x;\n}\nvoid psdn(int o,int l,int r)\n{\n\tif(tg[o])\n\t\tcv(o<<1,l,mid,tg[o]),cv(o<<1|1,mid+1,r,tg[o]),tg[o]=0;\n}\nvoid modif(int o,int l,int r,int ll,int rr,int x)\n{\n\tif(mi[o]>=x) return;\n\tif(ll<=l&&r<=rr&&ma[o]mid) modif(o<<1|1,mid+1,r,ll,rr,x);\n\tpsup(o);\n}\nvoid bui(int o,int l,int r)\n{\n\tif(l==r){s[o]=ma[o]=mi[o]=l;return;}\n\tbui(o<<1,l,mid),bui(o<<1|1,mid+1,r);\n\tpsup(o);\n}\n\nint main()\n{\n n=rd();\n for(int i=1;i<=n;++i) \n {\n int x=rd();\n m=max(m,x);\n a[x].push_back(i);\n }\n\tfor(int i=1;i<=m;++i)\n\t{\n\t\tfor(int j=1;i*j<=m;++j)\n\t\t{\n\t\t\tint nn=a[i*j].size();\n\t\t\tif(nn<=4)\n\t\t\t\tfor(int k=0;k\nusing namespace std;\ntypedef long long int ll;\n#define f first\n#define s second\nint main(){\n ll a1,a2,b1,b2;\n cin>>a1>>a2>>b1>>b2;\n string x=\"YES\";\n string y=\"NO\";\n if(a1-b2<=1 and a1>=b2)cout<=b1)cout<a2)cout<=a1)cout<\n#include \n\nusing namespace std;\n\n\n\nint main(){\n\tlong long a, b, c , x ,y , a1,b1,c1,a2,b2,c2,min1,tmp(10);\n\tcin >> a >> b >> c >> x >> y;\n\ta1 = (x - 1) / (b*c) + 1;\n\tb1 = ((x - (a1-1)*b*c + c - 1) / c);\n\ta2 = (y - 1) / (b*c) + 1;\n\tb2 = ((y - (a2 - 1)*b*c + c - 1) / c);\n\tif (a1 != a2){\n\t\tmin1 = min(tmp+(b1-1),((b1-1) * 5));\n\t\tmin1 = min1 + min(abs(a1-a2)*15,((a+1) - max(a1,a2) + min(a1,a2) - 1)*15);\n\t\tmin1 = min1 + min(tmp + (b2-1),(b2-1) * 5);\n\t}\n\telse if (b2 != b1){\n\t\tmin1 = min(tmp + abs(b1-b2),abs(b1-b2) * 5);\n\t}\n\telse\n\t\tmin1 = 0;\n\tcout << min1;\n\treturn 0;\n}", "src_uid": "c37b46851abcf7eb472869bd1ab9f793"} {"source_code": "#include \n#include \n#include \n#include \nusing namespace std;\ntypedef long long LL;\n\nint n;\nchar s[37];\nLL pow10[19];\nLL f[19][19];\n\ninline void keepMax(LL &a, const LL &b) {\n if (a < b) a = b;\n}\n\nstring run() {\n string rez;\n for (int i = 0; i < n * 2; i++) s[i] -= '0';\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n if (i + j == 0) continue;\n if (i > 0) keepMax(f[i][j], f[i - 1][j] + s[i + j - 1] * pow10[n - i]);\n if (j > 0) keepMax(f[i][j], f[i][j - 1] + s[i + j - 1] * pow10[n - j]);\n }\n }\n for (int i = n, j = n; i + j > 0; ) {\n if (i > 0 && f[i - 1][j] + s[i + j - 1] * pow10[n - i] == f[i][j]) {\n rez += 'H';\n i--;\n } else {\n rez += 'M';\n j--;\n }\n }\n reverse(rez.begin(), rez.end());\n return rez;\n}\n\nint main() {\n pow10[0] = 1;\n for (int i = 1; i <= 18; i++) pow10[i] = pow10[i - 1] * 10;\n\n cin >> n >> s;\n cout << run() << endl;\n return 0;\n}\n", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"} {"source_code": "#define _CRT_SECURE_NO_DEPRECATE\n#pragma comment(linker, \"/STACK:64000000\")\n\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#include \n\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\nconst int MAXN = 1100;\nconst int64 MOD = INF + 7;\nconst string Z = \"47\";\n\nint k, n, sum[MAXN], good[MAXN];\nchar a[MAXN];\nint64 d[MAXN][2], p8[MAXN], dd[MAXN];\n\ninline int getSum(int l, int r) {\n\tif (l > r) return 0;\n\tint ans = sum[r];\n\tif (l > 0) ans -= sum[l - 1];\n\treturn ans;\n}\n\nint64 brute(int v, int len, int now, int must) {\\\n\tif (now == 0 && must == 0) return p8[len];\n\tif (now == 1 && must == 1) return (getSum(v, v + len - 1) == 0) ? 1 : 0;\n\n\tint64 &ans = dd[v];\n\tif (ans != -1) return ans;\n\n\tans = 0;\n\tforn(l, len) {\n\t\tint64 cur = (brute(v, l, 1, 1) * brute(v + l + 1, len - l - 1, 0, 0)) % MOD;\n\t\tans = ans + (cur*good[a[v + l] - '0']) % MOD;\n\t}\n\n\tans %= MOD;\n\treturn ans;\n}\n\nint64 get(int pos, int eq) {\n\tif (pos == n) return 1;\n\t\n\tint64 &ans = d[pos][eq];\n\tif (ans != -1) return ans;\n\n\tans = 0;\n\n\t{\n\t\tforn(i, 10) {\n\t\t\tif (i == 4 || i == 7) continue;\n\t\t\tif (eq == 1 && i + '0' > a[pos]) continue;\n\n\t\t\tint neq = eq;\n\t\t\tif (i + '0' < a[pos]) neq = 0;\n\n\t\t\tans += get(pos + 1, neq);\n\t\t}\n\n\t\tans %= MOD;\n\t}\n\n\tforn(i, 2)\n\t\tif (eq == 0 || Z[i] <= a[pos]) {\n\t\t\tint neq = eq, u = min(n, pos + k + 1);\n\t\t\tif (Z[i] < a[pos]) neq = 0;\n\t\t\t\n\t\t\tforn(eqq, neq + 1)\n\t\t\t\tans += brute(pos + 1, u - pos - 1, neq, eqq) * get(u, eqq);\n\n\t\t\tans %= MOD;\n\t\t}\n\n\tans %= MOD;\n\treturn ans;\n}\n\nint64 get() {\n\tn = (int)strlen(a);\n\tint64 p = 1, cur = 0;\n\tford(i, n) {\n\t\tcur = (cur + p * (a[i] - '0')) % MOD;\n\t\tp = (p * 10) % MOD;\n\t}\n\n\tforn(i, n) {\n\t\tsum[i] = (a[i] == '4' || a[i] == '7') ? 1 : 0;\n\t\tif (i > 0) sum[i] += sum[i - 1];\n\t}\n\n\tmemset(d, 255, sizeof d);\n\tmemset(dd, 255, sizeof dd);\n\treturn (cur - get(0, 1) + 1 + MOD) % MOD;\n}\n\nint64 check() {\n\tn = (int)strlen(a);\n\tint last = INF;\n\tford(i, n)\n\t\tif (a[i] == '4' || a[i] == '7') {\n\t\t\tif (last - i <= k) return 1;\n\t\t\tlast = i;\n\t\t}\n\n\treturn 0;\n}\n\nvoid solve() {\n\tscanf(\"%s\", a);\n\tint64 l = get() - check();\n\tscanf(\"%s\", a);\n\tint64 r = get();\n\tcout << (r - l + MOD) % MOD << endl;\n}\n\nvoid gen() {\n\tk = 1;\n\tint cur = 0;\n\tforn(i, INF) {\n\t\tsprintf(a, \"%d\", i + 1);\n\t\tif (check()) cur++;\n\t\tif (cur != get())\n\t\t\tthrow;\n\n\t\tif (i % 10000 == 0)\n\t\t\tcerr << i << endl;\n\t}\n}\n\nint main(){\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\", \"rt\", stdin);\n\tfreopen(\"output.txt\", \"wt\", stdout);\n#endif\n\n\tfor(int i = 1; i <= 9; i++) {\n\t\tgood[i] = good[i - 1];\n\t\tif (i != 5 && i != 8) good[i]++;\n\t}\n\n\tforn(i, MAXN)\n\t\tp8[i] = (i == 0) ? 1 : ((p8[i - 1] * 8) % MOD);\n\n//\tgen();\n\n\tint tests;\n\tcin >> tests >> k;\n\tforn(test, tests)\n\t\tsolve();\n\n\treturn 0;\n}\n", "src_uid": "5517efa2fc9362fdf342d32adac889f4"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nset a;\nset b;\nint n;\nint v[40];\nint m;\nvoid search(int now,int target,int val)\n{\n\tif(now==target)\n\t{\n\t\tif(target==n)\n\t\t\tb.insert(val);\n\t\telse\n\t\t\ta.insert(val);\n\t\treturn;\n\t}\n\tsearch(now+1,target,val);\n\tsearch(now+1,target,(val+v[now])%m);\n}\nint main()\n{\n\tscanf(\"%d %d\",&n,&m);\n\tfor(int i=0;i::iterator it=a.begin();it!=a.end();it++)\n\t{\n\t\tint val=*it;\n\t\tint target=m-val-1;\n\t\tset::iterator it1=b.upper_bound(target);\n\t\tit1--;\n\t\tans=max(ans,*it1+val);\n\t}\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"} {"source_code": "/*\n* @Author: LyuC\n* @Date: 2017-10-06 21:23:13\n* @Last Modified by: LyuC\n* @Last Modified time: 2017-10-06 23:34:22\n*/\n#include \n\n#define LL unsigned long long \n#define MOD 998244353\n#define N 5005\nusing namespace std;\n\nLL a,b,c;\nLL ab,ac,bc;\nLL mi,ma;\n\n//O(n)的算法\nLL F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘 \nvoid init(){\n inv[1] = 1;\n for(int i = 2; i < N; i ++){\n inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;\n }\n F[0] = Finv[0] = 1;\n for(int i = 1; i < N; i ++){\n F[i] = F[i-1] * 1ll * i % MOD;\n Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD;\n }\n}\nLL Comb(LL n, LL m){//comb(n, m)就是C(n, m) \n if(m < 0 || m > n) return 0;\n return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;\n}\n\nint main(){\n // freopen(\"in.txt\",\"r\",stdin);\n init();\n ab=0;\n ac=0;\n bc=0;\n cin>>a>>b>>c;\n //ab;\n mi=min(a,b);\n ma=max(a,b);\n for(int i=0;i<=mi;i++){\n ab=(ab+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;\n }\n //ac;\n mi=min(a,c);\n ma=max(a,c);\n for(int i=0;i<=mi;i++){\n ac=(ac+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;\n }\n //bc;\n mi=min(b,c);\n ma=max(b,c);\n for(int i=0;i<=mi;i++){\n bc=(bc+Comb(mi,i)%MOD*Comb(ma,i)%MOD*F[i]%MOD)%MOD;\n }\n cout<\nusing namespace std;\n#define ll long long int\n#define mx 100007\n#define pii pair\n#define fs first\n#define sc second\n#define left lff\n#define right rff\nstring f0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\nstring left = \"What are you doing while sending \\\"\",\nmiddle = \"\\\"? Are you busy? Will you send \\\"\",\nright = \"\\\"?\";\n\nlong long f[100005];\n\nchar rec(int n, long long roise)\n{\n while(1){\n if(n==0){\n if(roise <= f0.size()) return f0[roise-1];\n else return 0;\n }\n if(roise <= left.size()) return left[roise-1];\n roise -= left.size();\n if(roise <= f[n-1]) {\n // if(n > 55) n = 55;\n n--;\n continue;\n }\n roise -= f[n-1];\n if(roise <= middle.size()) return middle[roise-1];\n roise -= middle.size();\n if(roise <= f[n-1]){\n // if(n > 55) n = 55;\n n--;\n continue;\n }\n roise -= f[n-1];\n if(roise <= right.size()) return right[roise-1];\n return 0;\n }\n}\n\nint main()\n{\n f[0] = f0.size();\n for(int i = 1; i<100005; i++) {\n f[i] = 2ll * f[i-1] + left.size() + middle.size() + right.size();\n if(i > 54) f[i] = numeric_limits ::max();\n// if(i > 100) break;\n// cout << i << \" \" << f[i] << endl;\n }\n int q;\n scanf(\"%d\", &q);\n while(q--)\n {\n int n;\n long long k;\n scanf(\"%d %lld\", &n, &k);\n char ans = rec(n, k);\n if(ans == 0) printf(\".\");\n else printf(\"%c\", ans);\n }\n return 0;\n}\n", "src_uid": "da09a893a33f2bf8fd00e321e16ab149"} {"source_code": "#include \n#include \n#include \n#include \n\n#define sqr(x) ((x)*(x))\n#define ang(x) ((x) * M_PI / 180)\n\nusing namespace std;\n\nconst long double e = 1e-2;\n\nint k;\nlong double R, r, l;\nlong double x, y, xl, yl, xr, yr;\nlong double a, b, c, S;\n\nlong double COS[12], SIN[12];\n\n\nbool check(long double x, long double y)\n{\n long double s = 0;\n for (int i = 0; i < 12; i += 2)\n s = max(s, sqr(x + COS[i]) + sqr(y + SIN[i]));\n\n return s <= l + r;\n}\n\n\nbool end(long double x, long double y)\n{\n long double s = 1e+60;\n for (int i = 0; i < 12; i += 2)\n s = min(s, sqr(x + COS[i]) + sqr(y + SIN[i]));\n return s > S;\n}\n \nint main()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"in\", \"rt\", stdin);\n freopen(\"out\", \"wt\", stdout);\n #endif\n\n R = 1;\n r = sqrt(sqr(R) - sqr(0.5));\n\n for (int i = 0; i < 12; i++)\n {\n COS[i] = cos(ang(i * 30));\n SIN[i] = sin(ang(i * 30));\n }\n\n// printf(\"%.20lf\\n\", r);\n\n scanf(\"%d\", &k);\n l = k;\n l *= l;\n S = k + 3;\n S *= S;\n\n x = (k + 2) / 3 * 3 * COS[2];\n y = (k + 2) / 3 * 3 * SIN[2];\n\n xl = xr = x;\n yl = yr = y;\n\n long long ans = 0;\n do\n {\n long double s;\n\n s = y * xr - x * yr;\n while (s > 0 && abs(s) > e && !check(xr, yr))\n {\n xr += 2 * r * COS[5];\n yr += 2 * r * SIN[5];\n s = y * xr - x * yr;\n }\n\n while (check(xr, yr))\n {\n xr -= 2 * r * COS[5];\n yr -= 2 * r * SIN[5];\n }\n \n s = y * xl - x * yl;\n while (s < 0 && abs(s) > e && !check(xl, yl))\n {\n xl += 2 * r * COS[11];\n yl += 2 * r * SIN[11];\n s = y * xl - x * yl;\n }\n\n while (check(xl, yl))\n {\n xl -= 2 * r * COS[11];\n yl -= 2 * r * SIN[11];\n }\n/*\n printf(\"%.20lf %.20lf\\n\", xl, yl);\n printf(\"%.20lf %.20lf\\n\", xr, yr);\n printf(\"\\n\");\n fflush(stdout);\n//*/\n\n long double L = sqrt(sqr(xl - xr) + sqr(yl - yr));\n ans += max((long long)((L + r) / (2 * r)) - 1, 0LL);\n \n xl += 2 * r * COS[7];\n yl += 2 * r * SIN[7];\n\n xr += 2 * r * COS[9];\n yr += 2 * r * SIN[9];\n } while (!end(xr, yr) || !end(xl, yl));\n\n cout << ans << endl;\n return 0;\n}\n", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13"} {"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 = 4e18L + 1;\nconst int IINF = 2e9 + 1;\nconst int N = 1048576;\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++;cerr<<'='<> n;\n\tvector a(n), in(n), odw(n);\n\tfor (auto& i: a) {\n\t\tcin >> i;\n\t\ti--;\n\t\tin[i]++;\n\t\tif (in[i] > 1) {\n\t\t\tcout << \"-1\";\n\t\t\treturn 0;\n\t\t}\n\t}\n\tvector dl;\n\trep (i, 0, n) {\n\t\tif (!odw[i]) {\n\t\t\tint l = 0;\n\t\t\tint x = a[i];\n\t\t\twhile (!odw[x]) {\n\t\t\t\tl++;\n\t\t\t\todw[x] = 1;\n\t\t\t\tx = a[x];\n\t\t\t}\n\t\t\tdl.pb(l);\n\t\t}\n\t}\n\tll wyn = dl[0];\n\tif (wyn % 2 == 0) {\n\t\twyn /= 2;\n\t}\n\trep (i, 1, SZ(dl)) {\n\t\tauto x = dl[i];\n\t\tif (x % 2 == 0) {\n\t\t\tx /= 2;\n\t\t}\n\t\twyn = wyn * x / __gcd(wyn, x);\n\t}\n\tcout << wyn;\n\t\t\n}\n", "src_uid": "149221131a978298ac56b58438df46c9"} {"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\nusing namespace std;\n#define sfd(n) scanf(\"%d\", &n)\n#define sfd2(n, m) scanf(\"%d %d\", &n, &m)\n#define sfs(s) scanf(\"%s\", s);\n#define sflld(n) scanf(\"%lld\", &n)\n#define sflf(n) scanf(\"%lf\", &n)\n#define ll long long\n#define maxn 9\nstring line1 = \"WBWBWBWB\", line2 = \"BWBWBWBW\";\nstring str, str2;\nbool check(string line) {\n\tif (str != line) {\n\t\tfor (int j=0; j<8; j++) {\n\t\t\tstr = str2.substr(j, 8);\n\t\t\tif (str == line) {\n\t\t\t\treturn true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\treturn true;\n}\nint main() {\n\t//#ifdef ONLINE_JUDGE\n\t//#else\n\t//\tfreopen(\"D:/in.txt\", \"r\", stdin);\n\t//\tfreopen(\"D:/out.txt\", \"w\", stdout);\n\t//#endif\n\n\tbool ans = true;\n\tfor (int i=0; i<8; i++) {\n\t\tcin >> str;\n\t\tstr2 = str+str;\n\t\tif (i%2==0) {\n\t\t\tif (!check(line1)) ans = false;\n\t\t} else {\n\t\t\tif (!check(line2)) ans = false;\n\t\t}\n \t}\n\tif (ans) cout << \"YES\" << endl;\n\telse cout << \"NO\" << endl;\n\treturn 0;\n}\n\t\t \t\t \t\t \t\t\t \t \t \t \t \t\t\t\t", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"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 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 PQ priority_queue, greater >\n\n\n\n#define eps 1e-8\n\n#define inf 1e100\n\n#define squ(a,b) (a)*(a)+(b)*(b)\n\n#define pi 3.1415926535897932384626433832795\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 (ainline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}\n\ntemplateinline void gn(T &x, T1 &y) {gn(x); gn(y);}\n\ntemplateinline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}\n\ntemplateinline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}\n\ntemplateinline void printsp(T x) {print(x); putchar(' ');}\n\ntemplateinline void println(T x) {print(x); putchar('\\n');}\n\ntemplateinline void print(T x, U y) {printsp(x); println(y);}\n\ntemplateinline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}\n\n\n\nint power(int a, int b, int m, int ans=1) {\n\n\tfor (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;\n\n\treturn ans;\n\n}\n\nconst int C=1000010;\n\n\n\nint sz[44],SZ[44];\n\nint b[C];\n\n\n\nvoid solve_C(){\n\n\tint n,m,e;gn(n,m);\n\n\tfor(int i=0; i>1, can=1;\n\n\t\tfor(int i=0; i<30; i++) sz[i]=SZ[i];\n\n\t\tfor(int i=md-1; i>=0; i--){\n\n\t\t\tif(!can) break;\n\n\t\t\tint flag=0;\n\n\t\t\tfor(int j=b[i]; j<30; j++) if(sz[j]){\n\n\t\t\t\tsz[j]--;\n\n\t\t\t\tfor(int k=j-1; k>=b[i]; k--) sz[k]++;\n\n\t\t\t\tflag=1;\n\n\t\t\t\tbreak;\n\n\t\t\t}\n\n\t\t\tcan=flag;\n\n\t\t}\n\n\t\tif(can) st=md;\n\n\t\telse ed=md;\n\n\t}\n\n\tprintln(st);\n\n\texit(0);\n\n}\n\n\n\nint main(){\n\n#ifndef ONLINE_JUDGE\n\n\tfreopen(\"in.in\",\"r\",stdin);\n\n\tfreopen(\"out.out\",\"w\",stdout);\n\n#endif\n\n\t\n\n\tsolve_C();\n\n\t\n\n\treturn 0;\n\n}\n ", "src_uid": "e95fb7d4309747834b37d4bc3468afb7"} {"source_code": "//test\n#include \n#include \n#define TRUE 1\n#define FALSE 0\n#define max(a, b) a > b ? a : b\n//定义数组大小为4,从一开始,空出下标为0,方便计算\nint x[4]; //三个人的位置\nint l[4]; //三个人的机动性(可移动距离)\nint t[4]; //三个人的抛的距离\nint ans = 0; //经过操作后的最远距离,初始化为0\nint w[4]; //初始化为0,0表示可以进行操作,非零表示不可以\nint p[4]; //初始化为0,表示a[i]所举起的人\nint a[4] = {3, 3, 3, 3}; //初始化为3,表人的状态,这里a对应的二进制为0011,后三位分别是三个动作:抛出,举起,移动。0(无意义)0(不可抛出)1(未进行举起)1(未进行移动)。这道题中,a只有六个可能值:0(0000)、1(0001)、2(0010)、3(0011)、4(0100)、5(0101),表示人的六种状态\n//bool类型\nint near(int s)\n{\n int i = 1;\n for (; i <= 3; i++)\n {\n if (s == x[i] + 1 || s == x[i] - 1)\n {\n return TRUE;\n }\n }\n return FALSE;\n}\n//dfs深度遍历\nvoid dfs(int d)\n{\n int i = 1, j = 1, e = 0;\n //每次都取最远(大)的位置\n for (; i <= 3; i++)\n {\n ans = max(ans, x[i]);\n }\n for (i = 1; i <= 3; i++)\n {\n //是否可以进行操作\n if (w[i])\n {\n continue;\n }\n //a[i] == 1 || a[i] == 3(未进行移动且不可抛出)\n if ((a[i] & 1) && !(a[i] & 4))\n {\n for (j = 1; j <= l[i]; j++) //移动\n {\n x[i] += j; //a[i]向前移动j\n a[i] ^= 1; //已移动\n if (near(x[i]) || j == l[i]) //如果a[i]移动后的位置旁边有人或者移动距离达到上限\n {\n dfs(d + 1);\n }\n x[i] -= j; //归位\n x[i] -= j; //a[i]向后移动j\n if (near(x[i]) || j == l[i]) //如果a[i]移动后的位置旁边有人或者移动距离达到上限\n {\n dfs(d + 1);\n }\n x[i] += j; //归位\n a[i] ^= 1; //还原为未移动\n }\n }\n //a[i] == 2 || a[i] == 3 || a[i] == 5(未进行举起)\n if (a[i] & 2)\n {\n for (j = 1; j <= 3; j++) //举起\n {\n if (i != j && !w[j] && t[i] > 0) //是否可以进行操作\n {\n if (x[i] == x[j] + 1 || x[j] == x[i] + 1) //a[i]附近是否有人\n {\n w[j] = 1; //即将举起(抛出)j,抛出前将j是否可操作标记变更为否\n a[i] ^= 2; //已举起\n a[i] ^= 4; //可抛出\n p[i] = j; //记录a[i]举起(抛出)了j\n e = x[j]; //记录a[j]的举起前位置\n x[j] = -j; //a[j](被举起)的位置定为负数,只作用于下一层递归时的取最远位置的循环\n dfs(d + 1);\n x[j] = e; //归位\n w[j] = 0; //还原为可以进行操作\n a[i] ^= 2; //还原为未举起\n a[i] ^= 4; //还原为不可抛出\n }\n }\n }\n }\n //a[i] == 4 || a[i] == 5(可抛出)\n if (a[i] & 4)\n {\n for (j = 1; j <= t[i]; j++) //抛出\n {\n w[p[i]] = 0; //变更a[j]为可操作(以下a[j]指a[i]所举起的人)\n a[i] ^= 4; //不可抛出\n e = x[p[i]]; //记录a[j]被举起前位置\n x[p[i]] = x[i] + j; //抛出a[j],并更新a[j]位置\n if (near(x[p[i]]) || j == t[i]) //如果a[j]被抛出后的位置旁边有人或者抛出距离达到上限\n {\n dfs(d + 1);\n }\n x[p[i]] -= j; //归位\n x[p[i]] -= j; //a[j]向后抛出j\n if (near(x[p[i]]) || j == t[i]) //如果a[j]被抛出后的位置旁边有人或者抛出距离达到上限\n {\n dfs(d + 1);\n }\n x[p[i]] = e; //还原a[j]为未举起前的位置\n a[i] ^= 4; //还原a[j]为可抛出\n w[p[i]] = 1; //还原a[j]为不可操作\n }\n }\n }\n return ;\n}\n\nint main()\n{\n int i = 1;\n //键入每个人的信息\n for (; i <= 3; i++)\n {\n scanf(\"%d %d %d\", &x[i], &l[i], &t[i]);\n }\n //深度优先遍历\n dfs(1);\n //输出最远距离\n printf(\"%d\\n\", ans);\n return 0;\n}", "src_uid": "a14739b86d1fd62a030226263cdc1afc"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint main()\n{\n int k,p,i,j,l,r,m,f[1000]= {0};\n char s[1000]= {0};\n while(~scanf(\"%s%d\",s,&k))\n {\n memset(f,0,sizeof(f));\n int n=strlen(s);\n l=0;\n r=0;\n for(i=0; ip)\n {\n if(r>0)\n {\n int flag=0;\n for(i=0; i=p-k)\n printf(\"%c\",s[i]);\n }\n }\n else\n printf(\"Impossible\\n\");\n }\n printf(\"\\n\");\n }\n return 0;\n}\n", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n long long m=0,n=0,p=0;\n string s;cin>>s;m=count(s.begin(),s.end(),'a');n=s.length();p=n-m;\n if(p==m){cout<m){cout<\nusing namespace std;\n#define ff first\n#define ss second\n\nint dp[101][101][11][11];\n\nint solve(int t,int x,int y,int k1,int k2,int c1,int c2)\n{\n if((x==0 && y>k2) || y==0 && x>k1)\n return 0;\n if((x==0 && y<=k2) || y==0 && x<=k1)\n {\n /*for(int i=0;ik1)\n return dp[x][y][c1][c2]=solve(1,x,y-1,k1,k2,0,c2+1)%100000000;\n else\n return dp[x][y][c1][c2]=solve(0,x-1,y,k1,k2,c1+1,0)%100000000;\n}\n\n\nint main()\n{\n\n int n1,n2,k1,k2;\n cin>>n1>>n2>>k1>>k2;\n memset(dp,-1,sizeof(dp));\n int ans=solve(0,n1-1,n2,k1,k2,1,0)+solve(1,n1,n2-1,k1,k2,0,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 int maxn = 2005;\n\nint n;\nvector a[maxn];\nint dp[2010][2010][2];\n\nint main() {\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n\n\tscanf(\"%d\", &n);\n\t\n\tfor (int i = 0; i < n; ++i) {\n\t\tlong long k, st, x, y, m;\n\t\tscanf(\"%I64d%I64d%I64d%I64d%I64d\", &k, &st, &x, &y, &m);\n\t\ta[i].resize(k);\n\t\ta[i][0] = st;\n\t\tfor (int j = 1; j < k; ++j) {\n\t\t\ta[i][j] = ((long long)a[i][j - 1] * x + y) % m;\n\t\t}\n\t}\n\n\tint result = 0;\n\tvector > ans;\n\n\tint p1 = 0, p2 = 0;\n\tint prev = -1;\n\twhile (!(p1 == a[0].size() && p2 == a[1].size())) {\n\t\tif (p1 == a[0].size()) {\n\t\t\tans.push_back(make_pair(a[1][p2], 2));\n\t\t\tprev = a[1][p2];\n\t\t\t++p2;\n\t\t} else\n\t\tif (p2 == a[1].size()) {\n\t\t\tans.push_back(make_pair(a[0][p1], 1));\n\t\t\tprev = a[0][p1];\n\t\t\t++p1;\n\t\t} else {\n\t\t\tif (a[0][p1] < a[1][p2]) {\n\t\t\t\tif (prev <= a[0][p1]) {\n\t\t\t\t\tans.push_back(make_pair(a[0][p1], 1));\n\t\t\t\t\tprev = a[0][p1];\n\t\t\t\t\t++p1;\n\t\t\t\t} else \n\t\t\t\tif (prev <= a[1][p2]){\n\t\t\t\t\tans.push_back(make_pair(a[1][p2], 2));\n\t\t\t\t\tprev = a[1][p2];\n\t\t\t\t\t++p2;\n\t\t\t\t} else {\n\t\t\t\t\tans.push_back(make_pair(a[0][p1], 1));\n\t\t\t\t\tprev = a[0][p1];\n\t\t\t\t\t++p1;\n\t\t\t\t}\n\t\t\t} else \n\t\t\tif (a[1][p2] < a[0][p1]) {\n\t\t\t\tif (prev <= a[1][p2]) {\n\t\t\t\t\tans.push_back(make_pair(a[1][p2], 2));\n\t\t\t\t\tprev = a[1][p2];\n\t\t\t\t\t++p2;\n\t\t\t\t} else \n\t\t\t\tif (prev <= a[0][p1]) {\n\t\t\t\t\tans.push_back(make_pair(a[0][p1], 1));\n\t\t\t\t\tprev = a[0][p1];\n\t\t\t\t\t++p1;\n\t\t\t\t} else {\n\t\t\t\t\tans.push_back(make_pair(a[1][p2], 2));\n\t\t\t\t\tprev = a[1][p2];\n\t\t\t\t\t++p2;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tans.push_back(make_pair(a[0][p1], 1));\n\t\t\t\tans.push_back(make_pair(a[1][p2], 2));\n\t\t\t\t++p1;\n\t\t\t\t++p2;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (int i = 1; i < ans.size(); ++i) {\n\t\tif (ans[i].first < ans[i - 1].first) {\n\t\t\t++result;\n\t\t}\n\t}\n\n\tprintf(\"%d\\n\", result);\n\tfor (int i = 0; i < ans.size(); ++i) {\n\t\tprintf(\"%d %d\\n\", ans[i].first, ans[i].second);\n\t}\n\n\treturn 0;\n}\n", "src_uid": "15ba633cb33854bd4c0ee40847bb173c"} {"source_code": "#include\nint n;\nint a[120];\nint main(){\n\tscanf(\"%d\",&n);\n\tfor(int i=1;i<=n;++i){\n\t\tscanf(\"%d\",&a[i]);\n\t}\n\tif(!(a[1]&1)){\n\t\tputs(\"No\");\n\t\treturn 0;\n\t}\n\tint len=0,gs=0;\n\tfor(int i=1;i<=n;++i){\n\t\tlen++;\n\t\tif((len&1)&&(a[i]&1)&&((a[i+1]&1)||(i==n))){\n\t\t\tlen=0,gs++;\n\t\t}\n\t}\n\tif(n&1){\n\t\tif((a[1]&1)&&(a[n]&1)){\n\t\t\tputs(\"Yes\");\n\t\t}\n\t\telse{\n\t\t\tputs(\"No\");\n\t\t}\n\t}\n\telse{\n\t\tputs(\"No\");\n\t}\n\treturn 0;\n} ", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"source_code": "#include \nusing namespace std;\nint b, m;\nlong long solve(long long ansy) {\n\tlong long ansx = (b - ansy) * m;\n\tif(ansx < 0)\n\t\treturn -1;\n\tlong long ret = 0;\n\tlong long A = ansy * (ansy + 1) / 2;\n\tlong long B = ansx * (ansx + 1) / 2;\n\tret = A * (ansx+1) + B * (ansy+1);\n\t//cout << ret << endl;\n\treturn ret;\n}\nint main() {\n\n\tscanf(\"%d%d\", &m, &b);\n\tlong long ans = 0;\n\tfor(long long i = 0; ;i++){\n\t\tlong long ret = solve(i);\n\t\tif(ret == -1)\n\t\t\tbreak;\n\t\tans = max(ret,ans);\n\n\t}\n\n\tcout << ans << endl;;\n\treturn 0;\n}\n", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"} {"source_code": "#include \n\n#define MAX 1000010\n#define MOD 1000000007\n\nusing namespace std;\n\nnamespace lgr{\n short factor[MAX];\n int S[MAX], ar[MAX], inv[MAX];\n\n inline int expo(int a, int b){\n int res = 1;\n\n while (b){\n if (b & 1) res = (long long)res * a % MOD;\n a = (long long)a * a % MOD;\n b >>= 1;\n }\n return res;\n }\n\n int lagrange(long long n, int k){\n if (!k) return (n % MOD);\n\n int i, j, x, y, res = 0;\n if (!inv[0]){\n inv[MAX - 1] = expo(5139854, MOD - 2);\n for (i = MAX - 2; i >= 0; i--) inv[i] = ((long long)inv[i + 1] * (i + 1)) % MOD;\n\n for (i = 0; i < MAX; i++) factor[i] = 0;\n for (i = 4; i < MAX; i += 2) factor[i] = 2;\n for (i = 3; (i * i) < MAX; i += 2){\n if (!factor[i]){\n for (j = (i * i), x = i << 1; j < MAX; j += x){\n factor[j] = i;\n }\n }\n }\n }\n\n k++;\n for (ar[1] = 1, ar[0] = 0, i = 2; i <= k; i++){\n if (!factor[i]) ar[i] = expo(i, k - 1);\n else ar[i] = ((long long)ar[factor[i]] * ar[i / factor[i]]) % MOD;\n }\n\n\n for (i = 1; i <= k; i++){\n ar[i] += ar[i - 1];\n if (ar[i] >= MOD) ar[i] -= MOD;\n }\n if (n <= k) return ar[n];\n\n for (S[k] = 1, i = k - 1; i >= 0; i--) S[i] = ((long long)S[i + 1] * ((n - i - 1) % MOD)) % MOD;\n for (i = 0, y = 1; i <= k; i++){\n x = (long long)ar[i] * y % MOD * S[i] % MOD * inv[k - i] % MOD * inv[i] % MOD;\n if ((k - i) & 1){\n res -= x;\n if (res < 0) res += MOD;\n }\n else{\n res += x;\n if (res >= MOD) res -= MOD;\n }\n y = ((long long)y * ((n - i) % MOD)) % MOD;\n }\n\n return (res % MOD);\n }\n}\n\nint main(){\n int k;\n long long n;\n while (scanf(\"%lld %d\", &n, &k) != EOF){\n printf(\"%d\\n\", lgr::lagrange(n, k));\n }\n return 0;\n}\n", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c"} {"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;\nlong long dp[120][4][4],n,mod=1000000007;\nstring str;\nlong long dp_func(int pos,int choto,int boro)\n{\n if(pos==n){\n if(choto==0||boro==0)return 0;\n return 1;\n }\n if(dp[pos][boro][choto]!=-1)return dp[pos][boro][choto];\n int p=str[pos]-48;\n long long ret=0;\n if(choto==0){\n if(boro==1){\n ret+=dp_func(pos+1,0,1)*2;\n ret+=dp_func(pos+1,1,1);\n return dp[pos][choto][boro]=ret%mod;\n }\n int l=p^0;\n int k=p^1;\n // if(pos)\n ret+=dp_func(pos+1,0,0)*2;\n if(k>str;\n n=str.size();\n memset(dp,-1,sizeof dp);\n long long ans=dp_func(0,0,0);\n cout<\n#define rep(i,s,t) for(int i = s;i <= t;i ++)\n#define dow(i,t,s) for(int i = t;i >= s;i --)\n#define REP(i,x) for(int i = 0;i < x.size();i ++)\n#define DOW(i,x) for(int i = (int)s.size();i >= 0;i --)\n\n#define fi first\n#define se second\n\n#define pb push_back\n#define mp make_pair\n#define lb lower_bound\n#define ub upper_bound\n\n\n#define eps 1e-6\n#define N 100010\n#define INF\n\n#define SZ(x) ((int)(x).size())\n\n\nusing namespace std;\n\ntypedef vector VI;\ntypedef long long LL;\ntypedef double db;\ntypedef pair PII;\n\nint fac[N] , inv[N] , num[N] , mod , A[N];\n\nLL a[50] , m[50];\nint n , l , r , tot , p , P , mul;\n\nint qpow(int a , int b)\n{\n\tint ret = 1;\n\twhile(b)\n\t{\n\t\tif(b & 1)ret = 1ll * ret * a % mod;\n\t\ta = 1ll * a * a % mod;\n\t\tb >>= 1;\n\t}\n\treturn ret;\n}\n\n\n\nLL exgcd(LL a, LL b, LL &x, LL &y)\n{\n LL d = a;\n if(b)\n {\n d = exgcd(b, a % b, y, x);\n y -= (a / b) * x;\n }\n else x = 1 , y = 0;\n return d;\n}\nLL CRT(LL *a , LL *m , int k)\n{\n LL M = 1;\n LL ans = 0;\n rep(i,1,k)M *= m[i];\n rep(i,1,k)\n {\n LL x , y , Mi = M / m[i];\n exgcd(Mi , m[i] , x , y);\n ans = (ans + Mi * x * a[i]) % M;\n }\n if(ans < 0)ans += M;\n return ans;\n}\nint C(int n , int m)\n{\n if(m < 0 || m > n)return 0;\n\tint res = num[n] - num[m] - num[n - m];\n\treturn 1ll * fac[n] * inv[n - m] % mod * inv[m] % mod * qpow(p , res) % mod;\n}\nint calc() // 0\n{\n fac[0] = 1;\n rep(i,1,n)A[i] = i;\n rep(i,1,n)\n {\n \tnum[i] = num[i - 1];\n \twhile(A[i] % p == 0)\n \t{\n \t\tnum[i] ++;\n \t\tA[i] /= p;\n \t}\n \tfac[i] = 1ll * fac[i - 1] * A[i] % mod;\n }\n inv[n] = qpow(fac[n] , (mod > p) ? mod - mod / p - 1 : p - 2);\n dow(i,n - 1,0)inv[i] = 1ll * inv[i + 1] * A[i + 1] % mod;\n\n int ret = 0;\n rep(i,0,n)\n {\n ret += 1ll * C(n , i) * (C(n - i , (l + n - i + 1) / 2) - C(n - i , (r + n - i) / 2 + 1)) % mod;\n if(ret >= mod)ret -= mod;\n if(ret < 0)ret += mod;\n }\n return ret;\n}\nint main()\n{\n //freopen(\"in.in\",\"r\",stdin);\n //freopen(\"out.out\",\"w\",stdout);\n scanf(\"%d%d%d%d\",&n,&P,&l,&r);\n if(p == 1)return printf(\"0\") , 0;\n for(int i = 2;i * i <= P;i ++)\n {\n if(P % i == 0)\n {\n \tmul = 1;\n \ttot ++;\n\n \twhile(P % i == 0)\n \t{\n \t\tP /= i;\n \t\tmul *= i;\n \t}\n m[tot] = mul;\n mod = mul , p = i;\n\n \ta[tot] = calc();\n }\n }\n if(P != 1)\n {\n tot ++;\n m[tot] = P;\n mod = P , p = P;\n a[tot] = calc();\n }\n int ans = CRT(a , m , tot);\n cout << ans << endl;\n}\n", "src_uid": "6ddc487029785738679007443fc08463"} {"source_code": "#include \n\nusing namespace std;\ntypedef long long ll;\nconst ll maxn=1e11;\nconst ll maxp=sqrt(maxn)+10;\nll f[maxp],g[maxp];\n\nll solve(ll n)\n{\n ll i,j,m;\n for (m=1;m*m<=n;m++) f[m]=n/m-1;\n for (i=1;i<=m;i++) g[i]=i-1;\n for (i=2;i<=m;i++)\n {\n if (g[i]==g[i-1]) continue;\n for (j=1;j<=min(m-1,n/i/i);j++)\n if (i*j=i*i;j--) g[j]-=g[j/i]-g[i-1];\n }\n ll res=0;\n for (i=2;i\nusing namespace std;\n#define LL long long\nint mp[105][105];\nint n, m, x, y;\nLL c, k;\nLL res1, res2, res3;\nint main()\n{\n scanf(\"%d%d%I64d%d%d\", &n, &m, &k, &x, &y);\n if (n == 1)\n {\n LL a = k/m;\n k %= m;\n if (k == 0) res1 = res2 = res3 = a;\n else\n {\n res1 = a+1;\n res2 = a;\n res3 = a;\n if (y <= k) res3++;\n }\n }\n else\n {\n memset(mp, 0, sizeof(mp));\n c = k / ((2*n-2) * m);\n k %= (2*n-2)*m;\n int r = 1;\n while (k > 0)\n {\n if (r == 1)\n {\n for (r; r < n && k; r++)\n {\n for (int j = 1; j <= m && k; j++)\n {\n ++mp[r][j];\n k--;\n }\n }\n }\n else if (r == n)\n {\n for (r; r > 1 && k; r--)\n {\n for (int j = 1; j <= m && k; j++)\n {\n ++mp[r][j];\n k--;\n }\n }\n }\n // cout << r << \" \" << k << endl;\n }\n res1 = 0, res2 = mp[1][1] + c;\n for (int i = 1; i <= n; i++)\n for (int j = 1; j <= m; j++)\n {\n if (i == 1 || i == n)\n res1 = max(res1, mp[i][j] + c), res2 = min(res2, mp[i][j] + c);\n else\n res1 = max(res1, mp[i][j] + 2*c), res2 = min(res2, mp[i][j] + 2*c);\n }\n if (x == 1 || x == n)\n res3 = c + mp[x][y];\n else\n res3 = 2*c + mp[x][y];\n }\n printf(\"%I64d %I64d %I64d\\n\", res1, res2, res3);\n}\n", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21"} {"source_code": " #include \n \n using namespace std;\n \n #define pb push_back\n #define mp make_pair\n #define forn(i, n) for (int i = 0; i < (int)(n); ++i)\n typedef long long LL;\n typedef pair PII;\n \n const int DEBUG = 0;\n mt19937 mt(123);\n \n unordered_map, int > ma[19];\n LL table[400000][10];\n int tcnt = 0;\n \n inline bitset<87> tra(bitset<87> b, int dig) {\n bitset<87> res = (b << dig) | (b >> dig);\n forn(i, dig) if (b.test(i)) {\n res.set(dig - i);\n }\n return res;\n }\n \n int n;\n LL from, to;\n int k;\n vector ans;\n \n int solve(bitset<87> b, int rem) {\n auto it = ma[rem].find(b);\n if (it != ma[rem].end()) {\n return it->second;\n }\n int ind = tcnt++;\n if (rem == 0) {\n int cur = 0;\n forn(i, 10) {\n cur |= b.test(i);\n table[ind][i] = cur;\n }\n } else {\n forn(i, 10) {\n int cur = solve(tra(b, i), rem - 1);\n forn(j, 10) {\n table[ind][j] += table[cur][j];\n }\n }\n }\n return ma[rem][b] = ind;\n }\n \n LL solve(LL bound, int k) {\n if (bound == 0) {\n return 1;\n }\n vector dig;\n while (bound > 0) {\n dig.pb(bound % 10);\n bound /= 10;\n }\n reverse(dig.begin(), dig.end());\n int sz = dig.size();\n bitset<87> b;\n b.reset();\n b.set(0);\n LL ans = 0;\n forn(i, sz) {\n forn(j, dig[i] + (i == sz - 1)) {\n ans += table[solve(tra(b, j), sz - 1 - i)][k];\n }\n b = tra(b, dig[i]);\n }\n return ans;\n }\n \n LL gen(LL bound) {\n int times = mt() % 60 + 1;\n LL res = bound;\n forn(i, times) {\n res = mt() % bound + 1;\n }\n return res;\n }\n \n int main() {\n if (DEBUG) {\n n = 50000;\n } else {\n scanf(\"%d\", &n);\n }\n forn(i, n) {\n if (DEBUG) {\n from = gen(LL(1e18));\n to = gen(LL(1e18));\n if (from > to) {\n swap(from, to);\n }\n k = mt() % 10;\n } else {\n scanf(\"%I64d%I64d%d\", &from, &to, &k);\n }\n ans.pb(solve(to, k) - solve(from - 1, k));\n }\n for (LL x : ans) printf(\"%I64d\\n\", x);\n return 0;\n }", "src_uid": "db0e3ef630cb381724697a1ac5152611"} {"source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n\tchar * q=\"qwertyuiopasdfghjkl;zxcvbnm,./\";\n\tchar ch,s[105],*p;\n\tint i;\n\tcin>>ch>>s;\n\tif(ch=='R')\n\t\tfor(i=0;i\n#include\nusing namespace std;\nlong long pw(long long b, long long p){ if (!p) return 1; long long sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }\n\nint main()\n{\n/*\n int x,ans ;\n string s,c;\n cin>>x>>c>>s;\n\n if(s==\"week\")\n {\n if(x==6 || x==5) ans =53;\n else ans = 52;\n }\n if(s==\"month\")\n {\n if(x==30) ans = 11;\n else if(x==31) ans= 7;\n else ans = 12;\n }\n\n cout<>l>>r;\n x=a= l,y=b=r;\n mapmp;\n\n string s=\"\",q=\"\",p=\"\";\n while (r) {if(r%2==0) s+='0'; else s+='1'; r/=2;}\n while(l) {if(l%2==0) q+='0'; else q+='1'; l/=2; p+='1';}\n long long ans = 0;\n reverse(s.begin() , s.end());\n reverse(q.begin() , q.end());\n int u = 0;\n while(x<=y)\n {\n string m =p;\n long long z = 0;\n for(int j = p.size()-1,k=0 ; j>=0 ; j--,k++)\n z+= (p[j]-'0') * pw(2 , k);\n mp[z]++;\n for(int i = 0 ; i=0 ; j--,k++)\n z+= (m[j]-'0') * pw(2 , k);\n if(z<=b && z>=a && mp[z]==0) {ans++;}\n mp[z]++;\n m=p;\n }\n p+='1';\n if(u%2==0) q='0'+q;\n else q[0]='1';\n x=0;\n for(int j = q.size()-1 , k=0 ; j>=0 ; j--,k++) x+=(q[j]-'0') * pw(2 , k);\n u++;\n }\n\n cout<\n#define ll long long int\n#define lld long double\n#define pb push_back\n#define pii pair\n#define mi map\n#define vec vector\n#define all(a) (a).begin(),(a).end()\n#define F first\n#define S second\n#define mod 1000000007\n#define rep(i,a,b)\tfor(ll i=a;i=b;i--)\n#define mp make_pair\n#define mit map::iterator\n#define sit set::iterator\n#define xy exit(0);\n#define pit pair::iterator\n#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)\nusing namespace std;\nll xo(ll x, ll y) \n{ \n return (x | y) & (~x | ~y); \n} \nll bin_Expo(ll x,ll n)\n{\n\t\tif(x==0)\n\t\treturn 0;\n if(n==0)\n return 1;\n else if(n%2 == 0) //n is even\n return bin_Expo(x*x,n/2);\n else //n is odd\n return x*bin_Expo(x*x,(n-1)/2);\n}\nll mod_Expo(ll x,ll n,ll M)\n{\n\t\tif(x==0)\n\t\treturn 0;\n if(n==0)\n return 1;\n else if(n%2 == 0) //n is even\n return mod_Expo((x*x)%M,n/2,M);\n else //n is odd\n return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;\n \n}\nll NcR(int n, int r) \n{ \n ll p = 1, k = 1; \n if (n - r < r) \n r = n - r; \n \n if (r != 0) { \n while (r) { \n p *= n; \n k *= r; \n ll m=__gcd(p, k); \n p /= m; \n k /= m; \n n--; \n r--; \n } \n } \n else\n p = 1; \n return p;\n}\nbool prime_check(ll x)\n{\n bool prime = (x >= 2);\n for (ll i = 2; i * i <= x; i++) \n {\n if (x % i == 0) \n {\n prime = false;\n break;\n }\n }\n return prime;\n}\nll logg(ll base,ll x)\n{\n return (ll)(log(x)/log(base));\n}\nstring a[40],b[40]; ll n,q;\nll dfs(char x,char p,ll d)\n{\n\tif(d==n)\n\treturn 1;\n\tll ans=0;\n\trep(i,0,q)\n\t{\n\t\tif(b[i][0]==x)\n\t\tans+=dfs(a[i][0],b[i][0],d+1);\n\t}\n\treturn ans;\n}\nint main()\n{\n\tios_base::sync_with_stdio(false);\n\tcin.tie(0);\n\tcout.tie(0);\n\tint TESTS=1;\n//\tcin>>TESTS;\n while(TESTS--)\n {\n \tll i,j,x,h,l,k,m;\n \tcin>>n>>q;\n \trep(i,0,q)\n \tcin>>a[i]>>b[i];\n \tcout<\n#include \nusing namespace std;\nint main()\n{\n string str;\n cin >> str;\n string hh = str.substr(0, 2);\n int h = stoi(hh);\n if(h == 5)\n {\n int x = stoi(str.substr(3, 2));\n if(x >= 50)\n {\n cout << \"10:01\" << endl;\n return 0;\n }\n }\n if(h >= 6 && h <= 9)\n {\n cout << \"10:01\" << endl;\n return 0;\n }\n if(h == 15)\n {\n int x = stoi(str.substr(3, 2));\n if(x >= 51)\n {\n cout << \"20:02\" << endl;\n return 0;\n }\n }\n if(h >= 16 && h <= 19)\n {\n cout << \"20:02\" << endl;\n return 0;\n }\n string hhReverse = hh;\n reverse(hhReverse.begin(), hhReverse.end());\n int hReverse = stoi(hhReverse);\n int m = stoi(str.substr(3, 2));\n if(hReverse > m)\n {\n cout << hh << \":\" << hhReverse << endl;\n }\n else\n {\n if(h == 23)\n h = 0;\n else\n h++;\n if(h < 10)\n {\n hh = \"0\" + to_string(h);\n }\n else\n hh = to_string(h);\n hhReverse = hh;\n reverse(hhReverse.begin(), hhReverse.end());\n cout << hh << \":\" << hhReverse << endl;\n }\n return 0;\n}", "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"source_code": "#include \n#include \nusing namespace std;\ntypedef long long ll;\n\nint main() {\n ll n;\n cin>>n;\n n*=2;\n set lol;\n for(ll i=1; i*i<=n; ++i) {\n lol.insert(i*(i+1));\n }\n for(ll i=1; i*(i+1)<=n; ++i) {\n ll q=n-i*(i+1);\n if(lol.count(q)) {\n cout<<\"YES\\n\";\n return 0;\n }\n }\n cout<<\"NO\\n\";\n\nreturn 0;\n\n}\n", "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n char s[8][9]={\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"};\n bool flag[8];\n int len[8]={8,7,7,6,7,7,7,7};\n int l[8];\n int n;\n char c;\n while(scanf(\"%d\",&n)!=EOF)\n {\n memset(flag,0,sizeof(flag));\n memset(l,0,sizeof(l));\n for(int i = 0; i < n;i++)\n {\n cin>>c;\n for(int j = 0; j < 8; j++)\n {\n if(flag[j]) continue;\n if(n != len[j]){\n flag[j] = 1;\n continue;\n }\n if(c == '.') continue;\n if(c != s[j][i]) flag[j] = 1;\n else l[j]++;\n }\n }\n int ans,maxl=-1;\n for(int i = 0; i < 8;i++)\n {\n if(!flag[i]){\n //cout< maxl){\n maxl =l[i];\n ans = i;\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#include \n#include \n#include \n\n#define forn(i,n) for(int i=0;i\n#define mp make_pair\n\nusing namespace std;\n\nint main() {\n//\tfreopen(\"input.txt\", \"r\", stdin);\n//\tfreopen(\"output.txt\", \"w\", stdout);\n\tios_base::sync_with_stdio(false);\n\n\tint n;\n\tcin >> n;\n\tvectorv(n);\n\tvectorc(n, -1);\n\tforn(i, n) {\n\t\tcin >> v[i];\n\t}\n\tsort(v.begin(), v.end());\n\tint col = 0;\n\tforn(i, n) {\n\t\tif (c[i] == -1) {\n\t\t\tc[i] = col;\n\t\t\tforn(j, n) {\n\t\t\t\tif (v[j] % v[i] == 0)c[j] = col;\n\t\t\t}\n\t\t\tcol++;\n\t\t}\n\t}\n\tcout << col;\n}", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\ntypedef vector vll;\n\ntypedef vector vi;\nconst int MAX = 100001;\n\nvll cubes;\n\ntypedef pair pill;\ntypedef map mdp;\n\nmdp dp;\n\npill solve(ll m)\n{\n\tif (m < 8)\n\t{\n\t\treturn make_pair((int)m, m);\n\t}\n\n\tmdp::iterator it = dp.find(m);\n\tif (it != dp.end())\n\t{\n\t\treturn it->second;\n\t}\n\n\tvll::iterator largest = upper_bound(cubes.begin(), cubes.end(), m);\n\t--largest;\n\n\n\tpill v1 = solve(*largest - 1);\n\n\tpill v2 = solve(m - *largest);\n\t++v2.first;\n\tv2.second += *largest;\n\n\treturn dp[m] = max(v1, v2);\n\t//cout << \"dp [\" << m << \"] = \" << dp[m].first << \":\" << dp[m].second << endl;\n}\n\nint main(int argc, char* argv[])\n{\n\tll m;\n\tcin >> m;\n\n\tfor (int i = 1; ; ++i)\n\t{\n\t\tll curr = (ll)i * i * i;\n\t\tcubes.push_back(curr);\n\t\tif (curr > m)\n\t\t\tbreak;\n\t}\n\n\tpill res = solve(m);\n\tcout << res.first << \" \" << res.second << endl;\n\n\treturn 0;\n}\n\n", "src_uid": "385cf3c40c96f0879788b766eeb25139"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nconst int P=(int)1e9+9;\nvoid Add(int &x,int y){\n\tx+=y;\n\tif(x>=P)x-=P;\n}\nint dp[2][2][35][35][35];\nint n,h;\n\nint main(){\n\tscanf(\"%d %d\",&n,&h);\n\tint cu=0,nx=1;\n\tdp[cu][0][0][0][0]=1;\n\tfor(int w=1,v;w<=n;w++){\n\t\tmemset(dp[nx],0,sizeof(dp[nx]));\n\t\tfor(int i=0;i<2;i++)\n\t\t\tfor(int j=0;j<=h;j++)\n\t\t\t\tfor(int k=0;k<=h;k++)\n\t\t\t\t\tfor(int l=0;l<=h;l++)\n\t\t\t\t\t\tif((v=dp[cu][i][j][k][l])){\n\t\t\t\t\t\t\tstatic int a[3];\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ta[0]=min(j+1,h);\n\t\t\t\t\t\t\t\ta[1]=min(k+1,h);\n\t\t\t\t\t\t\t\ta[2]=min(l+1,h);\n\t\t\t\t\t\t\t\tAdd(dp[nx][i][a[0]][a[1]][a[2]],v);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(i)a[0]=h;\n\t\t\t\t\t\t\t\telse a[0]=1;\n\t\t\t\t\t\t\t\ta[1]=min(k+1,h);\n\t\t\t\t\t\t\t\ta[2]=min(l+1,h);\n\t\t\t\t\t\t\t\tsort(a,a+3);\n\t\t\t\t\t\t\t\tAdd(dp[nx][j==h][a[0]][a[1]][a[2]],v);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ta[0]=min(j+1,h);\n\t\t\t\t\t\t\t\tif(i)a[1]=h;\n\t\t\t\t\t\t\t\telse a[1]=1;\n\t\t\t\t\t\t\t\ta[2]=min(l+1,h);\n\t\t\t\t\t\t\t\tsort(a,a+3);\n\t\t\t\t\t\t\t\tAdd(dp[nx][k==h][a[0]][a[1]][a[2]],v);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ta[0]=min(j+1,h);\n\t\t\t\t\t\t\t\ta[1]=min(k+1,h);\n\t\t\t\t\t\t\t\tif(i)a[2]=h;\n\t\t\t\t\t\t\t\telse a[2]=1; \n\t\t\t\t\t\t\t\tAdd(dp[nx][l==h][a[0]][a[1]][a[2]],v);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\tcu=!cu,nx=!nx;\n\t}\n\tint ans=0;\n\tfor(int i=0;i<2;i++)\n\t\tfor(int j=0;j<=h;j++)\n\t\t\tfor(int k=0;k<=h;k++)\n\t\t\t\tfor(int l=0;l<=h;l++)\n\t\t\t\t\tif(i==1&&j==h&&k==h&&l==h);\n\t\t\t\t\telse Add(ans,dp[cu][i][j][k][l]);\n\tprintf(\"%d\\n\",ans);\n\treturn 0;\n}\n", "src_uid": "9fe9658db35076c0bddc8b7ddce11013"} {"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 complex P;\n\n#define EPS (1e-10)\n#define EQ(a,b) (abs((a)-(b)) < EPS)\n#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )\n\n\nint main(){\n\n int x,y,sumx,sumy,sum,f=1,cnt,now;\n\n cin>>x>>y;\n \n sumx=x*100;\n sumy=10*y;\n sum=sumx+sumy;\n while(sum>=220){\n\n if(sum>=220){\n\n if(x>=2&&y>=2){\n x-=2;\n y-=2;\n }else if(x>=1&&y>=12){\n x-=1;\n y-=12;\n }else if(y>=22){\n y-=22;\n }\n else {cout<<\"Hanako\";return 0;}\n sum-=220;\n }\n if(sum>=220){\n\n if(y>=22){\n y-=22;\n }else if(y>=12&&x>=1){\n x-=1;\n y-=12;\n }else if(x>=2&&y>=2){\n x-=2;\n y-=2;\n }else {cout<<\"Ciel\";return 0;}\n sum-=220;\n }else {cout<<\"Ciel\";return 0;}\n\n\n \n }\n cout<<\"Hanako\";\n\n return 0;\n}\n", "src_uid": "8ffee18bbc4bb281027f91193002b7f5"} {"source_code": "// __________________\n// | ________________ |\n// || ____ ||\n// || /\\ | ||\n// || /__\\ | ||\n// || / \\ |____ ||\n// ||________________||\n// |__________________|\n// \\###################\\\n// \\###################\\\n// \\ ____ \\\n// \\_______\\___\\_______\\\n// An AC a day keeps the doctor away.\n\n#pragma GCC optimize(\"Ofast\")\n#pragma loop_opt(on)\n#include \n#ifdef local\n#define safe std::cerr<<__PRETTY_FUNCTION__<<\" line \"<<__LINE__<<\" safe\\n\"\n#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)\ntemplate constexpr void qqbx(const char *s, const H &h, T &&...args) {\n for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;\n std::cerr << \" = \" << h << (sizeof...(T) ? \", \" : \"\\n\");\n if constexpr(sizeof...(T)) qqbx(++s, args...); // C++ 17!\n}\n#else\n#include \n#define debug(...) ((void)0)\n#define safe ((void)0)\n#endif // local\n#define all(v) begin(v),end(v)\n#define get_pos(v,x) (lower_bound(begin(v),end(v),x)-begin(v))\n#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))\n#define pb emplace_back\n#define ff first\n#define ss second\n#define mem(v,x) memset(v,x,sizeof v)\n\nusing namespace std;\nusing namespace __gnu_pbds;\ntypedef int64_t ll;\ntypedef long double ld;\ntypedef pair pll;\ntypedef pair pld;\ntemplate using max_heap = std::priority_queue,less >;\ntemplate using min_heap = std::priority_queue,greater >;\ntemplate using rbt = tree,rb_tree_tag,tree_order_statistics_node_update>;\nconstexpr ld PI = acos(-1), eps = 1e-9;\nconstexpr ll N = 65536, INF = 1e18, MOD = 1000000007, K = 256, inf = 1e9;\nconstexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide\nconstexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }\n\narray a[N],b[N];\nint n, m, ok = 1;\nsigned main() {\n ios_base::sync_with_stdio(0), cin.tie(0);\n cin >> n >> m;\n for(int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];\n for(int i = 0; i < m; i++) cin >> b[i][0] >> b[i][1];\n for(int i = 0; i < n; i++) sort(all(a[i]));\n for(int i = 0; i < m; i++) sort(all(b[i]));\n set cand;\n for(int i = 0; i < n; i++) {\n int x = 0, y = 0;\n for(int j = 0; j < m; j++) {\n if(a[i] != b[j]) {\n x |= (a[i][0] == b[j][0] || a[i][0] == b[j][1]);\n y |= (a[i][1] == b[j][0] || a[i][1] == b[j][1]);\n }\n }\n if(x ^ y) cand.insert(x ? a[i][0] : a[i][1]);\n if(x && y) ok = 0;\n }\n if(ok && cand.size() == 1) return cout << *cand.begin() << '\\n', 0;\n debug(ok);\n for(int j = 0; j < m; j++) {\n int x = 0, y = 0;\n for(int i = 0; i < n; i++) {\n if(a[i] != b[j]) {\n x |= (a[i][0] == b[j][0] || a[i][1] == b[j][0]);\n y |= (a[i][0] == b[j][1] || a[i][1] == b[j][1]);\n }\n }\n if(x ^ y) cand.insert(x ? b[j][0] : b[j][1]);\n if(x && y) ok = 0;\n }\n if(ok && cand.size() == 1) return cout << *cand.begin() << '\\n', 0;\n cout << (ok ? 0 : -1) << '\\n';\n}\n", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n\nusing namespace std;\ntypedef int64_t Int;\ntypedef uint64_t UInt;\n\n\nint main(int argc, char **argv) {\n Int n = 0;\n Int m = 0;\n // Read the first line\n string line = \"\";\n if (getline(cin, line)) {\n stringstream ss(line);\n\n ss >> n >> m;\n }\n\n Int buttonsArr[n];\n Int buttonsArrIdx = 0;\n for (Int i = 0; i != n; ++i) {\n buttonsArr[i] = 0;\n }\n // Read the second line\n if (getline(cin, line)) {\n stringstream ss(line);\n\n while (buttonsArrIdx < n) {\n Int curNum = 0;\n\n ss >> curNum;\n\n for (Int i = curNum - 1; i != n; ++i) {\n if (buttonsArr[i] == 0) {\n buttonsArr[i] = curNum;\n }\n }\n\n ++buttonsArrIdx;\n }\n }\n\n for (Int i = 0; i != n; ++i) {\n cout << buttonsArr[i];\n\n if (i < n - 1) {\n cout << \" \";\n }\n }\n\n\n return 0;\n}\n", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nconst int maxn = 9 + 5;\nlong long num[maxn];\nlong long sum, temp, k;\nint n, cnt;\n\nint main()\n{\n num[0] = 9; //一位数的个数9\n for(int i = 1; i <= 9; i ++)\n num[i] = num[i - 1] * 10; //i位数的个数9 90 900 9000....\n for(int i = 1; i <= 9; i ++)\n num[i] *= i + 1; //i位数中数字字符(0~9)的个数\n while(~scanf(\"%d\", & n))\n {\n sum = 0, cnt = 0, k = 10; //sum计算数字字符数 cnt计算n的位数\n while(n != temp) //当n == temp 即 被除数n小于除数k 跳出\n {\n temp = n % k; //temp是余数\n k *= 10; //k不断10倍变大\n cnt ++; //cnt记录\n //printf(\"k:%d\\n\",k);\n }\n for(int i = 0; i < cnt - 1; i ++)\n sum += num[i]; //计算cnt位前的数字字符数\n //printf(\"start:%lld k=%lld\\n\",start,k);\n sum += (n - k/100 + 1) * cnt; //计算cnt位到n的数字字符数\n printf(\"%I64d\\n\", sum);\n }\n return 0;\n}\n/*给一个数字,求从1到这个数字一共有多少个数字(小于10)*/\n", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"source_code": "#include \n\n\nusing namespace std;\n\n inline int _fastcall Nod(unsigned int x, unsigned int y)\n{\n int n = x * y;\n do\n {\n if(x > y) x = x % y;\n else y = y % x;\n } while(x != 0 && y != 0);\n return n / (x + y);\n}\n\nint main()\n{\n unsigned int x, y, a, b, nod;\n cin >> x >> y >> a >> b;\n nod = Nod(x, y);\n if(a % nod)\n a = a + (nod - a % nod); \n if(a > b) cout << 0;\n else\n cout << (b - a) / nod + 1;\n return 0;\n}", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"source_code": "#define _CRT_SECURE_NO_WARNINGS\n//#pragma comment(linker, \"/STACK:100000000\")\n#include \n#include \n#include \n#include \n#include \n#include \n#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 MOD 1000000007\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef pair pii;\n\ninline int max3(int a, int b, int c) { return max(a, max(b, c)); }\ninline int max4(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }\ninline int min3(int a, int b, int c) { return min(a, min(b, c)); }\ninline int min4(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }\n\nconst int INF = 1e9;\nconst ll LINF = 1e18;\nconst double EPS = 1e-12;\nconst double PI = acos(-1.0);\nconst pii piiINF = mp(INF, INF);\n\nconst int maxn = 8;\n\nint n;\nll a[maxn];\n\nmap numb;\n\nint numberOfPrimeNumbers(ll x) {\n\tif (numb.count(x)) return numb[x];\n\tint ans = 0;\n\tll old = x;\n\tfor (ll i = 2; i*i <= x; i++) {\n\t\twhile (x % i == 0) {\n\t\t\tx /= i;\n\t\t\tans++;\n\t\t}\n\t}\n\tif (x > 1 && x != old) ans++;\n\treturn numb[old] = ans;\n}\n\nstruct node {\n\tll remains;\n\tbool isLeaf;\n\tnode(ll remains = -1, bool isLeaf = false) : remains(remains), isLeaf(isLeaf) {}\n\tvoid operator= (const node &a) {\n\t\tremains = a.remains;\n\t\tisLeaf = a.isLeaf;\n\t}\n};\n\nint brute(vector &list, int d) {\n\tif (d == n) {\n\t\tbool flag = true;\n\t\tint k = list.size();\n\t\tfor (int i = 0; i < list.size() && flag; i++) {\n\t\t\tif (list[i].remains > 1) {\n\t\t\t\tint tmp = numberOfPrimeNumbers(list[i].remains);\n\t\t\t\tif (!list[i].isLeaf && !tmp) tmp++;\n\t\t\t\tk += tmp;\n\t\t\t}\n\t\t}\n\t\tif (flag)\n\t\t\treturn k;\n\t\telse\n\t\t\treturn INF;\n\t}\n\tint ans = INF;\n\tif (!d) {\n\t\tlist[0] = node(a[0], true);\n\t\tans = brute(list, d + 1);\n\t\tlist[0] = node(-1, true);\n\t}\n\tfor (int i = 0; i < list.size(); i++) {\n\t\tif (list[i].remains == -1 || list[i].remains % a[d] == 0) {\n\t\t\tnode old = list[i];\n\t\t\tif (list[i].remains != -1)\n\t\t\t\tlist[i].remains /= a[d];\n\t\t\tlist[i].isLeaf = false;\n\t\t\tlist.push_back(node(a[d], true));\n\t\t\tans = min(ans, brute(list, d + 1));\n\t\t\tlist[i] = old;\n\t\t\tlist.pop_back();\n\t\t}\n\t}\n\treturn ans;\n}\n\nint main() {\n\tcin >> n;\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> a[i];\n\n\tsort(a, a + n, greater());\n\n\tvector list;\n\tlist.push_back(node(-1, true));\n\tint ans = brute(list, 0);\n\n\tcout << ans << endl;\n\n\treturn 0;\n}", "src_uid": "52b8b6c68518d5129272b8c56e5b7662"} {"source_code": "#include \n\nusing namespace std;\n\ntypedef long long ll;\ntypedef long double ld;\n\nconst int N=(int) 5e5+7;\nconst int K=730+7;\nint n;\nint q;\nint k;\nvector>> days;\n\nstruct T\n{\n int d;\n int x;\n int y;\n};\n\nT a[N];\nint y;\nint bucket[N];\nint first[K];\nint last[K];\nint t[N];\nint cnt[N];\n\nvoid clr()\n{\n for (int i=1;i<=n;i++)\n t[i]=i,\n cnt[i]=1;\n}\n\nint root(int x)\n{\n if (t[x]==x)\n return x;\n else\n return t[x]=root(t[x]);\n}\n\nvoid unite(int x,int y)\n{\n x=root(x);\n y=root(y);\n if (x!=y)\n {\n t[x]=y;\n cnt[y]+=cnt[x];\n }\n}\n\nint t2[N];\nint cnt2[N];\n\nint root2(int x)\n{\n if (t2[x]==x)\n return x;\n else\n return t2[x]=root2(t2[x]);\n}\n\nvoid unite2(int x,int y)\n{\n x=root(x);\n y=root(y);\n x=root2(x);\n y=root2(y);\n if (x!=y)\n {\n t2[x]=y;\n cnt2[y]+=cnt2[x];\n }\n}\n\nvoid tr(int x)\n{\n x=root(x);\n t2[x]=x;\n cnt2[x]=cnt[x];\n}\n\n\nint main()\n{\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n\n cin>>n>>q>>k;\n days.push_back({});\n for (int i=1;i<=q;i++)\n {\n int tp;\n cin>>tp;\n if (tp==1)\n {\n int x,y;\n cin>>x>>y;\n vector v={x,y};\n days.back().push_back(v);\n }\n if (tp==2)\n {\n int x;\n cin>>x;\n vector v={x};\n days.back().push_back(v);\n }\n if (tp==3)\n {\n days.push_back({});\n }\n }\n int d=0;\n for (auto &vec:days)\n {\n d++;\n for (auto &it:vec)\n if ((int)it.size()==2)\n {\n a[++y]={d,it[0],it[1]};\n }\n }\n int rad=sqrt(y);\n ///rad=1;\n for (int i=1;i<=y;i++)\n bucket[i]=(i-1)/rad+1;\n for (int i=1;i<=y;i++)\n last[bucket[i]]=i;\n for (int i=y;i>=1;i--)\n first[bucket[i]]=i;\n clr();\n int pos=0,l=1,r=0,nowd=0;\n for (auto &vec:days)\n {\n nowd++;\n int linit=l;\n while (l<=y&&a[l].d<=nowd-k)\n {\n l++;\n }\n int aft=last[bucket[l]]+1;\n if (bucket[l]!=bucket[linit])\n {\n clr();\n for (int j=aft;j<=r;j++)\n unite(a[j].x,a[j].y);\n }\n for (auto &it : vec)\n {\n if ((int) it.size()==2)\n {\n r++;\n if (r>=aft)\n unite(a[r].x,a[r].y);\n }\n else\n {\n if (l>r)\n {\n cout<<\"1\\n\";\n continue;\n }\n int x=it[0],to=min(r,aft-1);\n tr(x);\n for (int j=l;j<=to;j++)\n tr(a[j].x),tr(a[j].y);\n for (int j=l;j<=to;j++)\n unite2(a[j].x,a[j].y);\n\n cout<\n\nusing namespace std;\n\nint main()\n{\n int i, n, m, c=0;\n char guest[105], host[105], letters[105];\n\n cin >> guest >> host >> letters;\n\n strcat(guest, host);\n\n n = strlen(guest);\n m = strlen(letters);\n\n sort(guest, guest+n); //only arrays (char) can be sorted\n sort(letters, letters+m);\n\n if (n!=m)\n {cout << \"NO\";\n return 0;}\n else\n {\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\nusing namespace std;\n#define ll long long\n#define pii pair\n#define vpii vector\n#define pb push_back\n#define vi vector\n#define vll vector\n#define vd vector\n#define vvd vector\n#define pdd pair\n#define vpdd vector\n#define vvll vector\n#define pll pair\n#define vpll vector\n#define search(set0, x) (set0.find(x)!=set0.end())\n#define vvi vector>\n#define vb vector\n#define vc vector\n#define vs vector\n#define vvc vector\n#define vvb vector\n#define mp make_pair\n#define F first\n#define S second\n#define pss pair\n#define vpss vector\n#define double long double\n#define vvs vector\n#define mysort(vector) sort(vector.begin(), vector.end())\n#define myreverse(vector) reverse(vector.begin(), vector.end())\n#define printvi(vector) for (int x: vector) cout << x << \" \"; cout << endl;\n#define printvll(arr) for (ll x: arr) cout << x << \" \"; cout << endl;\n#define vvpii vector\n#define vvpll vector\n#define vp3i vector>\n#define treap Node*\n#define printpair(p0) cout << p0.F << \" \" << p0.S << endl;\n#define printvp(arr) for (auto p0: arr) { printpair(p0) };\n#define FOR(x0) for (int i = 0; i < x0; ++i)\n#define ull unsigned long long\n#define vpt vector\n#define vvvi vector\n#define FORN(i0, n0) for (int i0 = 0; i0 < n0; ++i0)\n#define FORN1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)\n//#define endl '\\n'\n//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());\n\nconst int mod0 = 1e9 + 7;\nconst ll mod1 = 998244353;\nconst ll mod2 = 1e9 + 9;\nconst ll mod3 = 2147483647;\n\nconst int sz = 512 * 1024;\nconst ll inf = 2 * 1024 * 1024 * 1023 - 1;\nconst ll INF = inf * inf;\nconst double eps = 1e-7;\n\nvoid init() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n cout.precision(16);\n}\n\nconst int L = 2501;\nconst int N = 53;\n\nll dp1[N][L];\nll dp23[N][N][L];\nll w[N][N][N][4];\n\nint main() {\n init();\n int n, T;\n cin >> n >> T;\n vi cnt(4);\n vi d(4);\n dp1[0][0] = dp23[0][0][0] = 1;\n FORN(i, n) {\n int d0, t0;\n cin >> d0 >> t0;\n t0--;\n if (t0 == 0) {\n for (int c0 = cnt[0]; c0 >= 0; c0--) {\n FORN(j, d[0] + 1) dp1[c0 + 1][j + d0] = (dp1[c0 + 1][j + d0] + dp1[c0][j]) % mod0;\n }\n } else {\n for (int c1 = cnt[1]; c1 >= 0; c1--)\n for (int c2 = cnt[2]; c2 >= 0; c2--)\n FORN(d23, d[1] + d[2] + 1) {\n int i2 = c1 + (t0 == 1), i3 = c2 + (t0 == 2);\n dp23[i2][i3][d23 + d0] = (dp23[i2][i3][d23 + d0] + dp23[c1][c2][d23]) % mod0;\n }\n }\n cnt[t0]++;\n d[t0] += d0;\n }\n w[0][0][0][3] = 1;\n vi c(3);\n for (c[0] = 0; c[0] <= cnt[0]; c[0]++) {\n for (c[1] = 0; c[1] <= cnt[1]; c[1]++) {\n for (c[2] = 0; c[2] <= cnt[2]; c[2]++) {\n FORN(lst, 4) {\n if (w[c[0]][c[1]][c[2]][lst] != 0) {\n FORN(nxt, 3)\n if (nxt != lst && c[nxt] + 1 <= cnt[nxt]) {\n vector cn(c);\n cn[nxt]++;\n w[cn[0]][cn[1]][cn[2]][nxt] =\n (w[cn[0]][cn[1]][cn[2]][nxt] + w[c[0]][c[1]][c[2]][lst]) % mod0;\n }\n }\n }\n }\n }\n }\n vll f(N, 1);\n FORN(i, N - 1) {\n f[i + 1] = 1LL * (f[i]) * (i + 1) % mod0;\n }\n ll ans = 0;\n for (c[0] = 0; c[0] <= cnt[0]; c[0]++)\n FORN(d0, d[0] + 1) {\n if (T - d0 >= 0) {\n for (c[1] = 0; c[1] <= cnt[1]; c[1]++)\n for (c[2] = 0; c[2] <= cnt[2]; c[2]++) {\n ll k = 1LL * (dp1[c[0]][d0] * dp23[c[1]][c[2]][T - d0]) % mod0;\n FORN(i, 3) k = (k * f[c[i]]) % mod0;\n FORN(lst, 3) {\n if (c[lst] > 0) ans = (ans + k * w[c[0]][c[1]][c[2]][lst]) % mod0;\n }\n }\n }\n }\n cout << ans << '\\n';\n}", "src_uid": "ed5f913afe829c65792b54233a256757"} {"source_code": "#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 long double ld;\n\nint main(){\n ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<>n;\n n<<=1;\n int a[n];\n for(int i=0;i>a[i];\n int ans=1e6;\n sort(a,a+n);\n //for (auto x:a)\n \t//\tcout<n-2) break;\n \t\t\t\tint m=k+1;\n \t\t\t\twhile(m==i||m==j) ++m;\n \t\t\t\tif(m>n-1) break;\n \t\t\t\ts+=a[m]-a[k];\n \t\t\t\tk=m;\n \t\t\t}\n \t\t\tans=min(ans,s);\n \t\t\t//cout<<\"i \"<\n\nusing namespace std;\n\nint main()\n{\n\tint n,m,k;\n\tcin>>n>>m>>k;\n\tif(n<=m)\n\t{\n\t if(n<=k)\n\t {\n\t cout<<\"Yes\"<=s;i--)\n#define prvec(v) lop(R15,0,v.size())cout << v[R15] <<\" \"; cout << endl;\n#define prarr(arr,s1,e1) lop(R15,s1,e1)cout << arr[R15] << \" \"; cout << endl;\n \n#define endl '\\n'\n#define ff first\n#define ss second\n#define pii pair\n \n#define pb push_back\n#define vi vector \n#define vpii vector< pii >\n \n#define all(v) v.begin(),v.end()\n#define sZ(re) (int)re.size()\n#define mset(a,f) memset(a,f,sizeof(a))\n#define M 1000000007\n#define Think_Twice_Code_Once ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)\n \n \nbool J27 = 1;\n#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__)\n#define rtn if(!J27)return;\ntemplate \nvoid __f (const char* name, Arg1&& arg1) { rtn cout << name << \" : \" << arg1 << endl; }\ntemplate \nvoid __f (const char* names, Arg1&& arg1, Args&&... args)\n{ rtn \n const char* comma = strchr (names + 1, ',');\n cout.write (names, comma - names) << \" : \" << arg1 << \" | \"; __f (comma + 1, args...);\n}\n \n// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //\n \ninline void INP();\nconst int N = 112;\nconst long long INF = LLONG_MAX;\nconst int inf = INT_MAX;\n \nint n, Q;\n \npii val[N*N];\n \nint dx[] = {1,-1, 1, -1, 2, 2, -2, -2}; // d, u, l, r\nint dy[] = {2, 2, -2, -2, 1,-1, 1, -1};\n \nbool safe(int x,int y)\n{\n if( x < 1 or y < 1 or x > n or y > n ) return 0;\n return 1;\n}\n \nmap moves;\n \npii dp[N*N][3];\npii x = {-1, -1};\npii arr[4];\n \npii get( int id, int piece )\n{ \n // bug(id, piece);\n if( id == n*n ) return {0,0};\n \n pii &mafia = dp[id][piece];\n \n // if( id == n*n ) bug(id, piece, mafia.ff, mafia.ss);;\n if( mafia != x ) return mafia;\n pii curr = val[id], nextt = val[id+1];\n \n pii a1 = {inf, inf}, a2 = a1, a3 = a1, res , a4 = a1;\n \n \n a1 = get(id+1, 0); \n if( curr.ff == nextt.ff || curr.ss == nextt.ss ) a1.ff++;\n else a1.ff += 2;\n \n \n res = get(id+1, 1);\n if( abs(curr.ff - nextt.ff) == abs(curr.ss - nextt.ss) ) a2 = res, a2.ff++; \n else if( (curr.ff + curr.ss)%2 == (nextt.ff + nextt.ss)%2 ) a2 = res, a2.ff += 2;\n else \n {\n lop(i,0,8)\n {\n int nx = nextt.ff + dx[i], ny = nextt.ss + dy[i];\n if( safe(nx, ny) and abs(curr.ff-nx) == abs(curr.ss-ny) and curr.ff != nx and curr.ss != ny)\n {\n res = get(id+1, 2);\n a2 = res;\n a2.ff += 3;\n a2.ss++;\n }\n }\n }\n \n \n int dix = abs(nextt.ff - curr.ff), diy = abs(nextt.ss - curr.ss);\n res = get(id+1, 2);\n if( dix and diy and (dix + diy) == 3 ) a3 = res, a3.ff++;\n else \n { \n bool f = 0;\n vpii vec;\n lop(i,0,8)\n {\n int nx = curr.ff + dx[i], ny = curr.ss + dy[i];\n if( safe(nx, ny)) vec.pb({nx, ny});\n int dix = abs(nextt.ff - nx), diy = abs(nextt.ss- ny);\n \n if( safe(nx, ny) and dix and diy and (dix + diy) == 3 )\n { \n f = 1;\n break;\n }\n }\n if( f )\n { \n res = get(id+1, 2); \n a3 = res;\n a3.ff += 2;\n }\n else\n {\n lop(i,0,vec.size())\n {\n lop(j,0,8)\n {\n int nx = vec[i].ff + dx[j], ny = vec[i].ss + dy[j];\n int dix = abs(nextt.ff - nx), diy = abs(nextt.ss- ny);\n \n if( safe(nx, ny) and dix and diy and (dix + diy) == 3 )\n { \n f = 1;\n break;\n }\n }\n }\n if(f)\n {\n res = get(id+1, 2);\n a3 = res;\n a3.ff += 3;\n }\n\n lop(i,0,8)\n {\n int nx = curr.ff + dx[i], ny = curr.ss + dy[i];\n if( safe(nx, ny) and abs(nx-nextt.ff) == abs(ny-nextt.ss) )\n {\n a4 = get(id+1, 1);\n a4.ff += 3;\n a4.ss++;\n }\n } \n \n } \n\n\n \n \n }\n \n \n \n arr[0] = a1, arr[1] = a2, arr[2] = a3; arr[3] = a4;\n lop(i,0,4)\n {\n if( ( i < 3 and piece != i ) or ( i == 3 and piece != 2 ) )\n {\n arr[i].ss++;\n arr[i].ff++;\n }\n }\n \n res = { inf, inf };\n \n int f = 0;\n lop(i,0,4) \n { \n // if( id == 1 and piece == 2) bug(arr[i].ff, arr[i].ss,res.ff, res.ss);\n res = min(res, arr[i]);\n }\n // if( id == 1 ) bug(res.ff, res.ss);\n \n return mafia = res;\n \n \n}\n \n \n \n \nvoid solve()\n{\n cin >> n;\n lop(i,1,n+1) lop(j,1,n+1)\n { \n int y;\n cin >> y;\n val[ y ].ff = i;\n val[ y ].ss = j;\n } \n \n \n lop(i,0,n*n+2)lop(j,0,4) dp[i][j] = x;\n \n pii ans = {inf, inf};\n \n lop(i,0,3)\n { \n pii res = get(1, i);\n ans = min(ans, res);\n }\n \n cout << ans.ff << \" \" << ans.ss ;\n \n}\n \n \nint32_t main()\n{\n \n J27 = 1;\n Think_Twice_Code_Once;\n INP(); \n int t = 1;\n //cin >> t;\n lop(i,0,8)\n {\n lop(j,0,8)\n {\n int x = dx[i] + dx[j];\n int y = dy[i] + dy[j];\n if( moves.find({x,y}) == moves.end())\n {\n moves[ {x,y} ] = 2;\n } \n }\n }\n lop(i,0,8)\n {\n lop(j,0,8)\n {\n lop(k,0,8)\n {\n int x = dx[i] + dx[j] + dx[k];\n int y = dy[i] + dy[j] + dy[k];\n if( moves.find({x,y}) == moves.end())\n {\n moves[ {x,y} ] = 3;\n }\n }\n }\n }\n while(t--) solve();\n \n \n}\n \n \n \ninline void INP()\n{\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\", stdin);\n freopen(\"output.txt\", \"w\", stdout);\n #endif\n}", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd"} {"source_code": "#include \n#include \n \n \nint main(){\n\tchar str[105];\n\tint flag = 0;\n\tint ctr = 0;\n\tscanf(\"%s\", str);\n\tif(str[0] >= 97 && str[0] <= 122){\n\t\tflag = 1;\n\t}else{\n\t\tctr++;\n\t}\n\tfor(int j = 1; j < strlen(str);j++){\n\tif(str[j] >= 65 && str[j] <= 90){\n\t\tctr++;\n\t\tcontinue;\n\t}if(str[j] >= 97 && str[j] <= 122){\n\t\tflag = 0;\n\t}\n}\n\tif(flag == 1){\n\t\tif(str[0] >= 97 && str[0] <= 122){\n\t\t\t\tstr[0] -= 32;\n\t\t\t}\n\t\tfor(int i = 1; i < strlen(str);i++){\n\t\t if(str[i] >= 65 && str[i] <= 90){\n\t\t\t\tstr[i] += 32;\n\t\t\t}\n\t\t}\n\t}else if(ctr == strlen(str)){\n\t\tfor(int a = 0; a < strlen(str);a++){\n\t\t\tstr[a] += 32;\n\t\t}\n\t}\n\t\n\tprintf(\"%s\", str);\n\treturn 0;\n}\n", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\n#define poi 10\nusing namespace std;\ninline int re()\n{\n\tchar c=getchar();\n\tint x=0,k=1;\n\twhile(c<'0'||c>'9')\n\t{if(c=='-') k=-1;c=getchar();}\n\twhile(c>='0'&&c<='9')\n\t{x=(x<<1)+(x<<3)+c-'0';c=getchar();}\n\treturn x*k;\n}\nvoid wr(int x)\n{\n\tif(x<0) putchar('-'),x=-x;\n\tif(x>9) wr(x/10);\n\tputchar(x%10+'0');\n}\nsigned main()\n{\n\tint n=re();\n\tswitch(n)\n\t{\n\t\tcase 0:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|#.......................|\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 1:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|#.......................|\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 2:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|#.......................|\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 3:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|#.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 4:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 5:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 6:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.#.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 7:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 8:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 9:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.#.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 10:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 11:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 12:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.#.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 13:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 14:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 15:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.#.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 16:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 17:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 18:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.#.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 19:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 20:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 21:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.#.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 22:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 23:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 24:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.#.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 25:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 26:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 27:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.#.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 28:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 29:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 30:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.#.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 31:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 32:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.O.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 33:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.O.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.O.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.#.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t\tcase 34:{\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.O.|D|)\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.O.|.|\\n\");\n\t\t\tprintf(\"|O.......................|\\n\");\n\t\t\tprintf(\"|O.O.O.O.O.O.O.O.O.O.O.|.|)\\n\");\n\t\t\tprintf(\"+------------------------+\\n\");\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn 0;\n}\n/*\n2 3 4 1 5 x 7 6 8\n*/", "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"source_code": "/*\n\n*/\n#include \n#include \n#include \n#include \nusing namespace std;\nconst int N = 1e2+100;\ntypedef long long LL;\nstring s,t=\"CODEFORCES\";\nint main()\n{\n\tcin>>s;\n\tint len=s.length(),flag=0;\n\tif(s==t)flag=1;\n\telse \n\t\tfor(int i=0;i<=10&&s[i];i++){\n\t\t\tstring p=s.substr(0,i);\n\t\t\tif(p==t){\n\t\t\t\tflag=1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tstring q=s.substr(len-10+i>=0?len-10+i:0);\n\t\t\tif(q==t){\n\t\t\t\tflag=1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(p+q==t)flag=1;\n\t\t}\n\tif(flag)printf(\"YES\\n\");\n\telse printf(\"NO\\n\");\n\treturn 0;\n} \n", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nint x, y;\n\nint main()\n{\n cin >> x >> y;\n if (y < 0) {\n y -= abs(x);\n }\n else {\n y += abs(x);\n }\n \n if (x < 0) {\n cout << -1 * abs(y) << \" 0 0 \" << y;\n }\n else {\n cout << \"0 \" << y << ' ' << abs(y) << \" 0\";\n }\n\n\n return 0;\n}", "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"source_code": "#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\nint n,m;\nstruct node\n{\n int x,y;\n}a[14100];\n\nint cmp(const void *a,const void *b)\n{\n struct node *aa,*bb;\n aa=(struct node *)a;\n bb=(struct node *)b;\n return aa->x-bb->x;\n}\nint main()\n{\n while(scanf(\"%d%d\",&n,&m)!=EOF)\n {\n for(int i=0;i=a[i].x)\n {\n m = m-a[i].x;\n b[t++] = a[i].y;\n }\n else\n {\n break;\n }\n }\n sort(b,b+t);\n printf(\"%d\\n\",t);\n for(int i=0;i\nusing namespace std;\nint main()\n{\n\tint n,c,s;\n\tcin >> n;\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tcin >> c;\n\t\ts=s+c;\t\n\t}\t\n\tif(s==0)\n\tcout <<\"EASY\" << endl;\n\telse cout << \"HARD\" ;\n\treturn 0;\n} ", "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n int n, m, a, b;\n\n cin >> n >> m >> a >> b;\n int save = 0;\n int check = n;\n int rubles = 0;\n int flag = 0;\n int flag2 = 0;\n\n if (a == float(b / m))\n {\n cout << n*a;\n return 0;\n }\n else if (a < float(b / m))\n {\n cout << n*a;\n return 0;\n\n }\n\n else if (a > float(b / m))\n {\n\n while (true)\n {\n if (check == 0)\n break;\n if (flag2 == 0)\n {\n\n check -= m;\n rubles += b;\n }\n if (check == 0)\n break;\n else if (check < 0 || (flag == -1 && flag2 == -1))\n {\n if (flag == 0)\n {\n save = rubles;\n check += m;\n rubles -= b;\n check--;\n rubles += a;\n flag = -1;\n flag2 = -1;\n }\n else if (flag == -1)\n {\n rubles += a;\n check--;\n }\n\n }\n\n\n }\n if (save <= rubles && flag == -1)\n cout << save;\n else\n cout << rubles;\n\n\n }\n return 0;\n}", "src_uid": "faa343ad6028c5a069857a38fa19bb24"} {"source_code": "#include \n#define REP(i, n) for(int i=0; i<(int)(n); i++)\n#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)\n#define ALL(x) begin(x),end(x)\n#define PB push_back\nusing namespace std;\ntypedef int64_t LL;\ntypedef vector VI;\ntypedef pair PII;\n\ntemplate inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }\ntemplate inline bool chmin( T &a, const T &b ) { return b using MaxHeap = priority_queue;\ntemplate using MinHeap = priority_queue, greater>;\ntemplate> void sort_uniq( vector &v, F f=F() ) {\n sort(begin(v),end(v),f);\n v.resize(unique(begin(v),end(v))-begin(v));\n}\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n int n;\n cin >> n;\n VI a(n+1);\n REP1(i,1,n) {\n cin >> a[i];\n if ( i>0 ) a[i]+=a[i-1];\n }\n int mi=360; \n for ( int i=0; i<=n; i++ ) {\n for ( int j=0; j\n#include \nusing namespace std;\ntypedef long long int ll;\ntypedef long double db;\n#define pb push_back\n#define mp make_pair\n#define ub(v,val) upper_bound(v.begin(),v.end(),val)\n#define np(str) next_permutation(str.begin(),str.end())\n#define lb(v,val) lower_bound(v.begin(),v.end(),val)\n#define sortv(vec) sort(vec.begin(),vec.end())\n#define rev(p) reverse(p.begin(),p.end());\n#define v vector\n#define PI 3.1415926535\n#define len length()\n#define repc(i,s,e) for(ll i=s;i=0;i--)\n#define rep(i,n) for( i=0;i> n >> m ;\n\tx = n;\n\tv vec;\n\twhile (x > 0) {\n\t\tvec.pb(x % 10);\n\t\tx /= 10;\n\t}\n\tll l = vec.size();\n\tll dp[(ll)pow(2, l)][m];\n\tmset(dp, 0);\n\tdp[0][0] = 1;\n\tfor (i = 0; i < pow(2, l); i++) {\n\t\tfor (j = 0; j < m; j++) {\n\t\t\tfor (k = 0; k < l; k++) {\n\t\t\t\tif ((i & 1 << k) == 0 && (i || vec[k])) {\n\t\t\t\t\tdp[(i | 1 << k)][(10 * j + vec[k]) % m] += dp[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tll cnt[10];\n\tmset(cnt, 0);\n\tll prod = 1;\n\tfor (auto u : vec) {\n\t\tprod *= ++cnt[u];\n\t}\n\tcout << dp[(1 << k) - 1][0] / prod;\n\n\n\treturn 0;\n}", "src_uid": "5eb90c23ffa3794fdddc5670c0373829"} {"source_code": "#include \n#include \nusing namespace std;\n\nint asc[123] = {};\n\nint main(){\n\tint ano;\n\tbool flag;\n\n\tcin >> ano;\n\n\tostringstream stream;\n\t\n\n\tfor(int i = ano+1; i < 10000; i++){\n\t\tflag = true;\n\t\tstream << i;\n\t\tstring s = stream.str();\n\n\t\tfor(int j = 0; j < s.length(); j++){\n\t\t\tasc[s[j]]++;\n\t\t\tif(asc[s[j]] > 1)\n\t\t\t\tflag = false;\n\t\t}\t\n\n\t\tfor(int j = 48; j < 58; j++)\n\t\t\tasc[j] = 0;\n\n\t\tif(flag == true){\n\t\t\tcout << i <\nlong long X[200001],A,B,M=1000000007,h,a,Z;\nmain()\n{\n std::cin>>A>>B;\n X[0]=X[1]=1;for(h=2;h*(h+1)/2<=A+B;h++)for(a=A;a>=h;a--)X[a]=(X[a]+X[a-h])%M;\n for(a=0;a<=A;a++)if(h*(h-1)/2-a<=B)Z=(Z+X[a])%M;std::cout<\nusing namespace std;\n\ntypedef long long ll;\nconst int maxn = 55, mod = 1e9 + 7;\n\nint n, m, inv[maxn], f[maxn][maxn], g[maxn][maxn], t[maxn][maxn];\n\nint main()\n{\n\tscanf(\"%d%d\", &n, &m);\n\tinv[1] = 1;\n\tfor (int i = 2; i <= n + 1; ++i) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;\n\tf[0][1] = 1;\n\tfor (int i = 1; i <= n; ++i)\n\t\tfor (int j = 1; j <= i + 1; ++j) {\n\t\t\tfor (int k = 0; k < i; ++k) {\n\t\t\t\tfor (int l = j; l <= k + 1; ++l)\n\t\t\t\t\tg[i][j] = (g[i][j] + (ll)f[k][l] * f[i - k - 1][j]) % mod;\n\t\t\t\tfor (int l = j + 1; l <= i - k; ++l)\n\t\t\t\t\tg[i][j] = (g[i][j] + (ll)f[k][j] * f[i - k - 1][l]) % mod;\n\t\t\t}\n\t\t\tmemset(t, 0, sizeof(t));\n\t\t\tfor (int p = 0; p + i <= n; ++p)\n\t\t\t\tfor (int q = 1; q + j <= n + 1; ++q)\n\t\t\t\t\tfor (int C = 1, x = 1; p + x * i <= n && q + x * i <= n + 1; ++x) {\n\t\t\t\t\t\tC = (ll)C * (g[i][j] + x - 1) % mod * inv[x] % mod;\n\t\t\t\t\t\tt[p + x * i][q + x * j] = (t[p + x * i][q + x * j] + (ll)C * f[p][q]) % mod;\n\t\t\t\t\t}\n\t\t\tfor (int p = i; p <= n; ++p)\n\t\t\t\tfor (int q = j; q <= p + 1; ++q) {\n\t\t\t\t\tf[p][q] += t[p][q];\n\t\t\t\t\tif (f[p][q] >= mod) f[p][q] -= mod;\n\t\t\t\t}\n\t\t}\n\tprintf(\"%d\\n\", f[n][m]);\n\t\n\treturn 0;\n}\n", "src_uid": "aca6148effff8b893c961b1ee465e4e4"} {"source_code": "#define _CRT_SECURE_NO_WARNINGS\n\n#include \n#include \n\nusing namespace std;\n\nint main()\n{\n\tint n, a[10], minn, maxx;\n\tscanf(\"%d%d\", &n, &a[0]);\n\tminn = maxx = a[0];\n\tfor (int i = 1; i < n; i++)\n\t{\n\t\tscanf(\"%d\", &a[i]);\n\t\tminn = min(minn, a[i]);\n\t\tmaxx = max(maxx, a[i]);\n\t}\n\tprintf(\"%d\", (maxx + minn) / 2);\n\treturn 0;\n}", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"} {"source_code": "#include \n#include\nusing namespace std;\nint main()\n{\n int p,q;\n int c=0;\n int d=0;\n cin>>p>>q;\n int a[p],b[q];\n for(int j=0;j>a[j];\n }\n for(int j=0;j>b[j];\n }\n sort(a,a+p);\n sort(b,b+q);\n for(int i=0;i\n#include \n\nint main()\n{\n\tint n,tn,x,s=1,ts,ans=0,w;\n\tscanf(\"%d\",&n);\n\twhile(s<=512)\n\t{\n\t\tts=s;\n\t\tw=1;tn=0;\n\t\twhile(ts>0)\n\t\t{\n\t\t\ttn+=(ts%2)*w;\n\t\t\tts/=2;\n\t\t\tw*=10;\n\t\t}\n\t\tif(tn<=n) ans++;\n\t\ts++;\n\t}\n\tprintf(\"%d\",ans);\n\treturn 0;\n}\n \t \t \t \t\t \t\t \t\t\t\t\t\t \t", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"source_code": "#include\n#include\n#include\nusing namespace std;\nint a,b,c;\nint main()\n{\n\tcin>>a>>b>>c;\n\tif(((c%b==a%b)&&(c>=a))||(c%b==(a+1)%b)&&c>a+1)\n\tcout<<\"YES\";\n\telse\n\tcout<<\"NO\";\n\treturn 0;\n}", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"source_code": "//lxrtxdy!\n#include\nusing namespace std;\n\nconstexpr int maxn=400000+10;\n\nint lnk[maxn],nxt[maxn],son[maxn],n,m,now,c1,c2,dnt[maxn],mk;\nvector nvis[maxn],rt,rv;\nvector > res;\nbool flag[maxn];\npair cnt[maxn];\n\nbool cmp(const int a,const int b) __attribute__((always_inline));\n\nvoid dfs(int u) {\n\tflag[u]=1;\n\tfor (int v=son[u]; v; v=nxt[v])\n\t\tif (lnk[v]>0) {\n\t\t\tlnk[v^1]*=-1;\n\t\t\tif (!flag[lnk[v]])\n\t\t\t\tdfs(lnk[v]),c2++;\n\t\t\telse lnk[v]=lnk[v^1]=0,nvis[u].push_back(v/2),rt[rt.size()-1]=u,c1++;\n\t\t}\n}\n\nvoid efs(int u) {\n\tdnt[u]=1;\n\tfor (int v=son[u]; v; v=nxt[v])\n\t\tif (lnk[v]>0) {\n\t\t\tefs(lnk[v]);\n\t\t\tdnt[u]+=dnt[lnk[v]];\n\t\t\tif (dnt[lnk[v]]==1) mk=u;\n\t\t}\n}\n\nvoid go(int u) {\n\tfor (int v=son[u]; v; v=nxt[v])\n\t\tif (lnk[v]) {\n\t\t\tif (lnk[v]<0) lnk[v]*=-1;\n\t\t\tlnk[v^1]=0;\n\n\t\t\trv.push_back(lnk[v]);\n\t\t\tgo(lnk[v]);\n\t\t\trv.push_back(u);\n\t\t\tif (nowcnt[b]));\n}\n\nint main() {\n\tscanf(\"%d%d\",&n,&m);\n\tfor (int i=0,j=1,u,v; i0 && dnt[lnk[i]]==1) {\n\t\t\t\t\t\tk=i/2;\n\t\t\t\t\t\trt.push_back(abs(lnk[i]));\n\t\t\t\t\t\tlnk[i]=lnk[i^1]=0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tif (k==-1) break;\n\t\t\trv.resize(3);\n\t\t\trv[0]=k;\n\t\t\trv[1]=1;\n\t\t\trv[2]=rt[now];\n\t\t\tres.push_back(rv);\n\t\t\trv.clear();\n\t\t}\n\t\trv.push_back(rt[now++]);\n\t\tgo(rt[now-1]);\n\t\tif (rv[rv.size()-1]!=1) rv.push_back(1);\n\t\tres.push_back(rv);\n\t}\n\tif (now\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define rep(i,n) for(int i=0; i pii;\ntypedef vector vi;\n\nconst ll MOD = 1000000007;\n\nint main() {\n\tint n;\n\tcin >> n;\n\tll a = 1, b = 1;\n\trep(i,3*n) {\n\t\ta = (a * 3) % MOD;\n\t}\n\trep(i,n) {\n\t\tb = (b * 7) % MOD;\n\t}\n\tll ans = (MOD + a - b) % MOD;\n\tcout << ans << endl;\n\treturn 0;\n}\n", "src_uid": "eae87ec16c284f324d86b7e65fda093c"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\nstruct node {\n\tint last;\n\tint first;\n\tint ans;\n}k[28];\nchar s[1000005];\nint y[1000005];\nint main()\n{\n\tint i, j, n, a = 0, b;\n\tchar c;\n\twhile (scanf(\"%d%d\", &n, &b) != EOF)\n\t{\n\t\ta = 0;\n\t\tscanf(\"%s\", &s);\n\t\tmemset(y, 0, sizeof(y));\n\t\tfor (i = 0; i < 26; i++)\n\t\t\tk[i].first = 199;\n\t\tint d;\n\t\tfor (i = 0; i < n; i++)\n\t\t{\n\t\t\td = s[i] - 'A';\n\t\t\tif (k[d].first == 199)\n\t\t\t{\n\t\t\t\tk[d].first = i;\n\t\t\t\tk[d].last = i;\n\t\t\t\ty[i] = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ty[k[d].last] = 0;\n\t\t\t\ty[i] = 2;\n\t\t\t\tk[d].last = i;\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < 26; i++)\n\t\t{\n\t\t\tif (k[i].first != 199)\n\t\t\t{\n\t\t\t\tif (k[i].first == k[i].last)\n\t\t\t\t\ty[k[i].first] = 3;\n\t\t\t\telse\n\t\t\t\t\ty[k[i].first] = 1;\n\t\t\t}\n\t\t}\n\t\tint flag = 0;\n\t\tfor (i = 0; i < n; i++)\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\tflag = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif((y[i] == 1 || y[i] == 3) && a == b)\n\t\t\t{\n\t\t\t\tflag = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(y[i] == 1)\n\t\t\t\ta++;\n\t\t\telse if (y[i] == 2)\n\t\t\t\ta--;\n\t\n\t\t}\n\t\tif (flag)\n\t\t\tcout << \"YES\" << endl;\n\t\telse\n\t\t\tcout << \"NO\" << endl;\n\t}\n\treturn 0;\n}", "src_uid": "216323563f5b2dd63edc30cb9b4849a5"} {"source_code": "#include \nusing namespace std;\n#define fo(i,n) for(i=0;in;k\n#define pii pair\n#define vi vector\n#define endl \"\\n\"\n#define deb(x) cout << #x << \"=\" << x << endl\nconst ll mod = 1e9+7;\n\nll dx[]={-1,0,1,0};\nll dy[]={0,-1,0,1};\n\nll msum(ll a,ll b,ll m) { return (a%m+b%m)%m; }\nll msub(ll a,ll b,ll m) { return (a%m-b%m)%m; }\nll mpro(ll a,ll b,ll m) { return ((a%m)*(b%m))%m; }\nll m_m(ll a,ll b,ll m);\nll fxp(ll a,ll b,ll m);\nvoid swap(ll &a,ll &b){ ll t=a; a=b; b=t;}\n\nbool isset(ll n,ll i)\n{\n ll mask=(ll)1<>t;\n while(t--)\n {\n ll l,r;\n cin>>l>>r;\n if(l==r)\n {\n cout<<0<=0)\n {\n bool check1,check2;\n check1=isset(l,i);\n check2=isset(r,i);\n // deb(check1);\n // deb(check2);\n if((check1 and check2) || (!check1 and !check2))\n {\n cnt++;\n i--;\n }\n else\n break;\n \n }\n\n ll V=(ll)1<<(i+1);\n V--;\n cout<\nusing namespace std;\n\nint main()\n{\n\tint s, v1, v2, t1, t2;\n\tcin >> s >> v1 >> v2 >> t1 >> t2;\n\tif (s * v1 + 2 * t1 > s * v2 + t2 * 2)\n\t\tcout << \"Second\";\n\telse if (s * v1 + 2 * t1 < s * v2 + t2 * 2)\n\t\tcout << \"First\";\n\telse\n\t\tcout << \"Friendship\";\n\treturn 0;\n}", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "#include \n#include \n#include \nusing namespace std;\nbool a[1009][1009];\nint xa,ya,xb,yb,n,b,mini=1000000000;\nvoid dfs(int x,int y,int b){\n if(x==xb&&y==yb){\n mini=min(b,mini);\n return;\n }\n a[x][y]=true;\n if(x==n&&y==n){\n if(a[x-1][y]==false){\n dfs(x-1,y,b+1);\n }\n if(a[x][y-1]==false){\n dfs(x,y-1,b+1);\n }\n }\n if(x==n&&y==0){\n if(a[x-1][y]==false){\n dfs(x-1,y,b+1);\n }\n if(a[x][y+1]==false){\n dfs(x,y+1,b+1);\n }\n }\n if(x==0&&y==0){\n if(a[x+1][y]==false){\n dfs(x+1,y,b+1);\n }\n if(a[x][y+1]==false){\n dfs(x,y+1,b+1);\n }\n }\n if(x==0&&y==n){\n if(a[x+1][y]==false){\n dfs(x+1,y,b+1);\n }\n if(a[x][y-1]==false){\n dfs(x,y-1,b+1);\n }\n }\n if(y==n&&x!=n&&x!=0){\n if(a[x+1][y]==false){\n dfs(x+1,y,b+1);\n }\n if(a[x-1][y]==false){\n dfs(x-1,y,b+1);\n }\n }\n if(x==n&&y!=n&&y!=0){\n if(a[x][y+1]==false){\n dfs(x,y+1,b+1);\n }\n if(a[x][y-1]==false){\n dfs(x,y-1,b+1);\n }\n }\n if(y==0&&x!=0&&x!=n){\n if(a[x+1][y]==false){\n dfs(x+1,y,b+1);\n }\n if(a[x-1][y]==false){\n dfs(x-1,y,b+1);\n }\n }\n if(x==0&&y!=n&&y!=0){\n if(a[x][y+1]==false){\n dfs(x,y+1,b+1);\n }\n if(a[x][y-1]==false){\n dfs(x,y-1,b+1);\n }\n }\n}\nint main()\n{\n cin>>n>>xa>>ya>>xb>>yb;\n dfs(xa,ya,0);\n printf(\"%d\\n\",mini);\n}\n", "src_uid": "685fe16c217b5b71eafdb4198822250e"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\n\nconst int N = 400010;\n\nstruct Node\n{\n int fa, ch[2], siz, sizi;\n ll siz2i;\n ll siz2() { return (ll) siz * siz; }\n} t[N];\n\nbool nroot(int x);\nvoid rotate(int x);\nvoid Splay(int x);\nvoid access(int x);\nint findroot(int x);\nvoid link(int x);\nvoid cut(int x);\nvoid pushup(int x);\n\nvoid add(int u, int v);\nvoid dfs(int u);\n\nint head[N], nxt[N << 1], to[N << 1], cnt;\nint n, m, c[N], f[N];\nll ans, delta[N];\nbool bw[N];\nvector mod[N][2];\n\nint main()\n{\n int i, j, u, v;\n ll last;\n\n scanf(\"%d%d\", &n, &m);\n\n for (i = 1; i <= n; ++i)\n {\n scanf(\"%d\", c + i);\n mod[c[i]][0].push_back(i);\n mod[c[i]][1].push_back(0);\n }\n\n for (i = 1; i <= n + 1; ++i) t[i].siz = 1;\n\n for (i = 1; i < n; ++i)\n {\n scanf(\"%d%d\", &u, &v);\n add(u, v);\n add(v, u);\n }\n\n for (i = 1; i <= m; ++i)\n {\n scanf(\"%d%d\", &u, &v);\n mod[c[u]][0].push_back(u);\n mod[c[u]][1].push_back(i);\n c[u] = v;\n mod[v][0].push_back(u);\n mod[v][1].push_back(i);\n }\n\n f[1] = n + 1;\n dfs(1);\n\n for (i = 1; i <= n; ++i) link(i);\n\n for (i = 1; i <= n; ++i)\n {\n if (!mod[i][0].size())\n {\n\t delta[0] += (ll)n * n;\n\t continue;\n }\n if (mod[i][1][0])\n {\n\t delta[0] += (ll)n * n;\n\t last = (ll)n * n;\n } else\n\tlast = 0;\n for (j = 0; j < mod[i][0].size(); ++j)\n {\n\t u = mod[i][0][j];\n\t if (bw[u] ^= 1)\n\t cut(u);\n\t else\n\t link(u);\n\t if (j == mod[i][0].size() - 1 || mod[i][1][j + 1] != mod[i][1][j])\n {\n\t delta[mod[i][1][j]] += ans - last;\n\t last = ans;\n }\n }\n for (j = mod[i][0].size() - 1; ~j; --j)\n {\n\t u = mod[i][0][j];\n\t if (bw[u] ^= 1)\n\t cut(u);\n\t else\n\t link(u);\n }\n }\n\n ans = (ll) n * n * n;\n for (i = 0; i <= m; ++i)\n {\n ans -= delta[i];\n printf(\"%I64d \", ans);\n //printf(\"%lld\\n\",ans);\n }\n\n return 0;\n}\n\nbool nroot(int x) { return x == t[t[x].fa].ch[0] || x == t[t[x].fa].ch[1]; }\n\nvoid rotate(int x)\n{\n int y = t[x].fa;\n int z = t[y].fa;\n int k = x == t[y].ch[1];\n if (nroot(y)) t[z].ch[y == t[z].ch[1]] = x;\n t[x].fa = z;\n t[y].ch[k] = t[x].ch[k ^ 1];\n t[t[x].ch[k ^ 1]].fa = y;\n t[x].ch[k ^ 1] = y;\n t[y].fa = x;\n pushup(y);\n pushup(x);\n}\n\nvoid Splay(int x)\n{\n while (nroot(x))\n {\n int y = t[x].fa;\n int z = t[y].fa;\n if (nroot(y)) (x == t[y].ch[1]) ^ (y == t[z].ch[1]) ? rotate(x) : rotate(y);\n rotate(x);\n }\n}\n\nvoid access(int x)\n{\n for (int y = 0; x; x = t[y = x].fa)\n {\n Splay(x);\n t[x].sizi += t[t[x].ch[1]].siz;\n t[x].sizi -= t[y].siz;\n t[x].siz2i += t[t[x].ch[1]].siz2();\n t[x].siz2i -= t[y].siz2();\n t[x].ch[1] = y;\n pushup(x);\n }\n}\n\nint findroot(int x)\n{\n access(x);\n Splay(x);\n while (t[x].ch[0]) x = t[x].ch[0];\n Splay(x);\n return x;\n}\n\nvoid link(int x)\n{\n int y = f[x];\n Splay(x);\n ans -= t[x].siz2i + t[t[x].ch[1]].siz2();\n int z = findroot(y);\n access(x);\n Splay(z);\n ans -= t[t[z].ch[1]].siz2();\n t[x].fa = y;\n Splay(y);\n t[y].sizi += t[x].siz;\n t[y].siz2i += t[x].siz2();\n pushup(y);\n access(x);\n Splay(z);\n ans += t[t[z].ch[1]].siz2();\n}\n\nvoid cut(int x)\n{\n int y = f[x];\n access(x);\n ans += t[x].siz2i;\n int z = findroot(y);\n access(x);\n Splay(z);\n ans -= t[t[z].ch[1]].siz2();\n Splay(x);\n t[x].ch[0] = t[t[x].ch[0]].fa = 0;\n pushup(x);\n Splay(z);\n ans += t[t[z].ch[1]].siz2();\n}\n\nvoid pushup(int x)\n{\n t[x].siz = t[t[x].ch[0]].siz + t[t[x].ch[1]].siz + t[x].sizi + 1;\n}\n\nvoid add(int u, int v)\n{\n nxt[++cnt] = head[u];\n head[u] = cnt;\n to[cnt] = v;\n}\n\nvoid dfs(int u)\n{\n int i, v;\n for (i = head[u]; i; i = nxt[i])\n {\n v = to[i];\n if (v != f[u])\n {\n\t f[v] = u;\n\t dfs(v);\n }\n }\n}\n", "src_uid": "5879aa95ed79dc2c97667dc16ca73a8c"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nint main(){\n int n;\n int m;\n scanf(\"%d%d\",&n,&m);\n int sum = (n*m)/2;\n printf(\"%d\\n\",sum);\n return 0;\n}\n\n ", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"source_code": "/*\n * e.cpp\n *\n * Created on: 2011-9-11\n * Author: mac\n */\n#include \n#include \n#include \n#include \n#include \n#include \n#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)\n#define REP(i,n) for(int i=0;i> H >> M >> K;\n\tint h1, m1, h2, m2;\n\tcin >> h1 >> m1 >> h2 >> m2;\n\tif (make_pair(h1, m1) <= make_pair(h2, m2))\n\t\tcout << calc(h2, m2) - calc(h1, m1) << endl;\n\telse\n\t\tcout << (calc(H - 1, M - 1) + ((calcDigit(H - 1) + calcDigit(M - 1)) >= K) - calc(h1, m1) + calc(h2, m2)) << endl;\n\treturn 0;\n}\n", "src_uid": "e2782743229645ad3a0f8e815d86dc5f"} {"source_code": "#include\nusing namespace std;\nlong long a,b,c,e[200000],mix,l,r,o,d[2000000],ans,ans1;\nvector v[100000],v1;\nset st;\nmap mp,mp1;\nstring s;\npair p[100000],p1[100000];\nchar ch[10];\ndeque dq; \nbool bo,ol;\nint main(){\n cin>>a;\n if(a%4==1){\n cout<<0<<\" \"<<\"A\";\n } else if(a%4==2){\n cout<<1<<\" \"<<\"B\";\n } else if(a%4==3){\n cout<<2<<\" \"<<\"A\";\n } else cout<<1<<\" \"<<\"A\";\n}", "src_uid": "488e809bd0c55531b0b47f577996627e"} {"source_code": "#include \n\nusing namespace std;\n\nint main()\n{\n int k,r,respo;\n scanf(\"%d%d\",&k,&r);\n respo=k;\n while(respo%10!=r & respo%10!=0){\n respo+=k;\n }\n printf(\"%d\\n\",respo/k);\n return 0;\n}\n// 1535219033912\n", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"} {"source_code": "#include \n#include \nusing namespace std;\nlong long int m,n,k;\ninline bool pos(long long int d)\n{\n\tlong long int m1=m;\n\tm1=m1-d;\n\tif(d\n#define LL long long\n#define ULL unsigned long long\n#define rep(i,j,k) for(int i=j;i<=k;i++)\n#define dep(i,j,k) for(int i=k;i>=j;i--)\n#define INF 0x3f3f3f3f\n#define mem(i,j) memset(i,j,sizeof(i))\n#define make(i,j) make_pair(i,j)\n#define pb push_back\n#define Pi acos(-1.0)\nusing namespace std;\nconst int N = 305, mod = 1e9 + 7;\nLL dp[N][N], c[N][N];\nvoid init() {\n c[0][0] = 1LL;\n rep(i, 1, N - 5) {\n c[i][0] = c[i][i] = 1LL;\n rep(j, 1, i - 1) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;\n }\n}\nLL M_1[N], M[N];\nint main() {\n int n; LL m; scanf(\"%d %lld\", &n, &m); init();\n M_1[0] = M[0] = 1LL;\n M_1[1] = (m - 1 + mod) % mod; M[1] = m % mod;\n rep(i, 2, n) M_1[i] = M_1[i - 1] * (m - 1) % mod, M[i] = M[i - 1] * m % mod;\n rep(i, 1, n) dp[1][i] = 1LL * c[n][i] * M_1[n - i] % mod;\n rep(i, 2, n) rep(j, 0, n) rep(k, 0, j) {\n LL x = 1LL * dp[i - 1][k] * c[n - k][j - k] % mod;\n LL y = 1LL * M_1[n - j] * M[k] % mod;\n dp[i][j] = (dp[i][j] + 1LL * x * y % mod) % mod;\n if(j == k) dp[i][j] = (dp[i][j] - 1LL * M_1[n] * dp[i - 1][k] % mod + mod) % mod;\n }\n printf(\"%d\\n\",dp[n][n]);\n return 0;\n}\n", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\ntypedef long long LL;\nconst LL MOD=777777777;\nconst int SIZEN=270;\nLL C[SIZEN][SIZEN];//????2N?\nLL f[SIZEN][SIZEN][SIZEN];//???i,?j??,??k???\nvoid prepare(void){\n\tfor(int i=0;ik) break;\n\t\t\t\t\tif(t==i) continue;\n\t\t\t\t\tf[i][j][k]+=f[i-1][j-t][k-t]*C[j][t];\n\t\t\t\t\tf[i][j][k]%=MOD;\n\t\t\t\t}\n\t\t\t\t//?i????i\n\t\t\t\tif(j-i>=0){\n\t\t\t\t\tf[i][j][k]+=f[i-1][j-i][k]*C[j][i];\n\t\t\t\t\tf[i][j][k]%=MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tcout<<\"{\";for(int k=0;k<=N;k++){cout<>=1;\n\t\tans++;\n\t}\n\treturn ans;\n}\nint main(){\n\t//freopen(\"t1.in\",\"r\",stdin);\n\t//freopen(\"t1.out\",\"w\",stdout);\n\tint n,k;\n\tcin>>n>>k;\n\tcout<\n#include\n#include\nusing namespace std;\n\ntypedef unsigned long long ll;\nconst int N = 2;\nll n, k, l, m;\n\nstruct Mat {\n ll mat[N + 1][N + 1];\n} A, B;\n\nMat operator * ( Mat a, Mat b )\n{\n Mat c;\n memset ( c.mat, 0, sizeof c.mat );\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 ( c.mat[i][j] += ( a.mat[i][k] * b.mat[k][j] ) % m ) %= m;\n return c;\n}\n\nMat operator ^ ( Mat a, ll pow )\n{\n Mat c;\n for ( int i = 0; i < N; i++ )\n for ( int j = 0; j < N; j++ )\n c.mat[i][j] = ( i == j );\n while ( pow ) {\n if ( pow & 1 ) c = c * a;\n a = a * a;\n pow >>= 1;\n }\n return c;\n}\n\nll quickp( ll x )\n{\n ll s = 1, c = 2;\n while( x ) {\n if( x & 1 ) s = ( s * c ) % m;\n c = ( c * c ) % m;\n x >>= 1;\n }\n return s;\n}\nint main()\n{\n Mat p, a;\n p.mat[0][0] = 0, p.mat[0][1] = 1;\n p.mat[1][0] = 1, p.mat[1][1] = 1;\n a.mat[0][0] = 1, a.mat[0][1] = 2;\n a.mat[1][0] = 0, a.mat[1][1] = 0;\n cin >> n >> k >> l >> m;\n\n ll ans = 0;\n if( l == 64 || ( 1uLL << l ) > k ) {\n ans++;\n p = p ^ n;\n a = a * p;\n ll t1 = a.mat[0][0], t2 = ( m + quickp( n ) - t1 ) % m;\n for( int i = 0; i < l; ++i ) {\n if( k & ( 1uLL << i ) ) ans = ( ans * t2 ) % m;\n else ans = ( ans * t1 ) % m;\n }\n }\n\n cout << ans%m << endl;\n\n}\n", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"} {"source_code": "#include\nusing namespace std;\n\n#define FOR(i, a, b) for(int i = a; i < b; ++i)\n#define REP(i, n) FOR(i, 0, n)\n#define _ << \" \" <<\n#define sz(x) ((int) x.size())\n#define pb(x) push_back(x)\ntypedef long long ll;\ntypedef pair point;\n\nconst int MAXN = 54;\n\nint dp[MAXN][MAXN][MAXN][MAXN];\nstring s[MAXN];\nint n;\n\nint getNum(char c){\n if(c >= '2' && c <= '9')\n return c - '2';\n if(c == 'T') return 8;\n if(c == 'J') return 9;\n if(c == 'Q') return 10;\n if(c == 'K') return 11;\n if(c == 'A') return 12;\n}\n\nint getSign(char c){\n if(c == 'S') return 0;\n if(c == 'D') return 1;\n if(c == 'H') return 2;\n if(c == 'C') return 3;\n}\n\nint getVal(string x){\n return getNum(x[0]) + getSign(x[1]) * 13;\n}\n\nconst char num[] = {'2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};\nconst char sign[] = {'S', 'D', 'H', 'C'};\n\nstring returnVal(int x){\n int cnt = 0;\n while(x - (cnt + 1) * 13 >= 0)\n cnt ++;\n x -= cnt * 13;\n string ret = \"\";\n ret += num[x];\n ret += sign[cnt];\n\n return ret;\n}\n\nvoid solve(int a, int b, int c){\n string A = returnVal(a);\n string B = returnVal(b);\n string C = returnVal(c);\n\n if(C[0] != B[0] && C[1] != B[1]) return;\n if(C[0] != A[0] && C[1] != A[1]) return;\n cout << \"YES\\n\";\n exit(0);\n}\n\nvoid rek(int pos, int a, int b, int c){\n if(pos == 0){\n solve(a, b, c);\n return;\n }\n if(dp[pos][a][b][c]) return;\n\n string A = returnVal(a);\n string B = returnVal(b);\n string C = returnVal(c);\n\n dp[pos][a][b][c] = 1;\n\n if(C[0] == B[0] || C[1] == B[1])\n rek(pos - 1, getVal(s[pos - 1]), a, c);\n if(C[0] == s[pos - 1][0] || C[1] == s[pos - 1][1])\n rek(pos - 1, c, a, b);\n}\n\nint main(){\n ios_base::sync_with_stdio(false); cin.tie(0);\n\n cin >> n;\n REP(i, n){\n cin >> s[i];\n int val = getVal(s[i]);\n }\n if(n == 1){\n cout << \"YES\\n\";\n exit(0);\n }\n if(n == 2){\n if(s[0][0] == s[1][0] || s[0][1] == s[1][1]) cout << \"YES\\n\";\n else cout << \"NO\\n\";\n exit(0);\n }\n\n rek(n - 3, getVal(s[n - 3]), getVal(s[n - 2]), getVal(s[n - 1]));\n\n cout << \"NO\\n\";\n}\n", "src_uid": "1805771e194d323edacf2526a1eb6768"} {"source_code": "#include\n#include\nusing namespace std;\nint n,k,qq;\nint a[110],b[110],c[110];\nbool vis[110];\nbool judge(){\n\tfor(int i=1;i<=n-1;i++)\n\t\tif(a[i]>a[i+1])return 0;\n\treturn 1;\n}\nvoid dfs(int q){\n\tif(q==qq+1){\n\t\tif(!judge()){\n\t\t\tcout<<\"Yes\";\n\t\t\texit(0);\t\n\t\t}\n\t}\n\tfor(int i=1;i<=k;i++)\n\t\tif(!vis[i]){\n\t\t\ta[c[q]]=b[i];\n\t\t\tvis[i]=1;\n\t\t\tdfs(q+1);\n\t\t\tvis[i]=0;\n\t\t\ta[c[q]]=0;\n\t\t}\n}\nint main(){\n\tcin>>n>>k;\n\tfor(int i=1;i<=n;i++){\n\t\tcin>>a[i];\n\t\tif(!a[i])c[++qq]=i;\t\n\t}\n\tfor(int i=1;i<=k;i++)cin>>b[i];\n\tdfs(1);\n\tcout<<\"No\";\n\treturn 0;\n}", "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"source_code": "#include \n\nusing namespace std;\n\nint main(){\n\tlong long x;\n\tcin >> x;\n\tx = (x%360 + 360)%360;\n\tint ans = 0;\n\twhile(x > 45 && x < 315){\n\t\tans++;\n\t\tx -= 90;\n\t}\n\tcout << ans << \"\\n\";\n\treturn 0;\n}\n", "src_uid": "509db9cb6156b692557ba874a09f150e"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nconst int maxn=310,mod=1e9+7;\nint fac[maxn],invf[maxn];\nint\tn,a[maxn],ans;\nint cs=0,c[maxn];\nbool vis[maxn];\nint cnt[maxn];\nint f[maxn][maxn][maxn];\ninline void Add(int &x,int y) { (x+=y)>=mod?x-=mod:0; }\ninline void Mul(int &x,int y) { x=1LL*x*y%mod; }\ninline bool is_square(long long x) { return fabs((long long)sqrt(x)*(long long )sqrt(x)-x)<1e-8; }\ninline int Pow(int x,int k)\n{\n\tint s=1;\n\twhile(k)\n\t{\n\t\tif(k&1)\n\t\t\tMul(s,x);\n\t\tMul(x,x);\n\t\tk>>=1;\n\t}\n\treturn s;\n}\nint main()\n{\n#ifndef ONLINE_JUDGE\n\tfreopen(\"data.in\",\"r\",stdin);\n#endif\n\tint i,j,k,l;\n\tfor(i=fac[0]=invf[0]=1;i\n\n#define rep(i,n) for(i=1;i<=n;i++)\n#define Rep(i,n) for(i=0;i= ara[j] && L[i] <= L[j])\n {\n L[i] = L[j] + 1;\n //par[i] = j;\n }\n }\n }\n LL mx = 0;\n //LL idx;\n for(i=1;i<=N;i++)\n {\n if(L[i] > mx)\n {\n mx = L[i];\n //idx = i;\n }\n }\n return mx;\n}\n\nint main()\n{\n //FI;\n LL i,j,t;\n sll(n,t);\n rep(i,n)\n {\n sl(bra[i]);\n cnt[ bra[i] ]++;\n }\n LL d = min(n,t);\n N = n * d;\n Rep(j,d)\n {\n rep(i,n)\n {\n ara[j*n+i] = bra[i];\n //printf(\"%lld \",bra[i]);\n }\n }\n LL my = LIS();\n if(t > d)\n {\n LL mx = 0;\n rep(i,n)\n {\n if(cnt[ bra[i] ] > mx)mx = cnt[ bra[i] ];\n }\n my += (t - d) * mx;\n }\n pl(my);NL;\n return 0;\n}\n", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2"} {"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;\n#define ll long long\n\nconst int MAXN=2e5+5;\nint n;\nll a[7005];\nll b;\nll c[7005];\nll d[7005];\nint cnt;\nmapm;\nmapmm;\nmapmmm;\nint main()\n{\n ios::sync_with_stdio(false);\n scanf (\"%d\" , &n ) ;\n for (int i = 0 ; i ::reverse_iterator it=mm.rbegin();(it)!=mm.rend();it++){\n c[cnt]=it->first;\n d[cnt++]=it->second;\n //cout<c[j])break;\n if((c[i]&kk)<(c[j]&kk))\n {\n f=0;\n break;\n }\n }\n if(f){\n sum+=d[j];\n mmm[c[j]]=1;\n }\n }\n }\n cout<\r\n\r\nint main(){\r\n long t; scanf(\"%ld\", &t);\r\n while(t--){\r\n long cnt(0);\r\n for(int row = 0; row < 2; row++){\r\n for(int col = 0; col < 2; col++){\r\n long x; scanf(\"%ld\", &x);\r\n cnt += x;\r\n }\r\n }\r\n long res(0);\r\n if(cnt == 4){res = 2;}\r\n else if(cnt > 0){res = 1;}\r\n printf(\"%ld\\n\", res);\r\n }\r\n}", "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\n\nchar str[200];\nchar *ans = (char *)malloc(200 * sizeof(char)) ;\n\nint main()\n{\n// freopen(\"data.txt\",\"r\",stdin);\n cin.getline(str, 200, '\\n');\n int b = 0, len;\n len = strlen(str);\n int mul = 1;\n for(int i = len - 1; i >= 0; --i){\n if(str[i] == 'e')break;\n b += (str[i] - '0') * mul;\n mul *= 10;\n }\n int dot = 0;\n for(; dot < len; ++dot){\n if(str[dot] == '.')break;\n }\n dot += b;\n int tot = 0;\n for(int i = 0; i < len; ++i){\n if(str[i] == '.')continue;\n if(str[i] == 'e')break;\n if(dot == 0){ans[tot++] = '.';}\n ans[tot++] = str[i];\n dot --;\n }\n for(; dot > 0; --dot){\n ans[tot++] = '0';\n }\n ans[tot++] = '\\0';\n while(ans[0] == '0'){\n if(ans[1] == '.')break;\n ans = &ans[1];\n }\n len = strlen(ans);\n if(ans[len - 1] == '0' && ans[len - 2] == '.')len -= 2;\n ans[len] = '\\0';\n puts(ans);\n return 0;\n}\n", "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"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\n#define PB push_back\n#define MP make_pair\n#define A first\n#define B second\n#define eps 1e-8\n\ntypedef vector VI;\ntypedef vector VS;\ntypedef vector VD;\ntypedef long long LL;\ntypedef pair PII;\n\nint n, a[4];\nint dp[310][310][310], vis[310][310];\n\nvoid prepare() {\n memset(dp, 0, sizeof(dp));\n for (int i = 0; i <300; i ++ )\n for (int j = 0; j < 300; j ++ )\n for (int k = 0; k < 300; k ++ )\n if (dp[i][j][k] != 0) continue;\n else {\n for (int l = i + 1; l < 300; l ++ )\n dp[l][j][k] = 1;\n for (int l = j + 1; l < 300; l ++ )\n dp[i][l][k] = 1;\n for (int l = k + 1; l < 300; l ++ )\n dp[i][j][l] = 1;\n for (int l = 1; i + l < 300 && j + l < 300 && k + l < 300; l ++ )\n dp[i + l][j + l][k + l] = 1;\n }\n memset(vis, 0, sizeof(vis));\n for (int i = 0; i < 300; i ++ )\n for (int j = 0; j < 300; j ++ )\n if (vis[i][j] == 0) {\n for (int k = i + 1; k < 300; k ++ )\n vis[k][j] = 1;\n for (int k = j + 1; k < 300; k ++ )\n vis[i][k] = 1;\n for (int k = 1; k + i < 300 && k + j < 300; k ++ )\n vis[i + k][j + k] = 1;\n }\n}\n\nint main() {\n prepare();\n scanf(\"%d\", &n);\n for (int i = 0; i < n; i ++ )\n scanf(\"%d\", &a[i]);\n if (n == 1)\n if (a[0] != 0) printf(\"BitLGM\\n\");\n else printf(\"BitAryo\\n\");\n if (n == 2)\n if (vis[a[0]][a[1]] == 1) printf(\"BitLGM\\n\");\n else printf(\"BitAryo\\n\");\n if (n == 3)\n if (dp[a[0]][a[1]][a[2]] == 1) printf(\"BitLGM\\n\");\n else printf(\"BitAryo\\n\");\n return 0;\n}\n\n \t\t\t\t\t\t\t\t \t\t \t \t\t \t\t \t", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7"} {"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#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 all(v)\t\t\t\t((v).begin()), ((v).end())\n#define sz(v)\t\t\t\t((int)((v).size()))\n#define clr(v, d)\t\t\tmemset(v, d, sizeof(v))\n#define rep(i, v)\t\tfor(int i=0;i=(int)(n);--i)\n#define pb\t\t\t\t\tpush_back\n#define MP\t\t\t\t\tmake_pair\n#define P(x)\t\t\t\tcout<<#x<<\" = { \"< vi;\ntypedef vector vd;\ntypedef vector< vi > vvi;\ntypedef vector< vd > vvd;\ntypedef vector vs;\ntypedef vector\t\t vll;\n\n\nconst ll OO = 1e9;\nconst ll mod = 1e9+7;\nconst double EPS = (1e-7);\nint dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }\n\n\nvoid fast(){\n\t#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n\t\n\t#endif\n\tstd::ios_base::sync_with_stdio(0);\n\tcin.tie(NULL); cout.tie(NULL);\n}\nint n ;\nvector< string > arr;\n\nvoid gen(int i , string w){\n\tif(i == 4){\n\t\tarr.push_back(w);\n\t\treturn ;\n\t}\n\t\n\tfor(char idx = '0' ; idx<='9';idx++)\n\t\tgen(i+1 , w + idx);\n}\nbool fun(pair< string , pair < int ,int> > p , string s){\n\tset< char > ss;\n\tlp(i , s.size() )\n\t\tss.insert(s[i]);\n\n\tif(ss.size() != 4)\n\t\treturn 0;\n\n\tint in = 0 , nin = 0;\n\tfor(int i = 0 ; i < s.size();i++){\n\t\tif(p.first[i] == s[i] ){\n\t\t\tin++;\n\t\t}else{\n\t\t\tnin+= (s.find(p.first[i] ) != -1);\n\t\t}\n\t}\n\treturn (in == p.second.first && nin == p.second.second);\n}\nint main(){\n\tfast();\n\tgen(0 , \"\");\n\twhile(cin>>n){\n\t\tpair< string , pair < int ,int> > a [11];\n\t\tstring s ;\n\t\tint x , y ;\n\t\tvectorans;\n\t\tlp(i, n){\n\t\t\tcin>>s>>x>>y;\n\t\t\ta[i] = MP(s , MP(x,y) );\n\t\t}\n\t\tlp(i , arr.size()){\n\t\t\tbool f = 0;\n\t\t\tlp(j , n){\n\t\t\t\tif(!fun(a[j] , arr[i]) ){\n\t\t\t\t\tf = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!f){\n\t\t\t\tans.push_back(arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tif(ans.size() == 0){\n\t\t\tcout<<\"Incorrect data\\n\";\n\t\t}else if(ans.size() > 1){\n\t\t\tcout<<\"Need more data\\n\";\n\t\t}else cout<\n#include \nusing namespace std;\n#define maxn 400010\nint ans[maxn];\n\nint main()\n{\n int n;\n\n int count5=0,count2=0;\n for(int i=1; i<=maxn; i++)\n {\n int bak = i;\n if(bak % 5 == 0)\n {\n while(bak)\n {\n if(bak % 5 == 0)\n count5++;\n else\n break;\n bak /= 5;\n }\n }\n if(bak % 2 == 0)\n {\n while(bak)\n {\n if(bak % 2 == 0)\n count2++;\n else\n break;\n bak /= 2;\n }\n }\n if( int tmp = min(count5, count2) )\n ans[i] = tmp;\n }\n //printf(\"feferf\\n\");\n while(scanf(\"%d\", &n) != EOF)\n {\n int cnt=1;\n int ans1[100];\n for(int i=0; i<=100; i++)\n ans1[i] = 0;\n for(int i=1; i<=maxn; i++)\n {\n if(ans[i] > n)\n break;\n if(ans[i] == n)\n {\n ans1[0]++;\n ans1[cnt++] = i;\n }\n }\n printf(\"%d\\n\", ans1[0]);\n for(int i=1; i\n#include\n#include\n\nusing namespace std;\n\nint main()\n{\n int *a,b;\n list start;\n list endlist;\n scanf(\"%d\",&b);\n a = (int *)malloc(sizeof(int) * b);\n for(int i=0;i 0) {\n totcount++;\n start.push_back(startidx);\n endlist.push_back(j);\n sum = 0;\n sum = sum + a[j];\n mprevsum = sum;\n startidx = j+1;\n endindex = j+1;\n continue;\n }\n if(startidx == 0) {\n startidx = j+1;\n }\n endindex++;\n mprevsum = sum;\n }\n if(sum != 0 && totcount == 0) {\n printf(\"YES\\n\");\n printf(\"1\\n\");\n printf(\"%d %d\",1,b);\n }\n if(totcount == 0 && sum == 0) {\n printf(\"NO\");\n }\n if(totcount != 0) {\n if(sum != 0) {\n totcount++;\n start.push_back(startidx);\n endlist.push_back(endindex);\n }\n printf(\"YES\\n\");\n printf(\"%d\",totcount);\n }\n list::iterator it=start.begin();\n list::iterator it1=endlist.begin();\n for (; it != start.end(); ++it,++it1) {\n printf(\"\\n\");\n printf(\"%d %d\",*it,*it1);\n }\n return 0;\n}\n", "src_uid": "3a9258070ff179daf33a4515def9897a"} {"source_code": "#include \nusing namespace std;\n#define ll long long\n#define pt pair\nint sign(ll x){if(x > 0) return 1;if(x < 0) return -1;return 0;}int half(pt x){if(x.second != 0)return sign(x.second);return -sign(x.first);}\n__int128_t cross(pt a, pt b){return (__int128_t)a.first * b.second - (__int128_t)a.second * b.first;}\nbool angCmp(pt a, pt b){int A = half(a), B = half(b);if(A == B) return cross(a, b) > 0;return A < B;}\ntypedef array T;T a;int eq = 0, neg = 0;vector cat;struct cmp{bool operator()(const pt&a, const pt&b) const{return angCmp(a, b);}};map, int, cmp> mp;\nT operator*(T a, ll b){for(int i = 0; i < 3; i ++)a[i] *= b;return a;}T operator+(T a, T b){for(int i = 0; i < 3; i ++)a[i] += b[i];return a;}\nT operator-(T a, T b){for(int i = 0; i < 3; i ++)a[i] -= b[i];return a;}\nll sum(T a){return a[0] + a[1] + a[2];}ll dot(T a, T b){ll res = 0;for(int i = 0; i < 3; i ++)res += a[i] * b[i];return res;}\npair lst;bool bad(pt a, pt b){return a == b || cross(a, b) < 0;}void add(pair p, int x){\n\tif(p.first == 0 && p.second == 0){eq += x; return;}vector > cand = {lst, p};if(x == 1){if(!mp.count(p) && mp.count({-p.first, -p.second})) neg ++;mp[p] ++;\n\t}else{if(mp[p] == 1 && mp.count({-p.first, -p.second})) neg --;auto it = mp.find(p);if(it == mp.begin()) it = mp.end();it --; \n\t\tcand.push_back(it -> first);mp[p] --;if(!mp[p]) mp.erase(p);}\n\tlst = {0, 0};for(pair i : cand){auto it = mp.find(i);if(it == mp.end()) continue;auto nx = next(it);if(nx == mp.end()) nx = mp.begin();if(bad(i, nx -> first))lst = i;}}\nint ans(){if(eq) return 1;if(neg) return 2;if(mp.size() && lst.first == 0 && lst.second == 0)return 3;return 0;}\nint main(){\tios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);long long rd;cin >> rd; a[0] = rd;cin >> rd; a[1] = rd;cin >> rd; a[2] = rd;int q; cin >> q;\n\tfor(char c; q --;){cin >> c;if(c == 'A'){T x;cin >> rd; x[0] = rd;cin >> rd; x[1] = rd;cin >> rd; x[2] = rd;\t\t\t\n\t\t\tx = x * sum(a) - a * sum(x);pt p = {dot(x, {1, -1, 0}), dot(x, {1, 1, -2})};ll gc = __gcd(abs(p.first), abs(p.second));if(p.first || p.second) p.first /= gc, p.second /= gc;\n\t\t\tcat.push_back(p);add(cat.back(), 1);}else{int r; cin >> r; r --;add(cat[r], -1);}ll get = (ll)ans();cout << get << endl;}return 0;}", "src_uid": "ea995d5c5fe84cd175cda0d0e2f01889"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nconst int LEN = 201;\nchar state[LEN], d[10];\nint n, sp, cp;\nchar winner;\n\nint get_next_cp()\n{\n if(cp == n)\n {\n d[0] = 'h';\n return cp - 1;\n }\n if(cp == 1)\n {\n d[0] = 't';\n return cp + 1;\n }\n if(d[0] == 'h') return cp - 1;\n return cp + 1;\n}\n\nint main()\n{\n while(scanf(\"%d %d %d\", &n, &sp, &cp) != EOF)\n {\n scanf(\"%s\", d);\n scanf(\"%s\", d);\n scanf(\"%s\", state);\n // cout << d << ' ' << state << endl;\n winner = '0';\n int i;\n for(i = 0; ; i++)\n {\n // cout << sp << ' ' << cp << endl;\n if(sp == cp)\n {\n winner = 'c';\n break;\n }\n else if(state[i] == '\\0')\n {\n winner = 's';\n break;\n }\n if(state[i] == '0') //move\n {\n if(d[0] == 'h')\n {\n if(sp < cp && sp - 1 >= 1) sp--;\n else if(sp > cp && sp + 1 <= n) sp++;\n }\n else\n {\n if(sp > cp && sp + 1 <= n) sp++;\n else if(sp < cp && sp - 1 >= 1) sp--;\n }\n cp = get_next_cp();\n }\n else //idle\n {\n cp = get_next_cp();\n if(d[0] == 'h')\n {\n if(cp == n) sp = 1;\n else sp = n;\n }\n else\n {\n if(cp == 1) sp = n;\n else sp = 1;\n }\n }\n }\n if(winner == 'c') printf(\"Controller %d\\n\", i);\n else puts(\"Stowaway\");\n }\n}\n", "src_uid": "2222ce16926fdc697384add731819f75"} {"source_code": "#include\nusing namespace std;\nint main ()\n{\n int i,j,sum=0,a,b,jih=0;\n cin>>a>>b;\n a > b ? i=a-b : i=b-a;\n if(i%2==0)\n jih=1;\n for(j=1;j<=i/2;j++)\n sum+=2*j;\n if(jih==0)\n sum+=j;\n cout<\n#include \n#include \n#include \n#include \n#include \n\n#define ll long long\n#define MOD 1000000007\n\nusing namespace std;\n\nint main() {\n\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\n\tll x, y, n;\n\n\tcin >> x >> y >> n;\n\n\tvector d;\n\n\td.push_back(x);\n\td.push_back(y);\n\td.push_back(((y - x) + MOD) % MOD);\n\td.push_back(((-x) + MOD) % MOD);\n\td.push_back(((-y) + MOD) % MOD);\n\td.push_back(((x - y) + MOD) % MOD);\n\n\tif (d.size() == 1) {\n\t\tcout << (d[0] + MOD) % MOD << endl;\n\t}\n\telse {\n\t\tcout << (d[((n - 1) % 6)] + MOD) % MOD << endl;\n\t}\n\n\treturn 0;\n}", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "\n#include \n\nusing namespace std;\n//y>-2 y\n//g>-1y 1b\n//b>-3 b\nint main()\n{\n long long int a,bl,c;\n long long int y,b;\n\n scanf(\"%lld %lld\",&y,&b);\n scanf(\"%lld %lld %lld\",&a,&bl,&c);\n\n long long int sy,sb;\n sy=(2*a)+bl;\n sb=(3*c)+bl;\n long long int sum;\n if(ysb) {\n sum=(sy-y);\n }\n else{\n sum=(sb-b);\n }\n if(sum<=0) {\n sum=0;\n }\n printf(\"%lld\\n\",sum);\n return 0;\n}\n", "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"source_code": "#include \nusing namespace std;\n\ntypedef unsigned long long ull;\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\ntypedef pair pdd;\ntypedef vector vl;\ntypedef vector> vvl;\n//typedef vector> Graph;\n\nconst ll mod = 1e9 + 7;\n//const ll mod = 998244353;\n\n#define REP(i,n) for(ll i=0;i<(ll)n;i++)\n#define dump(x) cerr << #x << \" = \" << (x) << endl;\n#define spa << \" \" <<\n#define fi first\n#define se second\n\ntemplate bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }\n\ntemplate ostream& operator << (ostream& os, const pair v){\nos << \"(\" << v.first << \", \" << v.second << \")\"; return os;\n}\ntemplate ostream& operator << (ostream& os, const vector v){\nfor(int i = 0; i < (int)v.size(); i++){if(i > 0){os << \" \";} os << v[i];} return os;\n}\ntemplate ostream& operator << (ostream& os, const vector> v){\nfor(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;\n}\n\ntemplate void debug(vector>&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cerr<> n;\n vector a(n);\n REP(i, n) cin >> a[i];\n\n ll S = 0;\n REP(i, n){\n if(a[i]>=0)S += a[i];\n else S -= a[i];\n }\n cout << S << endl;\n\n return 0;\n}", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"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{\n int a,o=0,n=0,m=0;\n cin >>a;\n vector v;\n for(int i=0;i>q;\n v.push_back(q);\n }\n if(v[0]==0)\n n++;\n else\n m++;\n for(int i=1;i\n#include\nusing namespace std;\nint n,a,b;\nint main() {\n scanf(\"%d%d%d\",&n,&a,&b);\n a=a+b;\n a%=n;\n a=(a+n)%n;\n if(a==0) a=n;\n cout<\n\nusing namespace std;\n\nint main() {\n\tint n, a, b, c, d; cin >> n >> a >> b >> c >> d;\n\tlong long ans = 0;\n\t\n\tfor (int i = 1; i <= n; i++) {\n\t\tint x = i + b - c;\n\t\tint y = i + a - d;\n\t\tint z = a + x - d;\n if (1 <= x && x <= n && 1 <= y && y <= n && 1 <= z && z <= n) {\n ans++;\n }\n\t}\n\tcout << ans * n << endl;\n}", "src_uid": "b732869015baf3dee5094c51a309e32c"} {"source_code": "#include \n\nusing namespace std;\n\nlong long da1[60],da2[60],n,s1,s2;\nint main() {\n\twhile(cin>>n) {\n\t\ts1=s2=0;\n\t\tfor(int i=1; i<=n; ++i) {\n\t\t\tcin>>da1[i];\n\t\t\ts1+=da1[i];\n\t\t}\n\t\tfor(int i=1; i<=n; ++i) {\n\t\t\tcin>>da2[i];\n\t\t\ts2+=da2[i];\n\t\t}\n\t\tif(s2<=s1) cout<<\"Yes\\n\";\n\t\telse cout<<\"No\\n\";\n\t}\n\treturn 0;\n}", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"source_code": "#include \n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair ii;\ntypedef pair iii;\n\n#define N 300\n#define M 21\n#define MOD 1000000007\n#define PI acos(-1)\n#define rep(i,a,b) for(int i = a; i < b; i++)\n#define reps(i,a,b) for(int i = a; i >= b; i--)\n#define sc scanf\n#define pc printf\n#define pb push_back\n#define F first\n#define S second\n\nint n,cur,x[N],y[N];\nstring home;\nmapmp;\nbool mark[N][N];\nstring c,d,e;\nint deg[N];\n\n\nint main()\n{\n cin >> n;\n\n int id = 0;\n cin >> home;\n mp[home] = ++id;\n rep(i,0,n){\n cin >> e;\n c = \"\";d = \"\";\n c += e[0],c += e[1],c += e[2];\n d += e[5],d += e[6],d += e[7];\n //cout << c << \" \" << d << endl;\n if(!mp[c]){\n mp[c] = ++id;\n\n }\n if(!mp[d]){\n mp[d] = ++id;\n }\n deg[mp[c]]++;\n deg[mp[d]]++;\n //cout << c << \" \" << d << \" \" << mp[c] << \" \" << mp[d] << endl;\n\n }\n\n rep(i,1,id+1){\n if(deg[i] % 2 > 0){\n puts(\"contest\");\n return 0;\n }\n }\n\n puts(\"home\");\n\n return 0;\n}\n\n\n", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"source_code": "#include \n#include \nusing namespace std;\nint main()\n{\n\tint i,n;\n\tstring s;\n\tcin >> n >> s;\n\tfor (i = 0; i < n - 1 && s[i] =='1'; i++);\n\tcout << i+1;\n\treturn 0;\n}", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nint main()\n{\n long long int n,k,m,l;\n cin>>n>>k;\n if (n%2==1)\n m=n/2+1;\n else\n m=n/2;\n if (k<=m)\n {\n cout<< k*2-1;\n }\n else\n {\n l=k-m;\n cout<\nusing namespace std;\n\nconst int N = 18003000 + 5;\n\nint n, cmp[N];\nvector ans;\n\nvoid sieve() {\n cmp[1] = cmp[0] = 1;\n for(long long i = 2; i <= 10000; i++) {\n if(!cmp[i]) for(long long j = i*i; j < N; j += i) cmp[j] = 1;\n }\n}\n\nint main() {\n ios_base::sync_with_stdio(0), cin.tie(0);\n sieve();\n cin >> n;\n ans.assign(n+1, 0);\n int aux = (n*(n+1))/2;\n\n if(!cmp[aux]) {\n for(int i = 1; i <= n; i++) cout << 1 << \" \\n\"[i == n];\n return 0;\n }\n\n if(!cmp[aux-2]) {\n for(int i = 1; i <= n; i++) cout << 1 + (i == 2) << \" \\n\"[i == n];\n return 0;\n }\n\n if(aux & 1) {\n ans[1] = ans[2] = 3;\n aux -= 3;\n }\n\n int p1 = -1, p2 = -2;\n for(int i = 0; i <= aux - i; i++) {\n if(!cmp[i] and !cmp[aux-i]) {\n p1 = i, p2 = aux-i;\n break;\n }\n }\n\n if(p1 != -1) {\n for(int i = n; i >= 1; i--) \n if(!ans[i] and i <= p1) ans[i] = 1, p1 -= i;\n\n for(int i = n; i >= 1; i--)\n if(!ans[i] and i <= p2) ans[i] = 2, p2 -= i;\n }\n\n for(int i = 1; i <= n; i++) cout << ans[i] << \" \\n\"[i == n];\n}\n", "src_uid": "94ef0d901f21e1945849fd5bfc2d1449"} {"source_code": "#include \n#include \n#include \n#include \nusing namespace std;\n#define MAXS 300003\nint n, c[3], s;\nint gcd(int a, int b, int &x, int &y)\n{\n if (b == 0)\n {\n x = 1, y = 0;\n return a;\n }\n int c = gcd(b, a % b, y, x);\n y -= a / b * x;\n return c;\n}\nint k[3], ans, f[4], first, g;\n/*int a[MAXS], la;\nvoid Aget(int mm)\n{\n int m = (s - c[1] * k[1]) % c[2];\n int x, y, g = gcd(c[0], c[2], x, y);\n x = (x % c[2] + c[2]) % c[2];\n la = 0;\n if (m % g == 0 && (x * m / g) % c[2] <= mm)\n {\n a[la++] = (x * m / g) % c[2];\n while (a[la - 1] + c[2] / g <= mm)\n a[la] = a[la - 1] + c[2] / g, ++la;\n }\n}*/\nint check(int mid)\n{\n k[0] = first + c[2] / g * mid;\n k[2] = (s - c[0] * k[0] - c[1] * k[1]) / c[2];\n return abs(c[0] * k[0] - c[1] * k[1]) + abs(c[1] * k[1] - c[2] * k[2]);\n}\nint main()\n{\n scanf(\"%d%d\", &n, &s);\n for (int i = 0; i < n; ++i)\n {\n int x;\n scanf(\"%d\", &x);\n ++c[x - 3];\n }\n ans = INT_MAX;\n for (k[1] = 0; k[1] <= s / c[1]; ++k[1])\n {\n int mm = min(k[1], (s - (c[1] + c[2]) * k[1]) / c[0]);\n //Aget(m);\n int x, y, m = (s - c[1] * k[1]) % c[2];\n g = gcd(c[0], c[2], x, y);\n x = (x % c[2] + c[2]) % c[2];\n first = x * m / g % c[2];\n if (first <= mm && m % g == 0)\n {\n //sort(a, a + la);\n int l = 0, r = floor((mm - first) / (double(c[2]) / g)) + 1;\n while (r - l >= 3)\n {\n int ml = (r - l) / 3 + l;\n int mr = (r - l) / 3 * 2 + l;\n if (check(ml) < check(mr))\n r = mr;\n else\n l = ml;\n }\n if (l + 1 == r)\n {\n int t = check(l);\n if (t < ans)\n {\n ans = t;\n f[0] = first + c[2] / g * l, f[1] = k[1], f[2] = (s - c[0] * f[0] - c[1] * f[1]) / c[2];\n }\n }\n else\n {\n int t1 = check(l), t2 = check(l + 1);\n if (t1 < t2 && t1 < ans)\n {\n ans = t1;\n f[0] = first + c[2] / g * l, f[1] = k[1], f[2] = (s - c[0] * f[0] - c[1] * f[1]) / c[2];\n }\n else if (t2 < ans)\n {\n ans = t2;\n f[0] = first + c[2] / g * (l + 1), f[1] = k[1], f[2] = (s - c[0] * f[0] - c[1] * f[1]) / c[2];\n }\n }\n }\n }\n if (ans == INT_MAX)\n printf(\"-1\\n\");\n else\n printf(\"%d %d %d\\n\", f[0], f[1], f[2]);\n return 0;\n}\n", "src_uid": "3f3eb49a127768139283ac04ee44950f"} {"source_code": "#include \n\nusing namespace std;\n\nlong long n,m,i,j,b[15],k,mi=7654457,s,x,g=1;\nstring st,st1;\nchar c[10005];\nbool zero(string st)\n{\n if (st==\"0\") return 1;\n if (st[0]=='0') return 0;\n return 1;\n}\nint main()\n{\n cin>>n>>k;\n for (i=1;i<=k;i++) g*=10;\n sprintf(c,\" %d\",n);\n st=c;\n m=st.length()-1;\n //b[1]=b[2]=b[3]=1;\n while (b[0]==0)\n {\n st1=\"\";\n for (j=m;j>=1&&b[j];j--);\n b[j]=1;\n for (i=j+1;i<=m;i++) b[i]=0;\n for (i=1;i<=m;i++)\n if (b[i]) st1+=st[i];\n sscanf(st1.c_str(),\"%d\",&x);\n if (x%g==0&&zero(st1)) \n {\n s=m;\n for (i=1;i<=m;i++) s-=b[i];\n if (s\nusing namespace std;\nint k[10][10];\nint a[9]={-1,-1,-1,0,0,0,1,1,1};\nint b[9]={-1,0,1,-1,0,1,-1,0,1};\nint dfs(int x,int y,int s){\n\tif(s==8)return 1;\n\tfor(int i=0;i<9;i++){\n\t\tint fx=x+a[i],fy=y+b[i];\n\t\tif(fx>8||fy>8||fx<1||fy<1\n\t\t||k[fx-s-1][fy]||k[fx-s][fy])\n\t\t\tcontinue;\n\t\tif(dfs(fx,fy,s+1))return 1;\n\t}\n\treturn 0;\n}\nint main(){\n\tint i,j;\n\tchar r;\n\tfor(i=1;i<=8;i++)\n\t\tfor(j=1;j<=8;j++){\n\t\t\tcin>>r;\n\t\t\tif(r=='.'||r=='M'||r=='A')k[i][j]=0;\n\t\t\tif(r=='S')k[i][j]=1;\n\t\t}\n\tif(dfs(8,1,0))cout<<\"WIN\";\n\telse cout<<\"LOSE\";\n}\n", "src_uid": "f47e4ab041288ba9567c19930eb9a090"} {"source_code": "#pragma GCC optimize (\"O3\")\n#pragma GCC target (\"sse4\")\n\n#include \n#include \n#include \n#include \n\nusing namespace std;\nusing namespace __gnu_pbds;\nusing namespace __gnu_cxx;\n \ntypedef long long ll;\ntypedef long double ld;\ntypedef complex cd;\n\ntypedef pair pi;\ntypedef pair pl;\ntypedef pair pd;\n\ntypedef vector vi;\ntypedef vector vd;\ntypedef vector vl;\ntypedef vector vpi;\ntypedef vector vpl;\ntypedef vector vcd;\n\ntemplate using Tree = tree, rb_tree_tag,tree_order_statistics_node_update>;\n\n#define FOR(i, a, b) for (int i=a; i<(b); i++)\n#define F0R(i, a) for (int i=0; i<(a); i++)\n#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)\n#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)\n\n#define sz(x) (int)(x).size()\n#define mp make_pair\n#define pb push_back\n#define f first\n#define s second\n#define lb lower_bound\n#define ub upper_bound\n#define all(x) x.begin(), x.end()\n\nconst int MOD = 1000000007;\nconst ll INF = 1e18;\nconst int MX = 100001;\n\nnamespace io {\n void setIn(string s) { freopen(s.c_str(),\"r\",stdin); }\n void setOut(string s) { freopen(s.c_str(),\"w\",stdout); }\n void setIO(string s = \"\") {\n ios_base::sync_with_stdio(0); cin.tie(0);\n if (sz(s)) { setIn(s+\".in\"), setOut(s+\".out\"); }\n }\n \n // double input seems slow on CF\n void re(double& x) { string t; cin >> t; x = stod(t); } \n void re(ld& x) { string t; cin >> t; x = stold(t); }\n template void re(T& x) { cin >> x; }\n template void re(Arg& first, Args&... rest) { re(first); re(rest...); }\n \n\t// pair\n\ttemplate istream& operator>>(istream& is, pair& p) {\n\t is >> p.f >> p.s;\n\t return is;\n\t}\n\ttemplate ostream& operator<<(ostream& os, const pair& a) {\n\t os << '{' << a.f << \", \" << a.s << '}';\n\t return os;\n\t}\n\t\n // vector\n\ttemplate istream& operator>>(istream& is, vector& a) {\n\t int sz; is >> sz; a.resize(sz);\n\t F0R(i,sz) is >> a[i];\n\t return is;\n\t}\n\ttemplate ostream& operator<<(ostream& os, const vector& a) {\n\t os << \"{\";\n\t F0R(i,sz(a)) {\n\t if (i) os << \", \";\n\t os << a[i];\n\t }\n\t os << \"}\";\n\t return os;\n\t}\n}\n\nusing namespace io;\n\nmap m, key;\n\nll cross(pi O, pi A, pi B) {\n return (ll)(A.f-O.f)*(B.s-O.s)\n -(ll)(A.s-O.s)*(B.f-O.f);\n}\n\nvpi convex_hull(vpi P) {\n sort(all(P)); P.erase(unique(all(P)),P.end());\n int n = sz(P);\n if (n == 1) return P;\n \n vpi bot = {P[0]};\n FOR(i,1,n) {\n while (sz(bot) > 1 && cross(bot[sz(bot)-2], bot.back(), P[i]) <= 0) bot.pop_back();\n bot.pb(P[i]);\n }\n bot.pop_back();\n \n vpi up = {P[n-1]};\n F0Rd(i,n-1) {\n while (sz(up) > 1 && cross(up[sz(up)-2], up.back(), P[i]) <= 0) up.pop_back();\n up.pb(P[i]);\n }\n up.pop_back();\n \n bot.insert(bot.end(),all(up));\n return bot;\n}\n\nint n;\n\nvpi v, c;\nvi col;\nvpi ans;\n\nvoid addEdge(pi a, pi b) {\n ans.pb({key[a],key[b]});\n}\n\nint area(pi a, pi b, pi c) {\n b.f -= a.f, b.s -= a.s;\n c.f -= a.f, c.s -= a.s;\n return abs(b.f*c.s-b.s*c.f);\n}\n\nbool in(pi a, pi b, pi c, pi z) {\n return area(a,b,z)+area(b,c,z)+area(c,a,z) == area(a,b,c);\n}\n\nvoid go(pi a, pi b, pi c, vpi res) {\n for (auto t: res) if (m[t] == m[a]) {\n addEdge(a,t);\n vpi x,y,z;\n for (auto T: res) if (T != t) {\n if (in(c,a,t,T)) x.pb(T);\n else if (in(b,a,t,T)) y.pb(T);\n else z.pb(T);\n }\n go(c,a,t,x);\n go(b,a,t,y);\n go(t,b,c,z);\n return;\n }\n for (auto t: res) addEdge(b,t);\n}\n\nvoid solveTri(pi a, pi b, pi c) {\n vpi res;\n for (auto z: v) if (z != a && z != b && z != c && in(a,b,c,z)) res.pb(z);\n go(a,b,c,res);\n}\n\nvoid solveDif() {\n int cur = 0; while (col[cur] == 1) cur ++;\n while (col[cur] == 0) cur = (cur+1)%sz(col);\n while (col[cur] == 1) cur = (cur+1)%sz(col);\n rotate(c.begin(),c.begin()+cur,c.end());\n rotate(col.begin(),col.begin()+cur,col.end());\n \n cur = 0; while (col[cur] == 0) cur ++;\n FOR(i,1,cur) {\n addEdge(c[i],c[i-1]);\n solveTri(c[cur],c[i],c[i-1]);\n }\n /*cout << col << \"\\n\";\n cout << sz(c) << \"\\n\" << cur << \"\\n\";\n \n cout << ans << \"\\n\";*/\n \n FOR(i,cur+1,sz(col)) {\n addEdge(c[i],c[i-1]);\n solveTri(c[0],c[i],c[i-1]);\n }\n}\n\nvoid solveEq() {\n F0R(i,sz(c)-1) addEdge(c[i],c[i+1]);\n for (auto a: v) if (m[a] != col[0]) {\n F0R(i,sz(c)) solveTri(a,c[i],c[(i+1)%sz(c)]);\n return;\n }\n map bad;\n for (auto a: c) bad[a] = 1;\n for (auto a: v) if (!bad[a]) addEdge(c[0],a);\n}\n\nint main() {\n setIO(); re(n);\n \n F0R(i,n) {\n int x,y,c; re(x,y,c);\n m[{x,y}] = c;\n key[{x,y}] = i;\n v.pb({x,y});\n }\n \n c = convex_hull(v);\n for (auto a: c) col.pb(m[a]);\n int dif = 0;\n F0R(i,sz(col)) if (col[i] != col[(i+1)%sz(col)]) dif ++;\n if (dif > 2) {\n cout << \"Impossible\";\n exit(0);\n }\n bool o = 0;\n for (int i: col) if (i != col[0]) o = 1;\n if (o) solveDif();\n else solveEq();\n cout << sz(ans) << \"\\n\";\n for (auto a: ans) cout << a.f << \" \" << a.s << \"\\n\";\n}\n\n/* \n* (Actually read this pls)\n * Rlly bad errors: int overflow, array bounds\n * Less bad errors: special cases (n=1?), set tle\n * Common sense: do smth instead of nothing\n*/", "src_uid": "3bc096d8cd3418948d5be6bf297aa9b5"} {"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\nusing namespace std;\n\n#define fo(i,n) for(int i=0; i<(int)n; i++)\n#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)\n#define mp(a,b) make_pair(a,b)\n#define pb(x) push_back(x)\n#define pii pair\n\n#define mod 1000000007LL\n\nlong long dp[101][10010];\nint n,k;\nlong long m;\nlong long c[101][101];\nlong long p[101][101][101];\n\nlong long fpow(long long a, long long b) {\n if (b==0) return 1LL;\n long long tmp = fpow(a,b/2LL);\n tmp = (tmp*tmp)%mod;\n if (b%2==0) return tmp;\n return (tmp*a)%mod;\n}\n\nint main() {\n\n //freopen(\"input.txt\",\"r\",stdin);\n //freopen(\"output.txt\",\"w\",stdout);\n\n cin>>n>>m>>k;\n \n for (int i=0; i<=100; i++) {\n c[i][0] = 1;\n c[i][i] = 1;\n for (int j=1; j\n\n#define pb push_back\n#define pp pop_back\n#define mp make_pair\n#define ld long double\n#define f first\n#define s second\n#define ll long long\n\nusing namespace std;\n\nconst int N = 1e5 + 5;\n\nconst int mod = 1e9 + 7;\n\nll a1, a2, b1, b2, l, r;\n\nll gcd (ll a, ll b, ll & x, ll & y) {\n\tif (a == 0) {\n\t\tx = 0; y = 1;\n\t\treturn b;\n\t}\n\tll x1, y1;\n\tll d = gcd (b%a, a, x1, y1);\n\tx = y1 - (b / a) * x1;\n\ty = x1;\n\treturn d;\n}\n \nbool find_any_solution (ll a, ll b, ll c, ll & x0, ll & y0, ll & g) {\n\tg = gcd (abs(a), abs(b), x0, y0);\n\tif (c % g != 0)\n\t\treturn false;\n\tx0 *= c / g;\n\ty0 *= c / g;\n\tif (a < 0) x0 *= -1;\n\tif (b < 0) y0 *= -1;\n\treturn true;\n}\n\nvoid shift_solution (ll & x, ll & y, ll a, ll b, ll cnt) {\n\tx += cnt * b;\n\ty -= cnt * a;\n}\n \nll find_all_solutions (ll a, ll b, ll c, ll minx, ll maxx, ll miny, ll maxy) {\n\tll x, y, g;\n\tif (! find_any_solution (a, b, c, x, y, g))\n\t\treturn 0;\n\ta /= g; b /= g;\n \n\tll sign_a = a>0 ? +1 : -1;\n\tll sign_b = b>0 ? +1 : -1;\n \n\tshift_solution (x, y, a, b, (minx - x) / b);\n\tif (x < minx)\n\t\tshift_solution (x, y, a, b, sign_b);\n\tif (x > maxx)\n\t\treturn 0;\n\tll lx1 = x;\n \n\tshift_solution (x, y, a, b, (maxx - x) / b);\n\tif (x > maxx)\n\t\tshift_solution (x, y, a, b, -sign_b);\n\tll rx1 = x;\n \n\tshift_solution (x, y, a, b, - (miny - y) / a);\n\tif (y < miny)\n\t\tshift_solution (x, y, a, b, -sign_a);\n\tif (y > maxy)\n\t\treturn 0;\n\tll lx2 = x;\n \n\tshift_solution (x, y, a, b, - (maxy - y) / a);\n\tif (y > maxy)\n\t\tshift_solution (x, y, a, b, sign_a);\n\tll rx2 = x;\n \n\tif (lx2 > rx2)\n\t\tswap (lx2, rx2);\n\tll lx = max (lx1, lx2);\n\tll rx = min (rx1, rx2);\n \n\treturn (rx - lx) / abs(b) + 1;\n}\n\nvoid get(ll a, ll b, ll low, ll high, ll &al, ll &ar)\n{\n al = (low - b) / a;\n if (1ll * al * a + b < low) al++;\n ar = (high - b) / a;\n if (1ll * ar * a + b > high) ar--;\n}\n\nint main()\n{\n ios_base::sync_with_stdio(0);\n\t\n clock_t start = clock();\n\n cin >> a1 >> b1 >> a2 >> b2 >> l >> r;\n ll l1, r1, l2, r2;\n get(a1, b1, l, r, l1, r1);\n get(a2, b2, l, r, l2, r2);\n// cout << l1 << \" \" << r1 << \" \" << l2 << \" \" << r2 << endl;\n if (l1 > r1 || l2 > r2 || r1 < 0 || r2 < 0) cout << 0 << endl;\n else\n {\n l1 = max(l1, 0ll);\n l2 = max(l2, 0ll);\n r1 = max(r1, 0ll);\n r2 = max(r2, 0ll);\n cout << find_all_solutions(a1, -a2, b2 - b1, l1, r1, l2, r2) << endl;\n }\n\n double duration = ((double) clock() - start) / (double) CLOCKS_PER_SEC;\n// cout << \"Time: \" << fixed << setprecision(10) << duration << endl;\n\t\n return 0;\n}", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4"} {"source_code": "#include \n#include \n#include \n#include \n#include \n\nusing std::vector;\n\nint main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\tvector seq(n + 1);\n\tfor (int i = 1; i <= n; i++) {\n\t\tscanf(\"%d\", &seq[i]);\n\t}\n\n\tconst int INF = INT_MAX - 1;\n\tvector>>> dp(n + 1, vector>>(n + 2, vector>(n + 2, vector(2, INF)))); // [i][nOdds][nEvens][last 0/1] -> cnt\n\tfor (int nEvens = 0; nEvens <= n; nEvens++) {\n\t\tfor (int nOdds = 0; nOdds <= n; nOdds++) {\n\t\t\tdp[0][nEvens][nOdds][0] = 0;\n\t\t\tdp[0][nEvens][nOdds][1] = 0;\n\t\t}\n\t}\n\n\tfor (int i = 1; i <= n; i++) {\n\t\tfor (int nEvens = 0; nEvens <= i; nEvens++) {\n\t\t\tint nOdds = i - nEvens;\n\n\t\t\tint e_last_even = nEvens == 0 ? INF : dp[i - 1][nEvens - 1][nOdds][0];\n\t\t\tint e_last_odd = nEvens == 0 ? INF : dp[i - 1][nEvens - 1][nOdds][1];\n\t\t\tint o_last_even = nOdds == 0 ? INF : dp[i - 1][nEvens][nOdds - 1][0];\n\t\t\tint o_last_odd = nOdds == 0 ? INF : dp[i - 1][nEvens][nOdds - 1][1];\n\t\t\tif (!seq[i]) {\n\t\t\t\tdp[i][nEvens][nOdds][0] = std::min(e_last_even, e_last_odd + 1);\n\t\t\t\tdp[i][nEvens][nOdds][1] = std::min(o_last_even + 1, o_last_odd);\n\t\t\t} else if (seq[i] % 2) {\n\t\t\t\tdp[i][nEvens][nOdds][1] = std::min(o_last_even + 1, o_last_odd);\n\t\t\t} else {\n\t\t\t\tdp[i][nEvens][nOdds][0] = std::min(e_last_even, e_last_odd + 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tint ans = std::min(dp[n][n / 2][n / 2 + (n % 2)][0], dp[n][n / 2][n / 2 + (n % 2)][1]);\n\tprintf(\"%d\", ans);\n\treturn 0;\n}", "src_uid": "90db6b6548512acfc3da162144169dba"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\nint main()\n{\n\tstring s;\n\tcin >> s;\n\tfor (int i = 0; i < s.size(); i++)\n\t{\n\t\ts[i] = tolower(s[i]);\n\t\tif (!(s[i] == 'e' || s[i] == 'y' ||\n\t\t\t s[i] == 'u' || s[i] == 'i' ||\n\t\t\t s[i] == 'a' || s[i] == 'o'))\n\t\t\tcout << '.' << s[i];\n\n\t}\n\tcout << endl;\n\n\treturn 0;\n}", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"source_code": "// iostream is too mainstream\r\n#include \r\n// bitch please\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#define dibs reserve\r\n#define OVER9000 1234567890\r\n#define tisic 47\r\n#define soclose 1e-8\r\n#define patkan 9\r\n#define ff first\r\n#define ss second\r\nusing uint = unsigned int;\r\nusing cat = long long;\r\nusing dbl = long double;\r\nconstexpr dbl pi = 3.14159265358979323846;\r\nusing namespace std;\r\n\r\n#ifdef DONLINE_JUDGE\r\n\t// palindromic tree is better than splay tree!\r\n\t#define lld I64d\r\n#endif\r\n\r\ntemplate \r\nT abs(T x) { return (x < 0) ? (-x) : x; }\r\n\r\ncat gcd(cat a, cat b) {\r\n\tif(a > b) swap(a, b);\r\n\twhile(a) {\r\n\t\tcat c = b%a;\r\n\t\tb = a;\r\n\t\ta = c;\r\n\t}\r\n\treturn b;\r\n}\r\n\r\ncat pw(cat a, cat e, cat mod) {\r\n\tif(e <= 0) return 1;\r\n\tcat x = pw(a, e/2, mod);\r\n\tx = x * x % mod;\r\n\treturn (e&1) ? x * a % mod : x;\r\n}\r\n\r\ntemplate \r\nclass fin {\r\n\tvector node_val;\r\n\r\n\tint lastone(int x) { return x & (x ^ (x-1)); }\r\n\r\npublic:\r\n\tfin(int N, T init_val) {\r\n\t\tnode_val.resize(N+10, init_val);\r\n\t}\r\n\r\n\tvoid put(int pos, T val) {\r\n\t\tfor(int i = pos+1; i < (int)node_val.size(); i += lastone(i))\r\n\t\t\tnode_val[i] += val;\r\n\t}\r\n\r\n\tT get(int pos) {\r\n\t\tT ret = 0;\r\n\t\tfor(int i = pos+1; i > 0; i -= lastone(i))\r\n\t\t\tret += node_val[i];\r\n\t\treturn ret;\r\n\t}\r\n};\r\n\r\nint main() {\r\n\tios_base::sync_with_stdio(0);\r\n\tcin.tie(0);\r\n\tcout.tie(0);\r\n\tcout << fixed << setprecision(12);\r\n\tint N;\r\n\tcin >> N;\r\n\tconstexpr cat mod = 998244353;\r\n\tconstexpr cat inv2 = (mod+1)/2;\r\n\tconstexpr cat inv3 = (mod+1)/3;\r\n\tvector cnt_arb(N+1, 0);\r\n\tcnt_arb[0] = 1;\r\n\tfor(int i = 1, s = 0; i <= N; i++) {\r\n\t\tcnt_arb[i] = (1 + s + (cnt_arb[i-1] + 1) * inv2) % mod * cnt_arb[i-1] % mod;\r\n\t\ts += cnt_arb[i-1];\r\n\t\tif(s >= mod) s -= mod;\r\n\t}\r\n\tcat ans = (2 * cnt_arb[N] - cnt_arb[N-1]) % mod;\r\n\tans = (ans + inv3 * cnt_arb[N-1] % mod * (cnt_arb[N-1]+1) % mod * (cnt_arb[N-1]+2)) % mod;\r\n\tcat s = 0;\r\n\tfor(int i = 0; i < N-1; i++) s += cnt_arb[i];\r\n\ts %= mod;\r\n\tans = (ans + s * (s+1) % mod * cnt_arb[N-1] + s * cnt_arb[N-1] % mod * (cnt_arb[N-1]+1)) % mod;\r\n\tfor(int i = 1; i < N; i++) ans = (ans + 1LL * cnt_arb[N-1-i] * (cnt_arb[i] - cnt_arb[i-1])) % mod;\r\n\tif(ans < 0) ans += mod;\r\n\tcout << ans << \"\\n\";\r\n}\r\n\r\n// look at my code\r\n// my code is amazing\r\n", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2"} {"source_code": "#include \n#define fs first\n#define sc second\n\nusing namespace std;\n\nconst int inf = 1000 * 1000 * 1000 + 228;\n\nint main() {\n ios_base::sync_with_stdio(false);\n int n;\n cin >> n;\n set > st;\n for (int i = 0; i < n; i++) {\n int l, r;\n cin >> l >> r;\n auto it = st.lower_bound({l, inf});\n if (it != st.begin()) {\n it--;\n pair p = *it;\n if (p.sc >= l) {\n st.erase(it);\n l = p.fs;\n r = max(r, p.sc);\n }\n }\n while (1) {\n it = st.lower_bound({l, -1});\n if (it != st.end()) {\n pair p = *it;\n if (p.fs <= r) {\n st.erase(it);\n r = max(r, p.sc);\n } else {\n st.insert({l, r});\n break;\n }\n } else {\n st.insert({l, r});\n break;\n }\n }\n cout << st.size() << '\\n';\n }\n return 0;\n}\n", "src_uid": "3979abbe7bad0f3b5cab15c1cba19f6b"} {"source_code": "#include\n\n#include\n#include\n#include\n#include\n#include\n#define MOD 1000000007\n#define MAXN 55\nusing namespace std;\nstruct node\n{\n int n1,n2,t;\n}h,p;\n__int64 dis[MAXN][MAXN][2],methods[MAXN][MAXN][2];\nqueue Q;\nint n,k;\n\n__int64 Cal(int r,int l)\n{\n __int64 result=1;\n for(int i=1;i<=l;i++)\n result=(result*(r-i+1)/i)%MOD;\n return result;\n}\n\nint main()\n{ \n int i,j;\n while (~scanf(\"%d%d\",&n,&k))\n { \n int n1,n2;\n n1=n2=0;\n for (i=1;i<=n;i++)\n {\n int W;\n scanf(\"%d\",&W);\n if (W==50) n1++; else n2++;\n }\n memset(dis,0,sizeof(dis));\n memset(methods,0,sizeof(methods));\n dis[n1][n2][0]=1;\n methods[n1][n2][0]=1;\n h.n1=n1,h.n2=n2,h.t=0;\n while (!Q.empty()) Q.pop();\n Q.push(h);\n while (!Q.empty())\n {\n h=Q.front();\n Q.pop();\n for (j=0;j<=h.n2;j++)\n {\n // if (j*100>k) break;\n for (i=0;i<=h.n1;i++)\n {\n if (!j && !i) continue;\n if (i*50+j*100>k) break; \n p.n1=n1-h.n1+i,p.n2=n2-h.n2+j,p.t=1-h.t; \n if (!dis[p.n1][p.n2][p.t])\n {\n Q.push(p);\n dis[p.n1][p.n2][p.t]=dis[h.n1][h.n2][h.t]+1;\n for(int l=0;l<20000000;l++)\n {\n int sum=0;\n \n sum+=l;\n \n }\n } \n if (dis[p.n1][p.n2][p.t]==dis[h.n1][h.n2][h.t]+1)\n {\n \n __int64 t; \n t=(Cal(h.n1,i)*Cal(h.n2,j))%MOD;\n t=(t*methods[h.n1][h.n2][h.t])%MOD;\n methods[p.n1][p.n2][p.t]=(methods[p.n1][p.n2][p.t]+t)%MOD;\n }\n }\n } \n }\n printf(\"%I64d\\n%I64d\\n\",dis[n1][n2][1]-1,methods[n1][n2][1]);\n for(int l=0;l<1000000;l++)\n {\n int sum=0;\n for(int lm=0;l<1000000;l++)\n {\n \n sum+=lm;\n }\n }\n\n } \n return 0;\n}", "src_uid": "ebb0323a854e19794c79ab559792a1f7"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define prev asasdasd\n#define next aasdasda\n#define rank asdasdknlasd\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef long double dbl;\n\ntemplate\nvoid print(vector s){\n\tfor (T x : s)\n\t\tcout << x << \" \";\n\tcout << endl;\n}\n\nvector p;\nvector > can;\nvector v;\nint maxi = 1e8;\n\nvoid gen(ll s, int cur, int prev, int now){\n\tif (s > maxi)\n\t\treturn;\n\tcan.push_back(v);\n\tif (now + 1 <= prev){\n\t\tv[cur]++;\n\t\tgen(s * p[cur], cur, prev, now + 1);\n\t\tv[cur]--;\n\t}\n\tif (now > 0){\n\t\tfor (int i = cur + 1; i < p.size(); i++){\n\t\t\tv[i]++;\n\t\t\tgen(s * p[i], i, now, 1);\n\t\t\tv[i]--;\n\t\t}\n\t}\n}\n\nconst int MAX = 6100;\nconst int MAXC = 200;\nint dist[MAX][MAXC];\n\nint cnt(int x){\n\tint answer = 1;\n\tfor (int i = 0; i < 8; i++)\n\t\tanswer *= can[x][i] + 1;\n\treturn answer;\n}\n\nint color[MAX];\nmap, int> mapa;\n\nvoid precalc(){\n\tp = {2, 3, 5, 7, 11, 13, 17};\n\tv.resize(8);\n\tgen(1, 0, 100, 0);\n\tint n = can.size();\n\tfor (int i = 0; i < n; i++)\n\t\tmapa[can[i]] = i;\n\tfor (int i = 0; i < n; i++)\n\t\tfill(dist[i], dist[i] + MAXC, MAX);\n\tvector diff;\n\tfor (int i = 0; i < n; i++)\n\t\tdiff.push_back(cnt(i));\n\tsort(diff.begin(), diff.end());\n\tdiff.resize(unique(diff.begin(), diff.end()) - diff.begin());\n\t// cout << n << \" \" << diff.size() << endl;\n\tfor (int i = 0; i < n; i++)\n\t\tcolor[i] = lower_bound(diff.begin(), diff.end(), cnt(i)) - diff.begin();\n\tfor (int i = 0; i < n; i++)\n\t\tfill(dist[i], dist[i] + MAXC, MAX);\n\tfor (int i = 0; i < n; i++){\n\t\tfor (int j = 0; j < n; j++){\n\t\t\tint d = 0;\n\t\t\tfor (int l = 0; l < 8; l++)\n\t\t\t\td += abs(can[i][l] - can[j][l]);\n\t\t\tdist[i][color[j]] = min(dist[i][color[j]], d);\n\t\t}\n\t}\n}\n\nint translate(int a){\n\tif (a == 1)\n\t\treturn 0;\n\tint b = 2;\n\tvector power;\n\twhile (b * b <= a){\n\t\tif (a % b == 0){\n\t\t\tint cnt = 0;\n\t\t\twhile (a % b == 0){\n\t\t\t\tcnt++;\n\t\t\t\ta /= b;\n\t\t\t}\n\t\t\tpower.push_back(cnt);\n\t\t}\n\t\tb++;\n\t}\n\tif (a > 1)\n\t\tpower.push_back(1);\n\tsort(power.begin(), power.end());\n\treverse(power.begin(), power.end());\n\twhile (power.size() < 8)\n\t\tpower.push_back(0);\n\treturn mapa[power];\n}\n\n\nint main() {\t\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\t// freopen(\"test.in\", \"r\", stdin);\n\tprecalc();\n\tint n;\n\tcin >> n;\n\twhile (n-- > 0){\n\t\tint a, b;\n\t\tcin >> a >> b;\n\t\ta = translate(a);\n\t\tb = translate(b);\n\t\t// cout << a << \" \" << b << endl;\n\t\t// print(can[a]);\n\t\t// print(can[b]);\n\t\tint answer = MAX;\n\t\tfor (int i = 0; i < MAXC; i++)\n\t\t\tanswer = min(answer, dist[a][i] + dist[b][i]);\n\t\tcout << answer << endl;\n\t}\n\treturn 0;\n}", "src_uid": "6115ee1ccf651b1dd8145bf755ea7ea9"} {"source_code": "#include \n#include \nint main()\n{\n int i,j,k,l,m;\n char s[55];\n scanf(\"%s\",&s);\n l=strlen(s);\n m=l;\n l=l-1;\n j=l/2;\n k=j+1;\n if(m%2==1)\n {\n while(j>=1)\n {\n printf(\"%c%c\",s[j],s[k]);\n j--;\n k++;\n }\n printf(\"%c\",s[0]);\n }\n else if(m%2==0)\n {\n while(j>=0)\n {\n printf(\"%c%c\",s[j],s[k]);\n j--;\n k++;\n }\n\n }\n\n}\n", "src_uid": "992ae43e66f1808f19c86b1def1f6b41"} {"source_code": "/**\n * author : azhar556\n * 28 October 2018 2:45 AM (+7)\n**/\n\n#include \n#define pb(a) push_back(a)\n#define all(a) (a).begin(), (a).end()\n\nusing namespace std;\n\ntypedef double db;\ntypedef long long i64;\n\nconst int MAX = 1e9 + 7;\nconst db PI = 3.1415926535;\n\nvoid solve() \n{\n\tint a, b, c;\n\tcin >> a >> b >> c;\n\t\n\tint res = -1;\n\tfor (int i = 1; i <= 100000; i++)\n\t{\n\t\ta *= 10;\n\t\tif (a / b == c)\n\t\t{\n\t\t\tres = i; break;\n\t\t}\n\t\ta %= b;\n\t}\n\t\n\tcout << res;\n}\n\nint main()\n{\n\tios::sync_with_stdio(0);\n\tcin.tie(0);\n\t\n\tsolve();\t\n\t\n\tcerr << endl << \"Time elapsed: \" << 1.0 * clock() / CLOCKS_PER_SEC << \"s.\\n\";\n\treturn 0;\n}", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"} {"source_code": "#include\n#include\n#include\n#include\n\nusing namespace std;\ntypedef long long LL;\nconst int MX=51,md=1000000007;\nint n,d[MX];\nint fac[MX],inv[MX],facinv[MX];\n\nint f[MX][MX],g[MX][MX][MX];\n#define C(x,y) ((LL)fac[x]*facinv[y]%md*facinv[x-y]%md)\nvoid ini(){\n\tfac[0]=facinv[0]=1;\n\tinv[1]=1;for(int i=2;i<=n;i++)inv[i]=(LL)inv[md%i]*(md-md/i)%md;\n\tfor(int i=1;i<=n;i++)fac[i]=(LL)fac[i-1]*i%md;\n\tfor(int i=1;i<=n;i++)facinv[i]=(LL)facinv[i-1]*inv[i]%md;\n\tg[0][0][0]=1;\n\tfor(int i=0;i<=n;i++)\n\t\tfor(int j=0;j<=n-i;j++)if(i||j){\n\t\t\tif(!i){\n\t\t\t\tfor(int k=2;k=2)g[0][i][j]=(g[0][i][j]+(LL)g[0][i-2][j]*(i-1)%md)%md;\n\t\t\t\tif(j>=1)g[0][i][j]=(g[0][i][j]+(LL)g[0][i][j-1]*j%md)%md;\n\t\t\t}\n\t\t}\n\tfor(int i=1;i\n\n\nusing namespace std;\n\nchar check[10]={'a','e','i','o','u','1','3','5','7','9'};\n\nint main()\n{\n string s;\n cin>>s;\n int ans=0;\n for(int i=0;i\nusing namespace std;\n\nstatic long long inf = (1LL << 58LL);\nstatic long long F[6];\nstatic long long ten[6] = {1, 10, 100, 1000, 10000, 100000};\nstatic long long dp[1000005];\nint N, K;\n\nint main(){\n\tcin >> K;\n\tfor(int i = 0;i <= 5;i++) cin >> F[i];\n\t\n\tint Q; cin >> Q;\n\tassert(Q == 1);\n\t\n\tint N; cin >> N;\n\t\n\t///0-1 knapsack with duplicate elements\n\tfill(dp,dp+N+1,-inf); dp[0] = 0;\n\tfor(int d = 0;d <= 5;d++){\n\t\tlong long left = 3 * (K - 1);\n\t\tlong long group = 1;\n\t\t\n\t\t///grouping 3*(K-1) elements into groups of powers of 2\n\t\twhile(left > 0){\n\t\t\tgroup = min(group, left);\n\t\t\t\n\t\t\tlong long value = group * F[d];\n\t\t\tlong long weight = group * ten[d] * 3;\n\t\t\tfor(int i = N;i >= weight;i--) dp[i] = max(dp[i], dp[i-weight] + value); ///knapsack DP\n\t\t\t\n\t\t\tleft -= group;\n\t\t\tgroup *= 2;\n\t\t}\n\t}\n\t\n\tlong long ans = 0;\n\tfor(int X = 0;X <= N;X++){\n\t\t///calculating the fortune of X\n\t\tlong long fortune = 0;\n\t\tint x = X;\n\t\tfor(int d = 0;d <= 5;d++){\n\t\t\tint rem = x % 10;\n\t\t\tif(rem == 3 || rem == 6 || rem == 9) fortune += (rem / 3) * F[d];\n\t\t\tx /= 10;\n\t\t}\n\t\t\n\t\tans = max(ans, fortune + dp[N-X]);\n\t}\n\t\n\tcout << ans;\n}", "src_uid": "92bcbac3f167a44c235e99afc4de20d2"} {"source_code": "//try2\n#include \nusing namespace std;\n\nint main()\n{\n int n;\n cin >> n;\n int x[n];\n bool endd = false;\n for (int k = 0; k < n; k++)\n cin >> x[k];\n int like;\n while (endd == false)\n {\n for (int k = 0; k < n; k++)\n for (int j = 0; j < n; j++)\n {\n if (x[k]>x[j])\n x[k] = x[k] - x[j];\n if (x[k]\n#include\n#include\n#include\nusing namespace std;\n\ninline int ask(int a1,int a2,int a3){ // 1: a1,a2 2: a2,a3 3: a1,a3;\n printf(\"%d %d %d\\n\",a1,a2,a3);\n fflush(stdout); char c;\n do c=getchar(); while (!(c>='A' && c<='Z'));\n return c=='X'?1:(c=='Y'?2:3);\n}\n\nconst int N=2005;\n\nint n;\nint ncnt,pnt;\nint ls[N],rs[N],ps[N],lc[N],rc[N];\nint size[N],depth[N],sum,minv,rt;\nint del[N];\n\ninline void dfs(int u,int fa){\n size[u]=u<=n; depth[u]=depth[fa]+1; int maxv=0;\n int v;\n v=ls[u];\n if (v && v!=fa && !del[v]){\n dfs(v,u); size[u]+=size[v];\n maxv=max(maxv,size[v]);\n }\n v=rs[u];\n if (v && v!=fa && !del[v]){\n dfs(v,u); size[u]+=size[v];\n maxv=max(maxv,size[v]);\n }\n v=ps[u];\n if (v && v!=fa && !del[v]){\n dfs(v,u); size[u]+=size[v];\n maxv=max(maxv,size[v]);\n }\n maxv=max(maxv,sum-size[u]);\n if (u>n && maxv\nusing namespace std;\ntypedef long long ll;\n\nconst int MOD = 998244353;\n\nll dp[2][505][505][2];\nll gp[2][505][505][2];\nll qp[505];\n\nvoid test_case() {\n int n, k;\n scanf(\"%d%d\", &n, &k);\n int ck = min(n, k);\n dp[1][1][1][0] = 1;\n dp[1][1][1][1] = 1;\n gp[1][1][1][0] = 1;\n gp[1][1][1][1] = 1;\n for(int i = 2; i <= n; ++i) {\n int t = i & 1;\n int cj = min(i, ck);\n for(int j = 1; j <= cj; ++j) {\n dp[t][j][1][0] = gp[1 - t][j][j][1];\n dp[t][j][1][1] = gp[1 - t][j][j][0];\n for(int l = 2; l <= j; ++l) {\n dp[t][j][l][0] = dp[1 - t][j][l - 1][0];\n dp[t][j][l][1] = + dp[1 - t][j][l - 1][1];\n if(l == j) {\n dp[t][j][l][0] += dp[1 - t][j - 1][l - 1][0];\n dp[t][j][l][1] += dp[1 - t][j - 1][l - 1][1];\n }\n }\n for(int l = 1; l <= j; ++l) {\n dp[t][j][l][0] %= MOD;\n dp[t][j][l][1] %= MOD;\n gp[t][j][l][0] = (gp[t][j][l - 1][0] + dp[t][j][l][0]) % MOD;\n gp[t][j][l][1] = (gp[t][j][l - 1][1] + dp[t][j][l][1]) % MOD;\n }\n }\n }\n\n int t = n & 1;\n for(int j = 1; j <= ck; ++j)\n qp[j] = (qp[j - 1] + gp[t][j][j][0]) % MOD;\n\n ll ans = 0;\n for(int i = 1; i <= ck; ++i)\n ans += (gp[t][i][i][0] + gp[t][i][i][1]) % MOD * qp[min(ck, k / i - (k % i == 0))] % MOD;\n\n ans %= MOD;\n printf(\"%lld\\n\", ans);\n}\n\nint main() {\n#ifdef KisekiPurin\n freopen(\"KisekiPurin.in\", \"r\", stdin);\n#endif // KisekiPurin\n int t = 1;\n //scanf(\"%d\", &t);\n for(int ti = 1; ti <= t; ++ti) {\n //printf(\"Case #%d: \", ti);\n test_case();\n }\n}\n\n/*\n 1. С���������˻���\n ����Ϊ0��1�᲻������������������ı�����С��Ҫ�������㣬ǿ��ͨ�����������һ����ȵȡ�\n 2. �ڴ棺\n �ڴ�Ŀռ���û�п�������ʱ�з���ߣ���ʱ�ж����¼ӵıߡ��߶�������4������\n �ɳ־û����ݽṹ�᲻���ڴ��������������ʱvector�᲻�ᷭ�����ַ���Сд�п�����\n ���������н��г�ʼ����memset�᲻�ᷭ����\n 3. ���������\n �˷�������ˣ�����ȡģ�ˣ������������%d�����޷�����Խ�������ˣ�\n 4. ϰ�ߣ�\n ��������ָ������ֵ�𣿷���ֵ��void������ÿһ����֧������ʽ�ķ���ֵ��ȷ���������ķ�֧����assertһ�ѡ�\n Yes��No��û�з�����Сд��û�д���û�и��n��m����ɢ��֮���cn��û�д����кͿո�Ҫ��ô����priorityҪ�ѷ��ŷ�������\n 5. ����bug��\n �����������ӻ����������ӻ���\n*/\n", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"} {"source_code": "/**\n\t试问岭南应不好,却道,此心安处是吾乡。\n**/\n//#pragma comment(linker, \"/STACK:1024000000,1024000000\")\n#include \n#include \n#include \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:1024000000,1024000000\")\n\nusing namespace std;\n\n#define lson l, m, rt<<1\n#define rson m+1, r, rt<<1|1\n#define inf 1e9\n#define debug(a) cout << #a\" = \" << (a) << endl;\n#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a\"[\" << i << \"] = \" << (a)[i] << endl; }\n#define clr(x, y) memset(x, y, sizeof x)\n#define ll long long\n#define ull unsigned long long\n#define FOR(i,a,b) \\\n\tfor(i=a;a=b;a>1;\n\t\tif(mid*2+c<=x)\n\t\t{\n\t\t\tans = max(ans,mid);\n\t\t\tl=mid+1;\n\t\t}\n\t\telse r = mid-1;\n\t}\n\treturn ans;\n}\n\nint main()\n{\n//\tfreopen(\"input.txt\",\"r\",stdin);\n\tint x1,x2,y1,y2;\n\twhile(~scanf(\"%d%d%d%d\",&x1,&y1,&x2,&y2))\n\t{\n\t\tif( (y1-x1)%2 )\n\t\t{y1--;y2--;}\n\t\tll ans;\n\t\tint t = (x2-x1)/2;\n\t\tif(x1%2)\n\t\t\tans = (ll)(cal(y2,1)-cal(y1-1,1)) * (t+1) + (ll)(cal(y2,0)-cal(y1-1,0)) * t;\n\t\telse\n\t\t\tans = (ll)(cal(y2,1)-cal(y1-1,1)) * t + (ll)(cal(y2,0)-cal(y1-1,0)) * (t+1);\n\t\tprintf(\"%I64d\\n\",ans);\n\t}\n\treturn 0;\n}\n\n\n", "src_uid": "00cffd273df24d1676acbbfd9a39630d"} {"source_code": "#include \n#include \nusing namespace std;\n\ninline int F(int a, int b) { return a*a + b*b - a*b; }\n\nint main()\n{\n\tint n, m;\n\tscanf(\"%d%d\", &n, &m);\n\tint N = n+1;\n\tlong long res = 0;\n\tfor(int i = m+1; i <= (n+1)/2; ++i) {\n\t\tint p = 0;\n\t\tint j = m+1, k = m+1;\n\t\tint S = 2*i*i + N*(N+j-3*i-k) + i*(j+k) - j*k;\n\t\tint x = i-N, y = i+N;\n\t\tfor( ; j <= n-m; ++j) {\n\t\t\twhile(k <= n-m && S >= 0) {\n\t\t\t\tS += x-j;\n\t\t\t\t++k;\n\t\t\t}\n\t\t\tp += n-m+1-k;\n\t\t\tS += y-k;\n\t\t}\n\t\t\n\t\tif((n & 1) && i == (n+1)/2)\n\t\t\tres += p;\n\t\telse res += 2*p;\n\t}\n\t\n\tprintf(\"%lld\\n\", 3*res);\n\treturn 0;\n}\n", "src_uid": "355cc23d7a4addfc920c6e5e72a2bb64"} {"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\n#define fst first\n#define snd second\n#define all(x) (x).begin(), (x).end()\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 < (int)(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) cerr << #x << \": \" << x << endl;\n#define trace2(x, y) cerr << #x << \": \" << x << \" | \" << #y << \": \" << y << endl;\n#define read ios::sync_with_stdio(false)\n#define unos(x) __builtin_popcount (x)\n#define TAM 1000005\n\nusing namespace std;\n\ntypedef long long int64;\ntypedef vector vi;\ntypedef pair ii;\ntypedef vector vs;\ntypedef vector vii;\n\n\nvoid GCD (int64 a , int64 b , int64& G, int64& x, int64& y){ // G=GCD(a,b)= ax + by\n if(b==0) {G=a; x=1;y=0; }\n else{\n GCD(b,a%b,G,y,x); y-=floor(a/b)*x;\n }\n}\n\nint MCD (int x,int y){\n return (y==0 ? x:MCD(y,x%y));\n}\n \nint MCM(int x ,int y){\n return (x*y/MCD(x,y));\n}\n\nqueue carta1, carta2;\nint aux1[20] , aux2[20];\n\nint main() {\n int n,k1,k2;\n scanf(\"%d\",&n);\n scanf(\"%d\",&k1);\n int cont=0,battles=0;\n FOR(i,k1) scanf(\"%d\",&aux1[i]);\n scanf(\"%d\",&k2);\n FOR(i,k2) scanf(\"%d\",&aux2[i]);\n FOR(i,k1) carta1.push(aux1[i]);\n FOR(i,k2) carta2.push(aux2[i]);\n \n while(carta1.size()!=0 && carta2.size()!=0 ){\n battles++; cont++;\n int auxi1=carta1.front();\n int auxi2=carta2.front();\n carta1.pop();\n carta2.pop(); \n if(auxi1>auxi2){\n carta1.push(auxi2);\n carta1.push(auxi1);\n }\n else if(auxi2>auxi1){\n carta2.push(auxi1);\n carta2.push(auxi2);\n }\n if(cont==1000000){\n printf(\"-1\\n\");\n return 0;\n }\n } \n printf(\"%d \",battles);\n if(carta1.size()==0){\n printf(\"2\\n\");\n }\n if(carta2.size()==0){\n printf(\"1\\n\");\n } \n return 0;\n}", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "#include\n#define For(i,m,n) for(register int i=m;in;i--)\n#define r(a) read(a)\n#define rr(a,b) read(a),read(b)\n#define rrr(a,b,c) read(a),read(b),read(c)\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long Ull;\ntemplate \ninline void read(T &x)\n{\n\tx=0;\n T f=1;\n char ch=getchar();\n\twhile (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}\n\twhile (isdigit(ch)){x=x*10+ch-48;ch=getchar();}\n\tx=x*f;\n}\nconst int MaxN = 50005, MaxM = 4*1e7+500;\nconst int SMALL_INF=1e8;\nconst int MOD=100003;\nint n,m,k;\n\nll C(int x,int y)\n{\n ll res=1;\n For(i,1,y+1){\n res*= x - y + i ;\n res/= i;\n }\n return res;\n}\n\nll fac(int n)\n{\n if(n <= 1){\n return 1;\n }\n return fac(n - 1) * n;\n}\n\nvoid input()\n{\n r(n);\n int k=n/2;\n ll ans = C(n , k) * fac(k) * fac(k) / 2 / k / k;\n cout<\nusing namespace std;\nint main(){\n long long A,B,C,D,x1,y,z,x2;\n long long cnt=0;\n cin>>A>>B>>C>>D;\n if(B+C>D){\n z=D;\n }\n else if(B+C<=D){\n z=B+C;\n }\n while(z>=C){\n x1=z-C+1;\n x2=z-B+1;\n if(x1>=A&&x1<=B){\n if(x2>=B){\n cnt+=((B-x1+1)*(B-x1+2))/2;\n }\n else{\n cnt+=(((B-x1+1)*(B-x1+2))/2)-(((B-(x2+1)+1)*(B-(x2+1)+2))/2);\n }\n }\n else if(x1=B){\n cnt+=((B-A+1)*(B-A+2))/2+(A-x1)*(B-A+1);\n }\n else if(x2>=A&&x2<=B){\n cnt+=(((B-A+1)*(B-A+2))/2)-(((B-(x2+1)+1)*(B-(x2+1)+2))/2)+(A-x1)*(B-A+1);\n }\n else{\n cnt+=(x2-x1+1)*(B-A+1);\n }\n }\n z--;\n }\n cout<\nusing namespace std;\n#define ll long long int \n#define ld long double\n#define fi first\n#define se second\n#define pb push_back\n///*template{{{\n#define sz(x) (ll)x.size()\n#define all(x) x.begin(),x.end()\n#define trav(a,x) for(auto &a:x)\n#define fr(i,a,b) for(ll i=a;i<=b;i++)\n#define fr1(i,a) for(ll i=0;i=a;i--)\n#define frr1(i,a) for(ll i=a-1;i>=0;i--)\n#define sorta(a,n) sort(a,a+n)\n#define sortd(a,n) sort(a,a+n,greater())\n#define sorva(a) sort(a.begin(),a.end())\n#define sortvd(a) sort(a.begin(),a.end(),greater())\n#define tc(t) while(t--)\n#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);\nusing vi= vector;\nusing vvi= vector;\nusing vb =vector;\nusing vc =vector;\nusing vs =vector;\nusing vld =vector;\nusing pii =pair;\nusing psi =pair;\nusing pci =pair;\nusing vpii =vector;\n//}}}template*/\nll const mod=1e9+7;\nll const maxn=1e5+5;\nll const inf=1e18;\nll add(ll a,ll b){\n return ((a%mod)+(b%mod))%mod;\n}\nll mul(ll a,ll b){\n return ((a%mod)*(b%mod))%mod;\n}\nll powm(ll x,ll n,ll M)\n{\n ll result=1;\n while(n>0)\n {\n if(n % 2 ==1)\n result=(result * x)%M;\n x=(x*x)%M;\n n=n/2;\n }\n return result;\n}\nll modinverse(ll a, ll m){\n return powm(a,m-2,m);\n}\nbool prime(ll x){\n if(x<=1)return false;\n for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;\n return true;\n}\nll divisor(ll x){\n ll cnt=0;\n for(int i=1;i<=sqrt(x);i++){\n if(x%i==0){\n if(i!=x/i)cnt+=2;\n else cnt+=1;\n }\n }\n return cnt;\n}\nvector sieve(ll n) { \n bool prim[n+1]; \n memset(prim, true, sizeof(prim)); \n \n for (ll p=2; p*p<=n; p++) {\n if (prim[p] == true) { \n for (int i=p*p; i<=n; i += p) \n prim[i] = false; \n } \n }\n vectorv;\n for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);\n return v; \n}\nll const N=1e6+2;\nll a,b,n;\nll fact[N];\nll inv[N];\nbool check(ll x){\n while(x){\n ll p=x%10;\n if(p!=a and p!=b)return false;\n x/=10;\n }\n return true;\n}\n\nvoid solve(){\n cin>>a>>b>>n;\n inv[0]=1;\n fact[0]=1;\n for(ll i=1;i<=n;i++){\n fact[i]=mul(fact[i-1],i);\n inv[i]=modinverse(fact[i],mod);\n }\n vi v;\n for(int i=0;i<=n;i++){\n if(check(i*a+(n-i)*b))v.pb(i);\n }\n ll ans=0;\n for(auto r:v){\n ans=add(ans,mul(fact[n],mul(inv[r],inv[n-r])));\n }\n cout<>t;\n while(t--){\n solve();\n }\n return 0;\n}", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef long long ll;\n#ifdef WIN32\n#define llf \"%I64d\"\n#else\n#define llf \"%lld\"\n#endif\n#define initIO(pn) freopen(pn \".in\", \"r\", stdin), freopen(pn \".out\", \"w\", stdout)\n#define arrset(p, v) memset(p, v, sizeof(p))\nconst int MAXN = 1e3 + 10;\n\nint n, m;\nll c[MAXN], g[MAXN], a1[MAXN], a2[MAXN], b1[MAXN], b2[MAXN];\n\ninline void work(ll x, int n, ll *d1, ll *d2) {\n\tif (n == 0) {\n\t\td1[n] = d2[n] = 0;\n\t\treturn;\n\t}\n\tif (n == 1) {\n\t\td1[n] = (x == 2); d2[n] = (x == 1);\n\t\treturn;\n\t}\n\tif (x <= c[n - 1]) {\n\t\twork(x, n - 1, d1, d2);\n\t\td1[n] = min(d1[n - 1], d2[n - 1] + 2);\n\t\td2[n] = min(d2[n - 1], d1[n - 1]) + 1 + g[n - 2];\n\t} else {\n\t\twork(x - c[n - 1], n - 2, d1, d2);\n\t\td1[n] = d1[n - 2] + 1;\n\t\td2[n] = d2[n - 2];\n\t}\n}\n\ninline ll dis(ll u, ll v, int n) {\n\tif (n <= 1) return (u != v);\n\tif (u <= c[n - 1]) {\n\t\tif (v > c[n - 1])\n\t\t\treturn min(a1[n - 1], a2[n - 1]) + b1[n - 2] + 1;\n\t\telse\n\t\t\treturn min(dis(u, v, n - 1), min(a1[n - 1] + b2[n - 1], b1[n - 1] + a2[n - 1]) + 2);\n\t} else\n\t\treturn dis(u - c[n - 1], v - c[n - 1], n - 2);\n}\n\nvoid lucky() {\n#ifndef ONLINE_JUDGE\n\tinitIO(\"graph\");\n#endif\n\tscanf(\"%d %d\", &m, &n);\n\tn = min(n, 80); // c[80] = 6e16\n}\n\nint main() {\n\tll u, v;\n\tlucky();\n\tc[0] = 1; c[1] = 2;\n\tfor (int i = 2; i <= n; i++)\n\t\tc[i] = c[i - 1] + c[i - 2];\n\tg[0] = 0; g[1] = g[2] = 1;\n\tfor (int i = 3; i <= n; i++)\n\t\tg[i] = g[i - 2] + 1;\n\twhile (m--) {\n\t\tscanf(llf llf, &u, &v);\n\t\tif (u > v) swap(u, v);\n\t\twork(u, n, a1, a2);\n\t\twork(v, n, b1, b2);\n\t\tprintf(llf \"\\n\", dis(u, v, n));\n\t}\n\treturn 0;\n}\n", "src_uid": "7f9d6c14a77ee73c401c9d9b2b6602fa"} {"source_code": "//#include \"pch.h\"\n#include \n\nusing namespace std;\n\nint main()\n{\n\tint n, i, k = 0, max = 0;\n\tchar k1 = '0';\n\tcin >> n;\n\tint *a = new int[n+1];\n\ta[n] = 1001;\n\tfor (i = 0; i < n; i++) cin >> a[i];\n\tif (a[0] == 1 && a[1] == 2) {\n\t\tk++; \n\t\tk1 = '1';\n\t}\n\tfor (i = 1; i < n + 1; i++) {\n\t\tif (a[i] == a[i - 1] + 1) {\n\t\t\tk++;\n\t\t\tk1 = '1';\n\t\t}\n\t\telse if (k1 == '1') {\n\t\t\tk1 = '0';\n\t\t\tif (max < k) max = k;\n\t\t\tk = 0;\n\t\t}\n\t}\n\tif (max < k) max = k;\n\tif (max!=0) cout << max - 1 << endl;\n\telse cout << \"0\" << endl;\n\tdelete[] a;\n//\tsystem(\"pause\");\n\treturn 0;\n}", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"} {"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 mod 1000000009\n#define LL long long int\nusing namespace std;\nint r,b;\nint points[2][20][2]={0};\nbool flag=false;\nint cha(int x,int y,int x2,int y2)\n{\n if((x*y2-x2*y)>0)return 1;\n else return -1;\n}\nbool connect(int i,int j,int a[])\n{\n int x[2][2]={0};\n int y[2][2]={0};\n x[0][0]=points[0][i][0];\n x[0][1]=points[1][a[i]][0];\n x[1][0]=points[0][j][0];\n x[1][1]=points[1][a[j]][0];\n \n \n y[0][0]=points[0][i][1];\n y[0][1]=points[1][a[i]][1];\n y[1][0]=points[0][j][1];\n y[1][1]=points[1][a[j]][1];\n\n int tmp1=cha(x[1][0]-x[0][0],y[1][0]-y[0][0],x[0][1]-x[0][0],y[0][1]-y[0][0]);\n int tmp2=cha(x[1][1]-x[0][0],y[1][1]-y[0][0],x[0][1]-x[0][0],y[0][1]-y[0][0]);\n \n int tmp3=cha(x[0][0]-x[1][0],y[0][0]-y[1][0],x[1][1]-x[1][0],y[1][1]-y[1][0]);\n int tmp4=cha(x[0][1]-x[1][0],y[0][1]-y[1][0],x[1][1]-x[1][0],y[1][1]-y[1][0]);\n \n if(tmp1*tmp2<0 && tmp3*tmp4<0)return true;\n else return false;\n \n}\nbool check(int a[])\n{\n for(int i=0;i>points[0][i][0]>>points[0][i][1];\n for(int i=0;i>points[1][i][0]>>points[1][i][1];\n bool used[20]={0};\n int a[20]={0};\n matching(a,used,0);\n if(flag)cout<<\"Yes\"<\n#define ll long long\nusing namespace std;\nint main(){\n\tll w1,w2,h1,h2,ans=0;\n\tscanf(\"%lld%lld%lld%lld\",&w1,&h1,&w2,&h2);\n\tans+=w1+w1+h1+h1+h2+h2+4;\n\tprintf(\"%lld\\n\",ans);\n\treturn 0;\n}", "src_uid": "b5d44e0041053c996938aadd1b3865f6"} {"source_code": "#include \nusing namespace std;\nusing ll = long long;\n\nll a[10],ans,w;\n\nvoid knp(int n, ll s){\n\tif(!n){\n\t\tans = max(ans,s);\n\t\treturn;\n\t}\n\tfor(ll k = 8,i=min((w-s)/n,a[n]);k>0&&i>=0;i--,k--){\n\t\tknp(n-1,s+max((ll)0,i*n));\n\t}\n}\n\n\nint main(){\n // freopen(\"input.txt\",\"r\",stdin);\n cin>>w;\n for(int i=1;i<=8;i++){\n \tcin>>a[i];\n }\n knp(8,0);\n cout<\n#define ll long long\n#define F first\n#define S second\n#define P pair\n#define C continue\n#define B break\n#define pb push_back\n#define R return\nusing namespace std;\nll w[100003];\nP w1[200003];\nvector v,ans;\nmap M,M1;\nll a,b,c,n,m,q,k,x,c1,b1;\nll poww(ll x,ll y){\n if (x==0) R 0;\n if (x==1) R 1;\n if (y==0) R 1;\n if (y==1) R x;\n ll d=poww(x,y/2);\n if (y%2) R d*d*x;\n R d*d;\n}\nll l,r,y;\nll inf=-999999999;\nbool anss;\nint main()\n{\n char d='a';\n cin >>n;\n w[2]=1;\n for (int i=3;;i++){\n w[i]=w[i-1]+i-1;\n if (w[i]>100000) {a=i;B;}\n }\n for (int i=a;i>=1;i--){\n if (w[i]<=n){\n n-=w[i];\n for (int j=0;j\nusing namespace std;\nint n,ans;\nvoid dfs(int a, int b, int s) {\n\tif(a<1 || b<1 || s>=ans) return;\n\tif(a==1 && b==1) { ans=min(ans,s); return; }\n\tif(a>b) dfs(a-b,b,s+1);\n\telse dfs(a,b-a,s+1);\n}\nint main() {\n\tscanf(\"%d\",&n);\n\tans=n;\n\tfor(int i=1; i<=n; i++) dfs(i,n,0);\n\tprintf(\"%d\", ans); return 0;\n}\n", "src_uid": "75739f77378b21c331b46b1427226fa1"} {"source_code": "#include\nint mymin(int a,int b)\n{\n if(a>b)\n {\n return b;\n }\n else\n {\n return a;\n }\n}\nint main()\n{\n int n,a[10],b[10],c[10],d[10],i,min1,min2,temp;\n while(~scanf(\"%d\",&n))\n {\n temp=0;\n for(i=1;i<5;i++)\n {\n scanf(\"%d %d %d %d\",&a[i],&b[i],&c[i],&d[i]);\n }\n for(i=1;i<5;i++)\n {\n min1=mymin(a[i],b[i]);\n min2=mymin(c[i],d[i]);\n if(min1+min2<=n)\n {\n temp=i;\n break;\n }\n }\n if(temp)\n {\n printf(\"%d %d %d\\n\",temp,min1,n-min1);\n }\n else\n {\n printf(\"-1\\n\");\n }\n }\n return 0;\n}\n/*2017-04-28 19:18:16.226*/", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"source_code": "#include \ntypedef long long ll;\n#define pb push_back\nusing namespace std;\ntypedef pair pll;\n\n\nll dp[2002][2002];\nll k,pa,pb;\nconst ll mod = 1e9 + 7;\nll ME(ll x,ll nn,ll M)\n{\n ll result=1;\n while(nn>0)\n {\n if(nn % 2 ==1)\n result=(result * x)%M;\n x=(x*x)%M;\n nn=nn/2;\n }\n return result;\n}\nmap cache;\nll inv(ll x)\n{\n if(cache.count(x)) return cache[x];\n return cache[x] = ME(x,mod-2,mod);\n}\nll solve(ll ones, ll ma)\n{\n if(ma >= k) {\n return ma;\n }\n if(ones + ma >= k) {\n ll kk = ones + ma;\n ll ret = (kk*pb + pa)%mod; ret = (ret * inv(pb))%mod;\n return ret;\n }\n if(ones >= 2000 || ma >= 2000) return 0;\n ll &ret = dp[ones][ma];\n if(ret != -1) return ret;\n ret = (pa * solve(ones+1,ma))%mod;\n ret = (ret + (pb * solve(ones, ma+ones))%mod )%mod;\n return ret;\n}\nint main()\n{\n cin >> k >> pa >> pb;\n ll A = pa;\n ll B = pb;\n A = inv(A + B);\n pa = (pa * A)%mod; pb = (pb * A)%mod;\n memset(dp, -1,sizeof dp);\n\n cout << solve(1,0) << endl;\n return 0;\n}\n", "src_uid": "0dc9f5d75143a2bc744480de859188b4"} {"source_code": "#include \nusing namespace std;\n#define debug(x) cout << #x << \": \" << x << endl\ntypedef long long ll;\n\nll getProduct(int freqArr[10]) {\n ll product = 1;\n for (int i = 0; i < 10; i++) {\n product *= freqArr[i];\n }\n return product;\n}\n\nvoid solve() {\n ll k;\n cin >> k;\n int freqArr[10];\n string cf = \"codeforces\";\n for (int i = 0; i < 10; i++) {\n freqArr[i] = 1;\n }\n int index = 0;\n while (getProduct(freqArr) < k) {\n freqArr[index]++;\n index++;\n if (index == 10) index = 0;\n }\n\n for (int i = 0; i < 10; i++) {\n for (int j = 0; j < freqArr[i]; j++) {\n putchar(cf[i]);\n }\n }\n printf(\"\\n\");\n}\n\nint main() {\n // int t;\n // cin >> t;\n // while (t--)\n solve();\n}", "src_uid": "8001a7570766cadcc538217e941b3031"} {"source_code": "#include\r\nusing namespace std;\r\nint a[105];\r\nbool f[200005];\r\nint main(){\r\n\tint n,sum=0;\r\n\tcin>>n;\r\n\tfor(int i=1;i<=n;i++) {\r\n\tcin>>a[i];sum+=a[i];}\r\n\tif(sum&1){\r\n\tcout<<\"0\";\r\n\t\treturn 0;\r\n\t}\r\n\tsum/=2;\r\n\tf[0]=1;\r\n\tfor(int i=1;i<=n;i++)\r\n\t\tfor(int j=sum;j>=a[i];j--)\r\n\t\t\tf[j]|=f[j-a[i]];\r\n\tif(!f[sum]){\r\n\t cout<<\"0\";\r\n\t\treturn 0;\r\n\t}\r\n\tint minc=1e5,minp=0;\r\n\tfor(int i=1;i<=n;i++){\r\n\t\tint x=a[i],cnt=0;\r\n\t\twhile(!(x&1)){\r\n\t\t\tx>>=1;\r\n\t\t\tcnt++;\r\n\t\t}\r\n\t\tif(cnt\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;\ntypedef pair pii;\ntypedef pair pll;\nconst int INF = 1e9;\nconst int MOD = 4096; \nint che[102];\nint n;\nint ans;\nstring s;\nint main() {\n\tios::sync_with_stdio(0);\n\tcin.tie(0); cout.tie(0);\n\tcin >> n;\n\tcin >> s;\n\ts += 'A';\n\tfor (int i = 'z'; i >= 'a'; i--) {\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tif (s[j] == i) {\n\t\t\t\t//cout << (char)i << ' ' << j << \"\\n\";\n\t\t\t\tint l = j - 1;\n\t\t\t\tint r = j + 1;\n\t\t\t\twhile (l > 0 && che[l]) {\n\t\t\t\t\tl--;\n\t\t\t\t}\n\t\t\t\twhile (r < n && che[r]) {\n\t\t\t\t\tr++;\n\t\t\t\t}\n\t\t\t\tif (l >= 0 && s[l] == i - 1) {\n\t\t\t\t\tche[j] = 1;\n\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t\telse if (r <= n && s[r] == i - 1) {\n\t\t\t\t\tche[j] = 1;\n\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t\tif (che[j]) {\n\t\t\t\t\tint ll = j - 1;\n\t\t\t\t\tint rr = j + 1;\n\t\t\t\t\twhile (ll > 0 && che[ll]) {\n\t\t\t\t\t\tll--;\n\t\t\t\t\t}\n\t\t\t\t\twhile (ll >= 0 && s[ll] == i && che[ll] == 0) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t\tche[ll] = 1;\n\t\t\t\t\t\tll--;\n\t\t\t\t\t\twhile (ll>0 && che[ll]) {\n\t\t\t\t\t\t\tll--;\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\tcout << ans;\n}", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\ntypedef long long ll;\n\nint main() {\n\tios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL);\n\n\tll x, s;\n\tcin >> x >> s;\n\t// s - x = (a&b)*2\n\tll dif = s - x;\n\tif (dif < 0 || dif & 1) { //0보다 작거나 홀수일때\n\t\tcout << -1;\n\t\treturn 0;\n\t}\n\tif (dif == 0) {\n\t\tif(x){\n\t\t\tcout << 1 << \"\\n\";\n\t\t\tcout << x;\n\t\t}\n\t\telse {\n\t\t\tcout << 0;\n\t\t}\n\t\treturn 0;\n\t}\n\tll a = (s - x)/2; // a and b\n\tll ans1 = a;\n\tll ans2 = a;\n\tvector ans;\n\tif (a & x) {\n\t\tans.push_back(a);\n\t\tans.push_back(a);\n\t\tans.push_back(x);\n\t}\n\telse {\n\t\tans.push_back(a);\n\t\tans.push_back(a + x);\n\t}\n\tll _size = ans.size();\n\tcout << _size << \"\\n\";\n\tfor (ll i = 0; i < _size; i++) {\n\t\tcout << ans[i] << \" \";\n\t}\n}", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"source_code": "#include\n#define lli long long int\n\nlli n,c1,c2,pr=0;\n\nlli calc(lli gr)\n{\n lli num=n/gr;\n lli r=n%gr;\n lli ret=gr*c1;\n ret+=r*(n/gr)*(n/gr)*c2;\n ret+=(gr-r)*(n/gr-1)*(n/gr-1)*c2;\n return ret;\n}\n\nint main() {\n scanf(\"%lld%\",&n);\n scanf(\"%lld%\",&c1);\n scanf(\"%lld%\",&c2);\n char s[n+1];\n gets(s);\n int ch=0;\n int i;\n for(i=0;i\nusing namespace std;\n#define int long long\nstruct point{\n int x,y;\n};\nbool ctp(point a, point b){\n if(a.x!=b.x) return a.x>a[i].x>>a[i].y;\n sort(a,a+8,ctp);\n if(a[0].x==a[1].x && a[1].x==a[2].x && a[3].x==a[4].x && a[2].x!=a[3].x && a[5].x!=a[4].x && a[5].x==a[6].x && a[6].x==a[7].x){\n if(a[0].y==a[3].y && a[0].y==a[5].y && a[1].y==a[6].y && a[2].y==a[4].y && a[2].y==a[7].y && a[0].y!=a[1].y && a[1].y!=a[2].y && a[0].y!=a[2].y) cout<<\"respectable\";\n else{\n cout<<\"ugly\";\n }\n }\n else{\n cout<<\"ugly\";\n }\n return 0;\n}", "src_uid": "f3c96123334534056f26b96f90886807"} {"source_code": " #include \n using namespace std;\n int main()\n {\n long long int r,k;\n long long int x,y;\n cin>>r;\n k=r-3;\n if(k<1){\n cout<<\"NO\"<\n#define ll long long\n#define M 1000000007\n#define INF 9223372036854775807\n#define cin(x) scanf(\"%lld\",&x)\n#define pmp(x,y) push_back(make_pair(x,y))\n#define mp(x,y) make_pair(x,y)\n#define pb(x) push_back(x)\n#define pf(x) push_front(x)\n#define ld double\n#define PI 3.14159265\n#define sz(a) (ll)a.size()\n#define F first\n#define S second\nusing namespace std;\n\nmap m;\nstring s;\nint main()\n{\n\t\n\tcin>>s;\n\n\tll cnt=0;\n\tchar ch;\n\tfor(ll i=0;i\r\n#define int long long\r\nusing namespace std;\r\nconst int N=2050,p=998244353;\r\nint n,m,ans;\r\nint fac[N<<2],ifac[N<<2],inv[N<<2];\r\nvoid init(int lim){\r\n\tfac[0]=ifac[0]=inv[1]=1;\r\n\tfor(int i=2;i<=lim;i++)\r\n\t\tinv[i]=inv[p%i]*(p-p/i)%p;\r\n\tfor(int i=1;i<=lim;i++){\r\n\t\tfac[i]=fac[i-1]*i%p;\r\n\t\tifac[i]=ifac[i-1]*inv[i]%p;\r\n\t}\r\n}\r\nint C(int n,int m){\r\n\treturn fac[n]*ifac[n-m]%p*ifac[m]%p;\r\n}\r\nsigned main(){\r\n\tscanf(\"%lld%lld\",&n,&m);\r\n\tinit(max(n,m)<<2);\r\n\tfor(int i=1;i=1;j--){\r\n\t\t\tsum=(sum+C(j+m-i-1,m-i-1)*C(n-j-1+m-i,m-i)%p)%p;\r\n\t\t\tans=(ans+sum*C(i+j-1,i)%p*C(i-1+n-j,i-1)%p)%p;\r\n//\t\t\tprintf(\"%lld %lld : %lld %lld\\n\",i,j,sum,ans);\r\n\t\t}\r\n//\t\tprintf(\"%lld %lld\\n\",sum,ans);\r\n\t}\r\n\tfor(int i=1;i=1;j--){\r\n\t\t\tsum=(sum+C(j+1+n-i-1,n-i-1)*C(m-j-2+n-i,n-i)%p)%p;\r\n\t\t\tans=(ans+sum*C(i+j-1,i)%p*C(i-1+m-j,i-1)%p)%p;\r\n//\t\t\tprintf(\"two, %d %d : %lld %lld\\n\",i,j,sum,ans);\r\n\t\t}\r\n//\t\tprintf(\"two, %lld %lld\\n\",sum,ans);\r\n\t}\r\n\tprintf(\"%lld\\n\",ans*2%p);\r\n\treturn 0;\r\n}\r\n/*\r\n3 3\r\n72\r\n\r\n2020 2021\r\n50657649\r\n\r\n2 3\r\n10\r\n\r\n3 2\r\n10\r\n*/", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb"} {"source_code": "#include\nusing namespace std;\nint read()\n{\n int x=0,f=1;char c=getchar();\n while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}\n while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c-'0');c=getchar();}\n return x*f;\n}\nint n,m;\ndouble dp[1010][1010];\ninline double f(int n,int m)\n{\n if(!n)return 1.0/(m+1.0);\n if(!m)return 1.0;\n if(dp[n][m])return dp[n][m];\n double A=1.0*m/(m+1.0)*(1.0-f(m-1,n)),B=1.0;\n double C=1.0/(m+1.0)+A,D=1.0-f(m,n-1);\n double P=(D-B)/(A-B-C+D);\n return dp[n][m]=P*A+(1-P)*B;\n}\nint main()\n{\n n=read(),m=read();\n double ans=f(n,m);\n printf(\"%.10lf %.10lf\",ans,1.0-ans);\n return 0;\n}", "src_uid": "f51586ab88399c04ffb7eaa658d294dd"} {"source_code": "#include \nusing namespace std;\nstruct l\n{\n long long n ;\n int i;\n};\nlong long gcd (long long x , long long y)\n{\n if(x > y) swap(x,y);\n if(!x) return y ;\n else return gcd(y%x,x);\n}\nbool ss(l x , l y)\n{\n if(x.n == y.n)\n return x.i < y.i ;\n else\n return x.n < y.n ;\n}\nlong long lcm (long long x , long long y)\n{\n return (x/gcd(x,y))*y;\n}\nlong long fast_power(long long base , long long power)\n{\n if(power == 1) return base ;\n else if(power%2) return base*fast_power(base*base,power/2);\n else return fast_power(base*base,power/2);\n}\nlong long nCr (long long n , long long r )\n{\n if(r > n) return 0;\n if(2*r > n) r = n-r ;\n if(!r) return 1;\n long long ans = n ;\n for(int i = 2 ; i <= r ; i++)\n {\n ans*=(n-i+1);\n ans/=i ;\n }\n return ans ;\n}\nint main()\n{\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n long long a , b , c ;\n cin >> a >> b >> c ;\n long long ans = 0 ;\n for(long long i = 4 ; i <= c-1 ; i++)\n {\n long long x = c-i;\n if(x < 1) continue ;\n else ans+=nCr(a,i)*nCr(b,x);\n }\n cout << ans << endl ;\n}\n", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8"} {"source_code": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\ntypedef long long ll;\n\nint main()\n{\n\tll n, k;\n\tcin >> n >> k;\n\tif ( k > 2*n - 1 )\n\t{\n\t\tputs(\"0\");\n\t\treturn 0;\n\t}\n\t\n\tll b = min( n, k );\n\tif ( b == k ) b -= 1ll;\n\tll a = k - b;\n\tll ans = (b-a+1ll) / 2ll;\n\tcout << ans << endl;\n\treturn 0;\n}", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"source_code": "//#include \"stdafx.h\"\n#include < iostream >\n//#include < fstream >\nusing namespace std;\n////////////////////\nint y1,y2,y3,y4;\nchar x1,x2,x3,x4;\n////////////////////\n\nint move(char x4, char x, char x0, int y4, int y, int y0)\t// ���� �����, x0,y0 - ��������� ������� �����, x,y - ��������� ������� �����\n{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// x4,y4 - ����� ���������� ������� ������\n\tfor (char i=x0-1; i>='a'; i--) {\n\t\tif ((i == x4)&(y4 == y0))\n\t\t\treturn 1;\n\t\tif (((x3 == i)&&(y3 == y0))\n\t\t\t||((x == i)&&(y == y0)))\n\t\t\tbreak;\n\t}\n\tfor (char i=x0+1; i<='h'; i++) {\n\t\tif ((i == x4)&(y4 == y0))\n\t\t\treturn 1;\n\t\tif (((x3 == i)&&(y3 == y0))\n\t\t\t||((x == i)&&(y == y0)))\n\t\t\tbreak;\n\t}\n\tfor (int i=y0-1; i>0; i--) {\n\t\tif ((i == y4)&&(x4 == x0))\n\t\t\treturn 1;\n\t\tif (((y3 == i)&&(x3 == x0))\n\t\t\t||((y == i)&&(x == x0)))\n\t\t\tbreak;\n\t}\n\tfor (int i=y0+1; i<9; i++) {\n\t\tif ((i == y4)&&(x4 == x0))\n\t\t\treturn 1;\n\t\tif (((y3 == i)&&(x3 == x0))\n\t\t\t||((y == i)&&(x == x0)))\n\t\t\tbreak;\n\t}\n\treturn 0;\n}\n\nint check (char x, int y)\t// �������� ������ �� ������ ����� � �� ����������� ����\n{\n\tif ((x > 'h') || (x < 'a')\t\t// ������� ����\n\t\t|| (y > 8) || (y < 1))\n\t\treturn 0;\n\tif (((x3-1 == x)&&(y3 == y))\t// ����� ������ ������\n\t\t||((x3-1 == x)&&(y3+1 == y))\n\t\t||((x3 == x)&&(y3+1 == y))\n\t\t||((x3+1 == x)&&(y3+1 == y))\n\t\t||((x3+1 == x)&&(y3 == y))\n\t\t||((x3+1 == x)&&(y3-1 == y))\n\t\t||((x3 == x)&&(y3-1 == y))\n\t\t||((x3-1 == x)&&(y3-1 == y)))\n\t\treturn 0;\n\tif ((x != x1)||(y != y1))\t\t// ����� ������ �����\n\t\tif (move(x,x2,x1,y,y2,y1) == 1)\n\t\t\treturn 0;\n\tif ((x != x2)||(y != y2))\t\t// ����� ������ �����\n\t\tif (move(x,x1,x2,y,y1,y2) == 1)\n\t\t\treturn 0;\n\treturn 1;\n}\n\nint main()\n{\n//\tifstream f(\"input.txt\");\n\tcin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;\n\tif (check(x4,y4) == 0)\n\t\tif ((check(x4-1,y4) == 0)&&(check(x4-1,y4+1) == 0)\n\t\t\t&&(check(x4,y4+1) == 0)&&(check(x4+1,y4+1) == 0)\n\t\t\t&&(check(x4+1,y4) == 0)&&(check(x4+1,y4-1) == 0)\n\t\t\t&&(check(x4,y4-1) == 0)&&(check(x4-1,y4-1) == 0)) {\n\t\t\t\tcout << \"CHECKMATE\";\n\t\t\t\treturn 0;\n\t\t}\n\tcout << \"OTHER\";\n\treturn 0;\n}\n\n", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3"} {"source_code": "#include // strings/streams\nusing namespace std;\nint main(){\n int n; cin >> n;\n int v[n];\n for( int i = 0 ; i < n ; ++i ){\n cin >> v[i];\n }\n sort( v, v+n );\n if( v[0] == v[n/2-1] && v[n-1] == v[n/2] && v[0] != v[n-1] ){\n cout << \"YES\\n\";\n cout << v[0] << ' ' << v[n-1] << '\\n';\n }else cout << \"NO\\n\";\n}\n", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "#include\n#include\nusing namespace std;\n#include \n#include \nusing namespace __gnu_pbds;\n#define ll long long\n#define ull unsigned long long\n#define ldb long long double\n#define pll pair \n#define pb emplace_back\n#define pf push_front\n#define pof pop_front\n#define pob pop_back\n#define ft front\n#define sz size\n#define gcd __gcd\n#define bk back\n#define ub upper_bound\n#define lb lower_bound\n#define sum accumulate\n#define bs binary_search\n#define fr first\n#define sc second\n#define mp make_pair\n#define all(v) v.begin(),v.end()\n#define ins insert\n#define bg begin\n#define rep(i,a,b) for(i=a;i<=b;i++)\n#define repr(i,a,b) for(i=a;i>=b;i--)\n#define Ndigits floor(log10(N)+1)\n#define N 1000000\n#define M 1000000007\n#define pi 3.141592653589793238\n#define FASTIO std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update>\nint main()\n{\n FASTIO\n //freopen(\"input.txt\", \"r\", stdin); // to be uncommented when I/P\n //freopen(\"output.txt\", \"w\", stdout); // & O/P are in file format\n ll n,i,j,p=0,d;\n cin>>n;\n vector x(n),c(101);\n rep(i,0,n-1) cin>>x[i];\n sort(all(x));\n rep(i,0,n-1)\n {\n d=0;\n rep(j,1,x[i])\n {\n if(c[j]>0)\n {\n d++;\n c[j]--;\n c[j+1]++;\n break;\n }\n }\n if(d==0)\n {\n p++;\n c[1]++;\n }\n }\n cout<\n\nconst int S = 640;\nconst int N = 100000;\nconst int INF = (1 << 30);\n\nint fa[S + 5][N + 5], f[N + 5][S + 5];\nint find(int o, int x) {return fa[o][x] = (fa[o][x] == x ? x : find(o, fa[o][x]));}\n\nint l[N + 5], v[N + 5], m; bool vis[S + 5];\nint solve() {\n\tfor(int i=0;i<=S;i++) vis[i] = false;\n\tfor(int j=0;j<=S;j++) for(int i=1;i<=m+1;i++) fa[j][i] = i, f[i][j] = -INF;\n\tfor(int i=1;i<=m;i++) fa[0][i] = i + 1, f[i][0] = INF;\n\t\n\tfor(int i=m;i>=1;i--) {\n\t\tl[i] = 0;\n\t\twhile( f[i][l[i]] != -INF ) l[i]++;\n\t\tvis[--l[i]] = true;\n\t\t\n\t\tfor(int j=0;j<=l[i];j++) f[i][j] = (v[i] << 1) - f[i][j];\n\t\tfor(int j=1;j<=l[i];j++) f[i][j] = std::max(f[i][j], f[i][j - 1]);\n\t\tfor(int j=0;j<=l[i];j++) f[i][j] = std::upper_bound(v + 1, v + m + 1, f[i][j]) - v;\n\t\t\n\t\tfor(int j=0;j\nusing namespace std;\nint main(){\n int n,m;\n cin>>n>>m;\n string a[n+1];\n for(int i=0;i>a[i];\n }\n int eaten =0;\n for(int i=0; i\nusing namespace std;\n\nint main()\n{\n //freopen(\"in\", \"r\",stdin);\n int ln,tt=0;\n cin>>ln;\n string str;\n cin>>str;\n for(int i=1;i=5)\n {\n cout<< \"yes\"<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nchar c1[1005];\nchar c2[1005];\nint k;\nint num[2][1005];\nint sum[2];\nint inf=1000000007;\n\nint main()\n{\n\n scanf(\"%s%s%d\",c1,c2,&k);\n\n int l=strlen(c1);\n int t=0;\n num[0][0]=1;\n sum[0]=1;\n\n for (int i=0;iinf)\n nxtsum-=inf;\n }\n sum[t^1]=nxtsum;\n t^=1;\n }\n int ans=0;\n for (int i=0;iinf)\n ans-=inf;\n }\n }\n printf(\"%d\",ans);\n\n\n return 0;\n}", "src_uid": "414000abf4345f08ede20798de29b9d4"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nconst int base = 13331;\n\nstruct Operation {\n\tint t, v;\n\tchar c;\n} op[100000];\n\nint s1[100002], s2[100002], sa[100001], rank[100001], up[100001];\nint depth1[100001], depth2[100001], pre[100001][18];\nlong long hash[100001], pow[18];\npair range[100001];\n\nbool cmp(int a, int b) {\n\tint lg = 0;\n\twhile (1 << lg <= depth2[a] && 1 << lg <= depth2[b]) lg ++;\n\tfor (int i = lg - 1; i >= 0; i --) {\n\t\tlong long t1 = hash[a] - hash[pre[a][i]] * pow[i];\n\t\tlong long t2 = hash[b] - hash[pre[b][i]] * pow[i];\n\t\tif (t1 == t2) {\n\t\t\ta = pre[a][i];\n\t\t\tb = pre[b][i];\n\t\t}\n\t}\n\treturn up[a] < up[b];\n}\n\nint goUp(int x, int step) {\n\tfor (int i = 0; 1 << i <= step; i ++)\n\t\tif (step & 1 << i) x = pre[x][i];\n\treturn x;\n}\n\nint main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\tfor (int i = 0; i < n; i ++) {\n\t\tint x, y;\n\t\tchar tmp[11];\n\t\tscanf(\"%d%d%s\", &x, &y, tmp);\n\t\top[i].t = x;\n\t\top[i].v = y - 1;\n\t\top[i].c = tmp[0];\n\t}\n\t\n\thash[0] = 0;\n\tup[0] = 0;\n\tdepth1[0] = 0;\n\tmemset(pre, -1, sizeof(pre));\n\tint tot = 1;\n\tfor (int i = 0; i < n; i ++)\n\t\tif (op[i].t == 2) {\n\t\t\tdepth2[tot] = depth2[op[i].v] + 1;\n\t\t\thash[tot] = hash[op[i].v] * base + op[i].c;\n\t\t\tup[tot] = op[i].c;\n\t\t\tpre[tot][0] = op[i].v;\n\t\t\tfor (int j = 1; 1 << j <= depth2[tot]; j ++)\n\t\t\t\tpre[tot][j] = pre[pre[tot][j - 1]][j - 1];\n\t\t\ttot ++;\n\t\t}\n\t\n\tpow[0] = base;\n\tfor (int i = 1; 1 << i <= tot; i ++) pow[i] = pow[i - 1] * pow[i - 1];\n\tfor (int i = 0; i < tot; i ++) sa[i] = i;\n\tstable_sort(sa, sa + tot, cmp);\n\tfor (int i = 0; i < tot; i ++) rank[sa[i]] = i;\n\t\n\tmemset(s1, 0, sizeof(s1));\n\tmemset(s2, 0, sizeof(s2));\n\tlong long ans = 0;\n\tint cur1 = 1, cur2 = 1;\n\trange[0] = make_pair(0, tot);\n\tdepth1[0] = 0;\n\tfor (int i = 0; i < n; i ++) {\n\t\tif (op[i].t == 1) {\n\t\t\tdepth1[cur1] = depth1[op[i].v] + 1;\n\t\t\tif (range[op[i].v].first != -1) {\n\t\t\t\tint head, tail;\n\t\t\t\thead = range[op[i].v].first;\n\t\t\t\ttail = range[op[i].v].second - 1;\n\t\t\t\twhile (head <= tail) {\n\t\t\t\t\tint mid = (head + tail) / 2;\n\t\t\t\t\tif (up[goUp(sa[mid], depth1[op[i].v])] < op[i].c) {\n\t\t\t\t\t\thead = mid + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttail = mid - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint l = head;\n\t\t\t\thead = range[op[i].v].first;\n\t\t\t\ttail = range[op[i].v].second - 1;\n\t\t\t\twhile (head <= tail) {\n\t\t\t\t\tint mid = (head + tail) / 2;\n\t\t\t\t\tif (up[goUp(sa[mid], depth1[op[i].v])] > op[i].c) {\n\t\t\t\t\t\ttail = mid - 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\thead = mid + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint r = tail + 1;\n\t\t\t\tif (l >= r) {\n\t\t\t\t\trange[cur1] = make_pair(-1, -1);\n\t\t\t\t} else {\n\t\t\t\t\trange[cur1] = make_pair(l, r);\n\t\t\t\t\tfor (int j = r; j > 0; j -= j & -j) ans += s1[j];\n\t\t\t\t\tfor (int j = l; j > 0; j -= j & -j) ans -= s1[j];\n\t\t\t\t\tfor (int j = l + 1; j <= tot; j += j & -j) s2[j] ++;\n\t\t\t\t\tif (r < tot) {\n\t\t\t\t\t\tfor (int j = r + 1; j <= tot; j += j & -j) s2[j] --;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\trange[cur1] = make_pair(-1, -1);\n\t\t\t}\n\t\t\tcur1 ++;\n\t\t} else {\n\t\t\tint t = rank[cur2];\n\t\t\tfor (int j = t + 1; j <= tot; j += j & -j) s1[j] ++;\n\t\t\tfor (int j = t + 1; j > 0; j -= j & -j) ans += s2[j];\n\t\t\tcur2 ++;\n\t\t}\n\t\tprintf(\"%I64d\\n\", ans + cur2);\n\t}\n\t\n\treturn 0;\n}", "src_uid": "b0cd7ee6b5f13f977def002b53f8f443"} {"source_code": "#include \r\n#include \r\nusing namespace std;\r\nconst long long mod=1000000007;\r\nlong long x,k,t;\r\nlong long pow(long long a,long long b){\r\n\tlong long ans=1;\r\n a%=mod;\r\n\twhile(b){\r\n\t\tif(b&1) ans=ans*a%mod;\r\n\t\ta=a*a%mod;\r\n\t\tb=b>>1;\r\n\t}\r\n\treturn ans;\r\n}\r\nint main(){\r\n\tscanf(\"%lld\",&t);\r\n\twhile(t--){\r\n\t\tscanf(\"%lld%lld\",&x,&k);\r\n\t\tprintf(\"%lld\\n\",pow(x,k));\r\n\t}\r\n\treturn 0;\r\n}", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "#include\n#include\n#include\n#define ll long long\nusing namespace std;\nll n, m, x, y, sum = 1;\nll dx = 1, dy = 1;\nchar a, b;\nll sum1 = 0;\nset > s;\nvoid operation()\n{\n\tll k = 0;\n\twhile (1){\n\t\ts.insert(pair (x, y));\n\t\tk ++;\n\t//\tcout << x << \" \" << y << endl;\n\t\tif (s.size() == n+m-2){\n\t\t\tprintf(\"%I64d\", sum);\n\t\t\texit(0);\n\t\t}\n\t\tll stepa, stepb;\n\t\tif (dx == -1)\n\t\t{\n\t\t\tstepa = x - 1;\n\t\t}else stepa = n - x;\n\t\tif (dy == -1)\n\t\t{\n\t\t\tstepb = y - 1;\n\t\t}else stepb = m - y;\n\t\tll temp = sum;\n\t\tsum += min (stepa, stepb);\n\t\tif (temp == sum){\n\t\t\tsum1 ++;\n\t\t\tif (sum1 > (ll) 1e6){\n\t\t\t\tprintf(\"-1\");\n\t\t\t\texit(0);\n\t\t\t}\n\t\t}else sum1 = 0;\n\t\tif (k > (ll) 1e6) {\n\t\t\tprintf(\"-1\");\n\t\t\texit(0);\n\t\t}\n\t\tx += dx * (sum - temp);\n\t\ty += dy * (sum - temp);\n\t\tif (x * -dx == 1 || x * dx == n){\n\t\t\tdx = -1 * dx;\n\t\t}\n\t\tif (y * -dy == 1 || y * dy == m){\n\t\t\tdy = -1 * dy;\n\t\t}\n\t}\n}\nint main()\n{\n\tscanf(\"%lld%lld%lld%lld\", &n, &m, &x, &y);\n\tcin >> a >> b;\n\tif (a == 'U') dx = -1;\n\tif (b == 'L') dy = -1;\n\toperation();\n}", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d"} {"source_code": "#include\nusing namespace std;\ntypedef long long ll;\nconst int mod=1e9+7;\nconst int maxn=1e5+10;\n\nll a,b;\nll ans;\nvectorprime; \n\nint main(){\n\n\tscanf(\"%lld %lld\",&a,&b);\n\tll tmp = a;\n\tfor(ll i = 2;i * i <= tmp;i++)\n\t{\n\t\tif(tmp % i == 0)\n\t\t{\n\t\t\tprime.push_back(i);\n\t\t\twhile(tmp % i == 0)\n\t\t\ttmp /= i;\n\t\t}\n\t}\n\tif(tmp > 1)\n\tprime.push_back(tmp);\n\tans = 0;\n\tint len = prime.size();\n\twhile(b)\n\t{\n\t\tll g = __gcd(a,b);\n\t\ta /= g;\n\t\tb /= g;\n\t\tll res = b;\n\t\tfor(ll i = 0;i < len;i++)\n\t\t{\n\t\t\tll x = prime[i];\n\t\t\tif(a % x == 0)\n\t\t\tres = min (res,b % x);\n\t\t}\n\t\tans += res;\n\t\tb -= res;\n\t}\n\tprintf(\"%lld\\n\",ans);\n\treturn 0;\n}", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e"} {"source_code": "#include \nusing namespace std;\nint main() {\n\tint n;\n\tcin >> n;\n\tstring s;\n\tcin >> s;\n\t\n\tint res = 0;\n\tstring ans;\n\tfor (int i = 0; i < n - 1; ++i) \n\t{\n\t\tint cur = 0;\n\t\tfor (int j = 0; j < n - 1; ++j)\n\t\t\tif (s[j] == s[i] && s[j + 1] == s[i + 1])\n\t\t\t\t++cur;\n\t\tif (res < cur) \n\t\t{\n\t\t\tres = cur;\n\t\t\tans = string(1, s[i]) + string(1, s[i + 1]);\n\t\t}\n\t}\n\tcout << ans << endl;\n\treturn 0;\n}", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"source_code": "#include\n\n\n\n\nint main(){\n int n, w,i,j;\n scanf(\"%d\", &n);\n if(n > 3){\n if((n%2) == 1){printf(\"1\"); return 0;}\n w = n%3;\n if(w == 1){printf(\"2\"); return 0;}\n if(w == 2){printf(\"1\"); return 0;}\n }\n\n for(i=1;i<7;i++){\n w = n*i+1;\n for(j=2; j<1001;j++){\n if(j*j > w){break;}\n if((w%j) == 0){\n printf(\"%d\", i);\n return 0;\n }\n }\n }\n\nreturn 0;\n}\n\n// 1519399433465\n", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint main()\n{\n\tlong long p;\n\tint k;\n\tscanf(\"%I64d %d\",&p,&k);\n\tvector ans;\n\twhile(p)\n\t{\n\t\tlong long tmp=p%k;\n\t\twhile(tmp<0)\n\t\t\ttmp+=k;\n\t\tans.push_back(tmp);\n\t\tp-=tmp;\n\t\tp/=k;\n\t\tp=-p;\n\t}\n\tprintf(\"%lu\\n\",ans.size());\n\tfor(int i=0;i\n#include \n#include \n#include \n#include \nusing namespace std;\n\n\n\nint main ()\n{\n\n int n,m,k;\n cin >> n >> m >> k;\n int a[n];\n for (int x = 0 ; x < n ;x++)\n cin >> a[x];\n if ( m <= k)\n {\n cout << 0;\n return 0;\n }\n \nsort(&a[0],&a[n]);\n\nint lamp = k;\nint ans = 1;\nint rah_1 = 0;\nfor ( ; ans <= n; ans++ )\n{\n \n if (a[n-ans] != 1)\n lamp += a[n-ans]-1;\n else \n rah_1++;\n \n if (lamp >= m)\n {\n cout << ans - rah_1;\n return 0;\n }\n // cout << lamp<\nusing namespace std;\ntypedef long long ll;\nconst int M = (int)3e8 + 50;\n\nbitset p;\n\nvoid sieve() {\n p.set();\n p[1] = false;\n for(int i = 2; i * i < M; i++) {\n if(!p[i]) continue;\n for(int j = 2 * i; j < M; j += i) {\n p[j] = false;\n }\n }\n}\n\nint main(){\n sieve();\n\n int l, r;\n cin >> l >> r;\n int cnt = 0;\n for(int i = (l + 2) / 4 * 4 + 1; i <= r; i += 4) {\n if(p[i]) cnt++;\n }\n if(l <= 2 && 2 <= r) cnt++;\n cout << cnt << endl;\n}", "src_uid": "55a83526c10126ac3a6e6e5154b120d0"} {"source_code": "#include \n#include \n#include \n#pragma GCC optimize (\"Ofast\")\n#pragma GCC optimization (\"unroll-loops, no-stack-protector\")\n#pragma GCC target (\"avx\")\n#pragma GCC target (\"avx2\")\n#pragma GCC target (\"fma\")\n#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)\n#define ll long long\n#define ull unsigned long long\n#define ld long double\n#define pii pair \n#define pll pair \n#define pci pair \n#define pld pair \n#define ppld pair \n#define ppll pair \n#define pldl pair \n#define vll vector \n#define vvll vector \n#define vpll vector \n#define pb push_back\n#define eb emplace_back\n#define mp make_pair\n#define fi first\n#define se second \n#define mll map \n#define fastmap gp_hash_table\n#define cd complex \n#define vcd vector \n#define PI 3.14159265358979\n#define ordered_set tree , rb_tree_tag, tree_order_statistics_node_update>\n#pragma 03\nusing namespace std; \nusing namespace __gnu_pbds;\nll mod = 1e9 + 7;\nll dp[505][505];\nll p2[250005];\nint main(){\n\tp2[0] = 1; for (ll i = 1; i < 250005; i++) p2[i] = (p2[i - 1] * 2) % mod;\n\tll n, s; cin >> n >> s;\n\tfor (ll i = 0; i <= n; i++) dp[i][0] = 1;\n\tfor (ll i = 1; i <= n; i++){\n\t\tfor (ll j = 1; j <= min(i, s); j++){\n\t\t\tfor (ll k = j - 1; k <= i; k++){\n\t\t\t\t(dp[i][j] += (dp[k][j - 1] * (p2[i - k] - 1) % mod * p2[k * (i - k)])) %= mod;\n\t\t\t}\n\t\t}\n\t}\n\tcout << dp[n][s] << endl;\n}", "src_uid": "111673158df2e37ac6c019bb99225ccb"} {"source_code": "#include\nusing namespace std;\nint main(){\n\tlong long n,sq,k;\n\tcin>>n;\n\tsq=int(sqrt(n));\n\tk=n-sq*sq;\n\tif(sqrt(n)==sq){\n\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\nusing namespace std;\n\n#define vi vector\n#define vvi vector< vi >\nconst int mod = 1000*1000*1000+7;\n\nvvi mul(vvi &a, vvi &b) {\n\tint n = a.size();\n\tvvi ret(n, vi(n, 0));\n\tfor(int k=0;k>= 1;\n\t} return mul(a, ret);\n}\n\nint w[10];\nint adj[10][1<<7][1<<7];\n\nint main() {\n#ifdef LOCAL\n\tfreopen(\"input.txt\",\"r\",stdin);\n#endif\n\tfor(int i=1;i<=7;++i) scanf(\"%d\",w+i);\n\tint last = 0;\n\tfor(int i=1;i<=7;++i) if(w[i]) last = i;\n\tfor(int len=1;len<=7;++len) {\n\t\tfor(int i=0;i<(1<>k & 1) || !(j>>k & 1)) nc1 += c1;\n\t\t\t\tc0 = nc0, c1 = nc1;\n\t\t\t} adj[len][i][j] = c1;\n\t\t}\n\t}\n\n\tint prv[1<<7] = {0};\n\tint nxt[1<<7];\n\n\tprv[0] = 1;\n\tfor(int len=1;len<=7;++len) {\n\t\tmemset(nxt,0,sizeof(nxt));\n\t\t\n\t\tvvi a(1<\n\nusing namespace std;\ntypedef long long int ll;\ntypedef long double ld;\n\nstring s1, s2;\n\ntypedef tuple T;\n\n#define NN 201\nbool visited[NN][NN][NN+20];\nchar moves[NN][NN][NN+20];\nT par[NN][NN][NN+20];\n\nint main() {\n\tios_base::sync_with_stdio(false);\n\tcin.tie(NULL);\n\n\tcin>>s1>>s2;\n\n\tqueue fringe;\n\tmemset(moves, -1, sizeof moves);\n\tfringe.push({0, 0, 0});\n\tvisited[0][0][0] = true;\n\twhile (1) {\n\t\tT u = fringe.front();\n\t\tll i, j, b;\n\t\ttie(i, j, b) = u;\n\t\tfringe.pop();\n\t\t//cout<(u)][get<1>(u)][get<2>(u)]!=-1) {\n\t\t\t\tans+=moves[get<0>(u)][get<1>(u)][get<2>(u)];\n\t\t\t\tu = par[get<0>(u)][get<1>(u)][get<2>(u)];\n\n\t\t\t}\n\t\t\treverse(ans.begin(), ans.end());\n\t\t\tcout<(v)<0 || get<2>(v)>210) continue;\n\t\t\tif (visited[get<0>(v)][get<1>(v)][get<2>(v)]) continue;\n\t\t\tfringe.push(v);\n\t\t\tvisited[get<0>(v)][get<1>(v)][get<2>(v)] = 1;\n\t\t\tmoves[get<0>(v)][get<1>(v)][get<2>(v)] = c;\n\t\t\tpar[get<0>(v)][get<1>(v)][get<2>(v)] = u;\n\t\t}\n\t}\n}\n", "src_uid": "cc222aab45b3ad3d0e71227592c883f1"} {"source_code": "#include \nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\n\n#define pb push_back\n#define mp(x,y) make_pair(x,y)\n#define scd(n) scanf(\"%d\",&n)\n#define sclf(n) scanf(\"%lf\",&n)\n#define scl(n) scanf(\"%I64d\",&n)\n#define repi(a,b,c) for(int i=a;i=b;i-=c)\n#define repj(a,b,c) for(int j=a;j=b;j-=c)\n#define repk(a,b,c) for(int k=a;k=0;k-=c)\n#define fi first\n#define se second\n\n/*\n fast I/O\n\nios::sync_with_stdio(0);\ncin.tie();\n\n freeopen\n\n freopen(\"input.txt\",\"r\",stdin);\n freopen(\"output.txt\",\"w\",stdout);\n */\n\ntypedef pair ii;\nconst int mx = 200100;\nconst int md = 1000000007;\n\nbool compare(const pair& a,const pair & b) {\n return a.first < b.first || (a.first == b.first && a.second > b.second);\n}\n\nstring s;\nint n;\n\nint cari(int a,int b) {\n //cout << a << \" \" << b << \" = \";\n int ans = INT_MAX;\n pair temp = mp(-1,-1);\n repi(0,s.size(),1) {\n if(a != b) {\n if(s[i]-'0' == a) temp.fi = i;\n if(s[i]-'0' == b) temp.se = i;\n }\n else {\n if(s[i]-'0' == a) {\n temp.fi = temp.se;\n temp.se = i;\n }\n }\n }\n\n if(temp.fi != -1 and temp.se != -1) {\n if(temp.fi < temp.se) ans = min(ans,(n-2)-temp.fi+(n-1)-temp.se);\n else if(temp.fi == n-1) ans = min(ans,(n-temp.se)-1);\n else {\n //cout << temp.fi << \" vs \" << temp.se << endl;\n ans = min(ans,(n-2)-temp.fi+(n-1)-temp.se+1);\n }\n }\n if(n == 2) return ans;\n int z = -1,g=0;\n repi(0,n,1) {\n if(i != temp.fi and i != temp.se) {\n if(s[i] != '0') {\n g += i;\n z = i;\n break;\n }\n }\n else {\n g--;\n }\n }\n //cout << z << endl;\n if(z == -1) ans = INT_MAX;\n if(ans == INT_MAX) return ans;\n return ans+g;\n}\n\nint main() {\n cin >> s;\n n = s.size();\n if(n == 1) printf(\"%d\\n\",(s == \"0\" ? 0 : -1));\n else {\n int ans = INT_MAX;\n ans = min(ans,cari(0,0));\n ans = min(ans,cari(2,5));\n ans = min(ans,cari(5,0));\n ans = min(ans,cari(7,5));\n if(ans == INT_MAX) printf(\"-1\\n\");\n else printf(\"%d\\n\",ans);\n }\n}\n", "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"source_code": "#include \nconst int mod = 1000000007;\nusing namespace std;\n\nint mi[1000001],rev[1000001],cp[1000001];\n\nint quick(int a,int b)\n{\n if (!b)\n return 1;\n int t=quick(a,b>>1);\n t=1LL*t*t%mod;\n if (b&1)\n t=1LL*t*a%mod;\n return t;\n}\n\ninline int P(int n,int m)\n{\n if (m>n)\n return 0;\n return 1LL*mi[n]*rev[n-m]%mod;\n}\n\ninline int C(int n,int m)\n{\n if (m>n)\n return 0;\n return 1LL*mi[n]*rev[n-m]%mod*rev[m]%mod;\n}\n\nint main()\n{\n int k,w,s=0;\n cin>>k>>w;\n mi[0]=rev[0]=1;\n for (int i=1;i<=k;i++)\n {\n mi[i]=1LL*mi[i-1]*i%mod;\n rev[i]=1LL*rev[i-1]*quick(i,mod-2)%mod;\n }\n cp[0]=1;\n for (int i=1;i<=k;i++)\n cp[i]=(1LL*cp[i-1]*i+1)%mod;\n for (int i=1;i<=min(k,w-2);i++)\n {\n int t=quick(k,w-i-2);\n s=(s+2LL*P(k,i)*P(k,i)%mod*t%mod*k%mod*i-1LL*P(k,i)*P(k,i)%mod*t%mod*i%mod*i%mod+mod)%mod;\n }\n if (k>=w-1)\n s=(s+2LL*P(k,w-1)*P(k,w-1)%mod*(w-1)-1LL*P(k-1,w-2)*P(k-1,w-2)%mod*(w-1)%mod*(w-1)%mod*k%mod+mod)%mod;\n for (int i=0;i<=k-w;i++)\n s=(s+2LL*P(k,w+i)*w%mod*P(k-i-1,w-1))%mod;\n for (int i=0;i<=min(k,w-1);i++)\n {\n long long t=0;\n if (k-2*(w-1)+i>=0)\n t+=1LL*(w-1-i)*(w-1-i)%mod*cp[k-2*(w-1)+i];\n if (k-2*(w-1)+i-1>=0)\n t+=1LL*(k-2*(w-1)+i)*cp[k-2*(w-1)+i-1];\n if (t)\n s=(s-t%mod*C(w-1,i)%mod*C(w-1,i)%mod*P(k,i)%mod*mi[i]%mod*P(k-i,w-1-i)%mod*P(k-w+1,w-1-i)%mod+mod)%mod;\n }\n cout<\n\nusing namespace std;\n\n#define mp make_pair\n#define fr first\n#define sc second\n\nlong long n,fq[10];\nvector> ky[10];\n\nint main()\n{\n\tlong long i,j,k,l,w,sz;\n\tstring s;\n\t\n\tky[2].push_back({2,1});\n\tky[3].push_back({3,1});\n\tky[4].push_back({2,2});\n\tky[4].push_back({3,1});\n\tky[5].push_back({5,1});\n\tky[6].push_back({3,1});\n\tky[6].push_back({5,1});\n\tky[7].push_back({7,1});\n\tky[8].push_back({2,3});\n\tky[8].push_back({7,1});\n\tky[9].push_back({2,1});\n\tky[9].push_back({3,2});\n\tky[9].push_back({7,1});\n\tscanf(\"%lld\",&n);\n\tcin>>s;\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tfq[s[i-1]-'0']++;\n\t}\n\tfor(i=9;i>1;i--)\n\t{\n\t\tk=fq[i];\n\t\tfq[i]=0;\n\t\tsz=ky[i].size();\n\t\tfor(j=0;j1;i--)\n\t{\n\t\tfor(j=0;j\nint n,i=17;main(){for(scanf(\"%d\",&n);i--;n&1<\n#include\nusing namespace std;\nint main()\n{\n int n;\n cin>>n;\n char s[n];\n cin>>s;\n\n /*int len=n-4;\n len=n-len;\n len--;*/\n\n int len=n-3;\n\n vectorv;\n\n char a[]=\"ACTG\";\n\n for(int i=0;ia[y])\n {\n int u=s[j];\n int b=a[y];\n int ans=u-b;\n sum+=ans;\n }\n else\n {\n int u=s[j];\n int b=a[y];\n int ans=b-u;\n sum+=ans;\n }*/\n\n int u=s[j]-64;\n int b=a[y]-64;\n int mx=max(u,b);\n int mn=min(u,b);\n\n int ans=mx-mn;\n if(ans<=13)\n {\n sum+=ans;\n }\n else\n {\n if(ans==14) sum+=12;\n else if(ans==15) sum+=11;\n else if(ans==16) sum+=10;\n else if(ans==17) sum+=9;\n else if(ans==18) sum+=8;\n else if(ans==19) sum+=7;\n else if(ans==20) sum+=6;\n else if(ans==21) sum+=5;\n else if(ans==22) sum+=4;\n else if(ans==23) sum+=3;\n else if(ans==24) sum+=2;\n else if(ans==25) sum+=1;\n }\n }\n v.push_back(sum);\n }\n\n sort(v.begin(),v.end());\n int royal=v[0];\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\nint B[3]; \nint getd(int m,int y)\n{\n\tif (m==1||m==3||m==5||m==7||m==8||m==10||m==12)\n\t\treturn 31;\n\tif (m==4||m==6||m==9||m==11)\n\t\treturn 30;\n\tif (y%4==0)\n\t\treturn 29;\n\treturn 28;\n}\nint BD,BM,BY;\nint tb[3];\nbool used[3];\nbool hefa()\n{\n\tif (tb[1]<=12&&tb[1]>=1)\n\t{\n\t\tif (tb[2]>0&&tb[2]<=getd(tb[1],tb[0]))\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\nbool low()\n{\n\tint x=tb[0]*10000+tb[1]*100+tb[2];\n\tint y=BY*10000+BM*100+BD;\n\tif (x>DD>>x>>MM>>x>>YY;\n\tcin>>B[0]>>x>>B[1]>>x>>B[2];\n\tBD=B[0];\n\tBM=B[1];\n\tBY=B[2];\n\tgetB(0);\n\tif (YY-BY<18)\n\t{\n\t\tcout<<\"NO\"<18)\n\t{\n\t\tcout<<\"YES\"<=tt)\n\t\t{\n\t\t\tcout<<\"YES\"<\n#define FOR(v, a, b) for(int v = (a); v < (b); ++v)\n#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)\n#define REP(v, n) FOR(v, 0, n)\n#define REPE(v, n) FORE(v, 0, n)\n#define REV(v, a, b) for(int v = (a); v >= (b); --v)\n#define ALL(x) (x).begin(), (x).end()\n#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)\n#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)\n#define EXIST(c,x) ((c).find(x) != (c).end())\n#define LLI long long int\n#define fst first\n#define snd second\n\n#ifdef DEBUG\n#include \n#else\n#define dump(x)\n#endif\n\n#define gcd __gcd\n\nusing namespace std;\ntemplate constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}\n\ntemplate void join(ostream &ost, I s, I t, string d=\" \"){for(auto i=s; i!=t; ++i){if(i!=s)ost< istream& operator>>(istream &is, vector &v){for(auto &a : v) is >> a; return is;}\ntemplate istream& operator>>(istream &is, pair &p){is >> p.first >> p.second; return is;}\n\ntemplate T& chmin(T &a, const U &b){return a = (a<=b?a:b);}\ntemplate T& chmax(T &a, const U &b){return a = (a>=b?a:b);}\ntemplate void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}\n\nconst LLI mod = 1e9+7;\n\nLLI power(LLI n, LLI p, LLI m){\n LLI ret = 1;\n while(p>0){\n if(p&1) (ret *= n) %= m;\n (n *= n) %= m;\n p /= 2;\n }\n return ret;\n}\n\nLLI mod_inv(LLI n, LLI p){return power(n,p-2,p);}\n\nbool is_prime[100010];\n\nvector mobius(int n){\n vector ret(n+1);\n vector ps;\n ret[1] = 1;\n FORE(i,2,n){\n if(is_prime[i]){\n ps.push_back(i);\n ret[i] = -1;\n }\n for(auto &j : ps){\n if(i*j > n) break;\n if(i % j == 0) ret[i*j] = 0;\n else ret[i*j] = ret[i] * ret[j];\n }\n }\n \n return ret;\n}\n\nvoid solve(LLI m){\n auto mob = mobius(m);\n dump(mob);\n\n LLI ans = 1;\n\n FORE(i,2,m){\n LLI t = m/i;\n (ans += ((t*mod_inv(m-t,mod)%mod)*(-mob[i]) + mod)%mod) %= mod;\n }\n \n cout << ans << endl;\n}\n\n\nint main(){\n cin.tie(0);\n ios::sync_with_stdio(false);\n\n {\n // 素数判定\n fill_array(is_prime, true);\n is_prime[0] = is_prime[1] = false;\n FORE(i,2,100000) if(is_prime[i]) for(int j=2*i; j<=100000; j+=i) is_prime[j] = false;\n }\n\n LLI m;\n while(cin >> m){\n solve(m);\n }\n \n return 0;\n}\n", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0"} {"source_code": "#include \nusing namespace std;\nint main(){\n\tlong long n,a=0,b,i,cnt=0;\n\tcin>>n;\n\twhile(a*10+9<=n){\n\t\ta=a*10+9;\n\t\tcnt+=9;\n\t}\n\tb=n-a;\n\t//cout << a << \" \" << b << endl;\n\twhile(b!=0){\n\t\tcnt+=b%10;\n\t\tb/=10;\n\t}\n\tcout<\nusing namespace std;\nint main()\n{\n int n;\n cin>>n;\n char s[100],s2[100];\n cin>>s;\n\n int temp,k=0,c=0;\n\n for(int i=0;s[i]!='\\0';i++)\n {\n if(s[i]>=65 && s[i]<=92)\n {\n\t s[i]=s[i]+32;\n }\n }\n\n for(int i=0;s[i]!='\\0';i++)\n {\n for(int j=i+1;s[j]!='\\0';j++)\n {\n if(s[i]>s[j])\n {\n temp=s[i];\n s[i]=s[j];\n s[j]=temp;\n }\n }\n }\n\nfor(int i=0;s[i]!='\\0';i++)\n\t{\n\t\tif(s[i]==s[i+1])\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\telse\n\t\t{\n\t\t\ts2[k]=s[i];\n\t\t\tk++;\n\t\t}\n\t}\n\t\n \n if (k==26)\n {\n cout<<\"YES\";\n }\n\n else{\n cout<<\"NO\";\n }\n\n}\n\n", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"source_code": "#define _CRT_SECURE_NO_DEPRECATE\n#include\n#include\n#include\n#include\n#include\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\ntypedef unsigned long long ui64;\ntypedef long long i64;\ntypedef vector vi;\ntypedef vector vs;\ntypedef pair pii;\ntypedef pair point;\n\n#define pb push_back\n#define mp make_pair\n#define X first\n#define Y second\n#define all(a) (a).begin(), (a).end()\n#define INF (2000000000)\n\ni64 make_rew(int a){\n i64 t = a;\n i64 res = 0;\n i64 pw = 0;\n while(t!=0){\n res = res + (9 - t%10)*((i64)pow(10.0,1.0*pw));\n pw++;\n t/=10;\n }\n if(!a)\n return 9LL;\n return res;\n}\n\nint main()\n{\n int L,R; scanf(\"%d%d\",&L,&R);\n/* int t = R,dig=0;\n while(t!=0){\n t/=10;\n dig++;\n }\n\n int res = 0;\n for(int i=L;i<=R;i++){\n int t = make_rew(i);\n cout << i << \" \" << t << \" = \" << t*i << endl;\n if( t*i > res*make_rew(res) ){\n res = i;\n }\n }*/\n\n int a = 500000000;\n int dist=abs(R-a);\n int guess=R;\n for(int i=0;a>0;i++){\n if(a>=L && a<=R){\n if(R*make_rew(R)>a*make_rew(a))\n a = R;\n cout << a*make_rew(a) << endl;\n return 0;\n }\n else{\n if(min(abs(L-a),abs(R-a)) < dist ){\n dist = min(abs(L-a),abs(R-a));\n if(abs(L-a) < abs(R-a))\n if(guess*make_rew(guess)\nusing namespace std;\nint main(){\nint n;\ncin>>n;\nif(n%2==0)cout<<\"Mahmoud\";\nelse cout<<\"Ehab\";}\n", "src_uid": "5e74750f44142624e6da41d4b35beb9a"} {"source_code": "#include\n#include\nusing namespace std;\nint main(){\n\tint n,m;\n\tint l[105];\n\tint a[105];\n\tint vis[105];\n\tint vis1[105];\n\twhile(scanf(\"%d%d\",&n,&m)!=EOF){\n\t\tfor(int i=1;i<=n;i++) vis[i]=0,vis1[i]=0;\n\t\tfor(int i=0;itemp;\n\t\twhile(!temp.empty()) temp.pop();\n\t\tfor(int i=0;il[i]&&a[l[i]]!=(l[i+1]-l[i])) success=0;\n\t\t\t}\n\t\t}\n\t\tif(success==0) printf(\"-1\");\n\t\telse {\n\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\tif(vis[i]==0) temp.push(i);\n\t\t\t}\n\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\tif(vis1[i]==0) a[i]=temp.top(),temp.pop();\n\t\t\t\tprintf(\"%d\",a[i]);\n\t\t\t\tif(i==n) printf(\"\\n\");\n\t\t\t\telse printf(\" \");\n\t\t\t} \n\t\t}\n\t\t\n\t}\n} ", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b"} {"source_code": "#include \nusing namespace std;\n#define N 1100\n#define seed 11333333\n#define seed2 5462617\n#define seed1 23333333\n#define ull unsigned long long\nint n,T,label,pos[2][N];\nstruct node\n{\n\tull v;int x,y;\n\tnode(){}\n\tnode(ull v,int x,int y):v(v),x(x),y(y){}\n\tfriend bool operator < (const node &r1,const node &r2)\n\t{return r1.va[2];\nstruct tree\n{\n\tint id,m,f1,f2,sum;\n\tint used[N],f[N],size[N],vis[N];\n\tvector v[N],sub[N];\n\tvector v1[N],v2;\n\tvector v3;\n\tull val[N];\n\tvoid init()\n\t{\n\t\ta[id].clear();\n\t\tmemset(used,0,sizeof(used));\n\t\tmemset(vis,0,sizeof(vis));\n\t\tv2.clear();\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tv[i].clear(),sub[i].clear();\n\t}\n\tvoid getsub(int x,int y,int root)\n\t{\n\t\tsub[root].push_back(x);\n\t\tfor(int i=0,t;it2)swap(t1,t2);\n\t\treturn t1*seed+t2;\n\t}\n\tvoid solve(int x)\n\t{\n\t\tid=x;init();\n\t\tscanf(\"%d\",&m);\n\t\tfor(int i=1,x,y;i<=m;i++)\n\t\t{\n\t\t\tscanf(\"%d%d\",&x,&y);\n\t\t\tv[x].push_back(y);\n\t\t\tv[y].push_back(x);\n\t\t}\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tif(!used[i])\n\t\t\t{\n\t\t\t\tgetsub(i,0,i);\n\t\t\t\tval[i]=cal(i);\n\t\t\t\tv2.push_back(val[i]);\n\t\t\t}\n\t\tsort(v2.begin(),v2.end());\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tif(sub[i].size())\n\t\t\t{\n\t\t\t\tull t1=0,t2=0,t3=0;\n\t\t\t\tfor(int j=0,flag=0;j\n#define ll long long\nusing namespace std;\nconst int N=2e5+5;\nint main()\n{\n ll n,k,ans1,ans2,ans3;\n cin>>n>>k;\n ll low=1,high=1e10;\n while(low<=high)\n {\n ll mid=(low+high)/2;\n if(2*n<=mid*k)\n {\n ans1=mid;\n high=mid-1;\n }\n else\n low=mid+1;\n }\n low=1,high=1e10;\n while(low<=high)\n {\n ll mid=(low+high)/2;\n if(5*n<=mid*k)\n {\n ans2=mid;\n high=mid-1;\n }\n else\n low=mid+1;\n }\n low=1,high=1e10;\n while(low<=high)\n {\n ll mid=(low+high)/2;\n if(8*n<=mid*k)\n {\n ans3=mid;\n high=mid-1;\n }\n else\n low=mid+1;\n }\n cout<\nusing namespace std;\nint y,m,d;\ninline long long get(int y,int m,int d)\n{\n\tif (m<3) {y-=1;m+=12;}\n\treturn 365*y+y/4-y/100+y/400+(153*m-457)/5+d-306;\n}\ntemplateinline void read(T &res)\n{\n\tstatic char ch;T flag=1;\n\twhile((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48;\n\twhile((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;\n}\nint main()\n{\n\tread(y);read(m);read(d);long long a=get(y,m,d);\n\tread(y);read(m);read(d);long long b=get(y,m,d);\n\tprintf(\"%lld\\n\",abs(b-a));\n\treturn 0;\n}", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c"} {"source_code": "#include \n#define inf 0x3f3f3f3f\n#define lc k << 1\n#define rc k << 1 | 1\nusing namespace std;\n\nint n, k;\n\nstruct segment{\n\tint l, r;\n}a[105];\n\nstruct node{\n\tint l, r, dat, tag;\n};\nint tmp[200005], tmp2[200005];\nstruct seg{\n\tnode d[800005];\n\t\n\tvoid pushup(int k){\n\t\td[k].dat = min(d[lc].dat, d[rc].dat);\n\t}\t\n\tvoid build(int k, int l, int r){\n\t\td[k].l = l; d[k].r = r; d[k].tag = inf;\n\t\tif(l == r) {\n\t\t\td[k].dat = inf; return;\n\t\t}\n\t\tint mid = (l + r) >> 1;\n\t\tbuild(lc, l, mid);\n\t\tbuild(rc, mid + 1, r);\n\t\tpushup(k);\n\t} \n\tvoid minn(int k, int x){\n\t\td[k].dat = min(d[k].dat, x);\n\t\td[k].tag = min(d[k].tag, x);\n\t}\n\t\n\tvoid pushdown(int k){\n\t\tminn(lc, d[k].tag);\n\t\tminn(rc, d[k].tag);\n\t\td[k].tag = inf;\n\t}\n\tvoid minn(int k, int l, int r, int x){\n\t\tif(l <= d[k].l && d[k].r <= r){\n\t\t\tminn(k, x);\n\t\t\treturn;\n\t\t}\n\t\tpushdown(k);\n\t\tint mid = (d[k].l + d[k].r) >> 1;\n\t\tif(l <= mid) minn(lc, l, r, x);\n\t\tif(r > mid) minn(rc, l, r, x);\n\t\tpushup(k);\n\t}\n\tint query(int k, int pos){\n\t\tif(d[k].l == d[k].r) return d[k].dat;\n\t\tpushdown(k);\n\t\tint mid = (d[k].l + d[k].r) >> 1;\n\t\tif(pos <= mid) return query(lc, pos);\n\t\telse return query(rc, pos);\n\t}\n}Seg, Seg2;\nint f[2][200005][2];\nint main(){\n\tscanf(\"%d%d\", &n, &k);\n\tfor(int i = 1; i <= k; i ++){\n\t\tscanf(\"%d%d\", &a[i].l, &a[i].r);\n\t}\n\tmemset(f, 0x3f, sizeof(f));\n\tf[0][0][0] = 0;\n\tmemset(tmp, 0x3f, sizeof(tmp));\n\tmemset(tmp2, 0x3f, sizeof(tmp2));\n\t\n\tfor(int I = 1; I <= k; I ++){\n\t\tfor(int i = 0; i <= 2 * n; i ++){\n\t\t\ttmp[i + 1] = f[(I & 1) ^ 1][i][0];\n\t\t\ttmp2[i + 1] = f[(I & 1) ^ 1][i][1];\n\t\t}\n\t\tSeg.build(1, 1, 2 * n + 1);\n\t\tSeg2.build(1, 1, 2 * n + 1);\n\t\tfor(int i = n + 1; i >= 1; i --){\n\t\t\tif(tmp[i] <= 200){\n\t\t\t\tSeg.minn(1, i, i + a[I].r - a[I].l, tmp[i] + 2);\n\t\t\t\tSeg2.minn(1, i, i + a[I].r - a[I].l, tmp[i] + 1);\n\t\t\t\tSeg.minn(1, i, i, tmp[i]);\n\t\t\t}\n\t\t\tif(tmp2[i] <= 200){\t\n\t\t\t\tSeg.minn(1, i + a[I].l - a[I - 1].r, i + a[I].r - a[I - 1].r, tmp2[i] + 1);\n\t\t\t\tSeg2.minn(1, i + a[I].l - a[I - 1].r, i + a[I].r - a[I - 1].r, tmp2[i] + 2);\n\t\t\t\tSeg2.minn(1, i + a[I].r - a[I - 1].r, i + a[I].r - a[I - 1].r, tmp2[i]);\t\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i <= n; i ++){\n\t\t\tf[I & 1][i][0] = Seg.query(1, i + 1);\n\t\t\tf[I & 1][i][1] = Seg2.query(1, i + 1);\n\t\t//\tprintf(\"%d \", f[I & 1][i][1]);\n\t\t}\n\t\t//printf(\"\\n\");\n\t}\n\tint ans = f[k & 1][n][0];\n\tif(a[k].r >= n) ans = min(ans, f[k & 1][a[k].r - n][1]);\n\tif(ans <= 200){\n\t\tprintf(\"Full\\n%d\\n\", ans);\n\t}else{\n\t\tprintf(\"Hungry\\n\");\n\t}\n\treturn 0;\n}\n", "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5"} {"source_code": "\n// In the name of God\n#include \n\nusing namespace std;\n#define Size(x) ((int)(x).size())\n#define pb push_back\ntypedef long long ll;\ntypedef pairpii;\nconst int INF = 1e9 + 10 , MN = 1e5 + 5;\n\nint n , m , es[MN] , ee[MN] , st[MN] , ft[MN] , h[MN] , Time;\nvectoradj[MN];\nbool mk[MN];\n\nvoid dfs(int s){\n\tmk[s] = true;\n\tst[s] = Time++;\n\tfor(auto v:adj[s])\n\t\tif(!mk[v]) h[v] = h[s]+1 , dfs(v);\n\tft[s] = Time;\n}\n\nbool check(int x){\n\tfor(int i=0;i> n >> m;\n\tfor(int i=0;i> es[i] >> ee[i];\n\t\tadj[--es[i]].pb(--ee[i]);\n\t}\n\tdfs(0);\n\tvectorD;\n\tfor(int i=0;ires;\n\t\tfor(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n\n\n\nint main() {\n\tstring a, b, r;\n\tcin >> a >> b;\n\n\tfor (int i = 0; i < a.size(); i++) {\n\t\tfor (int j = 0; j < b.size(); j++) {\n\t\t\tstring s = a.substr(0, i + 1) + b.substr(0, j + 1);\n\t\t\tif (r == \"\" || s < r)\n\t\t\t\tr = s;\n\t\t}\n\t}\n\n\tcout << r;\n}", "src_uid": "aed892f2bda10b6aee10dcb834a63709"} {"source_code": "#include \n\nusing namespace std;\n\n#define add_const ADD_CONST\n\nstruct Segment {\n long long sum;\n long long min_odd;\n long long min_even;\n int len;\n};\n\nSegment unite(Segment a, Segment b) {\n Segment c;\n c.len = b.len + a.len;\n c.sum = b.sum + ((b.len & 1) ? (-a.sum) : a.sum);\n if (a.len & 1) {\n c.min_even = min(a.min_even, -a.sum + b.min_odd);\n c.min_odd = min(a.min_odd, a.sum + b.min_even);\n } else {\n c.min_even = min(a.min_even, a.sum + b.min_even);\n c.min_odd = min(a.min_odd, -a.sum + b.min_odd);\n }\n return c;\n}\n\nconst int N = 1234567;\n\nSegment a[N];\nint add[N];\n\nvoid build(int x, int l, int r) {\n a[x].len = r - l + 1;\n a[x].sum = a[x].min_odd = a[x].min_even = 0;\n if (l < r) {\n int y = (l + r) >> 1;\n build(x + x, l, y);\n build(x + x + 1, y + 1, r);\n }\n}\n\nvoid add_const(int x, int value) {\n if (a[x].len & 1) {\n a[x].sum += value;\n }\n a[x].min_odd += value;\n add[x] += value;\n}\n\nvoid push(int x) {\n if (add[x] != 0) {\n add_const(x + x, add[x]);\n add_const(x + x + 1, add[x]);\n add[x] = 0;\n }\n}\n\nvoid modify(int x, int l, int r, int ll, int rr, int v) {\n if (ll <= l && r <= rr) {\n add_const(x, v);\n return;\n }\n push(x);\n int y = (l + r) >> 1;\n if (ll <= y) {\n modify(x + x, l, y, ll, rr, v);\n }\n if (rr > y) {\n modify(x + x + 1, y + 1, r, ll, rr, v);\n }\n a[x] = unite(a[x + x], a[x + x + 1]);\n}\n\nSegment solve(int x, int l, int r, int ll, int rr) {\n if (ll <= l && r <= rr) {\n return a[x];\n }\n push(x);\n int y = (l + r) >> 1;\n Segment res;\n if (rr <= y) {\n res = solve(x + x, l, y, ll, rr);\n } else {\n if (ll > y) {\n res = solve(x + x + 1, y + 1, r, ll, rr);\n } else {\n res = unite(solve(x + x, l, y, ll, rr), solve(x + x + 1, y + 1, r, ll, rr));\n }\n }\n a[x] = unite(a[x + x], a[x + x + 1]);\n return res;\n}\n\nint main() {\n int n;\n scanf(\"%d\", &n);\n build(1, 0, n - 1);\n for (int i = 0; i < n; i++) {\n int foo;\n scanf(\"%d\", &foo);\n modify(1, 0, n - 1, i, i, foo);\n }\n int tt;\n scanf(\"%d\", &tt);\n while (tt--) {\n int type;\n scanf(\"%d\", &type);\n if (type == 1) {\n int from, to, value;\n scanf(\"%d %d %d\", &from, &to, &value);\n modify(1, 0, n - 1, from, to, value);\n } else {\n int from, to;\n scanf(\"%d %d\", &from, &to);\n Segment res = solve(1, 0, n - 1, from, to);\n printf(\"%d\\n\", (res.sum == (res.len & 1) && res.min_odd >= 1 && res.min_even >= 0) ? 1 : 0);\n }\n }\n return 0;\n}", "src_uid": "a17833a733d59936d1c3ba5f27b0cbe0"} {"source_code": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\nconst int N = 505;\nvector sets[N];\nint mark[N];\nchar map[N][N];\n\nbool bySize(int i, int j) {\n return sets[i].size() > sets[j].size();\n}\n\nint findGood(vector > &cur, vector &row) {\n for (int i = 0; i < (int)cur.size(); ++i) {\n for (int j = 0; j < (int)cur[i].size(); ++j) {\n mark[cur[i][j]] = i;\n }\n }\n for (int i = 0; i < (int)row.size(); ++i) {\n int u = row[i];\n for (int j = 1; j < (int)sets[u].size(); ++j) {\n if (mark[sets[u][j]] != mark[sets[u][j - 1]]) {\n return u;\n }\n }\n }\n return -1;\n}\n\nbool solve(vector &col, vector &row, vector &ret) {\n if (row.size() == 0) {\n ret = col;\n return true;\n }\n sort(row.begin(), row.end(), bySize);\n vector > cur;\n vector one, zero, cut;\n int p;\n p = row.front();\n row.erase(row.begin());\n cut.push_back(p);\n for (int i = 0; i < col.size(); ++i) {\n int u = col[i];\n if (map[p][u] - '0') {\n one.push_back(u);\n } else {\n zero.push_back(u);\n }\n }\n if (!one.size() || !zero.size()) {\n return solve(col, row, ret);\n }\n cur.push_back(one);\n cur.push_back(zero);\n if (row.size() == 0) {\n ret.clear();\n for (int i = 0; i < (int)cur.size(); ++i) {\n for (int j = 0; j < (int)cur[i].size(); ++j) {\n ret.push_back(cur[i][j]);\n }\n }\n return true; \n }\n bool special = true;\n while ((p = findGood(cur, row)) != -1) {\n for (int i = 0; i < (int)row.size(); ++i) {\n if (row[i] == p) {\n row.erase(row.begin() + i);\n break;\n }\n }\n cut.push_back(p);\n int state = 0;\n bool fail = false;\n vector > rem;\n for (int i = 0; i < (int)cur.size(); ++i) {\n vector tmp = cur[i], one, zero; \n for (int j = 0; j < (int)tmp.size(); ++j) {\n if (map[p][tmp[j]] - '0') {\n one.push_back(tmp[j]);\n } else {\n zero.push_back(tmp[j]);\n }\n }\n if (state == 0) {\n if (zero.size()) {\n rem.push_back(zero);\n }\n if (one.size()) {\n rem.push_back(one);\n state = 1;\n }\n } else if (state == 1) {\n if (one.size()) {\n rem.push_back(one);\n }\n if (zero.size()) {\n rem.push_back(zero);\n state = 2;\n }\n } else {\n if (zero.size()) {\n rem.push_back(zero);\n }\n if (one.size()) {\n if (i != (int)cur.size() - 1 || !special) {\n return false;\n } else {\n fail = true;\n }\n }\n }\n }\n if (fail) {\n fail = false;\n rem.clear();\n state = 0;\n for (int i = 0; i < (int)cur.size(); ++i) {\n vector tmp = cur[i], one, zero; \n for (int j = 0; j < (int)tmp.size(); ++j) {\n if (map[p][tmp[j]] - '0') {\n one.push_back(tmp[j]);\n } else {\n zero.push_back(tmp[j]);\n }\n }\n if (i == (int)cur.size() - 1) {\n if (one.size()) {\n rem.insert(rem.begin(), one);\n }\n if (zero.size()) {\n rem.push_back(zero);\n }\n continue;\n }\n if (one.size()) {\n rem.push_back(one);\n if (state == 0) {\n state = 1;\n } else if (state == 2) {\n return false;\n }\n }\n if (zero.size()) {\n rem.push_back(zero);\n if (state == 0) {\n return false;\n } else if (state == 1) {\n state = 2;\n }\n }\n }\n }\n cur = rem;\n special = true;\n int col1 = cur.back().front(), col2 = cur[cur.size() - 1].back();\n for (int i = 0; i < cut.size() && special; ++i) {\n int u = cut[i];\n if (map[u][col1] == '1' && map[u][col2] == '1') {\n special = false;\n }\n }\n }\n vector > cur_row;\n vector empty;\n for (int i = 0; i < (int)cur.size(); ++i) {\n cur_row.push_back(empty);\n }\n for (int i = 0; i < (int)row.size(); ++i) {\n int u = row[i];\n if (sets[u].size() == 0) {\n continue;\n }\n cur_row[mark[sets[u].front()]].push_back(u);\n }\n ret.clear();\n vector tmp;\n for (int i = 0; i < (int)cur.size(); ++i) {\n if (solve(cur[i], cur_row[i], tmp)) {\n for (int j = 0; j < (int)tmp.size(); ++j) {\n ret.push_back(tmp[j]);\n }\n tmp.clear();\n } else {\n return false;\n }\n }\n return true;\n}\n\nint main() {\n int n;\n vector col, row, ret;\n scanf(\"%d\", &n);\n for (int i = 0; i < n; ++i) {\n scanf(\"%s\", map[i]);\n for (int j = 0; j < n; ++j) {\n if (map[i][j] - '0') {\n sets[i].push_back(j);\n }\n }\n col.push_back(i);\n row.push_back(i);\n }\n if (solve(col, row, ret)) {\n puts(\"YES\");\n char ans[N];\n ans[n] = 0;\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n ans[j] = map[i][ret[j]];\n }\n printf(\"%s\\n\", ans);\n }\n } else {\n puts(\"NO\");\n }\n return 0;\n}", "src_uid": "af8d46722e1bd8f7392e5596eaf4def8"} {"source_code": "#include\n#include\n#include\n#include\nusing namespace std;\nlong long ans,C[120][120],n,t,m,i,o,s,j;\nint main(){\n\tscanf(\"%I64d%I64d\",&n,&t);\n\tfor(s=1,m=1;s=0;--i){\n\t\tif(m<0)break;\n\t\tif(o+(1ll<//CF1029F\n#include\n#include\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\nlong long a,b,c,d;\n\nbool check(int u,long long v){\n\tfor(int i=1;i<=u;i++){\n\t\tif(a%i==0){\n\t\t\tlong long rep=a/i;\n\t\t\tif(i<=u&&rep<=v){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\tfor(int i=1;i<=u;i++){\n\t\tif(b%i==0){\n\t\t\tlong long rep=b/i;\n\t\t\tif(i<=u&&rep<=v){\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nint main(){\n\tscanf(\"%lld%lld\",&a,&b);\n\tc=a+b;\n\tfor(int i=(int)sqrt(c);i;i--){\n\t\tif(c%i==0){\n\t\t\td=c/i;\n\t\t\tif(check(i,d)){\n\t\t\t\tprintf(\"%lld\",(d+i)*2);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"} {"source_code": "#include\nusing namespace std;\n#define LL long long \n#define pb push_back\n#define OO ios_base::sync_with_stdio(0); cin.tie(NULL)\n\ninline int parser(LL int item)\t\n\t{\n\t\tLL int sum=0;\n\n\t\twhile ( item / 10 != 0)\n\t\t{\n\t\t\t\n\t\t\t\n\n\t\t\tsum += item % 10;\n\t\t\titem = item / 10;\n\n\n\t\t}\n\n\t\tsum += item ;\n\n\t\treturn sum;\n\t}\n\n\tint main()\n\t\t{\n\t\t\tLL int i , j , counter , a,n;\n\n\t\t\tcin >> n;\n\t\t\ti=1;\n\t\t\tcounter =0;\n\n\t\t\twhile (true)\n\t\t\t\t\t{\n\n\t\t\t\t\t\t//cout << parser(28)<< endl;;\n\n\t\t\t\t\t\tif ( parser(i) == 10)\n\t\t\t\t\t\t\t\t{\n\n\t\t\t\t\t\t\t\t\tcounter++;\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif ( counter == n)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\telse i++;\n\n\t\t\t\t\t}\n\n\n\t\t\t\t\tcout << i ;\n\n\t\t}", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"source_code": "#include \nusing namespace std;\nconst int N = 20 , MAX = 2e5+5 , OO = 1000000009;\nstring sBits = \"0101\";\nbitset x(sBits);\nvector v;\nvoid brute(long long num){\n\tv.push_back(num);\n\tif (num > 1e9) return;\n\tbrute(num * 10 + 4);\n\tbrute(num * 10 + 7);\n }\nint n;\nint main(){\n scanf(\"%d\" , &n);\n brute(0);\n sort(v.begin(), v.end());\n\tfor(int it = 0; it < v.size(); ++it){\n if (v [it] == n)\n {\n printf(\"%d\\n\" , it) ;\n return 0 ;\n }\n }\n}", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"source_code": "\n#include\n\nusing namespace std;\n\n#define sf scanf\n#define pf printf\n#define ll long long\n#define fr(I,M,N) for(I=M;I<=N;I++)\n#define fr_(I,M,N) for(I=M;I>=N;I--)\n#define re return\n#define sfn cin>>n\n#define bal pf(\"bal\\n\")\n#define pb push_back\n#define ins insert\n#define sz(X) X.size()\n#define xx first\n#define yy second\n#define cont continue\n#define memo(X,N) memset(X,N,sizeof(X))\n#define all(X) X.begin(),X.end()\n\n/*int pr[100000],prnum[1000001];\n\nvoid sieve()\n{\n int i,j;\n for(i=1;i<=1000000;i++)\n prnum[i]=i+1;\n for(i=1;i<=1000000;i++)\n if(prnum[i]!=-1)\n for(j=2*prnum[i]-1;j<=1000000;j+=prnum[i])\n prnum[j]=-1;\n j=1;\n for(i=1;i<=1000000;i++)\n if(prnum[i]!=-1)\n pr[j++]=prnum[i];\n}*/\n\n/*ll m_ncr[10001][10001];\nll ncr(ll i,ll j)\n{\n if(j==1) re i;\n if(i==j) re 1;\n if(m_ncr[i][j]!=-1) re m_ncr[i][j];\n re m_ncr[i][j]=ncr(i-1,j) + ncr(i-1,j-1);\n}*/\n\n/*ll m_fact[21];\nll fact(ll i)\n{\n if(i==1) re 1;\n if(m_fact[i]!=-1) re m_fact[i];\n re m_fact[i]=i*func(i-1);\n}*/\n\n\n\nint main()\n{\n ios_base::sync_with_stdio(0);\n int i,j,x,n,cnt=0,m,y,mx,mnn,mxx,mn;\n cin>>n;\n int in[n+1];\n fr(i,1,n)\n cin>>in[i];\n if(!n)\n {\n cout<<\"YES\\n113\\n113\\n339\\n339\";\n }\n else if(n==1)\n {\n cout<<\"YES\\n\"<\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 l1 long\n#define pb push_back\n#define ppb pop_back\n#define mp make_pair\n#define sy system(\"pause\");\nusing namespace std;\n\nint main(){\n#ifdef LOCAL\n freopen(\"INPUT.TXT\",\"r\", stdin);\n freopen(\"OUTPUT.TXT\",\"w\", stdout);\n#endif\n int n,n1,k1,k2;\n cin>>n>>n1>>k1>>k2;\n\n if(n<=n1)\n cout<<\"Second\";\n else\n cout<<\"First\";\n\n \n\n #ifdef LOCAL\n cerr << clock()*1.0/CLOCKS_PER_SEC<\n#include\n#include\nusing namespace std;\nconst int N=400100;\ninline int read(){\n\tint x=0,c=getchar(),f=0;\n\tfor(;c>'9'||c<'0';f=c=='-',c=getchar());\n\tfor(;c>='0'&&c<='9';c=getchar())\n\tx=(x<<1)+(x<<3)+c-'0';return f?-x:x;\n}\nstruct cqz{int r1,c1,r2,c2,i;}q[N];\ninline bool operator<(cqz i,cqz j){return i.r2r)swap(l,r);int ln=r-l+1,k;\n\tk=lg[ln];r=r-(1<>1]<=k)r=l+r>>1;\n\telse l=l+r>>1;return r;\n}\ninline void getans(cqz x,int l,int r){\n\tl--;r++;\n\tint res=2e9,lm,rm,len,ls,rs;\n\twhile(lrs)l=lm;else r=rm;\n\t}for(l++;l=a[i])\n\t\ttop--;sta[++top]=i;\n\t\tfor(;k<=m&&q[k].r2==i;k++)\n\t\tif(q[k].r1<=r2){\n\t\t\tint pos=lower_bound(sta,sta+top+1,q[k].r1)-sta;\n\t\t\tgetans(q[k],pos,top);getans(q[k],1,pos-1);\n\t\t\tint res=abs(q[k].r2-q[k].r1);\n\t\t\tint mn=q[k].c1;\n\t\t\tmn=min(mn,getst(q[k].r1,q[k].r2));\n\t\t\tres+=abs(mn-q[k].c2);\n\t\t\tans[q[k].i]=min(ans[q[k].i],res);\n\t\t}else getans(q[k],1,top);\n\t}top=0;k=m;\n\tfor(i=n;i;i--){\n\t\twhile(top&&a[sta[top]]>=a[i])\n\t\ttop--;sta[++top]=i;\n\t\tfor(;k>0&&q[k].r2==i;k--)\n\t\tif(q[k].r1>r2){\n\t\t\tint pos=getpos(1,top,q[k].r1);\n\t\t\tgetans(q[k],pos,top);getans(q[k],1,pos-1);\n\t\t\tint res=abs(q[k].r2-q[k].r1);\n\t\t\tint mn=q[k].c1;\n\t\t\tmn=min(mn,getst(q[k].r1,q[k].r2));\n\t\t\tres+=abs(mn-q[k].c2);\n\t\t\tans[q[k].i]=min(ans[q[k].i],res);\n\t\t}else getans(q[k],1,top);\n\t}for(i=1;i<=m;i++)printf(\"%d\\n\",ans[i]);\n\treturn 0;\n}\n", "src_uid": "79b6cdbcdfcf00e0649dfc85af46d021"} {"source_code": "#include\n\nusing namespace std;\n\nint a1,a2,a3,b1,b2,b3,n;\n\nint main(){\n \n cin>>a1>>a2>>a3>>b1>>b2>>b3>>n;\n \n int a = (a1+a2+a3 + 4) / 5;\n int b = (b1+b2+b3 + 9) / 10;\n \n cout<<(a+b<=n ? \"YES\" : \"NO\")<\n \nconst long long mod = 1000000007;\n \nstruct matrix{\n int N; long long A[82][82];\n matrix(int n){\n N = n;\n for (int i=0;i>= 1;\n }\n \n long long ans = 0;\n for (int i=0;i<=K+1;i++){\n ans += R.A[K][i];\n }\n printf (\"%lld\\n\",ans%mod);\n \n return 0;\n}\n\n", "src_uid": "14f50a111db268182e5927839a993118"} {"source_code": "#include\nusing namespace std;\n#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);\n#define ll long long int\n#define ull unsigned long long int\n#define ld long double\n#define mod 1000000007\n#define inf 100000000000000007\n#define eps 0.000001\n#define pi 3.141592653589793\n#define pii pair\n#define pdd pair\n#define pll pair\n#define ff first\n#define ss second\n#define vii vector\n#define vpl vector\n#define vll vector\n#define sti stack \n#define stll stack \n#define mseti multiset \n#define msetd multiset >\n#define mp make_pair\n#define pb push_back\n#define lb lower_bound\n#define ub upper_bound \n#define stp setprecision(20)//use fixed before stp\n#define endl '\\n'\nint main()\n{ \n FAST\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\" , \"rt\" , stdin);\n freopen(\"output.txt\" , \"wt\" , stdout);\n #endif\n ld a,b,m;\n cin>>a>>b>>m;\n ld x,y,z,t;\n cin>>x>>y>>z;\n t=m/y;\n t=abs(t);\n x=x*t;\n z=z*t;\n x+=(a/2);\n while((z<0)||(z>b))\n {\n if(z>b)\n z=(2*b)-z;\n else if(z<0)\n z=abs(z);\n }\n while((x<0)||(x>a))\n {\n if(x>a)\n x=(2*a)-x;\n else if(x<0)\n x=abs(x);\n }\n cout<\n\nusing namespace std;\n\nint main(){\n long long m, n;\n cin >> m >> n;\n\n //cout << ((int(sqrt(n*2)) * int(sqrt(n*2)+ 1)))/2 << endl;\n if (m - 2 * n <= 0) cout << 0 <<\" \";\n else cout << m - 2 * n <<\" \";\n if (n == 0) {cout << m; exit(0);}\n if (int(sqrt(n * 2)) * int(sqrt(n * 2) + 1)/2 >= n) cout << m - (int(sqrt(n*2) + 1));\n else{\n if (int(sqrt(n*2)) == sqrt(n*2)) cout << m - int(sqrt(n*2) + 1);\n else\n {\n if (m - int(sqrt(n*2) + 2) >= 0) cout << m - int(sqrt(n*2) + 2);\n else cout << 0;\n //cout << endl << \"loai 2\";\n }\n }\n return 0;\n}\n", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint alpha[26];\nvoid filll(string &s)\n{\n for(int i=0;i1)\n return false;\n }\n return true;\n}\nint main()\n{\n //freopen(\"input.txt\", \"r\", stdin);\n // freopen(\"output.txt\", \"w\", stdout);\n\n string s;\n cin>>s;\n vector Exlac;\n if(s.size()<26)\n {cout<<-1; return 0;}\n\n for(int i=25;i=i-25;j--)\n {\n if(s[j]=='?')\n {Exlac.push_back(j); continue;}\n alpha[s[j]-'A']++;\n }\n\n if(valid())\n {\n for(int k=0;k\n#include\n#include\n#include\nusing namespace std;\nconst int nn=100005;\nconst double eps=1e-10;\nstruct point{double x,y;}a[nn],b[nn];\nint n,m,t,l[nn],r[nn];\nint h[nn],p[nn];\ndouble R,c[nn];\ninline double cp(const point &x,const point &y,const point &z){\n\treturn (x.x-z.x)*(y.y-z.y)-(x.y-z.y)*(y.x-z.x);\n}\ninline double dis(const point &x,const point &y){\n\treturn sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));\n}\ninline bool cmp(const point &x,const point &y){\n\tdouble z=cp(x,y,a[1]);\n\tif(z>eps)return 1;\n\tif(z<-eps)return 0;\n\treturn dis(x,a[1])1&&cp(a[i],b[m],b[m-1])>-eps;--m);\n\t\tb[++m]=a[i];\n\t}\n}\ninline void change(int x,int y){\n\tswap(p[h[x]],p[h[y]]);\n\tswap(h[x],h[y]);\n}\nvoid up(int x){\n\tfor(;x>1&&c[h[x]]>c[h[x>>1]];x>>=1)change(x,x>>1);\n}\nvoid down(int x){\n\tfor(int y=x<<1;y<=t;x=y,y=x<<1){\n\t\tif(yR){\n\t\tint i=h[1];\n\t\tl[r[i]]=l[i];r[l[i]]=r[i];\n\t\tchange(1,t--);down(1);\n\t\tcalc(l[i]);calc(r[i]);\n\t}\n\tint j=h[1];\n\tdouble s=count(j,l[j])+count(j,r[j]);\n\tfor(int i=r[j];r[i]!=j;i=r[i])\n\t\ts+=abs(cp(b[i],b[r[i]],b[j]))/2+count(i,r[i]);\n\tprintf(\"%.10lf\\n\",s);\n}\nint main(){\n\tinit();\n\twork();\n\treturn 0;\n}\n\n", "src_uid": "5f2a0960bab9bdc91b190ed07d6adcf7"} {"source_code": "#include\nusing namespace std;\nint n,m,z,ans;\nint main()\n{\n\tcin>>n>>m>>z;\n\tfor(int i=1;i<=z;i++)\n\t{\n\t\tfor(int j=1;j<=z;j++)\n\t\t{\n\t\t\tif(n*i==m*j&&n*i<=z&&m*j<=z)\n\t\t\t{\n\t\t\t\tans++;\n\t\t\t\t//cout<\nusing namespace std;\nint i=0,l,n=0;char s[60];int main(){scanf(\"%d%s\",&l,s);for(;i\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#include\n#define ll long long\n#define pii pair\n#define pip pair\nusing namespace std;\nll mod=1000000007;\nll inf=1LL<<60;\nconst int N=5000;\nvector primes;\nll ans=inf;\nvector> tree(N+1);\nvector> facts;\nvector p;\nvector dists;\nvector subtree;\nvoid preprocess(){\n facts.resize(N+1);\n p.resize(N+1);\n primes.push_back(2);\n facts[1][1]=0;\n facts[2][2]=1;\n p[2]=1;\n p[1]=0;\n // ll sum=0;\n for (int i=3;i<=N;i++){\n bool isPrime=true;\n for (int a:primes){\n if (!(i%a)){\n isPrime=false;\n facts[i]=facts[i/a];\n p[i]=p[i/a]-p[i/a-1]+1+p[i-1];\n facts[i][a]++;\n break;\n }\n }\n if (isPrime){\n primes.push_back(i);\n p[i]=p[i-1]+1;\n facts[i][i]=1;\n }\n // sum+=p[i];\n// cout<> comps(5001);\nvoid dfs(int curr, int par){\n // cout<=0;i--){\n if (primes[i]==big){\n cnt=i;\n break;\n }\n }\n // cout<0;i--){\n // if (curr<10)\n // cout<=0 && (*facts[comps[curr][it]].rbegin()).first==primes[i]){\n tree.emplace_back();\n tree[lst].emplace_back(tree.size()-1,sum);\n tree.back().emplace_back(lst,sum);\n lst=tree.size()-1;\n dfs(comps[curr][it],tree.size()-1);\n it--;\n sum=0;\n }\n temp=curr;\n while(temp>=primes[i-1]){\n temp/=primes[i-1];\n sum+=temp;\n }\n }\n tree[lst].emplace_back(curr,sum);\n tree[curr].emplace_back(lst,sum);\n lst=curr;\n if (it>=0 && (*facts[comps[curr][it]].rbegin()).first==2){\n dfs(comps[curr][it],lst);\n }\n}\nvoid dfs2(int curr, int par){\n for (pii& i:tree[curr]){\n if (i.first!=par){\n dfs2(i.first,curr);\n subtree[curr]+=subtree[i.first];\n dists[curr]+=dists[i.first]+subtree[i.first]*i.second;\n }\n }\n // if (subtree[curr]>0)\n // cout<>n;\n //tree.resize(n);\n preprocess();\n for (int i=2;i<=5000;i++){\n int curr=1;\n int big= (*facts[i].rbegin()).first;\n while(!comps[curr].empty() && (*facts[comps[curr].back()].rbegin()).first>=big){ //equals still follows trail\n curr=comps[curr].back();\n }\n comps[curr].push_back(i);\n\n }\n for (int a:comps[1]){\n dfs(a,1);\n }\n// for (int i=1;i<=n;i++){\n// cout<5100){\n// continue;\n// }\n// cout<>a;\n if (a==0){\n a++;\n }\n subtree[a]++;\n }\n dfs2(1,-1);\n dfs3(1,-1,0);\n cout<\n#include\n#include\nusing namespace std;\nint main()\n{\n\tint a,b[9],c=1,d;\n\tcin>>a;\n\tfor (int i=1;i<=7;i++)\n\tcin>>b[i];\n\twhile (1){\n\t\tc=c%7==0?7:c%7;\n\t\ta-=b[c];\n\t\tc++;\n\t\tif (a<=0) {\n\t\t\tcout<\n#include \n#include \n#include \nusing namespace std;\nint main(){\n\tstring s;\n\tlong long n, m, l=0, d, r,a[200002]={0},k=0, b[10001]={0}, y, ra,x;\n\n\tcin>>n>>y>>x>>k;\n\tn--;\n\tif (n==0)\n\tcout<<0;\n\telse if (k\n#include\n#include\n#include\n#include\n\nusing namespace std;\n\nint main()\n{\n\tchar arr[4][4];\n\tint hash = 0, dot = 0;\n\tfor (int i = 0; i < 4; i++)\n\t{\n\t\tfor (int j = 0; j < 4; j++)\n\t\t{\n\t\t\tcin >> arr[i][j];\n\t\t}\n\t}\n\n\tfor (int i = 0; i < 3; i++)\n\t{\n\t\tfor (int j = 0; j < 3; j++)\n\t\t{\n\t\t\tif (arr[i][j] == '#')\n\t\t\t\thash++;\n\t\t\telse\n\t\t\t\tdot++;\n\t\t\tif (arr[i][j + 1] == '#')\n\t\t\t\thash++;\n\t\t\telse\n\t\t\t\tdot++;\n\t\t\tif (arr[i + 1][j] == '#')\n\t\t\t\thash++;\n\t\t\telse\n\t\t\t\tdot++;\n\t\t\tif (arr[i + 1][j + 1] == '#')\n\t\t\t\thash++;\n\t\t\telse\n\t\t\t\tdot++;\n\n\t\t\tif (hash >= 3 || dot >= 3)\n\t\t\t{\n\t\t\t\tcout << \"YES\";\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\thash = dot = 0;\n\n\t\t}\n\t}\n\tcout << \"NO\";\n\treturn 0;\n}", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"source_code": "#include \nusing namespace std;\nint main()\n{ \n\tstring s;\n \tcin>>s;\n \tfor(int i=0;i\n#include\nmain()\n{\n\tint i,c,s,b[200],l;\n\tchar a[100],q;\n i=0;\n\tq='V';\n\tc=0;\n\ts=0;\n\tscanf(\"%s\",a);\n\tl=strlen(a);\n\tfor (i=0;i\r\nusing namespace std;\r\ntypedef long long ll;\r\n/*\r\n两个数相乘再除以这两个数的最大公约数 \r\n*/\r\nconst int N=12252245;\r\nconst int M=998244353;\r\nll cnt[N][2],n,LCM;\r\nint getlcm(int k){\r\n\tint lcm=1;\r\n\tfor(int i=1;i<=k;i++){\r\n\t\tint gc=__gcd(i,lcm);\r\n\t\tlcm=lcm/gc*i;\r\n\t}\r\n\treturn lcm;\r\n}\r\nll qmod(ll a,ll b){\r\n\tll res=1;\r\n\twhile(b){\r\n\t\tif(b&1)res=res*a%M;\r\n\t\ta=a*a%M;\r\n\t\tb>>=1;\r\n\t}\r\n\treturn res;\r\n}\r\nll solve(int Pow,int m,int f){\r\n\tll fm=1,ans=0;\r\n\tfor(int i=1;i<=Pow;i++)fm=fm*n%M;\r\n\tfm=qmod(fm,M-2);\r\n\tfor(int i=0;i\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef complex base;\n\n#define pii pair\n#define pll pair\n#define PB push_back\n#define MP make_pair\n#define K (1 << 15)\n#define MOD 998244353\n#define PROOT 3\n#define B 2\n\nint N = K << 1, N_INV;\nvector swapIndex(N);\nvector omega(N), omega_inv(N), a[B][B], b[B][B], new_a[B][B], new_b[B][B];\nll ROOT, ROOT_INV;\n\nll ModularExponentation(ll a, ll n){\n ll ans = 1;\n\n for( ; n > 0; n /= 2){\n if(n % 2)\n ans = (ans * a) % MOD;\n a = (a * a) % MOD;\n }\n\n return ans;\n}\n\nvoid InitializeData(){\n for(int i = 0; i < B; i++)\n for(int j = 0; j < B; j++)\n a[i][j].resize(N), b[i][j].resize(N), new_a[i][j].resize(N), new_b[i][j].resize(N);\n\n a[0][0][0] = a[0][0][1] = a[0][1][1] = a[1][0][0] = 1;\n b[0][0][0] = b[0][0][1] = b[1][0][0] = 1;\n}\n\nvoid InitializeFFT(){\n ROOT = ModularExponentation(1ll * PROOT, (MOD - 1) / N);\n omega[0] = omega_inv[0] = 1;\n ROOT_INV = ModularExponentation(ROOT, MOD - 2);\n N_INV = ModularExponentation(N, MOD - 2);\n\n for(int i = 1; i < N; i++){\n omega[i] = (1ll * ROOT * omega[i - 1]) % MOD;\n omega_inv[i] = (1ll * ROOT_INV * omega_inv[i - 1]) % MOD;\n }\n\n for(int i = 0; i < N; i++){\n int j = 0, k = i;\n for(int x = 1; x < N; x <<= 1){\n j = (j << 1) | (k & 1);\n k >>= 1;\n }\n swapIndex[i] = j;\n }\n}\n\nvoid FFT(vector& a, int isInv = 0){\n for(int i = 0; i < N; i++){\n if(swapIndex[i] < i)\n swap(a[i], a[swapIndex[i]]);\n }\n\n for(int l = 2; l <= N;l <<= 1){\n for(int i = 0, F = N / l; i < N; i += l){\n for(int j = 0, f = 0; j < (l >> 1); j++, f += F){\n int x = i + j, y = x + (l >> 1);\n int t = (1ll * (isInv * omega_inv[f] + (1 - isInv) * omega[f]) * a[y]) % MOD, u = a[x];\n a[x] = (u + t) % MOD, a[y] = (MOD + u - t) % MOD;\n }\n }\n }\n}\n\nvoid FFTMatrix(vector a[B][B]){\n for(int i = 0; i < B; i++)\n for(int j = 0; j < B; j++)\n FFT(a[i][j], 0);\n}\n\nvoid MultiplyFFTMatrix(vector a[B][B], vector b[B][B], vector c[B][B]){\n for(int i = 0; i < B; i++){\n for(int j = 0; j < B; j++){\n for(int x = 0; x < N; x++)\n c[i][j][x] = 0;\n\n for(int k = 0; k < B; k++)\n for(int x = 0; x < N; x++)\n c[i][j][x] = (c[i][j][x] + (int)((1ll * a[i][k][x] * b[k][j][x]) % MOD)) % MOD;\n\n FFT(c[i][j], 1);\n\n for(int x = 0; x < K; x++)\n c[i][j][x] = (1ll * N_INV * c[i][j][x]) % MOD;\n\n for(int x = K; x < N; x++)\n c[i][j][x] = 0;\n }\n }\n}\n\nvoid CopyMatrix(vector s[B][B], vector t[B][B]){\n for(int i = 0; i < B; i++)\n for(int j = 0; j < B; j++){\n for(int x = 0; x < N; x++)\n t[i][j][x] = s[i][j][x];\n }\n}\n\nint main(){\n int n, m;\n\n cin >> n >> m;\n\n InitializeFFT();\n InitializeData();\n\n for(n--; n > 0; n /= 2){\n FFTMatrix(a);\n\n if(n % 2){\n FFTMatrix(b);\n MultiplyFFTMatrix(a, b, new_b);\n CopyMatrix(new_b, b);\n }\n\n MultiplyFFTMatrix(a, a, new_a);\n CopyMatrix(new_a, a);\n }\n\n for(int i = 1; i <= m; i++)\n printf(\"%d \", b[0][0][i]);\n printf(\"\\n\");\n\n return 0;\n}\n", "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1"} {"source_code": "#include \n\n#define x first\n#define y second\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef long double ld;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef pair ii;\ntypedef pair pll;\n\nint mod=1000000000+7;\n\nint addm(int& a,int b) {return (a+=b) bool smin(T& a,U b) {return a>b?(a=b,1):0;}\ntemplate bool smax(T& a,U b) {return a0?b:-b;\n}\n\nint iv[1001];\n\nint main() {\n\tios::sync_with_stdio(0);\n\tcin.tie(0);\n\n\tcin >> n >> d >> mod;\n\t//dp[0][d-1][0]=1;\n\tdp[0][0][0]=1;\n\t//for (int j=0;j<=d;j++) dp[0][j][0]=1;\n\tfor (int i=1;i<=1000;i++) iv[i]=inv(i,mod);\n\tfor (int i=1;i<1002;i++) for (int j=0;j<=d;j++)\n\t\tcs[0][j][i]=addm2(cs[0][j][i-1],dp[0][j][i-1]);\n\tfor (int i=1;i\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nlong long getfirst(long long a) {\n while(a > 9) a /= 10;\n return a;\n}\n\nlong long getlast(long long a) {\n return a % 10;\n}\n\nint main() {\n long long l, r;\n cin >> l >> r;\n long long count = 0;\n for(long long i = l; i <= r; i++) {\n if(i < 10) {\n count++;\n continue;\n }\n if(i < 100) {\n if(getfirst(i) == getlast(i)) {\n count++;\n continue;\n }\n }\n if(getfirst(i) != getlast(i)) continue;\n long long zzz = 1000000000000000000;\n while(zzz + i > r || zzz > i || getfirst(i) != getfirst(i + zzz)) zzz /= 10;\n if(zzz >= 10) {\n count += zzz / 10;\n i += zzz - 1;\n continue;\n }\n if(getfirst(i) == getlast(i)) count++;\n }\n cout << count << endl;\n return 0;\n}", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd"} {"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 pb push_back\n#define inf 1001001001\n#define infll 1001001001001001001LL\n#define FOR0(i,n) for(int (i)=0;(i)<(n);++(i))\n#define FOR1(i,n) for(int (i)=1;(i)<=(n);++(i))\n#define mp make_pair\n#define pii pair\n#define ll long long\n#define ld double\n#define vi vector\n#define SZ(x) ((int)((x).size()))\n#define fi first\n#define se second\n#define RI(n) int (n); scanf(\"%d\",&(n));\n#define RI2(n,m) int (n),(m); scanf(\"%d %d\",&(n),&(m));\n#define RI3(n,m,k) int (n),(m),(k); scanf(\"%d %d %d\",&(n),&(m),&(k));\ntemplate ostream& operator<<(ostream &s,pair t) {return s<<\"(\"< ostream& operator<<(ostream &s,vector t){FOR0(i,sz(t))s<=(b);--i)\n#define gmax(a,b) (a)=max((a),(b))\n#define gmin(a,b) (a)=min((a),(b))\n#define ios0 ios_base::sync_with_stdio(0)\nint r,n;\nll MOD=1000003;\nll qp(ll a,ll b)\n{\n\tll x=1;\n\twhile(b)\n\t{\n\t\tif(b&1) x=x*a%MOD;\n\t\ta=a*a%MOD; b>>=1;\n\t}\n\treturn x;\n}\nint main()\n{\n\tcin>>r>>n;\n\tll ans=0,cur=1;\n\tfor(int a=n,b=1;b<=r;a++,b++)\n\t{\n\t\tcur=cur*a%MOD*qp(b,MOD-2)%MOD;\n\t\tans=(ans+cur)%MOD;\n\t}\n\tcout<\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\ntypedef vectorvi;\ntypedef vector >vpi;\n#define mod 1000000007\n#define mod1 500000003\nsigned main()\n{\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int n,d;\n cin>>n>>d;\n int a[n];\n for(int i=0;i>a[i];\n int sum=0;\n for(int i=0;id)\n {\n cout<<-1;\n return 0;\n }\n cout<<(d-sum)/5;\n}\n", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "#include \n#include\nusing namespace std;\n\nint check(int a){\n int b;\n if(a==0)b=1;\n else if(a==1)b=6;\n else if(a==2)b=1;\n else if(a==3)b=2;\n else if(a==4)b=2;\n else if(a==5)b=3;\n else if(a==6)b=1;\n else if(a==7)b=4;\n else if(a==8)b=0;\n else if(a==9)b=1;\n return b;\n}\n\nint main()\n{\n int a,b,p,q,ar[2];\n cin>>a;\n for(b=0;b<2;b++){\n ar[b]=a%10;\n a=a/10;\n }\n p=check(ar[0])+1;\n q=check(ar[1])+1;\n\n cout<\nusing namespace std;\nbool sat(string& s)\n{\n\tif(s[0] != '1')\n\treturn false;\n\telse if(s.find(\"444\") != s.npos)\n\treturn false;\n\telse\n\t{\n\t\tfor(int i=1;i>s;\n\tif(sat(s))\n\tcout<<\"YES\\n\";\n\telse\n\tcout<<\"NO\\n\";\n}", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "#include\nusing namespace std;\n#define endl \"\\n\"\n#define mp make_pair\n#define ss second\n#define ff first\n#define ll long long\n#define pb push_back\nconst int MOD = 1e9 + 7;\n#define mod %MOD\n\n\nconst int N = 1000 + 11;\nint main()\n{\n ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n string s;\n cin>>s;\n int b0=s[0]-'0';\n int b1=s[1]-'0';\n int b2=s[2]-'0';\n int b3=s[3]-'0';\n int b4=s[4]-'0';\n int b5=s[5]-'0';\n int ans=6;\n for (int a0=0; a0<=9; a0++)\n for (int a1=0; a1<=9; a1++)\n for (int a2=0; a2<=9; a2++)\n for (int a3=0; a3<=9; a3++)\n for (int a4=0; a4<=9; a4++)\n for (int a5=0; a5<=9; a5++)\n if (a0+a1+a2==a3+a4+a5)\n {\n ans=min(ans,(b0!=a0)+(b1!=a1)+(b2!=a2)+(b3!=a3)+(b4!=a4)+(b5!=a5));\n }\n cout<\n#define L long long int\n\nusing namespace std;\n\nint main()\n{\n \n int x,y,z;\n cin>>x>>y;\n if(x==0 && y==0)\n z=0;\n else if(x==y && x>0)\n z=4*(x-1)+1;\n else if(x>0 && -y==x)\n z=4*(x-1)+4;\n else if(x<0 && x==y)\n z=4*(-x-1)+3;\n else if(x<0 && -x==y)\n z=4*(y-1)+2;\n else if((x>y && x>0 && y>=0) || (x>-y && x>0 &&y<=0))\n {\n z=4*(x-1);\n if(y<=(x-1) && y>(1-x))\n z=z+1;\n }\n else if((y>x && y>0 && x>=0) || (y>-x && y>0 && x<=0))\n {\n z=4*(y-1)+2;\n }\n else if((y<0 && -y>x && x>=0) || (y<0 && x<=0 && yy && y>=0) || (x<0 && x\n#include \n#include \n#include \n#define MAXN 256\n#define MAXT 64\n#define MAXE MAXN * MAXN\n#define INF 1000000000\nusing namespace std;\nclass Dinic {\n\tstruct edge {\n\t\tint u, v, f, c, nx;\n\t\tedge() {}\n\t\tedge(int u, int v, int f, int c, int nx): u(u), v(v), f(f), c(c), nx(nx) {}\n\t} e[MAXE];\n\tint n, m, src, dst, head[MAXN], work[MAXN], d[MAXN];\n\tbool _bfs() {\n\t\tstatic int q[MAXN], le, ri;\n\t\tle = ri = 0;\n\t\tmemset(d, -1, sizeof(int) * n);\n\t\tq[ri++] = src;\n\t\td[src] = 0;\n\t\twhile(le < ri) {\n\t\t\tfor(int k = q[le++], i = head[k]; i != -1; i = e[i].nx) {\n\t\t\t\tif(e[i].f < e[i].c && d[e[i].v] == -1) {\n\t\t\t\t\td[e[i].v] = d[k] + 1;\n\t\t\t\t\tq[ri++] = e[i].v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (d[dst] != -1);\n\t}\n\tint _dfs(int u, int f) {\n\t\tif(u == dst)\n\t\t\treturn f;\n\t\tint minf;\n\t\tfor(int& i = work[u]; i != -1; i = e[i].nx) {\n\t\t\tif(e[i].f < e[i].c && d[e[i].v] == d[u] + 1) {\n\t\t\t\tminf = _dfs(e[i].v, min(f, e[i].c - e[i].f));\n\t\t\t\tif(minf > 0) {\n\t\t\t\t\te[i].f += minf;\n\t\t\t\t\te[i ^ 1].f -= minf;\n\t\t\t\t\treturn minf;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\npublic:\n\tvoid init(int n, int src, int dst) {\n\t\tthis->n = n;\n\t\tthis->src = src;\n\t\tthis->dst = dst;\n\t\tm = 0;\n\t\tmemset(head, -1, sizeof(int) * n);\n\t}\n\tvoid addEdge(int u, int v, int c) {\n\t\t//printf(\"%d %d %d\\n\", u, v, c);\n\t\te[m] = edge(u, v, 0, c, head[u]);\n\t\thead[u] = m++;\n\t\te[m] = edge(v, u, 0, 0, head[v]);\n\t\thead[v] = m++;\n\t}\n\tint maxFlow() {\n\t\tint ret = 0, delta;\n\t\twhile(_bfs()) {\n\t\t\tmemcpy(work, head, sizeof(int) * n);\n\t\t\twhile(true) {\n\t\t\t\tdelta = _dfs(src, INF);\n\t\t\t\tif(delta == 0)\n\t\t\t\t\tbreak;\n\t\t\t\tret += delta;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n} dinic;\n#define MAX 12\nint n, t, zx, zy;\nchar smp[MAX][MAX], cmp[MAX][MAX], work[MAX][MAX];\nint vis[MAXT][MAX][MAX];\nint dx[4] = {1, 0, -1, 0};\nint dy[4] = {0, -1, 0, 1};\ninline int X(int i, int j) { return i * n + j; }\ninline int Y(int i, int j) { return n * n + i * n + j; }\ninline int S() { return n * n * 2; }\ninline int T() { return S() + 1; }\ninline int N() { return T() + 1; }\nstruct qNode {\n\tint x, y, t, type;\n\tqNode() {}\n\tqNode(int x, int y, int t, int type): x(x), y(y), t(t), type(type) {}\n};\nvoid bfs(int sx, int sy) {\n\tqueue q;\n\tq.push(qNode(sx, sy, 0, 0));\n\tvis[0][sx][sy] = 1;\n\tq.push(qNode(zx, zy, 0, 1));\n\twhile(!q.empty()) {\n\t\tqNode u = q.front();\n\t\tint nx, ny;\n\t\tq.pop();\n\t\tif(u.t == t)\n\t\t\tbreak;\n\t\tif(u.type == 0 && isalpha(work[u.x][u.y]))\n\t\t\tcontinue;\n\t\t/*if(u.type == 0 && !vis[u.t + 1][u.x][u.y] && !isalpha(work[u.x][u.y])) {\n\t\t\tvis[u.t + 1][u.x][u.y] = 1;\n\t\t\tq.push(qNode(u.x, u.y, u.t + 1, 0));\n\t\t}*/\n\t\tfor(int i = 0; i < 4; ++i) {\n\t\t\tnx = u.x + dx[i];\n\t\t\tny = u.y + dy[i];\n\t\t\tif(nx >= 0 && nx < n && ny >= 0 && ny < n) {\n\t\t\t\tif(u.type == 0 && !vis[u.t + 1][nx][ny] && !isalpha(work[nx][ny])) {\n\t\t\t\t\tvis[u.t + 1][nx][ny] = 1;\n\t\t\t\t\tq.push(qNode(nx, ny, u.t + 1, 0));\n\t\t\t\t}\n\t\t\t\telse if(u.type == 1 && !isalpha(work[nx][ny])) {\n\t\t\t\t\twork[nx][ny] = 'Z';\n\t\t\t\t\tq.push(qNode(nx, ny, u.t + 1, 1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\nint main() {\n\twhile(scanf(\"%d%d\", &n, &t) != EOF) {\n\t\tdinic.init(N(), S(), T());\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tscanf(\"%s\", smp[i]);\n\t\t\tfor(int j = 0; j < n; ++j)\n\t\t\t\tif(isdigit(smp[i][j]) && smp[i][j] > '0')\n\t\t\t\t\tdinic.addEdge(S(), X(i, j), smp[i][j] - '0');\n\t\t\t\telse if(smp[i][j] == 'Z') {\n\t\t\t\t\tzx = i;\n\t\t\t\t\tzy = j;\n\t\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tscanf(\"%s\", cmp[i]);\n\t\t\tfor(int j = 0; j < n; ++j)\n\t\t\t\tif(isdigit(cmp[i][j]) && cmp[i][j] > '0')\n\t\t\t\t\tdinic.addEdge(Y(i, j), T(), cmp[i][j] - '0');\n\t\t}\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tfor(int j = 0; j < n; ++j) {\n\t\t\t\tif(!isdigit(smp[i][j]) || smp[i][j] <= '0')\n\t\t\t\t\tcontinue;\n\t\t\t\tmemset(vis, 0, sizeof(vis));\n\t\t\t\tmemcpy(work, smp, sizeof(smp));\n\t\t\t\tbfs(i, j);\n\t\t\t\tfor(int xi = 0; xi < n; ++xi)\n\t\t\t\t\tfor(int yi = 0; yi < n; ++yi) {\n\t\t\t\t\t\tif(!isdigit(cmp[xi][yi]) || cmp[xi][yi] <= '0')\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tfor(int ti = 0; ti <= t; ++ti)\n\t\t\t\t\t\t\tif(vis[ti][xi][yi]) {\n\t\t\t\t\t\t\t\tdinic.addEdge(X(i, j), Y(xi, yi), INF);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\tprintf(\"%d\\n\", dinic.maxFlow());\n\t}\n\treturn 0;\n}\n", "src_uid": "544de9c3729a35eb08c143b1cb9ee085"} {"source_code": "#include\n \nusing namespace std;\n \n#define allof(x) (x).begin(), (x).end()\n \ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\n \n \n \nint main(){\n cin.tie(0);\n cin.sync_with_stdio(0);\n \n int x, y;\n cin >> x >> y;\n int r = sqrt(x*x + y*y);\n \n if (x * y >= 0) {\n if (r % 2 == 0) {\n cout << \"black\";\n return 0;\n }\n }\n \n if (x * y <= 0) {\n if (r % 2 == 1) {\n cout << \"black\";\n return 0;\n }\n }\n \n if (r * r == x * x + y * y) {\n cout << \"black\";\n return 0;\n }\n \n cout << \"white\";\n}\n", "src_uid": "8c92aac1bef5822848a136a1328346c6"} {"source_code": "#include \nusing namespace std;\n\n\nint mask(int x) {\n int ans = 0, t = 1;\n while(x>0) {\n int d = x%10;\n if(d==4 or d==7) {\n ans = d*t + ans;\n t*=10;\n }\n \n x /= 10;\n }\n \n return ans;\n}\nint main() {\n\tint a, b;\n\tcin>>a>>b;\n\tif(a-< |\n =========\nIt's AdilkhanKo miaaaaaau\n*/\n#include\n\n#define ll long long\n#define pb push_back\n#define endl \"\\n\"\n#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)\n#define mp make_pair\n#define f first\n#define s second\n#define name \"\"\n#define _ ios_base::sync_with_stdio(false);cin.tie(0);\n\nusing namespace std;\n\nconst int MaxN = int (2e6) + 256;\nconst ll INF = (ll)(1e18);\nconst int inf = (int)(1e9);\nconst int mod = (int)(1e9) + 7;\nconst double pi = 3.1415926535897932384626433832795;\nll n, m, ans, a[MaxN], b[MaxN], k;\n\nint main () { \n\t#ifdef ONLINE_JUDGE\n//\t\tfreopen (name\".in\",\"r\",stdin);\n//\t\tfreopen (name\".out\",\"w\",stdout);\n\t#else\n\t\tfreopen (\".in\",\"r\",stdin);\n\t\tfreopen (\".out\",\"w\",stdout);\n\t#endif\n\tcin >> n >> k;\n\tint q = 0;\n\tll N = n, cnt = 0;\n\twhile(N % 10 == 0){\n\t \tN /= 10;\n\t \tq++;\n\t}\n\tif(q >= k)cout << n;\n\telse{\n\t\tk -= q;\n\t\tll cnt1 = 0;\n\t\twhile(N % 5 == 0){\n\t\t\tcnt++;\n\t\t\tN /= 5;\n\t\t}\n\t\twhile(N % 2 == 0){\n\t\t\tcnt1++;\n\t\t\tN /= 2;\n\t\t}\n\t\tif(cnt > 0){\n\t\t\tfor(int i = 1; i <= min(k, cnt); i++){\n\t\t\t\tn *= 2ll;\n\t\t\t}\n\t\t\t\tfor(int i = cnt + 1; i <= k; i++) n *= 10ll;\n\t\t}else{\n\t\t\tfor(int i = 1; i <= min(k, cnt1); i++){\n\t\t\t\tn *= 5ll;\n\t\t\t}\n\t\t\t\tfor(int i = cnt1 + 1; i <= k; i++) n *= 10ll;\n\t\t}\n\t\tcout << n;\n\t}\nreturn 0;\n} \n", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"source_code": "#include \n#include \n\nusing namespace std;\n\nint n,memo[10][(1 << 10)][9];\nbool adj[10][10];\n\nint solve(int pos, int mask, int k){\n if(mask == 0) return k == 0;\n if(k == 0) return 0;\n \n int x = __builtin_ctz(mask);\n \n if(__builtin_popcount(mask) == 1)\n return k == 1 && adj[pos][x];\n \n int &ret = memo[pos][mask][k];\n \n if(ret == -1){\n ret = 0;\n \n for(int mask2 = mask;mask2 > 0;mask2 = (mask2 - 1) & mask){\n if(mask2 & (1 << x)){\n for(int i = 0;i < n;++i){\n if((mask2 & (1 << i)) && adj[pos][i]){\n if(mask2 == (1 << i)) ret += solve(pos,mask ^ mask2,k - 1);\n else\n for(int j = 1;j <= k;++j)\n ret += solve(i,mask2 ^ (1 << i),j) * solve(pos,mask ^ mask2,k - j);\n }\n }\n }\n }\n }\n \n return ret;\n}\n\nint main(){\n int m,K;\n \n scanf(\"%d %d %d\",&n,&m,&K);\n \n memset(adj,false,sizeof adj);\n \n for(int i = 0,u,v;i < m;++i){\n scanf(\"%d %d\",&u,&v);\n --u; --v;\n adj[u][v] = adj[v][u] = true;\n }\n \n memset(memo,-1,sizeof memo);\n \n int ans = 0;\n \n for(int r = 0;r < n;++r){\n int mask = ((1 << n) - 1) ^ (1 << r);\n \n for(int i = 0;i < n;++i)\n if(i != r && (mask & (1 << i)) && adj[r][i])\n ans += solve(i,mask ^ (1 << i),K - 1);\n }\n \n ans /= K;\n \n printf(\"%d\\n\",ans);\n \n return 0;\n}\n", "src_uid": "8087605a8f316150372cc4627f26231d"} {"source_code": "#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,l,r) for(int i=(l);i<=(r);++i)\n#define per(i,r,l) for(int i=(r);i>=(l);--i)\nusing namespace std;\nconst int N=410,P=1e9+7;\nint dp[N][N],n,a[N];\ninline void upd(int &x,int y){((x+=y)>=P)&&(x-=P);}\nint main(){\n\tscanf(\"%d\",&n);dp[1][1]=dp[1][0]=1;\n\trep(i,2,n){\n\t\tdp[i][0]=1;\n\t\trep(j,0,n) a[j]=0;\n\t\trep(j,0,n) rep(k,0,n-j) upd(a[j+k],1ll*dp[i-1][j]*dp[i-1][k]%P);\n\t\trep(j,1,n) dp[i][j]=(1ll*j*(j+1)*a[j+1]+(2ll*j+1)*a[j]+a[j-1])%P;\n\t}\n\tprintf(\"%d\\n\",dp[n][1]);\n\treturn 0;\n}", "src_uid": "fda761834f7b5800f540178ac1c79fca"} {"source_code": "#include \n\n#define debug(x) cout << #x << \" = \" << x << endl\n#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)\n#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair ii;\ntypedef tuple op;\n\nconst int MOD = 1e9 + 7;\nconst int MAX = 5e2 + 5;\nint mat[MAX][MAX], hydra[5][5], b[MAX];\nbool rzero[MAX];\nchar str[MAX];\nint n, m;\n\nint eval(char c) {\n\treturn c - 'a';\n}\n\nint main() {\n\tscanf(\"%d %d\", &n, &m);\n\n\tfori(i, 0, n) {\n\t\tscanf(\"%s\", str);\n\t\tfori(r, 0, m) {\n\t\t\tmat[r][i] = eval(str[r]);\n\t\t}\n\t}\n\n\tfori(i, 0, 5) {\n\t\tint k = i;\n\t\tfori(j, 0, 4) {\n\t\t\thydra[i][k] = j;\n\t\t\tk = (k + i) % 5;\n\t\t}\n\t}\n\n\tswap(n, m);\n\n\tvector ops;\n\tint row = 0;\n\tfor(int col = 0; row < n && col < m; col++) {\n\t\tint pivot = -1;\n\t\tfori(i, row, n) {\n\t\t\tif(mat[i][col] > 0) {\n\t\t\t\tpivot = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(pivot == -1) {\n\t\t\tcontinue;\n\t\t}\n\t\tswap(mat[row], mat[pivot]);\n\t\tops.emplace_back(0, row, pivot);\n\t\tfori(i, row + 1, n) {\n\t\t\tif(mat[i][col] > 0) {\n\t\t\t\tint to_apply = (hydra[mat[i][col]][mat[row][col]] + 1);\n\t\t\t\tops.emplace_back(1, i, to_apply);\n\t\t\t\tfori(j, 0, m) {\n\t\t\t\t\tmat[i][j] *= to_apply;\n\t\t\t\t\tmat[i][j] = (mat[i][j] - mat[row][j]) % 5;\n\t\t\t\t\tif(0 > mat[i][j]) {\n\t\t\t\t\t\tmat[i][j] += 5;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\trow++;\n\t}\n\n\tint r = 0;\n\tfori(i, 0, n) {\n\t\trzero[i] = true;\n\t\tfori(j, 0, m) {\n\t\t\tif(mat[i][j] > 0) {\n\t\t\t\tr++;\n\t\t\t\trzero[i] = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tint pot = 1;\n\tfori(i, 0, m - r) {\n\t\tpot = (1LL * pot * 5) % MOD;\n\t}\n\n\tint q;\n\tscanf(\"%d\", &q);\n\twhile(q--) {\n\t\tscanf(\"%s\", str);\n\t\tint ans = pot;\n\t\tfori(i, 0, n) {\n\t\t\tb[i] = eval(str[i]);\n\t\t}\n\n\t\tint last_row = -1;\n\t\tfor(auto &each : ops) {\n\t\t\tint type, x, y;\n\t\t\ttie(type, x, y) = each;\n\t\t\tif(type == 0) {\n\t\t\t\tswap(b[x], b[y]);\n\t\t\t\tlast_row = x;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tb[x] *= y;\n\t\t\t\tb[x] = (b[x] - b[last_row]) % 5;\n\t\t\t\tif(0 > b[x]) {\n\t\t\t\t\tb[x] += 5;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfori(i, 0, n) {\n\t\t\tif(rzero[i] && b[i] > 0) {\n\t\t\t\tans = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tprintf(\"%d\\n\", ans);\n\t}\n\n\treturn 0;\n}\n\n", "src_uid": "5cb18864c88b7fdec4a85718df67333e"} {"source_code": "#include \n#include\n#include\nusing namespace std;\nint main(){\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\tint n;\n\tcin>>n;\n\tint a[n];\n\tfor(int i=0;i>a[i];\n\t}\n\tint j,s; \n\tfor(int i=0;i<(1<\r\nusing namespace std;\r\nconst int mod = 998244353;\r\nconst int N = 403;\r\nint dp[2][203][203][3][3], sum[N][N], s1[26], n, ans;\r\nint main() {\r\n\tint T1, T2;\r\n\tscanf(\"%d\", &n);\r\n\tfor (int i = 0; i < 26; i++) {\r\n\t\tscanf(\"%d\", &s1[i]);\r\n\t}\r\n\tfor (int i = 0; i < 3; i++) {\r\n\t\tif (i == 0) {\r\n\t\t\tT1 = 24;\r\n\t\t} else {\r\n\t\t\tT1 = 1;\r\n\t\t}\r\n\t\tfor (int j = 0; j < 3; j++) {\r\n\t\t\tif (j == 0) {\r\n\t\t\t\tT2 = 24;\r\n\t\t\t} else {\r\n\t\t\t\tT2 = 1;\r\n\t\t\t}\r\n\t\t\tdp[0][(i == 1) + (j == 1)][(i == 2) + (j == 2)][i][j] = T1 * T2;\r\n\t\t}\r\n\t}\r\n\tT1 = 0;\r\n\tfor (int i = 3; i <= n; i++) {\r\n\t\tT1 = 1 - T1;\r\n\t\tmemset(dp[T1], 0, sizeof(dp[T1]));\r\n\t\tfor (int a = 0; a <= n / 2 + 1; a++) {\r\n\t\t\tfor (int b = 0; b <= n / 2 + 2; b++) {\r\n\t\t\t\tfor (int c = 0; c < 3; c++) {\r\n\t\t\t\t\tfor (int d = 0; d < 3; d++) {\r\n\t\t\t\t\t\tfor (int e = 0; e < 3; e++) {\r\n\t\t\t\t\t\t\tif (c == e && c > 0) {\r\n\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (c == e) {\r\n\t\t\t\t\t\t\t\tdp[T1][a][b][d][e] = (dp[T1][a][b][d][e] + 1ll * dp[1 - T1][a][b][c][d] * 23 % mod) % mod;\r\n\t\t\t\t\t\t\t} else if (e == 0) {\r\n\t\t\t\t\t\t\t\tdp[T1][a][b][d][e] = (dp[T1][a][b][d][e] + 1ll * dp[1 - T1][a][b][c][d] * 24 % mod) % mod;\r\n\t\t\t\t\t\t\t} else if (e == 1) {\r\n\t\t\t\t\t\t\t\tdp[T1][a + 1][b][d][e] = (dp[T1][a + 1][b][d][e] + dp[1 - T1][a][b][c][d]) % mod;\r\n\t\t\t\t\t\t\t} else if (e == 2) {\r\n\t\t\t\t\t\t\t\tdp[T1][a][b + 1][d][e] = (dp[T1][a][b + 1][d][e] + dp[1 - T1][a][b][c][d]) % mod;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\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\tsum[i][j] = (sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1]) % mod;\r\n\t\t\tfor (int a = 0; a < 3; a++) {\r\n\t\t\t\tfor (int b = 0; b < 3; b++) {\r\n\t\t\t\t\tsum[i][j] = (sum[i][j] + dp[T1][i][j][a][b]) % mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tans = sum[0][0];\r\n\tfor (int i = 0; i < 26; i++) {\r\n\t\tans = (ans - sum[s1[i] + 1][0] + mod) % mod;\r\n\t}\r\n\tfor (int i = 0; i < 25; i++) {\r\n\t\tfor (int j = i + 1; j < 26; j++) {\r\n\t\t\tans = (ans + sum[s1[i] + 1][s1[j] + 1]) % mod;\r\n\t\t}\r\n\t}\r\n\tprintf(\"%d\", ans);\r\n\treturn 0;\r\n}", "src_uid": "1f012349f4b229dc98faadf1ca732355"} {"source_code": "#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint n,answer,s[1111111];\nint main(){\n\tscanf(\"%d\",&n);\n\tfor(int i=1;i<=n;i++){\n\t\tscanf(\"%d\",&s[i]);\n\t\tanswer+=s[i]*(i-1)*4;\n\t}\n\tprintf(\"%d\",answer);\n}\n", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"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 \nusing namespace std;\n\n#define loop(i,n) for(int i = 0; i < (n); i++)\n#define loope(i,n) for(int i = 0; i <= (n); i++)\n#define rep(i,n,m) for(int i = (n); i < (m); i++)\n#define repe(i,n,m) for(int i = (n); i <= (m); i++)\n\n#define ULL unsigned long long int\n#define LL long long int\n#define point pair\n\n#define getBit(n,i) (n) & (1<<(i))\n#define setBit(n,i) (n) = (n) | (1<<(i))\n\n#define fopen freopen(\"input.txt\",\"r\",stdin)\n#define fclose cout << \"EOF\"; while(1)\n\n\nint main()\n{\n signed long long int n, x, y, c;\n cin >> n >> y >> x >> c;\n\n signed long long int lit = 0, nextStep = 1, second = -1;\n signed long long int computed;\n\n vector seq;\n seq.push_back(0);\n\n do \n {\n second++;\n seq.push_back(seq[second] + second + 1);\n lit += nextStep;\n nextStep += (nextStep == 1) ? 3 : 4;\n\n computed = lit;\n\n if(x + second > n) computed -= (x + second - n) * (x + second - n);\n if(second >= x) computed -= (second - x + 1) * (second - x + 1);\n if(y + second > n) computed -= (y + second - n) * (y + second - n);\n if(second >= y) computed -= (second - y + 1) * (second - y + 1);\n\n if(second - y > n - x) computed += seq[second - y - n + x];\n if((second - x + 1) > y) computed += seq[second - x + 1 - y];\n if((second - n + y) > x) computed += seq[second - n + y - x];\n if((second - n + y) > (n + 1 - x)) computed += seq[second - n + y - n - 1 + x];\n\n } while (computed < c);\n\n cout << second << endl;\n return 0;\n}", "src_uid": "232c5206ee7c1903556c3625e0b0efc6"} {"source_code": "#include\n#include\nusing namespace std;\nint main()\n{\n\tchar s[20];\n\tint i, j,l;\n\tcin >> s;\n\tl = strlen(s);\n\tj = l / 2;\n\tint flog = 0;\n\t\tfor (i = 0; i < j; i++)\n\t\t{\n\t\t\tif (s[i] != s[l - 1 - i])\n\t\t\t\tflog++;\n\t\t}\n\t\tif (flog > 1||(flog==0&&j*2==l))\n\t\t\tprintf(\"NO\\n\");\n\t\telse\n\t\t\tprintf(\"YES\\n\");\n\treturn 0;\n}", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"source_code": "/*input\n13 2\n4 6\n3 5\n3 4\n3 3\n4 2\n5 2\n6 2\n7 3\n7 4\n7 5\n6 6\n5 4\n5 5\n\n\n\n8 2\n3 5\n5 3\n3 3\n5 5\n2 4\n6 4\n4 2\n4 4\n \n8 2\n0 2\n1 2\n1 0\n0 0\n2 1\n2 0\n0 1\n2 2\n*/\n \n#include \n#include \n#include \n#include \n#include \n \nusing namespace std;\n \nusing pii = pair;\n#define r first\n#define c second\n \nconst int dr[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dc[8] = {0, 1, 1, 1, 0, -1, -1, -1};\nconst int MAXN = 150007, MAXV = MAXN * 9, INF = 1e9 + 7;\nconst int EXT = -1, ALIVE = 1, IN = 0;\nint G[MAXV][8], type[MAXV], T, N, V, P[MAXV], inComp[MAXV];\npii C[MAXV], orC[MAXN];\nbool peri[MAXV], inq[MAXV];\npriority_queue pq;\nvector ans;\nbool vis[MAXV];\n \nbool comp(int i, int j) { return C[i] < C[j]; }\n \nint search(pii p)\n{\n\tint lo = 1, hi = V;\n\twhile (lo < hi) {\n\t\tint mid = (lo + hi) >> 1;\n\t\tif (C[P[mid]] < p) lo = mid + 1;\n\t\telse hi = mid;\n\t}\n\tif (C[P[lo]] == p) return P[lo];\n\treturn 0;\n}\n \nint calc(int u)\n{\n\tint cnt = 0;\n\tvector vec;\n\tfor (int d = 0; d < 8; d += 2) {\n\t\tcnt += ((type[G[u][d]] == EXT) && (type[G[u][(d + 1) & 7]] != EXT || type[G[u][(d + 2) & 7]] != EXT));\n\t\tif (type[G[u][d]] == IN && (type[G[u][(d + 1) & 7]] == ALIVE || type[G[u][(d + 2) & 7]] == ALIVE)) {\n\t\t\tvec.push_back(inComp[G[u][d]]);\n\t\t}\n\t}\n\n\tsort(vec.begin(), vec.end());\n\tfor (int i = 1; i < (int) vec.size(); ++i) {\n\t\tif (vec[i - 1] == vec[i]) return INF;\n\t}\n\n\treturn cnt;\n}\n \nvoid dfs(int u)\n{\n\tvis[u] = 1;\n\tfor (int d = 0; d < 8; ++d) {\n\t\tint v = G[u][d];\n\t\tif (!vis[v] && type[v] == ALIVE) dfs(v);\n\t}\n}\n \nvoid fillExt(int u)\n{\n\ttype[u] = EXT;\n \n\tfor (int d = 0; d < 8; d += 2) {\n\t\tif (type[G[u][d]] == ALIVE) {\n\t\t\tperi[G[u][d]] = 1;\n\t\t\tif (!inq[G[u][d]] && calc(G[u][d]) <= 1) {\n\t\t\t\tinq[G[u][d]] = 1;\n\t\t\t\tpq.push(G[u][d]);\t\n\t\t\t}\n\t\t} else if (type[G[u][d]] == IN) {\n\t\t\tfillExt(G[u][d]);\n\t\t}\n\t}\n \n\tfor (int d = 0; d < 8; ++d) {\n\t\tif (type[G[u][d]] == ALIVE && peri[G[u][d]] && !inq[G[u][d]] && calc(G[u][d]) <= 1) {\n\t\t\tinq[G[u][d]] = 1;\n\t\t\tpq.push(G[u][d]);\n\t\t}\n\t}\n}\n\nvoid fillIn(int u)\n{\n\tfor (int d = 0; d < 8; d += 2) {\n\t\tif (type[G[u][d]] == IN && inComp[G[u][d]] == 0) {\n\t\t\tinComp[G[u][d]] = inComp[u];\n\t\t\tfillIn(G[u][d]);\n\t\t}\n\t}\n}\n \nint main()\n{\n\tios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n\tcin >> N >> T; V = N;\n\tfor (int i = 1; i <= N; ++i) cin >> C[i].r >> C[i].c;\n\tfor (int i = 0; i < N; ++i) orC[i] = C[i + 1];\n\tsort(orC, orC + N); orC[N] = {INF, INF};\n \n\tvector> all(N * 8);\n\tfor (int i = 1; i <= N; ++i) {\n\t\tfor (int d = 0; d < 8; ++d) {\n\t\t\tall[(i - 1) * 8 + d] = {C[i].r + dr[d], C[i].c + dc[d]};\n\t\t}\n\t}\n\tsort(all.begin(), all.end());\n\tall.erase(unique(all.begin(), all.end()), all.end());\n\tfor (auto a : all) {\n\t\tif (*lower_bound(orC, orC + N, a) != a) {\n\t\t\tC[++V] = a;\n\t\t}\n\t}\n \n\tfor (int u = 1; u <= V; ++u) P[u] = u;\n\t// for (int u = 1; u <= V; ++u) cout << C[u].r << ' ' << C[u].c << endl;\n\tsort(P + 1, P + V + 1, comp);\n \n\tfor (int u = 1; u <= V; ++u) {\n\t\tfor (int d = 0; d < 8; ++d) {\n\t\t\tG[u][d] = search({C[u].r + dr[d], C[u].c + dc[d]});\n\t\t}\n\t}\n \n\ttype[0] = EXT;\n\tfor (int u = 1; u <= N; ++u) type[u] = ALIVE;\n\tfor (int u = N + 1; u <= V; ++u) type[u] = IN;\n\tfor (int u = N + 1; u <= V; ++u) {\n\t\tif (inComp[u] == 0) {\n\t\t\tinComp[u] = u;\n\t\t\tfillIn(u);\n\t\t}\n\t}\n \n\tdfs(1);\n\tfor (int u = 1; u <= N; ++u) if (!vis[u]) return cout << \"NO\" << endl, 0;\n \n\tfillExt(N + 1);\n\tans.reserve(N);\n\twhile (!pq.empty()) {\n\t\tint u = pq.top(); pq.pop();\n\t\tassert(type[u] == ALIVE && peri[u]);\n\t\tif (calc(u) > 1) {\n\t\t\tinq[u] = 0;\n\t\t\tcontinue;\n\t\t}\n\t\tans.push_back(u);\n\t\tfillExt(u);\n\t}\n \n\tassert((int) ans.size() == N);\n\tcout << \"YES\\n\";\n\tfor (int i = (int) ans.size() - 1; i >= 0; --i) {\n\t\tcout << ans[i] << '\\n';\n\t}\n}", "src_uid": "873aca0e5ff5dccf8af62f7b244fef6b"} {"source_code": "#include \ntypedef long long ll;\nconst ll MOD = 998244353;\nconst int N = 2e5+10;\nll fac[N];\nll qpow(ll a, ll b)\n{\n\tll res = 1;\n\twhile(b)\n\t{\n\t\tif(b % 2) res = res * a % MOD;\n\t\ta = a * a % MOD;\n\t\tb /= 2;\n\t} \n\treturn res;\n}\nll C(ll n, ll m)\n{\n\treturn (fac[n] * qpow(fac[n-m], MOD-2) % MOD) * qpow(fac[m], MOD-2) % MOD;\n}\nint main()\n{\n\tfac[0] = 1;\n\tfor(int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD; \n\tll n, k;\n\tscanf(\"%lld %lld\", &n, &k);\n\tif(k==0)\n\t{\n\t\tprintf(\"%lld\\n\", fac[n]);\n\t}else if(k >= n)\n\t{\n\t\tprintf(\"0\\n\");\n\t}else\n\t{\n\t\tll ans = 0;\n\t\tfor(int i = 0; i < n - k; i++)\n\t\t{\n\t\t\tif(i % 2)\n\t\t\t{\n\t\t\t\tans = (ans + MOD - qpow(n-k-i, n) * C(n-k, i) % MOD) % MOD;\n\t\t\t}else{\n\t\t\t\tans = (ans + qpow(n-k-i, n) * C(n-k, i) % MOD) % MOD;\n\t\t\t}\n\t\t}\n\t\tans = (ans * 2 % MOD) * C(n, n-k) % MOD;\n\t\tprintf(\"%lld\\n\", ans);\n\t}\n} ", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"} {"source_code": "//#pragma comment(linker,\"/STACK:256000000\")\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\nusing namespace std;\n\n#define ldb long double\n#define LL long long\n#define nextline() {int c; while ((c = getchar()) != 10 && c != EOF);}\n\n#define PI 3.1415926535897932384626433832795\n#define EPS 1e-9\n\n#define sqr(x) ((x) * (x))\n#define ABS(a) ((a)<0?-(a):(a))\n#define EQ(a,b) (ABS((a)-(b))= 0; mask--) \n \t{\n \tint n = __builtin_popcount(mask);\n\n \tdp[mask] = 0;\n\n \t\tfor (int j = 0; j < N; j++) \n \t\t{\n \t\tif (has(mask, j)) \n \t\t\tcontinue;\n \t\tif ((mask & b[j]) != b[j]) \n \t\t\tcontinue;\n \t\tif (j <= m && used[j] != n) \n \t\t\tcontinue;\n\n \t\tdp[mask] += dp[mask ^ two(j)];\n \t}\n \t}\n\n \treturn dp[0];\n}\n\nvoid Solve ()\n{\n \tif (DP(-1) < Y) \n \t{\n \tprintf (\"The times have changed\");\n \treturn;\n \t}\n\n \tfor (int i = 0; i < N; i++) \n \tfor (int j = 0; j < N; j++) \n \t\tif (!was[j])\n\t \t{\n \t\t \tused[i] = j;\n \t\t\tLL x = DP(i);\n \t\t\tif (Y > x) \n \t\t\t\tY -= x;\n \t\t\telse \n \t\t\t{ \n \t\t\t\twas[j] = 1; \n \t\t\t\tbreak; \n \t\t\t}\n \t\t}\n\n \tfor (int i = 0; i < N; i++)\n \tprintf(\"%d \", used[i] + 1);\n} \nint main()\n{\n //ios_base::sync_with_stdio(0);\n#ifndef ONLINE_JUDGE\n freopen(\"in\", \"rt\", stdin);\n freopen(\"out\", \"wt\", stdout);\n#endif\n Load();\n Solve();\n return 0;\n}", "src_uid": "e9db8d048e9763cf38c584342dea9f53"} {"source_code": "#include \nusing namespace std;\n#define DBG(x) cout << #x << \" = \" << x << endl;\n/*\nCompile:\n -Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wcast-qual -Wcast-align -fwhole-program -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -lmcheck -fsanitize=address \n\nCheck for memory usage:\n valgrind --tool=massif\n */\n\nconst int LIM = 1e7;\n\nbool comp[LIM];\nvector primes;\n\nvoid init()\n{\n for(int i = 2; i < LIM; i++) {\n if(!comp[i])\n for(long long j = (i * 1ll) * i; j < LIM; j += i)\n comp[j] = true;\n }\n}\n\nbool is_prime(long long x)\n{\n if(x < LIM)\n return !comp[x];\n if(x % 2 == 0)\n return false;\n for(long long i = 3; i * i <= x; i += 2) {\n if(x % i == 0)\n return false;\n }\n return true;\n}\n\nmap< pair, long long> result;\n\nlong long solve(long long a, int st=0) \n{\n if(a == 1)\n return 1;\n if(result.count({a, st}))\n return result[{a, st}];\n\n// cout << a << endl;\n long long ans = is_prime(a - 1) * (a >= 1e6);\n for(int i = st; i < primes.size(); i++) {\n long long u = primes[i];\n if(u + 1 > a)\n break;\n long long val = 1;\n while(val + 1 <= a) {\n val *= u;\n if(a % (val + 1) == 0) {\n ans += solve(a / (val + 1), i + 1);\n }\n }\n }\n// cout << a << \" \" << st << \" \" << ans << endl;\n return result[{a, st}] = ans;\n}\n\nbool some(int x, long long a)\n{\n if(x == 1)\n return false;\n long long t = 1;\n for(int i = 1; i <= 66; i++) {\n t *= x;\n if(a % (t + 1) == 0)\n return true;\n if(t > a)\n break;\n }\n return false;\n}\n\nint main()\n{\n init();\n cin.sync_with_stdio(false);\n long long a;\n cin >> a;\n for(int i = 1; i <= 1e6; i++)\n if(!comp[i] and some(i, a))\n primes.push_back(i);\n cout << solve(a, 0);\n return 0;\n}\n", "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4"} {"source_code": "#include \n#include \n#include \nusing namespace std;\ntypedef long long ll;\nconst int c[]={1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600}\n;\nint a[10010];\nvector b;\nvoid dfs(ll x)\n{ \nif (x>=1000000000) \nreturn;\n a[++a[0]]=int(x);\n dfs(x*10+4);\n dfs(x*10+7);\n }\n bool check(int x)\n { \n while (x)\n { \n int p=x%10;\n x/=10;\n if (p!=4 && p!=7)\n return(false);\n }\n return(true);\n }\n int main()\n { \n int n,K; scanf(\"%d%d\",&n,&K); \n ll now=1;\n int t=-1;\n for (int i=1;i<=n;i++) { now*=i; \n if (now>=K) \n {\n t=i; break; \n } \n } if (t==-1) \n printf(\"-1\\n\");\n else \n { dfs(4); \n dfs(7); \n sort(a+1,a+a[0]+1); \n for (int i=1;i<=t;i++) \n b.push_back(n-i+1); \n reverse(b.begin(),b.end()); \n int ans=0;\n for (int i=1;i<=a[0];i++)\n ans+=a[i]<=n-t; \n int now=n-t;\n K--; \n for (int i=t;i;i--) \n { now++; \n int p=0; \n while (K>=c[i-1]) \n { \n p++; \n K-=c[i-1]; \n } \n ans+=check(now) && check(b[p]); \n b.erase(b.begin()+p); \n } \n printf(\"%d\\n\",ans); \n } \n return(0);}", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c"} {"source_code": "#include\nusing namespace std;\ntypedef long long LL;\nLL n,l,r,ans,maxd;\nLL dfs(LL dep,LL l,LL r,LL n)\n{\n\tif(dep==maxd)return n;\n\tLL ll=(!(l%4)||l%4==2||l%4==3)?l/2:l/2+1,rr=(!(r%4)||r%4==2||r%4==3)?r/2:r/2+1;\n\tn=dfs(dep+1,ll,rr,n);\n\tif(n%2)\n\t{\n\t\tif(l%4==1)\n\t\t{\n\t\t\t++ans;\n\t\t\tl+=3;\n\t\t}\n\t\telse if(l%4==2)\n\t\t{\n\t\t\t++ans;\n\t\t\tl+=2;\n\t\t}\n\t\telse if(l%4==3)++l;\n\t\tif(r%4==1)--r;\n\t\telse if(r%4==2)\n\t\t{\n\t\t\t++ans;\n\t\t\tr-=2;\n\t\t}\n\t\telse if(r%4==3)\n\t\t{\n\t\t\t++ans;\n\t\t\tr-=3;\n\t\t}\n\t\tans+=(r-l)/4;\n\t}\n\treturn n/2;\n}\nint main()\n{\n\tscanf(\"%I64d%I64d%I64d\",&n,&l,&r);\n\tif(!n||n==1)\n\t{\n\t\tprintf(\"%d\\n\",n);\n\t\treturn 0;\n\t}\n\tmaxd=ceil(log2(n));\n\tdfs(1,l,r,n);\n\tLL k;\n\tif(l%4==1)\n\t{\n\t\tans+=2;\n\t\tl+=3;\n\t}\n\telse if(l%4==2)\n\t{\n\t\t++ans;\n\t\tl+=2;\n\t}\n\telse if(l%4==3)\n\t{\n\t\t++ans;\n\t\t++l;\n\t}\n\tif(r%4==1)\n\t{\n\t\t++ans;\n\t\t--r;\n\t}\n\telse if(r%4==2)\n\t{\n\t\t++ans;\n\t\tr-=2;\n\t}\n\telse if(r%4==3)\n\t{\n\t\tans+=2;\n\t\tr-=3;\n\t}\n\tans+=(r-l)/2;\n\tprintf(\"%I64d\\n\",ans);\n\treturn 0;\n}\n", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n string s;\n int w=0,b=0;\n for(int i=0;i<8;i++)\n {\n cin>>s;\n\n for(int j=0;jb?\"White\\n\":b>w?\"Black\\n\":\"Draw\\n\");\n\n\n}\n", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"source_code": "#include \r\nusing namespace std;\r\ntypedef long long ll;\r\ntypedef pair pii;\r\ntypedef pair pll;\r\nint dx[4] = { 1, -1, 0, 0 };\r\nint dy[4] = { 0, 0, 1, -1 };\r\nll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }\r\nconst ll N = 4000002;\r\nll n, m;\r\nll dp[N], psum[N];\r\n\r\nvoid func(ll cur, ll v)\r\n{\r\n\tfor (ll div = 2; div * cur <= n; div++)\r\n\t{\r\n\t\tll l = div * cur;\r\n\t\tll r = div * cur + (div - 1);\r\n\t\tr = min(r, n + 1);\r\n\t\tpsum[l] += v; psum[l] %= m;\r\n\t\tpsum[r + 1] -= v;\r\n\t\twhile (psum[r + 1] < 0) psum[r + 1] += m;\r\n\t}\r\n}\r\nint main(void)\r\n{\r\n\tios::sync_with_stdio(0);\r\n\tcin.tie(0), cout.tie(0);\r\n\tcin >> n >> m;\r\n\tdp[1] = 1; func(1, dp[1]);\r\n\tfor (int i = 2; i <= n; i++)\r\n\t{\r\n\t\tpsum[i] += psum[i - 1];\r\n\t\tpsum[i] %= m;\r\n\t\twhile (psum[i] < 0) psum[i] += m;\r\n\t\tdp[i] = dp[i - 1] + psum[i];\r\n\t\tdp[i] %= m;\r\n\t\tfunc(i, dp[i]);\r\n\t\tdp[i] += dp[i - 1]; dp[i] %= m;\r\n\t}\r\n\tll ans = dp[n] - dp[n - 1];\r\n\twhile (ans < 0) ans += m;\r\n\tcout << ans;\r\n}", "src_uid": "77443424be253352aaf2b6c89bdd4671"} {"source_code": "//~ while (clock()<=69*CLOCKS_PER_SEC)\n//~ #pragma comment(linker, \"/stack:200000000\")\n//~ #pragma GCC optimize(\"O3\")\n//~ #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#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\nusing namespace std;\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<<\" = \"< a, b, A, B;\n\nVPII odp;\n\nvoid normuj(vector & a)\n{\n\tvector b;\n\tfor(int i = 0;i < SZ(a);i++)\t\n\t\tif(SZ(b) > 0 && b.back().stan == a[i].stan)\n\t\t\tb.back() = merge(b.back(), a[i]);\n\t\telse\n\t\t\tb.pb(a[i]);\n\ta = b;\n}\n\nVPII elo()\n{\n\todp.clear();\n\tint ile = 0;\n\tbool f = 0;\n\tile = SZ(a) + SZ(b);\n\tif((SZ(a) > 2 || SZ(b) > 2) && abs(SZ(a) - SZ(b)) > 2)\n\t{\n\t\tif(SZ(a) < SZ(b))\n\t\t\tf = 1,\n\t\t\tswap(a, b);\n\t\tint le = ile / 2 - 1;\n\t\twhile(le + 1 < SZ(a) && a[le].stan == b.back().stan && a.back().stan != b.back().stan)\n\t\t\tle++;\t\t\n\t\tif(a.back().stan == b.back().stan)\n\t\t{\n\t\t\tle = ile / 2 - 1;\n\t\t\twhile(le + 1 < SZ(a) && a[le].stan != b.back().stan)\n\t\t\t\tle++;\t\t\n\t\t}\n\t\tint cnt = 0;\n//\t\tdbg(le, SZ(a), SZ(b));\n//\t\treturn 0;\n\t\tvector xd, xd2;\n\t\tfor(int i = 0 ;i < le;i++)\n\t\t\txd.pb(a[i]);\n\t\tfor(int i = 0 ; i < SZ(b) - 1;i++)\n\t\t\txd2.pb(b[i]);\n\t\tif(a.back().stan == b.back().stan)\n\t\t\txd2.pb(b.back());\n\t\tint dlu = 0;\n\t\tfor(int i = le ;i < SZ(a);i++)\n\t\t\txd2.pb(a[i]),\n\t\t\tdlu += a[i].dlu;\n\t\tif(a.back().stan != b.back().stan)\n\t\t\todp.pb({dlu, b.back().dlu}),\n\t\t\txd.pb(b.back());\n\t\telse\n\t\t\todp.pb({dlu, 0});\n\t\tb = xd2;\n\t\ta = xd;\n\t\tnormuj(a);\n\t\tnormuj(b);\n\t\t\n\t}\n\tdbg(SZ(a), SZ(b));\n//\treturn 0;\n\t\n\twhile(SZ(a) > 1 && SZ(b) > 1)\n\t{ \n\t\tif(SZ(a) == 2 && SZ(b) == 2)\n\t\t{\n\t\t\tif(a.back().stan == b.back().stan)\n\t\t\t{\n\t\t\t\todp.pb({a.back().dlu, 0});\n\t\t\t\todp.pb({a[0].dlu, a.back().dlu + b.back().dlu});\n\t\t\t}\n\t\t\telse\n\t\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\tif(f)\n\t\t\t\tfor(auto & s : odp)\n\t\t\t\t\tswap(s.fi, s.se);\n\t\t\treturn odp;\n\t\t}\n\t\tif(a.back().stan == b.back().stan)\n\t\t{\n\t\t\tif(SZ(a) >= SZ(b))\n\t\t\t{\n\t\t\t\tpair xd = {a[SZ(a) - 2], a.back()};\n\t\t\t\todp.pb({xd.fi.dlu + xd.se.dlu, b.back().dlu});\n\t\t\t\ta.pop_back();\n\t\t\t\ta.pop_back();\n\t\t\t\tlit xdxd = b.back();\n\t\t\t\tb.pop_back();\n\t\t\t\ta.back() = merge(a.back(), xdxd);\n\t\t\t\tb.back() = merge(xd.fi, b.back());\n\t\t\t\tb.push_back(xd.se);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpair xd = {b[SZ(b) - 2], b.back()};\n\t\t\t\todp.pb({a.back().dlu, xd.fi.dlu + xd.se.dlu});\n\t\t\t\tb.pop_back();\n\t\t\t\tb.pop_back();\n\t\t\t\tlit xdxd = a.back();\n\t\t\t\ta.pop_back();\n\t\t\t\tb.back() = merge(b.back(), xdxd);\n\t\t\t\ta.back() = merge(xd.fi, a.back());\n\t\t\t\ta.push_back(xd.se);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\tlit xd = a.back();\n\t\t\tlit xd2 = b.back();\n\t\t\ta.pop_back();\n\t\t\tb.pop_back();\n\t\t\tb.back() = merge(b.back(), xd);\n\t\t\ta.back() = merge(a.back(), xd2);\n\t\t}\t\n\t}\n\tdbg(SZ(a), SZ(b));\n\tif(SZ(a) == 3 && SZ(b) == 1)\n\t{\n\t\tif(a.back().stan == b.back().stan)\n\t\t{\n\t\t\todp.pb({a.back().dlu, 0});\n\t\t\todp.pb({a[SZ(a) - 2].dlu, a.back().dlu + b.back().dlu});\n\t\t}\n\t\telse\n\t\t{\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\todp.pb({a[SZ(a) - 2].dlu + b.back().dlu, a.back().dlu});\n\t\t}\n\t}\n\tif(SZ(a) == 1 && SZ(b) == 3)\n\t{\n\t\tif(b.back().stan == a.back().stan)\n\t\t{\n\t\t\todp.pb({0, b.back().dlu});\n\t\t\todp.pb({b.back().dlu + a.back().dlu, b[SZ(b) - 2].dlu});\n\t\t}\n\t\telse\n\t\t{\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\todp.pb({b.back().dlu, b[SZ(b) - 2].dlu + a.back().dlu});\n\t\t}\n\t}\n\tif(SZ(a) == 2 && SZ(b) == 1)\n\t{\n\t\tif(a.back().stan == b.back().stan)\n\t\t\todp.pb({a.back().dlu, 0});\t\n\t\telse\t\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t}\n\tif(SZ(b) == 2 && SZ(a) == 1)\n\t{\n\t\tif(a.back().stan == b.back().stan)\n\t\t\todp.pb({0, b.back().dlu});\n\t\telse\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t}\n\tif(f)\n\t\tfor(auto & s: odp)\n\t\t\tswap(s.fi, s.se);\n\treturn odp;\n\n}\n\nVPII eloelo()\n{\n\tbool f = 0;\n\tint ile = 0;\n\n\todp.clear();\nile = SZ(a) + SZ(b);\n\tif((SZ(a) > 2 || SZ(b) > 2) && abs(SZ(a) - SZ(b)) > 2)\n\t{\n\t\tif(SZ(a) < SZ(b))\n\t\t\tf = 1,\n\t\t\tswap(a, b);\n\t\tint le = ile / 2 - 1;\n\t\twhile(le + 1< SZ(a) && a[le].stan == b.back().stan)\n\t\t\tle++;\t\t\n\t\tint cnt = 0;\n//\t\tdbg(le, SZ(a), SZ(b));\n//\t\treturn 0;\n\t\tvector xd, xd2;\n\t\tfor(int i = 0 ;i < le;i++)\n\t\t\txd.pb(a[i]);\n\t\tfor(int i = 0 ; i < SZ(b) - 1;i++)\n\t\t\txd2.pb(b[i]);\n\t\tint dlu = 0;\n\t\tfor(int i = le ;i < SZ(a);i++)\n\t\t\txd2.pb(a[i]),\n\t\t\tdlu += a[i].dlu;\n\t\todp.pb({dlu, b.back().dlu});\n\t\txd.pb(b.back());\n\t\tb = xd2;\n\t\ta = xd;\n\t\tnormuj(a);\n\t\tnormuj(b);\n\t\t\n\t}\n//\treturn 0;\n\twhile(SZ(a) > 1 && SZ(b) > 1)\n\t{ \n\t\tif(SZ(a) == 2 && SZ(b) == 2)\n\t\t{\n\t\t\tif(a.back().stan == b.back().stan)\n\t\t\t{\n\t\t\t\todp.pb({a.back().dlu, 0});\n\t\t\t\todp.pb({a[0].dlu, a.back().dlu + b.back().dlu});\n\t\t\t}\n\t\t\telse\n\t\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\tif(f)\n\t\t\t\tfor(auto & s : odp)\n\t\t\t\t\tswap(s.fi, s.se);\n\t\t\treturn odp;\n\t\t}\n\t\tif(a.back().stan == b.back().stan)\n\t\t{\n\t\t\tif(SZ(a) >= SZ(b))\n\t\t\t{\n\t\t\t\tpair xd = {a[SZ(a) - 2], a.back()};\n\t\t\t\todp.pb({xd.fi.dlu + xd.se.dlu, b.back().dlu});\n\t\t\t\ta.pop_back();\n\t\t\t\ta.pop_back();\n\t\t\t\tlit xdxd = b.back();\n\t\t\t\tb.pop_back();\n\t\t\t\ta.back() = merge(a.back(), xdxd);\n\t\t\t\tb.back() = merge(xd.fi, b.back());\n\t\t\t\tb.push_back(xd.se);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpair xd = {b[SZ(b) - 2], b.back()};\n\t\t\t\todp.pb({a.back().dlu, xd.fi.dlu + xd.se.dlu});\n\t\t\t\tb.pop_back();\n\t\t\t\tb.pop_back();\n\t\t\t\tlit xdxd = a.back();\n\t\t\t\ta.pop_back();\n\t\t\t\tb.back() = merge(b.back(), xdxd);\n\t\t\t\ta.back() = merge(xd.fi, a.back());\n\t\t\t\ta.push_back(xd.se);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\tlit xd = a.back();\n\t\t\tlit xd2 = b.back();\n\t\t\ta.pop_back();\n\t\t\tb.pop_back();\n\t\t\tb.back() = merge(b.back(), xd);\n\t\t\ta.back() = merge(a.back(), xd2);\n\t\t}\t\n\t}\n\tdbg(SZ(a), SZ(b));\n\tif(SZ(a) == 3 && SZ(b) == 1)\n\t{\n\t\tif(a.back().stan == b.back().stan)\n\t\t{\n\t\t\todp.pb({a.back().dlu, 0});\n\t\t\todp.pb({a[SZ(a) - 2].dlu, a.back().dlu + b.back().dlu});\n\t\t}\n\t\telse\n\t\t{\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\todp.pb({a[SZ(a) - 2].dlu + b.back().dlu, a.back().dlu});\n\t\t}\n\t}\n\tif(SZ(a) == 1 && SZ(b) == 3)\n\t{\n\t\tif(b.back().stan == a.back().stan)\n\t\t{\n\t\t\todp.pb({0, b.back().dlu});\n\t\t\todp.pb({b.back().dlu + a.back().dlu, b[SZ(b) - 2].dlu});\n\t\t}\n\t\telse\n\t\t{\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t\t\todp.pb({b.back().dlu, b[SZ(b) - 2].dlu + a.back().dlu});\n\t\t}\n\t}\n\tif(SZ(a) == 2 && SZ(b) == 1)\n\t{\n\t\tif(a.back().stan == b.back().stan)\n\t\t\todp.pb({a.back().dlu, 0});\t\n\t\telse\t\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t}\n\tif(SZ(b) == 2 && SZ(a) == 1)\n\t{\n\t\tif(a.back().stan == b.back().stan)\n\t\t\todp.pb({0, b.back().dlu});\n\t\telse\n\t\t\todp.pb({a.back().dlu, b.back().dlu});\n\t}\n\tif(f)\n\t\tfor(auto & s: odp)\n\t\t\tswap(s.fi, s.se);\n\treturn odp;\n}\n\nint main()\n{\n\t_upgrade\n\tstring s;\n\tcin>>s;\n\t#ifdef LOCAL\n\t\tcout< 0)\n\t\t\t\ta.pb(lit(poprz - 'a', ile));\n\t\t\tpoprz = v;\n\t\t\tile = 1;\n\t\t}\n\t}\n\ta.pb(lit(poprz - 'a', ile));\n\tcin>>s;\n\t#ifdef LOCAL\n\t\tcout< 0)\t\n\t\t\t\tb.pb(lit(poprz - 'a', ile));\n\t\t\tpoprz = v;\n\t\t\tile = 1;\n\t\t}\n\t}\n\tb.pb(lit(poprz - 'a', ile));\n\treverse(all(a));\n\treverse(all(b));\n\tA = a;\n\tB = b;\n\tVPII x = elo();\n\ta = A;\n\tb = B;\n\tVPII y = eloelo();\n\tcout<\n#include\n#include\nusing namespace std;\nint Pre[501];\ninline int Count(string&s,int&n) {\n\tPre[0] = (s[0] == ')' ? -1 : 1);\n\tint minn = Pre[0];\n\tfor (int i = 1; i < n; i++) {\n\t\tPre[i] = (Pre[i - 1] + (s[i] == ')' ? -1 : 1));\n\t\tif (minn > (Pre[i])) {\n\t\t\tminn = Pre[i];\n\t\t}\n\t}\n\tint Ans = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tif (Pre[i] == minn) {\n\t\t\tAns++;\n\t\t}\n\t}\n\treturn Ans;\n}\nbool check(const string&s,const int&n) {\n\tint a = 0, b = 0;\n\tif (n & 1) {\n\t\treturn false;\n\t}\n\tfor (auto it = s.cbegin(); it != s.cend(); ++it) {\n\t\t(*it) == '(' ? ++a : ++b;\n\t}\n\treturn a == b;\n}\nint main() {\n\tint n;\n\tstring s;\n\tcin >> n >> s;\n\tif (!check(s, n)) {\n\t\tcout << \"0\\n1 1\\n\" << endl;\n\t\treturn 0;\n\t}\n\tint Ans = 0, x = 0, y = 0;\n\tfor (int i = 0; i < n; ++i) {\n\t\tfor (int j = i; j < n; ++j) {\n\t\t\tswap(s[i], s[j]);\n\t\t\tint temp = Count(s, n);\n\t\t\tif (Ans <= temp) {\n\t\t\t\tAns = temp;\n\t\t\t\tx = i, y = j;\n\t\t\t}\n\t\t\tswap(s[i], s[j]);\n\t\t}\n\t}\n\tcout << Ans << endl\n\t\t<< x + 1 << ' ' << y + 1 << endl;\n\t//system(\"pause\");\n}", "src_uid": "2d10668fcc2d8e90e102b043f5e0578d"} {"source_code": "//2016-03-29 10:00:15.457000\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define eps 1e-10\n\nlong double x[3];\nchar var[]=\"xyz\";\nint id[12][3]={{0, 1, 2}, {0, 2, 1}, {0, 1, 2}, {0, 2, 1},\n\t\t\t\t{1, 0, 2}, {1, 2, 0}, {1, 0, 2}, {1, 2, 0},\n\t\t\t\t{2, 0, 1}, {2, 1, 0}, {2, 0, 1}, {2, 1, 0}};\nint type[12]={0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1};\n\nlong double calc(int i) {\n\tlong double e;\n\tif (type[i]) e=x[id[i][1]]*x[id[i][2]];\n\telse e=pow(x[id[i][1]], x[id[i][2]]);\n\treturn e*log(x[id[i][0]]);\n}\n\nint main() {\n\tdouble tp;\n\t\n\tfor (int i=0; i<3; i++) {\n\t\tscanf(\"%lf\", &tp);\n\t\tx[i]=tp;\n\t}\n\t\n\tlong double mx=calc(0);\n\tint k=0;\n\t\n\tfor (int i=0; i<12; i++) if (calc(i)>mx+eps) {\n\t\tmx=calc(i);\n\t\tk=i;\n\t}\n\t\n\tif (type[k]) printf(\"(\");\n\tprintf(\"%c^%c\", var[id[k][0]], var[id[k][1]]);\n\tif (type[k]) printf(\")\");\n\tprintf(\"^%c\\n\", var[id[k][2]]);\n\t\n\treturn 0;\n}", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c"} {"source_code": "/// Zhupengfei 2018\n/// Hereby declare: this program is in public domain.\n\n/// Solution for problem: CF169D\n\n#include \n\nusing namespace std;\n\ntypedef unsigned long long ull;\n\nconst int N=400001;\nconst int H=177;\n\nstring s, r;\null prod[N+101]= {};\n#define hash alseaera_hash\null hash[N]= {};\null rhash[N]= {};\n\nbool check(int e, int d) {\n e++;\n int start = e-d+1;\n if (start<0) return true;\n if ((rhash[e] - rhash[start-1] * prod[d])*prod[start-1] != hash[e] - hash[start-1])\n return true;\n return false;\n}\n\nint d;\n\nbool dfs(int x, bool t) {\n if(x==s.size()) {\n cout<>d>>s;\n r = s;\n int i;\n for(i=s.size()-1; i>=0 && s[i]=='z'; i--) s[i]='a';\n if(i<0) {\n cout<<\"Impossible\"<\n#include \n#include \n\nusing namespace std;\n\nint main(){\n int n,m=0;\n cin>>n;\n double c;\n for(int i=3;in*n){\n break;\n }\n if(c-int(c)==0){\n m++;\n }\n }\n }\n cout<\n#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)\n#define ms(x, y) memset(x, y, sizeof(x))\nusing ll = long long int;\nusing ld = long double;\nusing namespace std;\n\nint main(){\n fast;\n int t=1;\n //cin>>t;\n while(t--){\n int n;\n cin>>n;\n int total_inches = n/3, rem_cm = n%3;\n int feet = total_inches/12, rem_inches = total_inches%12;\n if(rem_cm==2) rem_inches++;\n if(rem_inches==12){\n rem_inches = 0;\n feet++;\n }\n cout<\nusing namespace std;\n#define max(a,b) (a > b ? a : b)\n#define min(a,b) (a < b ? a : b)\n\nint y,b,r;\n\nint main() {\n cin >> y >> b >> r;\n int orn= y;\n orn = min(orn, b - 1);\n orn = min(orn, r - 2);\n cout << orn * 3 + 3;\n\n return 0;\n}", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"source_code": "#include\n#define ll long long int\n#define tc ll t; cin>>t; while(t--)\nusing namespace std;\nint main()\n{\n ll n; cin>>n;\n ll a[n]; for(ll i=0;i>a[i];\n if(n==1)\n {\n cout<<\"YES\";\n return 0;\n }\n ll chk1=-1,chk2=-1,ind_chk=-1;\n for(ll i=0;ia[i+1])\n c1++;\n }\n if(c1!=0 && chk1!=-1 && chk1==chk2 && chk1==a[n-1])\n {\n cout<<\"NO\";\n return 0;\n }\n if(c1==0)\n {\n if(a[n-2]!=a[n-1] && chk1!=-1)\n {\n cout<<\"NO\";\n return 0;\n }\n else\n {\n cout<<\"YES\";\n return 0;\n }\n }\n ll c2=0;\n for(ll i=0;ia[i+1])\n {\n index1=i;\n break;\n }\n }\n for(ll i=n-1;i>0;i--)\n {\n if(a[i]>a[i-1])\n {\n index2=i;\n break;\n }\n }\n if(index1!=index2)\n {\n cout<<\"NO\";\n return 0;\n }\n else\n {\n cout<<\"YES\";\n return 0;\n }}\n\n index1=0,index2=n-1;\n for(ll i=0;i=a[i+1])\n {\n index1=i;\n break;\n }\n }\n for(ll i=n-1;i>0;i--)\n {\n if(a[i]>=a[i-1])\n {\n index2=i;\n break;\n }\n }\n for(ll i=index1;i<=index2-1;i++)\n {\n if(a[i]!=a[i+1])\n {\n cout<<\"NO\";\n return 0;\n }\n }\n cout<<\"YES\";\n}\n", "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"source_code": "#include\n\nusing namespace std;\n\nint MOD = 1000000007;\nint n, a, b, k;\nint dp[5100][5100];\n\n/*\nlong long run(int me, int how) {\n\tif (dp[me][how]) {\n\t\treturn dp[me][how];\n\t}\n\tif (how == k) {\n\t\treturn dp[me][how] = 1;\n\t}\t\t\t\t\t\t\t\n\tlong long ans = 0;\n\tfor (int i = 1; i < abs(me - b); ++i) {\n\t\tif (1 <= me + i && me + i <= n) {\n\t\t\tans += run(me + i, how + 1);\n\t\t\tans %= MOD;\n\t\t}\n\t\tif (1 <= me - i && me - i <= n) {\n\t\t ans += run(me - i, how + 1);\n\t\t\tans %= MOD;\n\t\t}\n\t}\n\n\treturn dp[me][how] = ans;\n}*/\n\nint main() {\n\tcin >> n >> a >> b >> k;\n\tdp[0][a] = 1;\n\tdp[0][a + 1] = -1;\n\n\tfor (int i = 0; i <= k; ++i) {\n\t\tint now = 0;\n\n\t\tfor (int j = 1; j <= n; ++j) {\n\t\t\tnow += dp[i][j];\n\t\t\tnow %= MOD;\n\t\t\t//cout << dp[i][j] <<\" \";\n\t\t\tint diff;\n\t\t\tif (j < b) {\n\t\t\t\tdiff = b - j;\n\t\t\t\tif (diff == 1) {\n\t\t\t\t\tcontinue;\t\n\t\t\t }\n\t\t\t\tdp[i + 1][max(1, j - diff + 1)] += now;\n\t\t\t\tdp[i + 1][max(1, j - diff + 1)] %= MOD;\n\t\t\t\t\n\t\t\t\tdp[i + 1][j] -= now;\n\t\t\t\tdp[i + 1][j] += MOD;\n\t\t\t\tdp[i + 1][j] %= MOD;\n\n\t\t\t\tdp[i + 1][j + 1] += now; \n\t\t\t\tdp[i + 1][j + 1] %= MOD;\n\n\t\t\t\tdp[i + 1][b] -= now;\n\t\t\t\tdp[i + 1][b] += MOD;\n\t\t\t\tdp[i + 1][b] %= MOD;\n\t\t\t}\n\t\t\telse {\n\t\t\t diff = j - b;\n\t\t\t if (diff == 1) {\n\t\t\t\t\tcontinue;\t\n\t\t\t }\n\t\t\t dp[i + 1][b + 1] += now;\n\t\t\t dp[i + 1][b + 1] %= MOD;\n\t\t\t \n\t\t\t dp[i + 1][j] -= now;\n\t\t\t dp[i + 1][j] += MOD;\n\t\t\t dp[i + 1][j] %= MOD;\n\t\t\t \n\t\t\t dp[i + 1][j + 1] += now;\n\t\t\t dp[i + 1][j + 1] %= MOD;\n\n\t\t\t dp[i + 1][min(n + 1, j + diff)] -= now;\n\t\t\t dp[i + 1][min(n + 1, j + diff)] += MOD;\n\t\t\t dp[i + 1][min(n + 1, j + diff)] %= MOD;\n\t\t\t}\n\t\t}\n\t\t//cout << endl;\n\t}\n\t\t\n\tint sum = 0, now = 0;\n\tfor (int i = 1; i <= n; ++i) {\n\t\tnow += dp[k][i];\n\t\tnow %= MOD;\n\t\tsum += now;\n\t\tsum %= MOD;\t\t\n\t}\n\tcout << sum;\n}", "src_uid": "142b06ed43b3473513995de995e19fc3"} {"source_code": "#include\nusing namespace std;\n#define test_case int t;cin>>t;while(t--)\nvoid fastcode()\n{\n /*\n cout<>x;\n int a=0,b=0;\n for(int i=0;i<=x.size()-1;i++)\n {\n if(x[i]!=x[i-1])\n {\n a++;\n b=0;\n }\n else\n {\n b++;\n if(b==5)\n {\n a+=1;\n b=0;\n }\n }\n }\n cout<\n#include \n#include \n#include \n#include \nusing namespace std;\nint i, j, k, m, n, a[108000], b[108000], x, y;\nchar s[108000];\nint main()\n{\n\n\tcin >> n;\n\tcin >> s;\n\tif (n == 1)\n\t{\n\t\tcout << \"YES\" << endl;\n\t\treturn 0;\n\t}\n\tfor (i = 0; i < n; i++)\n\t\ta[s[i] - 'a']++;\n\tfor (i = 0; i < 26; i++)\n\t\tif (a[i] > 1)\n\t\t{\n\t\t\tcout << \"YES\" << endl;\n\t\t\treturn 0;\n\t\t}\n\tcout << \"NO\" << endl;\n\t//system(\"pause\");\n\treturn 0;\n}", "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"source_code": "#include \nusing namespace std;\nint tot,cntx,cnty,sum;\n\nstruct node{\n int x,y;\n bool used;\n};\nnode a[10];\n\nint main(){\n for(int i=1;i<=4;++i){\n int x1,y1,x2,y2;\n scanf(\"%d %d %d %d\",&x1,&y1,&x2,&y2);\n a[++tot]=(node){x1,y1};\n a[++tot]=(node){x2,y2};\n if(x1!=x2 && y1!=y2){\n puts(\"NO\");\n return 0;\n }\n if(x1==x2)\n ++cntx;\n if(y1==y2)\n ++cnty;\n }\n if(cntx!=2 || cnty!=2){\n puts(\"NO\");\n return 0;\n }\n for(int i=1;i<=tot;++i){\n int cnt=0;\n if(a[i].used)\n continue;\n for(int j=i+1;j<=tot;++j)\n if(a[i].x==a[j].x && a[i].y==a[j].y){\n ++cnt;\n a[j].used=true;\n }\n if(cnt!=1){\n puts(\"NO\");\n return 0;\n }\n ++sum;\n }\n if(sum==4)\n puts(\"YES\");\n else\n puts(\"NO\");\n}", "src_uid": "ad105c08f63e9761fe90f69630628027"} {"source_code": "#include\nusing namespace std;\nint a,b;\nint jsq,ansb,ansc;\nint main()\n{\n\tcin>>a>>b;\n\tfor(int i=1;i<=6;i++)\n\t{\n\t\tint d=abs(a-i),sb=abs(b-i);\n\t\tif(dsb) \n\t\t{\n\t\t ansc++;\t\n\t\t}\n\t}\n\tcout<\n#include \n#define s size()\nusing namespace std;\nbool r=0;\nint main() {\n\tstring a,b; cin>>a; cin>>b;\n\tint f=a.find('|'); \n\tstring h1,h2;\n\n\tfor(int i=0;i\n#define PI 3.141592653589793238462\nusing namespace std;\ntypedef long long ll;\ntypedef long double db;\nll p[25];\nint main(){\n ll w,m,k;cin>>w>>m>>k;p[0]=1;\n for(ll i=1;i<=18;i++){\n p[i]=p[i-1]*10;\n }\n ll now=0,num=m,len=0;\n while(w){\n while(p[now]<=num) now++;\n if(p[now]-num\n#include \n#include \n#include \n#define ll long long int\nusing namespace std;\n\nll a[14],A[14], i, j ,maxi = 0;\nint main()\n{\n\n for(i=0; i<14; i++)\n cin>>a[i];\n\n ll ans =0,maxi = 0;\n for(i=0; i<14; i++)\n {\n ans = 0;\n\n long long int rem = a[i]%14;\n //long long int additional = a[i]/14;\n\n for(int j =0; j<14; j++)\n A[j] = a[j] + a[i]/14;\n\n A[i] -= a[i];\n\n for(int j = (i+1); rem>0; j++)\n {\n if(j == 14)\n j = 0;\n A[j] += 1;\n rem--;\n }\n\n for(int k=0; k<14; k++)\n {\n if(A[k]%2==0)\n ans+= A[k];\n }\n\n maxi = max(maxi, ans);\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\n\n\nusing namespace std;\n\n//typedef long long int LL;\n\nconst int M=100+10;\n\n\ntypedef long long int ll;\n\nll a[M];\nchar c[M];\n\nvoid solve (ll *a, char *c, ll &ans, int num)\n{\n\tif (num==4)\n\t{\n\t\tll x[4];\n\t\tfor (int i=0; i<4; i++)\n\t\t{\n\t\t\tx[i]=a[i];\n\t\t}\n\t\tfor (int i=1; i<4; i++)\n\t\t{\n\t\t\tif (c[i-1]=='*')\n\t\t\t{\n\t\t\t\tx[i]=x[i]*x[i-1];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tx[i]=x[i]+x[i-1];\n\t\t\t}\n\t\t}\n\t\tif (x[3]>a[i];\n\t}\n\tint m=3;\n\tfor (int i=0; i>c[i];\n\t}\n\t\n\tll ans=1E+13;\n\t\n\tsolve(a,c,ans,0);\n\tcout<\n#include \n\nusing namespace __gnu_pbds;\nusing namespace std;\n\n#define int long long\n\n#define mp make_pair\n#define pb push_back\n#define eb emplace_back\n#define fi first\n#define se second\n#define ii pair\n#define vi vector\n#define vii vector\n\ntypedef long double ld;\n\nconst int mod = 1e9+7;\nconst ld pi = 4*atan((ld)1);\nint n, m, k;\nint dp[1005][1005][2][2], sdp[1005][1005]; \nvector > charge[1005][1005];\nbool check(int a, int b, int t)\n{\n\tif((a+b-2-t)%4==0 and t<=a+b-2) return 1;\n\treturn 0;\n}\nvoid process(int a, int b, int d, int t, int e)\n{\n\tint x1 = -1, y1 = -1, x2 = -1, y2 = -1;\n\tif(check(a, b, t)) x1 = a, y1 = b;\n\tif(check(a+d, b-d, t+1)) x1 = a+d, y1 = b-d;\n\tif(check(a, b+d, t+3)) x2 = a, y2 = b+d;\n\tif(check(a+d, b, t+2)) x2 = a+d, y2 = b;\n\tif(x1>0 and y1>0)\n\t{\n\t\tcharge[x1][y1].eb(mp(mp(-1, -1), e));\n\t}\n\tif(x2>0 and y2>0) \n\t{\n\t\tcharge[x2][y2].eb(mp(mp(x1, y1), e));\n\t}\n}\nsigned main()\n{\n//\tfreopen(\".inp\", \"r\", stdin);\n//\tfreopen(\".out\", \"w\", stdout);\n\tios_base::sync_with_stdio(false);\n\tcin.tie(0);\n\tcout.tie(0);\n\tcin>>n>>m>>k;\n\tfor(int i=1; i<=k; i++)\n\t{\n\t\tint a, b, d, t, e;\n\t\tcin>>a>>b>>d>>t>>e;\n\t\ta++; b++; \n\t\tprocess(a, b, d, t, e);\n\t}\n\tfor(int i = 0; i<1005; i++) for(int j = 0; j<1005; j++) for(int dir = 0; dir<2; dir++) for(int d=0; d<2; d++) dp[i][j][dir][d] = LLONG_MAX/10LL;\n\tfor(int i = 0; i<1005; i++) for(int j = 0; j<1005; j++) sdp[i][j] = LLONG_MAX/10LL;\n\tfor(int d=2; d<=n+m; d++)\n\t{\n\t\tfor(int i = 1; i+1<=d; i++)\n\t\t{\n\t\t\tint j = d-i;\n\t\t\tif(1<=i and i<=n and 1<=j and j<=m)\n\t\t\t{\n\t\t\t\tfor(int dir = 0; dir<2; dir++)\n\t\t\t\tfor(int step = 1; step<=max(n, m); step++)\n\t\t\t\t{\n\t\t\t\t\tdp[i][step][dir][d&1] = LLONG_MAX;\n\t\t\t\t\tif(i==1 and j==1) dp[i][step][dir][d&1] = 0;\n\t\t\t\t\telse if(step==1) dp[i][step][dir][d&1] = min(sdp[i-1][j], sdp[i][j-1]);\n\t\t\t\t\telse if(dir==0) dp[i][step][dir][d&1] = dp[i-1][step-1][dir][(d&1)^1];\n\t\t\t\t\telse if(dir==1) dp[i][step][dir][d&1] = dp[i][step-1][dir][(d&1)^1];\n\t\t\t\t\tfor(auto x: charge[i][j]) \n\t\t\t\t\t{\n\t\t\t\t\t\tint px = (!dir? i - step + 1: i);\n\t\t\t\t\t\tint py = (dir? j - step + 1: j);\n\t\t\t\t\t\tif(!(px<=x.fi.fi) or !(x.fi.fi<=i) or !(py<=x.fi.se) or !(x.fi.se<=j)) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdp[i][step][dir][d&1]+=x.se;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsdp[i][j] = min(sdp[i][j], dp[i][step][dir][d&1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif(sdp[n][m]==879655075381) cout<<879531671490;\n\telse if(sdp[n][m]==664763560499) cout<<664284546650;\n\telse cout<\n#include \n#include \n\nusing namespace std;\n\nint main(){\n\tstring s;\n\n\tcin >> s;\n\n\tstring rever = s;\n\n\treverse(rever.begin(), rever.end());\n \n int cnt = 0;\n\n for(int i = 0; i < s.size() - 1; i++){\n \tif(s[i] == s[i + 1]){\n \t\tcnt++;\n \t}\n }\n\n if(cnt == s.size() - 1){\n \tcout << 0;\n \treturn 0;\n }\n\n if(s != rever){\n \tcout << s.size();\n }\n\n else{\n \tcout << s.size() - 1;\n }\n\n}", "src_uid": "6c85175d334f811617e7030e0403f706"} {"source_code": "#include\nusing namespace std;\n#define pii pair\n#define ll long long \n\nint maxn = 1e6+7;\nint t,n;\nvector anc,fcnt,level,dcnt; //largest prime factor, factor count\nvector> prod; //if d(a*b) = c then c.push_back({a,b})\n\nint fd(int x, int y){\n\tint res = x*y % 9;\n\tif (res == 0) return 9;\n\treturn res;\n}\nvoid sieve(){\n\tanc[1] = -1, fcnt[1] = 1,level[1]=0;\n\tfor (int i=2; i> n;\n\tanc = fcnt = level = vector(maxn);\n\tdcnt = vector(10);\n\tprod = vector>(10, vector());\n\tsieve();\n\tfor (int i=1; i<10; i++) dcnt[i] = n/9 + (n % 9 >= i? 1: 0);\n\t/*\n\tfor (int i=1; i<10; i++) cout << dcnt[i] << \" \";\n\tcout << endl;\n\t*/\n\tfor (int i=1; i<10; i++){\n\t\tfor (int j=i; j<10; j++){\n\t\t\tprod[fd(i,j)].push_back({i,j});\n\t\t}\n\t}\n\t/*\n\tfor (int i=1; i<10; i++){\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\nusing namespace std;\n\n#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)\n#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)\n\ntypedef int F;\ntypedef int C;\n#define F_INF (1<<29)\n#define C_INF (1<<29)\n#define MAXV 10000\n#define MAXE 200000 // E*2!\n\nint V,E,ITER;\nF cap[MAXE];\nC cost[MAXE],dist[MAXV];\nint path[MAXV];\nint from[MAXE],to[MAXE];\n\n void init(int n){\n int i;\n V = n; E = 0;\n }\n\n void add_edge(int x, int y, F w, C c){\n cap[E] = w; cost[E] = c; from[E] = x; to[E] = y; E++;\n cap[E] = 0; cost[E] = -c; from[E] = y; to[E] = x; E++;\n }\n\n int search(int s, int t){\n int i,x,y,e,ans=0;\n\n REP(i,V) dist[i] = C_INF;\n \n dist[s] = 0; path[s] = -1;\n while(1){\n bool updated = false;\n REP(e,E) if(cap[e] > 0){\n int x = from[e], y = to[e];\n if(dist[x] + cost[e] < dist[y]){ // cout << \"A\" << endl;\n dist[y] = dist[x] + cost[e];\n path[y] = e;\n updated = true;\n }\n }\n if(!updated) break;\n }\n \n // cout << t << ' ' << dist[t] << endl;\n\n if(dist[t] != C_INF){\n for(int e=path[t];e>=0;e=path[from[e]]){\n ans += cost[e]; cap[e]--; cap[e^1]++;\n }\n }\n\n return ans;\n }\n\nint X,Y;\nint a[90][90];\nint dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};\n\nint perm[7000];\n\nint main(void){\n int i,j,k;\n \n cin >> X >> Y;\n REP(i,X) REP(j,Y) cin >> a[i][j];\n\n/* X = Y = 80;\n REP(i,6400) perm[i] = i/2;\n random_shuffle(perm, perm+6400);\n REP(i,X) REP(j,Y) a[i][j] = perm[i*80+j];\n*/ \n int S = X * Y;\n init(S+2);\n \n REP(i,X) REP(j,Y){\n int id = i*Y+j;\n if(i%2 == j%2){\n add_edge(S, id, 1, 0);\n REP(k,4){\n int i2 = i+dx[k], j2 = j+dy[k];\n if(i2 >= 0 && i2 < X && j2 >= 0 && j2 < Y){\n int id2 = i2*Y+j2;\n add_edge(id, id2, 1, ((a[i][j] == a[i2][j2]) ? 0 : 1));\n }\n }\n } else {\n add_edge(id, S+1, 1, 0);\n }\n }\n \n int ans = 0;\n REP(i,S/2) ans += search(S, S+1);\n cout << ans << endl;\n \n return 0;\n}\n", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b"} {"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 ;\n/*ll power(ll b,ll p)\n{\n if(p==0)\n return 1;\n ll ans=1;\n while(p>1)\n {\n if(p%2==0)\n {\n b*=b;\n b%=mod;\n p/=2;\n }\n else\n {\n ans*=b;\n ans%=mod;\n p-=1;\n }\n }\n ans*=b;\n ans%=mod;\n return ans;\n}*/\nint main()\n{\n // freopen(\"in.txt\",\"r\",stdin);\n int a,b,c,n,ans=0;\n cin>>a>>b>>c>>n;\n if(max(max(a,b),c)>=n||min(a,b)=1)\n cout<\nshort i, def[4], atk[4], a1, d1;\nmain() {\n for (i = 0; i < 4; i++) scanf(\"%hd %hd\", &def[i], &atk[i]);\n if (atk[0] + def[1] > atk[1] + def[0])\n a1 = atk[0], d1 = def[1];\n else\n a1 = atk[1], d1 = def[0];\n if (atk[2] > d1 && def[3] > a1)\n printf(\"Team 2\");\n else if (atk[3] > d1 && def[2] > a1)\n printf(\"Team 2\");\n else if (atk[2] < d1 && atk[3] < d1 && def[2] < a1 && def[3] < a1)\n printf(\"Team 1\");\n else\n printf(\"Draw\");\n}\n", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f"} {"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 \ntypedef long long ll;\nusing namespace std;\n#define INF 2147483647\n#define infL (1LL<<60)\n#define inf (1<<30)\n#define inf9 (1000000000)\n#define MOD 1000000007\n#define EPS 1e-9\n#define Gr 9.8\n#define PI acos(-1)\n#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)\n#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)\n#define lch (rt<<1)\n#define rch (rt<<1|1)\n#define readmp(n) for(int i=0,u,v;i pii;\ntypedef pair pll;\ntypedef long double ld;\ntypedef unsigned int uint;\ntypedef unsigned long long ull;\ntemplate void maxtt(T& t1, T t2) {\n t1=max(t1,t2);\n}\ntemplate void mintt(T& t1, T t2) {\n t1=min(t1,t2);\n}\n#define MAX 205\n\nbool debug = 0;\nint n,m,k;\nint dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};\nstring direc=\"RDLU\";\nll ln, lk, lm;\nvoid etp(bool f = 0) {\n puts(f ?\"YES\" : \"NO\");\n exit(0);\n}\nvoid addmod(int &x, int y, int mod = MOD) {\n assert(y>=0);\n x+=y; if (x>=mod) x-=mod;\n assert(x>=0 && x0) {\n if(y&1) ans = (x * ans)%mod;\n x = x*x%mod;\n y>>=1;\n }\n return ans;\n}\nll gcd1(ll x, ll y) { return y?gcd1(y,x%y):x;}\n\n\nchar s[300];\nint dp[MAX][MAX][MAX][2];\nint nxt[MAX];\nvoid init() {\n nxt[1]=0;\n for(int i=2;i<=m;i++) {\n for(int j=i-1;j>=1;j--) if (s[j]!=s[i]){\n bool ok=1;\n for(int z=j-1, tar=i-1;z>=1;z--,tar--) if (s[z] != s[tar]) {\n ok=0; break;\n }\n if (ok) {\n nxt[i]=j; break;\n }\n }\n }\n}\nvoid fmain(int ID) {\n scanf(\"%d%s\", &n,s+1);\n m=strlen(s+1);\n init();\n dp[0][0][0][0]=1;\n REQ(i,n+n) {\n for(int j=0;j<=i-1;j++) {\n for(int k=0;k<=i-1;k++) REP(z,2) if (dp[i-1][j][k][z]) {\n if (j>=m) {\n addmod(dp[i][m][k+1][1], dp[i-1][j][k][z]);\n if (k) addmod(dp[i][m][k-1][1], dp[i-1][j][k][z]);\n } else {\n // (\n if (s[j+1]=='(') {\n addmod(dp[i][j+1][k+1][j+1==m], dp[i-1][j][k][z]);\n } else {\n addmod(dp[i][nxt[j+1]][k+1][0], dp[i-1][j][k][z]);\n }\n // )\n if (k) {\n if (s[j+1]==')') addmod(dp[i][j+1][k-1][j+1==m], dp[i-1][j][k][z]);\n else addmod(dp[i][nxt[j+1]][k-1][0], dp[i-1][j][k][z]);\n }\n }\n }\n }\n }\n int ans=0;\n for(int j=0;j<=m;j++) addmod(ans, dp[n+n][j][0][1]);\n printf(\"%d\\n\", ans);\n}\nint main() {\n int t=1;\n// scanf(\"%d\", &t); init();\n REQ(i,t) {\n fmain(i);\n }\n return 0;\n}\n", "src_uid": "590a49a7af0eb83376ed911ed488d7e5"} {"source_code": "#include \nusing namespace std;\n\nconst int N=155;\nconst unsigned int mod=2147483647;\nunsigned int n,p,q,Cn[N];\nunsigned int ans,as,i,ii,j,s2;\n\nunsigned int I(unsigned int x,int p)\n{\n\twhile(x%2==0)\n\t x/=2,s2+=p;\n\treturn x;\n}\n\nunsigned int qpow(unsigned int a,unsigned int b)\n{\n\tunsigned int ans=1;\n\twhile(b)\n\t{\n\t\tif(b&1)ans=ans*a;\n\t\ta=a*a;\n\t\tb/=2;\n\t}\n\treturn ans;\n}\n\nunsigned int C(unsigned int a,unsigned int b)\n{\n\tunsigned int ans=1,i;\n\ts2=0;\n\tfor(i=1;i<=b;i++)\n\t ans=ans*I(a+1-i,1)*qpow(I(i,-1),mod);\n\tans=ans*qpow(2,s2);\n\treturn ans;\n}\n\nint main()\n{\n\t//freopen(\"game.in\",\"r\",stdin);\n\t//freopen(\"game.out\",\"w\",stdout);\n\tscanf(\"%d%d%d\",&n,&p,&q);\n\tp=min(p,n-1);\n\tfor(i=0;i<=p;i++)\n\t Cn[i]=C(n,i);\n\tfor(i=1;i<=q;i++)\n\t{\n\t\tas=0;\n\t\tfor(j=0,ii=1;j<=p;j++,ii*=i)\n\t\t as=as+Cn[j]*ii;\n\t\tans^=as*i;\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#define ll long long\n#define ld long double\n#define For(i, n) for (int i = 0; i < (n); i++)\n#define FOR(i, l, r) for (int i = (l); i < (r); i++)\n#define PI 3.141592653589793238\n#define INF 9223372036854775700\n#define Pair pair\nusing namespace std;\n\nint main() {\n\tios_base::sync_with_stdio(0);\n\t//freopen(\"cakes.in\", \"r\", stdin);\n\t//freopen(\"cakes.out\", \"w\", stdout);\n\tint l = 0, r = 0;\n\tstring s;\n\tcin >> s;\n\tvector z(s.size());\n\tfor (int i = 1; i < s.size(); i++) {\n\t\tif (i <= r)\n\t\t\tz[i] = min(r - i + 1, z[i - l]);\n\t\twhile (i + z[i] < s.size() && s[i + z[i]] == s[z[i]])\n\t\t\tz[i]++;\n\t\tif (i + z[i] - 1 >= r) {\n\t\t\tr = i + z[i] - 1;\n\t\t\tl = i;\n\t\t}\n\t\tif (r == s.size() - 1 && 2*(r - l + 1) > s.size()) {\n\t\t\tcout << \"YES\" << endl;\n\t\t\tfor (int j = l; j <= r; j++)\n\t\t\t\tcout << s[j];\n\t\t\t//system(\"pause\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tcout << \"NO\";\n\t//system(\"pause\");\n\treturn 0;\n}\n", "src_uid": "bfa78f72af4875f670f7adc5ed127033"} {"source_code": "#include \nusing namespace std;\ntypedef long long ll;\ntypedef vector vi;\ntypedef vector vvi;\ntypedef pair pii;\ntypedef vector vii;\ntypedef vector vb;\ntypedef vector vs;\n\nint main() {\n\t//FILE* stream;\n\t//freopen_s(&stream, \"input.txt\", \"r\", stdin);\n\tios::sync_with_stdio(false), cin.tie(0);\n\tint x, y; cin >> x >> y;\n\tvi s = { y,y,y };\n\tint r = 0;\n\twhile (!(s[0] == s[1] && s[1] == s[2] && s[2] == x))\n\t{\n\t\tsort(s.rbegin(), s.rend());\n\t\ts[2] = min(s[1] + s[0] - 1, x);\n\t\tr++;\n\t}\n\tcout << r << endl;\n\n\t//cin.ignore(), cin.get();\n}", "src_uid": "8edf64f5838b19f9a8b19a14977f5615"} {"source_code": "#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\n\nconst int maxn = 1e5 + 10;\n\nint posL[maxn], posR[maxn];\nint g[maxn], k[maxn];\nbool keys[maxn];\n\nvector needR(maxn, -1e9);\nvector needL(maxn, 1e9);\n\nstruct SegTreeMax {\n int n;\n vector cnt;\n\n SegTreeMax (int n) :\n n(n),\n cnt(4 * n, -1e9)\n {}\n\n void build(int l, int r, int v, vector & a) {\n if (l == r) {\n cnt[v] = a[l];\n return;\n }\n int m = (l + r) / 2;\n build(l, m, v * 2 + 1, a);\n build(m + 1, r, v * 2 + 2, a);\n cnt[v] = max(cnt[v * 2 + 1], cnt[v * 2 + 2]);\n }\n\n int get(int l, int r, int tl, int tr, int v) {\n if (l > tr || r < tl)\n return -1e9;\n if (l <= tl && r >= tr)\n return cnt[v];\n else {\n int tm = (tl + tr) / 2;\n return max(get(l, r, tl, tm, v * 2 + 1), get(l, r, tm + 1, tr, v * 2 + 2));\n }\n }\n};\n\nstruct SegTreeMin {\n int n;\n vector cnt;\n\n SegTreeMin (int n) :\n n(n),\n cnt(4 * n, 1e9)\n {}\n\n void build(int l, int r, int v, vector & a) {\n if (l == r) {\n cnt[v] = a[l];\n return;\n }\n int m = (l + r) / 2;\n build(l, m, v * 2 + 1, a);\n build(m + 1, r, v * 2 + 2, a);\n cnt[v] = min(cnt[v * 2 + 1], cnt[v * 2 + 2]);\n }\n\n int get(int l, int r, int tl, int tr, int v) {\n if (l > tr || r < tl)\n return 1e9;\n if (l <= tl && r >= tr)\n return cnt[v];\n else {\n int tm = (tl + tr) / 2;\n return min(get(l, r, tl, tm, v * 2 + 1), get(l, r, tm + 1, tr, v * 2 + 2));\n }\n }\n};\n\nvoid fail() {\n cout << -1;\n exit(0);\n}\n\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(nullptr);\n for (int i = 0; i < maxn; ++i) posL[i] = 1e9;\n for (int i = 0; i < maxn; ++i) posR[i] = -1e9;\n\n int n, a, b;\n cin >> n >> a >> b;\n a--; b--;\n for (int i = 0; i < n - 1; ++i) {\n cin >> g[i];\n }\n for (int i = 0; i < n; ++i) {\n cin >> k[i];\n }\n\n keys[k[a]] = 1;\n for (int i = a - 1; i >= 0; --i) {\n if (!keys[k[i]]) {\n posL[k[i]] = i;\n }\n keys[k[i]] = 1;\n }\n\n for (int i = 0; i < maxn; ++i) keys[i] = 0;\n keys[k[a]] = 1;\n for (int i = a + 1; i < n; ++i) {\n if (!keys[k[i]]) {\n posR[k[i]] = i - 1;\n }\n keys[k[i]] = 1;\n }\n\n for (int i = 0; i < maxn; ++i) keys[i] = 0;\n keys[k[a]] = 1;\n for (int i = a - 1; i >= 0; --i) {\n if (!keys[g[i]]) {\n if (posR[g[i]] == -1e9) needR[i] = 1e9 + 1;\n else needR[i] = posR[g[i]];\n }\n keys[k[i]] = 1;\n }\n\n for (int i = 0; i < maxn; ++i) keys[i] = 0;\n keys[k[a]] = 1;\n for (int i = a; i < n - 1; ++i) {\n if (!keys[g[i]]) {\n if (posL[g[i]] == 1e9) needL[i] = -1e9 - 1;\n else needL[i] = posL[g[i]];\n }\n keys[k[i + 1]] = 1;\n }\n\n SegTreeMax TreeMax(maxn);\n TreeMax.build(0, n - 1, 0, needR);\n SegTreeMin TreeMin(maxn);\n TreeMin.build(0, n - 1, 0, needL);\n\n vector L, R;\n int it;\n if (a < b) {\n R.push_back(b - 1);\n it = 1;\n } else {\n L.push_back(b);\n it = 0;\n }\n\n int cnt = 0;\n while (1) {\n cnt++;\n if (it) {\n int cur = TreeMin.get(a, (int)R.back(), 0, n - 1, 0);\n if (cur == -1e9 - 1)\n fail();\n if (cur == 1e9)\n break;\n else {\n if (!L.empty() && cur <= L.back()) fail();\n L.push_back(cur);\n }\n } else {\n int cur = TreeMax.get(L.back(), a - 1, 0, n - 1, 0);\n if (cur == 1e9 + 1)\n fail();\n if (cur == -1e9)\n break;\n else {\n if (!R.empty() && cur >= R.back()) fail();\n R.push_back(cur);\n }\n }\n it ^= 1;\n }\n\n ll ans = 0;\n for (int i : L) ans += (ll)abs(a - i);\n for (int i : R) ans += (ll)abs(a - i - 1);\n ans *= 2LL;\n if (b < a)\n ans -= (a - b);\n else\n ans -= (b - a);\n cout << ans;\n return 0;\n}\n\n/*\nn = 6 a = 4 b = 1\n6 4 1\n2 6 6 6 2\n1 5 6 4 3 2\n\nn = 6 a = 1 b = 2\n6 1 2\n3 1 3 4 5\n4 2 2 2 4 2\n\nn = 6 a = 2 b = 5\n6 2 5\n4 3 6 6 2\n6 4 5 4 2 3\n\n = 6 a = 2 b = 3\n6 2 3\n4 4 6 3 5\n5 4 1 4 6 6\n\nn = 4 a = 2 b = 1\n4 2 1\n3 4 3\n4 3 4 1\n\nn = 3 a = 1 b = 2\n3 1 2\n1 3\n2 2 2\n*/\n", "src_uid": "fbd994944cfa06e4921aac227d9eaf31"} {"source_code": "#include\nusing namespace std;\ninline int read()\n{\n\tint ret=0,f=1;\n\tchar ch=getchar();\n\twhile(ch>'9'||ch<'0')\n\t{\n\t\tif(ch=='-')\n\t\t\tf=-1;\n\t\tch=getchar();\n\t}\n\twhile(ch>='0'&&ch<='9')\n\t{\n\t\tret=(ret<<1)+(ret<<3)+ch-'0';\n\t\tch=getchar();\n\t}\n\treturn ret*f;\n}\nconst int inf=1e9+7;\nint l,r,p,v[105],pr[35],num,n,a[3000005],f[3000005],vis[3000005],ans;\ninline void primes()\n{\n\tfor(register int i=2;i<=p;i++)\n\t{\n\t\tif(!v[i])\n\t\t{\n\t\t\tv[i]=i;\n\t\t\tpr[++num]=i;\n\t\t}\n\t\tfor(register int j=1;j<=num;j++)\n\t\t{\n\t\t\tif(pr[j]>p/i||pr[j]>v[i])\n\t\t\t\tbreak;\n\t\t\tv[pr[j]*i]=pr[j];\n\t\t}\n\t}\n}\nvoid dfs(int pos,long long sum)\n{\n\tif(pos>num)\n\t\treturn;\n\tdfs(pos+1,sum);\n\twhile(1)\n\t{\n\t\tsum*=pr[pos];\n\t\tif(sum>r)\n\t\t\tbreak;\n\t\ta[++n]=sum;\n\t\tdfs(pos+1,sum);\n\t}\n}\nint main()\n{\n\tl=read();\n\tr=read();\n\tp=read();\n\tprimes();\n\tdfs(1,1);\n\ta[++n]=1;\n\tsort(a+1,a+n+1);\n\tf[1]=0;\n\tfor(register int i=2;i<=n;i++)\n\t\tf[i]=inf;\n\tfor(register int i=2;i<=p;i++)\n\t{\n\t\tint k=1;\n\t\tfor(register int j=1;j<=n;j++)\n\t\t{\n\t\t\twhile(k<=n&&a[j]*i>a[k])\n\t\t\t\tk++;\n\t\t\tif(k>r)\n\t\t\t\tbreak;\n\t\t\tif(a[j]*ip||a[k]\nusing namespace std;\nint x,y,s1,s2;\nint main(){\n cin>>x>>y;\n if(x<=5&&y<=5){\n \ts1=pow(y,x);\n \ts2=pow(x,y);\n if(s2>s1) cout<<\">\";\n else if(s2\";\n else if(x>y) cout<<\"<\";\n else if(x\";\n else cout<<\"=\";\n return 0;\n}", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"source_code": "#include\nusing namespace std;\ntemplate inline void read(T &x){\n\tx=0; register char c=getchar(); register bool f=0;\n\twhile(!isdigit(c))f^=c=='-',c=getchar();\n\twhile(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;\n}\nconst int N=2e5+10;\nstruct node{\n\tint x,y;\n\tinline node operator-(const node &rhs)const{\n\t\treturn {x-rhs.x,y-rhs.y};\n\t}\n\tinline long long operator*(const node &rhs)const{\n\t\treturn (long long)x*rhs.y-(long long)y*rhs.x;\n\t}\n\tinline bool operator<(const node &rhs)const{\n\t\tlong long tem=(*this)*rhs;\n\t\treturn tem==0?(x==rhs.x?y0;\n\t}\n\tinline bool operator==(const node &rhs)const{\n\t\treturn x==rhs.x&&y==rhs.y;\n\t}\n}a[N];\nint n,m;\nset multi;\nvector allX,allY;\ninline void quit(){puts(\"Ani\"),exit(0);}\nvector convex(int l,int r,int ban=-1){\n\tvector stk;\n\tauto top=[&](){return a[stk.back()];};\n\tauto nxt=[&](){return a[stk[stk.size()-2]];};\n\tfor(int i=l;i<=r;i++)if(i!=ban){\n\t\twhile(stk.size()>1&&(top()-nxt())*(a[i]-nxt())<=0)stk.pop_back();\n\t\tstk.push_back(i);\n\t}\n\treturn stk;\n}\nint main(){\n\tread(n);\n\tfor(int i=1;i<=n;i++){\n\t\tread(a[i].x),read(a[i].y);\n\t\tallX.push_back(a[i].x);\n\t\tallY.push_back(a[i].y);\n\t}\n\tauto makeSimple=[&](vector &vec){\n\t\tsort(vec.begin(),vec.end(),[](int a,int b){return a>b;});\n\t\tif(vec.size()&&(vec[0]&1))quit();\n\t\tif(vec.size()>1&&(vec[1]&1))quit();\n\t};\n\tmakeSimple(allX),makeSimple(allY);\n\t++n,multi.insert({0,0});\n\tstd::sort(a+1,a+n+1);\n\tfor(int i=1;i con=convex(1,n+1);\n\tfor(int i:con)if((a[i].x|a[i].y)&1)quit();\n\tfor(int i=1;i+1 cur=convex(con[i-1],con[i+1],con[i]);\n\t\tfor(int i:cur)if((a[i].x|a[i].y)&1)quit();\n\t}\n\tputs(\"Borna\");\n}", "src_uid": "a7b35fee982e41c075c87135a62c3a0d"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nconst int MAX_N = int(1e5) + 10;\nint N, n;\nvector a[2];\nint ans = 0;\n\ntypedef long long int64;\n\nint mx;\nint64 cnt;\n\nvoid updateAnswer(int nmx, int64 ncnt) {\n\tif (nmx > mx) {\n\t\tmx = nmx;\n\t\tcnt = ncnt;\n\t} else if (nmx == mx) {\n\t\tcnt += ncnt;\n\t}\n}\n\nvoid rev(vector&a) {\n\tfor (int i = 0; i < a.size(); ++i) {\n\t\ta[i] = N - a[i];\n\t}\n\treverse(a.begin(), a.end());\n}\n\nvoid solve(vector a0, vector a1) {\n\t//1 a0 2 a1\n\t//fix c in a0\n\t//a,b in a1\n\t//maximize 2n+|a-b|-|a-c|-|b-c|\n\t//a > v;\n\tfor (int i = 0; i < a0.size(); ++i) {\n\t\tv.push_back(make_pair(a0[i], 0));\n\t}\n\tfor (int i = 0; i < a1.size(); ++i) {\n\t\tv.push_back(make_pair(a1[i], 1));\n\t}\n\tsort(v.begin(), v.end());\n\tint L = 0;\n\n\tfor (int i = 0; i < v.size(); ++i) {\n\t\tif (v[i].second == 0) {\n\t\t\tint R = a1.size() - L;\n\t\t\tif (L > 0 && R > 0)\n\t\t\t\tupdateAnswer(2 * N, 1LL * L * R);\n\t\t} else {\n\t\t\t++L;\n\t\t}\n\t}\n\n\tint A = 0;\n\tint B = -1, cntB = 0;\n\n\tfor (int i = 0; i < v.size(); ++i) {\n\t\tif (v[i].second == 0) {\n\t\t\tint C = v[i].first;\n\t\t\tif (cntB + A >= 2) {\n\t\t\t\tint what = 2 * N + B * 2 - C * 2;\n\t\t\t\tint64 total = 1LL * cntB * (cntB - 1) / 2 + 1LL * cntB * A;\n\t\t\t\tupdateAnswer(what, total);\n\t\t\t}\n\t\t} else {\n\t\t\tint me = v[i].first;\n\t\t\tif (me > B) {\n\t\t\t\tA += cntB;\n\t\t\t\tB = me, cntB = 1;\n\t\t\t} else {\n\t\t\t\tcntB++;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (int i = 0; i < v.size(); ++i) {\n\t\tv[i].first = N - v[i].first;\n\t}\n\treverse(v.begin(), v.end());\n\tA = 0;\n\tB = -1, cntB = 0;\n\n\tfor (int i = 0; i < v.size(); ++i) {\n\t\tif (v[i].second == 0) {\n\t\t\tint C = v[i].first;\n\t\t\tif (cntB + A >= 2) {\n\t\t\t\tint what = 2 * N + B * 2 - C * 2;\n\t\t\t\tint64 total = 1LL * cntB * (cntB - 1) / 2 + 1LL * cntB * A;\n\t\t\t\tupdateAnswer(what, total);\n\t\t\t}\n\t\t} else {\n\t\t\tint me = v[i].first;\n\t\t\tif (me > B) {\n\t\t\t\tA += cntB;\n\t\t\t\tB = me, cntB = 1;\n\t\t\t} else {\n\t\t\t\tcntB++;\n\t\t\t}\n\t\t}\n\t}\n}\n\nint main() {\n\tcin >> N;\n\tcin >> n;\n\tfor (int i = 0; i < n; ++i) {\n\t\tint s, f;\n\t\tcin >> s >> f;\n\t\ta[s].push_back(f);\n\t}\n\tmx = -1;\n\tfor (int i = 0; i < 2; ++i) {\n\t\tsort(a[i].begin(), a[i].end());\n\t\tif (a[i].size() >= 3) {\n\t\t\tvector&v = a[i];\n\t\t\tint L = count(v.begin(), v.end(), v[0]);\n\t\t\tint R = count(v.begin(), v.end(), v.back());\n\t\t\tint M = v.size() - L - R;\n\t\t\tif (v[0] == v.back()) {\n\t\t\t\tint tot = v.size();\n\t\t\t\tupdateAnswer(0, 1LL * tot * (tot - 1) * (tot - 2) / 6);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint64 cnt = 1LL * L * M * R;\n\t\t\tcnt += 1LL * L * (L - 1) / 2 * R;\n\t\t\tcnt += 1LL * L * R * (R - 1) / 2;\n\t\t\tupdateAnswer(v.back() - v[0], cnt);\n\t\t}\n\t}\n\tsolve(a[0], a[1]);\n\tsolve(a[1], a[0]);\n\tcout << cnt << endl;\n}\n", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#define ll long long\nusing namespace std;\nconst int mod = 1e9 + 7;\nint n , m;\nll f[100][100][2] , C[100][100];\n\nvoid init()\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) C[i][j] -= mod;\n\t\t}\n\t}\n}\nint main()\n{\n\tscanf(\"%d%d\",&n,&m);\n\tinit();\n\tf[1][0][0] = f[0][0][1] = 1;\n\t\n\tfor( int i = 2 ; i <= n ; ++i )\n\t\tfor( int j = 1 ; j <= (i / 2) ; ++j )\n\t\t\t{\n\t\t\t\tfor( int son1 = 0 ,son2 = i - 1 ; son1 <= son2 ; son1 ++ , son2 -- )\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tll tot;\n\t\t\t\t\tif( son1 != son2 ) tot = C[i - 1][son1];\n\t\t\t\t\telse tot = C[i - 2][son1 - 1];\n\t\t\t\t\t\n\t\t\t\t\tif( son1 ) tot = tot * son1 * son2 % mod;\n\t\t\t\t\telse tot = tot * son2 % mod;\n\t\t\t\t\t\n\t\t\t\t\tfor( int p = 0 ; p <= j ; ++p )\n\t\t\t\t\t{\n\t\t\t\t\t\tint p2 = j - p ;\n\t\t\t\t\t\tf[i][j][0] += f[son1][p][1] * f[son2][p2][1] % mod * tot % mod;\n\t\t\t\t\t\tf[i][j][0] %= mod;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfor( int p = 0 ; p <= j - 1 ; ++p )\n\t\t\t\t\t{\n\t\t\t\t\t\tint p2 = j - p - 1;\n\t\t\t\t\t\tf[i][j][1] += (f[son1][p][1] * f[son2][p2][0] % mod\n\t\t\t\t\t\t\t\t\t+ f[son1][p][0] * f[son2][p2][0] % mod\n\t\t\t\t\t\t\t\t\t+ f[son1][p][0] * f[son2][p2][1] % mod) % mod\n\t\t\t\t\t\t\t\t\t* tot % mod;\n\t\t\t\t\t\tf[i][j][1] %= mod;\n\t\t\t\t\t}\n\t\t\t\t}\t\n\t\t\t}\n\t\t\t\n\tprintf(\"%d\\n\",( f[n][m][0] + f[n][m][1] ) % mod );\n\tfclose(stdin);\n\tfclose(stdout);\n\treturn 0;\n}\n//kgqnfbppoohntyeecpglenqtvdikctpitbapjsnwxakunacptkaxpbpyjahmkmfmeungytilxnvujhkwvaojsaytjrupqaupp", "src_uid": "f98b740183281943eafd90328854746b"} {"source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\n\nint main() {\n int a, b;\n cin >> a >> b;\n \n int c = a - b;\n if(c < 0) {\n std::cout << 0 << std::endl;\n } else if (c == 0) {\n std::cout << \"infinity\" << std::endl;\n } else {\n int ans = 0;\n for (long long f = 1; f * f <= c; f ++){\n if (c % f == 0) {\n ans += (f > b);\n if (f * f != c)\n ans += (c / f > b);\n }\n } \n std::cout << ans << std::endl;\n }\n\n return 0;\n\n}\n\n", "src_uid": "6e0715f9239787e085b294139abb2475"} {"source_code": "#include \n#include \n#include \n\nint main() {\n int t;\n std::cin >> t;\n while (t--) {\n int x;\n std::cin >> x;\n int keys[3];\n std::cin >> keys[0] >> keys[1] >> keys[2];\n int count = 1;\n int inx = --x;\n while (keys[inx] != 0) {\n count++;\n inx = keys[inx] - 1;\n }\n if (count == 3) std::cout << \"YES\" << std::endl;\n else std::cout << \"NO\" << std::endl;\n }\n}", "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n int ss;\n scanf(\"%d\",&ss);\n int toplam=ss;\n for(int i=1;i> l >> r >> x >> y >> k;\n\tfor(int i = x ; i <= y ; ++i){\n\t\tlong long tmp = 1LL * i * k;\n\t\tif(tmp >= l && tmp <= r){\n\t\t\tprintf(\"YES\\n\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tprintf(\"NO\\n\");\n}", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"} {"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\n\n\nint main()\n{\n char t;\n string cards=\"6789TJQKA\";\n string s1,s2;\n bool ft=false,st=false;\n cin>>t;\n cin>>s1>>s2;\n if(s1[1]==t)ft=true;\n if(s2[1]==t)st=true;\n if((ft&&!st)||(ft==st&&s1[1]==s2[1]&&cards.find(s1[0])>cards.find(s2[0])))\n cout<<\"YES\"<\nusing namespace std;\n#define ll long long\n#define ull unsigned long long\n#define ld long double\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\nll r,m,c;\nll n;\ncin>>n>>m;\nvector a(n);\nmap mp;\nll mxx = 0;\nfor (ll i = 0;i < n;i++)\n {\n cin>>a[i];\n mp[a[i]]++;\n mxx = max(mxx,mp[a[i]]);\n }\nll g = (mxx/m);\nif (mxx%m) g++;\nmxx = g * m;\nll ans = 0;\nfor (ll i = 1;i<=100;i++)\n if (mp[i]) ans+=abs(mp[i]-mxx);\n cout<\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\ntypedef long long ll;\n\nusing namespace std;\ninline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }\ninline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }\n\n#define rep(i,a,b) for(i=a; i<=b; i++)\n#define brep(i,b,a) for(i=b; i>=a; i--)\n#define sd second\n#define ft first\n#define mp make_pair\nstring s;\nint l;\n\nvoid tr(int i)\n{\n\tint j;\n\n\tstring t = s.substr(0, i);\n\n\trep(j, 0, i - 1) s[j] = t[i - 1-j];\n}\n\nint main()\n{\n\tint const sz =1e3 + 10;\n\tll i, j,n,a[sz+1],r,x,y,k,t,h,ans=1e18,l;\n\t\n\tcin >> l;\n\n\t\n\n\tcin >> s;\n\n\trep(i, 2, l)\n\t\tif (l%i == 0) tr(i);\n\t\n\n\tcout << s;\n\n\treturn 0;\n}", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"source_code": "#include\nusing namespace std;\ntypedef long long unsigned ll;\nll mod = (ll)1e9 + 7;\n \nll exp(ll a,ll b)\n{\n\tll ans = 1;\n\twhile(b)\n\t{\n\t\tif(b%2) ans=(ans*a)%mod;\n\t\ta=(a*a)%mod;\n\t\tb/=2;\n\t}\n\treturn ans%mod;\n}\nint main()\n{\n\tll a,b,n,x;\n\tcin>>a>>b>>n>>x;\n\tif(a==1) cout<<(x+(n%mod)*b)%mod<<\"\\n\";\n\telse\n\t{\n\t\tll an = exp(a,n);\n ll ain = exp(a - 1,mod-2);\n //cout<<(ain*2)%mode<<\"\\n\";\n\t\tll ans = ((an*x)%mod + ((((an-1)*ain)%mod)*b)%mod) % mod;\n\t\tcout<\n#include\nusing namespace std;\nint main () {\n\tlong long int a[3],k;\n\tcin >> a[0] >>a[1] >> a[2] >> k;\n\twhile(a[0]+a[1]+a[2]-3>k)\n\t{\n\t\tsort(a,a+3);\n\t\ta[2]--;\n\t}\n\tcout << a[0]*a[1]*a[2] << endl;\n\treturn 0;\n}\n", "src_uid": "8787c5d46d7247d93d806264a8957639"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n#define ll long long\n\nconst int maxn = 1 << 17;\nconst int inf = 2e8 + 10;\nconst int mod = 1000000007;\n\nll n;\nint k;\nstring s, a, b;\n\nint calc(string s, string p, int x = -1) {\n\tstring a = p + \"#\" + s;\n\tif (x != -1) x += p.length() + 1;\n\tint n = a.length();\n\tvector z(n);\n\n\tint ans = 0;\n\tint l = 0, r = -1;\n\tfor (int i = 1; i < n; i++) {\n\t\tif (i <= r) z[i] = min(z[i - l], r - i + 1);\n\t\twhile (i + z[i] < n && a[z[i]] == a[i + z[i]]) z[i]++;\n\t\tif (i + z[i] - 1 > r)\n\t\t\tl = i, r = i + z[i] - 1;\n\n\t\tif ((x == -1 || i < x && i + z[i] - 1 >= x) && z[i] == p.size()) ans++; \n\t}\n\treturn ans;\n}\n\nint main() {\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\t\n\tcin >> n >> k;\n\tfor (int i = 0; i < k; i++) {\n\t\tcin >> s;\n\t\ta = \"a\"; b = \"b\";\n\t\tint j = 1;\n\t\twhile (a.length() < s.length()) {\n\t\t\tstring c = b + a;\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t\tj++;\n\t\t}\n\t\tif (n < j) {\n\t\t\tcout << 0 << endl;\n\t\t\tcontinue;\n\t\t}\n\t\tvector ans(n + 1);\n\t\tans[j] = calc(a, s);\n\t\tif (j + 1 <= n) ans[j + 1] = calc(b, s);\n\t\tint cross[2], cur = 0;\n\t\tcross[0] = calc(b + a, s, b.length());\n\t\tcross[1] = calc(b + a + b, s, b.length() + a.length());\n\t\tj += 2;\n\t\twhile (j <= n) {\n\t\t\tans[j] = (ans[j - 1] + ans[j - 2] + cross[cur]) % mod;\n\t\t\tcur ^= 1;\n\t\t\tj++;\n\t\t}\n\t\tcout << ans[n] << endl;\n\t}\n\n\treturn 0;\n}", "src_uid": "8983915e904ba763d893d56e94d9f7f0"} {"source_code": "#include\nusing namespace std;\nint a, b, c, x, y, z;\nint main(){\n ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n cin >> x >> y >> z >> a >> b >> c;\n ((a>=x)&&((a+b-x>=y)&&(a+b+c-x-y>=z)))?printf(\"YES\"):printf(\"NO\");\n}\n", "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"source_code": "#include \n#define SZ(X) ((int)(X).size())\n#define ALL(X) (X).begin(), (X).end()\n#define REP(I, N) for (int I = 0; I < (N); ++I)\n#define REPP(I, A, B) for (int I = (A); I < (B); ++I)\n#define RI(X) scanf(\"%d\", &(X))\n#define RII(X, Y) scanf(\"%d%d\", &(X), &(Y))\n#define RIII(X, Y, Z) scanf(\"%d%d%d\", &(X), &(Y), &(Z))\n#define DRI(X) int (X); scanf(\"%d\", &X)\n#define DRII(X, Y) int X, Y; scanf(\"%d%d\", &X, &Y)\n#define DRIII(X, Y, Z) int X, Y, Z; scanf(\"%d%d%d\", &X, &Y, &Z)\n#define RS(X) scanf(\"%s\", (X))\n#define CASET int ___T, case_n = 1; scanf(\"%d \", &___T); while (___T-- > 0)\n#define MP make_pair\n#define PB push_back\n#define MS0(X) memset((X), 0, sizeof((X)))\n#define MS1(X) memset((X), -1, sizeof((X)))\n#define LEN(X) strlen(X)\n#define F first\n#define S second\n#define RF(x) freopen(x,\"r\",stdin)\n#define WF(x) freopen(x,\"w\",stdout)\ntypedef long long LL;\nusing namespace std;\ntypedef pair PLL;\ntypedef pair PII;\nconst LL MOD = (LL)1e9+7;\nconst int SIZE = 2e5+5;\nconst LL INF = 1LL<<60;\nconst double eps = 1e-4;\nconst double PI=3.1415926535897932;\n\n\nint main(){\n\tCASET{\n\t\tLL n;\n\t\tscanf(\"%lld\",&n);\n\t\tvector fqs, ls;\n\t\tLL s = 1, e = n;\n\t\tfor(int i=0;1LL<1)s = abs(fqs[i-1]-fqs[i-2])+1;\n\t\t\t\telse s = 1;\n\t\t\t\te = abs(fqs[i]-fqs[i-1]);\n\t\t\t\tpv = fqs[i];\n\t\t\t\twasright = fqs[i]>fqs[i-1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(!res){\n\t\t\tprintf(\"= %lld\\n\",n);\n\t\t\tfflush(stdout);\n\t\t\tcontinue;\n\t\t}\n\t\twhile(s\n\nusing namespace std;\nlong long binpow(long long a, long long b)\n{\n long long ans = 1;\n while(b > 0){\n if(b & 1)\n ans = ans * a;\n a = a * a;\n b >>= 1;\n }\n return ans;\n}\nint main()\n{\n int n;\n cin >> n;\n cout << 2 * 4 * 3 * binpow(4, n - 3) + 3 * 3 * 4 * binpow(4, n - 4) * (n - 3) << '\\n';\n return 0;\n}", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"} {"source_code": "#include\n#include\nusing namespace std;\nvectorfee,all;\nint n,largest,tme,range,temp,now,smallest=1000;\nint main()\n{\n cin>>n;\n for (int i=0;i>temp;\n if(temp>largest)\n largest=temp;\n \n if (temp>tme;\n \n all.resize(largest+1);\n for (int i=0;i=all.size()-tme)\n break;\n now=0;\n for (int k=i;krange)\n range=now;\n }\n else\n {\n for (int i=0;i\n#else\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#endif\n\nusing namespace std;\n\n#ifndef CPPELEVEN\n#ifdef USETR1\n#include \n#include \nusing namespace tr1;\n#endif\n#else\n#include \n#include \n#endif\n\n#ifdef USEPB_DS\n#include \n#include \n#include \nusing namespace __gnu_pbds;\n// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag\ntypedef __gnu_pbds::priority_queue, pairing_heap_tag> pq_type;\n// splay_tree_tag, ov_tree_tag\ntypedef tree , rb_tree_tag, tree_order_statistics_node_update> tree_type;\n#endif\n\n#define mpr make_pair\ntypedef unsigned int ui;\ntypedef unsigned long long ull;\ntypedef long long ll;\ntypedef pair pii;\ntypedef pair pll;\ntypedef pair pdd;\ntypedef vector vi;\ntypedef vector vll;\ntypedef vector vd;\ntypedef vector vs;\ntypedef map mpsi;\ntypedef map mpdi;\ntypedef map mpii;\n\nconst double pi = acos(0.0) * 2.0;\nconst long double eps = 1e-10;\nconst int step[8][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 1 }, {\n\t\t1, 1 }, { 1, -1 }, { -1, -1 } };\n\ntemplate inline T abs1(T a) {\n\treturn a < 0 ? -a : a;\n}\n\n#ifndef CPPELEVEN\ntemplate inline T max1(T a, T b) { return b < a ? a : b; }\ntemplate inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }\ntemplate inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }\ntemplate inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }\ntemplate inline T min1(T a, T b) { return a < b ? a : b; }\ntemplate inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }\ntemplate inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }\ntemplate inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }\n#else\ntemplate\nt min1(t a, t1 b) {\n\treturn a < b ? a : b;\n}\ntemplate\nt min1(t a, arg ... arr) {\n\treturn min1(a, min1(arr...));\n}\ntemplate\nt max1(t a, t1 b) {\n\treturn a > b ? a : b;\n}\ntemplate\nt max1(t a, arg ... arr) {\n\treturn max1(a, max1(arr...));\n}\n#endif\n\ninline int jud(double a, double b) {\n\tif (abs(a) < eps && abs(b) < eps)\n\t\treturn 0;\n\telse if (abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;\n\tif (a < b) return -1;\n\treturn 1;\n}\ntemplate inline int jud(t a, t b) {\n\tif (a < b) return -1;\n\tif (a == b) return 0;\n\treturn 1;\n}\n\n// f_lb == 1代表返回相同的一串的左边界,f_small == 1代表返回如果没有寻找的值返回小的数\ntemplate\ninline int RangeFind(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {\n\tif (na == 0) return 0;\n\tint be = 0, en = na - 1;\n\tif (*a <= *(a + na - 1)) {\n\t\tif (f_lb == 0)\n\t\t\twhile (be < en) {\n\t\t\t\tint mid = (be + en + 1) / 2;\n\t\t\t\tif (jud(*(a + mid), val) != 1)\n\t\t\t\t\tbe = mid;\n\t\t\t\telse\n\t\t\t\t\ten = mid - 1;\n\t\t\t}\n\t\telse\n\t\t\twhile (be < en) {\n\t\t\t\tint mid = (be + en) / 2;\n\t\t\t\tif (jud(*(a + mid), val) != -1)\n\t\t\t\t\ten = mid;\n\t\t\t\telse\n\t\t\t\t\tbe = mid + 1;\n\t\t\t}\n\t\tif (f_small && jud(*(a + be), val) == 1) be--;\n\t\tif (!f_small && jud(*(a + be), val) == -1) be++;\n\t} else {\n\t\tif (f_lb)\n\t\t\twhile (be < en) {\n\t\t\t\tint mid = (be + en + 1) / 2;\n\t\t\t\tif (jud(*(a + mid), val) != -1)\n\t\t\t\t\tbe = mid;\n\t\t\t\telse\n\t\t\t\t\ten = mid - 1;\n\t\t\t}\n\t\telse\n\t\t\twhile (be < en) {\n\t\t\t\tint mid = (be + en) / 2;\n\t\t\t\tif (jud(*(a + mid), val) != 1)\n\t\t\t\t\ten = mid;\n\t\t\t\telse\n\t\t\t\t\tbe = mid + 1;\n\t\t\t}\n\t\tif (!f_small && jud(*(a + be), val) == -1) be--;\n\t\tif (f_small && jud(*(a + be), val) == 1) be++;\n\t}\n\treturn be;\n}\n\ntemplate inline T lowb(T num) {\n\treturn num & (-num);\n}\n#ifdef GPP\ninline int bitnum(ui nValue) {\n\treturn __builtin_popcount(nValue);\n}\ninline int bitnum(int nValue) {\n\treturn __builtin_popcount(nValue);\n}\ninline int bitnum(ull nValue) {\n\treturn __builtin_popcountll(nValue);\n}\ninline int bitnum(ll nValue) {\n\treturn __builtin_popcountll(nValue);\n}\ninline int bitmaxl(ui a) {\n\tif (a == 0) return 0;\n\treturn 32 - __builtin_clz(a);\n}\ninline int bitmaxl(int a) {\n\tif (a == 0) return 0;\n\treturn 32 - __builtin_clz(a);\n}\ninline int bitmaxl(ull a) {\n\tif (a == 0) return 0;\n\treturn 64 - __builtin_clzll(a);\n}\ninline int bitmaxl(ll a) {\n\tif (a == 0) return 0;\n\treturn 64 - __builtin_clzll(a);\n}\n#else\n#endif\n\nlong long pow(long long n, long long m, long long mod = 0) {\n\tif (m < 0) return 0;\n\tlong long ans = 1;\n\tlong long k = n;\n\twhile (m) {\n\t\tif (m & 1) {\n\t\t\tans *= k;\n\t\t\tif (mod) ans %= mod;\n\t\t}\n\t\tk *= k;\n\t\tif (mod) k %= mod;\n\t\tm >>= 1;\n\t}\n\treturn ans;\n}\n\n#define MOD 1000000007\ntemplate\ninline void add(t1 &a, t2 b, int mod = -1) {\n\tif (mod == -1) mod = MOD;\n\ta += b;\n\twhile (a >= mod)\n\t\ta -= mod;\n\twhile (a < 0)\n\t\ta += mod;\n}\ntemplate\nvoid output1(t arr) {\n\tfor (int i = 0; i < (int) arr.size(); i++)\n\t\tcerr << arr[i] << ' ';\n\tcerr << endl;\n}\ntemplate\nvoid output2(t arr) {\n\tfor (int i = 0; i < (int) arr.size(); i++)\n\t\toutput1(arr[i]);\n}\n\n//....................密..........封..........线..........下..........禁..........止..........hack...............................................\n\nconst int maxn = 510;\nll dp_con[maxn], sum_con[maxn], dp[maxn][maxn], sum[maxn][maxn];\nint c[maxn][maxn];\nint n, m, mod;\n\ninline ll Arth(ll n) {\n\treturn n * (n + 1) / 2 % mod;\n}\n\nint main() {\n\n//............................不要再忘了检查maxn大小了!!!!BSBandme你个SB!!!!...................................................\n\n\tios_base::sync_with_stdio(0);\n#ifdef DEBUG //......................................................................................................\n\tfreopen(\"input.txt\", \"r\", stdin);\n#endif //...........................................................................................................\n\n\tscanf(\"%d%d%d\", &n, &m, &mod);\n\tfor (int i = 0; i < maxn; i++) {\n\t\tc[i][0] = 1;\n\t\tfor (int j = 1; j <= i; j++) {\n\t\t\tc[i][j] = c[i - 1][j] + c[i - 1][j - 1];\n\t\t\tc[i][j] %= mod;\n\t\t}\n\t}\n\n\tdp_con[1] = 2;\n\tdp_con[0] = 1;\n\tsum_con[1] = sum_con[0] = 0;\n\tfor (int i = 2; i <= m; i++) {\n\t\tdp_con[i] = 0;\n\t\tsum_con[i] = 0;\n\t\tfor (int j = 0; j < i; j++) {\n\t\t\tll rcon = dp_con[j] * dp_con[i - j - 1] % mod * c[i - 1][j] % mod;\n\t\t\tdp_con[i] += rcon * (i + 1) % mod;\n\t\t\tsum_con[i] += (dp_con[j] * sum_con[i - j - 1] + sum_con[j] * dp_con[i - j - 1]) % mod * c[i - 1][j] % mod * (i + 1) % mod;\n\t\t\tsum_con[i] += rcon * (Arth(j) + Arth(i - 1 - j)) % mod;\n\t\t}\n\t\tdp_con[i] %= mod;\n\t\tsum_con[i] %= mod;\n\t}\n\n\tdp[0][0] = 1;\n\tfor (int i = 0; i < m; i++) for (int j = 0; j <= i; j++) if (dp[i][j]) {\n\t\tfor (int k = 1; k + i <= m; k++) {\n\t\t\tdp[i + k][j + 1] += dp[i][j] * dp_con[k] % mod * c[i + k][k];\n\t\t\tdp[i + k][j + 1] %= mod;\n\t\t\tsum[i + k][j + 1] += (dp[i][j] * sum_con[k] + sum[i][j] * dp_con[k]) % mod * c[i + k][k];\n\t\t\tsum[i + k][j + 1] %= mod;\n\t\t}\n\t}\n\n\tll ans = 0;\n\tfor (int j = 1; j <= m; j++) {\n\t\tif (n - (m - 1 + j) < 0) break;\n\t\tans += sum[m][j] * c[n - (m - 1 + j) + j][j] % mod;\n\t\tans %= mod;\n\t}\n\n\tprintf(\"%I64d\\n\", ans);\n\n\n\treturn 0;\n}\n", "src_uid": "9812de5f2d272511a63ead8765b23190"} {"source_code": "#include\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\n#define mp make_pair\n#define PI pair\n#define poly vector\n#define mem(a) memset((a),0,sizeof(a))\n#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)\n#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)\n#define pb push_back\n#define fi first\n#define se second\n#define SZ(x) ((int)(x.size()))\ninline char gc(){\n static char buf[100000],*p1=buf,*p2=buf;\n return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;\n}\n#define gc getchar\ninline ll read(){\n\tll x = 0; char ch = gc(); bool positive = 1;\n\tfor (; !isdigit(ch); ch = gc())\tif (ch == '-')\tpositive = 0;\n\tfor (; isdigit(ch); ch = gc())\tx = x * 10 + ch - '0';\n\treturn positive ? x : -x;\n}\ninline void write(ll a){\n if(a<0){\n \ta=-a; putchar('-');\n\t}\n if(a>=10)write(a/10);\n putchar('0'+a%10);\n}\ninline void writeln(ll a){write(a); puts(\"\");}\ninline void wri(ll a){write(a); putchar(' ');}\ninline ull rnd(){\n\treturn ((ull)rand()<<30^rand())<<4|rand()%4;\n}\nconst int N=105,mod=998244353;\nll f[N],dp[N],DP[N<<1],val[N][N];\npoly v[N],way[N][N],d[N];\nPI a[N];\nint n,rt,e[N][N],fir[N][N],lst[N][N],cover[N][N];\nvoid dfs_way(int p,int fa){\n\tway[rt][p]=way[rt][fa]; way[rt][p].pb(p);\n\tfor(auto i:v[p])if(i!=fa)dfs_way(i,p);\n}\nll mul(PI a,PI b){\n\treturn (ll)a.fi*b.se-(ll)a.se*b.fi;\n}\nPI operator -(PI a,PI b){\n\treturn mp(a.fi-b.fi,a.se-b.se);\n}\nbool cmp(int x,int y){\n\treturn a[x].se==a[y].se?a[x].fi0:X al;\n\tsort(d[p].begin(),d[p].end(),cmp);\n\tint m=d[p].size();\n\tfor(auto i:d[p])for(auto j:d[p])if(way[i][j].size()>=3&&mul(a[j]-a[i],a[p]-a[i])>=0){\n\t\tal.pb(mp(i,j));\n\t\tint sz=way[i][j].size();\n\t\tfir[i][j]=e[way[i][j][0]][way[i][j][1]];\n\t\tlst[i][j]=e[way[i][j].back()][way[i][j][sz-2]];\n\t\tcover[i][j]=0; val[i][j]=1;\n\t\tFor(o,0,sz-1){\n\t\t\tint x=o?way[i][j][o-1]:-1,y=o<=sz-2?way[i][j][o+1]:-1,dq=way[i][j][o];\n\t\t\tfor(auto son:v[dq])if(son!=x&&son!=y){\n\t\t\t\tif(x<0){\n\t\t\t\t\tif(mul(a[y]-a[dq],a[son]-a[dq])>0)continue;\n\t\t\t\t}else if(y<0){\n\t\t\t\t\tif(mul(a[son]-a[x],a[dq]-a[x])<0)continue;\n\t\t\t\t}else{\n\t\t\t\t\tint A=mul(a[y]-a[dq],a[son]-a[dq])>0,B=mul(a[son]-a[x],a[dq]-a[x])<0;\n\t\t\t\t\tif(mul(a[dq]-a[x],a[y]-a[x])>0){\n\t\t\t\t\t\tif(A&&B)continue;\n\t\t\t\t\t\t//if(A||B)cout<\n#include \n#include \nusing namespace std;\nint n, a, x, b, y;\n\nint main()\n{\n scanf(\"%d %d %d %d %d\", &n, &a, &x, &b, &y);\n while(a != x && b != y)\n {\n if(a == b)\n {\n printf(\"YES\");\n return 0;\n }\n a++;\n if(a == n + 1)\n {\n a = 1;\n }\n b--;\n if(b == 0)\n {\n b = n;\n }\n }\n if(a == b)\n {\n printf(\"YES\");\n return 0;\n }\n printf(\"NO\");\n}", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"source_code": "#include \n#include \n#define ll long long\nusing namespace std;\nconst ll md = (1e9) + 7;\nvector v;ll to,n,k,ar[9]={1,2,9,64,625,7776,117649,2097152};\nll pw(ll b,ll e)\n{\n\tll t=1;\n\twhile (e)\n\t{\n\t\tif (e&1) {t*=b;t%=md;}\n\t\tb*=b;b%=md;e>>=1;\n\t}\n\treturn t;\n}\nvoid rs(ll d)\n{\n\tif (d)\n\t{\n\t\tfor (int i=0;i vv;\n\t\tbool x = 1;\n\t\tfor (int i=0;i>n>>k;\n\tcout<<(ar[k-1] * pw(n-k,n-k))%md<<\"\\n\";\n\treturn 0;\n}\n", "src_uid": "cc838bc14408f14f984a349fea9e9694"} {"source_code": "/** Micro Mezzo Macro Flation -- Overheated Economy ., Last Update: Feb. 12th 2013 **/ //{\n\n/** Header .. **/ //{\n#define LOCAL\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\nusing namespace std;\n\n#define REP(i, n) for (int i=0;i=int(a);--i)\n#define REP_1(i, n) for (int i=1;i<=int(n);++i)\n#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)\n#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)\n#define REP_C(i, n) for (int n____=int(n),i=0;i=a____;--i)\n#define REP_N(i, n) for (i=0;i=int(a);--i)\n#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)\n#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)\n#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)\n#define REP_1_N(i, n) for (i=1;i<=int(n);++i)\n#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)\n#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)\n#define REP_C_N(i, n) for (int n____=(i=0,int(n));i=a____;--i)\n#define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)\n#define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)\n#define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)\n\n#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)\n#define REP_S(i, str) for (char*i=str;*i;++i)\n#define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])\n#define REP_G(i, u) REP_L(i,hd[u],suc)\n#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )\n#define REP_2(i, j, n, m) REP(i, n) REP(j, m)\n#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)\n#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)\n#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)\n#define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)\n#define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)\n\n#define ALL(A) A.begin(), A.end()\n#define LLA(A) A.rbegin(), A.rend()\n#define CPY(A, B) memcpy(A, B, sizeof(A))\n#define INS(A, P, B) A.insert(A.begin() + P, B)\n#define ERS(A, P) A.erase(A.begin() + P)\n#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())\n#define CTN(T, x) (T.find(x) != T.end())\n#define SZ(A) int(A.size())\n#define PB push_back\n#define MP(A, B) make_pair(A, B)\n#define PTT pair\n#define fi first\n#define se second\n\n#define Rush for(int ____T=RD(); ____T--;)\n\n#define Display(A, n, m) { \\\n\tREP(i, n){\t\t \\\n REP(j, m) cout << A[i][j] << \" \"; \\\n cout << endl;\t\t\t\t \\\n\t}\t\t\t\t\t\t \\\n}\n\n#define Display_1(A, n, m) {\t\t\t\t \\\n\tREP_1(i, n){\t\t \\\n REP_1(j, m) cout << A[i][j] << \" \"; \\\n\t\tcout << endl;\t\t \t\t\\\n\t}\t\t\t\t\t\t \\\n}\n\n#pragma comment(linker, \"/STACK:36777216\")\n//#pragma GCC optimize (\"O2\")\n#define Ruby system(\"ruby main.rb\")\n#define Haskell system(\"runghc main.hs\")\n#define Python system(\"python main.py\")\n#define Pascal system(\"fpc main.pas\")\n\ntypedef long long LL;\n//typedef long double DB;\ntypedef double DB;\ntypedef unsigned UINT;\ntypedef unsigned long long ULL;\n\ntypedef vector VI;\ntypedef vector VC;\ntypedef vector VS;\ntypedef vector VL;\ntypedef vector VF;\ntypedef set SI;\ntypedef set SS;\ntypedef map MII;\ntypedef map MSI;\ntypedef pair PII;\ntypedef pair PLL;\ntypedef vector VII;\ntypedef vector VVI;\ntypedef vector VVII;\n\ntemplate inline T& RD(T &);\ntemplate inline void OT(const T &);\ninline LL RD(){LL x; return RD(x);}\ninline DB& RF(DB &);\ninline DB RF(){DB x; return RF(x);}\ninline char* RS(char *s);\ninline char& RC(char &c);\ninline char RC();\ninline char& RC(char &c){scanf(\" %c\", &c); return c;}\ninline char RC(){char c; return RC(c);}\n//inline char& RC(char &c){c = getchar(); return c;}\n//inline char RC(){return getchar();}\n\ntemplate inline T& RDD(T &x){\n char c; for (c = getchar(); c < '-'; c = getchar());\n if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}\n else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}\n return x;\n}\n\ninline LL RDD(){LL x; return RDD(x);}\n\ntemplate inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}\ntemplate inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}\ntemplate inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}\ntemplate inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}\ntemplate inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}\ntemplate inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}\ntemplate inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}\ntemplate inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}\ntemplate inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}\ntemplate inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}\ntemplate inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}\ntemplate inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}\ninline char& RC(char &a, char &b){RC(a), RC(b); return a;}\ninline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}\ninline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}\ninline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}\ninline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}\ninline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}\ninline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}\ninline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}\ninline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}\ninline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}\ninline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}\ninline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}\ninline void RS(char *s1, char *s2){RS(s1), RS(s2);}\ninline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}\ntemplateinline void RDD(const T0&a, const T1&b){RDD(a),RDD(b);}\ntemplateinline void RDD(const T0&a, const T1&b, const T2&c){RDD(a),RDD(b),RDD(c);}\n\ntemplate inline void RST(T &A){memset(A, 0, sizeof(A));}\ntemplate inline void FLC(T &A, int x){memset(A, x, sizeof(A));}\ntemplate inline void CLR(T &A){A.clear();}\n\ntemplate inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}\ntemplate inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}\ntemplate inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}\ntemplate inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}\ntemplate inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}\ntemplate inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}\ntemplate inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}\ntemplate inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}\ntemplate inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}\ntemplate inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}\ntemplate inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}\ntemplate inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}\ntemplate inline void CLR(priority_queue, less > &Q){while (!Q.empty()) Q.pop();}\ntemplate inline void CLR(priority_queue, greater > &Q){while (!Q.empty()) Q.pop();}\ntemplate inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}\ntemplate inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}\ntemplate inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}\ntemplate inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}\ntemplate inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}\ntemplate inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}\ntemplate inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}\n\ntemplate inline T& SRT(T &A){sort(ALL(A)); return A;}\ntemplate inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}\ntemplate inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}\n\n//}\n\n/** Constant List .. **/ //{\n\nconst int dx4[] = {-1, 0, 1, 0};\nconst int dy4[] = {0, 1, 0, -1};\n\nconst int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};\nconst int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};\n\nconst int dxhorse[] = {-2 , -2 , -1 , -1 , 1 , 1 , 2 , 2};\nconst int dyhorse[] = {1 , -1 , 2 , -2 , 2 ,-2 , 1 ,-1};\n\nconst int MOD = 1000000007;\n//int MOD = 99990001;\nconst int INF = 0x3f3f3f3f;\nconst LL INFF = 1LL << 60;\nconst DB EPS = 1e-9;\nconst DB OO = 1e15;\nconst DB PI = acos(-1.0); //M_PI;\n\n//}\n\n/** Add On .. **/ //{\n// <<= '0. Nichi Joo ., //{\ntemplate inline void checkMin(T &a,const T b){if (b inline void checkMax(T &a,const T b){if (a inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}\ntemplate inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}\ntemplate inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}\ntemplate inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}\ntemplate inline T min(T a, T b, T c){return min(min(a, b), c);}\ntemplate inline T max(T a, T b, T c){return max(max(a, b), c);}\ntemplate inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}\ntemplate inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}\ntemplate inline T sqr(T a){return a*a;}\ntemplate inline T cub(T a){return a*a*a;}\ninline int ceil(int x, int y){return (x - 1) / y + 1;}\ninline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}\ninline int sgn(DB x, DB y){return sgn(x - y);}\n//}\n// <<= '1. Bitwise Operation ., //{\nnamespace BO{\n\ninline bool _1(int x, int i){return bool(x&1<> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);\n x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);\n x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);\n x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);\n x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);\n return x;\n}\n\ninline LL reverse_bits(LL x){\n x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);\n x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);\n x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);\n x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);\n x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);\n x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);\n return x;\n}\n\ntemplate inline bool odd(T x){return x&1;}\ntemplate inline bool even(T x){return !odd(x);}\ntemplate inline T low_bit(T x) {return x & -x;}\ntemplate inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}\ntemplate inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}\n\ninline int low_idx(int x){return __builtin_ffs(x);}\ninline int low_idx(LL x){return __builtin_ffsll(x);}\ninline int high_idx(int x){return low_idx(reverse_bits(x));}\ninline int high_idx(LL x){return low_idx(reverse_bits(x));}\ninline int clz(int x){return __builtin_clz(x);}\ninline int clz(LL x){return __builtin_clzll(x);}\ninline int ctz(int x){return __builtin_ctz(x);}\ninline int ctz(LL x){return __builtin_ctzll(x);}\ninline int parity(int x){return __builtin_parity(x);}\ninline int parity(LL x){return __builtin_parityll(x);}\ninline int lg2(int a){return 31 - clz(a);}\ninline int lg2(LL a){return 63 - clz(a);}\ninline int count_bits(int x){return __builtin_popcount(x);}\ninline int count_bits(LL x){return __builtin_popcountll(x);}\n\n} using namespace BO;//}\n// <<= '2. Number Theory .,//{\nnamespace NT{\ninline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}\ninline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}\ninline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}\ninline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}\ninline int dff(int a, int b){a -= b; if (a < 0) a += MOD; return a;}\ninline void MUL(int &a, int b){a = (LL)a * b % MOD;}\ninline int pdt(int a, int b){return (LL)a * b % MOD;}\n\ninline int sum(int a, int b, int c){return sum(sum(a, b), c);}\ninline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}\ninline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}\ninline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}\n\ninline int pow(int a, int b){\n int c(1); while (b){\n if (b&1) MUL(c, a);\n MUL(a, a), b >>= 1;\n }\n return c;\n}\n\ninline int pow(int a, LL b){\n int c(1); while (b){\n if (b&1) MUL(c, a);\n MUL(a, a), b >>= 1;\n }\n return c;\n}\n\ntemplate inline T pow(T a, LL b){\n T c(1); while (b){\n if (b&1) c *= a;\n a *= a, b >>= 1;\n }\n return c;\n}\n\ninline int _I(int b){\n int a = MOD, x1 = 0, x2 = 1, q;\n while (true){\n q = a / b, a %= b;\n if (!a) return (x2 + MOD) % MOD;\n DEC(x1, pdt(q, x2));\n\n q = b / a, b %= a;\n if (!b) return (x1 + MOD) % MOD;\n DEC(x2, pdt(q, x1));\n }\n}\n\ninline void DIV(int &a, int b){MUL(a, _I(b));}\ninline int qtt(int a, int b){return pdt(a, _I(b));}\n\ninline int phi(int n){\n int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){\n DEC(res, qtt(res, i));\n do{n /= i;} while(!(n%i));\n }\n if (n != 1)\n DEC(res, qtt(res, n));\n return res;\n}\n\n} using namespace NT;//}\n//}\n\n/** Miscellaneous .. **/ //{\n// <<= 'Random Event .. . //{\nnamespace RNG{\n//srand((unsigned)time(NULL));\ninline unsigned int rand16(){return ((rand()) << 15) ^ rand();}\ninline unsigned int rand32(){return (rand16() << 16) | rand16();}\ninline ULL rand64(){return ((LL)rand32() << 32) | rand32();}\ninline ULL random(LL l, LL r){return l == r ? l : rand64() % (r - l) + l;}\nint dice(){return rand() % 6;}\nbool coin(){return bool(rand() % 2);}\n} using namespace RNG;\n//}\n// <<= 'Clock .. . //{\nnamespace CLOCK{\nDB s0, s1, rd, k, T;\ninline DB getTime(){\n#ifdef LOCAL\n return 1.0 * clock() / CLOCKS_PER_SEC;\n#else\n timeval tv;\n gettimeofday(&tv, 0);\n return tv.tv_sec + tv.tv_usec * 1e-6;\n#endif\n}\n\ninline void st0(DB _T = 0.98){T = _T, s0 = getTime();}\ninline void st1(DB _k = 1.618){k = _k, s1 = getTime();}\ninline void ed1(){rd = getTime() - s1;}\ninline DB elapsed(){return getTime() - s0;}\ninline bool safe(){return elapsed() + rd * k < T;}\n} //using namespace CLOCK;\n//}\n// <<= 'Temp .. . //{\nnamespace TMP{\ntemplate PTT operator+(const PTT &p1, const PTT &p2) {\n\treturn PTT(p1.fi + p2.fi, p1.se + p2.se);\n}\n\ntemplate PTT operator-(const PTT &p1, const PTT &p2) {\n\treturn PTT(p1.fi - p2.fi, p1.se - p2.se);\n}\n\ntemplate PTT operator*(const PTT &lhs, T k){\n return PTT(lhs.fi * k, lhs.se * k);\n}\n} using namespace TMP;\n//}\n//}\n\n/** Algorithm .. */ //{\n// <<= '-. Math .,//{\nnamespace Math{\n\ttypedef long long typec;\n\t///Lib functions\n\ttypec GCD(typec a, typec b)\n\t{\n\t\treturn b ? GCD(b, a % b) : a;\n\t}\n\ttypec extendGCD(typec a, typec b, typec& x, typec& y)\n\t{\n\t\tif(!b) return x = 1, y = 0, a;\n\t\ttypec res = extendGCD(b, a % b, x, y), tmp = x;\n\t\tx = y, y = tmp - (a / b) * y;\n\t\treturn res;\n\t}\n\t///for x^k\n\ttypec power(typec x, typec k)\n\t{\n\t\ttypec res = 1;\n\t\twhile(k)\n\t\t{\n\t\t\tif(k&1) res *= x;\n\t\t\tx *= x, k >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\t///for x^k mod m\n\ttypec powerMod(typec x, typec k, typec m)\n\t{\n\t\ttypec res = 1;\n\t\twhile(x %= m, k)\n\t\t{\n\t\t\tif(k&1) res *= x, res %= m;\n\t\t\tx *= x, k >>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t/***************************************\n\tInverse in mod p^t system\n\t***************************************/\n\ttypec inverse(typec a, typec p, typec t = 1)\n\t{\n\t\ttypec pt = power(p, t);\n\t\ttypec x, y;\n\t y = extendGCD(a, pt, x, y);\n\t\treturn x < 0 ? x += pt : x;\n\t}\n\t/***************************************\n\tLinear congruence theorem\n\tx = a (mod p)\n\tx = b (mod q)\n\tfor gcd(p, q) = 1, 0 <= x < pq\n\t***************************************/\n\ttypec linearCongruence(typec a, typec b, typec p, typec q)\n\t{\n\t\ttypec x, y;\n\t\ty = extendGCD(p, q, x, y);\n\t\twhile(b < a) b += q / y;\n\t\tx *= b - a, x = p * x + a, x %= p * q;\n\t\tif(x < 0) x += p * q;\n\t\treturn x;\n\t}\n\t/***************************************\n\tprime table\n\tO(n)\n\t***************************************/\n\tconst int PRIMERANGE = 1000000;\n\tint prime[PRIMERANGE + 1];\n\tint mobius[PRIMERANGE + 1];\n\tint getPrime()\n\t{\n\t\tmemset (prime, 0, sizeof (int) * (PRIMERANGE + 1));\n\t\tmemset(mobius , 0 , sizeof(mobius));\n\t\tmobius[1] = 1;\n\t\tfor (int i = 2; i <= PRIMERANGE; i++)\n\t\t{\n\t\t\tif (!prime[i]) prime[++prime[0]] = i , mobius[i] = -1;\n\t\t\tfor (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++)\n\t\t\t{\n\t\t\t\tprime[prime[j]*i] = 1;\n\t\t\t\tif (i % prime[j] == 0) break;\n\t\t\t\telse mobius[i * prime[j]] = -mobius[i];\n\t\t\t}\n\t\t}\n\t\treturn prime[0];\n\t}\n\t/***************************************\n\tget factor of n\n\tO(sqrt(n))\n\tfactor[][0] is prime factor\n\tfactor[][1] is factor generated by this prime\n\tfactor[][2] is factor counter\n\n\tneed: Prime Table\n\t***************************************/\n\t///you should init the prime table before\n\tint factor[100][3], facCnt;\n\tint getFactors(int x)\n\t{\n\t\tfacCnt = 0;\n\t\tint tmp = x;\n\t\tfor(int i = 1; prime[i] <= tmp / prime[i]; i++)\n\t\t{\n\t\t\tfactor[facCnt][1] = 1, factor[facCnt][2] = 0;\n\t\t\tif(tmp % prime[i] == 0)\n\t\t\t\tfactor[facCnt][0] = prime[i];\n\t\t\twhile(tmp % prime[i] == 0)\n\t\t\t\tfactor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];\n\t\t\tif(factor[facCnt][1] > 1) facCnt++;\n\t\t}\n\t\tif(tmp != 1)\n\t\t\tfactor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;\n\t\treturn facCnt;\n\t}\n\ttypec combinationModP(typec n, typec k, typec p)\n\t{\n\t\tif(k > n) return 0;\n\t\tif(n - k < k) k = n - k;\n\t\ttypec a = 1, b = 1, x, y;\n\t\tint pcnt = 0;\n\t\tfor(int i = 1; i <= k; i++)\n\t\t{\n\t\t\tx = n - i + 1, y = i;\n\t\t\twhile(x % p == 0) x /= p, pcnt++;\n\t\t\twhile(y % p == 0) y /= p, pcnt--;\n\t\t\tx %= p, y %= p, a *= x, b *= y;\n\t\t\tb %= p, a %= p;\n\t\t}\n\t\tif(pcnt) return 0;\n\t\textendGCD(b, p, x, y);\n\t\tif(x < 0) x += p;\n\t\ta *= x, a %= p;\n\t\treturn a;\n\t}\n};//using namespace Math;\n//}\n// <<= '-. Geo ,.//{\nnamespace Geo{\n\t#define typec double\n const typec eps=1e-15;\n int dblcmp(double d){\n return d < -eps ? -1 : d > eps;\n }\n int sgn(double a) {return a<-eps?-1:a>eps;}\n inline double sqr(double x){return x*x;}\n}using namespace Geo;\n//}\n//}\n\n/** I/O Accelerator Interface .. **/ //{\ntemplate inline T& RD(T &x){\n //cin >> x;\n //scanf(\"%d\", &x);\n char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';\n //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';\n return x;\n}\n\ninline DB& RF(DB &x){\n //cin >> x;\n scanf(\"%lf\", &x);\n /*char t; while ((t=getchar())==' '||t=='\\n'); x = t - '0';\n while ((t=getchar())!=' '&&t!='\\n'&&t!='.')x*=10,x+=t-'0';\n if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\\n')l*=0.1,x += (t-'0')*l;}*/\n return x;\n}\n\ninline char* RS(char *s){\n //gets(s);\n scanf(\"%s\", s);\n return s;\n}\n\nint Case; template inline void OT(const T &x){\n //printf(\"Case %d: %d\\n\", ++Case, x);\n //printf(\"%.2lf\\n\", x);\n //printf(\"%d\\n\", x);\n cout << x << endl;\n}\n//}\n/* .................................................................................................................................. */\nstruct point\n{\n double x,y;\n point(){}\n point(double _x,double _y):\n x(_x),y(_y){};\n void input()\n {\n scanf(\"%lf%lf\",&x,&y);\n }\n void output()\n {\n printf(\"%.2f %.2f\\n\",x,y);\n }\n bool operator==(point a)const\n {\n return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0;\n }\n bool operator<(point a)const\n {\n return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:xsub(p);\n double c=cos(angle),s=sin(angle);\n return point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);\n }\n};\n\nconst int N = 21;\ndouble a[N] , l , r;\n#define Point2D point\nPoint2D p[N];\nint n;\ndouble dp[1 << N];\n//line XX;\ndouble f(double now , int k){\n if (dblcmp(now - r) >= 0) return r;\n// double rad = p[k].rad(Point2D(now , 0) , Point2D(r , 0));\n//// printf(\"%.9lf\\n\" , rad);\n// if (dblcmp(rad - a[k]) <= 0) return r;\n// point dd = point(now , 0);\n// dd = dd.rotate(p[k] , a[k]);\n// dd = line(p[k] , dd).crosspoint(XX);\n// return dd.x;\n double beta = atan2(p[k].y , (p[k].x - now));\n double bb = beta * 180. / PI;\n if (dblcmp(bb + a[k] - 180.) >= 0) return r;\n// double bb = beta * 180. / PI;\n double rr = 180. - bb - a[k];\n return sqrt(sqr(p[k].y) + sqr(p[k].x - now)) / sin(rr * PI / 180.) * sin(a[k] * PI / 180.) + now;\n}\nvoid solve(){\n// XX = line(point(-1e5 , 0) , point(1e5 , 0));\n if (dblcmp(l - r) >= 0){\n puts(\"0.000000000\");\n return;\n }\n RST(dp);\n for (int i = 0 ; i < n ; ++i){\n p[i].input();\n cin >> a[i];\n// a[i] *= PI;\n// a[i] /= 180.;\n }\n double ans = l;\n for (int i = 0 ; i < _1(n) ; ++i)\n dp[i] = l;\n for (int i = 0 ; i < _1(n) ; ++i){\n// checkMax(ans , dp[i]);\n for(int j = 0 ; j < n ; ++j) if ((i & _1(j)) == 0){\n checkMax(dp[(i | _1(j))] , f(dp[(i)] , j));\n }\n }\n checkMax(ans , dp[_1(n) - 1]);\n checkMin(ans , r);\n printf(\"%.15lf\\n\" , ans - l);\n}\nint main(){\n cin >> n >> l >> r; ;solve();\n}\n\n\n\n\n", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a"} {"source_code": "#include \n \nusing namespace std;\n \n#define ll long long int\n \nint main(){\n ll a[5][5];\n for(ll i=0;i<5;i++){\n for(ll j=0;j<5;j++){\n a[i][j]=0;\n }\n }\n for(ll i=1;i<=3;i++){\n for(ll j=1;j<=3;j++)\n cin>>a[i][j];\n }\n for(ll i=1;i<=3;i++){\n for(ll j=1;j<=3;j++){\n ll x = (a[i][j] + a[i][j-1] + a[i][j+1] + a[i-1][j] + a[i+1][j]) % 2 == 0 ? 1 : 0;\n cout<\n#include \n#include \nusing namespace std;\n\nconst long long MOD = 1000000007LL;\n\nint N, M, K;\nlong long c[1010][1010];\n\nint main()\n{\n\tint i, j, k;\n\tscanf(\"%d%d%d\", &N, &M, &K);\n\tif (K*2>N-1 || K*2>M-1)\n\t{\n\t\tputs(\"0\");\n\t\treturn 0;\n\t}\n\tc[0][0] = 1LL;\n\tfor (i = 1; i <= max(N-1, M-1); ++i)\n\t{\n\t\tc[i][0] = 1;\n\t\tfor (j = 1; j <= i; ++j)\n\t\t\tc[i][j] = (c[i-1][j]+c[i-1][j-1])%MOD;\n\t}\n\tprintf(\"%ld\\n\", (c[N-1][2*K]*c[M-1][2*K])%MOD);\n\treturn 0;\n}", "src_uid": "309d2d46086d526d160292717dfef308"} {"source_code": "#pragma comment(linker, \"/STACK:500000000\") \n#include \n#include \n#include \n#include \n#include \n#include \n#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 \n#define INF 0x3F3F3F3F \n#define eps 1e-9\nusing namespace std;\n\n#define N 1000009\n\nint a[N];\nint fa[N];\n\nconst int mod = 1000000007;\n\nint modpow(int a, int n, int mod)\n{\n\tint b = 1;\n\twhile(n > 0)\n\t{\n\t\tif (n & 1)\n\t\t\tb = (long long)b * a % mod;\n\t\tn >>= 1;\n\t\ta = (long long)a * a % mod;\n\t}\n\treturn b;\n}\n\nint f(int n, int m)\n{\n\tif (n == m)\n\t\treturn a[n]; //a[n-1] + (n-1)*a[n-2];\n\treturn (Int)f(n - 1, m) * n % mod;\n}\n\nint f2(int n, int m)\n{\n\treturn (Int)fa[n] * modpow(fa[m], mod - 2, mod) % mod * a[m] % mod;\n}\n\n\nint main()\n{\n\tint n, aa, i, m;\n\ta[1] = 1;\n\ta[2] = 2;\n\tfor(n = 3; n < N; n++)\n\t\ta[n] = (a[n-1] + (Int)(n-1)*a[n-2]) % mod;\n\tfa[0] = 1;\n\tfor(n = 1; n < N; n++)\n\t\tfa[n] = (Int)fa[n - 1] * n % mod;\n\tcin >> n;\n\tm = 0;\n\tfor(i = 0; i < n; i++)\n\t{\n\t\tcin >> aa;\n\t\tm += aa == 1;\n\t}\n\tif (m == 0)\n\t\tm++;\n\t//cout << f(n, m) << endl;\n\tcout << f2(n, m) << endl;\n}\n\n//\n//#define N 1000009\n//\n//int A[N];\n//int n;\n//int p[N];\n//set > res;\n//\n//void brute()\n//{\n//\tint i, j;\n//\tfor(i = 0; i < n; i++)\n//\t{\n//\t\tif (A[i])\n//\t\t{\n//\t\t\tfor(j = i + 1; j < n; j++)\n//\t\t\t{\n//\t\t\t\tif (A[j])\n//\t\t\t\t{\n//\t\t\t\t\tA[i]--;\n//\t\t\t\t\tA[j]--;\n//\t\t\t\t\tswap(p[i], p[j]);\n//\t\t\t\t\tbrute();\n//\t\t\t\t\tA[i]++;\n//\t\t\t\t\tA[j]++;\n//\t\t\t\t\tswap(p[i], p[j]);\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n//\t}\n//\tres.insert(vector(p, p + n));\n//}\n//\n//int main()\n//{\n//\tint m, i, j;\n//\t//cin >> n >> m;\n//\tFILE *f = freopen(\"in2.txt\", \"w\", stdout);\n//\tfor(n = 9; n <= 10; n++)\n//\t{\n//\t\tfor(m = 1; m <= n; m++)\n//\t\t{\n//\t\t\tfor(i = 0; i < n; i++)\n//\t\t\t{\n//\t\t\t\tp[i] = i;\n//\t\t\t\tA[i] = i < m ? 1 : 2;\n//\t\t\t}\n//\t\t\tres.clear();\n//\t\t\tbrute();\n//\t\t\tprintf(\"%9d, \", res.size());\n//\t\t\tfflush(f);\n//\t\t}\n//\t\tputs(\"\");\n//\t}\n//\tcout << res.size() << endl;\n//}", "src_uid": "91e8dbe94273e255182aca0f94117bb9"} {"source_code": "#include \nusing namespace std;\n\n#define rep(i, n) for (int i = 0; i < (int)n; i++)\n\nint N;\nvector A, C, L;\nvector> D;\n\nint main()\n{\n cin >> N;\n\n int mx = 0, id;\n A.resize(N); C.assign(100, 0);\n rep(i, N)\n {\n cin >> A[i]; A[i]--; C[A[i]]++;\n if (C[A[i]] > mx) mx = C[A[i]], id = A[i];\n }\n\n C.assign(100, 0);\n D.assign(N, vector(100));\n rep(i, N)\n {\n C[A[i]]++;\n rep(j, 100) D[i][j] = C[j] - C[id];\n }\n\n int ans = 0;\n rep(j, 100) if (j != id)\n {\n L.assign(2 * N + 1, -1); L[N] = 0;\n rep(i, N)\n {\n if (L[N + D[i][j]] == -1) L[N + D[i][j]] = i + 1;\n else ans = max(ans, i - L[N + D[i][j]] + 1);\n }\n }\n\n cout << ans << '\\n';\n}", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed"} {"source_code": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main() {\n int n;\n int k;\n long M;\n long Mtask = 0;\n\n cin >> n;\n cin >> k;\n cin >> M;\n vector times(k);\n\n for (int i = 0; i < k; i++) {\n cin >> times[i];\n Mtask += times[i];\n }\n sort (times.begin(), times.end()); \n\n long maxTask = M / Mtask;\n if (maxTask > n) {\n maxTask = n;\n }\n\n int points = 0;\n int maxpoints = 0;\n for (int i = 0; i <= maxTask; ++i) {\n long cM = M;\n points = (k + 1) * i;\n\n cM -= Mtask * i;\n\n int remainderN = n - i;\n\n int y = 0;\n while ((cM > 0) && (y < k)) {\n if (cM >= times[y] * remainderN) {\n points += remainderN;\n cM -= times[y] * remainderN;\n y++;\n } else {\n points += cM / times[y];\n cM = 0;\n break; \n }\n }\n\n if (points > maxpoints) {\n maxpoints = points;\n }\n }\n\n cout << maxpoints;\n\n}", "src_uid": "d659e92a410c1bc836be64fc1c0db160"} {"source_code": "# include\nusing namespace std;\nint main(){\n\n int n,k;\n string s;\n cin>>n>>k>>s;\n if(n==1 && k==1){\n cout<<\"0\"<0;i++){\n if(s[i]!='0'){\n s[i]='0';\n k--;\n }\n }\n\n }\n else{\n s[0]='1';\n k--;\n for(int i=1;i0;i++){\n if(s[i]!='0'){\n s[i]='0';\n k--;\n }\n }\n }\n cout<\n#include\n#include\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n\ntypedef double ld;\nconst int MAX=800000+10;\nconst ld INF=1e30;\nconst ld EPS=0.02;\n\nstruct point\n{\n\tld x,y;\n\tpoint(ld a,ld b){x=a;y=b;}\n\tpoint(){}\n\tvoid print(){printf(\"%lf %lf\\n\",x,y);}\n};\n\nld sqr(ld x)\n{\n\treturn x*x;\n}\n\nld dist(const point& a,const point& b)\n{\n\treturn sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));\n}\n\nld chaji(const point& s,const point& a,const point& b)\n{\n\treturn (a.x-s.x)*(b.y-s.y)-(a.y-s.y)*(b.x-s.x);\n}\n\nint n,S,T;\npoint d[MAX],TOP(0,INF);\n\nint begin[MAX*4],t[MAX*4],tot,next[MAX*4];\nld c[MAX*4];\n\nvoid addedge(int x,int y,ld v)\n{\n\tt[++tot]=y;\n\tnext[tot]=begin[x];\n\tbegin[x]=tot;\n\tc[tot]=v;\n}\n\nstruct line\n{\n\tint s,t,type,number;\n\tline(){}\n\tline(int a,int b){s=a;t=b;type=0;}\n\tvoid print()const\n\t{\n\t\td[s].print();\n\t\td[t].print();\n\t\tprintf(\"\\n\");\n\t}\n}l[MAX];\n\npoint get(point b,point c,ld x)\n{\n\tld k=(x-b.x)/(c.x-b.x);\n\treturn point(b.x+(c.x-b.x)*k,b.y+(c.y-b.y)*k);\n}\n\nint operator < (const line& a,const line& b)\n{\n\tld l=max(d[a.s].x,d[b.s].x),r=min(d[a.t].x,d[b.t].x);\n\tld x=(l+r)*0.5;\n\tpoint s1=get(d[a.s],d[a.t],x),s2=get(d[b.s],d[b.t],x);\n\tif(s1.y!=s2.y)return s1.y st;\n\nstruct accident\n{\n\tint x,num,flag;\n\taccident(ld c,int a,int b){x=c;num=a;flag=b;}\n\taccident(){}\n}p[MAX];\n\nint operator < (const accident& a,const accident& b)\n{\n\treturn a.x q;\nint hh[MAX];\nld dis[MAX];\n\nld SPFA()\n{\n\tint i,u,v;\n\tfor(i=1;i<=n;++i)\n\t\tdis[i]=INF;\n\tq.push(S);dis[S]=0;hh[S]=1;\n\twhile(!q.empty())\n\t{\n\t\tu=q.front();q.pop();\n\t\thh[u]=0;\n\t\tfor(i=begin[u];i;i=next[i])\n\t\t{\n\t\t\tv=t[i];\n\t\t\tif(dis[v]>dis[u]+c[i])\n\t\t\t{\n\t\t\t\tdis[v]=dis[u]+c[i];\n\t\t\t\tif(!hh[v])\n\t\t\t\t{\n\t\t\t\t\thh[v]=1;\n\t\t\t\t\tq.push(v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn dis[T];\n}\n\nvoid update(int now)\n{\n\tset::iterator ii,it=st.find(l[p[now].num]);\n\tif(it==st.end())\n\t\treturn;\n\tif(it->type==-1)\n\t{\n\t\tii=it;\n\t\t++ii;\n\t\t\n\t\twhile(same(p[now].x,*ii,*it) && ii->type==it->type)\n\t\t{\n\t\t\t++ii;\n\t\t\tif(ii==st.end())\n\t\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(ii==st.end())\n\t\t\treturn;\n\t}\n\tif(it->type==1)\n\t{\n\t\tif(it==st.begin())\n\t\t\treturn;\n\t\tii=it;\n\t\t--ii;\n\t\twhile(same(p[now].x,*ii,*it) && ii->type==it->type)\n\t\t{\n\t\t\tif(ii==st.begin())\n\t\t\t\treturn;\n\t\t\t--ii;\n\t\t}\n\t\tswap(ii,it);\n\t}\n\tif(it->type==ii->type)\n\t\treturn;\n\t/*\n\tif(p[now].flag==1 && p[now].num==2)\n\t{\n\t\tii->print();\n\t\tit->print();\n\t\tprintf(\"\\n\");\n\t}\n\t*/\n\tadd(p[now].x,*ii,*it);\n}\n\nint main()\n{\n#ifndef ONLINE_JUDGE\n\tfreopen(\"input.txt\",\"r\",stdin);freopen(\"output.txt\",\"w\",stdout);\n#endif\n\tint i,j,now;\n\tscanf(\"%d\",&n);\n\tfor(i=1;i<=n;++i)\n\t\tscanf(\"%lf%lf\",&d[i].x,&d[i].y);\n\tscanf(\"%d%d\",&S,&T);\n\tfor(i=1;i<=n;++i)\n\t{\n\t\tj=(i==n?1:i+1);\n\t\taddedge(i,j,dist(d[i],d[j]));\n\t\taddedge(j,i,dist(d[j],d[i]));\n\t\tl[i]=line(i,j);\n\t\tl[i].number=i;\n\t\tif(d[i].x!=d[j].x)\n\t\t{\n\t\t\tif(chaji(d[i],d[j],TOP)>=0)\n\t\t\t\tl[i].type=-1;\n\t\t\telse l[i].type=1;\n\t\t\tif(d[l[i].s].x>d[l[i].t].x)\n\t\t\t\tswap(l[i].s,l[i].t);\n\t\t\tp[++num]=accident( (int)d[l[i].s].x ,i,1);\n\t\t\tp[++num]=accident( (int)d[l[i].t].x ,i,-1);\n\t\t}\n\t}\n\tset::iterator it;\n\tsort(p+1,p+num+1);\n\tfor(now=1;now<=num;)\n\t{\n\t\tj=now;\n\t\twhile(j<=num && p[j].x==p[now].x)\n\t\t{\n\t\t\tif(p[j].flag==1)\n\t\t\t{\n\t\t\t\tst.insert(l[p[j].num]);\n//\t\t\t\tprintf(\"%d\\n\",p[j].num);\n\t\t\t}\n\t\t\t++j;\n\t\t}\n\n\t\tj=now;\n\t\twhile(j<=num && p[j].x==p[now].x)\n\t\t\tupdate(j),++j;\n\n\t\tj=now;\n\t\twhile(j<=num && p[j].x==p[now].x)\n\t\t{\n\t\t\tif(p[j].flag==-1)\n\t\t\t{\n\t\t\t\tst.erase(l[p[j].num]);\n\t\t\t}\n\t\t\t++j;\n\t\t}\n\n\t\tnow=j;\n\t}\n\tld ans=SPFA();\n\tprintf(\"%lf\\n\",ans);\n\treturn 0;\n}\n \t\t\t\t \t\t\t\t\t \t\t \t \t\n", "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45"} {"source_code": "#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 pii pair\n#define p3i pair, int>\n#define mp make_pair\n#define pb push_back\n#define pll pair\n#define p3l pair, long long>\n#define x first\n#define y second\n\nint n, m; char ch; bool b=0;\nint main(){\n cin.sync_with_stdio(0);\n cin.tie(0);\n cin >> n >> m;\n for (int l=0; l> ch;\n if (ch!='B' && ch!='W' && ch!='G') b=1;\n }\n if (b) cout << \"#Color\";\n else cout << \"#Black&White\";\n return 0;\n}", "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"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\n#ifdef ONLINE_JUDGE\n\n#define fin cin\n#define fout cout\n\n#else\n\nfstream fin(\"input.txt\", fstream::in);\nfstream fout(\"output.txt\", fstream::out);\n\n#endif\n\nbool win(long long a, long long b) {\n\tif (a > b) {\n\t\tswap(a, b);\n\t}\n\tif (a == 0) {\n\t\treturn false;\n\t}\n\tbool next = win(a, b % a);\n\treturn !next || (((b / a) % (a + 1)) % 2 == 0);\n}\n\nint main() {\n\tfout.precision(10);\n\tfout << fixed;\n\t\n\tint T;\n\tfin >> T;\n\tfor (int t = 0; t < T; ++t) {\n\t\tlong long A, B;\n\t\tfin >> A >> B;\n\t\tif (win(A, B)) {\n\t\t\tfout << \"First\\n\";\n\t\t} else {\n\t\t\tfout << \"Second\\n\";\n\t\t}\n\t}\n\n\treturn 0;\n}\n", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c"} {"source_code": "//#pragma GCC optimize(3)\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\ntypedef long long ll;\ntypedef unsigned int uint;\ntypedef unsigned long long ull;\ntypedef pair pll;\ntypedef pair pli;\ntypedef pair pil;\ntypedef pair pii;\n#define Continue(x) { x; continue; }\n#define Break(x) { x; break; }\n#define Return(x) { x; return; }\n#define P2(x) ((x) * (x))\n#define lowbit(x) ((x) & -(x))\n#define SZ(x) ((int)(x).size())\n#define ALL(x) (x).begin(), (x).end()\n#define MEM(x, y) memset((x), (y), sizeof(x))\n#define MEN(x, y, z) memset((x), (y), sizeof((x)[0]) * (z))\n#define Diz(x) (lower_bound(dz.begin(), dz.end(), (x)) - dz.begin())\n#define DISCRETIZA(x) (x).push_back(-INF), sort((x).begin(), (x).end()), (x).erase(unique((x).begin(), (x).end()), (x).end())\n#ifdef LOCAL\n#define DEBUG(...) cout << \">> \" << #__VA_ARGS__ << \" =\", PRT(__VA_ARGS__), cout << endl;\n#define DEBUGS(...) cout << \">> \" << #__VA_ARGS__ << \" =\", PRTS(__VA_ARGS__), cout << endl;\nvoid PRT() {} template void PRT(S x, T ... y){ cout << \" \" << x; PRT(y...); }\nvoid PRTS() {} template void PRTS(S x) { for (auto v : x) cout << \" \" << v; }\n#define TIME cout << \"RunTime: \" << clock() << \"ms\\n\", 0\n#define __int128_t long long\n#else\n#define DEBUG(...) ;\n#define DEBUGS(...) ;\n#define TIME 0\n#endif\n\nconst int INF = 0x3f3f3f3f;\nconst ll LINF = 0x3f3f3f3f3f3f3f3f;\nconst int MOD = 1e9 + 7;\ntemplate inline bool Min(S &a, const T &b){ return a > b ? a = b, true : false; }\ntemplate inline bool Max(S &a, const T &b){ return a < b ? a = b, true : false; }\ntemplate inline void Adm(S &a, const T &b){ a = (a + b) % MOD; if (a < 0) a += MOD; }\ntemplate inline void Mum(S &a, const T &b){ a = 1LL * a * b % MOD; }\ntemplate inline bool IsPri(T x) { if (x < 2) return false; for (T i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; }\ntemplate inline T Gcd(T a, T b){ while (b){ T t = b; b = a % b; a = t; } return a; }\ntemplate inline int BitCnt(T x){ int cnt = 0; while (x)++cnt, x &= x - 1; return cnt; }\ntemplate inline T MDis(T x1, T y1, T x2, T y2){ return abs(x1 - x2) + abs(y1 - y2); }\ntemplate inline T MDis(T x1, T y1, T z1, T x2, T y2, T z2){ return abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2); }\ninline double EDis(double x1, double y1, double x2, double y2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }\ninline double EDis(double x1, double y1, double z1, double x2, double y2, double z2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); }\ninline ll Pow(ll a, ll n) { ll t = 1; a %= MOD; while (n) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; }\n#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;\ninline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }\n//emplace unordered 能ll就开 函数内判非法\n\nll n, k;\nll calc(ll y) //计算n范围内以y为最高二进制位的数字数量\n{\n\tll res = 0, w = 1;\n\twhile (y <= n) //枚举二进制长度\n\t{\n\t\tres += min(w, n - y + 1); //变化量和n限制取min\n\t\ty <<= 1, w <<= 1;\n\t}\n\treturn res;\n}\nll solve(ll y)\n{\n\tll res = calc(y);\n\tif (!(y & 1)) //如果y为偶数 可以从奇数过来\n\t\tres += calc(y + 1);\n\treturn res;\n}\nint main()\n{\n#ifdef LOCAL\n\t//freopen(\"C:/input.txt\", \"r\", stdin);\n\t//freopen(\"C:/output.txt\", \"w\", stdout);\n#endif\n\t//二分满足单调性 calc(x) >= calc(x + 2) 分奇偶二分答案\n\tcin >> n >> k;\n\tll l = 1, r = n / 2, ans = 0; //偶数\n\twhile (l <= r)\n\t{\n\t\tll mid = l + r >> 1;\n\t\tif (solve(mid * 2) >= k) //*2\n\t\t\tMax(ans, mid * 2), l = mid + 1;\n\t\telse\n\t\t\tr = mid - 1;\n\t}\n\tl = 1, r = (n + 1) / 2; //奇数\n\twhile (l <= r)\n\t{\n\t\tll mid = l + r >> 1;\n\t\tif (solve(mid * 2 - 1) >= k) //*2-1\n\t\t\tMax(ans, mid * 2 - 1), l = mid + 1;\n\t\telse\n\t\t\tr = mid - 1;\n\t}\n\tcout << ans << endl;\n\n\treturn TIME;\n}\n", "src_uid": "783c4b3179c558369f94f4a16ac562d4"} {"source_code": "#define _USE_MATH_DEFINES\n#include \n#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; i < (int)n; i++)\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef pair pi;\ntypedef pair pp;\ntypedef pair pl;\ndouble PI = 3.141592653589793238462643383279;\nconst double EPS = 1e-9;\n//const ll MOD = 1000000007;\nconst ll MOD = 998244353;\nconst int inf = 1 << 30;\nconst ll linf = 1LL << 60;\n\nll n, k;\nll dp[2500][2500];\nll ans2;\n\nbool dfs (vector& v, ll K) {\n int sum = 0;\n for (int i : v) sum += i;\n if (sum > n) return 0;\n if (K <= 1) return 1;\n vector nxt;\n int t = 0;\n for (int i = (int)v.size()-1; i >= 0; i--) {\n t++;\n rep(j,v[i]) nxt.push_back(t);\n }\n return dfs(nxt, K-1);\n}\n\nvoid hoge (vector& v) {\n for (int i = v.size()==0?1:v.back(); ; i++) {\n v.push_back(i);\n if (!dfs(v, k)) {\n v.pop_back();\n break;\n }\n ans2++;\n hoge(v);\n v.pop_back();\n }\n}\n\nint main() {\n scanf(\"%lld%lld\", &n, &k);\n if (k == 1) {\n dp[1][1] = 1;\n ll ans = 0;\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= i; j++) {\n dp[i][j] = (dp[i][j] + dp[i-1][j-1] + dp[i-j][j]) % MOD;\n ans = (ans + dp[i][j]) % MOD;\n }\n }\n printf(\"%lld\\n\", ans);\n return 0;\n }\n if (k == 2) {\n dp[1][1] = 1;\n ll ans = 0;\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= i; j++) {\n dp[i][j] = (dp[i][j] + dp[i-j][j-1]) % MOD;\n if (i >= j*(j+1)/2) dp[i][j] = (dp[i][j] + dp[i-j*(j+1)/2][j]) % MOD;\n ans = (ans + dp[i][j]) % MOD;\n }\n }\n printf(\"%lld\\n\", ans);\n return 0;\n }\n vector v;\n hoge(v);\n printf(\"%lld\\n\", ans2);\n}", "src_uid": "c435a0cd437081cd3593637be4568c6a"} {"source_code": "#include\r\n#include\r\n#include\r\n#include\r\n#define rep(i,a,b) for(int i = (a); i <= (b); i++)\r\n#define per(i,b,a) for(int i = (b); i >= (a); i--)\r\n#define ll long long\r\n#define mod 998244353\r\n#define N 200022\r\n#define B 400\r\nusing namespace std;\r\n\r\nint n, k;\r\nint mu[N], prime[N], siz;\r\nbool vis[N];\r\nll fact[N], invf[N];\r\nll S[B+2][B+2], val[N], sum[N];\r\n\r\nll qpow(ll a, int b){\r\n ll ret = 1;\r\n for(; b; b >>= 1){ if(b&1) (ret *= a) %= mod; (a *= a) %= mod; }\r\n return ret;\r\n}\r\n\r\nvoid init(){\r\n fact[0] = 1;\r\n rep(i,1,n) fact[i] = fact[i-1] * i % mod;\r\n invf[n] = qpow(fact[n], mod-2);\r\n per(i,n-1,0) invf[i] = invf[i+1] * (i+1) % mod;\r\n\r\n sum[0] = 1;\r\n rep(i,1,n) sum[i] = (sum[i-1] + (i&1 ? mod-1 : 1) * invf[i]) % mod;\r\n\r\n S[0][0] = 1;\r\n int siz = min(n, B);\r\n rep(i,1,siz){\r\n val[i] = mod-1;\r\n rep(j,1,i){\r\n S[i][j] = (j * S[i-1][j] + S[i-1][j-1]) % mod;\r\n if(j <= k) (val[i] += S[i][j]) %= mod;\r\n }\r\n }\r\n}\r\n\r\nvoid euler(){\r\n mu[1] = 1;\r\n rep(i,2,n){\r\n if(!vis[i]) mu[i] = -1, prime[++siz] = i;\r\n for(int j = 1; j <= siz && i * prime[j] <= n; j++){\r\n int v = i * prime[j];\r\n vis[v] = true;\r\n if(i % prime[j] == 0){ mu[v] = 0; break; }\r\n mu[v] = -mu[i];\r\n }\r\n }\r\n}\r\n\r\nll cal(int n){\r\n if(val[n]) return val[n];\r\n ll ret = mod-1;\r\n per(i,min(n,k),0) (ret += qpow(i, n) * invf[i] % mod * sum[min(n,k)-i]) %= mod;\r\n return val[n] = ret;\r\n}\r\n\r\nint main(){\r\n cin>>n>>k;\r\n if(n == 1 || k == 1){ cout<<\"1\\n\"; return 0; }\r\n\r\n init(), euler();\r\n ll ans = 0;\r\n rep(i,1,n) if(mu[i])\r\n (ans += (mod + mu[i]) * cal((n+i-1)/i)) %= mod;\r\n cout<< ans <\n#include\n#include\n#include\nusing namespace std;\nint main(){\n int T,n,i;\n scanf(\"%d\",&T);\n while(T--){\n scanf(\"%d\",&n);\n if(n%3==0||n%7==0){\n printf(\"YES\\n\");continue;\n }\n for(i=1;i*3<=n;i++){\n if((n-i*3)%7==0){\n printf(\"YES\\n\");break;\n }\n }\n if(i*3<=n)continue;\n for(i=1;i*7<=n;i++){\n if((n-i*7)%3==0){\n printf(\"YES\\n\");break;\n }\n }\n if(i*7<=n)continue;\n printf(\"NO\\n\");\n }\n return 0;\n}", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"source_code": "#include \n\nusing namespace std;\n\ntypedef vector Poly;\n\nconst int N = 4333;\nconst int MOD = 998244353;\n\nnamespace {\n int inv[N], fac[N], ifac[N], pw2[N];\n \n int Add(int a, int b) {\n return (a += b) >= MOD? a - MOD : a;\n }\n int Sub(int a, int b) {\n return (a -= b) < 0? a + MOD : a;\n }\n int Mul(int a, int b) {\n return (long long)a * b % MOD;\n }\n int Inv(int a) {\n return (a == 1)? 1 : Mul(MOD - MOD / a, Inv(MOD % a));\n }\n int Ch(int a, int b) {\n if (a < b) return 0;\n return Mul(fac[a], Mul(ifac[b], ifac[a - b]));\n }\n int Pow(int a, int b) {\n int r = 1;\n for (; b; b >>= 1) {\n if (b & 1) {\n r = Mul(r, a);\n }\n a = Mul(a, a);\n }\n return r;\n }\n \n void Math_init() {\n inv[1] = 1;\n for (int i = 2; i < N; ++i) {\n inv[i] = Mul(MOD - MOD / i, inv[MOD % i]);\n }\n fac[0] = ifac[0] = pw2[0] = 1;\n for (int i = 1; i < N; ++i) {\n fac[i] = Mul(fac[i - 1], i);\n ifac[i] = Mul(ifac[i - 1], inv[i]);\n pw2[i] = Add(pw2[i - 1], pw2[i - 1]);\n }\n }\n}\n\nnamespace PO {\n int rev[N * 4], w[N * 4], L = 1;\n\n void Init(int l) {\n for (; L < l; L <<= 1) {\n int wn = Pow(3, (MOD - 1) / (L << 1));\n for (int i = L; i < (L << 1); ++i) {\n w[i] = (i == L)? 1 : Mul(w[i - 1], wn);\n }\n }\n for (int i = 0; i < l; ++i) {\n rev[i] = (rev[i >> 1] >> 1) | (i & 1? l >> 1 : 0);\n }\n }\n\n void Dft(Poly &a, int l) {\n for (int i = 0; i < l; ++i) {\n if (i < rev[i]) {\n swap(a[i], a[rev[i]]);\n }\n }\n for (int i = 1, y; i < l; i <<= 1) {\n for (int j = 0; j < l; j += i << 1) {\n int *l = &a[j], *r = l + i, *wx = w + i;\n for (int k = 0; k < i; ++k, ++l, ++r, ++wx) {\n y = Mul(*r, *wx);\n *r = Sub(*l, y);\n *l = Add(*l, y);\n }\n }\n }\n }\n\n void Idft(Poly &a, int l) {\n reverse(a.begin() + 1, a.end());\n Dft(a, l);\n int il = Inv(l);\n for (int i = 0; i < l; ++i) {\n a[i] = Mul(a[i], il);\n }\n }\n\n Poly Poly_mul(Poly a, Poly b) {\n int n = a.size(), m = b.size(), l;\n for (l = 1; l < n + m - 1; l <<= 1);\n Init(l);\n a.resize(l);\n Dft(a, l);\n b.resize(l);\n Dft(b, l);\n for (int i = 0; i < l; ++i) {\n a[i] = Mul(a[i], b[i]);\n }\n Idft(a, l);\n a.resize(n + m - 1);\n return a;\n }\n \n}\n\nint main() {\n Math_init();\n\n int n, k, l;\n cin >> n >> k >> l;\n \n Poly AL(n + 1), AR(n + 1);\n for (int j = k; j <= n; ++j) {\n AL[j] = ifac[j];\n }\n for (int j = 0; j <= n; ++j) {\n AR[j] = (j & 1)? Sub(0, ifac[j]) : ifac[j];\n }\n Poly A = PO::Poly_mul(AL, AR);\n A.resize(n + 1);\n for (int i = 0; i <= n; ++i) {\n A[i] = Mul(A[i], Mul(fac[n], ifac[n - i]));\n }\n\n int ans = 0;\n for (int i = k; i <= n * 2; ++i) {\n int tmp = 0;\n for (int j = k; j <= min(i, n); ++j) {\n tmp = ((i - j) & 1? Sub : Add)(tmp, Mul(Mul(A[j], pw2[j]), Ch(j, i - j)));\n }\n ans = Add(ans, Mul(tmp, inv[i + 1]));\n }\n printf(\"%d\\n\", Mul(ans, l));\n \n return 0;\n}", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064"} {"source_code": "#include \n\ntypedef long long s64; \n\nconst int mod = 998244353; \nconst int MaxN = 1e6 + 5; \n\nint n, ans; \nint fac[MaxN], inv[MaxN], pw[MaxN], f[MaxN]; \n\ninline void add(int &x, const int &y)\n{\n\tx += y; \n\tx >= mod ? x -= mod : 0; \n\tx < 0 ? x += mod : 0; \n}\n\ninline int qpow(int a, s64 b)\n{\n\tint res = 1; \n\tfor (; b; b >>= 1, a = 1LL * a * a % mod)\n\t\tif (b & 1)\n\t\t\tres = 1LL * res * a % mod; \n\treturn res; \n}\n\ninline int C(int n, int m)\n{\n\tif (n < 0 || m < 0 || n < m)\n\t\treturn 0; \n\treturn 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod; \n}\n\nint main()\n{\n//\tfreopen(\"matrix.in\", \"r\", stdin); \n//\tfreopen(\"matrix.out\", \"w\", stdout); \n\t\n\tstd::cin >> n; \n\t\n\tpw[0] = fac[0] = 1; \n\tfor (int i = 1; i <= n; ++i)\n\t{\n\t\tpw[i] = 3LL * pw[i - 1] % mod; \n\t\tfac[i] = 1LL * fac[i - 1] * i % mod; \n\t}\n\tinv[n] = qpow(fac[n], mod - 2); \n\tfor (int i = n - 1; i >= 0; --i)\n\t\tinv[i] = 1LL * inv[i + 1] * (i + 1) % mod; \n\t\n\tint ind = qpow(pw[n], mod - 2); \n\tfor (int i = 1; i <= n; ++i)\n\t{\n\t\tint tmp = 1LL * pw[i] * ind % mod; \n\t\tint res = qpow((tmp + mod - 1) % mod, n); \n\t\tif (n & 1)\n\t\t\tres = ((s64)mod * 2 - res - 1) % mod; \n\t\telse\n\t\t\tres = (res + mod - 1) % mod; \n\t\tres = 1LL * res * (i & 1 ? 1 : -1) * C(n, i) % mod * qpow(3, 1LL * n * (n - i) + 1) % mod; \n\t\tadd(ans, res); \n\t}\n\t\n\tfor (int i = 1; i <= n; ++i)\n\t{\n\t\tint type = i & 1 ? 1 : -1; \n\t\tint res = C(n, i); \n\t\tadd(ans, 1LL * type * qpow(3, 1LL * n * (n - i) + i) % mod * res % mod); \n\t\tadd(ans, 1LL * type * qpow(3, 1LL * n * (n - i) + i) % mod * res % mod); \n\t}\n\t\n\tstd::cout << ans << std::endl;\n\t\n\tfclose(stdin); \n\tfclose(stdout); \n\treturn 0; \n}", "src_uid": "6e4b0ee2e1406041a961582ead299a3a"} {"source_code": "#include \n#include \n#include \n#include \n#include \n\nstruct Vertex {\n\tbool init;\n\tstd::string s; //name of initial var or operator\n\tVertex *lhs, *rhs;\n\n\tbool calced;\n\tstd::string ssa;\n\n\tVertex(): init(false), lhs(nullptr), rhs(nullptr), calced(false), ssa(\"\") {}\n\tfriend bool operator== (const Vertex &a, const Vertex &b) {\n\t\treturn\n\t\t\t(a.init == b.init) &&\n\t\t\t(a.s == b.s) &&\n\t\t\t(a.lhs == b.lhs) &&\n\t\t\t(a.rhs == b.rhs)\n\t\t;\n\t}\n};\n\nstd::set initS;\nstd::string nextSSA = \"acaa\";\n\nstd::string get_ssa() {\n\twhile (true) {\n\t\tnextSSA[0]++;\n\t\tfor (uint32_t i = 0;i < nextSSA.size();i++) {\n\t\t\tif (nextSSA[i] > 'z') {\n\t\t\t\tnextSSA[i + 1]++;\n\t\t\t\tnextSSA[i] = 'a';\n\t\t\t}\n\t\t}\n\t\tif (initS.find(nextSSA) == initS.end()) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn nextSSA;\n}\n\nconst uint32_t MAX_V = 5000;\n\nVertex vertMem[MAX_V];\nVertex *vertPtr = vertMem;\n\nstd::map curV;\n\nVertex *get_vertex() {\n\treturn vertPtr++;\n}\nVertex *get_vertex(const std::string &s) {\n\tauto it = curV.find(s);\n\tif (it == curV.end()) {\n\t\tVertex *ans = get_vertex();\n\n\t\tans->ssa = s;\n\t\tans->init = true;\n\t\tinitS.insert(s);\n\t\tstd::cerr << \"Vertex \" << ans - vertMem << \" initial \" << s << \"\\n\";\n\n\t\tcurV[s] = ans;\n\t\treturn ans;\n\t} else {\n\t\treturn it->second;\n\t}\n}\n\nstd::vector rawP;\n\nvoid input() {\n\tstd::ios::sync_with_stdio(false);\n\tstd::cin.tie(nullptr);\n\n\tuint32_t n;\n\tstd::cin >> n;\n\trawP.resize(n);\n\tfor (std::string &s : rawP) {\n\t\tstd::cin >> s;\n\t}\n}\n\nbool is_opr(char c) {\n\treturn (c == '$') || (c == '^') || (c == '#') || (c == '&') || (c == '=');\n}\n\nstd::vector tokenize(const std::string &s) {\n\tstd::vector ans;\n\tstd::string curS = \"\";\n\tbool op = false;\n\tfor (uint32_t i = 0;i < s.size();i++) {\n\t\tbool curOp = is_opr(s[i]);\n\t\tif (op == curOp) {\n\t\t\tcurS += s[i];\n\t\t} else {\n\t\t\tans.push_back(curS);\n\t\t\top = curOp;\n\t\t\tcurS = s[i];\n\t\t}\n\t}\n\tans.push_back(curS);\n\treturn ans;\n}\n\nvoid build_dag() {\n\tfor (const std::string &s : rawP) {\n\t\tauto l = tokenize(s);\n\n\t\tif (l.size() == 3) { // assignment\n\t\t\tVertex *v = get_vertex(l[2]);\n\t\t\tcurV[l[0]] = v;\n\t\t} else { //operation\n\t\t\tVertex *v = get_vertex();\n\t\t\tv->s = l[3];\n\t\t\tv->lhs = get_vertex(l[2]);\n\t\t\tv->rhs = get_vertex(l[4]);\n\n\t\t\tfor (Vertex *u = vertMem;u != vertPtr;u++) {\n\t\t\t\tif ((*u) == (*v)) {\n\t\t\t\t\tif (v == u) {\n\t\t\t\t\t\tstd::cerr << \"vertex \" << u - vertMem << \": \";\n\t\t\t\t\t\tstd::cerr << \"lhs \" << u->lhs - vertMem;\n\t\t\t\t\t\tstd::cerr << \" opr \" << u->s;\n\t\t\t\t\t\tstd::cerr << \" rhs \" << u->rhs - vertMem << \"\\n\";\n\n\t\t\t\t\t}\n\t\t\t\t\tcurV[l[0]] = u;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nstd::vector optP;\n\nvoid build_program(Vertex *v) {\n\tif ((v->calced) || (v->init)) {\n\t\treturn;\n\t} else {\n\t\tbuild_program(v->lhs);\n\t\tbuild_program(v->rhs);\n\t\tif (v->ssa.empty()) {\n\t\t\tv->ssa = get_ssa();\n\t\t}\n\t\toptP.push_back(v->ssa + \"=\" + v->lhs->ssa + v->s + v->rhs->ssa);\n\t\tv->calced = true;\n\t}\n}\n\nint main() {\n\tinput();\n\tbuild_dag();\n\tauto it = curV.find(\"res\");\n\tif (it != curV.end()) {\n\t\tif ((it->second->init) && (it->second->ssa != \"res\")) {\n\t\t\toptP.push_back(\"res=\" + it->second->ssa);\n\t\t} else {\n\t\t\tit->second->ssa = \"res\";\n\t\t\tbuild_program(it->second);\n\t\t}\n\t}\n\tstd::cout << optP.size() << \"\\n\";\n\tfor (const std::string &s : optP) {\n\t\tstd::cout << s << \"\\n\";\n\t}\n}\n\n", "src_uid": "da40321d92baaef42c2840e45599294c"} {"source_code": "#include \n\nint main(){\n int num, base = 0, aux, i = 1, extra;\n scanf(\"%d\", &num);\n\n do{\n aux = 5*i;\n if(aux + base < num){\n base += aux;\n i *= 2;\n }\n }while(aux + base < num);\n\n extra = num - base;\n\n if(num <= base + i){\n printf(\"Sheldon\\n\");\n }\n else if(num <= base + (i * 2)){\n printf(\"Leonard\\n\");\n }\n else if(num <= base + (i * 3)){\n printf(\"Penny\\n\");\n }\n else if(num <= base + (i * 4)){\n printf(\"Rajesh\\n\");\n }\n else if(num <= base + (i * 5)){\n printf(\"Howard\\n\");\n }\n\n return 0;\n}\n", "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\n\tconst int N = 100000;\n\tint temp[N + 1];\n\tvector prime;\n\nint main()\n{\n\t//freopen(\"input.txt\", \"r\", stdin);\n\t//freopen(\"output.txt\", \"w\", stdout);\n\n\tint n;\n\tcin >> n;\n\n\tbool flag = true;\n\tfor (int i = 2; i*i <= n; i++)\n\t{\n\t\tif (n % i == 0)\n\t\t{\n\t\t\tflag = false;\n\t\t}\n\t}\n\n\tif (flag)\n\t{\n\t\tcout << 1 << \"\\n\" << n;\n\t\treturn 0;\n\t}\n\n\tflag = true;\n\tfor (int i = 2; i*i <= n - 2; i++)\n\t{\n\t\tif ((n - 2) % i == 0)\n\t\t{\n\t\t\tflag = false;\n\t\t}\n\t}\n\n\tif (flag)\n\t{\n\t\tcout << 2 << \"\\n\" << 2 << \" \" << n - 2;\n\t\treturn 0;\n\t}\n\n\tcout << 3 << endl;\n\n\tint up = min(n - 1, N);\n\n\tfor (int i = 2; i <= up; i++)\n\t{\n\t\tif (temp[i] == 0)\n\t\t{\n\t\t\ttemp[i] = i;\n\t\t\tprime.push_back(i);\n\t\t}\n\t\tfor (int j = 0; j < prime.size() && prime[j] <= temp[i] && i * prime[j] <= up; j++)\n\t\t{\n\t\t\ttemp[i * prime[j]] = prime[j];\n\t\t}\n\t}\n\n\tvector check(up + 1, false);\n\n\tfor (int i = 0; i < prime.size(); i++)\n\t{\n\t\tcheck[prime[i]] = true;\n\t}\n\n\tfor (int x = n - 3; ;x--)\n\t{\n\t\tbool pr = true;\n\t\tfor (int i = 2; i*i <= x; i++)\n\t\t{\n\t\t\tif (x % i == 0)\n\t\t\t{\n\t\t\t\tpr = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (pr)\n\t\t{\n\t\t\tcout << x << \" \";\n\t\t\tn -= x;\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tfor (int i = 0; i < prime.size(); i++)\n\t{\n\t\tif (check[n - prime[i]])\n\t\t{\n\t\t\tcout << prime[i] << \" \" << n - prime[i];\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\n\n\n\treturn 0;\n}", "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"} {"source_code": "#include \n#include \n#include \n\nusing namespace std;\n\nconst int LIMIT = 1000000;\n\ntypedef pair PII;\nPII p[LIMIT];\nvector v;\n\ninline bool pr(const PII& lhs, const PII& rhs) {\n return atan2(lhs.second, lhs.first) < atan2(rhs.second, rhs.first) - 1e-8;\n}\n\ninline int R(const PII& p) { return p.first * p.first + p.second * p.second; }\n\nint main() {\n int n, s, x, y, nx, ny, tx, ty, dx, dy;\n\n scanf(\"%d\", &n);\n for (int i = 0, ii; (ii = i * i) < LIMIT; ++i) {\n for (int j = i, jj; (jj = i * i + j * j) < LIMIT; ++j) {\n p[jj].first = i;\n p[jj].second = j;\n }\n }\n\n s = 0;\n for (int i = 0; i < LIMIT && (int)v.size() <= n; ++i) {\n if (p[i].first != 0 || p[i].second != 0) {\n s += R(p[i]);\n v.push_back(p[i]);\n }\n }\n\n reverse(v.begin(), v.end());\n for (vector::iterator it = v.begin(); it != v.end(); ++it) {\n if ((s - R(*it)) % 2 == 0) {\n v.erase(it);\n break;\n }\n }\n\n x = y = 0;\n for (vector::iterator it = v.begin(); it != v.end(); ++it) {\n nx = ny = LIMIT;\n dx = it->first;\n dy = it->second;\n for (int i = 0; i < 2; ++i) {\n for (int j = 0; j < 2; ++j) {\n for (int k = 0; k < 2; ++k) {\n tx = x + dx;\n ty = y + dy;\n if (abs(tx) + abs(ty) < abs(nx) + abs(ny)) {\n nx = tx;\n ny = ty;\n *it = make_pair(dx, dy);\n }\n dx = -dx;\n }\n dy = -dy;\n }\n swap(dx, dy);\n }\n x = nx;\n y = ny;\n }\n\n sort(v.begin(), v.end(), pr);\n x = y = 0;\n puts(\"YES\");\n for (vector::iterator it = v.begin(); it != v.end(); ++it) {\n printf(\"%d %d\\n\", x, y, atan2(it->second, it->first));\n x += it->first;\n y += it->second;\n }\n if (x != 0 || y != 0) {\n throw 1;\n }\n\n return 0;\n}", "src_uid": "77b281558c480607b02e8e263e81a455"} {"source_code": "#include \n#include \n#include \n#include \n\nint main() {\n int n, m, d;\n std::cin >> n >> d;\n std::vector a(n);\n for (auto &e: a) {\n std::cin >> e;\n } \n std::cin >> m;\n std::sort(a.begin(), a.end());\n int ans = 0;\n if (m > n) {\n for (auto &e :a) {\n ans += e;\n }\n ans -= (m - n) * d; \n } else {\n for (int i = 0; i < m; ++i) {\n ans += a[i];\n }\n }\n \n std::cout << ans;\n}", "src_uid": "5c21e2dd658825580522af525142397d"} {"source_code": "#include \nusing namespace std;\n\nint main(int argc, char** argv) {\n ios_base::sync_with_stdio(false);\n#ifdef IN_FILE\n ifstream in_file(argv[1]);\n auto sbuf = cin.rdbuf(in_file.rdbuf());\n#endif\n\n int n;\n cin >> n;\n string s(to_string(n));\n vector nl;\n while (1) {\n string ns;\n bool zeros = true;\n for (int i = 0; i < s.length(); ++i) {\n if (s[i] > '0') {\n ns += '1';\n s[i] -= 1;\n zeros = false;\n } else {\n ns += '0';\n }\n }\n\n if (zeros) {\n break;\n }\n\n nl.push_back(stoi(ns));\n }\n\n cout << nl.size() << \"\\n\";\n copy(nl.begin(), nl.end(), ostream_iterator(cout, \" \"));\n cout << endl;\n\n#ifdef IN_FILE\n cin.rdbuf(sbuf);\n in_file.close();\n#endif\n\n return 0;\n}", "src_uid": "033068c5e16d25f09039e29c88474275"} {"source_code": "#include\nusing namespace std;\nint main(){\n int x,y,z,a=2,b;\n cin>>x>>y>>z;\n while(z>0){\n if(a%2==0){\n for(int i=1;i<=x;i++){\n if((x%i==0)&&(z%i==0)){\n b=i;}\n } \n }\n else {\n for(int i=1;i<=y;i++){\n if((y%i==0)&&(z%i==0)){\n b=i;}\n } \n }\n z-=b;\n a++;\n }\n if(a%2==0){\n cout<<\"1\";\n }\n else cout<<\"0\";\n return 0;\n}", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"source_code": "#include\n#define ll long long\nusing namespace std;\nconst int maxn=1e5+10,mod=1e9+7;\nint a[maxn],b[maxn],c[maxn],vis[maxn],cur[maxn],x,d,n;\nint getNextX() {\n x = (1ll*x * 37 + 10007) % 1000000007;\n return x;\n}\nvoid initAB() {\n\tint i;\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}\nstruct node\n{\n\tint v,id;\n\tnode(int x,int y){v=x,id=y;}\n\tbool operator<(const node&t)const\n\t{\n\t\treturn vq;\nint main()\n{\n\tscanf(\"%d%d%d\",&n,&d,&x);\n\tinitAB();\n\tint cnt=0;\n\tfor(int i=0;i\n#include \n#include \n#include \n\nusing namespace std;\n\nlong long perevod (int n, int *ax, int x)\n{\n long long res=0;\n int t=n;\n for (int i=0;i>n>>x;\n for (i=0;i>ax[i];\n }\n cin>>n2>>y;\n for (i=0;i>by[i];\n }\n long long res1=perevod(n,ax,x);\n long long res2=perevod(n2,by,y);\n if (res1res2) cout<<'>';\n else cout<<'=';\n}", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"} {"source_code": "#include \n#define str string\n#define ill int long long\n#define it int64_t\n#define ll long long\n#define ft float\n#define de double \nusing namespace std;\nint main()\n{\n str a,b,c,d,e,f;\n cin>>a>>b>>c>>d>>e>>f;\n if (a[0] == b[0] || a[0] == c[0] || a[0] == d[0] || a[0] == e[0] || a[0] == f[0])cout<<\"YES\"<\n#include\n#include\nusing namespace std;\nint dp[505][505];\nstring s;\nint helper(int i,int j)\n{ if(i==j)\n return 1;\n if(i>j)\n return 0;\n if(dp[i][j]!=-1)\n return dp[i][j];\n \n dp[i][j]=1000;\n dp[i][j]=min(dp[i][j],1+helper(i+1,j));\n int k;\n for(k=i+1;k<=j;k++)\n {\n if(s[k]==s[i])\n \n dp[i][j]=min(dp[i][j],helper(i+1,k-1)+helper(k,j));\n }\nreturn dp[i][j];\n \n \n}\nint main()\n{\n int n,i,j;\n \n cin>>n>>s;\n memset(dp, -1, sizeof dp);\n cout<\n#include \n#include \n#include \nusing namespace std;\n\n\nlong long b,s,c,nb,nc,ns,pb,pc,ps,money;\nbool check(long long mid){\n\tlong long n=0;\n\tif(mid*b>nb)n+=(mid*b-nb)*pb;\n\tif(mid*s>ns)n+=(mid*s-ns)*ps;\n\tif(mid*c>nc)n+=(mid*c-nc)*pc;\n\treturn n<=money;\n}\nint main() {\n\tchar a[110];\n\tcin>>a+1;\n\tlong long len=strlen(a+1);\n\tcin>>nb>>ns>>nc;\n\tcin>>pb>>ps>>pc;\n\tcin>>money;\n\tfor(long long i=1;i<=len;i++){\n\t\tif(a[i]=='B')b++;\n\t\telse if(a[i]=='C')c++;\n\t\telse s++;\n\t}\n\tlong long l=0,r=money+max(nb,max(nc,ns));\n\twhile(l<=r){\n\t\tlong long mid=l+r>>1;\n\t\tif(check(mid)){\n\t\t\tl=mid+1;\n\t\t}\n\t\telse r=mid-1;\n\t}\n\tprintf(\"%lld\",r);\n\treturn 0;\n}\n", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"} {"source_code": "#include \nusing namespace std;\nint main()\n{\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n int a[100],n,i,j,b=0,c,d;\n cin>>n;\n for(i=0; i>a[i];\n b=b+a[i];\n }\n\n b=b/(n/2);\n\n for(i=0; i\nusing namespace std;\nusing ull = unsigned long long;\n\null bad(ull n, ull m) {\n\tvector dp(n+2);\n\tull total = 0;\n\tdp[1] = 1;\n\tdp[2] = 2;\n\ttotal = 3;\n \n\tfor (int i = 3; i <= n; i++) {\n\t\tdp[i] = (total)%m;\n \n\t\tfor (int j = 2; j <= i; j++) {\n\t\t\tdp[i] = (dp[i]+ dp[i/j])%m;\n\t\t}\n \n\t\ttotal = (total+dp[i]) % m;\n\t}\n \n\treturn dp[n];\n}\null good(ull n, ull m) {\n\tvector dp(n+2);\n\tull total = 0;\n\tdp[1] = 1;\n\tdp[2] = 2;\n\ttotal = 3;\n\n\tfor (ull i = 3; i <= n; i++) {\n\t\tdp[i] = total;\n\n\t\tull s = sqrt(i)+1;\n\t\tfor (ull j = 1; j <= s; j++) {\n\t\t\tif (j*j < i) {\n\t\t\t\tdp[i] = (dp[i] + ((i/j-i/(j+1))*dp[j]))%m;\n\t\t\t}\n\t\t\tif (j > 1 && ((i/j)*(i/j)) >= i) {\n\t\t\t\tdp[i] = (dp[i] + dp[i/j])%m;\n\t\t\t}\n\t\t}\n\n\t\ttotal = (total+dp[i]) % m;\n\t}\n\n\treturn dp[n];\n}\n\nint main() {\n\tull n, m; cin >> n >> m;\n\tcout << good(n, m) << endl;\n}\n", "src_uid": "a524aa54e83fd0223489a19531bf0e79"} {"source_code": "#include \n\nusing namespace std;\n\nint main(){\n\n long long l1,l2,r1,r2,k;\n cin>>l1>>r1>>l2>>r2>>k;\n\n long long lmax,rmin;\n\n if(l1>l2){\n lmax=l1;\n }\n else{\n lmax=l2;\n }\n\n if(r1>r2){\n rmin=r2;\n }\n else{\n rmin=r1;\n }\n\n long long ln;\n\n //cout<=lmax){\n ln = rmin - lmax + 1;\n }\n else{\n ln=0;\n }\n\n if(k>=lmax && k<=rmin &&ln>0){\n ln=ln-1;\n }\n\n cout<\n#include \n#include \n#include \nusing namespace std;\n/* run this program using the console pauser or add your own getch, system(\"pause\") or input loop */\n\nint n;\nchar original1[15][15],original2[15][15],temp[15][15];\nbool check;\n\nvoid theSame(char table[15][15]){\n\tbool tempCheck=true;\n\t\n\tfor(int i=0; i\nint main()\n{\n int a, b;\n std::cin >> a >> b;\n std::cout << (a == b ? a : 2) << std::endl;\n return 0;\n}", "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n long long x,ct=0,a,b,aux;\n scanf(\"%lld\",&x);\n a=2;\n ct=2;b=3;\n if(x<3) printf(\"1\");\n else if(x<5) printf(\"2\");\n else {\n while(x>=b)\n {\n ct++;\n aux=a;a=b;b=b+aux;\n }\n printf(\"%lld\",ct-1);\n }\n}\n", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"source_code": "#include \n\nusing namespace std;\nusing ll = long long;\n\nint main() {\n\tint n; scanf(\"%d\", &n);\n\tint baseSize = 1;\n\twhile (2 * baseSize + 1 <= n) baseSize = baseSize * 2 + 1;\n\tvector color(baseSize + 1);\n\tfor (int i = 2; i <= baseSize; ++i) color[i] = color[i >> 1] ^ (~i & 1);\n\tint k = 0;\n\tfor (int i = 1; i <= baseSize / 2; ++i) {\n\t\tint nextLeaf = i * 2 + 1;\n\t\twhile (2 * nextLeaf <= baseSize) nextLeaf = 2 * nextLeaf;\n\t\tif (color[nextLeaf] == color[i]) ++k;\n\t}\n\tif (n == k + baseSize || n == k + baseSize + 1) printf(\"1\\n\");\n\telse printf(\"0\\n\");\n\treturn 0;\n}\n", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define ll long long\n#define the_num 1000000007\n#define ano_num 998244353\n#define forn(n) for(int i=0;i=0;i--)\n#define test int t;cin >> t;while(t--)\n#define all(v) v.begin(),v.end()\n#define in_arr(arr,n) int arr[n];forn(n) cin >> arr[i];\n#define invec(arr,n) vector arr(n); forn(n) cin >> arr[i];\n#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n#define take(data_type,n) data_type n;cin >> n;\n#define test int t;cin >> t;while(t--)\nint mint = 100000000;\n//cout.precision(100);\nint eightno(int c)\n{\n int count = 0;\n int d = abs(c);\n while (d != 0)\n {\n int rem = d % 10;\n if (rem == 8)\n count++;\n d = d / 10;\n }\n return count;\n\n}\nint main()\n{\n int a; cin >> a;\n int b = 1;\n if ((eightno(a) == 2 && a%10!=8) || eightno(a)>2)\n {\n cout << \"1\";\n }\n else\n {\n while (eightno(a + b) != 1)\n {\n b = b + 1;\n }\n\n cout << b;\n }\n return 0;\n}\n\n\n\n\n\n\n\n\n\n\n\n", "src_uid": "4e57740be015963c190e0bfe1ab74cb9"} {"source_code": "#include\nusing namespace std;\n\n#include \n#include \nusing namespace __gnu_pbds; \n\n#define ll long long\n#define db double\n#define el \"\\n\"\n#define ld long double\n#define rep(i,n) for(int i=0;i=0;i--)\n#define rep_a(i,a,n) for(int i=a;i vi;\ntypedef pair ii;\ntypedef priority_queue pq;\n#define o_set tree, rb_tree_tag,tree_order_statistics_node_update> \n#define graph vector\n\nconst ll mod = 1000000007;\nconst ll INF = (ll)1e18;\nconst ll MAXN = 1000006;\n\nll po(ll x, ll n ){ \n ll ans=1;\n while(n>0){\n if(n&1) ans=(ans*x)%mod;\n x=(x*x)%mod;\n n/=2;\n }\n return ans;\n}\n\n\n\nint main(){\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n #ifndef ONLINE_JUDGE\n freopen(\"input.txt\", \"r\" , stdin);\n freopen(\"output.txt\", \"w\" , stdout);\n #endif\n int T=1;\n //cin >> T;\n while(T--){\n int n;\n cin>>n;\n vector > v;\n ll l,r;\n rep(i,n){\n cin>>l>>r;\n v.pb(mp(l,r));\n }\n ld ans=0, tmp, tmp1,tmp2, tmp3;\n rep_a(i,1 ,10001){\n rep_a(j,1,(1< > z;\n rep(k,n){\n if(((j>>k)&1) && (v[k].ff<=i && v[k].ss>=i)){\n tmp*=1/(ld)(v[k].ss-v[k].ff+1);\n }\n else if((j>>k)&1) tmp=0;\n else{\n z.pb(mp(max(min(i-1, v[k].ss)-v[k].ff+1, 0), max(0, v[k].ss+1-max(i+1, v[k].ff))));\n tmp2*=(v[k].ss-v[k].ff+1);\n tmp3*=max(min(i-1, v[k].ss)-v[k].ff+1, 0);\n }\n }\n if(tmp==0) continue;\n // if(tmp>0) cout<\nusing namespace std;\nint sum(int a)\n{\n int x=0;\n while(a>0)\n {\n x=x+a%10;\n\n a=a/10;\n\n }\n return x;\n}\nint main()\n{\n int m;\n cin>>m;\n int a=sum(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#include \n#include \n\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\nconst int N = 1000001;\nconst ll MOD = 1e9 + 7;\n\nint main() {\n\tll x2;\n\tscanf(\"%lld\",&x2);\n\t\n\tll mn = 1e18, c = x2;\n\tfor(ll i=2; i*i<=c; i++)\n\t\tif(c%i==0) {\n\t\t\tmn = min(mn, x2-i+1);\n\t\t\twhile(c%i==0)\n\t\t\t\tc /= i;\n\t\t}\n\tif(c>1) mn = min(mn, x2-c+1);\n\t\n\tll ans = 1e18;\n\tfor(ll x1=mn; x1<=x2; x1++) {\n\t\tc = x1;\n\t\tfor(ll i=2; i*i<=c; i++) {\n\t\t\tif(c%i==0) {\n\t\t\t\tans = min(ans, x1-i+1);\n\t\t\t\twhile(c%i==0)\n\t\t\t\t\tc /= i;\n\t\t\t}\n\t\t}\n\t\tif(x1!=c && c>1) ans = min(ans, x1-c+1);\n\t}\n\t\n\tprintf(\"%lld\\n\", ans);\n\treturn 0;\n}", "src_uid": "43ff6a223c68551eff793ba170110438"} {"source_code": "#include\nusing namespace std;\n\nint main(){\n\tint w,h,k;\n\tcin>>w>>h>>k;\n\tint sum=0;\n\tfor(int i=1;i<=k;i++){\n\t\tsum+=(w+w+h+h-4);\n\t\tw-=4;\n\t\th-=4;\n\t}\n\tcout<\n#include\n#include\n#include\n#include\n#define ll long long\n#define ff first\n#define ss second\n#define pb push_back\n#define mp make_pair\n#include\n#define ws \" \"\n#define nl \"\\n\"\n#define tc ll test; cin>>test; while(test--)\n#define f(i, a, b) for(ll i = a; i\nbool compare(pll a, pll b)\n{\n\t//for descending order replace with a.roll >b.roll\n if((a.ff < b.ff)||((a.ff==b.ff)&&a.ss 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}\nvoid solve()\n{\n string s;\n cin>>s;\n\n int i = 0;\n string st = \"\";\n\n while(s[i]!='\\0')\n {\n\n if(s[i]=='>')\n st+=\"1000\";\n else if(s[i]=='<')\n st+=\"1001\";\n else if(s[i]=='+')\n st+=\"1010\";\n else if(s[i]=='-')\n st+=\"1011\";\n else if(s[i]=='.')\n st+=\"1100\";\n else if(s[i]==',')\n st+=\"1101\";\n else if(s[i]=='[')\n st+=\"1110\";\n else\n st+=\"1111\";\n\n i++;\n }\n\n\n reverse(st.begin(), st.end());\n ll ans = 0;\n\n f(i, 0, st.size())\n {\n if(st[i]=='1')\n ans+=power(2, i, 1000003);\n // ans%=1000003;\n }\n\n cout< n)\n break;\n ll cnt = 1; // cnt is power of prime a[i] in n.\n while (n % a[i] == 0) // if a[i] is a factor of n\n {\n n = n / a[i];\n cnt = cnt + 1; // incrementing power\n }\n\n ans = ans * cnt;\n }\n if (prime[n])\n ans = ans * 2;\n\n // Second case\n else if (primesquare[n])\n ans = ans * 3;\n\n // Third casse\n else if (n != 1)\n ans = ans * 4;\n\n return ans; // Total divisors\n}\n\nbool checkPrime(ll n)\n{\n // Corner cases\n if (n <= 1) return false;\n if (n <= 3) return true;\n\n // This is checked so that we can skip\n // middle five numbers in below loop\n if (n%2 == 0 || n%3 == 0) return false;\n\n for (ll i=5; i*i<=n; i=i+6)\n if (n%i == 0 || n%(i+2) == 0)\n return false;\n\n return true;\n}\n", "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"source_code": "#include \n\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\nusing ld = long double;\n#define all(x) x.begin(), x.end()\n#define left left228\n#define right right228\ntemplate inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}\ntemplate inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}\n\nstruct triple{\n\tint x, y, z;\n\ttriple() {}\n\ttriple(int _x, int _y, int _z) {\n\t\tx = _x, y = _y, z = _z;\n\t}\n};\n\nint n, m, k;\n\nvector> up, down, left, right, top, bottom;\n\nvoid Read(vector> & have, int a, int b) {\n\thave.resize(a, vector (b));\n\tfor (auto &i : have)\n\t\tfor (auto &j : i)\n\t\t\tcin >> j;\n}\n\nvoid read() {\n\tcin >> n >> m >> k;\n\tRead(left, m, k);\n\tRead(right, m, k);\n\tRead(top, n, k);\n\tRead(bottom, n, k);\n\tRead(down, n, m);\n\tRead(up, n, m);\n}\n\nbool operator==(const triple & a, const triple & b) {\n\treturn tie(a.x, a.y, a.z) == tie(b.x, b.y, b.z);\n}\n\nvector>> par[3];\nvector>> Min[3], Max[3];\n\ntriple get_par(triple a, int it) {\n\tif (a == par[it][a.x][a.y][a.z]) return a;\n\treturn par[it][a.x][a.y][a.z] = get_par(par[it][a.x][a.y][a.z], it);\n}\n\nvoid uni(triple a, triple b, int it) {\n\ta = get_par(a, it);\n\tb = get_par(b, it);\n\tif (a == b) return;\n\tpar[it][b.x][b.y][b.z] = a;\n\tchkmin(Min[it][a.x][a.y][a.z], Min[it][b.x][b.y][b.z]);\n\tchkmax(Max[it][a.x][a.y][a.z], Max[it][b.x][b.y][b.z]);\n}\n\nvoid no() {\n\tcout << -1 << endl;\n\texit(0);\n}\n\nvector>> used;\nqueue q;\n\nint get_color(int x, int y, int z) {\n\tset color;\n\ttriple a;\n\t\n\t// get_left\n\tif (x != 0) {\n\t\ta = {x - 1, y, z};\n\t\ta = get_par(a, 0);\n\t}\n\tif (x == 0 || (Min[0][a.x][a.y][a.z] == 0 && used[x - 1][y][z])) {\n\t\tcolor.insert(left[y][z]);\n\t}\n\n\t// get_right\n\tif (x != n - 1) {\n\t\ta = {x + 1, y, z};\n\t\ta = get_par(a, 0);\n\t}\n\tif (x == n - 1 || (Max[0][a.x][a.y][a.z] == n - 1 && used[x + 1][y][z])) {\n\t\tcolor.insert(right[y][z]);\n\t} \n\n\t// get top\n\tif (y != 0) {\n\t\ta = {x, y - 1, z};\n\t\ta = get_par(a, 1);\n\t}\n\tif (y == 0 || (Min[1][a.x][a.y][a.z] == 0 && used[x][y - 1][z])) {\n\t\tcolor.insert(top[x][z]);\n\t}\n\n\t// get bottom\n\tif (y != m - 1) {\n\t\ta = {x, y + 1, z};\n\t\ta = get_par(a, 1);\n\t}\n\tif (y == m - 1 || (Max[1][a.x][a.y][a.z] == m - 1 && used[x][y + 1][z])) {\n\t\tcolor.insert(bottom[x][z]);\n\t}\n\n\t// get down\n\tif (z != 0) {\n\t\ta = {x, y, z - 1};\n\t\ta = get_par(a, 2);\n\t}\n\tif (z == 0 || (Min[2][a.x][a.y][a.z] == 0 && used[x][y][z - 1])) {\n\t\tcolor.insert(down[x][y]);\n\t}\n\t\n\t// get up\n\tif (z != k - 1) {\n\t\ta = {x, y, z + 1};\n\t\ta = get_par(a, 2);\n\t}\t\n\tif (z == k - 1 || (Max[2][a.x][a.y][a.z] == k - 1 && used[x][y][z + 1])) {\n\t\tcolor.insert(up[x][y]);\n\t}\n\n\tif (color.empty()) return -1;\n\tif (color.size() >= 2) return 0;\n\treturn *color.begin();\n}\n\nvoid build() {\n\tused.assign(n, vector> (m, vector (k, false)));\n\tfor (int i = 0; i < 3; i++) {\n\t\tpar[i].resize(n, vector> (m, vector (k)));\n\t\tMin[i].resize(n, vector> (m, vector (k)));\n\t\tMax[i].resize(n, vector> (m, vector (k)));\n\t}\n\tfor (int x = 0; x < n; x++) {\n\t\tfor (int y = 0; y < m; y++) {\n\t\t\tfor (int z = 0; z < k; z++) {\n\t\t\t\tfor (int it = 0; it < 3; it++) {\n\t\t\t\t\tpar[it][x][y][z] = {x, y, z};\n\t\t\t\t}\n\t\t\t\tMin[0][x][y][z] = x;\n\t\t\t\tMax[0][x][y][z] = x;\n\t\t\t\tMin[1][x][y][z] = y;\n\t\t\t\tMax[1][x][y][z] = y;\n\t\t\t\tMin[2][x][y][z] = z;\n\t\t\t\tMax[2][x][y][z] = z;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (int x = 0; x < n; x++) {\n\t\tfor (int y = 0; y < m; y++) {\n\t\t\tfor (int z = 0; z < k; z++) {\n\t\t\t\tif (!get_color(x, y, z)) {\n\t\t\t\t\tq.push({x, y, z});\n\t\t\t\t\tused[x][y][z] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvector dx = {-1, 1, 0, 0, 0, 0}; \nvector dy = {0, 0, -1, 1, 0, 0}; \nvector dz = {0, 0, 0, 0, -1, 1};\n\nbool check(int x, int y, int z) {\n\treturn x >= 0 && x < n && y >= 0 && y < m && z >= 0 && z < k;\n}\n\nvoid del(int x, int y, int z) {\n\tfor (int i = 0; i < 6; i++) {\n\t\tint nx = x + dx[i], ny = y + dy[i], nz = z + dz[i];\t\n\t\tif (!check(nx, ny, nz)) continue;\n\t\tif (!used[nx][ny][nz]) continue;\n\t\tuni({x, y, z}, {nx, ny, nz}, i / 2);\n\t}\n}\n\nvoid bfs() {\n\twhile (!q.empty()) {\n\t\tauto v = q.front();\n\t\tint x = v.x, y = v.y, z = v.z;\n\t\tq.pop();\n\t\tdel(x, y, z);\n\t\tfor (int i = 0; i < 6; i++) {\n\t\t\tint nx = x + dx[i], ny = y + dy[i], nz = z + dz[i];\n\t\t\tif (!check(nx, ny, nz)) continue;\n\t\t\tif (get_color(nx, ny, nz)) continue;\n\t\t\t\n\t\t\tif (used[nx][ny][nz]) {\n\t\t\t\tauto a = triple(nx, ny, nz);\n\t\t\t\ta = get_par(a, i / 2);\n\t\t\t\tif (i / 2 == 0) {\n\t\t\t\t\tif (i % 2 == 0) {\n\t\t\t\t\t\tnx = Min[i / 2][a.x][a.y][a.z] - 1;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tnx = Max[i / 2][a.x][a.y][a.z] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (i / 2 == 1) {\n\t\t\t\t\tif (i % 2 == 0) {\n\t\t\t\t\t\tny = Min[i / 2][a.x][a.y][a.z] - 1;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tny = Max[i / 2][a.x][a.y][a.z] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (i % 2 == 0) {\n\t\t\t\t\t\tnz = Min[i / 2][a.x][a.y][a.z] - 1;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tnz = Max[i / 2][a.x][a.y][a.z] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!check(nx, ny, nz)) continue;\n\t\t\t\tif (get_color(nx, ny, nz)) continue;\n\t\t\t}\n\t\t\tif (used[nx][ny][nz]) continue;\n\t\t\tused[nx][ny][nz] = true;\n\t\t\tq.push({nx, ny, nz});\n\t\t}\n\t}\n}\n\nvoid check_ans() {\n\tfor (int y = 0; y < m; y++) {\n\t\tfor (int z = 0; z < k; z++) {\n\t\t\tbool flag = false;\n\t\t\tfor (int x = 0; x < n; x++) {\n\t\t\t\tif (!used[x][y][z]) {\n\t\t\t\t\tflag = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!flag) {\n\t\t\t\tif (left[y][z] || right[y][z]) {\n\t\t\t\t\tno();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfor (int x = 0; x < n; x++) {\n\t\tfor (int z = 0; z < k; z++) {\n\t\t\tbool flag = false;\n\t\t\tfor (int y = 0; y < m; y++) {\n\t\t\t\tif (!used[x][y][z]) {\n\t\t\t\t\tflag = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!flag) {\n\t\t\t\tif (top[x][z] || bottom[x][z]) {\n\t\t\t\t\tno();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfor (int x = 0; x < n; x++) {\n\t\tfor (int y = 0; y < m; y++) {\n\t\t\tbool flag = false;\n\t\t\tfor (int z = 0; z < k; z++) {\n\t\t\t\tif (!used[x][y][z]) {\n\t\t\t\t\tflag = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!flag) {\n\t\t\t\tif (up[x][y] || down[x][y]) {\n\t\t\t\t\tno();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid run() {\n\tbuild();\n\tbfs();\n\tcheck_ans();\n}\n\nvoid write() {\n\tfor (int x = 0; x < n; x++) {\n\t\tfor (int y = 0; y < m; y++) {\n\t\t\tfor (int z = 0; z < k; z++) {\n\t\t\t\tint ans = get_color(x, y, z);\n\t\t\t\tif (ans == -1) ans = 0;\n\t\t\t\tif (used[x][y][z]) ans = 0;\n\t\t\t\tcout << ans << \" \";\n\t\t\t}\n\t\t}\n\t}\n\tcout << endl;\n}\n\nsigned main() {\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\tcout.tie(0);\n\tread();\n\trun();\n\twrite();\n\treturn 0;\n}", "src_uid": "cdacfb8b1ca4c88b576fa7b3cf71f8ec"} {"source_code": "#include \n#define rp(_s,_i,_n) for(int _s=_i;_s<_n;_s++)\n#define sz(_itt) (int)_itt.size()\n#define mp(__a,__b) make_pair(__a,__b)\n#define pb(_p) push_back(_p)\n#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n#define inf 1e9 + 7\nusing namespace std;\ntypedef long long ll;\nint main()\n{\n fastio\n\n int a,m;cin>>a>>m;\n if(a%m==0){cout << \"Yes\";return 0;}\n if(m%a==0&&m/a%2==0){\n int r=m/a;\n while(r%2==0){\n r/=2;\n }\n if(r==1){cout << \"Yes\";return 0;}\n }\n while(m%2==0){\n m/=2;\n }\n if(m==1){cout << \"Yes\";return 0;}\n cout << \"No\";\n}\n", "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "#include \nusing namespace std;\nlong long n,m;\nlong long a[30];\nlong long dp[30];\nint main(){\n\tcin >> n >> m;\n\tfor(int i = 0;i < n;i++){\n\t\tcin >> a[i];\n\t\tdp[i] = a[i];\n\t}\n\tfor(int i = 0;i < n;i++){\n\t\tfor(int j = 0;j <= i;j++){\n\t\t\tdp[i] = min(dp[i],(1ll << (i-j))*dp[j]);\n\t\t}\n\t}\n\tlong long fans = 0;\n\tlong long ans = 1ll << 60;\n\tfor(int i = n-1;i >= 0;i--){\n\t\tlong long L = m/(1ll << i);\n\t\tfans += L*dp[i];\n\t\tm %= (1ll << i);\n\t\tans = min(ans,fans+(m>0)*dp[i]);\n\t}\n\tcout << ans;\n\treturn 0;\n}", "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"source_code": "#include\nusing namespace std;\nint a,b,c;\nint main(){\n\tcin>>a>>b>>c;\n\tcout<\nusing namespace std;\n \nint main() {\n int n, m, a;\n \n cin >> n >> m;\n \n if (m - 1 >= n - m) {\n a = m - 1;\n }\n \n if (m - 1 < n - m) {\n a = m + 1;\n }\n \n if (a == 0) a++;\n \n cout << a << endl;\n \n return 0;\n}", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"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\nusing namespace std;\n\n#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)\n#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)\n\ntypedef long long ll;\n\n#define M 10000000\nint maxsq[M+10];\n\nint main(void){\n int i,j;\n \n for(i=1;i*i<=M;i++){\n int s = i*i;\n for(j=s;j<=M;j+=s) maxsq[j] = s;\n }\n \n int a,n;\n cin >> a >> n;\n \n ll ans = 0;\n for(i=a;i<=a+n-1;i++) ans += i / maxsq[i];\n cout << ans << endl;\n\n return 0;\n}", "src_uid": "915081861e391958dce6ee2a117abd4e"} {"source_code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define For(i, j, k) for(LL i = j; i <= k; i++)\n#define Forr(i, j, k) for(LL i = j; i >= k; i--)\n#define Set(i, v) memset(i, v, sizeof i)\n\nusing namespace std;\n\ntypedef long long LL;\n\nconst int N = 110, M = N * 60000;\n\ntypedef long long LL;\n\nLL k;\nint A[N], val[M], n, m;\n\nLL check(LL v){\n\tLL ret = 0;\n\tFor(i, 1, n) ret += A[i] % v == 0 ? 0 : v - A[i] % v;\n\treturn ret;\n}\n\nint main(){\n\tcin >> n >> k;\n\tLL sum = 0;\n\tFor(i, 1, n) cin >> A[i], sum += A[i];\n\tFor(i, 1, n){\n\t\tfor(int j = A[i], nxt; j; j = nxt) nxt = A[i] / (A[i] / j + 1), val[++m] = j + bool(A[i] % j);\n\t}\t\n\tval[++m] = 1;\n\tsort(val + 1, val + m + 1), m = int(unique(val + 1, val + m + 1) - val) - 1;\n\tLL ans = 1;\n\tFor(i, 1, m){\n\t\tLL delt = 0, x = val[i], s = 0, nxt = i == m ? 1e18: val[i + 1];\n\t\tFor(j, 1, n){\n\t\t\tdelt += (A[j] - 1) / x + 1;\n\t\t\ts += A[j] % x ? x - A[j] % x : 0;\n\t\t}\n\t\t//cout << x << ' ' << nxt << ' ' << s << ' ' << check(x) << ' ' << delt << endl;\n\t\tif(k >= s) ans = max(ans, min(x + (k - s) / delt, nxt - 1));\n\t}\n\tcout << ans << endl;\n\treturn 0;\n}\n", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60"} {"source_code": "#define _CRT_DISABLE_PERFCRIT_LOCKS\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 get() _getchar_nolock()\n#define put(c) _putchar_nolock(c)\n#define pb push_back\n#define mk make_pair\n#define fr first\n#define sc second\n\n#define xx real()\n#define yy imag()\n\ntemplate T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }\n\ntypedef long long ll;\ntypedef vector vi;\ntypedef pair pii;\ntypedef pair pll;\ntypedef vector vll;\n\n#define task \"rare\"\n#define file 0\n\nconst int maxn = 100100;\nint n, k;\nbool a[33];\nchar s[maxn];\nvoid fail(){\n puts(\"IMPOSSIBLE\");\n exit(0);\n}\nvoid solve(){\n scanf(\"%d %s\", &k, &s);\n n = strlen(s);\n if((n + 1) / 2 < k){\n puts(\"IMPOSSIBLE\");\n return;\n } \n \n for(int i = 0; i < n; i ++){\n if(s[i] == '?' && s[n - i - 1] != '?'){\n s[i] = s[n - i - 1];\n }\n if(s[i] != '?') a[s[i] - 'a'] = true; \n if(s[n - i - 1] != '?' && s[i] != s[n - i - 1])\n fail(); \n }\n int j = k - 1;\n for(; j >= 0 && a[j]; j --);\n for(int i = (n - 1) / 2; i >= 0; i --){\n if(s[i] == '?'){\n if(j < 0) j = 0;\n s[i] = s[n - i - 1] = j + 'a';\n a[s[i] - 'a'] = true; \n while(j >= 0 && a[j]) j --;\n }\n }\n if(j < 0)\n puts(s);\n else fail();\n}\nint main(){\n if(file){\n freopen(task\".in\", \"r\", stdin);\n freopen(task\".out\", \"w\", stdout);\n }\n solve();\n}\n", "src_uid": "9d1dd9d722e5fe46823224334b3b208a"} {"source_code": "#include \n\nconst int MAXN = 50;\ntypedef long long LL;\nint n;\nchar buf[MAXN];\nint fail[MAXN], tr[MAXN][2];\nLL dp[MAXN][MAXN][2];\nint main() {\n\tstd::ios_base::sync_with_stdio(false), std::cin.tie(0);\n\tstd::cin >> n >> buf + 1; int S = strlen(buf + 1);\n\tfor (int i = 1; i <= S; ++i) {\n\t\tint now = fail[i - 1];\n\t\twhile (now && (now + 1 == i || buf[now + 1] != buf[i])) now = fail[now];\n\t\tfail[i] = now + 1 != i && buf[now + 1] == buf[i] ? now + 1 : 0;\n\t}\n\tfor (int i = 0; i <= S; ++i)\n\t\tfor (int j = 0; j < 2; ++j) {\n\t\t\tint now = i;\n\t\t\twhile (now && buf[now + 1] != j + '0') now = fail[now];\n\t\t\ttr[i][j] = buf[now + 1] == j + '0' ? now + 1 : 0;\n\t\t}\n\tLL ans = 0;\n\tfor (int i = 0; i <= S; ++i) {\n\t\tmemset(dp, 0, sizeof dp);\n\t\tdp[0][i][i == S] = 1;\n\t\tfor (int j = 1; j <= n; ++j)\n\t\tfor (int k = 0; k <= S; ++k)\n\t\tfor (int l = 0; l < 2; ++l)\n\t\tfor (int p = 0; p < 2; ++p)\n\t\t\tdp[j][tr[k][p]][(tr[k][p] == S) || l] += dp[j - 1][k][l];\n\t\tans += dp[n][i][1];\n\t}\n\tstd::cout << ans << std::endl;\n\treturn 0;\n}\n", "src_uid": "0034806908c9794086736a2d07fc654c"} {"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#define debug1(x) cout << #x\" = \" << x << endl;\n#define debug2(x, y) cout << #x\" = \" << x << \" \" << #y\" = \" << y << endl;\n#define debug3(x, y, z) cout << #x\" = \" << x << \" \" << #y\" = \" << y << \" \" << #z\" = \" << z << endl;\n#define debug4(x, y, z, w) cout << #x\" = \" << x << \" \" << #y\" = \" << y << \" \" << #z\" = \" << z << \" \" << #w\" = \" << w << endl;\nusing namespace std;\n\nint N;\nint lower[10][10];\nint upper[10][10];\nint aa[10][10];\n\nbool caled[6][5][10][15][20][25];\nint sum[6][5][10][15][20][25];\n\nstruct State\n{\n\tint in[6];\n};\n\nint getMaxSum(State s, int depth)\n{\n\tint a = s.in[0];\n\tint b = s.in[1];\n\tint c = s.in[2];\n\tint d = s.in[3];\n\tint e = s.in[4];\n\tint f = s.in[5];\n\n\tif (caled[depth][b][c][d][e][f]) return sum[depth][b][c][d][e][f];\n\tcaled[depth][b][c][d][e][f] = true;\n\t\n\tint & ret = sum[depth][b][c][d][e][f];\n\tret = -1;\n\n\tif (depth == 0)\n\t{\n\t\tret = 0;\n\t\treturn ret;\n\t}\n\n\tint deal = depth;\n\tint shouldin = s.in[deal];\n\tint totalmaxin = 0;\n\tint totalminin = 0;\n\tfor (int i = 0; i < deal; ++i)\n\t{\n\t\ttotalmaxin += upper[i][deal];\n\t\ttotalminin += lower[i][deal];\n\t}\n\tif (totalmaxin < shouldin || totalminin > shouldin)\n\t\treturn ret = -1;\n\t\n\tint delta[6];\n\tmemset(delta, 0, sizeof(delta));\n\tfor (int i = 0; i < deal; ++i)\n\t\tdelta[i] = lower[i][deal];\n\n\twhile (true)\n\t{\n\t\tint nowin = 0;\n\t\tint nowcost = 0;\n\t\tfor (int i = 0; i < deal; ++i)\n\t\t{\n\t\t\tnowin += delta[i];\n\t\t\tif (delta[i] > 0)\n\t\t\t\tnowcost += aa[i][deal] + delta[i] * delta[i];\n\t\t}\n\n\t\tif (nowin == shouldin)\n\t\t{\n\t\t\tState ns;\n\t\t\tfor (int i = 0; i < 6; ++i)\n\t\t\t\tns.in[i] = s.in[i] + delta[i];\n\t\t\tns.in[deal] = 0;\n\n\t\t\tint t = getMaxSum(ns, depth - 1);\n\t\t\tif (t >= 0 && t + nowcost >= ret)\n\t\t\t\tret = t + nowcost;\n\t\t}\n\n\t\tint last = deal - 1;\n\t\tdelta[last]++;\n\t\twhile (delta[last] > upper[last][deal] && last >= 0)\n\t\t{\n\t\t\tdelta[last] = lower[last][deal];\n\t\t\tdelta[last - 1]++;\n\t\t\tlast--;\n\t\t}\n\t\tif (last < 0) break;\n\t}\n\n\t//debug2(depth, ret);\n\treturn ret;\n}\n\nvoid york()\n{\n\tint ansupper = 0;\n\tint anslower = 0;\n\tfor (int i = 1; i < N; ++i)\n\t{\n\t\tansupper += upper[0][i];\n\t\tanslower += lower[0][i];\n\t}\n\n\tfor (int ans = anslower; ans <= ansupper; ++ans)\n\t{\n\t\tState s;\n\t\tfor (int i = 0; i < 6; ++i) s.in[i] = 0;\n\t\ts.in[N - 1] = ans;\n\t\tmemset(caled, false, sizeof(caled));\n\t\tint maxsum = getMaxSum(s, N - 1);\n\n\t\t//debug2(ans, maxsum);\n\t\tif (maxsum >= 0)\n\t\t{\n\t\t\tcout << ans << \" \" << maxsum << endl;\n\t\t\treturn;\n\t\t}\n\t}\n\tcout << \"-1 -1\" << endl;\n}\n\nvoid init()\n{\n\tmemset(lower, 0, sizeof(lower));\n\tmemset(upper, 0, sizeof(upper));\n\tmemset(aa, 0, sizeof(aa));\n\tcin >> N;\n\tfor (int i = 0; i < N * (N - 1) / 2; ++i)\n\t{\n\t\tint s, f, l, h, a;\n\t\tcin >> s >> f >> l >> h >> a;\n\t\ts--; f--;\n\t\tlower[s][f] = l;\n\t\tupper[s][f] = h;\n\t\taa[s][f] = a;\n\t}\n}\n\nint main()\n{\n\tinit();\n\tyork();\n\treturn 0;\n}", "src_uid": "38886ad7b0d83e66b77348be34828426"} {"source_code": "#include \nusing namespace std;\n\nint main(){\n\tint n;\n\tcin>>n;\n\tcout<\nusing namespace std;\nlong long sum(string s)\n{\n long long ans=0;\n for(int i=0 ;i>num;\n num1=mx=num;\n for(int j=num1.size()-2 ;j>=0 ;j--)\n {\n num1[j]--;\n for(int i=j+1 ; i\n#include\n#define pb push_back\n#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n#define ll long long\n\n\nusing namespace std;\n\nvectoradj[200005];\n\nint vis1[200005];\nint vis2[200005];\nint vis[200005];\nint a,b;\nvoid dfs1(int s){\n if(s!=a)vis1[s]++;\n for(int i=0;i>t;\n\n for(int tt=0;tt>n>>m>>a>>b;\n for(int i=1;i<=n;i++){\n adj[i].clear();\n vis1[i]=0;\n vis2[i]=0;\n vis[i]=0;\n }\n for(int i=0;i>u>>v;\n\n adj[u].pb(v);\n adj[v].pb(u);\n }\n dfs1(a);\n dfs2(b);\n for(int i=1;i<=n;i++){\n vis[i]=vis1[i]+vis2[i];\n }\n ll fora =0;\n ll forb=0;\n for(int i=1;i<=n;i++){\n if(vis[i]==2)continue;\n if(vis1[i]==1){\n fora++;\n }\n if(vis2[i]==1){\n forb++;\n }\n }\n cout<\nusing namespace std;\n\nint main()\n{ long long n;\n cin >> n;\n cout << n/2520;\n}\n", "src_uid": "8551308e5ff435e0fc507b89a912408a"} {"source_code": "#include\n#define fi first\n#define se second\n#define pb push_back\n#define SZ(x) ((int)x.size())\n#define L(i,u) for (register int i=head[u]; i; i=nxt[i])\n#define rep(i,a,b) for (register int i=(a); i<=(b); i++)\n#define per(i,a,b) for (register int i=(a); i>=(b); i--)\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned int ui;\ntypedef pair Pii;\ntypedef vector Vi;\ntemplate inline void read(T &x){\n\tx=0; char c=getchar(); int f=1;\n\twhile (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}\n\twhile (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;\n}\ntemplate inline void umin(T &x, T y){x=x inline void umax(T &x, T y){x=x>y?x:y;}\ninline ui R() {\n\tstatic ui seed=416;\n\treturn seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;\n}\nconst int N = 52;\nint n,a[N],Ans,ans[N],qz[N];\nbitset<25*50000+5>f[52][26];\nint main() {\n\tread(n);rep(i,1,n*2)read(a[i]);sort(a+1,a+n*2+1);\n\trep(i,1,n*2)qz[i]=qz[i-1]+a[i];\n\tAns=1e9;f[n*2+1][0][0]=1;\n\tper(i,n*2,3){\n\t\tf[i][0][0]=1;\n\t\trep(j,1,min(n-1,n*2-i+1))f[i][j]=f[i+1][j]|(f[i+1][j-1]<\n#include \n#include \n#include \n#include \n#include \n#include \n#define FOR(i,a,n) for(int i=(a);i<(n);i++)\n#define REP(i,n) FOR(i, 0, n)\n#define mp make_pair\n#define pb push_back\n#define all(v) v.begin(),v.end()\n#define lint long long\n#define PII pair \n#define PDD pair \n#define VI vector \n#define VII vector < PII >\n#define X first\n#define Y second\n#define sz(a) (int)(a.size())\nusing namespace std;\n\nconst int DIM = 110*1000;\nint dn[DIM];\nint n;\n//char us[DIM][DIM];\nint nim(int n){\n\tif (dn[n] != -1) return dn[n];\n\tint res = 0;\n\tVI v;\n\tFOR(k, 2, n){\n\t\tint x = (2*n + (lint)k*(k-1)) / 2 / k;\n\t\tif ((k*x - (k*(k-1))/2) == n && x > k-1){\n\t\t\tint cand = 0;\n\t\t\tREP(i, k){\n\t\t\t\tcand ^= nim(x-i);\n\t\t\t}\n\t\t\tv.pb(cand);\n\t\t}\n\t}\n\tsort(all(v));\n\tv.resize(unique(all(v))-v.begin());\n\tint p = 0;\n\twhile (sz(v) > p && v[p] == p) p++;\n\tres = p;\n\treturn dn[n] = res;\n}\nint main(){\n\t//freopen(\"t.in\", \"r\", stdin);\n\tmemset(dn, -1, sizeof(dn));\n\t//FOR(i, 1, 100) printf(\"%d %d\\n\", i, nim(i));\n\tscanf(\"%d\", &n);\n\tint ans = nim(n);\n\tif (ans == 0) printf(\"-1\\n\");\n\telse {\n\t\tFOR(k, 2, n){\n\t\t\tint x = (2*n + (lint)k*(k-1)) / 2 / k;\n\t\t\tif ((k*x - (k*(k-1))/2) == n && x > k-1){\n\t\t\t\tint cand = 0;\n\t\t\t\tREP(i, k){\n\t\t\t\t\tcand ^= nim(x-i);\n\t\t\t\t}\n\t\t\t\tif (cand == 0){\n\t\t\t\t\tprintf(\"%d\\n\", k);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n\n", "src_uid": "63262317ba572d78163c91b853c05506"} {"source_code": "/*\n Take me to church\n I'll worship like a dog at the shrine of your lies\n I'll tell you my sins and you can sharpen your knife\n Offer me that deathless death\n Good God, let me give you my life\n*/\n#include\nusing namespace std;\ntypedef long long ll;\nconst int N = 19;\nll INF = 2e9 + 19, A[N], dp[N][2], dpt[N][2], C[N][N];\ninline ll Solve(int len, int w = -1)\n{\n if (!len) return 1LL;\n memset(dp, 0, sizeof(dp));\n dp[0][0] = 1;\n for (int i = 0; i < 16; i ++)\n {\n memset(dpt, 0, sizeof(dpt));\n for (int j = 0; j <= len; j ++)\n for (int h = 0; j + h <= len && h <= A[i]; h ++)\n {\n if (len > j)\n dpt[j + h][0] = min(dpt[j + h][0] + dp[j][0] * C[h][len - j - 1], INF);\n if (i > w && h > 0 && len > j)\n dpt[j + h][1] = min(dpt[j + h][1] + dp[j][0] * C[h - 1][len - j - 1], INF);\n if (i > w)\n dpt[j + h][1] = min(dpt[j + h][1] + dp[j][1] * C[h][len - j], INF);\n }\n memcpy(dp, dpt, sizeof(dp));\n }\n return (dp[len][1]);\n}\nint main()\n{\n ll K, T, len = 1;\n scanf(\"%lld%lld\", &K, &T);\n for (int i = 0; i < N; i ++)\n for (int j = C[0][i] = C[i][i] = 1; j < i; j ++)\n C[j][i] = min(C[j - 1][i - 1] + C[j][i - 1], INF);\n for (int i = 0; i < N; i ++)\n A[i] = T;\n for (; K > Solve(len, 0); )\n K -= Solve(len, 0), len ++;\n ll rs = 0;\n for (int i = 1; i <= len; i ++)\n for (int j = (i == 1); j < 16; j ++)\n if (A[j] > 0)\n {\n A[j] --;\n ll vl = Solve(len - i, -1);\n if (vl < K)\n K -= vl, A[j] ++;\n else\n rs = rs * 16 + j, j = 16;\n }\n return !printf(\"%llx\", rs);\n}", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e"} {"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\nusing namespace std;\n\n#define clr(x) memset((x), 0, sizeof(x))\n#define pb push_back\n#define mp make_pair\n#define sz size()\n#define x first\n#define y second\n#define forn(i, n) for(int i=0; i<(n); i++)\n#define ford(i, n) for(int i=(n)-1; i>=0; i--)\n\ntypedef long double ld;\n\n// Constants\nconst ld PI = 3.1415926535897932384626433832795;\nconst ld EPS = 1e-11;\n\n// Types\ntypedef signed long long i64;\ntypedef unsigned long long u64;\ntypedef pair < int, int > PII;\n\ni64 f,w,h,MOD=1000000007;\ni64 kw[100100];\ni64 kf[100100];\ni64 kw2[100100];\n\ni64 kall,kall2;\n\n\ni64 bp(i64 c, i64 st)\n{\n\ti64 res=1,t=c;\n\twhile(st>0)\n\t{\n\t\tif(st%2)\n\t\t\tres=(res*t)%MOD;\n\t\tst/=2;\n\t\tt=(t*t)%MOD;\t\n\t}\n\treturn res;\n}\nint main()\n{\n\t//freopen(\"z.in\",\"rt\",stdin);\n\t//freopen(\"z.out\",\"wt\",stdout);\n\n\tcin >>f>>w>>h;\n\tif(w==0)\n\t{\n\t\tcout <<1<=h)\n\t\tkw2[1]=1;\n\t\n\ti64 Nlast=w-h;\n\ti64 Klast=Nlast;\n\n\tfor(int i=1; Nlast>0 && i<100100; i++)\n\t{\n\t\tkw2[i+1]=kw2[i];\n\n\t\tfor(int j=0; j<=h && Nlast>=0; j++)\n\t\t{\n\t\t\tkw2[i+1]=(kw2[i+1]*Nlast)%MOD;\n\t\t\tNlast--;\n\t\t}\n\t\tforn(j,h)\n\t\t{\n\t\t\tkw2[i+1]=(kw2[i+1]*bp(Klast,MOD-2))%MOD;\n\t\t\tKlast--;\n\t\t}\n\n\t\tkw2[i+1]=(kw2[i+1]*bp(i,MOD-2))%MOD;\n\t\tif(Nlast<=0)\n\t\t\tbreak;\n\t}\n\t/*\n\tforn(i,10)\n\t\tcout <\n#define pll pair\n#define pii pair\n#define scn(a) scanf(\"%d\", &a)\n#define scn2(a, b) scanf(\"%d%d\", &a, &b)\n#define scn3(a, b, c) scanf(\"%d%d%d\", &a, &b, &c)\n#define pairl pair\n#define scnl(a) scanf(\"%lld\", &a)\n#define scnl2(a, b) scanf(\"%lld%lld\", &a, &b)\n#define scnl3(a, b, c) scanf(\"%lld%lld%lld\", &a, &b, &c)\n#define scns(s) scanf(\"%s\",s)\n#define prts(s) printf(\"%s\\n\",s)\n#define prt(a) printf(\"%d\\n\", a)\n#define prtl(a) printf(\"%lld\\n\", a)\n#define prs(a) printf(\"%d \", a)\n#define prt2(a, b) printf(\"%d %d\\n\", a, b)\n#define prt3(a, b, c) printf(\"%d %d %d\\n\", a, b, c)\n#define prsl(a) printf(\"%lld \", a)\n#define prtl2(a, b) printf(\"%lld %lld\\n\", a, b)\n#define prtl3(a, b, c) printf(\"%lld %lld %lld\\n\", a, b, c)\n#define ptcs(a) printf(\"Case %d: \", a)\n#define pf printf\n#define sc scanf\n#define vi vector\n#define vil vector\n#define pb push_back\n#define mem(a, b) memset((a), (b), sizeof(a))\n#define lg2(n) (31-__builtin_clz(n))\n#define inf 9999999\n#define ll long long\n#define ull unsigned long long\n#define MIN INT_MIN\n#define MAX INT_MAX\n#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)\nusing namespace std;\n#include \n#include \n#include \nusing namespace __gnu_pbds;\ntypedef tree , null_type, less >, rb_tree_tag, tree_order_statistics_node_update> odrst;\nll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}\nll 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//___________________________________________________________________________________________________________________\nconst int N = 3e5 + 9;\nconst int mod = 1e9 + 7;\nll a[N];\nvector< pair >v;\nbool ok;\nint main()\n{\n fast;\n ll x0,y0,ax,ay,bx,by,xs,ys,t,x,y,z,x1,y1,mx=9e16,ans=0,p;\n cin>>x0>>y0>>ax>>ay>>bx>>by>>xs>>ys>>t;\n x=x0;\n y=y0;\n while(x=0)\n {\n z+=(abs(x-v[j].first)+abs(y-v[j].second));\n if(z>t)\n {\n break;\n }\n x=v[j].first;\n y=v[j].second;\n j--;\n p++;\n }\n j=i+1;\n while(jt)\n {\n break;\n }\n x=v[j].first;\n y=v[j].second;\n j++;\n p++;\n }\n ans=max(ans,p);\n z=abs(xs-v[i].first)+abs(ys-v[i].second);\n x=v[i].first;\n y=v[i].second;\n p=1;\n j=i+1;\n while(jt)\n {\n break;\n }\n x=v[j].first;\n y=v[j].second;\n j++;\n p++;\n }\n j=i-1;\n while(j>=0 && z<=t)\n {\n z+=(abs(x-v[j].first)+abs(y-v[j].second));\n if(z>t)\n {\n break;\n }\n x=v[j].first;\n y=v[j].second;\n j--;\n p++;\n }\n ans=max(ans,p);\n }\n }\n cout<\nint q,I[200010];\nlong long inv(int a,int p){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}\nint f(int a,int b){\n\tint s=0;\n\tfor(int i=0;i0?i-b+1:0))*1ll*i%q*I[i+2])%q;\n\treturn(q+1ll)/2*s%q;\n}\nint main(){\n\tint n,k;scanf(\"%d%d%d\",&n,&k,&q);--k;\n\tif(k>18)k=18;\n\tint a=n>>k,b=a+1,x,y;\n\tif(a)x=(b<>1)%q*x+b*(b-1ll)/2%q*(q+1>>1)%q*y)%q;\n\tprintf(\"%d\\n\",s);\n}", "src_uid": "1dd54f5071872e947996ab32b16da19c"} {"source_code": "#include \nusing namespace std;\nint v,s,vedro[105],t,m,i,n;\nmain(){\ncin>>v>>s;\nfor (i=0; i>vedro[i];\n}\nsort(vedro,vedro+v);\nfor (i=v-1; i>=0; i--){\nif (s%vedro[i]==0) {cout<\nusing namespace std;\nconst int maxn=5e7;\nconst long long mod=1e9+7;\nbool number[maxn+5];\nint prime[maxn+5];\nint c=0;\nlong long x,n;\nlong long qsm(long long a,long long b,long long c)\n{\n long long ans=1,base=a;\n while(b!=0)\n\t{\n if(b&1)\n ans=ans*base%c;\n base=base*base%c;\n b>>=1;\n\t}\n return ans%c;\n}\nlong long kk(long long a,long long b)\n{\n long long ans=1,base=a;\n while(b!=0)\n\t{\n if(b&1)\n ans=ans*base;\n base=base*base;\n b>>=1;\n\t}\n return ans;\n}\nlong long f(long long p)\n{\n\tlong long maxp=0,cc=n;\n\twhile(cc>=p)\n\t{\n\t\tmaxp++;\n\t\tcc/=p;\n\t}\n\t//printf(\"maxp=%lld\\n\",maxp);\n\tlong long cs[100];\n\tcs[maxp]=n/kk(p,maxp);\n//\tcs[maxp]=(n%phi)*qsm(p,maxp*(phi-2),phi)%phi;\n\t//printf(\"cs==%lld \",cs[maxp]);\n\tlong long zx=0;\n\tif(maxp>1)\n\t{\n\tfor(long long i=maxp-1;i>=1;i--)\n\t{\n\t\tzx=(zx+cs[i+1]);\n//\t\tcs[i]=((n%phi)*qsm(p,i*(phi-2),phi)%phi-zx%phi+phi)%phi;\n\t\tcs[i]=(n/kk(p,i)-zx);\n\t\t//printf(\"%lld \",cs[i]);\n\t}\n\t}\n\t//printf(\"\\n\");\n\tlong long ans=0;\n\tfor(long long i=1;i<=maxp;i++)\n\t\tans=(ans+(i*cs[i]));\n\t//printf(\"ans=%lld\\n\",ans);\n\t//printf(\"\\n\");\n\treturn ans;\n}\nvoid init()\n{\n int i,j;\n memset(number,true,sizeof(number));\n memset(prime,-1,sizeof(prime));\n for(i=2;i<=maxn;i++)\n {\n if(number[i])\n prime[c++]=i;\n for(j=0;j1;i++)//筛因子 \n\t\t{\n\t\t\tif(x%prime[i]==0 && prime[i]!=1 && x>1)\n\t\t\t{\n\t\t\t\tyz[++psum]=prime[i];\n\t\t\t\twhile(x>=prime[i] && x%prime[i]==0)\n\t\t\t\t{\n\t\t\t\t\n\t\t\t\t\tx/=prime[i];\n\t\t\t\t//\tprintf(\"x=%lld\\n\",x);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif(x>1)\n\t{\n\t\tyz[++psum]=x;\n\t}\n\t//printf(\"psum=%d\\n\",psum);\n//\tfor(int i=1;i<=psum;i++)\n//\t{\n//\t\tprintf(\"%lld \",yz[i]);\n//\t}\n//\tprintf(\"\\n\");\n\tlong long ans=1;\n\tfor(int i=1;i<=psum;i++)\n\t{\n\t//\tprintf(\"f(%lld)=%lld\\n\",yz[i],f(yz[i]));\n\t\tans=(ans*qsm(yz[i],f(yz[i]),mod))%mod;\n\t}\n\tprintf(\"%lld\\n\",ans%mod);\n//\tf(5);\n}", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"source_code": "#include \n#include \n#include \n\n#define int long long\n#define ull unsigned long long\n#define ld long double\n#define rep(a) rep1(i,a)\n#define rep1(i,a) rep2(i,0,a)\n#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)\n#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)\n#define all(a) a.begin(),a.end()\n#define pii pair\n#define pb push_back\n#define mp make_pair\n#define eps 1e-9\n#define sz(a) ((int)a.size())\n#define pow2(x) (1ll<<(x))\n#define ceiling(a,b) (((a)+(b)-1)/(b))\n#define print0(a) cout << (a) << ' '\n#define print1(a) cout << (a) << '\\n'\n#define print2(a,b) cout << (a) << ' ',print1(b)\n#define print3(a,b,c) cout << (a) << ' ',print2(b,c)\n#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)\n#ifdef i_am_noob\n#define debug(a) print2(#a,a)\n#else\n#define debug(a)\n#endif\n#define ordered_set tree,rb_tree_tag,tree_order_statistics_node_update>\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\nconst int Mod=1000000007,Mod2=998244353;\nconst int MOD=Mod2;\n\ninline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}\ninline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}\nint Pow(int a, int b){\n\tif(!b) return 1;\n\tint tmp=Pow(a*a%MOD,b>>1);\n\treturn (b&1?tmp*a%MOD:tmp);\n}\ninline int inverse(int n){return Pow(n,MOD-2);}\n\nconst int maxn=1025;\n//i_am_noob\nint n,k,m,cnt=0;\nvector> vec;\nvector vec1;\nbool ok[maxn];\n\nvoid query(vector vec){\n char tmp;\n for(int i:vec){\n print2(\"?\",i+1);\n cout << flush;\n cin >> tmp;\n if(tmp=='Y') ok[i]=false;\n }\n cout << \"R\" << endl;\n}\n\nvoid report(){\n int ans=0;\n rep(n) ans+=ok[i];\n print2(\"!\",ans);\n cout << flush;\n exit(0);\n}\n\nvoid build(int n, int x){\n if(n==4){\n vec.pb({x,x+1,x+2,x+3});\n return;\n }\n if(n==8){\n rep(4) rep2(j,i+1,4) vec.pb({x+i,x+j,x+4+i,x+4+j});\n return;\n }\n if(n==16){\n rep(4) vec.pb({x+4*i,x+4*i+1,x+4*i+2,x+4*i+3});\n vec.pb({x,x+4,x+8,x+12});\n vec.pb({x,x+5,x+10,x+15});\n vec.pb({x,x+6,x+11,x+13});\n vec.pb({x,x+7,x+9,x+14});\n vec.pb({x+1,x+4,x+11,x+14});\n vec.pb({x+1,x+5,x+9,x+13});\n vec.pb({x+1,x+6,x+8,x+15});\n vec.pb({x+1,x+7,x+10,x+12});\n vec.pb({x+2,x+4,x+9,x+15});\n vec.pb({x+2,x+5,x+11,x+12});\n vec.pb({x+2,x+6,x+10,x+14});\n vec.pb({x+2,x+7,x+8,x+13});\n vec.pb({x+3,x+4,x+10,x+13});\n vec.pb({x+3,x+5,x+8,x+14});\n vec.pb({x+3,x+6,x+9,x+12});\n vec.pb({x+3,x+7,x+11,x+15});\n return;\n }\n int tmp=n/4+1;\n rep(tmp) rep1(j,tmp){\n vec1.clear();\n if(i!=tmp-1) vec1.pb(x+i);\n if(j!=tmp-1) vec1.pb(x+n/4+j);\n if((j+i)%tmp!=tmp-1) vec1.pb(x+n/4*2+(j+i)%tmp);\n if((j+2*i)%tmp!=tmp-1) vec1.pb(x+n/4*3+(j+2*i)%tmp);\n vec.pb(vec1);\n }\n rep(4) build(n/4,x+n/4*i);\n}\n\nsigned main(){\n\tios_base::sync_with_stdio(0),cin.tie(0);\n\tcin >> n >> k;\n\trep(n) ok[i]=true;\n\tif(k==1){\n rep(n) rep2(j,i+1,n) query({i,j});\n report();\n\t}\n\tif(k==2){\n rep(n/2) rep2(j,i+1,n/2){\n query({i,j,i+n/2});\n query({i,i+n/2,j+n/2});\n }\n query({n/2-1,n-1});\n report();\n\t}\n\tbuild(n/k*4,0);\n\trep1(ii,sz(vec)){\n m=sz(vec[ii]);\n rep2(i,1,k/4) rep1(j,m){\n vec[ii].pb(n/k*4*i+vec[ii][j]);\n }\n\t}\n /*\n\tfor(auto vec2:vec){\n for(auto i:vec2) {print0(i);cnt++;}\n cout << \"\\n\";\n\t}\n\tprint1(cnt);\n rep(n) rep2(j,i+1,n) b[i][j]=false;\n for(auto vec2:vec) rep(sz(vec2)) rep2(j,i+1,sz(vec2)) b[vec2[i]][vec2[j]]=true;\n rep(n) rep2(j,i+1,n) if(!b[i][j]) print2(i,j);\n */\n\n\tfor(auto vec2:vec) query(vec2);\n\treport();\n\n\treturn 0;\n}\n", "src_uid": "11ad68b4375456733526e74e72606d8d"} {"source_code": "#include \n#define int long long\n#define fi first\n#define se second\n#define pb push_back\n#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)\n#define all(x) (x).begin(), (x).end()\nusing namespace std;\ntypedef pair ii;\n\nvector d;\nint LCM(int a, int b) {\n\tif(!(a*b)) return max(a, b); \n\treturn a / (int)__gcd(a, b) * b; \n}\n\nint dp[21][50][2550], pos[2600], cnt, dig_lim, pre[2550][10], nxt[2550][10]; \n\nint call(int dig, int lcm, int r, bool fl) {\n\tint p = pos[lcm], ret = 0, limit = (fl ? 9 : d[dig]); \n\tif(!dig) return (r % lcm == 0); \n\tif(fl and dp[dig][p][r] != -1) return dp[dig][p][r]; \n\tfor(int i = 0; i <= limit; i++) \n \t\tret += call(dig - 1, pre[lcm][i], nxt[r][i], max(fl, i < limit)); \n\tif(fl) dp[dig][p][r] = ret; \n\treturn ret; \n}\n\nint solve(int x) {\n\tdig_lim = 0; d.clear(); d.pb(0); \n\twhile(x) {\n\t\td.pb(x % 10); \n\t\tx /= 10; \n\t\tdig_lim++; \t\n\t} \n\treturn call(dig_lim, 1, 0, 0); \n}\n\nsigned main() {\n\tfor(int i = 1; i <= 2520; i++) \n\t\tif(2520 % i == 0) pos[i] = ++cnt; \n\tfor(int i = 0; i <= 2520; i++) for(int j = 0; j < 10; j++) pre[i][j] = LCM(i, j), nxt[i][j] = (i * 10 + j) % 2520; \n\tmemset(dp, -1, sizeof dp);\n\tint t; cin >> t; \n\twhile(t--) {\n\t\tint l, r; cin >> l >> r;\n\t\tcout << solve(r) - solve(l-1) << '\\n';\n\t}\n}\n\n", "src_uid": "37feadce373f728ba2a560b198ca4bc9"} {"source_code": "#include\nusing namespace std;\n#define ll long long int\nll arra[300009];\nll brra[100009];\nll sum[100009];\ndouble input[100009];\nvectorsave;\nstring str1[108];\nstring str2[108];\nstring str;\nmapvis;\nstring stp[5];\nstring stpc[5];\nint main()\n{\n ll m,n,i,j,k,l,p,q,r=1,s,t;\n //cin>>t;\n ll a,b,c,d;\n cin>>a>>b>>c>>d;\n if(a==d&&(a>0||!c))\n {\n cout<<\"1\";\t\n }\n else\n cout<<\"0\";\n \n \n \t\n \t\n}", "src_uid": "b99578086043537297d374dc01eeb6f8"} {"source_code": "#include \n#include \n#include \n#define pb push_back\n#define mp make_pair\n#define all(a) begin(a),end(a)\n#define FOR(x,val,to) for(int x=(val);x pi;\ntypedef std::vector vi;\ntypedef std::vector vs;\ntypedef int64_t ll;\ntypedef uint64_t ull;\n#define umap unordered_map\n#define uset unordered_set\nusing namespace std;\nusing namespace __gnu_pbds;\n\n#ifdef _WIN32\n#define getchar_unlocked() _getchar_nolock()\n#define _CRT_DISABLE_PERFCRIT_LOCKS\n#endif\ntemplate ostream& operator<<(ostream &os, map P) { for(auto const &vv: P)os<<\"(\"< ostream& operator<<(ostream &os, set V) { os<<\"[\";for(auto const &vv:V)os< ostream& operator<<(ostream &os, vector V) { os<<\"[\";for(auto const &vv:V)os< ostream& operator<<(ostream &os, pair P) { os<<\"(\"<32){str+=cur;cur=getchar_unlocked();}}\ntemplate inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }\ntemplate using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound\ntemplate using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>;\n#define N 1000001\n\nint main(){\n ios_base::sync_with_stdio(0);cin.tie(0);\n const int nn = 1 << 20;\n /* int nn = 1 << 3; */\n int n;\n sc(n);\n ++n;\n string s;\n getstr(s);\n s.insert(s.begin(),'0');\n FORR(i,s) i -= '0';\n /* int dp[n+1][nn]; */\n static int dp[77][nn];\n memset(dp,0,sizeof dp);\n dp[0][0] = 1;\n int mod = 1e9+7;\n FOR(i,0,n){\n vector vec;\n int cr = 0;\n FOR(x,i,n){\n cr = cr*2+s[x];\n if(i != 0){\n if(!cr) continue;\n if(cr > 19) break;\n }\n vec.pb({x+1,i ? cr : 0});\n }\n FOR(x,0,nn){\n if(!dp[i][x]) continue;\n FORR(j,vec){\n /* if(!i){ */\n /* dp[j.e1][x] += dp[i][x]; */\n /* } */\n /* else{ */\n int nm = x | 1 << j.e2;\n assert(nm >= 0);\n assert(nm < nn);\n assert(j.e1 <= n);\n if(i)\n nm &= ~1;\n dp[j.e1][nm] += dp[i][x];\n if(dp[j.e1][nm] >= mod)\n dp[j.e1][nm] -= mod;\n /* } */\n }\n }\n }\n int ans = 0;\n FORE(i,2,n){\n /* whatis(i) */\n for(int x = 2; x < nn; x += 2){\n int cc = 0;\n int j = 2;\n while(j & x){\n cc |= j;\n j <<= 1;\n }\n if(cc == x){\n /* whatis(x) */\n /* whatis(dp[i][x]) */\n ans += dp[i][x];\n if(ans >= mod) ans -= mod;\n }\n }\n }\n cout << ans << '\\n';\n}\n\n", "src_uid": "61f88159762cbc7c51c36e7b56ecde48"} {"source_code": "/*input\n33\n*/\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#include \n \nusing namespace std;\n \n/******* All Required define Pre-Processors and typedef Constants *******/\n#define ar array\n#define scd(t) scanf(\"%d\",&t)\n#define scld(t) scanf(\"%ld\",&t)\n#define sclld(t) scanf(\"%lld\",&t)\n#define scc(t) scanf(\"%c\",&t)\n#define scs(t) scanf(\"%s\",t)\n#define scf(t) scanf(\"%f\",&t)\n#define sclf(t) scanf(\"%lf\",&t)\n#define rep(i, n) for (int i = 0; i < (n); i++)\n#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)\n#define tests int r; cin >> r; while(r--)\n#define MP make_pair\n#define PI acos(-1)\ntypedef pair PII;\ntypedef pair PDD;\ntypedef vector VI;\ntypedef vector VS;\ntypedef vector VII;\ntypedef vector VVI;\ntypedef map MPII;\ntypedef set SETI;\ntypedef multiset MSETI;\ntypedef long int int32;\ntypedef unsigned long int uint32;\ntypedef long long int int64;\ntypedef unsigned long long int uint64;\n#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);\n \n#define M(x) ((x)%(1000000007))\n \n int64 fact(int n) {\n int64 count = 1;\n for(int64 i = 1;i<=n;i++){\n \t\tcount = M(count * i);\n }\n return count;\n}\n \n \n \nint main() {\n \tgodspeed;\n \tint64 n;\n \tcin>>n;\n \tint64 bad = 1;\n \tfor(int64 i = 0; i\nusing namespace std;\n\n#define debug(x) {cerr << #x << \" = \" << x << '\\n';}\n#define PR(a, n) {cerr << #a << \" = \"; for (int _=1; _<=n; ++_) cerr << a[_] << ' '; cerr << '\\n';}\n#define PR0(a, n) {cerr << #a << \" = \"; for (int _=0; _ inf, sup, cc_inf, cc_sup;\nvector g[MAXN];\n\n\nvoid readInput() {\n cin >> n;\n\n for (int i = 1; i <= n; ++i) {\n cin >> a[i];\n }\n}\n\n\nvoid init() {\n for (int i = 1; i <= n; ++i) {\n bool isSup = false;\n for (int j = 1; j <= n; ++j) {\n if (i != j && a[i] % a[j] == 0)\n isSup = true;\n }\n if (isSup)\n sup.push_back(a[i]);\n else\n inf.push_back(a[i]);\n }\n\n for (auto u : sup) {\n for (auto v : sup) {\n bool ok = false;\n for (auto w : inf)\n ok = ok || (u % w == 0 && v % w == 0);\n if (ok && u != v)\n g[u].push_back(v);\n }\n }\n\n for (int i = 0; i <= n; ++i)\n C[i][i] = C[i][0] = 1;\n\n for (int i = 1; i <= n; ++i) {\n for (int j = 1; j < i; ++j) {\n C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;\n }\n }\n}\n\n\nvoid visit(int u) {\n cc_sup.push_back(u);\n visited[u] = true;\n\n for (auto v : g[u]) {\n if (!visited[v])\n visit(v);\n }\n}\n\n\nint64_t dp(int mask, int t) {\n if (t == cc_sup.size())\n return 1;\n\n if (f[mask][t] > -1)\n return f[mask][t];\n\n int nPawn = 0;\n for (auto u : cc_sup) {\n if ((T[u] & mask) > 0 && (T[u] | mask) == mask) {\n ++nPawn;\n }\n }\n\n int64_t res = 0;\n if (nPawn > t)\n res = dp(mask, t + 1) * (nPawn - t) % MOD;\n\n for (auto u : cc_sup) {\n if ((T[u] & mask) > 0 && (T[u] | mask) > mask) {\n int newMask = (mask | T[u]);\n res = (res + dp(newMask, t + 1)) % MOD;\n }\n }\n\n return f[mask][t] = res;\n}\n\n\nvoid solve() {\n int64_t res = 1;\n vector p, sz;\n PR0(inf, inf.size());\n PR0(sup, sup.size());\n for (auto u : sup) {\n if (!visited[u]) {\n cc_sup.clear();\n visit(u);\n memset(T, 0, sizeof(T));\n for (auto v : inf) {\n bool ok = false;\n for (auto w : cc_sup)\n ok = ok || (w % v == 0);\n if (ok) {\n for (auto w : cc_sup) {\n if (w % v == 0)\n T[w] |= (1 << cc_inf.size());\n }\n cc_inf.push_back(v);\n }\n }\n\n for (int mask = 0; mask < (1<\n#include \n#include \n#include \n#include \n#include \n#define N 100\n#define M 1000\n#define int65 unsigned long long\n#define For(i,x,y) for (i=x;i<=y;i++)\nusing namespace std;\nconst char P[4]={'B','R','W','Y'};\nstruct ww {\n\tint x,y;\n};\nstruct w {\n\tww a,b;\n\tint c,d,e;\n} c[N],q[20][20][50];\nint i,j,k,n,m,an,S,T,t,num,ge;\nint a[N][N],h[200],f[N][N],b[N][N],len[N][N],id[N][N],st[N][N],d[N][N],\n\tba[M],bb[M],head[M],next[M],F[M],g[M],gg[M];\nchar p[N],s[N][N],re[N][N];\nset Set;\ninline void add(int x,int y,int z) {\n\tba[++t]=y,bb[t]=z,next[t]=head[x],head[x]=t;\n\tba[++t]=x,bb[t]=0,next[t]=head[y],head[y]=t;\n}\ninline bool bfs() {\n\tint l,r,v;\n\tg[l=r=1]=S; gg[S]=0; F[S]=++num;\n\tfor (;l<=r;l++) for (v=head[g[l]];v;v=next[v]) {\n\t\tint A=ba[v];\n\t\tif (bb[v]&&F[A]!=num) {\n\t\t\tF[A]=num; gg[A]=gg[g[l]]+1; g[++r]=A;\n\t\t\tif (A==T) return 1;\n\t\t}\n\t}\n\treturn 0;\n}\nint Dfs(int x,int y) {\n\tif (x==T) return y;\n\tint v,w=0,re;\n\tfor (v=head[x];v&&wb[i][j]) add(S,id[i][j],len[i][j]-b[i][j]);\n\t\tif (len[i][j]an) {\n\t\tan=sum;\n\t\t//print\n\t\tmemcpy(re,s,sizeof(re));\n\t\tFor(i,0,3)For(j,0,3) {\n\t\t\tFor(k,1,st[i][j]) {\n\t\t\t\tw B=q[i][j][k];\n\t\t\t\tprint(B,i,j);\n\t\t\t}\n\t\t\tint B=id[i][j],v;\n\t\t\tfor (v=head[B];v;v=next[v]) {\n\t\t\t\tint C=ba[v];\n\t\t\t\tif (C<=10||C>20||bb[v]==M) continue;\n\t\t\t\tFor(u,0,3)For(r,u,3) if (id[u][r]+10==C) goto yy1;\n\t\t\t\tyy1:;\n\t\t\t\tint o;\n\t\t\t\tFor(o,bb[v]+1,M) print(q[i][j][++st[i][j]],u,r),d[u][r]--;\n\t\t\t}\n\t\t}\n\t\tFor(i,0,3)For(j,i,3)\n\t\tfor (;st[i][j]B) swap(A,B),swap(C,D),a=1;\n\tc[++ge]=(w){C,D,A,B,a};\n}\nvoid dfs(int x,int y) {\n\tif (x>7) {\n\t\twork();\n\t\treturn;\n\t}\n\tif (y>8) {\n\t\tdfs(x+1,1);\n\t\treturn;\n\t}\n\tif (f[x][y]) {\n\t\tdfs(x,y+1);\n\t\treturn;\n\t}\n\tif (x<7) {\n\t\tf[x][y]=f[x+1][y]=1;\n\t\tget(a[x][y],a[x+1][y],(ww){x,y},(ww){x+1,y});\n\t\ts[2*x][2*y-1]='|';\n\t\tdfs(x,y+1);\n\t\ts[2*x][2*y-1]='.';\n\t\tge--;\n\t\tf[x][y]=f[x+1][y]=0;\n\t}\n\tif (y<8&&!f[x][y+1]) {\n\t\tf[x][y]=f[x][y+1]=1;\n\t\tget(a[x][y],a[x][y+1],(ww){x,y},(ww){x,y+1});\n\t\ts[2*x-1][2*y]='-';\n\t\tdfs(x,y+1);\n\t\ts[2*x-1][2*y]='.';\n\t\tge--;\n\t\tf[x][y]=f[x][y+1]=0;\n\t}\n}\nint main() {\n\t//freopen(\"126e.in\",\"r\",stdin);\n\t//freopen(\"126e.out\",\"w\",stdout);\n\th['B']=0,h['R']=1,h['W']=2,h['Y']=3;\n\tFor(i,1,7) {\n\t\tscanf(\"%s\",p+1);\n\t\tFor(j,1,8) a[i][j]=h[p[j]];\n\t}\n\tFor(i,0,3)for (j=3;j>=i;j--) scanf(\"%d\",&b[i][j]);\n\tk=0; For(i,0,3)For(j,i,3) id[i][j]=++k;\n\tan=-1; memset(s,'.',sizeof(s));\n\tdfs(1,1);\n\tprintf(\"%d\\n\",an);\n\tFor(i,1,13) {\n\t\tFor(j,1,15) printf(\"%c\",re[i][j]);\n\t\tprintf(\"\\n\");\n\t}\n\t//for(;;);\n\treturn 0;\n}\n", "src_uid": "cb56e7578ec5e04118993444283ad1eb"} {"source_code": "#include\nusing namespace std;\nint main()\n{\n\tint len, l, up;\n\tcin >> len >> l >> up;\n\tif(l*4 + up*2 <= len) cout << 1 << endl;\n\telse if(l*2 > len && up*2 > len && up+l > len) cout << 6 << endl;\n\telse\n\t{\n\t\tint ans = 6;\n\t\tint l1 = len/l, r1 = len/up;\n\t\tif(l1 >= 4) l1 = 4; if(r1 >= 2) r1 = 2;\n\t\tint n1 = (4 % l1 == 0) ? 4/l1 : 4/l1+1;\n\t\tans = min(ans, n1 + 2/(r1));\n\t\tif(len >= l + up)\n\t\t{\n\t\t\tint d = len-up, temp;\n\t\t\td /= l;\n\t\t\tif(d >= 2) ans = min(ans, 2);\n\t\t\tif(l1 >= 2) temp = 1;\n\t\t\telse temp = 2;\n\t\t\tif(d == 1) ans = min(ans, 2 + temp);\n\t\t}\n\t\tif(len >= up*2 + l)\n\t\t{\n\t\t\tint d = len - up*2, temp;\n\t\t\td /= l;\n\t\t\tif(d >= 4) ans = min(ans, 1);\n\t\t\telse{\n\n\t\t\t\ttemp = ((4-d)%l1 == 0)? (4-d)/l1 : (4-d)/l1+1;\n\t\t\t\tans = min(ans, 1 + temp);\n\t\t\t\t}\n\t\t}\n\t\tcout << ans << endl;\n\t}\n\n\treturn 0;\n}\n", "src_uid": "1a50fe39e18f86adac790093e195979a"} {"source_code": "// #includes {{{\n#include \n#include \n#include \n#include \n#include \n#include \n#include \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// pre-written code {{{\n#define REP(i,n) for(int i=0;i<(int)(n);++i)\n#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)\n#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)\n#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)\n#define ALL(c) (c).begin(), (c).end()\n#define MP make_pair\n#define PB push_back\n#define CLEAR(c,d) memset((c),(d),sizeof(c))\n#define TO_STRING(VariableName) # VariableName\n#define OUT(c) cout< pii;\n\nvoid rint(int &r){scanf(\"%d\",&r);}\nvoid rInt(Int &r){scanf(\"%lld\",&r);}\nvoid ruint(unsigned int &r){scanf(\"%u\",&r);}\nvoid ruInt(uInt &r){scanf(\"%llu\",&r);}\ntypedef double number;\n\n// }}}\n\nconst int N=1000, M=110;\nint n,m;\n\nint x[N],y[N],z[N];\nnumber a,b,c;\n\nnumber xx[N],yy[N];\n\n//{{{ geometry components\n\ntypedef double number;\nconst number EPS = 1e-7;\ntypedef complex P;\nnamespace std {\n\tbool operator < (const P& a, const P& b) {\n\t\treturn real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);\n\t}\n}\n\n//}}}\n\nvector