code
stringlengths
4
1.01M
language
stringclasses
2 values
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.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, core.bitop; void main(){ auto S = scanString; writeln((15-S.length)+S.count('o')>=8?"YES":"NO"); } long g...
D
void main() { string n = readln.chomp; string m; foreach (x; n) { m ~= x == '1' ? '9' : '1'; } m.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
import std; import core.bitop; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "g"); alias PQueue(T, alias less = "a>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 s = readln.chomp; auto dp = new int[](s.length+1); dp[0] =...
D
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } ...
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; auto ds = readln.split.to!(int[]); bool[24] T; T[0] = true; int solve(int i) { if (i == N) { int r = 12, j; foreach (k; ...
D
import std.stdio: writeln, readln; import std.string: strip; void main() { string a = readln.strip; string b = readln.strip; if (a == b) writeln("EQUAL"); else if (a.length > b.length) writeln("GREATER"); else if (b.length > a.length) writeln("LESS"); else if (a > b) writeln("GREATER"); else writeln(...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { writeln(readln.chomp == "1" ? "Hello World" : (2.iota.map!(_ => readln.chomp.to!int).sum).to!string); }
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; readV(n); writeln(n*(n+1)...
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 t = readln.chomp; int o, z; foreach (c; t) { if (c == '0') ++z; if (c == '1') ++o; ...
D
import std.stdio; import std.string; import std.conv; import std.array; void main() { int N = readln.chomp.to!int; auto buf = readln.split; int A = buf[0].to!int; int B = buf[1].to!int; int[] P = readln.split.to!(int[]); int[] cnt = [0, 0, 0]; foreach (i; 0..N){ if (P[i] <= A){ ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[][10^^5*2] T; bool[10^^5*2] FS; void main() { auto N = readln.chomp.to!int; foreach (i; 0..N-1) { auto ab = readln.split.to!(int[]); auto a = ab[0]-1; auto b = ab[1]-1; T[...
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.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int N; scan(N); auto a = readln.split.to!(int[]); auto...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, k; rd(n, k); long tot=0; for(int a=1; a<=n; a++){ if(a%k==0){ auto y=(n/k).to!(long); tot+=y*y; }else{ auto x=k-a%k; if((x*2)%k==0){ if(n>=x){ auto y=((n-x)/k+1).to!(long); tot...
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long a, b, c; scan(a, b, c); writeln(min(a + b, a + c, b + c...
D
#!/usr/bin/env rdmd import std.stdio, std.string, std.conv; import std.algorithm, std.array; void main() { for(string S; (S=readln().chomp()).length; ) { auto n = S.to!int(); string w = "<3"; foreach(i;0..n) w ~= readln().chomp() ~ "<3"; immutable string t = readln()...
D
import std.stdio, std.array, std.conv, std.string; void main(){ string s; for(;;){ s=readln(); if(stdin.eof()) break; for(int i = cast(int)s.length; i > 1; --i ){ write(s[i-2]); } if(s.length > 0) write("\n"); } }
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() { int h, w, k; scan(h, w, k); auto c = iota(h).map!(i => readln.chomp).array; int ans; foreach (rs; 0 .. 1 << h) { ...
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
// 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; void main() { auto ab = readln.split.to!(int[]); auto a = ab[0]; auto b = ab[1]; if (a > 0) { writeln("Positive"); } else if (a <= 0 && b >= 0) { writeln("Zero"); } else { ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; void main() { int input; immutable limitList = 200000; bool[] listNumbers = new bool[](limitList); int[] listPrimeNumbers; listNumbers.fill(true); foreach (i; 2..limitList.to!double.sqrt.to!int) { ...
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 Q = s[1]; auto st = new LazySegmentT...
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; } long calc(long n, long a, long b) { if (n == 1) ...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a=readln.split.to!(long[]); a=0L~a~0L; long s=0; import std.math; for(int i=0; i<=n; i++){ s+=(a[i+1]-a[i]).abs; } for(int i=1; i<=n; i++){ auto t=s; t-=(a[i]-a[i-1]).abs; t-=(a[i+1]-a[i]).abs; ...
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 = assumeSor...
D
import std.stdio; import std.array; import std.conv; void main() { while (1) { string[] str = split(readln()); int a = to!(int)(str[0]); int b = to!(int)(str[1]); if (a == 0 && b == 0) { break; } else if (a > b) { writeln(b, " ", a); } else { writeln(a, " ", b); } } }
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; int[] a; void main() { scan(n); a = iota(n).map!(i => readln.chomp.to!int - 1).array; auto d = new int[]...
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int N; scan(N); auto x = readln.split.to!(int[]); int ...
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 w = readint; ...
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(){ import std.stdio, std.string, std.conv, std.algorithm; int n, q; rd(n, q); auto tree=new SquareRootDecomposition(n); while(q--){ auto args=readln.split.to!(int[]); if(args[0]==0){ tree.add(args[1]-1, args[2], args[3]); }else{ writeln(tree.sum(args[1]-1, args[2])); } }...
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
void main() { long[] tmp = readln.split.to!(long[]); long a = tmp[0], b = tmp[1], c = tmp[2]; long x = tmp[3], y = tmp[4]; if (a + b < 2 * c) { writeln(a * x + b * y); } else { long z = min(x, y); long u = a * (x - z) + b * (y - z); long v = 2 * c * (max(...
D
import std.algorithm, std.string, std.traits, std.array, std.range, std.stdio, std.conv; N gcd(N)(N a, N b) if (isNumeric!N || is (N == BigInt)) { return a ? gcd(b % a, a) : b; } N lcm(N)(N a, N b) if (isNumeric!N || is (N == BigInt)) { return a / gcd(a, b) * b; } void main()...
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { int n = readln.chomp.to!int; int k = n / 15; writeln(n * 800 - k * 200); }
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, 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; scan(n); auto w = readln.split.to!(...
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.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric; void main(){ readln.split.map!(to!int).map!"a-1".reduce!"a*b".writeln; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); int a; rd(a); if(n%500<=a) writeln("Yes"); else writeln("No"); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(...
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(){ auto s=scan!st...
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 H, W; scan(H, W); int h, w; scan(h...
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.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
unittest { assert( [ "ATCODER" ].parse.expand.solve == 3 ); assert( [ "HATAGAYA" ].parse.expand.solve == 5 ); assert( [ "SHINJUKU" ].parse.expand.solve == 0 ); } import std.conv; import std.range; import std.stdio; import std.typecons; void main() { stdin.byLineCopy.parse.expand.solve.writeln; } auto parse( Ra...
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; enum lim = 80 * 80 * 2; void main() { int m1, d1; ...
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() { auto w = ["Sunny", "Cloudy", "Rainy"]; string s...
D
void main() { problem(); } void problem() { auto K = scan!int; auto S = scan; string solve() { if (S.length > K) return S[0..K] ~ "..."; return S; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.contain...
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.stdio, std.string, std.conv, std.array, std.algorithm, std.math; long calc(long x) { return x * (x + 1) / 2; } void main() { string s = readln.chomp; if (s[0] == '>') s = '<' ~ s; if (s[$-1] == '<') s ~= '>'; auto g = s.group.array; long[] a = new long[g.length]; foreach (i, x; ...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}} void readM(T...)(size_...
D
import std.stdio, std.conv, std.string, std.math, std.regex, std.array; void main(){ auto ip = readln.chomp.to!(char[]); replace(ip, ",", " ").writeln; }
D
import std.stdio; import std.string; import std.conv; void main() { int N = readln.chomp.to!int; int H = readln.chomp.to!int; int W = readln.chomp.to!int; int result = (N - H + 1) * (N - W + 1); writeln(result); }
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[]); if (x[0] * x[1] % 2) { writeln("Odd"); ...
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; long result; foreach (n; 1 .. N + 1) { long cnt; if (n % 2 == 0) ...
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; // 差の絶対値 @nogc @safe pure T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } // 切り上げ除算 @nogc @safe pur...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; bool[10^^5+1] PS; void prime_init() { PS[] = true; PS[0] = false; PS[1] = false; foreach (i; 2..10^^5+1) { if (PS[i]) { auto x = i*2; while (x <= 10^^5) { ...
D
import std.stdio; import std.algorithm; import std.conv; import std.string; import std.array; import std.math; void main(){ auto input = readln().chomp.split.map!(to!int); if(input[1] % input[0] == 0){ writeln(input[0] + input[1]); }else{ writeln(input[1] - input[0]); } }
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; char get(char a, char b) { foreach (c; "RGB") { if (c != a && c != b) return c; } assert(false); } long calc(string s) { int n = cast(int)s.length; auto r = new int[n]; auto g = new int[n]; auto b = new int[n]; if (s[0] == 'R') r[0] = 1; if (s[0] == 'G') g[0] =...
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.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long[] as; fo...
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, m, x; scan(n, m, x); auto 参考書の値段とアルゴリズム = new long[]...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, q; rd(n, q); int s=0; while(q--){ int t, k; rd(t, k); if(t){ (s+=k)%=n; }else{ writeln(((k-1)+s)%n+1); } } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; asser...
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; 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() { while (1) { auto n = readln.chomp.to!int; if (!n) break; auto sum = readln.chomp.split.map!(to!i...
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 k = readNums!int; auto start = k[0] * 60 + k[1]; auto end = ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); int[] N; N.length = S.length; int x; foreach (i, c; S) { if (c == 'R') { ++x; } else { N[i-1] += (x+1)/2; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; long[10^^5] HS, TABLE; void main() { auto nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; foreach (i, h; readln.split.to!(long[])) HS[i] = h; foreach_reverse (i; 0..N) { i...
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; 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.numeric; void main() { auto n = readln.chomp.to!int; //auto s = new string[](n); int...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.math; void main() { int n, k; scan(n, k); auto a = readln.split.to!(int[]); auto presum = new long[](n + 1); auto possum = new long[](n + 1); foreach (i ; 1 .. n + 1) { presum[i] = a[i-1] + presum[...
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 adj = new int[...
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 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; import std.numeric; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array ...
D
import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main(){ stdin.readln.chomp.filter!(a => a != ',' && a != '.').array.split.filter!(a => a.length > 2 && a.length < 7).reduce!((a, b) => a ~ " " ~ b).writeln; }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; immutable int mod = 10 ^^ 9 + 7; immutable int limit = 60; immutable auto p2 = limit.iota.map !(i => (1L << i) % mod).array.idup; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = r...
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.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { long N; scan(N); if (N % 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; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", ...
D
import std.stdio; void main() { auto r1 = readln(); auto r2 = readln(); auto r3 = readln(); write(r1[0], r2[1], r3[2]); }
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
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int a, b; rd(a, b); for(int c=1; c<=3; c++){ if((a*b*c)&1){ writeln("Yes"); return; } } writeln("No"); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.leng...
D
void main() { string n = readln.chomp; n.count('2').writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { int N = readln.chomp.to!int; int[][] CSF = (N-1).iota.map!(_ => readln.chomp.split.to!(int[])).array; int[] C, S, F; foreac...
D
import std.string; import std.conv; import std.algorithm; import std.stdio; void main() { int hp = readln.chomp.split(" ")[0].to!int; foreach (e;readln.chomp.split(" ").map!(to!int)) { hp -= e; if (hp <= 0) { writeln("Yes"); return; } } writeln("No"); }
D
import std.stdio; import std.conv; import std.string; void main() { string s = readln.chomp; int w = readln.chomp.to!int; for (int i = 0; i < s.length; i++) { if (!(i % w)) write(s[i]); } }
D
import std; void main() { int n, m; scan(n, m); auto a = readints; int ans = n - a.sum; writeln(max(ans, -1)); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[])...
D
import std; alias P = Tuple!(long, "x", long, "y"); const MOD = 10^^9 + 7; long calc(P[] ps, int zeros) { long[P] m; foreach (p; ps) m[p]++; bool[P] used; long[] group; foreach (p; ps) { if (used.get(p, false)) continue; // p に属するグループ数 auto a1 = p; auto a2 = P(-p....
D
import std.stdio; void main() { for (int i = 0; i < 1000; i++) { writeln("Hello World"); } }
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 scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i]...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; import std.math; void main() { int n; scan(n); auto s = readln.split; foreach (ch ; s) { if (ch == "Y") { writeln("Four"); return; } } writeln("Three"); } void scan(T...
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; long mod = 1000000007; long modinv(long a) { long b=mod, u=1, v=0; while(b>0) { long t=a/b; a -= t*b; swap(a,b); u -= t*v; swap(u,v); } u %= mod; if(u<0) u+=mod; return u; } void ma...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.numeric; 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() { string s;...
D
import std.stdio; import std.algorithm; import std.conv; import std.array; import std.string; import std.math; void main(string[] args) { readln.chomp.solve.writeln; } auto solve(string input) { return input.count("1"); } unittest { assert(solve("101") == 2); assert(solve("000") == 0); assert(solve("0001")...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; auto readNum(T)(){ return readln.chomp.to!T; } auto readNums(T)(){ return readln.chomp.split.to!(T[]); } void main(){ auto nm = readNums!int; int maxGate = nm[0]+1, minGate = 0; foreach(i; 0 .. nm[1]){ auto g ...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, k; rd(n, k); auto cost=new int[][](k, k); foreach(i; 0..k) cost[i]=readln.split.to!(int[]); auto a=new int[][](n, n); foreach(i; 0..n){ a[i]=readln.split.to!(int[]); a[i].each!((ref e)=>e--); } auto s=new int[][](k, n*2...
D