code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio,std.array,std.conv,std.algorithm,std.range,std.string,std.math; void main(string[] args) { real a; a = readln.chomp.to!real; a.sqrt.floor.to!int.pow(2).writeln; }
D
import std.stdio,std.conv,std.string; /*int lyca(int n){ if(n==0) return 2; else if(n==1) return 1; else return lyca(n-1)+lyca(n-2); }*/ void main(){ int n=readln().chomp().to!int; ulong k=2UL,l=1UL,ans=1UL; for(int i=1;i<n;i++){ ans=k+l; //ansはl(i+1)に対応 k=l; l=ans; } writeln(ans); }
D
/+ dub.sdl: name "C" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) sc.read!true; int n; long l; long[] c; sc.read(n, l, c); foreach_reverse (i; 0..n-1) { c[i] = min(c[i], c[i+1]); } foreach (i; 1..n) { c[i] = min(c[i], 2*c[i-1]); } long ans = 10L^^18; long nw = 0; foreach_reverse (i; 0..n) { long u = 2L ^^ i; if (u <= l) { long x = l / u; l -= u * x; nw += c[i] * x; } ans = min(ans, nw + c[i]); } writeln(min(ans, nw)); 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.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 = 998244353; //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 main() { auto t = RD!int; auto ans = new long[](t); foreach (ti; 0..t) { auto n = RD!int; auto g = RD!int; auto b = RD!int; long need = (n+1) / 2; long cnt = need / g * (g+b) - b; long r = need % g; if (r != 0) cnt += b + r; ans[ti] = max(n, cnt); } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
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.traits; import core.bitop; import std.typecons; class LazyPropagationSegmentTree(T = int, D = int, D init = D.init) { immutable size_t n; immutable int h; T[] t; D[] d; abstract void calc (size_t p, int k); abstract void apply (size_t p, D value, int k); final void build (size_t l, size_t r) { int k = 2; for (l += n, r += n - 1; l > 1; k <<= 1) { l >>= 1; r >>= 1; foreach_reverse (i; l .. r + 1) { calc (i, k); } } } final void push (size_t l, size_t r) { int s = h, k = 1 << (h-1); for (l += n, r += n - 1; s > 0; --s, k >>= 1) { foreach (i; l >> s .. (r >> s) + 1) { immutable delta = d[i]; if (delta != init) { apply (i << 1, delta, k); apply ((i << 1) | 1, delta, k); d[i] = init; } } } } this (const T[] a) { n = a.length; h = bsr (n); t = uninitializedArray!(T[])(n); t ~= a; d = uninitializedArray!(D[])(n); d[] = init; build (0, n); } } class AssignSumLazyPropagationSegmentTree (T = int) : LazyPropagationSegmentTree!(T, T, T.min) { override void calc (size_t p, int k) { if (d[p] == T.min) t[p] = t[p<<1] + t[(p << 1) | 1]; else t[p] = d[p] * k; } override void apply (size_t p, T value, int k) { t[p] = value * k; if (p < n) d[p] = value; } final void assign (size_t l, size_t r, T value) { debug stderr.writefln ("assign (l:%d, r:%d, value:%d)", l, r, value); push (l, l + 1); push (r - 1, r); immutable l0 = l, r0 = r; int k = 1; for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) { if (l & 1) { apply (l++, value, k); } if (r & 1) { apply (--r, value, k); } } build (l0, l0 + 1); build (r0 - 1, r0); } final T sum (size_t l, size_t r) { push (l, l + 1); push (r - 1, r); T res; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) { res += t[l++]; } if (r & 1) { res += t[--r]; } } return res; } this (T[] a) { super (a); } } 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; } } alias Q = Tuple!(int, int); void main() { auto r = new InputReader (); const nt = r.next!uint(); foreach (tid; 0 .. nt) { const n = r.next!uint(); const nq = r.next!uint(); r.seekByte(48); int[] a, b; foreach (i; 0 .. n) { const c = r.nextByte!false(); a ~= c.to!int - 48; } r.seekByte(48); foreach (i; 0 .. n) { const c = r.nextByte!false(); b ~= c.to!int - 48; } debug stderr.writeln(a); debug stderr.writeln(b); auto st = new AssignSumLazyPropagationSegmentTree!int(b); Q[] q; foreach (i; 0 .. nq) { const u = r.next!int - 1; const v = r.next!int; q ~= Q(u, v); } bool res = true; foreach_reverse (k, const w; q) { const l = w[1] - w[0]; const h = (l - 1) / 2; int t = st.sum(w[0], w[1]); debug stderr.writefln("l = %d, r = %d, sum = %d, h = %d, l = %d", w[0], w[1], t, h, l); if (t <= h) { st.assign(w[0], w[1], 0); } else if (t + h >= l) { st.assign(w[0], w[1], 1); } else { debug stderr.writefln("FAILED: l = %d, r = %d", w[0], w[1]); res = false; break; } } if (res) { foreach (i; 0 .. n) { if (st.sum(i, i + 1) != a[i]) { res = false; break; } } } if (res) write("YES\n"); else write("NO\n"); } }
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 x = rd[0], y = rd[1]; if (x == 0 && y == 0) break; if (x > y) swap(x, y); writeln(x, " ", y); } }
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(i; 2..50) inv_[i]=mul(inv_[mod%i], mod-mod/i)%mod; 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]=mod-(inv(mod%x)*(mod/x))%mod); } long mul(long x, long y){ return ((x*(y>>16)%mod)<<16) + (x*(y&0xffff)); }
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T read(T)(){ return read.to!T; } T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; } T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int n = read!int; string s = read!string; int best = 100_000; foreach(int i; 0 .. n - 3){ string q = s[i .. i + 4]; int x = diff(q[0], 'A') + diff(q[1], 'C') + diff(q[2], 'T') + diff(q[3], 'G'); if(x < best) best = x; } best.writeln; } int diff(char a, char b){ int res; if(a > b) res = min(a - b, b + 26 - a); else res = min(b - a, a + 26 - b); return res; }
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 b = RD; auto g = RD; auto n = RD; auto x = max(b, g); auto y = min(b, g); writeln(min(x, n) - max(n-y, 0) + 1); stdout.flush(); debug readln(); }
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; import std.numeric; import std.bigint; import core.checkedint; import core.bitop; void main() { int n = readln.chomp.to!int; writeln = ["ABC", "ABD"][n / 1000]; } void tie(R, Args...)(R arr, ref Args args) if (isRandomAccessRange!R || isArray!R) in { assert (arr.length == args.length); } body { foreach (i, ref v; args) { alias T = typeof(v); v = arr[i].to!T; } } void verbose(Args...)(in Args args) { stderr.write("["); foreach (i, ref v; args) { if (i) stderr.write(", "); stderr.write(v); } stderr.writeln("]"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto sa = readln.chomp; auto sb = readln.chomp; auto sc = readln.chomp; char t = 'a'; for (;;) { switch (t) { case 'a': if (sa.empty) { writeln("A"); return; } t = sa[0]; sa = sa[1..$]; break; case 'b': if (sb.empty) { writeln("B"); return; } t = sb[0]; sb = sb[1..$]; break; case 'c': if (sc.empty) { writeln("C"); return; } t = sc[0]; sc = sc[1..$]; break; default: return; } } }
D
import std.stdio, std.array, std.conv, std.typecons, std.algorithm; T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } void main() { immutable ip = readln.split.to!(ulong[]); immutable a = ip[0], p = ip[1]; writeln((a*3+p)/2); }
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[])(); } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } alias sread = () => readln.chomp(); void main() { long N = lread(); static immutable dp = () { enum Nmax = 10 ^^ 5; auto dp = new byte[](Nmax + 1); dp[] = byte.max; dp[0] = 0; foreach (i; 0 .. Nmax) if (dp[i] != byte.max) { dp[i + 1].minAssign(cast(ubyte) dp[i] + 1); size_t j = 6; while (i + j < dp.length) { dp[i + j].minAssign(cast(ubyte) dp[i] + 1); j *= 6; } j = 9; while (i + j < dp.length) { dp[i + j].minAssign(cast(ubyte) dp[i] + 1); j *= 9; } } return dp; }(); dp[N].writeln(); }
D
import std.stdio, std.string, std.conv; import std.algorithm, std.array; auto solve(string s_) { immutable P = "Possible"; immutable I = "Impossible"; immutable N = s_.to!int(); immutable a = readln.split.map!(to!int).array(); auto c = new int[N]; foreach(v;a) { if(v<1 || N<=v) return I; ++c[v]; } int n=0, d; foreach(int i,v;c) { if(n==0) { if(v>2) return I; d=i-(v-1); } else { if(v<2) return I; if(--d<0) return I; } n+=v; if(n==N && d==0) return P; } return I; } void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], a = tmp[1], b = tmp[2]; writeln(min(n*a, b)); }
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() { bool[] as = readln.chomp.map!"a=='1'".array; auto stack = DList!bool(); long ans = 0; foreach(a; as) { if (!stack.empty) { long b = stack.back; if (a^b) { stack.removeBack; ans+=2; continue; } } stack.insertBack(a); } ans.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, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range; void main(){ auto hwd=readln.split.map!(to!int).array; auto H=hwd[0],W=hwd[1],d=hwd[2]; foreach(w;0..H){ foreach(h;0..W){ auto k=w+h; auto j=w-h; auto x=k.div(d); auto y=j.div(d); draw(x.mod(2)+2*y.mod(2)); } writeln(); } } int mod(int a,int d){ if(a>=0)return a%d; return (a%d+d)%d; } int div(int a,int d){ return (a-a.mod(d))/d; } void draw(int i){ "RYGB"[i].write; }
D
import std.stdio, std.conv, std.string; void main() { auto D = readln().strip.to!int; switch(D) { case 25: writeln("Christmas"); break; case 24: writeln("Christmas Eve"); break; case 23: writeln("Christmas Eve Eve"); break; case 22: writeln("Christmas Eve Eve Eve"); break; default: break; } }
D
import std.stdio, std.string, std.array, std.conv; void main() { while (true) { int[] tmp = readln.chomp.split.to!(int[]); int h = tmp[0], w = tmp[1]; if (h == 0 && w == 0) break; foreach (i; 0 .. h) { foreach (j; 0 .. w) { write(i == 0 || i == h - 1 || j == 0 || j == w - 1 ? "#" : "."); } writeln; } writeln; } }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; import core.stdc.stdlib; //C // void main() // { // auto N = scanElem; // auto K = scanElem; // auto k = K; // long count=1; // real res=0; // for(long i=N;i>=1;i--) // { // while(i<=k){ // count*=2; // k/=2; // } // res+=1f/count; // writeln(count); // } // writefln("%f20", res/N); // } struct Node{ long connect; long cost; } long[] res; Node[][] nodes; bool[] toutatu; void main() { auto N = scanElem; nodes.length = N+1; res.length = N+1; toutatu.length = N+1; foreach(i; 0..N-1) { auto a = scanElem; auto b = scanElem; auto cost = scanElem; nodes[a] ~= Node(b, cost); nodes[b] ~= Node(a, cost); } calc(1, 0); foreach(x; res[1..$]) { writeln(x%2); } } void calc(long index, long cost) { if(toutatu[index])return; res[index]=cost; toutatu[index] = true; foreach(node; nodes[index]){ calc(node.connect, cost+node.cost); } } long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a % b); } class UnionFind{ UnionFind parent = null; void merge(UnionFind a) { if(same(a)) return; a.root.parent = this.root; } UnionFind root() { if(parent is null)return this; return parent = parent.root; } bool same(UnionFind a) { return this.root == a.root; } } void scanValues(TList...)(ref TList list) { auto lit = readln.splitter; foreach (ref e; list) { e = lit.fornt.to!(typeof(e)); lit.popFront; } } T[] scanArray(T = long)() { return readln.split.to!(T[]); } void scanStructs(T)(ref T[] t, size_t n) { t.length = n; foreach (ref e; t) { auto line = readln.split; foreach (i, ref v; e.tupleof) { v = line[i].to!(typeof(v)); } } } long scanULong(){ long x; while(true){ const c = getchar; if(c<'0'||c>'9'){ break; } x = x*10+c-'0'; } return x; } T scanElem(T = long)() { char[] res; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { res ~= cast(char) c; c = getchar; } return res.strip.to!T; } 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 { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } 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); } } struct Factor { long n; long c; } Factor[] factors(long n) { Factor[] res; for (long i = 2; i ^^ 2 <= n; i++) { if (n % i != 0) continue; int c; while (n % i == 0) { n = n / i; c++; } res ~= Factor(i, c); } if (n != 1) res ~= Factor(n, 1); return res; } long[] primes(long n) { if(n<2)return []; auto table = new long[n+1]; long[] res; for(int i = 2;i<=n;i++) { if(table[i]==-1) continue; for(int a = i;a<table.length;a+=i) { table[a] = -1; } res ~= i; } return res; } bool isPrime(long n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long i = 3; i ^^ 2 <= n; i += 2) if (n % i == 0) return false; return true; }
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 S = RD!string; bool ans = true; foreach (i, c; S) { debug writeln(i == A ? c : c - '0'); if (i == A) { if (c != '-') ans = false; debug writeln("a"); } else if (c - '0' < 0 || c - '0' > 9) { ans = false; debug writeln("b"); } } writeln(ans ? "Yes" : "No"); stdout.flush(); debug readln(); }
D
import std.conv; import std.stdio; import std.string; void main() { int n = readln.chomp.to!int; writeln(n % 2 == 0 ? n : 2 * n); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto x = readln.chomp.to!int; writeln(x ^^ 3); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } int calc(int[] xs) { int rec(int p, int[] buf) { if (p == buf.length) { return buf.any!(e => e % 2 == 0) ? 1 : 0; } int ans = 0; for (int i = -1; i <= 1; i++) { buf[p] = xs[p] + i; ans += rec(p + 1, buf); } return ans; } auto buf = new int[xs.length]; return rec(0, buf); } void main() { readint; auto xs = readints; writeln(calc(xs)); }
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 n, m; readV(n, m); auto t = 1900*m + 100*(n-m); writeln(t*2^^m); }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons; void main() { string S = readln.chomp; switch(S) { case "SUN": 7.writeln; break; case "MON": 6.writeln; break; case "TUE": 5.writeln; break; case "WED": 4.writeln; break; case "THU": 3.writeln; break; case "FRI": 2.writeln; break; case "SAT": 1.writeln; break; default: break; } }
D
void main(){ string s = readln().chomp(); foreach(ch; s){ if( s.count(ch) != 2){ writeln("No"); return; } } writeln("Yes"); } 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.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[][] MAX, MEMO; void main() { auto s = readln.chomp.to!(wchar[]); auto t = readln.chomp.to!(wchar[]); MEMO.length = s.length; MAX.length = s.length; foreach (i; 0..s.length) { MEMO[i].length = t.length; MAX[i].length = t.length; MAX[i][] = -1; } int solve(int i, int j) { if (i == s.length || j == t.length) return 0; if (MAX[i][j] != -1) return MAX[i][j]; auto r1 = s[i] == t[j] ? solve(i+1, j+1) + 1 : -1; auto r2 = solve(i+1, j); auto r3 = solve(i, j+1); auto max_r = max(r1, r2, r3); if (max_r == r1) { return MAX[i][j] = r1; } else if (max_r == r2) { MEMO[i][j] = 1; return MAX[i][j] = r2; } else { MEMO[i][j] = 2; return MAX[i][j] = r3; } } solve(0, 0); wchar[] answer(int i, int j) { if (i == s.length || j == t.length) return []; switch (MEMO[i][j]) { case 0: return s[i] ~ answer(i+1, j+1); case 1: return answer(i+1, j); case 2: return answer(i, j+1); default: return []; } } writeln(answer(0, 0)); }
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 std.regex; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; enum long INF = long.max/5; enum long MOD = 10L^^9+7; void main() { string s = readln.chomp; bool ok = s.length%2 == 0; foreach(i; 0..s.length/2) { if (!ok) break; ok &= s[i*2..i*2+2] == "hi"; } writeln(ok ? "Yes" : "No"); } // ---------------------------------------------- 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 (y > 0 && t * y < x) t++; if (y < 0 && t * y > x) t++; return t; } T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) { T t = x / y; if (y > 0 && t * y > x) t--; if (y < 0 && 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) { enum sep = " "; enum n = Args.length; enum fmt = n.rep!(()=>"%s").join(sep); string line = readln.chomp; static if (__VERSION__ >= 2074) { line.formattedRead!fmt(args); } else { enum argsTemp = n.iota.map!( i => "&args[%d]".format(i) ).join(", "); mixin( "line.formattedRead(fmt, " ~ argsTemp ~ ");" ); } } // 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); } } } } // 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.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() { string s; readV(s); auto n = s.length; auto t = new dchar[]((n+1)/2); foreach (i; 0..(n+1)/2) t[i] = s[i*2]; writeln(t); }
D
// Vicfred // https://atcoder.jp/contests/abc163/tasks/abc163_c // map import std.algorithm; import std.array; import std.conv; import std.stdio; import std.string; void main() { int n = readln.chomp.to!int; int[] a = readln.split.map!(to!int).array; int[] boss = new int[n+1]; foreach(person; a) boss[person] += 1; for(int i = 1; i <= n; i++) boss[i].writeln; }
D
import std.stdio; import std.string; import std.conv; void main() { string[] input = split(readln()); int A = to!int(input[0]); int B = to!int(input[1]); if(A + B >= 10){ writeln("error"); } else { writeln(A + B); } }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto list = [0,1,3,1,2,1,2,1,1,2,1,2,1]; if(list[scanElem]==list[scanElem])end("Yes");end("No"); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void calc(string[] g) { auto rows = g.length; auto cols = g[0].length; bool[int] rowSkip, colSkip; for (int r = 0; r < rows; r++) { bool isSkip = true; for (int c = 0; c < cols; c++) { if (g[r][c] == '#') { isSkip = false; break; } } if (isSkip) rowSkip[r] = true; } for (int c = 0; c < cols; c++) { bool isSkip = true; for (int r = 0; r < rows; r++) { if (g[r][c] == '#') { isSkip = false; break; } } if (isSkip) colSkip[c] = true; } for (int r = 0; r < rows; r++) { if (r in rowSkip) continue; for (int c = 0; c < cols; c++) { if (c in colSkip) continue; write(g[r][c]); } writeln(); } } void main() { auto hw = readints; int h = hw[0]; string[] g; for (int i = 0; i < h; i++) { g ~= read!string; } calc(g); }
D
import std.stdio, std.string, std.range, std.algorithm, std.math, std.typecons, std.conv; void main() { auto a = readln.split; ((a[0][$-1] == a[1][0] && a[1][$-1] == a[2][0]) ? "YES" : "NO").writeln; }
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 n = r.next!uint (); auto a = r.nextA!uint (n); auto b = new bool[n + 1]; foreach (i; a) { b[i] = true; } int odds, evens; for (int i = 1; i <= n; ++i) { if (!b[i]) { if (i & 1) odds++; else evens++; } } int[] pos; foreach (i; 0 .. n) { if (a[i] == 0) pos ~= i; } immutable int m = pos.length.to!int; auto dp = new int[][][] (m + 1, odds + 1, 3); foreach (i; 0 .. m + 1) foreach (j; 0 .. odds + 1) dp[i][j][] = -1; auto vo = new int[m]; auto ve = new int[m]; b = new bool[m]; foreach (i; 0 .. m) { immutable int k = pos[i]; if (k > 0) { if (a[k-1] != 0) { if (a[k-1] & 1) { ve[i]++; } else { vo[i]++; } } else b[i] = true; } if (k+1 < n) { if (a[k+1] != 0) { if (a[k+1] & 1) { ve[i]++; } else { vo[i]++; } } } } debug stderr.writeln (vo); debug stderr.writeln (ve); debug stderr.writeln (b); debug stderr.writeln (odds); debug stderr.writeln (evens); int f (const int k, const int o, const int last) { if (dp[k][o][last] >= 0) return dp[k][o][last]; immutable int r = m - k; if (!r) return dp[k][o][last] = 0; immutable int co = odds - o, ce = k - co, e = evens - ce; assert (e >= 0); int res = int.max; if (o > 0) { int w = f (k + 1, o - 1, 1) + vo[k]; if (b[k] && last == 0) ++w; res = min (res, w); } if (e > 0) { int w = f (k + 1, o, 0) + ve[k]; if (b[k] && last == 1) ++w; res = min (res, w); } return dp[k][o][last] = res; } int res = f (0, odds, 2); foreach (i; 1 .. n) { if (a[i-1] != 0 && a[i] != 0 && 0 != ((a[i-1] ^ a[i]) & 1)) { ++res; } } writeln (res); }
D
void main() { problem(); } void problem() { auto A = scan!int; auto B = scan!int; auto C = scan!int; auto D = scan!int; bool solve() { while(true) { C -= B; if (C <= 0) return true; A -= D; if (A <= 0) return false; } } writeln(solve() ? "Yes" : "No"); } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } alias Point = Tuple!(long, "x", long, "y"); // -----------------------------------------------
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_t; 0..T) { auto N = readln.chomp.to!int; writeln(N/2); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // 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 one; while (S[one] == '1') one++; if (K <= one) { writeln(1); return; } writeln(S[one]); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto N = readln.chomp.to!int; string d1 = "..##"; string d2 = ".#.#"; string r1 = ""; string r2 = ""; bool right_end = false; while (true) { bool t = false; foreach (k; 0..4) { if (right_end) { r1 = d1[k] ~ r1; r2 = d2[k] ~ r2; } else { r1 = r1 ~ d1[k]; r2 = r2 ~ d2[k]; } writeln(r1); writeln(r2); stdout.flush; string tf = readln.chomp; if (tf == "T") { t = true; break; } else if (tf == "end") return; if (right_end) { r1 = r1[1..$]; r2 = r2[1..$]; } else { r1 = r1[0..$-1]; r2 = r2[0..$-1]; } } if (!t) { right_end = true; N += 1; } } }
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; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; void main() { writeln(readln.chomp.equal(readln.chomp.retro) ? "YES" : "NO"); } // ---------------------------------------------- void scanln(Args...)(ref Args args) { foreach(i, ref v; args) { "%d".readf(&v); (i==args.length-1 ? "\n" : " ").readf; } // ("%d".repeat(args.length).join(" ") ~ "\n").readf(args); } void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D
import std.stdio,std.conv,std.string,std.algorithm,std.array; void main(){ auto s=readln().chomp().split().map!(to!int); int a=s[0],b=s[1]; if(a<=8&&b<=8) writeln("Yay!"); else 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, std.typecons; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string : chomp; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.chomp.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 main() { auto cin = new Scanner; int a, b, x; cin.scan(a, b, x); if (a <= x && a + b >= x) { writeln("YES"); } else { writeln("NO"); } }
D
import std.stdio; import std.algorithm; import std.string; import std.conv; import std.math; void main(){ while(true){ int n = to!int(chomp(readln())); if(n == 0) break; int ans = 0; int nf=8; while(nf>0){ ans += n / pow(5,nf) ; nf--; } writeln(ans); } }
D
import std.stdio; import std.algorithm; import std.container; import core.stdc.stdio; import std.typecons; int n,k; int[][] sg; int[][] graph; int[2][] queue; bool[] visited; int gSize=0; void buildGraph(int idx,int r){ visited[] = false; int qc=0; visited[idx]=true; foreach(c;sg[idx]){ queue[qc++] = [1,c]; visited[c]=true; } for(int i=0;i<qc;i++){ int s=queue[i][0]; int p=queue[i][1]; if(s>r) return; graph[idx] ~= p; gSize++; foreach(c;sg[p]){ if(!visited[c]){ visited[c] = true; queue[qc++] = [s+1,c]; } } } } void main(){ scanf("%d%d",&n,&k); graph = new int[][n]; sg = new int[][n]; int[] cs=new int[n]; int[] rs=new int[n]; queue = new int[2][n]; visited = new bool[n]; for(int i=0;i<n;i++){ scanf("%d%d",&cs[i],&rs[i]); } for(int i=0;i<k;i++){ int a,b; scanf("%d%d",&a,&b); sg[--a] ~= --b; sg[b] ~= a; } for(int i=0;i<n;i++){ buildGraph(i,rs[i]); } visited[] = false; alias Tuple!(int,"cost",int,"idx") ci; alias BinaryHeap!(ci[],"a>b") pq; pq q = pq(new ci[gSize+1],0); q.insert(ci(0,0)); int ans; while(1){ ci s = q.front; q.removeFront; if(s.idx==n-1){ ans=s.cost; break; } if(visited[s.idx]) continue; visited[s.idx]=true; foreach(c;graph[s.idx]){ if(!visited[c]){ q.insert(ci(s.cost+cs[s.idx],c)); } } } printf("%d\n",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; void main() { auto s = readln.chomp; auto cnt = s.count!(a=>a=='o'); auto d = 15 - s.length; if (cnt + d >= 8) { writeln("YES"); } else { writeln("NO"); } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long X = lread(); long n = 1; foreach (i; 2 .. 32) { long j = 2; while (i ^^ j <= X) { n.maxAssign(i ^^ j); j++; } } writeln(n); }
D
import std; // 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, K; scan(N, K); auto C = new long[](K + 1); long ans; foreach_reverse (x; 1 .. K + 1) { C[x] = powmod(K / x, N, MOD); long i = 2; while (x * i <= K) { C[x] = (MOD - C[x * i] + C[x]) % MOD; i++; } ans = (ans + C[x] * x) % MOD; } writeln(ans); } /// x^^n % m T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7) { if (n < 1) return 1; if (n & 1) { return x * powmod(x, n - 1, m) % m; } T tmp = powmod(x, n / 2, m); return tmp * tmp % m; }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; import core.stdc.stdlib, core.bitop; enum MOD=pow(10,9)+7; void main() { auto S = scanString; long[2][] dp; dp.length = S.length+1; dp[0][1]=1; foreach(long i, b; S) { i++; if(b=='1') { dp[i][0] = dp[i-1][0]*3+dp[i-1][1]; dp[i][1] = dp[i-1][1]*2; }else{ dp[i][0] = dp[i-1][0]*3; dp[i][1] = dp[i-1][1]; } dp[i][0] %= MOD; dp[i][1] %= MOD; } writeln((dp[$-1][0]+dp[$-1][1])%MOD); } long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a % b); } class UnionFind{ UnionFind parent = null; void merge(UnionFind a) { if(same(a)) return; a.root.parent = this.root; } UnionFind root() { if(parent is null)return this; return parent = parent.root; } bool same(UnionFind a) { return this.root == a.root; } } string scanString() { return scanElem!string; } void scanValues(TList...)(ref TList list) { auto lit = readln.splitter; foreach (ref e; list) { e = lit.fornt.to!(typeof(e)); lit.popFront; } } T[] scanArray(T = long)() { return readln.split.to!(T[]); } void scanStructs(T)(ref T[] t, size_t n) { t.length = n; foreach (ref e; t) { auto line = readln.split; foreach (i, ref v; e.tupleof) { v = line[i].to!(typeof(v)); } } } long scanULong(){ long x; while(true){ const c = getchar; if(c<'0'||c>'9'){ break; } x = x*10+c-'0'; } return x; } T scanElem(T = long)() { char[] res; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { res ~= cast(char) c; c = getchar; } return res.strip.to!T; } 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 { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } 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); } } struct Factor { long n; long c; } //素因数分解 Factor[] factors(long n) { Factor[] res; for (long i = 2; i ^^ 2 <= n; i++) { if (n % i != 0) continue; int c; while (n % i == 0) { n = n / i; c++; } res ~= Factor(i, c); } if (n != 1) res ~= Factor(n, 1); return res; } //約数をすべて列挙 long[] divisors(long n) { long[] list; void func(Factor[] fs, long n) { if(fs.empty){ list ~= n; return; } foreach(c; 0..fs[0].c+1) { func(fs[1..$], n * (fs[0].n ^^ c)); } } func(factors(n), 1); sort(list); return list; } //nまでの素数のリスト long[] primes(long n) { if(n<2)return []; auto table = new long[n+1]; long[] res; for(int i = 2;i<=n;i++) { if(table[i]==-1) continue; for(int a = i;a<table.length;a+=i) { table[a] = -1; } res ~= i; } return res; } //素数判定 bool isPrime(long n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long i = 3; i ^^ 2 <= n; i += 2) if (n % i == 0) return false; return true; }
D
import std.stdio; import std.string; import std.conv; void main() { auto line = chomp(readln()).split(" "); int H = to!int(line[0]), W = to!int(line[1]); while(H || W) { writeln(repeat("#", W)); foreach(int i; 2 .. H) { writeln("#" ~ repeat(".", W - 2) ~ "#"); } writeln(repeat("#", W)); writeln(); line = chomp(readln()).split(" "); H = to!int(line[0]); W = to!int(line[1]); } } string repeat(string s, int n) { string r; while(n) { if(n % 2) { r ~= s; } n >>= 1; s ~= s; } return r; }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto n=scanElem; (n*(n+1)/2).end(); }
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 H = readln.chomp.to!(int); auto W = readln.chomp.to!(int); auto N = readln.chomp.to!(int); auto sizePerPaint = H > W ? H : W; writeln(N / sizePerPaint + (N % sizePerPaint == 0 ? 0 : 1)); }
D
import std.stdio; import std.string; import std.conv; import std.range; import std.algorithm; void main() { int count = 0; string input; while ((input = readln.chomp).length != 0) { if (hantei(input)) count++; } writeln(count); } bool hantei(string input) { for (int i = 0; i < (input.length / 2); i++) { if (input[i] != input[(input.length - 1) - i]) return false; } return true; }
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 r = readln.chomp.to!int; if (r < 1200) { writeln("ABC"); } else if (r < 2800) { writeln("ARC"); } else { writeln("AGC"); } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp.dup; s.reverse(); writeln(s); }
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() { long n, m; scan(n, m); auto s = readln.chomp; auto t = readln.chomp; auto l = lcm(n, m); auto sg = l / m; auto tg = l / n; foreach (i ; 0 .. n / sg) { if (s[i*sg] != t[i*tg]) { writeln(-1); return; } } writeln(l); } long lcm(long a, long b) { return a / gcd(a, b) * 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; void main() { auto x = readln.chomp.to!int; int sum, i; while (x > sum) sum += ++i; writeln(i); }
D
import std.stdio; import std.string; import std.conv; void main() { auto M = readln.chomp.to!int; auto x = 48-M; writeln(x); }
D
import std.container; import std.range; import std.algorithm; import std.array; import std.string; import std.conv; import std.stdio; import std.container; void main() { auto s = readln.chomp; write(s); if (s[$ - 1] == 's') { writeln("es"); } else { writeln("s"); } }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int[string] memo; foreach(str; ["A", "B", "AB", "O"]) { memo[str] = 0; } while(true) { auto line = readln; if(!line)break; auto f = line.chomp.split(","); ++memo[f[1]]; } foreach(str; ["A", "B", "AB", "O"]) { memo[str].writeln; } }
D
import std.stdio, std.string, std.conv, std.regex; void main() { auto n = readln.chomp; if(n[0] == '9' || n[1] == '9'){ writeln("Yes"); } else { writeln("No"); } }
D
// Vicfred // https://atcoder.jp/contests/abc159/tasks/abc159_b // string manipulation import std.stdio; import std.string; bool palindrome(string s) { long n = s.length; for(long i = 0; i < n/2; i++) if(s[i] != s[$-i-1]) return false; return true; } void main() { string s = readln.chomp; long n = s.length; if(s[0..(n-1)/2].palindrome && s[(n+1)/2..$].palindrome && s.palindrome) "Yes".writeln; else "No".writeln; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm, std.math; long q, h, s, d; rd(q, h, s, d); long n; rd(n); s=min(s, 2*h, 4*q); long c=n*s; if(n%2==0){ c=min(c, n/2*d); }else{ c=min(c, s+(n-1)/2*d); } writeln(c); } 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
long solve(long a, long b, long h){ return (a+b)*h/2; } void main(){ int a = inelm(); int b = inelm(); int h = inelm(); solve(a, b, h).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio; import std.string; import std.conv; int main() { int line = readln.chomp.to!int; int n = readln.chomp.to!int; int[31] values; foreach(int i;0..line) { values[i] = i+1; } foreach(int i;0..n) { auto input = readln.chomp.split(","); int a = to!int(input[0]); int b = to!int(input[1]); int value = values[a-1]; values[a-1] = values[b-1]; values[b-1] = value; } foreach(int i;0..line) { writeln(values[i]); } return 0; }
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, W; scan(N, W); auto w = new int[](N); auto v = new int[](N); iota(N).each!(i => scan(v[i], w[i])); auto dp = new int[](W + 1); foreach (i ; 0 .. N) { foreach (j ; 0 .. W + 1) { if (j - w[i] >= 0) chmax(dp[j], dp[j - w[i]] + v[i]); } } auto ans = dp[W]; 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.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { while (1) { auto s = readln.chomp; if (s == ".") return; writeln(isBalance(s) ? "yes" : "no"); } } bool isBalance(string s) { auto st = Stack!(char)(200); foreach (ch ; s) { if (ch == '(' || ch == '[') st.push(ch); else if (ch == ')') { if (st.empty || st.top != '(') return false; else st.pop; } else if (ch == ']') { if (st.empty || st.top != '[') return false; else st.pop; } } return st.empty; } 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.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() { int maxN = 10^^6; int[] f, f_odd; for(int n=1; ;n++) { f ~= func(n); if (f.back > maxN) break; if (f.back%2!=0) f_odd~= f.back; } int INF = 1<<30; int[] ary = new int[maxN+1]; ary[] = INF; ary[0] = 0; foreach(int i; 0..maxN) { for(int n=0; n<f.length; n++) { if (i+f[n]<=maxN) { ary[i+f[n]] = min(ary[i+f[n]], ary[i]+1); } else { break; } } } int[] _ary = new int[maxN+1]; _ary[] = INF; _ary[0] = 0; foreach(int i; 0..maxN) { for(int n=0; n<f_odd.length; n++) { if (i+f_odd[n]<=maxN) { _ary[i+f_odd[n]] = min(_ary[i+f_odd[n]], _ary[i]+1); } else { break; } } } while(true) { int N = readln.chomp.to!int; if (N==0) break; writeln(ary[N], " ", _ary[N]); } } int func(int n) { return n*(n+1)*(n+2)/6; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a,b; scan(a,b); a %= 3, b %= 3; writeln(a == b && a != 0 ? "Impossible" : "Possible"); } 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() { int n = readln.chomp.to!int; int a = readln.chomp.to!int; writeln(n % 500 <= a ? "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.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.chomp; if (A.front == 'W' || A.back == 'W') { writeln(0); return; } immutable long MOD = 10^^9 + 7; long ans = 1; long cnt = 0; foreach (a; A) { if (cnt == 0 && a == 'W') { writeln(0); return; } else if (cnt == 0) { cnt += 1; } else if (a == 'W') { if (cnt % 2 == 1) { cnt += 1; } else { ans = ans * cnt % MOD; cnt -= 1; } } else { if (cnt % 2 == 1) { ans = ans * cnt % MOD; cnt -= 1; } else { cnt += 1; } } } if (cnt != 0) { writeln(0); } else { foreach (i; 1..N+1) ans = ans * i % MOD; writeln(ans); } }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); s[3]='8'; writeln(s); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv, std.exception; auto l=readln.split; enforce(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n, a, b, c; scan(n, a, b, c); int ans = n - (a + b - c); 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.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; writeln(xs[0] ^ xs[1] ^ xs[2]); }
D
import std.stdio; import std.regex; void main(){ auto io = new IO(); auto N = io.line()[0]; auto A = io.line(N); size_t paired = 0; size_t surplus = 0; foreach( i,a ; A ){ if( surplus == 1 ){ paired += (a+1)/2; surplus = ( (a+1)/2 ) ? (a+1)%2 : 0 ; }else{ paired += a/2; surplus = a%2; } //writeln( i,",",a,":",paired," ",surplus ); } paired.writeln(); return; } import std.stdio,std.conv,std.string; import std.algorithm,std.array,std.math; class IO { T[] line( T = size_t , string token = " " )( size_t m = 1 ){ T[] arr = []; foreach( i ; 0..m ){ arr ~= this.read!T(); } return arr; } T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){ T[][] arr = new T[][](m); foreach( i ; 0..m ){ arr[i] = this.read!T(token); } return arr; } private T[] read( T = size_t )( string token = " " ){ T[] arr; foreach( elm ; readln().chomp().split(token) ){ arr ~= elm.to!T(); } return arr; } } // T -> T[] pure T[] step( T = size_t )( in T begin , in T end , in T step = 1 ){ T[] ret; for( T i = begin ; i < end ; i += step ){ ret ~= i; } return ret; } unittest{ assert( step(0,10,2) == [0,2,4,6,8] ); } // T[] -> T[] pure T[] fill( T )( T[] args , in T filling ){ foreach( ref arg ; args ){ arg = filling; } return args; } T[] map( T )( T[] args , T function(T) f ){ foreach( ref arg ; args ){ arg = f(arg); } return args; } unittest{ assert( [true,false,true,false].fill(true) == [true,true,true,true] ); assert( [1,-2,3,-4].map!int(x=>x*2) == [2,-4,6,-8] ); } // T[] -> number pure T sum( T )( in T[] args ){ T ret = 0; foreach( i ; 0..args.length ){ ret += args[i]; } return ret; } pure T ave(T)( in T[] args ){ return args.sum()/args.length; } pure real multi( in real[] args ){ real ret = 1.0; foreach( i ; 0..args.length ){ ret *= args[i]; } return ret; } // T[] -> bool pure bool any( T )( in T[] args , in T target ){ foreach( arg ; args ){ if( arg == target ){return true;} } return false; } pure bool all( T )( in T[] args , in T cond ){ foreach( arg ; args ){ if( arg != cond ){return false;} } return true; } pure bool have( T )( in T[] args , in T[] target ... ){ bool[] found = new bool[](target.length); foreach( arg ; args ){ foreach( i,t ; target ){ if( arg == t ){ found[i] = true; } } } foreach( f ; found ){ if( f == false ){return false;} } return true; } unittest{ assert( [1,2,3,4,5].sum() == 15 ); assert( [1,2,3,4,5].ave() == 3 ); assert( cmp( [0.3,0.3].multi() , 0.09 ) , "multi() test failed" ); assert( cmp( [0.3,0.3,0.3].multi() , 0.027 ) , "multi() test failed" ); assert( [1,1,1].all(1) == true ); assert( [1,1,2].all(1) == false ); assert( [1,1,2].any(2) == true ); assert( [1,1,2].any(3) == false ); assert( [1,2,3,4,5].have([1,3,5]) == true ); assert( [1,2,3,4,5].have([1,3,5,7]) == false ); }
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { auto S = sread(); bool f(string s) { return s.length % 2 == 0 && s[0 .. $ / 2] == s[$ / 2 .. $]; } foreach_reverse (i; 0 .. S.length) { if (f(S[0 .. i])) { writeln(i); return; } } }
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.replace("C", "A").replace("G", "A").replace("T", "A"); int res, cnt; foreach (e; s) { if (e == 'A') { cnt++; } else { res = max(res, cnt); cnt = 0; } } res = max(res, cnt); res.writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new int[](t); foreach (ti; 0..t) { auto n = RD!int; auto s = RD!string; long cnt0, cnt1; foreach (i; 0..n) { if (s[i] == '<') ++cnt0; else if (s[i] == '>') ++cnt1; if (s[(n+i-1)%n] == '-' || s[i] == '-') ++ans[ti]; } if (cnt0 == 0 || cnt1 == 0) ans[ti] = n; } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
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() { auto tokens = split(my_readln()); auto S = to!string(tokens[0]); if (S.length == 2) writeln(S); else { foreach_reverse(e; S) write(e); writeln(); } stdout.flush(); }
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 X = RD; long ans, y; while (y != 360) { y %= 360; y += X; ++ans; } writeln(ans); 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; void main() { auto S = readln.chomp; auto T = readln.chomp; auto N = S.length.to!int; auto M = T.length.to!int; auto st = new SegmentTree(N); auto tt = new SegmentTree(M); foreach (i; 0..N) if (S[i] == 'A') st.add(i, 1); foreach (i; 0..M) if (T[i] == 'A') tt.add(i, 1); auto Q = readln.chomp.to!int; foreach (q; 0..Q) { auto s = readln.split.map!(to!int); auto a = s[0]-1; auto b = s[1]-1; auto c = s[2]-1; auto d = s[3]-1; auto n = b - a + 1; auto m = d - c + 1; auto sa = st.sum(a, b); auto sb = n - sa; auto ta = tt.sum(c, d); auto tb = m - ta; sa += sb * 2; ta += tb * 2; writeln((sa-ta)%3==0 ? "YES" : "NO"); } } class SegmentTree { int[] table; int size; this(int n) { assert(bsr(n) < 29); size = 1 << (bsr(n) + 2); table = new int[](size); } void add(int pos, int num) { return add(pos, num, 0, 0, size/2-1); } void add(int pos, int num, int i, int left, int right) { table[i] += num; if (left == right) return; auto mid = (left + right) / 2; if (pos <= mid) add(pos, num, i*2+1, left, mid); else add(pos, num, i*2+2, mid+1, right); } int sum(int pl, int pr) { return sum(pl, pr, 0, 0, size/2-1); } int sum(int pl, int pr, int i, int left, int right) { if (pl > right || pr < left) return 0; else if (pl <= left && right <= pr) return table[i]; else return sum(pl, pr, i*2+1, left, (left+right)/2) + sum(pl, pr, i*2+2, (left+right)/2+1, right); } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp; writeln(s.replace(",", " ")); }
D
import std.stdio; import std.string; import std.conv; import std.range; import std.algorithm; import std.math; import std.regex; void main() { auto ip = readln.split.to!(int[]), a = ip[0], b = ip[1]; ((a*b)&1 ? "Odd" : "Even").writeln; }
D
import std.array : split; import std.conv : to; import std.stdio; import std.string : strip; private { string[] temp; } void main() { read(); int n = get!int(0); int count = 0; foreach (i; 1 .. n + 1) { count += (n - (i - 1)) * i - i + 1; } stdout.write(count); } void read() { temp = split(strip(stdin.readln())); } T get(T)(int p) { return to!(T)(temp[p]); }
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!long).array; immutable long MOD = 10^^9 + 7; long ans = 1; long pos = 1; long cnt = 0; foreach (i; 0..N) { if (A[i] >= pos) { cnt += 1; pos += 2; } else { ans = ans * (cnt + 1) % MOD; } } while (cnt) { ans = ans * cnt % MOD; cnt -= 1; } ans.writeln; }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; void main(){ long x = readln.chomp.to!long; long i; for(i = 0; i * (i + 1) / 2 < x; i ++){ } i.writeln; }
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { auto S = sread(); DList!char stack; foreach (i, c; S) { if (!stack.empty && stack.back == 'S' && c == 'T') { stack.removeBack(); } else { stack.insertBack(c); } } long ans; foreach (_; stack) { ans++; } writeln(ans); }
D
#!/usr/bin/rdmd import std.stdio; import std.conv: to; import std.array: split; import std.ascii: newline; immutable greater = "a > b"; immutable less = "a < b"; immutable equa = "a == b"; void main() { int[2] a; foreach (string line; lines(stdin)) { if(line == newline) break; else { a = to!(int[])(split(line)); if(a[0] > a[1]) writeln(greater); else if(a[0] < a[1]) writeln(less); else writeln(equa); } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void main() { auto rs = new int[](10^^4+1); foreach (x; 1..101) foreach (y; 1..101) foreach (z; 1..101) { auto n = x^^2 + y^^2 + z^^2 + x*y + y*z + z*x; if (n > 10^^4) continue; ++rs[n]; } auto N = readln.chomp.to!int; foreach (i; 1..N+1) writeln(rs[i]); }
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; auto s = new string[](N); foreach (i; 0..N) { s[i] = RD!string; } long cnt_ab; long cnt_a, cnt_b, cnt_a_b; foreach (i; 0..N) { foreach (j; 1..s[i].length) { if (s[i][j-1] == 'A' && s[i][j] == 'B') { ++cnt_ab; } } if (s[i][$-1] == 'A' && s[i][0] == 'B') { ++cnt_a_b; } else { if (s[i][$-1] == 'A') ++cnt_a; if (s[i][0] == 'B') ++cnt_b; } } auto ans = max(0, cnt_a_b - 1); if (cnt_a_b != 0) { if (cnt_a != 0) { ++ans; --cnt_a; } if (cnt_b != 0) { ++ans; --cnt_b; } } ans += min(cnt_a, cnt_b); ans += cnt_ab; 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.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto M = RD; auto edges = new long[][](N); auto deg = new long[](N); foreach (i; 0..N-1+M) { auto A = RD-1; auto B = RD-1; edges[A] ~= B; ++deg[B]; } long[] open; foreach (i; 0..N) { if (deg[i] == 0) { open ~= i; break; } } auto par = new long[](N); while (!open.empty) { auto from = open.front; open.popFront; foreach (to; edges[from]) { --deg[to]; if (deg[to] == 0) { par[to] = from+1; open ~= to; } } } foreach (i; 0..N) { writeln(par[i]); } stdout.flush; debug readln; }
D
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; import std.math; import std.range; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } //Digit count---{{{ int DigitNum(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } //}}} //}}} void main() { Scanner sc = new Scanner; int X; sc.scan(X); if (X == 7 || X == 5 || X == 3) writeln("YES"); else writeln("NO"); }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; bool [int] b; foreach (i; 0..n) { foreach (j; i + 1..n) { b[a[j] - a[i]] = true; } } writeln (b.length); } }
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!(string, "x", long, "y"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto c = lread!char(); writeln((c + 1).to!char); } 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; 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; auto res = int.max; foreach (i; 0..s.length-2) { res = min(res, abs(s[i..i+3].to!int - 753)); } res.writeln; }
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { while (true) { int x, y, s; scan(x, y, s); if (!x && !y && !s) return; solve(x, y, s); } } void solve(int x, int y, int s) { int ans; foreach (p ; 1 .. s) { int q = s - p; int pp = calckmax(p, x); int qq = calckmax(q, x); if (!pp || !qq) continue; int pz = calczei(pp, y); int qz = calczei(qq, y); ans = max(ans, pz + qz); } writeln(ans); } int calczei(int p, int x) { return p*(100+x)/100; } int calckmax(int p, int x) { int btm = 0, top = 2*p; while (top - btm > 1) { int mid = (btm + top) / 2; if (mid*(100+x)/100 <= p) { btm = mid; } else { top = mid; } } if (btm*(100+x)/100 == p) { return btm; } else { return 0; } } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.string, std.array, std.conv; void main() { while (true) { string[] tmp = readln.chomp.split; int a = tmp[0].to!int, b = tmp[2].to!int; string op = tmp[1]; if (op == "+") { writeln(a + b); } else if (op == "-") { writeln(a - b); } else if (op == "*") { writeln(a * b); } else if (op == "/") { writeln(a / b); } else { break; } } }
D
import std.stdio, std.ascii, std.string; void main() { readln.chomp.toUpper.writeln; }
D
import std.stdio; import std.algorithm; void main(){ string str = "Hello World"; for(int i=0;i<1000;i++){ writeln(str); } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto N = readln.chomp.to!int; bool[string] s; foreach (_; 0..N) { auto t = readln.chomp; s[t] = true; } s.keys.length.writeln; }
D