code
stringlengths
4
1.01M
language
stringclasses
2 values
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto par=new int[](n); par[0]=-1; foreach(int i; 1..n){ int p; rd(p); par[i]=(p-1); } auto leaf=new bool[](n); foreach(i; 0..n){ auto c=count(par, i); if(c==0) leaf[i]=true; } foreach(i; 0..n)if(leaf[...
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.algorithm; import std.conv; import std.math; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; int [int] k; foreach (ref c; 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.string; void solve() { auto N = readln.chomp.to!int; auto S = readln.chomp; int pos = -1; foreach (i; 0..N) if (S[...
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.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 K = s[1]; long x = K % 2 == 1 ? K / 2 ...
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 c = readln.splitter.map !(to !(int)).array; auto a = readln.splitter.map !(to !(int)).array; auto...
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(){ import std.stdio, std.string, std.conv, std.algorithm; import std.typecons; int n; rd(n); auto y=readln.split.to!(long[]); alias pt=Tuple!(long, "x", long ,"y"); pt[] f(long dy, long dx){ pt[] rt; foreach(x; 1..n){ long dy_=y[x]-y[0]; if(dy*x!=dy_*dx) rt~=pt(x, y[x]); ...
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.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { string s, t; scan(s); scan(t); int n = s.length.to!int, m = t.length.to!int; auto dp = new int[][](n + 1, m + 1); foreach (i ; 1 .....
D
import std; void main() { const N = readln().chomp().to!long(); ulong sum = 0; foreach (i; 1 .. N + 1) { if (i % 3 == 0) continue; if (i % 5 == 0) continue; sum += i; } writeln(sum); }
D
void main() { long[] tmp = rdRow; long n = tmp[0], m = tmp[1], k = tmp[2]; foreach (i; 0 .. n+1) { foreach (j; 0 .. m+1) { long s = i * m + j * n - 2 * i * j; if (s == k) { "Yes".writeln; return; } }...
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 =...
D
import std; int calc(long k, int[] a) { a = [0] ~ a; auto used = new long[a.length]; used[] = -1; int p = 1; long step = 0; while (true) { if (step == k) { return p; } if (used[p] != -1) { // writeln("loop ", step - used[p]); auto m =...
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(string s) { ...
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional; import std.algorithm, std.container; void scanValues(TList...)(ref TList list) { auto lit = readln.splitter; foreach (ref e; list) { e = lit.fornt.to!(typeof(e)); ...
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_007; void main() { int x, a; scan(x, a); writeln(x < a ? 0 : 10...
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=(...
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
import std.stdio; import std.conv; import std.string; import std.algorithm; import std.array; void main() { auto tmp = readln.split.map!(s => s.chomp[0]).array; auto X = tmp[0]; auto Y = tmp[1]; writeln(X == Y ? "=" : X < Y ? "<" : ">"); }
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; int[string] words; auto f = true; auto prev = re...
D
void main() { int n = readln.chomp.to!int; int[] t = readln.split.to!(int[]); int m = readln.chomp.to!int; int[] p = new int[m], x = new int[m]; foreach (i; 0 .. m) { int[] tmp = readln.split.to!(int[]); p[i] = tmp[0], x[i] = tmp[1]; } foreach (i; 0 .. m) { writeln(x[...
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; } /* i番目までの子供にj個の飴を分ける分け方の数 x...
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() { auto s = iota(3).map!(i => readln.chomp.map!(ch => ch - 'a').array...
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.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.numeric; void main() { int n; int[] a; scan(n); a = readln.split.to!(int[]); int am = a.reduce!max; auto cnt = new int[](n); foreach (i ; 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 readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int a, b, c; readV(a, b, c); wri...
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 N = readln.chomp; int s; foreach (c; N) s += (c - '0').to!int; writeln(s%9 == 0 ? "Yes" : "No"); }
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
void main() { long n, m; rdVals(n, m); long[][] edge = new long[][](n); foreach (i; 0 .. m) { long x, y; rdVals(x, y); --x, --y; edge[x] ~= y; } long[] dp = new long[n]; long dfs(long x) { if (dp[x]) return dp[x]; long result; ...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { int n...
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(); void main(...
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.conv,std.string; void main(){ foreach(_;0..readln.chomp.to!int){ int point,base,_out; while(1){ final switch(readln.chomp){ case "HIT": if(base==3)++point; else ++base; break; ...
D
void main() { long[] tmp = readln.split.to!(long[]); long n = tmp[0], t = tmp[1]; long[] a = readln.split.to!(long[]); long x = t; foreach (i; 0 .. n-1) { x += min(t, a[i+1]-a[i]); } x.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import st...
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return read...
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.chomp; auto Q = readln.chomp.to!int; DList!dchar que; foreach (s; S) que.ins...
D
unittest { assert( [ "a" ].parse.expand.solve == "vowel" ); assert( [ "z" ].parse.expand.solve == "consonant" ); assert( [ "s" ].parse.expand.solve == "consonant" ); } import std.conv; import std.range; import std.stdio; import std.typecons; void main() { stdin.byLineCopy.parse.expand.solve.writeln; } auto par...
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; int lo = int.max; int hi = 0; bool ok = true; for...
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; long n, s; void main() { scan(n); scan(s); if (n == s) { writeln(n + 1); return; } for...
D
import std.stdio, std.string, std.conv; import std.algorithm, std.array; auto solve(string s_) { immutable N = s_.to!int(); auto a = new int[][N]; foreach(i;1..N) a[readln.chomp.to!int()-1]~=i; int dfs(int i) { int m=0; foreach(int k,v;a[i].map!dfs().array().sort!"a>b"().array()) ...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int a, b, c; readV(a, b, c); au...
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.array; void main() { auto reader = readln.split; int N = reader[0].to!int; int K = reader[1].to!int; string S = readln.chomp; int[] cnt; int beforeI = 0; if (S[0] == '0') cnt ~= 0; foreach (i; 0..N){ if (S[i] != S...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto s = readln.chomp.to!(char[]); int sum = 0; foreach (c; s[1 .. $]) { if (c == 'E') sum++; } auto mn = sum; foreach (i; 1 .. n) { if (s[i - 1] == 'W') sum++; if (s[i] == 'E') sum--; ...
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.typecons; alias Path = Tuple!(int, "from", int, "to", int, "weight"); auto make_node() { int[100][100] ret; foreach (ref l; ret) foreach (ref e; l) e = int.max / 2; return ret; } auto NS = make_node(); Path[1000] PS; void main() { ...
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 f = true; if (!(s.length % 2)) { ...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; auto s = readln.chomp.to!(char[]); char[] t; foreach (i; 0 .. (s.length)) { if (i % 2 == 0) { t ~= s[i]; } } writeln(t); } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.con...
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 a = aryread(); auto ans = new long[](2 * (10 ^^ 5) + 10); foreach (i; 0 .. n - 1) { ans[a[i]] += 1; } ...
D
import std.stdio, std.conv, std.string, std.math; void main(){ auto ip = readln.split.to!(int[]); if(ip[0] + ip[1] < 10){ writeln(ip[0] + ip[1]); } else { writeln("error"); } }
D
import std.stdio,std.string,std.array; void main(){ string line,sw; size_t total=0; sw = readln().chomp(); while( 1 ){ line = readln().chomp(); if( line == "END_OF_TEXT" ){ break; } foreach( w ; line.split() ){ if( toLower(w) == toLower(sw) ) total++; } } writeln( total ); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; long P = 10^^9+7; long[1001] F, RF; long pow(long x, long n) { long y = 1; while (n) { if (n%2 == 1) y = (y * x) % P; x = x^^2 % P; n /= 2; } return y; } long ...
D
import std.stdio; import std.string; import std.algorithm; import std.conv; import std.array; import std.math; void main() { foreach(line; stdin.byLine) { auto hw = line.chomp.split.map!(to!int); auto h = hw[0], w = hw[1]; if(h == 0 && w == 0) return; foreach(i; 0 .. h){ ...
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; void position(int n, int row, int col, char[6][1000] rows) { rows[row][col] = rows[row][col + 1] = '+'; printf("YES\n"); for (int i = 0; i < n; i++) { printf("%s\n", rows[i].ptr); } } void main() { int n; scanf("%d", &n); char[6][1000] rows; for (int i = 0; i < n; i++) { scanf("%s", ro...
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 main(){ (readln.chomp.to!int / 3).writeln; }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; string my_readln() { return chomp(readln()); } long mod = pow(10, 9) + 7; long moda(long x, long y) { return (x + y) % mod; } long mods(long x, long y) { return ((x + mod) - (y % mo...
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
/+ dub.sdl: name "D" dependency "dcomp" version=">=0.7.3" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; // import dcomp.algorithm; int main() { Scanner sc = new Scanner(stdin); int n, k; sc.read(n, k); int[2][] p = new int[2][n]; fore...
D
// Cheese-Cracker: cheese-cracker.github.io void theCode(){ ll n = scan; ll tim = (n / 2) * 5; if(n % 2 != 0) tim += 5; tim = max(tim, 15); writeln(tim); } void main(){ long tests = scan; // Toggle! while(tests--) theCode(); } /********* That's All Folks! *********/ import std.st...
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.0.2" +/ import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop; // import dcomp.scanner; bool solve(bool[] a) { int n = (a.length.to!int + 1) / 2; int l = n-1; while (l) { if (a[l-1] == a[l]) break; l--; } ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.math; void main() { int a, b, c, x, y; scan(a, b, c, x, y); int ans = 1<<30; foreach (i ; 0 .. 2 * 10^^5 + 1) { int xr = max(0, x - i / 2); int yr = max(0, y - i / 2); int tmp = xr * a + yr...
D
import std.algorithm; import std.container; import std.conv; import std.functional; import std.math; import std.meta; import std.random; import std.range; import std.stdio; import std.string; import std.traits; import std.typecons; void main() { int ans = 0; foreach (c; readln.chomp) if (c == '+') ans++...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main() { auto n = readln.chomp.to!int; int[][][] f = new int[][][](n, 5, 2); int[][] p = new int[][](n, 11); for (int i = 0; i < n; ++i) { auto l = readln.chomp.split.map!(to!int).array; for (int j = 0; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; int[500][500] MS, CS; void main() { auto nmq = readln.split.to!(int[]); auto N = nmq[0]; auto M = nmq[1]; auto Q = nmq[2]; foreach (_; 0..M) { auto lr = readln.split.to!(int[]); ++MS[lr[0]-1]...
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() { auto c = new string[](2); c[0] = readln.chomp; c[1] = readln.chomp; string ans = (equal(c[0], c[1].retro)) ? "YES" : "NO"; writeln(ans...
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 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; void main() { while(true) { int num = readln.chomp.to!int, cnt; if(!num)break; while(num) cnt += num /= 5; cnt.writeln; } }
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.string, std.conv; import std.algorithm, std.array, std.range; auto solve(string S_) { auto NM=S_.split.map!(to!int)(); immutable N=NM[0], M=NM[1]; auto A=new int[][N]; foreach(ref a;A) a=readln.split.map!(to!int).array(); auto c=new int[M+1]; foreach(a;A) ++c[a[0]]; int...
D
import std.stdio; import std.string; import std.conv; void main() { int[] arr = readln.chomp.split.to!(int[]); int d = arr[0], n = arr[1]; if (d == 0) { if (n == 100) writeln(101); else writeln(n); } else if (d == 1) { if (n == 100) writeln(100 * n + 100); else writ...
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 calc2(int lo, int h...
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.ascii; import std.concurrency; import std.traits; import...
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.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; void main() { auto n = readln.chomp.to!long; string result; while (n != 0) { long m = n % -2; // writeln([n,m]); ...
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; auto gcd(T)(T x, T y) { if (x < y) x.swap(y); while (y > 0) { auto r = x % y; x = y; y = r; } return x; } void main() ...
D
import std.stdio, std.conv, std.array, std.string; import std.algorithm; import std.container; import std.range; import core.stdc.stdlib; import std.math; void main() { auto N = readln.chomp.to!ulong; ulong answer = N-1; for(ulong i = 1; i * i <= N; i++) { if (N % i != 0) continue; auto j = N/i; au...
D
void main() { int x = readln.chomp.to!int; int d = x / 100, r = x % 100; writeln(d >= (r + 4) / 5 ? 1 : 0); } 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; imp...
D
void main() { long n = readln.chomp.to!long; long[] a = readln.split.to!(long[]); long[] l = new long[n+1]; foreach (i; 0 .. n) { l[i+1] = gcd(l[i], a[i]); } long[] r = new long[n+1]; foreach_reverse (i; 0 .. n) { r[i] = gcd(r[i+1], a[i]); } long result; ...
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { int c=0; foreach(s;stdin.byLine()) { bool f=true; foreach(i;0..s.length/2+1) if(s[i]!=s[$-i-1]) { f=false;break;} if(f) ++c; } writeln(c); }
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) = () ...
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; auto ai = readln.split.map!(to!long); writeln(ai.reduce!(min), " ", ai.reduc...
D
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; void main(){ auto S=readln.chomp; if(S[0]=='a' && S[1]=='b' && S[2]=='c')writeln("Yes"); else if(S[0]=='a' && S[1]=='c' && S[2]=='b')writeln("Yes"); else if(S[0]=='b' && S[1]=='a' && S[2]=='c')writel...
D
import std.stdio; import std.string; import std.conv; void main() { while (true) { auto input = readln().split; if (input.length == 0) break; writeln(to!int(input[0]) + to!int(input[1])); } }
D
void main() { writeln(48 - readln.chomp.to!int); } 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
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 { string s; } void parseInput(T)(out Input input, T adapter) { with (input) { s = adapter.readln(); } } ...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional; void main() { readln.chomp.to!int.pipe!(K => (K+1)/2 * (K/2)).writeln; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a, b; scan(a, b); auto map = new char[][](100, 100); fillAll(map, '.'); foreach (i ; 0 .. 50) { foreach (j ; 0 .. 50) { map[i][j] = '#'; } } a--; foreac...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp; writeln(s.canFind('9') ? "Yes" : "No"); }
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 nt = readln.chomp.split.to!(int[]); auto res = int.max; foreach(_; 0..nt[0])...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto a = readln.chomp.to!int; auto b = readln.chomp.to!int; auto h = readln.chomp.to!int; writeln((a + b) * h / 2); }
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; long powMod(long x, lon...
D
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons; import core.stdc.stdio; // foreach, foreach_reverse, writeln alias P = Tuple!(int,int); int k; class UnionFind { int score; int[] data, cnt; this(int n) { data = new int[n]; cnt = new int[n]; data[] = -1;...
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { long a, b, ab, x, y; scan(a, b, ab, x, y); long cost1, cost2, cost3, cost4; cost1 = a * x + b * y; cost2 = ab * 2 * max(x, y); long ...
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 =...
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