code
stringlengths
4
1.01M
language
stringclasses
2 values
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.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() ...
D
import std; long calc(long a, long b, long c, long k) { long x = min(a, k); long y = min(b, k - x); long z = min(c, k - x - y); return x - z; } void main() { long a, b, c, k; scan(a, b, c, k); writeln(calc(a, b, c, k)); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach ...
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() { int n; scan(n); if (n == 0 || n...
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 infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { string s; scan(s); auto p = "keyence"; ...
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 nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; auto bs = new int[][](K*2, K*2); auto ws = new int[][](K*2, K*2); foreach (_; 0..N) { auto xyc = readln...
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { ulong[] XY = readln.chomp.split.to!(ulong[]); ulong X = XY[0], Y = XY[1]; ulong n; while (X*2^^n <= Y) { n++; ...
D
import std.stdio,std.conv,std.string; void main(){int x=to!int(readln.chomp);writeln(x*x*x);}
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[] lreads(T = long)(long n){ret...
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
/+ dub.sdl: name "D" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { auto sc = new Scanner(stdin); int n; sc.read(n); if (n == 2) { writeln("Second"); return 0; } int[...
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 x = lread(); foreach (i; x .. (x + 10 ^^ 6)) { ...
D
import std.stdio; import std.uni; import std.string; import core.stdc.stdio; import std.array; import std.algorithm; int main(string[] argv) { int n,k; scanf("%d", &n); int [] arr = new int[n]; for(int i = 0; i<n; i++){ int h,m; scanf("%d:%d", &h,&m); h*=60; arr[i] = h+m; } arr.sort(); int mx=0; for...
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 x, y; readV(x, y); writeln(x...
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.uni; import std.range; void main() { auto a = readln.strip.repeat(10).join(""); if (a.indexOf(readln.strip) != -1) writeln("Yes"); else writeln("No"); }
D
void main(){ string s = readln().chomp(); foreach(i,c; s){ if( (i+1)%2 ){ if(c!='R' && c!='U' && c!='D'){ writeln("No"); return; } }else{ if(c!='L' && c!='U' && c!='D'){ writeln("No"); return; } } } writeln("Yes"); } import std.stdio, std.conv, std.algorithm, std.numeric, st...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto nab = readln.split.to!(int[]); writeln(nab[0] * nab[1] > nab[2] ? nab[2] : nab[0] * nab[1]); }
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 dts = readln.split.to!(int[]); auto D = dts[0]; auto T = dts[1]; auto S = dts[2]; writeln(D <= T * S ? "Yes" : "No"); }
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]; auto MAP = new char[][](H, W); foreach (i; 0..H) { foreach (j, c; readln.chomp) MAP[i][j] = c; } fo...
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.format; void main() { auto input1 = readln.chomp.to!int...
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 rd = readln.split.map!(to!int); auto w = rd[0], h = rd[1], x = rd[2], y = rd[3], r = rd[4]; writeln(x...
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, N = data[0].to!int, X = data[1].to!int; auto x = readln.split.to!(int[]); x = x.map!(a => (a-X).abs).array; auto minx = x.reduce!"min(a,b)...
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; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; import std.typecons; import std.regex; import std.range; int n,s; int saiki(int n1,int u,int m){ if(n1 > s) return 0; else if(m==1){ int d = s-n1; if(d <= 9 && (u & (1<<d))==0...
D
import std.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 = 1L<<60; void main() { long n, s; scan(n); scan(s); if (n == s) { writeln(n + 1); return; } if (n < s) { ...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void main() { int n; readV(n); writeln((n%1000)%111 == 0 || (n/10)%111 == 0 ? "Yes" : "No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { int solve(int n, int x, int p) { if (p == 0) return x == 0 ? 1 : 0; if (n == 0) return 0; int r; if (x >= n) r += solve(n-1, x-n, p-1); r += solve(n-1, x, p);...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; 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; auto ts = [A, B, C, D, E]; ...
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(long x, long y...
D
import std.stdio; import std.string; import std.algorithm; import std.conv; void main() { auto arr = readln.chomp.split.map!(to!int); int result = 0; for (int i = arr[0]; i <= arr[1]; i++) { if (arr[2] % i == 0) result++; } result.writeln; }
D
import std.algorithm; import std.array; import std.ascii; 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 log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } void main() ...
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; void main(){ auto inputs = readln; if(inputs[2] == inputs[3] && inputs[4] == inputs[5]) writeln("Yes"); else writeln("No"); }
D
void main() { long[] tmp = rdRow; long n = tmp[0], k = tmp[1]; long result; if (k) { foreach (i; k+1 .. n+1) { long d = n / i; long cnt = (i - k) * d; long rem = n - i * d; cnt += max(0, rem-k+1); result += cnt; } ...
D
void main() { long n, q; rdVals(n, q); long[][] tree = new long[][](n); foreach (i; 0 .. n-1) { long a, b; rdVals(a, b); --a, --b; tree[a] ~= b, tree[b] ~= a; } long[] lists = new long[n]; foreach (i; 0 .. q) { long p, x; rdVals(p, x)...
D
void main() { long n, k; rdVals(n, k); long[] list = new long[n]; foreach (i; 0 .. k) { long d = rdElem; long[] a = rdRow; foreach (x; a) { ++list[x-1]; } } long result; foreach (l; list) { if (l) continue; ++resul...
D
import std.stdio,std.string,std.conv,std.algorithm,std.range; void main() { auto n = readln.chomp.to!ulong; if(n==0) 1.writeln; else iota(1, n + 1).reduce!"a*b".writeln; }
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; struct Box{ long a, b, c; } enum MOD = 1000000007L; void main() { long N = scanElem; string s1 = readln.strip; string s2 = readln.strip...
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(){ auto x = readln.chomp.to!int; auto a = readln.chom...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.math; void main() { int n, x; scan(n, x); auto m = iota(n).map!(i => readln.chomp.to!int).array; writeln(n + (x - m.sum) / m.reduce!min); } void scan(T...)(ref T args) { import std.stdio : readln; import...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void main() { int a, b, c, d, e, f; readV(a, b, c, d, e, f); auto nu = 0, de = a*100; foreach (o1; 0....
D
/+ dub.sdl: name "C" 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); long B = 10L^^10; long x, d; sc.read(x, d); lo...
D
void main() { auto S = rs, T = rs; foreach(i; 0..S.length) { string tmp = S[1..$]; tmp ~= S[0]; if(S == T) { writeln("Yes"); return; } S = tmp; } writeln("No"); } // =================================== import std.stdio; import std.string; import std.functional; import std.conv; import std.algorith...
D
import std.stdio, std.string, std.range, std.algorithm, std.math, std.typecons, std.conv; long[] weights, values; long N; long W; long w0; long[][][] memo; void main() { auto inp = readln.split.to!(long[]); N = inp[0]; W = inp[1]; weights = new long[N]; values = new long[N]; foreach (i; 0..N) { inp = r...
D
import std.stdio, std.string, std.conv; import std.algorithm, std.array; import std.math; auto solve(string s_) { immutable N = s_.to!int(); auto AS = new int[N]; foreach(ref a;AS) a=readln.chomp().to!int(); int[2][int] c; foreach(i;0..N) { immutable v=AS[i]; if(v !in c) c[v]=[...
D
import std.stdio; import std.ascii; import std.numeric; import std.algorithm; import core.stdc.stdio; int main() { int t = readInt!int; foreach(ti; 0 .. t) { int n = readInt!int; int[] a = new int[](n); int[] even; int[] odd; foreach(ref ai; a) { ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int n, k; scan(n, k); auto mc = ModComb(n...
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 f(long n) { if...
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() { auto a = reads(); if (a[0] + a[1] == 15) writeln("+"); else if (a[0] * a[1] == 15) writeln("*");...
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 x = readln.chomp.to!int; auto res = (x / 500) * 1000; res ...
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, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int x, y; scan(x, y); int ans; if (1L * x * y != 0) { if (0 < x && x < y) ans = y - x; else if (0 < y && y < x) ans = x - y + 2; ...
D
import std.stdio; import std.array; import std.algorithm; import std.conv; import std.numeric; import std.string; void main() { int N = readln.chomp.to!int; long[] L = new long[N + 1]; L[0] = 2; L[1] = 1; for (int i = 2; i <= N; ++i) L[i] = L[i - 1] + L[i - 2]; L[N].writeln; }
D
import std.stdio, std.conv, std.string, std.range, std.typecons, std.format, core.bitop; import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.mutation; void main() { long[] input = readln().split.to!(long[]); long N = input[0]; long K = input[1]; long[] list = r...
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; immutable long INF = 1L << 59; long even(long n) { return n == 0 ? 2 : n % 2; } long odd(long n) { return 1 - n ...
D
import std.stdio; void main() { int n, h, x; int result = 0; scanf("%d%d", &n, &h); for (int i = 0; i < n; i++) { scanf("%d", &x); result += (x > h) ? 2 : 1; } printf("%d\n", result); }
D
import std.stdio; void main() { int n; scanf("%d", &n); char[][] m = new char[][n]; for (int i = 0; i < n; i++) { m[i] = new char[n + 1]; scanf("%s", m[i].ptr); } int res = 0; for (int i = 0; i < n; i++) { int r = 0; int c = 0; for (int j = 0; j < n; j++) { if (m[j][i] == 'C') c++; i...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static 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.algorithm; import std.conv; import std.range; void main() { int n = readln.chomp.to!int; int[][] diploma; for (int i = 0; i < 3; i++) { diploma ~= readln.chomp.split.map!(to!int).array; } int dip_1 = min(diploma[0][1], n - (diploma[1][0] + di...
D
import std.algorithm, std.stdio, std.string; void main () { string s; while ((s = readln.strip) != "") s.count !(x => "aeiou13579".canFind (x)).writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.stdio; void main() { int n; scanf("%d", &n); printf("%lld\n", (1L << n + 1) - 1 - 1); }
D
import std.stdio; import std.range; import std.uni; import std.conv; import std.container; import std.functional; import std.algorithm; import std.array; import std.typecons; void main(string[] args) { inputFile = stdin; debug inputFile = File(args[1]); auto nt = next!int; foreach(t; 0 .. nt) { auto ...
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.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() { writeln(readln.chomp.to!int ^^ 2); } 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.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } bool isPrime(int n) { if (n < 2) return ...
D
void main(){ int r = _scan(); (3*r^^2).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); ...
D
import std.stdio; import std.conv; import std.array; import std.string; void main() { string s, str = ""; while ((s = readln()).length) { str ~= s; } for (int i = 0; i < 26; i++) { int cnt; cnt += str.count('a' + i); cnt += str.count('A' + i); writeln(to!char('a' + i), " : ", cnt); ...
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.math; 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 readln.chomp.to!T; } T[]...
D
import std.stdio; import std.array; import std.conv; import std.algorithm; import std.string; import std.typecons; import std.format; int[Tuple!(long, long, long)] patterns; long answer; void solve(long a, long b, long c, long x) { auto key = tuple(a, b, c); if (key in patterns) { return; } patterns[key] = 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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto ...
D
void main() { auto ip = readln.split, X = ip[0], Y = ip[1]; if(X < Y) writeln("<"); else if(X > Y) writeln(">"); else writeln("="); } // =================================== import std.stdio; import std.string; import std.functional; import std.conv; import std.algorithm; import std.range; import std.traits; impor...
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.algorithm; import std.math; import std.range; import std.ascii; import std.array; import std.container; import std.conv; import std.numeric; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } class UnreliableRollingHash(ulong P) { // fast but un...
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() { import std.stdio, std.string, std.conv, std.algorithm; int L; rd(L); struct E { int from, to, cost; } E[] edges; int f(int K) { if (K == 2) { edges ~= E(1, 2, 0); edges ~= E(1, 2, 1); return 2; } if (K & 1) { auto last = f(K - 1); edges ~= E(1,...
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; bool solve() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto S = s[2]-1; auto...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; long P = 10^^9+7; long[10^^5*4+50] 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; } void init() {...
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.algorithm; import std.conv; import std.string; int f(int n) { return n*(n+1)/2; } void main() { int n, l; scanf("%d %d", &n, &l); if (l <= 0 && l + n > 0) { write(f(l+n-1)-f(-l)); } else if (l > 0) { write(f(l+n-1)-f(l)); } else { write(-f(-l)+f(-l-n+1)); } }
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; import std.conv; import std.string; import std.algorithm; void main(){ int n=to!int(readln.chomp); string[] a; while(n--) a~=readln.chomp; sort(a); writeln(a[0]); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void pickV(R,T...)(ref R r,ref T t){foreach(ref v;t)pick(r,v);} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t...
D
import core.stdc.stdio; import std.typecons; import std.algorithm; void main(){ int n,e,t; scanf("%d%d%d",&n,&e,&t); --t; long[] cost = new long[n]; static immutable int inf = 1145141919; bool[] used = new bool[n]; foreach(i;0..n){ int w; scanf("%d",&w); if(w==1){ cost[i]=1; used[i]=true; }else ...
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; bool isNumeric(char c) { return '0' <= c && c <= '9'; } void main() { int[] AB = readln.chomp.split.to!(int[]); int A = AB[0], B = AB...
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
string vowels = ['a', 'e', 'i', 'o', 'u']; void main(){ char c = _scan!char(); if(vowels.find(c).empty)writeln("consonant"); else writeln("vowel"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[...
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<<30; enum full = (1<<26) - 1; void main() { string s; scan(s); int n = s.length.to!int; auto dp = new int[](n + 1); dp[n] = 1; ...
D
#!/usr/bin/rdmd import std.stdio: writeln, readln; import std.conv: parse; void main() { auto input = readln(); auto num = parse!int(input); writeln((num^^3)); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; long f(long b, long n) { long r; while (n) { r += n%b; n /= b; } return r; } void main() { auto n = readln.chomp.to!long; auto s = readln.chomp.to!long; if (n == s) { ...
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.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.algorithm; import std.array; import std.conv; import std.string; import std.math; void main() { auto abc = readln.chomp.split.map!(to!int).array; long a = abc[0], b = abc[1], c = abc[2]; if (a == b && b == c && a % 2 == 0 && b % 2 == 0 && c % 2 == 0) { (-1).writeln; } else ...
D
void main() { long s, w; rdVals(s, w); writeln(w < s ? "safe" : "unsafe"); } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; enum double eps = 1.0e-9; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdEle...
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; alias Edge = Tuple!(int, "from", int, "to", int, "cost"); void main()...
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