code
stringlengths
4
1.01M
language
stringclasses
2 values
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { long a, b, ab, x, y; scan(a, b, ab, x, y); long cost1, cost2, cost3, cost4; cost1 = a * x + b * y; cost2 = ab * 2 * max(x, y); long tmp; tmp = ab * min(x, y) * 2; // writeln("tmp", tmp); if (x > y) { cost3 = tmp + a * (max(x, y) - min(x, y)); } else { cost4 = tmp + b * (max(x, y) - min(x, y)); } // writeln(cost1); // writeln(cost2); // writeln(cost3); // writeln(cost4); if (cost3 == 0) { writeln(min(cost1, cost2, cost4)); } if (cost4 == 0) { writeln(min(cost1, cost2, cost3)); } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = 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); } enum MOD = (10 ^^ 9) + 7; void main() { long N = lread(); auto T = new long[](N); foreach (i; 0 .. N) T[i] = lread(); // gcd(10, 1000000000000000000).writeln; // writeln(10 * 1000000000000000000); long lcm(long a, long b) { // writefln("%d %d", a, b); return a * (b / gcd(a, b)); } T.reduce!lcm().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() { long N = lread(); writeln((N * 800) - ((N/15) * 200)); }
D
import std; void main() { int N, M, Q; scanf("%d %d %d\n", &N, &M, &Q); auto as = new int[Q]; auto bs = new int[Q]; auto cs = new int[Q]; auto ds = new int[Q]; foreach(q;0..Q) { int a, b, c, d; scanf("%d %d %d %d\n", &a, &b, &c, &d); as[q] = a-1; bs[q] = b-1; cs[q] = c; ds[q] = d; } auto As = new int[10]; long scoremax = -1; foreach(d0; 0..M){ foreach(d1; d0..M){ foreach(d2; d1..M){ foreach(d3; d2..M){ foreach(d4; d3..M){ foreach(d5; d4..M){ foreach(d6; d5..M){ foreach(d7; d6..M){ foreach(d8; d7..M){ foreach(d9; d8..M){ long score; As[0] = d0; As[1] = d1; As[2] = d2; As[3] = d3; As[4] = d4; As[5] = d5; As[6] = d6; As[7] = d7; As[8] = d8; As[9] = d9; foreach(q; 0..Q){ if (As[bs[q]]-As[as[q]] == cs[q]) score += ds[q]; } scoremax = max(score, scoremax); } } } } } } } } } } scoremax.write; }
D
import std.stdio,std.conv,std.string; void main(){ auto args = readln().chomp().split(); auto a = to!int(args[0]); auto b = to!int(args[1]); auto c = to!int(args[2]); writeln( a<b&&b<c?"Yes":"No" ); }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons; void main() { int N = readln.chomp.to!int; int[] A = new int[N]; foreach(ref a; A) { a = readln.chomp.to!int; } int[] pal = new int[0]; foreach(a; A) { auto lb = assumeSorted!"a>b"(pal).upperBound(a); if(lb.empty) { pal ~= a; } else { lb.front = a; } } pal.length.writeln; }
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 a=scanElem; auto b=scanElem; if(a%3==0||b%3==0||(a+b)%3==0)end("Possible");end("Impossible"); }
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 = 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; } long[2][] primeFact(long x) { long[2][] ans; for (long i = 2; i*i <= x; ++i) { if (x % i != 0) continue; long r; while (x % i == 0) { ++r; x /= i; } ans ~= [i, r]; } if (x != 1) ans ~= [x, 1]; return ans; } void main() { auto A = RD; auto B = RD; auto aa = primeFact(A); auto bb = primeFact(B); debug writeln(aa); debug writeln(bb); bool[long] set; foreach (e; aa) { set[e[0]] = true; } long ans = 1; foreach (e; bb) { if (set.get(e[0], false) == true) ++ans; } writeln(ans); stdout.flush(); debug readln(); }
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() { dchar[] s; readV(s); s[3] = '8'; writeln(s); }
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 ip = readln.split.to!(int[]), a=ip[0], b=ip[1], c=ip[2]; if(a==b) writeln(c); else if(b==c) writeln(a); else writeln(b); }
D
import std.stdio; import std.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; import std.numeric; T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void main() { auto s = readln.chomp; auto t = readln.chomp; char[char] dict1; char[char] dict2; foreach (i; 0 .. s.length) { if (s[i] in dict1 && dict1[s[i]] != t[i]) { writeln("No"); return; } else dict1[s[i]] = t[i]; if (t[i] in dict2 && dict2[t[i]] != s[i]) { writeln("No"); return; } else dict2[t[i]] = s[i]; } writeln("Yes"); }
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; void main(){ int e, rest, ans; while (true) { e = readln.chomp.to!int; if (!e) break; ans = 1<<30; for(int z = 0; z^^3 <= e; ++z) { rest = e - z^^3; for(int y = 0; y^^2 <= rest; ++y) { int x = rest - y^^2; ans = min(ans, x + y + z); } } writeln(ans); } }
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; void main () { auto a = readln.strip.to !(int); auto b = readln.strip.to !(int); auto c = readln.strip.to !(int); auto d = readln.strip.to !(int); writeln (((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d))); }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; import std.exception; int t; rd(t); while (t--) { int a; rd(a); bool ok = false; for (int n = 3; n <= 360; n++) { if (360 % n == 0) { auto x = 180 - 360 / n; if (a * (n - 2) % x == 0) { if (a * (n - 2) / x <= (n - 2)) { writeln(n); ok = true; break; } } } } enforce(ok); } } /* 3 60 60 4 90 45 5 108 36 6 120 30 7 180-360/7 x/5 8 135 135/6 . . . n 180-360/n:=x x/(n-2) */ void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; 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.string, std.conv, std.math, std.regex; void main() { auto n = readln.chomp; if(n[0] == n[2]){ writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { while(1){ auto n = readln.chomp.to!int; if(n==0) break; int s=1; int max=50000001; for(int i=2;i<n/2;++i){ if(n%i==0){ if(i<max){ s+=(i+n/i); max = n/i; if(i==max) s -= i; }else break; }else if(i>max) break; } if(s<n || n==1) writeln("deficient number"); else if(s==n) writeln("perfect number"); else writeln("abundant number"); } }
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio; int[] readints() { return readln.split.to!(int[]); } long calc(long n, long k, long b) { long cnt = max(0, b - k); long p = n / b; long r = n - p * b; long x = max(0, r - k + 1); return p * cnt + x; } void main() { auto input = readints(); long n = input[0], k = input[1]; long ans; foreach (b; k+1..n+1) ans += calc(n, k, b); writeln(!k ? n * n : ans); }
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; } } void main() { long a,b,c; scan(a,b,c); if((a < c && c < b) || (a > c && c > b)) { writeln("Yes"); } else { writeln("No"); } }
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 A = to!ulong(tokens[0]); auto B = to!ulong(tokens[1]); auto C = to!ulong(tokens[2]); ulong ans = min(A + B + 1, C) + B; writeln(ans); stdout.flush(); /*}catch (Throwable e) { writeln(e.toString()); } readln();*/ }
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; void main() { auto K = readln.chomp.to!int; long[] ans = iota(1L, 10L).array; int idx = 0; while (idx < K) { auto L = ans.length.to!int; foreach (i; idx..L) { auto ld = ans[i] % 10; if (ld > 0) ans ~= ans[i] * 10 + ld - 1; ans ~= ans[i] * 10 + ld; if (ld < 9) ans ~= ans[i] * 10 + ld + 1; } idx = L; } ans[K-1].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; 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 N, A, B; scan(N, A, B); long ans = MOD + powmod(2, N, MOD) - 1; ans %= MOD; auto f = new long[](B + 1); f[0] = 1; foreach (i; 1 .. B + 1) f[i] = (f[i - 1] * i) % MOD; long xa = 1; foreach (i; (N - A + 1) .. N + 1) xa *= i, xa %= MOD; long xb = 1; foreach (i; (N - B + 1) .. N + 1) xb *= i, xb %= MOD; auto ca = xa * invmod(f[A]) % MOD; auto cb = xb * invmod(f[B]) % MOD; writeln((ans + 2 * MOD - ca - cb) % MOD); } T powmod(T = long)(T x, T n, T m) { if (n < 1) return 1; if (n & 1) { return x * powmod(x, n - 1, m) % m; } T tmp = powmod(x, n / 2, m); return tmp * tmp % m; } T invmod(T = long)(T x, T m = 10 ^^ 9 + 7) { return powmod(x, m - 2, m); }
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 = "%.15f"; 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 = 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 s = RD!string; long l = 0, r = s.length-1; long ans; while (r-l > 0) { if (s[l] == s[r]) { ++l; --r; } else if (s[l] == 'x') { ++ans; ++l; } else if (s[r] == 'x') { ++ans; --r; } else { ans = -1; break; } } writeln(ans); stdout.flush(); debug readln(); }
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; } } //累積和でバーーン!!ってやってみる. void main() { long n, q; scan(n, q); auto s = sread(); long[] com_count = new long[n + 1]; foreach (i, ref e; com_count) { if (i < 2) { continue; } if (s[i - 2 .. i] == "AC") { com_count[i] = com_count[i - 1] + 1; } else { com_count[i] = com_count[i - 1]; } } // writeln(com_count); foreach (i; 0 .. q) { long a,b; scan(a,b); writeln(com_count[b] - com_count[a]); } }
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;}} T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;} T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;} void main() { int a; readV(a); int b; readV(b); int c; readV(c); int d; readV(d); writeln(min(a, b) + min(c, d)); }
D
import std.stdio, std.string, std.conv, std.algorithm; void main(){ auto s = readln.chomp.to!int; writeln(s/3600, ":", s%3600/60, ":", s%3600%60); }
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() { string a; scan(a); int[] cnt = new int[](26); foreach (ai ; a) { cnt[ai - 'a']++; } long ans = 1L * a.length * (a.length + 1) / 2 - a.length + 1; foreach (i ; 0 .. 26) { ans -= 1L * cnt[i] * (cnt[i] - 1) / 2; } 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
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); } void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ string s = scan; string ans; foreach(c; s){ if(c == '?') ans ~= 'D'; else ans ~= c; } ans.print; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, m; rd(n, m); auto c=readln.split.to!(int[]); auto a=readln.split.to!(int[]); int cnt=0; for(int i=0, j=0; i<n && j<m; ){ if(c[i]<=a[j]){ cnt++; i++; j++; }else{ i++; } } writeln(cnt); } 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.algorithm, std.conv, std.array, std.string; void main() { auto ks = readln.split.to!(int[]); auto k = ks[0]; auto s = ks[1]; long cnt; foreach (x; 0..k+1) { foreach (y; x..k+1) { auto z = s - x - y; if (z < y || z > k) continue; if (x == y && y == z) ++cnt; else if (x == y || y == z || z == x) cnt += 3; else cnt += 6; } } writeln(cnt); }
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 c = new string[](3); foreach (i; 0..3) { c[i] = RD!string; } writeln([c[0][0], c[1][1], c[2][2]]); stdout.flush(); debug readln(); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; int[string] blue; foreach (_; 0..n) { blue[readln.chomp]++; } auto m = readln.chomp.to!int; int[string] red; foreach (_; 0..m) { red[readln.chomp]++; } int res; foreach (k; blue.keys) { res = max(blue[k] - red.get(k, 0), res); } writeln(max(res, 0)); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { readln.chomp.count('2').writeln; }
D
import std.stdio, std.string, std.algorithm, std.conv, std.range, std.math; void main() { readln.toUpper.write; }
D
import std.stdio; void main(){ foreach(i;0..1000) writeln("Hello World"); }
D
import std.stdio, std.string, std.conv, std.math; void main() { auto ip = readln.split.to!(int[]); if((ip[1] * 10 + ip[2]) % 4 == 0){ writeln("YES"); } else { writeln("NO"); } }
D
void main() { readln.chomp.count('1').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.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 ab = readln.split.map!(to!int); while (1) { bool f; foreach (y; ab[0]..ab[1]+1) { if (isLeapYear(y)) { y.writeln; f = 1; } } if (!f) writeln("NA"); ab = readln.split.map!(to!int); if (ab[0] + ab[1] == 0) break; writeln(""); } } bool isLeapYear(int year) { if (year % 4) return 0; if (year % 400 == 0) return 1; if (year % 100 == 0) return 0; return 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; void main() { const long MAX = 3501; auto N = readln.chomp.to!long; foreach (b; 1..MAX) { foreach (c; 1..MAX) { long bunbo = 4 * b * c - b * N - c * N; long bunsi = b * c * N; if (bunbo <= 0 || bunsi % bunbo != 0) continue; long a = bunsi / bunbo; writeln(a, " ", b, " ", c); return; } } }
D
import std.stdio; import std.string; import std.conv; int main() { string[] str = readln().split(); int a = to!int(str[0]); int b = to!int(str[1]); if (a > b) writeln("a > b"); else if (a < b) writeln("a < b"); else writeln("a == b"); return 0; }
D
import std.conv, std.stdio; import std.algorithm, std.array, std.range, std.string; void main() { auto a = readln[0]; if ('a' <= a && a <= 'z') return 'a'.writeln; 'A'.writeln; }
D
string solve(int x){ return (x<1200)? "ABC": "ARC"; } void main(){ int x = inelm(); solve(x).writeln(); } 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.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; 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; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long mod = 10^^9 + 7; 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 sx = RD; auto sy = RD; auto tx = RD; auto ty = RD; auto dx = tx - sx; auto dy = ty - sy; foreach (i; 0..dy) { write("U"); } foreach (i; 0..dx) { write("R"); } write("U"); foreach (i; 0..dx+1) { write("L"); } foreach (i; 0..dy+1) { write("D"); } write("R"); foreach (i; 0..dx) { write("R"); } foreach (i; 0..dy) { write("U"); } write("R"); foreach (i; 0..dy+1) { write("D"); } foreach (i; 0..dx+1) { write("L"); } write("U"); writeln(); stdout.flush(); //readln(); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { long N, K; scan(N, K); auto v = abs(N - K) % K; auto ans = min(v, K - v); writeln(ans); } void scan(T...)(ref T args) { auto 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); } } } 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; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }
D
import std.stdio, std.string, std.conv; void main() { string N = readln.chomp; int a, b; foreach (c; N) { a += c - '0'; } b = N[0] - 1 - '0'; foreach (c; N[1..N.length]) { b += '9' - '0'; } writeln(a > b ? a : b); }
D
void main() { problem(); } void problem() { auto N = scan!ulong + 1; ulong solve() { ulong[] divisers = new ulong[N]; divisers[] = 1; foreach(i; 2..N) { for(ulong x = i; x < N; x += i) divisers[x]++; } ulong ans; foreach(i; 1..N) ans += i * divisers[i]; return ans; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } alias Queue = Tuple!(long, "from", long, "to"); // -----------------------------------------------
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; int[int] cnt; foreach (i; 0..n) { auto d = readln.chomp.to!int; cnt[d]++; } cnt.keys.length.writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; import std.math; void main(){ auto A=readln.split.to!(int[]),x=A[0],a=A[1],b=A[2]; if(a>=b)writeln("delicious"); else if(a<b&&b-a<=x)writeln("safe"); else if(a<b&&b-a>x)writeln("dangerous"); }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int n = readln.chomp.to!int; int[] r = new int[n]; foreach (i; 0 .. n) { r[i] = readln.chomp.to!int; } int maxv = int.min; int minv = r[0]; foreach (i; 1 .. n) { maxv = max(maxv, r[i] - minv); minv = min(minv, r[i]); } maxv.writeln; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); auto cnt=new int[](3); foreach(c; s) cnt[c-'a']++; auto mn=reduce!(min)(cnt); auto cnt1=map!(e=>e-mn)(cnt); auto a=new int[](0); foreach(e; cnt1)if(e>0) a~=e; if(a.length==0){writeln("YES"); return;} if(a.length==1){ if(a[0]<2){writeln("YES"); return;} else{writeln("NO"); return;} } if(a[0]<2 && a[1]<2){writeln("YES"); return;} else{writeln("NO"); return;} } 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; 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!uint; auto a = new ulong[][](N); foreach (i; 0..N) { foreach (j, token; my_readln.split) { auto x = token.to!(ulong); if (x == 0) continue; a[i] ~= x << j; } } auto dp = new long[](1<<N); dp[0] = 1; foreach (j; 1..1<<N) { auto i = popcnt(j) - 1; foreach (e; a[i]) { if ((j & e) == 0) continue; auto x = j | e; dp[j] = moda(dp[j], dp[j^e]); } } //stderr.writeln(dp[i+1]); writeln(dp[(1<<N)-1]); stdout.flush(); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; string Sorting_String(string s) { char[] str; for (int i = 0; i < s.length; i++) str ~= s[i]; for (int i = 0; i < str.length; i++) for (int j = i + 1; j < str.length; j++) { if (str[i] > str[j]) { auto tmp = str[i]; str[i] = str[j]; str[j] = tmp; } } return to!string(str); } int Change_To_Int(string s) { int res = 0; for (int i = 1; i < s.length; i++) res += ((to!int(s[i]) - 48) * ((10 ^^ i) / 10)); return res; } int Reverse_To_Int(string s) { char[] str; str ~= " "; for (int i = 1; i < s.length; i++) str ~= s[s.length - i]; int res = Change_To_Int(to!string(str)); return res; } int main() { int N; N = readln().chomp().to!int(); for (int i = 0; i < N; i++) { string s = readln(); auto str = Sorting_String(s); int num1 = Change_To_Int(str); int num2 = Reverse_To_Int(str); int ans = num1 - num2; writeln(ans); } return 0; }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm, std.range; void main() { auto s = readln.chomp; string ret; foreach (c; s) { switch (c) { case 'B': if (!ret.empty) ret = ret[0..$-1]; break; default: ret ~= c; } } writeln(ret); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); alias 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 main() { long n,k; scan(n,k); writeln(n - k + 1); }
D
void main(){ long n = _scan!long(); long[] stat = [0, 0, 0]; bool legitimate_travel = true; foreach(i; 0..n){ long[] tmp_stat = _scanln!long(); long tdif = tmp_stat[0] - stat[0]; // 所要時間 long xdif = abs( tmp_stat[1] - stat[1] ); // x方向移動距離 long ydif = abs( tmp_stat[2] - stat[2] ); // y方向移動距離 // 移動可能判定 if( xdif+ydif <= tdif ){ // tdifで移動できる範囲である if( tdif%2 == (xdif+ydif)%2 ){ // かつ, 余らず移動できるか stat = tmp_stat; // 移動できれば位置を変更 }else legitimate_travel = false; }else legitimate_travel = false; if(legitimate_travel == false)break; } writeln(legitimate_travel?"Yes":"No"); } 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.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() { long k; readV(k); auto n = 50, a = new long[](n); a[] = n-1+(k/n); foreach (i; 0..k%n) foreach (j; 0..n) a[j] += i == j ? n : -1; writeln(n); foreach (i; 0..n) { write(a[i]); if (i < n-1) write(" "); } writeln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.math; 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(i;0..n){t[i]=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 main() { int n; readV(n); int[] a; readA(n, a); a = 0 ~ a ~ 0; auto s = 0; foreach (i; 0..n+1) s += (a[i+1]-a[i]).abs; foreach (i; 0..n) writeln(s-(a[i+1]-a[i]).abs-(a[i+2]-a[i+1]).abs+(a[i+2]-a[i]).abs); }
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 data = readln.split; auto X = data[0].to!int, Y = data[1].to!int; writeln(X + Y/2); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.15f"; 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 = 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 S = RD!string; bool ans = true; foreach (i, c; S) { if (i % 2 == 0) { if (c == 'L') { ans = false; break; } } else { if (c == 'R') { ans = false; break; } } } writeln(ans ? "Yes" : "No"); stdout.flush(); debug readln(); }
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(){ long n = read.to!long; bool[long] set; int ans; while(n > 0 && n !in set){ ans += 1; set[n] = 1; n += 1; while(n % 10 == 0 && n > 0) n /= 10; } ans.writeln; }
D
/+ dub.sdl: name "D" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); string s; sc.read(s); int n = s.length.to!int; int i = 0; int mid = n/2; while (true) { if (n/2 + i >= n) break; char l = s[(n-1)/2 - i]; char r = s[n/2 + i]; if (l != s[mid] || r != s[mid]) break; i++; } writeln(n/2 + i); return 0; } /* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/scanner.d */ // module dkh.scanner; // import dkh.container.stackpayload; 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 succW() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (!line.empty && line.front.isWhite) { line.popFront; } return !line.empty; } 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; line = lineBuf[]; f.readln(line); if (!line.length) return false; } 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 static if (isStaticArray!T) { foreach (i; 0..T.length) { bool f = succW(); assert(f); x[i] = line.parse!E; } } else { StackPayload!E buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } 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); } } } /* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */ // module dkh.container.stackpayload; struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) { import core.exception : RangeError; private T* _data; private uint len, cap; @property bool empty() const { return len == 0; } @property size_t length() const { return len; } alias opDollar = length; inout(T)[] data() inout { return (_data) ? _data[0..len] : null; } ref inout(T) opIndex(size_t i) inout { version(assert) if (len <= i) throw new RangeError(); return _data[i]; } ref inout(T) front() inout { return this[0]; } ref inout(T) back() inout { return this[$-1]; } void reserve(size_t newCap) { import core.memory : GC; import core.stdc.string : memcpy; import std.conv : to; if (newCap <= cap) return; void* newData = GC.malloc(newCap * T.sizeof); cap = newCap.to!uint; if (len) memcpy(newData, _data, len * T.sizeof); _data = cast(T*)(newData); } void free() { import core.memory : GC; GC.free(_data); } void clear() { len = 0; } void insertBack(T item) { import std.algorithm : max; if (len == cap) reserve(max(cap * 2, MINCAP)); _data[len++] = item; } alias opOpAssign(string op : "~") = insertBack; void removeBack() { assert(!empty, "StackPayload.removeBack: Stack is empty"); len--; } } /* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/foundation.d */ // module dkh.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ 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); } } } } /* This source code generated by dunkelheit and include dunkelheit's source code. dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit) dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt) */
D
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional; void main() { int tol(string n) { auto r = n.to!int; if (r == 1) r = 14; return r; } auto ab = readln.split; auto a = tol(ab[0]); auto b = tol(ab[1]); writeln( a > b ? "Alice" : a < b ? "Bob" : "Draw" ); }
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 ab=readln.split.map!(to!int).array; writeln((ab[0]+ab[1])%24); }
D
import std.stdio; import std.string; import std.conv; void main() { auto input = split( readln() ); long N = to!long(input[0]), M = to!long(input[1]); if (N >= 2 && M >= 2) { writeln( (N-2) * (M-2) ); } else if ( N == 1 && M >= 2 ) { writeln( M-2 ); } else if ( M == 1 && N >= 2 ) { writeln( N-2 ); } else if ( N == 1 && M == 1 ) { writeln(1); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; bool[101] L; void main() { auto nmx = readln.split.to!(int[]); auto N = nmx[0]; auto M = nmx[1]; auto X = nmx[2]; foreach (a; readln.split.to!(int[])) L[a] = true; int a, b; foreach (i; 0..N+1) { if (L[i]) ++a; if (i == X) { b = a; a = 0; } } writeln(min(a, b)); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_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() { bool[long] set; set[RD] = true; set[RD] = true; set[RD] = true; writeln(set.keys.length); stdout.flush(); debug readln(); }
D
void main() { long[] tmp = readln.split.to!(long[]); long n = tmp[0], x = tmp[1]; long[] a = readln.split.to!(long[]); long cnt; foreach (i; 1 .. n) { long diff = a[i] + a[i-1] - x; if (diff > 0) { a[i] = max(0, a[i]-diff); cnt += diff; } } cnt.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.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; } 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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void main() { auto N = RD; auto M = RD; writeln(N == M ? "Yes" : "No"); stdout.flush; debug readln; }
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() { int n; scanf("%d", &n); int[] v = new int[n]; foreach (i; 0..n) { scanf("%d", &v[i]); } int ans = 0; int memkey = -1; int memdiff = 0; foreach (p; 0..2) { int[int] counter; for (int i = p; i < n; i += 2) { if (!(v[i] in counter)) { counter[v[i]] = 0; } counter[v[i]]++; } int first = 0, second = 0, firstkey = -1; foreach (key, val; counter) { if (second < val) { second = val; if (first < val) { swap(first, second); firstkey = key; } } } ans += first; if (p == 0) { memkey = firstkey; memdiff = first-second; } else if (memkey == firstkey) { int diff = first-second; ans -= min(memdiff, diff); } } writeln(n-ans); }
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 = sread(); writeln(S[2] == S[3] && S[4] == S[5] ? "Yes" : "No"); }
D
void main() { long x = readln.chomp.to!long; long result = x / 11 * 2; long r = x % 11; if (r > 0) ++result; if (r > 6) ++result; 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
void main() { dchar[] s = readln.chomp.to!(dchar[]); dchar[] t = readln.chomp.to!(dchar[]); long last = t.length - 1; bool ok; foreach_reverse (i, x; s) { if (x == t[last] || x == '?') { bool check = true; if (i.to!long - last >= 0) { foreach (j; 0 .. last) { if (s[i-last+j] != t[j] && s[i-last+j] != '?') { check = false; break; } } } else check = false; if (check) { ok = true; foreach (j; 0 .. last+1) { s[i-last+j] = t[j]; } foreach (j; 0 .. s.length) { if (s[j] == '?') s[j] = 'a'; } break; } } } if (ok) s.writeln; else "UNRESTORABLE".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.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 R = RD; auto G = RD; writeln((G * 2) - R); stdout.flush(); debug readln(); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto s = readln.chomp; if (s.length < 4) writeln("No"); else if (s[0..4] != "YAKI") writeln("No"); else writeln("Yes"); }
D
void main() { long n = rdElem; dchar[] s = rdDchar; s.uniq.array.length.writeln; } 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.string, std.conv; void main() { while(true) { auto line = readln; if(!line)break; auto f = line.chomp.to!real; f.classify.writeln; } } string classify(real w) { if(w <= 48) return "light fly"; if(w <= 51) return "fly"; if(w <= 54) return "bantam"; if(w <= 57) return "feather"; if(w <= 60) return "light"; if(w <= 64) return "light welter"; if(w <= 69) return "welter"; if(w <= 75) return "light middle"; if(w <= 81) return "middle"; if(w <= 91) return "light heavy"; return "heavy"; }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto k = readln.chomp.to!int; auto x = readln.chomp.to!int; auto y = readln.chomp.to!int; writeln(min(n,k)*x+max(0,n-k)*y); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.container; import std.datetime; void main() { while (1) { auto x = readln.chomp.split.map!(to!int); if (x[0] == -1) break; (Date(x[3], x[4], x[5]) - Date(x[0], x[1], x[2])).total!"days".writeln; } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto m = n; int cnt; int k = 1; while (n) { auto t = n / 10; if (t) { cnt += 10 ^^ k - 10 ^^ (k - 1); } else { cnt += m - 10 ^^ (k - 1) + 1; } k += 2; n /= 100; } cnt.writeln; }
D
import std.stdio; import std.ascii; import std.string; import std.range; import std.algorithm; import core.stdc.stdio; int main() { int k = readInt!int; char[] s = readString.dup.reverse; int n = cast(int)s.length; int q = readInt!int; long[] pos = new long[](n + 1); void calculate(int v) { if (v * 2 > s.length) { if (s[v - 1] == '0' || s[v - 1] == '1') pos[v] = 1; else pos[v] = 2; return; } int left = 2 * v; int right = 2 * v + 1; calculate(left); calculate(right); if (s[v - 1] == '1') { pos[v] = pos[left]; } else if (s[v - 1] == '0') { pos[v] = pos[right]; } else { pos[v] = pos[right] + pos[left]; } } calculate(1); foreach(qi; 0 .. q) { int p = n - readInt!int + 1; string ch = readString; s[p - 1] = ch[0]; while (p >= 1) { if (p * 2 >= n) { if (s[p - 1] == '0' || s[p - 1] == '1') pos[p] = 1; else pos[p] = 2; goto done; } if (s[p - 1] == '1') { pos[p] = pos[2 * p]; } else if (s[p - 1] == '0') { pos[p] = pos[2 * p + 1]; } else { pos[p] = pos[2 * p] + pos[2 * p + 1]; } done: p /= 2; } pos[1].writeln; } return 0; } /* INPUT ROUTINES */ int currChar; static this() { currChar = getchar(); } char topChar() { return cast(char) currChar; } void popChar() { currChar = getchar(); } auto readInt(T)() { T num = 0; int sgn = 0; while (topChar.isWhite) popChar; while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; } while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; } if (sgn) return -num; return num; } string readString() { string res = ""; while (topChar.isWhite) popChar; while (!topChar.isWhite) { res ~= topChar; popChar; } return res; } /**MODULAR SYSTEM*/ struct Z(immutable long m) { long rep; this(long num) { rep = num; } Z!m opBinary(string operator)(Z!m rhs) { static if (operator == "+") { long result = rhs.rep + this.rep; if (result >= m) result -= m; return Z!m(result); } else static if (operator == "-") { long result = this.rep - rhs.rep; if (result < 0) result += m; return Z!m(result); } else static if (operator == "*") { long result = this.rep * rhs.rep; if (result >= m) result %= m; return Z!m(result); } else static assert(text("Operator ", operator, " not supported")); } Z!m opBinary(string operator)(long exponent) if (operator == "^^") { assert(exponent >= 0); Z!m base = this; Z!m result = 1; while (exponent) { if (exponent & 1) result = result * base; base = base * base; exponent >>= 1; } return result; } invariant { assert(rep >= 0 && rep < m); } }
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; } } // 冪乗をmod取りつつ計算 ulong modPow(ulong a, ulong n, ulong m) { ulong r = 1; while (n > 0) { if(n % 2 != 0) r = r * a % m; a = a * a % m; n /= 2; } return r; } // フェルマーの小定理から乗法逆元を計算 // 定理の要請により法は素数 ulong modInv(ulong a, ulong m) { return modPow(a, m-2, m); } // mod取りつつ組み合わせを計算 // modInvを使っているので法は素数 ulong modComb(ulong n, ulong r, ulong m) { if (n == r) return 1; if (r == 0) return 1; if (n < r) return 0; ulong up = 1; ulong down = 1; for(ulong i = n-r+1; i <= n; i++) { up *= i; up %= m; } for(ulong i = 2; i <= r; i++) { down *= i; down %= m; } return up*modInv(down, m) % m; } ulong MOD = 1000000007; void main() { ulong n, k; readInto(n, k); for (ulong i = 1; i <= k; i++) { writeln(modComb(n-k+1, i, MOD)*modComb(k-1, i-1, MOD) % MOD); } }
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 a = readln.chomp.split.to!(int[]); auto x = a[0] + a[1]; auto y = a[0] * a[1]; if (x == 15) writeln("+"); else if (y == 15) writeln("*"); else writeln("x"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto xy = readln.split.to!(long[]); auto X = xy[0]; auto Y = xy[1]; writeln(abs(X - Y) <= 1 ? "Brown" : "Alice"); }
D
import std.stdio; import std.string; void main(){ string a,s=readln.chomp; for(int i=0;i<s.length;++i){ if('a'<=s[i]&&s[i]<='z')a~=s[i]-'a'+'A'; else if('A'<=s[i]&&s[i]<='Z')a~=s[i]-'A'+'a'; else a~=s[i]; } writeln(a); }
D
import std.stdio; import std.algorithm; import std.range; import std.array; import std.string; import std.conv; void main(){ auto n = readln.chomp.to!long; writeln(get_lucas(n)); } long get_lucas(long n, long pre = 2, long after = 1){ if(n == 1){ return after; }else if(n == 0){ return 2; }else{ return get_lucas(n-1, after, pre+after); } }
D
// Try Codeforces // author: Leonardone @ NEETSDKASU import std.stdio : readln, writeln; import std.string : chomp; import std.array : split; import std.conv : to; import std.algorithm : sum; auto gets() { return readln.chomp; } auto getNum(T)() { return gets.to!T; } auto getVals(T)() { return gets.split.to!(T[]); } void main() { auto n = getNum!int; int[6] xs; for (int i = 0; i < 6; i++) { xs[i] = n % 10; n = (n - n % 10) / 10; } auto check = () => sum(xs[0..3]) == sum(xs[3..$]); if (check()) { writeln(0); return; } foreach (i; 0..6) { auto backup = xs[i]; foreach (j; 0..10) { xs[i] = j; if (check()) { writeln(1); return; } } xs[i] = backup; } foreach (i; 0..5) { auto backupA = xs[i]; foreach (a; 0..10) { xs[i] = a; foreach (j; i+1..6) { auto backupB = xs[j]; foreach (b; 0..10) { xs[j] = b; if (check()) { writeln(2); return; } } xs[j] = backupB; } } xs[i] = backupA; } writeln(3); }
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(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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); } void main() { auto a = RD; auto b = RD; auto k = RD; string ans1, ans2; if (a == 0) { if (k == 0) { foreach (i; 0..b) { ans1 ~= '1'; ans2 ~= '1'; } } } else if (b == 1) { if (k == 0) { ans1 ~= '1'; ans2 ~= '1'; foreach (i; 0..a) { ans1 ~= '0'; ans2 ~= '0'; } } } else if (k == 0) { foreach (i; 0..b) { ans1 ~= '1'; ans2 ~= '1'; } foreach (i; 0..a) { ans1 ~= '0'; ans2 ~= '0'; } } else if (k <= a + b - 2) { auto d = k-1; ans1 ~= "11"; ans2 ~= "10"; auto aa = min(a-1, d); foreach (i; 0..aa) { ans1 ~= '0'; ans2 ~= '0'; } d -= aa; foreach (i; 0..d) { ans1 ~= '1'; ans2 ~= '1'; } ans1 ~= '0'; ans2 ~= '1'; auto rem_a = a - 1 - aa; auto rem_b = b - 2 - d; foreach (i; 0..rem_a) { ans1 ~= '0'; ans2 ~= '0'; } foreach (i; 0..rem_b) { ans1 ~= '1'; ans2 ~= '1'; } } if (ans1.empty) writeln("No"); else { writeln("Yes"); writeln(ans1); writeln(ans2); } stdout.flush; debug readln; }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; import std.utf; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto s = readln.strip; alias mirror = len => s[0..len] ~ s[0..len].byChar.retro.array; int len = 1; bool first = true; int [] cand = [1, n]; foreach (i; 0..n - 1) { if (s[i + 1] < s[i]) { cand ~= i + 1; } if (s[i + 1] > s[i]) { cand ~= i + 1; break; } } debug {writeln (cand);} cand.map !(mirror).minElement.writeln; } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1]; auto S = readln.chomp; auto st = new int[](N*2); int p = -1; int cnt = 0; int front = 0; foreach (i; 0..N) { if (S[i] == '(') { st[++p] = i; } else if (cnt < N - K) { cnt += 2; p -= 1; } else { st[++p] = i; } } foreach (i; 0..p+1) { write(S[st[i]]); } writeln; }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; long res = 0; foreach (i; 1..n) { res += max (0, a[i - 1] - a[i]); } writeln (res); } }
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(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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long 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!string; ans[ti] = cast(int)n.length; } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.container, std.math; immutable int mod = 10^^9 + 7; long n, s; void main() { readVariables(n, s); long top, btm, mid; if (n - dsum(n) < s) { writeln(0); return; } top = n; while (top - btm > 1) { mid = btm + (top - btm) / 2; debug { writeln(mid, " ", dsum(mid)); } if (mid - dsum(mid) >= s) { top = mid; } else { btm = mid; } } long ans = n - top + 1; writeln(ans); } long dsum(long mid) { return mid > 0 ? dsum(mid / 10) + mid % 10 : 0; } void readVariables(T...)(ref T args) { string[] 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.conv, std.stdio; import std.string; void main() { auto n = readln.chomp.to!int; long s; foreach (i; 1..n+1) if (i % 3 && i % 5) s += i; s.writeln; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, m, k; rd(n, m, k); foreach(i; 0..n+1)foreach(j; 0..m+1){ int s=0; s+=i*m; s-=j*i; s+=j*(n-i); if(s==k){writeln("Yes"); return;} } writeln("No"); } 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.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}} void main() { int n; readV(n); int[] t, a; readC(n, t, a); auto ta = new long[](n), aa = new long[](n); ta[0] = t[0]; aa[0] = a[0]; foreach (i; 1..n) { auto k = max((ta[i-1]+t[i]-1)/t[i], (aa[i-1]+a[i]-1)/a[i]); ta[i] = k*t[i]; aa[i] = k*a[i]; } writeln(ta[$-1]+aa[$-1]); }
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; 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 S = RD; auto dp = new long[][](S.length+1, 4); dp[0][0] = 1; foreach (i, c; S) { dp[i+1][] = dp[i][]; if (c == '?') { dp[i+1][0].moda(dp[i][0]); dp[i+1][0].moda(dp[i][0]); foreach (j; 0..3) { dp[i+1][j+1].moda(dp[i][j]); dp[i+1][j+1].moda(dp[i][j+1]); dp[i+1][j+1].moda(dp[i][j+1]); } } else { auto j = c - 'A'; dp[i+1][j+1].moda(dp[i][j]); } } //stderr.writeln(dp); writeln(dp[S.length][$-1]); stdout.flush(); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { foreach (i, x; readln.split.to!(int[])) if (x == 0) { writeln(i+1); return; } }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { string[] XY = readln.chomp.split.to!(string[]); string X = XY[0], Y = XY[1]; if (X < Y) { writeln("<"); } else if (X > Y) { writeln(">"); } else { writeln("="); } }
D
// url: http://tenka1-2017-beginner.contest.atcoder.jp/tasks/tenka1_2017_a import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp; writeln(s.count('1')); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.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 N = lread(); auto memo = new long[](N + 1); memo[] = -1; memo[0] = 0; long solve(long n) { if (memo[n] != -1) return memo[n]; long i = 1; long ans = long.max; while (i <= n) { ans = ans.min(solve(n - i) + 1); i *= 6; } i = 1; while (i <= n) { ans = ans.min(solve(n - i) + 1); i *= 9; } memo[n] = ans; return ans; } solve(N).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() { while (true) { int n; scan(n); if (!n) return; auto a = readln.split; if (n&1) { n--; a.popBack; } int ans; foreach (i ; 0 .. n/2) { ans += (a[2*i] == "lu" && a[2*i + 1] == "ru" || a[2*i] == "ru" && a[2*i+1] == "lu" || a[2*i] == "ld" && a[2*i+1] == "rd" || a[2*i] == "rd" && a[2*i+1] == "ld"); } 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