code
stringlengths
4
1.01M
language
stringclasses
2 values
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 readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}} void main() { string[] s; readC(3, s); auto t = 0, i = new int[](3); for (;;) { if (i[t] >= s[t].length) { writeln(cast(char)('A'+t)); return; } t = cast(int)(s[t][i[t]++]-'a'); } }
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 ap = readNums!int; writeln((ap[0]*3+ap[1])/2); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias SugarWater = Tuple!(long, "swater", long, "sugar"); T lread(T = long)() { return readln.chomp.to!T(); } 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].to!(T); Args[i] = val; } } void main() { auto n = lread(); long mini = n; foreach (i; iota(0, n + 1)) { auto rest = n - i; auto nine = calmoves(i, 9); auto six = calmoves(rest, 6); mini = min(nine + six, mini); } mini.writeln(); } auto calmoves(long n, long div) { auto powers = [div]; while (powers[$ - 1] < n) powers ~= powers[$ - 1] * div; // powers.writeln(); long moves, current = powers.length - 1; while (current >= 0) { auto t = n / powers[current]; // writefln("%stimes : %s", n, t); moves += t; n -= powers[current] * t; current--; } return moves + n; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[101] T; void main() { auto N = readln.chomp.to!int; foreach (a; readln.split.to!(int[])) ++T[a]; size_t i; for (;; ++i) { if (T[i] == 0) continue; break; } auto h = i.to!int; if (T[i] == 2) { --h; } else if (T[i] > 2) { writeln("Impossible"); return; } int s = T[i]; foreach (_; 0..h) { ++i; if (T[i] < 2) { writeln("Impossible"); return; } s += T[i]; } writeln(s == N ? "Possible" : "Impossible"); }
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 n; } void parseInput(T)(out Input input, T adapter) { with (input) { n = adapter.readln(); } } struct Output { } auto main2(Input* input) { int sum = 0; foreach (c; input.n) sum += c - '0'; return (sum % 9) == 0 ? "Yes" : "No"; } alias retType = ReturnType!main2; static if (!is(retType == void)) { unittest { writeln("begin unittest"); } auto _placeholder_ = ReturnType!main2.init; unittest // example1 { string example = `123456789`; if (example.empty) return; Input input = void; parseExample(input, example); auto result = main2(&input); printResult(result); assert(result == "Yes"); } unittest // example2 { string example = `0`; if (example.empty) return; Input input = void; parseExample(input, example); auto result = main2(&input); printResult(result); assert(result == "Yes"); } unittest // example3 { string example = `31415926535897932384626433832795028841971693993751058209749445923078164062862089986280`; if (example.empty) return; Input input = void; parseExample(input, example); auto result = main2(&input); printResult(result); assert(result == "No"); } unittest { writeln("end unittest"); } void parseExample(out Input input, string example) { parseInput(input, new StringAdapter(example)); } } class StdinAdapter { // readf!"%s"は使えない // https://issues.dlang.org/show_bug.cgi?id=19820 uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); } string readln() { return std.stdio.readln().strip(); } } class StringAdapter { import std.format; string _s; this(string input) { _s = input; } uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); } string readln() { auto i = _s.countUntil("\n"); if (i == -1) i = _s.length; string ret = _s[0..i]; _s = _s[i..$]; return ret; } } void printResult(T)(T result) { static if (isFloatingPoint!T) writefln("%f", result); else writeln(result); } void main() { Input input = void; parseInput(input, new StdinAdapter()); static if (is(retType == void)) main2(&input); else { auto result = main2(&input); printResult(result); } }
D
import std.conv, std.stdio; import std.algorithm, std.array, std.range, std.string; enum p = 26; void main() { (readln.chomp.to!ulong - 1).solve.writeln; } private: auto solve(ulong n) { long a = p; auto i = 1; while (a <= n) { n -= a; a *= p; i += 1; } return n.to26ary(i); } unittest { foreach (i; 0..1000) i.solve.write(" "); foreach (i; 999_9999_9999_9000..1000_0000_0000_0002) i.solve.write(" "); } auto to26ary(ulong n, int i) { string ret; foreach (_; 0..i) { ret = cast(char)('a' + (n % p)) ~ ret; n /= p; } return ret; }
D
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { const int MOD = 998244353; int k, n; scanf("%d%d", &k, &n); long[][] r = new long[][](2,k+1); long[] dp = new long[n+1]; dp[0] = 1; foreach (i; 0..k) { foreach (j; 0..n) { (dp[j+1] += dp[j]) %= MOD; } } foreach (i; 0..k+1) { r[0][i] = dp[n]; foreach_reverse (j; 0..n) { (dp[j+1] += MOD - dp[j]) %= MOD; } r[1][i] = (dp[n] + dp[n-1]) % MOD; foreach_reverse (j; 0..n) { (dp[j+1] += MOD - dp[j]) %= MOD; } long[] a = dp.dup; foreach (j; 0..n) { (a[j+1] += a[j]) %= MOD; } foreach (j; 0..n) { (dp[j+1] += a[j]*2) %= MOD; } } foreach (i; 2..2*k+1) { int a = 1-i%2; int b = -a; foreach (j; 1..k+1) { int nj = i-j; if (1 <= nj && nj <= k) b++; } b /= 2; //writeln(i," ",a," ",b); writeln(r[a][b]); } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.numeric; void main() { auto s = readln.chomp; auto rn = s.count('0'); auto bn = s.count('1'); writeln(min(rn, bn) * 2); }
D
void main() { long n = readln.chomp.to!long; long mod = 10 ^^ 9 + 7; long[] factors = new long[n+1]; foreach (i; 1 .. n+1) { long d = i; long tmp; while (d % 2 == 0) { ++tmp; d /= 2; } factors[2] += tmp; long ind = 3; while (ind * ind <= d) { tmp = 0; while (d % ind == 0) { ++tmp; d /= ind; } factors[ind] += tmp; ind += 2; } if (d > 1) { ++factors[d]; } } long result = 1; foreach (i; 0 .. n+1) { if (factors[i] > 0) { result = result * (factors[i] + 1) % mod; } } result.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto D = readln.chomp.to!int; switch (D) { case 22: writeln("Christmas Eve Eve Eve"); break; case 23: writeln("Christmas Eve Eve"); break; case 24: writeln("Christmas Eve"); break; case 25: writeln("Christmas"); break; default: } }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.uni; import std.range; import std.algorithm; void main() { while (!stdin.eof) { auto a = readln.strip; if (a == "-") break; auto m = readln.strip.to!int; foreach (x; iota(m).map!(x => readln.strip.to!int)) { a = a[x..$] ~ a[0..x]; } writeln(a); } }
D
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } //Digit count---{{{ int DigitNum(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } //}}} //}}} void main() { Scanner sc = new Scanner; int N; sc.scan(N); int[] A = new int[N]; foreach (i; 0 .. N) sc.scan(A[i]); int res = 0; Break1: while (true) { foreach (i; 0 .. N) { if (A[i] % 2 != 0) break Break1; else A[i] /= 2; } res++; } writeln(res); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { string vo = "aiueo"; char a; scan(a); writeln(vo.canFind(a) ? "vowel" : "consonant"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
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 s = readln.split.map!(to!int); auto N = s[0]; auto Q = s[1]; if (N == 1) { while (Q--) { s = readln.split.map!(to!int); auto v = s[0]; auto w = s[1]; writeln(min(v, w)); } return; } while (Q--) { s = readln.split.map!(to!int); auto v = s[0]-1; auto w = s[1]-1; while (v != w) { if (v > w) swap(v, w); int q = w % N; if (q == 0) q = N; w = (w-q) / N; } writeln(v+1); } }
D
void main() { long n = rdElem; writeln((n + 1) / 2); } 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 rdDchar = rdElem!(dchar[]); T rdElem(T)() if (is(T == struct)) { T result; string[] input = rdRow!string; assert(T.tupleof.length == input.length); foreach (i, ref x; result.tupleof) { x = input[i].to!(typeof(x)); } return result; } T[] rdRow(T = long)() { return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { return iota(col).map!(x => rdRow!T).array; } void rdVals(T...)(ref T data) { string[] input = rdRow!string; assert(data.length == input.length); foreach (i, ref x; data) { x = input[i].to!(typeof(x)); } } void wrMat(T = long)(T[][] mat) { foreach (row; mat) { foreach (j, compo; row) { compo.write; if (j == row.length - 1) writeln; else " ".write; } } } 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.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } long mod = pow(10, 9) + 7; long moda(long x, long y) { return (x + y) % mod; } long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; } long modm(long x, long y) { return (x * y) % mod; } void main() { auto N = RD!long; auto M = RD!long; long ans = (N - M) * 100 + M * 1900; ans *= pow(2, M); writeln(ans); stdout.flush(); }
D
import std; void main() { int s, w; scan(s, w); writeln(s <= w ? "unsafe" : "safe"); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int;
D
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm; void main(){ auto ip = readln.split.to!(int[]), A = ip[0], B = ip[1]; int X; if(A > B){ X += A; A--; } else { X += B; B--; } if(A > B){ X += A; } else { X += B; } writeln(X); }
D
void main(){ int a, b; scanf("%d %d", &a, &b); writeln(a+b>=10?"error":(a+b).to!string); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
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 readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; bool calc(int n) { foreach (i; 1..10) { foreach (j; 1..10) { if (i * j == n) return true; } } return false; } void main() { int n = readint; writeln(calc(n) ? "Yes" : "No"); }
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_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto A = RD!string; auto B = RD!string; auto C = RD!string; writeln(A[$-1] == B[0] && B[$-1] == C[0] ? "YES" : "NO"); stdout.flush(); debug readln(); }
D
import std.stdio; void main() { int n; scanf("%d", &n); long[500][500] m; int r, c; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%lld", &m[i][j]); if (m[i][j] == 0) { r = i; c = j; } } } long sum = 0; long s = 1; if (n > 1) { int g = 0; if (r == 0) { g++; } for (int i = 0; i < n; i++) { sum += m[g][i]; } s = sum; for (int i = 0; i < n; i++) { s -= m[r][i]; } } else { sum = 1; } m[r][c] = s; long sumDiagL = 0; long sumDiagR = 0; for (int i = 0; i < n; i++) { long sumRow = 0; long sumCol = 0; for (int j = 0; j < n; j++) { sumRow += m[i][j]; sumCol += m[j][i]; } sumDiagL += m[i][i]; sumDiagR += m[n - 1 - i][i]; if (sumRow != sum || sumCol != sum) { s = -1; } } if (sumDiagL != sum || sumDiagR != sum) { s = -1; } if (s <= 0) { printf("-1\n"); } else { printf("%lld\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 std.regex; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; enum long INF = long.max/5; void main() { readln.chomp.any!"a=='7'".pipe!"a?\"Yes\":\"No\"".writeln; } // ---------------------------------------------- void times(alias fun)(long n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(long n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { // `(x+y-1)/y` will only work for positive numbers ... T t = x / y; if (y > 0 && t * y < x) t++; if (y < 0 && t * y > x) t++; return t; } T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { T t = x / y; if (y > 0 && t * y > x) t--; if (y < 0 && t * y < x) t--; return t; } ref T ch(alias fun, T, S...)(ref T lhs, S rhs) { return lhs = fun(lhs, rhs); } unittest { long x = 1000; x.ch!min(2000); assert(x == 1000); x.ch!min(3, 2, 1); assert(x == 1); x.ch!max(100).ch!min(1000); // clamp assert(x == 100); x.ch!max(0).ch!min(10); // clamp assert(x == 10); } mixin template Constructor() { import std.traits : FieldNameTuple; this(Args...)(Args args) { // static foreach(i, v; args) { foreach(i, v; args) { mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v; } } } void scanln(Args...)(auto ref Args args) { enum sep = " "; enum n = Args.length; enum fmt = n.rep!(()=>"%s").join(sep); string line = readln.chomp; static if (__VERSION__ >= 2074) { line.formattedRead!fmt(args); } else { enum argsTemp = n.iota.map!( i => "&args[%d]".format(i) ).join(", "); mixin( "line.formattedRead(fmt, " ~ argsTemp ~ ");" ); } } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { return reduce!fun(tuple(seed), r); } } } } // popcnt with ulongs was added in D 2.071.0 static if (__VERSION__ < 2071) { ulong popcnt(ulong x) { x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L); x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L); x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL); x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL); x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL); x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL); return x; } }
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 times(alias pred)(int n) { foreach(i; 0..n) pred(); } auto rep(alias pred, T = typeof(pred()))(int n) { T[] res = new T[n]; foreach(ref e; res) e = pred(); return res; } void main() { bool[] top = readln.chomp.map!(a => a=='p').array; int N = top.length.to!int; int[] ary = new int[N+1]; foreach(i, e; top) { ary[i+1] = ary[i] + (e ? -1:1); } writeln(ary.back/2); }
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 w, h, n; readV(w, h, n); auto x1 = 0, x2 = w, y1 = 0, y2 = h; foreach (_; 0..n) { int x, y, a; readV(x, y, a); switch (a) { case 1: x1 = max(x1, x); break; case 2: x2 = min(x2, x); break; case 3: y1 = max(y1, y); break; case 4: y2 = min(y2, y); break; default: assert(0); } } writeln(x2<x1 || y2<y1 ? 0 : (x2-x1)*(y2-y1)); }
D
// import std.stdio,std.array,std.conv; void main(){ auto sn=readln.split,n=to!int(sn[0]); auto sk=readln.split,k=to!int(sk[0]); int d=1; for(int i=0;i<n;i++){ int a=d*2; int b=d+k; if(a>b) d=b; else d=a; } writeln(d); }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { string s = readln.chomp; int c; foreach (i; 0..s.length-1) { if (s[i] != s[i + 1]) { c++; } } writeln(c); }
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", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } 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].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { auto a = sread(); auto b = sread(); bool z = a[0] == b[2] && a[1] == b[1] && a[2] == b[0]; writeln(z ? "YES" : "NO"); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.math; void main() { int a, b, x; scan(a, b, x); writeln(0 <= x - a && x - a <= b ? "YES" : "NO"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.string; import std.conv; void main() { int n; while ((n = readln.chomp.to!int) != 0) { int count = 0; while ((n /= 5) != 0) { count += n; } writeln(count); } }
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.3.2" lflags "-stack_size" "100000000" +/ import std.algorithm, std.conv, std.range, std.stdio; // import dcomp.scanner; // import dcomp.algorithm; // import dcomp.container.deque; int main(string[] argv) { auto sc = new Scanner(); int n, a, b; sc.read(n, a, b); int[] ti = new int[](n); foreach (i; 0..n) { sc.read(ti[i]); } writeln(n-ti.count!(x => (a <= x && x < b))); return 0; } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/container/deque.d */ // module dcomp.container.deque; struct Deque(T) { import core.exception : RangeError; import core.memory : GC; import std.range : ElementType, isInputRange; import std.traits : isImplicitlyConvertible; struct Payload { T *d; size_t st, length, cap; @property bool empty() const { return length == 0; } alias opDollar = length; ref inout(T) opIndex(size_t i) inout { version(assert) if (length <= i) throw new RangeError(); return d[(st+i >= cap) ? (st+i-cap) : st+i]; } private void expand() { import std.algorithm : max; assert(length == cap); auto nc = max(4L, 2*cap); T* nd = cast(T*)GC.malloc(nc * T.sizeof); foreach (i; 0..length) { nd[i] = this[i]; } d = nd; st = 0; cap = nc; } void insertFront(T v) { if (length == cap) expand(); if (st == 0) st += cap; st--; length++; this[0] = v; } void insertBack(T v) { if (length == cap) expand(); length++; this[length-1] = v; } void removeFront() { assert(!empty, "Deque.removeFront: Deque is empty"); st++; length--; if (st == cap) st = 0; } void removeBack() { assert(!empty, "Deque.removeBack: Deque is empty"); length--; } } struct RangeT(A) { alias T = typeof(*(A.p)); alias E = typeof(A.p.d[0]); T *p; size_t a, b; @property bool empty() const { return b <= a; } @property size_t length() const { return b-a; } @property RangeT save() { return RangeT(p, a, b); } @property RangeT!(const A) save() const { return typeof(return)(p, a, b); } alias opDollar = length; @property ref inout(E) front() inout { return (*p)[a]; } @property ref inout(E) back() inout { return (*p)[b-1]; } void popFront() { version(assert) if (empty) throw new RangeError(); a++; } void popBack() { version(assert) if (empty) throw new RangeError(); b--; } ref inout(E) opIndex(size_t i) inout { return (*p)[i]; } RangeT opSlice() { return this.save; } RangeT opSlice(size_t i, size_t j) { version(assert) if (i > j || a + j > b) throw new RangeError(); return typeof(return)(p, a+i, a+j); } RangeT!(const A) opSlice() const { return this.save; } RangeT!(const A) opSlice(size_t i, size_t j) const { version(assert) if (i > j || a + j > b) throw new RangeError(); return typeof(return)(p, a+i, a+j); } } alias Range = RangeT!Deque; alias ConstRange = RangeT!(const Deque); alias ImmutableRange = RangeT!(immutable Deque); Payload *p; private void I() { if (!p) p = new Payload(); } private void C() const { assert(p, "this deque is not init"); } //some value this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {I; p = new Payload(); foreach (v; values) { insertBack(v); } } //range this(Range)(Range r) if (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range, T) && !is(Range == T[])) {I; p = new Payload(); foreach (v; r) { insertBack(v); } } @property bool empty() const { return (!p || p.empty); } @property size_t length() const { return (p ? p.length : 0); } alias opDollar = length; ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; } ref inout(T) front() inout {C; return (*p)[0]; } ref inout(T) back() inout {C; return (*p)[$-1]; } void insertFront(T v) {I; p.insertFront(v); } void insertBack(T v) {I; p.insertBack(v); } void removeFront() {C; p.removeFront(); } void removeBack() {C; p.removeBack(); } Range opSlice() {I; return Range(p, 0, length); } } unittest { import std.algorithm : equal; import std.range.primitives : isRandomAccessRange; import std.container.util : make; auto q = make!(Deque!int); assert(isRandomAccessRange!(typeof(q[]))); //insert,remove assert(equal(q[], new int[](0))); q.insertBack(1); assert(equal(q[], [1])); q.insertBack(2); assert(equal(q[], [1, 2])); q.insertFront(3); assert(equal(q[], [3, 1, 2]) && q.front == 3); q.removeFront; assert(equal(q[], [1, 2]) && q.length == 2); q.insertBack(4); assert(equal(q[], [1, 2, 4]) && q.front == 1 && q.back == 4 && q[$-1] == 4); q.insertFront(5); assert(equal(q[], [5, 1, 2, 4])); //range assert(equal(q[][1..3], [1, 2])); assert(equal(q[][][][], q[])); //const range const auto rng = q[]; assert(rng.front == 5 && rng.back == 4); //reference type auto q2 = q; q2.insertBack(6); q2.insertFront(7); assert(equal(q[], q2[]) && q.length == q2.length); //construct with make auto a = make!(Deque!int)(1, 2, 3); auto b = make!(Deque!int)([1, 2, 3]); assert(equal(a[], b[])); } unittest { Deque!int a; Deque!int b; a.insertFront(2); assert(b.length == 0); } unittest { import std.algorithm : equal; import std.range : iota; Deque!int a; foreach (i; 0..100) { a.insertBack(i); } assert(equal(a[], iota(100))); } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f = stdin) { this.f = f; } string[] buf; private bool succ() { while (!buf.length) { if (f.eof) return false; buf = f.readln.split; } return true; } private bool readSingle(T)(ref T x) { if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { //string or char[10] etc x = buf.front; buf.popFront; } else { static if (isStaticArray!T) { //static assert(buf.length == T.length); } x = buf.map!(to!E).array; buf.length = 0; } } else { x = buf.front.to!T; buf.popFront; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } unittest { import std.path : buildPath; import std.file : tempDir; import std.algorithm : equal; import std.stdio : File; string fileName = buildPath(tempDir, "kyuridenanmaida.txt"); auto fout = File(fileName, "w"); fout.writeln("1 2 3"); fout.writeln("ab cde"); fout.writeln("1.0 1.0 2.0"); fout.close; Scanner sc = new Scanner(File(fileName, "r")); int a; int[2] b; char[2] c; string d; double e; double[] f; sc.read(a, b, c, d, e, f); assert(a == 1); assert(equal(b[], [2, 3])); assert(equal(c[], "ab")); assert(equal(d, "cde")); assert(e == 1.0); assert(equal(f, [1.0, 2.0])); } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */ // module dcomp.algorithm; //[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定 T binSearch(alias pred, T)(T l, T r) { while (r-l > 1) { T md = (l+r)/2; if (!pred(md)) l = md; else r = md; } return r; } import std.range.primitives; Rotator!Range rotator(Range)(Range r) if (isForwardRange!Range && hasLength!Range) { return typeof(return)(r); } struct Rotator(Range) if (isForwardRange!Range && hasLength!Range) { size_t cnt; Range start, now; this(Range r) { cnt = 0; start = r.save; now = r.save; } this(this) { start = start.save; now = now.save; } @property bool empty() { return now.empty; } @property auto front() { assert(!now.empty); import std.range : take, chain; return chain(now, start.take(cnt)); } @property Rotator!Range save() { return this; } void popFront() { cnt++; now.popFront; } } E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, E) == void)) { import std.functional; while (!range.empty) { if (binaryFun!pred(range.front, seed)) { seed = range.front; } range.popFront; } return seed; } ElementType!Range minimum(alias pred = "a < b", Range)(Range range) if (isInputRange!Range && !isInfinite!Range) { assert(!range.empty, "range must not empty"); auto e = range.front; range.popFront; return minimum!pred(range, e); } unittest { assert(minimum([2, 1, 3]) == 1); assert(minimum!"a > b"([2, 1, 3]) == 3); assert(minimum([2, 1, 3], -1) == -1); assert(minimum!"a > b"([2, 1, 3], 100) == 100); } bool[ElementType!Range] toMap(Range)(Range r) { import std.algorithm : each; bool[ElementType!Range] res; r.each!(a => res[a] = true); return res; }
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_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto X = RD; long ans; (){ foreach_reverse (i; 1..X+1) { foreach_reverse (j; 1..i+1) { if (j*j > i) continue; foreach (k; 2..i+2) { if (j^^k == i) { ans = i; return; } if (j^^k > i) break; } } }}(); writeln(ans); stdout.flush(); debug readln(); }
D
void main() { auto b = rs; switch(b) { case "A": writeln("T"); break; case "T": writeln("A"); break; case "G": writeln("C"); break; case "C": writeln("G"); break; default: break; } } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; import std.math; import std.container; import std.bigint; import std.numeric; import std.conv; import std.typecons; import std.uni; import std.ascii; import std.bitmanip; import core.bitop; T readAs(T)() if (isBasicType!T) { return readln.chomp.to!T; } T readAs(T)() if (isArray!T) { return readln.split.to!T; } T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { auto s = rs; foreach(j; 0..width) res[i][j] = s[j].to!T; } return res; } int ri() { return readAs!int; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
D
import std.stdio, std.algorithm, std.range, std.array, std.conv, std.string; void main() { int[][] C; foreach (i; 0..3) { C ~= readln.split.to!(int[]); } writeln( C[0][1] - C[0][0] == C[1][1] - C[1][0] && C[0][1] - C[0][0] == C[2][1] - C[2][0] && C[0][2] - C[0][0] == C[1][2] - C[1][0] && C[0][2] - C[0][0] == C[2][2] - C[2][0] ? "Yes" : "No"); }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; immutable mod = 10^^9 + 7; void main() { int h, w; scan(h, w); auto map = new char[][](h + 2, w + 2); iota(h).each!(i => map[i + 1][1 .. w + 1] = readln.chomp.to!(char[])); auto dx = [1, 0, -1, 0, 1, 1, -1, -1], dy = [0, 1, 0, -1, 1, -1, 1, -1]; foreach (i ; 1 .. h + 1) { foreach (j ; 1 .. w + 1) { if (map[i][j] == '.') { int cnt; foreach (k ; 0 .. 8) { cnt += (map[i + dx[k]][j + dy[k]] == '#'); } map[i][j] = ('0' + cnt).to!char; } } } iota(h).each!(i => writeln(map[i + 1][1 .. w + 1])); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import core.bitop; import core.checkedint; import core.simd; import core.stdc.stdlib; import core.stdc.string; import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.bitmanip; import std.complex; import std.container; import std.conv; import std.datetime; import std.format; import std.functional; import std.math; import std.meta; import std.numeric; import std.random; import std.range; import std.regex; import std.stdio; import std.string; import std.typecons; import std.variant; __gshared: auto getAddrTuple() { return tuple(); } auto getAddrTuple(T, U...)(ref T head, ref U tail) { return tuple(&head, getAddrTuple(tail).expand); } bool read(T...)(ref T vars) if (vars.length > 0) { return readf(' ' ~ replicate("%s ", vars.length), getAddrTuple(vars).expand) == vars.length; } T[ ] allocate(T)(size_t n) { return (cast(T*)malloc(n * T.sizeof))[0 .. n]; } auto pairwise(R)(R range) if (isForwardRange!R) { return lockstep(range, dropOne(range)); } char[100_001] _a, _b; bool[100_000] used; void main() { while (true) { version (LocalProject) memset(used.ptr, 0x00, used.sizeof); auto a = _a[ ]; auto b = _b[ ]; readln(a); if (a.empty) break; readln(b); a = a[0 .. $ - 1]; b = b[0 .. $ - 1]; const n = cast(int)a.length; const m = cast(int)b.length; //b[0 .. lb] ~ b[rb .. m] int la = 0, lb = 0, ra = n, rb = m; while (la < n && lb < m) { while (la < n && a[la] != b[lb]) la++; if (la == n) break; used[la] = true; debug writeln("Left-using ", la); la++; lb++; } int lres = lb, rres = m; while (ra && rb) { ra--; rb--; int passed = 0; while (ra >= 0 && a[ra] != b[rb]) if (used[ra--]) passed++; if (ra < 0) break; if (used[ra]) passed++; debug writeln("Right-using ", ra); while (passed-- > 0 || lb > rb) { lb--; if (lb) { while (a[--la] != b[lb]) { } do used[la--] = false; while (a[la] != b[lb - 1]); la++; } else la = 0; } if (lb + m - rb > lres + m - rres) { lres = lb; rres = rb; } } if (!lres && rres == m) writeln('-'); else writeln(b[0 .. lres], b[rres .. m]); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nm = readln.split.to!(int[]); auto N = nm[0]; auto M = nm[1]; auto qs = new int[](N); foreach (_; 0..M) { auto ab = readln.split.to!(int[]); ++qs[ab[0]-1]; ++qs[ab[1]-1]; } foreach (q; qs) { if (q%2 == 1) { writeln("NO"); return; } } writeln("YES"); }
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) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; } enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { long x; scan(x); for (long i = 1; ; i++) { if (i * (i + 1) / 2 >= x) { writeln(i); return; } } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.array; void main(){ auto s=readln.chomp; if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba")writeln("Yes"); else writeln("No"); }
D
import std.algorithm; import std.conv; import std.stdio; import std.string; void main(){ foreach(string s; stdin.lines) writeln(s.chomp.split.map!(to!int).reduce!"a + b"); }
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.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void main() { auto N = scanElem; writeln(24-N+24); } void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; void main() { int input; immutable limitList = 200000; bool[] listNumbers = new bool[](limitList); int[] listPrimeNumbers; listNumbers.fill(true); foreach (i; 2..limitList.to!double.sqrt.to!int) { if (listNumbers[i]) { for (int j = i*2; j < limitList; j += i) listNumbers[j] = false; } } foreach (i; 2..listNumbers.length) { if (listNumbers[i]) { listPrimeNumbers ~= i.to!int; } } while ((input = readln.chomp.to!int) != 0) { ulong sum = 0; foreach (i; 0..listPrimeNumbers.length) { if (i == input) break; sum += listPrimeNumbers[i]; } writeln(sum); } }
D
import std.stdio; import std.string; import std.array; import std.range; import std.random; import std.algorithm; import std.conv; void main(){ auto nk = readln().chomp().split().map!(to!int).array(); auto as = readln().chomp().split().map!(to!int).array(); auto k = nk[1]; auto n = nk[0]; solve(n, k).writeln(); } int solve(int n, int k){ if((n - 1) % (k - 1) == 0){ return (n - 1) / (k - 1); }else{ return (n - 1) / (k - 1) + 1; } }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test oder atc ---+/ void main(string[] args) { const S = readln.chomp.split.array; (S[1] ~ S[0]).writeln; }
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; import std.functional; import std.container; struct Puzzle { int[9] panel; size_t toHash() const @safe pure nothrow { size_t hash = 0; foreach (i; panel) { hash *= 10; hash += i; } return hash; } bool opEquals(ref const Puzzle s) const @safe pure nothrow { return equal(panel[0..$], s.panel[0..$]); } int c; } int[] dx = [-1, 0, 1, 0]; int[] dy = [0, -1, 0, 1]; void main() { bool[Puzzle] set; auto queue = DList!Puzzle(); Puzzle initial; foreach (i; 0..9) { scanf("%d", &initial.panel[i]); } set[initial] = true; queue.insertBack(initial); while (!queue.empty) { auto u = queue.front; queue.removeFront; if (u.panel[0..$].equal([1, 2, 3, 4, 5, 6, 7, 8, 0])) { writeln(u.c); break; } auto sp = u.panel[0..$].countUntil(0); auto sx = sp % 3; auto sy = sp / 3; foreach (r; 0..4) { auto tx = sx + dx[r]; auto ty = sy + dy[r]; if (tx < 0 || tx >= 3 || ty < 0 || ty >= 3) continue; auto temp = u; temp.panel[sp].swap(temp.panel[tx + ty * 3]); if (temp !in set) { set[temp] = true; temp.c++; queue.insertBack(temp); } } } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}} void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}} void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}} void main() { int n; readV(n); int[] a; readA(n, a); int[int] h; foreach (ai; a) ++h[ai]; int r = 0; foreach (k, v; h) if (v >= k) r += v-k; else r += v; writeln(r); }
D
void main() { writeln(2 ^^ readln.chomp.to!int.log2.to!int); } 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.stdio; import std.string; import std.conv; int main() { int n = readln().chomp().to!int(); string s = "Hoshino"; while (n--) { string str = readln().chomp(); char[] ans; for (int i = 0; i < str.length; i++) { ans ~= str[i]; if (str[i] == 'H') { bool flag = true; if (i + 6 > str.length - 1) flag = false; for (int j = 0; j < 7 && flag; j++) { if (str[i + j] != s[j]) flag = false; } if (flag) { i += 6; ans ~= str[i-5..i]; ans ~= 'a'; } } } writeln(ans); } return 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_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto n = RD!int; auto edges = new long[][](n); foreach (i; 0..n-1) { auto u = RD!int-1; auto v = RD!int-1; edges[u] ~= v; edges[v] ~= u; } debug writeln(edges); bool ans = true; foreach (i; 0..n) { if (edges[i].length == 2) { ans = false; break; } } writeln(ans ? "YES" : "NO"); stdout.flush(); debug readln(); }
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; void main() { int n = readln.chomp.to!int; ["Mahmoud", "Ehab"][n % 2].writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main(){ auto z=readln.split.to!(int[]),a=z[0],b=z[1]; if(a%3==0||b%3==0||(a+b)%3==0)writeln("Possible"); else writeln("Impossible"); }
D
import std.stdio; import std.string; import std.math; import std.conv; import std.algorithm; import std.bigint; void main(){ int d,m; int date = 2; auto ds = ["Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Monday"]; auto a = [31,29,31,30,31,30,31,31,30,31,30,31]; while(true){ date = 2; auto s = split(readln()); d = to!int(s[0]); m = to!int(s[1]); if(d == 0 && m == 0) break; for(int i=0;i<d-1;i++){ date += a[i]; } date += m-1; date = date % 7; writeln(ds[date]); } }
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 false; } p = stdin.rawRead (buffer); if (p.empty) { eof = true; return false; } return true; } ubyte nextByte(bool check) () { static if (check) { if (p.empty) { if (!rawRead ()) { return 0; } } } auto r = p.front; p.popFront (); return r; } public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); } bool seekByte (in ubyte lo) { while (true) { p = p.find! (c => c >= lo); if (!p.empty) { return false; } if (!rawRead ()) { return true; } } } template next(T) if (isSigned!T) { T next () { if (seekByte (45)) { return 0; } T res; ubyte b = nextByte!false (); if (b == 45) { while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { T next () { if (seekByte (48)) { return 0; } T res = nextByte!false () - 48; while (true) { ubyte b = nextByte!true (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } T[] nextA(T) (in int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } void main() { auto r = new InputReader (); immutable nt = r.next!uint (); foreach (tid; 0 .. nt) { auto n = r.next!uint; writeln (n); } }
D
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; immutable long mod = 10^^9 + 7; void main(){ auto n = readln.chomp.to!int; auto s = readln.chomp; int stack; int lb, rb; foreach(ch ; s){ if (ch == '('){ stack += 1; } else { if (stack == 0){ lb += 1; } else { stack--; } } } rb = stack; auto ans = repeat("(", lb).join ~ s ~ repeat(")", rb).join; writeln(ans); } void readVars(T...)(auto ref T args){ auto line = readln.split; foreach(ref arg ; args){ arg = line.front.to!(typeof(arg)); line.popFront; } if(!line.empty){ throw new Exception("args num < input num"); } }
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() { auto nte = readln.chomp.split.map!(to!int); auto lo = nte[1] - nte[2]; auto up = nte[1] + nte[2]; auto san = readln.chomp.split.map!(to!int).array; auto res = -1; foreach (i, e; san) { auto tmp = e; while (tmp < lo) tmp += e; if (tmp <= up) { res = i.to!int + 1; break; } } res.writeln; }
D
void main() { int[] tmp = readln.split.to!(int[]); int hw = tmp[0], ww = tmp[1]; tmp = readln.split.to!(int[]); int hb = tmp[0], wb = tmp[1]; writeln((hw - hb) * (ww - wb)); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
import std.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(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new long[](t); long[] add = [0, 0, 0, 4, -4, 4]; auto list = new long[](2*(10^^6)); list[2] = 4; list[3] = 4; list[4] = 12; foreach (i; 5..list.length) { auto x = add[(i-5)%6]; list[i] = list[i-1]; list[i].modm(2); list[i].moda(x); } foreach (ti; 0..t) { auto n = RD!int-1; ans[ti] = list[n]; /*int[][] edges; edges.length = 1; foreach (i; 0..n-1) { foreach (u; 0..edges.length) { if (edges[u].length == 3) continue; if (edges[u].length == 0) { ++edges.length; edges[u] ~= cast(int)edges.length - 1; } else if (edges[u].length == 1) { ++edges.length; ++edges.length; edges[u] ~= cast(int)edges.length - 2; edges[u] ~= cast(int)edges.length - 1; } } } int[] dfs(int u, int par) { int res; bool used; foreach (v; edges[u]) { if (v == par) continue; auto r = dfs(v, u); if (r[1]) used = true; res += r[0]; } if (!used && edges[u].length == 3) { ++res; used = true; } else { used = false; } return [res, used ? 1 : 0]; } writeln(dfs(0, -1));*/ } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std; void main() { int k; scan(k); string s; scan(s); if (s.length > k) writeln(s[0..k], "..."); else writeln(s); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T=string)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readints = reads!int;
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void get(Args...)(ref Args args) { import std.traits, std.meta, std.typecons; static if (Args.length == 1) { alias Arg = Args[0]; static if (isArray!Arg) { args[0] = readln.split.to!Arg; } else static if (isTuple!Arg) { auto input = readln.split; static foreach (i; 0..Fields!Arg.length) { args[0][i] = input[i].to!(Fields!Arg[i]); } } else { args[0] = readln.chomp.to!Arg; } } else { auto input = readln.split; assert(input.length == Args.length); static foreach (i; 0..Args.length) { args[i] = input[i].to!(Args[i]); } } } void get_lines(Args...)(size_t N, ref Args args) { import std.traits, std.range; static foreach (i; 0..Args.length) { static assert(isArray!(Args[i])); args[i].length = N; } foreach (i; 0..N) { static if (Args.length == 1) { get(args[0][i]); } else { auto input = readln.split; static foreach (j; 0..Args.length) { args[j][i] = input[j].to!(ElementType!(Args[j])); } } } } void main() { long X, Y; get(X, Y); writeln(abs(X - Y) <= 1 ? "Brown" : "Alice"); }
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_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD!string; writeln(N[0] == N[2] ? "Yes" : "No"); stdout.flush(); debug readln(); }
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) { string s; scan(s); if (s == "#") return; solve(s); } } void solve(string s) { auto h = "qwertasdfgzxcvb"; int res; foreach (int i, ch; s) { if (i == 0) continue; res += h.canFind(ch) ^ h.canFind(s[i-1]); } writeln(res); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.math; void main() { int[3] n; n = numText2IntArray(readln()); if((n[0] + n[1]) == n[2] || (n[0] + n[2]) == n[1] || (n[1] + n[2]) == n[0]) { writeln("Yes"); } else { writeln("No"); } } int[] numText2IntArray(string text) { return map!(to!int)(split(text)).array; }
D
import std.stdio; import std.conv; import std.algorithm; import std.string; import std.array; void main() { int n = readln.chomp.to!int; string[] s = new string[](n); char[5] initial = ['M', 'A', 'R', 'C', 'H']; long[5] num; for (int i = 0; i < n; ++i) { s[i] = readln.chomp; for (int j = 0; j < 5; ++j) { if (s[i][0] == initial[j]) { num[j]++; break; } } } long ans; for (int i = 0; i < 5; ++i) { for (int j = i + 1; j < 5; ++j) { for (int k = j + 1; k < 5; ++k) { ans += (num[i] * num[j] * num[k]); } } } writeln(ans); return; }
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 N = readln.chomp.to!int; int res; foreach(i; iota(1,N+1,2)) { int count; foreach(k; 1..i+1) { if(i % k == 0) count++; } if(count == 8) res++; } res.writeln; } //writeln("滲み出す混濁の紋章 不遜なる狂気の器 湧き上がり 否定し 痺れ 瞬き 眠りを妨げる 爬行する鉄の王女 絶えず自壊する泥の人形 結合せよ 反発せよ 地に満ち己の無力を知れ 破道の九十 黒棺")
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() { long k,a,b; scan(k, a, b); if (a >= k) { writeln(1); return; } if (a <= b) { writeln(-1); } else { long s = a - b; long ans = (k - a + s - 1) / s; ans = 2*ans + 1; writeln(ans); } } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
void main() { int[] tmp = readln.split.to!(int[]); int a = tmp[0], b = tmp[1]; writeln(b % a == 0 ? a + b : b - a); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
import std.stdio,std.string,std.conv,std.math; int main() { int[4] a,b; int count,count_2; string s,s2; while((s = readln.chomp).length != 0 ) { s2 = readln.chomp; string[] input = split(s); string[] input2 = split(s2); foreach(i;0..4) { a[i] = input[i].to!int; b[i] = input2[i].to!int; } count = 0; count_2 = 0; foreach(i;0..4) { foreach(j;0..4) { if(a[i] == b[j]) { if(i == j) count++; else count_2++; } } } writeln(count," ",count_2); } return 0; }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test 3776 ---+/ /+---test 8080 ---+/ void main(string[] args) { const S = readln.chomp; (S.uniq.equal(S)? "Good": "Bad").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, std.datetime; // 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].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = new string[](3); foreach (i; 0 .. 3) S[i] = sread(); long M = S.map!"a.length"().reduce!(max); auto match = new bool[][][](3, 3, M * 3); foreach (x; 0 .. 3) foreach (y; 0 .. 3) loop_i: foreach (i; 0 .. M * 3) { if (S[x].length <= i) { match[x][y][i] = true; continue; } foreach (j; 0 .. M * 2) if (j + i < S[x].length && j < S[y].length) if (S[x][j + i] != S[y][j] && S[x][j + i] != '?' && S[y][j] != '?') { continue loop_i; } match[x][y][i] = true; } // writeln(match[0][1]); auto p = [0, 1, 2]; bool check(long i, long j) { auto A = p[0], B = p[1], C = p[2]; if (!match[A][B][i]) return false; if (!match[A][C][j]) return false; if (!match[B][C][j - i]) return false; return true; } long ans = long.max; do { foreach (i; 0 .. S[p[0]].length + 1) foreach (j; i .. max(S[p[0]].length, i + S[p[1]].length) + 1) { long len = max(S[p[0]].length, i + S[p[1]].length, j + S[p[2]].length); if (check(i, j) && len < ans) { // writeln(i, " ", j, " ", len); ans = len; } // writeln(i, " ", j, " ", i + S[2].length); } } while (nextPermutation(p)); writeln(ans); }
D
// module dcomp.scanner; class Scanner { import std.stdio : File, readln, stdin; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeString, isDynamicArray; import std.algorithm : map; File f; this(File f = stdin) { this.f = f; } string[] buf; bool succ() { while (!buf.length) { if (f.eof) return false; buf = readln.split; } return true; } int read(Args...)(auto ref Args args) { foreach (i, ref v; args) { if (!succ()) return i; alias VT = typeof(v); static if (!isSomeString!VT && isDynamicArray!VT) { v = buf.map!(to!(ElementType!VT)).array; buf.length = 0; } else { v = buf.front.to!VT; buf.popFront(); } } return args.length; } } /+ dub.sdl: name "A" dependency "dcomp" version="~master" +/ int main() { import std.stdio, std.algorithm; // import dcomp.scanner; auto sc = new Scanner(); string s; sc.read(s); int mi = 0, sm = 0; foreach (c; s) { if (c == 'S') { sm++; } else { sm--; } mi = min(mi, sm); } writeln(mi * -2); return 0; }
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(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new int[](t); foreach (ti; 0..t) { auto n = RD!int; ans[ti] = n / 2 + 1; } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio; import std.algorithm; import std.array; 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 K = to!ulong(tokens[1]); long[] h; foreach (token; split(my_readln())) { h ~= to!long(token); } ulong[] costs; costs.length = N; fill(costs, ulong.max); costs[0] = 0; foreach (i; 0..N) { foreach (j; 1..K+1) { if (i + j >= N) break; costs[i+j] = min(costs[i+j], costs[i] + abs(h[i] - h[i+j])); } } writeln(costs[N-1]); stdout.flush(); /*}catch (Throwable e) { writeln(e.toString()); } readln();*/ }
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(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto T = RD!(char[]); foreach (i; 0..T.length) { if (T[i] == '?') T[i] = 'D'; } writeln(T); stdout.flush; debug readln; }
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){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].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); foreach (state; 0 .. 1 << 3) { long tmp = S[0] - '0'; foreach (j; 0 .. 3) if (state & (1 << j)) { tmp += S[j + 1] - '0'; } else { tmp -= S[j + 1] - '0'; } if (tmp == 7) { write(S[0]); foreach (j; 0 .. 3) if (state & (1 << j)) { write('+', S[j + 1]); } else { write('-', S[j + 1]); } writeln("=7"); return; } } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), k = rd[0], s = rd[1]; auto ans = 0; foreach (x; 0..k+1) foreach (y; 0..k+1) { auto z = s-x-y; if (0 <= z && z <= k) ++ans; } writeln(ans); }
D
import core.bitop; import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; void main() { int n = readln.chomp.to!int; int sum = 0; foreach (i; 0..n) { auto lr = readln.chomp.split.map!(to!int); sum += lr.back - lr.front + 1; } sum.writeln; }
D
void main() { int n = readln.chomp.to!int; int[string] a; foreach (i; 0 .. n) { string s = readln.chomp; if (s in a) ++a[s]; else a[s] = 1; } int m = readln.chomp.to!int; foreach (i; 0 .. m) { string t = readln.chomp; if (t in a) --a[t]; else a[t] = -1; } max(0, a.values.reduce!max).writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test 3 1 2 3 ---+/ /+---test 10 3 1 4 1 5 9 2 6 5 3 ---+/ /+---test 10 3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820 ---+/ enum MOD = 1000000007; void main(string[] args) { const N = readln.chomp.to!long; const A = readln.split.map!(to!long).array; long ans; foreach (i; 0..60) { long x; foreach (a; A) if ((a >> i) & 1) ++x; long cnt = x * (N-x); foreach (j; 0..i) cnt = cnt*2%MOD; ans = (ans+cnt)%MOD; } ans.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[] 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].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; // dfmt on void main() { auto S = sread(); long ans = long.max; bool[char] d; foreach (c; S) d[c] = true; if (d.keys.length == 1) { writeln(0); return; } foreach (c; d.keys) { ans = ans.min(solve(S, c)); } writeln(ans); } long solve(string S, char c) { bool flag = true; string newS = ""; foreach (i; 0 .. S.length - 1) { if (S[i] == c || S[i + 1] == c) newS ~= c; else { newS ~= S[i]; flag = false; } } if (flag) { return 1; } else { return 1 + solve(newS, c); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto ab = readln.split.to!(int[]); writeln(ab[0] & 1 && ab[1] & 1 ? "Yes" : "No"); }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } long mod = pow(10, 9) + 7; long moda(long x, long y) { return (x + y) % mod; } long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; } long modm(long x, long y) { return (x * y) % mod; } void main() { auto N = RD!long; long[] C, S, F; foreach (i; 0..N-1) { C ~= RD!long; S ~= RD!long; F ~= RD!long; } foreach (i; 0..N-1) { long t; foreach (j; i..N-1) { t = max(t, S[j]); t = (t / F[j] + (t % F[j] != 0 ? 1 : 0)) * F[j]; t += C[j]; } writeln(t); } writeln(0); stdout.flush(); }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; import std.uni, std.range, std.math, std.container, std.datetime; import core.bitop, std.typetuple, std.typecons; immutable long MOD = 1_000_000_007; alias tie = TypeTuple; void main(){ int a, b; char op; while(true){ readVars(a, op, b); switch(op){ case '+': writeln(a + b); break; case '-': writeln(a - b); break; case '*': writeln(a * b); break; case '/': writeln(a / b); break; default: return; } } } void readVars(T...)(auto ref T args){ auto line = readln.split; foreach(ref arg ; args){ arg = line.front.to!(typeof(arg)); line.popFront; } if(!line.empty){ throw new Exception("args num < input num"); } }
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 s = read!string; writeln(s.count('1')); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long n, m; scan(n, m); long max_x = long.min; long min_x = long.max; foreach (_; 0 .. m) { long l, r; scan(l, r); // writeln(l, r); max_x = max(max_x, l); min_x = min(min_x, r); } // writeln("max", max_x); // writeln("min", min_x); if (min_x >= max_x) { writeln(min_x - max_x + 1); } else { writeln(0); } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
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(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T read(T)(){ return read.to!T; } T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; } T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int n = read!int; string s = readln.chomp; int sum = 0; int[] sums = [0]; // sum[i] = sum(0 .. i) foreach(i; 0 .. n){ if(s[i] == '#') sum += 1; sums ~= sum; } int ans = n + 10; foreach(i; 0 .. n + 1){ int tmp = sums[i] + ((n - i) - (sums[n] - sums[i])); if(tmp < ans) ans = tmp; } ans.writeln; }
D
import std.stdio,std.string,std.conv,std.array,std.algorithm; void main(){ readln(); auto arr = readln().chomp().split(); reverse(arr); arr.join(" ").writeln(); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; long n; rd(n); for(long a=1; a<=3500; a++)for(long b=1; b<=3500; b++){ auto x=4*a*b-n*a-n*b; if(x<=0) continue; auto y=n*a*b; if(y%x==0){ writeln(a, " ", b, " ", y/x); return; } } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio; import std.array; import std.conv; void main() { auto input = split(readln()); int a = to!(int)(input[0]); int b = to!(int)(input[1]); if (a < b) writeln("a < b"); else if (a > b) writeln("a > b"); else writeln("a == b"); }
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=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std; // dfmt on void main() { auto S = sread(); if ('A' <= S[0] && S[0] <= 'Z') { writeln("A"); } else { writeln("a"); } }
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", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } 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].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long X = lread(); writeln((X < 1200) ? "ABC" : "ARC"); }
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)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto t = RD!int; auto ans = new bool[](t); foreach (i; 0..t) { auto a = RD!int; auto b = RD!int; if (min(a, b)*2 < max(a, b)) ans[i] = false; else ans[i] = (a+b) % 3 == 0; } foreach (e; ans) writeln(e ? "YES" : "NO"); stdout.flush; debug readln; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto n=readln.chomp.to!(char[]); int sum1=0; foreach(c; n) sum1+=(c-'0'); if(n.length>1){ int tmp=(n[0]-'0')-1; tmp+=(n.length.to!(int)-1)*9; sum1=max(sum1, tmp); } writeln(sum1); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio, std.conv, std.string, std.array; bool f(int[] nList, int i, int m) { if(m == 0) return true; if(m < 0) return false; if(i == nList.length) return false; return f(nList, i+1, m) || f(nList, i+1, m-nList[i]); } void main() { readln(); int[] nList = readln.split.to!(int[]); readln(); int[] qList = readln.split.to!(int[]); foreach(int q; qList) { if(f(nList, 0, q)) writeln("yes"); else writeln("no"); } }
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, q; scan(n, k, q); auto a = iota(q).map!(i => readln.chomp.to!int).array; a[] -= 1; auto s = new int[](n); s[] = q; foreach (ai ; a) { s[ai]--; } foreach (i ; 0 .. n) { writeln(s[i] < k ? "Yes" : "No"); } } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
void main(){ int n=_scan(); int d, ans; int[int] dic; foreach(i; 0..n){ d = _scan(); if(dic.get(d, 0)==0){ ans++; } dic[d]++; } ans.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(); } return ln; }
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.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto x = scanElem; auto a = scanElem-scanElem; if(a>=0)end("delicious"); if(a+x>=0)end("safe"); end("dangerous"); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a, b, c; scan(a, b, c); writeln(b - a == c - b ? "YES" : "NO"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv; void main() { string s = readln.chomp; auto cur = s.length / 2; char pi = s[cur]; if (s.length % 2 == 0) { while (cur < s.length && pi == s[$ - cur - 1] && pi == s[cur]) { ++cur; } } else { ++cur; while (cur < s.length && pi == s[$ - cur - 1] && pi == s[cur]) { ++cur; } } writeln(cur); }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto tmp = readln.split.to!(long[]); auto N = tmp[0], K = tmp[1]; auto xs = readln.split.to!(long[]); long minTime = long.max; foreach (i; 0..N-K+1) { auto j = i + K - 1; auto t = min(abs(xs[i]) + xs[j] - xs[i], abs(xs[j]) + xs[j] - xs[i]); if (t < minTime) minTime = t; } if (minTime == long.max) minTime = 0; writeln(minTime); }
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)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto T = RD!int; auto ans = new long[](T); foreach (i; 0..T) { auto a = RD!int; auto b = RD!int; auto x = min(a, b); auto y = max(a, b); auto d = y - x; ans[i] += d / 5; x += ans[i] * 5; if (x != y) { if (y-x >= 3) ans[i] += 2; else ++ans[i]; } } foreach (e; ans) writeln(e); stdout.flush(); debug readln(); }
D