code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto ret = ""; auto h = readln.split[0].to!int; foreach (_; 0..h) { auto line = readln; ret ~= line ~ line; } write(ret); }
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 r; scan(r); auto ans = r*r; 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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N = lread(); auto cnt = new long[][](2, 30); cnt[1][] = long.max; foreach (i; 0 .. N) { auto S = sread(); cnt[i & 1][] = 0; foreach (c; S) cnt[i & 1][c - 'a']++; // writeln(cnt[i & 1]); foreach (j; 0 .. 30) cnt[i & 1][j] = cnt[(i + 1) & 1][j].min(cnt[i & 1][j]); } // writeln(cnt[(N + 1) & 1]); string ans; foreach (i; 0 .. 30) { ans ~= repeat(cast(char)('a' + i)).take(cnt[(N + 1) & 1][i]).array; } writeln(ans); }
D
import std.stdio; import std.string; import std.array; import std.conv; void main() { int A=to!int(chomp(readln())); int B=to!int(chomp(readln())); int C=to!int(chomp(readln())); int X=to!int(chomp(readln())); int ans=0; for(int i=0;i<=A;i++) { for(int j=0;j<=B;j++) { for(int k=0;k<=C;k++){ if(500*i+100*j+50*k==X) ans++; } } } writeln(ans); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nm = readln.split.to!(long[]); auto N = nm[0]; auto M = nm[1]; long al; long[long] AM = [0: 0]; foreach (i, a; readln.split.to!(long[])) { al = (al + a) % M; ++AM[al]; } long r = AM[0]; foreach (_, n; AM) r += n * (n-1) / 2; writeln(r); }
D
import std.stdio, std.algorithm, std.string; void main(){ readln.split.reduce!q{ a < b ?"<" : a==b ? "=" : ">" }.writeln; }
D
import std.algorithm; import std.math; import std.range; import std.ascii; import std.array; import std.container; import std.conv; import std.numeric; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } class UnreliableRollingHash(ulong P) { // fast but unreliable rolling hash // base is P, modulus is 2^64 ulong[] H; this(in string s) { auto N = s.length; this.H = new ulong[](N + 1); foreach (int i, c; s) { H[i + 1] = (H[i] * P + cast(int)(c)); } } ulong hash(int l, int r) { // [l, r) return H[r] - H[l] * pow(P, r - l); } } void main() { int N, M; scanf("%d %d\n", &N, &M); auto s = readln.chomp; auto hasher = new UnreliableRollingHash!991(s); int l = 0, r = 1; bool[ulong] appeared; foreach (_; 0 .. M) { auto q = readln.chomp; switch (q) { case "L++": l++; break; case "L--": l--; break; case "R++": r++; break; case "R--": r--; break; default: assert(false); } appeared[hasher.hash(l, r)] = true; } writeln(appeared.keys.length); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; immutable long MOD = 10^^9 + 7; void solve() { auto N = readln.chomp.to!int; auto S = readln.chomp; int ans = 1 << 29; foreach (i; 0..N) { if (S[i] == '>' || S[N - i - 1] == '<') { ans = i; break; } } ans.writeln; } void main() { auto T = readln.chomp.to!int; while (T--) solve; }
D
/+ dub.sdl: name "B" dependency "dcomp" version=">=0.7.3" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); int n; sc.read(n); int[] a; sc.read(a); a[]-=1; bool[] used = new bool[n]; int r = n-1; writeln(1); foreach (int i, d; a) { used[d] = true; while (r >= 0 && used[r]) r--; int s = 1 + (i+1) - (n-1-r); writeln(s); } return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.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); } } } } version (X86) static if (__VERSION__ < 2071) { import core.bitop : bsf, bsr, popcnt; int bsf(ulong v) { foreach (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int bsr(ulong v) { foreach_reverse (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int popcnt(ulong v) { int c = 0; foreach (i; 0..64) { if (v & (1UL << i)) c++; } return c; } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; // import dcomp.array; 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 { FastAppender!(E[]) buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } else { x = line.parse!T; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */ // module dcomp.array; T[N] fixed(T, size_t N)(T[N] a) {return a;} struct FastAppender(A, size_t MIN = 4) { import std.algorithm : max; import std.conv; import std.range.primitives : ElementEncodingType; import core.stdc.string : memcpy; private alias T = ElementEncodingType!A; private T* _data; private uint len, cap; @property size_t length() const {return len;} bool empty() const { return len == 0; } void reserve(size_t nlen) { import core.memory : GC; if (nlen <= cap) return; void* nx = GC.malloc(nlen * T.sizeof); cap = nlen.to!uint; if (len) memcpy(nx, _data, len * T.sizeof); _data = cast(T*)(nx); } void free() { import core.memory : GC; GC.free(_data); } void opOpAssign(string op : "~")(T item) { if (len == cap) { reserve(max(MIN, cap*2)); } _data[len++] = item; } void insertBack(T item) { this ~= item; } void removeBack() { len--; } void clear() { len = 0; } ref inout(T) back() inout { assert(len); return _data[len-1]; } ref inout(T) opIndex(size_t i) inout { return _data[i]; } T[] data() { return (_data) ? _data[0..len] : null; } } /* This source code generated by dcomp and include dcomp's source code. dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp) dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt) */
D
import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; import core.bitop; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } class Tree { int N; // Graph(Tree)???????????° int[][] G; // Graph(Tree)?????£??\???????????¨??? int[] D; // ????????????root??????????????¢ int LOG_N; // log2(N)????????? int[][] P; // P[k][v] : ??????v???2^k?????????????\? void dfs(int prev, int index, int d) { P[0][index] = prev; D[index] = d; for (int i = 0; i < G[index].size; i++) { int next = G[index][i]; if (next == prev) continue; dfs(index, next, d + 1); } } this(int[][] G) { this.N = G.size; this.G = G; this.LOG_N = bsr(N) + 1; this.P = new int[][](LOG_N, N); this.D = new int[N]; D[] = -1; dfs(-1, 0, 0); for (int k = 0; k < LOG_N - 1; k++) { for (int v = 0; v < N; v++) { if (P[k][v] < 0) P[k + 1][v] = -1; else P[k + 1][v] = P[k][ P[k][v] ]; } } } // ??????v???n????????????????????? int nth_parent(int v, int n) { for (int k = 0; k < LOG_N; k++) if (n & (1 << k)) v = P[k][v]; return v; } // 2??????u??¨v???LCA????????? int lca(int u, int v) { if (D[u] > D[v]) swap(u, v); v = nth_parent(v, D[v] - D[u]); if (u == v) return u; for (int k = LOG_N - 1; k >= 0; k--) { if (P[k][u] != P[k][v]) { u = P[k][u]; v = P[k][v]; } } return P[0][u]; } // 2??????u??¨v????????¢????????? int dist(int u, int v) { int root = lca(u, v); return (D[u] - D[root]) + (D[v] - D[root]); } } void main() { int N = readln.chomp.to!int; auto G = new int[][N]; for (int i = 0; i < N; i++) { int k; scanf("%d ", &k); for (int j = 0; j < k; j++) { int c; scanf("%d", &c); G[i] ~= c; } } auto t = new Tree(G); int Q; scanf("%d", &Q); for (int q = 0; q < Q; q++) { int u, v; scanf("%d %d", &u, &v); writeln(t.lca(u, v)); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int l; readV(l); auto r = l.bsr, n = r+1; struct Edge { int u, v, w; } Edge[] e; foreach (i; 1..n) { e ~= Edge(i, i+1, 0); e ~= Edge(i, i+1, 1<<(i-1)); } l -= (1<<r); auto t = (1<<r); while (l > 0) { r = l.bsr; e ~= Edge(r+1, n, t); l -= (1<<r); t += (1<<r); } writeln(n, " ", e.length); foreach (ei; e) writeln(ei.u, " ", ei.v, " ", ei.w); } pragma(inline) { pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; } pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); } pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); } pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); } pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); } pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); } pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); } import core.bitop; pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); } pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); } pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); } }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long n = read.to!long; char[][] ss; for(int i = 0; i < n; i ++) ss ~= readln.chomp.to!(char[]); int[char] count; foreach(c; "abcdefghijklmnopqrstuvwxyz") count[c] = int.max; foreach(s; ss){ int[char] tempcount; foreach(c; s){ tempcount[c] += 1; } foreach(c; count.keys){ if(c in tempcount){ if(tempcount[c] < count[c]) count[c] = tempcount[c]; } else count[c] = 0; } } string ans; foreach(c; "abcdefghijklmnopqrstuvwxyz") for(int i = 0; i < count[c]; i ++) ans ~= c; ans.writeln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias Pair = Tuple!(long, "number", long, "times"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { auto s = sread(); long[dchar] count; foreach (e; s) { count[e]++; } long remove; if ('0' in count && '1' in count) remove = min(count['0'], count['1']); writeln(remove * 2); }
D
import std.stdio,std.string,std.conv; int main() { string[] s = readln.chomp.split(" "); string len_max = s[0],ans = s[0]; int[string] map; int count_max = 1; foreach(i;0..(s.length)) { if(len_max.length < s[i].length) { len_max = s[i]; } map[s[i]]++; if(map[s[i]] > count_max) { count_max = map[s[i]]; ans = s[i]; } } writeln(ans," ",len_max); return 0; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto M = RD; auto D = RD; long ans; foreach (i; 0..M) { foreach (j; 0..D) { auto d1 = (j+1) % 10; auto d10 = (j+1) / 10; if (d1 >= 2 && d10 >= 2 && d1*d10 == i+1) { ++ans; } } } writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; alias Pair = Tuple!(int, "a", int, "b"); void main() { int N, M, L; scan(N, M, L); auto dist = new long[][](N, N); foreach (i ; 0 .. N) { foreach (j ; 0 .. N) { if (i != j) dist[i][j] = inf6; } } foreach (i ; 0 .. M) { int ai, bi, ci; scan(ai, bi, ci); ai--, bi--; dist[ai][bi] = dist[bi][ai] = ci; } foreach (k ; 0 .. N) { foreach (i ; 0 .. N) { foreach (j ; 0 .. N) { chmin(dist[i][j], dist[i][k] + dist[k][j]); } } } auto d = new int[][](N, N); foreach (i ; 0 .. N) { foreach (j ; 0 .. N) { if (i == j) { d[i][j] = 0; continue; } d[i][j] = dist[i][j] <= L ? 1 : inf; } } foreach (k ; 0 .. N) { foreach (i ; 0 .. N) { foreach (j ; 0 .. N) { chmin(d[i][j], d[i][k] + d[k][j]); } } } int Q; scan(Q); while (Q--) { int si, ti; scan(si, ti); si--, ti--; writeln(d[si][ti] < inf ? d[si][ti] - 1 : -1); } } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto d=new int[](n); foreach(i; 0..n) rd(d[i]); int r=0; foreach(int i, int e; d){ if(r<i*10){writeln("no"); return;} if(r<i*10+e) r=i*10+e; } reverse(d); r=0; foreach(int i, int e; d){ if(r<i*10){writeln("no"); return;} if(r<i*10+e) r=i*10+e; } writeln("yes"); } void chmax(T)(ref T x, T y){ if(x<y) x=y; } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; enum AEIOU = "aeiou"; void main() { auto c = readln[0]; writeln(AEIOU.canFind(c) ? "vowel" : "consonant"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, q; rd(n, q); while(q--){ int v, w; rd(v, w); v--; w--; if(n==1){writeln(v+1); continue;} auto fun(int i){ int ret=0; while(i>0) i=(i-1)/n, ret++; return ret; } auto dv=fun(v), dw=fun(w); foreach(_; 0..(dw-dv)) w=(w-1)/n; if(v==w){writeln(v+1); continue;} while(v!=w){ v=(v-1)/n; w=(w-1)/n; } writeln(v+1); } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } } void wr(T...)(T x){ import std.stdio; foreach(e; x) write(e, " "); 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 = 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 modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto N = RD; writeln((N+1)/2); stdout.flush; debug readln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto nm = readln.split.to!(int[]); writeln( (100 * (nm[0] - nm[1]) + 1900 * nm[1]) * (2^^nm[1]) ); }
D
import std.stdio; void main(){ int a; scanf("%d", &a); if(a>=30){ writeln("Yes"); }else{ writeln("No"); } }
D
void main() { problem(); } void problem() { const K = scan!long; long solve() { long ans; foreach(a; 1..K+1) { foreach(b; 1..K+1) { foreach(c; 1..K+1) { ans += a.gcd(b).gcd(c); } } } return ans; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.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); } // -----------------------------------------------
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; bool ans; foreach (i; 0..100) { auto remain = N - 4 * i; if (remain < 0) continue; if (remain % 7 == 0) ans = true; } writeln(ans ? "Yes" : "No"); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { bool[4][5][5] m; foreach(i;0..9) foreach(j,b;readln().chomp().map!"a!='0'"().array()) if(b) foreach(k;0..2) m[i/2+k*(i%2)][j+k*(1-i%2)][k*2+i%2]=true; string r; int x=0,y=0,d=0; do{ foreach(i;-1..3) { auto n = (d+i+4)%4; if(m[y][x][n]) { x += [1,0,-1,0][n]; y += [0,1,0,-1][n]; d=n; r~="RDLU"[n]; break; } } }while(x!=0 || y!=0); writeln(r); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long H, W; scan(H, W); auto A = new string[](H); foreach (i; 0 .. H) A[i] = sread(); string[] B; foreach (i; 0 .. H) if (A[i].any!"a == '#'") { B ~= A[i]; } auto C = new string[](B.length); foreach (i; 0 .. W) { bool b; foreach (j; 0 .. B.length) if (B[j][i] == '#') { b = true; break; } if (b) foreach (j; 0 .. B.length) { C[j] ~= B[j][i]; } } foreach (c; C) writeln(c); }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; void times(alias fun)(int n) { foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } // fold was added in D 2.071.0. 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); } } } void main() { readln.chomp.pipe!(str => (str.length%2==0) != (str.front==str.back) ).pipe!(a => a?"Second":"First").writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y", long, "cost"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto s = sread(); bool t; foreach (e; s) t |= e == '7'; if (t) writeln("Yes"); else writeln("No"); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio, std.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 S = readln.chomp; auto D = S.map!(c => c == 'D').sum; auto R = N - D; auto dead = new bool[](N); int can_kill_D, can_kill_R; while (D > 0 && R > 0) { foreach (i, c; enumerate(S)) { if (dead[i]) continue; if (c == 'D' && can_kill_D > 0) { D--; can_kill_D--; dead[i] = true; } else if (c == 'D') { can_kill_R++; } else if (c == 'R' && can_kill_R > 0) { R--; can_kill_R--; dead[i] = true; } else if (c == 'R') { can_kill_D++; } } } writeln(D > 0 ? "D" : "R"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; long a, b, c, x, y; rd(a, b, c, x, y); if(a+b<c*2){ writeln(x*a+y*b); }else{ auto z=min(x, y), ret=z*c*2; x-=z; y-=z; // writeln(ret); if(x>0){ ret+=x*min(a, c*2); }else if(y>0){ ret+=y*min(b, c*2); } writeln(ret); } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x) e=l[i].to!(typeof(e)); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}} void main() { string[] c; readC(2, c); writeln(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0] ? "YES" : "NO"); }
D
/+ dub.sdl: name "D" dependency "dcomp" version=">=0.6.0" +/ //ICPC Bangkok Regional 2016 F import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { auto sc = new Scanner(stdin); int n; sc.read(n); int[][] g = new int[][](n); foreach (i; 0..n-1) { int a, b; sc.read(a, b); a--; b--; g[a] ~= b; g[b] ~= a; } int dfs(int p, int b) { int sm = 0; foreach (d; g[p]) { if (d == b) continue; sm ^= dfs(d, p); } if (p != 0) sm++; return sm; } if (dfs(0, -1)) { writeln("Alice"); } else { writeln("Bob"); } return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.foundation; static if (__VERSION__ <= 2070) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } version (X86) static if (__VERSION__ < 2071) { import core.bitop : bsf, bsr, popcnt; int bsf(ulong v) { foreach (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int bsr(ulong v) { foreach_reverse (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int popcnt(ulong v) { int c = 0; foreach (i; 0..64) { if (v & (1UL << i)) c++; } return c; } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f) { this.f = f; } char[512] lineBuf; char[] line; private bool succ() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (true) { while (!line.empty && line.front.isWhite) { line.popFront; } if (!line.empty) break; if (f.eof) return false; line = lineBuf[]; f.readln(line); } return true; } private bool readSingle(T)(ref T x) { import std.algorithm : findSplitBefore; import std.string : strip; import std.conv : parse; if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { auto r = line.findSplitBefore(" "); x = r[0].strip.dup; line = r[1]; } else { auto buf = line.split.map!(to!E).array; static if (isStaticArray!T) { assert(buf.length == T.length); } x = buf; line.length = 0; } } else { x = line.parse!T; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void main(){ auto ip = readln.split.to!(int[]); if(ip[0] > ip[2]){ "NO".writeln; } else if(ip[2] - ip[0] <= ip[1]){ "YES".writeln; } else { "NO".writeln; } }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long n, d; scan(n, d); long cnt; foreach (_; 0 .. n) { long x, y; scan(x, y); if (x ^^ 2 + y ^^ 2 <= d ^^ 2) { cnt += 1; } } writeln(cnt); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto len = readln.chomp.to!long; auto as = readln.split; string[] ret; ret.length = len; size_t p = len / 2; auto v = len & 1 ? 1 : -1; foreach (i, a; as) { v = -v; p += i * v; ret[p] = a; } writeln(ret.join(" ")); }
D
import std.stdio; import std.string; import std.array; import std.range; import std.algorithm; import std.conv; import std.typecons; long solve(long d, long n){ if(n != 100){ return 100 ^^ d * n; }else{ return 100 ^^ (d+1) + 100 ^^ d; } } void main(){ auto dn = readln().chomp().split().map!(to!long).array(); auto d = dn[0]; auto n = dn[1]; solve(d, n).writeln(); }
D
void main() { auto b = rs; switch(b) { case "A": writeln("T"); break; case "T": writeln("A"); break; case "G": writeln("C"); break; case "C": writeln("G"); break; default: break; } } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; import std.math; import std.container; import std.bigint; import std.numeric; import std.conv; import std.typecons; import std.uni; import std.ascii; import std.bitmanip; import core.bitop; T readAs(T)() if (isBasicType!T) { return readln.chomp.to!T; } T readAs(T)() if (isArray!T) { return readln.split.to!T; } T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { auto s = rs; foreach(j; 0..width) res[i][j] = s[j].to!T; } return res; } int ri() { return readAs!int; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}} void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}} void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}} void main() { auto c = new int[][](3, 3); foreach (i; 0..3) readA(3, c[i]); writeln(c[1][1] == c[1][0]-c[0][0]+c[0][1] && c[1][2] == c[1][0]-c[0][0]+c[0][2] && c[2][1] == c[2][0]-c[0][0]+c[0][1] && c[2][2] == c[2][0]-c[0][0]+c[0][2] ? "Yes" : "No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!long; writeln(N * (N-1) / 2); }
D
import std.stdio; import std.string; import std.algorithm; import std.conv; void main() { int X, Y, r; auto input = readln.split.to!(int[]); X = input[0]; Y = input[1]; while(X%Y) { r = X%Y; X = Y; Y = r; } writeln(Y); }
D
import std.stdio; import std.conv; import std.string; void main() { int n = readln.chomp.to!int; if (n == 1){ "Hello World".writeln; return; } int a = readln.chomp.to!int; int b = readln.chomp.to!int; (a + b).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[] ds = readln.chomp.split.map!(to!long).array; long a = ds[0], b = ds[1], c = ds[2]; long ans; if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) ans = 0; else ans = min(a * b, a * c, b * c); ans.writeln; }
D
void main() { int n = readln.chomp.to!int; writeln(n * (n + 1) / 2); } 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; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long a, b, c, d; scan(a, b, c, d); auto tmp = new long[](100000); foreach (i; a .. b) { tmp[i] += 1; } foreach (i; c .. d) { tmp[i] += 1; } // writeln(tmp); long cnt; foreach (i; 0 .. tmp.length) { if (tmp[i] == 2) { cnt += 1; } } writeln(cnt); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio; import std.algorithm; import std.string; import std.conv; import std.math; void main(){ int ans=0; while(true){ auto s = readln(); if(stdin.eof()) break; s = chomp(s); int len = to!int(s.length); int l,r; if(len%2==1){ l = len/2 - 1; r = len/2 + 1; }else{ l = len/2 - 1; r = len/2; } bool flg = true; for(int i=0;i<to!int(len/2);i++){ if(s[l]!=s[r]) { flg = false; break; } l--; r++; } if(flg) ans++; } writeln(ans); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); writeln(s[0], s.length-2, s[$-1]); }
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.7.3" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); int n; sc.read(n); int[] g = new int[n]; foreach (i; 0..n-1) { int a, b, z; sc.read(a, b, z); g[a] ^= z; g[b] ^= z; } int f; int ans = g.count(0).to!int; foreach (d; 1..16) { int u = g.count(d).to!int; ans += u/2; if (u % 2) f |= (1<<d); } int[] ls; foreach (i; 1..(1<<16)) { int x = 0; foreach (j; 0..16) { if (i & (1<<j)) x ^= j; } if (x == 0) ls ~= i.to!int; } int[] dp = new int[1<<16]; foreach (i; 0..(1<<16)) { if (i & ~f) continue; foreach (d; ls) { if (d & ~i) continue; if (d > i) break; dp[i] = max(dp[i], dp[i^d]+1); } } ans += dp[f]; writeln(n - ans); return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.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); } } } } version (X86) static if (__VERSION__ < 2071) { import core.bitop : bsf, bsr, popcnt; int bsf(ulong v) { foreach (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int bsr(ulong v) { foreach_reverse (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int popcnt(ulong v) { int c = 0; foreach (i; 0..64) { if (v & (1UL << i)) c++; } return c; } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; // import dcomp.array; 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 { FastAppender!(E[]) buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } else { x = line.parse!T; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */ // module dcomp.array; T[N] fixed(T, size_t N)(T[N] a) {return a;} struct FastAppender(A, size_t MIN = 4) { import std.algorithm : max; import std.conv; import std.range.primitives : ElementEncodingType; import core.stdc.string : memcpy; private alias T = ElementEncodingType!A; private T* _data; private uint len, cap; @property size_t length() const {return len;} bool empty() const { return len == 0; } void reserve(size_t nlen) { import core.memory : GC; if (nlen <= cap) return; void* nx = GC.malloc(nlen * T.sizeof); cap = nlen.to!uint; if (len) memcpy(nx, _data, len * T.sizeof); _data = cast(T*)(nx); } void free() { import core.memory : GC; GC.free(_data); } void opOpAssign(string op : "~")(T item) { if (len == cap) { reserve(max(MIN, cap*2)); } _data[len++] = item; } void insertBack(T item) { this ~= item; } void removeBack() { len--; } void clear() { len = 0; } ref inout(T) back() inout { assert(len); return _data[len-1]; } ref inout(T) opIndex(size_t i) inout { return _data[i]; } T[] data() { return (_data) ? _data[0..len] : null; } } /* This source code generated by dcomp and include dcomp's source code. dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp) dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt) */
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { auto s = readln().chomp().to!(char[]); reverse(s); writeln(s); }
D
import std.stdio, std.string, std.algorithm, std.conv, std.range, std.math; void main() { auto p = readln.chomp.split.map!(to!double); auto ans = sqrt(pow(p[2] - p[0], 2) + pow(p[3] - p[1], 2)); printf("%.8lf\n", ans); }
D
void main(){ string n = readln().chomp(); writeln(n.count('9')==0? "No": "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; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long a, b, c, d; scan(a, b, c, d); max(a * c, b * c, a * d, b * d).writeln(); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { immutable N = 8; immutable n = readln().chomp().to!int(); foreach(i;0..n) { readln(); auto m = iota(N).map!(_=>readln.chomp().to!(char[])()).array(); immutable x = readln().chomp().to!int(); immutable y = readln().chomp().to!int(); void dfs(int x, int y) { if(x<0 || N<=x || y<0 || N<=y || m[y][x]=='0') return; m[y][x]='0'; foreach(d;[[1,0],[-1,0],[0,1],[0,-1]]) foreach(k;1..4) dfs(x+d[0]*k,y+d[1]*k); } dfs(x-1,y-1); writeln("Data ",i+1,":"); m.join("\n").writeln(); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long a = lread(); long b = lread(); long h = lread(); writeln((a + b) * h / 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; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N = lread(); string[] itos; void init(string S) { if (S.length == 3) { itos ~= S; return; } foreach (c; "ACGT") init(S ~ c); return; } init(""); long M = itos.length; long[string] stoi; foreach (i; 0 .. M) stoi[itos[i]] = i; auto dp = new long[][](N + 1, M); foreach (i; 0 .. M) { dp[3][i] = (itos[i] != "AGC" && itos[i] != "ACG" && itos[i] != "GAC"); } foreach (i; 3 .. N) { foreach (j; 0 .. M) { if (itos[j] == "AGC" || itos[j] == "ACG" || itos[j] == "GAC") continue; foreach (c; "ACGT") { string s4 = itos[j] ~ c; // writeln(s4); string s3 = s4[1 .. $]; if (s3 == "AGC" || s3 == "ACG" || s3 == "GAC") continue; if (s4[0] == 'A' && s4[2 .. $] == "GC") continue; if (s4[0 .. 2] == "AG" && s4[$ - 1] == 'C') continue; dp[i + 1][stoi[s3]] += dp[i][j]; dp[i + 1][stoi[s3]] %= MOD; } } // writeln(dp[i]); } long ans; foreach (a; dp[N]) ans = (ans + a) % MOD; writeln(ans); }
D
import std.stdio; import std.algorithm; import std.string; import std.range; import std.array; import std.conv; import std.complex; import std.math; import std.ascii; import std.bigint; import std.container; bool isConnected(int[26][] c) { bool[26] appear; foreach(i; 0..26) { foreach(j; 0..26) { if(c[i][j]) { appear[i] = true; appear[j] = true; } } } bool[26] arrived; int[] next; foreach(i; 0..26){ foreach(j; 0..26) { if(c[i][j]){ arrived[i] = true; arrived[j] = true; next ~= j; } } if(!next.empty()) break; } while(!next.empty()) { int[] newNext; foreach(t; next) { foreach(i; 0..26) { if(!arrived[i] && c[t][i]){ arrived[i] = true; newNext ~= i; } } } next = newNext; } return appear == arrived; } bool isEuler(int[26][] c) { foreach(i; 0..26) { int to, from; foreach(j; 0..26) { to += c[j][i]; from += c[i][j]; } if(to != from) return false; } return true; } void main() { auto n = to!int(readln().strip()); while(n) { int[26][26] c; bool[26] appear; foreach(i; 0..n) { auto l = readln().strip(); int s = l[0]-'a'; int t = l[$-1]-'a'; appear[s] = true; appear[t] = true; ++c[s][t]; } if(isConnected(c) && isEuler(c)) writeln("OK"); else writeln("NG"); n = to!int(readln().strip()); } }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { auto n = lread(); auto a = aryread(); // writeln(a); auto s = new long[](n + 1); s[1] = a[0]; foreach (i; 1 .. n) { s[i + 1] = s[i] + a[i]; } // writeln("s:", s); long ans = long.max; foreach (i; 0 .. n - 1) { // writeln(a[0 .. i + 1], a[i + 1 .. $]); //sを使って左と右の長さを求める // s[i + 1].writeln(); //左 // (s[$ - 1] - s[i + 1]).writeln(); //右 ans = min(ans, abs(s[i + 1] - (s[$ - 1] - s[i + 1]))); } writeln(ans); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { writeln(readln.chomp[0..$-8]); }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { auto a = readln.split.map!(to!int); if (a[0] >= a[1]) { writeln("No"); return; } if (a[1] >= a[2]) { writeln("No"); return; } writeln("Yes"); }
D
import std.stdio, std.conv, std.array,std.string; void main() { string[] input=readln.split; int a=input[0].to!int,b=input[1].to!int; writeln((a-1)*(b-1)); }
D
import std.stdio; import std.string; char[8][8] ch; void main(){ foreach (i; 0..8) ch[i] = chomp(readln()); for (int i = 1; i <= 3; i++) { rotate(); writeln(i*90); print(); } } void rotate(){ char[8][8] tmp; foreach (i; 0..8) foreach (j; 0..8) tmp[i][j] = ch[7-j][i]; foreach (i; 0..8) foreach (j; 0..8) ch[i][j] = tmp[i][j]; } void print(){ foreach (i; 0..8) { foreach (j; 0..8) { write(ch[i][j]); } writeln(); } }
D
import std.algorithm, std.string, std.array, std.stdio, std.range, std.conv; void main() { int[] AB = readln.chomp.split.to!(int[]); int A = AB[0], B = AB[1]; writeln([(A % 3), (B % 3), ((A + B) % 3)].any!(x => x == 0) ? "Possible" : "Impossible"); }
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 arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;} void scan(TList...)(ref TList Args){auto line = readln.split; foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}} void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length); static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}} alias sread=()=>readln.chomp();enum MOD =10^^9+7; alias PQueue(T,alias less="a<b") = BinaryHeap!(Array!T,less); // dfmt on void main() { auto S = sread(); auto T = sread(); writeln(S == T[0 .. $ - 1] ? "Yes" : "No"); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long a,b,c; scan(a,b,c); if(a == b) { writeln(c); } if(b == c) { writeln(a); } if(c == a) { writeln(b); } }
D
void main() { long n = readln.chomp.to!long; bool[] cards = new bool[n]; long pair; foreach (i; 0 .. n) { long a = readln.chomp.to!long; if (i > 0 && cards[i-1] && a > 0) { ++pair; --a; } pair += a / 2; cards[i] = a % 2 == 1; } pair.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test ABCABC ---+/ /+---test C ---+/ /+---test ABCACCBABCBCAABCB ---+/ void main(string[] args) { const S = readln.chomp.replace("BC", "D").splitter!(x => x == 'B' || x == 'C').array; long ans; foreach (S1; S) { long a_cnt; foreach (s; S1) { if (s == 'A') { ++a_cnt; } else { ans += a_cnt; } } } ans.writeln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new string[](t); foreach (ti; 0..t) { auto s = RD!string; char c = 'z'; size_t pos; foreach (i, e; s) { if (e < c) { pos = i; c = e; } } ans[ti] = [c, ' ']; foreach (i, e; s) { if (i == pos) continue; ans[ti] ~= e; } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio; import std.array; import std.string; import std.algorithm; string[char] next; static this() { next = [ 'A': "BD", 'B': "ACE", 'C': "BF", 'D': "AEG", 'E': "BDFH", 'F': "CEI", 'G': "DH", 'H': "EGI", 'I': "FH" ]; } bool movable(char c, char t) { return !next[c].find(t).empty; } void main() { loop: foreach (_; 0 .. 1000) { string s = readln.chomp; foreach (i; 1 .. s.length) { if (!s[i - 1].movable(s[i])) { continue loop; } } s.writeln; } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}} void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}} void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}} void main() { int a, b, k; readV(a, b, k); if (a+k-1 < b-k+1) { foreach (i; a..a+k) writeln(i); foreach (i; b-k+1..b+1) writeln(i); } else { foreach (i; a..b+1) writeln(i); } }
D
void main() { problem(); } void problem() { auto N = scan!int; string solve() { int hon, pon, bon; int n = N % 10; if (n == 3) { return "bon"; } if (n == 0 || n == 1 || n == 6 || n == 8) { return "pon"; } return "hon"; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } alias Point = Tuple!(long, "x", long, "y"); // -----------------------------------------------
D
void main() { auto K = ri; auto S = rs; if(S.length <= K) writeln(S); else { writeln(S[0..K] ~ "..."); } } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; import std.math; import std.container; import std.bigint; import std.numeric; import std.conv; import std.typecons; import std.uni; import std.ascii; import std.bitmanip; import core.bitop; T readAs(T)() if (isBasicType!T) { return readln.chomp.to!T; } T readAs(T)() if (isArray!T) { return readln.split.to!T; } T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { auto s = rs; foreach(j; 0..width) res[i][j] = s[j].to!T; } return res; } int ri() { return readAs!int; } long rl() { return readAs!long; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
D
import std.stdio; import std.string; import std.array; // split import std.conv; // to void main() { string n = chomp(readln()); int a = to!int(n); if(a%10 == a/100){ writeln("Yes"); } else { writeln("No"); } }
D
/+ dub.sdl: name "F" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; // import dcomp.datastructure.lazyseg; int main() { auto sc = new Scanner(stdin); int n, m; sc.read(n, m); int[] l = new int[n], r = new int[n]; int[][] rg = new int[][m+2]; foreach (i; 0..n) { sc.read(l[i], r[i]); rg[r[i]] ~= i; } auto seg = LazySeg!(int, int, (a, b) => min(a, b), (a, b) => a+b, (a, b) => a+b, 10^^9, 0)(m+2); foreach (i; 0..m+2) { seg[i] = i; } int ans = min(n, m); int off = n; foreach_reverse (ri; 2..m+2) { //right use [ri .. m+1] int buf = m+1 - ri; //add r[i] = ri foreach (i; rg[ri]) { off--; seg[0..l[i]] += 1; } ans = min(ans, buf + off + seg[0..ri-1].sum()); } writeln(n - ans); return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */ // module dcomp.foundation; static if (__VERSION__ <= 2070) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } version (X86) static if (__VERSION__ < 2071) { import core.bitop : bsf, bsr, popcnt; int bsf(ulong v) { foreach (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int bsr(ulong v) { foreach_reverse (i; 0..64) { if (v & (1UL << i)) return i; } return -1; } int popcnt(ulong v) { int c = 0; foreach (i; 0..64) { if (v & (1UL << i)) c++; } return c; } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f) { this.f = f; } char[512] lineBuf; char[] line; private bool succ() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (true) { while (!line.empty && line.front.isWhite) { line.popFront; } if (!line.empty) break; if (f.eof) return false; line = lineBuf[]; f.readln(line); } return true; } private bool readSingle(T)(ref T x) { import std.algorithm : findSplitBefore; import std.string : strip; import std.conv : parse; if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { auto r = line.findSplitBefore(" "); x = r[0].strip.dup; line = r[1]; } else { auto buf = line.split.map!(to!E).array; static if (isStaticArray!T) { assert(buf.length == T.length); } x = buf; line.length = 0; } } else { x = line.parse!T; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/datastructure/lazyseg.d */ // module dcomp.datastructure.lazyseg; struct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) { const int n, sz, lg; T[] d; L[] lz; @disable this(); this(int n) { import std.algorithm : fill, each; import core.bitop : bsr; if (n == 0) return; int lg = n.bsr; if ((2^^lg) < n) lg++; this.n = n; this.sz = 2^^lg; this.lg = lg; d = new T[](2*this.sz); d.each!((ref x) => x = eT); lz = new L[](2*this.sz); lz.each!((ref x) => x = eL); } private void lzAdd(int k, L x) { d[k] = opTL(d[k], x); lz[k] = opLL(lz[k], x); } private void push(int k) { if (lz[k] == eL) return; lzAdd(2*k, lz[k]); lzAdd(2*k+1, lz[k]); lz[k] = eL; } T sum(int a, int b, int l, int r, int k) { if (b <= l || r <= a) return eT; if (a <= l && r <= b) return d[k]; push(k); int md = (l+r)/2; return opTT(sum(a, b, l, md, 2*k), sum(a, b, md, r, 2*k+1)); } T single(int k) { k += sz; foreach_reverse (int i; 1..lg+1) { push(k>>i); } return d[k]; } void singleSet(T x, int k) { k += sz; foreach_reverse (int i; 1..lg+1) { push(k>>i); } d[k] = x; foreach (int i; 1..lg+1) { d[k>>i] = opTT(d[2*(k>>i)], d[2*(k>>i)+1]); } } T sum(int a, int b) { assert(0 <= a && a <= b && b <= n); return sum(a, b, 0, sz, 1); } void add(int a, int b, L x, int l, int r, int k) { if (b <= l || r <= a) return; if (a <= l && r <= b) { lzAdd(k, x); return; } push(k); int md = (l+r)/2; add(a, b, x, l, md, 2*k); add(a, b, x, md, r, 2*k+1); d[k] = opTT(d[2*k], d[2*k+1]); } void add(int a, int b, L x) { assert(0 <= a && a <= b && b <= n); add(a, b, x, 0, sz, 1); } @property int opDollar() const {return sz;} struct Range { LazySeg* seg; int start, end; @property T sum() { return seg.sum(start, end); } } T opIndex(int k) { assert(0 <= k && k < n); return single(k); } void opIndexAssign(T x, int k) { assert(0 <= k && k < n); singleSet(x, k); } int[2] opSlice(size_t dim)(int start, int end) { assert(0 <= start && start <= end && end <= sz); return [start, end]; } Range opIndex(int[2] rng) { return Range(&this, rng[0], rng[1]); } void opIndexOpAssign(string op : "+")(L x, int[2] rng) { add(rng[0], rng[1], x); } }
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; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } class X{ } void main(){ // A=1、B=2として、区間の合計を3で割った余りが一致すればYES。一致しなければNO // xs[i]はSの先頭i文字を3で割った余りを保持する // ys[i]はTの先頭i文字を3で割った余りを保持する // 求めるものは (xs[b] - xs[a - 1]) == (ys[d] - ys[c - 1]) string s = readln.chomp; string t = readln.chomp; int[] xs = [0]; int x = 0; foreach(c; s){ if(c == 'A') x += 1; else x += 2; xs ~= x; } debug xs.writeln; int[] ys = [0]; int y = 0; foreach(c; t){ if(c == 'A') y += 1; else y += 2; ys ~= y; } debug ys.writeln; int q = read.to!int; for(int i = 0; i < q; i ++){ int a = read.to!int; int b = read.to!int; int c = read.to!int; int d = read.to!int; string ans; if((xs[b] - xs[a - 1]) % 3 == (ys[d] - ys[c - 1]) % 3) ans = "YES"; else ans = "NO"; ans.writeln; } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.typecons; void main() { auto input = split(readln()); auto N = to!int(input[0]); long aM, aA, aR, aC, aH; // the number of the names that starts with ... foreach(i; 0..N) { auto S = split(readln())[0]; aM += (S[0] == 'M'? 1 : 0); aA += (S[0] == 'A'? 1 : 0); aR += (S[0] == 'R'? 1 : 0); aC += (S[0] == 'C'? 1 : 0); aH += (S[0] == 'H'? 1 : 0); } writeln( aM*aA*(aR+aC+aH) + aM*aR*(aC+aH) + aM*aC*aH + aA*aR*(aC+aH) + aA*aC*aH + aR*aC*aH ); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { long a, b, c; scan(a, b, c); auto ans = b; if (a + b >= c) { ans += c; } else { long t = a + b + 1; ans += t; } writeln(ans); } void scan(T...)(ref T args) { auto line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront; } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x > arg) { x = arg; isChanged = true; } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x < arg) { x = arg; isChanged = true; } return isChanged; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.net.curl, std.net.isemail, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.socket, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib; /*}}}*/ /+---test 5 1 3 5 4 2 ---+/ /+---test 9 9 6 3 2 5 8 7 4 1 ---+/ void main(string[] args) { readln; const P = readln.split.map!(to!long).array; long ans; foreach (i; 1..P.length-1) { if (min(P[i-1], P[i+1]) < P[i] && P[i] < max(P[i-1], P[i+1])) ++ans; } ans.writeln; }
D
import std.stdio; import std.numeric; import std.math; import std.algorithm; import std.string; import std.container; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } void main() { int p, q; scanf("%d %d\n", &p, &q); q /= gcd(p, q); int ans = 1; for (int n = 2; n * n <= q; n++) { if (q % n == 0) { while (q % n == 0) q /= n; ans *= n; } } ans *= q; writeln(ans); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; long ans; foreach (i; 1..N+1) { if (i % 2 == 0) continue; long cnt; foreach (j; 1..i+1) { if (i % j == 0) ++cnt; } if (cnt == 8) ++ans; } writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv; void main() { int a = readln.chomp.to!int; string s = readln.chomp; writeln(a >= 3200 ? s : "red"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.math; auto s=readln.chomp.to!(char[]); char[] t; foreach(c; s)if(c!='x') t~=c; bool ok=true; foreach(i; 0..(t.length/2)) ok&=(t[i]==t[$-i-1]); if(!ok){writeln(-1); return;} int cnt=0; int[] y; foreach(c; s){ if(c=='x'){ cnt++; }else{ y~=cnt; cnt=0; } } y~=cnt; int sum=0; foreach(i; 0..(y.length/2)) sum+=(y[i]-y[$-i-1]).abs; writeln(sum); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
D
import std.stdio; void main() { int n, q; scanf("%d %d\n", &n, &q); auto c1 = 'X'; int cnt = 0; int[] cache = []; auto s = readln; foreach (c; s) { if (c1 == 'A' && c == 'C') { ++cnt; } c1 = c; cache ~= cnt; } foreach(_;0..q) { int l, r; scanf("%d %d", &l, &r); writeln(cache[r-1] - cache[l-1]); } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void main() { auto n = RD!int; auto s = RD!string; long l, r; foreach (i; 0..n) { if (s[i] == 'L') ++l; else ++r; } writeln(l+r+1); stdout.flush; debug readln; }
D
import std.stdio,std.conv,std.string; void main(){ auto args = readln().chomp().split(); auto a = to!int(args[0]); auto b = to!int(args[1]); writeln( a<b?"a < b":a==b?"a == b":"a > b" ); }
D
import std.stdio, std.array, std.conv; void main(){ string s; int i = 0,j = 0; int[] result; for(;;){ s=readln(); if(stdin.eof()) break; result.length += 1; string[] input = split(s); int a = to!int(input[0]); int b = to!int(input[1]); int k = 0; int keta = 1; while(a+b >= keta){ keta *= 10; ++k; } result[i] = k; ++i; } while(j < result.length){ writeln(result[j]); ++j; } }
D
void main() { string s = readln.chomp; writeln( s.canFind('N') == s.canFind('S') && s.canFind('W') == s.canFind('E') ? "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.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } /* x: i日目にAをするときの最大 y: i日目にBをするときの最大 z: i日目にCをするときの最大 漸化式は x = as[i] + max(y, z) y = bs[i] + max(x, z) z = cs[i] + max(x, y) */ void main(){ long n = read.to!long; long[3][] xs; foreach(i; 0 .. n){ xs ~= [read.to!long, read.to!long, read.to!long]; } long[3] ans = [0, 0, 0]; foreach(x; xs){ ans = [ x[0] + max(ans[1], ans[2]), x[1] + max(ans[0], ans[2]), x[2] + max(ans[0], ans[1]) ]; } max(ans[0], ans[1], ans[2]).writeln; }
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 A = to!uint(tokens[0]); auto B = to!uint(tokens[1]); auto K = to!uint(tokens[2]); foreach (i; 0..K) { if (i % 2 == 0) { if (A % 2 == 1) --A; B += A / 2; A /= 2; } else { if (B % 2 == 1) --B; A += B / 2; B /= 2; } } writeln(A, " ", B); stdout.flush(); }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; enum MAX = 1_000_100; ulong MOD = 1_000_000_007; ulong INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias Pair = Tuple!(long, "a", long, "b"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto n = lread(); if(n % 2) { writeln(0); } else { long five_cnt; n /= 2; while(n > 0) { n /= 5; five_cnt += n; } writeln(five_cnt); } } 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; } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto N = readln.chomp.to!int; int ret; foreach (_; 0..N) { auto lr = readln.split.to!(int[]); ret += lr[1] - lr[0] + 1; } writeln(ret); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N = lread(); auto B = new string[](N); foreach (i; 0 .. N) B[i] = sread(); long M = lread(); auto R = new string[](M); foreach (i; 0 .. M) R[i] = sread(); long[string] d; foreach (b; B) d[b] = d.get(b, 0) + 1; foreach (r; R) d[r] = d.get(r, 0) - 1; long ans = 0; foreach (k, v; d) ans = ans.max(v); writeln(ans); }
D
void main() { string[] s = readln.split; foreach (i; 0 .. 3) { s[i][0].toUpper.write; } writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.uni;
D
import std.stdio; import std.algorithm; import std.conv; import std.string; import std.range; import std.math; void main() { while (true) { int n = readln.chomp.to!int; if (n == 0) break; int[] s; foreach (i; 0..n) { s ~= readln.chomp.to!int; } writeln((s.reduce!("a + b") - s.minPos[0] - s.minPos!("a > b")[0]) / (n - 2)); } }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long n, m; scan(n, m); auto 色 = new bool[](n); 色[0] = true; auto 個数 = new long[](n); 個数[] = 1; foreach (i; 0 .. m) { long x, y; scan(x, y); // writeln(x, y); 個数[x - 1] -= 1; 個数[y - 1] += 1; if (色[x - 1]) { 色[y - 1] = true; } if (個数[x - 1] == 0) { 色[x - 1] = false; } } // writeln(個数); // writeln(色); long cnt; foreach (i; 0 .. n) { if (色[i] == true && 個数[i] >= 0) { cnt += 1; } } writeln(cnt); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto a = readln.chomp.split.map!(to!int); auto b = new int[](n); int cnt; foreach (i; 0..n) { if (a[i] < i+1) { if (b[a[i]-1] == i+1) { cnt++; } } else { b[i] = a[i]; } } cnt.writeln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { auto s = sread(); writeln(s.map!(c => cast(long)(c - '0')).sum()); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { string s = readln.chomp; if (s[0] != 'A') { writeln("WA"); return; } if (s[2..$-1].count('C') != 1) { writeln("WA"); return; } string po = s.toLower; for (int i = 0; i < s.length; i++) { if ((s[i] != 'A' && s[i] != 'C') && s[i] != po[i]) { writeln("WA"); return; } } writeln("AC"); }
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; 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; } enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int w, a, b; scan(w, a, b); auto ans = max(0, b - (a + w), a - (b + w)); writeln(ans); }
D
import std.stdio; import std.algorithm; import std.range; import std.conv; void main() { string[] input = split(readln()); int n = to!int(input[0]); int a = to!int(input[1]); int b = to!int(input[2]); bool check() { if (a+b-1 > n) return false; if (long(a)*b < n) return false; return true; } if (!check()) { writeln(-1); return; } int[] num = new int[a]; int sum = b; num[0] = b; foreach (i; 1..a) { num[i] = 1; sum++; } while (sum < n) { foreach (i; 1..a) { if (sum == n) break; num[i]++; sum++; } } int[] ans = new int[n]; int x = 1; foreach (i; 0..a) { foreach_reverse (j; x..x+num[i]) { ans[j-1] = x++; } } foreach (i; ans) { writeln(i); } }
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 x = readln.chomp.to!int; writeln(x < 1200 ? "ABC" : "ARC"); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y", long, "cost"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long n, k; scan(n, k); auto l = n / k; writeln(min(n - l * k, abs(n - (l + 1) * k))); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D