code
stringlengths
4
1.01M
language
stringclasses
2 values
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "l ", long, "r"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long d, n; scan(d, n); if(n < 100) writeln(n * 100 ^^ d); else writeln(100 ^^ d + 100 ^^ (d + 1)); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import core.bitop, 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(); auto T = "ACGT"; auto U = "TGCA"; foreach (i; 0 .. 4) { if (S[0] == T[i]) { writeln(U[i]); return; } } }
D
void main() { long n = rdElem; calc(n).writeln; } long calc(long x) { long result = inf; for (long i = 1; i * i <= x; ++i) { if (x % i == 0) { result = min(result, i+x/i-2); } } return result; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; 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 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, C; scan(A, B, C); if ((A & 1) == 0 || (B & 1) == 0 || (C & 1) == 0) writeln(0); else min(A * B, B * C, C * A).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(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; long ans; if (X < 600) ans = 8; else if (X < 800) ans = 7; else if (X < 1000) ans = 6; else if (X < 1200) ans = 5; else if (X < 1400) ans = 4; else if (X < 1600) ans = 3; else if (X < 1800) ans = 2; else ans = 1; writeln(ans); stdout.flush; debug readln; }
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { writeln(reduce!((a,_)=>(a*105+99999)/100000*1000)(100000L,iota(readln().chomp().to!long()))); }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { ulong[] NM = readln.chomp.split.to!(ulong[]); ulong n = NM[0], m = NM[1]; ulong s, c; if (n <= m / 2) { writeln(n + (m - 2*n) / 4); } else { writeln(m / 2); } }
D
import std.string; import std.stdio; import std.conv; import std.algorithm; int[] nums = [0,1,2,3,4,5,6,7,8,9]; int n,s; int saiki(int x,int m,int item){ if(m == s && item == n) return 1; if(x == 10) return 0; return saiki(x+1,m+nums[x],item+1) + saiki(x+1,m,item); } void main(){ while(true){ auto ss = split(readln()); n = to!int(ss[0]); s = to!int(ss[1]); if(n == 0 && s == 0) break; writeln(saiki(0,0,0)); } }
D
import std.stdio; import std.algorithm; import std.conv; import std.numeric; import std.math; import std.string; void main() { auto tokens = split(chomp(readln())); auto N = to!ulong(tokens[0]); auto M = to!ulong(tokens[1]); string S = chomp(readln()); string T = chomp(readln()); ulong lcm = (N * M) / gcd(N, M); if (S[0] != T[0]) writeln("-1"); else { uint nr = cast(uint)(lcm / N); uint mr = cast(uint)(lcm / M); bool flag = true; foreach (i; 1..cast(uint)N) { uint p1= i * nr; if (p1 % mr != 0) continue; //foreach (j; 1..M) { uint j = p1 / mr; //uint p2 = j * mr; //if (p1 == p2) { if (S[i] != T[j]) { flag = false; break; } } } } ulong r = nr > mr ? nr * N : mr * M; if (flag) writeln(r); else writeln("-1"); } stdout.flush(); }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { int m = readln.chomp.to!int; writeln(48 - m); }
D
import std.stdio; import std.algorithm; import std.conv; import std.string; void main() { auto k = to!int(chomp(readln())); auto a = k / 2; auto b = k / 2 + k % 2; writeln(a * b); stdout.flush(); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; int abs(int n) { return n < 0 ? -n : n; } void main() { int[] arr = readln.chomp.split.to!(int[]); bool flg = false; writeln( (abs(arr[0] - arr[2]) <= arr[3] || abs(arr[0] - arr[1]) <= arr[3] && abs(arr[1] - arr[2]) <= arr[3]) ? "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; } 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; auto T = RD!string; writeln(T ~ S); stdout.flush; debug readln; }
D
import std.stdio; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; import std.typecons; import std.regex; import std.range; char[8][8] s; void bom(int x,int y){ s[y][x] = '0'; for(int dx=-3;dx<=3;dx++){ int nx = x + dx; if(0<=nx&&nx<8) if(s[y][nx]=='1'){ bom(nx,y); } } for(int dy=-3;dy<=3;dy++){ int ny = y + dy; if(0<=ny&&ny<8) if(s[ny][x]=='1'){ bom(x,ny); } } } void main(){ int n = readln().chomp().to!int; for(int i=0;i<n;i++){ readln(); for(int j=0;j<8;j++){ string ss = readln().chomp(); for(int k=0;k<8;k++) s[j][k] = ss[k]; } int x = readln().chomp().to!int; int y = readln().chomp().to!int; bom(x-1,y-1); writeln("Data ",i+1,":"); for(int k=0;k<8;k++){ for(int l=0;l<8;l++){ write(s[k][l]); } writeln(); } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void solve() { auto N = readln.chomp.to!long; long x; foreach (long i; 0..32) { x += x + (2L^^i)^^2; if (N >= x) { N -= x; } else { writeln(i); return; } } } void main() { auto T = readln.chomp.to!int; foreach (_; 0..T) { solve(); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int a, b, c, x, y; readV(a, b, c, x, y); auto ans = 10^^9; foreach (nc; 0..2*max(x,y)+1) { auto na = max(0, x-nc/2), nb = max(0, y-nc/2); ans = min(ans, na*a+nb*b+nc*c); } writeln(ans); }
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; void main() { readln.chomp.to!int.rep!readln.map!chomp.map!(to!long).fold!( (a, b) => a/gcd(a, b)*b )(1L).writeln; } // ---------------------------------------------- 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, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } void main() { auto I = readln.split.to!(long[]); auto N = I[0]; auto K = I[1]; long solve() { long ketasu = 1; for(auto i = K; N >= i; i *= K) { ketasu++; } return ketasu; } solve().writeln; }
D
import std; void main() { int t; scanf("%d", &t); getchar(); foreach(_; 0..t) { auto s = readln.strip; auto z = count(s, '0'); auto o = s.length - z; if (z == 0 || o == 0) writeln(0); else if (o == z) if (s.length > 2) writeln(o - 1); else writeln(0); else writeln(min(o, z)); } }
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(); long N = S.length; auto dp = new long[][](13, N + 1); dp[0][0] = 1; foreach (i; 0 .. N) { if (S[i] == '?') { foreach (j; 0 .. 10) foreach (k; 0 .. 13) { dp[(k * 10 + j) % 13][i + 1] += dp[k][i]; dp[(k * 10 + j) % 13][i + 1] %= MOD; } continue; } foreach (j; 0 .. 13) { dp[(j * 10 + (S[i] - '0')) % 13][i + 1] += dp[j][i]; dp[(j * 10 + (S[i] - '0')) % 13][i + 1] %= MOD; } } writeln(dp[5][N]); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip; int N; string S; char[] ans; bool solve() { foreach (i; 1..N-1) { auto prev = ans[(i-1+N)%N]; if (ans[i] == 'S' && S[i] == 'o') { ans[(i+1)%N] = prev; } else if (ans[i] == 'S' && S[i] == 'x') { ans[(i+1)%N] = (prev == 'S') ? 'W' : 'S'; } else if (ans[i] == 'W' && S[i] == 'o') { ans[(i+1)%N] = (prev == 'S') ? 'W' : 'S'; } else { ans[(i+1)%N] = prev; } } foreach (i; 0..N) { auto prev = ans[(i-1+N)%N]; auto next = ans[(i+1)%N]; if (ans[i] == 'S' && S[i] == 'o' && prev != next) return false; else if (ans[i] == 'S' && S[i] == 'x' && prev == next) return false; else if (ans[i] == 'W' && S[i] == 'o' && prev == next) return false; else if (ans[i] == 'W' && S[i] == 'x' && prev != next) return false; } return true; } void main() { N = readln.chomp.to!int; S = readln.chomp; ans = new char[](N); auto cand = ["SS", "SW", "WS", "WW"]; foreach (i; 0..4) { foreach (j; 0..N) ans[j] = '*'; ans[0] = cand[i][0]; ans[1] = cand[i][1]; if (solve) { ans.writeln; return; } } writeln(-1); }
D
import std; void main() { string s = read; string t = read; writeln(t.startsWith(s) ? "Yes" : "No"); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T=string)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readints = reads!int;
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(string, "s", long, "p"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { auto s = sread(); s.length -= 2; while (s.length > 0) { if (s.is_evenstring()) { s.length.writeln(); return; } s.length -= 2; } assert(0); } bool is_evenstring(string s) { return (s[0 .. $ / 2] == s[$ / 2 .. $]); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; import std.container; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ int n = read.to!int; int[] as; foreach(i; 0 .. n) as ~= read.to!int; bool[int] aset; foreach(a; as) aset[a] = 1; if(aset.keys.length > 2){ debug writeln("A"); writeln("No"); return; } if(aset.keys.length == 2){ int m; if(aset.keys[0] + 1 == aset.keys[1]) m = aset.keys[0]; else if(aset.keys[1] + 1 == aset.keys[0]) m = aset.keys[1]; else{ debug writeln("B"); writeln("No"); return; } int k = 0; foreach(a; as) if(a == m) k += 1; if(m < k){ debug writeln("C-1"); writeln("No"); return; } if(k + (n - k) / 2 < m + 1){ debug writeln("C-2"); writeln("No"); return; } debug writeln("D"); writeln("Yes"); return; } else{ int m = aset.keys[0]; if(m == n - 1){ debug writeln("E"); writeln("Yes"); return; } if(n >= m * 2){ debug writeln("F"); writeln("Yes"); return; } debug writeln("G"); writeln("No"); return; } } /* 差は最大で1である。 (たとえば9と10しか存在しないなど) 9と言うのは他の誰ともちがうぼうしをかぶっている人 10と言うのは他の誰かと同じぼうしをかぶっている人 9と言った人の人数+(10と言った人の人数 / 2)に注目。 それが10以上ならOK。 差が0つまり全員同じ数を言った場合は2つのパターンがある。 全員他の人と違う帽子をかぶっているパターン。 これは人数-1を言っているならOK。 全員誰かと同じ帽子をかぶっているパターン。 これは人数がその言った数の2倍以上ならOK。 */
D
import std.stdio; import std.string; void main() { int n, k; scanf("%d %d\n", &n, &k); auto l = readln.chomp(); write(l[0..k-1] ~ l[k-1..k].toLower ~ l[k..$]); }
D
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; import std.math; import std.range; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } //Digit count---{{{ int DigitNum(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } //}}} //}}} void main() { Scanner sc = new Scanner; int N, K; sc.scan(N, K); if ((N - K) >= N / 2) { writeln("YES"); } else { writeln("NO"); } }
D
// Vicfred // https://atcoder.jp/contests/abc168/tasks/abc168_b // implementation import std.conv; import std.stdio; import std.string; void main() { int K = readln.chomp.to!int; string S = readln.strip; if(S.length > K) { S[0..K].write; "...".writeln; } else { S.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; } 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; int[] as; foreach(i; 0 .. n) as ~= read.to!int; // 1: Circle, 2: Triangle, 3: Square long ans; bool f; // was 3 -> 1. foreach(i; 0 .. n - 1){ int a = as[i] * 10 + as[i + 1]; switch(a){ case 11: case 22: case 33: case 23: case 32: writeln("Infinite"); return; case 12: if(f) ans += 2; else ans += 3; f = 0; break; case 13: ans += 4; f = 0; break; case 21: ans += 3; f = 0; break; case 31: ans += 4; f = 1; break; default: assert(0); } } writeln("Finite"); ans.writeln; }
D
void main() { dchar[] n = readln.chomp.to!(dchar[]); dchar[] m = n.dup; reverse(m); writeln(n == m ? "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.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; int [] d; int i = 0; while (i < n * 2) { int j = i; do { i += 1; } while (i < n * 2 && a[i] < a[j]); d ~= i - j; } auto f = new int [n * 2 + 1]; f[] = int.max; f[0] = -1; foreach (int k, ref c; d) { for (int p = c; p <= n * 2; p++) { if (f[p] == int.max && f[p - c] < k) { f[p] = k; } } } writeln (f[n] < int.max ? "YES" : "NO"); } }
D
import std.stdio; import std.conv; import std.string; import core.bitop; void main() { auto N = readln.chomp.to!long; immutable march = "MARCH"; long[march.length] list; foreach (_; 0 .. N) { auto name = readln(); foreach (i, c; march) { if (name[0] == c) { list[i]++; } } } long nonzero; byte mask; foreach (i, n; list) { if (n != 0) { mask |= 1 << i; nonzero++; } } long result; foreach (comb; 0b0 .. 0b111111) if ((comb & mask) == comb && popcnt(comb) == 3) { long tmp = 1; foreach (i, n; list) if ((comb & (1 << i)) != 0) { tmp *= n; } result += tmp; } writeln(result); }
D
import std.stdio; import std.string; import std.conv; void main() { string[] inputs = split(readln()); int A = to!int(inputs[0]); int B = to!int(inputs[1]); int C = to!int(inputs[2]); int D = to!int(inputs[3]); if(A + B > C + D) writeln("Left"); else if(A + B == C + D) writeln("Balanced"); else writeln("Right"); }
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii; // }}} // tbh.scanner {{{ class Scanner { import std.stdio; import std.conv : to; import std.array : split; import std.string : chomp; private File file; private dchar[][] str; private uint idx; this(File file = stdin) { this.file = file; this.idx = 0; } private dchar[] next() { if (idx < str.length) { return str[idx++]; } dchar[] s; while (s.length == 0) { s = file.readln.chomp.to!(dchar[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(uint len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } } // }}} void main() { auto cin = new Scanner; int n = cin.next!int, y = cin.next!int; writeln(n * y % 2 == 0 ? "Even" : "Odd"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_; 0..T) { readln; auto as = readln.split.to!(int[]); auto x = as[0]%2; foreach (a; as) if (x != a%2) goto ng; writeln("YES"); continue; ng: writeln("NO"); } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.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; } 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 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 main() { auto n = RD!int; auto q = RD!int; auto ans = new bool[](q); auto cell = new bool[][](2, n); bool[int] set; foreach (i; 0..q) { auto r = RD!int-1; auto c = RD!int-1; cell[r][c] = !cell[r][c]; debug writeln(cell[0]); debug writeln(cell[1]); if (cell[r][c]) { bool ok = i == 0 ? true : ans[i-1]; foreach (j; max(0, c-1)..min(n, c+2)) { if (cell[r^1][j]) { ok = false; set[r*n+c] = true; } } ans[i] = ok; } else { if (set.get(r*n+c, false)) set.remove(r*n+c); foreach (j; max(0, c-1)..min(n, c+2)) { if (!cell[r^1][j]) continue; if (set.get((r^1)*n+j, false) == false) continue; bool ok = true; foreach (k; max(0, j-1)..min(n, j+2)) { if (cell[r][k]) ok = false; } if (ok) set.remove((r^1)*n+j); } ans[i] = set.length == 0; } } foreach (e; ans) writeln(e ? "Yes" : "No"); stdout.flush; debug readln; }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n, q; readV(n, q); string s; readV(s); auto a = new int[](n); foreach (i; 1..n) a[i] = s[i-1..i+1] == "AC"; auto ac = a.cumulativeSum; foreach (_; 0..q) { int l, r; readV(l, r); writeln(ac[l..r]); } } class CumulativeSum(T) { size_t n; T[] s; this(T[] a) { n = a.length; s = new T[](n+1); static if (T.init != 0) s[0] = T(0); foreach (i; 0..n) s[i+1] = s[i] + a[i]; } pure auto opSlice(size_t l, size_t r) { return s[r]-s[l]; } pure auto opDollar() { return n; } } auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { auto A = readln.chomp.to!int; auto B = readln.chomp.to!int; auto C = readln.chomp.to!int; auto D = readln.chomp.to!int; writeln(min(A, B) + min(C, D)); }
D
/+ dub.sdl: name "D" dependency "dcomp" version=">=0.7.3" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); string s; sc.read(s); int n = s.length.to!int; int[] sm = new int[n+1]; foreach (i, c; s) { int d = c - 'a'; sm[i+1] = sm[i]; sm[i+1] ^= (1 << d); } int[] dp = new int[1<<26]; dp[] = 10^^9; dp[sm[n]] = 0; foreach_reverse (i; 1..n) { int f = sm[i]; foreach (j; 0..26) { int g = f ^ (1<<j); dp[f] = min(dp[f], 1+dp[g]); } } int ans = 1+dp[0]; foreach (j; 0..26) { ans = min(ans, 1 + dp[1<<j]); } writeln(ans); return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ 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); } } } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; // import dcomp.array; 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 succW() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (!line.empty && line.front.isWhite) { line.popFront; } return !line.empty; } 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; line = lineBuf[]; f.readln(line); if (!line.length) return false; } 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 static if (isStaticArray!T) { foreach (i; 0..T.length) { bool f = succW(); assert(f); x[i] = line.parse!E; } } else { FastAppender!(E[]) buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } 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); } } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */ // module dcomp.array; T[N] fixed(T, size_t N)(T[N] a) {return a;} struct FastAppender(A, size_t MIN = 4) { import std.algorithm : max; import std.conv; import std.range.primitives : ElementEncodingType; import core.stdc.string : memcpy; private alias T = ElementEncodingType!A; private T* _data; private uint len, cap; @property size_t length() const {return len;} bool empty() const { return len == 0; } void reserve(size_t nlen) { import core.memory : GC; if (nlen <= cap) return; void* nx = GC.malloc(nlen * T.sizeof); cap = nlen.to!uint; if (len) memcpy(nx, _data, len * T.sizeof); _data = cast(T*)(nx); } void free() { import core.memory : GC; GC.free(_data); } void opOpAssign(string op : "~")(T item) { if (len == cap) { reserve(max(MIN, cap*2)); } _data[len++] = item; } void insertBack(T item) { this ~= item; } void removeBack() { len--; } void clear() { len = 0; } ref inout(T) back() inout { assert(len); return _data[len-1]; } ref inout(T) opIndex(size_t i) inout { return _data[i]; } T[] data() { return (_data) ? _data[0..len] : null; } } /* This source code generated by dcomp and include dcomp's source code. dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp) dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt) */
D
import std.stdio; import std.string; import std.conv; import std.math; int main() { auto digit = 0; string buf; while ((buf = strip(readln())) != null) { digit = calc_digit(buf); writeln(calc_digit(buf)); } return 0; } int calc_digit(string src) { string[] seed = split(src); int sum = to!(uint)(seed[0]) + to!(uint)(seed[1]); uint digit = 0; while (pow(10, digit) <= sum) { digit += 1; } return digit; }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto X = readln.split[0].to!(long); foreach (A; 0 .. 10^^3+1) foreach (B; 0 .. A) { if (A^^5 - B^^5 == X) { writeln (A, " ", B); return; } if (A^^5 + B^^5 == X) { writeln (A, " ", -B); return; } } assert(0); }
D
import std.stdio; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; import std.typecons; import std.regex; import std.range; void main(){ string[6] ans; for(int i=1;i<=6;i++) ans[i-1] = to!char(i + '0') ~ ":"; int n = readln().chomp().to!int; for(int i=0;i<n;i++){ double h = readln().chomp().to!double; if(h < 165.0) ans[0] ~= '*'; else if(h < 170.0) ans[1] ~= '*'; else if(h < 175.0) ans[2] ~= '*'; else if(h < 180.0) ans[3] ~= '*'; else if(h < 185.0) ans[4] ~= '*'; else ans[5] ~= '*'; } foreach(i ; ans) writeln(i); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto ab = readln.split.to!(int[]); int s, i = 1; while (i <= ab[1] - ab[0]) { s += i; ++i; } writeln(s - ab[1]); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split, a = rd[0], b = rd[1]; writeln(a == b ? "H" : "D"); }
D
import std.stdio; import std.string; import std.conv; import std.array; import std.range; void main(){ auto a=readln.chomp; auto b=readln.chomp; auto c=readln.chomp; writeln("" ~ a[0] ~ b[1] ~ c[2]); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, m; rd(n, m); writeln((m*1900+(n-m)*100)*(1<<m)); } 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
/+ dub.sdl: name "D" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; long isq(long x) { long l = 0, r = 10L^^10; while (r-l > 1) { long md = (l+r)/2; if (md*(md-1) < x) l = md; else r = md; } return l; } long solve(long a, long b) { if (a > b) swap(a, b); if (a == 1 && b == 1) return 0; long ans = 2*(a-1); long up = min(a*b / (a+1), isq(a*b)); ans += (up-a+1); long lup = (a*b-1) / up; ans += lup - a - 1; return ans; } int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int q; sc.read(q); foreach (i; 0..q) { long a, b; sc.read(a, b); writeln(solve(a, b)); } return 0; } /* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */ // module dkh.container.stackpayload; struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) { import core.exception : RangeError; private T* _data; private uint len, cap; @property bool empty() const { return len == 0; } @property size_t length() const { return len; } alias opDollar = length; inout(T)[] data() inout { return (_data) ? _data[0..len] : null; } ref inout(T) opIndex(size_t i) inout { version(assert) if (len <= i) throw new RangeError(); return _data[i]; } ref inout(T) front() inout { return this[0]; } ref inout(T) back() inout { return this[$-1]; } void reserve(size_t newCap) { import core.memory : GC; import core.stdc.string : memcpy; import std.conv : to; if (newCap <= cap) return; void* newData = GC.malloc(newCap * T.sizeof); cap = newCap.to!uint; if (len) memcpy(newData, _data, len * T.sizeof); _data = cast(T*)(newData); } void free() { import core.memory : GC; GC.free(_data); } void clear() { len = 0; } void insertBack(T item) { import std.algorithm : max; if (len == cap) reserve(max(cap * 2, MINCAP)); _data[len++] = item; } alias opOpAssign(string op : "~") = insertBack; void removeBack() { assert(!empty, "StackPayload.removeBack: Stack is empty"); len--; } } /* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */ // module dkh.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ 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); } } } } /* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */ // module dkh.scanner; // import dkh.container.stackpayload; 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 succW() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (!line.empty && line.front.isWhite) { line.popFront; } return !line.empty; } 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; line = lineBuf[]; f.readln(line); if (!line.length) return false; } 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 static if (isStaticArray!T) { foreach (i; 0..T.length) { bool f = succW(); assert(f); x[i] = line.parse!E; } } else { StackPayload!E buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } else { x = line.parse!T; } return true; } int unsafeRead(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); } } void read(Args...)(auto ref Args args) { import std.exception; static if (args.length != 0) { enforce(readSingle(args[0])); read(args[1..$]); } } bool hasNext() { return succ(); } } /* This source code generated by dunkelheit and include dunkelheit's source code. dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit) dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt) */
D
import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; long solve (long [] a) { long a0 = min (a[0], 2); a[0] -= a0; long a3 = min (a[3], 2); a[3] -= a3; long a4 = min (a[4], 2); a[4] -= a4; long res = 0; res += a[1]; a[1] = 0; res += (a[0] / 2) * 2; a[0] %= 2; res += (a[3] / 2) * 2; a[3] %= 2; res += (a[4] / 2) * 2; a[4] %= 2; long add = 0; add = max (add, ((a0 + a[0]) / 2) * 2 + ((a3 + a[3]) / 2) * 2 + ((a4 + a[4]) / 2) * 2); if (a0 > 0 && a3 > 0 && a4 > 0) { add = max (add, 3 + ((a0 + a[0] - 1) / 2) * 2 + ((a3 + a[3] - 1) / 2) * 2 + ((a4 + a[4] - 1) / 2) * 2); } if (a0 > 1 && a3 > 1 && a4 > 1) { add = max (add, 6 + ((a0 + a[0] - 2) / 2) * 2 + ((a3 + a[3] - 2) / 2) * 2 + ((a4 + a[4] - 2) / 2) * 2); } return res + add; } void main () { long [] a; while ((a = readln.split.map !(to !(long)).array).length > 0) { writeln (solve (a)); } }
D
import std.stdio; import std.algorithm; import std.math; import core.stdc.stdio; int[int] compCoord(ref int[] data){ data.sort; int[int] ret; int c=0; foreach(i,d;data){ if((d in ret) is null){ ret[d] = c; data[c++] = d; } } data = data[0..c]; return ret; } void main(){ while(1){ int w,h; scanf("%d%d",&w,&h); if(h==0&&w==0) break; int n; scanf("%d",&n); int size=n*2+2; int[] xs = new int[size]; int[] ys = new int[size]; struct rect{ int x1; int y1; int x2; int y2; } rect[] rs = new rect[n]; for(int i=0;i<n;i++){ scanf("%d%d%d%d",&rs[i].x1,&rs[i].y1,&rs[i].x2,&rs[i].y2); xs[i*2] = rs[i].x1; xs[i*2+1] = rs[i].x2; ys[i*2] = rs[i].y1; ys[i*2+1] = rs[i].y2; } xs[n*2] = 0; xs[n*2+1] = w; ys[n*2] = 0; ys[n*2+1] = h; int[int] xc = xs.compCoord; int[int] yc = ys.compCoord; int[] imos = new int[xs.length*ys.length]; foreach(r;rs){ int cx1 = xc[r.x1]; int cy1 = yc[r.y1]; int cx2 = xc[r.x2]; int cy2 = yc[r.y2]; imos[cy1*xs.length+cx1]++; imos[cy1*xs.length+cx2]--; imos[cy2*xs.length+cx1]--; imos[cy2*xs.length+cx2]++; } for(int i=0;i<ys.length;i++){ int last=0; for(int j=0;j<xs.length;j++){ imos[i*xs.length+j]+=last; last = imos[i*xs.length+j]; } } for(int i=0;i<xs.length;i++){ int last=0; for(int j=0;j<ys.length;j++){ imos[i+j*xs.length]+=last; last = imos[i+j*xs.length]; } } int ans=0; bool[] visited = new bool[xs.length*ys.length]; int[] dx = [0,-1,0,1]; int[] dy = [-1,0,1,0]; int[2][] queue = new int[2][xs.length*ys.length]; int BFS(int y,int x){ if(visited[y*xs.length+x] || imos[y*xs.length+x] != 0) return 0; int qc=0; queue[qc++] = [y,x]; visited[y*xs.length+x]=true; for(int i=0;i<qc;i++){ int py = queue[i][0]; int px = queue[i][1]; for(int k=0;k<4;k++){ int ny = py+dy[k]; int nx = px+dx[k]; if(0<=ny&&ny<ys.length&&ys[ny]<h&&0<=nx&&nx<xs.length&&xs[nx]<w){ if(!visited[ny*xs.length+nx] && imos[ny*xs.length+nx] == 0){ queue[qc++] = [ny,nx]; visited[ny*xs.length+nx]=true; } } } } return 1; } for(int i=0;ys[i]<h;i++){ for(int j=0;xs[j]<w;j++){ ans += BFS(i,j); } } printf("%d\n",ans); } }
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; void main() { auto S = readln.chomp; auto T = readln.split.array; foreach (t; T) { if (S[0] == t[0] || S[1] == t[1]) { writeln("YES"); return; } } writeln("NO"); }
D
import std.stdio; void main(){ for(int i = 0; i < 1000; i++) writeln("Hello World"); }
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((scanElem*100+scanElem*10+scanElem)%4==0)end("YES");end("NO"); }
D
void main() { int n = readln.chomp.to!int; int[] h = readln.split.to!(int[]); int hs = h[0]; int cnt = 1; foreach (i; 1 .. n) { if (h[i] >= hs) { ++cnt; hs = h[i]; } } cnt.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
import std.stdio; void main() { string input = readln(); int count; foreach(char c; input) { if(c == '1') count++; } writeln(count); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; void main(){ auto a=readln.chomp; writeln("ABC",a); }
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 readM(T)(size_t r,size_t c,ref T[][]t){t=new T[][](r);foreach(ref v;t)readA(c,v);} void main() { int n, c; readV(n, c); int[][] d; readM(c, c, d); int[][] a; readM(n, n, a); foreach (i; 0..n) a[i][] -= 1; auto b = new int[][](3, c); foreach (i; 0..n) foreach (j; 0..n) ++b[(i+j)%3][a[i][j]]; auto calc(int[] b, int t) { auto r = 0; foreach (i; 0..c) r += b[i]*d[i][t]; return r; } auto r = 10^^9; foreach (c0; 0..c) foreach (c1; 0..c) foreach (c2; 0..c) { if (c0 == c1 || c0 == c2 || c1 == c2) continue; r = min(r, calc(b[0], c0)+calc(b[1], c1)+calc(b[2], c2)); } writeln(r); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto n = lread(); auto d = aryread(); auto m = lread(); auto t = aryread(); long[long] dd; foreach (i; 0 .. n) { dd[d[i]] = dd.get(d[i], 0) + 1; } // writeln(dd); long[long] tt; foreach (i; 0 .. m) { tt[t[i]] = tt.get(t[i], 0) + 1; } // writeln(tt); foreach (key, value; tt) { if (key in dd) { if (dd[key] < value) { writeln("NO"); return; } } else { writeln("NO"); return; } } writeln("YES"); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
void main() { long n = rdElem; if (n == 1) { 0.writeln; return; } long[long] cnt; for (long i = 2; i * i <= n; ++i) { while (!(n % i)) { ++cnt[i]; n /= i; } } if (n > 1) ++cnt[n]; long m = cnt.byValue.reduce!max; long[] list; list ~= 1; foreach (i; 2 .. m+1) { list ~= list[$-1] + i; if (list[$-1] > m) break; } long result; foreach (x; cnt.byValue) { long num; foreach (y; list) { if (x >= y) ++num; } result += num; } result.writeln; } enum long mod = 10L^^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, std.conv, std.string; void main() { (readln.chomp.to!int < 1200 ? "ABC" : "ARC").writeln; }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { auto w = sread(); // writeln(w); long[char] ary; foreach (i; 0 .. (w.length)) { ary[w[i]] = ary.get(w[i], 0) + 1; } // writeln(ary); foreach (value; ary) { // writeln(value); if (value % 2 == 0) { continue; } else { writeln("No"); return; } } writeln("Yes"); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "begin", long, "end"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long n, m; scan(n, m); if(n < m) swap(n, m); foreach (_; iota(n)) { write(m); } writeln(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
/+ dub.sdl: name "A" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); string s; sc.read(s); int n = s.length.to!int; int ans = 0; int sm = 0; foreach (int i, c; s) { sm += c - '0'; if (c != '0') ans = max(ans, sm - 1 + (n-1-i)*9); } ans = max(ans, sm); writeln(ans); return 0; } /* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */ // module dkh.container.stackpayload; struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) { import core.exception : RangeError; private T* _data; private uint len, cap; @property bool empty() const { return len == 0; } @property size_t length() const { return len; } alias opDollar = length; inout(T)[] data() inout { return (_data) ? _data[0..len] : null; } ref inout(T) opIndex(size_t i) inout { version(assert) if (len <= i) throw new RangeError(); return _data[i]; } ref inout(T) front() inout { return this[0]; } ref inout(T) back() inout { return this[$-1]; } void reserve(size_t newCap) { import core.memory : GC; import core.stdc.string : memcpy; import std.conv : to; if (newCap <= cap) return; void* newData = GC.malloc(newCap * T.sizeof); cap = newCap.to!uint; if (len) memcpy(newData, _data, len * T.sizeof); _data = cast(T*)(newData); } void free() { import core.memory : GC; GC.free(_data); } void clear() { len = 0; } void insertBack(T item) { import std.algorithm : max; if (len == cap) reserve(max(cap * 2, MINCAP)); _data[len++] = item; } alias opOpAssign(string op : "~") = insertBack; void removeBack() { assert(!empty, "StackPayload.removeBack: Stack is empty"); len--; } } /* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/foundation.d */ // module dkh.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ 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); } } } } /* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/scanner.d */ // module dkh.scanner; // import dkh.container.stackpayload; 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 succW() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (!line.empty && line.front.isWhite) { line.popFront; } return !line.empty; } 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; line = lineBuf[]; f.readln(line); if (!line.length) return false; } 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 static if (isStaticArray!T) { foreach (i; 0..T.length) { bool f = succW(); assert(f); x[i] = line.parse!E; } } else { StackPayload!E buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } else { x = line.parse!T; } return true; } int unsafeRead(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); } } void read(Args...)(auto ref Args args) { import std.exception; static if (args.length != 0) { enforce(readSingle(args[0])); read(args[1..$]); } } bool hasNext() { return succ(); } } /* This source code generated by dunkelheit and include dunkelheit's source code. dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit) dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt) */
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container; int n; void solve(int max_i, string prefix) { if(prefix.length == n) { writeln(prefix); return; } for(int i=0; i<max_i+1; i++) solve(max(i+1, max_i), prefix~('a'+i).to!char); } void main() { n = readln.chomp.to!int; solve(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; } 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 = 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 main() { auto n = RD!int; auto ans = new long[](n); int cnt; foreach (i; 0..n) { auto a = RD!int; if (a % 2 == 0) ans[i] = a/2; else if (cnt == 0) { ans[i] = a/2; if (a < 0) --ans[i]; ++cnt; } else { ans[i] = a/2; if (a > 0) ++ans[i]; --cnt; } } foreach (e; ans) writeln(e); stdout.flush(); debug readln(); }
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.split.map!(to!long).array; auto B = new long[](N+1); foreach (i; 0..N) B[i+1] = B[i] + A[i]; long[long] cnt; long ans = 0; foreach_reverse(i; 0..N) { long x = B[i]; cnt[B[i+1]] += 1; if (x in cnt) ans += cnt[x]; } 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; // dfmt on void main() { long N = lread(); writeln((N - 2) * 180); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto A = RD; auto B = RD; auto C = RD; auto D = RD; writeln(max(A*B, C*D)); stdout.flush(); debug readln(); }
D
import std.stdio; void main(){ auto cin = new Cin(); auto S = cin.rect!(char[],"")()[0]; //writeln(S); char[] c; foreach( s ; S ){ switch( s ){ case "0": c ~= "0"; break; case "1": c ~= "1"; break; case "B": c.length = 0<c.length ? c.length-1 : 0 ; break; default:break; } } (c).writeln(); } auto solve(){ } unittest{ } import std.stdio,std.conv,std.string; import std.algorithm,std.array; class Cin { T[] line( T = size_t , string token = " " )( size_t m = 1 ){ T[] arr = []; foreach( i ; 0..m ){ arr ~= this.read!T(); } return arr; } T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){ T[][] arr = new T[][](m); foreach( i ; 0..m ){ arr[i] = this.read!T(token); } return arr; } private T[] read( T = size_t )( string token = " " ){ T[] arr; foreach( elm ; readln().chomp().split(token) ){ arr ~= elm.to!T(); } return arr; } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto N = readln.chomp.to!int; auto G = new int[][](N); foreach (i; 0..N-1) { auto s = readln.split.map!(to!int); G[s[0]] ~= s[1]; G[s[1]] ~= s[0]; } int root = -1; foreach (i; 0..N) if (G[i].length >= 3) root = i; if (root == -1) { writeln(1); return; } int dfs(int n, int p) { int ret = 0; int cnt = 0; int children = G[n].length.to!int - (p != -1); foreach (m; G[n]) { if (m == p) continue; int v = dfs(m, n); ret += v; cnt += v > 0; } if (cnt < children - 1) ret += children - 1 - cnt; return ret; } dfs(root, -1).writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } 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 lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto K = RD; writeln(N - K + 1); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional; void main() { readln.split.to!(long[]).pipe!(tmp => max(tmp[0] - tmp[1], 0)).writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; void main(){ auto A=readln.split.to!(int[]),a=A[0],b=A[1],c=A[2]; if(a+b>=c)writeln("Yes"); else writeln("No"); }
D
void main(){ long x, a, b; scanf("%ld %ld %ld", &x, &a, &b); if(abs(x-a)>abs(x-b))writeln("B"); else writeln("A"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.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 xy = readints; int x = xy[0], y = xy[1]; writeln(x + y / 2); }
D
void main() { auto s = rs; auto p = rs; writeln((s ~ s).canFind(p) ? "Yes" : "No"); } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; import std.math; import std.container; import std.bigint; import std.numeric; import std.conv; import std.typecons; import std.uni; import std.ascii; import std.bitmanip; import core.bitop; T readAs(T)() if (isBasicType!T) { return readln.chomp.to!T; } T readAs(T)() if (isArray!T) { return readln.split.to!T; } T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { auto s = rs; foreach(j; 0..width) res[i][j] = s[j].to!T; } return res; } int ri() { return readAs!int; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); foreach (i, c; S) { if (i%2 == 0) { if (c == 'L') { writeln("No"); return; } } else { if (c == 'R') { writeln("No"); return; } } } writeln("Yes"); }
D
void main(){ int k,a,b; k = _scan(); scanf("%d %d", &a, &b); if( a<= b/k*k ) writeln("OK"); else writeln("NG"); } 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
/* 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 1905 ---+/ /+---test 0112 ---+/ /+---test 1700 ---+/ void main(string[] args) { const S = readln.chomp; const l = S[0..2].to!int; const r = S[2..4].to!int; const yymm = 1 <= r && r <= 12; const mmyy = 1 <= l && l <= 12; if (yymm && !mmyy) { "YYMM".writeln; } else if (!yymm && mmyy) { "MMYY".writeln; } else if (yymm && mmyy) { "AMBIGUOUS".writeln; } else { "NA".writeln; } }
D
import std.stdio; import std.algorithm; import std.range; import std.array; import std.string; void main(){ auto num_str = readln.chop; auto check_tri = (string target){ return target[0] == target[1] && target[1] == target[2]; }; auto answer = check_tri(num_str[0..3]) || check_tri(num_str[1..4]) ? "Yes" : "No"; writeln(answer); }
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { auto S = sread(); auto T = sread(); auto b = new long[][](26); foreach (i, c; S) b[c - 'a'] ~= i; foreach (c; T) if (b[c - 'a'].empty) { writeln(-1); return; } long ptr; long ans; foreach (j, c; T) { long k = () { long ok = 0; long ng = b[c - 'a'].length; while (1 < ng - ok) { long m = (ok + ng) / 2; if (b[c - 'a'][m] <= ptr) ok = m; else ng = m; } return ok; }(); long m = long.max; foreach (i; [ b[c - 'a'][k], b[c - 'a'][(k + 1) % $], b[c - 'a'][($ + k - 1) % $] ]) { if (ptr == i) m = m.min((j != 0 && T[j - 1] == c) ? S.length : 0); if (ptr < i) m = m.min(i - ptr); if (i < ptr) m = m.min(S.length + i - ptr); } ptr += m; ptr %= S.length; ans += m; } writeln(ans + 1); }
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 c = new int[](10^^5+1); foreach (ai; a) c[ai]++; auto c1 = 0, c2 = 0; foreach (ci; c) if (ci%2 == 1) ++c1; else if (ci > 0) ++c2; writeln(c1+c2-c2%2); }
D
void main() { string s = readln.chomp; writeln(s[0..4], " ", s[4..$]); } 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.range; import std.string; import std.algorithm; import std.conv; void main() { writeln(readln.find("A").retro.find("Z").source.length); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto ps = readln.split.to!(int[]); int d; foreach (i, p; ps) { if (i.to!int+1 != p) ++d; } writeln(d <= 2 ? "YES" : "NO"); }
D
import std.stdio; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; import std.typecons; import std.regex; import std.range; void main(){ string list = "abcdefghijklmnopqrstuvwxyz.?! "; while(true){ string s = readln(); if(stdin.eof()) break; s = s.chomp(); if(s.length % 2 == 1){ writeln("NA"); continue; } string ans = ""; for(int i=0;i<s.length/2;i++){ int c = to!int(s[2*i]-'0') - 1; int r = to!int(s[2*i+1]-'0') - 1; if(5<c || 4<r || c < 0 || r < 0){ ans = "NA"; break; } ans ~= list[5*c + r]; } writeln(ans); } }
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; /* A = 1, B = 2, C = 100, D = 100みたいなケースもある */ void main() { int t; scan(t); while (t--) { long ai, bi, ci, di; scan(ai, bi, ci, di); writeln(solve(ai, bi, ci, di)); } } string solve(long a, long b, long c, long d) { if (a < b) { return "No"; } if (b > c) { if (b == c + 1) { if (d >= b) { return "Yes"; } else { return "No"; } } if ((a % b) > c) { return "No"; } else { long g = gcd(b, d); if (d >= b && (c + 1 + g - 1) / g * g >= b) { return "Yes"; } else { return "No"; } } } else { if (b == 1) { return "Yes"; } if (d >= c) { return "Yes"; } else { if (b <= d) { return "Yes"; } else { return "No"; } } } } 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.string, std.conv, std.algorithm; void main() { foreach(_; 0..readln.chomp.to!int) { readln; int up, down; auto inp=readln.split.map!(to!int); for(int i; i < inp.length-1; ++i) { up=max(inp[i+1]-inp[i],up); down=min(inp[i+1]-inp[i],down); } writeln(up, " ", -down); } }
D
import std.stdio; import std.conv; import std.string; void main() { int R, G; R = readln().chomp().to!(int); G = readln().chomp().to!(int); writeln(R+(G-R)*2); }
D
import std.stdio, std.string, std.conv, std.range, std.algorithm; void main() { auto abc = readln.chomp.split.map!(to!int); if (count(abc, 5) == 2 && count(abc, 7) == 1) { "YES".writeln; } else { "NO".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);}} alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { long N = lread(); auto S = sread(); auto R = new long[](N + 1); auto W = new long[](N + 1); foreach (i; 0 .. N) { R[i + 1] = R[i] + (S[i] == 'R'); W[i + 1] = W[i] + (S[i] == 'W'); } long ans = long.max; foreach (i; 0 .. N + 1) { long r = R[$ - 1] - R[i]; long w = W[i]; long a = min(r, w) + abs(r - w); ans = ans.min(a); } writeln(ans); }
D
import std.stdio, std.string, std.conv, std.range, std.algorithm; void main() { iota(2, readln.chomp.to!long+1).reduce!"a*b".writeln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!int; auto k = readln.chomp.to!int; auto x = readln.chomp.to!int; auto y = readln.chomp.to!int; if (n < k) writeln(x * n); else writeln(x * k + y * (n - k)); }
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 n = readint; int a = readint; writeln(n * n - a); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.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; auto T = RD!string; bool ans; foreach (i; 0..S.length) { bool ok = true; foreach (j; 0..T.length) { if (S[(i+j)%S.length] != T[j]) { ok = false; break; } } if (ok) { ans = ok; break; } } writeln(ans ? "Yes" : "No"); stdout.flush(); debug readln(); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias SugarWater = Tuple!(long, "swater", long, "sugar"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long n = lread(), ans; if(n >= 0) ans += min(10 - 1, n - 1 + 1); if(n >= 100) ans += min(1000 - 100, n - 100 + 1); if(n >= 10_000) ans += min(100_000 - 10_000, n - 10_000 + 1); ans.writeln(); }
D
import std.stdio; int main(){ for(int i=1;i<10;i++)for(int j=1;j<10;j++)printf("%dx%d=%d\n",i,j,i*j); return 0; }
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() { string s, t; scan(s); scan(t); iota(3).map!(i => s[i] == t[i]).sum().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
import std.stdio, std.string, std.conv; long [100] L; long foo(int n) { if(L[n]==0) { L[n]= foo(n-1) + foo(n-2); } return L[n]; } void main() { int N = readln().chomp().to!(int); L[0]=2;L[1]=1; writeln(foo(N)); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { int n = readln.chomp.to!int; int price = 0; int[][] apList; for (int i = 0; i < n; i++) { auto ap = readln.chomp.split.map!(to!int); int a = ap[0]; int p = ap[1]; apList ~= [a, p]; } for (int i = 1; i < n; i++) { if (apList[i - 1][1] < apList[i][1]) { apList[i][1] = apList[i - 1][1]; } } int answer = 0; foreach (e; apList) { answer += e[0] * e[1]; } writeln(answer); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; long n, m; rd(n); rd(m); auto k=2L, p=1L; while(k<=m) k*=2, p++; if(p<=n){writeln(m); return;} auto npow2=1L; while(n--) npow2*=2; writeln(m%npow2); } 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)); } } void wr(T...)(T x){ import std.stdio; foreach(e; x) write(e, " "); 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(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new bool[](t); foreach (ti; 0..t) { auto n = RD!int; auto a = RD!int-1; auto b = RD!int-1; auto da = RD!int; auto db = RD!int; auto edges = new int[][](n); foreach (i; 0..n-1) { auto u = RD!int-1; auto v = RD!int-1; edges[u] ~= v; edges[v] ~= u; } if (db <= da*2) { ans[ti] = true; continue; } bool dfs1(int pos, int last, int depth) { if (pos == b) return true; if (depth == da) return false; foreach (v; edges[pos]) { if (v == last) continue; auto res = dfs1(v, pos, depth+1); if (res) return true; } return false; } auto otk = dfs1(a, -1, 0); if (otk) { ans[ti] = true; continue; } int[] dfs2(int pos, int last, int depth) { int[] res = [depth, pos]; foreach (v; edges[pos]) { if (v == last) continue; auto r = dfs2(v, pos, depth+1); if (r[0] > res[0]) { res = r; } } return res; } auto r = dfs2(0, -1, 0); auto r2 = dfs2(r[1], -1, 0); ans[ti] = r2[0] <= da*2; } foreach (e; ans) writeln(e ? "Alice" : "Bob"); stdout.flush; debug readln; }
D