code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.conv, std.string; void main() { int N = to!(int)(readln().chomp()); string [] S = readln().chomp().split(); bool flg = false; foreach(i; S) { if(i=="Y") flg = true; } if(flg) writeln("Four"); else writeln("Three"); }
D
// import chie template :) {{{ static if (__VERSION__ < 2090) { 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, std.bitmanip, std.numeric; } else { import std; } // }}} // 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(T...)(ref T args) { foreach (ref arg; args) { arg = next!(typeof(arg)); } } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } // }}} // alias {{{ alias Heap(T, alias less = "a < b") = BinaryHeap!(Array!T, less); alias MinHeap(T) = Heap!(T, "a > b"); // }}} // memo {{{ /* - ある値が見つかるかどうか <https://dlang.org/phobos/std_algorithm_searching.html#canFind> canFind(r, value); -> bool - 条件に一致するやつだけ残す <https://dlang.org/phobos/std_algorithm_iteration.html#filter> // 2で割り切れるやつ filter!"a % 2 == 0"(r); -> Range - 合計 <https://dlang.org/phobos/std_algorithm_iteration.html#sum> sum(r); - 累積和 <https://dlang.org/phobos/std_algorithm_iteration.html#cumulativeFold> // 今の要素に前の要素を足すタイプの一般的な累積和 // 累積和のrangeが帰ってくる(破壊的変更は行われない) cumulativeFold!"a + b"(r, 0); -> Range - rangeをarrayにしたいとき array(r); -> Array - 各要素に同じ処理をする <https://dlang.org/phobos/std_algorithm_iteration.html#map> // 各要素を2乗 map!"a * a"(r) -> Range - ユニークなやつだけ残す <https://dlang.org/phobos/std_algorithm_iteration.html#uniq> uniq(r) -> Range - 順列を列挙する <https://dlang.org/phobos/std_algorithm_iteration.html#permutations> permutation(r) -> Range - ある値で埋める <https://dlang.org/phobos/std_algorithm_mutation.html#fill> fill(r, val); -> void - バイナリヒープ <https://dlang.org/phobos/std_container_binaryheap.html#.BinaryHeap> // 昇順にするならこう(デフォは降順) BinaryHeap!(Array!T, "a > b") heap; heap.insert(val); heap.front; heap.removeFront(); - 浮動小数点の少数部の桁数設定 // 12桁 writefln("%.12f", val); - 浮動小数点の誤差を考慮した比較 <https://dlang.org/phobos/std_math.html#.approxEqual> approxEqual(1.0, 1.0099); -> true - 小数点切り上げ <https://dlang.org/phobos/std_math.html#.ceil> ceil(123.4); -> 124 - 小数点切り捨て <https://dlang.org/phobos/std_math.html#.floor> floor(123.4) -> 123 - 小数点四捨五入 <https://dlang.org/phobos/std_math.html#.round> round(4.5) -> 5 round(5.4) -> 5 */ // }}} void main() { auto cin = new Scanner; long x; cin.scan(x); long t = 100; int cnt; while (t < x) { t = cast(long)(cast(real)t * 1.01); cnt++; } writeln(cnt); }
D
import std.algorithm, std.string, std.array, std.range, std.stdio, std.conv; void main() { string n = readln.chomp; writeln("ABC", n); }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; auto s = readln.chomp.to!(char[]); if (s[0] != 'A') { writeln("WA"); return; } if (s.count('A') != 1 || s.count('C') != 1) { writeln("WA"); return; } foreach (c; s) { if (c != 'A' && c != 'C') { if ('A' <= c && c <= 'Z') { writeln("WA"); return; } } } if (s[2 .. ($ - 1)].count('C') != 1) { writeln("WA"); return; } writeln("AC"); } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; auto l = readln.split; assert(l.length == x.length); foreach (i, ref e; x) e = l[i].to!(typeof(e)); }
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 N = readln.chomp.to!int; auto S = readln.chomp; auto Q = readln.chomp.to!int; auto K = readln.split.map!(to!int).array; foreach (k; K) { long d = 0; long m = 0; long dm = 0; long ans = 0; foreach (i; 0..k) { if (S[i] == 'D') { d += 1; } else if (S[i] == 'M') { m += 1; dm += d; } else if (S[i] == 'C') { ans += dm; } } foreach (i; k..N) { if (S[i-k] == 'D') { d -= 1; dm -= m; } else if (S[i-k] == 'M') { m -= 1; } if (S[i] == 'D') { d += 1; } else if (S[i] == 'M') { m += 1; dm += d; } else if (S[i] == 'C') { ans += dm; } } ans.writeln; } }
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() { long N = lread(); auto honest = new ulong[](N); auto unkind = new ulong[](N); foreach (i; 0 .. N) { long A = lread(); foreach (_; 0 .. A) { long x, y; scan(x, y); if (y) { honest[i] |= 1 << (x - 1); } else { unkind[i] |= 1 << (x - 1); } } } bool isValid(ulong mh) { foreach (i; 0 .. N) if ((mh & (1 << i)) != 0) { if ((unkind[i] & mh) != 0) return false; if ((honest[i] & (~mh)) != 0) return false; } return true; } long ans; foreach (mh; 0 .. (1 << N)) if (isValid(mh)) { ans = ans.max(popcnt(mh)); } writeln(ans); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp; auto K = readln.chomp.to!int; auto DP = new long[][][](2, K+1, N.length); DP[1][K-1][0] += 1; foreach (x; 1..N[0]-'0') DP[0][K-1][0] += 1; foreach (i; 1..N.length) { if (N[i] == '0') { foreach (k; 0..K+1) DP[1][k][i] += DP[1][k][i-1]; } else { foreach (k; 1..K+1) DP[1][k-1][i] += DP[1][k][i-1]; foreach (k; 0..K+1) DP[0][k][i] += DP[1][k][i-1]; } foreach (k; 1..K+1) DP[0][k-1][i] += DP[1][k][i-1] * max(0, (N[i]-'0').to!long-1); foreach (k; 1..K+1) DP[0][k-1][i] += DP[0][k][i-1] * 9; foreach (k; 0..K+1) DP[0][k][i] += DP[0][k][i-1]; DP[0][K-1][i] += 9; } long r; foreach (x; 0..2) r += DP[x][0][N.length-1]; writeln(r); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; Tuple!(N, N)[] prime_division(N)(N n) { Tuple!(N, N)[] res; foreach (N i; 2..10^^6+1) { if (n%i == 0) { N cnt; while (n%i == 0) { ++cnt; n /= i; } res ~= tuple(i, cnt); } } if (n != cast(N)1) res ~= tuple(n, cast(N)1); return res; } void main() { auto N = readln.chomp.to!long; auto ps = prime_division(N); int r; foreach (p; ps) { auto k = p[1]; foreach (i; 1..40) { if (k < i) break; ++r; k -= i; } } writeln(r); }
D
void main() { string s = readln.chomp; int price = 700; foreach (x; s) { if (x == 'o') price += 100; } price.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
// This file is a "Hello, world!" in D language by DMD for wandbox. import std.algorithm, std.conv, std.stdio, std.array; int main() { const I = readln.split.map!(to!long).array; ((I[2]/I[0])*I[1]).writeln; return 0; } // DMD reference: // https://dlang.org/dmd-linux.html // D language references: // https://dlang.org // http://www.kmonos.net/alang/d/ ( Japanese )
D
import std.stdio, std.string, std.algorithm, std.conv; const long INF = long.max/3; void main() { while(solve()){} } bool solve() { int N = readln.chomp.to!int; if (N == 0) return false; long[] as = new long[N]; foreach(i; 0..N) { as[i] = readln.chomp.to!long; } long res = -INF; long s = 0; foreach(i; 0..N) { s = max(as[i], s + as[i]); res = max(res, s); } res.writeln; return true; }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto a = readln.split.to!(int[]); if (a[2] > a[0] + a[1]) { writeln("dangerous"); } else if (a[2] > a[0]) { writeln("safe"); } else { writeln("delicious"); } }
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; } /* (B - A) < 2 の場合は、換金しないでひたすら叩くだけ ans = 1 + K そうでないの場合は、換金できるなら換金した方がいい 最初にA枚まで貯める それに(A-1)ターンかかる Aターン目から換金できる。残りは K - A + 1 ターン 換金→購入で2ターン使うので ((K - A + 1) / 2)(B-A) 個になる。 K - A + 1 が奇数の場合は最初に1ターン余るのでそこで1枚 */ void main(){ long k = read.to!long; long a = read.to!long; long b = read.to!long; long ans; if(b - a < 2){ ans = 1 + k; } else{ ans = a + ((k - a + 1) / 2 ) * (b - a); if((k - a + 1) % 2 == 1) ans += 1; } ans.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.regex : regex; import std.container; import std.bigint; void main() { auto s = readln.chomp; auto d = s.length - 7; auto f = false; foreach (i; 0..s.length - d) { if (s[0..i] ~ s[i+d..$] == "keyence") { f = true; break; } } if (f) { writeln("YES"); } else { writeln("NO"); } }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional; void main() { auto abcd = readln.split.to!(long[]); auto ab = abcd[0] * abcd[1]; auto cd = abcd[2] * abcd[3]; writeln( ab > cd ? ab : cd ); }
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; import std.numeric; void main() { auto nk = readln.split.to!(long[]); long n = nk[0]; long k = nk[1]; long[] X = readln.split.to!(long[]); long result = long.max; foreach (i; 0 .. n - k + 1) { long a = (X[i + k - 1] - X[i]); long b = min(abs(X[i + k - 1]), abs(X[i])); result = result.min(a + b); } result.writeln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.math; 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 n; readV(n); int[] t, x, y; readM(n, t, x, y); if ((x[0]+y[0])%2 != t[0]%2 || x[0]+y[0] > t[0]) { writeln("No"); return; } foreach (i; 1..n) if ((x[i]+y[i])%2 != t[i]%2 || (x[i]-x[i-1]).abs+(y[i]-y[i-1]).abs > t[i]-t[i-1]) { writeln("No"); return; } writeln("Yes"); }
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() { readln; auto S = readln.split[0]; writeln( S.count('R') > S.count('B') ? "Yes" : "No" ); }
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 x, t; scan(x, t); writeln(max(x - t, 0)); } 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.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; readV(a, b, c); writeln(a+b >= c ? "Yes" : "No"); }
D
void main(){ long n = _scan!long(); long[] a = _scanln!long(); // 要素に0がある場合 if( a.count(0) != 0 ){ writeln(0); return; } // 桁あふれが起きないかチェックしならが積をとる long mula = 1; foreach(elm; a){ if( mula <= mula*elm && mula <= 10L^^18/elm ) mula *= elm; else { writeln(-1); return; } } mula.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.stdio, std.algorithm, std.conv, std.array, std.string, std.math; void main() { auto xab = readln.split.to!(int[]); writeln(abs(xab[0] - xab[1]) > abs(xab[0] - xab[2]) ? "B" : "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; } T read(T)(){ return read.to!T; } T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; } T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int n = read.to!int; char[] a = readln.chomp.to!(char[]); char[char] y; foreach(c; "123456789") y[c] = '0', y[c] += read.to!int.to!char; int f = 0; foreach(i, c; a){ if(f == 0){ if(y[c] <= c) continue; else{ f = 1; a[i] = y[c]; } } else if(f == 1){ if(y[c] < c){ f = 2; break; } else{ a[i] = y[c]; } } } a.to!string.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.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto a = readln.chomp.to!int; auto b = readln.chomp.to!int; if ((a == 1 && b == 2) || (a == 2 && b == 1)) { writeln(3); } else if ((a == 1 && b == 3) || (a == 3 && b == 1)) { writeln(2); } else if ((a == 2 && b == 3) || (a == 3 && b == 2)) { writeln(1); } }
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() { auto s = readln.chomp.to!int; auto u2 = s / 100; auto d2 = s % 100; bool uf, df; if (u2 >= 1 && u2 <= 12) { uf = true; } if (d2 >= 1 && d2 <= 12) { df = true; } if (uf && df) { writeln("AMBIGUOUS"); } else if (uf) { writeln("MMYY"); } else if (df) { writeln("YYMM"); } else { writeln("NA"); } }
D
import std.stdio; import std.array; import std.conv; void main() { string[] input = split(readln()); int a = to!(int)(input[0]); int b = to!(int)(input[1]); writeln(a*b, ' ', a * 2 + b * 2); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nm = readln.split.to!(long[]); auto N = nm[0]; auto M = nm[1]; writeln(N == 1 && M == 1 ? 1 : N == 1 ? M-2 : M == 1 ? N-2 : (N-2) * (M-2)); }
D
import std.functional, std.algorithm, std.container, std.typetuple, std.typecons, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { auto ip = readln.split.to!(int[]), w=ip[0], h=ip[1], x=ip[2], y=ip[3], r=ip[4]; if(x >= r && x <= w - r && y >= r && y <= h - r){ writeln("Yes"); } else { writeln("No"); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; import std.numeric; 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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n, sx; readV(n, sx); int[] x; readA(n, x); auto y = x.map!(xi => (xi-sx).abs); auto g = y[0]; foreach (i; 1..n) g = gcd(g, y[i]); writeln(g); }
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!string; writeln(N[1] == N[2] && (N[0] == N[1] || N[2] == N[3]) ? "Yes" : "No"); stdout.flush(); debug readln(); }
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() { while (true) { int n, x; scan(n, x); if (n == 0 && x == 0) return; auto ans = solve(n, x); writeln(ans); } } int solve(int n, int x) { int ans; foreach (i ; 1 .. n + 1) { foreach (j ; i + 1 .. n + 1) { foreach (k ; j + 1 .. n + 1) { if (i + j + k == x) ans++; } } } return 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
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.random; void main() { auto x = readln.chomp.split.map!(to!int); int cnt; foreach (i; x[0]..x[1]+1) if (x[2] % i == 0) cnt++; cnt.writeln; }
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(){ int n = read.to!int; int[] ps; foreach(i; 0 .. n) ps ~= read.to!int; int cnt; foreach(i, p; ps) if(i + 1 != p) cnt += 1; if(cnt <= 2) "YES".writeln; else "NO".writeln; }
D
void main() { problem(); } void problem() { auto S = scan; string solve() { return S[2] == S[3] && S[4] == S[5] ? "Yes" : "No"; } 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.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 x = RD; long ans = x / 11 * 2; if (x % 11 != 0) ans += x % 11 <= 6 ? 1 : 2; writeln(ans); stdout.flush(); //readln(); }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional; void main() { auto N = readln.split[0].to!int; auto S = readln.chomp; auto dp = new int[][N]; foreach(ref d; dp) { d = new int[N]; } for(int i = N - 2; i >= 0; i--) { for(int j = N - 1; j > i; j--) { if(S[i] != S[j]) { dp[i][j] = 0; } else if(j == N - 1) { dp[i][j] = 1; } else { dp[i][j] = 1 + dp[i+1][j+1]; } } } int m = 0; foreach(i; 0..N) { foreach(j; (1+i)..N) { m = max(m, min(j-i, dp[i][j])); } } m.writeln; }
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() { auto S = sread(); auto T = sread(); bool eq(string s, string t) { foreach (i; 0 .. s.length) { if (s[i] == '?' || t[i] == '?' || s[i] == t[i]) continue; return false; } return true; } foreach_reverse (i; 0 .. S.length - T.length + 1) { dprint(S[i .. i + T.length], T); if (eq(S[i .. i + T.length], T)) { char[] U = new char[](S.length); foreach (j; 0 .. S.length) { if (i <= j && j < i + T.length) { U[j] = T[j - i]; continue; } if (S[j] == '?') { U[j] = 'a'; continue; } U[j] = S[j]; } writeln(U); return; } } writeln("UNRESTORABLE"); }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void times(alias pred)(int n) { foreach(i; 0..n) pred(); } auto rep(alias pred, T = typeof(pred()))(int n) { T[] res = new T[n]; foreach(ref e; res) e = pred(); return res; } void main() { string str = readln.chomp; long ans = 0; foreach(i; 0..2^^(str.length-1)) { size_t k = 0; foreach(j; 0..str.length-1) { if (i>>j&1) { ans += str[k..j+1].to!long; k = j+1; } } ans += str[k..$].to!long; } ans.writeln; }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional; import std.algorithm, std.container; struct Node{ long index; long[] to; long[] cost; } void main() { auto N = scanElem; Node[] nodes; nodes.length = N+1; foreach(i;0..N-1) { long a = scanElem; long b = scanElem; long c = scanElem; nodes[a].index = a; nodes[a].to ~= b; nodes[a].cost ~= c; nodes[b].index = b; nodes[b].to ~= a; nodes[b].cost ~= c; } long[] costs; costs.length = N+1; costs[] = -1; auto Q = scanElem; auto K = scanElem; long[] queue = [K]; costs[K] = 0; while(!queue.empty) { auto node = nodes[queue[0]]; queue = queue[1..$]; foreach(i; 0..node.to.length) { if(costs[node.to[i]]!=-1)continue; queue ~= node.to[i]; costs[node.to[i]] = costs[node.index] + node.cost[i]; } } foreach(i;0..Q) { long x = scanElem; long y = scanElem; writeln(costs[x]+costs[y]); } } 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)); } } } 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
void main() { int n = readln.chomp.to!int; string s = readln.chomp; int k = readln.chomp.to!int - 1; foreach (x; s) { if (x == s[k]) x.write; else '*'.write; } 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 std.stdio; import std.conv; import std.string; void main(){ long n=to!int(readln.chomp),a=1; while(n--)a*=n+1; writeln(a); }
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 x; readV(x); int a; readV(a); int b; readV(b); writeln((x-a)%b); }
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 n; readV(n); int k; readV(k); int x; readV(x); int y; readV(y); writeln(n <= k ? n*x : k*x+(n-k)*y); }
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; void main() { int n, a, b, c, d; scan(n, a, b, c, d); auto fact = new long[](n + 1); auto rfact = new long[](n + 1); fact[0] = 1; foreach (i ; 1 .. n + 1) { fact[i] = (fact[i-1] * i) % mod; } rfact[n] = inv(fact[n]); foreach_reverse (i ; 0 .. n) { rfact[i] = (rfact[i+1] * (i + 1)) % mod; } long perm(int n, int k) { return fact[n] * rfact[n-k] % mod; } debug { //writeln(fact); //writeln(rfact); } auto dp = new long[][](n + 1, n + 1); foreach (i ; 0 .. n/a + 1) { if (i != 0 && (i < c || i > d)) { continue; } dp[a][i*a] = perm(n, i*a) * powmod(rfact[a], i) % mod * rfact[i] % mod; } foreach (i ; a + 1 .. b + 1) { foreach (j ; 0 .. n + 1) { foreach (k ; 0 .. min(d, j/i) + 1) { if (k != 0 && (k < c || k > d)) { continue; } (dp[i][j] += dp[i-1][j - i*k] * perm(n - j + i*k, i*k) % mod * powmod(rfact[i], k) % mod * rfact[k] % mod) %= mod; } } } debug { writefln("%(%(%s %)\n%)", dp); } long ans = dp[b][n]; writeln(ans); } long powmod(long x, long y) { return y > 0 ? powmod(x, y>>1)^^2 % mod * x^^(y&1) % mod : 1; } long inv(long x) { return powmod(x, mod - 2); } 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; 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 s = sread(); if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') { writeln(3); return; } if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) { writeln(2); return; } else if ((s[0] == 'R') || (s[1] == 'R') || (s[2] == 'R')) { writeln(1); return; } writeln(0); } 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; import std.string; import std.format; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.concurrency; import std.traits; import std.uni; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; enum long INF = long.max/3; enum long MOD = 10L^^9+7; void main() { long A, B, K; scanln(A, B, K); long cnt = 0; foreach_reverse(i; 1..min(A, B)+1) { if (A%i==0 && B%i==0) { cnt++; if (cnt == K) { i.writeln; return; } } } } // ---------------------------------------------- void times(alias fun)(long n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(long n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { // `(x+y-1)/y` will only work for positive numbers ... T t = x / y; if (t * y < x) t++; return t; } T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { T t = x / y; if (t * y > x) t--; return t; } ref T ch(alias fun, T, S...)(ref T lhs, S rhs) { return lhs = fun(lhs, rhs); } unittest { long x = 1000; x.ch!min(2000); assert(x == 1000); x.ch!min(3, 2, 1); assert(x == 1); x.ch!max(100).ch!min(1000); // clamp assert(x == 100); x.ch!max(0).ch!min(10); // clamp assert(x == 10); } mixin template Constructor() { import std.traits : FieldNameTuple; this(Args...)(Args args) { // static foreach(i, v; args) { foreach(i, v; args) { mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v; } } } void scanln(Args...)(auto ref Args args) { import std.meta; template getFormat(T) { static if (isIntegral!T) { enum getFormat = "%d"; } else static if (isFloatingPoint!T) { enum getFormat = "%g"; } else static if (isSomeString!T || isSomeChar!T) { enum getFormat = "%s"; } else { static assert(false); } } enum string fmt = [staticMap!(getFormat, Args)].join(" "); string[] inputs = readln.chomp.split; foreach(i, ref v; args) { v = inputs[i].to!(Args[i]); } } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { 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 { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { 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); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { private template RebindableOrUnqual(T) { static if (is(T == class) || is(T == interface) || isDynamicArray!T || isAssociativeArray!T) alias RebindableOrUnqual = Rebindable!T; else alias RebindableOrUnqual = Unqual!T; } private auto extremum(alias map, alias selector = "a < b", Range)(Range r) if (isInputRange!Range && !isInfinite!Range && is(typeof(unaryFun!map(ElementType!(Range).init)))) in { assert(!r.empty, "r is an empty range"); } body { alias Element = ElementType!Range; RebindableOrUnqual!Element seed = r.front; r.popFront(); return extremum!(map, selector)(r, seed); } private auto extremum(alias map, alias selector = "a < b", Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seedElement) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void) && is(typeof(unaryFun!map(ElementType!(Range).init)))) { alias mapFun = unaryFun!map; alias selectorFun = binaryFun!selector; alias Element = ElementType!Range; alias CommonElement = CommonType!(Element, RangeElementType); RebindableOrUnqual!CommonElement extremeElement = seedElement; // if we only have one statement in the loop, it can be optimized a lot better static if (__traits(isSame, map, a => a)) { // direct access via a random access range is faster static if (isRandomAccessRange!Range) { foreach (const i; 0 .. r.length) { if (selectorFun(r[i], extremeElement)) { extremeElement = r[i]; } } } else { while (!r.empty) { if (selectorFun(r.front, extremeElement)) { extremeElement = r.front; } r.popFront(); } } } else { alias MapType = Unqual!(typeof(mapFun(CommonElement.init))); MapType extremeElementMapped = mapFun(extremeElement); // direct access via a random access range is faster static if (isRandomAccessRange!Range) { foreach (const i; 0 .. r.length) { MapType mapElement = mapFun(r[i]); if (selectorFun(mapElement, extremeElementMapped)) { extremeElement = r[i]; extremeElementMapped = mapElement; } } } else { while (!r.empty) { MapType mapElement = mapFun(r.front); if (selectorFun(mapElement, extremeElementMapped)) { extremeElement = r.front; extremeElementMapped = mapElement; } r.popFront(); } } } return extremeElement; } private auto extremum(alias selector = "a < b", Range)(Range r) if (isInputRange!Range && !isInfinite!Range && !is(typeof(unaryFun!selector(ElementType!(Range).init)))) { return extremum!(a => a, selector)(r); } // if we only have one statement in the loop it can be optimized a lot better private auto extremum(alias selector = "a < b", Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seedElement) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void) && !is(typeof(unaryFun!selector(ElementType!(Range).init)))) { return extremum!(a => a, selector)(r, seedElement); } auto minElement(alias map = (a => a), Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { return extremum!map(r); } auto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void)) { return extremum!map(r, seed); } auto maxElement(alias map = (a => a), Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { return extremum!(map, "a > b")(r); } auto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void)) { return extremum!(map, "a > b")(r, seed); } } // popcnt with ulongs was added in D 2.071.0 static if (__VERSION__ < 2071) { ulong popcnt(ulong x) { x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L); x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L); x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL); x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL); x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL); x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL); return x; } }
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; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long a = read.to!long; long b = read.to!long; if(a + b == 15) writeln("+"); else if(a * b == 15) writeln("*"); else writeln("x"); }
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; void main() { int a, b; scan(a, b); writeln((a-1)*(b-1)); } 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.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 X = RD; auto ans = X / 500 * 1000; X %= 500; ans += X / 5 * 5; writeln(ans); 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]); char op = inputs[1][0]; int B = to!int(inputs[2]); if(op == '+') (A + B).writeln; else (A - B).writeln; }
D
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.uni; void main(){ string i = readln.chomp; string s; foreach(c;i){ if (isLower(c)) s ~= toUpper(c); else s ~= toLower(c); } writeln(s); }
D
// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.datetime, std.bigint; void main() { readln(); auto s = readln.split(); int ans = 0; int vol(string w) { int res; debug { writeln(w); } foreach (ch ; w) { if (ch <= 'Z') res++; } return res; } foreach (w ; s) { ans = max(ans, vol(w)); } writeln(ans); } 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.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!int; auto a0 = x%4; auto a1 = (x+1)%4; auto a2 = (x+2)%4; long ans; if (a0 == 1 || a1 == 1 || a2 == 1) writeln(a0 == 1 ? "0" : a1 == 1 ? "1" : "2", " A"); else if (a0 == 3 || a1 == 3 || a2 == 3) writeln(a0 == 3 ? "0" : a1 == 3 ? "1" : "2", " B"); else if (a0 == 2 || a1 == 2 || a2 == 2) writeln(a0 == 2 ? "0" : a1 == 2 ? "1" : "2", " C"); else writeln(a0 == 0 ? "0" : a1 == 0 ? "1" : "2", " D"); stdout.flush(); debug readln(); }
D
import std.stdio; void main(string[ ] args) { int n; scanf("%d", &n); int n_0 = 0; int n_1 = 0; for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); if (a % 2 == 0) { ++n_0; } else { ++n_1; } } //writeln(n_0); //writeln(n_1); int ans; if (n_0 >= n_1) { writeln(n_1); } else { writeln(n_0 + (n_1 - n_0) / 3); } }
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 N = readln.chomp.to!int; auto A = readln.chomp; auto B = readln.chomp; long ans = 0; for (int i = 0; i < N; ++i) { if (A[i] == B[i]) continue; if (i == N - 1) { ans += 1; } else if (A[i+1] != B[i+1] && A[i] != A[i+1]) { ans += 1; i += 1; } else { ans += 1; } } ans.writeln; }
D
import std.algorithm; import std.ascii; import std.stdio; import std.string; void main () { string s; while ((s = readln.strip) != "") { int res = 0; foreach (c; s) { if (c.isLower) { res -= c - 'a' + 1; } else if (c.isUpper) { res += c - 'A' + 1; } } writeln (res); } }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; bool solve (int n, int [] a) { auto m = 1 << n; for (int s = 0; s < m; s++) { int r = m - 1 - s; int t = r; do { int cur = 0; foreach (i; 0..n) { if (s & (1 << i)) { cur += a[i]; } if (t & (1 << i)) { cur -= a[i]; } } if (cur == 0 && !(s == 0 && t == 0)) { return true; } t = (t - 1) & r; } while (t != r); } return false; } 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; writeln (solve (n, a) ? "YES" : "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.string; immutable long MOD = 10^^9 + 7; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto dp = new long[][][](2, N, N); dp[0][0][0] = 1; int cur = 0; int tar = 1; foreach (i; 0..M) { foreach (j; 0..N) { foreach (k; 0..N) { dp[tar][j][k] = 0; } } foreach (j; 0..N) { foreach (k; 0..N) { if (dp[cur][j][k] == 0) { continue; } if (j < N - 1) { (dp[tar][j+1][k] += dp[cur][j][k]) %= MOD; } (dp[tar][j][k] += dp[cur][j][k] * (j - k) % MOD) %= MOD; (dp[tar][j][j] += dp[cur][j][k] * (k + 1) % MOD) %= MOD; } } swap(cur, tar); } long ans = dp[cur][N-1][N-1]; foreach (i; 1..N) ans = ans * i % MOD; ans.writeln; }
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; void main() { auto r = readln.chomp.to!int; writeln(r*r); }
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; } bool calc(string s) { for (int i = 0; i < s.length - 1; i++) { if (s[i] == 'A' && s[i + 1] == 'C') { return true; } } return false; } void main() { auto s = readln.chomp; writeln(calc(s) ? "Yes" : "No"); }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional; import std.algorithm, std.container; void main() { long N = scanElem; primes(55555).filter!"a%5==1".take(N).each!writeln; } 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)); } } } 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); } } } 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.array; import std.algorithm; void main() { auto input = readln.split.to!(int[]); auto a = input[0]; auto b = input[1]; auto max = max(a+b, a-b, a*b); writeln(max); }
D
import std.stdio, std.conv, std.string; void main() { auto r = readln.chomp.to!int; writeln(3 * r * r); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math; void main() { auto A = readln.chomp.to!int; auto B = readln.chomp.to!int; auto C = readln.chomp.to!int; auto X = readln.chomp.to!int; int result; foreach (a; 0..A+1) { foreach (b; 0..B+1) { auto rest = X - 500*a - 100*b; if (rest >= 0 && rest % 50 == 0 && rest / 50 <= C) ++result; } } writeln(result); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto M = readln.split[1].to!long; long[long] HS = [0: 0]; long c; foreach (a; readln.split.to!(long[])) { c = (c + a) % M; if (c in HS) { ++HS[c]; } else { HS[c] = 0; } } long r; foreach (_, n; HS) { r += n * (n + 1) / 2; } writeln(r); }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; void main() { int[] xs = readln.split.map!(to!char).map!(to!int).array; string f(string op)() { mixin("return xs.front" ~ (op=="="?"==":op) ~ "xs.back ? \"" ~ op ~ "\" : \"\";"); } writeln(f!"<"~f!">"~f!"="); } // ---------------------------------------------- void scanln(Args...)(ref Args args) { foreach(i, ref v; args) { "%d".readf(&v); (i==args.length-1 ? "\n" : " ").readf; } // ("%d".repeat(args.length).join(" ") ~ "\n").readf(args); } void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { 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 { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { 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); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; import std.regex; import std.math; void main(){ auto a=readln.chomp; writeln(a.count('1')); }
D
import std.stdio, std.conv, std.string; void main() { while ( true ) { immutable int n = to!int( readln().strip() ); if ( n == 0 ) break; int count = 0; bool right = false; bool left = false; bool isUp = false; foreach ( s; split( readln() ) ) { switch ( s ) { case "lu": left = true; break; case "ld": left = false; break; case "ru": right = true; break; case "rd": right = false; break; default : } if ( isUp && !right && !left ) { isUp = false; count++; } else if ( !isUp && right && left ) { isUp = true; count++; } } writeln( count ); } }
D
// Vicfred // https://atcoder.jp/contests/abc052/tasks/arc067_a // math import std.algorithm; import std.array; import std.conv; import std.functional; import std.math; import std.range; import std.stdio; import std.string; uint[] sieve(in uint limit) nothrow @safe { if (limit < 2) return []; auto composite = new bool[limit]; foreach (immutable uint n; 2 .. cast(uint)(limit ^^ 0.5) + 1) if (!composite[n]) for (uint k = n * n; k < limit; k += n) composite[k] = true; return iota(2, limit).filter!(i => !composite[i]).array; } void main() { uint[] primes = sieve(1000); long n = readln.chomp.to!long; long[long] exponents; foreach(prime; primes) exponents[prime] = 0; for(long i = 2; i <= n; ++i) { long m = i; foreach(prime; primes) { long div = 0; while(m%prime == 0) { div += 1; m /= prime; } exponents[prime] += div; } } long ans = 1; foreach(exp; exponents.values) { ans *= (exp+1); ans %= 10^^9+7; } ans.writeln; }
D
import std.stdio, std.algorithm, std.string; void main() { int[string] count; int maxCount; string maxWord; auto input = readln.split; foreach(str; input) { ++count[str]; if(maxCount < count[str]) { maxCount = count[str]; maxWord = str; } } size_t maxLen = 0; string maxLenWord; foreach(str; input) { if(maxLen < str.length) { maxLen = str.length; maxLenWord = str; } } writeln(maxWord, " ", maxLenWord); }
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 N = lread(); auto H = aryread(); foreach_reverse (i; 0 .. N - 1) { // writeln(i); if (H[i + 1] - H[i] < -1) { writeln("No"); return; } if (H[i + 1] - H[i] == -1) { H[i]--; } } writeln("Yes"); }
D
import std.stdio, std.string, std.conv; void main() { auto n = readln.strip.to!int; if(n%2==0){ writeln(n); return; } writeln(n*2); }
D
import std.stdio, std.string, std.conv; void main() { auto x = readln.chomp.to!int; writeln(x*x*x); }
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; void main() { auto abc = readints; int a = abc[0], b = abc[1], c = abc[2]; if (a <= c && c <= b) writeln("Yes"); else writeln("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(); 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 main() { long a,b,c; scan(a,b,c); long k = lread(); long three_max = max(a,b,c); three_max = three_max * pow(2, k); three_max -= max(a,b,c); writeln(three_max + a + b + c); }
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 inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N, K; scan(N, K); if (K == 1) { writeln(N == 1 ? 1 : 0); return; } auto adj = new int[][](N, 0); foreach (i ; 0 .. N - 1) { int ai, bi; scan(ai, bi); ai--, bi--; adj[ai] ~= bi; adj[bi] ~= ai; } long dfs(int v, int p, int dep) { long res = 1; long t = dep > 0 ? K - 2 : K - 1; foreach (u ; adj[v]) if (u != p) { res *= t * dfs(u, v, dep + 1) % mod; res %= mod; t--; if (t < 0) t = 0; } debug { writefln("v: %d, res: %d", v, res); } return res; } auto ans = dfs(0, -1, 0) * K % mod; 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
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 S = RD!string; long[char] cnt; foreach (c; S) { ++cnt[c]; } bool ans; auto keys = cnt.keys; if (keys.length == 2) { if (cnt[keys[0]] == cnt[keys[1]]) ans = true; } writeln(ans ? "Yes" : "No"); stdout.flush(); debug readln(); }
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; import std.typecons; void main() { auto s = read(); const string t = "CODEFESTIVAL2016"; int ret = 0; foreach(i; 0..t.length) { if (s[i] != t[i]) ret++; } writeln(ret); } string read() { static string[] ss; while (!ss.length) ss = readln.chomp.split; auto res = ss[0]; ss.popFront; return res; }
D
import std.container; import std.range; import std.algorithm; import std.array; import std.string; import std.conv; import std.stdio; import std.container; int de(string s, string t) { int c; foreach (i;0..t.length) { if (s[i] != t[i]) { ++c; } } return c; } void main() { auto s = readln.chomp; auto t = readln.chomp; auto m = int.max; while (s.length >= t.length) { auto r = de(s[0..t.length], t); if (r < m) { m = r; } s = s[1..$]; } writeln(m); }
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(); if (x >= 30) { writeln("Yes"); } else { writeln("No"); } } 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.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 n, y; readV(n, y); foreach (i; 0..n+1) foreach (j; 0..n-i+1) { auto k = n-i-j; if (i*10000 + j*5000 + k*1000 == y) { writeln(i, " ", j, " ", k); return; } } writeln("-1 -1 -1"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto K = readln.chomp.to!long; long s; foreach (a; 1..K+1) foreach (b; 1..K+1) { auto x = gcd(a, b); foreach (c; 1..K+1) s += gcd(c, x); } writeln(s); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto N = readln.chomp.to!int; for (int a = 0; a * 4 <= 100; ++a) { for (int b = 0; b * 7 <= 100; ++b) { if (a * 4 + b * 7 == N) { writeln("Yes"); return; } } } writeln("No"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto s=readln.chomp.to!(char[]); auto e=new int[](n+1), w=new int[](n+1); foreach(i; 0..n){ if(s[i]=='E') e[i+1]++; else w[i+1]++; } foreach(i; 0..n){ e[i+1]+=e[i]; w[i+1]+=w[i]; } int mn=n; foreach(i; 0..n){ int k=w[i]+(e[n]-e[i+1]); mn=min(mn, k); } writeln(mn); } 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 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[] 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); alias T = Tuple!(long, long); auto G = new T[][](N); alias T2 = Tuple!(long, long, long); auto LRD = new T2[](M); foreach (i; 0 .. M) { long L, R, D; scan(L, R, D); L--, R--; LRD[i] = T2(L, R, D); G[R] ~= T(L, D); } auto pos = new long[](N); pos[] = -2; long eval(long x) { // writefln("%s %s", x, G[x]); if (pos[x] == -1) return 0; if (pos[x] == -2) { pos[x] = -1; if (G[x].length == 0) { pos[x] = 0; return 0; } long d; foreach (t; G[x]) { d = max(d, t[1] + eval(t[0])); } pos[x] = d; return d; } else { return pos[x]; } } foreach (i; 0 .. N) eval(i); foreach (lrd; LRD) { if (pos[lrd[1]] - pos[lrd[0]] != lrd[2]) { writeln("No"); return; } } writeln("Yes"); // writeln(pos); }
D
import std.stdio, std.string; void main(){ auto a = readln.split; writeln(a[0][$-1]==a[1][0] && a[1][$-1]==a[2][0] ? "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) { x.modm(y.modpow(mod - 2)); } void main() { auto A = RD; auto B = RD; auto C = RD; auto D = RD; auto cnt1 = (C+B-1) / B; auto cnt2 = (A+D-1) / D; writeln(cnt1 <= cnt2 ? "Yes" : "No"); stdout.flush; debug readln; }
D
import std.conv, std.stdio; import std.string; void main() { immutable n = readln.chomp.to!int; ((n % 10 == 7 || n % 100 / 10 == 7 || n / 100 == 7) ? "Yes" : "No").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.regex : regex; import std.container; void main() { foreach (line; stdin.byLine) { auto str = line.chomp; string ans = ""; int i; while (i < str.length) { if (str[i] == '@') { foreach (j; 0..str[i+1]-'0') { ans ~= str[i+2]; } i += 3; } else { ans ~= str[i]; i++; } } ans.writeln; } }
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 K = readln.chomp.to!long; foreach (i; 0..K) { if (S[i] != '1' || i == K-1) { writeln(S[i]); 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[] 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 S = sread(); S.map!"a=='-'?-1:1".sum().writeln(); }
D
/+ dub.sdl: name "C" dependency "dcomp" version=">=0.3.2" lflags "-stack_size" "100000000" +/ import std.algorithm, std.conv, std.range, std.stdio; import core.sys.posix.stdlib; // import dcomp.scanner; int n; Scanner sc; static this(){ sc = new Scanner(); } bool que(string[2] s) { writeln(s[0]); writeln(s[1]); stdout.flush; string buf; sc.read(buf); if (buf == "end") { exit(0); } return buf == "T"; } int main(string[] argv) { sc.read(n); string[2] s; while (true) { auto rng = iota(4).find!((i){ string s0 = s[0] ~ (i%2 ? "." : "#"); string s1 = s[1] ~ (i/2 ? "." : "#"); return que([s0, s1]); }); if (rng.empty) break; auto i = rng.front; string s0 = s[0] ~ (i%2 ? "." : "#"); string s1 = s[1] ~ (i/2 ? "." : "#"); s = [s0, s1]; } while (true) { auto rng = iota(4).find!((i){ string s0 = (i%2 ? "." : "#") ~ s[0]; string s1 = (i/2 ? "." : "#") ~ s[1]; return que([s0, s1]); }); if (rng.empty) break; auto i = rng.front; string s0 = (i%2 ? "." : "#") ~ s[0]; string s1 = (i/2 ? "." : "#") ~ s[1]; s = [s0, s1]; } return 0; } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f = stdin) { this.f = f; } string[] buf; private bool succ() { while (!buf.length) { if (f.eof) return false; buf = f.readln.split; } return true; } private bool readSingle(T)(ref T x) { if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { //string or char[10] etc x = buf.front; buf.popFront; } else { static if (isStaticArray!T) { //static assert(buf.length == T.length); } x = buf.map!(to!E).array; buf.length = 0; } } else { x = buf.front.to!T; buf.popFront; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } unittest { import std.path : buildPath; import std.file : tempDir; import std.algorithm : equal; import std.stdio : File; string fileName = buildPath(tempDir, "kyuridenanmaida.txt"); auto fout = File(fileName, "w"); fout.writeln("1 2 3"); fout.writeln("ab cde"); fout.writeln("1.0 1.0 2.0"); fout.close; Scanner sc = new Scanner(File(fileName, "r")); int a; int[2] b; char[2] c; string d; double e; double[] f; sc.read(a, b, c, d, e, f); assert(a == 1); assert(equal(b[], [2, 3])); assert(equal(c[], "ab")); assert(equal(d, "cde")); assert(e == 1.0); assert(equal(f, [1.0, 2.0])); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; long n, m; rd(n, m); if(n>m) swap(n, m); if((m-n)>=2){ writeln(0); return; } long tot=1, mod=10^^9+7; for(int i=1; i<=n; i++) (tot*=i)%=mod; for(int i=1; i<=m; i++) (tot*=i)%=mod; if(n==m) (tot*=2)%=mod; writeln(tot); } 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 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; // dfmt on void main() { auto S = sread(); long cnt; foreach (c; S) cnt += c == 'o'; bool b = 8 <= cnt + (15 - S.length); writeln(b ? "YES" : "NO"); }
D
import std.stdio; import std.string; import std.conv; import std.array; void main(){ int n=to!int(chomp(readln())),b=0; string s=""; bool f=false; for(int i=0;i<n;++i){ string[] input=split(readln()); if(input[0]=="(") b+=to!int(input[1]); else b-=to!int(input[1]); if(b<0) f=true; } writeln((b==0&&!f)?"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; void main() { int x = readint; int ans = 1; for (int b = 2; b <= x; b++) { int a = b * b; while (a <= x) { ans = max(ans, a); a *= b; } } writeln(ans); }
D
import std.stdio,std.conv,std.string; void main(){ int D,N; auto DN = readArray!int(); D = DN[0]; N = DN[1]; if( N == 100 ){ (100^^D*101).writeln(); }else{ (100^^D*N).writeln(); } } T[] readArray(T)(){ T[] ret; foreach( elm ; readln().split() ){ ret ~= elm.to!T(); } return ret; }
D
void main() { string l = rdStr; long len = l.length; long[] exp = new long[len]; exp[len-1] = 1; foreach_reverse (i; 0 .. len-1) { exp[i] = (3 * exp[i+1]) % mod; } long num = 1; long result; foreach (i, x; l) { if (x == '0') continue; result = (result + (num * exp[i]) % mod) % mod; num = (2 * num) % mod; } result = (result + num) % mod; result.writeln; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; enum double eps = 1.0e-9; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)() if (is(T == struct)) { T result; string[] input = rdRow!string; assert(T.tupleof.length == input.length); foreach (i, ref x; result.tupleof) { x = input[i].to!(typeof(x)); } return result; } T[] rdRow(T = long)() { return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { return iota(col).map!(x => rdRow!T).array; } void rdVals(T...)(ref T data) { string[] input = rdRow!string; assert(data.length == input.length); foreach (i, ref x; data) { x = input[i].to!(typeof(x)); } } void wrMat(T = long)(T[][] mat) { foreach (row; mat) { foreach (j, compo; row) { compo.write; if (j == row.length - 1) writeln; else " ".write; } } } 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.mathspecial; import std.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni; import core.bitop;
D
import std.stdio; import std.string; import std.conv; int main() { while (true) { string[] str = readln().split(); if (str[0] == "0" && str[1] == "0") break; for (int i = 0; i < str[0].to!int(); i++) { for (int j = 0; j < str[1].to!int(); j++) { char s; if (i == 0 || i == str[0].to!int() - 1 || j == 0 || j == str[1].to!int() - 1) s = '#'; else s = '.'; write(s); } writeln(); } writeln(); } return 0; }
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; long ans = long.max; foreach (i; 1..N) { auto a = i; auto b = N - i; long cnt; while (a != 0) { cnt += a % 10; a /= 10; } while (b != 0) { cnt += b % 10; b /= 10; } ans = min(ans, cnt); } writeln(ans); stdout.flush(); debug readln(); }
D