code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio; import std.conv; import std.array; void main() { int N = readln.split[0].to!int; int[] V = readln.split.to!(int[]); int[] C = readln.split.to!(int[]); int ans = 0; foreach (i; 0..N){ if (V[i] > C[i]) ans += V[i] - C[i]; } writeln(ans); }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; string my_readln() { return chomp(readln()); } long mod = pow(10, 9) + 7; long moda(long x, long y) { return (x + y) % mod; } long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; } long modm(long x, long y) { return (x * y) % mod; } void main() { auto tokens = my_readln.split; auto D = tokens[0].to!long; auto G = tokens[1].to!long; ulong[] p, c; foreach (i; 0..D) { auto tokens2 = my_readln.split; p ~= tokens2[0].to!ulong; c ~= tokens2[1].to!ulong; } long f(ulong[] used, long score, long cnt) { if (score <= 0) return cnt; long r = long.max; foreach (i, e; used) { if (e == 1) continue; auto x = score / ((i + 1) * 100) + (score % ((i + 1) * 100) == 0 ? 0 : 1); if (x <= p[i]) { r = min(r, cnt + x); } else { auto nUsed = used.dup; nUsed[i] = 1; r = min(r, f(nUsed, score - ((i + 1) * 100 * p[i] + c[i]), cnt + p[i])); } } return r; } writeln(f(new ulong[](D), G, 0)); stdout.flush(); }
D
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range; T Read(T)() { return readln.chomp.to!(T); } T[] Reads(T)() { return readln.split.to!(T[]); } alias read = Read!(int); alias reads = Reads!(int); void main() { int d = read(); if (d == 25) writeln("Christmas"); else if (d == 24) writeln("Christmas Eve"); else if (d == 23) writeln("Christmas Eve Eve"); else if (d == 22) writeln("Christmas Eve Eve Eve"); }
D
import std.stdio, std.array, std.conv; void main() { while (true) { string[] input = split(readln()); int H = to!int(input[0]); int W = to!int(input[1]); if (H == 0 && W == 0) return; for (int i = 0; i < H; ++i) { for (int j= 0; j < W; ++j) { write(is_side(i, j, H, W) ? "#" : "."); } writeln(""); } writeln(""); } } bool is_side(int y, int x, int H, int W) { return (y == 0 || x == 0 || y == (H - 1) || x == (W - 1)); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto n = lread(); auto h = aryread(); long cnt; foreach (i; 0 .. n - 1) { if (h[i] < h[i + 1]) { h[i + 1] -= 1; } // writeln(h); } foreach (i; 0 .. n - 1) { if (h[i] > h[i + 1]) { writeln("No"); return; } } writeln("Yes"); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
void main() { long n = readln.chomp.to!long; writeln(2 * n / gcd(2, n)); } 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.uni;
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); long ac = N - M; writeln((2 ^^ M) * (ac * 100 + 1900 * M)); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto nk = readln.split.to!(int[]); writeln(nk[0] % nk[1] ? 1 : 0); }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test SAT ---+/ /+---test SUN ---+/ /+---test TUE ---+/ void main(string[] args) { const S = readln.chomp; auto days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; auto x = days.countUntil!(x => x == S); (7 - x).writeln; }
D
import std.conv; import std.stdio; import std.string; void main() { auto s = readln.strip; writeln( solve( s ) ); } auto solve( in string s ) { auto n = s.to!int; auto sn = 0; foreach( c; s ) { sn += [ c ].to!int; } return ( n % sn == 0 ) ? "Yes" : "No"; } unittest { assert( solve( "12" ) == "Yes" ); assert( solve( "101" ) == "No" ); assert( solve( "999999999" ) == "Yes" ); }
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; } /* 部分文字列 文字列の一致 sのi文字目までとtのj文字目まででやった場合の答えをxs[i][j]とする s[i]とt[j]が一致する場合、 xs[i][j] = xs[i - 1][j - 1] + 1 そうでない場合、 xs[i][j] = max(xs[i - 1][j], xs[i][j - 1])) ただし添字が負になる項は 0 求めるものはxs[n][m]である 上記を求めたあと、文字列は以下のようにして作る string solve(int i, int j){ if(s[i] == t[j]){ if(i == 0 || j == 0) return "" ~ s[i]; else return solve(i - 1, j - 1) ~ s[i]; } else{ if(i == 0 && j == 0) return ""; if(i == 0) return solve(i, j - 1); if(j == 0) return solve(i - 1, j); if(xs[i - 1][j] > xs[i][j - 1]) return solve(i - 1, j); else return solve(i, j - 1); } } // メモ化再帰のほうがよかったかも */ void main(){ string s = readln.chomp; string t = readln.chomp; long n = s.length; long m = t.length; int[][] xs; foreach(i; 0 .. n){ xs ~= new int[](m); foreach(j; 0 .. m){ debug writeln("i:", i, " j: ", j, " xs:", xs); if(s[i] == t[j]){ if(i == 0 || j == 0) xs[i][j] = 1; else xs[i][j] = xs[i - 1][j - 1] + 1; } else{ if(i == 0 && j == 0) xs[i][j] = 0; else if(i == 0) xs[i][j] = xs[i][j - 1]; else if(j == 0) xs[i][j] = xs[i - 1][j]; else xs[i][j] = max(xs[i - 1][j], xs[i][j - 1]); } } } string solve(long i, long j){ if(s[i] == t[j]){ if(i == 0 || j == 0) return "" ~ s[i]; else return solve(i - 1, j - 1) ~ s[i]; } else{ if(i == 0 && j == 0) return ""; if(i == 0) return solve(i, j - 1); if(j == 0) return solve(i - 1, j); if(xs[i - 1][j] > xs[i][j - 1]) return solve(i - 1, j); else return solve(i, j - 1); } } solve(n - 1, m - 1).writeln; }
D
// Vicfred // https://atcoder.jp/contests/abc162/tasks/abc162_c // math import std.conv; import std.stdio; import std.string; long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a%b); } long gcd(long a, long b, long c) { return gcd(a,gcd(b,c)); } void main() { int K = readln.chomp.to!int; long sum = 0; for(int i = 1; i <= K; i++) for(int j = 1; j <= K; j++) for(int k = 1; k <= K; k++) sum += gcd(i,j,k); sum.writeln; }
D
import std.stdio, std.string, std.algorithm, std.array; void main() { int t; scanf("%d", &t); getchar(); foreach(i; 0..t){ long a,b,c,m; scanf("%lld %lld %lld %lld", &a, &b, &c, &m); auto top_max = a + b + c - 3; auto max_v = max(a,b,c); auto min_v = min(a,b,c); auto mid_v = a + b + c - max_v - min_v; if ((m > top_max) || (max_v > (min_v + mid_v + 1 + m))) writeln("NO"); else writeln("YES"); } }
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) { const int n = r.next!uint (); const int m = r.next!uint (); writeln ((n % m) == 0 ? "YES" : "NO"); } }
D
import std.stdio; import std.string; void main() { auto n = readln; auto s = readln.strip; writeln( solve( s ) ); } int solve( in string s ) { auto lc = new int[ s.length ]; lc[ 0 ] = 0; foreach( i; 1 .. s.length ) { lc[ i ] = lc[ i - 1 ] + ( s[ i - 1 ] == 'E' ? 0 : 1 ); } auto rc = new int[ s.length ]; rc[ $-1 ] = 0; foreach_reverse( i; 0 .. s.length-1 ) { rc[ i ] = rc[ i + 1 ] + ( s[ i + 1 ] == 'W' ? 0 : 1 ); } auto result = lc[ 0 ] + rc[ 0 ]; foreach( i; 1 .. s.length ) { auto lrc = lc[ i ] + rc[ i ]; if( lrc < result ) result = lrc; } return result; } unittest { assert( solve( "WEEWW" ) == 1 ); assert( solve( "WEWEWEEEWWWE" ) == 4 ); assert( solve( "WWWWWEEE" ) == 3 ); }
D
import std.stdio, std.conv, std.array, std.string; import std.algorithm; import std.container; import std.range; import core.stdc.stdlib; import std.math; void main() { bool[int] kuku_answers; foreach(i; 1..10) { foreach(o; 1..10) { kuku_answers[i*o] = true; } } auto N = readln.chomp.to!int; writeln(N in kuku_answers ? "Yes" : "No"); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial; void main(){ auto abc=readln.split.array; if(abc[0][$-1]==abc[1][0] && abc[1][$-1]==abc[2][0])writeln("YES"); else writeln("NO"); }
D
void main(){ int[] n = _scanln(); (n[0]-n[1]+1).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std; 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(){ long a,b,c,d; scan(a,b,c,d); while(true){ c-=b; if(c<=0){ "Yes".writeln; break; } a-=d; if(a<=0){ "No".writeln; break; } } }
D
// import chie template :) {{{ import std; // }}} // nep.scanner {{{ 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; } } // }}} void main() { auto cin = new Scanner; string s; cin.scan(s); writeln(canFind(s, '7') ? "Yes" : "No"); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; import std.regex; void main() { auto N = readln.chomp.to!int, K = readln.chomp.to!int; int res = 1; foreach(i; 0..N) res = (res * 2 < res + K ? res * 2 : res + K); writeln(res); }
D
import std.stdio; import std.string; import std.conv; void main() { string s = readln.chomp; ulong k = readln.chomp.to!ulong; foreach(i, c; s) { if (c != '1') { if (i < k) { s[i].writeln; return; } } } 1.writeln; }
D
import std.conv; import std.stdio; import std.string; void main() { auto s = readln.strip; writeln( solve( s ) ); } auto solve( in string s ) { auto r = 0; foreach( c; s ) { if( c == '+' ) r++; else r--; } return r; } unittest { assert( solve( "+-++" ) == 2 ); assert( solve( "-+--" ) == -2 ); assert( solve( "----" ) == -4 ); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; import std.regex; void main() { auto ip = readln.split.to!(int[]), X = ip[0], Y = ip[1], Z = ip[2]; auto a = X - Z, b = Z + Y; writeln(a / b); }
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); auto d = max(10 * a + b + c, a + 10 * b + c, a + b + 10 * c); d.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() { dchar[] n; readV(n); foreach (ref ni; n) if (ni == '1') ni = '9'; else if (ni == '9') ni = '1'; writeln(n); }
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(); auto prev = ""; long ans; long i; while (i < S.length) { long j = 1; while (i + j < S.length && S[i .. i + j] == prev) j++; if (i + j != S.length || S[i .. i + j] != prev) ans++; prev = S[i .. i + j]; i += j; // writeln(prev, i); } writeln(ans); }
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 size = readln.chomp.to!int; auto lucky = cast(byte[])readln.chomp; lucky[] -= '0'; void solve() { int count; bool[byte] ava; foreach(a; lucky) ava[a] = true; foreach(x; ava.keys) foreach(y; ava.keys) foreach(z; ava.keys) { auto after = lucky.findSplitAfter([x]); if (!after[1].canFind(y)) continue; after = after[1].findSplitAfter([y]); if (!after[1].canFind(z)) continue; count++; } writeln(count); } solve(); }
D
import std.stdio; import std.stdio; import std.algorithm; import std.range; import std.functional; import std.conv; import std.string; import std.math; import core.bitop; ulong diff(ulong a, ulong b) { ulong res = 0; foreach (bit; 0 .. 64) { if ((a & (1UL << bit)) != (b & (1UL << bit))) { res++; } } return res; } ulong calc(ulong a) { if ((a & (a - 1)) == 0) { return a | (a - 1); } else { ulong highestBit = 1UL << bsr(a); return calc(a - highestBit) + calc(highestBit); } } void main() { // ulong res = 0; // foreach (i; 0 .. 1000) { // res += diff(i, i + 1); // write("f(", (i + 1).to!string.padLeft(' ', 10), ") = ", res.to!string(2).padLeft('0', 10)); // writeln("; ", calc(i + 1).to!string(2).padLeft('0', 10)); // } int tt = readln().chomp.to!int; outer: foreach (t; 0 .. tt) { ulong n = readln().chomp.to!ulong; // writeln(n.to!string(2).padLeft('0', 64)); writeln(calc(n)); } }
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 <= "2019/04/30" ? "Heisei" : "TBD"); }
D
import std.stdio; import std.conv; import std.array; import std.string; void main() { while (1) { string[] input = split(readln()); int h = to!(int)(input[0]); int w = to!(int)(input[1]); if (h == 0 && w == 0) break; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j != 0 && i != 0 && i != h - 1 && j != w - 1) { write("."); } else { write("#"); } } write("\n"); } write("\n"); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y", long, "z"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto h = lread(); auto w = lread(); auto n = lread(); if(h < w) swap(h, w); // 必ずh >= w writeln((n + h - 1) / h); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const R = readln.chomp.to!int; writeln(R < 1200 ? "ABC" : R < 2800 ? "ARC" : "AGC"); }
D
import std.stdio, std.string, std.conv; void main() { auto M = readln.chomp.to!int; writeln(48 - M); }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; auto go (string s, string c) { char [] stack = "**".dup; foreach (ref e; s.filter !(e => c.canFind (e))) { stack.assumeSafeAppend (); stack ~= e; if (stack[$ - 2..$] == c) { stack.popBackN (2); } } return stack.length.to !(int) - 2; } void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto s = readln.strip; writeln ((s.length - s.go ("()") - s.go ("[]")) / 2); } }
D
import std.stdio; import std.string; import std.conv : to; import std.algorithm : fill; import std.math : sqrt; void main() { int input; immutable limitList = 200000; bool[] listNumbers = new bool[](limitList); int[] listPrimeNumbers; listNumbers.fill(true); foreach (i; 2..limitList.to!double.sqrt.to!int) { if (listNumbers[i]) { for (int j = i*2; j < limitList; j += i) listNumbers[j] = false; } } foreach (i; 2..listNumbers.length) { if (listNumbers[i]) { listPrimeNumbers ~= i.to!int; } } while ((input = readln.chomp.to!int) != 0) { ulong sum = 0; foreach (i; 0..listPrimeNumbers.length) { if (i == input) break; sum += listPrimeNumbers[i]; } writeln(sum); } }
D
import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string; void main() { auto buf = readln.chomp.split; (buf[1] ~ buf[0]).writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; bool[10^^5+1] NS; void main() { auto nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; auto as = readln.split.to!(int[]); foreach (i; 0..K+1) { bool win; foreach (j; 0..N) if (i >= as[j] && !NS[i - as[j]]) { win = true; break; } NS[i] = win; } writeln(NS[K] ? "First" : "Second"); }
D
// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.datetime, std.bigint; int a, b; void main() { scan(a, b); if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) { writeln("Possible"); } else { writeln("Impossible"); } } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.string; import std.math; import std.conv; import std.algorithm; import std.bigint; void main(){ int d,m; int date = 2; auto ds = ["Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Monday"]; auto a = [31,29,31,30,31,30,31,31,30,31,30,31]; while(true){ date = 2; auto s = split(readln()); d = to!int(s[0]); m = to!int(s[1]); if(d == 0 && m == 0) break; for(int i=0;i<d-1;i++){ date += a[i]; } date += m-1; date = date % 7; writeln(ds[date]); } }
D
import std.stdio; import std.conv; import std.string; const int DATA = 200; int main() { int data = to!(int)(chomp(readln)); string[] result = new string[data]; for(int i=0; i<data; i++) { int a, b, c, tmp; // a:max string[] input = (chomp(readln)).split(" "); a = to!(int)(input[0]); b = to!(int)(input[1]); c = to!(int)(input[2]); if(a<b) { tmp = a; a = b; b = tmp; } if(a<c) { tmp = a; a = c; c = tmp; } if(a*a == b*b+c*c) result[i]="YES"; else result[i]="NO"; } for(int i=0; i<data; i++) writeln(result[i]); return 0; }
D
import std.stdio,std.conv,std.string,std.algorithm,std.array; void main(){ auto sn=readln().split(); auto sa=readln().split(); int n,a; n=to!int(sn[0]); a=to!int(sa[0]); if(n%500<=a) writeln("Yes"); else writeln("No"); }
D
import std.stdio, std.string, std.conv; void main() { int N = readln.chomp.to!int; while(N--) { auto i = readln.split; auto c = i[0].to!int, a = i[1].to!int, n = i[2].to!int; int ans; while(c && a && n) { ans++; c--; a--; n--; } while(c >= 2 && a) { ans++; c -= 2; a--; } while(c >= 3) { ans++; c -= 3; } ans.writeln; } }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { auto xs = readints; int[int] m; foreach (x; xs) m[x]++; foreach (k, v; m) { if (v == 1) writeln(k); } }
D
import core.bitop; import std.algorithm; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long a,b; scan(a,b); auto s = sread(); foreach (i, e; s) { if(i == b - 1) { write(toLower(e)); continue; } write(e); } writeln(); }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto S = readln.split[0]; auto cnt = 0; string[] answers = [ "" ]; while (cnt < S.length) { if ( S[cnt] == 'A' || S[cnt] == 'T' || S[cnt] == 'G' || S[cnt] == 'C') { answers[$-1] ~= S[cnt]; } else { answers ~= ""; } cnt++; } string ans; answers.each!(x => x.length > ans.length ? (ans = x) : ""); ans.length.writeln; }
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 N, K; scanln(N, K); if (N.ceil(2) >= K) { "YES".writeln; } else { "NO".writeln; } } // ---------------------------------------------- void times(alias fun)(long n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(long n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { // `(x+y-1)/y` will only work for positive numbers ... T t = x / y; if (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; import std.conv; import std.array; void main() { int N = readln.split[0].to!int; auto reader = readln.split; int[] A = new int[N + 1]; for(uint i = 0; i < N + 1; i++){ A[i] = reader[i].to!int; } reader = readln.split; int[] B = new int[N]; for(uint i = 0; i < N; i++){ B[i] = reader[i].to!int; } ulong ans = 0; for (uint i = 0; i < N; i++){ ans += battle(A[i], B[i]); ans += battle(A[i + 1], B[i]); } writeln(ans); } int battle(ref int a, ref int b){ int ret; if (b > a){ ret = a; b -= a; a = 0; } else { ret = b; a -= b; b = 0; } return ret; }
D
import std; void main(){ auto input=readln.chomp.split.to!(size_t[]); auto x=input[0]; auto y=input[1]; auto b_2=y-2*x; if(b_2%2!=0){ "No".writeln; return; } auto b=b_2/2; if(x<b){ "No".writeln; return; } "Yes".writeln; }
D
import std.stdio, std.string, std.conv, std.range, std.algorithm; void main() { auto _n = readln; string[] n = []; string line; while((line = readln.chomp) != "") { n ~= line; } foreach (_s; ["S", "H", "C", "D"]) foreach (_i; 1..14) { auto t = _s ~ " " ~ _i.to!string; if (!n.canFind(t)) t.writeln; } }
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() { while (true) { auto rd = readln.split.map!(to!int); auto h = rd[0], w = rd[1]; if (h == 0 && w == 0) break; foreach (i; 0..h) { foreach (j; 0..w) write((i + j) % 2 == 0 ? '#' : '.'); writeln; } writeln; } }
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; // }}} // 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; int n, a, b; n = cin.next!int; a = cin.next!int; b = cin.next!int; writeln((a + b) & 1 ? "Borys" : "Alice"); }
D
import std.stdio; import std.conv; import std.string; void main() { char[] s = readln.dup.chomp; s[5] = ' '; s[13] = ' '; writeln(s); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long a, b, c, d; scan(a, b, c, d); if (a + b > c + d) { writeln("Left"); } else if (a + b < c + d) { writeln("Right"); } else { writeln("Balanced"); } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio; import std.string; import std.array; // split import std.conv; // to void main() { string[] input = split(readln()); // splitで文字列を文字列の配列に切り分け int a = to!int(input[0]); // 第0要素を整数に変換 int b = to!int(input[1]); // 第1要素を整数に変換 if((a*b)%2 == 0){ writeln("Even"); // 表示 } else { writeln("Odd"); // 表示 } }
D
import std.stdio,std.ascii,std.conv,std.string,std.algorithm,std.range,std.functional,std.math,core.bitop; void main() { int num; auto a=readln.chomp.to!int; for(int i=0;i<=a;i++){ if(i%2==0)continue; int b; for(int j=1;j<=i;j++){ if(i%j==0)b++; } if(b==8)num++; } writeln(num); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { string a, b, c; scan(a); scan(b); scan(c); auto A = a.length.to!int; auto B = b.length.to!int; auto C = c.length.to!int; auto ab = new bool[](20000); auto ac = new bool[](20000); auto bc = new bool[](20000); ab[] = ac[] = bc[] = true; bool match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; } foreach (i ; 0 .. A) { foreach (j ; 0 .. B) { if (!match(a[i], b[j])) { ab[i - j + 10000] = false; } } } foreach (i ; 0 .. A) { foreach (j ; 0 .. C) { if (!match(a[i], c[j])) { ac[i - j + 10000] = false; } } } foreach (i ; 0 .. B) { foreach (j ; 0 .. C) { if (!match(b[i], c[j])) { bc[i - j + 10000] = false; } } } int ans = inf; foreach (lb ; -4000 .. 4001) { foreach (lc ; -4000 .. 4001) { bool valid = ab[lb + 10000] && ac[lc + 10000] && bc[lc - lb + 10000]; if (valid) { int l = min(lb, lc, 0); int r = max(lb + B, lc + C, A); chmin(ans, r - l); } } } writeln(ans); } void scan(T...)(ref T args) { auto line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront; } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x > arg) { x = arg; isChanged = true; } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x < arg) { x = arg; isChanged = true; } return isChanged; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }
D
import std.stdio, std.string, std.conv; import std.algorithm, std.array; auto solve(string X) { immutable N = X.length.to!int(); int n=0,q=0; foreach(c;X) { if(c=='S') ++q; else if(q>0) --q; else ++n; } return n+q; } void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
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 long MOD = 10^^9 + 7; immutable long INF = 1L << 59; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto A = s[1] - 1; auto B = s[2] - 1; auto C = s[3] - 1; auto D = s[4] - 1; auto S = readln.chomp; bool ok1 = !S[A..min(N, C+1)].canFind("##"); bool ok2 = !S[B..min(N, D+1)].canFind("##"); if (C < D) { writeln(ok1 && ok2 ? "Yes" : "No"); } else { long flip = S[B-1..min(N, D+2)].indexOf("..."); if (flip == -1) { writeln("No"); return; } writeln(ok1 && ok2 ? "Yes" : "No"); } }
D
string solve(int n){ int x = (n.to!double/1.08).to!int(); if((x*1.08).to!int() < n)x++; if((x*1.08).to!int()==n)return x.to!string(); else return ":("; } void main(){ int n = inelm(); writeln(solve(n)); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n; scan(n); int[int] cnt; foreach (i ; 0 .. n) { int ai; scan(ai); cnt[ai]++; debug { writeln(cnt); } } int ans; foreach (n, v; cnt) { if (v & 1) ans++; } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto S = readln.chomp; auto N = S.length.to!int; auto ans = new int[](N); foreach (i; 0..N-1) { if (S[i..i+2] == "RL") { int p = i; for (int j = i, k = 0; j >= 0 && S[j] == 'R'; --j, k ^= 1) ans[p+k] += 1; p = i + 1; for (int j = i+1, k = 0; j < N && S[j] == 'L'; ++j, k ^= 1) ans[p-k] += 1; } } ans.map!(to!string).join(" ").writeln; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int h, n; scan(h, n); auto a = new int[](n); auto b = new int[](n); foreach (i ; 0 .. n) { scan(a[i], b[i]); } auto dp = new long[][](n + 1, h + 1); foreach (j ; 1 .. h + 1) { dp[0][j] = inf6; } foreach (i ; 1 .. n + 1) { foreach (j ; 0 .. h + 1) { dp[i][j] = dp[i - 1][j]; if (j - a[i - 1] < 0) { chmin(dp[i][j], dp[i][0] + b[i - 1]); } if (j - a[i - 1] >= 0) { chmin(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]); } } foreach_reverse (j ; 0 .. h) { chmin(dp[i][j], dp[i][j + 1]); } } auto ans = dp[n][h]; 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
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; // 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 X; sc.scan(X); if (X == 7 || X == 5 || X == 3) { writeln("YES"); } else { writeln("NO"); } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto a = readln.chomp.map!(c => cast(int)(c-'0')).array; foreach (i; 0..1<<3) { auto r = a[0]; foreach (j; 0..3) r += a[j+1] * (i.bitTest(j) ? 1 : -1); if (r == 7) { write(a[0]); foreach (j; 0..3) write(i.bitTest(j) ? "+" : "-", a[j+1]); writeln("=7"); return; } } } pragma(inline) { pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; } pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); } pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); } pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); } pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); } pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); } pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); } import core.bitop; pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); } pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); } pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); } }
D
import std.algorithm, std.array, std.conv, std.stdio, std.string; void main() { writeln(cast(char)(readln[0]+1)); }
D
import std.stdio, std.string, std.algorithm, std.array; void main() { writeln(readln.chomp.split(" ").uniq.array.length == 1 ? "H" : "D"); }
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio; void main() { string[3] ss; foreach(ref s; ss) s = readln(); writeln(ss[0][0], ss[1][1], ss[2][2]); }
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.random; import std.range; import std.stdio; import std.string; import std.typecons; void main() { auto nm = readln.chomp.split.map!(to!int); int n = nm.front; int m = nm.back; writeln = m * 1900 * (1 << m) + (n - m) * 100 * (1 << m); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, 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 a, b; scan(a, b); writeln(a * b % 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; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto s = readln.chomp; bool[char] ch; foreach (e; s) { ch[e] = false; } bool f; foreach (c; 'a'..'z'+1) { auto t = c.to!char; if (ch.get(t, true)) { writeln(t); f = true; break; } } if (!f) { writeln("None"); } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto t = RD!int; auto ans = new bool[](t); foreach (ti; 0..t) { auto p = RD!string; auto h = RD!string; auto cnt1 = new int[](26); foreach (c; p) ++cnt1[c-'a']; auto cnt2 = new int[][](h.length+1, 26); foreach (i, c; h) { cnt2[i+1] = cnt2[i].dup; ++cnt2[i+1][c-'a']; } foreach (i; p.length..h.length+1) { bool ok = true; foreach (j; 0..26) { if (cnt2[i][j] - cnt2[i-p.length][j] != cnt1[j]) { ok = false; break; } } if (ok) { ans[ti] = true; break; } } } foreach (e; ans) writeln(e ? "YES" : "NO"); stdout.flush; debug readln; }
D
import std.stdio; import std.string; import std.conv; void main() { int n = readln.chomp.to!int; bool[string] table; foreach (i;0..n) { auto line = readln.chomp; table[line] = true; } writeln(table.length); }
D
import std.stdio; import std.conv; import std.algorithm; import std.string; import std.array; void main() { int n = readln.chomp.to!int; auto s = readln.chomp.split; bool[string] dict; int ans; foreach(ss; s) { if ((ss in dict) is null) { dict[ss] = true; ans++; } } if (ans == 3) { writeln("Three"); } else { writeln("Four"); } return; }
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio; int f(int x) { string s = x.to!string; int r = 1, n = cast(int) s.length; foreach(i, c; s) { r &= s[i] == s[n-1-i]; } return r; } void main() { int a, b; scanf("%d %d", &a, &b); int ans; foreach(x; a..b+1) ans += f(x); ans.writeln; }
D
import std.stdio; void main() { string line=readln(); int ans=0; for(int i=0;i<3;i++) ans+=line[i]-'0'; writeln(ans); }
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; writeln("ABC" ~ n); }
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; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; // dfmt on void main() { long n, m; scan(n, m); auto b = new bool[](n); long L = 1; long R = n; foreach (_; 0 .. m) { long l, r; scan(l, r); L = max(l, L); R = min(r, R); } max(R - L + 1, 0).writeln(); }
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; void main() { string str = readln.chomp; string ans = ""; string[] boin = ["w", "", "k", "s", "t", "n", "h", "m", "y", "r"]; string[] shiin = ["a", "i", "u", "e", "o"]; for (int i=0; i<str.length; i+=2) { if (str[i..i+2] == ['0', 'U']) { ans ~= "nn"; } else { ans ~= boin[str[i]-'0']; switch(str[i+1]) { case 'T': ans ~= shiin[0]; break; case 'L': ans ~= shiin[1]; break; case 'U': ans ~= shiin[2]; break; case 'R': ans ~= shiin[3]; break; case 'D': ans ~= shiin[4]; break; default: } } } ans.writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] 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, D; scan(A, B, C, D); long f(long x) { long lcm = (C * D) / gcd(C, D); return x - (x / C) - (x / D) + (x / lcm); } writeln(f(B) - f(A - 1)); }
D
import std.algorithm; import std.array; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; void main() { //stdin.open("input.txt", "r"); //stdout.open("output.txt", "w"); string num = strip(readln()); if (num[0] == '-') { int a = to!int(num[0..$-1]); int b = to!int(num[0..$-2] ~ num[$-1..$]); writeln(a > b ? a : b); } else { writeln(num); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] 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 N = S.length; long K = lread(); auto dp = new long[][][](2, 4, N + 1); // N以下確定か否か、0でない数字使用回数、処理する位置 dp[0][0][N] = 1; foreach_reverse (i; 0 .. N) { long s = S[N - i - 1] - '0'; dp[s != 0][3][i] += dp[0][3][i + 1]; dp[1][3][i] += dp[1][3][i + 1]; foreach (j; 0 .. 3) { if (s == 0) { dp[1][j + 1][i] += dp[1][j][i + 1] * 9; dp[1][j][i] += dp[1][j][i + 1]; dp[0][j][i] += dp[0][j][i + 1]; } else { dp[1][j + 1][i] += dp[1][j][i + 1] * 9; dp[1][j][i] += dp[1][j][i + 1]; dp[0][j + 1][i] += dp[0][j][i + 1]; // sを使う dp[1][j][i] += dp[0][j][i + 1]; // 0を使う dp[1][j + 1][i] += dp[0][j][i + 1] * (s - 1); // それ以外 } } } // writeln(dp[0][K][0]); // writeln(dp[1][K][0]); writeln(dp[0][K][0] + dp[1][K][0]); }
D
import std.stdio; import std.string; import std.conv; void main() { int x = to!int(chomp(readln())); writeln(x < 1200 ? "ABC": "ARC"); }
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 N = readln.chomp.to!int; auto A = readln.split.map!(to!int).array; auto B = new long[](N+10); long ans = 0; foreach (a; A) B[a] += 1; foreach (b; B) ans += b * (b - 1) / 2; foreach (a; A) writeln(ans - B[a] * (B[a] - 1) / 2 + (B[a] - 1) * (B[a] - 2) / 2); }
D
import std.stdio; import std.conv; import std.string; import std.algorithm; import std.math; void main(){ while(true){ string[] s = []; for(int i=0;i<8;i++){ string temp = readln(); if(stdin.eof()) break; s ~= chomp(temp); } if(stdin.eof()) break; string ans = "none"; for(int i=0;i<7;i++) for(int j=0;j<7;j++) if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i+1][j]=='1'&&s[i+1][j+1]=='1') ans = "A"; for(int i=0;i<5;i++) for(int j=0;j<8;j++) if(s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+2][j]=='1'&&s[i+3][j]=='1') ans = "B"; for(int i=0;i<8;i++) for(int j=0;j<5;j++){ if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i][j+2]=='1'&&s[i][j+3]=='1') ans = "C"; } for(int i=0;i<6;i++) for(int j=1;j<8;j++) if(s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+1][j-1]=='1'&&s[i+2][j-1]=='1') ans = "D"; for(int i=0;i<7;i++) for(int j=0;j<6;j++) if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i+1][j+1]=='1'&&s[i+1][j+2]=='1') ans = "E"; for(int i=0;i<6;i++) for(int j=0;j<7;j++) if(s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+1][j+1]=='1'&&s[i+2][j+1]=='1') ans = "F"; for(int i=0;i<7;i++) for(int j=1;j<7;j++) if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i+1][j-1]=='1'&&s[i+1][j]=='1') ans = "G"; writeln(ans); if(stdin.eof()) break; auto a = readln(); if(stdin.eof()) break; } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.container; import std.bigint; import std.math; void main() { auto ab = readln.split.map!(to!int); writeln(ab[0]*ab[1], " ", ab[0]*2+ab[1]*2); }
D
import std.stdio, std.conv, std.array, std.string; import std.algorithm; import std.container; import std.range; import core.stdc.stdlib; import std.math; void main() { auto N = readln.chomp.to!ulong; auto halfN = N / 2; writeln(halfN - (N%2 == 0 ? 1 : 0)); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "a", long, "b"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long a, b, c, k; scan(a, b, c, k); if (a > k) k.writeln(); else if (a + b >= k) a.writeln(); else writeln(a - (k - (a + b))); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { auto s = sread(); if (s.solve()) writeln("YES"); else writeln("NO"); } bool solve(string s) { auto key = "keyence"; if (s[0 .. key.length] == key) return true; if (s[$ - key.length .. $] == key) return true; long iter; while (s[iter] == key[iter]) iter++; // s[$ - (key.length - iter) .. $].writeln(); // key[iter .. $].writeln(); return (s[$ - (key.length - iter) .. $] == key[iter .. $]); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio, std.conv, std.string, std.math; void main(){ auto ip = readln.split.to!(int[]); if(ip[0] * ip[1] < ip[2] * ip[3]){ writeln(ip[2] * ip[3]); } else if(ip[0] * ip[1] > ip[2] * ip[3]){ writeln(ip[0] * ip[1]); } else { writeln(ip[2] * ip[3]); } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } enum MOD = (10 ^^ 9) + 7; void main() { long X, Y; scan(X, Y); long n = X; long cnt; while (n <= Y) { cnt++; n <<= 1; } writeln(cnt); }
D
/+ dub.sdl: name "F" dependency "dunkelheit" version=">=0.7.4" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); int n; sc.read(n); int[][] g = new int[][n]; foreach (i; 0..n-1) { int a, b; sc.read(a, b); g[a] ~= b; g[b] ~= a; } if (iota(n).filter!(i => g[i].length >= 3).empty) { writeln(1); return 0; } int ans = 0; bool dfs(int p, int b) { bool f = true; if (g[p].length >= 3) f = false; int lc = 0; foreach (d; g[p]) { if (d == b) continue; bool u = dfs(d, p); if (u) lc++; else f = false; } if (g[p].length >= 3) { ans += max(0, lc-1); f = false; } return f; } foreach (i; 0..n) { if (g[i].length >= 3) { dfs(i, -1); break; } } writeln(ans); return 0; } /* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */ // module dkh.container.stackpayload; struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) { import core.exception : RangeError; private T* _data; private uint len, cap; @property bool empty() const { return len == 0; } @property size_t length() const { return len; } alias opDollar = length; inout(T)[] data() inout { return (_data) ? _data[0..len] : null; } ref inout(T) opIndex(size_t i) inout { version(assert) if (len <= i) throw new RangeError(); return _data[i]; } ref inout(T) front() inout { return this[0]; } ref inout(T) back() inout { return this[$-1]; } void reserve(size_t newCap) { import core.memory : GC; import core.stdc.string : memcpy; import std.conv : to; if (newCap <= cap) return; void* newData = GC.malloc(newCap * T.sizeof); cap = newCap.to!uint; if (len) memcpy(newData, _data, len * T.sizeof); _data = cast(T*)(newData); } void free() { import core.memory : GC; GC.free(_data); } void clear() { len = 0; } void insertBack(T item) { import std.algorithm : max; if (len == cap) reserve(max(cap * 2, MINCAP)); _data[len++] = item; } alias opOpAssign(string op : "~") = insertBack; void removeBack() { assert(!empty, "StackPayload.removeBack: Stack is empty"); len--; } } /* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */ // module dkh.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } /* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */ // module dkh.scanner; // import dkh.container.stackpayload; class Scanner { import std.stdio : File; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f) { this.f = f; } char[512] lineBuf; char[] line; private bool succW() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (!line.empty && line.front.isWhite) { line.popFront; } return !line.empty; } private bool succ() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (true) { while (!line.empty && line.front.isWhite) { line.popFront; } if (!line.empty) break; line = lineBuf[]; f.readln(line); if (!line.length) return false; } return true; } private bool readSingle(T)(ref T x) { import std.algorithm : findSplitBefore; import std.string : strip; import std.conv : parse; if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { auto r = line.findSplitBefore(" "); x = r[0].strip.dup; line = r[1]; } else static if (isStaticArray!T) { foreach (i; 0..T.length) { bool f = succW(); assert(f); x[i] = line.parse!E; } } else { StackPayload!E buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } else { x = line.parse!T; } return true; } int 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(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) { import std.exception; enforce(readSingle(x)); static if (args.length == 0) { enforce(enforceEOF == false || !succ()); } else { read!enforceEOF(args); } } void read(bool enforceEOF = false, Args...)(auto ref Args args) { import std.exception; static if (args.length == 0) { enforce(enforceEOF == false || !succ()); } else { enforce(readSingle(args[0])); read!enforceEOF(args); } } } /* 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.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; } 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 lcm(long x, long y) { return x * y / gcd(x, y); } 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 N = RD; long ans; for (long i = 1; i * i < N; ++i) { /*if (N / i == N % i) { ans += i; //debug writeln("1:", i, " ", i); }*/ auto x = N - i; auto y = x / i; if (x % i == 0 && x / y == i && N / y == i) { debug writeln("3:", y, " ", N / y, " ", i); ans += y; //debug writeln("3:", i, " ", y); } } writeln(ans); 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 A = RD; auto B = RD; auto C = RD; writeln(A + B >= C ? "Yes" : "No"); stdout.flush(); debug readln(); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, core.bitop; Tuple!(N, N)[] prime_division(N)(N n) { auto nn = n; Tuple!(N, N)[] res; for (N i = 2; i^^2 <= nn; ++i) { if (n%i == 0) { N cnt; while (n%i == 0) { ++cnt; n /= i; } res ~= tuple(i, cnt); } } if (n != cast(N)1) res ~= tuple(n, cast(N)1); return res; } void main() { auto N = readln.chomp.to!long; long[] ps; foreach (p; prime_division(N)) { ps ~= p[0]; } auto r = N; foreach (x; 1..(1<<(ps.length))) { long n = 1; foreach (i; 0..ps.length) if (x & (1L<<i)) n *= ps[i]; r += N/n * (-1)^^popcnt(x); } writeln(r); }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.numeric; void main() { int n; scan(n); foreach (k ; 1 .. n + 1) { int s = k * (k + 1) / 2; if (n <= s) { int x = s - n; foreach (j ; 1 .. k + 1) { if (j == x) continue; writeln(j); } return; } } } struct Stack(T) { private: int N, peek; T[] data; public: this(int size) { N = size; data = new T[](N); } bool empty() @property { return peek == 0; } bool full() @property { return peek == N; } void push(T x) @property { assert(!full); data[peek++] = x; } void pop() @property { assert(!empty); --peek; } T top() @property { return data[peek - 1]; } void clear() @property { peek = 0; } int length() @property { return peek; } } 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.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { readln; auto xs = readints(); int n = cast(int) xs.length; auto segTree = new SegmentTree(n + 1); foreach (x; xs) { auto max = segTree.query(1, x); segTree.update(x, x + max); } auto max = segTree.query(1, n + 1); writeln(cast(long) n * (n + 1) / 2 - max); } class SegmentTree { private long[] _data; this(int n) { int len = 1; while (len < n) len *= 2; _data = new long[len * 2]; } /// k ?????????????´????(0-indexed)??? a ????????´ void update(int k, long a) { // ????????\??? k += (_data.length / 2) - 1; _data[k] = a; // ?????????????????´??° while (k > 0) { k = (k - 1) / 2; _data[k] = max(_data[k * 2 + 1], _data[k * 2 + 2]); } } /// [a, b) ???????°????????±??????? long query(int a, int b, int k, int l, int r) { // [a, b) ??¨ [l, r) ?????????????????? if (r <= a || b <= l) return 0; // [a, b) ??? [l, r) ????????¨???????????§????????°???????????\????????? if (a <= l && r <= b) { return _data[k]; } // ????????§???????????°???2 ?????????????????§??? auto vl = query(a, b, k * 2 + 1, l, (l + r) / 2); auto vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } long query(int a, int b) { return query(a, b, 0, 0, cast(int)(_data.length / 2)); } }
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, a, b; readV(x, a, b); writeln((x-a).abs < (x-b).abs ? "A" : "B"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto k = readln.chomp.to!int; auto ab = readln.split.to!(int[]); auto A = ab[0]; auto B = ab[1]; auto x = k; while (x <= B) { if (x >= A) { writeln("OK"); return; } x += k; } writeln("NG"); }
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; int readInt(){ return readln.chomp.to!int; } int[] readInts(){ return readln.chomp.split.to!(int[]); } void main(){ string s = readln.chomp; int nf = s[0 .. 2].to!int; int nl = s[2 .. 4].to!int; bool YYMM = false, MMYY = false; if((nf == 0 || nf > 12) && (nl == 0 || nl > 12)) { writeln("NA"); return; } if(1 <= nf && nf <= 12) MMYY = true; if(1 <= nl && nl <= 12) YYMM = true; if(YYMM && MMYY){ writeln("AMBIGUOUS"); } else if(YYMM){ writeln("YYMM"); } else if(MMYY){ writeln("MMYY"); } }
D