code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;
void main() {
string str = readln.chomp;
string[2] ss = ["eraser", "dreamer"];
// array.lengthの返り値の型はulongなので
// intに代入しようとすると(dmd64 v2.070.1では)CEになる
int p = str.length.to!int;
while (p > 0) {
bool flag = false;
if (str[p - 1] == 'r') {
for (int i = 0; i < 2; ++i) {
if (p < ss[i].length.to!int) {
break;
}
if (ss[i] == str[(p - ss[i].length.to!int)..p]) {
p -= ss[i].length.to!int;
flag = true;
break;
}
}
}
else if (str[p - 1] == 'e' && p >= 5) {
if (str[(p - 5)..p] == "erase") {
flag = true;
p -= 5;
}
}
else if (str[p - 1] == 'm' && p >= 5) {
if (str[(p - 5)..p] == "dream") {
flag = true;
p -= 5;
}
}
if (!flag) {
writeln("NO");
return;
}
}
writeln("YES");
return;
}
|
D
|
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
string my_readln() { return chomp(readln()); }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto tokens = my_readln.split;
auto N = tokens[0].to!long;
auto A = tokens[1].to!long;
auto B = tokens[2].to!long;
writeln(min(A, B), " ", max(0, (A + B) - N));
stdout.flush();
}
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm;
void main(){
auto a = readln.split.map!(to!int);
int n = a[0];
int m = a[1];
int c;
int cnt,gomi;
for(uint i;i<m;++i){
auto b = readln.split.map!(to!int);
c = b[0];
if(c<n){
cnt += n-c;
if(n-c>gomi) gomi = n-c;
}
}
writeln(cnt-gomi);
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.range, std.typecons;
void main() {
auto S = readln.split.to!(ulong[]);
auto N = S[0], A = S[1], B = S[2];
auto X = readln.split.to!(ulong[]);
ulong res = 0;
foreach (i; 0..N-1) {
res += min((X[i+1] - X[i]) * A, B);
}
writeln(res);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
auto T = S.idup;
long ans = 1;
auto last = [S[0]];
S.popFront;
while (!S.empty)
{
if (last.length == 2)
{
last = [S[0]]; S.popFront;
++ans;
}
else if (S[0] == last[0])
{
if (S.length == 1)
{
break;
}
last = S[0..2];
S = S[2..$];
++ans;
}
else
{
last = [S[0]]; S.popFront;
++ans;
}
}
long ans2 = 1;
last = [T[0], T[1]];
T = T[2..$];
while (!T.empty)
{
if (last.length == 2)
{
last = [T[0]]; T.popFront;
++ans2;
}
else if (T[0] == last[0])
{
if (T.length == 1)
{
break;
}
last = T[0..2];
T = T[2..$];
++ans2;
}
else
{
last = [T[0]]; T.popFront;
++ans2;
}
}
writeln(max(ans, ans2));
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string a; readV(a);
string b; readV(b);
if (a.length > b.length)
writeln("GREATER");
else if (a.length < b.length)
writeln("LESS");
else if (a > b)
writeln("GREATER");
else if (a < b)
writeln("LESS");
else
writeln("EQUAL");
}
|
D
|
void main()
{
dchar[] s = rdDchar;
dchar[] t;
foreach_reverse (x; s)
{
if (x == 'b') t ~= 'd';
if (x == 'd') t ~= 'b';
if (x == 'p') t ~= 'q';
if (x == 'q') t ~= 'p';
}
writeln(s == t ? "Yes" : "No");
}
enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
void main() {
int x;
scan(x);
x -= 400;
auto ans = 8 - (x / 200);
writeln(ans);
}
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.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
void main() {
const MAX = 1000000;
auto budget = readln.chomp.to!int;
auto hasuu = budget % 100;
int purchasedCount;
while(hasuu > 0) {
if (hasuu < 5) {
purchasedCount++;
break;
}
purchasedCount++;
hasuu -= 5;
}
writeln(purchasedCount*100 <= budget ? "1" : "0");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.numeric;
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[] a; readA(n, a);
auto b = new int[](n); b[0] = a[0];
foreach (i; 1..n) b[i] = gcd(b[i-1], a[i]);
auto c = new int[](n); c[$-1] = a[$-1];
foreach_reverse (i; 0..n-1) c[i] = gcd(c[i+1], a[i]);
auto r = max(b[$-2], c[1]);
foreach (i; 1..n-1)
r = max(r, gcd(b[i-1], c[i+1]));
writeln(r);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.regex;
const dx = [-1, 0, 1, -1, 1, -1, 0, 1];
const dy = [-1, -1, -1, 0, 0, 1, 1, 1];
void main() {
auto ip = readln.split.to!(int[]), H = ip[0], W = ip[1];
char[][] S;
foreach(_; 0..H) S ~= readln.chomp.dup;
foreach(i; 0..H) {
foreach(j; 0..W) {
if(S[i][j] != '#') {
int count;
foreach(m; -1..2) {
if(i+m < 0 || i+m >= H) continue;
foreach(n; -1..2) {
if(j+n < 0 || j+n >= W) continue;
if(S[i+m][j+n] == '#') count++;
}
}
S[i][j] = ('0' + count).to!char;
}
}
}
foreach(i; 0..H) {
writeln(S[i]);
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons;
immutable int inf = 10^^9 + 7;
int n;
void main() {
scan(n);
long ans = 10L^^5;
foreach (i ; 0 .. n) {
ans = (ans * 105) / 100;
ans = ((ans + 999) / 1000) * 1000;
}
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);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
T readNum(T)(){
return readStr.to!T;
}
T[] readNums(T)(){
return readStr.split.to!(T[]);
}
string readStr(){
return readln.chomp;
}
void main(){
auto a = readNum!int;
writeln(a^^3);
}
|
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 N, M;
scan(N, M);
auto cnt = new long[](N + 1);
foreach (_; 0 .. M)
{
long a, b;
scan(a, b);
cnt[a]++;
cnt[b]++;
}
writeln(cnt.all!"a%2==0"() ? "YES" : "NO");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto hw = readln.split.to!(int[]);
auto h = hw[0];
auto w = hw[1];
auto ret = "";
foreach (_; 0..(w+1)) ret ~= "#";
ret ~= "#\n";
foreach (_; 0..h) {
ret ~= "#";
ret ~= readln.chomp;
ret ~= "#\n";
}
foreach (_; 0..(w+2)) ret ~= "#";
writeln(ret);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nt = readln.split.to!(long[]);
auto N = nt[0];
auto T = nt[1];
auto ts = readln.split.to!(long[]);
ts ~= long.max;
long st;
foreach (i; 0..N) st += min(T, ts[i+1] - ts[i]);
writeln(st);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long A, B, C, D;
scan(A, B, C, D);
bool b = abs(A - B) <= D && abs(B - C) <= D;
bool c = abs(A - C) <= D;
writeln((b || c) ? "Yes" : "No");
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!size_t;
auto a = new int[](n), b = new bool[](n);
foreach (i; 0..n) a[i] = readln.chomp.to!int-1;
auto c = 0, d = 0;
for (;;) {
++d;
b[c] = true;
c = a[c];
if (c == 1) {
writeln(d);
break;
}
if (b[c]) {
writeln(-1);
break;
}
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.numeric;
void main() {
int n;
scan(n);
long ans = 1;
foreach (i ; 0 .. n) {
long t;
scan(t);
ans = lcm(ans, t);
}
writeln(ans);
}
long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
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
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n, m;
rd(n, m);
int[] a;
for (int i = 2; i * i <= m; i++) {
if (m % i == 0) {
int cnt = 0;
while (m % i == 0) {
cnt++;
m /= i;
}
a ~= cnt;
}
}
if (m > 1) {
a ~= 1;
}
const long mod = 10 ^^ 9 + 7;
const size_t M = 10 ^^ 5 * 2;
static long[M] fac, inv;
fac[0] = fac[1] = 1;
foreach (i; 2 .. M)
fac[i] = (fac[i - 1] * i) % mod;
long _pow(long a, long x) {
if (x == 0)
return 1;
else if (x == 1)
return a;
else if (x & 1)
return a * _pow(a, x - 1) % mod;
else
return _pow(a * a % mod, x / 2);
}
foreach (i; 0 .. M)
inv[i] = _pow(fac[i], mod - 2);
long cmb(long a, long b) {
if (a < b)
return 0;
else
return fac[a] * inv[b] % mod * inv[a - b] % mod;
}
long tot = 1;
foreach (e; a) {
(tot *= cmb(e + n - 1, e)) %= mod;
}
writeln(tot);
}
void rd(T...)(ref T x) {
import std.stdio, std.string, std.conv;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.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 A = RD;
auto B = RD;
bool ans;
if (A % 3 == 0)
ans = true;
else if (B % 3 == 0)
ans = true;
else if ((A + B) % 3 == 0)
ans = true;
writeln(ans ? "Possible" : "Impossible");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
int M = 1000000007;
int[] tbl = [ 1, 10, 9, 12, 3, 4 ];
void main() {
string S = readln.chomp;
auto N = S.length;
ulong[] items = new ulong[0];
int baseMod13 = 0;
foreach(i; 0..N) {
char c = S[$-1-i];
if(c == '?') items ~= i % 6;
c = c != '?' ? c : '0';
baseMod13 += (tbl[i % 6]*(c - '0')) % 13;
}
baseMod13 %= 13;
int mod13 = ((13+5) - baseMod13) % 13;
ulong[13][] dp = new ulong[13][items.length];
if (dp.length == 0) {
writeln(baseMod13 == 5 ? 1 : 0);
return;
}
foreach(i; 0..10) {
int mod = (tbl[items[0]] * i)%13;
dp[0][mod]++;
}
foreach(i; 1..dp.length) {
foreach(j; 0..13) {
ulong m = 0;
foreach(k; 0..10) {
int mod = (tbl[items[i]] * k) % 13;
int diff = ((13+j) - mod) % 13;
m = (m + dp[i-1][diff]) % M;
}
dp[i][j] = m % M;
}
}
dp[$-1][mod13].writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;
void main(){
auto a=readln.chomp.to!int;
auto b=readln.chomp.to!int;
if(a%500<=b)writeln("Yes");
else writeln("No");
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
ans[ti] = n % 4 == 0;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush;
debug readln;
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
auto n = s.length;
foreach_reverse (i; 2..n) {
if (i%2 == 1) continue;
if (s[0..i/2] == s[i/2..i]) {
writeln(i);
return;
}
}
}
|
D
|
import std.stdio;
void main() {
int m1, m2, d1, d2;
scanf("%d %d\n%d %d\n", &m1, &d1, &m2, &d2);
if (m1 == m2) {
0.write;
}
else {
1.write;
}
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/+---test
Sunny
---+/
/+---test
Rainy
---+/
void main(string[] args) {
const S = readln.chomp;
[
"Sunny": "Cloudy",
"Cloudy": "Rainy",
"Rainy": "Sunny",
][S].writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
alias sread = () => readln.chomp();
void main()
{
string s = sread();
if (s.length == 3)
{
writeln(s[2],s[1],s[0]);
return;
}
s.writeln();
}
|
D
|
void main() {
auto k = ri;
auto s = rs;
if (s.length <= k) writeln(s);
else writeln(s[0..k] ~ "...");
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
long rl() {
return readAs!long;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
void main()
{
string s = rdStr;
if (s[0] == '>') s = '<' ~ s;
if (s[$-1] == '<') s ~= '>';
auto g = s.group.array;
long result;
for (long i = 0; i < g.length; i += 2)
{
long x = g[i][1], y = g[i+1][1];
if (x < y)
{
result += x * (x - 1) / 2;
result += y * (y + 1) / 2;
}
else
{
result += x * (x + 1) / 2;
result += y * (y - 1) / 2;
}
}
result.writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
// 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 N = lread();
long ans = N % 1000;
writeln((1000 - ans) % 1000);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main(){
auto F=readln.split.to!(int[]),a=F[0],b=F[1],c=F[2];
if(a+b==c||a+c==b||b+c==a)writeln("Yes");
else writeln("No");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;
void main()
{
auto n = readln.chomp.to!int;
long[char] cnt;
foreach (_; 0..n) {
cnt[readln.chomp[0]]++;
}
long sum;
auto ini = ['M', 'A', 'R', 'C', 'H'];
foreach (i; 0..ini.length) {
if (!cnt.get(ini[i], 0)) continue;
long ltmp = cnt[ini[i]];
foreach (j; i+1..ini.length) {
if (!cnt.get(ini[j], 0)) continue;
ltmp *= cnt[ini[j]];
foreach (k; j+1..ini.length) {
if (!cnt.get(ini[k], 0)) continue;
ltmp *= cnt[ini[k]];
sum += ltmp;
ltmp /= cnt[ini[k]];
}
ltmp /= cnt[ini[j]];
}
}
sum.writeln;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;
string my_readln() { return chomp(readln()); }
void main()
{//try{
//auto tokens = split(my_readln());
//auto N = to!ulong(tokens[0]);
//auto W = to!ulong(tokens[1]);
auto N = my_readln().to!ulong();
auto H = my_readln().to!ulong();
auto W = my_readln().to!ulong();
auto x = N - H + 1;
auto y = N - W + 1;
writeln(x * y);
stdout.flush();
/*}catch (Throwable e)
{
writeln(e.toString());
}
readln();*/
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main(){
auto F=readln.split.to!(int[]),A=F[0],B=F[1],C=F[2],D=F[3];
if(A+B<C+D)writeln("Right");
else if(A+B>C+D)writeln("Left");
else writeln("Balanced");
}
|
D
|
import std.stdio;
import std.array;
import std.conv;
void main() {
string[] input = split(readln());
int a=to!int(input[0]);
int b=to!int(input[1]);
if((a*b)%2==0) {
writeln("Even");
}else {
writeln("Odd");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
void main() {
2.rep!(() => readln.chomp).pipe!(
a => a.map!(
b => b.length
).sum.iota.map!(
i => a[i%2][i/2]
).fold!"a~b"("")
).writeln;
}
// ----------------------------------------------
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
const mx=1_000_00+5;
auto isPrime=new bool[](mx);
auto sub=new int[](mx);
isPrime[2]=true;
for(int i=3; i<=1_000_00; i+=2){
for(int j=3; j*j<=i; j+=2){
if(i%j==0) goto hell;
}
isPrime[i]=true;
if(isPrime[(i+1)/2]) sub[i]=1;
hell:;
}
int[] a;
for(int i=3; i<=1_000_00; i++)if(sub[i]) a~=i;
int q; rd(q);
while(q--){
int l, r; rd(l, r);
int cnt=0;
foreach(e; a){
if(l<=e && e<=r) cnt++;
}
writeln(cnt);
}
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) write(e, " ");
writeln();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto A = readln.chomp.to!int;
auto B = readln.chomp.to!int;
auto C = readln.chomp.to!int;
auto D = readln.chomp.to!int;
writeln(min(A, B) + min(C, D));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
int[2][6] pt;
void main()
{
foreach (i; 0..3) {
auto ab = readln.split.to!(int[]);
pt[i] = [ab[0], ab[1]];
pt[3+i] = [ab[1], ab[0]];
}
foreach (i, a; pt) {
foreach (j, b; pt) {
foreach (k, c; pt) {
if (i%3 == j%3 || j%3 == k%3 || k%3 == i%3) continue;
if (a[1] == b[0] && b[1] == c[0]) {
writeln("YES");
return;
}
}
}
}
writeln("NO");
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
void main() {
readln;
string s = readln.chomp;
int count=0;
for(int i=0; i<s.length-2; i++) {
if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') count++;
}
writeln(count);
}
|
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.outbuffer;
void main() {
long x = readln.chomp.to!long;
long atom = x / 11;
long remain = x - atom * 11;
long ans = atom * 2;
if (remain > 6) {
ans += 2;
} else if (remain > 0) {
++ans;
}
ans.writeln;
}
|
D
|
void main()
{
long n = readln.chomp.to!long;
long result;
foreach (i; 1 .. 500001)
{
int x = 108 * i / 100;
if (x == n)
{
result = i;
break;
}
}
if (result > 0)
{
result.writeln;
}
else
{
":(".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.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 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; }
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 k = RD!int;
auto ans = new bool[](k);
foreach (i; 0..k)
{
auto n = RD!int;
auto s = RD!string;
auto t = RD!string;
int[2] pos;
int cnt;
foreach (j; 0..n)
{
if (s[j] != t[j])
{
++cnt;
if (cnt >= 3) break;
pos[cnt-1] = j;
}
}
if (cnt == 2)
{
auto p1 = pos[0];
auto p2 = pos[1];
if (s[p1] == s[p2] && t[p1] == t[p2])
ans[i] = true;
}
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;
struct E{
long[] parentes;
long h=-1;
}
E[] list;
long calc(long i)
{
if(list[i].parentes.empty){
list[i].parentes = [0];
list[i].h=0;
}
if(list[i].h!=-1) return list[i].h;
long m;
foreach(parent; list[i].parentes)
{
if(calc(parent) > list[m].h){
m = parent;
}
}
list[i].parentes = [m];
list[i].h = list[m].h+1;
return list[i].h;
}
void main()
{
auto N = scanElem;
auto M = scanElem;
list.length=N+1;
foreach(i;0..N-1+M)
{
auto parent = scanElem;
auto node = scanElem;
list[node].parentes~=parent;
}
foreach(i;1..N+1)
{
calc(i);
}
foreach(i;1..N+1)
{
writeln(list[i].parentes[0]);
}
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long H, N;
scan(H, N);
auto A = new long[](N);
auto B = new long[](N);
foreach (i; 0 .. N)
scan(A[i], B[i]);
auto ans = new long[](H + 1);
ans[] = long.max >> 2;
ans[H] = 0;
foreach_reverse (h; 1 .. H + 1)
foreach (i; 0 .. N)
{
ans[max(0, h - A[i])] = ans[max(0, h - A[i])].min(ans[h] + B[i]);
}
writeln(ans[0]);
}
|
D
|
import std.stdio, std.string, std.range, std.algorithm;
import std.conv;
void main() {
int n = readln.strip.to!int;if (n == 3 || n == 5 || n == 7) writeln("YES"); else writeln("NO");
}
|
D
|
import std.stdio,
std.string,
std.conv;
string selectOp(int f) {
return (f ? "+" : "-");
}
void main() {
string s = readln.chomp;
int[] a;
for (int i = 0; i < s.length; i++) {
a ~= cast(char)s[i] - '0';
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
int e = a[0] + (i ? a[1] : -a[1])
+ (j ? a[2] : -a[2]) + (k ? a[3] : -a[3]);
if (e == 7) {
writeln(s[0] ~ selectOp(i) ~ s[1] ~ selectOp(j)
~ s[2] ~ selectOp(k) ~ s[3] ~ "=7");
return;
}
}
}
}
}
|
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[] a; readA(n, a);
writeln(a.sum-n);
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.math;
import std.format;
void main() {
int[] q;
foreach (string line; stdin.lines) {
int n = line.chomp.to!int;
if (n == 0) {
q.back.writeln;
q.popBack;
} else {
q ~= n;
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto S = readln.split[0];
int result = 10000;
foreach (i; 0 .. S.length-2) { result = min( (S[i .. i+3].to!int - 753).abs, result); }
result.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
foreach (i; 0..3) write(readln.chomp.to!(wchar[])[i]);
writeln("");
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int n;
scan(n);
auto c = new int[](n);
auto s = new int[](n);
auto f = new int[](n);
foreach (i ; 0 .. n-1) {
int ci, si, fi;
scan(ci,si,fi);
c[i] = ci;
s[i] = si;
f[i] = fi;
}
foreach (i ; 0 .. n) {
int ans;
foreach (j ; i .. n-1) {
if (ans < s[j]) {
ans = s[j];
}
else {
if (ans % f[j]) {
ans += f[j] - ans % f[j];
}
}
ans += c[j];
debug {
writeln(j, " ", ans);
}
}
writeln(ans);
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto ts = readln.split.to!(long[]);
auto I = ts[0];
auto O = ts[1];
auto J = ts[3];
auto L = ts[4];
auto K = O + I/2*2 + J/2*2 + L/2*2;
auto r = I%2 + J%2 + L%2;
if (r == 3) {
K += 3;
} else if (r == 2 && I > 0 && J > 0 && L > 0) {
K += 1;
}
writeln(K);
}
|
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 = readln.chomp.to!int;
auto a = new int[](n + 1);
foreach(i ; 1 .. n + 1){
readVars(a[i]);
}
auto dp = new int[](n + 1);
auto ma = new int[](n + 1);
ma[1 .. $] = inf;
ma[0] = -1;
foreach(i ; 1 .. n + 1){
int j = nibutan(n, ma, a[i]) + 1;
ma[j] = a[i];
dp[i] = j;
//writeln(ma);
}
int ans = dp.reduce!max;
writeln(ans);
}
int nibutan(int n, int[] ma, int v){
int btm = -1, top = n;
while (top - btm > 1) {
int mid = (top + btm) / 2;
if (ma[mid] < v) {
btm = mid;
}
else {
top = mid;
}
}
return btm;
}
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, std.string, std.algorithm, std.array, std.conv;
void main() {
for (int i = 0; i < 1000; i++) {
"Hello World".writeln;
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int r, g, b; readV(r, g, b);
writeln((g*10+b)%4 == 0 ? "YES" : "NO");
}
|
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;
import std.datetime, std.bigint;
void main() {
string n;
scan(n);
writeln("ABC" ~ 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.string;
void main()
{
while(true)
{
int sum=readln.chomp.to!int;
if(sum==0)break;
foreach(unused;0..9)
{
sum-=readln.chomp.to!int;
}
sum.writeln;
}
}
|
D
|
void main()
{
long N = rdElem;
foreach (h; 1 .. 3501)
{
foreach (n; 1 .. 3501)
{
long numer = h * n * N;
long dinom = 4 * h * n - (h + n) * N;
if (dinom <= 0) continue;
long w = numer / dinom, rem = numer % dinom;
if (w > 0 && rem == 0)
{
writeln(h, " ", n, " ", w);
return;
}
}
}
}
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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
char a;
scan(a);
if (a >= 'a')
writeln("a");
else
writeln("A");
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long N, K;
scan(N, K);
writeln(((K - 1) ^^ (N - 1)) * K);
}
|
D
|
import std.algorithm;
import std.stdio;
import std.string;
void main()
{
auto s = readln.strip;
writeln( solve( s ) );
}
int solve( in string s )
{
return 700 + s.map!( a => ( a == 'o' ) ? 100 : 0 ).sum;
}
unittest
{
assert( solve( "oxo" ) == 900 );
assert( solve( "ooo" ) == 1000 );
assert( solve( "xxx" ) == 700 );
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;
import core.stdc.stdlib;
void main()
{
auto A = scanElem;
auto B = scanElem;
auto T = scanElem;
writeln((T/A)*B);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio, std.string, std.algorithm, std.array, std.conv;
int mex(int[] arr)
{
if (arr.maxElement == 2)
return 2;
else if (arr.minElement == arr.maxElement)
return 1 - arr.minElement;
else
return 2;
}
void main()
{
int t;
scanf("%d", &t);
getchar();
foreach(j; 0..t){
int str_l;
scanf("%d", &str_l);
getchar();
auto str1 = readln.strip();
auto str2 = readln.strip();
int[] result;
for (int i = 0; i < str_l; i++)
{
if (str1[i] == str2[i])
{
result ~= cast(int)(str1[i] - '0');
}
else
result ~= 2;
}
int[] mex_res;
debug{writeln(result);}
for (int i = 0; i < str_l; i++)
{
mex_res ~= mex(result[i..i+1]);
}
debug{writeln(mex_res);}
for (int i = 0; i < str_l; i++)
{
if (mex_res[i] == 0)
{
if (i == 0)
{
if (mex_res[i+1] == 1)
{
if (mex(result[i..i+2]) == 2)
mex_res[i+1]++;
}
}
else if (i == str_l - 1)
{
if (mex_res[i-1] == 1)
{
if (mex(result[i-1..i+1]) == 2)
mex_res[i-1]++;
}
}
else
{
if (mex_res[i-1] == 1)
{
if (mex(result[i-1..i+1]) == 2)
mex_res[i-1]++;
}
else if (mex_res[i+1] == 1)
{
if (mex(result[i..i+2]) == 2)
mex_res[i+1]++;
}
}
}
}
writeln(mex_res.sum);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
void main() {
auto N = readln.chomp.to!int;
bool[int] d;
foreach(_; 0..N) {
d[readln.chomp.to!int] = true;
}
writeln(d.length);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int x, a, b;
scan(x, a, b);
if (b - a <= 0) {
writeln("delicious");
}
else if (b - a <= x) {
writeln("safe");
}
else {
writeln("dangerous");
}
}
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;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, M, K;
scan(N, M, K);
long MOD = 998244353;
auto C = Combination_mod(N, MOD);
long ans;
foreach (i; 0 .. K + 1)
{
long tmp = C(N - 1, i) * powmod(M - 1, N - i - 1, MOD);
// writeln(tmp);
ans = (ans + tmp) % MOD;
}
writeln(ans * M % MOD);
}
/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
if (n < 1)
return 1;
if (n & 1)
{
return x * powmod(x, n - 1, m) % m;
}
T tmp = powmod(x, n / 2, m);
return tmp * tmp % m;
}
/// Number of k-combinations % m (precalculated)
alias Combination_mod = Combination_modImpl!long;
struct Combination_modImpl(T)
{
T _n, _m;
T[] _fact, _factinv;
this(T maxnum, T mod = 10 ^^ 9 + 7)
{
_n = maxnum, _m = mod, _fact = new T[](_n + 1), _factinv = new T[](_n + 1), _fact[0] = 1;
foreach (i; 1 .. _n + 1)
_fact[i] = _fact[i - 1] * i % _m;
T powmod(T x, T n, T m)
{
if (n < 1)
return 1;
if (n & 1)
{
return x * powmod(x, n - 1, m) % m;
}
T tmp = powmod(x, n / 2, m);
return tmp * tmp % m;
}
foreach (i; 0 .. _n + 1)
_factinv[i] = powmod(_fact[i], _m - 2, _m);
}
T opCall(T n, T k, T dummy = 10 ^^ 9 + 7)
{
return n < k ? 0 : ((_fact[n] * _factinv[n - k] % _m) * _factinv[k] % _m);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.algorithm;
void main() {
int n = readln.chomp.to!int;
int minv = readln.chomp.to!int;
int maxv = -1_000_000_000;
foreach (i; iota(1, n, 1)) {
int l = readln.chomp.to!int;
maxv = max(maxv, l - minv);
minv = min(minv, l);
}
maxv.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.format;
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.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/3;
enum long MOD = 10L^^9+7;
void main() {
long K, A, B;
scanln(K, A, B);
long D = B-A;
if (D <= 2) {
(K+1).writeln;
return;
}
long y = max(0, min(K.floor(2), (K+1-A).floor(2)));
long x = K - 2*y;
writeln(1 + x + y*D);
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (t * y < x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (t * y > x) t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach(i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
void scanln(Args...)(auto ref Args args) {
import std.meta;
template getFormat(T) {
static if (isIntegral!T) {
enum getFormat = "%d";
} else static if (isFloatingPoint!T) {
enum getFormat = "%g";
} else static if (isSomeString!T || isSomeChar!T) {
enum getFormat = "%s";
} else {
static assert(false);
}
}
enum string fmt = [staticMap!(getFormat, Args)].join(" ");
string[] inputs = readln.chomp.split;
foreach(i, ref v; args) {
v = inputs[i].to!(Args[i]);
}
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
private template RebindableOrUnqual(T)
{
static if (is(T == class) || is(T == interface) || isDynamicArray!T || isAssociativeArray!T)
alias RebindableOrUnqual = Rebindable!T;
else
alias RebindableOrUnqual = Unqual!T;
}
private auto extremum(alias map, alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
in
{
assert(!r.empty, "r is an empty range");
}
body
{
alias Element = ElementType!Range;
RebindableOrUnqual!Element seed = r.front;
r.popFront();
return extremum!(map, selector)(r, seed);
}
private auto extremum(alias map, alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
{
alias mapFun = unaryFun!map;
alias selectorFun = binaryFun!selector;
alias Element = ElementType!Range;
alias CommonElement = CommonType!(Element, RangeElementType);
RebindableOrUnqual!CommonElement extremeElement = seedElement;
// if we only have one statement in the loop, it can be optimized a lot better
static if (__traits(isSame, map, a => a))
{
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
if (selectorFun(r[i], extremeElement))
{
extremeElement = r[i];
}
}
}
else
{
while (!r.empty)
{
if (selectorFun(r.front, extremeElement))
{
extremeElement = r.front;
}
r.popFront();
}
}
}
else
{
alias MapType = Unqual!(typeof(mapFun(CommonElement.init)));
MapType extremeElementMapped = mapFun(extremeElement);
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
MapType mapElement = mapFun(r[i]);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r[i];
extremeElementMapped = mapElement;
}
}
}
else
{
while (!r.empty)
{
MapType mapElement = mapFun(r.front);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r.front;
extremeElementMapped = mapElement;
}
r.popFront();
}
}
}
return extremeElement;
}
private auto extremum(alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r);
}
// if we only have one statement in the loop it can be optimized a lot better
private auto extremum(alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r, seedElement);
}
auto minElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!map(r);
}
auto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!map(r, seed);
}
auto maxElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!(map, "a > b")(r);
}
auto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!(map, "a > b")(r, seed);
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
return x;
}
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long l, r, d;
scan(l, r, d);
long cnt;
foreach (i; l .. r + 1)
{
if (i % d == 0)
{
cnt += 1;
}
}
writeln(cnt);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], b = tmp[1], c = tmp[2], d = tmp[3];
max(a*b, c*d).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.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime;
void main() {
auto S = readln.chomp;
string result;
foreach (s; S) {
final switch (s) {
case '0':
case '1':
result ~= s;
break;
case 'B':
if (result.length > 0)
result = result[0..$-1];
break;
}
}
writeln(result);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;
import core.bitop;
void main() {
int n; scan(n);
auto a = iota(n).map!(i => readln.chomp.to!int).array;
auto on = new bool[](32);
int xs;
foreach (i ; 0 .. n) {
on[bsf(a[i])] = 1;
xs ^= a[i];
}
int ans;
foreach_reverse (i ; 0 .. 32) {
if ((xs >> i) & 1) {
if (on[i]) {
xs ^= (1<<i) - 1;
ans++;
}
else {
writeln(-1);
return;
}
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
module main;
import core.stdc.stdio;
import std.algorithm.sorting;
int gcd (int a, int b) {
if (b == 0)
return a;
else
return gcd (b, a % b);
}
int main(string[] argv)
{
int n;
scanf("%d", &n);
int [] a = new int[n];
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
a.sort();
int small = a[1] - a[0];
for(int i = 1; i < n - 1; i++)
small = gcd(small, a[i + 1] - a[i]);
printf("%d", (a[n - 1] - a[0]) / small - n + 1);
return 0;
}
|
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;
int calc2(int n) {
if(n <= 1000) {
return n+1;
} else {
return 2000-n+1;
}
}
void main() {
while(!stdin.eof()){
auto s = readln().strip();
if(s.empty())
break;
int n = to!int(s);
int sum;
for(int i = max(0, n-2000); i <= min(n, 2000); ++i) {
sum += calc2(i)*calc2(n-i);
}
writeln(sum);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a, b, c;
scan(a, b, c);
writeln(a + b >= c ? "Yes" : "No");
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, K;
scan(N, K);
auto s = new long[](N + 2);
foreach (i; 0 .. N + 1)
{
s[i + 1] += s[i] + i;
}
long ans;
foreach (i; K .. N + 1)
{
ans = (ans + (s[$ - 1] - s[$ - i - 1]) - (s[i]) + 1) % MOD;
}
writeln(ans + 1);
}
|
D
|
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
int balance = 0;
int lo = 0;
long res = s.length;
foreach (i, char c; s)
{
balance += (c == '+') ? +1 : -1;
if (lo > balance)
{
lo = balance;
res += i + 1;
}
}
writeln (res);
}
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm;
void main(){
int[] xs = readln.chomp.split.map!(to!int).array;
int x = xs[0], y = xs[1];
writeln(x + y / 2);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
auto s = readln.chomp.split.map!(to!int).array;
if (s[0] * s[1] < s[2]) writeln(s[0] * s[1]);
else s[2].writeln;
}
|
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;
immutable long mod = 10L^^9 + 7L;
long n, m;
void main() {
scan(n, m);
if (n < m) swap(n, m);
if (n == m) {
long ans = 1;
foreach (i ; 1 .. n + 1) {
ans *= (1L * i * i) % mod;
ans %= mod;
}
(ans *= 2) %= mod;
writeln(ans);
}
else if (n == m + 1) {
long ans = 1;
foreach (i ; 1 .. n) {
ans *= (1L * i * i) % mod;
ans %= mod;
}
(ans *= n) %= mod;
writeln(ans);
}
else {
writeln(0);
}
}
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);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.array;
import std.string;
import std.math;
import std.functional;
import std.range;
import std.typecons;
import std.format;
void main(string[] args) {
readln.solve.writeln;
}
auto solve(string line1) {
auto _ = line1.chomp.split.map!(to!int).array;
int N = _[0];
int A = _[1];
int B = _[2];
long res = 0;
foreach(d1; 0..2)
foreach(d2; 0..10)
foreach(d3; 0..10)
foreach(d4; 0..10)
foreach(d5; 0..10) {
auto dsum = d1 + d2 + d3 + d4 + d5;
auto num = 10000*d1 + 1000*d2 + 100*d3 + 10*d4 + d5;
if (A <= dsum && dsum <= B && num <= N) {
res += num;
}
}
return res;
} unittest {
assert(solve("100 4 16") == 4554, "1");
assert(solve("10 1 2") == 13, "2");
assert(solve("20 2 5") == 84, "3");
}
|
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;
bool calc(int h, int w, string[] ss) {
foreach (r; 0..h) {
foreach (c; 0..w) {
if (ss[r][c] == '#') {
int k = 1;
if (r > 0 && ss[r-1][c] == '#') k++;
if (r < h-1 && ss[r+1][c] == '#') k++;
if (c > 0 && ss[r][c-1] == '#') k++;
if (c < w-1 && ss[r][c+1] == '#') k++;
if (k == 1) return false;
}
}
}
return true;
}
void main() {
int h, w; scan(h, w);
string[] ss;
foreach (_; 0..h) ss ~= read!string;
writeln(calc(h, w, ss) ? "Yes" : "No");
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
|
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 N, cnt;
bool ask(long n) {
writeln("? ", n);
stdout.flush;
cnt += 1;
debug {
string sn = n.to!string;
string sN = N.to!string;
return (n <= N && sn <= sN) || (n > N && sn > sN);
} else {
return readln.chomp == "Y";
}
}
void main() {
debug {N = readln.chomp.to!long;}
long x = 10;
for (; x <= 10^^9 && ask(x); x *= 10) {}
if (x == 10L^^10) { // N = 1, 10, 100, ...
x = 2;
for (; x <= 2 * 10L^^9 && !ask(x); x *= 10) {}
writeln("! ", x / 2);
} else {
long hi = x - 1;
long lo = x / 10;
while (hi - lo > 1) {
long mid = (hi + lo) / 2;
if (ask(mid * 10L^^9)) hi = mid;
else lo = mid;
}
writeln("! ", hi);
}
debug {cnt.writeln;}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nx = readln.split.to!(long[]);
auto N = nx[0];
auto x = nx[1];
auto as = readln.split.to!(long[]);
long r;
if (as[0] > x) {
r += as[0] - x;
as[0] = x;
}
foreach (i; 1..N) {
auto s = as[i-1] + as[i];
if (s > x) {
r += s - x;
as[i] -= s - x;
}
}
writeln(r);
}
|
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[i][w]: i個目より前までで、重さw以下とした場合の価値の最大値
xs[0][w] = 0
xs[i][w] = (w - ws[i] >= 0)?
xs[i - 1][w - ws[i]] + vs[i] : xs[i - 1][w]
*/
void main(){
long n = read.to!long;
long npw = read.to!long;
long[] ws, vs;
foreach(i; 0 .. n){
ws ~= read.to!long;
vs ~= read.to!long;
}
long[][] xs = [[]];
foreach(w; 0 .. npw + 1) xs[0] ~= 0;
foreach(i; 0 .. n){
long[] q = [];
foreach(w; 0 .. npw + 1){
q ~= max(
((w - ws[i] >= 0) ? xs[$ - 1][w - ws[i]] + vs[i] : 0),
xs[$ - 1][w]
);
debug writeln("q:", q, " w:", w, " i:", i);
}
xs ~= q;
}
xs[n][npw].writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abc = readln.split.to!(int[]);
auto AB = abc[0];
auto BC = abc[1];
writeln(AB * BC / 2);
}
|
D
|
import std.stdio;
import std.string;
import std.format;
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.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/5;
enum long MOD = 10L^^9+7;
void main() {
char[] xs = readln.chomp.to!(char[]);
long ans = 0;
foreach(i; 0..xs.length/2) {
if (xs[i] != xs[$-i-1]) ans++;
}
ans.writeln;
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (y > 0 && t * y < x) t++;
if (y < 0 && t * y > x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (y > 0 && t * y > x) t--;
if (y < 0 && t * y < x) t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach(i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
void scanln(Args...)(auto ref Args args) {
enum sep = " ";
enum n = Args.length;
enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
static if (__VERSION__ >= 2071) {
readf!fmt(args);
} else {
enum argsTemp = n.iota.map!(
i => "&args[%d]".format(i)
).join(", ");
mixin(
"readf(fmt, " ~ argsTemp ~ ");"
);
}
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
return x;
}
}
|
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() {
string s;
scan(s);
yes(check(s));
}
bool check(string s) {
return s[2] == s[3] && s[4] == s[5];
}
unittest {
assert(check("coffee"));
assert(!check("iphone"));
assert(check("sippuu"));
}
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.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
int r = readint;
int g = readint;
// (r + p) / 2 = g
int p = 2 * g - r;
writeln(p);
}
|
D
|
import std.conv;
import std.string;
import std.algorithm;
import std.array;
import std.stdio;
void main() {
auto s = readln.chomp;
auto t = readln.chomp;
uint a;
foreach (i;0..s.length) {
if (s[i] != t[i]) {
++a;
}
}
a.writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int N, A;
scan(N);
scan(A);
writeln(N^^2 - A);
}
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;
void main(){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
printf("%dx%d=%d\n",i,j,i*j);
}
}
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
long x = cin.next!long;
if (x < 500) {
writeln(x / 5 * 5);
} else {
writeln(x / 500 * 1000 + x % 500 / 5 * 5);
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split, a = rd[0].to!int, op = rd[1], b = rd[2].to!int;
writeln(op == "+" ? a+b : a-b);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
long r, g, b, n;
scan(r, g, b, n);
// writeln(r, g, b, n);
long cnt;
foreach (i; 0 .. 3001)
{
foreach (j; 0 .. 3001)
{
long tmp;
if (r * i + g * j <= n)
{
tmp = n - (r * i + g * j);
if (tmp % b == 0)
{
cnt += 1;
}
}
}
}
writeln(cnt);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new char[][](t);
foreach (i; 0..t)
{
auto n = RD!int;
auto a = RD!int;
auto b = RD!int;
auto c = RD!int;
auto s = RD!string;
int cnt;
foreach (j; 0..n)
{
if (s[j] == 'R')
{
if (b == 0)
ans[i] ~= '?';
else
{
ans[i] ~= 'P';
--b;
++cnt;
}
}
else if (s[j] == 'P')
{
if (c == 0)
ans[i] ~= '?';
else
{
ans[i] ~= 'S';
--c;
++cnt;
}
}
else
{
if (a == 0)
ans[i] ~= '?';
else
{
ans[i] ~= 'R';
--a;
++cnt;
}
}
}
if (cnt*2 < n)
{
ans[i].length = 0;
}
else
{
foreach (j; 0..n)
{
if (ans[i][j] == '?')
{
if (a != 0)
{
--a;
ans[i][j] = 'R';
}
else if (b != 0)
{
--b;
ans[i][j] = 'P';
}
else
{
--c;
ans[i][j] = 'S';
}
}
}
}
}
foreach (e; ans)
{
if (e.length == 0)
{
writeln("NO");
}
else
{
writeln("YES");
writeln(e);
}
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto T = readln.chomp.to!int;
foreach (_; 0..T) {
auto S = readln.chomp;
auto len = S.length;
auto l1 = new size_t[](len);
auto r1 = new size_t[](len);
auto l2 = new size_t[](len);
auto r2 = new size_t[](len);
auto l3 = new size_t[](len);
auto r3 = new size_t[](len);
auto i1 = len, i2 = len, i3 = len;
foreach (i, c; S) {
switch (c) {
case '1': i1 = i; break;
case '2': i2 = i; break;
default: i3 = i;
}
l1[i] = i1;
l2[i] = i2;
l3[i] = i3;
}
i1 = len, i2 = len, i3 = len;
foreach_reverse (i, c; S) {
switch (c) {
case '1': i1 = i; break;
case '2': i2 = i; break;
default: i3 = i;
}
r1[i] = i1;
r2[i] = i2;
r3[i] = i3;
}
auto res = size_t.max;
foreach (i; 0..len) {
switch (S[i]) {
case '1':
if (l2[i] != len && r3[i] != len) {
res = min(res, r3[i] - l2[i] + 1);
}
if (l3[i] != len && r2[i] != len) {
res = min(res, r2[i] - l3[i] + 1);
}
break;
case '2':
if (l1[i] != len && r3[i] != len) {
res = min(res, r3[i] - l1[i] + 1);
}
if (l3[i] != len && r1[i] != len) {
res = min(res, r1[i] - l3[i] + 1);
}
break;
default:
if (l2[i] != len && r1[i] != len) {
res = min(res, r1[i] - l2[i] + 1);
}
if (l1[i] != len && r2[i] != len) {
res = min(res, r2[i] - l1[i] + 1);
}
}
}
writeln(res == size_t.max ? 0 : res);
}
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;
void main() {
int nt = readln.strip.to!int;
foreach (tid; 0 .. nt) {
int n = readln.strip.to!int;
auto s = readln.take (n).array;
auto res = "NO";
foreach (i; 0 .. n) {
if (s[i] == '8' && (n - 1) - i >= 10) {
res = "YES";
break;
}
}
writeln (res);
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.