code
stringlengths
4
1.01M
language
stringclasses
2 values
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto A = sread(); long N = A.length; auto cnt = new long[]('z' - 'a' + 1); foreach (c; A) cnt[c - 'a']++; writeln(N * (N - 1) / 2 - cnt.map!"a*(a-1)/2"().sum() + 1); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto n=readln.chomp.to!(int); foreach(b; 0..(1<<3)){ auto tmp=n, sum=0; foreach(i; 0..3){ if((b>>i)&1) sum+=tmp%10; else sum-=tmp%10; tmp/=10; } sum+=tmp; if(sum==7){ char[] s; foreach(i; 0..3){ s~=(n%10)+'0'; s~=(b>>i)&1 ? '+' : '-'; n/=10; } s~=n+'0'; reverse(s); writeln(s~"=7"); return; } } assert(false); } 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
void main(){ string[] val = inln!string(); writeln( (val[0]=="H")^(val[1]=="H")?'D':'H'); } 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.algorithm; import std.range; import std.conv; void main() { string[] input = split(readln()); long n = to!long(input[0]); long m = to!long(input[1]); if (n > m) swap(n,m); long ans = 0; if (n == 1) { ans = max(0, m-2); if (m == 1) ans = 1; } else { ans = (n-2)*(m-2); } writeln(ans); }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n; scan(n); int ans; foreach (i ; 0 .. n) { int li, ri; scan(li, ri); ans += ri - li + 1; } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import 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[string] d; foreach (_; 0 .. lread()) { auto s = sread(); if (s !in d) { d[s] = 0; } d[s]++; } foreach (_; 0 .. lread()) { auto s = sread(); if (s !in d) { d[s] = 0; } d[s]--; } d.values.reduce!max().max(0).writeln(); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto ss = reads!(string).map!(toUpper); writeln(ss[0][0], ss[1][0], ss[2][0]); }
D
import std.stdio; import std.string; import std.conv; int main() { while (true) { string[] str = readln().chomp().split(); int n = str[0].to!int; int m = str[1].to!int; if (m == n && n == 0) break; int[1001] ans; int c = n - 1; for (int i = 0; i < n; i++) ans[i] = i + 1; while (n > 1) { c = (c + m) % n; for (int i = c; i < n - 1; i++) ans[i] = ans[i + 1]; n--; c--; } writeln(ans[0]); } return 0; }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; auto n = readln.chomp.to!(char[]); auto dp = new long[][][][](n.length + 1, 2, 1000, 2); dp[0][0][0][0] = 1; foreach (i; 0 .. (n.length)) { foreach (l; 0 .. 2) { foreach (k; 0 .. 1000) { foreach (ok; 0 .. 2) { auto x = k / 100, y = (k / 10) % 10, z = k % 10; auto d = l ? 9 : (n[i] - '0'); for (int digit = 0; digit <= d; digit++) { auto less = l || (digit < d); auto okok = ok || (x == 5 && y == 1 && digit == 3); dp[i + 1][less][y * 100 + z * 10 + digit][okok] += dp[i][l][k][ok]; } } } } } long s = 0; foreach (j; 0 .. 2) { foreach (k; 0 .. 1000) { s += dp[n.length][j][k][1]; } } writeln(s); } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; auto l = readln.split; assert(l.length == x.length); foreach (i, ref e; x) e = l[i].to!(typeof(e)); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.container; import std.bigint; void main() { readln.chomp.toUpper.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 bool[](t); foreach (ti; 0..t) { auto l = RD; auto r = RD; auto a = r+1; ans[ti] = l*2 >= a; } foreach (e; ans) writeln(e ? "YES" : "NO"); stdout.flush; debug readln; }
D
import std.stdio; import std.string; import std.conv; import std.math; void main() { string[] inputs = split(readln()); //int r = to!int(inputs[0]); int g = to!int(inputs[1]); int b = to!int(inputs[2]); if((10*g + b) % 4 == 0) "YES".writeln; else "NO".writeln; }
D
import std.stdio; import std.conv; import std.array; void main() { int N = readln.split[0].to!int; int[] H = readln.split.to!(int[]); int max = 0; int ans = 0; foreach (h; H){ if (h >= max){ ans++; max = h; } } writeln(ans); }
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); } enum MOD = (10 ^^ 9) + 7; void main() { long W, a, b; scan(W, a, b); solve(W, a, b).writeln(); } long solve(long W, long a, long b) { if (a + W < b) { return b - (a + W); } if (b + W < a) { return a - (b + W); } return 0; }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { auto x = lread(); if (x < 1200) { writeln("ABC"); return; } writeln("ARC"); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
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; } long calc(int n, int s) { long rec(int p, int sum, int to, long[][][] memo) { if (to > 0 && memo[p][to][sum] >= 0) return memo[p][to][sum]; if (p == n) { return sum == s ? 1 : 0; } long ans = 0; for (int i = to + 1; i <= 100; i++) { if (sum + i > s) break; ans += rec(p + 1, sum + i, i, memo); } if (to > 0) memo[p][to][sum] = ans; return ans; } auto memo = new long[][][](n + 1, 101, 1001); for (int i = 0; i < n + 1; i++) { for (int j = 0; j < 101; j++) { for (int k = 0; k < 1001; k++) memo[i][j][k] = -1L; } } return rec(0, 0, -1, memo); } void main() { string t; while ((t = readln.chomp).length > 0) { auto ns = t.split.map!(to!int).array; int n = ns[0], s = ns[1]; if (n == 0 && s == 0) break; writeln(calc(n, s)); } }
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, "p", long, "dist"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long sx, sy, tx, ty; scan(sx, sy, tx, ty); foreach (_; iota(tx - sx)) write('R'); foreach (_; iota(ty - sy)) write('U'); foreach (_; iota(tx - sx)) write('L'); foreach (_; iota(ty - sy)) write('D'); write('D'); foreach (_; iota(tx - sx + 1)) write('R'); foreach (_; iota(ty - sy + 1)) write('U'); write('L'); write('U'); foreach (_; iota(tx - sx + 1)) write('L'); foreach (_; iota(ty - sy + 1)) write('D'); writeln('R'); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
module c; import std.conv, std.stdio; import std.algorithm, std.array, std.string, std.range; void main() { auto buf = readln.chomp.split.to!(long[]); auto n = buf[0], k = buf[1]; n = n % k; n.min(k-n).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; string s; cin.scan(s); int ans; foreach (c; s) { ans += c - '0'; } writeln(max(ans, s[0] - '0' - 1 + 9.repeat.take(s.length - 1).sum)); }
D
import std.stdio, std.array, std.string, std.conv; void main() { int n = to!int(chomp(readln())); string[] a = split(readln()); for (int i = n - 1; i >= 0; --i) { write(a[i]); write(i ? " ": "\n"); } }
D
import std.stdio;import std.conv;import std.algorithm;import std.array; void main() { auto it = readln().split().map!(to!int); writeln(it[0]*it[1]," ",(it[0]+it[1])*2); }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; void main() { int[] abc = readln.chomp.split.to!(int[]); if(abc[0]!=abc[1]&&abc[1]==abc[2] || abc[0]!=abc[1]&&abc[0]==abc[2] || abc[0]==abc[1]&&abc[1]!=abc[2]) writeln("Yes"); else writeln("No"); }
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; scan(n); auto s = readln.chomp.to!string; auto pf = new int[](n + 1); foreach (i ; 1 .. n + 1) { pf[i] = pf[i-1] | (1 << (s[i-1] - 'a')); } auto sf = new int[](n + 1); foreach_reverse (i ; 0 .. n) { sf[i] = sf[i+1] | (1 << (s[i] - 'a')); } int ans; foreach (i ; 0 .. n) { ans = max(ans, popcnt(pf[i] & sf[i])); } 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
// Your code here! 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>b) writeln(a-1); else writeln(a); }
D
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.typecons, std.numeric, std.math; void main() { auto n = readln.chomp.to!int; auto DP = new long[](n+1); DP[0] = 1; DP[1] = 1; foreach (i; 2..n+1) { DP[i] = DP[i-1] + DP[i-2]; } writeln(DP[n]); }
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; string S; string trueStr = "keyence"; sc.scan(S); foreach (i; 0 .. trueStr.length) { if (S[0 .. i] ~ S[$ - (trueStr.length - i) .. $] == trueStr) { writeln("YES"); return; } } writeln("NO"); }
D
import std.functional, std.algorithm, std.typecons, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv, std.math; T read_num(T)() { return readln.chomp.to!T; } T min(T)(T a, T b) { return a < b ? a : b; } void main() { long N = read_num!long; long A = read_num!long; long B = read_num!long; long C = read_num!long; long D = read_num!long; long E = read_num!long; long x = min(A, min(B, min(C, min(D, E)))); long ans = 4 + N / x; ans += !!(N % x); writeln(ans); }
D
/+ dub.sdl: name "A" dependency "dunkelheit" version="1.0.1" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int n, k; sc.read(n, k); writeln(n - k + 1); return 0; } /* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */ // module dkh.foundation; static if (__VERSION__ <= 2070) { /* Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d Copyright: Andrei Alexandrescu 2008-. License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). */ template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { import std.algorithm : reduce; static if (S.length < 2) { return reduce!fun(seed, r); } else { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } } /* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */ // module dkh.container.stackpayload; struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) { import core.exception : RangeError; private T* _data; private uint len, cap; @property bool empty() const { return len == 0; } @property size_t length() const { return len; } alias opDollar = length; inout(T)[] data() inout { return (_data) ? _data[0..len] : null; } ref inout(T) opIndex(size_t i) inout { version(assert) if (len <= i) throw new RangeError(); return _data[i]; } ref inout(T) front() inout { return this[0]; } ref inout(T) back() inout { return this[$-1]; } void reserve(size_t newCap) { import core.memory : GC; import core.stdc.string : memcpy; import std.conv : to; if (newCap <= cap) return; void* newData = GC.malloc(newCap * T.sizeof); cap = newCap.to!uint; if (len) memcpy(newData, _data, len * T.sizeof); _data = cast(T*)(newData); } void free() { import core.memory : GC; GC.free(_data); } void clear() { len = 0; } void insertBack(T item) { import std.algorithm : max; if (len == cap) reserve(max(cap * 2, MINCAP)); _data[len++] = item; } alias opOpAssign(string op : "~") = insertBack; void removeBack() { assert(!empty, "StackPayload.removeBack: Stack is empty"); len--; } } /* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */ // module dkh.scanner; // import dkh.container.stackpayload; class Scanner { import std.stdio : File; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; private File f; this(File f) { this.f = f; } private char[512] lineBuf; private char[] line; private bool succW() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (!line.empty && line.front.isWhite) { line.popFront; } return !line.empty; } private bool succ() { import std.range.primitives : empty, front, popFront; import std.ascii : isWhite; while (true) { while (!line.empty && line.front.isWhite) { line.popFront; } if (!line.empty) break; line = lineBuf[]; f.readln(line); if (!line.length) return false; } return true; } private bool readSingle(T)(ref T x) { import std.algorithm : findSplitBefore; import std.string : strip; import std.conv : parse; if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { auto r = line.findSplitBefore(" "); x = r[0].strip.dup; line = r[1]; } else static if (isStaticArray!T) { foreach (i; 0..T.length) { assert(succW()); x[i] = line.parse!E; } } else { StackPayload!E buf; while (succW()) { buf ~= line.parse!E; } x = buf.data; } } else { x = line.parse!T; } return true; } int unsafeRead(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } void read(Args...)(auto ref Args args) { import std.exception : enforce; static if (args.length != 0) { enforce(readSingle(args[0])); read(args[1..$]); } } bool hasNext() { return succ(); } } /* This source code generated by dunkelheit and include dunkelheit's source code. dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit) dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt) */
D
import std.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() { long a, b, x; readV(a, b, x); writeln(b/x+1 - (a == 0 ? 0 : (a-1)/x+1)); }
D
void main() { int n = readln.chomp.to!int; int t, x, y; bool ok = true; foreach (i; 0 .. n) { int[] tmp = readln.split.to!(int[]); int ti = tmp[0], xi = tmp[1], yi = tmp[2]; int len = abs(xi - x) + abs(yi - y); if (ti - t < len) { ok = false; } else if ((ti - t) % 2 != len % 2) { ok = false; } t = ti, x = xi, y = yi; } writeln(ok ? "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.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto k = readln.chomp.to!long, n = 50; auto kd = k/n, km = k%n; auto a = new long[](n); a[] = n-1+kd; foreach (i; 0..km) { a[] -= 1; a[i] += n+1; } writeln(n); foreach (i, ai; a) write(ai, i < n-1 ? " " : ""); writeln; }
D
import std.stdio; import std.conv; import std.algorithm; import std.range; import std.string; import std.math; void main() { readln; auto s = readln.chomp.split.map!(to!int); readln; auto t = readln.chomp.split.map!(to!int); int cnt = 0; foreach (e; t) { if (!s.find(e).empty) cnt++; } cnt.writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto X = readln.chomp.to!int; auto ns = new bool[](100004); foreach (i; 2..100004) { if (ns[i]) continue; if (i >= X) { writeln(i); return; } auto j = i*2; while (j < 100004) { ns[j] = true; j += i; } } }
D
import std.algorithm; import std.conv; import std.math; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto s = readln.strip; auto balance = abs (s.count ('0').to !(int) - s.count ('1').to !(int)); auto moves = (s.length - balance) / 2; writeln ((moves & 1) ? "DA" : "NET"); } }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const tmp = readln.split.to!(int[]); writeln(tmp[0] + tmp[1]/2); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.stdio; import std.string; import std.range; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { auto s = readln.chomp; auto t = readln.chomp; if ((s ~ s).indexOf(t) != -1) writeln("Yes"); else writeln("No"); }
D
module app; import core.bitop; import std.algorithm; import std.array; import std.bigint; import std.conv; import std.stdio; import std.string; void main() { Input input = void; parseInput(input, stdin); auto result = main2(&input); writeln(result); } auto main2(Input* input) { foreach (i, c; input.s) { if (i & 1) { if (c == 'L' || c == 'U' || c == 'D') { } else return "No"; } else { if (c == 'R' || c == 'U' || c == 'D') { } else return "No"; } } return "Yes"; } unittest // example1 { string example = `RUDLUDR`; Input input = void; parseExample(input, example); auto result = main2(&input); assert(result == "Yes"); } unittest // example2 { string example = `UUUUUUUUUUUUUUU`; Input input = void; parseExample(input, example); auto result = main2(&input); assert(result == "Yes"); } unittest // example3 { string example = `DULL`; Input input = void; parseExample(input, example); auto result = main2(&input); assert(result == "No"); } struct Input { string s; } void parseInput(T)(out Input input, T file) { with (file) with (input) { s = readln().strip(); } } void parseExample(out Input input, string example) { struct Adapter { import std.string; string[] _lines; this(string input) { _lines = input.splitLines(); } string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; } } Adapter a = Adapter(example); parseInput(input, a); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons; import std.math, std.numeric; immutable long mod = 10L^^9 + 7; void main() { int n; scan(n); auto fact = new long[](n + 1); auto rfact = new long[](n + 1); fact[0] = 1; foreach (i ; 1 .. n + 1) { fact[i] = (fact[i-1] * i) % mod; } rfact[n] = powmod(fact[n], mod - 2, mod); foreach_reverse (i ; 0 .. n) { rfact[i] = (rfact[i+1] * (i+1)) % mod; } debug { writeln(fact); writeln(rfact); } long binom(int n, int k) { return fact[n] * rfact[k] % mod * rfact[n-k] % mod; } long ans; long pre; foreach (k ; 0 .. n) { int b = n - 2 - (k - 1); if (b < 0 || b > k - 1) continue; long v = binom(k - 1, b) * fact[k] % mod * fact[n - 1 - k] % mod; debug { writeln(k, " ", v); } ans += k * (v - pre + mod) % mod; ans %= mod; pre = v; } writeln(ans); } long powmod(long x, long y, long mod) { return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1L; } 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
// 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; // dfmt on void main() { long H, W; scan(H, W); auto S = new string[](H); foreach (i; 0 .. H) S[i] = sread(); foreach (h; 0 .. H) foreach (w; 0 .. W) if (S[h][w] == '#') { if (0 < h && S[h - 1][w] == '#') continue; if (h + 1 < H && S[h + 1][w] == '#') continue; if (0 < w && S[h][w - 1] == '#') continue; if (w + 1 < W && S[h][w + 1] == '#') continue; writeln("No"); return; } writeln("Yes"); }
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 = 998244353; void main() { auto N = readln.chomp.to!int; auto S = N.iota.map!(_ => readln.chomp).array; int ans = 0; int[] dr = [0, -1, -1, 1, 1]; int[] dc = [0, -1, 1, -1, 1]; foreach (r; 1..N-1) { foreach (c; 1..N-1) { int ok = 1; foreach (k; 0..5) { int nr = r + dr[k]; int nc = c + dc[k]; if (S[nr][nc] == '.') { ok = 0; break; } } ans += ok; } } ans.writeln; }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { auto a = readln.split.map!(to!int); if (a[4] <= a[2] && a[2] <= a[0] - a[4] && a[4] <= a[3] && a[3] <= a[1] - a[4]) writeln("Yes"); else writeln("No"); }
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; if (((n[0] == n[1]) && (n[1] == n[2])) || ((n[1] == n[2]) && (n[2] == n[3]))) { writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum mod = 998244353L; void main() { int n; scan(n); auto f = new long[](n + 1); f[0] = f[1] = 1; foreach (i ; 2 .. n + 1) { f[i] = f[i-1] * i % mod; } auto rf = new long[](n + 1); rf[n] = powmod(f[n], mod - 2, mod); foreach_reverse (i ; 1 .. n) { rf[i] = rf[i+1] * (i + 1) % mod; } long comb(int n, int k) { return f[n] * rf[k] % mod * rf[n-k] % mod; } long ans = f[n]; foreach (i ; 2 .. n) { long t = comb(n, i) * (f[i] - 1 + mod) % mod * f[n - i] % mod; ans += t; ans %= mod; } writeln(ans); } long powmod(long x, long y, long mod) { return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 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); } } }
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; void main() { auto n = to!int(readln().strip()); while(n > 0){ string[] s; for(int i; i < n; ++i){ s ~= readln().chomp(); } int[][] yoko = new int[][](n+1,n+1); int[][] tate = new int[][](n+1,n+1); int[][] square = new int[][](n+1,n+1); int maxSquare = 0; for(int i = n-1; i >= 0; --i) { for(int j = n-1; j >= 0; --j) { if(s[i][j] == '.') { yoko[i][j] = yoko[i][j+1]+1; tate[i][j] = tate[i+1][j]+1; square[i][j] = min(yoko[i][j],tate[i][j],square[i+1][j+1]+1); maxSquare = max(maxSquare, square[i][j]); }else{ yoko[i][j] = 0; tate[i][j] = 0; square[i][j] = 0; } } } writeln(maxSquare); n = to!int(readln().strip()); } }
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.range; void main() { auto N = readln.split[0].to!int; auto s = new string[N]; foreach(i; 0..N) { s[i] = readln.split[0]; } auto bucket = new int[26][N]; foreach(i; 0..N) { foreach(c; s[i]) { bucket[i][c - 'a']++; } } int[int[26]] m; ulong ans = 0; foreach(b; bucket) { if(b in m) { ans += m[b]; } m[b]++; } ans.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 n; scan(n); if (n == 0) return; solve(n); } } void solve(int n) { int l=1, r=1; int v; int cnt; while (r <= n) { if (v < n) { v += r++; } else { if (v == n) cnt++; v -= l++; } } writeln(cnt); } 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.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; void main() { string s, t; scan(s); scan(t); auto n = s.length; int ans; foreach (i; 0 .. n) { ans += s[i] != t[i]; } ans.writeln; } void scan(T...)(ref T args) { auto line = readln.split; // @suppress(dscanner.suspicious.unmodified) foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront; } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x > arg) { x = arg; isChanged = true; } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x < arg) { x = arg; isChanged = true; } return isChanged; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto data = readln.split; auto N = data[0].to!int, M = data[1].to!int; auto D = M / N; if (D == 1) { writeln(1); return; } foreach_reverse (i; 1 .. D+1) { if (M%i == 0) { writeln(i); return; } } }
D
void main() { auto S = rs, T = rs; S ~= S; if(S.canFind(T)) writeln("Yes"); else writeln("No"); } // =================================== import std.stdio; import std.string; import std.functional; import std.conv; 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
// Vicfred // https://atcoder.jp/contests/abc175/tasks/abc175_a // implementation import std.stdio; import std.string; void main() { string S = readln.strip; if(S.count("RRR") == 1) { 3.writeln; return; } else if(S.count("RR") == 1) { 2.writeln; return; } else if(S.count("R") >= 1) { 1.writeln; return; } else { 0.writeln; } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; import core.bitop; string FMT_F = "%.10f"; T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long mod = 10^^9 + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto A = RD; auto B = RD; auto K = RD; long ans; foreach_reverse (i; 1..min(A, B)+1) { if (A % i == 0 && B % i == 0) { --K; //stderr.writeln(i); } if (K == 0) { ans = i; break; } } writeln(ans); stdout.flush(); }
D
import std.stdio; void main() { foreach(i; 1 .. 10) { foreach(j; 1 .. 10) { printf("%dx%d=%d\n",i,j,i*j); } } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int a, b; readV(a, b); writeln((a-1)*(b-1)); }
D
/+ dub.sdl: name "C" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner, dcomp.algorithm; import std.container.rbtree; int main() { auto sc = new Scanner(stdin); bool ans; scope(exit) { if (ans) writeln("Yes"); else writeln("No"); } int n; int[] a; sc.read(n, a); int f(int x) { if (x % 2) return 0; x /= 2; if (x % 2) return 1; return 2; } int[3] c; a.each!(x => c[f(x)]++); int b = 2; foreach (ph; 0..n) { if (b == 0) { if (c[2]) { c[2]--; b = 2; continue; } return 0; } if (b == 1) { if (c[1]) { c[1]--; b = 1; continue; } if (c[2]) { c[2]--; b = 2; continue; } return 0; } if (b == 2) { if (c[0]) { c[0]--; b = 0; continue; } if (c[1]) { c[1]--; b = 1; continue; } if (c[2]) { c[2]--; b = 2; continue; } return 0; } } ans = true; 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/algorithm.d */ // module dcomp.algorithm; import std.range.primitives; import std.traits : isFloatingPoint, isIntegral; T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) { while (r-l > 1) { T md = (l+r)/2; if (!pred(md)) l = md; else r = md; } return r; } T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) { foreach (i; 0..cnt) { T md = (l+r)/2; if (!pred(md)) l = md; else r = md; } return r; } E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed) if (isInputRange!Range && !isInfinite!Range) { import std.algorithm, std.functional; return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range); } ElementType!Range minimum(alias pred = "a < b", Range)(Range range) { assert(!range.empty, "range must not empty"); auto e = range.front; range.popFront; return minimum!pred(range, e); } E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed) if (isInputRange!Range && !isInfinite!Range) { import std.algorithm, std.functional; return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range); } ElementType!Range maximum(alias pred = "a < b", Range)(Range range) { assert(!range.empty, "range must not empty"); auto e = range.front; range.popFront; return maximum!pred(range, e); } Rotator!Range rotator(Range)(Range r) { return Rotator!Range(r); } struct Rotator(Range) if (isForwardRange!Range && hasLength!Range) { size_t cnt; Range start, now; this(Range r) { cnt = 0; start = r.save; now = r.save; } this(this) { start = start.save; now = now.save; } @property bool empty() { return now.empty; } @property auto front() { assert(!now.empty); import std.range : take, chain; return chain(now, start.take(cnt)); } @property Rotator!Range save() { return this; } void popFront() { cnt++; now.popFront; } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; immutable long MOD = 10^^9+7; void main() { auto S = readln.chomp; if (S.canFind("ABC") || S.canFind("ACB") || S.canFind("BAC") || S.canFind("BCA") || S.canFind("CAB") || S.canFind("CBA")) { writeln("Yes"); } else { writeln("No"); } }
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 int[](t); foreach (ti; 0..t) { auto s = RD!string; bool start; foreach (c; s) { if (c == '1') start = true; else if (start) ++ans[ti]; } foreach_reverse (c; s) { if (c == '1') start = false; else if (start) --ans[ti]; } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio; import std.math; import std.algorithm; import std.array; import std.string; import std.conv; import std.range; import std.file; import std.datetime; void main() { int elemanSayısı = stdin.readln.strip.to!int; string harfler = stdin.readln.strip.to!string; int enBüyükIndeksi = 0; char enBüyükHarf = 'a'; for ( int i = 0; i < harfler.length; i++ ) { if ( harfler[i] >= enBüyükHarf ) { enBüyükIndeksi = i; enBüyükHarf = harfler[i]; } else { writeln("YES"); return writeln( enBüyükIndeksi+1, " ", i+1 ); } } writeln("NO"); }
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; void main() { auto s = readln.stripRight; int[26] c; long[26][26] d; foreach (ch; s) { int i = ch.to!int - 97; foreach (j; 0 .. 26) { d[j][i] += c[j]; } ++c[i]; } long res; foreach (i; 0 .. 26) { res = max (res, c[i]); foreach (j; 0 .. 26) res = max (res, d[i][j]); } writeln (res); }
D
import std.stdio; import std.math; void main() { int n, t; scanf("%d%d", &n, &t); printf("%.10f\n", n * pow(1.000000011, t)); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf3 = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int n; long a, b, c, d; scan(n, a, b, c, d); b = b - a; a = 0; auto s = - (n - 1) * d; auto t = - (n - 1) * c; foreach (i ; 0 .. n) { if (s <= b && b <= t) { writeln("YES"); return; } s += c + d; t += c + d; } writeln("NO"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nmk = readln.split.to!(int[]); auto N = nmk[0]; auto M = nmk[1]; auto K = nmk[2]; foreach (y; 0..N+1) { auto b = 2*y - N; if (b == 0) { if (N*M == 2*K) { writeln("Yes"); return; } } else { auto s = K + M*y - M*N; if (s % b != 0) continue; auto x = s / b; if (0 <= x && x <= M) { writeln("Yes"); return; } } } writeln("No"); return; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto ab = reads!string; auto s = ab[0] ~ ab[1]; int n = s.to!int; int x = cast(int)sqrt(1.0 * n); writeln(n == x * x ? "Yes" : "No"); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; import std.conv; import std.typecons; void main() { (rs.uniq.array.length - 1).writeln; } // =================================== 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 (isBasicType!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } int ri() { return readAs!int; } string rs() { return readln.chomp; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum mod = 10L^^9 + 7; enum inf = 10^^9; void main() { string s; scan(s); auto n = s.length.to!int; auto dp = new long[][](n + 1, 4); dp[0][0] = 1; foreach (i ; 0 .. n) { foreach (j ; 0 .. 4) { dp[i+1][j] = s[i] == '?' ? dp[i][j]*3 % mod : dp[i][j]; } if (s[i] == 'A' || s[i] == '?') { (dp[i+1][1] += dp[i][0]) %= mod; } if (s[i] == 'B' || s[i] == '?') { (dp[i+1][2] += dp[i][1]) %= mod; } if (s[i] == 'C' || s[i] == '?') { (dp[i+1][3] += dp[i][2]) %= mod; } } debug { writeln(dp); } long ans = dp[n][3]; 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.stdio; import std.conv; import std.string; import std.algorithm; import std.range; void main() { auto input = readln.split; auto X = input[0]; auto Y = input[1]; (X < Y ? "<" : X > Y ? ">" : "=").writeln; }
D
import std.stdio; import std.conv; import std.string; void main() { auto n = readln.chomp.to!int; string[] words = []; auto ans = "Yes"; foreach (i; 0..n) { auto word = readln.chomp; foreach (w; words) { if (w == word){ "No".writeln; return; } } words ~= word; } foreach (i; 1..n){ if (words[i - 1][$ - 1] != words[i][0]) { ans = "No"; break; } } ans.writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; 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, R; scan(N, R); writeln((10 <= N) ? R : R + 100 * (10 - N)); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial; void main(){ auto as=readln.chomp.array; auto bs=readln.chomp.array; auto cs=readln.chomp.array; auto turn=0; while(true){ final switch(turn){ case 0: if(!as.any){ writeln("A");return; } turn=int(as[0]-'a'); as=as[1..$]; break; case 1: if(!bs.any){ writeln("B");return; } turn=int(bs[0]-'a'); bs=bs[1..$]; break; case 2: if(!cs.any){ writeln("C");return; } turn=int(cs[0]-'a'); cs=cs[1..$]; break; } } }
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; } } //}}} void main() { Scanner sc = new Scanner; int A, P; sc.scan(A, P); P += (A * 3); writeln(P / 2); }
D
import std.conv : to; import std.stdio; import std.string : strip; void main() { int n = to!int(strip(stdin.readln())); string sequence = strip(stdin.readln()); char last_symbol = sequence[0]; int length = 1; for (auto i = 1; i < sequence.length; ++i) { if (sequence[i] != last_symbol) { ++length; last_symbol = sequence[i]; } } stdout.write(sequence.length - length); }
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; long m; foreach (e;s) { m += cast(int)(e - '0'); } if (m % 9 == 0) { writeln("Yes"); } else { writeln("No"); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int a, b; readV(a, b); writeln([a+b, a-b, a*b].reduce!max); }
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; struct Queue(T) { private { size_t cap, head, tail; T[] data; } this (size_t n) in { assert(n > 0, "The capacity of a queue must be a positive integer."); } body { cap = n + 1; data = new T[](cap); } void clear() { head = tail = 0; } bool empty() { return head == tail; } bool full() { return head == (tail + 1) % cap; } size_t length() { return head <= tail ? tail - head : cap - head + tail; } T front() in { assert(!empty, "The queue is empty."); } body { return data[head]; } void removeFront() in { assert(!empty, "The queue is empty."); } body { (++head) %= cap; } alias popFront = removeFront; void insertBack(T x) in { assert(!full, "The queue is full."); } body { data[tail++] = x; tail %= cap; } alias insert = insertBack; T[] array() { return head <= tail ? data[head .. tail].dup : data[head .. $] ~ data[0 .. tail]; } string toString() { import std.format : format; if (head <= tail) { return format("[%(%s, %)]", data[head .. tail]); } else { return format("[%(%s, %)", data[head .. $]) ~ format(", %(%s, %)]", data[0 .. tail]); } } } unittest { auto a = Queue!(int)(5); //a.front; a.insert(2); a.insert(5); a.insert(3); //a.insert(8); import std.stdio; a.removeFront; a.removeFront; a.insert(11); a.insert(7); a.insert(123); a.insert(543); a.removeFront; a.removeFront; a.removeFront; a.insert(1212); a.insert(9898); a.insert(3154); a.removeFront; a.removeFront; a.removeFront; a.removeFront; a.removeFront; } unittest { auto q = Queue!(int)(5); assert(q.empty); q.insert(3); q.insert(1); q.insert(5); q.insert(4); q.insert(8); // q = [3,1,5,4,8] auto hoge = q.array; assert(hoge == [3,1,5,4,8]); assert(q.full); q.popFront(); q.popFront(); // q = [5,4,8] hoge = q.array; assert(hoge == [5,4,8]); hoge[0] = 3; hoge[2] = 11; assert(q.front == 5); assert(q.length == 3); q.popFront(); q.popFront(); // q = [8] q.insert(11); q.insert(-8); // q = [8,11,-8] assert(q.front == 8); assert(q.length == 3); q.insert(23); q.insert(31); // q = [8,11,-8,23,31] assert(q.full); assert(q.length == 5); auto a = new int[](0); foreach (e ; q) { a ~= e; } assert(a == [8, 11, -8, 23, 31]); foreach (i ; 0 .. 5) { q.popFront(); } assert(q.length == 0); assert(q.empty); hoge = q.array; assert(hoge == []); } unittest { auto q = Queue!(string)(4); q.insert("Hello"); q.insert(","); q.insert("World"); q.insert("!"); auto hoge = q.array; assert(hoge == ["Hello", ",", "World", "!"]); assert(q.full); assert(q.length == 4); q.popFront(); q.popFront(); assert(q.front == "World"); assert(q.length == 2); q.clear(); assert(q.empty); assert(q.length == 0); q.insert("hoge"); q.insert("fuga"); q.insert("melon"); q.popFront(); q.popFront; q.popFront; q.insert("hayo"); q.insert("hoge"); q.insert("pippi"); hoge = q.array; hoge[0] = "aho"; assert(q.front == "hayo"); q.insert("huni"); q.popFront; q.popFront; q.insert("ueue"); assert(q.front == "pippi"); assert(q.length == 3); } void main() { int N, T; scan(N, T); auto a = new int[](N); auto b = new int[](N); foreach (i ; 0 .. N) { scan(a[i], b[i]); } auto dpf = new long[][](N + 1, T); foreach (i ; 1 .. N + 1) { foreach (w ; 0 .. T) { dpf[i][w] = dpf[i - 1][w]; if (w - a[i - 1] >= 0) { chmax(dpf[i][w], dpf[i - 1][w - a[i - 1]] + b[i - 1]); } } } auto dpr = new long[][](N + 1, T); foreach_reverse (i ; 0 .. N) { foreach (w ; 0 .. T) { dpr[i][w] = dpr[i + 1][w]; if (w - a[i] >= 0) { chmax(dpr[i][w], dpr[i + 1][w - a[i]] + b[i]); } } } long ans; foreach (i ; 0 .. N) { foreach (j ; 0 .. T) { chmax(ans, dpf[i][j] + dpr[i + 1][T - 1 - j] + b[i]); } } 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
//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; import std.typecons; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); p = stdin.rawRead (buffer); } final ubyte skipByte (ubyte lo) { while (true) { auto a = p[cur .. $]; auto r = a.find! (c => c >= lo); if (!r.empty) { cur += a.length - r.length; return p[cur++]; } p = stdin.rawRead (buffer); cur = 0; if (p.empty) return 0; } } final ubyte nextByte () { if (cur < p.length) { return p[cur++]; } p = stdin.rawRead (buffer); if (p.empty) return 0; cur = 1; return p[0]; } template next(T) if (isSigned!T) { final T next () { T res; ubyte b = skipByte (45); if (b == 45) { while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { final T next () { T res = skipByte (48) - 48; while (true) { ubyte b = nextByte (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } final T[] nextA(T) (int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } alias T = Tuple!(int, int); void main() { auto r = new InputReader; immutable n = r.next!int; auto p = r.nextA!int(n); p[] -= 1; auto q = new int[n]; foreach (i; 0 .. n) { q[p[i]] = i; } int m = n / 2; T[] res; int s (int i, int j) { debug stderr.writefln ("swap: %d %d\n", i + 1, j + 1); if (i == j) { return j; } debug stderr.writefln ("%d %d", 2 * abs (i - j), n); assert (2 * abs (i - j) >= n); res ~= tuple (i + 1, j + 1); swap (p[i], p[j]); q[p[i]] = i; q[p[j]] = j; return j; } immutable last = n - 1; debug stderr.writeln ("m = ", m); foreach_reverse (i; 1 .. m) { int pos = m - i; int u = q[pos]; debug stderr.writeln ("p = ", p, ", pos = ", pos, ", u = ", u); if (u != pos) { if (u < m) { u = s (u, last); } else { u = s (u, 0); u = s (0, last); } assert (u == last); s (last, pos); } pos = m + i - 1; u = q[pos]; debug stderr.writeln ("p = ", p, ", pos = ", pos, ", u = ", u); if (u != pos) { if (u >= m) { u = s (u, 0); } else { u = s (u, last); u = s (last, 0); } assert (u == 0); s (0, pos); } } if (p[0] != 0) { s (0, last); } writeln (res.length); foreach (t; res) { writeln (t[0], ' ', t[1]); } debug { stderr.writeln (p); foreach (i; 0 .. n) { assert (p[i] == i); } } }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; class InputReader { private: ubyte[] p; ubyte[] buffer; size_t cur; public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); p = stdin.rawRead (buffer); } final ubyte skipByte (ubyte lo) { while (true) { auto a = p[cur .. $]; auto r = a.find! (c => c >= lo); if (!r.empty) { cur += a.length - r.length; return p[cur++]; } p = stdin.rawRead (buffer); cur = 0; if (p.empty) return 0; } } final ubyte nextByte () { if (cur < p.length) { return p[cur++]; } p = stdin.rawRead (buffer); if (p.empty) return 0; cur = 1; return p[0]; } template next(T) if (isUnsigned!T) { final T next () { T res = skipByte (48) - 48; while (true) { ubyte b = nextByte (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } } void main() { auto r = new InputReader; immutable int n = r.next!uint; immutable int m = r.next!uint; auto a = uninitializedArray!(uint[][]) (n, m); auto b = uninitializedArray!(uint[][]) (n, m); foreach (i; 0 .. n) foreach (j; 0 .. m) a[i][j] = r.next!uint; foreach (i; 0 .. n) foreach (j; 0 .. m) b[i][j] = r.next!uint; bool test () { foreach (d; 0 .. n + m - 1) { uint[] X, Y; foreach (i; 0 .. n) { immutable j = d - i; if (j >= 0 && j < m) { X ~= a[i][j]; Y ~= b[i][j]; } } X.sort (); Y.sort (); debug stderr.writeln ("d = ", d); debug stderr.writeln ("X = ", X); debug stderr.writeln ("Y = ", Y); if (!equal (X, Y)) return false; } return true; } write (test () ? "YES" : "NO"); }
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 K = RD; auto X = RD; writeln(K*500 >= X ? "Yes" : "No"); stdout.flush; debug readln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { for (;;) { auto s = readln.chomp; if (s == "-") break; auto m = readln.chomp.to!size_t; auto hi = m.iota.map!(_ => readln.chomp.to!int); foreach (h; hi) s = s[h..$] ~ s[0..h]; writeln(s); } }
D
void main(){ _scan(); int[] a = _scanln(); int ans_bit; foreach(elm; a)ans_bit = elm|ans_bit; int cnt; while( (ans_bit&1) == 0){ cnt++; ans_bit = ans_bit >> 1; } cnt.writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto s = read!string; writeln("aeiou".canFind(s) ? "vowel" : "consonant"); }
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; bool[] seen, finished; int pos = -1; int[] hist; void dfs(int[][] adj, int v) { seen[v] = true; hist ~= v; foreach (nv ; adj[v]) { if (finished[nv]) continue; if (seen[nv] && !finished[nv]) { pos = nv; return; } dfs(adj, nv); if (pos != -1) return; } hist.popBack(); finished[v] = true; } void main() { int N, M; scan(N, M); auto adj = new int[][](N, 0); foreach (i ; 0 .. M) { int ai, bi; scan(ai, bi); ai--, bi--; adj[ai] ~= bi; } seen = new bool[](N); finished = new bool[](N); foreach (v ; 0 .. N) { dfs(adj, v); if (pos != -1) break; } if (pos == -1) { writeln(-1); return; } int[] cycle; while (!hist.empty) { int t = hist.back; cycle ~= t; hist.popBack(); if (t == pos) break; } cycle.reverse(); while (true) { auto ord = new int[](N); ord[] = -1; foreach (i ; 0 .. cycle.length) { ord[cycle[i]] = i.to!int; } int from = -1, to = -1; foreach (i ; 0 .. cycle.length) { foreach (nv ; adj[cycle[i]]) { if (nv != cycle[(i + 1) % cycle.length] && ord[nv] != -1) { from = i.to!int; to = ord[nv]; break; } } if (from != -1) break; } if (from == -1) break; int[] ncycle; ncycle ~= cycle[from]; int i = to; while (i != from) { ncycle ~= cycle[i]; i = (i + 1) % cycle.length.to!int; } cycle = ncycle; } writeln(cycle.length); cycle.each!(v => writeln(v + 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
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 a, b, c; scan(a, b, c); bool B = a <= c && c <= b; writeln(B ? "Yes" : "No"); }
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; scan(a, b, c); foreach (i; 1 .. 10 ^^ 6) { if ((a * i) % b == c) { writeln("YES"); return; } } writeln("NO"); } 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
void main(){ auto SW = readLine!size_t(); if( SW[0] <= SW[1] ){ writeln("unsafe"); } else { writeln("safe"); } } import std.stdio, std.string, std.conv; import std.math, std.algorithm, std.array; import std.regex; T[] readLine( T = size_t )( string sp = " " ){ T[] ol; foreach( string elm ; readln().chomp().split(sp) ){ ol ~= elm.to!T(); } return ol; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto t = RD!int; auto ans = new string[][](t); foreach (ti; 0..t) { auto n = RD!int; auto m = RD!int; ans[ti].length = n; foreach (y; 0..n-1) { foreach (x; 0..m-1) { ans[ti][y] ~= 'W'; } ans[ti][y] ~= 'B'; } foreach (i; 0..m) { ans[ti][$-1] ~= 'B'; } } foreach (e; ans) { foreach (ee; e) writeln(ee); } stdout.flush; debug readln; }
D
void main() { string s = readln.chomp; int[string] week; week["SAT"] = 1; week["FRI"] = 2; week["THU"] = 3; week["WED"] = 4; week["TUE"] = 5; week["MON"] = 6; week["SUN"] = 7; week[s].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
import std.stdio; import std.string; import std.conv; import std.algorithm; int s_n(int n) { int sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } void main() { int n = readln.chomp.to!(int); writeln((n % s_n(n) == 0) ? "Yes" : "No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); int[char] memo; foreach (c; S) { if (c !in memo) memo[c] = 0; ++memo[c]; } foreach (k, v; memo) { if (v != 2) { writeln("No"); return; } } writeln("Yes"); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto K = RD; long ans; foreach (i; 1..K+1) { foreach (j; 1..K+1) { auto tmp = gcd(i, j); foreach (k; 1..K+1) { ans += gcd(tmp, k); } } } writeln(ans); stdout.flush; debug readln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void calc(string[] g) { auto rows = g.length; auto cols = g[0].length; // # が存在する行、列 bool[int] mrow, mcol; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { if (g[r][c] == '#') { mrow[r] = true; break; } } } for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { if (g[r][c] == '#') { mcol[c] = true; break; } } } for (int r = 0; r < rows; r++) { if (r !in mrow) continue; for (int c = 0; c < cols; c++) { if (c in mcol) 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
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { long N, M; scan(N, M); auto graph = new long[long][](N); foreach (_; 0 .. M) { long l, r, d; scan(l, r, d); l--; r--; graph[l][r] = d; graph[r][l] = -d; } auto p = new long[](N); p[] = -long.min; bool ans = true; void solve(long x) { if (p[x] == long.min) p[x] = 0; foreach (k, v; graph[x]) { if (p[k] == long.min) { p[k] = p[x] + v; solve(k); } else { if (p[k] - p[x] != v) { ans = false; return; } } } } foreach (i; 0 .. N) solve(i); writeln(ans ? "Yes" : "No"); }
D
void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], i = tmp[1]; writeln(n - i + 1); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.container; import std.typecons;
D
import std.stdio; void main() { string s = readln; if (s[0] == '7' || s[1] == '7' || s[2] == '7') { writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto whn = readln.split.map!(to!int); auto w = whn[0]; auto h = whn[1]; auto n = whn[2]; int t = h, b = 0, l = 0, r = w; foreach (_; 0..n) { auto xya = readln.split.map!(to!int); auto x = xya[0]; auto y = xya[1]; auto a = xya[2]; switch (a) { case 1: l = l < x ? x : l; break; case 2: r = r > x ? x : r; break; case 3: b = b < y ? y : b; break; case 4: t = t > y ? y : t; break; default: } } writeln(r <= l || t <= b ? 0 : (r-l)*(t-b)); }
D
import std.stdio; import std.string; import std.array; // split import std.conv; // to import std.math; import std.algorithm; void main() { string a = chomp(readln()); string b = chomp(readln()); int N = to!int(a); // 第0要素を整数に変換 int K = to!int(b); // 第1要素を整数に変換 int ans = 1; for(int i=0;i<N;i++){ if(ans < K) ans*=2; else ans+=K; } writeln(ans); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto t = readln.chomp.split.map!(to!int); auto a = readln.chomp.split.map!(to!int); auto res1 = new int[](n); res1[0] = t[0]; foreach (i; 1..n) { if (t[i] - t[i-1]) { res1[i] = t[i]; } else { res1[i] = 1; } } auto res2 = new int[](n); res2[$-1] = a[$-1]; foreach_reverse (i; 0..n-1) { if (a[i] - a[i+1]) { res2[i] = a[i]; } else { res2[i] = 1; } } long sum = 1; foreach (i; 0..n) { auto diff = min(t[i], a[i]) - max(res1[i], res2[i]) + 1; if (diff < 0) diff = 0; sum = (sum*diff)% 1_000_000_007; } writeln(sum); }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.math; void main() { int N = readln.chomp.to!int; auto a = readln.chomp.split.map!(to!int).array; int odd; for (int i = 0; i < N; ++i) { if (a[i] % 2 == 1) { odd++; } } if (odd % 2 == 1 && N > 1) { "NO".writeln; } else { "YES".writeln; } return; }
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { foreach(s;stdin.byLine()) { string t; for(int i=0; i<s.length; ++i) if(s[i]!='@') t~=s[i]; else t~=s[i+2].repeat().take(s[i+1]-'0').array(),i+=2; writeln(t); } }
D
void main() { string s = rdStr; long k = rdElem; long idx; foreach (i, x; s) { if (x != '1') { idx = i; break; } } writeln(idx >= k ? s[0] : s[idx]); } enum long mod = 10L^^9 + 7; enum long inf = 1L << 60; enum double eps = 1.0e-9; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)() if (is(T == struct)) { T result; string[] input = rdRow!string; assert(T.tupleof.length == input.length); foreach (i, ref x; result.tupleof) { x = input[i].to!(typeof(x)); } return result; } T[] rdRow(T = long)() { return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { return iota(col).map!(x => rdRow!T).array; } void rdVals(T...)(ref T data) { string[] input = rdRow!string; assert(data.length == input.length); foreach (i, ref x; data) { x = input[i].to!(typeof(x)); } } void wrMat(T = long)(T[][] mat) { foreach (row; mat) { foreach (j, compo; row) { compo.write; if (j == row.length - 1) writeln; else " ".write; } } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.mathspecial; import std.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni; import core.bitop;
D
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm; void main(){ auto S = readln.chomp.to!(char[]); int count; foreach(i; 0..4){ if(S[i] == '+') count++; else count--; } writeln(count); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "x", long, "y"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { auto n = lread(); long ok = -1, ng = n; writeln(0); stdout.flush(); auto first = sread(); if (first == "Vacant") return; long p = (first == "Male" ? 0 : 1); while (abs(ok - ng) > 1) { auto mid = (ok + ng) / 2; mid.writeln(); stdout.flush(); auto s = sread(); bool check(long i, string s) { if ((i + p) % 2) return (s == "Female"); else return (s == "Male"); } if (s == "Vacant") return; if (check(mid, s)) ok = mid; else ng = mid; } } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D