code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.algorithm; import std.array; import std.container; import std.conv; import std.exception; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; import core.bitop; void main () { int n; while (scanf (" %d", &n) > 0) { bool...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a=new int[](n); foreach(i; 0..n) rd(a[i]), a[i]--; int cur=0, cnt=0; foreach(_; 0..n+1){ cur=a[cur]; cnt++; if(cur==1){ writeln(cnt); return; } } writeln(-1); } void rd(T...)(ref T x){ ...
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; void times(alias fun)(int n) { foreach(i...
D
import std.stdio; import std.string; import std.array; // split import std.conv; // to void main() { string s1 = chomp(readln()); string s2 = chomp(readln()); string s3 = chomp(readln()); int a = to!int(s1); // 第0要素を整数に変換 int b = to!int(s2); // 第1要素を整数に変換 int c = to!int(s3); // 第1要素を整数に変換 writeln(...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum P = 10L^^9+7; void main() { auto N = readln.chomp.to!int; auto DP = new long[][][][](4, 4, 4, N); DP[0][0][0][0] = 1; DP[0][0][1][0] = 1; DP[0][0][2][0] = 1; DP[0][0][3][0] = 1; fore...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math; void main() { auto N = readln.chomp.to!int; auto AS = readln.split.to!(int[]); if (N == 1) { writeln("0"); return; } else if (N == 2) { writeln(AS[0] == AS[1] ? "1" : "0"); return; } in...
D
void main(){ import std.stdio, std.algorithm; long n, a, b, k; rd(n, a, b, k); const long mod=998244353; const int M=1_000_00*4; long powmod(long a, long x, long mod){ if(x==0) return 1; else if(x==1) return a; else if(x&1) return a*powmod(a, x-1, mod)%mod; else return powmod(a*a%mod, 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; import std.ascii; void main() { auto n = readln.chomp.to!int; writeln(n*800-(n/15)*200); }
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.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { readln.split.to!(int[]).reduce!"(a-1)*(b-1)".writeln; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; ...
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.container, std.math, std.typecons; immutable int mod = 10^^9 + 7; immutable int inf = 20000; long s; void main() { s = readln.chomp.to!long; solve(s).writeln; } string solve(long s) { long top = s, btm = 0, mid; ...
D
import std.stdio, std.string, std.conv, std.algorithm, std.array; void main(){ auto A = readln.chomp.to!(int); auto B = readln.chomp.to!(int); auto C = readln.chomp.to!(int); auto D = readln.chomp.to!(int); auto E = readln.chomp.to!(int); int ans; if(A<0){ ans += -A*C; A=0; } if(A==0){ ans += D; }...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto hw = readln.split.to!(int[]); auto H = hw[0]; auto W = hw[1]; int[][] AS, BS; AS.length = H; BS.length = H; foreach (i; 0..H) { AS[i] = readln.split.to!(int[]); ...
D
import std.stdio; import std.string; import std.array; import std.conv; bool isRightTriangle(int a, int b, int c) { int a2 = a * a; int b2 = b * b; int c2 = c * c; return a2 + b2 == c2 || b2 + c2 == a2 || c2 + a2 == b2; } void main() { uint n = to!uint(chomp(readln())); int[][] data; for(uint i = 0; i...
D
import std.stdio, std.string, std.conv; void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], d = tmp[1]; writeln((n + 2 * d) / (2 * d + 1)); }
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; // }}} // tbh.scanner {{{ class Scanner { import std.stdio; import std.conv ...
D
void main() { string[] tmp = readln.split('/'); string y = "2018", m = tmp[1], d = tmp[2]; writeln(y, '/', m, '/', d); } 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.type...
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[10^^5] AS; void main() { auto N = readln.chomp.to!int; long r; foreach (i; 0..N) { auto A = readln.chomp.to!long; if (i != 0 && A > 0 && AS[i-1] > 0) { --A; ++...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; void main() { auto nk = readln.split.to!(long[]); auto N = nk[0]; auto K = nk[1]; writeln(N <= K ? 1 : 0); }
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
/+ dub.sdl: name "A" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); long a, b, c, k; sc.read(a, b, c, k); if (k % 2 == 0) { writeln(a-b); } else ...
D
import std.stdio, std.string, std.conv, std.algorithm, std.math; void main() { while(true) { int n = readln.chomp.to!int; if(!n)break; int y = readln.chomp.to!int; real max = 0; int maxBank; foreach(_; 0 .. n) { auto inp = readln.split.map!(t...
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong MOD =...
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 readC(T...)(size_t n,ref T t){foreach(ref v;t)...
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 n = lread(); auto s = sread(); auto t = sread(); //...
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; writeln (n * 3); for (int i = 1; i <= n; i += 2) { ...
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); alias route...
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.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.csv; import std.regex; import std.math; import core.time; import std.ascii; import std.digest.sha; import std.outb...
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 calc(int a, int b,...
D
string solve(string s){ return s.replace(',',' '); } void main(){ string s = readln().chomp(); solve(s).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() ); } ...
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!long); auto N = s[0]; auto Q = s[1]; while (Q--) { s = re...
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) = (...
D
// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.datetime, std.bigint; immutable inf = 101101101; int n, m; int[][] adj; void main() { scan(n, m); adj = n...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; const mx=1_000_00+5; auto isPrime=new bool[](mx); auto sub=new int[](mx); isPrime[2]=true; for(int i=3; i<=1_000_00; i+=2){ for(int j=3; j*j<=i; j+=2){ if(i%j==0) goto hell; } isPrime[i]=true; if(isPrime[(i+1)/2]) su...
D
import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int; bool include3(int x) { for (; x > 0; x /= 10) if (x % 10 == 3) retu...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; stri...
D
import std; void main() { readln; auto S = readln.split[0].to!string; auto N = S.length; size_t[][char] rgb; rgb['R'] = [], rgb['G'] = [], rgb['B'] = []; foreach (n, c; S) { rgb[c] ~= n; } size_t ans; ans += rgb['R'].length * rgb['G'].length * rgb['B'].length;...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[10^^5] CS; void main() { auto nq = readln.split.to!(int[]); auto N = nq[0]; auto Q = nq[1]; auto S = readln.chomp.to!(char[]); auto pre = 'T'; foreach (i, c; S) { if (i) CS[i] =...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int[] a; for (int i = 0; i < 4; i++) { a ~= readln.chomp.to!(int); } writeln(min(a[0], a[1]) + min(a[2], a[3])); }
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.c...
D
void main() { problem(); } void problem() { const N = scan!int; const M = scan!int; const X = scan!int; auto C = new int[N]; int[][] A; foreach(i; 0..N) { C[i] = scan!int; A ~= scan!int(M); } int[] bitNums = 12.iota.map!(x => 2.pow(x)).array; void solve() { int answer = int.max; ...
D
import std.stdio; import std.string; import std.format; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.concurrency; import std.traits; import std.uni; import c...
D
// Vicfred // https://atcoder.jp/contests/abc176/tasks/abc176_c // greedy import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main() { long n = readln.chomp.to!long; long[] a = readln.split.map!(to!long).array; long last = a[0]; long ans = 0; for(int...
D
import std.algorithm, std.array, std.conv, std.stdio, std.string; void main() { readln; auto l = readln.chomp; l.count("ABC").writeln; }
D
import std.stdio; import std.string; import std.conv; import std.array; void main() { string s; string op = "+"; int res = 0; while(1) { s = readln(); int a = to!int(chomp(s)); if(op[0] == '+') res += a; else if(op[0] == '-') res -= a; else if(op[0] == '*') res *= a; else res /= a; op =...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto hmk = readln.split.to!(int[]); auto h1 = hmk[0]; auto m1 = hmk[1]; auto h2 = hmk[2]; auto m2 = hmk[3]; auto K = hmk[4]; auto s = h1 * 60 + m1; auto e = h2 * 60 + m2...
D
import std.stdio, std.string, std.array, std.conv; void main() { int[] a = readln.chomp.split.to!(int[]); if (a[0] < a[1]) { "a < b".writeln; } else if (a[0] > a[1]) { "a > b".writeln; } else { "a == b".writeln; } }
D
import std.stdio; import std.string; import std.array; import std.conv; uint figure(uint num) { if(num == 0) return 0; else return figure(num / 10) + 1; } void main() { string[][] inputs; while(true) { auto s = readln(); if(stdin.eof()) break; else inputs ~= split(s); } foreach(input; inputs)...
D
import std; void calc(long x) { foreach (i; -200L..200L) { foreach (j; -200L..200L) { long y = i^^5 - j^^5; if (x == y) { writeln(i, " ", j); return; } } } } void main() { long x; scan(x); calc(x); } void scan(T...)(r...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto n = readln.chomp.to!int; auto as = readln.split.to!(int[]); int even_cnt; int quart_cnt; foreach (a; as) { if (!(a&1)) { ++even_cnt; if (!(a&2)) ++quart_cnt; ...
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 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 : File, stdin; import std.conv : to; import std.array : split; import ...
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math; int read() { return readln.chomp.to!int; } int[] reads() { return readln.split.to!(int[]); } void main() { readln; writeln(reads.map!(i => i=i-1).sum); }
D
import std.stdio, std.string, std.conv; void main() { int n = readln.chomp.to!int; int[] a = [1, 5, 10, 25]; int coin = 0; foreach_reverse (x; a) { coin += n / x; n %= x; } coin.writeln; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int a, b; scan(a, b); int n = b - a; int ans = n * (n - 1) / 2 - a; writeln(ans); } void...
D
import std.stdio; import std.string; import std.conv; void main() { string[] inputs = split(readln()); bool a = inputs[0] == "H"; bool b = inputs[1] == "H"; if(a == b) 'H'.writeln; else 'D'.writeln; }
D
import std; // dfmt off T lread(T=long)(){return readln.chomp.to!T;} T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);} void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;} void scan(TList...)(ref TList Args){auto line =...
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() { for (...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { string s; s = readln.chomp; auto cnt = new int[](26); foreach (ch ; s) { cnt[ch - 'a']++; } int odd; foreach (i ; 0 .. 26) { if (cnt[i] & 1) odd++; } if (odd > 1) ...
D
import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.complex; import std.container; import std.conv; import std.functional; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp; auto DP = new long[](2019); DP[0] = 1; int n, d = 1; foreach_reverse (c; S) { n = ((c - '0').to!int * d + n) % 2019; (d *= 10) %= 2019; ...
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; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void times(alias pred)(int n) { foreach(i; 0..n) pred(); } auto ...
D
void main(){ int r, g, b; scanf("%d %d %d", &r, &g, &b); ( (100*r+10*g+b)%4?"NO":"YES").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行に同一型の複数入力...
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; // }}} // tbh.scanner {{{ class Scanner { import std.stdio; import std.conv ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.math; void main() { char[] s = readln.chomp.to!(char[]); int k; scan(k); foreach (i ; 0 .. s.length.to!int - 1) { if (s[i] == 'a') continue; int t = 26 - (s[i] - 'a'); if (t <= k) { ...
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 H = readln.split.to!(int[]); int ans; foreach (i, height; H) { bool flag = true; foreach (h; H[0..i]) if (h > height) fl...
D
/+ dub.sdl: name "E" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int n; sc.read(n); long[] a = new long[n], b = new l...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; void main() { auto nk = readln.split.to!(long[]); auto N = nk[0]; auto K = nk[1]; writeln(N <= K ? 1 : 0); }
D
import std.stdio; import std.string; import std.format; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.concurrency; import std.traits; import std.uni; import c...
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; int[][][] MEMO; MEMO.length = N; foreach (i; 0..N) { auto A = readln.chomp.to!int; MEMO[i].length = A; foreach (j; 0..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, core.stdc.stdio; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto ok = new bool[](N); ...
D
/+ dub.sdl: name "B" dependency "dcomp" version=">=0.7.4" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); int[3] cnt; string s; sc.read(s); int n = s.length.to!int; foreach (c; s) cnt[c - ...
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, k; readV(n, k); writeln(k...
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(s.co...
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 w = readln.chomp; int[char] cnt; foreach (e; w) { cnt[e]++; } auto f...
D
import std.stdio,std.math,std.string,std.conv,std.typecons,std.format; import std.algorithm,std.range,std.array; T[] readarr(T=long)(){return readln.chomp.split.to!(T[]);} void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;} //END OF TEMPLATE void main(){ ulong n,k; ...
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.map!(a=>a-'0').array; auto res = n.sum; i...
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void calc(long[] a) { long[long] freq; foreach (x; a) freq[x]++; long sum = 0; foreach (v; freq.values) { ...
D
import std.stdio, std.string, std.array, std.conv; void main() { int n = readln.chomp.to!int; int[] a = readln.chomp.split.to!(int[]); int q = readln.chomp.to!int; int[] m = readln.chomp.split.to!(int[]); bool[] check = new bool[2001]; foreach (i; 0 .. 1<<n) { int sum = 0; forea...
D
import std.stdio, std.string, std.array, std.conv, std.range; void main() { int[] tmp = readln.chomp.split.to!(int[]); int n = tmp[0], k = tmp[1], q = tmp[2]; int[] points = repeat(k-q, n).array; foreach (i; 0 .. q) { int a = readln.chomp.to!int - 1; ++points[a]; } foreach (x; p...
D
import std.stdio; import std.algorithm; import std.string; import std.conv; import std.range; int cnt(int x) { x = x - ((x >>> 1) & 0x55555555); x = (x & 0x33333333) + ((x >>> 2) & 0x33333333); x = (x + (x >>> 4)) & 0x0f0f0f0f; x = x + (x >>> 8); x = x + (x >>> 16); return x & 0x3f; } void main() { in...
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto N = lread(); auto D = new long[](N); foreach (i; 0 .. N) { auto d = lread(); D[i] = d; } // writeln(D); auto...
D
import std.stdio; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.csv; import std.regex; import std.math; import core.time; import std.ascii; import std.digest.sha; import std.outb...
D
void main() { problem(); } void problem() { auto N = scan!int; auto L = scan!long(N); long solve() { long ans; foreach(x; 0..N-2) { auto lx = L[x]; foreach(y; x+1..N-1) { auto ly = L[y]; if (lx == ly) continue; foreach(z; y+1..N) { auto lz = L[z]; ...
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
void main() { long n, s; rdVals(n, s); long[] a = rdRow; long[][] dp = new long[][](n+1, s+1); foreach (i; 0 .. n+1) dp[i][0] = 1; long result; foreach (i, x; a) { foreach (j; 0 .. s+1) { dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod; if (j - x < 0) ...
D
import std.conv,std.string,std.stdio; void main(){ immutable x=readln().chomp().to!int(); writeln(x*x*x); }
D
import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if...
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 x = readln.chomp.split.to!(int[]); auto s = readln.chomp; auto ab = x[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; import std.container; alias sread = () => readln.chomp(); alias Point...
D
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional; void main() { auto tmp = readln.split.to!(int[]); writeln(abs(tmp[0] - tmp[1]) < abs(tmp[0] - tmp[2]) ? "A" : "B"); }
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.c...
D
// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; int n, q, com, x, y; void main() { scan(n, q); auto sg = SegTree(n); while (q--) { scan(com, x, y); ...
D
void main() { long k = rdElem; long a, b; rdVals(a, b); foreach (i; a .. b+1) { if (i % k == 0) { "OK".writeln; return; } } "NG".writeln; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; enum double eps = 1.0e-9; T rdElem(T = long)() ...
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 ...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} ...
D
import std.stdio; import std.algorithm; import std.string; import std.range; import std.array; import std.conv; import std.complex; import std.math; import std.ascii; import std.bigint; import std.container; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split())); } auto readInt() ...
D