code
stringlengths
4
1.01M
language
stringclasses
2 values
void main() { auto N = ri; ulong cnt; foreach(i; 0..N) { if(rs == "E869120") cnt++; } cnt.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.string; import std.conv; import std.range; import std.array; import std.algorithm; void main() { string input; while ((input = readln.chomp).length != 0) { while (input.length > 1) { string output; for (int i = 0; i < input.length-1; i++) { output ~= (((input[i] - '0')+(input[i+1] - '0'))%10).to!string; } input = output; } writeln(input); } }
D
void main(){ int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); writeln(max(a*b, c*d)); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio; import std.string, std.conv, std.array, std.algorithm; import std.uni, std.math, std.container; import core.bitop, std.datetime; void main(){ auto s = readln.chomp; auto stack = new Stack!(char)(s.length.to!int); foreach(c;s){ if(c == 'B'){ if(!stack.isEmpty) stack.pop(); } else{ stack.push(c); } } stack.print; } class Stack(T){ private T[] stack; private int top, size; this(int N){ stack = new T[](N + 1); size = N + 1; } bool isEmpty(){ return top == 0; } bool isFull(){ return top >= size; } void push(T stuff){ ++top; if(isFull) throw new Exception("Stack is Full."); stack[top] = stuff; } auto pop(){ if(isEmpty) throw new Exception("Stack is Empty."); auto ret = stack[top]; --top; return ret; } auto print(){ foreach(i ; 1 .. top + 1){ write(stack[i]); } writeln; } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; struct P {int first; int second;} int main() { while (true) { string[] str = readln().chomp().split(); int h = str[0].to!int(); int w = str[1].to!int(); if (h == 0 && w == 0) break; string t; char[101][101] f; for (int i = 0; i < h; i++) { t = readln.chomp; for (int j = 0; j < w; j++) { f[i][j] = t[j].to!char; } } P[char] m; P p; p.first = 0; p.second = 1; m['>'] = p; p.first = 0; p.second = -1; m['<'] = p; p.first = -1; p.second = 0; m['^'] = p; p.first = 1; p.second = 0; m['v'] = p; p.first = p.second = 0; m['.'] = m['*'] = p; int x = 0, y = 0; while (true) { int nx = x, ny = y; if (f[nx][ny] == '*') { writeln("LOOP"); break; } //writeln(m[f[nx][ny]].first, " ", m[f[nx][ny]].second); if (0 <= nx + m[f[nx][ny]].first && nx + m[f[nx][ny]].first < h && 0 <= ny + m[f[nx][ny]].second && ny + m[f[nx][ny]].second < w) { nx = nx + m[f[nx][ny]].first; ny = ny + m[f[nx][ny]].second; } f[x][y] = '*'; if (x == nx && y == ny || f[nx][ny] == '.') { writeln(ny, " ", nx); break; } x = nx; y = ny; } } return 0; }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return false; } p = stdin.rawRead (buffer); if (p.empty) { eof = true; return false; } return true; } ubyte nextByte(bool check) () { static if (check) { if (p.empty) { if (!rawRead ()) { return 0; } } } auto r = p.front; p.popFront (); return r; } public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); } bool seekByte (in ubyte lo) { while (true) { p = p.find! (c => c >= lo); if (!p.empty) { return false; } if (!rawRead ()) { return true; } } } template next(T) if (isSigned!T) { T next () { if (seekByte (45)) { return 0; } T res; ubyte b = nextByte!false (); if (b == 45) { while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { T next () { if (seekByte (48)) { return 0; } T res = nextByte!false () - 48; while (true) { ubyte b = nextByte!true (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } T[] nextA(T) (in int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } void main() { auto r = new InputReader (); immutable nt = r.next!uint (); foreach (tid; 0 .. nt) { auto a = r.nextA!uint (4); writeln (a[1], ' ', a[2], ' ', a[2]); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_; 0..T) { auto xnm = readln.split.to!(int[]); auto X = xnm[0]; auto N = xnm[1]; auto M = xnm[2]; while (N > 0 && X/2 >= 10) { X = X/2 + 10; --N; } writeln(X <= M*10 ? "YES" : "NO"); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void main() { int x, t; readV(x, t); writeln(max(0, x-t)); }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void main(){ auto ip = readln.split.to!(int[]); if(ip[0] + ip[1] >= ip[2]){ writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio; void main() { long l, r; scanf("%ld%ld", &l, &r); auto ans = 0; for (long a2=1; a2<=r; a2*=2) { for (long a3=1; a3<=r/a2; a3*=3) { if (a2 * a3 >= l) ans++; } } writeln(ans); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { import std.math; int x, a, b; scan(x, a, b); writeln(abs(x-a) < abs(x-b) ? "A" : "B"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int x, y; scan(x, y); writeln(x + y / 2); } 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
void main(){ auto K = readLine!()()[0]; auto AB = readLine!()(); foreach( i ; 1..1000 ){ if( AB[0] <= K*i && K*i <= AB[1] ){ writeln("OK"); return; } if( K*i > 1001 ){break;} } writeln("NG"); return; } import std.stdio, std.string, std.conv; import std.math, std.algorithm, std.array; import std.regex; T[] readLine( T = size_t )( string sp = " " ){ T[] ol; foreach( string elm ; readln().chomp().split(sp) ){ ol ~= elm.to!T(); } return ol; }
D
import std.stdio; import std.string; import std.conv; void main() { auto l = readln.chomp; auto fst = l[0..2].to!int; auto snd = l[2..4].to!int; auto fM = fst > 0 && fst <= 12; auto sM = snd > 0 && snd <= 12; if (fM && sM) write("AMBIGUOUS"); else if (sM) write("YYMM"); else if (fM) write("MMYY"); else write("NA"); }
D
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; import std.typecons; void main(){ auto hw = readln().chomp().split().map!(to!int).array(); string[] grids; foreach(i; 0..(hw[0])){ grids ~= readln().chomp(); } solve(grids).writeln(); } string solve(string[] grids){ bool result = true; foreach(int y; 0..cast(int) grids.length){ foreach(int x; 0..cast(int) grids[y].length){ if(!check(x, y, grids)){ result = false; break; } } if(!result){ break; } } if(result){ return "Yes"; }else{ return "No"; } } bool check(int x, int y, string[] grids){ bool result; if(grids[y][x] == '#'){ if(x - 1 >= 0){ if(grids[y][x-1] == '#'){ result = true; } } if(y - 1 >= 0){ if(grids[y - 1][x] == '#'){ result = true; } } if(x + 1 < grids[y].length){ if(grids[y][x+1] == '#'){ result = true; } } if(y + 1 < grids.length){ if(grids[y+1][x] == '#'){ result = true; } } }else{ result = true; } return result; }
D
import std.stdio; import std.algorithm; import std.math; import std.string; import std.conv; import std.range; void main() { foreach (string line; stdin.lines) { string s = line.chomp; int joi = 0; int ioi = 0; for (int i = 0; i < s.length - 2; i++) { if (s[i..i+3] == "JOI") { joi++; } else if (s[i..i+3] == "IOI") { ioi++; } } joi.writeln; ioi.writeln; } }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); foreach(i; 0..10){ char[] t; foreach(_; 0..3) t~=i+'0'; if(s[0..($-1)]==t){writeln("Yes"); return;} if(s[1..$]==t){writeln("Yes"); return;} } writeln("No"); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; template bsearch(alias fun) { import std.functional: unaryFun; alias f = unaryFun!fun; int bsearch(T)(T[] arr) { if (arr.empty) return -1; if (!f(arr[0])) return -1; if (f(arr[$-1])) return arr.length.to!int - 1; int l, r = arr.length.to!int - 1; while (l+1 < r) { auto m = (l+r)/2; if (f(arr[m])) { l = m; } else { r = m; } } return l; } } size_t[][26] D; void main() { auto s = readln.chomp.to!(char[]); auto t = readln.chomp.to!(char[]); foreach (i, c; s) { D[c - 'a'] ~= i; } ulong cnt; size_t p; bool first = true; foreach (c; t) { auto d = D[c - 'a']; if (d.empty) { writeln(-1); return; } if (first) { first = false; if (d[0] == 0) { continue; } } if (d[$-1] <= p) { p = d[0]; ++cnt; continue; } else if (d[0] > p) { p = d[0]; continue; } auto l = bsearch!(i => i <= p)(d); p = d[l+1]; } writeln(s.length * cnt + p + 1); }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto a = readln.split[0].to!int; auto b = readln.split[0].to!int; auto c = readln.split[0].to!int; auto d = readln.split[0].to!int; auto e = readln.split[0].to!int; int f(int x) { if (x % 10 == 0) return x; else return x + 10 - x%10; } writeln(min( f(a) + f(b) + f(c) + f(d) + e, f(a) + f(b) + f(c) + d + f(e), f(a) + f(b) + c + f(d) + f(e), f(a) + b + f(c) + f(d) + f(e), a + f(b) + f(c) + f(d) + f(e) )); }
D
import std.stdio,std.conv,std.string,std.algorithm,std.array,std.math; void main(){ auto s=readln().chomp().split().map!(to!int); int a=s[0],b=s[1],c=s[2],ans=0; if(a>b && a>c) ans=b*c/2; else if(b>a && b>c) ans=c*a/2; else ans=a*b/2; writeln(int(ans)); }
D
import std.stdio,std.regex; void main(){ auto next = readln().chomp().to!size_t; auto list = [111,222,333,444,555,666,777,888,999]; foreach( val; list ){ if( next <= val ){ writeln(val); break; } continue; } return; } import std.string,std.conv;
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons; import std.math, std.numeric; void main() { long n, x; scan(n, x); if (x > n - x) { x = n - x; } if (x == n - x) { writeln(3*x); return; } long ans = n; void dfs(long x, long y) { if (x % y == 0) { ans += (x / y) * 2 * y - y; return; } else { ans += (x / y) * 2 * y; dfs(y, x % y); } } dfs(n - x, x); writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.functional, std.algorithm, std.container, std.typetuple, std.typecons, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv, std.format; void main() { auto ip = readln.split.to!(int[]); int count; foreach(i; ip[0]..ip[1]+1){ if(ip[2] % i == 0) count++; } writeln(count); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional; void main() { auto s = readln.chomp; auto n = s.length; foreach (c; s) { if (c == 'A') break; --n; } foreach_reverse (c; s) { if (c == 'Z') break; --n; } writeln(n); }
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; // 差の絶対値 @nogc @safe pure T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } // 切り上げ除算 @nogc @safe pure T divCeil(T)(const ref T a, const ref T b) { return (a+b-1)/b; } T[] readToArray(T)() { return readln.split.to!(T[]); } void readInto(T...)(ref T ts) { auto ss = readln.split; foreach(ref t; ts) { t = ss.front.to!(typeof(t)); ss.popFront; } } // 冪乗をmod取りつつ計算 @nogc @safe pure ulong modPow(ulong a, ulong n, ulong m) { ulong r = 1; while (n > 0) { if(n % 2 != 0) r = r * a % m; a = a * a % m; n /= 2; } return r; } // フェルマーの小定理から乗法逆元を計算 // 定理の要請により法は素数 @nogc @safe pure ulong modInv(ulong a, ulong m) { return modPow(a, m-2, m); } // mod取りつつ順列を計算 @nogc @safe pure ulong modPerm(ulong n, ulong k, ulong m) { if (n < k) return 0; ulong r = 1; for (ulong i = n-k+1; i <= n; i++) { r *= i; r %= m; } return r; } // mod取りつつ順列を計算 @nogc @safe pure ulong modFact(ulong n, ulong m) { return modPerm(n, n, m); } // mod取りつつ組み合わせを計算 // modInvを使っているので法は素数 @nogc @safe pure ulong modComb(ulong n, ulong r, ulong m) { return modPerm(n, r, m)*modInv(modFact(r, m), m) % m; } immutable ulong MOD = 1000000007; void main() { ulong n; readInto(n); ulong[] p = readToArray!(ulong); ulong cnt = 0; for(ulong i = 0; i < n; i++) { ulong min = p[i]; ulong min_idx = i; for(ulong j = i+1; j < n; j++) { if (p[j] < min) { min_idx = j; } } if (min_idx != i) { if (cnt != 0) { writeln("NO"); return; } ulong tmp = p[i]; p[i] = p[min_idx]; p[min_idx] = tmp; cnt++; } } writeln("YES"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.range, std.string, std.math, std.typecons; void main() { auto nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; long cnt; foreach (long i; 0..N) { if (i < K) continue; else { cnt += N / (i+1) * (i+1-K); if (N % (i+1) >= K) cnt += N % (i+1) - K + 1; if (!K) cnt -= 1; } } writeln(cnt); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long a,b,c; scan(a,b,c); long max = max(a,b,c); long min = min(a,b,c); (max - min).writeln(); }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { auto abc = readln.chomp.split(" ").map!(to!int); writeln( abc.count!"a==5" == 2 && abc.count!"a==7" == 1 ? "YES" : "NO" ); }
D
/+ dub.sdl: name "C" dependency "dunkelheit" version="1.0.0" +/ import std.stdio, std.algorithm, std.range, std.conv, std.math; // import dkh.foundation, dkh.scanner; immutable int MD = 3*(10^^5); immutable int S = MD/2; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int n; sc.read(n); int[] limo = new int[MD+1], rimo = new int[MD+1]; foreach (i; 0..n+1) { int l, r; if (i == 0) l = r = 0; else sc.read(l, r); l += S; r += S; limo[0]++; limo[l]--; rimo[r]++; rimo[MD]--; } foreach (i; 0..MD) { limo[i+1] += limo[i]; rimo[i+1] += rimo[i]; } long sm = 0; foreach (i; 0..MD) { int d = min(limo[i], rimo[i]); sm += 2*d; } writeln(sm); return 0; } /* IMPORT /home/yosupo/.dub/packages/dunkelheit-1.0.0/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(); } } /* IMPORT /home/yosupo/.dub/packages/dunkelheit-1.0.0/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/.dub/packages/dunkelheit-1.0.0/dunkelheit/source/dkh/foundation.d */ // module dkh.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } /* This source code generated by dunkelheit and include dunkelheit's source code. dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit) dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt) */
D
import std.stdio, std.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 N = RD; auto c = RD!string; auto cnt = new long[](N+1); foreach (i; 0..N) { cnt[i+1] = cnt[i]; if (c[i] == 'R') ++cnt[i+1]; } long ans = long.max; foreach (i; 0..N+1) { auto l = i - cnt[i]; auto r = max(0, cnt[$-1] - cnt[i] - l); ans.chmin(l+r); debug writeln("i:", i, " ans:", l+r); } writeln(ans); stdout.flush; debug readln; }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N; string S; scan(N); scan(S); writeln(S[0 .. N / 2] == S[N / 2 .. $] ? "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
import std.stdio, std.string, std.conv, std.algorithm, std.range; void main(){ int m, f, r; string rs; while(true){ scanf("%d %d %d", &m, &f, &r); if (m == -1 && f == -1 && r == -1) break; if (m == -1 || f == -1){ rs ~= "F"; } else if (m+f>=80){ rs ~= "A"; } else if (m+f>=65){ rs ~= "B"; } else if (m+f>=50){ rs ~= "C"; } else if (m+f>=30){ if (r >= 50){ rs ~= "C"; }else{ rs ~= "D"; } } else { rs ~= "F"; } rs ~= "\r\n"; } writeln(rs.chomp); }
D
import core.bitop; import core.checkedint; import core.simd; import core.stdc.stdio; import core.stdc.stdlib; import core.stdc.string; import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.bitmanip; import std.complex; import std.container; import std.conv; import std.datetime; import std.format; import std.functional; import std.math; import std.meta; import std.numeric; import std.random; import std.range; import std.regex; //import std.stdio; import std.string; import std.typecons; import std.variant; __gshared: /+ bool read(T...)(T ptrs) if (ptrs.length > 0) { return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length; } +/ T[ ] allocate(T)(size_t n) { return (cast(T*)malloc(n * T.sizeof))[0 .. n]; } auto pairwise(R)(R range) if (isForwardRange!R) { return lockstep(range, dropOne(range)); } struct Dsu(int n) { int[n] p; void init() { iota(n).copy(p[ ]); } int get(int x) { return x == p[x] ? x : (p[x] = get(p[x])); } void merge(int x, int y) { p[get(x)] = get(y); } } int n; Dsu!10_000 dsu; void main() { scanf("%d", &n); dsu.init(); foreach (i; 0 .. n) { int x; scanf("%d", &x); dsu.merge(i, x - 1); } int result = 0; foreach (i; 0 .. n) if (i == dsu.get(i)) result++; printf("%d\n", result); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[10^^5*2+2] LR, DU; void main() { auto hwn = readln.split.to!(int[]); auto H = hwn[0]; auto W = hwn[1]; auto N = hwn[2]; auto rc = readln.split.to!(int[]); auto SR = rc[0]; auto SC = rc[1]; auto S = readln.chomp.to!(char[]); auto T = readln.chomp.to!(char[]); int a, b, c, d; a = 0, b = SC, c = SC, d = W+1; foreach (i; 0..N) { if (S[i] == 'L') { ++a; } else if (S[i] == 'R') { --d; } if (a == c || b == d || a+1 == d) { writeln("NO"); return; } if (T[i] == 'L') { if (d <= W) { ++d; } else if (b > 0) { --b; } } else if (T[i] == 'R') { if (a > 0) { --a; } else if (c <= W) { ++c; } } } a = 0, b = SR, c = SR, d = H+1; foreach (i; 0..N) { if (S[i] == 'U') { ++a; } else if (S[i] == 'D') { --d; } if (a == c || b == d || a+1 == d) { writeln("NO"); return; } if (T[i] == 'U') { if (d <= W) { ++d; } else if (b > 0) { --b; } } else if (T[i] == 'D') { if (a > 0) { --a; } else if (c <= W) { ++c; } } } writeln("YES"); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { int[] buf = readln.chomp.split.to!(int[]); int a = buf[0], b = buf[1]; if (a + b == 15) { writeln("+"); } else if (a * b == 15) { writeln("*"); } else { writeln("x"); } }
D
void main() { problem(); } void problem() { auto X = scan!long; long solve() { long answer; auto num500 = X / 500; auto num5 = (X - num500 * 500) / 5; return num500 * 1000 + num5 * 5; } solve().writeln; } // ---------------------------------------------- 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); } 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, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a, b; char op; scan(a, op, b); if (op == '+') { writeln(a+b); } else { writeln(a-b); } } 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.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!int; auto l = new long[](n+1); l[0] = 2; l[1] = 1; foreach (i; 2..n+1) l[i] = l[i-1]+l[i-2]; writeln(l[n]); }
D
import std.stdio; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.csv; import std.regex; import std.math; import core.time; import std.ascii; import std.digest.sha; import std.outbuffer; void main() { int n = readln.chomp.to!int; writeln = (n + 2) / 2; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto q = RD!int; auto ans = new long[](q); foreach (i; 0..q) { auto n = RD!int; if (n == 2) { ans[i] = 2; } else ans[i] = n % 2 == 0 ? 0 : 1; } foreach (e; ans) writeln(e); stdout.flush(); debug readln(); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; immutable int M = 30; long x, y; int cnt = 0; int ask(long c, long d) { debug { cnt += 1; if ((x^c) > (y^d)) return 1; else if ((x^c) == (y^d)) return 0; else return -1; } writeln("? ", c, " ", d); stdout.flush; return readln.chomp.to!int; } void answer(long a, long b) { writeln("! ", a, " ", b); stdout.flush; } void main() { debug { auto s = readln.split.map!(to!long); x = s[0]; y = s[1]; } int f = ask(0, 0); int ff = f; if (f == 0) { long a = 0; foreach_reverse (i; 0..M) { long c = (1L << (i + 1)) - 1; long d = (1L << i) - 1; c += a; d += a; f = ask(c, d); if (f == -1) { a += 1L << i; } } answer(a, a); return; } bool a_large = f == 1; long a = 0; long b = 0; auto same = new bool[](M); foreach_reverse (i; 0..M) { long c = 1L << i; f = ask(a+c, b+c); if (a_large && f == -1) { a += c; f = ask(a, b); a_large = f == 1; } else if (!a_large && f == 1) { b += c; f = ask(a, b); a_large = f == 1; } else { same[i] = true; } } foreach (i; 0..M) { if (!same[i]) { continue; } long c = 1L << i; f = ask(a+c, b); if (f == -1) { a += c; b += c; } } answer(a, b); debug{cnt.writeln;} }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto H = RD; auto W = RD; auto C = new string[](H); foreach (i; 0..H) { C[i] = RD!string; } foreach (i; 0..H) { writeln(C[i]); writeln(C[i]); } stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { while (true) { auto a = readln.split.map!(to!int); if (a[0] == 0 && a[1] == 0) break; if (a[0] < a[1]) writeln(a[0], " ", a[1]); else writeln(a[1], " ", a[0]); } }
D
import std.stdio; immutable mod = 4294967311L; long[] inv; void main(){ long x; int n, y, op; scanf("%d", &n); inv = new long[1_000_001]; inv[1] = 1; foreach(_; 0..n){ scanf("%d%d", &op, &y); if(op >= 3 && y < 0) x = -x, y = -y; if(op == 1) x += y; else if(op == 2) x -= y; else if(op == 3) x *= y; else if(op == 4) x = mul(x, inv_(y)); x %= mod; } if(x < 0) x += mod; if(x > int.max) x -= mod; writeln(x); } long inv_(int x){ return inv[x] ? inv[x] : (inv[x]=mul(inv_(mod%x), mod-mod/x)); } long mul(long x, long y){ return ( ((x*(y>>16)%mod)<<16) + (x*(y&0xffff)) ) % mod; }
D
import std.stdio, std.string, std.conv; void main() { foreach (i; 1 .. 10001) { int x = readln.chomp.to!int; if (x == 0) break; writeln("Case ", i, ": ", x); } }
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; T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } alias sread = () => readln.chomp(); void main() { long A = lread(); long B = lread(); long C = lread(); long X = lread(); long i; foreach (a; 0 .. A + 1) foreach (b; 0 .. B + 1) foreach (c; 0 .. C + 1) if ((a * 500 + b * 100 + c * 50) == X) { i++; } i.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 n; readV(n); writeln(n < 1000 ? "ABC" : "ABD"); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); long[2] cnt; foreach (c; S) cnt[c - 'A']++; writeln((cnt[0] * cnt[1] != 0) ? "Yes" : "No"); }
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, R; scan(N, R); auto ans = N >= 10 ? R : R + 100 * (10 - N); writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nab = readln.split.to!(long[]); auto N = nab[0]; auto A = nab[1]; auto B = nab[2]; if ((B-A)%2 == 0) { writeln((B-A)/2); } else { writeln(min(A + (B-A)/2, N-B+1 + (B-A-1)/2)); } }
D
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range; pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); } alias reads = Reads!int; pragma(inline, true) void scan(Args...)(ref Args args) { string[] ss = readln.split; foreach (i, ref arg ; args) arg = ss[i].parse!int; } void main() { int a,b,c; scan(a,b,c); writeln(max(0, c - (a - b))); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); int[] a; for(int x=6; x<=n; x*=6) a~=x; for(int x=9; x<=n; x*=9) a~=x; a~=1; auto dp=new int[](n+1); const int inf=1_000_000_000; fill(dp, inf); dp[0]=0; foreach(i; 0..n)foreach(e; a){ if(i+e<=n) dp[i+e]=min(dp[i+e], dp[i]+1); } writeln(dp[n]); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x) e=l[i].to!(typeof(e)); }
D
import std.stdio, 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"; T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } 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 A = RD; auto B = RD; auto C = RD; writeln(min(B / A, C)); stdout.flush(); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.datetime; void main() { auto S = readln.chomp; auto s = readln.split.map!(to!int); auto X = s[0]; auto Y = s[1]; int tmp = 0; bool isX = true; int[] yoko; int[] tate; foreach (c; S) { if (c == 'F') { tmp += 1; } else if (isX) { yoko ~= tmp; isX ^= 1; tmp = 0; } else { tate ~= tmp; isX ^= 1; tmp = 0; } } if (isX) yoko ~= tmp; else tate ~= tmp; auto dpX = new bool[int][](yoko.length+1); dpX[0][0] = true; foreach (i; 0..yoko.length) { foreach (k; dpX[i].keys) { dpX[i+1][k + yoko[i]] = true; if (i > 0) dpX[i+1][k - yoko[i]] = true;; } } auto dpY = new bool[int][](tate.length+1); dpY[0][0] = true; foreach (i; 0..tate.length) { foreach (k; dpY[i].keys) { dpY[i+1][k + tate[i]] = true; dpY[i+1][k - tate[i]] = true; } } if (X in dpX[yoko.length] && Y in dpY[tate.length]) { writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() { auto tokens = my_readln().split(); auto N = tokens[0].to!ulong; auto M = tokens[1].to!ulong; ulong[][2][] v; v.length = N; foreach (i; 0..M) { auto tokens2 = my_readln().split(); auto x = tokens2[0].to!ulong - 1; auto y = tokens2[1].to!ulong - 1; v[y][0] ~= x; v[x][1] ~= y; } ulong[] memo; memo.length = N; ulong search(ulong pos) { ulong r; foreach (e; v[pos][1]) { r = max(r, memo[e] == 0 ? search(e) + 1 : memo[e] + 1); } stderr.writeln("a", pos, " ", r); memo[pos] = r; return r; } ulong ans; foreach (i; 0..N) { if (v[i][0].length != 0) continue; ans = max(ans, search(i)); stderr.writeln("b", i, " ", ans); } writeln(ans); stdout.flush(); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { int d = readint; string[] ss = ["Christmas"]; for (int i = 0; i < 25 - d; i++) ss ~= "Eve"; writeln(ss.join(" ")); }
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)); } double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; } 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 bool[](t); foreach (ti; 0..t) { auto s = RD!string; auto ss = RD!string; if (s.length < ss.length) continue; if ((ss.length - s.length) % 2) s.popFront; int i, j; while (i < s.length && j < ss.length) { if (s[i] == ss[j]) { ++i; ++j; } else { i += 2; } } debug writeln("i:", i, " j:", j); if (j == ss.length) ans[ti] = true; } foreach (e; ans) { writeln(e ? "YES" : "NO"); } 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; } 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; writeln(N % 2 == 0 ? N : N * 2); stdout.flush(); debug readln(); }
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 x = readln.chomp.to!int; writeln(x ^^ 3); }
D
import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int n; int[] a; int dfs(int depth, bool gu) { if (depth == n) { return gu; } int cnt = 0; for (int i = -1; i <= 1; ++i) { cnt += dfs(depth + 1, gu || ((a[depth] + i) % 2 == 0)); } return cnt; } void main() { n = readln.chomp.to!int; a = readln.chomp.split.map!(to!int).array; writeln = dfs(0, false); }
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 S = to!string(tokens[0]); ulong ans, cnt_b; foreach (i, e; S) { if (e == 'B') ++cnt_b; else ans += cnt_b; } writeln(ans); stdout.flush(); /*}catch (Throwable e) { writeln(e.toString()); } readln();*/ }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric; void main(){ auto abc=readln.split.map!(to!int).array; auto gcd=gcd(abc[0],abc[1]); writeln(abc[2]%gcd==0?"YES":"NO"); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto T = readln.chomp.to!int; while (T--) { auto s = readln.split.map!(to!long); auto a = s[0]; auto b = s[1]; auto c = s[2]; auto r = s[3]; if (a > b) swap(a, b); auto u = c - r; auto v = c + r; if (u >= b || v <= a) { writeln(b - a); } else { u = max(u, a); v = min(v, b); writeln(b - a - (v - u)); } } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto q = RD!int; auto ans = new long[](q); foreach (i; 0..q) { auto c = RD; auto m = RD; auto x = RD; auto a = c + m + x; ans[i] = min(min(c, m), a/3); } foreach (e; ans) { writeln(e); } stdout.flush(); debug readln(); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); long K = lread(); long N = S.length; long[] len; long i; while (i < N) { long l; char prev = S[i]; while (i + l < N && S[i + l] == prev) l++; len ~= l; i += l; } if (len.length == 1) { writeln(len[0] * K / 2); return; } long ans = len.map!"a/2"().sum() * K; if (S[0] == S[$ - 1]) { ans -= (len[0] / 2) * (K - 1); ans -= (len[$ - 1] / 2) * (K - 1); ans += ((len[0] + len[$ - 1]) / 2) * (K - 1); } writeln(ans); }
D
import std.stdio; import std.string; import std.array; // split import std.conv; // to void main() { string s = chomp(readln()); for(int i=0; i<s.length; ++i){ if(i%2 == 0){ write(s[i]); } } }
D
void main() { problem(); } void problem() { auto N = scan!int; auto X = scan!int; auto T = scan!int; int solve() { auto t = N % X == 0 ? N / X : 1 + N / X; return t * T; } 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
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a=new int[](n); foreach(i; 0..n) rd(a[i]); auto dp=new int[](n); dp[0]=1; bool up=true; foreach(i; 1..n){ if(up){ if(a[i-1]<a[i]) dp[i]=dp[i-1]+1; else if(a[i-1]==a[i]) dp[i]=dp[i-1]; else dp[i]=2, up=false; }else{ if(a[i-1]>a[i]) dp[i]=dp[i-1]+1; else if(a[i-1]==a[i]) dp[i]=dp[i-1]; else dp[i]=2, up=true; } } writeln(reduce!(max)(dp)); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { long N, M; scan(N, M); auto A = new long[](N); auto B = new long[](N); auto C = new long[](M); auto D = new long[](M); foreach (i; 0 .. N) { scan(A[i], B[i]); } foreach (i; 0 .. M) { scan(C[i], D[i]); } alias T = Tuple!(long, long); foreach (i; 0 .. N) { auto m = T(long.max, 0); foreach (j; 0 .. M) { m = m.min(T(abs(A[i] - C[j]) + abs(B[i] - D[j]), j + 1)); } writeln(m[1]); } }
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.count('7'); if (n) { writeln("Yes"); } else { writeln("No"); } }
D
import core.bitop; import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int n, k; void main() { int n = readln.chomp.to!int; int k = readln.chomp.to!int; int ans = int.max; foreach (i; 0 .. 1 << n) { int v = 1; foreach (j; 0 .. n) { if ((i >> j) & 1) { v *= 2; } else { v += k; } } ans = min(ans, v); } ans.writeln; }
D
import std.stdio; import std.string; import std.conv; void main() { string s = readln.chomp; ulong k = readln.chomp.to!ulong; if (s[0] != '1') { s[0].writeln; return; } foreach(i, c; s) { if (c != '1') { if (i < k) { s[i].writeln; return; } } } 1.writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); long cnt; char prev = '@'; foreach (i; 0 .. S.length) if (prev != S[i]) { prev = S[i]; cnt++; } writeln(cnt - 1); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.container; import std.datetime; void main() { while (1) { auto n = readln.chomp.to!int; if (!n) break; auto m = new int[][](n); foreach (i; 0..n) { auto x = readln.chomp.split.map!(to!int).array; if (x[0] == 0) continue; m[i] ~= x[1..$]; } auto y = readln.chomp.split.map!(to!int).array[1..$]; int[] res; foreach (i; 0..n) { int cnt; foreach (e; y) { foreach (me; m[i]) { if (me == e) cnt++; } } if (cnt == y.length) { res ~= i + 1; } } if (res.length == 1) { res[0].writeln; } else { writeln(-1); } } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); writeln(s.predSwitch("A", "T", "T", "A", "C", "G", "G", "C")); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.numeric; void main() { int[3][3] c; foreach (i; 0..3) { c[i] = readln.chomp.split.to!(int[]); } auto h1 = c[0][0] - c[0][1]; auto h2 = c[0][0] - c[0][2]; auto h3 = c[0][1] - c[0][2]; auto v1 = c[0][0] - c[1][0]; auto v2 = c[0][0] - c[2][0]; auto v3 = c[1][0] - c[2][0]; bool f; foreach (i; 1..3) { if (h1 != c[i][0] - c[i][1]) { f = true; } if (h2 != c[i][0] - c[i][2]) { f = true; } if (h3 != c[i][1] - c[i][2]) { f = true; } if (v1 != c[0][i] - c[1][i]) { f = true; } if (v2 != c[0][i] - c[2][i]) { f = true; } if (v3 != c[1][i] - c[2][i]) { f = true; } } if (f) { writeln("No"); } else { writeln("Yes"); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N = lread(); writeln(N * (N - 1) / 2); // iota(N - 1).map!"a+1"().sum().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); } import std.bigint, std.functional; void main() { auto I = readln.split.to!(long[]); auto A = cast(real)(I[0]); auto B = cast(real)(I[1]); auto C = cast(real)(I[2]); bool solve() { return A + B + 2f*(A.sqrt*B.sqrt) < C; } writeln(solve() ? "Yes" : "No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto a = readln.chomp; auto b = readln.chomp; writeln( a.length > b.length ? "GREATER" : a.length < b.length ? "LESS" : a > b ? "GREATER" : a < b ? "LESS" : "EQUAL" ); }
D
import std.stdio, std.algorithm, std.conv, std.string, std.array; void main() { const N = readln.chomp.to!long; auto ans = long.max; for (long i = 1; i*i <= N; ++i) { if (N%i == 0) ans = ans.min(i+N/i-2); } ans.writeln; }
D
import std.conv, std.stdio, std.string, std.array, std.range, std.algorithm; string s = "CODEFORCES"; void main() { char[] t = readln.strip.dup; int len; foreach (i, e; s) { if (e == t[i]) { ++len; } else { break; } } if (len == 10) { writeln("YES"); return; } len = 0; int j; foreach_reverse (i, e; s) { if (e == t[$ - j - 1]) { ++len; } else { break; } ++j; } if (len == 10) { writeln("YES"); return; } char[] begin, end; foreach (i, e; s) { if (e == t[i]) { begin ~= t[i]; } else { break; } } j = 0; foreach_reverse (i, e; s) { if (e == t[$ - j - 1]) { end ~= t[$ - j - 1]; } else { break; } ++j; } if ((begin ~ end).length >= 10) { writeln("YES"); return; } writeln("NO"); }
D
import std.stdio; import std.algorithm; void main() { int w, h, n; scanf("%d\n%d\n%d", &w, &h, &n); write((n + max(w,h) - 1) / max(w, h)); }
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 MOD = 1_000_000_007; ulong INF = 1_000_000_000_000; ulong MIDDLE = 100_000; alias Pair = Tuple!(long, "flag", long, "num"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { auto x = lread(); long current, t = 1; while(current < x) current += t++; (t - 1).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 st = readln.split.to!(string[]); void solve() { writeln(st[1] ~ st[0]); } solve(); }
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); } long[] t; bool[] b; void main() { long N = lread; t = new long[](N + 1); b = new bool[](N + 1); foreach (i; 0 .. N) t[i + 1] = lread(); solve(1).max(-1).writeln(); } long solve(long n) { if (b[n]) return long.min; if (n == 2) return 0; b[n] = true; return solve(t[n]) + 1; }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto data = readln.split; auto N = data[0].to!int, T = data[1].to!int; int cost = 10_000; foreach (i; 0 .. N) { data = readln.split; auto c = data[0].to!int, t = data[1].to!int; if (t <= T && c < cost) { cost = c; } } if (cost == 10_000) writeln("TLE"); else writeln(cost); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a, b, h; scan(a); scan(b); scan(h); writeln((a + b) * h / 2); } 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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long A, B, C, X, Y; scan(A, B, C, X, Y); long a = max(X, Y) * 2 * C; long b = X * 2 * C + max(0, Y - X) * B; long c = Y * 2 * C + max(0, X - Y) * A; long d = X * A + Y * B; // writeln(a, b, c, d); writeln(min(a, b, c, d)); }
D
import std.stdio; import std.algorithm; import std.conv; import std.numeric; import std.math; import std.string; void main() { auto n = to!int(chomp(readln())); long[] t; foreach (i; 0..n) { t ~= to!long(chomp(readln())); } long lcm(long a, long b) { if (a < b) { auto tmp = a; a = b; b = tmp; } auto r = a % b; long x = a, y = b; while (r != 0) { x = y; y = r; r = x % y; } return b / y * a; } auto result = t[0]; foreach (e; t[1..$]) { result = lcm(result, e); } writeln(result); stdout.flush(); }
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 n; readV(n); writeln(n*800-(n/15)*200); }
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } T[] readToArray(T)() { return readln.split.to!(T[]); } void readInto(T...)(ref T ts) { auto ss = readln.split; foreach(ref t; ts) { t = ss.front.to!(typeof(t)); ss.popFront; } } // 冪乗をmod取りつつ計算 @nogc @safe pure ulong modPow(ulong a, ulong n, ulong m) { ulong r = 1; while (n > 0) { if(n % 2 != 0) r = r * a % m; a = a * a % m; n /= 2; } return r; } // フェルマーの小定理から乗法逆元を計算 // 定理の要請により法は素数 @nogc @safe pure ulong modInv(ulong a, ulong m) { return modPow(a, m-2, m); } // mod取りつつ順列を計算 @nogc @safe pure ulong modPerm(ulong n, ulong k, ulong m) { if (n < k) return 0; ulong r = 1; for (ulong i = n-k+1; i <= n; i++) { r *= i; r %= m; } return r; } // mod取りつつ順列を計算 @nogc @safe pure ulong modFact(ulong n, ulong m) { return modPerm(n, n, m); } // mod取りつつ組み合わせを計算 // modInvを使っているので法は素数 @nogc @safe pure ulong modComb(ulong n, ulong r, ulong m) { return modPerm(n, r, m)*modInv(modFact(r, m), m) % m; } immutable ulong MOD = 1000000007; void main() { ulong n, d; readInto(n, d); writeln((n+2*d)/(2*d+1)); }
D
import std.algorithm, std.string, std.range, std.stdio, std.conv; void main() { int N = readln.chomp.to!int; string S = readln.chomp; char l = '(', r = ')'; int ls, rs; int als; foreach (c; S) { if (c == l) { ls++; } else { rs++; } if (ls - rs < 0) { als++; ls = 0; rs = 0; } } als.iota.each!(_ => write(l)); write(S); (ls-rs).iota.each!(_ => write(r)); writeln; }
D
void main(){ import std.stdio; auto x = readln.dup; x[3] = '8'; writeln(x); }
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[]); char[] S; for (size_t i; i < s.length; ++i) { if (i < s.length-1 && s[i] == 'B' && s[i+1] == 'C') { S ~= 'X'; ++i; } else { S ~= s[i]; } } long[] C; C.length = S.length; long cnt; foreach (i, c; S) { if (c == 'A') { ++cnt; } else if (c != 'X') { cnt = 0; } C[i] = cnt; } long r; foreach (i, c; S) if (c == 'X') r += C[i]; writeln(r); }
D
void main() { string s = readln.chomp; char[] acgt = ['A', 'C', 'G', 'T']; int cnt, ans; foreach (x; s) { if (acgt.canFind(x)) { ++cnt; ans = max(ans, cnt); } else { ans = max(ans, cnt); cnt = 0; } } ans.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], k = tmp[1]; writeln((n + 1) / 2 >= k ? "YES" : "NO"); } 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; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int a, b, c; long k; scan(a, b, c, k); writeln(k & 1 ? b - a : a - b); } 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.array; import std.conv; import std.string; import std.algorithm; void main() { string s; while( (s=readln.strip) != "0 0") { auto n = map!(to!int)(s.strip.split); int h = n[0], w = n[1]; foreach(i;0..h) { foreach(j;0..w) { write((i+j)%2==0 ? '#':'.'); } writeln(); } writeln(); } }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; void main() { auto n = readln.chomp.to!int; int[][] ab = new int[][](10,10); for(int i=1; i<=n; i++) { int a = i; while(a>=10) a/=10; int b = i%10; ab[a][b]++; } long result = 0; for(int i=0; i<10; i++) for(int j=0; j<10; j++) { result += ab[i][j]*ab[j][i]; } writeln(result); }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } void main() { int N = readln.chomp.to!int; string s = readln.chomp; string t = readln.chomp; (N+1).iota.countUntil!( i => s[i..$] == t[0..$-i] ).pipe!(a => a+N).writeln; } // ---------------------------------------------- // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D