code
stringlengths
4
1.01M
language
stringclasses
2 values
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } enum MOD = (10 ^^ 9) + 7; void main() { string s; string input = sread(); foreach (c; input) { switch (c) { case '0': s ~= '0'; break; case '1': s ~= '1'; break; case 'B': if (!s.empty) s.popBack(); break; default: assert(0); } } writeln(s); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto st = readln.split.to!(char[][]); char[] u; foreach (i; 0..N) { u ~= st[0][i]; u ~= st[1][i]; } writeln(u); }
D
import std.algorithm; import std.array; import std.stdio; import std.conv; import std.string; import std.range; void main(){ size_t w, h, sx, sy; char[][] data = new char[][](20, 20); while(true){ auto input = readln.split; w = input[0].to!int; h = input[1].to!int; if(!(w | h)){ break; } foreach(i; 0..h){ foreach(j, c; readln.chomp){ data[i][j] = c; if(c == '@'){ sx = j; sy = i; data[i][j] = '#'; } } } data.dfs(sx, sy, w, h).writeln; } } enum move = [[1, 0], [0, 1], [-1, 0], [0, -1]]; size_t dfs(char[][] data, size_t sx, size_t sy, size_t w, size_t h){ size_t count = 1; foreach(i; 0..4){ size_t x = sx + move[i][0]; size_t y = sy + move[i][1]; if(0 <= x && x < w && 0 <= y && y < h && data[y][x] != '#'){ data[y][x] = '#'; count += dfs(data, x, y, w, h); } } return count; }
D
void main() { long n = readln.chomp.to!long; long total; for (long i = 1; i * i < n; ++i) { if (n % i == 0) { long d = n / i; if (i == n % (d - 1)) total += d - 1; } } total.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
void main(){ long x, t; scanf("%ld %ld", &x, &t); (x-t>0?x-t:0).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio,std.conv,std.string,std.algorithm,std.array; void main(){ auto s=readln().chomp().split().map!(to!int); int a=s[0],b=s[1],c=s[2]; if(a+b>=c) writeln("Yes"); else writeln("No"); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { readln; auto a = readln.chomp.split.map!(to!int); auto s = new int[](100003); foreach (e; a) { s[e]++; s[e+3]--; //s[e..e+3] +=1; //writeln(s[0..10]); } int cnt, prevCnt; foreach (i, e; s) { cnt += e; prevCnt = max(cnt, prevCnt); } prevCnt.writeln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { readln; auto xs = readints(); int n = cast(int) xs.length; auto segTree = new SegmentTree(n + 1); foreach (x; xs) { auto max = segTree.query(1, x); segTree.update(x, x + max); } auto max = segTree.query(1, n + 1); writeln(cast(long) n * (n + 1) / 2 - max); } class SegmentTree { private long[] _data; this(int n) { int len = 1; while (len < n) len *= 2; _data = new long[len * 2]; } /// k ?????????????´????(0-indexed)??? a ????????´ void update(int k, long a) { // ????????\??? k += (_data.length / 2) - 1; _data[k] = a; // ?????????????????´??° while (k > 0) { k = (k - 1) / 2; _data[k] = max(_data[k * 2 + 1], _data[k * 2 + 2]); } } /// [a, b) ???????°????????±??????? long query(int a, int b, int k, int l, int r) { // [a, b) ??¨ [l, r) ?????????????????? if (r <= a || b <= l) return 0; // [a, b) ??? [l, r) ????????¨???????????§????????°???????????\????????? if (a <= l && r <= b) { return _data[k]; } // ????????§???????????°???2 ?????????????????§??? auto vl = query(a, b, k * 2 + 1, l, (l + r) / 2); auto vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } long query(int a, int b) { return query(a, b, 0, 0, cast(int)(_data.length / 2)); } }
D
void main() { int[] tmp = readln.split.to!(int[]); int x = tmp[0], a = tmp[1], b = tmp[2]; writeln(abs(x-a) < abs(x-b) ? 'A' : 'B'); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new bool[](t); foreach (ti; 0..t) { auto s = RD!string; long cnt0, cnt1; foreach (c; s) { if (c == '0') ++cnt0; else ++cnt1; } ans[ti] = min(cnt0, cnt1) % 2 == 1; } foreach (e; ans) { writeln(e ? "DA" : "NET"); } stdout.flush; debug readln; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto g=new int[][](n+1, 0); auto can=new int[](n+1); void f(int i){ if(g[i].length==0){can[i]=0; return;} foreach(j; g[i]) f(j); foreach(j; g[i])if(can[j]==0){ can[i]=can[j]=1; break; } can[i]=max(can[i], 0); } foreach(i; 1..n+1){ int p; rd(p); g[p]~=i; fill(can, -1); f(0); int sm=reduce!("a+max(0, b)")(0, can); // assert(sm%2==0); writeln(sm/2); // writeln(can); } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; import std.container; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } const ulong MOD = 1_000_000_007; void main(){ long n = read.to!long; long m = read.to!long; ulong ans; if(n < m - 1 || n > m + 1) ans = 0; else if(n == m) ans = 2 * f(n) * f(n) % MOD; else ans = f(m) * f(n) % MOD; ans.writeln; } ulong f(long n){ ulong res = 1; for(long i = 1; i <= n; i ++){ res *= i; res %= MOD; } return res; }
D
void main(){ int ans = 6; int[] ab; ab ~= _scan(); ab ~= _scan(); foreach(elm; ab)ans -= elm; ans.writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); auto u = s[0..2].to!int, v = s[2..4].to!int; if (1 <= u && u <= 12 && 1 <= v && v <= 12) writeln("AMBIGUOUS"); else if (1 <= u && u <= 12) writeln("MMYY"); else if (1 <= v && v <= 12) writeln("YYMM"); else writeln("NA"); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), a = rd[0], b = rd[1]; writeln((a + b) % 24); }
D
import std.stdio, std.array, std.conv, std.string; void main() { string[] input = split(readln()); int W = to!int(input[0]), H = to!int(input[1]); int x = to!int(input[2]), y = to!int(input[3]), r = to!int(input[4]); if (r <= x && r <= (W - x) && r <= y && r <= (H - y)) { writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto n = readln.chomp.to!long; auto s = readln.chomp.to!long; long b = 2; for (; b^^2 <= n; ++b) { auto m = n; long t; while (m) { t += m % b; m /= b; } if (t == s) { writeln(b); return; } } auto x = n/(b-1); for (; x > 0; --x) { auto y = s - x; if (y < 0) continue; b = (n-y)/x; if (n-y >= 0 && (n-y)%x == 0 && b > 1 && n%b + (n/b)%b == s) { writeln(b); return; } } if (s == n) { writeln(n+1); return; } writeln(-1); }
D
import std.stdio, std.string; void main() { string input = chomp(readln()); char lastChar = ' '; byte count = 1; foreach(char i; input) { if(lastChar == ' ') { lastChar = i; continue; } if(lastChar == i) { count++; } else { count = 1; lastChar = i; } if(count >= 3) { writeln("Yes"); return; } } writeln("No"); return; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); long n = S.length; auto T = sread(); { auto cnt = new long[]('z' - 'a' + 1); foreach (c; S) cnt[c - 'a']++; foreach (c; T) if (cnt[c - 'a'] == 0) { writeln(-1); return; } } auto next = new long[][](n, 'z' - 'a' + 1); auto SS = S ~ S; next[$ - 1][] = 0; next[$ - 1][S[0] - 'a'] = 1; foreach_reverse (i; 0 .. n * 2) { next[i % n][] = next[(i + 1) % n][] + 1; next[i % n][SS[i] - 'a'] = 0; } // foreach (i, r; next) // writeln(i, " ", S[i], " ", r['t' - 'a']); // writeln(); long cur = -1; foreach (c; T) { cur++; // writeln(cur, " ", c, " ", next[cur % n][c - 'a']); cur += next[cur % n][c - 'a']; } writeln(cur + 1); }
D
void main() { string n = readln.chomp; while (n.count(n[0]) != 3) { n = n.succ; } n.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); long bignum = 1_000_000_007; T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { auto s = sread(); foreach (i, e; s) { if(i == 4) write(" "); e.write(); } writeln(); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } enum MOD = (10 ^^ 9) + 7; void main() { string s = sread(); long a, z; foreach (i; 0 .. s.length) if (s[i] == 'A') { a = i; break; } foreach_reverse (i; 0 .. s.length) if (s[i] == 'Z') { z = i; break; } writeln(z - a + 1); }
D
import std.stdio, std.string, std.conv; void main() { int n = readln.chomp.to!int; int[] p = readln.split.to!(int[]); int cnt; foreach (i, x; p) { if (x != i + 1) ++cnt; } writeln(cnt < 3 ? "YES" : "NO"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nk = readln.split.to!(long[]); auto N = nk[0]; auto K = nk[1]; long r; foreach (n; K+1..N+1) { r += N/n * (n-K); r += max(0, N - N/n * n - max(0, K-1)); } writeln(r); }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int r, g; scan(r); scan(g); writeln(2*g - r); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main(){ auto F=readln.split.to!(int[]),A=F[0],B=F[1],C=F[2]; if(A+B+C==17)writeln("YES"); else writeln("NO"); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip; import std.datetime; immutable long MOD = 10^^9 + 7; int N, X, Y, Z, S, MASK, NG; long[][] mem; long dp(int n, int mask) { if (n >= N) return 1; if (mem[n][mask] >= 0) return mem[n][mask]; long ret = 0; foreach (i; 1..11) { //if (i == ng) continue; int n_mask = (mask << i) | (1 << (i - 1)); if ((n_mask & NG) == NG) continue; n_mask &= MASK; ret = (ret + dp(n+1, n_mask)) % MOD; } return mem[n][mask] = ret; } void main() { scanf("%d %d %d %d", &N, &X, &Y, &Z); S = X + Y + Z; mem = new long[][](N, 1<<S); foreach (i; 0..N) fill(mem[i], -1); MASK = (1 << S) - 1; NG |= (1 << (Z-1)); NG |= (1 << (Y+Z-1)); NG |= (1 << (X+Y+Z-1)); long ans = 1; foreach (i; 0..N) ans = (ans * 10) % MOD; ans = ((ans - dp(0, 0)) % MOD + MOD) % MOD; ans.writeln; }
D
// Vicfred // https://atcoder.jp/contests/abc174/tasks/abc174_d // greedy import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main() { const int n = readln.chomp.to!int; string s = readln.strip; int reds = 0; foreach(ch; s) if(ch == 'R') reds += 1; int ans = 0; for(int i = 0; i < reds; i++) if(s[i] == 'W') ans += 1; ans.writeln; }
D
void main() { problem(); } void problem() { auto S = scan; auto T = scan; long solve() { long ans; foreach(i; 0..S.length) { if (S[i] != T[i]) ans++; } return ans; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } alias Point = Tuple!(long, "x", long, "y"); // -----------------------------------------------
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int x, a, b; scan(x); scan(a); scan(b); writeln((x-a)%b); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long N = lread(); long K = lread(); long n = N - K; long X = lread(); long a = (n < 0) ? N * X : K * X; long b = (n < 0) ? 0 : n * lread(); writeln(a + b); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; long A, B, C, D, E, F; rd(A, B, C, D, E, F); A*=100; B*=100; long tot=A, su=0; for(long a=0; a<=F; a+=A)for(long b=0; a+b<=F; b+=B){ for(long c=0; a+b+c<=F; c+=C){ if(c*100>(a+b)*E) continue; for(long d=0; a+b+c+d<=F; d+=D){ if((c+d)*100>(a+b)*E) continue; long wa_=a+b, su_=c+d, to_=wa_+su_; if(su*to_<tot*su_){ tot=to_; su=su_; } } } } writeln(tot, " ", su); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x) e=l[i].to!(typeof(e)); }
D
import std.stdio; import std.algorithm; import std.conv; import std.numeric; import std.math; import std.string; void main() { auto tokens = split(chomp(readln())); auto N = to!ulong(tokens[0]); auto M = to!ulong(tokens[1]); ulong inc = 1; if (M % 2 == 1) { if (N % 2 == 0) ++N; inc = 2; } ulong blocks = M; ulong i; while (i < M/2 - N + 1) { if (M % (N + i) == 0) { blocks = N + i; break; } i += inc; } writeln(M / blocks); stdout.flush(); }
D
import std.conv; import std.stdio; import std.string; void main() { auto s = readln.strip; auto t = readln.strip; writeln( solve( s, t ) ); } auto solve( in string s, in string t ) { foreach( i; 0 .. t.length ) { auto ts = t[ i .. $ ] ~ t[ 0 .. i ]; if( s == ts ) return "Yes"; } return "No"; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto S = RD!string; long ans; if (S == "RSR") ans = 1; else { foreach (c; S) { if (c == 'R') ++ans; } } writeln(ans); stdout.flush; debug readln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias Pair = Tuple!(long, "number", long, "times"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } auto comb = new long[][](2019, 2019); void calc_comb(long limit) { long times; comb[times++][0] = 1; comb[times][0] = comb[times][1] = 1; while (++times < limit) { long row; while (row <= times) { if (row == 0) { comb[times][row] = 1; row++; continue; } comb[times][row] = (comb[times - 1][row] + comb[times - 1][row - 1]) % bignum; row++; } } } void main() { long n, blue; scan(n, blue); auto red = n - blue; calc_comb(n + 1); foreach (i; 1.. blue + 1) { // comb[red + 1][i].write(" "); // comb[blue - 1][i - 1].writeln(); auto ans = comb[red + 1][i] * comb[blue - 1][i - 1]; ans %= bignum; ans.writeln(); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int a, b; readV(a, b); writeln(a+b == 15 ? "+" : a*b == 15 ? "*" : "x"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!long; auto AS = readln.split.to!(long[]); long sum_a; foreach (a; AS) sum_a += a; auto d = (N+1) * N / 2; if (sum_a % d != 0) { writeln("NO"); return; } auto n = sum_a / d; d = 0; foreach (i; 0..N) { auto a = AS[(i+1)%N] - AS[i]; if ((n-a)%N != 0 || n-a < 0 || n < (n-a)/N) { writeln("NO"); return; } d += a; } writeln(d == 0 ? "YES" : "NO"); }
D
import core.bitop; import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.random; import std.range; import std.stdio; import std.string; import std.typecons; void main() { long n = readln.chomp.to!long; long ans = 0; foreach (i; 0 .. n + 1) { if (i * i > n) { break; } ans = i * i; } ans.writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto a = new long[](N+1); a[0] = 2; a[1] = 1; foreach (i; 2..N+1) { a[i] = a[i-1] + a[i-2]; } writeln(a[N]); stdout.flush(); debug readln(); }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { readln.splitter.map !(to !(int)).sum.writeln; } }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; int res = n - (n == 1); foreach (i; 0..n) { foreach (j; i + 1..n) { auto num = a[j] - a[i]; auto den = j - i; int cur = 0; foreach (k; 0..n) { auto value = num * (k - i); cur += (a[k] - a[i]) * den != value; } res = min (res, cur); } } writeln (res); } }
D
import std.stdio; void main() { long n; scanf("%lld", &n); printf("%lld\n", n / (2 * 2 * 2* 3 * 3 * 5 * 7)); }
D
import std.stdio : writeln, stdin; import std.conv : to; import std.range : dropOne; import core.stdc.stdio; void main() { int n; scanf("%d", &n); string ss; int[100005] arr; for(int i = 0 ;i < 100005; ++i){ arr[i] = 1; } foreach(word; stdin.byLine) { ss = to!string(word); } for (int i = 0; i < n; ++i) { int curr = i; if(!(ss[i] == 'a' || ss[i] =='e' || ss[i] =='i' || ss[i] =='o' || ss[i] =='u' || ss[i] =='y')) { continue; } while((i+1) < n && ss[i + 1] == ss[curr]){ ++arr[curr]; arr[i+1] = 0; ++i; } } for(int i = 0; i < n; ++i){ if(arr[i] == 0){ continue; } if(arr[i] ==2 && (ss[i] == 'e' || ss[i] == 'o')) { printf("%c%c", ss[i], ss[i]); while((i + 1) < n && arr[i+1] == 0) { ++i; } } else if(arr[i] > 0) { printf("%c", ss[i]); while((i + 1) < n && arr[i+1] == 0) { ++i; } } } }
D
import std; long calc(int n) { long sum = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) continue; sum += i; } return sum; } void main() { int n; scan(n); writeln(calc(n)); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int;
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum long mod = 10^^9 + 7; void main() { string s = readln.chomp; string abc = "ABC"; int n = s.length.to!int; auto dp = new long[][](n + 1, 4); dp[0][0] = 1; foreach (i ; 1 .. n + 1) { foreach (j ; 0 .. 4) { dp[i][j] = dp[i-1][j]; if (s[i-1] == '?') { dp[i][j] *= 3; dp[i][j] %= mod; } if (j > 0 && (s[i-1] == '?' || s[i-1] == abc[j-1])) { dp[i][j] += dp[i-1][j-1]; dp[i][j] %= mod; } } } debug { writeln(dp); } writeln(dp[n][3]); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio,std.conv,std.string,std.algorithm,std.array; void main(){ auto sn=readln().split(); int n=to!int(sn[0]); if(n<1000) writeln("ABC"); else writeln("ABD"); }
D
module app; import core.bitop; import std.algorithm; import std.array; import std.bigint; import std.container.rbtree; import std.conv; import std.stdio; import std.string; import std.traits; struct Input { string s; } void parseInput(T)(out Input input, T file) { with (file) with (input) { s = readln().strip(); } } auto main2(Input* input) { with (input) { if (s == "AAA" || s == "BBB") return "No"; else return "Yes"; } } alias retType = ReturnType!main2; static if (!is(retType == void)) { unittest { writeln("begin unittest"); } auto _placeholder_ = ReturnType!main2.init; unittest // example1 { string example = `ABA`; if (example.empty) return; Input input = void; parseExample(input, example); auto result = main2(&input); printResult(result); assert(result == "Yes"); } unittest // example2 { string example = `BBA`; if (example.empty) return; Input input = void; parseExample(input, example); auto result = main2(&input); printResult(result); assert(result == "Yes"); } unittest // example3 { string example = `BBB`; if (example.empty) return; Input input = void; parseExample(input, example); auto result = main2(&input); printResult(result); assert(result == "No"); } unittest { writeln("end unittest"); } void parseExample(out Input input, string example) { struct Adapter { string[] _lines; this(string input) { _lines = input.splitLines(); } string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; } } parseInput(input, Adapter(example)); } } void printResult(T)(T result) { static if (isFloatingPoint!T) writefln("%f", result); else writeln(result); } void main() { Input input = void; parseInput(input, stdin); static if (is(retType == void)) main2(&input); else { auto result = main2(&input); printResult(result); } }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.numeric; void main() { int n, m; scan(n, m); auto adj = new int[][](m, 0); auto ex = new bool[](m); foreach (i ; 0 .. n) { auto line = readln.split.to!(int[]); int u = line[1] - 1; ex[u] = 1; if (line.length < 3) continue; foreach (v ; line[2 .. $]) { v--; ex[v] = 1; adj[u] ~= v; adj[v] ~= u; } } debug { writeln(adj); } auto visited = new bool[](m); void dfs(int u) { visited[u] = 1; foreach (v ; adj[u]) { if (!visited[v]) { dfs(v); } } } foreach (i ; 0 .. m) { if (ex[i]) { dfs(i); break; } } foreach (i ; 0 .. m) { if (ex[i] && !visited[i]) { writeln("NO"); return; } } writeln("YES"); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } void main() { auto I = readln.split.to!(long[]); auto N = I[0]; auto R = I[1]; long solve() { return N >= 10 ? R : R + 100 * (10 - N); } solve().writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; int[11] NS = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6]; void main() { auto N = readln.chomp.to!int; int[int][11] memo; int solve(int i, int n) { if (n == 0) return 0; if (i == 11) return n; if (n in memo[i]) return memo[i][n]; if (n < NS[i]) { return memo[i][n] = solve(i+1, n); } else { return memo[i][n] = min(solve(i+1, n), solve(i, n - NS[i]) + 1); } } writeln(solve(0, N)); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N, M; scan(N, M); auto adj = new int[][](N, 0); foreach (i ; 0 .. M) { int xi, yi; scan(xi, yi); xi--, yi--; adj[yi] ~= xi; } auto dp = new int[](N); dp[] = -1; int rec(int v) { if (dp[v] != -1) { return dp[v]; } dp[v] = 0; foreach (u ; adj[v]) { chmax(dp[v], rec(u) + 1); } return dp[v]; } int ans; foreach (i ; 0 .. N) { chmax(ans, rec(i)); } writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
// This file is a "Hello, world!" in D language by DMD for wandbox. import std.algorithm, std.conv, std.stdio, std.array, std.math, std.string; void main() { const N = readln.chomp.to!long; const V = readln.split.map!(to!long).array; const C = readln.split.map!(to!long).array; long ans; foreach (b; 0..2.pow(N)) { long X, Y; foreach (n; 0..N) { if (!(b >> n & 1)) continue; X += V[n]; Y += C[n]; } const temp = X - Y; if (ans < temp) ans = temp; } ans.writeln; } // DMD reference: // https://dlang.org/dmd-linux.html // D language references: // https://dlang.org // http://www.kmonos.net/alang/d/ ( Japanese )
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(long[]), n = rd[0], ts = rd[1]; auto t = readln.split.to!(long[]); auto ans = 0L; foreach (i; 0..n-1) ans += t[i+1]-t[i] > ts ? ts : t[i+1]-t[i]; ans += ts; writeln(ans); }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n, d; rd(n, d); struct P { int x, y; } P[] vec = [P(d, -d), P(n - d, n - d), P(-d, d), P(d - n, d - n)]; P[] ps = [P(0, d), P(d, 0), P(n, n - d), P(n - d, n)]; int m; rd(m); while (m--) { int x, y; rd(x, y); int[] o; foreach (i, p; ps) { auto u = P(x - p.x, y - p.y); o ~= vec[i].x * u.y - vec[i].y * u.x; } auto inside = reduce!((r, e) => (r && e >= 0))(true, o); if (inside) { writeln("YES"); } else { writeln("NO"); } } } void rd(T...)(ref T x) { import std.stdio, std.string, std.conv; auto l = readln.split; assert(l.length == x.length); foreach (i, ref e; x) e = l[i].to!(typeof(e)); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.container; import std.bigint; import std.math; void main() { while (1) { auto x = readln.chomp.split.map!(to!int); if (x[0] == 0) break; foreach (i; 0..x[0]) { foreach (j; 0..x[1]) { if (i == 0 || j == 0 || i == x[0] - 1 || j == x[1] - 1) write("#"); else write("."); } writeln(""); } writeln(""); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Node = Tuple!(long, "p", long, "dist"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto n = lread(); auto TREE = new Node[][](n, 0); auto color = new long[](n); foreach (_; iota(n - 1)) { long u, v, w; scan(u, v, w); TREE[u - 1] ~= Node(v - 1, w); TREE[v - 1] ~= Node(u - 1, w); } // TREE.each!(x => x.writeln()); color[0] = 1; dfs(TREE, color, 0, 0); foreach (e; color) writeln(e - 1); } void dfs(T)(T tree, long[] color, long current, long dist) { foreach (node; tree[current]) { if (!color[node.p]) { if ((dist + node.dist) % 2) color[node.p] = 2; else color[node.p] = 1; dfs(tree, color, node.p, dist + node.dist); } } } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio; void main() { string land = stdin.readln(); size_t position = 1; foreach (char command; stdin.readln()) { if (command == land[position - 1]) { ++position; } } stdout.write(position); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.container; import std.datetime; void main() { while (1) { auto str = readln.chomp; if (str == "#") break; int i = str.length.to!int-1; long a, b = 1; while (i > 0) { a *= 2; b *= 2; if (str[i] == 'h') { a -= 90; a = max(0, a); i -= 5; } else { a += 90; a = min(90*b/2, a); i -= 4; } } if (b != 2) { b /= 4; a /= 2; } else { b /= 2; } if (b == 1) a.writeln; else writeln(a, "/", b); } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum mod = 10L^^9 + 7; alias Pair = Tuple!(long, "s", long, "x"); void main() { long n; scan(n); long[Pair] mem; long func(long s, long x) { if (Pair(s, x) in mem) { return mem[Pair(s, x)]; } if (s == 0) { return 1; } if (x == 0) { return s/2 + 1; } mem[Pair(s, x)] = (func(s/2, x/2) + func((s-1)/2, (x-1)/2)) % mod; if (s >= 2) { mem[Pair(s, x)] += func((s-2)/2, x/2); } mem[Pair(s, x)] %= mod; return mem[Pair(s, x)]; } writeln(func(n, n)); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm: canFind; void main() { string[] inputs = split(readln()); int A = to!int(inputs[0]); int B = to!int(inputs[1]); int C = to!int(inputs[2]); if(C >= A && C <= B) "Yes".writeln; else "No".writeln; }
D
import std.stdio, std.string, std.conv; void main() { while(true){ string s = readln; if (stdin.eof()) break; int n = s.chomp.to!int; int c = 0; foreach(int i; 0..10) foreach(int j; 0..10) foreach(int k; 0..10) foreach(int l; 0..10) if (i + j + k + l == n){ c += 1; } writeln(c); } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { string s = readln.strip; long sm = 0, cnt = 0; foreach(i,c;s) if(c == 'W') sm += i - cnt++; writeln(sm); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto S = RD; auto W = RD; writeln(W >= S ? "unsafe" : "safe"); stdout.flush; debug readln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias Pair = Tuple!(long, "number", long, "times"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { auto s = sread(); sort(cast(ubyte[])s); if(s[0] == s[1] && s[2] == s[3] && s[1] && s[1] != s[2]) writeln("Yes"); else writeln("No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum CF = "CODEFESTIVAL2016"; void main() { auto S = readln.chomp; int r; foreach (i, c; S) if (c != CF[i]) ++r; writeln(r); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); string t; readV(t); auto ns = s.length.to!int, nt = t.length.to!int; auto dp = new int[][](ns+1, nt+1); foreach (i; 1..ns+1) foreach (j; 1..nt+1) { dp[i][j] = max(dp[i-1][j], dp[i][j-1]); if (s[i-1] == t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1); } char[] r; auto i = ns, j = nt; while (i > 0 && j > 0) { if (dp[i-1][j] == dp[i][j]) --i; else if (dp[i][j-1] == dp[i][j]) --j; else { r ~= s[i-1]; --i; --j; } } r.reverse(); writeln(r); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new int[](t); foreach (ti; 0..t) { auto s = RD!string; int n = cast(int)s.length; auto a = new int[](s.length); auto cnt = new int[](10); foreach (i; 0..s.length) { a[i] = s[i] - '0'; ++cnt[a[i]]; } int best; foreach (i; 0..10) best.chmax(cnt[i]); ans[ti] = n - best; foreach (i; 0..10) { foreach (j; i+1..10) { int last = -1; int c; foreach (e; a) { if (last != e && (e == i || e == j)) { ++c; last = e; } } if (c % 2) --c; ans[ti].chmin(n - c); } } } foreach (e; ans) { writeln(e); } stdout.flush; debug readln; }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; import core.bitop; T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T)(in string str) { return str.split.to!(T[]); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; } long mod = pow(10, 9) + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } /*struct UnionFind { void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; } long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); } bool same(long i, long j) { return root(i) == root(j); } void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; } long[] par; }*/ struct UnionFind { void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; dist = new long[](n); } long root(long i) { if (par[i] == i) return i; else { auto d = distance(par[i]); par[i] = root(par[i]); dist[i] += d; return par[i]; } } bool same(long i, long j) { return root(i) == root(j); } long distance(long i) { long d; long pos = i; while (par[pos] != pos) { d += dist[pos]; pos = par[pos]; } return d; } bool unite(long i, long j, long d) { auto root_i = root(i); auto root_j = root(j); auto d_i = distance(i); auto d_j = distance(j); if (root_i == root_j) { return d_i - d_j == d; } else { par[root_i] = j; dist[root_i] = d - d_i; return true; } } long[] par; long[] dist; } void main() { auto N = RD!long; auto M = RD!long; UnionFind uf; uf.init(N); foreach (i; 0..M) { auto L = RD!long - 1; auto R = RD!long - 1; auto D = RD!long; auto r = uf.unite(R, L, D); if (!r) { writeln("No"); return; } } writeln("Yes"); stdout.flush(); }
D
import std.stdio, std.string, std.algorithm, std.conv, std.array, std.math, std.container, std.range; void main(){ readln.split.map!(to!int).reduce!"a-b+1".writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto ad = readln.split.to!(int[]); auto A = ad[0]; auto B = ad[1]; auto C = ad[2]; auto D = ad[3]; for (;;) { C -= B; if (C <= 0) { writeln("Yes"); return; } A -= D; if (A <= 0) { writeln("No"); return; } } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto N = RD!string; bool ans; foreach (i; 0..3) { if (N[i] == '7') ans = true; } writeln(ans ? "Yes" : "No"); stdout.flush; debug readln; }
D
void main(){ int[] a = _scanln(); writeln( a.sum()>=22? "bust": "win" ); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto A = scanElem; auto B = scanElem; writeln((A+B+1)/2); }
D
import std.stdio; import std.string; void main() { char[] input = chomp(readln).dup; int i = 0; foreach(e; input) { if(e == '+') { i += 1; } else { i -= 1; } } writeln(i); }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; import core.stdc.stdlib; long scanState() { auto s = scanElem!string; if(s=="Male") return 0; if(s=="Female") return 1; exit(0); return 0; } void main() { long N = scanElem; writeln(0); stdout.flush; auto o = scanState; long s = 0; long l = N-1; foreach(_;0..19) { auto i = (s+l)/2; writeln(i); stdout.flush; auto res = scanState; if(((i%2)^o)==res)s=i; if(((i%2)^o)!=res)l=i; if(abs(s-l)==1) { writeln(l);stdout.flush; exit(0); } } } class UnionFind{ UnionFind parent = null; void merge(UnionFind a) { if(same(a)) return; a.root.parent = this.root; } UnionFind root() { if(parent is null)return this; return parent = parent.root; } bool same(UnionFind a) { return this.root == a.root; } } void scanValues(TList...)(ref TList list) { auto lit = readln.splitter; foreach (ref e; list) { e = lit.fornt.to!(typeof(e)); lit.popFront; } } T[] scanArray(T = long)() { return readln.split.to!(long[]); } void scanStructs(T)(ref T[] t, size_t n) { t.length = n; foreach (ref e; t) { auto line = readln.split; foreach (i, ref v; e.tupleof) { v = line[i].to!(typeof(v)); } } } long scanULong(){ long x; while(true){ const c = getchar; if(c<'0'||c>'9'){ break; } x = x*10+c-'0'; } return x; } T scanElem(T = long)() { char[] res; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { res ~= cast(char) c; c = getchar; } return res.strip.to!T; } template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } struct Factor { long n; long c; } Factor[] factors(long n) { Factor[] res; for (long i = 2; i ^^ 2 <= n; i++) { if (n % i != 0) continue; int c; while (n % i == 0) { n = n / i; c++; } res ~= Factor(i, c); } if (n != 1) res ~= Factor(n, 1); return res; } long[] primes(long n) { if(n<2)return []; auto table = new long[n+1]; long[] res; for(int i = 2;i<=n;i++) { if(table[i]==-1) continue; for(int a = i;a<table.length;a+=i) { table[a] = -1; } res ~= i; } return res; } bool isPrime(long n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long i = 3; i ^^ 2 <= n; i += 2) if (n % i == 0) return false; return true; }
D
import std.stdio, std.conv, std.string; void main() { int [] a; a = readln().chomp().split().to!(int[]); if(a[0] <= 8 && a[1] <= 8) writeln("Yay!"); else writeln(":("); }
D
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { int n; scanf("%d", &n); int[] x = new int[n]; foreach (i; 0..n) scanf("%d", &x[i]); int[] y = x.dup; y.sort; int l = y[n/2-1], r = y[n/2]; foreach (i; 0..n) { if (x[i] <= l) writeln(r); else writeln(l); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N = lread(); auto f = new long[](N); foreach (x; 1 .. N + 1) { foreach (y; factorize(x)) f[y]++; } auto dp = new long[][](N, 77); dp[0][1] = 1; foreach (i; 1 .. N) { foreach (j; 0 .. f[i] + 1) { foreach (k; 0 .. 77) { long cnt = k * (j + 1); dp[i][min(cnt, 76)] += dp[i - 1][k]; } } } writeln(dp[$ - 1][75]); } /// 素因数分解 long[] factorize(long x) { assert(0 < x, "x is negative"); long[] result; while ((x & 1) == 0) { x /= 2; result ~= 2; } for (long i = 3; i * i <= x; i += 2) while (x % i == 0) { x /= i; result ~= i; } if (x != 1) result ~= x; return result; }
D
void main() { int[] tmp = readln.split.to!(int[]); int d = tmp[0], n = tmp[1]; writeln(n != 100 ? 100 ^^ d * n : 100 ^^ d * (n + 1)); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.uni;
D
import std.stdio; import std.string; import std.algorithm; void main() { auto s = readln.chomp; size_t begin, end = 1, cnt; string cache = ""; while (end < s.length) { if (cache != s[begin..end]) { ++cnt; cache = s[begin..end]; begin = end; end = end + 1; } else { ++end; } } if (cache == s[begin..end]) write(cnt); else write(cnt+1); }
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii, std.typecons, std.format; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } // }}} void main() { auto cin = new Scanner; long a, b, c; cin.scan(a, b, c); writeln(c - a - b > 0 && 4 * a * b < (c - a - b) ^^ 2 ? "Yes" : "No"); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; int cmp(string a, string b) { if (a.length == b.length) { if (a == b) return 0; return a < b ? -1 : 1; } else if (a.length < b.length) { return -1; } return 1; } void main() { auto a = read!string; auto b = read!string; auto c = cmp(a, b); if (c < 0) writeln("LESS"); else if (c == 0) writeln("EQUAL"); else writeln("GREATER"); }
D
import std.stdio,std.conv, std.string; void main(){ if(readln.chomp.to!int == 1){ writeln("Hello World");} else{ auto a = readln.chomp.to!int; auto b = readln.chomp.to!int; writeln(a+b);} }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto T = RD!int; auto ans = new string[](T); foreach (ti; 0..T) { auto t = RD!string; bool[char] set; foreach (c; t) { set[c] = true; } if (set.keys.length == 1) { ans[ti] = t; } else { char last; foreach (i; 0..t.length) { if (t[i] == last) { if (t[i] == '0') ans[ti] ~= "10"; else ans[ti] ~= "01"; } else { ans[ti] ~= t[i]; } last = t[i]; } } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio; import std.string; import std.conv; void main(){ int n = stdin.readln.chomp.to!int; int money = 100_000; while(n--){ money = cast(int)(money * 1.05); if(money % 1_000) money = money - (money % 1_000) + 1_000; } writeln(money); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto u = s[1] - 1; auto v = s[2] - 1; auto G = new int[][](N); foreach (i; 0..N-1) { s = readln.split.map!(to!int); G[s[0]-1] ~= s[1]-1; G[s[1]-1] ~= s[0]-1; } auto d = new int[](N); auto b = new bool[](N); auto dd = new int[](N); void dfs3(int n, int p, int v) { dd[n] = v; foreach (m; G[n]) if (m != p) { dfs3(m, n, v+1); } } bool dfs2(int n, int p) { if (n == u) return b[n] = true; foreach (m; G[n]) if (p != m) { if (dfs2(m, n)) return b[n] = true; } return false; } int dfs(int n, int p) { foreach (m; G[n]) if (m != p) { if (p == -1 && !b[m] ) continue; d[n] = max(d[n], dfs(m, n) + 1); } return d[n]; } dfs3(v, -1, 0); dfs2(v, -1); dfs(v, -1); int dist = dd[u] / 2 - (1 - dd[u] % 2); int ans = 0; foreach (i; 0..N) if (b[i] && dd[u] - dd[i] <= dist) { int turn = (dd[u] - dd[i]); int hoge = (dd[i] - turn) % 2; int val = d[i] + dd[u] - dd[i]; val = hoge ? val : val + 1; ans = max(ans, val); } ans.writeln; }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const tmp = readln.split.to!(long[]); const a = tmp[0], b = tmp[1], c = tmp[2], d = tmp[3]; writeln(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d) ? "Yes" : "No"); }
D
import std.stdio; import std.algorithm; import std.string; import std.range; string[dchar] code1; dchar[string] code2; void main() { code1[' '] = "101"; code1['\''] = "000000"; code1[','] = "000011"; code1['-'] = "10010001"; code1['.'] = "010001"; code1['?'] = "000001"; code1['A'] = "100101"; code1['B'] = "10011010"; code1['C'] = "0101"; code1['D'] = "0001"; code1['E'] = "110"; code1['F'] = "01001"; code1['G'] = "10011011"; code1['H'] = "010000"; code1['I'] = "0111"; code1['J'] = "10011000"; code1['K'] = "0110"; code1['L'] = "00100"; code1['M'] = "10011001"; code1['N'] = "10011110"; code1['O'] = "00101"; code1['P'] = "111"; code1['Q'] = "10011111"; code1['R'] = "1000"; code1['S'] = "00110"; code1['T'] = "00111"; code1['U'] = "10011100"; code1['V'] = "10011101"; code1['W'] = "000010"; code1['X'] = "10010010"; code1['Y'] = "10010011"; code1['Z'] = "10010000"; code2["00000"] = 'A'; code2["00001"] = 'B'; code2["00010"] = 'C'; code2["00011"] = 'D'; code2["00100"] = 'E'; code2["00101"] = 'F'; code2["00110"] = 'G'; code2["00111"] = 'H'; code2["01000"] = 'I'; code2["01001"] = 'J'; code2["01010"] = 'K'; code2["01011"] = 'L'; code2["01100"] = 'M'; code2["01101"] = 'N'; code2["01110"] = 'O'; code2["01111"] = 'P'; code2["10000"] = 'Q'; code2["10001"] = 'R'; code2["10010"] = 'S'; code2["10011"] = 'T'; code2["10100"] = 'U'; code2["10101"] = 'V'; code2["10110"] = 'W'; code2["10111"] = 'X'; code2["11000"] = 'Y'; code2["11001"] = 'Z'; code2["11010"] = ' '; code2["11011"] = '.'; code2["11100"] = ','; code2["11101"] = '-'; code2["11110"] = '\''; code2["11111"] = '?'; while(!stdin.eof()) { auto s1 = readln().chomp(); if(!s1.empty()) { auto s2 = map!(a => code1[a])(s1).join(""); while(!s2.empty()) { while(s2.length < 5) s2 = s2 ~ '0'; write(code2[s2[0..5]]); s2 = s2.drop(5); } writeln(); } } }
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { foreach(_;0..readln().chomp().to!int()) { bool f=true; auto a=int.min, b=a; foreach(v;readln().split().map!(to!int)) if(v>a) a=v; else if(v>b) b=v; else{ f=false; break; } writeln(f?"YES":"NO"); } }
D
void main(){ string[] st = _scanln!string(); writeln(st[1], st[0]); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto S = RD!string; bool ans = true; { long l, r = S.length / 2 - 1; while (l < r) { if (S[l] != S[r]) ans = false; ++l; --r; } } { long l = S.length / 2 + 1, r = S.length - 1; while (l < r) { if (S[l] != S[r]) ans = false; ++l; --r; } } { long l = 0, r = S.length - 1; while (l < r) { if (S[l] != S[r]) ans = false; ++l; --r; } } writeln(ans ? "Yes" : "No"); stdout.flush; debug readln; }
D
import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main () { long [] a; while ((a = readln.splitter.map !(to !(long)).array) != []) { auto n = readln.strip.to !(long); foreach (i, c; a) { if (i > 0) { a[i] = min (a[i], a[i - 1] * 2); } } writeln (a[3] * (n / 2) + a[2] * (n % 2)); } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto s = readln.chomp; auto isValid(bool[] sw) { foreach (i; 2..n) sw[i] = sw[i-1] ^ (s[i-1] != 'o') ^ sw[i-2]; return ((sw[$-1] ^ (s[$-1] != 'o') ^ sw[$-2]) == sw[0] && (sw[0] ^ (s[0] != 'o') ^ sw[$-1]) == sw[1]); } foreach (sw1; [false, true]) foreach (sw2; [false, true]) { auto sw = new bool[](n); sw[0] = sw1; sw[1] = sw2; if (isValid(sw)) { foreach (swi; sw) write(swi ? 'W' : 'S'); writeln; return; } } writeln(-1); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { int N = readln.chomp.to!(int); int[] a = readln.chomp.split.to!(int[]); int ans; for (int i = 0; i < a.length - 1; i++) { if (a[i] == a[i + 1]) { ans += 1; i += 1; } } writeln(ans); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { auto n = lread(); auto t = new long[](n); foreach (ref e; t) e = lread(); long lcm = t[0]; foreach (e; t[1 .. $]) { lcm /= gcd(lcm, e); lcm *= e; } lcm.writeln(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { long N = lread(); writeln(N * 800 - N / 15 * 200); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!long; if (N == 2) { writeln(1); return; } int res; long d; for (d = 2; d^^2 < N; ++d) { if (N % d == 1) { auto dd = (N-1)/d; res += d == dd ? 1 : 2; } if (N % d == 0) { auto n = N; while (n%d == 0) n /= d; if (n % d == 1) { ++res; } auto dd = N / d; n = N; while (n % dd == 0) n /= dd; if (n % dd == 1) { ++res; } } } if (d^^2 == N) { ++res; } writeln(res+2); }
D
import std.stdio, std.string, std.array, std.conv; void main() { auto a = readln.chomp.split.to!(int[]); writeln(a[0] < a[1] && a[1] < a[2] ? "Yes" : "No"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, m; rd(n, m); auto g=new int[][](n, 0); foreach(_; 0..m){ int a, b; rd(a, b); a--; b--; g[a]~=b; g[b]~=a; } auto c=new int[](n); fill(c, -1); bool dfs(int i, int w, int p=-1){ c[i]=w; bool ret=true; foreach(j; g[i])if(j!=p){ if(c[j]==-1) ret&=dfs(j, w^1, i); if((c[j]^w)==0) ret=false; } return ret; } if(dfs(0, 0)){ long w=0; foreach(e; c)if(e==0) w++; auto b=to!long(n)-w; writeln(w*b-m); }else{ auto _n=to!long(n); writeln(_n*(_n-1)/2-m); } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D