code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; void main() { auto N = readln.chomp.to!int; auto YS = new long[](N+1); YS[] = 1; YS[0] = 0; foreach (i; 2..N+1) { long k = 1; while (i*k <= N) { YS[i*k] ...
D
import core.stdc.stdio; import std.math; import std.algorithm; import std.typecons; import std.stdio; void main(){ int n; scanf("%d",&n); long[] x=new long[n],y=new long[n]; foreach(i;0..n) scanf("%lld%lld",&x[i],&y[i]); alias Tuple!(long,"x",long,"y",int,"k") p; p[] ps = new p[n-1]; foreach(i;0..n){ int c;...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int q; rd(q); bool enough(long k, long n, long a, long b, long m) { return a * m + b * (n - m) < k; } while (q--) { long k, n, a, b; rd(k, n, a, b); if (b * n >= k) { writeln(-1); continue; } long ok =...
D
import std.stdio, std.string, std.array, std.conv; void main() { int[] a = readln.chomp.split.to!(int[]); writeln(a[0] * a[1], " ", 2 * (a[0] + a[1])); }
D
void main() { int[] tmp = readln.split.to!(int[]); int a = tmp[0], b = tmp[1], c = tmp[2]; writeln(b - a == c - b ? "YES" : "NO"); } 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; im...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto S = readln.chomp.to!(dchar[]); auto N = S.length; size_t i = 0, j = S.length - 1; auto a = S[0], b = S[0], c = S[$-1], d = S[$-1]; int x, y; foreach (s; S) { ++(s == '1' ? x : y); } if (!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; // 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto as = readln.split.to!(long[]); long r; for (;;) { bool flg; foreach (i, ref a; as) { if (a >= N) { flg = t...
D
void main() { long n = rdElem; long[] a = 5.rdCol; long amin = a.reduce!min; long m = (n + amin - 1) / amin; writeln(m + 4); } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdD...
D
void main() { long n, c; rdVals(n, c); long limit = 2 * 10 ^^ 5 + 1; long[][] lists = new long[][](c, limit); foreach (i; 0 .. n) { long s, t, d; rdVals(s, t, d); s = 2 * s - 1, t = 2 * t, --d; ++lists[d][s], --lists[d][t]; } long[] record = new long[lim...
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.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; void main() { auto N = readln.chomp.to!int; auto A = readln.split.map!(to!long).array; if (A[$-1] != 2) { writeln(-1);...
D
void main() { long n = readln.chomp.to!long; long[] a = readln.split.to!(long[]); long[] b = new long[n+2]; foreach (i; 1 .. n+1) { b[i] = a[i-1]; } long total; foreach (i; 1 .. n+2) { total += abs(b[i] - b[i-1]); } foreach (i; 1 .. n+1) { write...
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 input = readln.split.to!(int[]); auto N = input[0], X = input[1], Y = input[2]; int[] ans; ans.length = N+1; foreach (k; 1 .. N+1) { a...
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
void main() { long x = rdElem; long limit = 200000; auto sieve = new Prime(limit); foreach (i; x .. limit) { if (sieve.isPrime(i)) { i.writeln; return; } } } struct Prime { bool[] flags; this(long limit) { flags = makeSieve(l...
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 >= 13) { writeln(B); } else if (A >= 6) { writeln(B/2); } else { writeln(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; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){ret...
D
unittest { assert( [ "AtCoder Beginner Contest" ].parse.expand.solve == "ABC" ); assert( [ "AtCoder Snuke Contest" ].parse.expand.solve == "ASC" ); assert( [ "AtCoder X Contest" ].parse.expand.solve == "AXC" ); } import std.conv; import std.range; import std.stdio; import std.typecons; void main() { stdin.byLin...
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
module main; import core.stdc.stdio; int main(string[] arv) { int n; scanf("%d", &n); char [] s = new char[n]; for(int i = 0; i < n; i++) scanf(" %c", &s[i]); for(int i = 0; i < n; i++) { if(s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'y') printf("%c", s[i]); else { ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; void main(){ int n = readln.chomp.to!int; int[] a = readln().split().map!(to!int).array; int[] x = [0,0,0]; foreach(i; 0..n-1){ if(a[i] == a[i+1]){ x ~= i+1; } } x ~= n; ...
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.string; import std.conv; import std.algorithm; import std.range; import std.file; void main(string[] args) { auto s = map!(to!int)(readln.strip.split); auto d = s[1] * 2; int n = 1; while(n <= s[0]) { auto des = d * n; if (des >= s[2]) break;...
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.container; import std.random; void main() { auto a = readln.chomp.split.map!(to!int); auto w = a[0]; auto h = a[1]; auto x = a[2]; auto y = a[3]; ...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto x = readln.chomp.split.to!(int[]); auto y = readln.chomp.split.to!(int[]); i...
D
void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], m = tmp[1]; int[] a = new int[m+1]; foreach (i; 0 .. n) { int[] survey = readln.split.to!(int[]); foreach (x; survey[1..$]) { ++a[x]; } } a.count(n).writeln; } import std.stdio; import std.str...
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; 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.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 N = readln.chomp.to!int; auto S = readln.chomp; auto T = S.map!(s => to!int(s - '1')).array...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons; import std.math, std.numeric; void main() { int n; scan(n); char[][] ban = new char[][](n, n); iota(n).each!(i => ban[i] = readln.chomp.to!(char[])); long ans; foreach (i ; 0 .. n) { if (isS...
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 io = new IO(); auto input = io.str(); writeln(input[0..4]," ",input[4..$]); } import std.stdio,std.string,std.conv; class IO { string str( size_t lines = 1 ) { return readln().chomp(); } T[] line( T = real , string sp = " " )( size_t lines = 1 ) { T[] ret; foreach( i ; 0..lines ...
D
import std.stdio, std.string, std.algorithm, std.range; void main() { auto S = readln.chomp; auto s = 0, e = S.length-1; while (S[s] != 'A') { s++; } while (S[e] != 'Z') { e--; } writeln(e - s + 1); }
D
import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.complex; import std.container; import std.conv; import std.datetime; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split()...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int t; scan(t); while (t--) { long ai, bi, ci, di; scan(ai, bi, ci, di); writeln(solve(ai, bi, ci, di) ? "Yes" ...
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.container; import std.bigint; void main() { foreach (line; stdin.byLine) { auto eqn = line.chomp.split("="); BigInt nnum, xnum; int i; bool zero; f...
D
import std; void main() { int n, k; scan(n, k); auto s = new int[n]; foreach (_; 0..k) { read; foreach (e; readints) s[e-1]++; } auto ans = s.count!"a == 0"; writeln(ans); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T ...
D
/+ dub.sdl: name "C" 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 H, W, h, w; sc.read(H, W, h, w); int[][] cnt = new int[][](h, w); foreach (y; 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 chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii; // }}} // tbh.scanner {{{ class Scanner { import std.stdio; import std.conv : to; import std.ar...
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.array; // split import std.conv; // to void main() { string s1 = chomp(readln()); string s2 = chomp(readln()); int a = to!int(s1); // 第0要素を整数に変換 int b = to!int(s2); // 第1要素を整数に変換 a *= a; writeln(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.container; void main() { int n = readln.chomp.to!int; auto cash = readln.split.map!(to!int); auto time = new int[](n); foreach (i; 0..n) { ...
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 AS = readln.split.to!(ulong[]); ulong x; size_t i, j; long r; while (j < N) { while (i < N && x&AS[j]) { x ^= AS[i++]; ...
D
import std.stdio; import std.algorithm; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() {//try{ auto tokens = split(my_readln()); auto N = to!ulong(tokens[0]); auto X = to!ulong(tokens[1]); ulong[2][] memo; ...
D
import std.stdio; import std.algorithm; import std.string; import std.range; import std.array; import std.conv; import std.complex; import std.math; import std.ascii; import std.bigint; import std.container; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split())); } auto readInt() ...
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; import std.typecons; import std.bigint; // import dcomp.foundation, dcomp.scanner; // import dcomp.container.deque; int main() { auto sc = new Scanner(stdin); int n, m, k; sc....
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; 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!(...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.numeric; import std.stdio; import std.string; void main() { long[] s = readln().chomp().split(" ").map!(to!(long)).array; long a = s[0]; long b = s[1]; if (a + b == 15) { writeln("+"); return; }...
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; scan(n); auto a = readln.split.to!(...
D
import std.stdio; import std.string; import std.conv; import std.algorithm.searching; void main(){ auto l = readln.chomp; auto x = l.to!long; long u = 0; while(x >= 500) { u += 1000; x -= 500; } while(x >= 5) { u+= 5; x -= 5; } u.writeln; }
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.stdlib, std.datetime; immutable int N = 26; //immutable int D = 365; int D; long[] C; long[][] S; void main() { auto stattime...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto s = readln.chomp; auto x = 0, m = 0; foreach (si; s) { x += si.predSwitch('I', +1, 'D', -1); m = max(m, x); } writeln(m); }
D
import std.stdio; import std.string; import std.conv; import std.bigint; import std.typecons; import std.algorithm; import std.array; import std.math; void main() { auto N = readln.chomp.to!real; writeln(cast(ulong)(floor(sqrt(N)) ^^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.stdio; immutable long INF = 1L << 60; const int N = 10; const int M = 5; void main() { auto B = N.iota.map!(_ => readln.chomp...
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; import std.ascii; void main() { int n; scan(n); auto adj = new int[][](n, 0); foreach (i ; 1 .. n) { int pi; scan(pi); adj[pi-1] ...
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.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.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
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; import std.bitmanip; import std.typecons; import std.numeric; final class PrimeTable { private: BitArray a; size_t n...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto x=readln.split.to!(int[]); int[200005] val,pre,nxt; for(int i=1;i<=n;i++) { val[i]=x[i-1]; pre[i]=i-1; nxt[i]=i+1; } nxt[0]=1; pre[n+1]=n; int cnt=n; for(int i=nxt[1];i<=n;i=nxt[i]) { while(val...
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 s = readln.strip.map !(q{a == 'R'}).array; auto t = s ~ s ~ s; immutable int [] toFind = [0, 1]; ...
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
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializ...
D
void main() { long n = rdElem; long total; foreach (i; 1 .. n+1) { if (i % 3 && i % 5) total += i; } total.writeln; } 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 rdS...
D
import std.stdio; immutable mod = 4294967311L; void main(){ long x, y; int n, op; scanf("%d", &n); foreach(i; 0..n){ scanf("%d%lld", &op, &y); if(op == 1) x += y; else if(op == 2) x -= y; else if(op == 3) x *= y; else if(op == 4) x = mul(x, inv(y)); x %= mod; } if(x < 0) x += mod; if(x > int.max) ...
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; } int calc(int[] xs) { int[int] d; for (int 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.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() { writeln(readln.chomp.uniq.array.length==1?"No":"Yes"); }
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; long calc(long h, long w) { if (h == 1 || w == 1) return 1; long a = (w + 1) / 2; long b = w / 2; long ans = ...
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 i = readNums!ulong; auto x = i[0]; auto y = i[1]; auto z = ...
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 scan(T...)(ref T args) { auto line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFro...
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; int N, K; int[][] edge; bool[] visited; void dfs(int n, int prev, int d) { visited[n] = true; if (d == 0) return; foreach (m; ...
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 K = readln.chomp.to!int; writeln("3 3"); auto IK = 0b100000000000000000 + K; auto IO = 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
void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.array; int n; rd(n); auto g=readln.split.to!(int[]).map!((e)=>(e-1)).array; int f(int i, bool[] vis){ if(vis[i]) return i; vis[i]=true; return f(g[i], vis); } foreach(i; 0..n){ auto vis=new bool[](n); wri...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { foreach (string line; stdin.lines) { int ans = 1; int n = line.chomp.to!int; for (int i = 1; i <= n; i++) { ans += i; } ans.writeln; } }
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 N = readln.chomp.to!int; auto S = readln.chomp; auto A = new int[](N+1); foreach (i; 0..N)...
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.functional; 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 r...
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() { long N = scanElem; long[] list; list.length=N; foreach(i;0..N) { list[sc...
D
void main(){ string s = readln().chomp(); if(s=="ABC")writeln("ARC"); else writeln("ABC"); } 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; readl...
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
void main() { int[] tmp = readln.split.to!(int[]); int month = tmp[0], day = tmp[1]; int cnt; foreach (m; 2 .. month+1) { foreach (d; 21 .. day+1) { int div = d / 10, rem = d % 10; if (rem >= 2 && m == div * rem) { ++cnt; ...
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() { while (true) { int n; scan(n); if (n == 0) return; auto map = new int[][](21, 21); foreach (i ; 0 .. n) { ...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), a = rd[0], b = rd[1]; auto s = readln.chomp; foreach (i, c; s) { if (i == a) { if (c != '-') { writeln("No"); return; } } else { if (c < '0' || c > '9') { ...
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; int q; Query[] queries; } enum QueryType { reverse, prepend, append, } str...
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 a = ['a', 'i', 'u', 'e', 'o']; auto c = readln.chomp.to!char...
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 nm = readln.split.to!(int[]); auto N = nm[0]; auto M = nm[1]; auto G = new int[][N]; auto RG = new int[][N]; foreach (_; 0..M) { auto ab = ...
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DE...
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n, q; scan(n, q); while (q--) { int vi, wi; scan(vi, wi); solve(n, vi, wi); } } void solve(int n, int v, int w...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; int[10][10] CS; void main() { int H = readln.split.to!(int[])[0]; foreach (i; 0..10) CS[i][] = readln.split.to!(int[])[]; foreach (_; 0..10) foreach (i; 0..10) foreach (j; 0..10) ...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto n = readln.chomp.to!int; writeln(n/2+(n%2>0)); }
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.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.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto N = readln.chomp.to!long; auto n = N; auto S = 0; while (n > 0) { S += n % 10; n /= 10; } writeln(N % S == 0 ? "Yes" : "No"); }
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.to!(int[]); } void main() { int n = readint(); string s = readln.chomp; int[] a = new int[300010]; int[] b = new int[300010]; ...
D