code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio, std.algorithm, std.array, std.ascii;
int main() {
char a = scanChar();
if('a'<=a && a<='z') {
writeln("a");
} else {
writeln("A");
}
return 0;
}
char scanChar() {
import std.ascii;
int c = ' ';
while(isWhite(c) && c != -1) {
c = getchar;
}
return cast(char)c;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto K = RD;
writeln(K * (K-1)^^(N-1));
stdout.flush();
debug readln();
}
|
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 s = sread();
long n = s.filter!(c => c == 'x')
.map!(x => 100)
.sum();
writeln(1000 - n);
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.algorithm;
void main() {
auto w = readln.chomp;
int[char] char_count;
foreach (c; w) {
char_count[c]++;
}
if (char_count.values.all!"a % 2 == 0") {
"Yes".writeln;
} else {
"No".writeln;
}
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto ip = readln.split.to!(int[]), A=ip[0], B=ip[1], T=ip[2];
writeln(T/A*B);
}
|
D
|
// import chie template :) {{{
static if (__VERSION__ < 2090) {
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, std.numeric;
} else {
import std;
}
// }}}
// 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(T...)(ref T args) {
foreach (ref arg; args) {
arg = next!(typeof(arg));
}
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
// alias {{{
alias Heap(T, alias less = "a < b") = BinaryHeap!(Array!T, less);
alias MinHeap(T) = Heap!(T, "a > b");
// }}}
// memo {{{
/*
- ある値が見つかるかどうか
<https://dlang.org/phobos/std_algorithm_searching.html#canFind>
canFind(r, value); -> bool
- 条件に一致するやつだけ残す
<https://dlang.org/phobos/std_algorithm_iteration.html#filter>
// 2で割り切れるやつ
filter!"a % 2 == 0"(r); -> Range
- 合計
<https://dlang.org/phobos/std_algorithm_iteration.html#sum>
sum(r);
- 累積和
<https://dlang.org/phobos/std_algorithm_iteration.html#cumulativeFold>
// 今の要素に前の要素を足すタイプの一般的な累積和
// 累積和のrangeが帰ってくる(破壊的変更は行われない)
cumulativeFold!"a + b"(r, 0); -> Range
- rangeをarrayにしたいとき
array(r); -> Array
- 各要素に同じ処理をする
<https://dlang.org/phobos/std_algorithm_iteration.html#map>
// 各要素を2乗
map!"a * a"(r) -> Range
- ユニークなやつだけ残す
<https://dlang.org/phobos/std_algorithm_iteration.html#uniq>
uniq(r) -> Range
- 順列を列挙する
<https://dlang.org/phobos/std_algorithm_iteration.html#permutations>
permutation(r) -> Range
- ある値で埋める
<https://dlang.org/phobos/std_algorithm_mutation.html#fill>
fill(r, val); -> void
- バイナリヒープ
<https://dlang.org/phobos/std_container_binaryheap.html#.BinaryHeap>
// 昇順にするならこう(デフォは降順)
BinaryHeap!(Array!T, "a > b") heap;
heap.insert(val);
heap.front;
heap.removeFront();
- 浮動小数点の少数部の桁数設定
// 12桁
writefln("%.12f", val);
- 浮動小数点の誤差を考慮した比較
<https://dlang.org/phobos/std_math.html#.approxEqual>
approxEqual(1.0, 1.0099); -> true
- 小数点切り上げ
<https://dlang.org/phobos/std_math.html#.ceil>
ceil(123.4); -> 124
- 小数点切り捨て
<https://dlang.org/phobos/std_math.html#.floor>
floor(123.4) -> 123
- 小数点四捨五入
<https://dlang.org/phobos/std_math.html#.round>
round(4.5) -> 5
round(5.4) -> 5
*/
// }}}
void main() {
auto cin = new Scanner;
int x, n;
cin.scan(x, n);
bool[102] c;
foreach (i; 0 .. n) {
c[cin.next!int] = true;
}
int mini;
int len;
foreach (i; x .. 102) {
if (!c[i]) {
mini = i;
len = i - x;
break;
}
}
foreach_reverse (i; 0 .. x + 1) {
if (!c[i]) {
if (len >= x - i) {
mini = i;
}
break;
}
}
writeln(mini);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto n = sread();
// writeln(n);
long sum_n;
foreach (i; 0 .. (n.length))
{
sum_n += n[i] - '0';
}
// writeln(sum_n);
auto tmp = new long[](n.length);
auto long_n = n.to!long();
// writeln(long_n / (10 ^^ ((n.length) - 1)) - 1);
tmp[0] = long_n / (10 ^^ ((n.length) - 1)) - 1;
foreach (i; 1 .. (n.length))
{
tmp[i] = 9;
}
// writeln(tmp);
// writeln(tmp.sum());
writeln(max(sum(tmp), sum_n));
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main(string[] args){
while(1){
int n = to!int(readln.chomp);
if(n == 0) break;
int S = 0;
int Smin = 0;
int Smax = int.min;
int dmax = int.min;
for(int i = 0; i < n; i ++){
S += to!int(readln.chomp);
if(S > Smax) Smax = S;
if(Smax - Smin > dmax) dmax = Smax - Smin;
if(S < Smin) Smin = S, Smax = int.min;
}
writeln(dmax);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int n;
scan(n);
auto a = iota(n).map!(i => readln.chomp.to!int).array;
long ans;
foreach_reverse (i ; 0 .. n) {
if (a[i] > i) {
writeln(-1);
return;
}
if (i == n - 1) {
ans += a[i];
continue;
}
if (a[i] == a[i+1] - 1) {
continue;
}
else if (a[i+1] - a[i] > 1) {
writeln(-1);
return;
}
else {
ans += a[i];
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import 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[][](100 + 1, (10 ^^ 5) * 2 + 1);
long N, W;
scan(N, W);
auto w = new long[](100 + 1);
auto v = new long[](100 + 1);
foreach (i; 0 .. N)
scan(w[i], v[i]);
dp[0][] = long.max / 2;
dp[0][0] = 0;
foreach (n; 0 .. N)
{
dp[n + 1][] = long.max / 2;
foreach (val; 0 .. 10 ^^ 5 + 1)
{
dp[n + 1][val].minAssign(dp[n][val]);
// writeln(v[n]);
dp[n + 1][val + v[n]].minAssign(dp[n][val] + w[n]);
}
}
foreach_reverse (i, val; dp[N])
{
if (val <= W)
{
writeln(i);
return;
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.range;
import std.conv;
void main()
{
auto ip = readln.split.to!(int[]), X = ip[0], A = ip[1], B = ip[2];
if(A >= B) {
writeln("delicious");
} else {
if(B-A > X) {
writeln("dangerous");
} else {
writeln("safe");
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm: canFind;
void main() {
string[] inputs = split(readln());
int a = to!int(inputs[0]);
int b = to!int(inputs[1]);
int c = to!int(inputs[2]);
if(b - a == c - b) "YES".writeln;
else "NO".writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto L = RD;
auto R = RD;
auto d = RD;
long ans;
foreach (i; L..R+1)
{
if (i % d == 0)
++ans;
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
string[] inputs = split(readln());
int A = to!int(inputs[0]);
int B = to!int(inputs[1]);
int C = to!int(inputs[2]);
int D = to!int(inputs[3]);
max(A*B, C*D).writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.math;
import std.random;
import std.range;
import std.algorithm;
import std.functional;
import core.bitop;
import std.bigint;
import std.typecons;
import std.container;
void main()
{
auto input = readln.split.to!(ulong[]);
auto X = input[0], Y = input[1];
int result;
for (ulong cur = X; cur <= Y; cur *= 2)
result++;
result.writeln;
}
|
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 input = readln.split.to!(ulong[]);
immutable r = input[0], d = input[1], x2k = input[2];
ulong x = x2k;
for(ulong i = 0; i < 10; i++) {
x = r * x - d;
writeln(x);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
int main()
{
int a = readln().chomp().to!int();
a = a * a * a;
writeln(a);
return 0;
}
|
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()
{
long n, x, y;
scan(n, x, y);
x--, y--;
auto cost = new long[][](n, n);
foreach (i; iota(n))
{
foreach (j; iota(i + 1, n))
{
cost[i][j] = min(j - i, abs(j - y) + abs(i - x) + 1);
}
}
auto ans = new long[](n);
foreach (i; iota(n))
{
foreach (j; iota(i + 1, n))
{
ans[cost[i][j]]++;
}
}
foreach (e; ans[1 .. $])
{
e.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
|
void main()
{
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], a = tmp[1], b = tmp[2];
string s = readln.chomp;
int pass, oversea;
foreach (c; s)
{
if (c == 'a' && pass < a + b)
{
"Yes".writeln;
++pass;
}
else if (c == 'b' && pass < a + b && oversea < b)
{
"Yes".writeln;
++pass;
++oversea;
}
else
{
"No".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.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto xt = readln.chomp.split.map!(to!int);
writeln(max(xt[0]-xt[1],0));
}
|
D
|
/+ dub.sdl:
name "D"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv, std.math;
// import dcomp.foundation, dcomp.scanner;
int main() {
auto sc = new Scanner(stdin);
int n;
sc.read(n);
int[][] g = new int[][](n);
foreach (i; 0..n-1) {
int a, b;
sc.read(a, b); a--; b--;
g[a] ~= b; g[b] ~= a;
}
int[] dist;
void dfs(int p, int b, int di) {
dist[p] = di;
foreach (d; g[p]) {
if (d == b) continue;
dfs(d, p, di+1);
}
}
int[] dist0 = new int[n]; dist = dist0;
dfs(0, -1, 0);
int[] dist1 = new int[n]; dist = dist1;
dfs(n-1, -1, 0);
auto s0 = iota(n).filter!(i => dist0[i] <= dist1[i]).count;
auto s1 = n - s0;
if (s0 > s1) {
writeln("Fennec");
} else {
writeln("Snuke");
}
return 0;
}
/* IMPORT /Users/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 /Users/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;
}
}
|
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()
{
auto S = aryread!string();
S.map!"a[0]".array().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;
auto A = RD;
auto B = RD;
writeln(min(N * A, B));
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
long d = scan!long, t = scan!long, s = scan!long;
if(t * s >= d) "Yes".writeln;
else "No".writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main() {
for(;;) {
// input
int R, C;
{
auto temp = readln.split;
R = to!int(temp[0]);
C = to!int(temp[1]);
}
if(R == 0 && C == 0) {
break;
}
bool[][] board;
board.length = R;
for(int i=0; i<R; ++i) {
board[i].length = C;
}
for(int i=0; i<R; ++i) {
auto temp = readln.split;
for(int j=0; j<C; ++j) {
board[i][j] = cast(bool) to!int(temp[j]);
}
}
// calc
int ret = 0;
int rowsEnd = 1 << R;
for(int rInt=0; rInt<rowsEnd; ++rInt) {
int val;
for(int i=0; i<C; ++i) {
int temp;
for(int j=0; j<R; ++j) {
bool r = cast(bool) (rInt & (1 << j));
if(r != board[j][i]) {
++temp;
}
}
temp = temp > R - temp ? temp : R - temp;
val += temp;
}
if(ret < val) {
ret = val;
}
}
writeln(ret);
}
}
|
D
|
import std.stdio;
import std.array;
import std.math;
import std.conv;
import std.string;
void main() {
string[] input = split(chomp(readln));
int x = to!int(input[0]);
int y = to!int(input[1]);
writeln((x*y)," ",(x*2 + y*2));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main(){
int[101] counter;
string rc;
int max;
while( 1 ){
rc = readln().chomp();
if( !rc ){ break; }
counter[ to!int( rc ) ]++;
if( max < counter[ to!int( rc ) ] ){
max = counter[ to!int( rc ) ];
}
}
foreach( i,c ; counter ){
if( c == max ){
writeln( i );
}
}
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
import std.algorithm;
struct Item {
int w;
int v;
}
void main()
{
auto buf = readln.split;
int N = buf[0].to!int;
int W = buf[1].to!int;
Item[] items = new Item[N];
foreach (i; 0..N){
buf = readln.split;
items[i].w = buf[0].to!int;
items[i].v = buf[1].to!int;
}
long[] sum_v = new long[W + 1];
foreach (i; 0..N){
int v = items[i].v;
int w = items[i].w;
for (uint j = W; j > 0; j--){
if (j < items[i].w) break;
long sum_i = sum_v[j - w] + v;
if (sum_i > sum_v[j]) sum_v[j] = sum_i;
}
}
writeln(sum_v[W]);
}
|
D
|
import std.string,
std.stdio,
std.conv;
void main(){
while(true){
string s = readln.chomp;
if (s == "-") break;
int n = readln.chomp.to!int;
ulong sx=0;
foreach(i;0..n){
sx+=readln.chomp.to!int;
}
sx = sx % s.length;
writeln(s[sx..$] ~ s[0..sx]);
}
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
static import std.ascii;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){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();
long N = S.length;
long X, Y;
scan(X, Y);
auto ls = new long[][](2, 1);
{
long s;
foreach (i; 0 .. N)
{
if (S[i] == 'T')
{
ls[s] ~= 0;
s = s ^ 1;
}
if (S[i] == 'F')
{
ls[s][$ - 1]++;
}
}
}
{
bool[long] D;
D[ls[0][0]] = true;
foreach (j; ls[0][1 .. $])
{
bool[long] D2;
foreach (k; D.byKey)
{
D2[k + j] = D2[k - j] = true;
}
D = D2;
}
if (X !in D)
{
writeln("No");
return;
}
}
{
bool[long] D;
D[0] = true;
foreach (j; ls[1])
{
bool[long] D2;
foreach (k; D.byKey)
{
D2[k + j] = D2[k - j] = true;
}
D = D2;
}
if (Y !in D)
{
writeln("No");
return;
}
}
writeln("Yes");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
int cnt;
foreach (i; 0..s.length/2) {
if (s[i] != s[$-i-1]) {
cnt++;
}
}
cnt.writeln;
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
string s;
while ((s = readln.strip) != "")
{
bool have0 = false;
bool have1 = false;
foreach (ref c; s)
{
if (c == '0')
{
writeln (have0 ? 1 : 3, " ", 1);
have0 ^= true;
}
else
{
writeln (1, " ", have1 ? 1 : 3);
have1 ^= true;
}
}
}
}
|
D
|
void main()
{
long n = rdElem;
string s = rdStr;
long result;
foreach (i; 0 .. n)
{
long[] z_arr = s[i..$].z;
foreach (j; 0 .. n-i)
{
if (j >= z_arr[j]) result = max(result, z_arr[j]);
}
}
result.writeln;
}
long[] z(string s)
{
long len = s.length;
long[] result = new long[len];
result[0] = len;
long i = 1, j;
while (i < len)
{
while (i + j < len && s[j] == s[i+j]) ++j;
result[i] = j;
if (j == 0)
{
++i;
continue;
}
long k = 1;
while (i + k < len && k + result[k] < j)
{
result[i+k] = result[k];
++k;
}
i += k;
j -= k;
}
return result;
}
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
|
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 bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");
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()
{
auto s = sread();
auto t = sread();
auto dif = max(s.length - t.length, 0);
foreach_reverse (i; 0 .. dif + 1)
{
auto parts = s[i .. t.length + i];
if (parts.is_match(t))
{
ans_write(s, t, i);
return;
}
}
writeln("UNRESTORABLE");
}
bool is_match(T)(T a, T b)
{
foreach (i, e; a)
{
if (!(e == b[i] || e == '?'))
return false;
}
return true;
}
void ans_write(string s, string t, long p)
{
auto s_before = s[0 .. p];
auto s_after = s[p + t.length .. $];
foreach (e; s_before ~ t ~ s_after)
{
if(e == '?')
write('a');
else
e.write();
}
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()
{
writeln(-lread() + (2 * lread));
}
|
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;
void main()
{
long N = scanElem;
string S = readln.strip;
long K = scanElem;
foreach(c; S)
{
if(S[K-1]==c)write(c);else write('*');
}
writeln("");
}
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
|
// 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() {
long n, k;
scan(n, k);
long x = n / k;
writeln(x & 1 ? "YES" : "NO");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
alias Pair = Tuple!(int, "a", int, "b");
void main() {
readln;
readln.chomp.group.count.writeln;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.algorithm, 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 s; readV(s);
auto b = new bool[](1000001);
b[s] = true;
foreach (i; 2..1000002) {
s = s%2 == 0 ? s/2 : s*3+1;
if (b[s]) {
writeln(i);
return;
}
b[s] = true;
}
}
|
D
|
import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;
import core.stdc.string;
char[] A;
char[] B;
class Arr{
int as,bs,cs,ds;
void Set(int a,int b,int c,int d){
as = a;
bs = b;
cs = c;
ds = d;
data = new int[a*b*c*d];
}
this(){
Set(500,10,2,3);
}
int[] data;
ref int opIndex(int a,int b,int c,int d){
return data[(((a)*bs+b)*cs+c)*ds+d];
}
void Clear(){
data[] = 0;
}
}
Arr now;
Arr next;
static immutable modBase = 10000;
void Minus(char[] d,int idx){
if(d[idx] == 0){
d[idx] = 9;
d.Minus(idx-1);
}else{
d[idx]--;
}
}
int Count(char[] d,int m,bool minus){
int len = cast(int)strlen(d.ptr);
for(int i=0;i<len;i++){
d[i] -= '0';
}
if(minus)
d[0..len].Minus(len-1);
now.Clear;
int md=1;
int res=0;
foreach_reverse(_,c;d[0..len]){
next.Clear;
for(int i=0;i<m;i++){
for(int j=0;j<10;j++){
if(_ == len-1){
if(i==0){
next[j%m,j,j<=c?0:1,2] = 1;
}
}else{
for(int k=0;k<10;k++){
if(j==k) continue;
int t = 0;
int s = 1;
if(j > k) swap(s,t);
if(j<c){
next[(i+md*j)%m,j,0,t] += now[i,k,0,s] + now[i,k,1,s] + now[i,k,0,2] + now[i,k,1,2];
next[(i+md*j)%m,j,0,t] %= modBase;
}else if(j==c){
next[(i+md*j)%m,j,0,t] += now[i,k,0,s] + now[i,k,0,2];
next[(i+md*j)%m,j,1,t] += now[i,k,1,s] + now[i,k,1,2];
next[(i+md*j)%m,j,0,t] %= modBase;
next[(i+md*j)%m,j,1,t] %= modBase;
}else{
next[(i+md*j)%m,j,1,t] += now[i,k,0,s] + now[i,k,1,s] + now[i,k,0,2] + now[i,k,1,2];
next[(i+md*j)%m,j,1,t] %= modBase;
}
}
}
}
}
swap(now,next);
for(int i=1;i<10;i++){
res += now[0,i,0,0] + now[0,i,0,1] + now[0,i,0,2];
if(_>0)
res += now[0,i,1,0] + now[0,i,1,1] + now[0,i,1,2];
res %= modBase;
}
md *= 10;
md %= m;
}
return res;
}
void main(){
A = new char[514];
B = new char[514];
scanf("%s",A.ptr);
scanf("%s",B.ptr);
int m;
scanf("%d",&m);
now = new Arr;
next = new Arr;
int ac = A.Count(m,true);
int bc = B.Count(m,false);
printf("%d\n",(bc+modBase-ac)%modBase);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.math;
void main() {
int N = to!int(chomp(readln()));
int A = to!int(chomp(readln()));
writeln(pow(N, 2) - A);
}
|
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 = sread();
foreach (i; 0 .. S.length)
{
if (S[i .. $] ~ S[0 .. i] == T)
{
writeln("Yes");
return;
}
}
writeln("No");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b, k; readV(a, b, k);
foreach_reverse (i; 1..101) {
if (a%i == 0 && b%i == 0) {
--k;
if (k == 0) {
writeln(i);
return;
}
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
void main() {
string s = readln.chomp;
string t = readln.chomp;
int cnt;
foreach (i; 0 .. 3) {
if (s[i] == t[i]) ++cnt;
}
cnt.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;
import std.datetime, std.bigint;
int n, a, b;
int[] x, y;
void main() {
scan(n, a, b);
x = new int[](n);
y = new int[](n);
foreach (i ; 0 .. n) {
scan(x[i], y[i]);
}
bool check(int U, int V, int u, int v) {
return (u <= U && v <= V) || (u <= V && v <= U);
}
int ans;
foreach (i ; 0 .. n) {
foreach (j ; 0 .. n) {
if (i == j) continue;
if (x[i] <= a && y[i] <= b) {
if (check(a - x[i], b, x[j], y[j]) || check(a, b - y[i], x[j], y[j])) {
ans = max(ans, x[i]*y[i] + x[j]*y[j]);
}
}
if (x[i] <= b && y[i] <= a) {
if (check(a - y[i], b, x[j], y[j]) || check(a, b - x[i], x[j], y[j])) {
ans = max(ans, x[i]*y[i] + x[j]*y[j]);
}
}
}
}
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(){
import std.stdio, std.string, std.conv, std.algorithm;
long n, m, a, b; rd(n, m, a, b);
long x=(((n+m-1)/m)*m-n)*a;
long y=(n-(n/m)*m)*b;
writeln(min(x, y));
}
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;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.typecons;
import std.variant;
void main() {
long tt = readln().chomp.to!long;
foreach (t; 0 .. tt) {
readln();
long[] piles = readln().chomp.split(" ").map!(to!long).array;
bool winner = true;
bool didBreak = false;
foreach (i; piles) {
if (i == 1) {
winner = !winner;
}
else {
didBreak = true;
break;
}
}
if (!didBreak) {
winner = !winner;
}
writeln(winner ? "First" : "Second");
}
}
|
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 long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto x = RD!int;
auto m = RD!int;
int ll = x, rr = x;
foreach (i; 0..m)
{
auto l = RD!int;
auto r = RD!int;
if (l <= rr && r >= ll)
{
ll.chmin(l);
rr.chmax(r);
}
}
ans[ti] = rr-ll+1;
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
void main() {
auto N = readln.chomp.to!int;
auto S = readln.chomp;
auto used = new bool[](N);
for (int i = 0, j = 0, t = 0, rest = N; rest > 11; t ^= 1, --rest) {
if (t == 0) {
while (i < N && (used[i] || S[i] == '8')) ++i;
if (i >= N) {
writeln("YES");
return;
}
used[i] = true;
} else {
while (j < N && (used[j] || S[j] != '8')) ++j;
if (j >= N) {
writeln("NO");
return;
}
used[j] = true;
}
}
foreach (i; 0..N) {
if (!used[i]) {
writeln(S[i] == '8' ? "YES" : "NO");
return;
}
}
}
|
D
|
module main;
import std.stdio;
import std.algorithm;
import std.array;
ulong pow(ulong a, ulong b){
if (b == 0)
return 1;
ulong ans = a;
for (ulong i = 2; i<=b; ++i)
ans *= a;
return ans;
}
int main(string[] argv)
{
ulong l;
ulong r;
scanf("%d %d", &l, &r);
ulong ans = 0;
for (ulong i = 0; i <= 32; ++i){
for (ulong j = 0; j <= 21; ++j){
if (pow(2, i) * pow(3, j) >= l && pow(2, i) * pow(3, j) <= r)
++ans;
}
}
printf("%d", ans);
return 0;
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
auto s=readln.chomp.to!(char[]);
auto t="abcdefghijklmnopqrstuvwxyz".to!(char[]);
if(s.length<t.length){writeln(-1); return;}
int cnt=0;
for(int i=0, j=0; i<t.length.to!(int); i++, j++){
if(cnt==t.length.to!(int)) break;
while(j<s.length.to!(int)){
if(s[j]<=t[i]){s[j]=t[i]; cnt++; break;}
else j++;
}
}
if(cnt<t.length.to!(int)) writeln(-1);
else writeln(s);
}
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.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;
bool solve() {
auto L = new int[](4);
auto S = new int[](4);
auto R = new int[](4);
auto P = new int[](4);
foreach (i; 0..4) {
auto s = readln.split.map!(to!int);
L[i] = s[0];
S[i] = s[1];
R[i] = s[2];
P[i] = s[3];
}
foreach (i; 0..4) {
if (L[i] && P[i]) return true;
if (S[i] && P[i]) return true;
if (R[i] && P[i]) return true;
}
foreach (i; 0..4) {
if (L[i] && P[(i+3)%4]) return true;
}
foreach (i; 0..4) {
if (S[i] && P[(i+2)%4]) return true;
}
foreach (i; 0..4) {
if (R[i] && P[(i+1)%4]) return true;
}
return false;
}
void main() {
writeln( solve ? "YES" : "NO" );
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
auto f = false;
foreach (i; 0..s.length-1) {
if (s[i] == 'A' && s[i+1] == 'C') {
f = true;
break;
}
}
if (f) writeln("Yes");
else writeln("No");
}
|
D
|
import std.stdio;
import std.algorithm;
import std.typecons : tuple, Tuple;
import std.container.rbtree;
int n;
long s;
int[] l;
int[] r;
bool can(long m) {
int cnt = 0;
int other = n;
long sum = 0;
for(int i = 0; i < n; ++i) {
if (m < l[i]) {
++cnt;
sum += l[i];
--other;
} else if (r[i] < m) {
sum += l[i];
--other;
}
}
if (cnt + other < (n + 1) / 2) {
return false;
}
int[] ls = new int[other];
int ptr = 0;
for(int i = 0; i < n; ++i) {
if (l[i] <= m && m <= r[i]) {
ls[ptr] = l[i];
++ptr;
}
}
sort(ls);
for(int i = other - 1; i >= 0; --i) {
if (i >= other - ((n+1)/2 - cnt)) {
sum += m;
} else {
sum += ls[i];
}
}
return sum <= s;
}
int main() {
int t;
scanf("%d", &t);
while (t --> 0) {
scanf("%d%lld", &n, &s);
l = new int[n];
r = new int[n];
for(int i = 0; i < n; ++i) {
scanf("%d%d", &l[i], &r[i]);
}
long tl = 0, tr = s + 1;
while (tl+1 < tr) {
long tm = (tl+tr) / 2;
if (can(tm)) {
tl = tm;
} else {
tr = tm;
}
}
printf("%lld\n", tl);
}
return 0;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
import std.math;
void main(string[] args)
{
auto n = split(strip(readln));
auto a = to!long(n[0]);
auto b = to!long(n[1]);
long count;
if (a == 1 && b == 1)
{
writeln(0);
return;
}
while(a >= 1 && b >= 1)
{
if (a < b)
{
a++;
b -= 2;
}
else
{
b++;
a -= 2;
}
count++;
// writeln(a, "\t", b);
}
writeln(count);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.regex;
import std.range;
void main() {
auto A = readln.chomp.to!int, B = readln.chomp.to!int, C = readln.chomp.to!int, X = readln.chomp.to!int;
int count;
foreach(i; 0..A+1) {
foreach(j; 0..B+1) {
foreach(k; 0..C+1) {
if(500*i + 100*j + 50*k == X) count++;
}
}
}
count.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 k, n; readV(k, n);
auto ans = new int[](n), s = n;
if (k%2 == 0) {
ans[0] = k/2;
ans[1..$][] = k;
} else {
ans[] = (k+1)/2;
foreach (i; 0..n/2) {
if (ans[s-1] == 1) {
--s;
} else {
ans[s-1]--;
ans[s..n][] = k;
s = n;
}
}
}
foreach (i; 0..s) {
write(ans[i]);
if (i < s-1) write(" ");
}
writeln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
auto S = sread();
long ans;
foreach (c; S)
ans += c == '1';
writeln(ans);
}
|
D
|
import std.stdio, std.string, std.conv;
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], p= tmp[1];
writeln((3 * a + p) / 2);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
immutable long MOD = 10^^9 + 7;
void main() {
auto N = readln.chomp.to!long;
auto S = readln.chomp;
auto cnt = new long[](26);
foreach (i; 0..N) {
cnt[S[i] - 'a'] += 1;
}
long ans = 0;
foreach (i; 0..N) {
long tmp = 1;
foreach (j; 0..26) if (cnt[j] && j != S[i] - 'a') tmp = tmp * (cnt[j] + 1) % MOD;
ans += tmp;
ans %= MOD;
cnt[S[i] - 'a'] -= 1;
}
ans = (ans + MOD) % MOD;
ans.writeln;
}
long powmod(long a, long x, long m) {
long ret = 1;
while (x) {
if (x % 2) ret = ret * a % m;
a = a * a % m;
x /= 2;
}
return ret;
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N, K;
scan(N, K);
K = min(K, N - 1);
long ans;
auto mc = ModComb(N);
foreach (i ; 0 .. K + 1) {
debug {
//writeln(mc.c(N, i) * mc.c(N - 1, i));
}
ans += mc.c(N, i) * mc.c(N - 1, i) % mod;
ans %= mod;
}
writeln(ans);
}
struct ModComb {
int _N;
long[] _fact, _factinv;
long _mod;
this(int n, long mod = 1_000_000_007L) {
_N = n;
_fact = new long[](_N + 1);
_factinv = new long[](_N + 1);
_mod = mod;
_fact[0] = 1;
foreach (i ; 1 .. _N + 1) {
_fact[i] = (_fact[i-1] * i) % mod;
}
_factinv[_N] = _powmod(_fact[_N], mod - 2);
foreach_reverse (i ; 0 .. _N) {
_factinv[i] = (_factinv[i+1] * (i+1)) % mod;
}
}
long c(int n, int k) {
if (k < 0 || k > n) return 0;
return f(n) * finv(n - k) % _mod * finv(k) % _mod;
}
long p(int n, int r) {
if (r < 0 || r > n) return 0;
return f(n) * finv(n - r) % _mod;
}
long f(int n) {
return _fact[n];
}
long finv(int n) {
return _factinv[n];
}
long _powmod(long x, long y) {
return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
}
}
unittest {
auto mc = ModComb(1_000_000);
assert(mc.c(5, 2) == 10);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
writeln(readln.chomp == "0" ? 1 : 0);
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format, 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 N, M;
scan(N, M);
writeln(N * (N - 1) / 2 + M * (M - 1) / 2);
}
|
D
|
void main(){
//auto NM = readLine!long();
if( readStr() == "ABC" ){
writeln("ARC");
} else {
writeln("ABC");
}
}
import std;
string readStr(){
return readln().chomp();
}
T[] readLine( T = long )(){
return readln().split().to!(T[])();
}
|
D
|
import std.stdio,std.string,std.conv,std.array,std.algorithm;
void main(){
string[] arr;
readln();
for(;;){
auto rc = readln().chomp();
if(!rc){ break; }
arr ~= rc;
}
sort( arr );
writeln( arr[0] );
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
void main() {
while(true) {
string[] cin;
cin=split(readln());
int n=to!int(cin[0]),a=to!int(cin[1]),b=to!int(cin[2]),c=to!int(cin[3]),x=to!int(cin[4]);
if(!(n||a||b||c||x)) break;
int[] z=new int[n];
cin=split(readln());
for(int i=0; i<n; i++) z[i]=to!int(cin[i]);
int d=0,cnt=0;
for(int i=0; i<=10000; i++) {
if(z[d]==x) d++;
if(d==n) break;
x=(a*x+b)%c;
cnt++;
}
if(d==n) writeln(cnt);
else writeln(-1);
}
}
|
D
|
import std.conv;
import std.stdio;
import std.string;
void main()
{
auto n = readln.strip.to!( int );
writeln( solve( n ) );
}
auto solve( in int n )
{
return n + n * ( n % 2 );
}
|
D
|
import std.stdio;
import std.array;
import std.conv;
void main(){
string[] input = split(readln());
int a = to!int(input[0]);
writeln(a*a*a);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main()
{
auto S = split(readln())[0];
//if (S == "zyxwvutsrqponmlkjihgfedcba") { writeln("-1"); return; }
if (S.length < 26) { writeln(solve1(S)); }
else { writeln(solve2(S)); }
}
string solve1(string S) {
bool[26] list;
foreach (c; S) list[c-'a'] = true;
foreach (i, f; list) {
if (!f) { return S ~ ( to!char('a'+i) ); }
}
return "-1";
}
string solve2(string S) {
int index = 25;
while (index >= 0) {
foreach ( c; S[index] + 1 .. 'z'+1 ) {
if (S[index+1..$].find(to!char(c)).length!=0) return S[0..index] ~ to!char(c);
}
--index;
}
return "-1";
}
|
D
|
import std.stdio: readln, writeln;
import std.string: chomp;
import std.conv: to;
void main() {
int n = readln.chomp.to!int;
writeln(n/2 + n%2);
}
|
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 Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long n, m;
scan(n, m);
auto a = 100 * (n - m) + 1900 * m;
writeln(a * 2 ^^ m);
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional;
char[54][54] NS;
char[54][54] MS;
void main()
{
auto nm = readln.split.to!(int[]);
auto n = nm[0];
auto m = nm[1];
foreach (i; 0..n) {
auto line = readln;
foreach (j, c; line)
NS[i][j] = c;
}
foreach (i; 0..m) {
auto line = readln;
foreach (j, c; line)
MS[i][j] = c;
}
foreach (i; 0..n-m+1) {
foreach (j; 0..n-m+1) {
bool check() {
foreach (ii; 0..m) {
foreach (jj; 0..m) {
if (NS[i+ii][j+jj] != MS[ii][jj]) return false;
}
}
return true;
}
if (check()) {
writeln("Yes");
return;
}
}
}
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.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto K = RD;
auto S = RD!string;
long[] cnts;
long cnt;
char last = S[0];
foreach (c; S)
{
if (c != last)
{
cnts ~= cnt;
cnt = 1;
last = c;
}
else
{
++cnt;
}
}
cnts ~= cnt;
long eo = S[0] == '0' ? 0 : 1;
long len = cnts.length / 2;
len += eo == 0 ? cnts.length % 2 : 0;
auto dp = new long[](max(1, len-K+1));
dp[0] = eo == 1 ? cnts[0] : 0;
foreach (i; 0..K)
{
auto j = i * 2 + eo;
if (j < cnts.length)
dp[0] += cnts[j];
if (j+1 < cnts.length)
dp[0] += cnts[j+1];
}
long ans = dp[0];
foreach (i; 1..dp.length)
{
dp[i] = dp[i-1];
auto j = (i-1) * 2 + eo;
dp[i] -= cnts[j];
if (j >= 1)
dp[i] -= cnts[j-1];
auto k = (i+K-1) * 2 + eo;
if (k < cnts.length)
dp[i] += cnts[k];
if (k+1 < cnts.length)
dp[i] += cnts[k+1];
ans = max(ans, dp[i]);
}
debug writeln(cnts);
debug writeln(dp);
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD!string;
long sn;
foreach (c; N)
{
sn += [c].to!long;
}
writeln(N.to!long % sn == 0 ? "Yes" : "No");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
long floor_sum(long n, long m, long a, long b)
{
long ans;
if (a >= m) ans += (n-1)*n*(a/m)/2; a %= m;
if (b >= m) ans += n*(b/m); b %= m;
long y_max = (a*n+b)/m, x_max = (y_max*m - b);
if (y_max == 0) return ans;
ans += (n-(x_max+a-1)/a)*y_max;
ans += floor_sum(y_max, a, m, (a - x_max%a)%a);
return ans;
}
void main()
{
auto T = RD;
foreach (i; 0..T)
{
auto N = RD;
auto M = RD;
auto A = RD;
auto B = RD;
writeln(floor_sum(N, M, A, B));
}
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
void main() {
string s = readln.chomp;
foreach(c;s) write("x");
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;
void main()
{
auto s = readln.chomp.array;
foreach (i;iota(0, s.length, 2)) write(s[i]);
writeln("");
}
|
D
|
void main() {
int n = readln.chomp.to!int;
bool ok;
foreach (i; 0 .. 26) {
foreach (j; 0 .. 15) {
if (4 * i + 7 * j == n) ok = true;
}
}
writeln(ok ? "Yes" : "No");
}
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
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp.to!(wchar[]);
int cost;
foreach_reverse (c; S[1..$]) {
if (c == 'E') ++cost;
}
auto min_cost = cost;
for (int p = 1; p < N; ++p) {
if (S[p] == 'E') --cost;
if (S[p-1] == 'W') ++cost;
min_cost = min(cost, min_cost);
}
writeln(min_cost);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
string a;
string b;
string c;
scan(a, b, c);
// writeln(a[$ - 1]);
if ((a[$ - 1] == b[0]) && (b[$ - 1] == c[0]))
{
writeln("YES");
return;
}
writeln("NO");
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main()
{
auto a = to!long( split(readln())[0] ) ;
writeln(a/3);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n;
scan(n);
string a, b, c;
scan(a);
scan(b);
scan(c);
int ans;
foreach (i ; 0 .. n) {
if (a[i] == b[i] && b[i] == c[i]) {
}
else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
ans++;
}
else {
ans += 2;
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main() {
auto n = readln.chomp.to!int;
auto s = readln.chomp.split.map!(to!int).array;
auto q = readln.chomp.to!int;
auto t = readln.chomp.split.map!(to!int).array;
auto c = 0;
foreach (e_t; t) {
foreach (e_s; s) {
if (e_t == e_s) {
c++;
break;
}
}
}
c.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
immutable limitList = 100000;
void main() {
int input;
bool[] listNumbers = new bool[](limitList);
int[] listPrimeNumbers; //List of prime numbers.
listNumbers.fill(true);
listNumbers[0..2] = false;
foreach (i; 2..limitList.to!double.sqrt.to!int) {
if (listNumbers[i]) {
for (int j = i*2; j < limitList; j += i) listNumbers[j] = false;
}
}
while ((input = readln.chomp.to!int) != 0) {
uint count = 0;
foreach (i; 0..(input/2)+1) {
if(listNumbers[i] && listNumbers[input-i]) count++;
}
writeln(count);
}
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm, std.range;
void main() {
auto input = readln.split.to!(int[]);
auto A = input[0];
auto B = input[1];
auto N = 1;
auto count=0;
while(N < B) {
N--;
N+=A;
count++;
}
count.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto s = readln.chomp;
auto cnt = 0;
char last = s[0];
foreach (c; s[1..$]) {
if (c != last) {
++cnt;
last = c;
}
}
writeln(cnt);
}
|
D
|
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to
void main()
{
string n = chomp(readln());
string m = chomp(readln());
if(n[0] == m[2] && n[1] == m[1] && n[2] == m[0]){
writeln("YES");
} else {
writeln("NO");
}
}
|
D
|
import std.stdio,
std.string,
std.conv,
std.algorithm;
void main() {
int[] buf = readln.chomp.split.to!(int[]);
int a = buf[0], b = buf[1], x = buf[2];
if (a == x || a < x && a + b >= x) {
writeln("YES");
}
else {
writeln("NO");
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int n, k;
scan(n, k);
writeln(1 + (n - k + k - 2) / (k - 1));
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
int[3][3] CS;
void main()
{
foreach (i; 0..3)
CS[i][] = readln.split.to!(int[])[];
foreach (a1; 0..201) {
if (a1 > CS[0][0] || a1 > CS[0][1] || a1 > CS[0][2]) continue;
auto b1 = CS[0][0] - a1;
if (b1 > CS[1][0] || b1 > CS[2][0]) continue;
auto a2 = CS[1][0] - b1;
auto a3 = CS[2][0] - b1;
auto b2 = CS[0][1] - a1;
if (a2 + b2 != CS[1][1] || a3 + b2 != CS[2][1]) continue;
auto b3 = CS[0][2] - a1;
if (a2 + b3 != CS[1][2] || a3 + b3 != CS[2][2]) continue;
writeln("Yes");
return;
}
writeln("No");
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
long n = read.to!long;
long best = 1_000_000_999;
long[] ms = [1, 10, 100, 1_000, 10_000, 100_000, 1_000_000];
foreach(i; 1 .. n){
long a = i;
long b = n - a;
long x;
while(a > 0 || b > 0){
x += a % 10, a /= 10;
x += b % 10, b /= 10;
}
best = min(best, x);
}
best.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main(){
auto N = readln.chomp.to!int;
writeln(N*(N+1)/2);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto abcd = readln.split.to!(int[]);
auto a = abcd[0];
auto b = abcd[1];
auto c = abcd[2];
auto d = abcd[3];
if (b <= c || d <= a) {
writeln(0);
} else if (a <= c) {
writeln(b < d ? b - c : d - c);
} else {
writeln(b < d ? b - a : d - a);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
long N;
scan(N);
auto ans = N^^3;
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
|
void main()
{
long[] tmp = readln.split.to!(long[]);
long n = tmp[0], m = tmp[1];
long scc = min(n, m/2);
scc += (m - 2 * scc) / 4;
scc.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b, c; readV(a, b, c);
writeln(min(a+b, b+c, c+a));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.array;
import std.range;
import std.regex;
void main(){
auto a=readln.chomp.to!int;
if(a<1200)writeln("ABC");
else if(a>=1200&&a<2800)writeln("ARC");
else writeln("AGC");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
foreach (line; stdin.byLine) {
auto str = line.chomp;
if (str.length == 1) break;
auto aScore = str[1..str.length].count!(a => a == 'A');
auto bScore = str[1..str.length].count!(a => a == 'B');
if (aScore > bScore) aScore++;
else bScore++;
writeln(aScore, " ", bScore);
}
}
|
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;
import std.numeric;
import std.bigint;
import core.checkedint;
void main()
{
for (;;) {
int n = readln.chomp.to!int;
if (n == 0) {
break;
}
char[char] dic;
foreach (i; 0..n) {
auto raw = readln.chomp;
dic[raw[0]] = raw[2];
}
int m = readln.chomp.to!int;
foreach (i; 0..m) {
auto c = readln[0];
if (c in dic) {
dic[c].write;
} else {
c.write;
}
}
writeln;
}
}
void tie(R, Args...)(R arr, ref Args args)
if (isRandomAccessRange!R || isArray!R)
in
{
assert (arr.length == args.length);
}
body
{
foreach (i, ref v; args) {
alias T = typeof(v);
v = arr[i].to!T;
}
}
void verbose(Args...)(in Args args)
{
stderr.write("[");
foreach (i, ref v; args) {
if (i) stderr.write(", ");
stderr.write(v);
}
stderr.writeln("]");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm.searching;
void main(){
auto str = readln.chomp;
if(str.canFind("a") && str.canFind("b") && str.canFind("c")){
"Yes".writeln;
}else{
"No".writeln;
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.