code
stringlengths
4
1.01M
language
stringclasses
2 values
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 x = n % 2 == 0 ? n : n * 2; writeln(x); }
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 3 2 1 2 ---+/ /+---test 3 2 2 2 ---+/ /+---test 10 3 1 4 1 5 9 2 6 5 3 ---+/ /+---test 1 1 ---+/ void main(string[] args) { const N = readln.chomp.to!long; const A = readln.split.map!(to!long).array; long next_expect = 1; long ans; foreach (a; A) { if (a == next_expect) { ++next_expect; } else { ++ans; } } (next_expect == 1? -1: ans).writeln; }
D
import std.stdio; void main() { int n = 0; scanf("%d", &n); writeln(n^^3); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto as = readln.chomp.split.map!(to!int); int res = 1; foreach (a; as) { if (a % 2 == 0) { res *= 2; } } writeln(3^^n - res); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a, b, c; scan(a, b, c); writeln(a <= c && c <= b ? "Yes" : "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.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto memo = new int[](51); foreach (i; 0..10) foreach (j; 0..10) ++memo[i + j]; string line; while ((line = readln) !is null) { auto n = line.chomp.to!int; auto r = 0; foreach (i; 0..n+1) r += memo[i] * memo[n - i]; writeln(r); } }
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, "l ", long, "r"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long a, b, c; scan(a, b, c); auto check = new bool[](b); long i = 1; while (!check[a * i % b]) { check[a * i % b] = true; i++; } if (check[c]) 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
/+ 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); long a, b, c; sc.read(a, b, c); int co = 0; while (co < 10^^7) { if (a%2 || b%2 || c%2) break; co++; long na = (b+c)/2; long nb = (a+c)/2; long nc = (a+b)/2; a = na; b = nb; c = nc; } if (co == 10^^7) co = -1; writeln(co); 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) { 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
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 s, w; scan(s, w); auto safe = s > w; yes(safe, "safe", "unsafe"); } void scan(T...)(ref T args) { auto line = readln.split; // @suppress(dscanner.suspicious.unmodified) 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.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ auto a = read.to!long; auto b = read.to!long; auto c = read.to!long; auto d = read.to!long; bool[] xs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; xs[a] = 1; xs[b] = 1; xs[c] = 1; xs[d] = 1; if(xs[1] + xs[9] + xs[7] + xs[4] == 4) "YES".writeln; else "NO".writeln; }
D
import std; auto input() { return readln().chomp(); } alias sread = () => readln.chomp(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { string s; s = input(); foreach (_; 0 .. s.length) { write('x'); } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void main() { writeln(readln.chomp.to!int >= 30 ? "Yes" : "No"); }
D
import std.stdio,std.string,std.conv; int main() { string s = readln.chomp; char[] ans; ans.length = s.length; foreach(i;0..s.length) { if(s[i] == 'a' && s[i+1] == 'p' &&s[i+2] == 'p' && s[i+3] == 'l' && s[i+4] == 'e') { ans[i] = 'p'; ans[i+1] = 'e'; ans[i+2] = 'a'; ans[i+3] = 'c'; ans[i+4] = 'h'; i += 4; } else if(s[i] == 'p' && s[i+1] == 'e' &&s[i+2] == 'a' && s[i+3] == 'c' && s[i+4] == 'h') { ans[i] = 'a'; ans[i+1] = 'p'; ans[i+2] = 'p'; ans[i+3] = 'l'; ans[i+4] = 'e'; i += 4; } else ans[i] = s[i]; } ans.writeln; return 0; }
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 K; scan(K); long ans; foreach (i ; 1 .. K + 1) { foreach (j ; 1 .. K + 1) { foreach (k ; 1 .. K + 1) { ans += gcd(gcd(i, j), k); } } } 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 core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { auto s = sread(); foreach (i, c; s) if (~i & 1) { write(c); } writeln(); }
D
import std.stdio, std.string, std.conv; void main() { while (true) { string str = readln.chomp; if (str == "0") break; int sum = 0; foreach (x; str) { sum += x - '0'; } sum.writeln; } }
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) { auto N = readln.chomp.to!long; long x = 1; foreach (k; 1..34) { x += 1L<<k; if (N%x == 0) { writeln(N/x); break; } } } }
D
void main(){ int n = inelm(); (n/3).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional; void main() { readln.split.to!(int[]).pipe!(a => a[0] - a[1] + 1).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; enum MAX = 1_000_100; ulong MOD = 1_000_000_007; ulong INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias Pass = Tuple!(long, "x", long, "y"); void main() { long a, b, c; scan(a, b, c); if (a + b + c < 22) writeln("win"); else writeln("bust"); } 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; } }
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 ab = readints; int a = ab[0], b = ab[1]; int x = cast(int)(ceil((a + b) / 2.0)); writeln(x); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto S = readln.chomp.to!(wchar[]); auto K = readln.chomp; int il; for (int i; i < S.length; ++i) { if (S[i] == '1') { ++il; } else break; } if (il == S.length) { writeln(1); return; } else if (!il) { writeln(S[0]); return; } auto n = S[il]; if (K.length > 3 || K.to!int > il) { writeln(n); } else { writeln("1"); } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { auto s = sread(); long a = s.filter!(c => c == '+').count(); long b = s.filter!(c => c == '-').count(); writeln(a - b); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.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; auto Z = RD; writeln((X-Z) / (Y+Z)); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; int[] dist, prev; void main() { int a, b; scan(a, b); auto ans = a < 10 && b < 10 ? a * b : -1; writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new string[](t); foreach (ti; 0..t) { auto s = RD!string; foreach (i; 0..s.length) { if (i % 2 == 0) { if (s[i] == 'a') ans[ti] ~= 'b'; else ans[ti] ~= 'a'; } else { if (s[i] == 'z') ans[ti] ~= 'y'; else ans[ti] ~= 'z'; } } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.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; 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 cnt; foreach (c; S) { if (c == 'x') ++cnt; } writeln(cnt >= 8 ? "NO" : "YES"); stdout.flush(); debug readln(); }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.uni; void main() { int[dchar] b; for (dchar c = 'a'; c <= 'z'; c++) b[c] = 0; while (!stdin.eof) { auto a = readln.strip; foreach (i; a) { if (i.isAlpha) b[i.toLower] += 1; } } for (dchar c = 'a'; c <= 'z'; c++) writeln(c, " : ", b[c]); }
D
import std.stdio,std.string,std.conv,std.algorithm,std.array; void main() { bool[501][501] M; while(true) { int n, m; string line=readln.chomp; try{n=line.to!int;}catch(Exception e){ throw new Exception(line);} try{m=readln.chomp.to!int;}catch(Exception e){ throw new Exception("m");} if(n==0&&m==0)break; foreach(unused;0..m) { int[] input; try{input=readln.split.map!(to!int).array;}catch(Exception e){ throw new Exception("list");} M[input[0]][input[1]]=true; M[input[1]][input[0]]=true; } int[int] num; foreach(i; 1..n+1) { if(M[1][i]) { num[i]=0; foreach(j; 2..n+1) { if(M[i][j]) { num[j]=0; } } } } writeln(num.length); foreach(i; 1..n+1) foreach(j; 1..n+1) M[i][j]=false; } }
D
import core.bitop; import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.random; import std.range; import std.stdio; import std.string; import std.typecons; int n; int[] a; int[][][] memo; bool[][] done; int[] dfs(int turn, int index, int z, int w) { if (index == n) { return [z, w]; } if (done[turn][index]) { return memo[turn][index]; } int ans = turn == 0 ? int.min : int.max; int[] ret; for (int i = index; i < n; ++i) { if (turn == 0) { auto sub = dfs(1, i + 1, a[i], w); if (ans < abs(sub.front - sub.back)) { ans = abs(sub.front - sub.back); ret = sub; } } else { auto sub = dfs(0, i + 1, z, a[i]); if (ans > abs(sub.front - sub.back)) { ans = abs(sub.front - sub.back); ret = sub; } } } done[turn][index] = true; memo[turn][index] = ret; return ret; } void main() { auto nzw = readln.chomp.split.map!(to!int); n = nzw[0]; int z = nzw[1]; int w = nzw[2]; a = readln.chomp.split.map!(to!int).array; memo = new int[][][](2, n); done = new bool[][](2, n); auto ret = dfs(0, 0, z, w); writeln = abs(ret.front - ret.back); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto n = readln.chomp.to!int; auto res = int.max; foreach (a; 1..n) { auto b = n - a; int sum; while (a) { sum += a % 10; a /= 10; } while (b) { sum += b % 10; b /= 10; } res = min(sum, res); } res.writeln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long N = lread(); writeln((1 + N) * N / 2); }
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!int; auto W = readln.chomp.to!int; auto N = readln.chomp.to!int; writeln((N + max(H, W) - 1) / max(H, W)); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { auto r = lread(); if(r < 1200) { writeln("ABC"); } else if(r < 2800) { writeln("ARC"); } else { writeln("AGC"); } }
D
import std.stdio, std.string, std.conv, std.ascii; void main() { auto d = stdin.readln.dup; foreach (c; d) { if (c.isLower) c -= 32; else if (c.isUpper) c+= 32; c.write; } }
D
void main() { string s = rdStr; long len = s.length; foreach (i; 0 .. len-1) { if (s[i] == s[i+1]) { writeln(i + 1, " ", i + 2); return; } if (i == len - 2) break; if (s[i] == s[i+2]) { writeln(i + 1, " ", i + 3); return; } } writeln(-1, " ", -1); } T rdElem(T = long)() { //import std.stdio : readln; //import std.string : chomp; //import std.conv : to; return readln.chomp.to!T; } alias rdStr = rdElem!string; dchar[] rdDchar() { //import std.conv : to; return rdStr.to!(dchar[]); } T[] rdRow(T = long)() { //import std.stdio : readln; //import std.array : split; //import std.conv : to; return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { //import std.range : iota; //import std.algorithm : map; //import std.array : array; return iota(col).map!(x => rdElem).array; } T[][] rdMat(T = long)(long col) { //import std.range : iota; //import std.algorithm : map; //import std.array : array; return iota(col).map!(x => rdRow).array; } void wrMat(T = long)(T[][] mat) { //import std.stdio : write, writeln; 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.container; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.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 H = RD; auto W = RD; auto a = new string[](H); foreach (y; 0..H) { a[y] = "#" ~ RD!string ~ "#"; } foreach (i; 0..W+2) write("#"); writeln(); foreach (y; 0..H) { writeln(a[y]); } foreach (i; 0..W+2) write("#"); writeln(); stdout.flush(); debug readln(); }
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 inf3 = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int n; scan(n); auto s = readln.chomp; // dp(i, j) = (i番目までを{0, 1, .., i}で作り、末尾がjであって条件を満たす順列の数) auto dp = new long[][](n + 1, n + 1); dp[0][0] = 1; foreach (i ; 1 .. n) { if (s[i - 1] == '<') { // dp(i, j) = dp(i - 1, 0) + dp(i - 1, 1) + .. + dp(i - 1, j - 1) // = dp(i, j - 1) + dp(i - 1, j - 1) foreach (j ; 1 .. i + 1) { dp[i][j] = dp[i-1][j-1] + dp[i][j-1]; dp[i][j] %= mod; } } else { // dp(i, j) = dp(i - 1, j) + dp(i - 1 j + 1) + .. + dp(i - 1, i - 1) // = dp(i - 1, j) + dp(i, j + 1) foreach_reverse (j ; 0 .. i) { dp[i][j] = dp[i-1][j] + dp[i][j + 1]; dp[i][j] %= mod; } } } long ans; foreach (i ; 0 .. n) { ans += dp[n - 1][i]; ans %= mod; } writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.string; import std.conv; int main() { int MAX = 1000000; int[] prime; prime.length = MAX; prime[0] = prime[1] = 0; foreach(int i;2..MAX) { prime[i] = 1; } foreach(int i;2..1001) { if(prime[i]) { for(int j=2*i;j<MAX;j += i) { prime[j] = 0; } } } string s; while((s = readln()).length != 0) { int number = to!(int)(chomp(s)); int count = 0; foreach(int i;2..number+1) { count += prime[i]; } writeln(count); } return 0; }
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 main() { string n; readV(n); writeln(n.canFind('9') ? "Yes" : "No"); }
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 abcd = readln.split.to!(long[]); auto a = abcd[0]; auto b = abcd[1]; auto c = abcd[2]; auto d = abcd[3]; writeln(max(a*c, a*d, b*c, b*d)); }
D
import std; auto input() { return readln().chomp(); } alias sread = () => readln.chomp(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { string s; s = input(); // writeln(s); // writeln(s[0 .. (s.length - 1) / 2]); // writeln(s[((s.length + 3) / 2) - 1 .. $]); if (s[0 .. (s.length - 1) / 2] == s[((s.length + 3) / 2) - 1 .. $]) { writeln("Yes"); } else { writeln("No"); } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
import std.stdio, std.string; void main() { long[dchar] table = ['I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000]; foreach(input; stdin.byLine) { dchar current = 'I'; long sum = 0; foreach_reverse(dchar c; input) { if(table[c] < table[current]) { sum -= table[c]; } else { sum += table[c]; current = c; } } sum.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() { // writeln(gcd(2, 3)); // writeln((2 * 3) / gcd(2, 3)); auto n = lread(); auto t = new long[](n); foreach (i; 0 .. n) { long T; scan(T); t[i] = T; } // writeln(t); long gcd_ans = t[0]; foreach (i; 1 .. n) { gcd_ans = gcd(gcd_ans, t[i]); } // writeln(gcd_ans); long lcm_ans = t[0]; foreach (i; 1 .. n) { lcm_ans = lcm_ans * (t[i] / gcd(lcm_ans, t[i])); } writeln(lcm_ans); // writeln(ans); } long gcd(long a, long b) { long tmp; if (a < b) { swap(a, b); } tmp = a % b; while (tmp != 0) { a = b; b = tmp; tmp = a % b; } return b; } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto N = RD; long ans = 2; auto N1 = N-1; for (long i = 2; i*i <= N1; ++i) { if (N1 % i == 0) { ++ans; debug writeln(i); if (i != N1 / i) { ++ans; debug writeln(N1 / i); } } } for (long i = 2; i*i <= N; ++i) { if (N % i == 0) { long x = N; while (x >= i) { if (x % i) break; x /= i; } if ((x-1) % i == 0) { ++ans; debug writeln(i); } auto z = N / i; if (z == i) continue; auto y = N; while (y >= z) { if (y % z) break; y /= z; } if ((y-1) % z == 0) { ++ans; debug writeln(z); } } } if (N == 2) writeln(1); else writeln(ans); stdout.flush; debug readln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.map!(to!int), a = rd[0], b = rd[1], c = rd[2]; writeln(a < b && b < c ? "Yes" : "No"); }
D
import std.stdio; import std.algorithm; import core.stdc.stdio; int[] ds; int[] as; int[][] dim2arr(int w,int h){ int[] buf = new int[w*h]; int[][] ret = new int[][h]; for(int i=0;i<h;i++){ ret[i] = buf[i*w..(i+1)*w]; } return ret; } int factorial(int a){ if(a <= 1) return 1; else return a * (a-1).factorial; } int unUsed(bool[] used,int idx){ foreach(int i,ref b;used){ if(!b){ if(idx-- == 0){ b = true; return i; } } } assert(false); } int dMax=0; bool[] used; void sequence(int[] dest,int t){ used[] = false; for(int i=0;i<dMax;i++){ dest[i] = used.unUsed(t % (dMax-i)); t /= (dMax-i); } } int[] seqTmp; int seqIdx(int[] seq){ used[] = false; for(int i=0;i<dMax;i++){ int c=0; for(int j=0;j<dMax;j++){ if(!used[j]){ if(j == seq[i]){ seqTmp[i] = c; used[j] = true; break; } c++; } } } int res = 0; for(int i=dMax-1;i>=0;i--){ res *= (dMax-i); res += seqTmp[i]; } return res; } void step_insert(int[] seq,int t,int idx){ int c=0; for(int i=0;i<dMax;i++){ if(seq[i] == 0){ if(i < idx){ idx--; } continue; } seq[c++] = seq[i]-1; } for(int i=idx;i<dMax;i++){ swap(seq[i],t); } } int[][] dp; void main(){ int n; scanf("%d",&n); ds = new int[n]; as = new int[n]; for(int i=0;i<n;i++){ scanf("%d",&ds[i]); dMax = max(dMax,ds[i]); } used = new bool[dMax]; seqTmp = new int[dMax]; for(int i=0;i<n;i++){ scanf("%d",&as[i]); } int dFact = dMax.factorial; dp = dim2arr(dFact,n); int[] seq = new int[dMax]; bool[] ate = new bool[dMax]; for(int k=0;k<dFact;k++){ sequence(seq,k); ate[] = false; int sum=0; foreach(i;seq){ ate[i] = true; for(int j=max(0,i-ds[i]);j<min(dMax,i+ds[i]+1);j++){ if(!ate[j]) sum += as[i]; } } dp[0][k] = sum; } for(int i;i<n-dMax;i++){ for(int j=0;j<dFact;j++){ for(int k=0;k<dMax+1;k++){ int s = dp[i][j]; sequence(seq,j); int c=0; foreach(l;seq[0..k]){ if(dMax-l <= ds[i+l]){ s += as[i+l]; } } foreach(l;seq[k..dMax]){ if(dMax-l <= ds[i+dMax]){ s += as[i+dMax]; } } seq.step_insert(dMax-1,k); int si = seq.seqIdx; dp[i+1][si] = max(dp[i+1][si],s); } } } int ri = max(0,n-dMax); int ans = 0; for(int i=0;i<dFact;i++){ ans = max(dp[ri][i],ans); } printf("%d\n",ans); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}} void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}} void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}} void main() { int n; readV(n); int a; readV(a); writeln(n%500 <= a ? "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); string t; readV(t); auto vs = conv(s), vt = conv(t); if (!equal(vs, vt)) { writeln("No"); return; } writeln("Yes"); } auto conv(string s) { auto c = new int[](s.length); int[int] h; foreach (i, si; s) { auto j = cast(int)(si-'a'); if (j !in h) h[j] = h.length.to!int; c[i] = h[j]; } return c; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp, n = s.length; foreach_reverse(i; 1..n/2) { if (s[0..i] == s[i..i*2]) { writeln(i*2); break; } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; enum P = 10L^^9+7; void main() { auto S = readln.chomp.to!int; auto DP = new long[](S+1); DP[] = -1; long solve(int s) { if (s == 0) return 1; if (s < 3) return 0; if (DP[s] == -1) { long r; foreach (i; 3..s+1) { (r += solve(s-i)) %= P; } DP[s] = r; } return DP[s]; } writeln(solve(S)); }
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, k; scan(a, b, c, k); if (k % 2 == 0) { writeln(a - b); } else { writeln(b - a); } } 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
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(); } } auto main2(Input* input) { switch (input.s) { case "Sunny" : return "Cloudy"; case "Cloudy" : return "Rainy"; case "Rainy" : return "Sunny"; default: assert(0); } } void main() { Input input = void; parseInput(input, stdin); auto result = main2(&input); writeln(result); } void parseExample(out Input input, string example) { struct Adapter { import std.string; string[] _lines; this(string input) { _lines = input.splitLines(); } string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; } /+ uint readf(Data...)(scope const(char)[] format, auto ref Data data) { import std.format; return formattedRead(readln(), format, data); }+/ } Adapter a = Adapter(example); parseInput(input, a); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm; void main() { string[] mark = ["S", "H", "C", "D"]; bool[] cards = new bool[52]; int n = readln.chomp.to!int; foreach (i; 0 .. n) { string[] tmp = readln.chomp.split; cards[mark.countUntil(tmp[0])*13+tmp[1].to!int-1] = true; } foreach (i; 0 .. 52) { if (cards[i] == false) { writeln(mark[i/13], " ", i % 13 + 1); } } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto N = RD; if (N % 10 == 3) { writeln("bon"); } else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) { writeln("pon"); } else { writeln("hon"); } stdout.flush; debug readln; }
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { long N = lread(); long r; { long ok = 0; long ng = 100_000_000; while (ng - ok > 1) { long m = (ok + ng) / 2; long s = m * (m + 1) / 2; if (s < N) { ok = m; } else { ng = m; } } r = ng; } long s = r * (r + 1) / 2; long e = s - N; foreach (x; 1 .. r + 1) if (x != e) { writeln(x); } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto s = readln.chomp; auto t = readln.chomp; int res = 2 * n; if (s == t) { res = n; } else { foreach (int i; 0..n) { if (s[$-i-1..$] == t[0..i+1]) { res = 2 * n - i - 1; } } } res.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() { int n; scan(n); writeln(n / 100 == n % 10 ? "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
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 s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1]; long ans = 0; if (K == 0) { writeln(1L * N * N); return; } foreach (b; K+1..N+1) { int M = N / b + (N % b > 0); ans += (b - K) * M; if (N % b != 0) ans -= min(b - K, M * b - N - 1); } ans.writeln; }
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() { readln.replace(",", " ").writeln; }
D
import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm; import std.bigint; void main() { while (true){ ulong n = readln().chomp().to!ulong; if (n == 0) break; ulong pat = shinobu(n); pat /= 10; if (pat % 10 != 0){ pat++; } writeln(pat / 365 + 1); } } ulong shinobu(ulong n) { if (n == 1) return (1); if (n == 2) return (2); if (n == 3) return (4); return (shinobu(n - 1) + shinobu(n - 2) + shinobu(n - 3)); }
D
void main() { string o = readln.chomp; string e = readln.chomp; string password; foreach (i; 0 .. e.length) { password ~= o[i]; password ~= e[i]; } if (o.length != e.length) password ~= o[$-1]; password.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.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; } bool[] sieve(long n) { auto f = new bool[](n/2); f[] = true; f[0] = false; long sq = cast(long)sqrt(cast(double)n); long sq_i = sq / 2; for (long i = 1; i < sq_i; ++i) { if (!f[i]) continue; long p = 2 * i + 1; for (long mul = 2 * i * (i+1); mul < f.length; mul += p) f[mul] = false; } return f; } void main() { auto Q = RD; auto p = sieve(10^^5); auto a = new long[](10^^5+1); foreach (i; 1..10^^5+1) { if ((i != 2 && i % 2 == 0) || ((i+1)/2 != 2) && (i+1)/2 % 2 == 0) continue; auto f = p[i/2] && p[(i+1)/4]; a[i] = f ? 1 : 0; } auto b = new long[](10^^5+1); foreach (i; 0..10^^5) { b[i+1] = b[i] + a[i]; } auto ans = new long[](Q); foreach (i; 0..Q) { auto l = RD; auto r = RD; ans[i] = b[r+1] - b[l-1]; } debug writeln(b[0..100]); foreach (i; 0..Q) writeln(ans[i]); stdout.flush(); debug readln(); }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; import core.bitop; T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T)(in string str) { return str.split.to!(T[]); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; } long mod = pow(10, 9) + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } struct UnionFind { void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; } long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); } bool same(long i, long j) { return root(i) == root(j); } void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; } long[] par; } void main() { auto A = RD!long; auto B = RD!long; writeln(B % A == 0 ? A + B : B - A); stdout.flush(); }
D
/+ dub.sdl: name "B" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; // import dcomp.functional; int n; int[][] g; int[] gsm; int main() { auto sc = new Scanner(stdin); int m; sc.read(n, m); calc.init([[0, 1<<n], [0, n-1], [0, n-1]]); g = new int[][](n, n); foreach (i; 0..m) { int a, b, c; sc.read(a, b, c); a--; b--; g[a][b] = g[b][a] = c; } gsm = new int[1<<n]; foreach (f; 0..1<<n) { foreach (x; 0..n) { if (!(f & (1<<x))) continue; foreach (y; x+1..n) { if (!(f & (1<<y))) continue; gsm[f] += g[x][y]; } } } writeln(calc((1<<n)-1, 0, n-1)); return 0; } int calcBase(int f, int s, int t) { if (s > t) return calc(f, t, s); assert(f & (1<<s)); assert(f & (1<<t)); int ans = 10^^9; if (g[s][t]) { for (int w = 0; w < f; w = ((w | ~f) + 1) & f) { if (!(w & (1<<s))) continue; if ( (w & (1<<t))) continue; ans = min(ans, gsm[f] - gsm[w] - gsm[f^w] - g[s][t]); } } foreach (z; 0..n) { if (!(f & (1<<z))) continue; if (z == s || z == t) continue; for (int w = 0; w < f; w = ((w | ~f) + 1) & f) { if (!(w & (1<<s))) continue; if ( (w & (1<<z))) continue; if ( (w & (1<<t))) continue; int sm = calc(w|(1<<z), s, z) + calc(f^w, z, t); ans = min(ans, sm + gsm[f] - gsm[w|(1<<z)] - gsm[f^w]); } } return ans; } memoCont!calcBase calc; /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/functional.d */ // module dcomp.functional; struct memoCont(alias pred) { import core.exception : RangeError; import std.range, std.algorithm, std.conv; import std.string : join; import std.traits : ReturnType, ParameterTypeTuple, isIntegral; import std.typecons : tuple, Tuple; import std.meta; alias R = ReturnType!pred; alias Args = ParameterTypeTuple!pred; static assert (allSatisfy!(isIntegral, Args)); static immutable N = Args.length; int[2][N] rng; int[N] len; R[] dp; bool[] used; void init(int[2][N] rng) { this.rng = rng; len = rng[].map!(a => a[1]-a[0]+1).array; int sz = len.reduce!"a*b"; dp = new R[sz]; used = new bool[sz]; } R opCall(Args args) { int idx, base = 1; foreach (i, v; args) { version(assert) { if (v < rng[i][0] || rng[i][1] < v) { throw new RangeError; } } assert(rng[i][0] <= v && v <= rng[i][1]); idx += base*(v - rng[i][0]); base *= len[i]; } if (used[idx]) return dp[idx]; used[idx] = true; auto r = pred(args); dp[idx] = r; return r; } } /* 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 core.bitop : popcnt; static if (!__traits(compiles, popcnt(ulong.max))) { public import core.bitop : popcnt; int popcnt(ulong v) { return popcnt(cast(uint)(v)) + popcnt(cast(uint)(v>>32)); } } bool poppar(ulong v) { v^=v>>1; v^=v>>2; v&=0x1111111111111111UL; v*=0x1111111111111111UL; return ((v>>60) & 1) != 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; // import dcomp.container.stack; 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 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/container/stack.d */ // module dcomp.container.stack; struct StackPayload(T, size_t MIN = 4) { import core.exception : RangeError; import std.algorithm : max; import std.conv; import std.range.primitives : ElementEncodingType; import core.stdc.string : memcpy; private T* _data; private uint len, cap; bool empty() const { return len == 0; } @property size_t length() const { return len; } alias opDollar = length; ref inout(T) opIndex(size_t i) inout { return _data[i]; } ref inout(T) front() inout { return _data[0]; } ref inout(T) back() inout { assert(len); return _data[len-1]; } 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; } inout(T)[] data() inout { return (_data) ? _data[0..len] : null; } static struct RangeT(A) { import std.traits : CopyTypeQualifiers; alias E = CopyTypeQualifiers!(A, T); A *p; size_t a, b; @property bool empty() const { return b <= a; } @property size_t length() const { return b-a; } @property RangeT save() { return RangeT(p, a, b); } @property RangeT!(const A) save() const { return typeof(return)(p, a, b); } alias opDollar = length; @property ref inout(E) front() inout { return (*p)[a]; } @property ref inout(E) back() inout { return (*p)[b-1]; } void popFront() { version(assert) if (empty) throw new RangeError(); a++; } void popBack() { version(assert) if (empty) throw new RangeError(); b--; } ref inout(E) opIndex(size_t i) inout { return (*p)[i]; } RangeT opSlice() { return this.save; } RangeT opSlice(size_t i, size_t j) { version(assert) if (i > j || a + j > b) throw new RangeError(); return typeof(return)(p, a+i, a+j); } RangeT!(const A) opSlice() const { return this.save; } RangeT!(const A) opSlice(size_t i, size_t j) const { version(assert) if (i > j || a + j > b) throw new RangeError(); return typeof(return)(p, a+i, a+j); } } alias Range = RangeT!(StackPayload!T); alias ConstRange = RangeT!(const StackPayload!T); alias ImmutableRange = RangeT!(immutable StackPayload!T); } struct Stack(T) { import core.exception : RangeError; import core.memory : GC; import std.range : ElementType, isInputRange; import std.traits : isImplicitlyConvertible; alias Payload = StackPayload!T; alias Range = Payload.Range; alias ConstRange = Payload.ConstRange; alias ImmutableRange = Payload.ImmutableRange; Payload* p; private void I() { if (!p) p = new Payload(); } private void C() const { version(assert) if (!p) throw new RangeError(); } private this(Payload* p) { this.p = p; } this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) { p = new Payload(); foreach (v; values) { insertBack(v); } } this(Range)(Range r) if (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range, T) && !is(Range == T[])) { p = new Payload(); foreach (v; r) { insertBack(v); } } static Stack make() { return Stack(new Payload()); } @property bool havePayload() const { return (p !is null); } @property bool empty() const { return (!havePayload || p.empty); } @property size_t length() const { return (havePayload ? p.length : 0); } @property inout(T)[] data() inout {C; return (!p) ? [] : p.data; } alias opDollar = length; ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; } ref inout(T) front() inout {C; return (*p)[0]; } ref inout(T) back() inout {C; return (*p)[$-1]; } void clear() { if (p) p.clear(); } void insertBack(T v) {I; p.insertBack(v); } alias stableInsertBack = insertBack; void removeBack() {C; p.removeBack(); } Range opSlice() {I; return Range(p, 0, length); } } /* 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, 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(){ string s = read; if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) "Bad".writeln; else "Good".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 int[](t); foreach (ti; 0..t) { auto n = RD!int; auto k = RD!int; auto x = new int[](n); auto y = new int[](n); foreach (i; 0..n) { x[i] = RD!int; y[i] = RD!int; } ans[ti] = -1; foreach (i; 0..n) { bool ok = true; foreach (j; 0..n) { auto dx = abs(x[i] - x[j]); auto dy = abs(y[i] - y[j]); if (dx+dy > k) { ok = false; break; } } if (ok) { ans[ti] = 1; break; } } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto H1 = RD; auto M1 = RD; auto H2 = RD; auto M2 = RD; auto K = RD; auto H = H2 - H1; auto M = M2 - M1; auto ans = H*60 + M - K; writeln(ans); stdout.flush; debug readln; }
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.range; import std.stdio; import std.string; void main() { int n = readln.chomp.to!int; bool[string] dic; for (int i = 0; i < n; i++) { auto input = readln.chomp.split; auto key = input[1]; if (input[0] == "insert") { dic[key] = true; } else { if (dic.get(key, false)) { "yes".writeln; } else { "no".writeln; } } } }
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 RRLRL ---+/ /+---test RRLLLLRLRRLL ---+/ /+---test RRRLLRLLRRRLLLLL ---+/ void main(string[] args) { const S = readln.chomp; auto ans = new size_t[S.length]; char prev = 'R'; size_t st, md; foreach (i, c; S~'R') { if (prev != c) { if (c == 'L') { md = i; } if (c == 'R') { const len = i - st; ans[md-1] = ans[md] = len/2; if (ans[md]*2 != len) { if ((md-st)%2 == 0) { ++ans[md]; } else { ++ans[md-1]; } } st = i; } } prev = c; } foreach (i, v; ans) { if (i != 0) " ".write; v.write; } writeln; }
D
import std.stdio; import std.conv; import std.algorithm; import std.string; import std.file; int main() { int[] hs; string l; while((l = readln()).length >= 2){ float a, b, c, d, e, f; a = to!int(l.split()[0]), b = to!int(l.split()[1]), c = to!int(l.split()[2]); d = to!int(l.split()[3]), e = to!int(l.split()[4]), f = to!int(l.split()[5]); float x, y; x = (c * e - f * b)/(a * e - d * b), y = (c * d - f * a)/(b * d - e * a); x = to!float(to!int(x * 1000)) / 1000, y = to!float(to!int(y * 1000)) / 1000; printf("%.3f %.3f\n", x, y); } return 0; }
D
import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm; long s(long n) { long s; while(n > 0) { s += n % 10; n /= 10; } return s; } void main(){ auto K = readln().strip().to!int(); long step = 1; long befoki = 0; long i = 1; for (long c = 0; c < K;) { auto nwev = i.to!double() / s(i); auto nxev = (i+step).to!double() / s(i+step); //write(nwev, "\t", nxev, "\t"); //writeln(i); if(nwev <= nxev) { writeln(i); c++; if(step != i-befoki) { step = i - befoki; } befoki = i; } nwev = nxev; i += step; } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto S = readln.chomp; auto N = S.length.to!int; string A = ""; string B = ""; foreach (i; 0..N) { if (S[i] == '1') A ~= S[i]; else B ~= S[i]; } if (B.empty) { A.writeln; return; } int x = B.length.to!int; foreach (i; 0..B.length.to!int) { if (B[i] == '2') { x = i; break; } } writeln(B[0..x] ~ A ~ B[x..$]); }
D
// Cheese-Cracker: cheese-cracker.github.io void theCode(){ ll l = scan; ll r = scan; if(l == r){ writeln(0); return; } ll d = r/2 + 1; d = max(l, d); writeln(r % d); } void main(){ long tests = scan; // Toggle! while(tests--) theCode(); } /********* That's All Folks! *********/ import std.stdio, std.random, std.functional, std.container, std.algorithm; import std.numeric, std.range, std.typecons, std.string, std.math, std.conv; string[] tk; 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; } } alias ll = long, tup = Tuple!(long, "x", long, "y");
D
import std.stdio, std.algorithm, std.conv, std.string; void main(){ while(true){ ulong[int] sales; int[] order; int data=readln.chomp.to!int; if(data==0)break; foreach(_;0..data){ auto inp=readln.split.map!(to!int); int id=inp[0],sale=inp[1],num=inp[2]; if(id in sales){ sales[id]+=sale*num; }else{ order~=id; sales[id]=sale*num; } } bool na=true; foreach(id;order){ if(sales[id]>=1_000_000){ id.writeln; na=false; } } na&&"NA".writeln; } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto a = RD; auto b = RD; auto d = b - a; long h; foreach (i; 1..d+1) { h += i; } writeln(h - b); stdout.flush(); debug readln(); }
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 s = readln.to!(char[]); s[0]++; writeln(s); }
D
import std.stdio, std.conv, std.string, std.math, std.algorithm; void main(){ auto ip = readln.chomp; if(ip[0] == 'H'){ if(ip[2] == 'H') 'H'.writeln; else if(ip[2] == 'D') 'D'.writeln; } else if(ip[0] == 'D') { if(ip[2] == 'H') 'D'.writeln; else if(ip[2] == 'D') 'H'.writeln; } }
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; T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { import core.stdc.stdlib; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto A = scanString; auto B = scanString; auto C = scanString; write(A[0], B[1], C[2], '\n'); }
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii, std.typecons; // }}} // nep.scanner {{{ class Scanner { import std.stdio; import std.conv : to; import std.array : split; import std.string : chomp; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.chomp.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 main() { auto cin = new Scanner; int n = cin.next!int; auto s = cin.nextArray!(string)(n); int m = cin.next!int; auto t = cin.nextArray!(string)(m); auto a = s ~ t; int ma = 0; foreach(i; a) { int cnt; foreach(j; s) { if (j == i) cnt++; } foreach(j; t) { if (j == i) cnt--; } ma = max(ma, cnt); } writeln(ma); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long A, B, N; scan(A, B, N); long x = min(N, B - 1); writeln((A * x) / B - A * (x / B)); // foreach (x; 1 .. N + 1) // { // writefln("%s %s", x, (A * x) / B - A * (x / B)); // } }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.functional; void main() { char[] s = readln.chomp.to!(char[]); int n = s.length.to!int; bool[] app = new bool[](26); foreach (ch ; s) { app[ch - 'a'] = 1; } debug { writeln("app:", app); } if (app.sum == 1) { writeln(0); return; } int ans = 200; foreach (alp ; 0 .. 26) { if (!app[alp]) continue; auto sc = s.dup; int cnt; debug { writeln((alp + 'a').to!char); } foreach (i ; 0 .. n - 1) { foreach (j ; 0 .. n - 1 - i) { if (sc[j + 1] == (alp + 'a')) { sc[j] = sc[j + 1]; } } debug { writeln("sc:", sc); } bool flag = true; foreach (j ; 0 .. n - 1 - i - 1) { if (sc[j] != sc[j + 1]) { flag = false; } } cnt++; if (flag) { break; } } ans = min(ans, cnt); } 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); }
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; T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } alias sread = () => readln.chomp(); void main() { auto str = sread(); long cnt; foreach(c;str){ cnt += (c == '2')? 1:0; } cnt.writeln; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int q; scan(q); while (q--) { long ai, bi; scan(ai, bi); solve(ai, bi); } } void solve(long ai, long bi) { long l = sqrt(ai*bi); debug { writefln("l:%s", l); } long ans; if (l*(l+1) < ai*bi) { ans = 2*l - 1; } else { ans = 2*l - 2; } if (ai == bi) ans++; writeln(ans); } long sqrt(long x) { long btm = 0, top = x; while (top - btm > 1) { long mid = (top + btm) / 2; if (mid < (x+mid-1)/mid) { btm = mid; } else { top = mid; } } return btm; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto s = readln.chomp; auto w = readln.chomp.to!int; string x = ""; foreach (i; iota(0,s.length,w)) { x ~= s[i]; } x.writeln; }
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() { long n; scan(n); int k; while (10L^^(k+1)-1 <= 2*n - 1) k++; debug { writeln(k); } long ans; foreach (d ; 1 .. 10) { long x = d * 10L^^k - 1; if (x > 2*n - 1) break; auto low = max(1, x - n); auto high = min(n + 1, (x + 1) / 2); debug { writefln("%d, %d", low, high); } ans += max(0, min(n + 1, high - low)); } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio,std.string,std.conv,std.array,std.algorithm; void main(){ int[string] mark; mark["S"]=0; mark["H"]=1; mark["C"]=2; mark["D"]=3; bool[13][4] card; readln(); for(;;){ auto rcs = readln().chomp().split(); if(!rcs){break;} card[mark[rcs[0]]][to!int(rcs[1])-1]=true; } foreach(m;0..4){foreach(n;0..13){ if(!card[m][n]){ final switch(m){ case 0:write("S ");break; case 1:write("H ");break; case 2:write("C ");break; case 3:write("D ");break; } writeln(n+1); } }} }
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; void main() { int sum = 0; foreach(i; 0..10) sum += readln.chomp.to!int; sum.writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; bool[string] res; foreach (_; 0..N) { res[readln.chomp] = true; } writeln(res.length); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto N = readln.chomp.to!int; auto S = readln.chomp; auto cnt = new long[string][](N+1); long ans = 0; foreach (mask; 0..(1<<N)) { string a = ""; string b = ""; foreach (i; 0..N) { if ((1 << i) & mask) { a ~= S[i]; } else { b = S[i] ~ b; } } cnt[mask.popcnt][a~b] += 1; } foreach (mask; 0..(1<<N)) { string a = ""; string b = ""; foreach (i; 0..N) { if ((1 << i) & mask) { a ~= S[i+N]; } else { b = S[i+N] ~ b; } } if ((b ~ a) in cnt[N-mask.popcnt]) { ans += cnt[N-mask.popcnt][b ~ a]; } } ans.writeln; }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); writeln("ABC", s); }
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, m; readV(n, m); auto g = Graph!int(n); foreach (_; 0..m) { int a, b; readV(a, b); --a; --b; g.addEdgeB(a, b); } foreach (i; 0..n) writeln(g[i].length); } struct Graph(N = int) { alias Node = N; Node n; Node[][] g; alias g this; this(Node n) { this.n = n; g = new Node[][](n); } void addEdge(Node u, Node v) { g[u] ~= v; } void addEdgeB(Node u, Node v) { g[u] ~= v; g[v] ~= u; } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { readln; auto r = readln.chomp.split(" ").map!(to!uint).all!((a) => (a % 2 == 1) || (a % 3 == 0) || (a % 5 == 0)); if (r) { writeln("APPROVED"); } else { writeln("DENIED"); } }
D
import std.stdio; import std.conv; import std.algorithm; import std.range; import std.string; import std.typecons; import std.math; import std.range; void main() { auto count = readln().strip.to!int; auto m = new int[(count + 1) * (count + 1)].chunks(count + 1); auto p = new int[count + 1]; foreach (i; iota(count)) { int x, y; scanf("%d %d", &x, &y); p[i] = x; p[i + 1] = y; } for (int l = 2; l <= count; l++) { for (int i = 1; i <= count - l + 1; i++) { auto j = i + l - 1; m[i][j] = int.max; for (int k = i; k <= j - 1; k++) { m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]); } } } writeln(m[1][count]); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp; auto DP = new long[][](N.length, 2); foreach (ref dp; DP) dp[] = -1; long solve(int i, bool k) { if (i == N.length) return k == 0 ? 0 : long.max/3; if (DP[i][k] == -1) { long n = N[i]-'0'; if (k) { DP[i][k] = min(solve(i+1, 0) + 10 - n, solve(i+1, 1) + 10 - n - 1); } else { DP[i][k] = min(solve(i+1, 0) + n, solve(i+1, 1) + n + 1); } } return DP[i][k]; } writeln(min(solve(0, 0), solve(0, 1) + 1)); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto ds = readln.chomp.split.to!(int[]); auto m = readln.chomp.to!int; auto ts = readln.chomp.split.to!(int[]); int[int] cnt; foreach (d; ds) { cnt[d]++; } bool f = false; foreach (t; ts) { if (cnt.get(t, 0)) { cnt[t]--; } else { f = true; break; } } if (f) writeln("NO"); else writeln("YES"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum as = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]; void main() { writeln(as[readln.chomp.to!int-1]); }
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 n; scan(n); void solve(int i, int shu, string s) { if (i == n) { writeln(s); return; } foreach (j ; 0 .. shu) { solve(i + 1, shu, s ~ ('a' + j).to!char); } solve(i + 1, shu + 1, s ~ ('a' + shu).to!char); } solve(0, 0, ""); } 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.algorithm; import std.array; import std.stdio; import std.string; void main() { string[] blocks; loop: for (;;) { auto command = readln.strip.split; auto operation = command[0]; final switch (operation) { case "push": auto block = command[1]; blocks ~= block; break; case "pop": auto block = blocks[$-1]; blocks = blocks[0 .. $-1]; writeln(block); break; case "quit": break loop; } } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y", long, "cost"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { auto n = lread(); long ans; foreach (i; iota(n).map!(x => x + 1).array()) { ans += (i + i * (n / i)) * (n / i) / 2; } ans.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