code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main() { auto data = readln().split(); auto S = data[0].to!string(); auto first = S; auto num = 0; foreach (c; S) { if (c == '1') num++; } writeln(2*min( num, S.length-num )); }
D
import std.stdio; void main() { int n; scanf("%u", &n); int a5, a0; while(n--) { int t; scanf("%u", &t); if(t == 5) a5++; else a0++; } if(a0 == 0) { write(-1); return; } int m, c; foreach(i; 0..a5) if((m += 5) % 9 == 0) c = i + 1; if(!c) a0 = 1; while(c--) write(5); wh...
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() { Scanner sc = new Scanner(stdin); int H, W, d; sc.read(H, W, d); string s = "RYGB"; int[][] res = new int[][](H, W); ...
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; alias A = Tuple!(int, "...
D
import std.conv; import std.math; import std.stdio; import std.string; private const JUMP_TIME = 1; private const EAT_TIME = 1; void main() { auto trees_count = read(), position = read(), time = position + EAT_TIME; foreach (i; 1 .. trees_count) { auto tree = read(); time += abs(position - tree) + EAT_T...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto S = readln.chomp; auto N = S.length.to!int; auto K = readln.chomp.to!int; auto dp = new...
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.concurrency; import core.bitop : popcnt; alias Generator ...
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 ...
D
import core.bitop, 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
import std.stdio;import std.conv;import std.string; void main(){ writeln( (readln().chomp().to!int())^^3 ); }
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, std.datetime; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generat...
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long....
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int h, w; rd(h, w); auto d=new int[][](10, 10); foreach(i; 0..10) d[i]=readln.split.to!(int[]); auto a=new int[][](h, w); foreach(i; 0..h) a[i]=readln.split.to!(int[]); foreach(_; 0..10)foreach(i; 0..10)foreach(j; 0..10){ d[i][j]=mi...
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!(long[]); auto A = abc[0]; auto B = abc[1]; auto C = abc[2]; int r; foreach (_; 0..1000) { if (A%2 == 1 || B%2 == 1 || C%2 == 1) { ...
D
void main() { problem(); } void problem() { auto N = scan!int; auto M = scan!int; auto K = scan!long; auto A = scan!long(N); auto B = scan!long(M); long solve() { long[] sumA = new long[N+1]; foreach(i; 1..N+1) sumA[i] = sumA[i-1] + A[i-1]; long[] sumB = new long[M+1]; foreach(i; 1..M+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
// Vicfred // https://atcoder.jp/contests/abc177/tasks/abc177_b // implementation, string manipulation import std.algorithm; import std.stdio; import std.string; void main() { string s = readln.strip; string t = readln.strip; long minima = t.length; for(int i = 0; i + t.length <= s.length; ++i) { ...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto xs = readln.split.to!(int[]); if (xs[0] != xs[1]) writeln(xs.reduce!max * 2 - 1); else writeln(xs[0] * 2); }
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 a = readln.split.to!(...
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, std.format, std.bitmanip, std.numeric; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.stdio; import std.string; import std.range; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { string s; while ((s = readln.chomp).length > 0) { ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; void main(){ auto Q=readln.split.to!(int[]),A=Q[0],B=Q[1]; if(A+B<10)writeln(A+B); else writeln("error"); }
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.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(){ auto n = read...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto ni = readln.split.to!(int[]); writeln(ni[0] - ni[1] + 1); }
D
import std.stdio; import std.algorithm; import std.conv; import std.string; void main() { auto tokens = split(chomp(readln())); auto n = to!int(tokens[0]); auto m = to!int(tokens[1]); string s = chomp(readln()); int[][] node; node.length = n; foreach (i; 0..m) { auto tokens2 = split(chomp(readln())); a...
D
void main() { string n = rdStr; writeln(n.canFind('7') ? "Yes" : "No"); } 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 rdElem(T)() ...
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, std.conv, std.string; long search(long n, long k, long cur) { if (n == 0) { return cur; } long a = search(n-1, k, cur+k); long b = search(n-1, k, cur*2); return (a>b) ? b : a; } void main() { long n, k; scanf("%d %d", &n ,&k); writeln(search(n, k, 1)); }
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() { auto s = readln.split.to!(int[]).sum();...
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; void main(){ int n = readln.chomp.to!int; int[] as = readln.chomp.split.map!(to!int).array; int c = 0; foreach(a; as) if(a % 2) c += 1; string ans; if(c % 2) ans =...
D
import std.stdio; import std.algorithm; import std.conv; import std.string; void main() { auto tokens = split(chomp(readln())); auto x1 = to!int(tokens[0]); auto y1 = to!int(tokens[1]); auto x2 = to!int(tokens[2]); auto y2 = to!int(tokens[3]); int dx = x2 - x1; int dy = y2 - y1; int x3 = x2 + -1 * dy;...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { readln.chomp.map!(c => c == '+' ? +1 : -1).sum.writeln; }
D
void main() { int[] tmp = readln.split.to!(int[]); int x = tmp[0], y = tmp[1], z = tmp[2]; writeln((x - z) / (y + z)); } 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.type...
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; alias Pair = Tuple!(int, "val", int, "num"); void main() { int n...
D
import std.stdio, std.string, std.conv, std.algorithm; void main(){ int n, m, q; rd(n, m, q); auto cul=new int[][](n+1, n+1); foreach(_; 0..m){ int l, r; rd(l, r); cul[l][r]++; } for(int i=1; i<=n; i++){ foreach(j; 0..n) cul[i][j+1]+=cul[i][j]; } while(q--){ int l, r; rd(l, r); int n...
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto n = lread(); auto a = aryread(); auto ans = new long[](n + 1); foreach (i; 0 .. n) { ans[a[i]] = i + 1; } // writel...
D
import std.stdio,std.array,std.conv,std.algorithm,std.range,std.string; void main(string[] args) { string[2] a; a[0] = readln.chomp; a[1] = readln.chomp; if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0]){ "YES".writeln; }else{ "NO".writeln; } }
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; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; void main() { auto input = readln.chomp.split.to!(long[]); long a = input[0]; long b = input[1]; long x = input[2]; writeln((a <= x && x <= a + ...
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; import std.conv; import std.algorithm; import std.range; import std.string; void main() { while (true) { auto input = readln.chomp.split.map!(to!int); if (input.array == [0, 0]) break; int n = input[0]; int x = input[1]; int cnt = 0; for (int i = 1; i <= n; i++) { fo...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; long P = 10^^9+7; long 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 main() { auto ...
D
void main() { int[][] c = new int[][](3, 3); foreach (i; 0 .. 3) { int[] tmp = readln.split.to!(int[]); foreach (j, x; tmp) { c[i][j] = x; } } bool ok = true; foreach (i; 1 .. 3) { int[] diff = new int[3]; foreach (j; 0 .. 3) { diff[j] ...
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!int; if (N == 0) { writeln(0); return; } int[] po; while (N != 0) { const c = abs(N % 2); po ~= c; N = (N - c) / (-2);...
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.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons, std.math; void main() { ulong N = readln.chomp.to!ulong; ulong res = ulong.max; ulong m = 1 + cast(ulong)ceil(sqrt(cast(double)N)); foreach(i; 1..m) { if(N % i == 0) { ulong j ...
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 nzw = readln.split.to!(int[]); auto N = nzw[0]; auto Z = nzw[1]; auto W = nzw[2]; auto as = readln.split.to!(int[]).reverse.array; auto DP = new i...
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; T gcd(T)(T a, T b) { ...
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; import std.range; void main() { auto tmp = readln.split.to!(int[]); auto H = tmp[0], W = tmp[1]; char[][] S; foreach (i; 0..H) { S ~= readln.ch...
D
import std.stdio, std.string, std.conv, std.math; void main() { int n = stdin.readln.chomp.to!int; long debt = 100000; foreach(i;0..n) { debt += debt * 0.05; debt = (((debt / 1000.0).ceil) * 1000).to!long; } debt.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
/+ dub.sdl: name "B" 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, m; sc.read(n, m); int[] deg = new int[n]; foreach (i; 0..m) { int a, b; ...
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.algorithm; void main() { auto d = readln.chomp.to!(char[]); d.reverse; d.writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.c...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int m; scan(m); auto ans = 24 - m + 24; writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range....
D
void main() { long n, t; rdVals(n, t); long[] a = rdRow; long total; long time; foreach (x; a) { if (x < time) { long diff = t - time + x; total += diff; time += diff; } else { total += t; ti...
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; } /* (1からNではなく、0からN-1として考える) ...
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
import std.stdio, std.conv, std.algorithm, std.array, std.string; void main(){ int n = to!int(readln.chomp); foreach(_; 0..n){ auto ns = array(map!(to!int)(readln.chomp.split)); writeln(solve(ns) ? "YES" : "NO"); } } bool solve(int[] ns){ foreach(bit; 0..1<<ns.length){ int[2] prev; bool ok = true; forea...
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 mod = 10L^^9 + 7; enum inf = 10^^9; void main() { int n, ma, mb; scan(n, ma, mb); auto a = new int[](n); auto b = new int[](n); auto c = n...
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(); } bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); } voi...
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.concurrency; void times(alias fun)(int n) { foreach(i...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.c...
D
void main() { long n = rdElem; string s = rdStr; long len = s.length; foreach (i; 0 .. 4) { string t; t ~= (i & 1 ? 'S' : 'W'), t ~= ((i >> 1) & 1 ? 'S' : 'W'); foreach (j; 1 .. len+1) { if ((t[j] == 'S') == (s[j%len] == 'o')) t ~= t[j-1]; els...
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; void main() { int[] input = readln.split.to!(int[]); int W = input[0]; in...
D
void main() { long n = readln.chomp.to!int; long[] a = readln.split.to!(long[]); long l, r = a.sum; long diff = long.max; foreach (i; 0 .. n) { if (abs(r-l-2*a[i]) < diff) { l += a[i]; r -= a[i]; diff = abs(r-l); } else { break; ...
D
import std.algorithm, std.string, std.array, std.range, std.stdio, std.conv; void main() { int n = readln.chomp.to!int; int m = 1; while (m < n) { m *= 2; } writeln(m / (m == n ? 1 : 2)); }
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 s = readln.chomp; s[0..$-8].writeln; }
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, std.format, std.bitmanip; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : ...
D
void main() { long[] tmp = rdRow; long h = tmp[0], a = tmp[1]; writeln((h + a - 1) / a); } T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)() if (is(T == struct)) { T result; string[] input = r...
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 a = rd[0], b = rd[1], c = rd[2]; writeln(a < b && b < c ? "Yes" ...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { string[] inputs = split(readln()); int A = to!int(inputs[0]); int B = to!int(inputs[1]); if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) "Possible".writeln; else "Impossible".writeln; }
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; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return fals...
D
import std.algorithm; import std.container; import std.conv; import std.format; import std.range; import std.stdio; import std.string; void main() { string s = readln.strip; int w = 0, l = 0; foreach (i, h; s) { if (i % 2 == 0 && h == 'p') { l++; } else if (i % 2 == 1 && h == ...
D
// Cheese-Cracker: cheese-cracker.github.io void play(){ int n; n = rd!int; auto mat = new ll[][](n, n); foreach(i; 0..n){ mat[i][] = 0; mat[i][i] = 1; mat[i][(i + 1) % n] = 1; } foreach(i; 0..n){ mat[i].each!(a => write(a, " ")); writeln; } } int ma...
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
void main() { string s = readln.chomp; long ind; long cnt; long op; while (ind < s.length) { if (s[ind] == 'A') { ++cnt; } else { if (ind < s.length - 1 &&s[ind] == 'B' && s[ind+1] == 'C') { op += cnt; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; alias E = Tuple!(int, "to", int, "cap", size_t, "rev"); E[][100+100+2] G; bool[100+100+2] USED; void main() { auto hw = readln.split.to!(int[]); auto H = hw[0]; auto W = hw[1]; auto lake = new char...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto as=readln.split.to!(int[]); auto t1=new int[](n), t2=new int[](n); foreach(i, a; as) t1[i]=a-1, t2[i]=1_000_000-a; auto mn=1_000_000_000; for(int i=0; i<=n; i++){ if(i==0) mn=min(mn, t2[i]); else if(i==n) ...
D
/+ dub.sdl: name "E" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; // import dcomp.datastructure.unionfind; int main() { auto sc = new Scanner(stdin); int m, h; sc.read(m, h); int n = 2*h+2; int[][] g...
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
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, 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() { string s; readV(s); writeln(s[0]...
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.datastructure.lazyseg; int main() { auto sc = new Scanner(stdin); int n, m; sc.read(n, m); int[] l = new int[n], r = ne...
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
void main() { string s, t; ipElems(s, t); long a, b; ipElems(a, b); string u = rdStr; if (u == s) --a; if (u == t) --b; writeln(a, " ", b); } 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...
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.string, std.conv; void main() { int N = to!int(readln.chomp); int[char] hash; for (int i = 0; i < N; i++) { string s = readln.chomp; if ("MARCH".count(s[0])) { hash[s[0]]++; } } int[] a = hash.values ~ [0, 0, 0, 0, 0]; long ans = 0; for (int i = 0; ...
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!(long[]); auto A = abc[0]; auto B = abc[1]; auto C = abc[2]; writeln((A+B >= C ? C : A+B+1) + B); }
D
import std.stdio, std.string, std.conv; void main() { int n = readln.chomp.to!int; int[] p = readln.split.to!(int[]); int cnt; foreach (i; 1 .. n-1) { if (p[i-1] < p[i] && p[i] < p[i+1]) ++cnt; if (p[i-1] > p[i] && p[i] > p[i+1]) ++cnt; } cnt.writeln; }
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; } /* ビットDP x[m]: ビットマップmで表...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto a = readln.split.to!(int[]); writeln(a.reduce!max - a.reduce!min); }
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
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 =...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto lr = readln.split.to!(long[]); auto L = lr[0]; auto R = lr[1]+1; if (R-L >= 2019L) { writeln(0); return; } long x = long.max; foreach (l; L..R) { ...
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(string s) { int ans = 0; int lo = 0...
D