code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.conv, std.string, std.math; void main() { int input = to!int(chomp(readln())); int i = 1; if(input==1) { writeln(1); return; } while (pow(i, 2) <= input) { i++; } writeln(pow(i-1, 2)); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto rgbn = readln.split.to!(int[]); auto R = rgbn[0]; auto G = rgbn[1]; auto B = rgbn[2]; auto N = rgbn[3]; int ret; foreach (r; 0..3001) { foreach (g; 0..3001) { auto rest = N - R*r - G*g; if (rest == 0 || (rest > 0 && rest%B == 0)) ++ret; } } writeln(ret); }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n, l, a; rd(n, l, a); auto s = new int[](n), t = new int[](n); foreach (i; 0 .. n) rd(s[i], t[i]); long cnt = 0; foreach (i; 1 .. n) { cnt += (s[i] - (s[i - 1] + t[i - 1])) / a; } if (n > 0) { cnt += (s[0]) / a; cnt += (l - (s[$ - 1] + t[$ - 1])) / a; } else { cnt += l / a; } writeln(cnt); } 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; void main() { auto s1 = split(readln()); bool flag; foreach (ind; 0 .. to!int(s1[0])) { auto s2 = split(readln); if (!s2.find("C").empty || !s2.find("M").empty || !s2.find("Y").empty) { flag = true; break; } } if (flag) writeln("#Color"); else writeln("#Black&White"); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long mod = 10^^9 + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD!int; auto s = RD!string; auto m = N - 11 + 1; long cnt; foreach (i; 0..m) { if (s[i] == '8') { ++cnt; } } writeln(cnt > m / 2 ? "YES" : "NO"); stdout.flush(); debug readln(); }
D
// Code By H~$~C module main; import std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint; import std.algorithm, std.conv, std.container, std.range, std.functional; import std.random, std.typecons; // FIXME int[] buildZ(in string s) { int n = cast(int)(s.length); int[] z; z.length = n; for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = (z[i - l] < r - i + 1 ? z[i - l] : r - i + 1); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } return z; } void solve(in int testcase) { string s, t; s.read; int n = cast(int)(s.length), m; for (int i = 0; i < n; ++i) t ~= s[n - i - 1]; if (s == t) { s.writeln; return ; } int[] z = buildZ(s ~ '$' ~ t); int x = z[n + 1]; string ans1 = s[0 .. x]; string ans2 = ""; int mx = 0; string p = s[x .. n - x]; string o; { n = cast(int)(p.length), m = n * 2 + 1; t = ""; for (int i = 0; i < n; ++i) t ~= p[n - i - 1]; o = p ~ '$' ~ t; z = buildZ(o); for (int i = m - 1; i >= 0; --i) { if (z[i] == m - i && mx < m - i) { mx = m - i; ans2 = o[i .. $]; } } } p = t; { n = cast(int)(p.length), m = n * 2 + 1; t = ""; for (int i = 0; i < n; ++i) t ~= p[n - i - 1]; o = p ~ '$' ~ t; z = buildZ(o); for (int i = m - 1; i >= 0; --i) { if (z[i] == m - i && mx < m - i) { mx = m - i; ans2 = o[i .. $]; } } } string ans3; for (int i = 0; i < x; ++i) ans3 ~= ans1[x - i - 1]; (ans1 ~ ans2 ~ ans3).writeln; } // ************************************************************ T reader(T)() { return readToken().to!T; } void read(T)(ref T t) { t = reader!T; } T[] readarray(T)() { return readln.splitter.map!(to!T).array; } void chmax(T)(ref T a, T b) { a = max(a, b); } void chmin(T)(ref T a, T b) { a = min(a, b); } alias less = (a, b) => a < b; alias greater = (a, b) => a > b; T min_element(T)(in T[] a) { return a.element!less; } T max_element(T)(in T[] a) { return a.element!greater; } alias unique = uniq; // constant or some variables immutable int inf = 0x3f3f3f3f; immutable long lnf = 0x3f3f3f3f3f3f3f3f; immutable typeof(null) NULL = null; string[] _tokens; // functions T element(alias pred, T)(in T[] a) { int pos = 0; for (int i = 1; i < cast(int)(a.length); ++i) if (binaryFun!pred(a[i], a[pos])) pos = i; return a[pos]; } string readToken() { for (; _tokens.empty; ) { if (stdin.eof) return ""; _tokens = readln.split; } auto token = _tokens.front; _tokens.popFront; return token; } int binary_bearch(alias pred, T)(in T[] as) { int l = -1, h = cast(int)(as.length), mid; for (; l + 1 < h; ) { mid = (l + h) >> 1; (unaryFun!pred(as[mid]) ? h : l) = mid; } return h; } int lower_bound(alias pred = less, T)(in T[] as, T val) { return as.binary_bearch!(a => a == val || pred(val, a)); } int upper_bound(alias pred = less, T)(in T[] as, T val) { return as.binary_bearch!(a => pred(val, a)); } void main(string[] args) { int tests = 1; tests.read(); foreach(test; 1 .. tests + 1) solve(test); }
D
import std.stdio; import std.string; void main () { string s; while ((s = readln.strip) != "") { long res = 0; foreach (pos; 1..s.length + 1) { res += !(s[pos - 1] & 3); if (pos > 1 && !((s[pos - 2] * 2 + s[pos - 1]) & 3)) { res += pos - 1; } } writeln (res); } }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons; immutable int inf = 10^^9 + 7; int N, W; int[] v, w; void main() { scan(N, W); int vi, wi; auto v = new int[](N); auto w = new int[](N); foreach (i ; 0 .. N) { scan(vi, wi); v[i] = vi; w[i] = wi; } auto dp = new int[](N * 100 + 1); dp[] = inf; dp[0] = 0; foreach (i ; 0 .. N) { foreach_reverse (j ; v[i] .. N * 100 + 1) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } foreach_reverse (j ; 0 .. N * 100 + 1) { if (dp[j] <= W) { writeln(j); return; } } } 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); }
D
import std.stdio, std.algorithm, std.conv, std.string, std.array, std.math; void main() { const r = readln.chomp.to!int; (r*r).writeln; }
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() { string s; scan(s); if (s.canFind("AC")) { writeln("Yes"); } else { writeln("No"); } } 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; import std.range, std.algorithm, std.array; import std.math : abs; void main() { int n; scan(n); int t, x, y; bool ok = 1; foreach (i ; 0 .. n) { int ti, xi, yi; scan(ti, xi, yi); int dt = ti - t; int dist = abs(xi - x) + abs(yi - y); if (dt < dist || dt % 2 != dist % 2) { ok = 0; } t = ti, x = xi, y = yi; } writeln(ok ? "Yes" : "No"); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio; import std.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; void main() { auto nm = readln.chomp.split.map!(to!long); long n = nm[0]; long m = nm[1]; auto A = readln.chomp.split.map!(to!long).array; long[long] t; t[0] = 1; long b; foreach (a; A) { b += a; b %= m; long mod = b % m; if (mod in t) t[mod]++; else t[mod] = 1; } long result; foreach (key, val; t) { result += (val).c(2); } writeln(result); } long c(long a, long b) { if (a < b) { return 0; } long c = 1; foreach (i; a - b + 1 .. a + 1) c *= i; long d = 1; foreach (i; 1 .. b + 1) d *= i; return c / d; }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void main() { string x, y; readV(x, y); writeln(x > y ? ">" : x < y ? "<" : "="); }
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() { readln.chomp.count!(x=>x=='1').writeln; }
D
import std.stdio, std.algorithm, std.range, std.conv, std.string; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { int n; scanf("%d", &n); int[] a = new int[n]; int[] b = new int[n]; foreach (i; 0..n) scanf("%d", &a[i]); foreach (i; 0..n) scanf("%d", &b[i]); int ans = 0; foreach (k; 0..29) { int mask = (1<<k)-1; int s = 0; if (n&1) { foreach (x; a) s ^= x>>k&1; foreach (x; b) s ^= x>>k&1; } int[] c = new int[n]; c[] = b[]&mask; sort(c); auto sorted = assumeSorted(c); foreach (x; a) { x &= mask; int l = n - to!int(sorted.lowerBound((1<<k)-x).length); s ^= l&1; } ans |= s<<k; } writeln(ans); }
D
// Vicfred // https://atcoder.jp/contests/abc176/tasks/abc176_b // implementation import std.stdio; import std.string; void main() { string n = readln.strip; int sum = 0; foreach(ch; n) { sum += ch - '0'; sum %= 9; } if(sum == 0) "Yes".writeln; else "No".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 N = RD!long - 1L; //foreach (N; 0..10L^^2) //{ debug writeln("N:", N+1); long x = 26; long[] num; while (N >= 0) { num ~= N % 26; N -= x; if (N < 0) break; N /= 26; } debug writeln(num); char[] ans; foreach (i; 0..num.length) { ans ~= cast(char)('a'+num[i]); } ans.reverse(); writeln(ans); stdout.flush;//} debug readln; }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { auto ip = readln.split.to!(int[]), a = ip[0], b = ip[1]; int s = max(a+b, a-b, a*b); writeln(s); }
D
import std.stdio, std.array, std.conv, std.string, std.range, std.algorithm; void main() { long n = readln.strip.to!(long); string s = readln.strip; long l = 0, r = s.length - 1; while (l < s.length && s[l] == '.') { l++; } while (r >= 0 && s[r] == '#') { r--; } r++; long w = s[l..r].count('.'); long b = s[l..r].count('#'); long right = w; long left = 0; long m = left + right; foreach (i; l..r) { if (s[i] == '.') { right--; } else { left++; } m = min(m, left + right); } writeln(m); }
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; immutable long MOD = 10^^9 + 7; long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; } void main() { auto N = readln.chomp.to!int; auto S = readln.chomp; auto M = S.length.to!int; auto mem = new long[][](N + 1, N + 1); foreach (i; 0..N+1) fill(mem[i], -1); // dp(i, j) : i回キーを叩いてj文字入力されている場合の数 long dp(int i, int j) { if (i == 0 && j == 0) return 1; if (i <= 0 || j < 0) return 0; if (j > i) return 0; if (mem[i][j] >= 0) return mem[i][j]; long ret = 0; if (j == 0) { ret += dp(i - 1, j); ret %= MOD; } ret += dp(i - 1, j + 1); // Back Space ret %= MOD; ret += dp(i - 1, j - 1) * 2; // 0 or 1 ret %= MOD; return mem[i][j] = ret; } auto ans = dp(N, M); ans = ans * powmod(powmod(2, MOD-2, MOD), M, MOD) % MOD; ans.writeln; }
D
import std.stdio, std.typecons, std.algorithm; alias Tuple!(int, "top", int, "bottom") Bundle; const int INF = (1 << 24); void main() { int times; scanf("%d", &times); int[][] dp = new int[][](times, times); Bundle[] cards; foreach(i; 0..times) { int top, bottom; scanf("%d %d", &top, &bottom); cards ~= Bundle(top, bottom); dp[i][] = INF; dp[i][i] = 0; } // dp[i][j] -> i 番目 から j 番目を計算する時の最適コスト for(int len = 1; len < times; len++) { for(int s = 0; s + len < times; s++) { int f = s + len; for(int i = s; i < f; i++) { int cost = (cards[s].top * cards[i].bottom) * (cards[i + 1].top * cards[f].bottom); cost += dp[s][i] + dp[i + 1][f]; if (cost < dp[s][f]) dp[s][f] = cost; } } } writeln(dp[0][times - 1]); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); writeln(min(s.count('0'), s.count('1'))*2); }
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 p = uninitializedArray!(int[]) (n); auto pos = uninitializedArray!(int[]) (n + 1); foreach (i; 0 .. n) { p[i] = r.next!uint; pos[p[i]] = i; } auto e = new int[][n+1]; foreach (edgeid; 0 .. m) { immutable i = r.next!uint; immutable j = r.next!uint; e[i] ~= j; } debug stderr.writeln (e); int res; auto d = new bool[n+1]; int l = 1; foreach_reverse (i; 0 .. n - 1) { int cnt; immutable pi = p[i]; immutable pk = pos[pi]; foreach (j; e[pi]) { if (!d[j] && pk < pos[j]) ++cnt; } debug stderr.writeln (cnt, ' ', l); if (cnt == l) { ++res; d[pi] = true; } else { ++l; } } write (res); }
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; void main() { int[string] cnt; string len; auto str = readln.split; foreach (s; str) { if (s.length > len.length) { len = s; } cnt[s]++; } string mode; int mode_v; foreach (key; cnt.keys) { if (cnt[key] > mode_v) { mode = key; mode_v = cnt[key]; } } writeln(mode, " ", len); }
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 A = ["Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"]; writeln(A[lread() - 22]); }
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 n; readV(n); int[] a; readA(n, a); writeln(a.map!(ai => calc(ai)).reduce!min); } auto calc(int n) { auto r = 0; for (; n%2 == 0; n /= 2) ++r; return r; }
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]); bool ok=true; void f(){ int r=0; foreach(int i, int e; d){ ok&=i*10<=r; chmax(r, i*10+e); } } f(); reverse(d); f(); if(ok) writeln("yes"); else writeln("no"); } 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; 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() { "aiueo".canFind(readln.chomp.to!char).pipe!(a => a?"vowel":"consonant").writeln; }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; long MOD = 10L^^9+7; long f(long x, long y) { if (x==0 && y==0) return 1; long res = 0; if (x>=0 && y>=0) res = (res + memoize!f((x-0)>>1, (y-0)>>1))%MOD; if (x>=1 && y>=1) res = (res + memoize!f((x-1)>>1, (y-1)>>1))%MOD; if (x>=0 && y>=2) res = (res + memoize!f((x-0)>>1, (y-2)>>1))%MOD; return res; } void main() { readln.chomp.to!long.pipe!(N => f(N, N)).writeln; } // ---------------------------------------------- void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D
import std.algorithm; import std.array; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; immutable int letters = 26; string solve (string s) { auto n = s.length.to !(int); if (n == letters) { auto t = s.dup; if (nextPermutation (t.representation)) { auto r = t.idup; while (s < r[0..$ - 1]) { r = r[0..$ - 1]; } return r; } return "-1"; } else { foreach (c; 'a'..'z' + 1) { if (!s.canFind (c)) { return s ~ c.to !(char); } } assert (false); } } void main () { string s; while ((s = readln.strip) != "") { writeln (solve (s)); } }
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() { int n, q; scan(n, q); while (q--) { int vi, wi; scan(vi, wi); solve(n, vi, wi); } } void solve(int n, int v, int w) { if (n == 1) { writeln(min(v, w)); return; } auto va = new int[](0); va ~= v; while (v > 1) { v = (v + n - 2) / n; va ~= v; } auto wa = new int[](0); wa ~= w; while (w > 1) { w = (w + n - 2) / n; wa ~= w; } debug { writeln(va); writeln(wa); } int ans = 0; foreach (vi ; va) { foreach (wi ; wa) { if (vi == wi) { ans = max(ans, vi); } } } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio,std.conv,std.string; void main(){ auto n=readln.chomp.to!int; (n%2==0?n/2:n/2+1).writeln; }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { ulong[] NM = readln.chomp.split.to!(ulong[]); ulong N = NM[0], M = NM[1]; ulong x = 1900*M + 100*(N - M); ulong p = 1; foreach (_; 0..M) { p <<= 1; } writeln(x*p); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; import std.math; import std.regex; void main(){ auto a=readln.split.to!(int[]),n=a[0],k=a[1]; if(n%k>0)writeln(1); else if(n%k==0)writeln(0); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; auto a = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; void main() { auto s = readln.strip; foreach (i; 0 .. a.length) { if (a[i] == s) { writeln (7 - i); break; } } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; void main() { auto S = readln.chomp; auto T = readln.chomp; auto N = S.length.to!int; auto M = T.length.to!int; auto next = new int[][](M, 26); foreach (i; 0..M) fill(next[i], 1<<29); foreach (i; 0..M) { foreach_reverse (j; i..M) { next[i][T[j]-'a'] = j; } } auto dp = new int[][](N+1, M+1); auto prevc = new dchar[][](N+1, M+1); auto previ = new Tuple!(int, int)[][](N+1, M+1); foreach (i; 0..N+1) fill(previ[i], tuple(-1, -1)); foreach (i; 0..N) { foreach (j; 0..M) { { int nx = j; int nv = dp[i][j]; if (nv > dp[i+1][nx]) { dp[i+1][nx] = nv; prevc[i+1][nx] = prevc[i][j]; previ[i+1][nx] = previ[i][j]; } } if (next[j][S[i]-'a'] != 1<<29) { int nx = next[j][S[i]-'a'] + 1; int nv = dp[i][j] + 1; if (nv > dp[i+1][nx]) { dp[i+1][nx] = nv; prevc[i+1][nx] = S[i]; previ[i+1][nx] = tuple(i, j); } } } } int mi = 0; int mj = 0; int ms = 0; foreach (i; 0..N+1) { foreach (j; 0..M+1) { if (dp[i][j] > ms) { ms = dp[i][j]; mi = i; mj = j; } } } dchar[] ans; while (previ[mi][mj][0] != -1) { ans ~= prevc[mi][mj]; auto t = previ[mi][mj]; mi = t[0]; mj = t[1]; } ans.reverse; ans.writeln; }
D
import std.stdio, std.string, std.range, std.conv, std.algorithm, std.typecons; void main(){ alias Tuple!(int, int) Data; int N, M; auto input = readln.split.map!(to!int); N = input[0], M = input[1]; int[] A = new int[N]; //?????¨ foreach (i; 0..N) { A[i] = readln.chomp.to!int; } int[] vote = new int[N]; foreach (i; 0..M) { int B = readln.chomp.to!int; foreach (j; 0..N) { if (A[j] <= B) { vote[j]++; break; } } } int max, idx; foreach (i; 0..N) { if (vote[i] > max) { max = vote[i]; idx = i; } } writeln(idx+1); }
D
import std.algorithm; import std.array; import std.conv; import std.numeric; import std.stdio; import std.string; void main() { long n; long sum; n = readln.chomp.to!(long); sum = 0; for (long i = 1; i <= n; i++) { for (long j = 1; j <= n; j++) { for (long k = 1; k <= n; k++) { sum += gcd(i, gcd(j, k)); } } } writeln(sum); }
D
import std.stdio; import std.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; void main() { auto n = readln.chomp.to!long; foreach (seven; 0 .. (n / 7 + 1)) { if ((n - (7 * seven)) % 4 == 0) { "Yes".writeln; return; } } "No".writeln; }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}} void main() { int h, w; readV(h, w); string[] a; readC(h, a); auto sh = new bool[](h), sw = new bool[](w); foreach (i; 0..h) if (a[i].all!(ai => ai == '.')) sh[i] = true; foreach (j; 0..w) if (a.map!(ai => ai[j]).all!(aj => aj == '.')) sw[j] = true; foreach (i; 0..h) { if (sh[i]) continue; foreach (j; 0..w) { if (sw[j]) continue; write(a[i][j]); } writeln; } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n; scan(n); auto s = readln.chomp; int e, w; foreach (i ; 0 .. n) { if (s[i] == 'E') e++; } int ans = 1<<30; foreach (i ; 0 .. n) { if (ans > e + w) { ans = e + w; } if (s[i] == 'E') e--; if (s[i] == 'W') w++; } ans = min(ans, e + w); writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto str = readln.split(" "); writeln( str[0][$-1] == str[1][0] && str[1][$-1] == str[2][0] ? "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.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; auto i = RD; writeln(N - i + 1); stdout.flush(); debug readln(); }
D
import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; import std.container; void main() { auto input = readln.split.map!(to!int); int W = input[0]; int H = input[1]; int N = input[2]; int[4] A = [0, W, 0, H]; foreach (i; 0..N) { input = readln.split.map!(to!int); if (input[2]== 1) A[0] = max(A[0], input[0]); else if (input[2]== 2) A[1] = min(A[1], input[0]); else if (input[2]== 3) A[2] = max(A[2], input[1]); else if (input[2]== 4) A[3] = min(A[3], input[1]); } if (A[0] >= A[1] || A[2] >= A[3]) writeln(0); else writeln((A[1]-A[0])*(A[3]-A[2])); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void main() { int n; readV(n); int k; readV(k); auto r = 10^^9; foreach (i; 0..1<<n) { auto d = 1; foreach (j; 0..n) if (i.bitTest(j)) d *= 2; else d += k; r = min(r, d); } writeln(r); } 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, std.algorithm, std.range, std.conv, std.string, std.math; import core.stdc.stdio; // foreach, foreach_reverse, writeln class BIT { int[] data; this(int n) { data = new int[n+1]; } BIT dup() { BIT ret = new BIT(to!int(data.length)); ret.data = data.dup; return ret; } void add(int i, int x=1) { i++; while (i) { data[i] += x; i -= i&-i; } } int sum(int i) { int ret = 0; i++; while (i < data.length) { ret += data[i]; i += i&-i; } return ret; } } void main() { int n; scanf("%d\n", &n); int[] b = new int[n]; int[] w = new int[n]; int m = n*2; foreach (i; 0..m) { char c; int a; scanf("%c %d\n", &c, &a); if (c == 'B') { b[a-1] = i; } else { w[a-1] = i; } } int[][] dp = new int[][](n+1,n+1); foreach (i; 0..n+1) dp[i][] = to!int(1e9); dp[0][0] = 0; BIT bit = new BIT(m); foreach (i; 0..n+1) { BIT _bit = bit.dup(); foreach (j; 0..n+1) { if (i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+_bit.sum(b[i])); if (j < n) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+_bit.sum(w[j])); if (j < n) _bit.add(w[j]); } if (i < n) bit.add(b[i]); } writeln(dp[n][n]); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math; void main() { auto it = readln.split.to!(int[]); auto A = it[0]; auto B = it[1]; auto C = it[2]; auto X = it[3]; auto Y = it[4]; int cost; if (A + B > C*2) { if (X > Y) { cost += 2 * Y * C; X -= Y; Y = 0; } else { cost += 2 * X * C; Y -= X; X = 0; } } else { if (X > Y) { cost += A * Y + B * Y; X -= Y; Y = 0; } else { cost += A * X + B * X; Y -= X; X = 0; } } if (X > 0) { if (A > C*2) { cost += 2 * C * X; } else { cost += A * X; } } if (Y > 0) { if (B > C*2) { cost += 2 * C * Y; } else { cost += B * Y; } } writeln(cost); }
D
import std.stdio, std.conv, std.string; void main() { int N = to!int(chomp(readln())); string str = to!string(N); int count; foreach(char chr; str) { count += to!int(chr)-48; } if(N % count == 0) { writeln("Yes"); } else writeln("No"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { int n; foreach (c; readln.chomp) { if (c == '+') { ++n; } else { --n; } } writeln(n); }
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 A = RD; auto B = RD; long cnt = 1, ans; while (cnt < B) { cnt += A - 1; ++ans; } writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; import std.container; void main() { auto S = readln.chomp; char c = S[0]; int ans = 0; foreach (s; S) if (s != c) { ans += 1; c = s; } writeln(ans); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(string, "x", long, "y"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { long a, b; scan(a, b); if(a <= 8 && b <= 8) writeln("Yay!"); else writeln(":("); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto t = RD!int; auto ans = new int[](t); foreach (ti; 0..t) { auto n = RD!int; auto m = RD!int; auto a = new string[](n); foreach (i; 0..n) { a[i] = RD!string; } foreach (i; 0..n) { if (a[i][$-1] == 'R') ++ans[ti]; } foreach (i; 0..m) { if (a[$-1][i] == 'D') ++ans[ti]; } } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
D
import std.stdio, std.array, std.conv, std.algorithm, std.string, std.numeric, std.range; void main() { string s; while( (s=readln.strip).length != 0 ){ auto as = s.to!int; if(as == 0) break; int ans = 0; while(0 < as){ ans += as/5; as /= 5; } writeln(ans); } }
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; void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } 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() { string s = read!string; int n = 0; foreach (c; s) { if (c == 'o') n++; } auto m = 15 - s.length; if (n + m >= 8) writeln("YES"); else writeln("NO"); }
D
import std.stdio, std.conv, std.string, std.range, std.typecons, std.format; import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.mutation; void main() { string input = readln().strip(); foreach(c; input) { write(c=='1'?'9':'1'); } writeln(""); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n; long a, b; readV(n, a, b); long[] x; readA(n, x); auto ans = 0L; foreach (i; 1..n) ans += min((x[i]-x[i-1])*a, b); writeln(ans); }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; int solve (string s) { auto n = s.length.to !(int); s ~= ".?!"; auto f = new int [3] [n + 4]; f[1][1] = 1; f[2][2] = 1; foreach (i; 0..n) { foreach (j; 1..3) { if (f[i][j]) { f[i + 3 - j][3 - j] = max (f[i + 3 - j][3 - j], f[i][j] + 1); if (s[i - j..i] != s[i..i + j]) { f[i + j][j] = max (f[i + j][j], f[i][j] + 1); } } } } return max (f[n][1], f[n][2]); } void main () { string s; while ((s = readln.strip) != "") { writeln (solve (s)); } }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.bitmanip; void main() { immutable n = readln.strip.to!int; auto s = readln.strip; BitArray m1, m2, m3; m1.length = 10; m2.length = 100; m3.length = 1000; debug stderr.writeln (s); foreach (i; 0 .. n) { int x = s[i].to!int - 48; foreach (k; m2.bitsSet ()) { m3[10 * k + x] = true; } foreach (k; m1.bitsSet ()) { m2[10 * k + x] = true; } m1[x] = true; } int c; foreach (k; m3.bitsSet()) ++c; writeln (c); }
D
import std.algorithm; import std.array; import std.stdio; import std.numeric; import std.conv; void main(){ auto input = readln.split.map!(to!int); gcd(input[0], input[1]).writeln; }
D
import std.stdio; import std.algorithm; import std.conv; import std.numeric; import std.math; import std.string; void main() { auto tokens = split(chomp(readln())); auto N = to!ulong(tokens[0]); if (N == 1) writeln("Hello World"); else { auto a = to!int(chomp(readln())); auto b = to!int(chomp(readln())); 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; ulong MOD = 1_000_000_007; ulong INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias t = Tuple!(string, "name", long, "y"); void main() { auto x = lread(); auto rest = x % 100; foreach (a; iota(100 / 1)) { foreach (b; iota(100 / 2)) { foreach (c; iota(100 / 3)) { foreach (d; iota(100 / 4)) { foreach (e; iota(100 / 5)) { if((a + 2 * b + 3 * c + 4 * d + 5 * e) == rest) { auto s = a + b + c + d + e; if(s * 100 <= x - rest) { writeln(1); return; } } } } } } } writeln(0); } 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.string, std.conv; import std.algorithm, std.array; auto solve(string s_) { immutable N = s_.to!int(); auto ab = new long[2][N]; foreach(ref v;ab) v = readln.split.map!(to!long).array(); long c=0; foreach_reverse(ref v;ab) { immutable a=v[0], b=v[1]; c+=(b-(a+c)%b)%b; } return c; } void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { int n = readint; int ans = 100_000; for (int i = 0; i < n; i++) { ans = ans * 105 / 100; if (ans % 1000 > 0) { ans += 1000 - (ans % 1000); } } 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.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto M = RD; auto cnt = new long[](N); foreach (i; 0..M) { auto a = RD-1; auto b = RD-1; ++cnt[a]; ++cnt[b]; } bool ans = true; foreach (i; 0..N) { if (cnt[i] % 2 == 1) { ans = false; break; } } writeln(ans ? "YES" : "NO"); stdout.flush; debug readln; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); } void main() { auto N = RD; auto X = RD; auto M = RD; auto pos = new long[](M); pos[] = -1; auto a = X; pos[a] = 0; auto cnt = new long[](M); cnt[0] = a; long ans = a; foreach (i; 1..min(N, M+1)) { auto last = cnt[a]; a = (a*a) % M; if (pos[a] == -1) { pos[a] = i; cnt[a] = last + a; ans += a; } else { auto len = i - pos[a]; auto loopCnt = last - cnt[a] + a; auto rem = N - i; auto loop = rem / len; auto loopRem = rem % len; ans += loop * loopCnt; foreach (j; 0..loopRem) { ans += a; a = (a*a) % M; } break; } } writeln(ans); stdout.flush; debug readln; }
D
import std.string, std.stdio, std.algorithm; void main() { char[] s = readln.chomp.dup.reverse; writeln(s); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.numeric; void main() { auto x = readln.chomp.to!int; int sum; auto i = 1; while (sum < x) { sum += i; i++; } (i-1).writeln; }
D
void main(){ string s = readln().chomp(); if(s.count('a') == 1 && s.count('b') == 1 && s.count('c') == 1){ writeln("Yes"); }else{ writeln("No"); } } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; // 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 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() { writeln(48 - lread()); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { long a, b; scan(a, b); writeln(a / gcd(a, b) * b); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
import std.algorithm; import std.conv; import std.stdio; import std.string; void main() { string[] b_type = [ "A", "B", "AB", "O" ]; int[string] b_counter; foreach (b; b_type) { b_counter[b] = 0; } foreach (string line; stdin.lines) { string b = line.chomp.split(",")[1]; b_counter[b]++; } foreach (b; b_type) { b_counter[b].writeln; } }
D
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range; void main() { auto N = readln.chomp.to!int; writeln(N / 10 == 9 || N % 10 == 9 ? "Yes" : "No"); }
D
import std.stdio,std.string,std.array,std.algorithm,std.range,std.conv; int main(){ auto s=readln.chomp; auto n=s.length; if(s.equal(s.retro)){ auto s1=s[0..(n-1)/2]; if(s1.equal(s1.retro)){ auto s2=s[(n+3)/2-1..$]; if(s2.equal(s2.retro)){ "Yes".writeln; return 0; } } } "No".writeln; return 0; }
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);} const mod = 10^^9+7; void main() { int n; readV(n); auto ans = 1L; foreach (i; 1..n+1) (ans *= i) %= mod; writeln(ans); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_t; 0..T) { auto N = readln.chomp.to!long; long a = 2L^^N, b; foreach (i; 1..N/2) { a += 2L^^i; } foreach (i; N/2..N) { b += 2L^^i; } writeln(a - b); } }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { ulong N = readln.chomp.to!ulong; ulong[] a = readln.chomp.split.to!(ulong[]); ulong[ulong] h; foreach (e; a) { if (e in h) { h[e]++; } else { h[e] = 1; } } ulong ans; foreach (k, v; h) { if (k < v) { ans += v - k; } else if (k > v) { ans += v; } } writeln(ans); }
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_007; void main() { int a, b; scan(a, b); if ((a + b) % 2) { writeln("IMPOSSIBLE"); return; } int ans = (a + b) / 2; writeln(ans); } int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new int[][](n, 0); foreach (i; 0 .. m) { int u, v; scan(u, v); if (is1indexed) { u--, v--; } adj[u] ~= v; if (isUndirected) { adj[v] ~= u; } } return adj; } alias Edge = Tuple!(int, "to", int, "cost"); Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new Edge[][](n, 0); foreach (i; 0 .. m) { int u, v, c; scan(u, v, c); if (is1indexed) { u--, v--; } adj[u] ~= Edge(v, c); if (isUndirected) { adj[v] ~= Edge(u, c); } } return adj; } void yes(bool b) { writeln(b ? "Yes" : "No"); } void YES(bool b) { writeln(b ? "YES" : "NO"); } T[] readArr(T)() { return readln.split.to!(T[]); } T[] readArrByLines(T)(int n) { return iota(n).map!(i => readln.chomp.to!T).array; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void get(Args...)(ref Args args) { import std.traits, std.meta, std.typecons; static if (Args.length == 1) { alias Arg = Args[0]; static if (isArray!Arg) { static if (isSomeChar!(ElementType!Arg)) { args[0] = readln.chomp.to!Arg; } else { args[0] = readln.split.to!Arg; } } else static if (isTuple!Arg) { auto input = readln.split; static foreach (i; 0..Fields!Arg.length) { args[0][i] = input[i].to!(Fields!Arg[i]); } } else { args[0] = readln.chomp.to!Arg; } } else { auto input = readln.split; assert(input.length == Args.length); static foreach (i; 0..Args.length) { args[i] = input[i].to!(Args[i]); } } } void get_lines(Args...)(size_t N, ref Args args) { import std.traits, std.range; static foreach (i; 0..Args.length) { static assert(isArray!(Args[i])); args[i].length = N; } foreach (i; 0..N) { static if (Args.length == 1) { get(args[0][i]); } else { auto input = readln.split; static foreach (j; 0..Args.length) { args[j][i] = input[j].to!(ElementType!(Args[j])); } } } } void main() { int T; get(T); while (T--) { int n, k; get(n, k); int[] hs; get(hs); int l = hs[0]; foreach (i, h; hs[1..$-1]) { if (l + k <= h || l - k + 1 > h + k - 1) goto ng; if (hs[i+2] >= h) { l = min(l + k - 1, h + k - 1); } else { l = max(l - k + 1, h); } } if (abs(hs[$-1] - l) >= k) goto ng; writeln("YES"); continue; ng: writeln("NO"); } }
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; import std.typecons, std.regex; void main() { auto s = read.to!string; writeln(s[0..$-8]); } string read() { static string[] ss; while (!ss.length) ss = readln.chomp.split; auto res = ss[0]; ss.popFront; return res; }
D
import std.stdio; import std.string; import std.conv; void main() { int times = readln.chomp.to!(int); foreach(t; 0..times) { dchar[] line = readln.chomp.dup.to!(dchar[]); if ( line.length >= 6) { for(uint i = 0; i < line.length - 6; i++) { if (line[i..(i + 7)] == "Hoshino") { line[i..(i + 7)] = "Hoshina"; } } } writeln(line); } }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int H, A; scan(H, A); int ans = (H + A - 1) / A; 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; 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; scan(A, B); bool b = (A % 3) == 0 || (B % 3) == 0 || ((A + B) % 3) == 0; writeln(b ? "Possible" : "Impossible"); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long 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() { long[] arr; arr ~= RD; arr ~= RD; arr ~= RD; arr ~= RD; arr ~= RD; auto K = RD; bool ans = true; foreach (i; 0..5) { foreach (j; i+1..5) { if (abs(arr[i] - arr[j]) > K) ans = false; } } writeln(ans ? "Yay!" : ":("); stdout.flush(); debug readln(); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; void main(){ auto N=readln.chomp.to!int; auto A=readln.chomp.to!int; if(N%500<=A)writeln("Yes"); else if(N%500>A)writeln("No"); }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { auto q = readln.chomp.to!int; for(int i=0;i<q;++i){ auto b = readln.split.map!(to!int); int c=b[0],a=b[1],n=b[2]; int ans=0; if(a<n){ ans+=min(c,a); c=max(0,c-ans); a=max(0,a-ans); n=max(0,n-ans); }else{ ans+=min(c,n); c=max(0,c-ans); a=max(0,a-ans); n=max(0,n-ans); } if(a>0){ int x = min(c/2,a); c=max(0,c-2*x); a=max(0,a-x); ans+=x; } ans+=c/3; ans.writeln(); } }
D
void main(){ string s = readln().chomp(); string t = readln().chomp(); if( s==t[0..s.length] && t[s.length..$].length==1 ){ writeln("Yes"); }else{ writeln("No"); } } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto S = readln.chomp; auto T = readln.chomp; char[char] c0, c1; foreach (i; 0..S.length) { const s = S[i]; const t = T[i]; if (s !in c0 && t !in c1) { c0[s] = t; c1[t] = s; } if (s in c0 && c0[s] != t) { writeln("No"); return; } if (t in c1 && c1[t] != s) { writeln("No"); return; } } writeln("Yes"); }
D
import std.stdio, std.range, std.conv, std.string; import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting; void main() { int[] input = readln().split.to!(int[]); int H = input[0]; int W = input[1]; input = readln().split.to!(int[]); int h = input[0]; int w = input[1]; writeln((H-h)*(W-w)); }
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(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() { /*foreach (n; 2..10) { auto a = new int[][](21, 21); long[][] q = [[9, 10, 0, n-1], [11, 10, 0, n-1], [10, 9, 1, n-1], [10, 11, 1, n-1]]; while (!q.empty) { auto nd = q.front; q.popFront; auto y = nd[0]; auto x = nd[1]; auto dir = nd[2]; auto rem = nd[3]; if (rem == 0) { a[y][x] = 1; continue; } if (dir == 0) { q ~= [y, x-1, 1, rem-1]; q ~= [y, x+1, 1, rem-1]; } else { q ~= [y-1, x, 0, rem-1]; q ~= [y+1, x, 0, rem-1]; } } long cnt; foreach (y; 0..21) { writeln(a[y]); foreach (x; 0..21) { if (a[y][x]) ++cnt; } } writeln("cnt:", cnt); }*/ auto t = 1;//RD!int; auto ans = new long[](t); foreach (ti; 0..t) { auto n = RD!int; auto m = (n+1) / 2 * 2 + 1; if (n % 2) { ans[ti] = (m^^2) / 2; } else { ans[ti] = ((m+1) / 2)^^2; } } foreach (e; ans) { writeln(e); } stdout.flush; debug readln; }
D
import core.stdc.stdio; import std.algorithm; void main(){ int s,t; scanf("%d%d",&s,&t); char[] x = new char[s+1],y=new char[t+1]; scanf("%s%s",x.ptr,y.ptr); int[][][] dp = new int[][][](2,s+1,t+1); foreach(d;dp[0]) d[]=-1145141919; foreach(i;0..s+1) foreach(j;0..t+1){ if(i<s) if(x[i]=='I') dp[0][i+1][j]=max(dp[0][i+1][j],dp[1][i][j]+1); else dp[1][i+1][j]=max(dp[1][i+1][j],dp[0][i][j]+1); if(j<t) if(y[j]=='I') dp[0][i][j+1]=max(dp[0][i][j+1],dp[1][i][j]+1); else dp[1][i][j+1]=max(dp[1][i][j+1],dp[0][i][j]+1); } int ans=0; foreach(ds;dp[0]) foreach(d;ds) ans=max(ans,d); printf("%d\n",ans); }
D
/+ dub.sdl: name "D" dependency "dunkelheit" version="1.0.1" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner, dkh.numeric.prime; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); debug { foreach (n; 3..1001) { bool ok = false; foreach (m; n..(n + n / 4 * 2) + 1) { if (isPrime(m)) { ok = true; writefln("find %d : %d", n, m); stdout.flush; break; } } if (!ok) { writeln("ERROR ", n); return 0; } } } int n; sc.read(n); foreach (m; n..(n + n / 4 * 2) + 1) { if (isPrime(m)) { int[2][] edges; foreach (i; 0..n) { edges ~= [i, (i + 1) % n]; } foreach (i; 0..n) { if (i % 4 >= 2) continue; if (edges.length.to!int >= m) break; edges ~= [i, (i + 2) % n]; } writeln(m); foreach (d; edges) { writeln(d[0] + 1, " ", d[1] + 1); } return 0; } } return 0; } /* 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(); } } /* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/numeric/prime.d */ // module dkh.numeric.prime; import std.traits; // import dkh.int128; ulong ulongPowMod(U)(ulong x, U n, ulong md) if (isIntegral!U || is(U == BigInt)) { x %= md; ulong r = 1; while (n) { if (n & 1) { r = mul128(r, x).mod128(md); } x = mul128(x, x).mod128(md); n >>= 1; } return r % md; } T[] divisorList(T)(T x) { import std.algorithm : sort; T[] res; for (T i = 1; i*i <= x; i++) { if (x%i == 0) { res ~= i; if (i*i != x) res ~= x/i; } } sort(res); return res; } T[] factorList(T)(T x) { T[] res; for (T i = 2; i*i <= x; i++) { while (x % i == 0) { res ~= i; x /= i; } } if (x > 1) res ~= x; return res; } // import dkh.numeric.primitive; bool isPrime(ulong n) { // import dkh.int128; if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; ulong d = n-1; while (d % 2 == 0) d /= 2; ulong[] alist = [2,3,5,7,11,13,17,19,23,29,31,37]; foreach (a; alist) { if (n <= a) break; ulong y = ulongPowMod(a, d, n); ulong t = d; while (t != n-1 && y != 1 && y != n-1) { y = mul128(y, y).mod128(n); t <<= 1; } if (y != n-1 && t % 2 == 0) { return false; } } return true; } /* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/numeric/primitive.d */ // module dkh.numeric.primitive; import std.traits, std.bigint; T lcm(T)(in T a, in T b) { import std.numeric : gcd; return a / gcd(a,b) * b; } Unqual!T pow(T, U)(T x, U n) if (!isFloatingPoint!T && (isIntegral!U || is(U == BigInt))) { return pow(x, n, T(1)); } Unqual!T pow(T, U, V)(T x, U n, V e) if ((isIntegral!U || is(U == BigInt)) && is(Unqual!T == Unqual!V)) { Unqual!T b = x, v = e; Unqual!U m = n; while (m) { if (m & 1) v *= b; b *= b; m /= 2; } return v; } T powMod(T, U, V)(T x, U n, V md) if (isIntegral!U || is(U == BigInt)) { T r = T(1); Unqual!U m = n; while (m) { if (m & 1) r = (r*x)%md; x = (x*x)%md; m >>= 1; } return r % md; } T[3] extGcd(T)(in T a, in T b) if (!isIntegral!T || isSigned!T) { if (b==0) { return [T(1), T(0), a]; } else { auto e = extGcd(b, a%b); return [e[1], e[0]-a/b*e[1], e[2]]; } } T invMod(T)(T x, T md) { auto r = extGcd!T(x, md); assert(r[2] == 1); auto z = r[0]; return (z % md + md) % md; } /* 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/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/ldc/inline.d */ // module dkh.ldc.inline; version(LDC) { pragma(LDC_inline_ir) R inlineIR(string s, R, P...)(P); } /* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/int128.d */ // module dkh.int128; version(LDC) { // import dkh.ldc.inline; } version(LDC) version(X86_64) { version = LDC_IR; } ulong[2] mul128(ulong a, ulong b) { ulong[2] res; version(LDC_IR) { ulong upper, lower; inlineIR!(` %r0 = zext i64 %0 to i128 %r1 = zext i64 %1 to i128 %r2 = mul i128 %r1, %r0 %r3 = trunc i128 %r2 to i64 %r4 = lshr i128 %r2, 64 %r5 = trunc i128 %r4 to i64 store i64 %r3, i64* %2 store i64 %r5, i64* %3`, void)(a, b, &lower, &upper); return [lower, upper]; } else version(D_InlineAsm_X86_64) { ulong upper, lower; asm { mov RAX, a; mul b; mov lower, RAX; mov upper, RDX; } return [lower, upper]; } else { ulong B = 2UL^^32; ulong[2] a2 = [a % B, a / B]; ulong[2] b2 = [b % B, b / B]; ulong[4] c; foreach (i; 0..2) { foreach (j; 0..2) { c[i+j] += a2[i] * b2[j] % B; c[i+j+1] += a2[i] * b2[j] / B; } } foreach (i; 0..3) { c[i+1] += c[i] / B; c[i] %= B; } return [c[0] + c[1] * B, c[2] + c[3] * B]; } } ulong div128(ulong[2] a, ulong b) { version(LDC_IR) { return inlineIR!(` %r0 = zext i64 %0 to i128 %r1 = zext i64 %1 to i128 %r2 = shl i128 %r1, 64 %r3 = add i128 %r0, %r2 %r4 = zext i64 %2 to i128 %r5 = udiv i128 %r3, %r4 %r6 = trunc i128 %r5 to i64 ret i64 %r6`,ulong)(a[0], a[1], b); } else version(D_InlineAsm_X86_64) { ulong upper = a[1], lower = a[0]; ulong res; asm { mov RDX, upper; mov RAX, lower; div b; mov res, RAX; } return res; } else { if (b == 1) return a[0]; while (!(b & (1UL << 63))) { a[1] <<= 1; if (a[0] & (1UL << 63)) a[1] |= 1; a[0] <<= 1; b <<= 1; } ulong ans = 0; foreach (i; 0..64) { bool up = (a[1] & (1UL << 63)) != 0; a[1] <<= 1; if (a[0] & (1UL << 63)) a[1] |= 1; a[0] <<= 1; ans <<= 1; if (up || b <= a[1]) { a[1] -= b; ans++; } } return ans; } } ulong mod128(ulong[2] a, ulong b) { version(D_InlineAsm_X86_64) { ulong upper = a[1], lower = a[0]; ulong res; asm { mov RDX, upper; mov RAX, lower; div b; mov res, RDX; } return res; } else { return a[0] - div128(a, b) * b; } } /* This source code generated by dunkelheit and include dunkelheit's source code. dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit) dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt) */
D
import std.stdio; void main() { string[] weather = ['S' : "Cloudy", 'C' : "Rainy", 'R' : "Sunny"]; weather[readln[0]].writeln; }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto s = readln.chomp.to!(char[]); auto bf = new int[](26), af = new int[](26); int kind = 0; foreach (c; s) { af[c - 'a']++; if (af[c - 'a'] == 1) { kind++; } } int ans = 0, mod = 998244353; for (int i = 0, j = 0; i < n; i++) { // [i, j) remove while (j < n && kind >= 2) { if ((--af[s[j++] - 'a']) == 0) { kind--; } } if (kind == 1) { ans += (n - j + 1); ans %= mod; } if ((++af[s[i] - 'a']) == 1) { kind++; } } writeln(ans); } 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, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long.max/3; enum MOD = 10L^^9+7; //辞書順順列はiota(1,N),nextPermituionを使う void end(T)(T v) if(isIntegral!T||isSomeString!T||isSomeChar!T) { import core.stdc.stdlib; writeln(v); exit(0); } T[] scanArray(T = long)() { static char[] scanBuf; readln(scanBuf); return scanBuf.split.to!(T[]); } dchar scanChar() { int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } return cast(dchar)c; } T scanElem(T = long)() { import core.stdc.stdlib; static auto scanBuf = appender!(char[])([]); scanBuf.clear; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { scanBuf ~= cast(char) c; c = getchar; } return scanBuf.data.to!T; } dchar[] scanString(){ return scanElem!(dchar[]); } void main() { auto s = scanString; if(s[0]==s[2])end("Yes");end("No"); }
D
import std.stdio, std.algorithm; void main() { enum cs = "MARCH"; size_t[char] d; foreach (c; cs) { d[c] = 0; } foreach (s; stdin.byLine) { if (s[0] in d) { ++d[s[0]]; } } size_t ret = 0; foreach (i, c0; cs[0..$-2]) { if (d[c0] == 0) continue; foreach (j, c1; cs[i+1..$-1]) { if (d[c1] == 0) continue; foreach (k, c2; cs[i+1+j+1..$]) { if (d[c2] == 0) continue; ret += d[c0] * d[c1] * d[c2]; } } } writeln(ret); }
D
void main() { long[] tmp = readln.split.to!(long[]); long a = tmp[0], b = tmp[1], c = tmp[2]; writeln(a + b >= c - 1 ? b + c : 2 * b + a + 1); } 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 : writeln; void main() { int a,b,c,d; scan(a,b,c,d); if (a+b > c+d) { writeln("Left"); } else if (a+b < c+d) { writeln("Right"); } else { writeln("Balanced"); } } void scan(T...)(ref T args) { import std.stdio : readln; import std.array : split; import std.conv : to; import std.range.primitives; 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.conv, std.string, std.algorithm; void main() { writeln(readln.split.to!(uint[]).reduce!"a*b" % 2 == 0 ? "Even" : "Odd"); }
D
void main() { string s = rdStr; long len = s.length; long l, r = len - 1; long cnt; while (l < r) { if (s[l] == s[r]) { ++l, --r; } else { if (s[l] == 'x') { ++cnt; ++l; } else if (s[r] == 'x') { ++cnt; --r; } else { writeln(-1); return; } } } cnt.writeln; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; 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.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni;
D