code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional; import std.algorithm, std.container; long check(long n) { long i=1; while(n>0) { n-=i; i++; } return n==0?i:-1; } void main() { auto N = scanElem; ...
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 N = readln.chomp.to!int; auto A = readln.split.to!(int[]); auto ans = int.max; foreach(x; -100 .. 101){ ans = min(ans, calc_dif2(...
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[...
D
import std.stdio; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.csv; import std.regex; import std.math; import core.time; import std.ascii; import std.digest.sha; import std.outb...
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", ...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto ...
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; struct Queue(T) { private { size_t cap, head, tail; T[] data; ...
D
void main() { problem(); } void problem() { auto L = scan!long; auto R = scan!long; auto d = scan!long; long solve() { long ans; foreach(i; L..R+1) { if (i % d == 0) ans++; } return ans; } solve().writeln; } // ---------------------------------------------- import std.stdio, st...
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 ...
D
void main() { long[] tmp = rdRow; long n = tmp[0], k = tmp[1]; long[] x = rdRow; long result = 1L << 60; foreach (i; 0 .. n-k+1) { long time = abs(x[i]-x[i+k-1]) + min(x[i].abs, x[i+k-1].abs); result = min(result, time); } result.writeln; } T rdElem(T = long)() { /...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto xy = readln.split.to!(long[]); auto X = xy[0]; auto Y = xy[1]; auto a = X; long r; while (a <= Y && a ) { ++r; a *= 2; } writeln(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, std.bitmanip, std.regex; void main() { immutable long MOD = 10^^9 + 7; auto N = readln.chomp.to!int; auto A = N.iota.map!(_ => ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nk = readln.split.to!(int[]); writeln(nk[0] - nk[1] + 1); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto hs = readln.split.to!(int[]); hs ~= 0; int c; foreach (i; 0..N) c += max(0, hs[i] - hs[i+1]); writeln(c); }
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 =...
D
import std.stdio,std.conv,std.string; void main(){ int sum; auto N = readln().chomp().to!int(); auto list = readArray!int(); foreach( elm ; list ){ while( elm%2 == 0 ){ elm /= 2; sum++; } } writeln(sum); } T[] readArray(T)(){ T[] ret; foreach( elm ; readln().split() ){ ret ~= elm.to!T(); } re...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!long; long r; foreach (x; 1..N) { if (x^^2 > N) break; if (N%x == 0) { auto m = N/x - 1; if (x*m + x == N && N/m == N%m) r +...
D
void main() { long n = rdElem; long[] a = rdRow; long q = rdElem; foreach (i; 0 .. q) { long p = rdElem; long r = a.binSrch!"a <= b"(p); if (r != -1 && a[r] == p) 1.writeln; else 0.writeln; } } long binSrch(alias pred = "a < b")(long[] arr, long val) { alias...
D
import std.stdio, std.string, std.conv, std.regex; void main() { auto n = readln.split.to!(int[]); if(n[0] > n[1]){ writeln(n[0] - n[1]); } else { writeln("0"); } }
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[])();} ...
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_r...
D
import std; bool calc(int k, int a, int b) { return a <= b / k * k; } void main() { int k; scan(k); int a, b; scan(a, b); writeln(calc(k, a, b) ? "OK" : "NG"); } 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!...
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; T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void sca...
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; void main() { long[] ary = [6000, 4000, 3000, 2000]; foreach(int i; 0..4) { ...
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; void main(){ string s = readln.chomp; int[] ans = [-1, -1]; // search for "aa" for(int i = 0; i < s.length - 1; i ++){ if(s[i] == s[i + 1]) ans = [i + 1, i + 2]; ...
D
import std.stdio, std.string, std.algorithm, std.conv, std.range, std.math; void main() { int[int] counter; foreach (string line; lines(stdin)) { int i = line.chomp.to!int; counter[i]++; } int max = counter.values.reduce!(max); foreach (k; counter.keys.sort) { if (counter[k] == max) k.writeln;...
D
import std.stdio; // readln import std.array; // split import std.conv; // to import std.typecons; bool[][] g; void main(){ string[] s = split(readln()); int N = to!int(s[0]); int M = to!int(s[1]); g = new bool[][](N,N); alias Tuple!(int,int) pair; pair[] p = new pair[](M); for(int i = 0; i < M; i++){ s = s...
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, M; scan(N, M); auto cnt = new int[](M); foreac...
D
void main(){ string n = readln().chomp(); int cnt, ans; foreach(i; 0..n.length){ if(cnt==0)cnt++; else if(n[i-1]==n[i])cnt++; else cnt=1; ans = max(cnt, ans); } ( ans>=3?"Yes":"No" ).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod ...
D
import std.stdio; import std.array; import std.conv; import std.string; import std.algorithm; void main() { int[] m; while((m=map!(to!int)(readln.strip.split).array)!=[0,0]) { int n=m[0],x=m[1],sum = 0; foreach(i;1..n) foreach(j;i+1..x-i) { int k = x-i-j; if(j<k && k<=n) su...
D
void main() { auto arr = 5.iota.map!(_ => ri).array; int res = int.max; do { int tmp; foreach(v; arr) { if(tmp % 10 != 0) tmp += 10 - (tmp % 10); tmp += v; } res = min(res, tmp); } while(nextPermutation(arr)); res.writeln; } // =================================== import std.stdio; import std.string...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; foreach (x; N..1000) { if (x/100 == (x/10)%10 && (x/10)%10 == x%10) { writeln(x); return; } } }
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; void main() { string s = readln.chomp; writeln(s[0 .. 4], " ", s[4 .. $]); } void scan(T...)(ref T args) { str...
D
import std.stdio, std.string, std.algorithm, std.range, std.conv, std.typecons, std.math; void main(){ auto S = readln.chomp; ulong min = 0, max = 0; foreach (i,c; S) { if (c == 'A') { min = i; break; } } foreach_reverse (i,c; S) { if (c == 'Z') { ...
D
import std.stdio; import std.conv; import std.array; void main() { int N = readln.split[0].to!int; auto reader = readln.split; int[] a = new int[N]; for(uint i = 0; i < N; i++){ a[i] = reader[i].to!int; } int cnt = 0; for(uint i = 0; i < N; i++){ if (a[i] != i + 1) cnt++; ...
D
import std.stdio; void main() { auto s = readln(); if(s[2]==s[3] && s[4]==s[5]) writeln("Yes"); else writeln("No"); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N; string S; scan(N); s...
D
void main() { long a = rdElem, b = rdElem, c = rdElem; long s = 3 * c; long[][] x = new long[][](3, 3); x[0][0] = a, x[0][1] = b, x[0][2] = s - a - b; x[1][0] = 4 * c - 2 * a - b, x[1][1] = c, x[1][2] = 2 * a + b - 2 * c; x[2][0] = a + b - c, x[2][1] = s - b - c, x[2][2] = s - a - c; x.wrM...
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 N = readln.chomp.to!int; auto X = new long[](N); auto S = new long[](N); foreach (i; 0....
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto S = readln.chomp; char last; int cnt; foreach (c; S) { if (c != last) ++cnt; last = c; } writeln(cnt); }
D
import std.stdio; import std.conv; import std.string; void main() { int times; while((times = readln.chomp.to!(int)) != 0){ char[] str = cast(char[])readln.chomp; for(int i = 0; i < times; i++) { char[] next_str; char prev; uint n = 1; prev = str[0]; foreach(s; str[1..$]) { ...
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() { auto n = readln.chomp.to!int; foreach (_; 0..n) { auto str = readln.chomp; char[] res; res ~= str[0...
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; T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to...
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(...
D
import std.stdio, std.math, std.conv, std.array, std.string, std.algorithm; void main() { string str; while((str = readln()).length != 0) { double v = to!double(str.chomp); double t = (v/9.8)^^2 * 4.9; int nt = to!int(floor(to!real(t))); int h = nt + (5 - nt%5); writeln(...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.typecons; import std.numeric, std.math; import core.bitop; string FMT_F = "%.10f"; 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; re...
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; long calc(long a, long ...
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(...
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 main() { int N = readln.chomp.to!i...
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) = (...
D
void main() { auto N = ri; auto S = rs; int c, res; foreach(i; S) { if(i == 'I') c++; else c--; res = max(res, c); } res.writeln; } // =================================== import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; impor...
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); int ans; foreach (i ; 0 .. n + 1) { if (i*i <= n) { ans = i*i; } else { br...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; immutable long MOD = 10^^9 + 7; void main() { auto s = readln.split; auto N = s[0].to!int; auto L = s[1].to!long;...
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; immutable int dirs = 4; immutable int [dirs] dRow = [ -1, 0, +1, 0]; immutable int [dirs] dCol = [ 0, -1, 0, +1]; immutable char [dirs] dName = ['N', 'W', 'S', 'E']; void main () { auto te...
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); } voi...
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_r...
D
import std.stdio; import std.ascii; import std.algorithm; import std.array; import core.stdc.stdio; int main() { int t = readInt!int; while(t--) { string astr = readString; auto a = new int[](astr.length); auto count = new int[](4); foreach(i, ref ai; a) { ...
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(...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; stri...
D
module main; import std.stdio : writeln, stdin; import core.stdc.stdio; int main(string[] argv) { int n, l, r; scanf("%d %d %d", &n, &l, &r); l = l - 1; r = r - 1; int [] arr = new int[n]; int [] b = new int[n]; for(int i = 0; i<n; i++) scanf("%d", &arr[i]); for (int i = 0; i < n; i++) scanf("%d", &b[i...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto ret = ""; auto h = readln.split[0].to!int; foreach (_; 0..h) { auto line = readln; ret ~= line ~ line; } write(ret); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int r; scan(r); auto ans = r*r;...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; static import std.ascii; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){ret...
D
void main() { problem(); } int mod(string x, int d) { int r; auto xs = x.length; foreach(i; 0..xs) { r = (r * 2 + (x[i] - '0')) % d; } return r; } int mod(BigInt b, int popcount) { BigInt q, r; b.divMod(BigInt(popcount), q, r); return r.toInt; } void problem() { int calc(BigInt x, int popcou...
D
import std.stdio; import std.string; import std.array; import std.conv; void main() { int A=to!int(chomp(readln())); int B=to!int(chomp(readln())); int C=to!int(chomp(readln())); int X=to!int(chomp(readln())); int ans=0; for(int i=0;i<=A;i++) { for(int j=0;j<=B;j++) { for(int k=0;k<=C;k++){ ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nm = readln.split.to!(long[]); auto N = nm[0]; auto M = nm[1]; long al; long[long] AM = [0: 0]; foreach (i, a; readln.split.to!(long[])) { al = (al + a) % M; ...
D
import std.stdio, std.algorithm, std.string; void main(){ readln.split.reduce!q{ a < b ?"<" : a==b ? "=" : ">" }.writeln; }
D
import std.algorithm; import std.math; import std.range; import std.ascii; import std.array; import std.container; import std.conv; import std.numeric; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } class UnreliableRollingHash(ulong P) { // fast but un...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; immutable long MOD = 10^^9 + 7; void solve() { auto N = readln.chomp.to!int; auto S = readln.chomp; int ans =...
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; int calc(int n) { a...
D
/+ dub.sdl: name "B" dependency "dcomp" version=">=0.7.3" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); int n; sc.read(n); int[] a; sc.read(a); a[]-=1; bool[] used = new bool[n]; int...
D
import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; import core.bitop; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(i...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a = readln.split.to!(int[]); if (a[0] != a[$ - 1]) { writeln(n - 1); return; } int mx = 1; foreach (i; 1 .. n) { if (a[0] != a[i]) { mx = max(mx, i, n - i - 1); } } writeln(mx); } void r...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int l; readV(l); auto r = l.bsr...
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.math; import std.numeric; 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 read...
D
void main() { long[] tmp = rdRow; long h = tmp[0], w = tmp[1]; long choco = h * w; long result = 1L << 60; foreach (i; 1 .. h) { long s1 = i * w; long s2 = (h - i) * (w / 2); long s3 = choco - s1 - s2; long diff = max(s1, s2, s3) - min(s1, s2, s3); result...
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long n = read.to!long; char[][] ...
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignu...
D
import std.stdio,std.string,std.conv; int main() { string[] s = readln.chomp.split(" "); string len_max = s[0],ans = s[0]; int[string] map; int count_max = 1; foreach(i;0..(s.length)) { if(len_max.length < s[i].length) { len_max = s[i]; } map[s[i]]++; if(map[s[i]] > count_max) { count_max = 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; long[] perm_prod(const long[] A, const long[] P) { auto ret = A.dup; foreach (i; 0..A.length) { ret[i] = A[P[i].to!int]; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto xyz = readln.split.to!(int[]); writeln(xyz[2], " ", xyz[0], " ", xyz[1]); }
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_r...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; alias Pair = Tuple!(int, "a", int, "b"); void main() { ...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto d=new int[](n); foreach(i; 0..n) rd(d[i]); int r=0; foreach(int i, int e; d){ if(r<i*10){writeln("no"); return;} if(r<i*10+e) r=i*10+e; } reverse(d); r=0; foreach(int i, int e; d){ if(r<i*10){writel...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; enum AEIOU = "aeiou"; void main() { auto c = readln[0]; writeln(AEIOU.canFind(c) ? "vowel" : "consonant"); }
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, q; rd(n, q); while(q--){ int v, w; rd(v, w); v--; w--; if(n==1){writeln(v+1); continue;} auto fun(int i){ int ret=0; while(i>0) i=(i-1)/n, ret++; return ret; } auto dv=fun(v), dw=fun(w); forea...
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 ...
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(...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto nm = readln.split.to!(int[]); writeln( (100 * (nm[0] - nm[1]) + 1900 * nm[1]) * (2^^nm[1]) ); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto ...
D
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range; T[] Reads(T)() { return readln.split.to!(T[]); } alias reads = Reads!(int); void scan(Args...)(ref Args args) { import std.conv : parse; string[] ss = readln.split; int i; foreach (ref arg ; args) ...
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 n; scan(n); auto a = readln.split.to!(...
D
import std.stdio; void main(){ int a; scanf("%d", &a); if(a>=30){ writeln("Yes"); }else{ writeln("No"); } }
D
void main() { problem(); } void problem() { const K = scan!long; long solve() { long ans; foreach(a; 1..K+1) { foreach(b; 1..K+1) { foreach(c; 1..K+1) { ans += a.gcd(b).gcd(c); } } } return ans; } solve().writeln; } // --------------------------------...
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_r...
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { bool[4][5][5] m; foreach(i;0..9) foreach(j,b;readln().chomp().map!"a!='0'"().array()) if(b) foreach(k;0..2) m[i/2+k*(i%2)][j+k*(1-i%2)][k*2+i%2]=true; st...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.c...
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; int calc(string s) { ...
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...
D