code
stringlengths
4
1.01M
language
stringclasses
2 values
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], T = readln.split[0]; int[26] s_data, t_data; int[26] s_ord, t_ord; int ord = 1; foreach ( c; S ) { if (s_ord[c-'a'] == 0) { s_ord[c-'a'] = (ord++); s_data[ s_ord[c-'a']-1 ]++; } else s_data[ s_ord[c-'a']-1 ]++; } ord = 1; foreach ( c; T ) { if (t_ord[c-'a'] == 0) { t_ord[c-'a'] = (ord++); t_data[ t_ord[c-'a']-1 ]++; } else t_data[ t_ord[c-'a']-1 ]++; } writeln(s_data == t_data ? "Yes" : "No"); }
D
/+ dub.sdl: name "F" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; // import dcomp.numeric.prime; // import dcomp.numeric.primitive; import std.numeric; long powmod(long x, long n, long md) { long r = 1; while (n) { if (n & 1) r = (r*x) % md; x = (x*x) % md; n >>= 1; } return r; } long tot(long x) { long y = x; for (long i = 2; i*i <= x; i++) { if (x % i) continue; y /= i; y *= (i-1); while (x % i == 0) x /= i; } if (x > 1) { y /= x; y *= (x-1); } return y; } long inv(long x, long md) { return extGcd(x, md)[0]; } long query(long a, long m) { if (m == 1) { return 10L^^9; } long t = tot(m); long g = gcd(t, m); long u = query(a, g); long f = powmod(a, u, m); // writefln("%d %d %d %d %d %d", a, m, t, g, u, f); f = ((f - u) % m + m) % m; f /= g; f *= inv(t/g, m/g); f = (f % m + m) % m; // writeln("last f", f); long ans = u + f * t; // writeln("RES ", powmod(a, ans, m), " ", ans % m); return u + f * t; } int main() { Scanner sc = new Scanner(stdin); int q; sc.read(q); foreach (ph; 0..q) { long a, m; sc.read(a, m); long z = query(a, m); writeln(z); // writeln(z, " ", powmod(a, z, m), " ", z % m); // break; } return 0; } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/numeric/primitive.d */ // module dcomp.numeric.primitive; import std.traits; import std.bigint; Unqual!T pow(T, U)(T x, U n) if (!isFloatingPoint!T && (isIntegral!U || is(U == BigInt))) { return pow(x, n, T(1)); } Unqual!T pow(T, U, V)(T x, U n, V e) if ((isIntegral!U || is(U == BigInt)) && is(Unqual!T == Unqual!V)) { Unqual!T b = x, v = e; Unqual!U m = n; while (m) { if (m & 1) v *= b; b *= b; m /= 2; } return v; } T lcm(T)(in T a, in T b) { import std.numeric : gcd; return a / gcd(a,b) * b; } T[3] extGcd(T)(in T a, in T b) if (!isIntegral!T || isSigned!T) { if (b==0) { return [T(1), T(0), a]; } else { auto e = extGcd(b, a%b); return [e[1], e[0]-a/b*e[1], e[2]]; } } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/numeric/prime.d */ // module dcomp.numeric.prime; T[] divisorList(T)(T x) { import std.algorithm : sort; T[] res; for (T i = 1; i*i <= x; i++) { if (x%i == 0) { res ~= i; if (i*i != x) res ~= x/i; } } sort(res); return res; } T[] factorList(T)(T x) { T[] res; for (T i = 2; i*i <= x; i++) { while (x % i == 0) { res ~= i; x /= i; } } if (x > 1) res ~= x; return res; } /* IMPORT /Users/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 /Users/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); } } } /* This source code generated by dcomp and include dcomp's source code. dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp) */
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() { auto res = iota(0, 1000001).array; foreach_reverse (i; 0..1000001) { foreach (y; 2..1001) { auto py = y ^^ 2; if (i + py > 1000000) break; res[i+py] = res[i] + y; } } foreach_reverse (i; 0..1000001) { foreach (z; 2..101) { auto pz = z ^^ 3; if (i + pz > 1000000) break; res[i+pz] = min(res[i+pz], res[i] + z); } } while (1) { auto n = readln.chomp.to!int; if (!n) break; res[n].writeln; } }
D
import std.stdio, std.string, std.algorithm, std.conv, std.range, std.array; void main() { auto inp = readln().chomp; int max; for(int i; i<=(inp.length-1)/2; i++){ if(inp[0..i]==inp[i..i*2]){max=i*2;} } max.writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto md1 = readln.split.to!(int[]); auto md2 = readln.split.to!(int[]); writeln(md1[0] == md2[0] ? 0 : 1); }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional; void main() { auto S = readln.chomp; if(S == "Sunny") { "Cloudy".writeln; } else if (S=="Cloudy") { "Rainy".writeln; } else if(S=="Rainy") { "Sunny".writeln; } }
D
void main() { auto n = ri; n %= 10; switch(n) { case 2, 4, 5, 7, 9: writeln("hon"); break; case 0, 1, 6, 8: writeln("pon"); break; case 3: writeln("bon"); break; default: assert(0); } } // =================================== 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; } long rl() { return readAs!long; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long A, B, K; scan(A, B, K); long a, b; a = max(A - K, 0); K = max(K - A, 0); b = max(B - K, 0); writeln(a, " ", b); }
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(){ int x = scan!int; int y = x; foreach(k; 3 .. 1000){ if((y * k) % 360 == 0){ k.print; return; } } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto S = RD!string; long ans; long last; long lastCnt; foreach (i; 1..S.length) { if (S[i-1..i+1] == "><" || S[i-1..i+1] == "<>") { auto cnt = i - last; ans += cnt * (cnt+1) / 2; if (S[i-1..i+1] == "><") ans -= min(cnt, lastCnt); last = i; lastCnt = cnt; } debug writeln("i:", i, " ans:", ans); } auto cnt = S.length - last; ans += cnt * (cnt+1) / 2; if (S[$-1] == '>') ans -= min(cnt, lastCnt); writeln(ans); stdout.flush(); debug readln(); }
D
void solve(){ } void main(){ string s = instr(); writeln( s==s.dup.reverse.to!string?"Yes":"No" ); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; alias instr = () => readln().chomp(); T inelm(T= int)(){ return to!(T)( readln().chomp() ); } T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }
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() { foreach (line; stdin.byLine) { auto str = line.chomp; if (str == "#") break; int s, cnt; foreach (e; str) { if ((e >= 'a' && e <= 'g') || (e >= 'q' && e <= 't') || (e >= 'v' && e <= 'x') || (e == 'z')) { if (s == -1) cnt++; s = 1; } else { if (s == 1) cnt++; s = -1; } } cnt.writeln; } }
D
import std.stdio, std.string; void main() { readln.chomp.replace(",", " ").writeln; }
D
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons; 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); } void main() { auto N = readln.chomp.to!int; auto A = readln.chomp.map!(c => cast(int)(c - '1')).array; int solve() { bool isOddTriangle(T)(long N, T arr) { bool isOdd; foreach(i, a; arr) { if (a != 1) continue; auto k = i; if ((N & k) == k) isOdd ^= true; debug [N, k, N&k, isOdd].writeln; } return isOdd; } if (isOddTriangle(N-1, A)) return 1; if (A.any!(a => a == 1)) return 0; return isOddTriangle(N-1, A.map!"a/2".array) ? 2 : 0; } solve().writeln(); }
D
import std.stdio, std.string, std.conv; void main() { auto ip = readln.split.to!(int[]), A = ip[0], B = ip[1], C = ip[2], D = ip[3]; if(A+B > C+D){ writeln("Left"); } else if(A+B < C+D){ writeln("Right"); } else { writeln("Balanced"); } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm; void main() { int a,b; scan(a,b); writeln(a*b % 2 ? "Odd" : "Even"); } 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
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; import std.math; import std.range; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } //Digit count---{{{ int DigitNum(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } //}}} //}}} void main() { Scanner sc = new Scanner; int A, B; sc.scan(A, B); if (B % A == 0) writeln(A + B); else writeln(B - A); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias SugarWater = Tuple!(long, "swater", long, "sugar"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long l, r; scan(l, r); if(r - l >= 2019) { writeln(0); return; } long minmod = 2019; foreach(i; l .. r) { foreach(j; i + 1 .. r + 1) { auto mod = (i * j) % 2019; minmod = min(mod, minmod); } } minmod.writeln(); }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; int solve() { auto s = readln.chomp; int i=0, j=(s.length-1).to!int; char x = 'x'; int res = 0; while(i<j) { if(s[i]==x&&s[j]==x) { i++; j--; continue; } if(s[i]==x&&s[j]!=x) { i++; res++; continue; } if(s[i]!=x&&s[j]==x) { j--; res++; continue; } if(s[i]!=x&&s[j]!=x) { if(s[i]==s[j]) { i++; j--; continue; } else return -1; } } return res; } void main() { solve.writeln; }
D
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; void main(){ auto a=readln.chomp.to!int; auto b=readln.chomp.to!int; auto c=readln.chomp.to!int; auto d=readln.chomp.to!int; if(a>=b&&c>=d)writeln(b+d); else if(a>=b&&c<=d)writeln(b+c); else if(a<=b&&c>=d)writeln(a+d); else if(a<=b&&c<=d)writeln(a+c); }
D
// Vicfred // https://atcoder.jp/contests/abc176/tasks/abc176_c // greedy import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main() { long n = readln.chomp.to!long; long[] a = readln.split.map!(to!long).array; long last = a[0]; long ans = 0; for(int i = 1; i < n; i++) if(a[i] < last) ans += last - a[i]; else last = a[i]; 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; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto x = cast(long)(N / 1.08); if (cast(long)(x * 1.08) == N) writeln(x); else if (cast(long)((x+1) * 1.08) == N) writeln(x+1); else writeln(":("); stdout.flush; debug readln; }
D
module aoj; import std.conv; import std.stdio; import std.string; int getInt() { return to!int(chomp(readln())); } void main() { int n; while ((n = getInt()) != 0) { int sum = 0; foreach (i; 0 .. n/4) { sum += getInt(); } writeln(sum); } }
D
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } /* a[i]: i番目を踏むときの最善 漸化式は a[i] = min(j; i - k .. i)(a[j] + abs(h[i] - h[j])) */ void main(){ long n = read.to!long; long k = read.to!long; long[] hs = readln.chomp.split.map!(to!long).array; long[] as = [0]; foreach(i; 1 .. n){ as ~= long.max; foreach(j; max(0, i - k) .. i){ long a = as[j] + abs(hs[i] - hs[j]); if(a < as[i]) as[i] = a; } } as[n - 1].writeln; }
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); auto S = readln.chomp.to!(char[]); foreach (i ; 0 .. S.length) { S[i] = (((S[i] - 'A') + N) % 26 + 'A').to!char; } writeln(S); } 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
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; alias T = Tuple!(int, int); void main() { immutable n = readln.strip.to!int; long res; int[4] c; foreach (qid; 0 .. n) { auto s = readln.strip; int t1 = (s.back == 'A') ? 1 : 0; int t2 = (s.front == 'B') ? 1 : 0; foreach (i; 1 .. s.length) { if (s[i-1] == 'A' && s[i] == 'B') ++res; } c[t1 * 2 + t2]++; } while (c[2]) { c[2]--; if (c[1]) { c[1]--; res++; } if (c[3]) { res += c[3]; c[3] = 0; } } if (c[3]) { res += c[3] - 1; if (c[1]) { c[1]--; res++; } } writeln (res); }
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 x; scan(x); if (x == 3 || x == 5 || x == 7) { writeln("YES"); } else { writeln("NO"); } } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; void main() { string input; int div; while ((input = readln().chomp()).length != 0) { div = input.to!int(); int[] position = iota(600).filter!(a => a % div == 0).array(); int sum; foreach (pos; position) { sum += pos * pos * div; } writeln(sum); } }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test 12 ---+/ /+---test 5 ---+/ /+---test 1000000000000000000 ---+/ void main(string[] args) { const N = readln.chomp.to!long; if (N%2 == 1) { 0.writeln; return; } size_t ans; for (long i = 10; i <= N; i*=5) { ans += N/i; } ans.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(); long cnt; foreach (i; 0 .. N) { long l, r; scan(l, r); cnt += r - l + 1; } writeln(cnt); }
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii, std.typecons; // }}} // tbh.scanner {{{ class Scanner { import std.stdio; import std.conv : to; import std.array : split; import std.string : chomp; private File file; private dchar[][] str; private uint idx; this(File file = stdin) { this.file = file; this.idx = 0; } private dchar[] next() { if (idx < str.length) { return str[idx++]; } dchar[] s; while (s.length == 0) { s = file.readln.chomp.to!(dchar[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(uint len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } } // }}} void main() { auto cin = new Scanner; foreach (i; 0 .. 3) { string s = cin.next!string; write(s[i]); } writeln(); }
D
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; import std.typecons; import std.math; int calc(int x,int r){ return x * (r+100) / 100; } void main() { while(true) { string[] cin; cin=split(readln()); int a=to!int(cin[0]),b=to!int(cin[1]),x=to!int(cin[2]); if(!(a||b||x)) break; int ans=0; for(int i=1; i<x; i++) { for(int j=1; j<x; j++) { if(calc(i,a)+calc(j,a)==x) { int z=calc(i,b)+calc(j,b); if(ans<z) ans=z; } } } writeln(ans); } }
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() { readln.chomp.count!"a == '2'".writeln; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; void main(){ ulong ai, ao, at, aj, al, as, az; { ulong[] tmp = readln.chomp.split.map!(to!ulong).array; ai = tmp[0], ao = tmp[1], at = tmp[2], aj = tmp[3], al = tmp[4], as = tmp[5], az = tmp[6]; } ulong ans; ans += ao; if(min(ai, aj, al) == 0){ ans += 2 * (ai / 2) + 2 * (aj / 2) + 2 * (al / 2); } else{ if(ai % 2 == aj % 2 && aj % 2 == al % 2){ ans += ai + aj + al; } else{ ans += ai + aj + al - 1; } } ans.writeln; } /* T, S, Z は捨てる O はそのまま使うしかない J, L, I は自分を2個セットで使うか、または3個で使う 使い方は2つ。 ・3個でとれるところまでとり、残りを2個セットで使う ・上記より1つ少なくとり、残りを2個セットで使う min(ai, aj, al) == 0 のとき 各自でがんばるしかない ans = 2 * (ai / 2) + 2 * (aj / 2) + 2 * (al / 2) その他のとき 高々1個残しにできる if(ai % 2 == aj % 2 && aj % 2 == al % 2) ans = ai + aj + al else ans = ai + aj + al - 1 */
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto H = readln.split.to!(int[])[0]; foreach (A; readln.split.to!(int[])) H -= A; writeln(H <= 0 ? "Yes" : "No"); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.numeric; import std.stdio; import std.string; void main() { string s = readln().chomp; long w = readln().chomp.to!long; for (int i = 0; i < s.length; i += w) { write(s[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 s = readln.strip; int cur = 1; foreach (i; 1..n) { cur += (s[i - 1] == s[i]); } writeln (cur / 2); } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { auto N = to!int(split(readln())[0]); auto input = split(readln()); auto D = to!int(input[0]), X = to!int(input[1]); int[] A; int n = X; foreach (i; 0..N) { n += (D-1) / ( to!int(split(readln())[0]) ) + 1; } writeln(n); }
D
import std.stdio, std.string, std.conv; void main() { writeln((readln.chomp.split.join.to!int % 4) == 0? "YES" : "NO"); }
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 = readln.chomp.to!int; foreach (ref c; s) { if (c == 'a') continue; int i = c-'a'; if (K < 26-i) continue; c = 'a'; K -= 26-i; } if (K) { s[$-1] = ('a' + ((s[$-1] - 'a').to!int + K) % 26).to!char; } writeln(s); }
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 abc = readln.split.to!(int[]); auto A = abc[0]; auto B = abc[1]; auto C = abc[2]; auto K = readln.chomp.to!int; int k; while (B <= A) { ++k; B *= 2; } while (C <= B) { ++k; C *= 2; } writeln(k <= K ? "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; import std.ascii; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; bool calc(string s) { if (s[0] != 'A') return false; if (s[2..$-1].count('C') != 1) return false; if (s.count!(c => isUpper(c)) > 2) return false; return true; } void main() { auto s = readln.chomp; writeln(calc(s) ? "AC" : "WA"); }
D
import std.stdio; import std.conv; import std.numeric; long f(long n, long c, long d) { return n - (n / c) - (n / d) + (n / (c * d / gcd(c, d))); } void main() { long a, b, c, d; scanf("%ld %ld %ld %ld", &a, &b, &c, &d); write(f(b, c, d) - f(a-1, c, d)); }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { long N; scan(N); foreach(h ; 1 .. 3501) { foreach (n ; 1 .. 3501) { long x = 4L * h * n; long hn = 1L * h * n; //writeln(x, " " , hn); if (x % N) { continue; } long denom = 4L * h * n / N - n - h; //writeln(denom); if (denom <= 0 || hn % denom) { continue; } debug { //writeln(hn, denom); } long w = hn / denom; if (0 < w && w <= 3500) { writeln(h, " ", n, " ", w); return; } } } } 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.string, std.algorithm, std.array, std.conv; void main() { auto input = readln.chomp.split.map!(to!int).array; auto a = input[0]; auto b = input[1]; if (a < b) { "a < b".writeln; } else if (a > b) { "a > b".writeln; } else { "a == b".writeln; } }
D
import std.algorithm, std.string, std.array, std.range, std.stdio, std.conv; void main() { ulong[] NK = readln.chomp.split.to!(ulong[]); ulong N = NK[0], K = NK[1]; writeln(K * (K-1)^^(N-1)); }
D
void main() { (700 + rs.count!(a => a == 'o') * 100).writeln; } // =================================== import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; 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; void main() { int N, M; scan(N, M); auto to1 = new bool[](N); auto toN = new bool[](N); foreach (i; 0 .. M) { int ai, bi; scan(ai, bi); ai--, bi--; if (ai == 0) { to1[bi] = true; } if (bi == N - 1) { toN[ai] = true; } } bool ok; foreach (i; 0 .. N) { if (to1[i] && toN[i]) ok = true; } yes(ok, "POSSIBLE", "IMPOSSIBLE"); } void scan(T...)(ref T args) { auto line = readln.split; // @suppress(dscanner.suspicious.unmodified) 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
// 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() { auto S = sread(); long N = S.length; writeln(max(S[0] - '0' - 1 + 9 * (N - 1), S.map!"a-'0'"().sum())); }
D
import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!size_t; auto ai = readln.split; ai.reverse(); writeln(ai.join(" ")); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto xab = readln.split.to!(long[]); writeln( xab[1] - xab[2] >= 0 ? "delicious" : xab[1] + xab[0] >= xab[2] ? "safe" : "dangerous" ); }
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 K, A, B; scan(K, A, B); if (B < A) { writeln(1 + K); } else { long k = K; k -= A - 1; long r = A + (B - A) * (k / 2) + (k & 1); max(1 + K, r).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 m, k; readV(m, k); if (m == 1) { writeln(k == 0 ? "0 0 1 1" : "-1"); return; } if (k >= 2^^m) { writeln(-1); return; } foreach (i; 0..2^^m) if (i != k) write(i, " "); write(k, " "); foreach_reverse (i; 0..2^^m) if (i != k) write(i, " "); writeln(k); }
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, c, d; readV(a, b, c, d); writeln(max(a*b, c*d)); }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return false; } p = stdin.rawRead (buffer); if (p.empty) { eof = true; return false; } return true; } ubyte nextByte(bool check) () { static if (check) { if (p.empty) { if (!rawRead ()) { return 0; } } } auto r = p.front; p.popFront (); return r; } public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); } bool seekByte (in ubyte lo) { while (true) { p = p.find! (c => c >= lo); if (!p.empty) { return false; } if (!rawRead ()) { return true; } } } template next(T) if (isSigned!T) { T next () { if (seekByte (45)) { return 0; } T res; ubyte b = nextByte!false (); if (b == 45) { while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { T next () { if (seekByte (48)) { return 0; } T res = nextByte!false () - 48; while (true) { ubyte b = nextByte!true (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } T[] nextA(T) (in int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } void main() { auto r = new InputReader (); immutable nt = r.next!uint (); foreach (tid; 0 .. nt) { int x = r.next!uint; const n = r.next!uint; const m = r.next!uint; foreach (i; 0 .. n) { const y = (x / 2) + 10; if (y >= x) break; x = y; } x -= m * 10; writeln (x > 0 ? "NO" : "YES"); } }
D
import std.stdio ,std.conv , std.string; void main(){ auto input = readLine!size_t(); solve(input[0],input[1]).writeln(); } auto solve( size_t x, size_t y ) { if( x < y ){ return 0; } else { return x-y; } } unittest{ assert(1); } T[] readLine( T )(){ T[] ret; foreach( val ; readln().chomp().split() ){ ret ~= to!T(val); } return ret; }
D
import std.stdio, std.string, std.conv; void main() { int[] a = readln.chomp.split.to!(int[]); writeln((a[0] + a[1] >= a[2]) ? "Yes" : "No"); }
D
import std; enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;} T scan(T=long)(){return readln.chomp.to!T;} void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;} T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);} alias Queue=DList;auto enq(T)(ref Queue!T q,T e){q.insertBack(e);}T deq(T)(ref Queue!T q){T e=q.front;q.removeFront;return e;} alias Stack=SList;auto push(T)(ref Stack!T s,T e){s.insert(e);}T pop(T)(ref Stack!T s){T e=s.front;s.removeFront;return e;} struct UnionFind(T){T[T]u;ulong[T] rank;@property{bool inc(T e){return e in u;}auto size(){return u.keys.length;}auto dup(){T[] child=u.keys;T[] parent=u.values;auto res=UnionFind!T(child);child.each!(e=>res.add(e));size.iota.each!(i=>res.unite(child[i],parent[i]));return res;}}this(T e){e.add;}this(T[] es){es.each!(e=>e.add);}auto add(T a,T b=a){assert(b.inc);u[a]=a;rank[a];if(a!=b)unite(a,b);}auto find(T e){if(u[e]==e)return e;return u[e]=find(u[e]);}auto same(T a,T b){return a.find==b.find;}auto unite(T a,T b){a=a.find;b=b.find;if(a==b)return;if(rank[a]<rank[b])u[a]=b;else{u[b]=a;if(rank[a]==rank[b])rank[a]++;}}} struct PriorityQueue(T,alias less="a<b"){BinaryHeap!(T[],less) heap;@property{bool empty(){return heap.empty;}auto length(){return heap.length;}auto dup(){return PriorityQueue!(T,less)(array);}T[] array(){T[] res;auto tp=heap.dup;foreach(i;0..length){res~=tp.front;tp.removeFront;}return res;}void push(T e){heap.insert(e);}void push(T[] es){es.each!(e=>heap.insert(e));}}T look(){return heap.front;}T pop(){T tp=look;heap.removeFront;return tp;}this(T e){ heap=heapify!(less,T[])([e]);} this(T[] e){ heap=heapify!(less,T[])(e);}} //END OF TEMPLATE void main(){ ulong n,k; scan(n,k); ulong sum; foreach(i;k..n+2){ sum=(sum+i*(n+1-i)+1)%(10^^9+7); } sum.writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; void main() { string[] inputs = split(readln()); int x = to!int(inputs[0]); int a = to!int(inputs[1]); int b = to!int(inputs[2]); if(abs(x - a) < abs(x - b)) 'A'.writeln; else 'B'.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 long[](t); foreach (ti; 0..t) { auto s = RD!string; long last; long cnt; foreach (i; 0..s.length) { if (s[i] == '-') --cnt; else ++cnt; if (cnt < last) { --last; ans[ti] += i+1; } } ans[ti] += s.length; } foreach (e; ans) { writeln(e); } stdout.flush; debug readln; }
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; bool calc(string s) { for (int i = 0; i < s.length; i += 2) { switch (s[i]) { case 'R': case 'U': case 'D': break; default: return false; } } for (int i = 1; i < s.length; i += 2) { switch (s[i]) { case 'L': case 'U': case 'D': break; default: return false; } } return true; } void main() { string s = read!string; writeln(calc(s) ? "Yes" : "No"); }
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 t = read.to!int; foreach(_; 0 .. t){ int n = read.to!int; int k = read.to!int; long[] as; foreach(i; 0 .. n) as ~= read.to!long; long best = as[k] - as[0]; int bestleft = 0; foreach(i; 0 .. n - k){ long tmp = as[i + k] - as[i]; if(tmp < best) best = tmp, bestleft = i; } long ans = as[bestleft] + best / 2; ans.writeln; } }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; string RD() { 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 = RD.split; auto H = tokens[0].to!long; auto W = tokens[1].to!long; string[] s; foreach (i; 0..H) { s ~= RD; } bool visit(long i, long j) { if (i < 0 || i >= H || j < 0 || j >= W) return false; return s[i][j] == '#'; } bool cant = false; foreach (i; 0..H) { foreach (j; 0..W) { if (s[i][j] == '.') continue; bool r = false; r |= visit(i-1, j); r |= visit(i+1, j); r |= visit(i, j-1); r |= visit(i, j+1); if (!r) cant = true; } } writeln(cant ? "No" : "Yes"); stdout.flush(); }
D
import std.stdio; import std.algorithm; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() {//try{ auto tokens = split(my_readln()); auto N = to!ulong(tokens[0]); ulong big, result; foreach (i; 0..N) { auto p = to!ulong(my_readln()); result += p; if (p > big) { big = p; } } result -= big / 2; writeln(result); stdout.flush(); /*}catch (Throwable e) { writeln(e.toString()); } readln();*/ }
D
import std.stdio; int main(){ int n; long c1 , c2; scanf("%d %lld %lld" , &n , &c1 , &c2); char arr; int zeroes = 0; int ones = 0; for(int i = 0 ; i < n ; ++i){ scanf(" %c" , &arr); if(arr == '0'){ ++zeroes; } else{ ++ones; } } long ans = 800000000000000000L; for(long i = 1 ; i <= ones ; ++i){ long res = 0L; res += 1L * c1 * i; long small = n / i; long large = small + 1L; long largecnt = n % i; long smallcnt = i - largecnt; res += 1L * c2 * (small - 1L) * (small - 1L) * smallcnt; res += 1L * c2 * (large - 1L) * (large - 1L) * largecnt; if(res < ans){ ans = res; } } printf("%lld" , ans); return 0; }
D
import std.algorithm; import std.array; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; bool ask (long value) { writeln ("? ", value); stdout.flush (); return readln.strip == "Y"; } void answer (long value) { writeln ("! ", value); stdout.flush (); } void main () { long lo = 1; bool rem = false; while (true) { auto x = ask (lo); auto y = ask (lo * 10 - 1); if (x && !y) { rem = true; } if (x && y && rem) { break; } if (!x && y) { lo /= 10; break; } if (lo >= int.max * 10L) { lo = 1; break; } lo *= 10; } long hi = lo * 10 - 1; while (lo < hi) { long me = (lo + hi) / 2; if (ask (me * 10)) { hi = me; } else { lo = me + 1; } } answer (lo); }
D
import std.stdio, std.string, std.conv; void main() { const tmp = readln.split.to!(int[]); const N = tmp[0]; const X = tmp[1]; const Ls = readln.split.to!(int[]); int p = 0; int cnt; foreach (i; 0..N+1) { if (p > X) break; p += Ls[i]; cnt++; } writeln(cnt); }
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[][](100 + 1, (10 ^^ 5) + 1); long N, W; scan(N, W); auto w = new long[](100 + 1); auto v = new long[](100 + 1); foreach (i; 0 .. N) scan(w[i], v[i]); foreach (n; 0 .. N) foreach (m; 0 .. W + 1) { dp[n + 1][m].maxAssign(dp[n][m]); if (m + w[n] <= W) { dp[n + 1][m + w[n]].maxAssign(dp[n][m] + v[n]); } } dp[N][W].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; auto len = S.length; int c; foreach (i; 0..len/2) { if (S[i] != S[len-i-1]) ++c; } writeln(c); }
D
void main() { string s = rdStr; writeln(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No"); } 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.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; 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 = lread(); if (N == 6) { writeln(1); return; } long x = (N * 2 + 10) / 11; if (5 <= x * 11 / 2 - N) { x--; } writeln(x); }
D
import std; void main() { char[] s, t; scan(s); scan(t); int n = s.length.to!int; int m = t.length.to!int; if (n < m) { writeln("UNRESTORABLE"); return; } char[] ans = new char[](n); bool exist; foreach_reverse (i; 0 .. n - m + 1) { if (match(s[i .. i + m], t)) { foreach (j; 0 .. n) { if (i <= j && j < i + m) { ans[j] = t[j - i]; } else { ans[j] = s[j]; } if (ans[j] == '?') { ans[j] = 'a'; } } exist = true; break; } } if (exist) { writeln(ans); } else { writeln("UNRESTORABLE"); } } bool match(char[] s, char[] t) { foreach (i; 0 .. s.length) { if (s[i] == '?') { continue; } if (s[i] != t[i]) { return false; } } return true; } void scan(T...)(ref T args) { auto line = readln.split; // @suppress(dscanner.suspicious.unmodified) 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp; long solve(int i, long n, long s) { if (i == S.length) { return n + s; } else { return solve(i+1, S[i]-'0', n+s) + solve(i+1, n*10+S[i]-'0', s); } } writeln(solve(1, S[0]-'0', 0)); }
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() { int n; scan(n); auto x = new long[](n + 1); auto s = new int[](n + 1); foreach (i ; 1 .. n + 1) { scan(x[i], s[i]); } auto p = new long[](n + 1); p[1] = s[1]; foreach (i ; 2 .. n + 1) { p[i] = p[i-1] + s[i] - (x[i] - x[i-1]); } auto pm = new long[](n + 1); pm[n] = p[n]; foreach_reverse (i ; 1 .. n) { pm[i] = max(p[i], pm[i+1]); } long ans = pm[1]; long d; foreach (i ; 2 .. n+1) { d += (x[i]-x[i-1]) - s[i-1]; ans = max(ans, pm[i] + d); } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
void main() { problem(); } void problem() { auto N = scan!int; auto STONES = scan!string.to!(char[]); long solve() { long left = 0; long right = N-1; long ans; while(left <= right) { if (STONES[right] != 'R') { right--; continue; } if (STONES[left] != 'W') { left++; continue; } STONES.deb; [ans, left, right].deb; STONES[left] = 'R'; STONES[right] = 'W'; ans++; } 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 Point = Tuple!(long, "x", long, "y"); // -----------------------------------------------
D
import std.stdio; import std.string; import std.format; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.concurrency; import std.traits; import std.uni; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; enum long INF = long.max/3; enum long MOD = 10L^^9+7; void main() { long X, A, B; scanln(X); scanln(A); scanln(B); writeln(X-A - (X-A)/B*B); } // ---------------------------------------------- void times(alias fun)(long n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(long n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { // `(x+y-1)/y` will only work for positive numbers ... T t = x / y; if (t * y < x) t++; return t; } T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { T t = x / y; if (t * y > x) t--; return t; } ref T ch(alias fun, T, S...)(ref T lhs, S rhs) { return lhs = fun(lhs, rhs); } unittest { long x = 1000; x.ch!min(2000); assert(x == 1000); x.ch!min(3, 2, 1); assert(x == 1); x.ch!max(100).ch!min(1000); // clamp assert(x == 100); x.ch!max(0).ch!min(10); // clamp assert(x == 10); } mixin template Constructor() { import std.traits : FieldNameTuple; this(Args...)(Args args) { // static foreach(i, v; args) { foreach(i, v; args) { mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v; } } } void scanln(Args...)(auto ref Args args) { import std.meta; template getFormat(T) { static if (isIntegral!T) { enum getFormat = "%d"; } else static if (isFloatingPoint!T) { enum getFormat = "%g"; } else static if (isSomeString!T || isSomeChar!T) { enum getFormat = "%s"; } else { static assert(false); } } enum string fmt = [staticMap!(getFormat, Args)].join(" "); string[] inputs = readln.chomp.split; foreach(i, ref v; args) { v = inputs[i].to!(Args[i]); } } // 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) { private template RebindableOrUnqual(T) { static if (is(T == class) || is(T == interface) || isDynamicArray!T || isAssociativeArray!T) alias RebindableOrUnqual = Rebindable!T; else alias RebindableOrUnqual = Unqual!T; } private auto extremum(alias map, alias selector = "a < b", Range)(Range r) if (isInputRange!Range && !isInfinite!Range && is(typeof(unaryFun!map(ElementType!(Range).init)))) in { assert(!r.empty, "r is an empty range"); } body { alias Element = ElementType!Range; RebindableOrUnqual!Element seed = r.front; r.popFront(); return extremum!(map, selector)(r, seed); } private auto extremum(alias map, alias selector = "a < b", Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seedElement) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void) && is(typeof(unaryFun!map(ElementType!(Range).init)))) { alias mapFun = unaryFun!map; alias selectorFun = binaryFun!selector; alias Element = ElementType!Range; alias CommonElement = CommonType!(Element, RangeElementType); RebindableOrUnqual!CommonElement extremeElement = seedElement; // if we only have one statement in the loop, it can be optimized a lot better static if (__traits(isSame, map, a => a)) { // direct access via a random access range is faster static if (isRandomAccessRange!Range) { foreach (const i; 0 .. r.length) { if (selectorFun(r[i], extremeElement)) { extremeElement = r[i]; } } } else { while (!r.empty) { if (selectorFun(r.front, extremeElement)) { extremeElement = r.front; } r.popFront(); } } } else { alias MapType = Unqual!(typeof(mapFun(CommonElement.init))); MapType extremeElementMapped = mapFun(extremeElement); // direct access via a random access range is faster static if (isRandomAccessRange!Range) { foreach (const i; 0 .. r.length) { MapType mapElement = mapFun(r[i]); if (selectorFun(mapElement, extremeElementMapped)) { extremeElement = r[i]; extremeElementMapped = mapElement; } } } else { while (!r.empty) { MapType mapElement = mapFun(r.front); if (selectorFun(mapElement, extremeElementMapped)) { extremeElement = r.front; extremeElementMapped = mapElement; } r.popFront(); } } } return extremeElement; } private auto extremum(alias selector = "a < b", Range)(Range r) if (isInputRange!Range && !isInfinite!Range && !is(typeof(unaryFun!selector(ElementType!(Range).init)))) { return extremum!(a => a, selector)(r); } // if we only have one statement in the loop it can be optimized a lot better private auto extremum(alias selector = "a < b", Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seedElement) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void) && !is(typeof(unaryFun!selector(ElementType!(Range).init)))) { return extremum!(a => a, selector)(r, seedElement); } auto minElement(alias map = (a => a), Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { return extremum!map(r); } auto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void)) { return extremum!map(r, seed); } auto maxElement(alias map = (a => a), Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { return extremum!(map, "a > b")(r); } auto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range) (Range r, RangeElementType seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void)) { return extremum!(map, "a > b")(r, seed); } } // popcnt with ulongs was added in D 2.071.0 static if (__VERSION__ < 2071) { ulong popcnt(ulong x) { x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L); x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L); x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL); x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL); x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL); x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL); return x; } }
D
import std.stdio, 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 S = RD!string; long[] num; foreach (i; 0..S.length) { num ~= S[i..i+1].to!long; } long ans; foreach (i; 0..2^^(num.length-1)) { long begin; auto x = num.dup; foreach (j; 0..num.length-1) { auto bit = 1LU << j; if (i & bit) { begin = j+1; } else { foreach (k; begin..j+1) { x[k] *= 10; } } } foreach (e; x) ans += e; } writeln(ans); stdout.flush(); //readln(); }
D
void main() { auto X = ri; ulong res; while(X >= 500) { res += 1000; X -= 500; } res += (X / 5) * 5; res.writeln; } // =================================== 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; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto n = readln.chomp.to!int; int[string] t; int sum; foreach (i; 0..n) { auto a = readln.chomp.split; sum += a[1].to!int; t[a[0]] = sum; } auto x = readln.chomp; writeln(sum - t[x]); }
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 s = RD!(char[]); long ans; foreach (i; 0..n/2) { if (s[i*2] == s[i*2+1]) { ++ans; s[i*2] = s[i*2] == 'a' ? 'b' : 'a'; } } writeln(ans); writeln(s); 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.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 bool[](t); foreach (ti; 0..t) { auto n = RD; auto k = RD; if (n < k^^2) ans[ti] = false; else ans[ti] = n % 2 == k % 2; } foreach (e; ans) writeln(e ? "YES" : "NO"); stdout.flush; debug readln; }
D
/+ dub.sdl: name "C" dependency "dunkelheit" version="1.0.1" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner, dkh.algorithm; immutable L = 19; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int n, q; sc.read(n, q); int[] a; sc.read(a); int[L] bk; bk[] = n; int[L][] dp = new int[L][n]; foreach_reverse (i; 0..n) { int d = a[i]; dp[i][] = n; foreach (j; 0..L) { if (!(d & (1 << j))) continue; dp[i][j] = i; int bi = bk[j]; if (bi != n) { foreach (k; 0..L) { dp[i][k] = min(dp[i][k], dp[bi][k]); } } bk[j] = i; } } debug writeln(dp); foreach (ph; 0..q) { int u, v; sc.read(u, v); u--; v--; bool ok = false; foreach (i; 0..L) { if (!(a[v] & (1 << i))) continue; if (dp[u][i] <= v) { ok = true; break; } } if (ok) writeln("Shi"); else writeln("Fou"); } return 0; } /* IMPORT /home/yosupo/Programs/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); } } } } /* IMPORT /home/yosupo/Programs/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 /home/yosupo/Programs/dunkelheit/source/dkh/algorithm.d */ // module dkh.algorithm; import std.traits : isFloatingPoint, isIntegral; T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) { while (r-l > 1) { T md = l + (r-l) / 2; if (!pred(md)) l = md; else r = md; } return r; } T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) { foreach (i; 0..cnt) { T md = (l+r)/2; if (!pred(md)) l = md; else r = md; } return r; } import std.range.primitives; E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed) if (isInputRange!Range && !isInfinite!Range) { import std.algorithm, std.functional; return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range); } ElementType!Range minimum(alias pred = "a < b", Range)(Range range) { assert(!range.empty, "minimum: range must not empty"); auto e = range.front; range.popFront; return minimum!pred(range, e); } E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed) if (isInputRange!Range && !isInfinite!Range) { import std.algorithm, std.functional; return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range); } ElementType!Range maximum(alias pred = "a < b", Range)(Range range) { assert(!range.empty, "maximum: range must not empty"); auto e = range.front; range.popFront; return maximum!pred(range, e); } Rotator!Range rotator(Range)(Range r) { return Rotator!Range(r); } struct Rotator(Range) if (isForwardRange!Range && hasLength!Range) { size_t cnt; Range start, now; this(Range r) { cnt = 0; start = r.save; now = r.save; } this(this) { start = start.save; now = now.save; } @property bool empty() const { return now.empty; } @property auto front() const { assert(!now.empty); import std.range : take, chain; return chain(now, start.take(cnt)); } @property Rotator!Range save() { return this; } void popFront() { cnt++; now.popFront; } } /* IMPORT /home/yosupo/Programs/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; private File f; this(File f) { this.f = f; } private char[512] lineBuf; private 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) { assert(succW()); 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 unsafeRead(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); } } void read(Args...)(auto ref Args args) { import std.exception : enforce; static if (args.length != 0) { enforce(readSingle(args[0])); read(args[1..$]); } } bool hasNext() { return succ(); } } /* 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.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 string[](t); foreach (ti; 0..t) { auto s = RD!string; foreach (i; 0..s.length) { if (s[$-i-1] != 'a') { ans[ti] = s[0..i] ~ 'a' ~ s[i..$]; break; } } } foreach (e; ans) { if (e.empty) writeln("NO"); else { writeln("YES"); 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.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new int[](t); foreach (ti; 0..t) { auto n = RD!int; auto s = RD!string; int[] list; char last = s[0]; int cnt; foreach (i; 0..n) { if (s[i] != last) { list ~= cnt; cnt = 0; } ++cnt; last = s[i]; } if (!list.empty && s[0] == s[$-1]) { list[0] += cnt; } else { list ~= cnt; } if (list.length == 1) { ans[ti] += (list[0] + 2) / 3; } else { foreach (e; list) ans[ti] += e / 3; } } 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 p = RD!int; int ans = -1; foreach (i; 1..33) { auto x = n - i * p; int cnt, cnt_max; foreach (j; 0..32) { auto bit = 1L << j; if (x & bit) { ++cnt; cnt_max += 2^^j; } } debug writeln("i:", i, " x:", x, " cnt:", cnt); if (i >= cnt && i <= cnt_max) { ans = i; break; } } writeln(ans); stdout.flush(); debug readln(); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto hw = readints; int h = hw[0]; for (int i = 0; i < h; i++) { string s = read!string; writeln(s); writeln(s); } }
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; long sum; foreach (int i; 1..n+1) { if (i % 3 && i % 5) { sum += i; } } sum.writeln; }
D
import std.conv; import std.stdio; import std.string; void main() { auto n = readln.strip.to!int; writeln( solve( n ) ); } auto solve( in int n ) { if( n < 1000 ) return "ABC"; else return "ABD"; } unittest { assert( solve( 999 ) == "ABC" ); assert( solve( 1000 ) == "ABD" ); assert( solve( 1481 ) == "ABD" ); }
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; } string calc(Vec2 a, Vec2 b, Vec2 c) { auto ab = b - a; auto ac = c - a; auto d = ab.cross(ac); if (d > 0) return "COUNTER_CLOCKWISE"; if (d < 0) return "CLOCKWISE"; // |ab||ac|cos(pi) で cos(pi) = -1 なので負なら逆向き if (ab.dot(ac) < 0) return "ONLINE_BACK"; if (ab.magSq() >= ac.magSq()) return "ON_SEGMENT"; return "ONLINE_FRONT"; } void main() { auto xs = readints(); auto a = Vec2(xs[0], xs[1]); auto b = Vec2(xs[2], xs[3]); int q = readint(); for (int i = 0; i < q; i++) { auto xy = readints(); auto c = Vec2(xy[0], xy[1]); auto ans = calc(a, b, c); writeln(ans); } } struct Vec2 { immutable double x; immutable double y; this(double x, double y) { this.x = x; this.y = y; } Vec2 opNeg() { return Vec2(-this.x, -this.y); } Vec2 opAdd(Vec2 other) { return Vec2(this.x + other.x, this.y + other.y); } Vec2 opSub(Vec2 other) { return Vec2(this.x - other.x, this.y - other.y); } Vec2 opMul(double d) { return Vec2(this.x * d, this.y * d); } double dot(Vec2 other) { return this.x * other.x + this.y * other.y; } double cross(Vec2 other) { return this.x * other.y - other.x * this.y; } double mag() { return sqrt(magSq()); } double magSq() { return this.x * this.x + this.y * this.y; } Vec2 normalized() { auto m = mag(); if (m != 0 && m != 1) return Vec2(this.x / m, this.y / m); return this; } static double distance(Vec2 a, Vec2 b) { return (a - b).mag(); } }
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; void main() { int m = readln.chomp.split.back.to!int; string s = readln.chomp; int l = 0, r = 1; // bool[string] set; bool[ulong[2]] set; auto hasher = new RollingHash(s); foreach (i; 0..m) { string v = readln; auto f = function(char c, ref int w) { if (c == '+') { ++w; } else { --w; } }; if (v[0] == 'L') { f(v[1], l); } else { f(v[1], r); } set[hasher.substr(l, r)] = true; // set[s[l..r]] = true; } writeln = set.length; } class RollingHash { enum long MOD1 = 1_000_000_007; enum long MOD2 = 1_000_000_009; enum long B1 = 1_009; enum long B2 = 1_007; ulong[] b1s, b2s; ulong[] array1; ulong[] array2; this(string s) { array1 ~= 0; array2 ~= 0; b1s ~= 1; b2s ~= 1; foreach (c; s) { array1 ~= ((array1.back + ulong(c)) * B1) % MOD1; array2 ~= ((array2.back + ulong(c)) * B2) % MOD2; b1s ~= (b1s.back * B1) % MOD1; b2s ~= (b2s.back * B2) % MOD2; } } ulong[2] substr(uint l, uint r) { ulong h1 = (array1[r] - ((b1s[r - l] * array1[l]) % MOD1) + MOD1) % MOD1; ulong h2 = (array2[r] - ((b2s[r - l] * array2[l]) % MOD2) + MOD2) % MOD2; return [h1, h2]; } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N, A, B; scan(N, A, B); if (B < A) swap(A, B); if ((B - A) % 2 == 0) { ((B - A) / 2).writeln(); return; } long a = N - A; long b = B - 1; long c = ((B - A) - 1) / 2 + (A); // 1で折り返す long d = (N - (A + N - B + 1)) / 2 + (N - B + 1); // Nで折り返す // writeln(a, " ", b, " ", c, " ", d); min(a, b, c, d).writeln(); }
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[]); writeln(max(0, tmp[2] - tmp[0] + tmp[1])); }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test 2 ---+/ /+---test 4 ---+/ /+---test 1000000000000 ---+/ void main(string[] args) { const H = readln.chomp.to!long; long ans, cnt = 1; for (long h = H; h > 0; h/=2) { ans += cnt; cnt *= 2; } ans.writeln; }
D
// Code By H~$~C import std.stdio; import std.math, std.uni, std.format, std.bigint; import std.array, std.string, std.container, std.range, std.typecons; import std.algorithm, std.conv, std.functional, std.random; immutable Maxn = 200005; int n; int[Maxn] c; int[][Maxn] g; long[Maxn] ans; int[Maxn] sz, num; void dfs(int u, int fa) { int col = c[u]; int bef = num[col]; sz[u] = 1; foreach(v; g[u]) { if (v == fa) continue; int pre = num[col]; dfs(v, u); int vcol = sz[v] - (num[col] - pre); ans[col] -= cast(long)(vcol + 1) * vcol / 2; sz[u] += sz[v]; } num[col] = bef + sz[u]; } void _Main() { read(n); foreach(i; 0 .. n) read(c[i]), c[i]--; foreach(i; 1 .. n) { int u, v; read(u, v); --u, --v; g[u] ~= v; g[v] ~= u; } foreach(i; 0 .. n) ans[i] = cast(long)(n + 1) * n / 2; dfs(0, -1); foreach(i; 0 .. n) { int rest = n - num[i]; (ans[i] -= cast(long)(rest + 1) * rest / 2).writeln; } } class EOFException : Throwable { this() { super("------ EOF Error!"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } void read(T...)(ref T x) { foreach(i, ref y; x) y = readToken.to!(T[i]); } void main(string[] args) { try { int tests = 1; // read(tests); foreach (test; 0 .. tests) _Main(); } catch(EOFException e) { } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto X = RD; auto Y = RD; long ans; if (X == 3) ans += 100000; else if (X == 2) ans += 200000; else if (X == 1) ans += 300000; if (Y == 3) ans += 100000; else if (Y == 2) ans += 200000; else if (Y == 1) ans += 300000; if (X == 1 && Y == 1) ans += 400000; 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.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(); long bignum = 1_000_000_007; 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; } } long manhattan(long x1, long y1, long x2, long y2) { return abs(x2 - x1) + abs(y2 - y1); } void main() { long n, l; scan(n, l); long sumf, minf = bignum; foreach (i; 0 .. n) { long f = l + i; minf = min(abs(minf), abs(f)); sumf += f; } if (sumf >= 0) (sumf - minf).writeln(); else (sumf + minf).writeln(); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; int[(10^^5)*2+1] PS; void main() { auto N = readln.chomp.to!int; foreach (_; 0..N) { auto p = readln.chomp.to!int; PS[p] = PS[p-1] + 1; } int max = 0; foreach (p; PS[0..N+1]) if (p > max) max = p; writeln(N - max); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int k, x; scan(k, x); writeln(500*k >= x ? "Yes" : "No"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
void main() { char c = readln.chomp.to!char; char[] vowels = ['a', 'e', 'i', 'o', 'u']; writeln(vowels.canFind(c) ? "vowel" : "consonant"); } 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; void main() { int x = readln.chomp.to!int; writeln(x ^^ 3); }
D