code
stringlengths 4
1.01M
| language
stringclasses 2
values |
---|---|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int x = readint;
int a = readint;
int b = readint;
/*
int donut = (x - a) / b;
writeln(x - a - b * donut);
*/
writeln((x - a) % b);
}
| D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto s = readln.chomp.to!(char[]);
auto t = readln.chomp.to!(char[]);
foreach (i; 0 .. s.length) {
if (s == t) {
writeln("Yes");
return;
}
s = s[$ - 1] ~ s[0 .. ($ - 1)];
}
writeln("No");
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
long f(long n)
{
long c = 0;
while (n != 0)
{
n /= 10;
c++;
}
return c;
}
void main()
{
long N = lread();
long cnt;
foreach (x; 1 .. N + 1)
{
if (f(x) & 1)
cnt++;
}
writeln(cnt);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
auto data = readln().split();
auto A = data[0].to!int(), B = data[1].to!int(), K = data[2].to!int();
int[] list;
foreach_reverse(i; 1 .. min(A, B)+1) {
if (A % i == 0 && B % i == 0) list ~= i;
}
writeln(list[K-1]);
} | 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() {
foreach(int i;1..10) foreach(int j; 1..10) {
writeln(i, "x", j, "=", i*j);
}
} | D |
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0] - 1, b = tmp[1] - 1;
writeln(a * b);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons; | D |
void main() {
writeln(readln.chomp.to!double.sqrt.to!int ^^ 2);
}
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.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
void main() {
immutable i = readln.split.to!(ulong[]);
immutable R = i[0], G = i[1], B = i[2], N = i[3];
ulong cnt = 0;
for(ulong r = 0; r <= N / R; r++) {
const ulong r_val = r * R;
if (r_val > N) break;
else if (r_val == N) cnt++;
else {
for(ulong g = 0; g <= N / G; g++) {
const ulong g_val = r*R + g*G;
if (g_val > N) break;
else if (g_val == N) cnt++;
else {
const ulong rem = (N - g_val) % B;
if (rem == 0) {
cnt++;
}
}
}
}
}
writeln(cnt);
}
| D |
import std.stdio; void main () {writeln ("NO");}
| D |
import std.stdio, std.algorithm, std.array, std.math, std.typecons, std.bigint, std.conv;
void main()
{
int k;
scanf("%d", &k);
long res1 = 2UL^^k - 2;
BigInt n = 4;
BigInt res2 = powmod(n, to!BigInt(res1), to!BigInt(10^^9 + 7));
writeln((res2 * to!BigInt(6)) % (10^^9 + 7));
} | D |
/+ dub.sdl:
name "B"
dependency "dunkelheit" version=">=0.9.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
int main() {
Scanner sc = new Scanner(stdin);
scope(exit) sc.read!true;
int n;
sc.read(n);
int[][] g = new int[][](n);
foreach (i; 1..n) {
int p;
sc.read(p); p--;
g[p] ~= i;
}
bool ans = true;
int dfs(int p) {
if (g[p].length == 0) return 1;
int u = 0;
foreach (d; g[p]) {
u += dfs(d);
}
if (u < 3) ans = false;
return 0;
}
dfs(0);
if (ans) writeln("Yes");
else writeln("No");
return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
import std.exception;
enforce(readSingle(x));
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
read!enforceEOF(args);
}
}
void read(bool enforceEOF = false, Args...)(auto ref Args args) {
import std.exception;
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
enforce(readSingle(args[0]));
read!enforceEOF(args);
}
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
| D |
module sigod.codeforces.p287A;
import std.stdio;
import std.string;
void main()
{
bool[4][4] square = read();
bool answer = solve(square);
stdout.writeln(answer ? "YES" : "NO");
}
private
bool[4][4] read()
{
bool[4][4] square;
foreach (ref line; square) {
auto tmp = stdin.readln().strip();
foreach (i; 0 .. 4) {
line[i] = tmp[i] == '.';
}
}
return square;
}
bool solve(bool[4][4] square)
{
foreach (i, line; square[0 .. $ - 1]) {
foreach (j, e; line[0 .. $ - 1]) {
auto count = e + line[j + 1]
+ square[i + 1][j] + square[i + 1][j + 1];
if (count != 2) return true;
}
}
return false;
}
unittest {
bool[4][4] t1 = [
[false, false, false, false],
[true, false, true, true],
[false, false, false, false],
[true, true, true, true]
];
assert(solve(t1) == true);
bool[4][4] t2 = [
[false, false, false, false],
[true, true, true, true],
[false, false, false, false],
[true, true, true, true]
];
assert(solve(t2) == false);
} | D |
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
p = stdin.rawRead (buffer);
}
final ubyte skipByte (ubyte lo) {
while (true) {
auto a = p[cur .. $];
auto r = a.find! (c => c >= lo);
if (!r.empty) {
cur += a.length - r.length;
return p[cur++];
}
p = stdin.rawRead (buffer);
cur = 0;
if (p.empty) return 0;
}
}
final ubyte nextByte () {
if (cur < p.length) {
return p[cur++];
}
p = stdin.rawRead (buffer);
if (p.empty) return 0;
cur = 1;
return p[0];
}
template next(T) if (isSigned!T) {
final T next () {
T res;
ubyte b = skipByte (45);
if (b == 45) {
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
final T next () {
T res = skipByte (48) - 48;
while (true) {
ubyte b = nextByte ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
}
long solve (long[] a) {
long curs = 0, maxs = 0;
foreach (x; a) {
curs += x;
if (curs < 0) {
curs = 0;
}
maxs = max (maxs, curs);
}
return maxs;
}
void main() {
auto r = new InputReader;
immutable n = r.next!int;
immutable x = r.next!int;
auto a = new long[n];
foreach (i; 0 .. n) {
a[i] = r.next!long;
}
long[3] curs;
long maxs = 0;
foreach (i; 0 .. n) {
foreach_reverse (state; 0 .. 3) {
long y = a[i];
if (state == 1) {
y *= x;
}
long s = long.min;
foreach (oldstate; max (0, state - 1) .. state + 1) {
s = max (s, curs[oldstate]);
}
s += y;
if (s < 0) {
s = 0;
}
curs[state] = s;
maxs = max (maxs, s);
}
}
writeln (maxs);
}
| D |
import std.stdio;
import std.ascii;
import core.stdc.stdio;
import std.algorithm;
int main()
{
int n = readInt!int;
auto a = new long[](n);
foreach(ref ai; a) ai = readInt!long;
int pos = cast(int) a.count!(ai => ai >= 0);
long[][] maxSum = new long[][](n + 1, n + 1);
maxSum[0][0] = (a[0] < 0)? 0 : a[0];
foreach(i; 1 .. n)
{
maxSum[i][0] = (a[i] < 0)? maxSum[i-1][0] : (maxSum[i-1][0] + a[i]);
}
foreach(p; 1 .. n)
{
foreach(i; 0 .. n)
{
if (a[i] < 0)
{
if (i == 0)
{
maxSum[i][p] = -1;
}
else
{
maxSum[i][p] = max(maxSum[i-1][p], maxSum[i-1][p-1] + a[i]);
}
}
else
{
if (i == 0)
{
maxSum[i][p] = -1;
}
else
{
maxSum[i][p] = (maxSum[i-1][p] >= 0)? (maxSum[i-1][p] + a[i]) : maxSum[i-1][p];
}
}
}
}
int p = 0;
while (p + 1 < n && maxSum[n-1][p + 1] >= 0)
{
p++;
}
writeln(pos + p);
return 0;
}
/* INPUT ROUTINES */
int currChar;
static this()
{
currChar = getchar();
}
char topChar()
{
return cast(char) currChar;
}
void popChar()
{
currChar = getchar();
}
auto readInt(T)()
{
T num = 0;
int sgn = 0;
while (topChar.isWhite) popChar;
while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
if (sgn) return -num; return num;
}
string readString()
{
string res = "";
while (topChar.isWhite) popChar;
while (!topChar.isWhite) { res ~= topChar; popChar; }
return res;
}
| D |
import std.algorithm;
import std.conv;
import std.array;
import std.stdio;
import std.string;
void main() {
string[][int] blocks;
readln; // to skip n
loop:
for (;;) {
auto command = readln.strip.split;
auto operation = command[0];
final switch (operation) {
case "push":
auto dst = command[1].to!int - 1;
auto block = command[2];
blocks[dst] ~= block;
break;
case "pop":
auto src = command[1].to!int - 1;
auto block = blocks[src][$-1];
blocks[src] = blocks[src][0 .. $-1];
writeln(block);
break;
case "move":
auto src = command[1].to!int - 1;
auto dst = command[2].to!int - 1;
auto block = blocks[src][$-1];
blocks[src] = blocks[src][0 .. $-1];
blocks[dst] ~= block;
break;
case "quit":
break loop;
}
}
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto X = RD;
auto A = RD;
writeln(X < A ? 0 : 10);
stdout.flush();
debug readln();
} | 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() {
char x, y;
scan(x, y);
char ans;
if (x < y) {
ans = '<';
}
else if (x > y) {
ans = '>';
}
else {
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 |
void main() {
string[dchar] s;
s['a'] = readln.chomp;
s['b'] = readln.chomp;
s['c'] = readln.chomp;
dchar now = 'a';
dchar ans;
while (true) {
dchar tmp = s[now][0];
s[now] = s[now][1..$];
now = tmp;
if (s[now].length == 0) {
ans = tmp;
break;
}
}
ans.toUpper.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.uni; | 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!long;
long ans = 0;
foreach (i; 2..N) ans += i * (i + 1);
ans.writeln;
}
| 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 r = long.max;
foreach (x; 0..N+1) {
long rr;
auto a = x;
while (a) rr += a%6, a /= 6;
auto b = N-x;
while (b) rr += b%9, b /= 9;
r = min(r, rr);
}
writeln(r);
} | D |
/+ dub.sdl:
name "F"
dependency "dcomp" version=">=0.7.3"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
import std.typecons;
alias E = Tuple!(int, "to", int, "dist");
alias D = int;
int main() {
Scanner sc = new Scanner(stdin);
static struct PairingHeapAllAdd {
alias NP = Node*;
static struct Node {
E e;
D offset;
NP head, next;
this(E e) {
this.e = e;
offset = D(0);
}
}
NP n;
size_t length;
this(E[] e) {
length = e.length;
foreach (d; e) {
n = merge(n, new Node(d));
}
}
static NP merge(NP x, NP y) {
if (!x) return y;
if (!y) return x;
if (x.e.dist+x.offset < y.e.dist+y.offset) swap(x, y);
y.offset -= x.offset;
y.next = x.head;
x.head = y;
return x;
}
void C() { assert(n); }
E front() {C; return n.e; }
void removeFront() {
assert(n);
assert(length > 0);
length--;
NP x;
NP s = n.head;
while (s) {
NP a, b;
a = s; s = s.next; a.next = null; a.offset += n.offset;
if (s) {
b = s; s = s.next; b.next = null; b.offset += n.offset;
}
a = merge(a, b);
assert(a);
if (!x) x = a;
else {
a.next = x.next;
x.next = a;
}
}
n = null;
while (x) {
NP a = x; x = x.next;
n = merge(a, n);
}
}
void meld(PairingHeapAllAdd r) {
length += r.length;
n = merge(n, r.n);
}
ref D offset() {C; return n.offset; }
}
int n, m;
sc.read(n, m);
E[][] g = new E[][n];
foreach (i; 0..m) {
int a, b, c;
sc.read(a, b, c); a--; b--;
g[a] ~= E(i, c);
g[b] ~= E(i, c);
}
auto heap = new PairingHeapAllAdd[2*n];
foreach (i; 0..n) {
// writeln(i, " -> ", g[i]);
heap[i] = PairingHeapAllAdd(g[i]);
}
int[] pre = new int[m]; pre[] = -1;
bool[] fix = new bool[m];
long sm = 0;
int pc = n;
foreach (i; 0..2*n) {
if (i == pc) break;
while (heap[i].length && fix[heap[i].front.to]) heap[i].removeFront;
if (!heap[i].length) continue;
auto e = heap[i].front;
int c = e.dist;
int x = i;
if (pre[e.to] == -1) {
sm += c;
pre[e.to] = i;
continue;
}
int y = pre[e.to];
//merge x, y
fix[e.to] = true;
int P = pc++;
heap[P].meld(heap[x]);
heap[P].meld(heap[y]);
}
writeln(sm);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
// import dcomp.array;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
FastAppender!(E[]) buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;
T[N] fixed(T, size_t N)(T[N] a) {return a;}
struct FastAppender(A, size_t MIN = 4) {
import std.algorithm : max;
import std.conv;
import std.range.primitives : ElementEncodingType;
import core.stdc.string : memcpy;
private alias T = ElementEncodingType!A;
private T* _data;
private uint len, cap;
@property size_t length() const {return len;}
bool empty() const { return len == 0; }
void reserve(size_t nlen) {
import core.memory : GC;
if (nlen <= cap) return;
void* nx = GC.malloc(nlen * T.sizeof);
cap = nlen.to!uint;
if (len) memcpy(nx, _data, len * T.sizeof);
_data = cast(T*)(nx);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void opOpAssign(string op : "~")(T item) {
if (len == cap) {
reserve(max(MIN, cap*2));
}
_data[len++] = item;
}
void insertBack(T item) {
this ~= item;
}
void removeBack() {
len--;
}
void clear() {
len = 0;
}
ref inout(T) back() inout { assert(len); return _data[len-1]; }
ref inout(T) opIndex(size_t i) inout { return _data[i]; }
T[] data() {
return (_data) ? _data[0..len] : null;
}
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/
| D |
import std.stdio;
import std.string;
import std.conv;
void main() {
string input;
while ((input = readln.chomp).length != 0) {
auto n = input.to!int;
auto sum = 0;
auto a = 2;
sum += a;
if (n >= 2) {
sum += (n+2)*(n-1)/2;
}
writeln(sum);
}
} | 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()
{
long n = lread();
auto alph = "abcdefghijklmnopqrstuvwxyz";
auto k = new long[](0);
while (n > 0)
{
k ~= n % 26;
n /= 26;
}
// k.writeln();
auto ans = new char[](0);
foreach (i, e; k)
{
if (e)
{
ans ~= alph[e - 1];
}
else
{
if (i + 1 < k.length)
{
ans ~= 'z';
long tmp = i + 1;
while (k[tmp] == 0)
{
k[tmp] = 25;
tmp++;
}
k[tmp]--;
}
}
}
ans.reverse().writeln();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
| D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long A, B;
scan(A, B);
long m = (A + B).max(A - B).max(A * B);
writeln(m);
}
| D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
void main() {
auto N = readln.chomp.to!int;
auto A = N.iota.map!(_ => readln.chomp.to!int - 1).array;
auto B = new int[](N);
foreach (i; 0..N) B[A[i]] = i;
int ans = 1;
int tmp = 1;
foreach (i; 0..N-1) {
if (B[i] < B[i+1])
tmp++;
else
tmp = 1;
ans = max(ans, tmp);
}
ans = N - ans;
ans.writeln;
}
| D |
import std.algorithm;
import std.stdio;
void main ()
{
auto s = readln;
auto x = (s[0] == 'a' || s[0] == 'h');
auto y = (s[1] == '1' || s[1] == '8');
writeln (8 - 3 * (x + y) + (x * y));
}
| D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
enum L = 2001;
void main() {
int M, D;
scan(M, D);
int ans;
foreach (m ; 1 .. M + 1) {
foreach (d ; 1 .. D + 1) {
auto d1 = d % 10;
auto d10 = d / 10;
if (d1 <= 1 || d10 <= 1) {
continue;
}
if (d1 * d10 == m) ans++;
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
| D |
import 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.stdio;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto P = s[1];
auto A = readln.split.map!(to!int).array;
auto dp = new long[][](N+1, 2);
dp[0][0] = 1;
foreach (i; 0..N) {
if (A[i] % 2 == 0) {
dp[i+1][0] = dp[i][0] + dp[i][0];
dp[i+1][1] = dp[i][1] + dp[i][1];
}
else {
dp[i+1][0] = dp[i][0] + dp[i][1];
dp[i+1][1] = dp[i][0] + dp[i][1];
}
}
dp[N][P].writeln;
}
| D |
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
void main() {
auto N = readln.chomp.to!long;
long solve() {
return N % 2 == 0 ? N/2 : N/2 + 1;
}
solve().writeln;
}
| D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long a,b;
scan(a,b);
(a%b?1:0).writeln();
} | D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int N, M;
scan(N, M);
auto a = new int[](N);
a[] = -1;
foreach (i ; 0 .. M) {
int si, ci;
scan(si, ci);
si--;
if (a[si] != -1 && a[si] != ci) {
writeln(-1);
return;
}
a[si] = ci;
}
if (a[0] == 0) {
writeln(N == 1 ? 0 : -1);
return;
}
if (a.all!"a == -1" && N == 1) {
writeln(0);
return;
}
foreach (i ; 0 .. N) {
if (a[i] != -1) {
write(a[i]);
}
else {
write(i == 0 ? 1 : 0);
}
}
writeln;
}
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;
}
| D |
import std.stdio;
import std.string;
void main() {
string s = readln.chomp;
if (s == "SUN") writeln(7);
if (s == "MON") writeln(6);
if (s == "TUE") writeln(5);
if (s == "WED") writeln(4);
if (s == "THU") writeln(3);
if (s == "FRI") writeln(2);
if (s == "SAT") writeln(1);
}
| D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int n;
scan(n);
writeln(n % s(n) == 0 ? "Yes" : "No");
}
int s(int n) {
return n > 0 ? s(n / 10) + n % 10 : 0;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
| D |
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
void main() {
auto n = readln.chomp.length;
foreach(i; 0..n) write("x");
writeln("");
}
| D |
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;
struct Qes{
char t;
char d;
}
long N;
string S;
Qes[] qs;
long calc(long s, long g)
{
long pos = (s+g)/2;
foreach(q; qs)
{
if(q.t!=S[pos-1])continue;
pos += q.d=='R'?1:-1;
if(pos==0)break;
if(pos==N+1)break;
}
if(s==g)
{
if(pos==0)
return s;
else
return 0;
}
if(abs(s-g)==1)
{
return max(calc(s, s) , calc(g, g));
}
return pos==0 ? calc((s+g)/2, g) : calc(s, (s+g)/2);
}
long calc2(long s, long g)
{
if(abs(s-g)==1)
{
return max(calc2(s, s) , calc2(g, g));
}
long pos = (s+g)/2;
foreach(q; qs)
{
if(q.t!=S[pos-1])continue;
pos += q.d=='R'?1:-1;
if(pos==N+1)break;
if(pos==0)break;
}
if(s==g)
{
if(pos==N+1)
return N-s+1;
else
return 0;
}
return pos==N+1 ? calc2(s, (s+g)/2) : calc2((s+g)/2, g);
}
void main()
{
N = scanElem;
long Q = scanElem;
S = readln.strip;
foreach(i; 0..Q)
{
char t = scanElem!char;
char d = scanElem!char;
qs ~= Qes(t,d);
}
auto l = calc(1, N);
auto r = calc2(1,N);
writeln(N-l-r);
}
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));
}
}
}
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.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto S = RD!string;
bool ans = true;
foreach (i; 0..S.length)
{
if (i % 2 == 0)
{
if (S[i] != 'h')
ans = false;
}
else if (S[i] != 'i')
ans = false;
}
writeln(S.length % 2 == 0 && ans ? "Yes" : "No");
stdout.flush;
debug readln;
} | D |
import std;
void main()
{
const K = readln().chomp().to!ulong();
ulong sum = 0;
foreach (i; 1 .. K + 1)
foreach (j; 1 .. K + 1)
foreach (k; 1 .. K + 1)
{
sum += gcd(gcd(i, j), k);
}
writeln(sum);
}
| D |
void main() {
auto N = ri;
ulong a = 0, b = 0;
while(4*a <= 100) {
ulong tmp = 4*a + 7*b;
while(tmp <= 100) {
if(tmp == N) {
writeln("Yes");
return;
}
b++;
tmp = 4*a + 7*b;
}
a++;
b = 0;
}
writeln("No");
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto s = readln.chomp.to!(char[]);
if (s[0] == s[$-1] && s.length%2 == 0 || s[0] != s[$-1] && s.length%2 == 1) {
writeln("First");
} else {
writeln("Second");
}
} | D |
import std.stdio, std.string, std.conv;
void main() {
int n = readln.chomp.to!int;
bool ok;
foreach (i; 1 .. 10) {
foreach (j; 1 .. 10) {
if (i * j == n) ok = true;
}
}
writeln(ok ? "Yes" : "No");
} | D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
auto ss = reads!string;
auto a = ss[0], b = ss[1], c = ss[2];
if (a[$-1] == b[0] && b[$-1] == c[0])
writeln("YES");
else
writeln("NO");
}
| 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 input = readln.split.to!(int[]);
auto A = input[0], B = input[1], C = input[2], D = input[3];
writeln( (C%B == 0 ? C/B : C/B+1) <= (A%D == 0 ? A/D : A/D+1) ? "Yes" : "No");
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
readln;
int c;
foreach (i; readln.split.to!(int[])) if (i%2 == 1) ++c;
writeln(c%2 == 0 ? "YES" : "NO");
} | D |
/+ dub.sdl:
name "C"
dependency "dunkelheit" version=">=0.9.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
int main() {
Scanner sc = new Scanner(stdin);
scope(exit) assert(!sc.hasNext);
long a, b, c, x, y;
sc.read(a, b, c, x, y);
a = min(a, 2*c);
b = min(b, 2*c);
c = min(2*c, a+b);
long z = min(x, y);
writeln(a*(x-z) + b*(y-z) + c*z);
return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(Args...)(auto ref Args args) {
import std.exception;
static if (args.length != 0) {
enforce(readSingle(args[0]));
read(args[1..$]);
}
}
bool hasNext() {
return succ();
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
| D |
import std.stdio, 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 ds = digsum(n);
writeln(n % ds == 0 ? "Yes" : "No");
}
int digsum(int n) {
return n > 0 ? digsum(n / 10) + (n % 10) : 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);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
} | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto s = sread();
long t;
foreach (e; s)
{
t += (e == '+' ? 1 : -1);
}
t.writeln();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
| D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}
void readM(T)(size_t r,size_t c,ref T[][]t){t=new T[][](r);foreach(ref ti;t)readA(c,ti);}
void main()
{
auto t = 10;
int n; readV(n);
int[][] f; readM(n, t, f);
int[][] p; readM(n, t+1, p);
auto fb = new int[](n);
foreach (i; 0..n)
foreach (j; 0..t)
if (f[i][j]) fb[i] = fb[i].bitSet(j);
auto r = -10^^9;
foreach (i; 1..1<<t) {
auto s = 0;
foreach (j; 0..n) s += p[j][(i&fb[j]).popcnt];
r = max(r, s);
}
writeln(r);
}
pragma(inline) {
pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }
pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
import core.bitop;
pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
void main() {
auto a = readln.chomp.dup;
auto b = readln.chomp.dup;
reverse(b);
writeln(a == b ? "YES" : "NO");
}
| D |
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const tmp = readln.split.to!(long[]);
writeln(tmp[0] <= 8 && tmp[1] <= 8 ? "Yay!" : ":(");
}
| 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()
{
auto S = sread();
auto T = ["dreamer", "eraser", "erase", "dream"];
long i = S.length;
w: while (0 < i)
{
foreach (t; T)
{
// writeln(max(0, i - cast(long)t.length), " ", min(i, S.length));
if (S[max(0, i - cast(long)t.length) .. min(i, S.length)] == t)
{
i -= t.length;
continue w;
}
}
writeln("NO");
return;
}
writeln("YES");
}
| D |
import std.stdio;
import std.conv;
import std.array;
void main()
{
while (1) {
int cnt = 0;
string[] input = split(readln());
int n = to!(int)(input[0]);
int x = to!(int)(input[1]);
if (n == 0 && x == 0) break;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
for (int k = j + 1; k <= n; k++) {
if (i == j || i == k || j == k) continue;
if (i + j + k == x) cnt++;
}
}
}
writeln(cnt);
}
} | D |
import std.stdio, std.conv, std.array, std.range, std.algorithm, std.string, std.typecons;
void main() {
auto s = readln.strip;
if (15 - s.length + s.count('o') >= 8) {
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.ascii;
void main()
{
auto s = readln.chomp;
foreach (e; s) {
if (e == '1') {
write('9');
} else if (e == '9') {
write('1');
} else {
write(e);
}
}
writeln("");
}
| D |
void main() {
long[] tmp = readln.split.to!(long[]);
long n = tmp[0], a = tmp[1], b = tmp[2];
long[] x = readln.split.to!(long[]);
long result;
foreach (i; 1 .. n) {
long diff = x[i] - x[i-1];
result += min(a*diff, b);
}
result.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;
void main(){
bool[3] a;
a[0] = true;
a[1] = false;
a[2] = false;
while(true){
auto s = readln();
if(stdin.eof()) break;
s = chomp(s);
swap(a[to!int(s[0]-'A')],a[to!int(s[2]-'A')]);
}
for(int i=0;i<3;i++){
if(a[i]) writeln(to!char(i + to!int('A')));
}
} | 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 N = RD;
writeln(N * (N - 1) / 2);
stdout.flush();
debug readln();
} | 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, std.datetime;
// 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, W, K;
scan(H, W, K);
auto S = new string[](H);
foreach (i; 0 .. H)
S[i] = sread();
long ans = long.max;
loop_split_row: foreach (uint split_row; 0 .. 1 << (H - 1))
{
long cnt = popcnt(split_row);
long row = cnt + 1;
auto sum = new long[][](row, W);
loop_w: foreach (i; 0 .. W)
{
long j;
foreach (k; 0 .. H)
{
// writefln("%010b %s %s", split_row & (1 << k), j, k);
sum[j][i] += S[k][i] - '0';
j += ((split_row & (1 << k)) != 0);
}
if (i == 0)
continue loop_w;
foreach (k; 0 .. row)
if (K < sum[k][i])
continue loop_split_row;
foreach (k; 0 .. row)
if (K < sum[k][i] + sum[k][i - 1])
{
// writeln(i);
cnt++;
continue loop_w;
}
foreach (k; 0 .. row)
sum[k][i] += sum[k][i - 1];
}
// writefln("%010b %s %s", split_row, sum, cnt);
ans = ans.min(cnt);
}
writeln(ans);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
auto S = split(readln())[0];
auto year = to!int(S[0 .. 4]), month = to!int(S[5 .. 7]), day = to!int(S[8 .. 10]);
string result = (year < 2019 || year == 2019 && month < 4 || year == 2019 && month == 4 && day <= 30) ? "Heisei" : "TBD";
writeln(result);
} | D |
import std.stdio, std.string, std.conv, std.array, std.algorithm, std.range;
void main()
{
0.iota(readln.chomp.to!int+1).reduce!"a+b".writeln;
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;
void main()
{
auto x = readln.chomp.to!int;
while (x > 0) {
auto m = x % 100;
if (m > 5) {
m = 5;
}
x -= 100 + m;
}
writeln(x == 0 ? 1 : 0);
}
| D |
/+ dub.sdl:
name "B"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner, dcomp.algorithm;
int main() {
auto sc = new Scanner(stdin);
int[] buf = new int[1000];
int a, b;
sc.read(a, b);
foreach (i; a..b) {
buf[i] += 1;
}
sc.read(a, b);
foreach (i; a..b) {
buf[i] += 1;
}
writeln(buf.filter!"a==2".array.length);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;
import std.range.primitives;
import std.traits : isFloatingPoint, isIntegral;
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
while (r-l > 1) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
foreach (i; 0..cnt) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}
ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return minimum!pred(range, e);
}
E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}
ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return maximum!pred(range, e);
}
Rotator!Range rotator(Range)(Range r) {
return Rotator!Range(r);
}
struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
size_t cnt;
Range start, now;
this(Range r) {
cnt = 0;
start = r.save;
now = r.save;
}
this(this) {
start = start.save;
now = now.save;
}
@property bool empty() {
return now.empty;
}
@property auto front() {
assert(!now.empty);
import std.range : take, chain;
return chain(now, start.take(cnt));
}
@property Rotator!Range save() {
return this;
}
void popFront() {
cnt++;
now.popFront;
}
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(long[]), n = rd[0], m = rd[1];
auto c = min(n, m/2);
m -= c*2;
c += m/4;
writeln(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;
void main() {
int r = readint;
if (r < 1200) writeln("ABC");
else if (r < 2800) writeln("ARC");
else writeln("AGC");
} | D |
import std.stdio, std.ascii;
void main() {
auto d = readln.dup;
foreach (c; d) c.isLower ? c.toUpper.write : c.toLower.write;
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
(48-readln.chomp.to!int).writeln;
}
| D |
import std.stdio;
import std.string;
import std.conv;
void main() {
uint[string] table;
while(true) {
string line = readln.chomp;
if (stdin.eof) break;
auto data = line.split(",");
table[data[1]] += 1;
}
foreach(type; ["A", "B", "AB", "O"]) {
if (type in table)
writeln(table[type]);
else
writeln(0);
}
} | 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.container;
import std.bigint;
void main()
{
auto str1 = readln.chomp;
auto str2 = readln.chomp;
int s1, s2;
for (int i; i < str1.length; i+=2) {
if (str1[i] == '(' && str2[i] == '8') s1++;
else if (str1[i] == '8' && str2[i] == '[') s1++;
else if (str1[i] == '[' && str2[i] == '(') s1++;
else if (str2[i] == '(' && str1[i] == '8') s2++;
else if (str2[i] == '8' && str1[i] == '[') s2++;
else if (str2[i] == '[' && str1[i] == '(') s2++;
}
if (s1 > s2) "TEAM 1 WINS".writeln;
else if (s1 < s2) "TEAM 2 WINS".writeln;
else "TIE".writeln;
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
long ans = 1;
foreach (i; 0..N)
{
ans.modm(i+1);
}
writeln(ans);
stdout.flush();
debug readln();
} | D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long Q, H, S, D;
scan(Q, H, S, D);
long N = lread();
N *= 4;
long solve(long x)
{
if (x == 0)
return 0;
long ret = long.max;
if (8 <= x)
ret = ret.min((x / 8) * D + solve(x % 8));
if (4 <= x)
ret = ret.min((x / 4) * S + solve(x % 4));
if (2 <= x)
ret = ret.min((x / 2) * H + solve(x % 2));
if (1 <= x)
ret = ret.min((x / 1) * Q + solve(x % 1));
return ret;
}
solve(N).writeln();
}
| D |
import std.stdio;
import std.algorithm;
import std.string;
void main() {
while (true) {
int H, N;
scanf("%d %d\n", &H, &N);
if (H == 0 && N == 0) break;
const int X = 20;
auto F = new string[2][X];
foreach (i; 0 .. H) {
F[i][0] = readln.chomp;
F[i][1] = readln.chomp;
}
foreach (i; H .. X) foreach (j; 0 .. 2) F[i][j] = "..";
int c = H;
struct S {
string[2][] F;
int del_n;
}
S[] states = [S(F, 0)];
foreach (n; 0 .. N) {
string[2][2] block;
foreach (i; 0 .. 2) foreach (j; 0 .. 2) {
block[i][j] = readln.chomp; // which comes first is the lower one
}
bool empty(string[2] f) {
foreach (i; 0 .. 2) foreach (j; 0 .. 2) if (f[i][j] == '#') return false;
return true;
}
if (empty(block[0])) {
swap(block[0], block[1]);
}
S[] nstates;
for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) {
char[][2][2] nblock;
foreach (i; 0 .. 2) foreach (j; 0 .. 2) {
nblock[i][j] = new char[2];
foreach (k; 0 .. 2) {
nblock[i][j][k] = '.';
}
}
foreach (k; 0 .. 2) {
foreach (i; 0 .. 2) {
foreach (j; 0 .. 2) {
if (block[k][i][j] == '#' && (i + dy < 0 || i + dy >= 2 || j + dx < 0 || j + dx >= 2)) {
goto next;
}
}
}
}
// this block can be slided by [dy, dx]
foreach (k; 0 .. 2) foreach (i; 0 .. 2) foreach (j; 0 .. 2) {
if (block[k][i][j] == '#') {
nblock[k][i + dy][j + dx] = '#'; // this line cannot cause range violation
}
}
foreach (s; states) {
S drop() {
auto F = s.F.dup;
int del_n = s.del_n;
int h = 0;
bool collide(string[2] f, string[2] g) {
foreach (i; 0 .. 2) foreach (j; 0 .. 2) {
if (f[i][j] == '#' && g[i][j] == '#') return true;
}
return false;
}
string[2] merge(string[2] f, string[2] g) {
assert(!collide(f, g));
char[2][2] r;
foreach (i; 0 .. 2) foreach (j; 0 .. 2) {
r[i][j] = ((f[i][j] == '#' || g[i][j] == '#') ? '#' : '.');
}
string[2] ret;
foreach (i; 0 .. 2) ret[i] = r[i].idup;
return ret;
}
for (int y = X - 2; y >= 0; y--) {
if (collide(F[y], cast(string[2])nblock[0]) || collide(F[y + 1], cast(string[2])nblock[1])) {
h = y + 1;
break;
}
}
foreach (i; 0 .. 2) {
F[h + i] = merge(F[h + i], cast(string[2])nblock[i]);
}
int c_height = 0;
foreach (y; 0 .. X) {
bool filled(string[2] f) {
foreach (i; 0 .. 2) foreach (j; 0 .. 2)
if (f[i][j] == '.') return false;
return true;
}
if (filled(F[y])) {
del_n++;
} else {
F[c_height] = F[y];
c_height++;
}
}
foreach (y; c_height .. X) {
F[y] = ["..", ".."];
}
return S(F, del_n);
}
auto nstate = drop();
nstates ~= nstate;
}
next:;
}
}
states = nstates;
}
int ans = 0;
foreach (state; states) {
ans = max(ans, state.del_n);
}
writeln(ans);
}
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long N = lread();
long x = 1;
while (x * 2 <= N)
{
x *= 2;
}
writeln(x);
}
| D |
void main()
{
string s = readln.chomp;
s[0..$-8].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.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
long x, y;
foreach (i; 0..n-1)
{
if (i < n/2-1)
{
x += 2^^(i+1);
}
else
{
y += 2^^(i+1);
}
}
x += 2^^n;
ans[ti] = x - y;
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
} | D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
writeln((scanElem-1)*(scanElem-1));
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto A = new long[](N);
foreach (i; 0 .. N)
A[i] = lread();
auto dp = new long[](N + 1);
dp[] = long.min;
dp[0] = long.max;
long ans = long.min;
foreach (i; 0 .. N)
{
long j = () {
long ok = 0;
long ng = N + 2;
while (1 < ng - ok)
{
long m = (ng + ok) / 2;
if (A[i] <= dp[m])
{
ok = m;
}
else
{
ng = m;
}
}
return ng;
}();
dp[j] = A[i];
ans = ans.max(j);
}
writeln(ans);
}
| 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;
void main(){
auto n = readln.chomp.to!int;
auto a = readln.chomp.to!int;
((n % 500) <= a ? "Yes" : "No").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() {
auto s = new bool[](10^^6 + 1);
s[] = 1;
s[0] = s[1] = 0;
for (int p = 2; p*p <= 10^^6; p++) {
if (s[p]) {
for (int q = p*p; q <= 10^^6; q += p) {
s[q] = 0;
}
}
}
while (1) {
int a, d, n;
scan(a, d, n);
if (!a) return;
int m;
while (m < n) {
if (s[a]) m++;
a += d;
}
a-=d;
writeln(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 |
void main(){
auto S = readln().chomp();
auto T = readln().chomp();
if ( S[] == T[0..$-1] ){
writeln("Yes");
} else {
writeln("No");
}
}
import std;
string readStr(){
return readln().chomp();
}
T[] readLine( T = long )(){
return readln().split().to!(T[])();
} | 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 MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias SugarWater = Tuple!(long, "swater", long, "sugar");
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;
}
}
auto charcount(string s)
{
char current = s[0];
auto ret = new long[](1);
foreach (e; s)
{
if (e != current)
{
ret ~= [0];
current = e;
}
ret[$ - 1]++;
}
return ret;
}
void main()
{
auto s = sread();
auto t = sread();
char[char] trans;
foreach (i; iota(s.length))
{
if (s[i] in trans)
{
if (trans[s[i]] != t[i])
{
writeln("No");
return;
}
}
else
{
trans[s[i]] = t[i];
}
}
auto check = new long[](26);
foreach (e; trans)
check[e - 'a']++;
foreach (e; check)
{
if (e > 1)
{
writeln("No");
return;
}
}
writeln("Yes");
} | 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() {
string str = readln.chomp;
str.length.iota.retro.filter!"a%2==0".find!(
i => str[0..i/2]==str[i/2..i]
).front.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 |
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 = "%.15f";
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;
string ans;
if (S[0] == 'S')
ans = "Cloudy";
else if (S[0] == 'C')
ans = "Rainy";
else
ans = "Sunny";
writeln(ans);
stdout.flush();
debug readln();
} | D |
import std;
void main() {
int n; scan(n);
int m = n % 10;
if (m == 3) writeln("bon");
else if (m == 0 || m == 1 || m == 6 || m == 8) writeln("pon");
else writeln("hon");
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;
| D |
void main()
{
long k = rdElem;
string s = rdStr;
if (s.length <= k) s.writeln;
else writeln(s[0..k], "...");
}
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.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
long x, y; readV(x, y);
writeln((x-y).abs <= 1 ? "Brown" : "Alice");
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
char[] input = readln().dup;
input[5] = ' ';
input[13] = ' ';
input.writeln;
}
| 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 H = readln.chomp.to!int;
auto W = readln.chomp.to!int;
writeln((N - W + 1) * (N - H + 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 xs = readints;
int a = xs[0], b = xs[1], c = xs[2], d = xs[3];
if (a + b > c + d) writeln("Left");
else if (a + b == c + d) writeln("Balanced");
else writeln("Right");
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int a, b; readV(a, b);
writeln(a*b%2 == 0 ? "Even" : "Odd");
}
| D |
void main() {
auto O = rs, E = rs;
foreach(i; 0..O.length) {
O[i].write;
if(!(i > E.length-1)) E[i].write;
}
writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto lr = readln.split.to!(long[]);
auto L = lr[0];
auto R = lr[1]+1;
long x = long.max;
foreach (l; L..min(L+2020, R)) {
foreach (r; l+1..min(L+2020,R)) {
x = min(x, (l*r)%2019L);
}
}
writeln(x);
} | 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
10
ZABCDBABCQ
---+/
/+---test
33
ABCCABCBABCCABACBCBBABCBCBCBCABCB
---+/
void main(string[] args) {
const N = readln.chomp.to!long;
const S = readln.chomp;
long ans;
long offset;
while (true) {
const x = S[offset..$].indexOf("ABC");
if (x == -1) break;
offset += x + 1;
++ans;
}
ans.writeln;
}
| D |
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
import std.typecons;
void main() {
auto N = readln.chomp.to!int;
int[] prices;
foreach(i; 0..50000) {
auto price = cast(int)(1.08f * cast(real)i);
if (price == N) {
prices ~= i;
}
}
if (prices.length == 0) {
writeln(":(");
} else {
writeln(prices[0]);
}
}
| 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.container;
import std.random;
void main() {
auto x = readln.chomp.split.map!(to!int);
auto a = x[0];
auto b = x[1];
auto op = a == b ? "==" : a > b ? ">" : "<";
writeln("a ", op, " b");
} | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main()
{
auto N = readln.chomp.to!int;
bool[int] data;
foreach(_; 0..N){
auto A = readln.chomp.to!int;
if(A in data)
data.remove(A);
else
data[A] = true;
}
writeln(data.length);
} | D |
import std.stdio, std.conv, std.string, std.array, std.algorithm,
std.numeric, std.math, std.range;
void main()
{
string s = readln.strip;
long[] xs = new long[](s.length);
char prev = 'x';
bool last_even = false;
long last_marked = -1;
long next = 0;
long next_1 = 0;
foreach (i; 0 .. s.length)
{
if (prev == 'R' && s[i] == 'L')
{
last_marked = i - 1;
last_even = (i - 1) % 2 == 0;
if ((i - 1) % 2 == 0)
{
xs[i - 1] = next;
xs[i] = next_1;
}
else
{
xs[i - 1] = next_1;
xs[i] = next;
}
next = 0;
next_1 = 0;
}
if (s[i] == 'L')
{
if (last_even == (i % 2 == 0))
{
xs[last_marked]++;
}
else
{
xs[last_marked + 1]++;
}
}
else
{
if (i % 2 == 0)
{
next++;
}
else
{
next_1++;
}
}
prev = s[i];
}
xs.map!(x => x.to!string).join(" ").writeln;
}
| D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
auto ans = new long[](100_000_000);
foreach (i; 1 .. 500)
foreach (j; 1 .. 500)
foreach (k; 1 .. 500)
{
ans[i * i + j * j + k * k + i * j + j * k + k * i]++;
}
foreach (i; 1 .. N + 1)
{
writeln(ans[i]);
}
}
| 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 r1, c1, r2, c2;
scan(r1, c1, r2, c2);
auto fact = new long[](r2 + c2 + 2);
fact[0] = 1;
foreach (i; 1 .. fact.length)
fact[i] = fact[i - 1] * i % MOD;
auto fact_inv = new long[](fact.length);
foreach (i; 0 .. fact_inv.length)
fact_inv[i] = powmod(fact[i], MOD - 2, MOD);
long combination_mod(long n, long k)
{
if (n < k)
return 1;
return (fact[n] * fact_inv[k] % MOD) * fact_inv[n - k] % MOD;
}
long g(long r, long c)
{
long ans;
foreach (y; 0 .. r + 1)
{
ans = (ans + combination_mod(y + c + 1, y + 1)) % MOD;
}
return ans;
}
writeln((MOD * 2 + g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % MOD);
}
T powmod(T = long)(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;
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp.to!long;
auto fs = new long[](1001);
foreach (long i; 0..1001) fs[i] = i^^5;
foreach (i; 0..1001) {
foreach (j; 0..1001) {
if (fs[i] - fs[j] == X) {
writeln(i, " ", j);
return;
}
if (fs[i] + fs[j] == X) {
writeln(i, " ", -j);
return;
}
if (-fs[i] + fs[j] == X) {
writeln(-i, " ", -j);
return;
}
}
}
} | D |
import std.stdio, std.string, std.conv, std.algorithm, std.math;
void main()
{
while(true)
{
auto inp = readln.split.map!(to!int);
if(!inp[0] && !inp[1] && !inp[2]) break;
real a = inp[0], b = inp[1], c = inp[2];
real r = min(a * a + b * b, b * b + c * c, c * c + a * a).sqrt;
foreach(_; 0 .. readln.chomp.to!int)
{
if(readln.chomp.to!int * 2 > r) "OK".writeln;
else "NA".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;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto dp = new long[][](10 ^^ 5 + 1, 3);
long N = lread();
auto ABC = new long[][](10 ^^ 5 + 1, 3);
foreach (i; 0 .. N)
scan(ABC[i][0], ABC[i][1], ABC[i][2]);
foreach (i; 0 .. N)
{
foreach (j; 0 .. 3)
dp[i + 1][j] = max(dp[i][(j + 1) % 3] + ABC[i][(j + 1) % 3],
dp[i][(j + 2) % 3] + ABC[i][(j + 2) % 3]);
}
writeln(dp[N][0].max(dp[N][1]).max(dp[N][2]));
}
| D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.