code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.algorithm, std.range, std.array, std.conv, std.string, std.math, std.container, std.typecons; void main() { writeln((readln.chomp.to!int - readln.chomp.to!int) % readln.chomp.to!int); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; void main(){ auto N=readln.chomp.to!int; auto K=readln.chomp.to!int; auto X=readln.chomp.to!int; auto Y=readln.chomp.to!int; if(N<=K)writeln(X*N); else writeln(X*K+Y*(N-K)); }
D
import std.functional, std.algorithm, std.container, std.typetuple, std.typecons, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv, std.format, std.math; void main() { auto n = readln.chomp.to!int; auto a = readln.chomp.to!int; writeln(n^^2-a); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(dchar[]); auto T = readln.chomp.to!(dchar[]); foreach (i; 0..S.length) { S = S[1..$] ~ S[0]; if (S == T) { writeln("Yes"); return; } } writeln("No"); }
D
import std.stdio, std.string; void main() { string n = readln.chomp; string s = "0"; int cnt; while (s != n) { s = succ(s); if (s.length % 2) ++cnt; } cnt.writeln; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n; long x; scan(n, x); auto a = new long[](n + 1); // 長さ auto b = new long[](n + 1); // Pの枚数 a[0] = b[0] = 1; foreach (i ; 1 .. n + 1) { a[i] = 2L*a[i-1] + 3; b[i] = 2L*b[i-1] + 1; } long query(int L, long x) { if (L == 0) { return x == 1; } if (x <= 1) { return 0; } else if (x < (a[L] + 1) / 2) { return query(L-1, x - 1); } else if (x == (a[L] + 1) / 2) { return b[L-1] + 1; } else if (x < a[L] - 1) { return b[L-1] + 1 + query(L-1, x - (a[L] + 1) / 2); } else { return 2*b[L-1] + 1; } } long ans = query(n, x); writeln(ans); } 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; void main() { foreach (former; 1 .. 10) { foreach (latter; 1 .. 10) { writeln(former,"x",latter,"=",former*latter); } } }
D
import std.stdio,std.string,std.conv; int main() { string s; while((s = readln.chomp).length != 0) { bool flag = true; for(int i=0;i<7;i += 3) { if(s[i] != 's' && s[i] == s[i+1] && s[i+1] == s[i+2]) { s[i].writeln; flag = false; break; } } if(flag) { foreach(i;0..3) { if(s[i] != 's' && s[i] == s[i+3] && s[i+3] == s[i+6]) { s[i].writeln; flag = false; break; } } } if(flag) { if(s[0] != 's' && s[0] == s[4] && s[4] == s[8]) { s[0].writeln; flag = false; } } if(flag) { if(s[2] != 's' && s[2] == s[4] && s[4] == s[6]) { s[2].writeln; flag = false; } } if(flag) { writeln("d"); } } 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 x = RD; auto y = RD; long ans; auto xy = sgn(x) * sgn(y); if (x <= y) { if (xy >= 0) ans = abs(abs(y) - abs(x)); else ans = abs(abs(y) - abs(x)) + 1; } else { if (xy == 0) ans = abs(abs(y) - abs(x)) + 1; else if (xy > 0) ans = abs(abs(y) - abs(x)) + 2; else ans = abs(abs(y) - abs(x)) + 1; } writeln(ans); stdout.flush(); debug readln(); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a=new long[](100); a[0]=2; a[1]=1; for(int i=2; i<=n; i++){ a[i]=a[i-1]+a[i-2]; } writeln(a[n]); } 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; import std.conv; import std.string; import std.math; import std.algorithm; import std.range; void main() { long n = readln.chomp.to!long; long[] answer; for (long i = 2; i <= sqrt(cast(float)n); i++) { if (n % i == 0) { answer ~= i; } while (n % i == 0) { n /= i; } } if (answer.empty) { writeln(n); } else { writeln(answer.reduce!("a * b") * n); } }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); p = stdin.rawRead (buffer); } final ubyte skipByte (ubyte lo) { while (true) { auto a = p[cur .. $]; auto r = a.find! (c => c >= lo); if (!r.empty) { cur += a.length - r.length; return p[cur++]; } p = stdin.rawRead (buffer); cur = 0; if (p.empty) return 0; } } final ubyte nextByte () { if (cur < p.length) { return p[cur++]; } p = stdin.rawRead (buffer); if (p.empty) return 0; cur = 1; return p[0]; } template next(T) if (isSigned!T) { final T next () { T res; ubyte b = skipByte (45); if (b == 45) { while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { final T next () { T res = skipByte (48) - 48; while (true) { ubyte b = nextByte (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } final T[] nextA(T) (int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } immutable names = "RPS"; void main() { auto r = new InputReader; foreach (t; 0 .. r.next!uint) { immutable n = r.next!uint; auto cnt = r.nextA!uint(3); auto a = new char[n]; auto b = new int[n]; foreach (i; 0 .. n) { char c; int k = -1; do { c = r.nextByte ().to!char; foreach (o; 0 .. 3) { if (names[o] == c) { k = o; } } } while (k < 0); b[i] = (k + 1) % 3; } debug stderr.writeln ("b = ", b); int wins; foreach (k; 0 .. 3) { foreach (j; 0 .. n) { if (cnt[k] > 0 && b[j] == k) { --cnt[k]; a[j] = names[k]; ++wins; } } } debug stderr.writeln ("wins = ", wins); foreach (i; 0 .. n) { if (a[i] == char.init) { foreach (k; 0 .. 3) { if (cnt[k] > 0) { a[i] = names[k]; --cnt[k]; break; } } } } int req = n / 2; if (n & 1) ++req; if (wins >= req) { writeln ("YES"); writeln (a); } else { writeln ("NO"); } } }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); p = stdin.rawRead (buffer); } final ubyte skipByte (ubyte lo) { while (true) { auto a = p[cur .. $]; auto r = a.find! (c => c >= lo); if (!r.empty) { cur += a.length - r.length; return p[cur++]; } p = stdin.rawRead (buffer); cur = 0; if (p.empty) return 0; } } final ubyte nextByte () { if (cur < p.length) { return p[cur++]; } p = stdin.rawRead (buffer); if (p.empty) return 0; cur = 1; return p[0]; } template next(T) if (isSigned!T) { final T next () { T res; ubyte b = skipByte (45); if (b == 45) { while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { final T next () { T res = skipByte (48) - 48; while (true) { ubyte b = nextByte (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } final T[] nextA(T) (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!int; foreach (tid; 0 .. nt) { immutable n = r.next!int; immutable s = r.next!int; immutable t = r.next!int; auto y = n - s; auto x = n - t; auto z = s - x; debug stderr.writefln ("x = %d, y = %d, z = %d", x, y, z); writeln (max (x, y) + 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; void main() { auto T = readln.chomp.to!int; while (T--) { auto N = readln.chomp.to!int; if (N % 2) write(7), N -= 3; foreach (i; 0..N/2) write(1); writeln; } }
D
import core.bitop; import std.algorithm; import std.array; import std.container; import std.conv; import std.exception; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; bool solve (string s, string [] t) { if (t.canFind (s)) { return true; } foreach (a; t) { foreach (b; t) { if ("" ~ a[1] ~ b[0] == s) { return true; } } } return false; } void main () { string s; while ((s = readln.strip) != "") { int n = readln.strip.to !(int); string [] t; foreach (i; 0..n) { t ~= readln.strip; } writeln (solve (s, t) ? "YES" : "NO"); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nd = readln.split.to!(long[]); auto N = nd[0]; auto A = nd[1]; auto B = nd[2]; auto C = nd[3]; auto D = nd[4]; foreach (m; 0..N-1) { if (C * (N-1-m) - D*m <= B-A && B-A <= D * (N-1-m) - C*m) { writeln("YES"); return; } } writeln("NO"); }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.functional; void main() { writeln(readln.replace(" ", "").chomp.to!uint.pipe!(x => (cast(uint)sqrt(cast(real)x)) ^^ 2 == x) ? "Yes" : "No"); }
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, std.regex; void main() { immutable int INF = 1 << 29; auto N = readln.chomp.to!int + 2; auto S = '0' ~ readln.chomp ~ '0'; auto dp = new int[](N); dp.fill(-INF); dp[0] = 0; foreach (i; 1..N-1) { dp[i] = max(dp[i], dp[i-1]); if (S[i-1..i+2] != "101") continue; for (int p = i - 1; p >= 0 && S[p] == '1'; --p) { dp[i+1] = max(dp[i+1], dp[p-1] + i - p); } for (int p = i + 1; p < N && S[p] == '1'; ++p) { dp[p] = max(dp[p], dp[i-2] + p - i); } } dp[N-2].writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_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; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } 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 = 998_244_353; //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 q = RD!int; auto ans = new int[](q); foreach (i; 0..q) { auto n = RD!int; int odd; int cnt1, cnt2; foreach (j; 0..n) { auto s = RD!string; if (s.length % 2 == 1) ++odd; foreach (c; s) { if (c == '1') ++cnt1; else ++cnt2; } } foreach (j; 0..odd) { if (cnt1 % 2 == 1) --cnt1; else if (cnt2 % 2 == 1) --cnt2; else if (cnt1 > cnt2) --cnt1; else --cnt2; } if (cnt1 % 2 == 0 && cnt2 % 2 == 0) ans[i] = n; else ans[i] = n-1; } foreach (e; ans) { writeln(e); } stdout.flush(); debug readln(); }
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; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } 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 = 998_244_353; //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 d = RD; auto e = RD*5; long ans = long.max; while (n >= e) { ans = min(n % d, ans); n -= e; } ans = min(n % d, ans); writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio,std.string,std.conv; void main() { auto N = readln.strip.to!int; (N>=1000?"ABD":"ABC").writeln; }
D
import std.stdio,std.string; int main(){ auto input=readln.chomp; char[] s=input.dup; foreach(ss;s[1..3]){ if(ss!=s[0]){ writeln("Yes"); return 0; } } "No".writeln; return 0; }
D
import std.stdio; import std.algorithm; import std.string; import std.array; import std.conv; import std.math; char[12][12] map; int[] dx = [1,0,-1,0]; int[] dy = [0,1,0,-1]; void saiki(int x, int y){ if(map[y][x] == '1'){ map[y][x] = '0'; for(int i=0;i<4;i++){ if(x+dx[i]>=12||y+dy[i]>=12||x+dx[i]<0||y+dy[i]<0) continue; saiki(x+dx[i],y+dy[i]); } } } void main(){ auto temp = map.dup; while(true){ map = temp.dup; int ans; for(int i=0;i<12;i++){ string t = readln().chomp(); for(int j=0;j<12;j++) map[i][j] = t[j]; } for(int i=0;i<12;i++){ for(int j=0;j<12;j++){ if(map[j][i]=='1'){ saiki(i,j); ans++; } } } writeln(ans); auto a = readln(); if(stdin.eof()) break; } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; import std.conv; void main() { string[char] d; d['a'] = rs; d['b'] = rs; d['c'] = rs; import std.uni; solve(d).toUpper.writeln; } char solve(string[char] d) { if(d['a'].length == 1) return 'a'; char turn = 'a'; while(true) { if(d[turn].length == 0) return turn; char tmp = turn; turn = d[turn].front.to!char; d[tmp].popFront; } } // =================================== 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 (isBasicType!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } int ri() { return readAs!int; } string rs() { return readln.chomp; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.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; 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; auto P = RD; writeln((A * 3 + P) / 2); stdout.flush(); debug readln(); }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; string my_readln() { return chomp(readln()); } 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 tokens = my_readln.split; auto N = tokens[0].to!long; ulong[] six, nine; uint x = 6; while (x <= N) { six ~= x; x *= 6; } uint y = 9; while (y <= N) { nine ~= y; y *= 9; } auto dp = new ulong[](N+1); fill(dp, ulong.max); dp[0] = 0; foreach (i; 0..N) { if (dp[i] == ulong.max) continue; foreach (e; six) { auto j = i + e; if (j <= N) { dp[j] = min(dp[j], dp[i] + 1); } } foreach (e; nine) { auto j = i + e; if (j <= N) { dp[j] = min(dp[j], dp[i] + 1); } } dp[N] = min(dp[N], dp[i] + N - i); } writeln(dp[N]); stdout.flush(); }
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 h = readln.chomp.to!long; long c = 1; long num; while (h != 0) { num += c; h /= 2; c *= 2; } writeln(num); }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const tmp = readln.split.to!(long[]); const A = tmp[0], B = tmp[1], C = tmp[2]; writeln(min(C, B/A)); }
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 = 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; } } enum MOD = (10 ^^ 9) + 7; void main() { long N, K; scan(N, K); long[10 ^^ 5 + 1] B; foreach (_; 0 .. N) { long a, b; scan(a, b); B[a] += b; } long sum; foreach (i; 0 .. 10 ^^ 5 + 1) { sum += B[i]; if (K <= sum) { writeln(i); return; } } }
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; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int n = read.to!int; int a = read.to!int; int b = read.to!int; int ans = min(n * a, b); ans.writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(wchar[]); int r, b; foreach (c; S) { switch (c) { case '0': ++r; break; case '1': ++b; break; default: } } writeln(min(r, b) * 2); }
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() { long D, G; scan(D, G); auto P_orig = new long[](D); auto C = new long[](D); foreach (i; 0 .. D) scan(P_orig[i], C[i]); long ans = long.max; foreach (comp; 0 .. (1 << D)) { auto P = P_orig.dup; long score; long cnt; foreach (i; 0 .. D) if (comp & (1 << i)) { cnt += P[i]; score += P[i] * 100 * (i + 1); score += C[i]; P[i] = 0; } if (G <= score) { ans = ans.min(cnt); continue; } foreach_reverse (i; 0 .. D) { long need = (G - score + (100 * (i + 1) - 1)) / (100 * (i + 1)); long c = min(need, P[i]); // writefln("%s %s %s %s %s", comp, G - score, i, need, P[i]); score += c * (100 * (i + 1)); cnt += c; if (G <= score) break; } ans = ans.min(cnt); } writeln(ans); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n, tc; readV(n, tc); int[] t; readA(n, t); auto ans = 0; foreach (i; 0..n-1) ans += t[i+1]-t[i] > tc ? tc : t[i+1]-t[i]; ans += tc; writeln(ans); }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; void main() { auto D = readln.split[0].to!int; auto c = D == 25 ? "Christmas" : D == 24 ? "Christmas Eve" : D == 23 ? "Christmas Eve Eve" : D == 22 ? "Christmas Eve Eve Eve" : ""; c.writeln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } int calc(int[] xs) { int ans = 0; for (int i = 0; i + 1 < xs.length; i++) { if (xs[i] == i + 1) { ans++; swap(xs[i], xs[i + 1]); } } if (xs[$ - 1] == xs.length) ans++; return ans; } void main() { readint; auto xs = readints; writeln(calc(xs)); }
D
import std.stdio, std.string, std.conv; void main() { foreach (i; 0 .. 10) { string cards = readln.chomp.to!(string); if (cards == "-") break; int m = readln.chomp.to!int; foreach (j; 0 .. m) { int h = readln.chomp.to!int; cards = cards[h..$] ~ cards[0..h]; } cards.writeln; } }
D
import std.stdio, std.string, std.conv, std.array, std.regex, std.algorithm; void main(){ auto ip = readln.chomp; switch(ip){ case "a", "i", "u", "e", "o": writeln("vowel"); break; default: writeln("consonant"); break; } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int n; scan(n); auto a = new int[](n), b = new int[](n); auto c = new int[](n), d = new int[](n); foreach (i ; 0 .. n) { scan(a[i], b[i]); } foreach (i ; 0 .. n) { scan(c[i], d[i]); } auto adj = new Edge[][](2*n + 2, 0); void addEdge(int u, int v) { adj[u] ~= Edge(v, 1, adj[v].length.to!int); adj[v] ~= Edge(u, 0, adj[u].length.to!int - 1); } foreach (i ; 0 .. n) { addEdge(0, i + 1); addEdge(n + i + 1, 2*n + 1); } foreach (i ; 0 .. n) { foreach (j ; 0 .. n) { if (a[i] < c[j] && b[i] < d[j]) { addEdge(i + 1, n + j + 1); } } } int ans = FordFulkerson(adj, 0, 2*n + 1); writeln(ans); } import std.typecons; alias Edge = Tuple!(int, "to", int, "cap", int, "rev"); immutable inf = 10^^9 + 7; int FordFulkerson(Edge[][] adj, int s, int t) { int n = adj.length.to!int; auto visited = new bool[](n); int dfs(int u, int f) { if (u == t) {return f;} visited[u] = 1; foreach (ref e ; adj[u]) { if (!visited[e.to] && e.cap > 0) { int d = dfs(e.to, min(f, e.cap)); if (d > 0) { e.cap -= d; adj[e.to][e.rev].cap += d; return d; } } } return 0; } int F; while (true) { visited[] = 0; int f = dfs(0, inf); if (!f) break; F += f; } return F; } 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.string, std.conv, std.algorithm; void main() { string S = readln.chomp; int[char] arr; foreach (c; 'a'..'z') { arr[c] = 0; } foreach (c; S) { arr[c]++; } char add_char = 'z' + 1; foreach (c; arr.byKey) { if (arr[c] != 0) continue; add_char = min(add_char, c); } if (add_char != 'z' + 1) { writeln(S ~ add_char); return; } char min_char = 'z' + 1; bool f = false; for (long i = S.length - 2; i != ulong.max; i--) { for (long j = i + 1; j < S.length; j++) { if (S[j] > S[i]) { min_char = min(min_char, S[j]); f = true; } } if (f) { writeln(S[0..i] ~ min_char); return; } } writeln(-1); }
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; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // const long mod = 998_244_353; void solve(){ int n = read.to!int; long[] as; foreach(i; 0 .. n) as ~= read.to!long; long[][] ws; foreach(a; as){ long [] w; for(long x = a; x > 0; x /= 10) w ~= x % 10; ws ~= w; } long ans; foreach(w; ws){ int i = 0; long m = 1; for(; i < w.length; i += 1, m *= 100, m %= mod){ ans += w[i] * 11 * m * n % mod; ans %= mod; } } ans.writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "a", long, "b"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { writeln((lread() + 1) / 2); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial; void main(){ auto mn=readln.split.map!(to!int).array; auto m=mn[0]; auto n=mn[1]; string[] as; string[] bs; foreach(i;0..m)as~=readln.chomp; foreach(i;0..n)bs~=readln.chomp; foreach(x;0..(m-n+1)) outer:foreach(y;0..(m-n+1)){ foreach(dx;0..n) foreach(dy;0..n){ if(as[x+dx][y+dy]!=bs[dx][dy])continue outer; } writeln("Yes"); return; } writeln("No"); return; }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { auto week = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]; string s; scan(s); auto ans = 6 - week.countUntil(s); if (s == "SUN") ans = 7; writeln(ans); } 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() { dchar[] s = rdDchar; dchar[] t = rdDchar; LCS!dchar(s, t).writeln; } T[] LCS(T)(T[] x, T[] y) { T[] result; long xlen = x.length, ylen = y.length; long[][] dp = new long[][](xlen+1, ylen+1); foreach (i, u; x) { foreach (j, v; y) { if (u == v) dp[i+1][j+1] = dp[i][j] + 1; else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]); } } for (long i = xlen, j = ylen; i && j; ) { if (x[i-1] == y[j-1]) { result ~= x[i-1]; --i, --j; } else { if (dp[i][j-1] < dp[i-1][j]) --i; else --j; } } reverse(result); return result; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; enum double eps = 1.0e-9; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)() 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.mathspecial; import std.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni; import core.bitop;
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) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "begin", long, "end"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto s = sread(); bool flag = true; foreach(i, e; s) { if(i % 2) flag &= (e == 'i'); else flag &= (e == 'h'); } if(!(s.length % 2) && flag) writeln("Yes"); else writeln("No"); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
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.datetime; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto Y = s[1]; for (int i = 0; i * 10000 <= Y && i <= N; ++i) { for (int j = 0; i * 10000 + j * 5000 <= Y && i + j <= N; ++j) { int k = Y - i*10000 - j*5000; if (i + j + k/1000 == N) { writeln(i, " ", j, " ", k/1000); return; } } } writeln(-1, " ", -1, " ", -1); }
D
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional; void main() { readln.enumerate.filter!(a => a.index % 2 == 0).map!(a => a.value).array.writeln; }
D
void main(){ int a = _scan(); (a+a^^2+a^^3).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 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 aa = new bool[long][](3); foreach (n; [1, 3, 5, 7, 8, 10, 12]) aa[0][n] = true; foreach (n; [4, 6, 9, 11]) aa[1][n] = true; aa[2][2] = true; long x, y; scan(x, y); foreach (a; aa) { if (x in a && y in a) { writeln("Yes"); return; } } writeln("No"); }
D
import std.stdio, std.string, std.array, std.conv; void main() { string row; foreach (i; 0 .. 300) row ~= "#"; while (true) { int[] tmp = readln.chomp.split.to!(int[]); int h = tmp[0], w = tmp[1]; if (h == 0 && w == 0) break; foreach (i; 0 .. h) row[0..w].writeln; writeln; } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", 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() { string A, B, C; scan(A, B, C); bool b = A[$ - 1] == B[0] && B[$ - 1] == C[0]; writeln(b ? "YES" : "NO"); }
D
import std; bool calc(int a, int b, int c, int d) { int x = (c + b - 1) / b; int y = (a + d - 1) / d; return x <= y; } void main() { int a, b, c, d; scan(a, b, c, d); writeln(calc(a, b, c, d) ? "Yes" : "No"); } 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto S = readln.chomp; auto T = readln.chomp; int s, t, c, max_c, d, max_d; foreach (i; 0..N) { auto s1 = S[i] == '1'; auto t1 = T[i] == '1'; if (s1) ++s; if (t1) ++t; if (s1 && !t1) { ++c; if (d > 0) --d; } else if (!s1 && t1) { ++d; if (c > 0) --c; } max_c = max(max_c, c); max_d = max(max_d, d); } if (s != t) { writeln(-1); } else { writeln(max(max_c, max_d)); } }
D
void main() { auto N = ri; auto K = ri; ulong res = 1; foreach(i; 0..N) res = (res * 2 < res + K ? res * 2 : res + K); writeln(res); } // =================================== 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.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 H = RD; auto W = RD; auto S = new string[](H); foreach (i; 0..H) { S[i] = RD!string; } long ans; auto dp = new long[2][][](H, W); foreach (y; 0..H) { foreach (x; 0..W) { if (S[y][x] == '#') continue; if (dp[y][x][0] == 0) { long cnt; foreach (z; x..W) { if (S[y][z] == '#') break; ++cnt; } foreach (z; x..x+cnt) { dp[y][z][0] = cnt; } } if (dp[y][x][1] == 0) { long cnt; foreach (z; y..H) { if (S[z][x] == '#') break; ++cnt; } foreach (z; y..y+cnt) { dp[z][x][1] = cnt; } } ans = max(ans, dp[y][x][0] + dp[y][x][1] - 1); } } writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto S = readln.split[0]; auto K = readln.split[0].to!long; foreach (c; S) { if (K == 1 || c != '1') { writeln(c); return; } else K--; } writeln(1); }
D
import std.stdio,std.array,std.conv; void main(){ string[] s=split(readln()); // splitで文字列を文字列の配列に切り分け int x=to!int(s[0]); // 第0要素を整数に変換 int y=to!int(s[1]); int z=to!int(s[2]); int ans=to!int((x-z)/(y+z)); writeln(ans); }
D
import std.stdio, std.string, std.algorithm, std.range, std.conv; void main() { auto ip = readln.split.to!(int[]), A = ip[0], B = ip[1]; if(A > 8 || B > 8) { writeln(":("); } else { writeln("Yay!"); } }
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) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "p", long, "dist"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto s = sread(); long iter = s.length; auto dream = "dream", dreamer = "dreamer"; auto erase = "erase", eraser = "eraser"; while (iter > 0) { if(s[max(0, iter - cast(long) dream.length) .. iter] == dream) iter -= dream.length; else if(s[max(0, iter - cast(long) dreamer.length) .. iter] == dreamer) iter -= dreamer.length; else if(s[max(0, iter - cast(long) erase.length) .. iter] == erase) iter -= erase.length; else if(s[max(0, iter - cast(long) eraser.length) .. iter] == eraser) iter -= eraser.length; else break; } if(iter) writeln("NO"); else writeln("YES"); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.conv, std.stdio, std.algorithm, std.string, std.range; void main() { const input = readln.split.map!(to!int).array; if (1 <= min(input[0], input[1]) && max(input[0], input[1]) <= 9) { (input[0] * input[1]).writeln; } else { (-1).writeln; } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); auto K = S.length; int w; foreach (s; S) { if (s == 'o') ++w; } writeln(w+(15-K) >= 8 ? "YES" : "NO"); }
D
import std.stdio, std.string, std.ascii, std.algorithm; void main() { string str, tmp; while ((tmp = readln.chomp.toLower) != "") { str ~= tmp; } foreach (ab; lowercase) { writeln(ab, " : ", str.count(ab)); } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib; immutable long MOD = 10^^9 + 7; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1]; auto dp = new long[](K + 1); dp[K] = 1; foreach_reverse (i; 1..K) { dp[i] = powmod(K / i, N, MOD); for (int j = i + i; j <= K; j += i) { dp[i] -= dp[j]; dp[i] = (dp[i] % MOD + MOD) % MOD; } } long ans = 0; foreach (i; 1..K+1) (ans += dp[i] * i % MOD) %= MOD; ans.writeln; } long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; }
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { bool[3] b;b[0]=true; foreach(s;stdin.byLine()) swap(b[s[0]-'A'],b[s[2]-'A']); foreach(i,v;b) if(v) writeln(cast(char)('A'+i)); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void main() { auto nk = readln.split.to!(long[]); auto N = nk[0]; auto K = nk[1]; long[] AS; long max_a; foreach (a; readln.split.to!(long[])) { max_a = max(max_a, a); AS ~= a; } long l, r = max_a; while (l+1 < r) { auto m = (l+r)/2; long k; foreach (a; AS) { k += a/m; if (a%m == 0) --k; } if (k <= K) { r = m; } else { l = m; } } writeln(r); }
D
/+ dub.sdl: name "D" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; import core.bitop; int mybsr(long x) { if (x == 0) return -1; return bsr(x); } long f(long a, long b) { if (a == 0 && b == 0) return 1; long u = 1L<<mybsr(b); if (mybsr(a) == mybsr(b)) { return f(a-u, b-u); } long sm = f(a, u-1); long x = u-a; long y = 1L<<(mybsr(b-u)+1); return sm + min(u, x + y); } int main() { auto sc = new Scanner(stdin); long a, b; sc.read(a, b); writeln(f(a, b)); return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.foundation; static if (__VERSION__ <= 2070) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } version (X86) static if (__VERSION__ < 2071) { import core.bitop : bsf, bsr, popcnt; int bsf(ulong v) { foreach (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int bsr(ulong v) { foreach_reverse (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int popcnt(ulong v) { int c = 0; foreach (i; 0..64) { if (v & (1UL << i)) c++; } return c; } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File; 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) { this.f = f; } char[512] lineBuf; char[] line; private bool succ() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (true) { while (!line.empty && line.front.isWhite) { line.popFront; } if (!line.empty) break; if (f.eof) return false; line = lineBuf[]; f.readln(line); } return true; } private bool readSingle(T)(ref T x) { import std.algorithm : findSplitBefore; import std.string : strip; import std.conv : parse; if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { auto r = line.findSplitBefore(" "); x = r[0].strip.dup; line = r[1]; } else { auto buf = line.split.map!(to!E).array; static if (isStaticArray!T) { assert(buf.length == T.length); } x = buf; line.length = 0; } } else { x = line.parse!T; } 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); } } }
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 dp = new long[][](1000 + 2, 1000 + 2); long H, W; scan(H, W); // if (H != 3) // return; dp[0][] = 0; foreach (row; dp) row[0] = 0; dp[1][1] = 1; foreach (i; 1 .. H + 1) { auto s = sread(); foreach (j; 1 .. W + 1) if (s[j - 1] == '.') { // writefln("(%d %d): %d + %d", i, j, dp[i - 1][j], dp[i][j - 1]); dp[i][j].maxAssign((dp[i - 1][j] + dp[i][j - 1]) % (10 ^^ 9 + 7)); } else { dp[i][j] = 0; } } dp[H][W].writeln(); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric; void main(){ auto l=readln.chomp; writeln(l[0],l.length-2,l[$-1]); }
D
void main() { int r = readln.chomp.to!int; if (r < 1200) { "ABC".writeln; } else if (r < 2800) { "ARC".writeln; } else { "AGC".writeln; } } 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; import std.string; import std.conv; import std.algorithm; void main(){ string s; while(!(s=readln).length==0){ s=chomp(s); for(int i=cast(int)s.length-1; i>=0; i--) write(s[i]); writeln(); } }
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math; void main() { string s = readln.chomp; bool can = 1; foreach(c; "abc") can &= (count(s, c) == 1); writeln(can ? "Yes" : "No"); }
D
import std.algorithm; import std.conv; import std.math; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(long)).array; writeln (a.front < a.back ? "YES" : "NO"); } }
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() { int m = readint; writeln(48 - m); }
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() { auto nq = readints(); int n = nq[0], q = nq[1]; for (int i = 0; i < q; i++) { auto xs = readints(); if (xs[0] == 0) { int s = xs[1]; int t = xs[2]; int x = xs[3]; add(s, t + 1, x, 0, 0, N / 2); } else { int s = xs[1]; int t = xs[2]; auto v = sum(s, t + 1, 0, 0, N / 2); writeln(v); } } } /////////////////////////////////////// const int N = 1 << 18; // ???????????° long[N * 2] _data; long[N * 2] _datb; /// [a, b) ??? x ??????????????? /// k ????????????????????§????????? [l, r) ??????????????? void add(int a, int b, int x, int k, int l, int r) { if (a <= l && r <= b) { _data[k] += x; } else if (l < b && a < r) { _datb[k] += (min(b, r) - max(a, l)) * x; add(a, b, x, k * 2 + 1, l, (l + r) / 2); add(a, b, x, k * 2 + 2, (l + r) / 2, r); } } /// [a, b) ??????????±??????? /// k ????????????????????§????????? [l, r) ???????????????] long sum(int a, int b, int k, int l, int r) { if (b <= l || r <= a) return 0; if (a <= l && r <= b) return _data[k] * (r - l) + _datb[k]; auto ret = (min(b, r) - max(a, l)) * _data[k]; ret += sum(a, b, k * 2 + 1, l, (l + r) / 2); ret += sum(a, b, k * 2 + 2, (l + r) / 2, r); return ret; }
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; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } void main() { readln.chomp.to!int.pipe!( n => n*800 - n/15*200 ).writeln; } // ---------------------------------------------- // 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); } } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D
// Vicfred // https://atcoder.jp/contests/abc129/tasks/abc129_b // brute force import std.algorithm; import std.array; import std.conv; import std.math; import std.stdio; import std.string; void main() { const long n = readln.chomp.to!long; const long[] ws = readln.split.map!(to!long).array; long[] sum = new long[n]; sum[0] = ws[0]; foreach(i; 1..n) sum[i] += sum[i - 1] + ws[i]; long minima = long.max; for(int i = 1; i < n; i++) { const long left = sum[i - 1]; const long right = sum[n-1] - sum[i - 1]; minima = min(minima, abs(left - right)); } minima.writeln; }
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 a, b; readV(a, b); writeln(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 ? "Possible" : "Impossible"); }
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 a, b, c, d, e, k; scan(a);scan(b);scan(c);scan(d);scan(e);scan(k); bool ok = e - a <= k; writeln(ok ? "Yay!" : ":("); } int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new int[][](n, 0); foreach (i; 0 .. m) { int u, v; scan(u, v); if (is1indexed) { u--, v--; } adj[u] ~= v; if (isUndirected) { adj[v] ~= u; } } return adj; } alias Edge = Tuple!(int, "to", int, "cost"); Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new Edge[][](n, 0); foreach (i; 0 .. m) { int u, v, c; scan(u, v, c); if (is1indexed) { u--, v--; } adj[u] ~= Edge(v, c); if (isUndirected) { adj[v] ~= Edge(u, c); } } return adj; } void yes(bool b) { writeln(b ? "Yes" : "No"); } void YES(bool b) { writeln(b ? "YES" : "NO"); } T[] readArr(T)() { return readln.split.to!(T[]); } T[] readArrByLines(T)(int n) { return iota(n).map!(i => readln.chomp.to!T).array; } 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() { import std.stdio, std.string; string s = readln.chomp; writeln("2018", s[4 .. $]); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.container; import std.array; import std.math; import std.range; import std.typecons; import std.ascii; import std.format; void main() { auto a = readln.chomp.split.map!(to!int); writeln = a[0] ^ a[1] ^ a[2]; }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons; void main() { auto N = readln.split[0].to!int; auto A = readln.split.to!(int[]); auto B = readln.split.to!(int[]); ulong ans = 0; foreach(i; 0..N) { int b = B[i]; int x; x = min(A[i], b); ans += x; A[i] -= x; b-= x; x = min(A[i+1], b); ans += x; A[i+1] -= x; b -= x; } ans.writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(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 x1 = RD!int; auto y1 = RD!int; auto x2 = RD!int; auto y2 = RD!int; ans[ti] = abs(x1-x2) + abs(y1-y2); if (x1 != x2 && y1 != y2) ans[ti] += 2; } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; import std.typecons; import std.regex; import std.range; void main(){ while(true){ int n = readln().chomp().to!int; if(n==0) break; int ans = 100000000; for(int i=0;i<=25;i++){ for(int j=0;j<=17;j++){ for(int k=0;k<=10;k++){ if((200*i+300*j+500*k)==n){ double p1,p2,p3; p1 = 380 * 5 * (i/5) * 0.8 + 380 * (i % 5); p2 = 550 * 4 * (j/4) * 0.85 + 550 * (j % 4); p3 = 850 * 3 * (k/3) * 0.88 + 850 * (k % 3); ans = min(ans , to!int(p1+p2+p3)); } } } } writeln(ans); } }
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) { x.modm(y.modpow(mod - 2)); } void main() { auto t = RD!int; auto ans = new long[](t); foreach (ti; 0..t) { auto n = RD!int; auto a = RD!int; auto b = RD!int; auto c = RD!int; auto d = RD!int; if ((a-b)*n > c+d) continue; if ((a+b)*n < c-d) continue; ans[ti] = true; } foreach (e; ans) { writeln(e ? "Yes" : "No"); } stdout.flush; debug readln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp; if (S.length == 2) { if (S[0] == '0' || S[1] == '1') { writeln(-1); } else { writeln("1 2"); } return; } if (S[0] == '0' || S[$-2] == '0' || S[$-1] == '1') { writeln(-1); return; } int[] as, bs; int p = 1; auto N = S.length.to!int; int i, j = N-2; while (i <= j) { if (S[i] != S[j]) { writeln(-1); return; } as ~= p; bs ~= i+2; if (S[i] == '1') p = i+2; ++i; --j; } for (; i < N-1; ++i) { as ~= p; bs ~= i+2; } foreach (k; 0..N-1) writeln(as[k], " ", bs[k]); }
D
void main() { long n = readln.chomp.to!long; dchar[] s = readln.chomp.to!(dchar[]); dchar[] t = readln.chomp.to!(dchar[]); long len = 2 * n; foreach_reverse (i; 0 .. n) { if (s[i..$] == t[0..$-i]) { len = i + n; } } len.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; 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() { readln.chomp.pipe!(a => a.retro.equal(a)).pipe!(a => a?"Yes":"No").writeln; } // ---------------------------------------------- void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } // 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); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D
import std.stdio, std.string, std.conv, std.algorithm, std.array; void main(){ while(1){ auto ffffffffff = readln.chomp.to!(int); if(ffffffffff==0) break; int a = 1000 - ffffffffff; int ans; if(a>=500){ ans++; a-=500; } if(a>=100){ ans += a/100; a -= a/100*100; } if(a>=50){ ans ++; a -= 50; } if(a>=10){ ans += a/10; a -= a/10*10; } if(a>=5){ ans++; a -= 5; } ans += a; writeln(ans); } }
D
void main() { string[] s = readln.split(','); s.join(" ").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.conv, std.string, std.range, std.array, std.algorithm; import std.bigint; int[32] dp; void main() { while (true){ int n = readln().chomp().to!int; if (n == 0) break; dp[0 .. 32] = -1; int pat = shinobu(n); pat /= 10; if (pat % 10 != 0){ pat++; } writeln(pat / 365 + 1); } } int shinobu(int n) { if (dp[n] != -1){ return (dp[n]); } if (n == 1) return (1); if (n == 2) return (2); if (n == 3) return (4); return (dp[n] = shinobu(n - 1) + shinobu(n - 2) + shinobu(n - 3)); }
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } T[] readToArray(T)() { return readln.split.to!(T[]); } void readInto(T...)(ref T ts) { auto ss = readln.split; foreach(ref t; ts) { t = ss.front.to!(typeof(t)); ss.popFront; } } void main() { ulong n; readInto(n); ulong[] p = readToArray!(ulong); ulong cnt = 0; for(ulong i = 1; i < p.length-1; i++) { //writefln("%d %d %d", p[i-1], p[i], p[i+1]); if(p[i-1] < p[i] && p[i] < p[i+1]) cnt++; else if (p[i+1] < p[i] && p[i] < p[i-1]) cnt++; } writeln(cnt); }
D
void main() { int[] ab = readln.split.to!(int[]); writeln(ab.all!"a & 1" ? "Odd" : "Even"); } 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.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N; scan(N); int ans; foreach (i ; 1 .. N + 1) { if (i % 2 && countDiv(i) == 8) ans++; } writeln(ans); } int countDiv(int x) { int[] divs; for (int i = 1; i <= x; i++) { if (x % i == 0) divs ~= i; } return divs.length.to!int; } 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
// 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, core.bitop; // dfmt on void main() { long a = lread(); auto s = sread(); writeln(3200 <= a ? s : "red"); }
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; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ long l = read.to!long; long r = read.to!long; long ans; if(r / 2019 > l / 2019) ans = 0; else{ ans = 2018; foreach(i; l .. r + 1) foreach(j; l .. i) ans = min(ans, i * j % 2019); } ans.writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; import std.conv; void main() { (min(r, r) + min(r, r)).writeln; } int r() { return readln.chomp.to!int; }
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() { int x = readint; int sum = 0; for (int t = 1; ; t++) { sum += t; if (sum >= x) { writeln(t); break; } } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "a", long, "b"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long x, y; scan(x, y); if (x % y) { writeln(x * (y - 1)); } else { writeln(-1); } } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.algorithm; import std.array; import std.stdio; import std.conv; import std.string; void main(){ int count; foreach(Unused; 0..readln.chomp.to!int){ if(readln.chomp.to!int.isPrime){ ++count; } } count.writeln; } bool isPrime(int n){ if(n <= 1){ return false; } if(n == 2){ return true; } if(n % 2 == 0){ return false; } for(int i = 3; i * i <= n; i += 2){ if(n % i == 0){ return false; } } return true; }
D
import std.stdio, std.string, std.conv; void main() { string s = readln.chomp; int[] num = new int[s.length]; int cnt; foreach (i, x; s) { if (x == 'R') { ++cnt; } else { num[i-1] += cnt / 2 + cnt % 2; num[i] += cnt / 2; cnt = 0; } } foreach_reverse (i, x; s) { if (x == 'L') { ++cnt; } else { num[i] += cnt / 2; num[i+1] += cnt / 2 + cnt % 2; cnt = 0; } } num.to!(string[]).join(" ").writeln; }
D