code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); writeln(S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ? "Bad" : "Good"); }
D
void main() { int[] path = new int[4]; foreach (i; 0 .. 3) { int[] tmp = readln.split.to!(int[]); int a = tmp[0] - 1, b = tmp[1] - 1; ++path[a], ++path[b]; } writeln(path.all!"a < 3" ? "YES" : "NO"); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.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() { readln; readln.chomp.count("ABC").writeln; } 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
void main(){ long n = _scan!long(); long[] a = _scanln!long(); long[long] dic; bool fl = true; foreach(i; 0..n){ if(dic.get(a[i], 0) == 0)dic[a[i]]++; else{ writeln("NO"); return; } } writeln("YES"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; version(unittest) {} else void main() { string line; while ((line = readln) !is null) { auto rd = line.split.to!(int[]), a = rd[0], b = rd[1]; writeln((a + b).numDigits); } } int numDigits(int n) { auto r = 1; for (; n >= 10; n /= 10) ++r; return r; }
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[4] used; foreach (i; 0..S.length) { if (S[i] == 'N') used[0] = 1; else if (S[i] == 'W') used[1] = 1; else if (S[i] == 'S') used[2] = 1; else used[3] = 1; } writeln(used[0] - used[2] == 0 && used[1] - used[3] == 0 ? "Yes" : "No"); 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.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 K = RD; auto S = RD; long ans; foreach (i; 0..K+1) { foreach (j; 0..K+1) { auto x = S - cast(long)(i+j); if (x < 0) break; if (x <= K) ++ans; } } writeln(ans); stdout.flush(); debug readln(); }
D
void main(){ char c = _scan!char(); (c+1).to!char.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.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() { if(scanString==scanString)end("H");end("D"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a=new int[](1_000_000); foreach(_; 0..n){ int l, r; rd(l, r); a[l-1]++; a[r]--; } foreach(i; 1..a.length){ a[i]+=a[i-1]; } int c=0; foreach(e; a)if(e>0) c++; writeln(c); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; int[string] h; void f (int dx) { int n = readln.strip.to! (int); foreach (i; 0 .. n) { string s = readln.strip(); if (s in h) { h[s] = h[s] + dx; } else { h[s] = dx; } } } void main() { f (1); f (-1); int r = 0; foreach (k, v; h) { r = max (r, v); } writeln (r); }
D
import std; // 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, N; scan(A, B, N); auto f = (long x) => (A * x) / B - A * (x / B); if (N < B) { writeln(f(N)); return; } writeln(max(f(B), f(B - 1))); }
D
import std.stdio; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; void main(){ while(true){ int n,m; auto s = split(readln()).to!(int[]); n = s[0]; m = s[1]; if(n==0&&m==0) break; int count; int d; int i = -1; bool[1001] al; for(int j=0;j<=1000;j++){ al[j] = false; } while(true){ i = (i+1)%n; if(!al[i]) count++; else continue; if(count%m==0){ al[i] = true; d++; } if(d==n-1) break; } for(int j=0;j<n;j++){ if(!al[j]) writeln(j+1); } } }
D
import std.stdio; import std.conv; import std.string; void main() { auto n =(readln.strip.split); while( n[1] != "?" ) { int a = to!int(n[0]),c = to!int(n[2]); switch(n[1]) { case "+": writeln(a+c); break; case "-": writeln(a-c); break; case "*": writeln(a*c); break; case "/": writeln(a/c); break; default: break; } n = (readln.strip.split); } }
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.to!string; writeln(str.find('C').find('F').length>0 ? "Yes":"No"); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); int w; readV(w); for (auto i = 0; i < s.length; i += w) write(s[i]); writeln; }
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; void main(){ int n = readln.chomp.to!int; int[] as = readln.chomp.split.map!(to!int).map!(x => x - 1).array; int count = 0; foreach(i, a; as){ if(i < a && as[a] == i) count ++; } count.writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; uint[10^^5] AS; long[10^^5] BS; void main() { auto nk = readln.split; auto N = nk[0].to!int; auto K = nk[1].to!uint; foreach (i; 0..N) { auto ab = readln.split; AS[i] = ab[0].to!uint; BS[i] = ab[1].to!long; } long r_max; foreach (i; 0..32) { uint m; if (!(K&(1<<i))) { if (i == 31) { m = K; } else { continue; } } else { m = K&(~(1<<i)) | ((1<<i)-1); } long r; foreach (j; 0..N) { if ((AS[j]|m) == m) r += BS[j]; } r_max = max(r_max, r); } writeln(r_max); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[10^^5*2] BS, WS; void main() { auto N = readln.chomp.to!int; auto S = readln.chomp; foreach (i, c; S) { if (i) { BS[i] = BS[i-1]; WS[i] = WS[i-1]; } if (c == '#') { ++BS[i]; } else { ++WS[i]; } } int r = int.max; foreach (i; 0..N+1) { auto s = WS[N-1]; if (i) { s -= WS[i-1]; s += BS[i-1]; } r = min(r, s); } writeln(r); }
D
import std.stdio; import std.conv; import std.array; import std.string; void main() { int[] a; int n = to!(int)(chomp(readln())); string[] input = split(readln()); a.length = n; for (int i = 0; i < n; i++) { a[i] = to!(int)(input[i]); } for (int i = n - 1; i >= 0; i--) { write(a[i]); if (i != 0) { write(" "); } else { write("\n"); } } }
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 a, b, c, d; scan(a, b, c, d); long lcm = c * d / gcd(c, d); // writeln(lcm); long c_cnt = b / c - (a - 1) / c; long d_cnt = b / d - (a - 1) / d; long lcm_cnt = b / lcm - (a - 1) / lcm; // writeln(c_cnt); // writeln(d_cnt); // writeln(lcm_cnt); writeln((b - a + 1) - (c_cnt + d_cnt - lcm_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
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); bool[char] map; foreach(c; s){ if(c in map){ writeln("no"); return; }else{ map[c]=true; } } writeln("yes"); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x) e=l[i].to!(typeof(e)); }
D
import std.stdio; import std.conv; import std.string; void main() { string[] buf; int a,b; buf = split(readln()); a = to!(int)(buf[0]); b = to!(int)(buf[1]); if(a<b) writeln("a < b"); else if(a>b) writeln("a > b"); else writeln("a == b"); }
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, 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; } bool dfs(long v, long d) { if (v == N - 1 && d == 2) return true; if (2 <= d) return false; bool ans; foreach (w; G[v]) ans = ans || memoize!dfs(w, d + 1); return ans; } writeln(dfs(0, 0) ? "POSSIBLE" : "IMPOSSIBLE"); }
D
import std.stdio,std.conv,std.string,std.algorithm; void main() { int[5000] dp; while(true) { int n=readln.chomp.to!int; if(!n) break; int ans=int.min; foreach(i;0..n) { int a=readln.chomp.to!int; if(!i) dp[i]=a; else dp[i]=max(dp[i-1]+a,a); ans=max(ans,dp[i]); } 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, std.bitmanip; void main() { auto N = readln.chomp.to!int; auto A = N.iota.map!(_ => readln.chomp.to!long).array; if (A[0] != 0) { writeln(-1); return; } if ((N-1).iota.map!(i => A[i+1] - A[i] > 1).any) { writeln(-1); return; } long ans = 0; foreach (i; 1..N) { if (A[i] - A[i-1] == 1) ans += 1; else if (A[i] > 0) ans += A[i]; } ans.writeln; }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons; void main() { int N = readln.split[0].to!int; int[] A = new int[N]; foreach(ref a; A) { a = readln.split[0].to!int; } int top = A.reduce!max; int second = 0; int maxcnt = 0; foreach(a; A) { if(a == top) { maxcnt++; continue; } second = max(second, a); } foreach(a; A) { writeln(a == top && maxcnt == 1 ? second : top); } }
D
void main(){ int[] val = _scanln(); foreach(elm; val){ if( count(val, elm)==2 ){ writeln("Yes"); return; } } writeln("No"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.stdio, std.conv, std.string, std.algorithm; void main() { auto ip = readln.split.to!(int[]); auto x = 0; if(ip[0] <= ip[1]){ x += ip[0]; } else { x += ip[0] - 1; } writeln(x); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint; void main() { auto N = readln.chomp.to!int; writeln(N/2 - (N%2 == 0 ? 1 : 0)); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto fi = new int[](45); fi[0] = fi[1] = 1; foreach (i; 2..n+1) fi[i] = fi[i-1] + fi[i-2]; writeln(fi[n]); }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() { //auto tokens = split(my_readln()); string S = my_readln(); string S2 = "keyence"; bool ans = false; ulong begin; ulong si; foreach (i, c; S) { if (c == S2[si]) { ++si; if (si == S2.length) { begin = i; break; } } else { begin = i - 1; break; } } ulong remain1 = S2.length - si; ulong remain2 = S.length - begin - remain1; if (S[0..begin+1] ~ S[begin+remain2..$] == S2) ans = true; stderr.writeln(S[0..begin+1], " ", S[begin+remain2..$]); writeln(ans ? "YES" : "NO"); stdout.flush(); }
D
void main() { string s = readln.chomp; string t; foreach (x; s) { if (x == 'B') { if (!t.empty) t.popBack; } else { t ~= x; } } t.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, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; import core.stdc.stdlib; void main() { auto N = scanElem; auto K = scanElem; writeln(N-K+1); } long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a % b); } class UnionFind{ UnionFind parent = null; void merge(UnionFind a) { if(same(a)) return; a.root.parent = this.root; } UnionFind root() { if(parent is null)return this; return parent = parent.root; } bool same(UnionFind a) { return this.root == a.root; } } void scanValues(TList...)(ref TList list) { auto lit = readln.splitter; foreach (ref e; list) { e = lit.fornt.to!(typeof(e)); lit.popFront; } } T[] scanArray(T = long)() { return readln.split.to!(long[]); } void scanStructs(T)(ref T[] t, size_t n) { t.length = n; foreach (ref e; t) { auto line = readln.split; foreach (i, ref v; e.tupleof) { v = line[i].to!(typeof(v)); } } } long scanULong(){ long x; while(true){ const c = getchar; if(c<'0'||c>'9'){ break; } x = x*10+c-'0'; } return x; } T scanElem(T = long)() { char[] res; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { res ~= cast(char) c; c = getchar; } return res.strip.to!T; } template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } struct Factor { long n; long c; } Factor[] factors(long n) { Factor[] res; for (long i = 2; i ^^ 2 <= n; i++) { if (n % i != 0) continue; int c; while (n % i == 0) { n = n / i; c++; } res ~= Factor(i, c); } if (n != 1) res ~= Factor(n, 1); return res; } long[] primes(long n) { if(n<2)return []; auto table = new long[n+1]; long[] res; for(int i = 2;i<=n;i++) { if(table[i]==-1) continue; for(int a = i;a<table.length;a+=i) { table[a] = -1; } res ~= i; } return res; } bool isPrime(long n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long i = 3; i ^^ 2 <= n; i += 2) if (n % i == 0) return false; return true; }
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.ascii; void main() { int n; scan(n); foreach (i ; 0 .. n) { string s1,s2; scan(s1, s2); writeln(i2m(m2i(s1) + m2i(s2))); } } int m2i(string s) { int res; int[char] t = ['m':1000, 'c':100, 'x':10, 'i':1]; while (!s.empty) { if (s[0].isDigit) { res += (s[0] - '0') * t[s[1]]; s.popFrontN(2); } else { res += t[s[0]]; s.popFront; } } return res; } string i2m(int x) { char[] res; char[int] t = [3:'m', 2:'c', 1:'x', 0:'i']; int d; while (x > 0) { int r = x % 10; if (r > 0) { res ~= t[d]; } if (r > 1) { res ~= r + '0'; } x /= 10; d++; } res.reverse(); return res.to!string; } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } void main() { auto X = readln.chomp.to!int; bool isPrime(int n) { if (n == 2) { return true; } else if (n % 2 == 0 || n < 2) { return false; } else { for (int i = 3; i <= sqrt(float(n)); i += 2) { if (n % i == 0) { return false; } } } return true; } for(int i = X; true; i++) { if (i > 2 && i % 2 == 0) continue; if (isPrime(i)) { writeln(i); break; } } }
D
import std.stdio; import core.stdc.stdio; import std.algorithm; struct cube{ int x1; int x2; int y1; int y2; int z1; int z2; } int find(int[] d,int t){ for(int i=0;i<d.length;i++) if(d[i] == t) return i; return -1; } void main(){ int n,k; int[] xs,ys,zs; cube[] cs; scanf("%d%d",&n,&k); xs = new int[n*2]; ys = new int[n*2]; zs = new int[n*2]; cs = new cube[n]; for(int i=0;i<n;i++){ scanf("%d%d%d%d%d%d",&cs[i].x1,&cs[i].y1,&cs[i].z1,&cs[i].x2,&cs[i].y2,&cs[i].z2); xs[i*2] = cs[i].x1; xs[i*2+1] = cs[i].x2; ys[i*2] = cs[i].y1; ys[i*2+1] = cs[i].y2; zs[i*2] = cs[i].z1; zs[i*2+1] = cs[i].z2; } sort(xs); sort(ys); sort(zs); //xs.writeln; //ys.writeln; //zs.writeln; int[] count = new int[n*n*n*8]; for(int i=0;i<n;i++){ int xl = xs.find(cs[i].x1); int xr = xs.find(cs[i].x2); int yl = ys.find(cs[i].y1); int yr = ys.find(cs[i].y2); int zl = zs.find(cs[i].z1); int zr = zs.find(cs[i].z2); for(int x=xl;x<xr;x++){ for(int y=yl;y<yr;y++){ for(int z=zl;z<zr;z++){ count[(x*n*2+y)*n*2+z]++; } } } } long ans=0; for(int x=0;x<n*2-1;x++){ long xd = xs[x+1]-xs[x]; for(int y=0;y<n*2-1;y++){ long yd = ys[y+1]-ys[y]; for(int z=0;z<n*2-1;z++){ long zd = zs[z+1]-zs[z]; if(count[(x*n*2+y)*n*2+z]>=k){ // writeln(x," ",y," ",z," ",xd," ",yd," ",zd); ans += xd*yd*zd; } } } } printf("%lld\n",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; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int t = read.to!int; foreach(_; 0 .. t){ long n = read.to!long; long k = read.to!long; long ans; while(n > 0){ if(n % k == 0) ans += 1, n /= k; else ans += n % k, n -= (n % k); } ans.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 S = readln.chomp; auto N = S.length; int k = int.max; char last; foreach (i, c; S) { if (c != last) { if (i) { k = min(k, max(i, N-i).to!int); } last = c; } } writeln(k == int.max ? N : k); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long A, B; scan(A, B); writeln((A + B) % 24); }
D
import std.stdio, std.string, std.conv, std.algorithm, std.array; void main(){ auto a = readln.split.map!(to!int); auto w = a[0]; auto h = a[1]; auto x = a[2]; auto y = a[3]; auto r = a[4]; if(w>=x+r && 0<=x-r && h>=y+r && 0<=y-r) writeln("Yes"); else writeln("No"); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, 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!T;r.popFront;}} void main() { int n, m, x; readV(n, m, x); int[] a; readA(m, a); auto as = a.assumeSorted; writeln(min(as.lowerBound(x).length, as.upperBound(x).length)); }
D
import std.stdio; import std.conv; import std.array; void main(){ string[] input = readln.split; int N = input[0].to!int; int M = input[1].to!int; if(N == 1){ write(readln.split[0]); } else{ int[] A = new int[M]; int K; int ij; for(int i = 0;i < N;i++){ input = readln.split; K = input[0].to!int; for(int j = 0;j < K;j++){ ij = input[j+1].to!int; A[ij - 1]++; } } int cnt; for(int i = 0;i < M;i++){ if(A[i] == N) cnt++; } write(cnt); } }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto S = scanString; dchar c; long i; foreach(_;S){ if(c==_){ i++; if(i==3)end("Yes"); }else{ i=1; } c=_; } end("No"); }
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 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, x; readV(n, x); int[] a; readA(n, a); auto ans = 0L; foreach (i; 1..n) { if (a[i-1]+a[i] > x) { auto r = min(a[i], a[i-1]+a[i]-x); a[i] -= r; ans += r; if (a[i] == 0) { r = a[i-1]-x; ans += r; } } } writeln(ans); }
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { auto sc = new Scanner(stdin); int k; sc.read(k); k *= 2; if (k == 0) { writeln("miku"); return 0; } string s; char nw = 'a'; while (k) { foreach (i; 1..1000) { if (k < (i+1)*(i)) { k -= i*(i-1); s ~= nw.repeat.take(i).array; nw++; break; } } } writeln(s); return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.foundation; static if (__VERSION__ <= 2070) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } version (X86) static if (__VERSION__ < 2071) { import core.bitop : bsf, bsr, popcnt; int bsf(ulong v) { foreach (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int bsr(ulong v) { foreach_reverse (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int popcnt(ulong v) { int c = 0; foreach (i; 0..64) { if (v & (1UL << i)) c++; } return c; } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File; 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) { this.f = f; } char[512] lineBuf; char[] line; private bool succ() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (true) { while (!line.empty && line.front.isWhite) { line.popFront; } if (!line.empty) break; if (f.eof) return false; line = lineBuf[]; f.readln(line); } return true; } private bool readSingle(T)(ref T x) { import std.algorithm : findSplitBefore; import std.string : strip; import std.conv : parse; if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { auto r = line.findSplitBefore(" "); x = r[0].strip.dup; line = r[1]; } else { auto buf = line.split.map!(to!E).array; static if (isStaticArray!T) { assert(buf.length == T.length); } x = buf; line.length = 0; } } else { x = line.parse!T; } 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); } } }
D
void main() { dchar[] s = readln.chomp.to!(dchar[]); long a = s.countUntil('A'); reverse(s); long z = s.countUntil('Z'); writeln(s.length - z - a); } 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
// 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; int n; void main() { while (true) { scan(n); if (n == 0) break; writeln(solve(n)); } } int solve(int n) { int res; foreach (r ; 1 .. n) { int x = r * (r + 1) / 2; int y = x - n; if (y < 0) continue; int btm = -1, top = r, mid; while (top - btm > 1) { mid = btm + (top - btm) / 2; if (mid * (mid + 1) / 2 >= y) { top = mid; } else { btm = mid; } } if (top * (top + 1) / 2 == y) { debug { writeln(top, " ", r); } res++; } } return res; } 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 = "%.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; } int binarySearch(alias pred, T)(in T[] arr, bool isLower = true) { int ok, ng; if (isLower) { ok = cast(int)arr.length; ng = -1; } else { ok = -1; ng = cast(int)arr.length; } while (abs(ok-ng) > 1) { auto mid = (ok+ng) / 2; if (unaryFun!pred(arr[mid])) ok = mid; else ng = mid; } return ok; } void main() { auto N = RD; auto S = RD!string; auto pos = new long[][](26); foreach (i; 0..N) { auto num = S[i] - 'a'; pos[num] ~= i; } long ans; foreach (i; 0..N-1) { auto num = S[i] - 'a'; auto pi = pos[num].binarySearch!((long a) => a > i)(); foreach (j; pos[num][pi..$]) { auto len1 = j - i; auto len2 = N - j; auto len = min(len1, len2); if (len <= ans) continue; bool ok = true; foreach (k; 0..ans) { if (S[i+k] != S[j+k]) { ok = false; break; } } if (!ok) continue; foreach (k; ans..len) { if (S[i+k] != S[j+k]) break; ans = max(ans, k+1); } } } writeln(ans); stdout.flush(); debug readln(); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); auto t=readln.chomp.to!(char[]); if(s.length<t.length){writeln("UNRESTORABLE"); return;} auto mn=new char[](s.length); foreach(ref e; mn) e='z'; bool none=true; for(auto i=0; i<=s.length-t.length; i++){ bool ok=true; for(auto j=0; j<t.length; j++){ ok&=(s[i+j]==t[j] || s[i+j]=='?'); } if(ok){ none=false; auto u=new char[](s.length); foreach(k; 0..i) u[k]=(s[k]=='?' ? 'a' : s[k]); foreach(k; 0..(t.length)) u[i+k]=t[k]; foreach(k; (i+t.length)..(s.length)) u[k]=(s[k]=='?' ? 'a' : s[k]); if(u<mn) mn=u; } } if(none){ writeln("UNRESTORABLE"); }else{ writeln(mn); } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
module app; import std.stdio; import std.string; void main() { auto abc = readln().strip(); if (abc == "5 5 7" || abc == "5 7 5" || abc == "7 5 5") write("YES"); else write("NO"); }
D
import std.stdio, std.string; void main() { string a = readln.chomp; if (a[0..4] == "YAKI") { writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() { auto tokens = my_readln().split(); auto s = tokens[0].to!uint; auto used = new uint[](1000000); used[s] = 1; uint last = s, ans; foreach (i; 1..1000000) { if (last % 2 == 0) { last /= 2; } else { last = last * 3 + 1; } if (used[last] == 1) { ans = i + 1; break; } used[last] = 1; } writeln(ans); stdout.flush(); }
D
import std.stdio,std.conv,std.string,std.algorithm,std.array; void main(){ auto sx=readln().split(); auto sa=readln().split(); auto sb=readln().split(); int x,a,b; x=to!int(sx[0]); a=to!int(sa[0]); b=to!int(sb[0]); writeln((x-a)%b); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto K = RD; auto X = RD; auto Y = RD; writeln(min(N, K) * X + max(N - K, 0) * Y); stdout.flush(); debug readln(); }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons; void main() { auto input = readln.split.to!(int[]); int A = input[0], B = input[1]; writeln(max(A-B-B, 0)); }
D
import std.stdio; import std.string; import std.math; import std.conv; import std.algorithm; import std.bigint; void main(){ while(true){ string input = readln(); if(stdin.eof()) break; auto s = to!real(chomp(input)); for(int i=1;;i++){ if(s*s < 19.6 * (5*i-5)) { writeln(i); break; } } } }
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 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; readV(n); int[] a; readA(n, a); auto ans1 = 0L, s1 = 0L; foreach (i; 0..n) { s1 += a[i]; if (i%2 == 0) { if (s1 <= 0) { ans1 += -s1 + 1; s1 = 1; } } else { if (s1 >= 0) { ans1 += s1 + 1; s1 = -1; } } } auto ans2 = 0L, s2 = 0L; foreach (i; 0..n) { s2 += a[i]; if (i%2 == 1) { if (s2 <= 0) { ans2 += -s2 + 1; s2 = 1; } } else { if (s2 >= 0) { ans2 += s2 + 1; s2 = -1; } } } writeln(min(ans1, ans2)); }
D
import std.stdio; import std.conv; import std.algorithm; import std.string; void main(){ while(1){ auto a=map!(to!int)(readln.chomp.split); int m=a[0],f=a[1],r=a[2]; if(m<0&&f<0&&r<0)break; if(m<0||f<0)writeln("F"); else if(80<=m+f)writeln("A"); else if(65<=m+f)writeln("B"); else if(50<=m+f)writeln("C"); else if(30<=m+f)writeln(((r>=50)?"C":"D")); else writeln("F"); } }
D
import std.stdio; import std.conv; import std.algorithm; import std.range; import std.string; import std.math; void main() { int taro, hanako; readln; foreach (string line; stdin.lines) { auto words = line.chomp.split; if (words[0] > words[1]) { taro += 3; } else if (words[0] < words[1]) { hanako += 3; } else { taro++; hanako++; } } writeln(taro, " ", hanako); }
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 A = RD; auto B = RD; long[40] f(long x) { long[40] r; foreach (i; 0..40) { auto unit = pow(2LU, i); auto y = x / unit / 2 * unit; if ((x / unit) % 2 == 1) y += x % unit; r[i] = y; } return r; } auto cnt_a = f(A); //stderr.writeln(cnt_a); auto cnt_b = f(B+1); //stderr.writeln(cnt_b); long ans; foreach (i; 0..40) { auto cnt = cnt_b[i] - cnt_a[i]; if (cnt % 2 == 1) ans |= 1LU << i; } writeln(ans); stdout.flush(); }
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() { long a, b; scan(a, b); if (a + b == 15) { writeln("+"); } else if (a * b == 15) { writeln("*"); } else { writeln("x"); } }
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; int[] di = [1,0,-1,0,1,1,-1,-1], dj = [0,1,0,-1,1,-1,1,-1]; int ans; void main() { while (1) { int n; scan(n); if (!n) return; auto ans = cntp(n); writeln(ans); } } int cntp(int n) { int cnt; foreach (a ; n + 1 .. 2*n + 1) { cnt += isPrime(a); } return cnt; } bool isPrime(int a) { for (int p = 2; p*p <= a; p++) { if (a % p == 0) { return false; } } return true; } 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.string, std.array, std.conv, std.algorithm.iteration, std.functional; void main() { auto _x = readln; auto s = readln.chomp; int x, max; foreach (c; s) { switch (c) { case 'I': if (++x > max) max = x; break; case 'D': --x; break; default: } } writeln(max); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { long n = lread(); // writeln(n); auto l = new long[](100); l[0] = 2; l[1] = 1; // writeln(l); foreach (i; 2 .. n + 1) { l[i] = l[i - 1] + l[i - 2]; } writeln(l[n]); } 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.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; void main() { int n = readln.chomp.to!int; string[] ss = readln.chomp.split; bool[bool[char]] roots; foreach (s; ss) { bool[char] root; foreach (c; s) { root[c] = true; } roots[root] = true; } roots.length.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 ref Args args) { stderr.write("["); foreach (i, ref v; args) { if (i) stderr.write(", "); stderr.write(v); } stderr.writeln("]"); }
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; void main() { auto n = readln.strip.to!int; auto s = readln.strip[0 .. n]; foreach (i; 1 .. n) { if (s[i-1] > s[i]) { debug stderr.writeln (i); writeln ("YES"); writeln (i, ' ', i + 1); return; } } writeln ("NO"); }
D
import std.algorithm; import std.array; import std.bigint; import std.conv; import std.exception; import std.math; import std.numeric; import std.random; import std.range; import std.stdio; import std.string; import std.typecons; import core.bitop; immutable int NA = -1; immutable string A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; immutable string B = "AxxxxxxHIxxxMxOxxxxTUVWXYx"; void main () { char [dchar] d; foreach (i; 0..A.length) { d[A[i]] = B[i]; } char [] s; while ((s = to !(char []) (readln ().strip ())) != "") { char [] b = s.dup; reverse (b); char [] c; foreach (x; b) { c ~= d[x]; } writeln (s == c ? "YES" : "NO"); } }
D
// cheese-cracker [2022-02-06] void solve(){ long n = scan; long k = scan; if(k == 1 || (n % 2 == 0)){ writeln("YES"); }else{ writeln("NO"); return; } long m = n * k; long x = 1; for(int i = 0; i < n; ++i){ for(int j = 0; j < k; ++j){ write(x, " "); x += 2; if(x > m){ x = 2; } } writeln; } } void main(){ long tests = scan; // Toggle! while(tests--) solve; } /*_________________________*That's All Folks!*__________________________*/ import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric; string[] tk; alias tup = Tuple!(long, long); T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;} T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; } void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
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, 2); foreach (ti; 0..t) { auto n = RD!int; auto s = RD!string; long cnt0, cnt1; foreach (i; 0..n) { if (s[i] == '0') ++cnt0; else ++cnt1; } long c0, c1; foreach (i; 0..n) { if (s[i] == '0') { ans[ti][0] ~= c0 % 2 ? ')' : '('; ++c0; } else { ans[ti][0] ~= c1 < cnt1/2 ? '(' : ')'; ++c1; } } foreach (i; 0..n) { if (s[i] == '1') ans[ti][1] ~= ans[ti][0][i]; else ans[ti][1] ~= ans[ti][0][i] == '(' ? ')' : '('; } bool ok = true; long cnt; foreach (i; 0..n) { if (ans[ti][1][i] == '(') ++cnt; else --cnt; if (cnt < 0) { ok = false; break; } } if (cnt != 0) ok = false; if (!ok) ans[ti].length = 0; } foreach (e; ans) { if (e.empty) writeln("NO"); else { writeln("YES"); writeln(e[0]); writeln(e[1]); } } stdout.flush; debug readln; }
D
import std.stdio; import std.algorithm; void main() { int n; scanf("%d", &n); int a, cnt1, cnt0; for (int i = 0; i < n; ++i) { scanf("%d", &a); if (a & 1) ++cnt1; else ++cnt0; } int ans = min(cnt0, cnt1); cnt1 -= ans; ans += cnt1 / 3; printf("%d", ans); }
D
import std.stdio, std.string, std.algorithm; void main() { immutable s1 = readln.chomp; immutable s2 = readln.chomp; int[][] dp = new int[][](s1.length+1, s2.length+1); for( int i=0; i<=s1.length; ++i ) dp[i][0] = i; for( int i=0; i<=s2.length; ++i ) dp[0][i] = i; for( int i=1; i<=s1.length; ++i ) { for( int j=1; j<=s2.length; ++j ) { immutable cost = s1[i-1] == s2[j-1] ? 0 : 1; dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + cost); } } dp[$-1][$-1].writeln; }
D
import std.conv,std.stdio,std.math,std.string;void main(){readln.chomp.to!int.pow(2).writeln;}
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() { string s; scan(s); writeln(s.canFind("AC") ? "Yes" : "No"); } 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
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test 4 ---+/ void main(string[] args) { const r = readln.chomp.to!long; (3*r.pow(2)).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; 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() { long x, a; scan(x, a); if(x < a) writeln(0); else writeln(10); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto x_y = readln.to!(wchar[]); writeln(x_y[0] > x_y[2] ? ">" : x_y[0] < x_y[2] ? "<" : "="); }
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; } const long mod = 1_000_000_007; void main(){ long h = read.to!long; long w = read.to!long; long k = read.to!long; // 解説見て考えた // HWK(K + 1)(K - 1)P(N - 2, K - 2) / 3 + P(H + W, K)K(K + 3) / 2 long a = h * w; a %= mod; a *= k, a %= mod; a *= k + 1, a %= mod; a *= k - 1, a %= mod; a *= perm(h + w - 2, k - 2), a %= mod; a *= inv(3), a %= mod; long b = perm(h + w, k); b *= k, b %= mod; b *= k + 3, b %= mod; b *= inv(2), b %= mod; long ans = a + b; ans %= mod; ans.writeln; } // mod p における乗法逆元 long inv(long x){ assert(x > 0); assert(x < mod); static long[] _inv = [0, 1]; while(x >= _inv.length){ _inv ~= _inv[mod % $] * (mod - mod / _inv.length) % mod; } return _inv[x]; } // 順列 P long perm(long n, long k){ long ans = 1; for(long i = 0; i < k; i ++){ ans *= n - i; ans %= mod; } return ans; } /* 交差点の個数で捉えると、1回の切断のスコアは (交差点の個数) + (割線の本数) + 1 と読み替えられる 長さKの操作列のうちのi回目である場合、そのスコアは (i回目での交差点の個数) + i + 1 よって、長さKの操作列のスコアは = Σ[i] (i回目での交差点の個数) + K(K + 3) / 2 求めるものは、P(N, K)種類ある操作列すべてにわたる和 Σ[操作列]( Σ[i] (i回目での交差点の個数) + K(K + 3) / 2 ) = Σ[操作列]( Σ[i] Σ[交差点](i回目以前に登場? 1: 0) + K(K + 3) / 2 ) = Σ[交差点]( Σ[操作列, i](i回目以前に登場? 1: 0) ) + Σ[操作列]( K(K + 3) / 2 ) 前半を求めるために、縦線aと横線bの交わる交差点に注目する aの登場する位置、bの登場する位置を同じa、bで表すとしたとき、 「a < b <= i となるような操作列およびiのとり方が何通りあるか」 である それは ・AとBと(K - 2)個の□を並べ、そのうちの1個を黒く塗ったとき  黒よりも右側にAもBもない場合の数 と考えればよく、 それは 2(1 + 3 + 6 + 10 + 15) のような形の和である。 つまり Σ[i in [1, K - 1]]( i(i + 1) / 2 ) であり K(K + 1)(K - 1) / 3 さらに□に文字をはめると考えると、 K(K + 1)(K - 1)P(N - 2, K - 2) / 3 交差点はHW個あるので、先程の前半と言っていたものは HWK(K + 1)(K - 1)P(N - 2, K - 2) / 3 求めるものは HWK(K + 1)(K - 1)P(N - 2, K - 2) / 3 + P(H + W, K)K(K + 3) / 2 たとえば H = 2, W = 1, K = 2のとき P(2 + 1, 2) 2 (4 - 4 + 3) 2 1 / 3(2 + 1)(2 + 1 - 1) + P(2 + 1, 2) 2 5 / 2 = 6 2 3 2 1 / 3 3 2 + 6 2 5 / 2 = 4 + 30 = 34 */
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto H = readln.chomp.to!long; long d, x = 1; while (H) { d += x; x *= 2; H /= 2; } writeln(d); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { for (;;) { auto rd = readln.split.map!(to!int), m = rd[0], f = rd[1], r = rd[2]; if (m == -1 && f == -1 && r == -1) break; if (m == -1 || f == -1) writeln("F"); else if (m + f >= 80) writeln("A"); else if (m + f >= 65 && m + f < 80) writeln("B"); else if (m + f >= 50 && m + f < 65) writeln("C"); else if (m + f >= 30 && m + f < 50) { if (r >= 50) writeln("C"); else writeln("D"); } else writeln("F"); } }
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, K; scan(N, K); long v = min(K, N - 1); long ans; auto c = Combination_mod(10 ^^ 6); // n個の中から重複ありでk個選ぶ long h(long n, long k) { return c(n + k - 1, n - 1); } // xは0人の部屋の数 foreach (x; 0 .. v + 1) { // c(N, x): 0人の部屋を選ぶ // h(N-x, x): 0人になった部屋から移動した人の移動先を選ぶ ans = (ans + (c(N, x) * h(N - x, x) % MOD)) % MOD; } writeln(ans); } /// Number of k-combinations % m (precalculated) alias Combination_mod = Combination_modImpl!long; struct Combination_modImpl(T) { T _n, _m; T[] _fact, _factinv; this(T maxnum, T mod = 10 ^^ 9 + 7) { _n = maxnum, _m = mod, _fact = new T[](_n + 1), _factinv = new T[](_n + 1), _fact[0] = 1; foreach (i; 1 .. _n + 1) _fact[i] = _fact[i - 1] * i % _m; T powmod(T x, T n, T m) { if (n < 1) return 1; if (n & 1) { return x * powmod(x, n - 1, m) % m; } T tmp = powmod(x, n / 2, m); return tmp * tmp % m; } foreach (i; 0 .. _n + 1) _factinv[i] = powmod(_fact[i], _m - 2, _m); } T opCall(T n, T k, T dummy = 10 ^^ 9 + 7) { return n < k ? 0 : ((_fact[n] * _factinv[n - k] % _m) * _factinv[k] % _m); } }
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 x = RD; writeln(x^1); 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; void main() { int a, b; scan(a, b); auto ans = a * (a - 1) / 2 + b * (b - 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.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto S = RD!string; writeln(S == "ABC" ? "ARC" : "ABC"); stdout.flush; debug readln; }
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!(string, "x", long, "y"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long k, x; scan(k, x); if(500 * k >= x) writeln("Yes"); else writeln("No"); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.typecons; int n; rd(n); int m; rd(m); auto lose=new int[](n), g=new int[][](n); foreach(i; 0..m){ int a, b; rd(a, b); g[a-1]~=(b-1); lose[b-1]++; } bool multi=false; auto used=new bool[](n); foreach(_; 0..n){ int[] cand; foreach(i; 0..n){ if(used[i]) continue; if(lose[i]>0) continue; cand~=i; } if(cand.length>1) multi=true; auto i=cand[0]; foreach(j; g[i]) lose[j]--; writeln(i+1); used[i]=true; } if(multi) writeln(1); else writeln(0); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm; void main() { int n = readln().chomp().to!int; string minS = readln().chomp(); for (int i = 0; i < n - 1; i++){ string dic = readln().chomp(); if (dic < minS){ minS = dic; } } writeln(minS); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long A, B; scan(A, B); auto S = sread(); bool a = S[A] == '-'; bool b = (S[0 .. A] ~ S[A + 1 .. $]).all!(c => '0' <= c && c <= '9'); writeln((a && b) ? "Yes" : "No"); }
D
import std.algorithm; import std.array; 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 scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; bool calc(int[] hs) { hs[0]--; for (int i = 1; i < hs.length; i++) { if (hs[i - 1] < hs[i]) hs[i]--; if (hs[i - 1] > hs[i]) return false; } return true; } void main() { readint; auto hs = readints; writeln(calc(hs) ? "Yes" : "No"); }
D
import std.stdio; import std.conv; import std.string; void main() { string s = readln().chomp; if (s[$ - 1] == '0' || s[$ - 1] == '2' || s[$ - 1] == '4' || s[$ - 1] == '6' || s[$ - 1] == '8' ) { writeln(s); } else { writeln(s.to!(int) * 2); } }
D
import std.stdio, std.string, std.range, std.algorithm, std.math, std.typecons, std.conv; void main() { auto a = readln.split.to!(int[]); ((a[0] <= a[2] && a[2] <= a[1]) ? "Yes" : "No").writeln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; 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]; bool found = false; for (int i = 1; i <= b; i++) { if (a * i % b == c) { found = true; break; } } writeln(found ? "YES" : "NO"); }
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; } void main() { bool solve() { auto s = readln.chomp; if (s == ".") return false; auto t = readln.chomp; if (s == t) { writeln("IDENTICAL"); return true; } auto ss = s.split("\"").array; auto ts = t.split("\"").array; if (ss.length != ts.length) { writeln("DIFFERENT"); return true; } foreach (int i, x; ss) { if (i % 2 != 0) continue; if (x != ts[i]) { writeln("DIFFERENT"); return true; } } int c = 0; foreach (int i, x; ss) { if (i % 2 == 0) continue; c += (x != ts[i]); } writeln(c == 1 ? "CLOSE" : "DIFFERENT"); return true; } while (solve()) {} }
D
import std.stdio; import std.conv; import std.array; import std.math; import std.algorithm; import std.string; public int gcd(int m, int n) { if ((m == 0) || (n == 0)) return 0; while (m != n) { if (m > n) m = m - n; else n = n - m; } return m; } public int lcm(int m, int n) { if ((m == 0) || (n == 0)) return 0; return ((m / gcd(m, n) * n)); } int main() { string s; while((s = readln()).length != 0) { string[] _s = split(s); int a = to!int(_s[0]); int b = to!int(_s[1]); int x = gcd(a,b); int y = lcm(a,b); printf("%d %d\n",x,y); } return 0; }
D
module app; import core.bitop; import std.algorithm; import std.array; import std.bigint; import std.conv; import std.stdio; import std.string; struct Input { string s; } void parseInput(T)(out Input input, T file) { with (file) with (input) { s = readln().strip(); } } struct Output { } auto main2(Input* input) { foreach (c; input.s) write("x"); } void main() { Input input = void; parseInput(input, stdin); main2(&input); }
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() { string s; scan(s); int n = s.length.to!int; if (n % 2) { writeln("No"); return; } foreach (i ; 0 .. n / 2) { if (s[2*i .. 2*i + 2] != "hi") { writeln("No"); return; } } writeln("Yes"); } 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.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { string s; scan(s); foreach (i ; 0 .. s.length) { if (i & 1 ^ 1) { write(s[i]); } } writeln(); } 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; auto y = RD; long[long] g = [1:0, 2:2, 3:0, 4:1, 5:0, 6:1, 7:0, 8:0, 9:1, 10:0, 11:1, 12:0]; auto ans = g[x] == g[y]; writeln(ans ? "Yes" : "No"); stdout.flush(); debug readln(); }
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 L; scanf("%d", &L); int n = 20, m = (n-2)*2; int l = L; foreach (i; 0..n) { m += l&1; if (i == n-1) m += l&1; l >>= 1; } writeln(n," ",m); foreach (i;0..n-2) { writeln(i+1," ",i+2," ",0); writeln(i+1," ",i+2," ",1<<i); } l = L; foreach (i; 0..n) { if (l>>i&1) { l ^= 1<<i; if (i+1 < n) { writeln(i+1," ",n," ",l); } else { writeln(n-1," ",n," ",l); writeln(n-1," ",n," ",l+(1<<(i-1))); } } } }
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; void main() { auto N = readln.chomp.to!int; auto A = N.iota.map!(_ => readln.chomp.to!int).array; auto dp = new bool[][](N+1, 10001); dp[0][0] = true; foreach (i; 0..N) { foreach (j; 0..10001) { if (dp[i][j]) { dp[i+1][j] = true; if (j + A[i] <= 10000) { dp[i+1][j+A[i]] = true; } } } } int ans = 0; foreach (i; 0..10001) { if (i % 10 > 0 && dp[N][i]) ans = i; } ans.writeln; }
D