code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.array, std.conv, std.typecons, std.algorithm; T diff(T)(const T a, const T b) { return a > b ? a - b : b - a; } T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } T[] readToArray(T)() { return readln.split.to!(T[]); } void main() { const ip = readToArray!(long); ...
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 p = iota(n).map!(i => readln.chomp.to!int).array; auto dp = new int[](n + 1); int ans = 1<<30; foreac...
D
import std; void main() { auto S = readln.split[0]; if (S == "ABC") writeln("ARC"); else writeln("ABC"); }
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; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return r...
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
// 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, p; int[] a; void main() { scan(n, p); a = readln.split.to!(int[]); int lim = n * 100; auto dp = new...
D
// cheese-cracker [2022-01-27] void solve(){ auto n = scan!int; auto a = scanArray; auto b = scanArray; long mn = min(a[0], b[0]); long mx = max(a[0], b[0]); for(int i = 0; i < n; ++i){ mn = max(min(a[i], b[i]), mn); mx = max(max(a[i], b[i]), mx); } writeln(mn * mx); } ...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.random; struct ImplicitKeyTreapNode(Value, Extra=void) { enum has_extra = !(is (Extra == void)); ImplicitKeyTreapNode!(Value, Extra)* left, right; Value value; static if (...
D
import std.stdio; import std.array; import std.string; import std.conv; void main() { int x = to!int(chomp(readln())); writeln(x * x * x); }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long a = read.to!long; long b = r...
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto na = readln.split.to!(int[]); auto N = na[0]; auto A = na[1]; auto XS = readln.split.to!(int[]); auto MEMO = new long[50*50+1][50+1][50+1]; foreach (ref a; MEMO) { foreach (...
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 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.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional; import std.algorithm, std.container; void main() { long A = scanElem; long B = scanElem; long cost; for(int i =0 ;i < 2;i++) { if(A<B){ cost += B; B...
D
void main() { long n, m; rdVals(n, m); Edge[] edge = m.rdCol!Edge; long[][] dist = new long[][](n, n); foreach (i; 0 .. n) { foreach (j; 0 .. n) { if (i == j) dist[i][j] = 0; else dist[i][j] = inf; } } foreach (ref e; edge) { ...
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { auto s = readln().chomp(); string t; for(int i=0; i<s.length; ) { if(startsWith(s[i..$],"apple")) t~="peach", i+=5; else if(startsWith(s[i..$],"peach")) t~="apple", i+=5; else t~=s[...
D
void main() { auto K = ri; long res; foreach(a; 1..K+1) foreach(b; 1..K+1) foreach(c; 1..K+1) { res += gcd(a,gcd(b, c)); } res.writeln; } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; import std.math...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int k; rd(k); int[] digit; while(k){ digit~=k&1; k/=2; } reverse(digit); struct E{int u, v, w;} E[] edges; int n=1; k=1; foreach(d; digit[1..$]){ foreach(ref e; edges) e.w*=2; edges~=E(n, n+1, 0); edges~=E(n, n...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto hw = readln.split.to!(int[]); auto H = hw[0]; auto W = hw[1]; string[][] map; map.length = H; foreach (i; 0..H) { map[i] = readln.chomp.split(""); } foreach (y; 0..H) { ...
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 n, x, t; scan(n, x, t); // writeln(n, x, t); long c...
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 a = readln.chomp; auto b = readln.chomp; aut...
D
void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], m = tmp[1]; int[] a = new int[n], b = new int[n]; foreach (i; 0 .. n) { tmp = readln.split.to!(int[]); a[i] = tmp[0], b[i] = tmp[1]; } int[] c = new int[m], d = new int[m]; foreach (i; 0 .. m) { tmp = ...
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() { readint(); auto ss = readints(...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, k; rd(n, k); auto x=new long[](n), y=new long[](n); foreach(i; 0..n) rd(x[i], y[i]); long mn=5_000_000_000_000_000_000; foreach(i1; 0..n)foreach(i2; (i1+1)..n){ foreach(j1; 0..n)foreach(j2; (j1+1)..n){ auto x1=x[i1], x2=x...
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.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 = min(x, y) * min(2*c, a + b); if (x > y) { ans += (x - y) * min(2*c, a); } else { ans += (y - x) * min(2*c, b); } ...
D
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.functional; void main() { auto N = readln.chomp.to!long; auto n = N; auto f = 0; while (n > 0) { f += n % 10; n /= 10; } writeln(N % f == 0 ? "Yes" : "No"); }
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.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { string s = readln.chomp; int c; foreach (i; 0..s.length-1) { if (s[i] != s[i + 1]) { c++; } } writeln(c); ...
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 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; void main(){ string c1=readln(); string c2=readln(); if(c1[0]==c2[2]&&c1[1]==c2[1]&&c1[2]==c2[0]) writeln("YES"); else writeln("NO"); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import std.stdio,std.string,std.conv; int main() { int n; while((n = readln.chomp.to!int) != 0) { int ans = 0; while((n /= 5) != 0) { ans += n; } ans.writeln; } return 0; }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; enum MOD = 1_000_000_007; struct Number { long x; this(long x) { this.x = (x % MOD + MOD) % MOD; } Number opBinary(string op)(long x) { return Number(mixin("this.x"~op~"x")); } ...
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); string s; sc.read(s); int n = s.length.to!int; bool check(string t) { return ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; void main() { auto nm = readln.split.to!(int[]); auto N = nm[0]; auto M = nm[1]; int[][] aa; foreach (i; 0..N) aa ~= readln.split.map!(a => a.to!int-1).array; auto ss = new bool...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto X = readln.chomp.to!int; int r = 1; foreach (i; 1..X+1) { foreach (j; 2..X+1) { if (i^^j <= X) r = max(r, i^^j); } } writeln(r); }
D
import std.stdio, std.string, std.array; import std.algorithm, std.regex; void main(){ "ATA CGC".find(readln[0])[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 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() { long N; scan(N); auto ans = N * (N - 1) / 2...
D
void main() { auto N = ri; string res; if(N == 0) res = "0"; while(N != 0) { if(abs(N)%2 == 1) { N--; res ~= '1'; } else res ~= '0'; N/=-2; } auto arr = res.to!(dchar[]); arr.reverse(); arr.writeln; } // =================================== import std.stdio; import std.string; import std.functional...
D
void main() { long a, b, c; rdVals(a, b, c); if (a + b >= c) { "No".writeln; return; } long x = a * b; long y = c - a - b; writeln(4 * x < y * y ? "Yes" : "No"); } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; T rdElem(T = long)() if (!is(T == struct)) { re...
D
void main() { long n = rdElem; long result = inf; for (long i = 1; i * i <= n; ++i) { if (n % i == 0) { result = min(result, i+n/i-2); } } result.writeln; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; T rdElem(T = long)() if (!is(T == struct)) { ...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); if (n == 1) { writeln("Hello World"); } else { int a, b; rd(a); rd(b); writeln(a + b); } } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; au...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int N = readln.chomp.to!(int); int[] A = readln.chomp.split.to!(int[]); if (N == 1) { writeln(1); return; } int ans1; for (int i = 1; i < N; ) { i += max(plus(A, i), minus(A, i)) + 1; ans1++; if ...
D
void main(){ import std.stdio, std.conv, std.string, std.algorithm; int n; rd(n); int f(int x){ int ret=0; while(x>0){ ret+=x%10; x/=10; } return ret; } int mn=1_000_000_000; for(int a=1; a<n; a++){ int b=n-a; mn=min(mn, f(a)+f(b)); } writeln(mn); } void rd(T......
D
import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime; void main() { auto n = readln.chomp.to!int; writeln(n*(n+1)/2); }
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(); // writeln(n); long 余り = n % 100; // w...
D
/+ dub.sdl: name "D" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) sc.read!true; import std.typecons; alias E = Tuple!(int, "to", long, "dist")...
D
import std.stdio, std.string, std.conv, std.math; void main() { int n = readln.chomp.to!int; long debt = 100000; foreach(i;0..n) debt = ((((debt + (debt*0.05)) / 1000.0).ceil) * 1000).to!long; debt.writeln; }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; import core.stdc.stdlib; void main() { auto N = scanElem; auto M = scanElem; long[] list; list.length = N; foreach(i; 0...
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.to!(int[]); } void main() { int n = readint; int[] a; int[string] db; ...
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; int[char] k; foreach (e; s) { k[e]++...
D
import std.stdio, std.string, std.conv; import std.algorithm; void main() { for(string s_; (s_=readln().chomp()).length;) { auto ab = s_.split.map!(to!int)(); immutable a=ab[0], b=ab[1]; if(0<a) writeln("Positive"); else if(a<=0 && 0<=b) writeln("Zero"); else if(b<0 && (...
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; void main() { int n; n = readln.chomp.to!int; while (n) { auto a = new int[9][9], b = new int[9][9], c = new in...
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; scan(s); foreach (cmb ; 0 .. 16) { string t; t ~= (cmb & 1) ? "AKIH" : "KIH"; t ~= (cmb & 2) ? "AB" : "B"; ...
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 k = readln.chomp.to!int; auto h = k / 2; if (k % 2) { ...
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[] xs, ys; long[] hs; foreach (_; 0..N) { auto xyh = readln.split.to!(int[]); xs ~= xyh[0]; ys ~= xyh[1]; hs ~= xyh[2]; ...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto D = [s[1], s[2]]; auto G = new int[]...
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); while (n > 0) { if (n % 10 == 9) { writeln("Yes"); return; } n /= 10; } writeln("N...
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 rs = S.dup; rs.reverse(); if (S != rs) { writeln("No"); return; } auto N = S.length; auto s = S[0..(N-1)/2]; rs = s.dup; r...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; alias Pair = Tuple!(int, "a", int, "b"); void main() { ...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.numeric; import std.stdio; import std.string; void main() { string n = readln().chomp; int[] a = readln().chomp.split(" ").to!(int[]); int count = 0; int max = 100; for (int i = 1; i < a.length; ++i) { ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void get(Args...)(ref Args args) { import std.traits, std.meta, std.typecons; static if (Args.length == 1) { alias Arg = Args[0]; static if (isArray!Arg) { ...
D
void main(){ int n = inelm(); ( 800*n - (n/15).to!int()*200).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[] l...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto ha = readln.split.to!(int[]); auto H = ha[0]; auto A = ha[1]; writeln((H+A-1)/A); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, m; rd(n, m); auto g=new int[][](n, 0); foreach(_; 0..m){ int a, b; rd(a, b); a--; b--; g[a]~=b; g[b]~=a; } auto c=new int[](n); fill(c, -1); bool dfs(int i, int w, int p=-1){ c[i]=w; bool ret=true; for...
D
import std.stdio, std.string, std.conv, std.math, std.regex; void main() { auto n = readln.split.to!(int[]); writeln((n[0] - 1) * (n[1] - 1)); }
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
// cheese-cracker [2022-01-31] void solve(){ auto s = scan!(dchar[]); long on = 0; long off = 0; long res = 0; foreach(c; s){ on += (c == '1'); off += (c == '0'); if(max(on, off) > min(on, off) && max(on, off) > 1){ res = max(res, min(on, off)); } } ...
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.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; writeln(N); } }
D
void main() { int n = readln.chomp.to!int; string s = readln.chomp; auto g = s.group.array; string bra, ket; foreach (i; 0 .. n) { bra ~= '('; ket ~= ')'; } int l, r; foreach (x; g) { if (x[0] == '(') { r += x[1].to!int; } else { in...
D
import std.stdio,std.conv,std.string,std.algorithm; void main(){ auto s=readln(); writeln("2018",s[4..10],); }
D
// Cheese-Cracker: cheese-cracker.github.io const ll PRIME = 10^^9 + 7; void play(){ ll n, x, pos; n = rd; x = rd; pos = rd; ll clo = x-1, chi = n - x; ll res = 1; int lo = 0, hi = n.to!int; while(lo < hi){ int midd = (lo + hi)/2; show(midd, pos, clo, chi); if(midd <= p...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.to!(dchar[]); auto T = readln.to!(dchar[]); dchar[dchar] smemo, tmemo; foreach (i, s; S) { auto t = T[i]; if (s in smemo && t in tmemo) { if ...
D
// Cheese-Cracker: cheese-cracker.github.io void theCode(){ int n = scan!int; auto arr = scanArray!int; auto ix = new int[2*n+1]; ix[] = -1000_000_0; for(int i = 0; i < n; ++i){ ix[arr[i]] = i+1; } int cnt = 0; for(int k = 2; k <= 2*n; ++k){ for(int i = 1; i * i < k; ++i...
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.algorithm, std.string, std.range, std.array, std.stdio, std.conv; bool check(string s) { if (s.length % 2) { return false; } string a = s[0..$/2], b = s[$/2..$]; return a == b; } void main() { string s = readln.chomp; size_t del = 1; while (del < s...
D
import std; import core.bitop; // dfmt off 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[]); void aryWrite(T = long)(T[] ary){ ary.map!(x => x.text()).join(' ')...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; Node node; foreach (_; n.iota) { auto rd = readln.chomp.splitter(' '), cmd = rd.front; switch (cmd) { case "insert": rd.popFront; node.insert(rd.front.to!int); break; ...
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
// Vicfred // https://atcoder.jp/contests/abc168/tasks/abc168_a import std.stdio; import std.conv; import std.string; void main() { int n = readln.chomp.to!int; n = n%10; switch(n) { case 0, 1, 6, 8: writeln("pon"); break; case 3: writeln("bon"); bre...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto K = readln.chomp.to!int; auto S = readln.chomp; if (S.length <= K) { writeln(S); } else { writeln(S[0..K], "..."); } }
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; void main() { auto abc = readln.split.to!(int[]); auto A = abc[0]; auto B = abc[1]; auto C = abc[2]; writeln((A < C && C < B) || (B < C && C < A) ? "Yes" : "No"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto s=new char[][](n); foreach(i; 0..n) s[i]=readln.chomp.to!(char[]); long[char] cnt; cnt['M']=cnt['A']=cnt['R']=cnt['C']=cnt['H']=0L; foreach(i; 0..n){ auto c=s[i][0]; if(c in cnt) cnt[c]++; } char[int] p; ...
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 data = readln.split.to!(int[]); auto A = data[0], B = data[1], C = data[2]; if (A+B >= C-1) writeln(B+C); else writeln( B + A+B+1 ); }
D
import std.stdio; import std.algorithm; import std.conv; import std.array; import std.string; import std.math; import std.functional; import std.range; import std.typecons; import std.format; void main(string[] args) { readln.solve.writeln; } auto solve(string line1) { auto _ = line1.chomp.split.map!(to!int).arra...
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
void main() { auto O = rs, E = rs; foreach(i, v; E) { write(O[i]); write(v); } if(O.length - E.length == 1) writeln(O[$-1]); else writeln; } // =================================== import std.stdio; import std.string; import std.functional; import std.conv; import std.algorithm; import std.range; import std.t...
D
void main() { problem(); } void problem() { const K = scan!long; long solve() { auto queue = DList!long(1,2,3,4,5,6,7,8,9); long count; while(true) { count++; auto n = queue.front; if (count == K) return n; queue.removeFront(); const tail = n % 10; const next = ...
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 std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int idx(char c) { switch (c) { case 'R': return 0; case 'G': return 1; default: return 2; } return -1; } void main() { auto N = readln.chomp.to!int; auto S = readln.chomp;...
D
/+ dub.sdl: name "F" 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...
D
import std.stdio,std.conv,std.string,std.algorithm,std.array,std.math; void main(){ auto sa=readln().split(); auto sb=readln().split(); auto sc=readln().split(); auto sd=readln().split(); int a,b,c,d,ans=0; a=to!int(sa[0]); b=to!int(sb[0]); c=to!int(sc[0]); d=to!int(sd[0]); ...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; T readNum(T)(){ return readStr.to!T; } T[] readNums(T)(){ return readStr.split.to!(T[]); } string readStr(){ return readln.chomp; } void main(){ auto s = readStr; bool dif; foreach(i; 0 .. 3){ if(s[i] == s[...
D