code
stringlengths
4
1.01M
language
stringclasses
2 values
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.stdlib; immutable int INF = 1 << 29; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; ...
D
import std.stdio; import std.conv; import std.string; import std.array; void main() { string[] input1 = split(readln()); string[] input2 = split(readln()); int S; int T; for(int i = 0; i < 4; ++i) S += to!int(input1[i]); for(int i = 0; i < 4; ++i) T += to!int(input2[i]); if (S > T) 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(DE...
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 =...
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_r...
D
#!/usr/bin/env rdmd import std.stdio, std.string, std.conv; import std.algorithm, std.array; import std.math, std.numeric; import std.range; void main() { for(string S; (S=readln().chomp()).length; ) { auto m = S.split().map!(to!int)(); auto n = m[0], l=m[1], r=m[2], Ql=m[3], Qr=m[4]; a...
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!int).array; int hi = A.reduce!max + 2; ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n; scan(n); auto a = readln.split.to!(int[]); auto pf = new long[](n + 1); foreach (i ; 1 .. n + 1) { pf[i] = pf[i-1...
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.c...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { int x...
D
import std.stdio, std.string, std.conv; void main() { auto S = readln.split.to!(int[]); auto sx = S[0], sy = S[1], tx = S[2], ty = S[3]; void po(string c, int x) { foreach (i; 0..x) { write(c); } } po("R", tx-sx); po("U", ty-sy); po("L", tx-sx); po("D", ty-s...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N, K; scan(N, K); auto S = readln.chomp...
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; int calc(int[] xs) { ...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; re...
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 ss = readln.chomp; int res0, res1; foreach (i, s; ss) { if (i % 2) { ...
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; import std.typecons, std.regex; void main() { int n = read.to!int; long W = read.to!long; auto w = new long[](n); auto v = new int[](n); for...
D
import std.stdio; import core.stdc.stdio; import std.array; import std.conv; import std.algorithm; import std.range; void main() { int n; scanf("%d",&n); int[] a; a.length=n; foreach(i; 0..n) scanf("%d", &a[i]); a.sort().reverse(); int x, y; foreach(i, v; a) { if(i & 1) y += v; ...
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(...
D
import std.stdio; import std.conv; import std.string; const int DATA = 10; int main() { int max=-1, mid=-1, min=-1; for(int i=0; i<DATA; i++) { int d = to!(int)(chomp(readln)); if(max < d) { min = mid; mid = max; max = d; } else if(mid < d) { min = mid; mid = d; }...
D
import std.stdio; import std.string; import std.conv; import std.math; void main() { string[] inputs = split(readln()); int X = to!int(inputs[0]); int A = to!int(inputs[1]); int B = to!int(inputs[2]); if(A - B >= 0) "delicious".writeln; else if(X >= abs(A - B)) "safe".writeln; else "dangerous".writeln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; bool isSameSign(int a, ...
D
static immutable MOD = 4; static immutable MOD_OVERAL = 5; static immutable MODS = [ [1, 1, 1, 1], [1, 2, 4, 3], [1, 3, 4, 2], [1, 4, 1, 4] ]; uint solve(const string n) { uint sum = 0; foreach (ch; n) { if (ch < '0' || ch > '9') {break;} sum = ( (sum * 10) + (ch - '0') ) % MOD; } sum %= MOD; uint res = ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto kab = readln.split.to!(long[]); auto K =kab[0]; auto A = kab[1]; auto B = kab[2]; if (A+2 > B) { writeln(K+1); return; } else if (K == 1) { writeln(...
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; 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; } long ...
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", ...
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; int[] di = [1,0,-1,0], dj = [0,1,0,-1]; int ans; void main() { while (1) { int w, h; scan(w, h); if (!w) return; auto bd = iota(h).m...
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 h = aryread(); // writeln(h); // writeln(h.maxElement); long cnt; while (true) { if (h.maxElement ...
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 ...
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; void main() { long n; scan(n); if (n == 1) { writeln(0); return; } long ans; for (long i = 1; i * i <= n; i++)...
D
import std.stdio; import std.array; import std.string; import std.conv; void main() { uint count = 0; auto n = chomp(readln()); auto s = split(readln()); auto q = to!(int)(chomp(readln())); auto t = split(readln()); foreach (i; t) foreach (j; s) if (i == j) {count++; b...
D
import std.stdio,std.range,std.algorithm,std.conv,std.array,std.string; void main() { int[1000] field; int[1000] dice; while(true) { auto input=readln.split; int N=input[0].to!int; int M=input[1].to!int; if(N==0&&M==0)break; foreach(i; 0..N) { ...
D
ulong[] generate_prime_list(T)(T N) if(isIntegral!T) { ulong[] prime_list = [2]; bool not_prime = false; foreach(i; 3..N.to!ulong+1) { auto p = i.to!float.sqrt.ceil.to!ulong; foreach(j; prime_list) { if(j > p) break; if(i % j == 0) { not_prime = true; break; } } if(!not_prime) prime_list ~= ...
D
// Vicfred // https://atcoder.jp/contests/abc155/tasks/abc155_c import std.algorithm; import std.conv; import std.stdio; import std.string; void main() { int n = readln.chomp.to!int; int[string] votes; foreach(_; 0..n) { string s = readln.chomp; votes[s] = votes.get(s,0)+1; } int...
D
import std.stdio, std.string, std.conv, std.algorithm; void main(string[] args) { readln(); auto a = readln().chomp.split.map!(to!int); int[] t; void f(int i){if(t.length<=i){t.length=i+1;} t[i]++;} foreach(int i; a){ if(i>0){ f(i-1); } f(i); f(i+1); } t.reduce!max.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_r...
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....
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializ...
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(...
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, m; scan(n, m); auto p = readln.spl...
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_r...
D
void main() { auto S = rs; auto A = S[0..2].to!int; auto B = S[2..4].to!int; bool YYMM = 0 <= A && A <= 99 && 0 < B && B <= 12; bool MMYY = 0 <= B && B <= 99 && 0 < A && A <= 12; if(YYMM && MMYY) writeln("AMBIGUOUS"); else if(YYMM) writeln("YYMM"); else if(MMYY) writeln("MMYY"); else writeln("NA"); } // ======...
D
import std.stdio,std.string,std.conv; int main() { string s; bool[int] m; bool[int] m2; int[int] count; while((s = readln.chomp).length != 0) { string[] _s = s.split(","); int a = _s[0].to!int; m[a] = true; count[a]++; } while((s = readln.chomp).length != 0) { string[] _s = s.split(","); int a ...
D
import std.algorithm; import std.conv; import std.stdio; import std.string; void main() { auto hw = readln.split.map!( to!byte ); auto s = new string[ hw[ 0 ] ]; foreach( ref sl; s ) { sl = readln.strip; } writeln( solve( hw[ 0 ], hw[ 1 ], s ) ); } string solve( in byte h, in byte w, in string[] s ) { boo...
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(...
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 N = readln.split[0].to!int; auto data = readln.split, T = data[0].to!int, A = data[1].to!int; auto H = readln.split.to!(int[]); auto diff = N.iota.map!(n => ...
D
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; immutable long mod = 10^^9 + 7; alias Pair = Tuple!(int, "l", int, "x"); void main(){ int N, M; int li, ri, xi; readVars(N, M)...
D
import std.stdio; import std.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; import std.numeric; alias lread = () => readln.chomp.to!long; alias aryread = () => readln.split.to!(long[]); void main() { auto nx = aryread()...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { string[] inputs = split(readln()); int a = to!int(inputs[0]); int b = to!int(inputs[1]); int c = to!int(inputs[2]); bool[int] flags; flags[a] = true; flags[b] = true; flags[c] = true; flags.length.writeln; }
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; int n,s; int saiki(int n1,int u,int m){ if(n1 > s) return 0; else if(m==1){ int d = s-n1; if(d <= 9 && (u & (1<<d))==0...
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 pickV(R,T...)(ref R r,ref T t){foreach(ref v;t)pick(r,v);} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nx = readln.split.to!(int[]); auto N = nx[0]; auto X = nx[1]; auto LS = readln.split.to!(int[]); int d, c; foreach (l; LS) { ++c; d += l; if (d > X)...
D
import std.stdio; import std.algorithm; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() {//try{ auto tokens = split(my_readln()); auto N = to!ulong(tokens[0]); auto H = to!ulong(tokens[1]); auto W = to!ulong(t...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split, n = rd[0].to!size_t, x = rd[1].to!long; auto a = readln.split.to!(long[]); auto ans = 0L; foreach (i; 1..n) { auto s = a[i-1] + a[i]; if (s <= x) continue; auto r = min(s - x, a[i]); a[i] -=...
D
void main(){ int[] ab = _scanln(); (ab[0] * ab[1]).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; wchar[600][600] BD1, BD2; void main() { auto N = readln.chomp.to!int; foreach (i; 0..N) { foreach (j, c; readln.chomp) { BD1[i][j] = BD1[i][N+j] = BD1[N+i][j] = BD1[N+i][N+j] = c; BD2[j][i] = BD2[j][N+i] = BD2[N...
D
void main() { int n = readln.chomp.to!int; int[] a = readln.split.to!(int[]); bool[] colors = new bool[8]; int red; foreach (x; a) { if (x < 3200) { colors[x/400] = true; } else { ++red; } } int cmin = colors.count(true).to!int; int cmax = ...
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { auto s = sread(); long n = s.length; long max_x = long.min; ...
D
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv, std.typecons, std.math, std.container, std.format; void main(string[] args) { auto s = readln.strip(); long cnt = 0; foreach (i; 0 .. s.length / 2) { if (s[i] != s[s.length - i - 1]) { cnt++; ...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { int n; while ((n = readint) > ...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto x = readln.chomp.to!long; auto ans = x / 11 * 2, mod = x % 11; if (1 <= mod && mod <= 6) ans += 1; else if (5 <= mod) ans += 2; writeln(ans); }
D
import std; enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;} T scan(T=long)(){return readln.chomp.to!T;} void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);} //END OF TEMPLATE void main(){ ulong n,k; ...
D
import std.stdio; import std.string; import std.conv; void main() { string ans = "UNRESTORABLE"; string s = readln.chomp; string t = readln.chomp; if (t.length <= s.length) { char[] t_ans; foreach_reverse (i; 0..s.length - t.length + 1) { bool flag = true; t_ans...
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() { int r; readV(r); int g; readV(g); writeln(2*g-r); }
D
import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; void main() { int N = readln().chomp.to!int; int Lsum = 0; int Rsum = 0; int[] L = new int[](N); int[] R = new int[](N); foreach (i; iota(...
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 s; scan(s); int ans = 1; bool[lo...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } bool isOnSegment(Vec2 p, Vec2 a, Vec2 b) { auto ...
D
import std.stdio, std.string, std.conv; void main() { auto n = readln.chomp.to!int; auto a = readln.chomp.to!int; writeln(n * n - a); }
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, M; scan(N, M); int ans; for (int i = 1; i*i <= M...
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 : ...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int[][] dp = new int[][](1001, 10001); int cases = 1; while(true) { int w = readln.chomp.to!int; if(!w)break; int n = readln.chomp.to!int; int[1001] treValue, treWeit; foreach(i; 1 .. n + 1) ...
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; import std.typecons; import std.bigint; // import dcomp.foundation, dcomp.scanner; // import dcomp.container.deque; /* int main() { auto sc = new Scanner(stdin); int n, m, k; sc.rea...
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(){ while(true){ int n = readln().chomp().to!int; if(n==0)break; int m = readln().chomp().to!int; int p = read...
D
import std.algorithm; import std.conv; import std.range; import std.stdio; void main(){ iota(1, 10).map!(a => iota(1, 10).map!(b => text(a, "x", b, "=", a * b)).join("\n")).join("\n").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.functi...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto s = readln.chomp; auto t = readln.chomp; int cnt; foreac...
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() { int n; scan(n); auto luca = new long[](100); luca[0] = 2, luca[1] = 1; foreach (i ; 2 .. 100) { luca[i] = luca[i - 1] + luca[i ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; long[10^^5*2] AS; long[10^^5*2][5] MEMO; void main() { auto L = readln.chomp.to!int; foreach (i; 0..L) { AS[i] = readln.chomp.to!long; } foreach (ref m; MEMO) m[] = -1; long solve(int i...
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 File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() ...
D
module cf1167a; import std.stdio; import std.string : indexOf, strip; import std.conv : to; void main() { int n; char[] buf; readln(buf); n = buf.strip.to!int; debug writeln(n); foreach(i; 0..n) { int x; readln(buf); x = buf.strip.to!int; readln(buf); immutable eight = buf.indexOf('8'); debug writeln(...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; import std.typecons; int cvt (dchar c) { return (c.to!int - 97); } void main() { immutable n = readln.strip.to!int; string s = readln.strip; auto idx = new int[][...
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(...
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(...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto Q = s[2]; auto S = r...
D
import std.stdio, std.conv, std.string; import std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } int DEBUG_LEVEL = 0; void pr...
D
import std.stdio; void main() { printf("25\n"); }
D
import std.stdio; import std.uni; import std.math; import std.conv; import std.container; import std.functional; import std.algorithm; import std.array; import std.typecons; void main(string[] args) { inputFile = stdin; debug inputFile = File(args[1]); auto nt = next!int; foreach(t; 0 .. nt) { auto a...
D
import std.stdio, std.string, std.conv, std.algorithm; void main(){ int n; rd(n); auto s=readln.chomp.to!(char[]); if(n==1){ writeln("Yes"); return; } bool[char] set; foreach(c; s){ if(c in set){ writeln("Yes"); return; } set[c]=true; } writeln("No"); } void rd(T.....
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; string s; scan(n); scan(s); s = "0" ~ s ~ "0"; auto dp = new int[](n + 1); foreach (i ; 3 .. n + 1) { dp[i] = max(dp[i], dp[...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; long[10^^5][4] CS; int P = 10^^9+7; void main() { auto S = readln.chomp.to!(wchar[]); auto len = S.length; foreach_reverse(i, c; S) { if (i == len-1) { switch (c) { case 'C': ...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens....
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto N = readln.chomp.to!int; auto A = readln.split.map!(to!int).array; auto C = new int[](101010); foreach ...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const N = readln.chomp.to!long; writeln(N < 1000 ? "ABC" : "ABD"); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; void main() { auto s = readln.stripRight[0 .. 3]; writeln ((s.count ('A') < 3 && s.count('B') < 3) ? "Yes" : "No"); }
D
module app; import core.bitop; import std.algorithm; import std.array; import std.bigint; import std.container.rbtree; import std.conv; import std.stdio; import std.string; import std.traits; struct Input { long h, w; } void parseInput(T)(out Input input, T file) { with (file) with (input) { auto ar = readln()...
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 t = readln.chomp.split.to!(int[]); auto m = re...
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range; import std.bigint; class Node{ Edge[] edges; int id; int flag; this(int i){ this.id = i; } void add(Edge e){ edges ~= e; } } class Edge{ Node[] nodes; this(Node n1, Node n2){ this.nodes = ...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = 3; auto s = new string[](n); foreach (i; 0..n) s[i] = readln.chomp; auto turn = 0; for (;;) { if (s[turn].empty) { writeln(cast(char)('A' + turn)); return; } auto next = cast(int)(s[turn][0] - '...
D
import std.stdio; import std.string; import std.algorithm; import std.conv; import std.math; void main() { int A, B, C; auto input = readln.split.to!(int[]); A = input[0]; B = input[1]; C = input[2]; if(A > B){ writeln(0); }else if(B/A >C){ writeln(C); }else{ writeln(B/A);...
D
import std.stdio,std.string,std.conv; void main(){ foreach(i;1..int.max){ int a = to!int(readln().chomp()); if( a==0 ){ break; } writeln("Case ",i,": ",a); } }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; 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() { readi...
D