code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; void main(){ auto ab = readln().chomp().split().map!(to!int).array(); ab.solve().writeln(); } int solve(int[] input){ auto a = input[0]; auto b = input[1]; if (b >= a){ return a; }else{ return a - 1; } }
D
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } /* ---------------------------------------- xs[m]は、 mの立っているビットの個数をkとするとき、 mのビットが立っているところにいるk人のと、 0番からk - 1番までの男との間で成立するマッチングの個数 を表すとする xs[0] = 1 xs[m]は、累乗を用いて m = or(i; 0 .. k) m[i] とかかれるとき m = sum xs[m[i] xor m] ただしこの和は、k - 1番の男とm[i]の表す女がマッチする場合にわたる和 求めるものは xs[1<<n - 1] ---------------------------------------- xs[0] = 1 xs[m]は、(i; 0 .. n) に対して、以下の和 mのビットの立っている個数をkとする 1<<i & m == 0 ならば 0 1<<i & m > 0 であって、 as[i][k - 1] == 0 ならば 0 as[i][k - 1] > 0 ならば xs[m ^ (1<<i)] */ const long mod = 1_000_000_007; void main(){ int n = read.to!int; int[][] as; foreach(i; 0 .. n) as ~= readln.chomp.split.map!(to!int).array; long[] xs = [1]; foreach(m; 1 .. 1<<n){ long k = 0; foreach(i; 0 .. n) if(m & (1<<i)) k += 1; long x = 0; foreach(i; 0 .. n){ debug writeln("m:", m, " k:", k, " i:", i, " xs:", xs); if(m & (1<<i)) if(as[i][k - 1] > 0){ x += xs[m ^ (1<<i)]; x %= mod; } } xs ~= x; } xs[(1<<n) - 1].writeln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp; auto t = ""; foreach (c; s) switch (c) { case '0': case '1': t ~= c; break; case 'B': t = t.empty ? t : t[0..$-1]; break; default: assert(0); } writeln(t); }
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; readV(n); int[] h; readA(n, h); h ~= 0; for (auto i = 0; ; ++i) { auto l = h.countUntil!"a>0"; if (l == -1) { writeln(i); return; } auto c = h[l..$].countUntil(0); --h[l..l+c]; } }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.functional; void main() { auto N = readln.chomp.to!int; int cx = 0, cy = 0; int ct = 0; bool ok = true; foreach (i; 0..N) { auto tmp = readln.split.to!(int[]); if (!ok) continue; auto t = tmp[0]; auto x = tmp[1]; auto y = tmp[2]; auto dt = t - ct; auto dx = x - cx; auto dy = y - cy; auto d = abs(dx) + abs(dy); if (d > dt) ok = false; if ((dt - d) % 2 == 1) ok = false; cx = x; cy = y; ct = t; } writeln(ok ? "Yes" : "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() { immutable N = readln.chomp.to!long; long res; foreach (i; 1..N.to!real.sqrt.to!long+1) { if (N / i == i) { continue; } if (N % i == 0) { immutable t = N / i - 1; if (N % t) { res += t; } } } res.writeln; }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int N, A, B; scan(N, A, B); string s = readln.chomp; int tot, avs; foreach (i ; 0 .. N) { bool ok; if (s[i] == 'a') { if (tot < A + B) { ok = true; } } else if (s[i] == 'b') { if (tot < A + B && avs < B) { ok = true; } } yes(ok); if (ok) { tot++; if (s[i] == 'b') { avs++; } } } } void scan(T...)(ref T args) { auto line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront; } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x > arg) { x = arg; isChanged = true; } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x < arg) { x = arg; isChanged = true; } return isChanged; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }
D
import std; 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 x, a, b; scan(x, a, b); long A = abs(x - a); long B = abs(x - b); if (min(A, B) == A) { writeln('A'); } else { writeln('B'); } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main(){ auto a=readln.split.to!(int[]),x=a[0],y=a[1]; writeln(x+y/2); }
D
import std; void main() { auto K = readln.split[0].to!int; auto AB = readln.split.to!(int[]); auto A = AB[0], B = AB[1]; foreach (i; A .. B+1) { if (i % K == 0) { writeln("OK"); return; } } writeln("NG"); }
D
void main() { string s = readln.chomp; string s1 = s[0..2], s2 = s[2..$]; bool yymm, mmyy; if ("01" <= s1 && s1 <= "12") mmyy = true; if ("01" <= s2 && s2 <= "12") yymm = true; if (yymm && mmyy) { writeln("AMBIGUOUS"); } else if (yymm && !mmyy) { writeln("YYMM"); } else if (!yymm && mmyy) { writeln("MMYY"); } else { writeln("NA"); } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.container; import std.typecons;
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } enum MOD = (10 ^^ 9) + 7; void main() { long N, M; scan(N, M); auto G = new long[][](N, N); foreach (_; 0 .. M) { long a, b; scan(a, b); G[a - 1][b - 1] = G[b - 1][a - 1] = 1; } // foreach (g; G) // writeln(g); auto ID = new long[](N); auto L = new long[](N); auto visited = new bool[][](N, N); ID[] = -1; ID[0] = 0; L[] = -1; L[0] = 0; long cnt; long id; long[] stack = [0]; loop: while (!stack.empty) { long x = stack.back; // writeln(x); // writeln(L, stack); foreach (i; 0 .. N) if (G[x][i] == 1 && !visited[x][i]) { visited[x][i] = visited[i][x] = true; if (ID[i] == -1) { ID[i] = L[i] = ++id; stack ~= i; } L[x] = L[x].min(ID[i]).min(L[i]); continue loop; } stack.popBack(); // writefln("back: %d-%d %d %d", x, stack.back, L[x], ID[x]); if (!stack.empty) { L[stack.back] = L[stack.back].min(ID[x]).min(L[x]); if (L[x] == ID[x]) { cnt++; } } } writeln(cnt); }
D
import std.stdio; import std.string; import std.array; // split import std.conv; // to void main() { string n = chomp(readln()); int a = to!int(n); if(a/100%10 == a/10%10 && (a/100%10 == a/1000 || a/100%10 == a%10)){ writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto N = readln.chomp.to!int; auto S = N.iota.map!(_ => readln.chomp).array; long ans = 0; foreach (i; 0..N) { bool ok = true; int a = 0; int b = i; foreach (j; 0..N) { int c = (a + j) % N; int d = (b + j) % N; foreach (k; 1..N-j) { if (S[(c+k)%N][d] != S[c][(d+k)%N]) { ok = false; } } } ans += ok * N; } ans.writeln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); long ans; foreach (i; 0 .. S.length / 2) if (S[i] != S[$ - i - 1]) { ans++; } writeln(ans); }
D
// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; int n; void main() { while (true) { scan(n); if (n == 0) break; writeln(solve(n)); } } int solve(int n) { int res; foreach (l ; 0 .. n) { foreach (r ; l + 2 .. n) { int x = r * (r + 1) / 2 - l * (l + 1) / 2; if (x == n) { debug { writeln('[', l, ", ", r, ']'); } res++; } } } return res; } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.algorithm, 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 x; readV(x); auto ans = x/11*2, m = x%11; if (m >= 1 && m <= 6) ++ans; else if (m > 6) ans += 2; writeln(ans); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto r = readln.chomp.to!int; auto g = readln.chomp.to!int; writeln(2 * g - r); }
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; const long INF = 1L << 59; const long MOD = 10 ^^ 9 + 7; void main() { auto N = readln.chomp.to!int; auto edges = new Tuple!(int, long)[][](N); foreach (i; 0..N-1) { auto s = readln.split.map!(to!int); edges[s[0] - 1] ~= tuple(s[1] - 1, s[2].to!long); edges[s[1] - 1] ~= tuple(s[0] - 1, s[2].to!long); } auto dist = new long[](N); void dfs(int n, int p, long c) { dist[n] = c; foreach (m; edges[n]) if (m[0] != p) dfs(m[0], n, c + m[1]); } auto s = readln.split.map!(to!int); auto Q = s[0]; auto K = s[1] - 1; dfs(K, -1, 0); while (Q--) { s = readln.split.map!(to!int); writeln(dist[s[0] - 1] + dist[s[1] - 1]); } }
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 N = readln.split[0].to!int; auto S = readln.split[0].to!(dchar[]); auto K = readln.split[0].to!int; string ans = ""; auto c = S[K-1]; foreach (d; S) { if (d == c) ans ~= d; else ans ~= '*'; } writeln(ans); }
D
import std.stdio; import std.string; import std.conv; int main() { string[] str; while (true) { str = readln().split(); int num1 = str[0].to!int(); char op = str[1].to!char(); int num2 = str[2].to!int(); switch (op) { case '+': writeln(num1 + num2); break; case '-': writeln(num1 - num2); break; case '*': writeln(num1 * num2); break; case '/': writeln(num1 / num2); break; default : break; } if (op == '?') break; } return 0; }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; } enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { readln; readln.chomp.uniq.count.writeln; }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto s = readln.chomp.to!ulong; bool[1000000] memo; foreach (i; 0..1000000) { memo[s] = true; auto a = s & 1 ? (3*s+1) : (s/2); if (memo[a]) { writeln(i+2); return; } s = a; } }
D
import std.stdio; import std.string; import std.conv; void main() { double[] weight = [48, 51, 54, 57, 60, 64, 69, 75, 81, 91]; string[] names = ["light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"]; while(true) { string line = readln.chomp; if (stdin.eof) break; double num = line.to!(double); string ans; if (weight[0] >= num) ans = names[0]; else if (weight[$ - 1] < num) ans = names[$ - 1]; else { for(uint i = 0; i < (weight.length - 1); i++) { if (weight[i] < num && num <= weight[i + 1]) { ans = names[i + 1]; } } } writeln(ans); } }
D
import std.stdio; import std.regex; void main(){ auto io = new IO(); auto N = io.line()[0]; auto K = io.line()[0]; auto X = io.line()[0]; auto Y = io.line()[0]; size_t fee = 0; if( N>K ){ fee += K*X; fee += (N-K)*Y; }else{ fee += N*X; } writeln(fee); return; } import std.stdio,std.conv,std.string; import std.algorithm,std.array,std.math; immutable PRIME = 1_000_000_007; immutable alphaB = "abcdefghijklmnopqrstuvwxyz"; immutable alphaU = "ABCDRFGHIJKLMNOPQRSTUVWXYZ"; class IO { T[] line( T = size_t , string token = " " )( size_t m = 1 ){ T[] arr = []; foreach( i ; 0..m ){ arr ~= this.read!T(); } return arr; } T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){ T[][] arr = new T[][](m); foreach( i ; 0..m ){ arr[i] = this.read!T(token); } return arr; } private T[] read( T = size_t )( string token = " " ){ T[] arr; foreach( elm ; readln().chomp().split(token) ){ arr ~= elm.to!T(); } return arr; } void swap( T )( ref T x , ref T y ){ x = x^y; y = x^y; x = x^y; } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!int; auto a = readln.chomp.to!int; writeln(n * n - a); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto S = readln.chomp.to!(wchar[]); auto T = readln.chomp.to!(wchar[]); foreach (_; 0..101) { if (S == T) { writeln("Yes"); return; } S = [S[$-1]] ~ S[0..$-1]; } writeln("No"); }
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 A, V; scan(A, V); long B, W; scan(B, W); long T = lread(); if (V - W <= 0) { writeln("NO"); return; } if (abs(A - B) <= T * (V - W)) { writeln("YES"); return; } writeln("NO"); }
D
import std.stdio; import std.ascii; import std.algorithm; import core.stdc.stdio; int main() { auto t = readInt!int; foreach(ti; 0 .. t) { int[4] s; s[0] = readInt!int; s[1] = readInt!int; s[2] = readInt!int; s[3] = readInt!int; if (min(s[2], s[3]) > max(s[0], s[1]) || min(s[0], s[1]) > max(s[2], s[3])) { writeln("NO"); } else writeln("YES"); } return 0; } /* INPUT ROUTINES */ int currChar; static this() { currChar = getchar(); } char topChar() { return cast(char) currChar; } void popChar() { currChar = getchar(); } auto readInt(T)() { T num = 0; int sgn = 0; while (topChar.isWhite) popChar; while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; } while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; } if (sgn) return -num; return num; } string readString() { string res = ""; while (topChar.isWhite) popChar; while (!topChar.isWhite) { res ~= topChar; popChar; } return res; } /**MODULAR SYSTEM*/ struct Z(immutable long m) { long rep; this(long num) { rep = num; } Z!m opBinary(string operator)(Z!m rhs) { static if (operator == "+") { long result = rhs.rep + this.rep; if (result >= m) result -= m; return Z!m(result); } else static if (operator == "-") { long result = this.rep - rhs.rep; if (result < 0) result += m; return Z!m(result); } else static if (operator == "*") { long result = this.rep * rhs.rep; if (result >= m) result %= m; return Z!m(result); } else static assert(text("Operator ", operator, " not supported")); } Z!m opBinary(string operator)(long exponent) if (operator == "^^") { assert(exponent >= 0); Z!m base = this; Z!m result = 1; while (exponent) { if (exponent & 1) result = result * base; base = base * base; exponent >>= 1; } return result; } invariant { assert(rep >= 0 && rep < m); } }
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; struct Strut{ long A; long B; } void main() { long[] input = readln().split.to!(long[]); long A = input[0]; long B = input[1]; writeln(f(A-1)^f(B)); } long f(long x) { switch(x%4) { case 0: return x; case 1: return 1; case 2: return x ^ 1; case 3: return 0; default: return 0; } }
D
// Vicfred // https://atcoder.jp/contests/abc052/tasks/abc052_b // simulation import std.algorithm; import std.conv; import std.stdio; import std.string; void main() { int n = readln.chomp.to!int; string s = readln.chomp; int maxima = 0; int x = 0; foreach(ch; s) { if(ch == 'I') x += 1; else x -= 1; maxima = max(maxima, x); } maxima.writeln; }
D
void main(){ long n = _scan!long(); for(int i;; i++){ if(i*i>n){ ( (i-1)*(i-1) ).writeln(); break; } } } 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
/+ dub.sdl: name "B" 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 a, b, c, d; sc.read(a, b, c, d); int ans = 0; foreach (r; 0..3030) { foreach (g; 0..3030) { int rem = d - (a * r + b * g); if (rem < 0) continue; if (rem % c == 0) ans++; } } writeln(ans); 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.stdio; import std.algorithm; import std.string; import std.range; import std.array; import std.conv; import std.complex; import std.math; import std.ascii; string[] operators = ["=","(", ")", "+", "-", "*", "/"]; bool isOperator(string s) { return operators.canFind(s); } int priority(string op) { int i = 0; while(operators[i] != op) ++i; return (i+1)/2; } string nextToken(ref string s) { string t = ""; while(s[0].isDigit()) { t ~= s[0]; s.popFrontN(1); } if(t == "") { t ~= s[0]; s.popFrontN(1); } return t; } int apply(string op, int l, int r) { switch(op){ case "+": return l+r; case "-": return l-r; case "*": return l*r; case "/": return l/r; default: return 0; } } void apply(string op, ref int[] vstack) { auto r = vstack.back; vstack.popBackN(1); auto l = vstack.back; vstack.popBackN(1); vstack ~= apply(op, l, r); } int calc(string s) { int[] vstack; string[] opstack; while(!s.empty()) { auto t = nextToken(s); if(!t.isOperator()) { vstack ~= to!int(t); } else { if(opstack.empty || t == "(" || t.priority() > opstack.back.priority()) opstack ~= t; else { auto op = opstack.back; opstack.popBackN(1); if(op == "(") { continue; } apply(op, vstack); s = t~s; } } } return vstack.front; } void main() { int n = to!int(readln().strip()); foreach(i; 0..n) { auto s = readln().strip(); writeln(calc(s)); } }
D
import std.stdio; import std.algorithm; int[] readArray(int n) { int[] a = new int[n - 1]; int start = -1; for (int i = 0, j = 0; i < n; i++) { int x; scanf("%d", &x); if (x == 1) { start = j; } if (x != 0) { a[j++] = x; } } int[] res = new int[n - 1]; for (int i = 0, j = start; i < n - 1; i++, j = (j + 1) % (n - 1)) res[i] = a[j]; return res; } void main() { int n; scanf("%d", &n); int[] a = readArray(n); int[] b = readArray(n); if (equal(a, b)) printf("YES\n"); else printf("NO\n"); }
D
import std.algorithm; import std.conv; import std.math; import std.range; import std.stdio; import std.string; bool isSquare (int n) { auto p = cast (int) (sqrt (n * 1.0) + 0.5); return p * p == n; } void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); while (true) { if (n & 1) { writeln ("NO"); break; } n /= 2; if (isSquare (n)) { writeln ("YES"); break; } } } }
D
import std.stdio, std.algorithm, std.array, std.string, std.conv; void main() { int t; scanf("%d", &t); foreach(_; 0..t) { long n; scanf("%lld", &n); getchar(); writeln(-1 * (n - 1), ' ', n); } }
D
import core.bitop; import std.algorithm; import std.array; import std.container; import std.conv; import std.exception; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void main () { string s; while ((s = readln.strip) != "") { string a = "."; string b = "."; ubyte cur = 0; foreach (c; s.representation) { while (c != cur) { cur -= 1; a ~= "X."; b ~= ".."; } a ~= ".X.."; b ~= "XXX."; } writeln (a); writeln (b); } }
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; 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; } } void main() { auto r = new InputReader; immutable int n = r.next!int; auto a = r.nextA!int (n); auto b = a.map!"abs(a)".array; sort (b); int i, j; ulong res; for (i = 0; i < n; ++i) { int x = b[i]; while (j < n && b[j] - x <= x) ++j; debug stderr.writefln ("i = %d, j = %d", i, j); res += max (0, j - i - 1); } writeln (res); }
D
module main; import std.stdio; import std.string; int main(string[] argv) { int n, j = 0; scanf("%d", &n); int [] a = new int[n]; for(int i = 0; i < n; i++) { scanf("%d", &a[j]); while(j > 0 && a[j] == a[j - 1]) { a[j - 1]++; a[j] = 0; j--; } j++; } writeln(j); for(int i = 0; i < j; i++) write(a[i]," "); return 0; }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a = new char[][](n); foreach (i; 0 .. n) { a[i] = readln.chomp.to!(char[]); } if (a[0][0] == '.' || a[0][n - 1] == '.' || a[n - 1][0] == '.' || a[n - 1][n - 1] == '.') { writeln("NO"); return; } for (int i = 1; i + 1 < n; i++) { for (int j = 1; j + 1 < n; j++) { if (a[i][j] == '.') { if (a[i - 1][j] == '#' || a[i][j - 1] == '#' || a[i + 1][j] == '#' || a[i][j + 1] == '#') { continue; } a[i][j] = a[i - 1][j] = a[i][j - 1] = a[i + 1][j] = a[i][j + 1] = '#'; } } } foreach (i; 0 .. n) { foreach (j; 0 .. n) { if (a[i][j] == '.') { writeln("NO"); return; } } } writeln("YES"); } 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
void main() { int[] tmp = readln.split.to!(int[]); int h = tmp[0], w = tmp[1]; string[] s = new string[h]; foreach (i; 0 .. h) { s[i] = readln.chomp; } foreach (i; 0 .. 2*h) { s[i/2].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, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int N; scan(N); long ans; foreach (i ; 1 .. N + 1) { if (i % 3 != 0 && i % 5 != 0) { ans += 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
import std.stdio, std.string, std.conv, std.algorithm; void main() { int[] tmp = readln.split.to!(int[]); int a = tmp[0], b = tmp[1]; max(a+b, a-b, a*b).writeln; }
D
void main(){ string[] str = readln().chomp().split(); if( str[0] > str[1] )writeln(">"); else if( str[0] < str[1] )writeln("<"); else 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.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 h, w; scan(h, w); int a, b; scan(a, b); auto ans = h * w - ((h / a * a) * (w / b * b)); 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; void main() { auto nr = readln.split.to!(int[]); auto N = nr[0]; auto R = nr[1]; if (N >= 10) { writeln(R); } else { writeln(R + 100 * (10-N)); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n; readV(n); auto dp1 = new int[](n+1), dp2 = new int[](n+1); dp1[] = n; foreach (i; 0..6) dp1[i] = i; foreach (i; 1..8) { dp2[] = dp1[]; auto m = 6^^i; foreach (j; 0..n+1) foreach (k; 0..6) if (j >= m*k) dp1[j] = min(dp1[j], dp2[j-m*k]+k); } foreach (i; 1..7) { dp2[] = dp1[]; auto m = 9^^i; foreach (j; 0..n+1) foreach (k; 0..9) if (j >= m*k) dp1[j] = min(dp1[j], dp2[j-m*k]+k); } writeln(dp1[n]); }
D
void main() { long h = rdElem; long cnt = 1; long result; while (h) { h >>= 1; result += cnt; cnt <<= 1; } result.writeln; } 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 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
import std.stdio; import std.string; import std.conv; void main() { for (int i = 1; ; i++) { int a = to!(int)(chomp(readln())); if (a != 0) { writeln("Case ", i, ": ", a); } else { break; } } }
D
import std; void main() { int n; string s; scan(n); scan(s); auto w = new int[](n + 1); auto b = new int[](n + 1); foreach (i; 1 .. n + 1) { b[i] = b[i-1] + (s[i-1]=='#'); } foreach_reverse (i; 0 .. n) { w[i] = w[i+1] + (s[i]=='.'); } auto ans = 1_000_000_000; foreach (i; 0 .. n + 1) { chmin(ans, b[i] + w[i]); } writeln(ans); } long[] factor(int x) { long[] res; for (int i = 2; i*i <= x; i++) { while (x % i == 0) { x /= i; res ~= i; } } if (x > 1) res ~= x; return res; } 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.algorithm, std.range, std.conv, std.string, std.math, std.container; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { int n; scanf("%d\n", &n); int[][] g = new int[][n]; int[] degree = new int[n]; foreach (i; 0..n-1) { int x, y; scanf("%d %d\n", &x, &y); --x; --y; g[x] ~= y; g[y] ~= x; degree[x]++; degree[y]++; } string c = readln().chomp; bool[] live = new bool[n]; live[] = true; alias Queue = DList!int; auto q = new Queue(); foreach (i; 0..n) { if (degree[i] == 1) { q.insertBack(i); } } int L = n; while (!q.empty) { int v = q.front(); q.removeFront(); if (c[v] == 'W') continue; live[v] = false; L--; foreach (u; g[v]) { degree[u]--; if (degree[u] == 1) { q.insertBack(u); } } } if (L == 0) { writeln(0); return; } int base = L*2; int[] score = new int[n]; foreach (v; 0..n) { if (!live[v]) continue; score[v] = (degree[v] + (c[v]=='B'?0:1)) % 2; base += score[v]; } int best = 0; int dfs(int v, int parent=-1) { int ret = score[v]; foreach (u; g[v]) { if (u == parent) continue; if (!live[u]) continue; int s = dfs(u,v); best = max(best, ret+s); ret = max(ret, s+score[v]); } return ret; } foreach (v; 0..n) { if (!live[v]) continue; dfs(v); break; } writeln(base-best*2-2); }
D
void main() { problem(); } void problem() { auto a = scan!long; long solve() { return a == 0 ? 1 : 0; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } alias Point = Tuple!(long, "x", long, "y"); // -----------------------------------------------
D
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 x = RD!int; auto y = RD!int; auto z = RD!int; string ans; if (abs(x - y) > z || z == 0) { ans = x == y ? "0" : x > y ? "+" : "-"; } else { ans = "?"; } writeln(ans); stdout.flush(); debug readln(); }
D
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; import std.math; import std.range; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } //Digit count---{{{ int DigitNum(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } //}}} //}}} void main() { Scanner sc = new Scanner; int n; sc.scan(n); if (n == 25) writeln("Christmas"); else if (n == 24) writeln("Christmas Eve"); else if (n == 23) writeln("Christmas Eve Eve"); else if (n == 22) writeln("Christmas Eve Eve Eve"); }
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; readV(n); long[] a; readA(n, a); auto as = a.cumulativeSum; auto dp = new long[][](n, n+1); long f(int i, int j) { if (i+1 == j) return 0; if (dp[i][j]) return dp[i][j]; auto r = 10L^^18; foreach (k; i+1..j) r = min(r, f(i, k) + f(k, j) + as[i..j]); return dp[i][j] = r; } writeln(f(0, n)); } class CumulativeSum(T) { size_t n; T[] s; this(T[] a) { n = a.length; s = new T[](n+1); s[0] = T(0); foreach (i; 0..n) s[i+1] = s[i] + a[i]; } T opSlice(size_t l, size_t r) { return s[r]-s[l]; } size_t opDollar() { return n; } } auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }
D
import std.stdio, std.string, std.array, std.conv; void main() { int n = readln.chomp.to!int; int[] h = readln.split.to!(int[]); bool ok = true; int cnt = 1; foreach (i; 1 .. n) { if (h[i] > h[i-1]) { ++cnt; } else if (h[i] < h[i-1]) { if (h[i-1] - h[i] > cnt) ok = false; cnt = 0; } } writeln(ok ? "Yes" : "No"); }
D
import std.stdio, std.string, std.algorithm, std.range, std.conv; void main() { auto N = readln.chomp.to!int; if(N%2==1) { writeln(N*2); } else { writeln(N); } }
D
import std.stdio, std.string, std.conv; void main() { writeln(readln.chomp.to!int ^^ 3); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.ascii; void main() { auto a = readln.chomp.split.to!(int[]); if (a[0] <= a[2] && a[1] >= a[2]) { writeln("Yes"); } else { writeln("No"); } }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N = lread(); writeln((N + 1) / 2); }
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } T[] readToArray(T)() { return readln.split.to!(T[]); } void readInto(T...)(ref T ts) { auto ss = readln.split; foreach(ref t; ts) { t = ss.front.to!(typeof(t)); ss.popFront; } } void main() { int[char] a; const string s = readln.chomp; foreach(c; s) { a[c]++; } if (a.length == 2 && a[s[0]] == 2) { 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); if (a < b) swap(a, b); writeln(a*2 - (a > b ? 1 : 0)); }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; import std.numeric; void main() { int k = readln.chomp.to!int; long sum = 0; for(int i=0; i<k; i++) for(int j=0; j<k; j++) for(int l=0; l<k; l++) { sum += gcd(i+1, gcd(j+1, l+1)); } writeln(sum); }
D
import std.stdio; import std.algorithm; import std.math; import std.string; import std.conv; import std.range; void main() { while (true) { int n = readln.chomp.to!int; if (n == 0) break; int[] ice = new int[10]; foreach (i; 0..n) { ice[readln.chomp.to!int]++; } foreach (e; ice) { if (e == 0) { writeln("-"); } else { foreach (i; 0..e) { write("*"); } writeln; } } } }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { long h, w; scan(h, w); auto a = new string[](h); foreach (i; 0 .. h) { a[i] = sread(); } // writeln(a); bool[] row = new bool[](h); bool[] col = new bool[](w); foreach (y; 0 .. h) { // writeln(a[y]); foreach (x; 0 .. w) { if (a[y][x] == '.') { continue; } else { row[y] = true; break; } } } // writeln(row); foreach (x; 0 .. w) { foreach (y; 0 .. h) { if (a[y][x] == '.') { continue; } else { col[x] = true; break; } } } // writeln(col); foreach (y; 0 .. h) { foreach (x; 0 .. w) { if (row[y] && col[x]) { write(a[y][x]); } } if (row[y]) { writeln(); } } } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio, std.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, std.datetime; void main() { auto N = readln.chomp.to!int; auto S = readln.chomp; auto W = new int[](N+1); auto E = new int[](N+1); foreach (i; 0..N) W[i+1] = W[i] + (S[i] == 'W'); foreach (i; 0..N) E[i+1] = E[i] + (S[i] == 'E'); int ans = 1 << 29; foreach (i; 0..N) { int tmp = 0; if (i > 0) { tmp += W[i]; } if (i < N-1) { tmp += E[N] - E[i+1]; } ans = min(ans, tmp); } ans.writeln; }
D
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; import std.math; import std.range; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } //Digit count---{{{ int DigitNum(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } //}}} //}}} void main() { Scanner sc = new Scanner; int N, i; sc.scan(N, i); writeln(N - i + 1); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int a, b, c, d; scan(a, b, c, d); foreach (i; 0 .. 1000) { if (a <= 0 || c <= 0) break; if (i % 2 == 0) { c -= b; } else { a -= d; } } yes(c <= 0); } 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.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; void main() { string s = readln.chomp; if(s[0]=='7' || s[1]=='7' || s[2]=='7') writeln("Yes"); else writeln("No"); }
D
import std.stdio, std.conv, std.string; void main() { int N, K; N = readln().chomp().to!(int); K = readln().chomp().to!(int); int res = 1; foreach(int i; 0..N) { if(res + K < res*2) { res += K; } else { res *= 2; } } writeln(res); }
D
import std.stdio; import std.string; import std.conv; void main() { auto X = readln.split.to!(int[]),A = X[0],B = X[1]; if((A + B) % 2 == 0) { writeln((A + B) / 2); } else { writeln((A + B) / 2 + 1); }}
D
// Vicfred // https://atcoder.jp/contests/abc047/tasks/arc063_a // greedy import std.stdio; import std.string; void main() { string s = readln.strip; long n = s.length; long count = 0; for(long i = 0; i < s.length-1; i++) { if(s[i] != s[i + 1]) count += 1; } count.writeln; }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int n; scan(n); int ans; int ls, rs; ans = query(0); if (ans == 2) return; ls = ans; ans = query(n-1); if (ans == 2) return; rs = ans; int left = 0, right = n - 1; while (true) { int mid = (left + right) / 2; ans = query(mid); if (ans == 2) return; int b = ((mid - left + 1) & 1) ^ (ls ^ ans); if (!b) { right = mid; rs = ans; } else { left = mid; ls = ans; } } } int query(int i) { writeln(i); stdout.flush(); string s = readln.chomp; if (s == "Male") { return 0; } else if (s == "Female") { return 1; } else { return 2; } } 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.conv; import std.stdio; import std.string; void main() { auto ab = readln.split.to!( int[] ); writeln( solve( ab[ 0 ], ab[ 1 ] ) ); } auto solve( in int a, in int b ) { return ( a <= 8 && b <= 8 ) ? "Yay!" : ":(" ; } unittest { assert( solve( 5, 4 ) == "Yay!" ); assert( solve( 8, 8 ) == "Yay!" ); assert( solve( 11, 4 ) == ":(" ); }
D
void main(){ int a, b, x; scanf("%d %d %d", &a, &b, &x); writeln(a+b>=x&&a<=x?"YES":"NO"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto ab = readln.split.to!(int[]); writeln(ab[0] < 10 && ab[1] < 10 ? ab[0] * ab[1] : -1); }
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 n = lread(); auto s = sread(); auto first = new long[](10); auto second = new long[](100); auto third = new long[](1_000); foreach (i; iota(n)) { long idx1 = s[i] - '0'; if (first[idx1]) continue; foreach (j; iota(i + 1, n)) { long idx2 = idx1 * 10 + s[j] - '0'; if (second[idx2]) continue; foreach (k; iota(j + 1, n)) { long idx3 = idx2 * 10 + s[k] - '0'; if (third[idx3]) continue; third[idx3] = 1; } second[idx2] = 1; } first[idx1] = 1; } third.sum.writeln(); } auto getdisit(T)(T n) { T i = 0; while (abs(n) >= 1) { n /= 10; i++; } return i; } 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
void main() { // ((A, B) => A > B ? "GREATER" : A < B ? "LESS" : "EQUAL")(BigInt(rs), BigInt(rs)).writeln; auto A = rs, B = rs; if(A.length == B.length) { if(A[0] > B[0]) writeln("GREATER"); else if(A[0] == B[0]) writeln("EQUAL"); else writeln("LESS"); } else { if(A.length > B.length) writeln("GREATER"); else writeln("LESS"); } } // =================================== import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; 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
void main() { import std.stdio; (readln>"2019/05"?"TBD":"Heisei").writeln; }
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto N = readln.split[0].to!int; if (N == 1) { writeln("Hello World"); } else if (N == 2) { auto A = readln.split[0].to!int; auto B = readln.split[0].to!int; writeln(A+B); } }
D
void main() { string n = readln.chomp; int total; foreach (d; n) { total += d - '0'; } if (total == 1) total *= 10; total.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.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; writeln((n * (n + 1)) / 2); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container; void main() { auto N = readln.chomp.to!int; auto T = new int[][N]; foreach (_; 1..N) { auto ab = readln.split.to!(int[]); auto a = ab[0]-1; auto b = ab[1]-1; T[a] ~= b; T[b] ~= a; } int p1, max_l; void run1(int i, int p, int l) { if (max_l < l) { max_l = l; p1 = i; } foreach (j; T[i]) if (j != p) run1(j, i, l+1); } run1(0, -1, 0); int run2(int i, int p, int l) { int ll = l; foreach (j; T[i]) if (j != p) ll = max(ll, run2(j, i, l+1)); return ll; } auto len = run2(p1, -1, 1); writeln((len-2)%3 == 0 ? "Second" : "First"); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long H = lread(); long W = lread(); long N = lread(); long m = max(H, W); writeln((N + m - 1) / m); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.container; import std.array; import std.math; import std.range; import std.typecons; import std.ascii; import std.format; void main() { int[101] imos; auto d = readln.chomp.split.map!(to!int); imos[d[0]]++; imos[d[1]]--; imos[d[2]]++; imos[d[3]]--; int cnt = 0; int ite = 0; for (int i = 0; i <= 100; ++i) { ite += imos[i]; if (ite == 2) { ++cnt; } } writeln = cnt; }
D
import std.stdio, std.ascii; void main() { auto d = stdin.readln.dup; foreach (c; d) { if (c.isLower) c -= 32; else if (c.isUpper) c+= 32; c.write; } }
D
import std.stdio; import std.string, std.conv, std.array, std.algorithm; import std.uni, std.math, std.container; import core.bitop, std.datetime; void main(){ auto s = readln.chomp; auto n = s.length.to!int; if(n == 2){ if(s[0] == s[1]){ writeln(1, " ", 2); return; } else { writeln(-1, " ", -1); return; } } foreach(i ; 0 .. n - 2){ if(s[i] == s[i + 1]){ writeln(i+1, " ", i + 2); return; } else if(s[i + 1] == s[i + 2]){ writeln(i+2, " ", i+3); return; } else if(s[i] == s[i + 2]){ writeln(i+1, " ", i+3); return; } } writeln(-1, " ", -1); }
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; scan(n); writeln(24 + 24 - n); } 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.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 A = RD; auto B = RD; writeln(lcm(A, B)); stdout.flush; debug readln; }
D
import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm; import std.bigint; bool[1000001] p; void main() { int[10002] sum; p[2 .. 1000001] = true; for (int i = 2; i <= 1000000; i++){ if (p[i]){ for (int j = i * 2; j <= 1000000; j += i){ p[j] = false; } } } for (int i = 1, j = 0; j <= 10000; i++){ if (p[i]){ sum[j + 1] = sum[j] + i; j++; } } while (true){ int n = readln().chomp().to!int; if (n == 0) break; writeln(sum[n]); } }
D
import std.stdio; import std.array; import std.conv; import std.algorithm; void main() { while ( true ) { string[] line = split( readln() ); int n = to!int( line[ 0 ] ); int q = to!int( line[ 1 ] ); if ( n == 0 && q == 0 ) break; int[ 101 ] date; foreach ( i; 0 .. n ) { line = split( readln() ); int m = to!int( line[ 0 ] ); foreach ( j; 0 .. m ) { date[ to!int( line[ j + 1 ] ) ]++; } } int mx = reduce!(max)( 0, date ); if ( mx >= q ) { foreach ( i; 0 .. 100 ) { if ( date[ i ] == mx ) { writeln( i ); break; } } } else { writeln( 0 ); } } }
D
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons; const dx = [1,0,-1,0]; const dy = [0,1,0,-1]; void read(T...)(auto ref T args){ auto line = readln().split(); foreach(i,ref arg; args) arg = line[i].to!(typeof(arg)); } int sum(int n){return n * (n + 1)/ 2;} void main(){ int m;m.read; for(;m>0;m--){ string cars;cars.read; bool[string] exist; foreach(i;1..cars.length){ auto f = (string a) =>[a,a.dup.reverse.idup]; foreach(c1;f(cars[0..i])) { foreach(c2;f(cars[i..$])){ exist[c1 ~ c2] = true; exist[c2 ~ c1] = true; } } } exist.length.writeln; } }
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!string; writeln(N[0] == '9' || N[1] == '9' ? "Yes" : "No"); stdout.flush(); debug readln(); }
D
void main() { long n = readln.chomp.to!int; long mod = 10 ^^ 9 + 7; long power = 1; foreach (i; 1 .. n+1) { power = power * i % mod; } power.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.array; import std.conv; import std.math; import std.algorithm; void main() { string[] input = split(readln()); int w = to!int(input[0]), h = to!int(input[1]), n = to!int(input[2]), ans = 0; input = split(readln()); int x = to!int(input[0]), y = to!int(input[1]); for(auto i = 0; i < n - 1; i++) { input = split(readln()); int tx = to!int(input[0]), ty = to!int(input[1]); if(tx - x < 0 && ty - y < 0 || tx - x > 0 && ty - y > 0) ans += max(abs(tx - x), abs(ty - y)); else ans += abs(tx - x) + abs(ty - y); x = tx; y = ty; } writeln(ans); }
D
/+ dub.sdl: name "F" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; // import dcomp.array; immutable long MD = 10^^9 + 7; int main() { auto sc = new Scanner(stdin); int q; sc.read(q); long[2][] base = [[1L, 1L].fixed]; while (base.back[1] < 10L^^18) { auto u = base.back; base ~= [u[1], u[0]+u[1]]; } foreach (i; 0..q) { long x, y; sc.read(x, y); if (x > y) swap(x, y); if (x == 1 && y == 1) { //corner case writeln("1 1"); continue; } int ans = (){ foreach (int i, u; base) { if (x < u[0] || y < u[1]) { return i-1; } } assert(false); }(); long cnt(long x, long y) { long last(long a, long b) { if (x < b) return 0; if (y < a+b) return 0; return ((y-a)/b) % MD; } long sm = last(base[ans-1][0], base[ans-1][1]); long[2] freq = [0L, 1L]; foreach_reverse (ph; 0..ans-1) { //use to ph long bb = base[ph][1]; long na = base[ans-1][0] + freq[0]*bb; long nb = base[ans-1][1] + freq[1]*bb; sm += last(na, nb); sm %= MD; freq = [freq[1], freq[0]+freq[1]]; } return sm; } long sm = cnt(x, y); if (base[ans-1][1] <= x) sm += cnt(x, x); if (ans == 1) sm += min(x, y); sm %= MD; writeln(ans, " ", sm); } 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/array.d */ // module dcomp.array; T[N] fixed(T, size_t N)(T[N] a) {return a;} struct FastAppender(A) { import std.algorithm : max; import std.range.primitives : ElementEncodingType; import core.stdc.string : memcpy; private alias T = ElementEncodingType!A; private T* _data; private size_t len, cap; @property size_t length() {return len;} void reserve(size_t nlen) { import core.memory : GC; if (nlen <= cap) return; void* nx = GC.malloc(nlen * T.sizeof); cap = nlen; if (len) memcpy(nx, _data, len * T.sizeof); _data = cast(T*)(nx); } void opOpAssign(string op : "~")(T item) { if (len == cap) { reserve(max(4, cap*2)); } _data[len++] = item; } void clear() { len = 0; } T[] data() { return (_data) ? _data[0..len] : null; } }
D
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; immutable long mod = 10^^9 + 7; immutable int inf = mod; void main(){ int N, W; readVars(N, W); auto v = new int[](N); auto w = new int[](N); foreach(i ; 0 .. N){ readVars(v[i], w[i]); } auto dp = new int[](W + 1); foreach(u ; 1 .. W + 1){ foreach(i ; 0 .. N){ if(u - w[i] >= 0){ dp[u] = max(dp[u], dp[u - w[i]] + v[i]); } } } writeln(dp[W]); } void readVars(T...)(auto ref T args){ auto line = readln.split; foreach(ref arg ; args){ arg = line.front.to!(typeof(arg)); line.popFront; } if(!line.empty){ throw new Exception("args num < input num"); } }
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; foreach (i; 1..8) { auto p = 2 ^^ i; if (p > n) { writeln(2 ^^ (i - 1)); break; } } }
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, "l ", long, "r"); alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); void main() { auto s = sread(); writeln(s[0 .. $ - "FESTIVAL".length]); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D