code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.csv; import std.regex; import std.math; import core.time; import std.ascii; import std.digest.sha; import std.outbuffer; import std.numeric; import std.bigint; import core.checkedint; void main() { string[string] dic = [ "purple" : "Power", "green" : "Time", "blue" : "Space", "orange" : "Soul", "red" : "Reality", "yellow" : "Mind" ]; int m = readln.chomp.to!int; foreach (i; 0..m) { string s = readln.chomp; dic.remove(s); } dic.length.writeln; foreach (k, v; dic) { v.writeln; } } void tie(R, Args...)(R arr, ref Args args) if (isRandomAccessRange!R || isArray!R) in { assert (arr.length == args.length); } body { foreach (i, ref v; args) { alias T = typeof(v); v = arr[i].to!T; } } void verbose(Args...)(in Args args) { stderr.write("["); foreach (i, ref v; args) { if (i) stderr.write(", "); stderr.write(v); } stderr.writeln("]"); }
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, std.bitmanip; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto S = readln.chomp; auto T = readln.chomp; if (S.canFind('*')) { if (N > M + 1) { writeln("NO"); return; } bool ok = true; for (int i = 0; S[i] != '*'; ++i) { if (S[i] != T[i]) { ok = false; break; } } for (int i = 0; S[N-i-1] != '*'; ++i) { if (S[N-i-1] != T[M-i-1]) { ok = false; break; } } writeln(ok ? "YES" : "NO"); } else { writeln( S == T ? "YES" : "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 t = RD!int; auto ans = new int[](t); foreach (ti; 0..t) { auto n = RD!int; auto k = RD!int; if (k >= n) { ans[ti] = k - n; } else { n -= k; ans[ti] = n % 2; } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
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; } void main(){ long n = read.to!long; long a = read.to!long; long b = read.to!long; long c = read.to!long; long d = read.to!long; long h = abs(b - a); long m = -(n - 1) * d; long r = (h - m) % (c + d); long x = (n - 1) * (d - c); long q = (h - m - x + (c + d - 1)) / (c + d); string ans = (q <= n - 1 && r <= x)? "YES": "NO"; debug "h m r x q".writeln; debug [h, m, r, x, q].writeln; ans.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 Pair = Tuple!(long, "x", long, "y", long, "cost"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto n = lread(); long sum; foreach(i; iota(n)) { if((i + 1) % 3 && (i + 1) % 5) sum += i + 1; } sum.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
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() { string a, b; scan(a, b); long n = (a ~ b).to!long(); foreach (i; 1 .. 400) if (i * i == n) { writeln("Yes"); return; } writeln("No"); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; bool[100000] prime; void initPrime() { prime[0] = false; prime[1] = false; for (int i = 3; i < 100000; i++) { for (int j = 2; j * j <= i; j++) { if (i % j == 0) { prime[i] = false; } } } } void main() { prime[] = true; initPrime(); int N = readln.chomp.to!(int); int[] ans; for (int i = 3; i <= 55555 && ans.length < N; i++) { if (prime[i] && i % 5 == 1) ans ~= i; } for (int i = 0; i < N; i++) { if (i != 0) write(" "); write(ans[i]); } writeln(); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; 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; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long mod = 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; } void main() { auto N = RD; long cnt_t, cnt_a; foreach (i; 0..N) { auto T = RD; auto A = RD; long pt = 1, pa = 1; if (T < cnt_t) pt = cnt_t / T + (cnt_t % T != 0 ? 1 : 0); if (A < cnt_a) pa = cnt_a / A + (cnt_a % A != 0 ? 1 : 0); auto p = max(pt, pa); cnt_t = T * p; cnt_a = A * p; //stderr.writeln(i, ":", cnt_t, " ", cnt_a); } writeln(cnt_t + cnt_a); stdout.flush(); //readln(); }
D
import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { int x; for (auto i = 1; ; ++i) { x = readln.chomp.to!int; if (x == 0) break; writeln("Case ", i, ": ", x); } }
D
import std.stdio; import std.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; void main() { auto s = readln.chomp; auto abc = "ABC"; auto mod = 10 ^^ 9 + 7; long[][4] dp; foreach (ref row; dp) row = new long[](s.length + 1); dp[3][$ - 1] = 1; foreach_reverse (i; 0 .. s.length) if (s[i] == '?') dp[3][i] = dp[3][i + 1] * 3 % mod; else dp[3][i] = dp[3][i + 1]; foreach_reverse (i; 0 .. s.length) foreach (j; 0 .. 3) { if (s[i] == '?') dp[j][i] = dp[j][i + 1] * 3 % mod; else dp[j][i] = dp[j][i + 1]; if (s[i] == '?' || s[i] == abc[j]) dp[j][i] = (dp[j][i] + dp[j + 1][i + 1]) % mod; } // foreach (r; dp) // writeln(r); dp[0][0].writeln; }
D
import std.stdio; import std.array; import std.conv; import std.algorithm; struct gom{ int x = -1; int depth=-1; this(int a,int b){ x = a; depth = b; } } gom[][5000] kugi; void main(){ string[] fi = readln().split(); int n = to!int(fi[0]); int m = to!int(fi[1]); for(int i = 0;i < m;++i){ string[] input = readln().split(); int a = to!int(input[0]); int b = to!int(input[1]); int c = to!int(input[2]); kugi[a-1] ~= gom(b-1,c); } int res = 0; int[] now = new int[5001]; int[] next = new int[5001]; now[] = -1; next[] = -1; for(int i = 0;i < n;++i){ foreach(gom k;kugi[i]){ now[k.x] = max(now[k.x],k.depth); } foreach(int x,int k;now[0..i+1]){ if(k >= 0){ ++res; } next[x] = max(next[x],k-1); next[x+1] = max(next[x+1],k-1); } int[] tmp = now; now = next; next = tmp; next[] = -1; } writeln(res); }
D
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm; void main(){ auto N = readln.chomp.to!int; if(N <= 999) writeln("ABC"); else writeln("ABD"); }
D
import std.stdio; void main() { auto s = readln; auto r = (s[0] == s[1] && s[0] == s[2]) ? "No" : "Yes"; writeln(r); }
D
// Vicfred // https://atcoder.jp/contests/abc045/tasks/abc045_b import std.array; import std.stdio; import std.string; import std.range.primitives; void main() { string a = readln.strip; string b = readln.strip; string c = readln.strip; char[] A; foreach(ch; a) A ~= ch; char[] B; foreach(ch; b) B ~= ch; char[] C; foreach(ch; c) C ~= ch; char[][char] deck; deck['a'] = A; deck['b'] = B; deck['c'] = C; char current = 'a'; while(deck[current].length > 0) { char temp = deck[current][0]; deck[current].popFront; current = temp; } if(current == 'a') "A".writeln; if(current == 'b') "B".writeln; if(current == 'c') "C".writeln; }
D
import std.stdio; import std.string; import std.conv; void main() { int[] buf = readln.chomp.split.to!(int[]); int a = buf[0], p = buf[1]; writeln((a * 3 + p) / 2); }
D
import std.stdio; import std.array; import std.conv; import std.algorithm; import std.math; void main() { string s; while( (s=readln()).length != 0 ){ string[] input = split(s); int a = to!int(input[0]); int x= 0; for(int i=0;i<10;i++){ if(a%2==1){ if(x!=0) write(" "); write(pow(2,i)); x++; } a/=2; } writeln(); } }
D
import std.stdio; import std.string; void main() { string input; int count = 0; for (int i = 1; ; i++) { input = chomp(readln()); if (input == "0") break; writeln("Case ", i, ": ", input); } }
D
import std.stdio; import std.string; import std.conv; import std.array; void main() { ulong N = readln.split[0].to!ulong; string S = readln.chomp; S = "." ~ S ~ "#"; int switch_i = 0; while (S[switch_i] == '.') switch_i++; int cnt = 0; foreach (i; switch_i..(N + 2)) if (S[i] == '.') cnt++; int ans = cnt; int cnt0 = 0; int cnt1 = 0; foreach (i; switch_i..(N + 1)){ if (S[i] == '.') cnt0++; else cnt1++; if (S[i] == '.' && S[i + 1] == '#'){ cnt = cnt + cnt1 - cnt0; if (cnt < ans) ans = cnt; cnt0 = 0; cnt1 = 0; } } writeln(ans); }
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // const long infty = 1_000_000_000_000_000_100; void solve(){ int n = read.to!int; long[] as; foreach(i; 0 .. n) as ~= read.to!long; long calc(long x, long y, int l, int r){ if(l + 1 == r) return 0; long res = infty; foreach(i; l + 1 .. r){ long temp = calc(x, x + y, l, i) + (x + y) * as[i] + calc(x + y, y, i, r); res = min(res, temp); } return res; } long ans = as[0] + calc(1, 1, 0, n - 1) + as[n - 1]; ans.writeln; }
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; long MOD = 10^^9 + 7; void main() { auto N = readln.chomp; auto K = readln.chomp.to!int; auto dp = new int[](1001); dp[1] = 1; for (int i = 2; i <= 1000; ++i) { dp[i] = dp[i.popcnt] + 1; } auto dp2 = new long[][][](N.length+1, N.length+1, 2); dp2[0][0][0] = 1; foreach (i; 0..N.length) { foreach (j; 0..N.length+1) { foreach (k; 0..2) { int digit = (k || N[i] == '1') ? 2 : 1; foreach (d; 0..digit) { if (j+d <= N.length) (dp2[i+1][j+d][k||(d < N[i]-'0')] += dp2[i][j][k]) %= MOD; } } } } long ans = 0; foreach (i; 1..N.length+1) { if (dp[i] == K) { (ans += dp2[N.length][i][0]) %= MOD; (ans += dp2[N.length][i][1]) %= MOD; } } if (K == 1) { ans -= 1; ans %= MOD; } else if (K == 0) { ans = 1; } ans.writeln; }
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; // 差の絶対値 @nogc @safe pure T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } // 切り上げ除算 @nogc @safe pure T divCeil(T)(const ref T a, const ref T b) { return (a+b-1)/b; } T[] readToArray(T)() { return readln.split.to!(T[]); } void readInto(T...)(ref T ts) { auto ss = readln.split; foreach(ref t; ts) { t = ss.front.to!(typeof(t)); ss.popFront; } } // 冪乗をmod取りつつ計算 @nogc @safe pure ulong modPow(ulong a, ulong n, ulong m) { ulong r = 1; while (n > 0) { if(n % 2 != 0) r = r * a % m; a = a * a % m; n /= 2; } return r; } // フェルマーの小定理から乗法逆元を計算 // 定理の要請により法は素数 @nogc @safe pure ulong modInv(ulong a, ulong m) { return modPow(a, m-2, m); } // mod取りつつ順列を計算 @nogc @safe pure ulong modPerm(ulong n, ulong k, ulong m) { if (n < k) return 0; ulong r = 1; for (ulong i = n-k+1; i <= n; i++) { r *= i; r %= m; } return r; } // mod取りつつ順列を計算 @nogc @safe pure ulong modFact(ulong n, ulong m) { return modPerm(n, n, m); } // mod取りつつ組み合わせを計算 // modInvを使っているので法は素数 @nogc @safe pure ulong modComb(ulong n, ulong r, ulong m) { return modPerm(n, r, m)*modInv(modFact(r, m), m) % m; } immutable ulong MOD = 1000000007; void main() { ulong m, d; readInto(m, d); ulong cnt = 0; for(ulong i = 1; i <= m; i++) { for (ulong j = 1; j <= d; j++) { ulong d1 = j%10; ulong d2 = j/10; if (d1 >= 2 && d2 >= 2 && d1*d2 == i) { cnt++; } } } writeln(cnt); }
D
module main; import std.stdio : readln, writeln, write, writefln, writef; import std.conv : to; import std.array : split, replace; import std.string : strip; import std.algorithm : max, min, map, reduce, sort, reverse; import std.functional : memoize; version = B; version (A) { void main() { auto sequence = read_one!string(); auto instructions = read_one!string(); size_t position = 0; foreach (instruction; instructions) { if (sequence[position] == instruction) { position += 1; } } writeln(position + 1); } } version (B) { T abs(T)(T x) { if (x < 0) return -x; return x; } void main() { auto n = read_one!int(); auto heights = new int[n+1]; foreach (i; 1..n+1) { heights[i] = read_one!int(); } auto answer = n * 2 - 1; foreach (i; 0..n) { answer += abs(heights[i] - heights[i+1]); } writeln(answer); // walks: heights[0] + (heights[i] - heights[i-1]).map!abs.sum // jumps: n-1 // eats: n } } version (C) { void main() { auto n = read_one!int(); } } version (D) { void main() { auto n = read_one!int(); } } version (E) { void main() { } } T read_one(T)() { return readln().strip().to!T(); } T[] read_some(T)() { T[] ret; foreach (e; readln().strip().split()) { ret ~= e.to!T(); } return ret; } T[m] read_fixed(int m, T)() { T[m] ret; foreach (i, e; readln().strip().split()) { ret[i] = e.to!T(); } return ret; }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; import std.random; import std.typecons; import std.datetime.systime : Clock; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); p = stdin.rawRead (buffer); } final ubyte skipByte (ubyte lo) { while (true) { auto a = p[cur .. $]; auto r = a.find! (c => c >= lo); if (!r.empty) { cur += a.length - r.length; return p[cur++]; } p = stdin.rawRead (buffer); cur = 0; if (p.empty) return 0; } } final ubyte nextByte () { if (cur < p.length) { return p[cur++]; } p = stdin.rawRead (buffer); if (p.empty) return 0; cur = 1; return p[0]; } template next(T) if (isSigned!T) { final T next () { T res; ubyte b = skipByte (45); if (b == 45) { while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { final T next () { T res = skipByte (48) - 48; while (true) { ubyte b = nextByte (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } final T[] nextA(T) (int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } alias T = Tuple!(uint, uint); void main() { rndGen.seed ((Clock.currTime.toHash & 0xffffffffU).to!uint); auto r = new InputReader; immutable n = r.next!uint, m = r.next!uint; auto a = uninitializedArray!(T[]) (m); bool[ulong] h; foreach (i; 0 .. m) { uint u = r.next!uint - 1, v = r.next!uint - 1; if (u > v) swap (u, v); a[i] = tuple (u, v); h[(u.to!ulong << 32) + v] = true; } randomShuffle (a); bool check (int k) { foreach (const p; a) { uint u = (p[0] + k) % n, v = (p[1] + k) % n; if (u > v) swap (u, v); if (! (((u.to!ulong << 32) + v) in h)) return false; } return true; } foreach (k; 1 .. n) { if (check (k)) { writeln ("Yes"); return; } } writeln ("No"); }
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 c = RD!string; auto str = "aiueo"; bool ans; foreach (s; str) { if (s == c[0]) ans = true; } writeln(ans ? "vowel" : "consonant"); stdout.flush(); debug readln(); }
D
void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], k = tmp[1]; writeln(n % k != 0 ? 1 : 0); } 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 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; import std.ascii; void main() { auto s = readln.chomp; int res; switch (s) { case "SUN": res = 7; break; case "MON": res = 6; break; case "TUE": res = 5; break; case "WED": res = 4; break; case "THU": res = 3; break; case "FRI": res = 2; break; case "SAT": res = 1; break; default: } res.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); } void main() { auto s = sread(); long N = s.to!long(); long SN = s.map!(c => cast(long)(c - '0'))().sum(); writeln((N % SN == 0) ? "Yes" : "No"); }
D
import std.stdio; import std.string; void main() { auto n = readln; auto s = readln.strip; writeln( solve( s ) ); } int solve( in string s ) { auto lc = new int[ s.length ]; lc[ 0 ] = 0; foreach( i; 1 .. s.length ) { lc[ i ] = lc[ i - 1 ] + ( s[ i - 1 ] == 'E' ? 0 : 1 ); } auto rc = new int[ s.length ]; rc[ $-1 ] = 0; foreach_reverse( i; 0 .. s.length-1 ) { rc[ i ] = rc[ i + 1 ] + ( s[ i + 1 ] == 'W' ? 0 : 1 ); } auto result = lc[ 0 ] + rc[ 0 ]; foreach( i; 1 .. s.length ) { auto lrc = lc[ i ] + rc[ i ]; if( lrc < result ) result = lrc; } return result; } unittest { assert( solve( "WEEWW" ) == 1 ); assert( solve( "WEWEWEEEWWWE" ) == 4 ); assert( solve( "WWWWWEEE" ) == 3 ); }
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; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long mod = 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; } void main() { auto N = RD; auto Q = RD; auto s = RD!string; auto t = new char[](Q); auto d = new char[](Q); foreach (i; 0..Q) { t[i] = RD!char; d[i] = RD!char; } long[256] cnt1, cnt2; long l, r = s.length - 1; foreach_reverse (i; 0..Q) { auto num = t[i] - 'A'; if (d[i] == 'L') { if (t[i] == s[l]) ++l; if (r != s.length - 1) { if (s[r+1] == t[i]) ++r; } } else if (d[i] == 'R') { if (t[i] == s[r]) --r; if (l != 0) { if (s[l-1] == t[i]) --l; } } } writeln(r - l + 1); stdout.flush(); debug readln(); }
D
import std.stdio, std.array, std.conv, std.string; void main() { while (true) { string[] input = split(readln()); int h = to!int(input[0]); int w = to!int(input[1]); if (h == 0 && w == 0) return; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { write("#"); } writeln(""); } writeln(""); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void main() { auto nxt = readln.split.to!(int[]); auto N = nxt[0]; auto X = nxt[1]; auto T = nxt[2]; writeln((N + X - 1) / X * T); }
D
import std.stdio, std.conv, std.string; void main() { int N = to!(int)(readln().chomp()); writeln(N/3); }
D
import std.stdio; import std.algorithm; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() {//try{ auto tokens = split(my_readln()); auto N = to!ulong(tokens[0]); ulong[] A; foreach (i; 0..N) { auto tokens2 = split(my_readln()); A ~= to!ulong(tokens2[0]); } string ans = "second"; foreach (e; A) { if (e % 2 == 1) { ans = "first"; break; } } writeln(ans); stdout.flush(); /*}catch (Throwable e) { writeln(e.toString()); } readln();*/ }
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; static import std.ascii; // 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 g, p; long ans; foreach (c; S) { if (c == 'p') { if (p < g) { p++; } else { g++; ans--; } } else if (c == 'g') { if (p < g) { p++; ans++; } else { g++; } } } writeln(ans); }
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(); long K = lread(); long solve(long x, long i) { if (i == N) return x; return min(solve(x * 2, i + 1), solve(x + K, i + 1)); } solve(1, 0).writeln(); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp, a = s.map!(c => cast(int)(c-'0')).sum, n = s.to!int; writeln(n%a == 0 ? "Yes" : "No"); }
D
void main() { string s = readln.chomp; auto g = s.group.array; writeln(g.length - 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.ascii; import std.uni;
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() { auto C = new string[](2); C[0] = sread(); C[1] = sread(); writeln((C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0]) ? "YES" : "NO"); }
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() { long n, m; scan(n, m); auto dif = abs(n - m); if(dif == 1) { auto set = product_mod(min(n, m)); set *= set; set %= bignum; set *= max(n, m); set %= bignum; set.writeln(); } else if(dif == 0) { auto set = product_mod(n); set *= set; set %= bignum; set *= 2; set %= bignum; set.writeln(); } else writeln(0); } long product_mod(long n) { if(n == 1) return 1; return n * product_mod(n - 1) % bignum; }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { auto x = lread(); long ans; foreach (p; 2 .. 11) { foreach (b; 1 .. 1001) { if (b ^^ p <= x) { ans = max(ans, b ^^ p); } } } writeln(ans); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto b = readln.split[0]; if (b == "A") "T".writeln; if (b == "T") "A".writeln; if (b == "G") "C".writeln; if (b == "C") "G".writeln; }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long n, k; scan(n, k); auto a = aryread(); // writeln(a); // writeln(ceil(a.length / k) * (k - 1) // long ans = ((a.length + k - 1) / k) * (k - 1); // writeln(ans); long i = 0; long cnt; while (i < n) { i += k; if (i == n) { cnt += 1; break; } i -= 1; cnt += 1; } writeln(cnt); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; 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() { long a, b, c, d, e, f, g, h, i; scan(a, b, c); scan(d, e, f); scan(g, h, i); bool x = a - b == d - e; x = x && d - e == g - h; x = x && b - c == e - f; x = x && e - f == h - i; x = x && a - d == b - e; x = x && b - e == c - f; x = x && d - g == e - h; x = x && e - h == f - i; writeln(x ? "Yes" : "No"); }
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; void main() { long N; scan(N); auto ans = N * (N - 1) / 2; writeln(ans); } void scan(T...)(ref T args) { auto 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); } } } 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; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }
D
import std.stdio, std.string, std.conv, std.math; void main(){ real x = 0, y = 0, rad = 90; while(true){ auto line = readln.chomp.split(","); auto speed = line[0].to!int; if(speed == 0) break; x += cos(rad / 180 * PI) * speed; y += sin(rad / 180 * PI) * speed; rad -= line[1].to!int; } writeln(cast(int)x); writeln(cast(int)y); }
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; 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; } enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { long n; scan(n); long ans = infl; for (long i = 1; i*i <= n; i++) { if (n % i == 0) { chmin(ans, (i - 1) + (n / i - 1)); } } writeln(ans); }
D
import std.stdio; import std.string; import std.conv; import std.math; void main () { double a = 100000; int n = to!int(chomp(readln())); foreach (i; 0 .. n) { a = a * 1.05; if(a % 1000) a = a - (a % 1000) + 1000; } writeln(to!int(a)); }
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 = "%.15f"; 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; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } 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; writeln(N^^3); stdout.flush(); debug readln(); }
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 k; readV(k); writeln((k/2) * ((k+1)/2)); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial; void main(){ auto a=readln.chomp.to!int; auto b=readln.chomp.to!int; auto h=readln.chomp.to!int; writeln((a+b)*h/2); }
D
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; immutable long mod = 10^^9 + 7; immutable long inf = mod; void main(){ long n, m; readVars(n, m); auto ans = modpow(n, m, mod); writeln(ans); } bool is_prime(int x){ for(int i = 2; i*i <= x; ++i){ if (x % i == 0) { return false; } } return true; } T modpow(T)(T x, T y, T mod){ T res = 1; while(y > 0){ (res *= x^^(y&1)) %= mod; y >>= 1; x = x^^2 % mod; } return res; } void readVars(T...)(auto ref T args){ auto line = readln.split; foreach(ref arg ; args){ arg = line.front.to!(typeof(arg)); line.popFront; } if(!line.empty){ throw new Exception("args num < input num"); } }
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, K; scan(N, K); auto ans = f(N, K); writeln(ans); } int f(int N, int K) { return N > 0 ? f(N / K, K) + 1 : 0; } 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
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(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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new long[](t); foreach (ti; 0..t) { auto n = RD!int; auto k = RD!int; long tmp = n; tmp.modpow(k); ans[ti] = tmp; } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
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 A, B; scan(A, B); writeln((A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) ? "Possible" : "Impossible"); }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto a = readln.split[0].to!int; auto b = readln.split[0].to!int; auto c = readln.split[0].to!int; auto d = readln.split[0].to!int; auto e = readln.split[0].to!int; auto k = readln.split[0].to!int; if ( e-a > k ) writeln(":("); else writeln("Yay!"); }
D
import std.stdio; // readln import std.array; // split import std.conv; // to void main(){ string[] s = split(readln()); int a = to!int(s[0]); int b = to!int(s[1]); int c = to!int(s[2]); if(a == b) writeln(c); else if(a == c) writeln(b); else writeln(a); }
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() { auto nq = readints(); int n = nq[0], q = nq[1]; auto uf = new UnionFind(n); for (int i = 0; i < q; i++) { auto xs = readints(); int com = xs[0], x = xs[1], y = xs[2]; switch (com) { case 0: uf.unite(x, y); break; case 1: writeln(uf.isSame(x, y) ? 1 : 0); break; default: } } } class UnionFind { private int[] _data; this(int n) { _data = new int[](n + 1); _data[] = -1; } int root(int a) { if (_data[a] < 0) return a; return _data[a] = root(_data[a]); } bool unite(int a, int b) { int rootA = root(a); int rootB = root(b); if (rootA == rootB) return false; _data[rootA] += _data[rootB]; _data[rootB] = rootA; return true; } bool isSame(int a, int b) { return root(a) == root(b); } int size(int a) { return -_data[root(a)]; } }
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ char[] s = readln.chomp.to!(char[]); int status = 0; long count = 0; long ans = 0; foreach(c; s){ if(c == 'A'){ if(status == 1) count += 1; else count = 1, status = 1; } else if(c == 'B'){ if(status == 1) status = 2; else count = 0, status = 0; } else if(c == 'C'){ if(status == 2){ ans += count; status = 1; } else count = 0, status = 0; } log(c, "count:", count, "status:", status, "ans:", ans); } ans.writeln; } /* 頭から見ていく 頭から見ていって損になることはない なぜなら「あえてやらない」=「ABCの形のまま残す」だが BC... あるいは C... の形が役に立つケースはないので A カウンタを+1する  現在位置は「A」 B 現在位置が「A」なら現在位置は「AB」 それ以外ならカウンタを0にして現在位置は「」 C 現在位置が「AB」なら 答えを+1する カウンタが正ならカウンタを−1して答えを+1する 現在位置は「A」 それ以外ならカウンタを0にして現在位置は「」 */
D
import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm, std.typecons; void main(){ auto buf = readln().strip().split().map!(to!int)(); immutable N = buf[0]; immutable K = buf[1]; if((N-1)/2 + 1 >= K) { writeln("YES"); } else { writeln("NO"); } }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return false; } p = stdin.rawRead (buffer); if (p.empty) { eof = true; return false; } return true; } ubyte nextByte(bool check) () { static if (check) { if (p.empty) { if (!rawRead ()) { return 0; } } } auto r = p.front; p.popFront (); return r; } public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); } bool seekByte (in ubyte lo) { while (true) { p = p.find! (c => c >= lo); if (!p.empty) { return false; } if (!rawRead ()) { return true; } } } template next(T) if (isSigned!T) { T next () { if (seekByte (45)) { return 0; } T res; ubyte b = nextByte!false (); if (b == 45) { while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { T next () { if (seekByte (48)) { return 0; } T res = nextByte!false () - 48; while (true) { ubyte b = nextByte!true (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } T[] nextA(T) (in int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } void main() { auto r = new InputReader (); immutable nt = r.next!uint (); foreach (tid; 0 .. nt) { const int n = r.next!uint; const int k = r.next!uint; auto a = r.nextA!uint (n); auto b = new int[n]; foreach (i; 1 .. n - 1) { if (a[i] > a[i-1] && a[i] > a[i+1]) { b[i] = 1; } } foreach (i; 1 .. n) { b[i] += b[i-1]; } int res = -1, peaks = int.min; foreach (j; k .. n + 1) { int i = j - k; //[i, j) int t = b[j - 2] - b[i]; if (peaks < t) { res = i; peaks = t; } } ++res; ++peaks; writeln (peaks, ' ', res); } }
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(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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new string[](t); foreach (ti; 0..t) { auto n = RD!int; auto b = RD!string; ans[ti] ~= '1'; long x; if (b[0] == '1') x = 2; else x = 1; foreach (i; 1..n) { if (x == 2) { x = 1; if (b[i] == '0') ans[ti] ~= '1'; else ans[ti] ~= '0'; } else if (x == 1) { if (b[i] == '0') { ans[ti] ~= '0'; x = 0; } else { ans[ti] ~= '1'; x = 2; } } else { ans[ti] ~= '1'; if (b[i] == '0') x = 1; else x = 2; } } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
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 N = RD; writeln((1000 - (N%1000)) % 1000); stdout.flush; debug readln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; 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(a + b == c || b + c == a || c + a == b) "Yes".writeln; else "No".writeln; }
D
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ auto n = read.to!long; auto h = read.to!long; auto w = read.to!long; auto a = n - h + 1; auto b = n - w + 1; (a * b).writeln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}} void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}} void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}} void main() { int a, b, c, d; readV(a, b, c, d); if (a+b > c+d) writeln("Left"); else if (a+b < c+d) writeln("Right"); else writeln("Balanced"); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.container; import std.array; import std.math; import std.range; import std.typecons; import std.ascii; void main() { readln; auto a = readln.chomp.split.map!(to!int); writeln = a.reduce!max - a.reduce!min; }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto a = lread(); auto s = sread(); if (a >= 3200) writeln(s); else if (a < 3200) writeln("red"); } //https://rclone.org/ void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { auto s = new bool[](10^^5 + 1); s[] = 1; s[0] = s[1] = 0; for (int p = 2; p*p <= 10^^5; p++) { if (s[p]) { for (int q = p*p; q <= 10^^5; q += p) { s[q] = 0; } } } auto t = new int[](10^^5 + 1); foreach (i ; 3 .. 10^^5 + 1) { if (s[i] && s[(i + 1) / 2]) { t[i] = 1; } } foreach (i ; 1 .. 10^^5 + 1) { t[i] += t[i-1]; } int q; int li,ri; scan(q); foreach (i ; 0 .. q) { scan(li, ri); writeln(t[ri] - t[li-1]); } } 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.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 main() { auto n = RD; auto a = RD; auto b = RD; if (a < b) swap(a, b); long ans = 2; ans.modpow(n); ans.mods(1); long x1 = 1, x2 = 1, y1 = 1, y2 = 1; foreach (i; 0..a) { x1.modm(n); y1.modm(a); --a; if (b != 0) { x2.modm(n); y2.modm(b); --b; } --n; } y1.modpow(mod - 2); x1.modm(y1); ans.mods(x1); y2.modpow(mod - 2); x2.modm(y2); ans.mods(x2); writeln(ans); stdout.flush; debug readln; }
D
import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } long extgcd(long a, long b, ref long x, ref long y) { long g = a; x = 1; y = 0; if (b != 0) { g = extgcd(b, a % b, y, x); y -= (a / b) * x; } return g; } void main() { int a, b; scanf("%d %d\n", &a, &b); long x, y; extgcd(a, b, x, y); writeln(x, " ", y); }
D
import std; void main() { const N = readln().chomp().to!uint(); const S = readln().chomp(); size_t ans = count(S, 'R') * count(S, 'G') * count(S, 'B'); foreach (uint i; 0 .. N) foreach (uint j; i + 1 .. N) { if (S[i] == S[j]) continue; const k = 2 * j - i; if (k >= N) continue; if (S[j] == S[k] || S[i] == S[k]) continue; --ans; } writeln(ans); }
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 X = RD!string; long ans; long cnt; foreach (c; X) { if (c == 'S') ++cnt; else if (cnt != 0) { ++ans; --cnt; } } writeln(X.length - ans*2); stdout.flush(); debug readln(); }
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; // dfmt on void main() { long X, Y; scan(X, Y); writeln(X % Y == 0 ? -1 : X); }
D
import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto a = rd[0], b = rd[1]; writeln(a == b ? "a == b" : (a < b ? "a < b" : "a > b")); }
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.range; import std.stdio; import std.string; import std.typecons; void main() { int n = readln.chomp.to!int; bool[int] set; foreach (i; 0..n) { int a = readln.chomp.to!int; if (a in set) { set.remove(a); } else { set[a] = true; } } writeln = set.length; }
D
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { int n, k; scanf("%d%d", &n, &k); int[] x = new int[n]; foreach (i; 0..n) scanf("%d", &x[i]); int c = x.assumeSorted.lowerBound(0).length.to!int; int ans = 1<<30; foreach (i; 0..c+1) { if (i+k > n) break; int l = 0, r = 0; if (i != c) { if (c-i > k) continue; l = -x[i]; } r = max(0, x[i+k-1]); ans = min(ans, l*2+r); ans = min(ans, l+r*2); } writeln(ans); }
D
import std.stdio, std.conv, std.array, std.string; import std.algorithm; import std.container; import std.range; import core.stdc.stdlib; import std.math; import std.typecons; void main() { auto N = readln.chomp.to!int; char[] S = cast(char[])readln.chomp; foreach(i; 0..S.length) { S[i] = 'A' + (S[i] - 'A' + N)%26; } S.writeln; }
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; int a, b, ab, r; foreach (_; 0..N) { auto s = readln.chomp; if (s[0] == 'B' && s[$-1] == 'A') { ++ab; } else if (s[0] == 'B') { ++b; } else if (s[$-1] == 'A') { ++a; } foreach (i; 0..s.length-1) { if (s[i..i+2] == "AB") ++r; } } if (ab > 0) { r += ab-1; if (a > 0) { --a; r += 1; } if (b > 0) { --b; r += 1; } } r += min(a, b); writeln(r); }
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; // dfmt on void main() { long H, W; scan(H, W); long ans = long.max; foreach (h; 1 .. H) { long a = h * W; long b = (H - h) * (W / 2); long c = (H - h) * (W - W / 2); if (a == 0 || b == 0 || c == 0) continue; dprint(a, b, c); ans = ans.min(max(a, b, c) - min(a, b, c)); } foreach (h; 1 .. H) { long a = h * W; long b = ((H - h) / 2) * W; long c = ((H - h) - (H - h) / 2) * W; if (a == 0 || b == 0 || c == 0) continue; dprint(a, b, c); ans = ans.min(max(a, b, c) - min(a, b, c)); } foreach (w; 1 .. W) { long a = w * H; long b = (W - w) * (H / 2); long c = (W - w) * (H - H / 2); if (a == 0 || b == 0 || c == 0) continue; dprint(a, b, c); ans = ans.min(max(a, b, c) - min(a, b, c)); } foreach (w; 1 .. W) { long a = w * H; long b = ((W - w) / 2) * H; long c = ((W - w) - (W - w) / 2) * H; if (a == 0 || b == 0 || c == 0) continue; dprint(a, b, c); ans = ans.min(max(a, b, c) - min(a, b, c)); } writeln(ans); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto n = lread(); auto a = aryread(); long ans; foreach (i; 0 .. n) { ans += a[i] - 1; } writeln(ans); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
import std.stdio; import std.string; import std.ascii; void main() { string s = readln.chomp; writeln( (s.length >= 6 && s.count!(isDigit) >= 1 && s.count!(isUpper) >= 1 && s.count!(isLower) >= 1) ? "VALID" : "INVALID" ); }
D
void main() { long n = readln.chomp.to!long; if (n & 1) { 0.writeln; } else { long cnt; long d = 10; while (d <= n) { cnt += n / d; d *= 5; } cnt.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
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(); alias route = Tuple!(long, "From", long, "To"); 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(); long first_C, first_F; foreach (i,e; s) { if(!first_C && e == 'C') first_C = i + 1; if(e == 'F') first_F = i + 1; } if(first_C && first_F) { if(first_C < first_F) { writeln("Yes"); return; } } writeln("No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp; auto DP = new long[][](2, 2019); long r; foreach (i, c; S) { auto n = c - '0'; foreach (x; 0..2019) DP[i%2][x] = 0; DP[i%2][n] = 1; foreach (x; 0..2019) DP[i%2][(x * 10 + n) % 2019] += DP[(i+1)%2][x]; r += DP[i%2][0]; } writeln(r); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; int main() { int i = 0; while (++i <= 1000) writeln("Hello World"); return 0; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.container; import std.array; import std.math; import std.range; import std.typecons; import std.ascii; void main() { writeln = readln.chomp.split.join.to!int % 4 ? "NO" : "YES"; }
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() { writeln(scanString.count!"a=='1'"); }
D
void main() { auto S = rs; bool flag = true; if(S[0] != 'A') flag = false; ulong tmp; foreach(i; 2..S.length-1) { tmp += S[i] == 'C'; } if(flag) { ulong tmp2; foreach(i; S) { if(i.isUpper) tmp2++; } if(tmp2!=2) flag = false; } if(tmp != 1) flag = false; writeln(flag ? "AC" : "WA"); } // =================================== import std.stdio; import std.string; import std.functional; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; import std.container; import std.bigint; import std.numeric; import std.conv; import std.typecons; import std.ascii; import std.bitmanip; import core.bitop; T readAs(T)() if (isBasicType!T) { return readln.chomp.to!T; } T readAs(T)() if (isArray!T) { return readln.split.to!T; } T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { auto s = rs; foreach(j; 0..width) res[i][j] = s[j].to!T; } return res; } int ri() { return readAs!int; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
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; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } 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; /*if (N % 2 == 0) { writeln(N/2, " ", N, " ", N); } else*/ { long h, n, w; (){ foreach (i; 1..3501) { foreach (j; 1..3501) { auto y = (4*i*j - N*j - N*i); if (y <= 0.0) continue; auto z = cast(double)(N*i*j) / y; if (z < 1.0) continue; if (z == cast(double)cast(long)z) { h = i; n = j; w = cast(long)z; return; } } }}(); writeln(h, " ", n, " ", w); } stdout.flush(); debug readln(); }
D
import std.stdio; import std.string; import std.conv; void main(){ string str; string[] input = split(readln()); int a = to!int(input[0]), b = to!int(input[1]); if(a > b) str = " > "; else if(a < b) str = " < "; else str = " == "; writeln('a',str,'b'); }
D
import std.stdio, std.algorithm, std.array, std.string, std.conv; void main() { int t; scanf("%d", &t); getchar(); foreach(_; 0..t) { auto str = readln.strip; int zero_cnt, five_cnt; bool zero_f = false, five_f = false; for(int i = cast (int) str.length - 1; i > 0; i--) { if (str[i] == '0') { int j = i - 1; while((str[j] != '0') && (str[j] != '5') && (!zero_f)) { zero_cnt++; j--; if (j == -1) break; } if (j >= 0) zero_f = true; if (!five_f) five_cnt++; } else if (str[i] == '5') { int j = i - 1; while((str[j] != '2') && (str[j] != '7') && (!five_f)) { five_cnt++; j--; if (j == -1) break; } if (j >= 0) five_f = true; if (!zero_f) zero_cnt++; } else { if (!zero_f) zero_cnt++; if (!five_f) five_cnt++; } } writeln(min(zero_cnt, five_cnt)); } }
D
import std.stdio; import std.algorithm; import std.string; import std.conv; import std.math; bool check(string s){ for(int i=0;i<s.length-3;i++){ string str = s[i..i+4]; if(str == "this" || str == "that"){ writeln(s); return true; } } return false; } void main(){ int n = to!int(chomp(readln())); for(int i=0;i<n;i++){ string ans; auto s = chomp(readln()); int[] ss; for(int a=1;a<=27;a++){ bool flg = false; for(int b=0;b<=26;b++){ flg = false; ans = ""; for(int j=0;j<s.length;j++){ int c = to!int(s[j]-'a'); if(0 <= c && c <= 25){ while((c-b+26)%a!=0){ c += 26; if(c>1000) break; } c = (c-b+26)/a; c %= 26; } ans ~= to!char(c +to!int('a')); } flg = check(ans); if(flg) break; } if(flg){ break; } } } }
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, M; scan(N, M); auto G = new long[][](N); foreach (_; 0 .. M) { long a, b; scan(a, b); a--, b--; G[a] ~= b; G[b] ~= a; } foreach (v; G[0]) { foreach (w; G[v]) if (w == N - 1) { writeln("POSSIBLE"); return; } } writeln("IMPOSSIBLE"); }
D
void main() { problem(); } void problem() { auto N = scan!long; const K = scan!long; long solve() { while(true) { real ratio = cast(real)N / cast(real)K; if (ratio <= 0.5) return N; if (ratio < 1.0) return K - N; N = N - (N/K)*K; } } solve().writeln; } // ---------------------------------------------- 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); } 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.algorithm,std.conv; void main(){ readln; auto a=readln.chomp.split.to!(ulong[]); ulong[ulong] l; foreach(x;a) l[x]++; ulong sum; foreach(x;l.values) sum+=x*(x-1)>>1; foreach(x;a) (sum-(l[x]-1)).writeln; }
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; void main() { auto S = readln.strip; if(S[0]==S[$-1]){ writeln(S.length%2==0?"First":"Second"); }else{ writeln(S.length%2==1?"First":"Second"); } }
D
module aoj; import std.array; import std.stdio; import std.string; void main() { string line; while ((line = chomp(readln())) != "END OF INPUT") { foreach (word; split(line, " ")) { write(word.length); } writeln(); } }
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() { foreach (line; stdin.byLine) { auto x = line.chomp; if (x.length == 0) continue; auto f = new string[](10); f[0] = f[9] = "0000000000"; f[1] = "0" ~ line.to!string ~ "0"; foreach (i; 2..9) { f[i] = "0" ~ readln.chomp ~ "0"; } bool ff; foreach (i; 1..9) { foreach (j; 1..9) { if (f[i][j] == '0') continue; if (f[i+1][j-1] == '1' && f[i][j+1] == '1') writeln("G"); else if (f[i+1][j-1] == '1') writeln("D"); else if (f[i][j+1] == '1' && f[i+1][j] == '1') writeln("A"); else if (f[i][j+1] == '1' && f[i+1][j+1] == '1') writeln("E"); else if (f[i+1][j] == '1' && f[i+1][j+1] == '1') writeln("F"); else if (f[i+1][j] == '1') writeln("B"); else if (f[i][j+1] == '1') writeln("C"); ff = 1; break; } if (ff) break; } } }
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 A = RD; auto B = RD; auto C = RD; writeln(B - A == C - B ? "YES" : "NO"); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.uni; void main() { string w = readln.chomp; int cnt = 0; while (true) { string t = readln.chomp; if (t == "END_OF_TEXT") break; string[] s = t.toLower.split; foreach (x; s) { if (x == w) ++cnt; } } cnt.writeln; }
D