code
stringlengths
4
1.01M
language
stringclasses
2 values
unittest { assert( [ "happy,newyear,enjoy" ].parse.expand.solve == "happy newyear enjoy" ); assert( [ "haiku,atcoder,tasks" ].parse.expand.solve == "haiku atcoder tasks" ); assert( [ "abcde,fghihgf,edcba" ].parse.expand.solve == "abcde fghihgf edcba" ); } import std.conv; import std.range; import std.stdio; impor...
D
import std.stdio; import std.conv; import std.string; import std.math; int f(int x, int y) { return x - y + 1; } void main() { int n = readln.strip.to!int; int h = readln.strip.to!int; int w = readln.strip.to!int; writeln(f(n, h) * f(n, w)); }
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 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 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
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, a, b; scan(n, a, b); au...
D
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range; T Read(T)() { return readln.chomp.to!(T); } T[] Reads(T)() { return readln.split.to!(T[]); } alias read = Read!(int); alias reads = Reads!(int); void main() { string s = readln.chomp; foreach (i;0..3) if (s[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; 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 r...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import 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 route...
D
import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main () { string a; while ((a = readln.strip) != "") { auto n = a.length.to !(int); int [char] w; foreach (c; a) { w[c] += 1; } auto res = 1 + (n * (n - 1L)) / 2; foreach (k, v; w) { res -= (v * ...
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { long N = readln.chomp.to!long; bool[long] A; foreach (_; 0..N) { long a = readln.chomp.to!long; if (a in A) { ...
D
import std.stdio; import std.conv; import std.algorithm; import std.range; import std.string; import std.typecons; import std.math; import std.random; import std.range; void main() { auto a = readln().strip.split(" ").map!(to!int); auto c = 0; foreach (i; iota(a[0])) { auto k = readln.strip.to!i...
D
import std.stdio, std.string, std.array, std.conv; struct S { string name; int time; } struct T { private: int n; S[] s; public: this(int n) { this.s = new S[](n); } ulong length() { return s.length; } S front() { return s[0]; } void pop() { ...
D
// Cheese-Cracker: cheese-cracker.github.io void solve(){ auto arr = scanArray; auto summ = arr[6]; long a = summ - arr[5]; long b = summ - arr[4]; long c = summ - a - b; writeln(a, " ", b, " ", c); } void main(){ long tests = scan; // Toggle! while(tests--) solve; } /*********...
D
import std.algorithm, std.string, std.array, std.range, std.stdio, std.conv; void main() { int n = readln.chomp.to!int; int[] a = readln.chomp.split.to!(int[]); int m1, m2, m4; bool flag; foreach (ai; a) { if (ai % 4 == 0) { m4++; } else if (ai % ...
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 s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto C = readln.split.map!(to!...
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 route...
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.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 n; while ((n = readint) > ...
D
import std.stdio; import std.string; import std.range; import std.conv; void main() { auto ip = readln.split.to!(int[]), a = ip[0], b = ip[1]; writeln(((b-a)*(1+(b-a))/2)-b); }
D
void main() { dchar c = rdElem!dchar; writeln((c + 1).to!dchar); } T rdElem(T = long)() { //import std.stdio : readln; //import std.string : chomp; //import std.conv : to; return readln.chomp.to!T; } alias rdStr = rdElem!string; dchar[] rdDchar() { //import std.conv : to; return rd...
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.algorithm, std.math, std.array, std.container, std.typecons; alias tuple = Tuple!(long,long,long); void main() { long n = readln.chomp.to!long; long[] a = readln.chomp.split.to!(long[]); long[long] l; long[long] r; for(long i=0; i<n; i++) { l[i+1+a[i]]+...
D
unittest { assert( [ "ant", "obe", "rec" ].parse.expand.solve == "abc" ); assert( [ "edu", "cat", "ion" ].parse.expand.solve == "ean" ); } import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; void main() { stdin.byLineCopy.parse.expand.solve.writeln; } auto parse( Range )...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto s = readln.chomp; auto K = readln.chomp.to!int; string[] ss; bool[string] memo; foreach (i; 0..s.length) { foreach (j; i+1..min(i+6, s.length+1)) { if (s[i....
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 main() { string str = readln.chomp...
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; bool f1, f2; foreach (e; s) { if (!f1) { if (e =...
D
#!/usr/bin/rdmd import std.stdio; immutable hW = "Hello World"; void main() { foreach(i;0..1000) { writeln(hW); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { readln; auto hs = readln.split; sort(hs); writeln(hs.uniq.count == 3 ? "Three" : "Four"); }
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; import std.string; import std.conv; void main() { auto input = split( readln() ); int sup = to!int(input[1]), inf = to!int(input[0]); int i = inf; int cnt = 0; while (i <= sup) { int n1 = i % 10; int n2 = (i % 100 - n1) / 10; int n3 = (i % 1000 - 10 * n2 - n1) / 100; int n4 = (i % 1000...
D
import std.stdio, std.conv, std.string; void main() { auto N = readln.chomp; writeln("ABC", N); }
D
void main() { problem(); } void problem() { auto N = scan!int; auto D = N.iota.map!(x => [scan!int, scan!int]); string solve() { int continuasLevel; foreach(d; D) { if (d[0] == d[1]) continuasLevel++; if (d[0] != d[1]) continuasLevel = 0; if (continuasLevel == 3) { return "Y...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto a = readln.chomp.split.to!(int[]); auto f = fa...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { long a, b, c, d; scan(a, b, c, d); auto a...
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.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; 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.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.array,std.algorithm; void main(){ for(;;write("\n")){ auto a = readln().chomp().split(); if( a[0]=="0" && a[1]=="0" ){ break; } foreach(y;0..to!int(a[0])){ foreach(x;0..to!int(a[1])){ write("#"); } 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; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int N, K; scan(N, K); auto ans = K; foreach (i ; 0 .. ...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { writeln(700 + readln.chomp.to!(char[]).count!(x=>x=='o') * 100); }
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
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 { int k; } void parseInput(T)(out Input input, T file) { with (file) with (input) { k = readln().strip().t...
D
// Vicfred // https://atcoder.jp/contests/abc159/tasks/abc159_a // math import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; long gauss(long n) { return n*(n-1)/2; } void main() { long n = readln.chomp.to!long; long[] a = readln.split.map!(to!long).array; long...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens....
D
void main() { auto N = ri; auto A = iota(N).map!(a => ri).array; if(A[0] > 0) { // むりむりのむり(X[0]は0以外の非負整数になれない) writeln(-1); return; } foreach_reverse(i; 1..N) { if(A[i]-A[i-1] > 1) { // むりむりのむり(数列を作る過程で(後ろ)-(前)が2以上にすることはできない) writeln(-1); return; } } ulong ans; foreach_reverse(i; 1..N) { debug w...
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.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; void main() { int n = readln.chomp.to!int, ans; bool[int] mp; foreach(i; 0..n) { int d = readln.chomp.to!int; // keyが連想配列に登録されているかどうか if ((d in mp) == null) { ans++; mp[d] = true; } } ...
D
import std.algorithm; import std.stdio; import std.string; import std.conv; void main() { uint[] arr; foreach(i; 0 .. 10) arr ~= readln().chomp().to!uint(); arr.sort!"a > b"(); foreach(i; 0 .. 3) writeln(arr[i]); }
D
import std.stdio,std.conv,std.string; void main(){ auto args = readln().chomp().split(); writeln( to!int(args[0]) * to!int(args[1])," ",(to!int(args[0]) + to!int(args[1])) * 2 ); }
D
import std.stdio; import std.string; import std.range; import std.conv; void main() { auto ip = readln.split.to!(int[]), a = ip[0], b = ip[1], c = ip[2]; if(b-a==c-b){ writeln("YES"); }else{ writeln("NO"); } }
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() { string s; readV(s); auto n = s.length.to!int, k = (n+1)/2+1; for (; k <= n; ++k) if...
D
/+ dub.sdl: name "C" dependency "dcomp" version=">=0.7.4" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); int n; int[] a, b, c; sc.read(n, a, b, c); a.sort!"a<b"; b.sort!"a<b"; c.sort!...
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; import std.algorithm; import std.string; import std.conv; import std.math; void main(){ while(true){ auto s = readln(); if(stdin.eof()) break; s = chomp(s); if(s=="")break; string s1,s2; s1 = s; s2 = s; while(s1.length > 1){ s2 = ""; for(int i=0;i<s1.length-1;i++){ s2 ~= to!ch...
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); auto 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; enum MAX = 1_000_100; ulong MOD = 1_000_000_007...
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 MOD = 998244353; void main() { auto S = readln.chomp; auto N = S.length.to!int; long ans = 1;...
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, k; scan(n, k); int ans = n - k + 1...
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.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(long[]), a = rd[0], b = rd[1], x = rd[2]; if (a > 0) writeln(b/x - (a-1)/x); else writeln(b/x + 1); }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.math; void main() { int N; N = readln.chomp.to!int; auto s = [0, 0, 0]; bool is_reach = true; for (int i = 0; i < N; ++i) { auto g = readln.chomp.split.map!(to!int).array; int t = g[0] - s[0], d...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; void main() { int[3] pasta; int[2] drink; foreach (i; 0..3) { pasta[i] = readln.chomp.to!int; } foreach (i; 0..2) ...
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.algorithm, std.conv, std.array, std.string, std.math; int[10^^5+2] CNT; void main() { auto N = readln.chomp.to!int; auto as = readln.split.to!(int[]); foreach (a; as) { CNT[a == 0 ? 10^^5+1 : a-1]++; CNT[a]++; CNT[a+1]++; } int m = 0; foreach (cnt;...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { writeln("A" ~ readln.split[1][0] ~ "C"); }
D
import std.stdio, std.conv, std.string, std.algorithm.comparison, std.algorithm.searching, std.algorithm.sorting; void main() { int[] input = readln().split.to!(int[]); int X = input[0]; int Y = input[1]; writeln(X + Y / 2); }
D
import std.stdio, std.string, std.algorithm; void main() { string s = readln.chomp; s ~= s; string p = readln.chomp; writeln(s.canFind(p) ? "Yes" : "No"); }
D
import std.stdio, std.string, std.conv; void main() { auto x = readln.split.to!(int[]), n = x[0], a = x[1], b = x[2]; if(a*n < b){ writeln(a*n); } else { writeln(b); } }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; void main() { int n, a, b; auto l = readln.chomp.split.map!(to!int); n = l[0], a = l[1], b = l[2]; long ans; // longである必要はない foreach(i; 1..(n + 1)) { int sum, num = i; while (num > 0) { sum += (num %...
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 S = readln.chomp; auto N = S.length.to!int; if (S.map!(s => s == S[0]).all) { writeln(...
D
import std.stdio, std.conv, std.string, std.math; void main(){ auto ip = readln.split.to!(int[]); if(ip[0] == ip[1]){ "Draw".writeln; } else if(ip[0] == 1){ "Alice".writeln; } else if(ip[1] == 1){ "Bob".writeln; } else if (ip[0] > ip[1]){ "Alice".writeln; } else { "Bob".writeln; } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum PCNT = 10^^6; bool[PCNT+1] PS; void prime_init() { PS[] = true; PS[0] = false; PS[1] = false; foreach (i; 2..PCNT+1) { if (PS[i]) { auto x = i*2; while (x <= PCN...
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>=24)writeln((A+B)-24); else writeln(A+B); }
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 readS(T)(size_t n,ref T t){t=new T(n);foreach(...
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 s = readln.chomp.split.to!(int[])[1]; auto x = readln.chom...
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; long digit_sum(long b, long n) { if (n < b) return n; else return digit_sum(b, n/b) + n % b; } voi...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto N = readln.chomp.to!(wchar[]); writeln(N[1] != N[2] ? "No" : N[0] == N[1] || N[2] == N[3] ? "Yes" : "No"); }
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 x, y; scan(x, y); long[] tmp; tmp ~= x; while (...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int y, b, r; rd(y, b, r); int mx = 0; for (int i = 1; i <= y; i++) { for (int j = 1; j <= b; j++) { for (int k = 1; k <= r; k++) { if (i + 1 == j && j + 1 == k) { mx = max(mx, i + j + k); } } }...
D
void main() { problem(); } void problem() { auto N = scan!int; auto A = scan!long(N); long solve() { ulong ans; long sumA; foreach(a; A) sumA = (sumA + a) % MOD; foreach(i; 0..N-1) { sumA -= A[i]; if (sumA < 0) sumA += MOD; auto add = (A[i] * sumA) % MOD; ans = (ans +...
D
import std.stdio; import std.conv; import std.string; void main() { auto n = readln.chomp.to!(int); ((n / 111 + (n % 111 != 0)) * 111).writeln; }
D
import std.stdio,std.conv,std.algorithm,std.array; int[] raia() { return readln().split().map!(to!int).array; } //read stdin as int[] void main(){ auto it = raia(); int count; for(auto i=it[0];i<=it[1];i++) if(it[2]%i == 0) count++; writeln(count); }
D
// unihernandez22 // https://atcoder.jp/contests/abc157/tasks/abc157_b // implementation import std.stdio: writeln, writefln, readln; import std.array: array, split; import std.algorithm: map; import std.string: chomp; import std.conv: to; void main() { int[3][3] bingo; foreach(byte i; 0..3) { int[3] input = read...
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, 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; long X; int cnt = 0; void ans(long x) { debug { writeln((x == X) ? "OK ": "NG"); writeln(cnt); re...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { auto a = readln.split.to!(int[]); a...
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.random; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) ...
D
import std.stdio, std.string, std.conv, std.algorithm, std.array; void main() { string S, T; S = readln().chomp(); T = readln().chomp(); string res = S.replace("?","z"); const string ng = "UNRESTORABLE"; bool flg = false; foreach(int i; 0..(to!(int)(S.length)-to!(int)(T.length)+1)) { bool f = true; foreach(...
D
import std.stdio, std.string, std.conv; void main() { auto r = readln.split.to!(int[]), R = r[0]; auto g = readln.split.to!(int[]), G = g[0]; writeln(2*G-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, std.bitmanip; const long INF = 1L << 59; void main() { auto N = readln.chomp.to!int; auto dp = new long[](1 << 3); fill(dp, INF...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; import std.array; int readInt(){ return readln.chomp.to!int; } int[] readInts(){ return readln.chomp.split.to!(int[]); } void main(){ int s = readInt(), n; int[] dic; dic ~= s; for(n = 2; ; n++){ if(s % 2 ...
D
import std.stdio; import std.string; import std.conv; void main(){ while(true){ auto s = readln(); if(stdin.eof()) break; real w = to!real(chomp(s)); if(w <= 48.0) writeln("light fly"); else if(w <= 51.0) writeln("fly"); else if(w <= 54.0) writeln("bantam"); else if(w <= 57.0) writeln("feather"); else if(...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { int N = to!int(chomp(readln())); int K = to!int(chomp(readln())); int X = to!int(chomp(readln())); int Y = to!int(chomp(readln())); int fee; if(N < K) { fee = N*X; fee.writeln; return; } fee += K*X; if(!N-K < 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.stdio, std.bitmanip; immutable int MAX = 10^^3+1; immutable long MOD = 10^^9+7; auto modinv = new long[](MAX); auto f_mod = new lo...
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(); long cnt; foreach (i; 1 .. n + 1) { string s; s = i.to!string(); if (s.length % 2 != 0) { ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; alias L = Tuple!(int, "level", long, "size", long, "patty"); L[51] LS; void main() { LS[0] = L(0, 1, 1); foreach (i; 0..50) { auto l = LS[i]; LS[i+1] = L(i+1, l.size*2 + 3, l.patty*2 + 1); ...
D