code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
void main() {
string s = readln.chomp;
writeln(2 * min(s.count('0'), s.count('1')));
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math, std.typecons;
void main() {
int n; scan(n);
auto ban = new int[][](1010, 1010);
foreach (i ; 0 .. n) {
int x1, y1, x2, y2;
scan(x1, y1, x2, y2);
ban[x1][y1]++;
ban[x1][y2]--;
ban[x2][y1]--;
ban[x2][y2]++;
}
foreach (x ; 0 .. 1010) {
foreach (y ; 0 .. 1009) {
ban[x][y+1] += ban[x][y];
}
}
foreach (y ; 0 .. 1010) {
foreach (x ; 0 .. 1009) {
ban[x+1][y] += ban[x][y];
}
}
int ans;
foreach (x ; 0 .. 1010) {
foreach (y ; 0 .. 1010) {
ans = max(ans, ban[x][y]);
}
}
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.stdio;
import std.string;
import std.conv;
int main()
{
int n = readln().chomp().to!int();
while (n--) {
int times = 3;
int Hit = 0;
int result = 0;
while (times) {
string str = readln().chomp();
if (str == "HIT") {
if (Hit == 3) result++;
else Hit++;
} else if (str == "OUT") {
times--;
} else {
result += (Hit + 1);
Hit = 0;
}
}
writeln(result);
}
return 0;
}
|
D
|
void main() {
auto S = rs;
if(S == "ABC") {
writeln("ARC");
} else writeln("ABC");
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
string[] ss = readln.split;
foreach (i, ref arg ; args) arg = ss[i].parse!int;
}
void main() {
int m, d; scan(m,d);
int ans;
foreach (i; 1..m+1) {
foreach (j; 1..d+1) {
int d1 = j%10, d2 = (j/10) % 10;
if (d1>=2 && d2>=2 && d1*d2 == i) ans++;
}
}
writeln(ans);
}
|
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;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!int).array;
int ans = 0;
for (int i = 0; i < N; i++) {
if (A[i] == i + 1) {
ans += 1;
i += 1;
}
}
ans.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;
struct Deque(T) {
private {
int N, head, tail;
T[] deq;
}
this(int n) {
N = n + 1;
deq = new T[](N + 1);
}
bool empty() {
return head == tail;
}
bool full() {
return head == ((tail + 1) % N);
}
int length() {
return (tail - head + N) % N;
}
T front() {
assert(!empty);
return deq[head];
}
T back() {
assert(!empty);
return deq[(tail - 1 + N) % N];
}
void pushFront(T x) {
assert(!full);
head = (head - 1 + N) % N;
deq[head] = x;
}
void pushBack(T x) {
assert(!full);
deq[tail++] = x;
tail %= N;
}
void popFront() {
assert(!empty);
head = (head + 1) % N;
}
void popBack() {
assert(!empty);
tail = (tail - 1 + N) % N;
}
alias insert = pushBack;
alias removeFront = popFront;
alias removeBack = popBack;
T opIndex(size_t index)
in {
assert(0 <= index && index < length);
}
body {
return deq[(head + index) % N];
}
alias opDollar = length;
}
unittest {
import std.stdio;
auto q = Deque!(int)(8);
q.insert(3);
q.insert(1);
q.insert(4);
q.insert(1);
assert(q[3] == 1);
assert(q[0] == 3);
q.removeFront;
q.removeFront;
// q = [4, 1]
q.insert(8);
q.pushFront(7);
q.insert(11);
q.pushFront(0);
// q = [0, 7, 4, 1, 8, 11]
assert(q[0] == 0);
assert(q[1] == 7);
assert(q[4] == 8);
assert(q[$-1] == 11);
}
unittest {
import std.stdio;
int n = 5;
auto deq = Deque!(int)(n);
deq.pushFront(3);
deq.pushBack(1);
deq.pushBack(4);
deq.pushFront(5);
assert(deq.front == 5);
assert(deq.back == 4);
assert(deq.length == 4);
deq.pushFront(0);
assert(deq.full);
assert(deq.front == 0);
assert(deq.length == 5);
deq.popFront();
deq.popFront();
deq.popBack();
assert(deq.front == 3);
assert(deq.back == 1);
assert(deq.length == 2);
deq.popBack();
deq.popFront();
assert(deq.empty);
assert(deq.length == 0);
}
void main() {
string s;
scan(s);
auto deq = Deque!(char)(4 * 10^^5);
foreach (ch ; s) {
deq.pushBack(ch);
}
int Q;
scan(Q);
bool rev;
foreach (_ ; 0 .. Q) {
auto ln = readln.split;
if (ln.front == "1") {
rev ^= 1;
}
else {
auto f = ln[1].to!int;
auto c = ln[2].to!char;
f--;
if ((f ^ rev) == 0) {
deq.pushFront(c);
}
else {
deq.pushBack(c);
}
}
}
string ans;
if (!rev) {
while (!deq.empty) {
ans ~= deq.front;
deq.removeFront();
}
}
else {
while (!deq.empty) {
ans ~= deq.back;
deq.removeBack();
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
string input = chomp(readln());
switch(input) {
case "a", "i", "u", "e", "o":
"vowel".writeln;
break;
default:
"consonant".writeln;
break;
}
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
void main()
{
auto x = readln.chomp.to!int;
writeln(x^^3);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
auto n = lread();
auto a = aryread();
long x = 3 ^^ n;
long y = 1;
foreach (i; 0 .. n)
{
if (a[i] % 2 == 0)
{
y *= 2;
}
}
writeln(x - y);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main() {
auto n = readln.chomp.to!uint;
writeln((n + 1) / 2);
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
// 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!(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 n, m;
cin.scan(n, m);
writeln((1900 * m + 100 * (n - m)) * 2 ^^ m);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(size_t[]), n = rd[0], m = rd[1];
auto a = new string[](n), b = new string[](m);
foreach (i; 0..n) a[i] = readln.chomp;
foreach (i; 0..m) b[i] = readln.chomp;
auto isSame(size_t i, size_t j)
{
foreach (k; 0..m)
if (a[i+k][j..j+m] != b[k]) return false;
return true;
}
foreach (i; 0..n-m+1)
foreach (j; 0..n-m+1)
if (isSame(i, j)) {
writeln("Yes");
return;
}
writeln("No");
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
bool chmin(T)(ref T a, T b) {
if (b < a) {
a = b;
return true;
} else {
return false;
}
}
void main() {
int N = readln.chomp.to!int;
string S = readln.chomp;
int[][] dp = new int[][](2, N);
foreach (i, ch; S) {
if (ch == 'W') {
if (i > 0) {
dp[0][i] = dp[0][i - 1] + 1;
} else {
dp[0][i] = 1;
}
} else {
if (i > 0) {
dp[0][i] = dp[0][i - 1];
} else {
dp[0][i] = 0;
}
}
}
foreach_reverse (i, ch; S) {
if (ch == 'E') {
if (i < N - 1) {
dp[1][i] = dp[1][i + 1] + 1;
} else {
dp[1][i] = 1;
}
} else {
if (i < N - 1) {
dp[1][i] = dp[1][i + 1];
} else {
dp[1][i] = 0;
}
}
}
int[] ans = new int[](N);
foreach (i; 0..N) {
ans[i] = dp[0][i] + dp[1][i];
}
int min = int.max;
foreach (a; ans) {
chmin(min, a);
}
writeln(min - 1);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto N = readln.split[0].to!int;
// p = 10^^k <= N < 10^^(k+1)
int p = 1, k = 0;
foreach (i; 0 .. 10) {
if (p <= N && N < p*10) break;
p *= 10; k += 1;
}
int result;
foreach (num; all(k+1)) {
if (num > N) break;
if (has(num, 3) && has(num, 5) && has(num, 7)) result++;
}
result.writeln;
}
// does n has m in its digit
bool has(int n, int m) {
if (n < 10) return n == m;
int n_ = n/10;
return m == n - n_*10 || has(n_, m);
}
int[] generate(int n) {
if (n == 1) return [3, 5, 7];
auto next = generate(n-1);
int[] result;
foreach (num; next) { result ~= [num*10+3, num*10+5, num*10+7]; }
return result;
}
int[] all(int n) {
if (n == 1) return generate(1);
else return all(n-1) ~ generate(n);
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
auto a = readln.splitter.map !(to !(int)).array;
writeln (isSorted (a) ? "NO" : "YES");
}
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/abc154/tasks/abc154_b
// simulation
import std.stdio;
import std.string;
void main() {
string S = readln.chomp;
foreach(ch; S) {
'x'.write;
} writeln;
}
|
D
|
import std.stdio;
import std.string;
void main ()
{
int divs = 0;
foreach (p; 2..51)
{
bool ok = true;
for (int d = 2; d * d <= p; d++)
{
if (p % d == 0)
{
ok = false;
}
}
if (!ok)
{
continue;
}
writeln (p);
stdout.flush ();
bool cur = (readln.strip == "yes");
divs += cur;
if (cur && p * p <= 100)
{
writeln (p * p);
stdout.flush ();
bool next = (readln.strip == "yes");
divs += next;
}
}
writeln (divs > 1 ? "composite" : "prime");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
int[] h; readA(n, h);
int[] a; readA(n, a);
auto st = new SegmentTree!(long, max)(n+1);
foreach (i; 0..n)
st[h[i]] = st[0..h[i]] + a[i];
writeln(st[0..$]);
}
class SegmentTree(T, alias pred = "a + b")
{
import core.bitop, std.functional;
alias predFun = binaryFun!pred;
const size_t n, an;
T[] buf;
T unit;
this(size_t n, T unit = T.init)
{
this.n = n;
this.unit = unit;
an = n == 1 ? 1 : (1 << ((n-1).bsr + 1));
buf = new T[](an*2);
if (T.init != unit) buf[] = unit;
}
this(T[] init, T unit = T.init)
{
this(init.length, unit);
buf[an..an+n][] = init[];
foreach_reverse (i; 1..an)
buf[i] = predFun(buf[i*2], buf[i*2+1]);
}
void opIndexAssign(T val, size_t i)
{
buf[i += an] = val;
while (i /= 2)
buf[i] = predFun(buf[i*2], buf[i*2+1]);
}
pure T opSlice(size_t l, size_t r)
{
l += an; r += an;
T r1 = unit, r2 = unit;
while (l != r) {
if (l % 2) r1 = predFun(r1, buf[l++]);
if (r % 2) r2 = predFun(buf[--r], r2);
l /= 2; r /= 2;
}
return predFun(r1, r2);
}
pure T opIndex(size_t i) { return buf[i+an]; }
pure size_t opDollar() { return n; }
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp;
char[] t;
foreach (i, c; s)
if (i % 2 == 0) t ~= c;
writeln(t);
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n;
scanf("%d\n", &n);
string s = readln().chomp;
int[] score = new int[n];
{
int cur = 0;
foreach (i; 0..n) {
score[i] += cur;
if (s[i] == 'W') cur++;
}
}
{
int cur = 0;
foreach_reverse (i; 0..n) {
score[i] += cur;
if (s[i] == 'E') cur++;
}
}
int ans = n;
foreach (i; 0..n) {
ans = min(ans, score[i]);
}
writeln(ans);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split, a = rd[0], b = rd[1], c = rd[2];
writeln(a[$-1] == b[0] && b[$-1] == c[0] ? "YES" : "NO");
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N, i;
scan(N, i);
auto ans = N + 1 - 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);
}
}
}
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 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;
}
}
// }}}
// ModInt {{{
struct ModInt(ulong modulus) {
import std.traits : isIntegral, isBoolean;
import std.exception : enforce;
private {
ulong val;
}
this(const ulong n) {
val = n % modulus;
}
this(const ModInt n) {
val = n.value;
}
@property {
ref inout(ulong) value() inout {
return val;
}
}
T opCast(T)() {
static if (isIntegral!T) {
return cast(T)(val);
} else if (isBoolean!T) {
return val != 0;
} else {
enforce(false, "cannot cast from " ~ this.stringof ~ " to " ~ T.stringof ~ ".");
}
}
ModInt opAssign(const ulong n) {
val = n % modulus;
return this;
}
ModInt opOpAssign(string op)(ModInt rhs) {
static if (op == "+") {
val += rhs.value;
if (val >= modulus) {
val -= modulus;
}
} else if (op == "-") {
if (val < rhs.value) {
val += modulus;
}
val -= rhs.value;
} else if (op == "*") {
val = val * rhs.value % modulus;
} else if (op == "/") {
this *= rhs.inv;
} else if (op == "^^") {
ModInt res = 1;
ModInt t = this;
while (rhs.value > 0) {
if (rhs.value % 2 != 0) {
res *= t;
}
t *= t;
rhs /= 2;
}
this = res;
} else {
enforce(false, op ~ "= is not implemented.");
}
return this;
}
ModInt opOpAssign(string op)(ulong rhs) {
static if (op == "+") {
val += ModInt(rhs).value;
if (val >= modulus) {
val -= modulus;
}
} else if (op == "-") {
auto r = ModInt(rhs);
if (val < r.value) {
val += modulus;
}
val -= r.value;
} else if (op == "*") {
val = val * ModInt(rhs).value % modulus;
} else if (op == "/") {
this *= ModInt(rhs).inv;
} else if (op == "^^") {
ModInt res = 1;
ModInt t = this;
while (rhs > 0) {
if (rhs % 2 != 0) {
res *= t;
}
t *= t;
rhs /= 2;
}
this = res;
} else {
enforce(false, op ~ "= is not implemented.");
}
return this;
}
ModInt opUnary(string op)() {
static if (op == "++") {
this += 1;
} else if (op == "--") {
this -= 1;
} else {
enforce(false, op ~ " is not implemented.");
}
return this;
}
ModInt opBinary(string op)(const ulong rhs) const {
mixin("return ModInt(this) " ~ op ~ "= rhs;");
}
ModInt opBinary(string op)(ref const ModInt rhs) const {
mixin("return ModInt(this) " ~ op ~ "= rhs;");
}
ModInt opBinary(string op)(const ModInt rhs) const {
mixin("return ModInt(this) " ~ op ~ "= rhs;");
}
ModInt opBinaryRight(string op)(const ulong lhs) const {
mixin("return ModInt(this) " ~ op ~ "= lhs;");
}
long opCmp(ref const ModInt rhs) const {
return cast(long)value - cast(long)rhs.value;
}
bool opEquals(const ulong rhs) const {
return value == ModInt(rhs).value;
}
ModInt inv() const {
ModInt ret = this;
ret ^^= modulus - 2;
return ret;
}
string toString() const {
import std.format : format;
return format("%s", val);
}
}
// }}}
// 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 a, b, c, d;
cin.scan(a, b, c, d);
bool flg = true;
while (true) {
if (flg) {
c -= b;
if (c <= 0) {
writeln("Yes");
return;
}
} else {
a -= d;
if (a <= 0) {
writeln("No");
return;
}
}
flg = !flg;
}
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
string s;
cin.scan(s);
foreach (e; s) {
if (e == '7') {
writeln("Yes");
return;
}
}
writeln("No");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
import std.math;
import std.range;
void main() {
auto N = readln.chomp.to!int;
auto K = readln.chomp.to!int;
auto x = 1;
foreach (i; 0..N) {
if (x < K) x *= 2;
else x += K;
}
writeln(x);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long a1, a2, a3;
scan(a1, a2, a3);
if (a1 + a2 + a3 <= 21)
{
writeln("win");
}
else if (22 <= a1 + a2 + a3)
{
writeln("bust");
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
import std.stdio,std.string,std.conv;
int main()
{
string s;
while((s = readln.chomp).length != 0)
{
for(int i=0;i<s.length;i++)
{
if(s[i] == '@')
{
int count = s[i+1] - '0';
foreach(j;0..count)
{
write(s[i+2]);
}
i += 2;
}
else
{
write(s[i]);
}
}
writeln;
}
return 0;
}
|
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 s = sread();
auto k = lread();
// writeln(s);
// writeln(k);
foreach (i; 0 .. k)
{
if (s[i] != '1')
{
writeln(s[i]);
return;
}
}
writeln(1);
}
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
|
void main(){
string s = readln().chomp();
int ans;
foreach(elm; s){
ans += (elm=='+')?1:-1;
}
ans.writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
// 1要素のみの入力
T inelm(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] inln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
return ln;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp;
writeln(s.uniq.array.length-1);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
alias Section = Tuple!(int, "l", int, "r");
auto data = readln.split, N = data[0].to!int, M = data[1].to!int, Q = data[2].to!int;
int[500][500] train;
int[500][500] row_sum; // row_sum[l][r] = t_1r + ... + t_lr
foreach (i; 0 .. M) {
data = readln.split, train[data[0].to!int-1][data[1].to!int-1]++;
}
foreach (r; 0 .. 500) {
int s;
foreach (l; 0 .. 500) {
s += train[l][r];
row_sum[l][r] = s;
}
}
int[] p, q;
foreach (j; 0 .. Q) {
data = readln.split;
p ~= data[0].to!int-1, q ~= data[1].to!int-1;
}
foreach (j; 0 .. Q) {
int ans;
foreach (r; p[j] .. q[j]+1) {
if (p[j]==0) { ans += row_sum[q[j]][r]; /*row_sum[q[j]][r].writeln;*/ }
else { ans += (row_sum[q[j]][r] - row_sum[p[j]-1][r]); /*(row_sum[q[j]][r] - row_sum[p[j]-1][r]).writeln;*/ }
}
writeln(ans);
}
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;
void main() {
auto l = readln.chomp.split.map!(to!int).array;
int a = l[0], b = l[1], x = l[2];
for (int i = 0; i <= b; ++i) {
if (a + i == x) {
writeln("YES");
return;
}
}
writeln("NO");
return;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
for(int n; 0!=(n=readln().chomp().to!int()); )
{
auto a=0,b=0;
foreach(i;1..n+1)
{
auto t=i;
while(t%2==0) t/=2,++a;
while(t%5==0) t/=5,++b;
}
writeln(min(a,b));
}
}
|
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();
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 x = lread();
long max_pow = 1;
foreach (e; 2 .. 40)
{
long i = 2,j;
while(1)
{
j = pow(e,i);
i++;
if(j > x)
{
break;
}
max_pow = max(j, max_pow);
}
}
writeln(max_pow);
}
|
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 d, n;
scan(d, n);
if (n == 100) {
writeln(100^^(d+1) + 100^^d);
return;
}
writeln(100^^d * n);
}
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.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n, k;
scanf("%d%d", &n, &k);
int[] a = new int[n];
foreach (i ; 0..n) scanf("%d", &a[i]);
int s = 10^^9;
foreach (x ; a) s = min(s, x);
int ans = 0;
int i = 0;
while (i < n) {
if (a[i] == s) {
i++;
continue;
}
ans++;
int cnt = 0;
int ti = min(n, i+k);
foreach (j ; i..ti) {
if (a[j] == s) cnt++;
}
if (cnt == 0 && ti == i+k) {
i = ti-1;
} else {
i = ti;
}
}
writeln(ans);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
const int n=3;
auto c=new int[][](n, n);
foreach(i; 0..n) c[i]=readln.split.to!(int[]);
for(int a0=-105; a0<=105; a0++){
auto a=new int[](n), b=new int[](n);
a[0]=a0;
foreach(j; 0..n) b[j]=c[0][j]-a[0];
foreach(i; 1..n) a[i]=c[i][0]-b[0];
bool ok=true;
foreach(i; 1..n)foreach(j; 1..n){
if(c[i][j]!=a[i]+b[j]) ok=false;
}
if(ok){writeln("Yes"); return;}
}
writeln("No");
}
/+
a1+b1 a1+b2 a1+b3
a2+b1 a2+b2 a2+b3
a3+b1 a3+b2 a3+b3
+/
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
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int t; rd(t);
while(t--){
auto s=readln.chomp.to!(char[]);
int d=0, l=0, u=0;
foreach(c; s){
if('0'<=c && c<='9') d++;
if('a'<=c && c<='z') l++;
if('A'<=c && c<='Z') u++;
}
if(d>0 && l>0 && u>0){
writeln(s);
continue;
}
if(d==0){
foreach(i; 0..s.length){
auto c=s[i];
if('a'<=c && c<='z' && l>1){
s[i]='0';
break;
}
if('A'<=c && c<='Z' && u>1){
s[i]='0';
break;
}
}
}
if(l==0){
foreach(i; 0..s.length){
auto c=s[i];
if('0'<=c && c<='9' && d>1){
s[i]='a';
break;
}
if('A'<=c && c<='Z' && u>1){
s[i]='a';
break;
}
}
}
if(u==0){
foreach(i; 0..s.length){
auto c=s[i];
if('0'<=c && c<='9' && d>1){
s[i]='A';
break;
}
if('a'<=c && c<='z' && l>1){
s[i]='A';
break;
}
}
}
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.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 10L^^15;
enum mod = 10L ^^ 9 + 7;
void main() {
int h, w;
scan(h, w);
auto ban = iota(h).map!(i => readln.chomp).array;
auto dp = new long[][](h, w);
dp[0][0] = 1;
foreach (i ; 0 .. h) {
foreach (j ; 0 .. w) {
if (ban[i][j] == '#') {
continue;
}
if (i > 0) {
dp[i][j] += dp[i-1][j];
dp[i][j] %= mod;
}
if (j > 0) {
dp[i][j] += dp[i][j-1];
dp[i][j] %= mod;
}
}
}
writeln(dp[h-1][w-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.string, std.conv, std.math;
void main() {
int n = readln.chomp.to!int;
long debt = 100000;
foreach(i;0..n) debt = (((debt+debt*0.05)/1000.0).ceil*1000).to!long;
debt.writeln;
}
|
D
|
import std.stdio;
import std.string;
void main() {
auto s = readln.chomp;
writeln(s[0..1], s.length - 2, s[$ - 1..$]);
}
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm;
import std.uni, std.range, std.math, std.container, std.datetime;
import core.bitop, std.typetuple, std.typecons;
immutable long MOD = 1_000_000_007;
alias tie = TypeTuple;
alias triplet = Tuple!(int, int, int);
void main(){
int N, M, a, b;
readVars(N, M);
auto ncnt = new int[](N);
foreach(i ; 0 .. M){
readVars(a, b);
a--; b--;
ncnt[a]++;
ncnt[b]++;
}
foreach(i ; 0 .. N){
if (ncnt[i] & 1) {
writeln("NO");
return;
}
}
writeln("YES");
}
void readVars(T...)(auto ref T args){
auto line = readln.split;
foreach(ref arg ; args){
arg = line.front.to!(typeof(arg));
line.popFront;
}
if(!line.empty){
throw new Exception("args num < input num");
}
}
|
D
|
import std.stdio, std.ascii;
void main() {
auto d = stdin.readln.dup;
foreach (c; d) {
if (c.isLower) c.toUpper.write;
else c.toLower.write;
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
foreach (i; 0..s.length-1) {
if (s[i] == s[i+1]) {
writeln(i+1, " ", i+2);
return;
}
if (i < s.length-2 && s[i] == s[i+2]) {
writeln(i+1, " ", i+3);
return;
}
}
writeln(-1, " ", -1);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto m = readln.chomp.to!int;
writeln(48-m);
}
|
D
|
// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio : readln, writeln;
import std.array : split;
import std.string : chomp;
import std.conv : to;
auto gets() { return readln.chomp; }
auto getVals(T)() { return gets.split.to!(T[]); }
void main() {
auto xs = getVals!long;
auto l = xs[0], r = xs[1], x = xs[2], y = xs[3], k = xs[4];
for (auto i = x; i <= y; i++) {
auto v = i * k;
if (l <= v && v <= r) {
writeln("YES");
return;
}
}
writeln("NO");
}
|
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);
long cnt;
void main()
{
auto s = sread();
auto before = (s.length - 1) / 2;
auto after = (s.length + 3) / 2 - 1;
// writeln(s[0 .. before]);
// writeln(s[after .. $]);
if(s.is_reverse() && is_reverse(s[0 .. before]) && is_reverse(s[after .. $]))
writeln("Yes");
else
writeln("No");
}
bool is_reverse(string s)
{
bool ret = true;
foreach(i; iota(s.length))
{
ret &= (s[i] == s[$ - 1 - i]);
}
return ret;
}
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.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 = new long[](N);
foreach (i; 0..N)
{
a[i] = RD-1;
}
auto used = new bool[](N);
long ans;
long pos;
used[0] = true;
while (pos != 1)
{
if (used[a[pos]])
{
ans = -1;
break;
}
else
{
pos = a[pos];
used[pos] = true;
++ans;
}
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
void main(){
import std.stdio, std.algorithm;
long n, a, b, k; rd(n, a, b, k);
const long mod=998244353;
const int M=1_000_00*4;
auto fact=genFact(M, mod);
auto invFact=genInv(fact, mod);
long comb(long nn, long rr){
if(nn<rr) return 0;
long ret=fact[nn]%mod;
(ret*=invFact[rr])%=mod;
(ret*=invFact[nn-rr])%=mod;
return ret;
}
long tot=0;
for(long x=0; x<=n; x++)if(k-a*x>=0){
if((k-a*x)%b==0){
long y=(k-a*x)/b;
if(y>n) continue;
(tot+=comb(n, x)*comb(n, y)%mod)%=mod;
}
}
writeln(tot);
}
long[] genFact(int n, long mod){
auto fact=new long[](n);
fact[0]=fact[1]=1;
foreach(i; 2..n) fact[i]=i*fact[i-1]%mod;
return fact;
}
long[] genInv(long[] arr, long mod){
auto inv=new long[](arr.length);
inv[0]=inv[1]=1;
foreach(i, elem; arr[1..$]) inv[i]=powmod(arr[i], mod-2, mod);
return inv;
}
long powmod(long a, long x, long mod){
if(x==0) return 1;
else if(x==1) return a;
else if(x&1) return a*powmod(a, x-1, mod)%mod;
else return powmod(a*a%mod, x/2, mod);
}
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;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long n;
scan(n);
auto T = new long[](n);
foreach (i; 0 .. n)
{
long t;
scan(t);
T[i] = t;
}
// writeln(T);
long ans_gcd;
ans_gcd = T[0];
foreach (i; 0 .. n)
{
ans_gcd = gcd(ans_gcd, T[i]);
}
// writeln(ans_gcd);
long ans_lcm;
ans_lcm = T[0];
foreach (i; 0 .. n)
{
ans_lcm = ans_lcm * (T[i] / gcd(ans_lcm, T[i]));
}
writeln(ans_lcm);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
auto binary_search(long key, long[] l)
{
long left = 0; //lの左端
long right = l.length - 1; //lの右端
while (right >= left)
{
long mid = left + (right - left) / 2; //区間の真ん中
if (l[mid] == key)
{
return mid;
}
else if (l[mid] > key)
{
right = mid - 1;
}
else if (l[mid] < key)
{
left = mid + 1;
}
}
return -1;
}
// auto a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910];
// auto a = aryread();
// writeln(a);
// long len_a = a.length;
// writeln(len_a);
// long ans;
// ans = binary_search(51, a);
// writeln(ans);
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
auto n = lread();
writeln(800 * n - (n / 15) * 200);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
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);
if (x[0] < x[1] && x[1] < x[2]) writeln("Yes");
else writeln("No");
}
|
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;
}
}
// }}}
// ModInt {{{
struct ModInt(ulong modulus) {
import std.traits : isIntegral, isBoolean;
import std.exception : enforce;
private {
ulong val;
}
this(const ulong n) {
val = n % modulus;
}
this(const ModInt n) {
val = n.value;
}
@property {
ref inout(ulong) value() inout {
return val;
}
}
T opCast(T)() {
static if (isIntegral!T) {
return cast(T)(val);
} else if (isBoolean!T) {
return val != 0;
} else {
enforce(false, "cannot cast from " ~ this.stringof ~ " to " ~ T.stringof ~ ".");
}
}
ModInt opAssign(const ulong n) {
val = n % modulus;
return this;
}
ModInt opOpAssign(string op)(ModInt rhs) {
static if (op == "+") {
val += rhs.value;
if (val >= modulus) {
val -= modulus;
}
} else if (op == "-") {
if (val < rhs.value) {
val += modulus;
}
val -= rhs.value;
} else if (op == "*") {
val = val * rhs.value % modulus;
} else if (op == "/") {
this *= rhs.inv;
} else if (op == "^^") {
ModInt res = 1;
ModInt t = this;
while (rhs.value > 0) {
if (rhs.value % 2 != 0) {
res *= t;
}
t *= t;
rhs /= 2;
}
this = res;
} else {
enforce(false, op ~ "= is not implemented.");
}
return this;
}
ModInt opOpAssign(string op)(ulong rhs) {
static if (op == "+") {
val += rhs;
if (val >= modulus) {
val -= modulus;
}
} else if (op == "-") {
if (val < rhs) {
val += modulus;
}
val -= rhs;
} else if (op == "*") {
val = val * rhs % modulus;
} else if (op == "/") {
this *= ModInt(rhs).inv;
} else if (op == "^^") {
ModInt res = 1;
ModInt t = this;
while (rhs > 0) {
if (rhs % 2 != 0) {
res *= t;
}
t *= t;
rhs /= 2;
}
this = res;
} else {
enforce(false, op ~ "= is not implemented.");
}
return this;
}
ModInt opUnary(string op)() {
static if (op == "++") {
this += 1;
} else if (op == "--") {
this -= 1;
} else {
enforce(false, op ~ " is not implemented.");
}
return this;
}
ModInt opBinary(string op)(const ulong rhs) const {
mixin("return ModInt(this) " ~ op ~ "= rhs;");
}
ModInt opBinary(string op)(ref const ModInt rhs) const {
mixin("return ModInt(this) " ~ op ~ "= rhs;");
}
ModInt opBinary(string op)(const ModInt rhs) const {
mixin("return ModInt(this) " ~ op ~ "= rhs;");
}
ModInt opBinaryRight(string op)(const ulong lhs) const {
mixin("return ModInt(this) " ~ op ~ "= lhs;");
}
long opCmp(ref const ModInt rhs) const {
return cast(long)value - cast(long)rhs.value;
}
bool opEquals(const ulong rhs) const {
return value == ModInt(rhs).value;
}
ModInt inv() const {
ModInt ret = this;
ret ^^= modulus - 2;
return ret;
}
string toString() const {
import std.format : format;
return format("%s", val);
}
}
// }}}
// 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 n, m;
cin.scan(n, m);
writeln((n - 1) * (m - 1));
}
|
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
??2??5
---+/
/+---test
?44
---+/
/+---test
7?4
---+/
/+---test
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???
---+/
void main(string[] args) {
const S = readln.chomp;
auto dp = new long[13][S.length+1];
dp[0][0] = 1;
foreach (i; 1..S.length+1) {
const long x = S[i-1] == '?'? -1: S[i-1]-'0';
foreach (j; 0..10) {
if (x != -1 && x != j) continue;
foreach (ki; 0..13) {
dp[i][(ki*10 + j)%13] += dp[i-1][ki];
}
}
foreach (j; 0..13) dp[i][j] %= 1000000007;
}
dp[$-1][5].writeln;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.array;
void main() {
auto Q = readln.chomp.to!int;
foreach (i; 0..Q) {
auto input = readln.split.map!(to!int).array;
//??????CAN?????°????±??????????CAN?????°??????min(C, A, N)????????????
int can = min(input[0], input[1], input[2]);
input[] -= can;
//?¬????CCA?????°????±??????????CCA?????°??????
int cca;
if (input[0] > input[1] * 2) cca = input[1];
else cca = input[0] / 2;
input[0] -= cca * 2;
int ccc = input[0] / 3;
writeln(can + cca + ccc);
}
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n;
scanf("%d", &n);
int[] X = new int[n];
int[] Y = new int[n];
long INF = 1L<<40;
int parity = 0;
foreach (i; 0..n) {
scanf("%d%d", &X[i], &Y[i]);
int p = (X[i]+Y[i]+INF+1)%2;
if (i == 0) parity = p;
else if (parity != p) {
writeln(-1);
return;
}
}
int m = 32;
writeln(m+parity);
foreach_reverse (i; 0..m) {
writeln(1L<<i);
}
if (parity) {
writeln(1);
}
foreach (_i; 0..n) {
long x = X[_i], y = Y[_i];
if (parity) x++;
string ans;
foreach_reverse (i; 0..m) {
long l = 1L<<i;
if (abs(x) < abs(y)) {
if (y < 0) {
ans ~= 'D';
y += l;
} else {
ans ~= 'U';
y -= l;
}
} else {
if (x < 0) {
ans ~= 'L';
x += l;
} else {
ans ~= 'R';
x -= l;
}
}
}
if (parity) ans ~= 'L';
writeln(ans);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;
void main() {
int n, q; scan(n, q);
auto uf = UnionFind(n);
foreach (_ ; 0 .. q) {
int com, x, y; scan(com, x, y);
if (com == 0) {
uf.merge(x, y);
}
else {
writeln(uf.same(x, y) ? 1 : 0);
}
}
}
struct UnionFind {
private {
int _size;
int[] _parent;
}
this(int N)
in {
assert(N > 0);
}
body {
_size = N;
_parent = new int[](_size);
foreach (i ; 0 .. _size) {
_parent[i] = i;
}
}
int findRoot(int x)
in {
assert(0 <= x && x < _size);
}
body {
if (_parent[x] != x) {
_parent[x] = findRoot(_parent[x]);
}
return _parent[x];
}
bool same(int x, int y)
in {
assert(0 <= x && x < _size);
assert(0 <= y && y < _size);
}
body {
return findRoot(x) == findRoot(y);
}
void merge(int x, int y)
in {
assert(0 <= x && x < _size);
assert(0 <= y && y < _size);
}
body {
int u = findRoot(x);
int v = findRoot(y);
if (u == v) return;
_parent[v] = u;
}
}
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.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 s = RD!(char[]);
long ans;
long streak;
foreach (i; 0..s.length-1)
{
if (s[i] == 'A')
{
++streak;
}
else if (s[i] == 'B')
{
if (s[i+1] == 'C')
{
ans += streak;
s[i+1] = 'A';
--streak;
}
else
{
streak = 0;
}
}
else
{
streak = 0;
}
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nk = readln.split.to!(int[]);
auto N = nk[0];
auto K = nk[1];
writeln((N+1) / 2 >= K ? "YES" : "NO");
}
|
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() {
long T1, T2;
long A1, A2;
long B1, B2;
scan(T1, T2);
scan(A1, A2);
scan(B1, B2);
if (T1*A1 + T2*A2 < T1*B1 + T2*B2) {
swap(A1, B1);
swap(A2, B2);
}
// T1*A1 + T2*A2 >= T1*B1 + T2*B2
auto d = T1*A1 + T2*A2 - (T1*B1 + T2*B2);
auto v = T1*B1 - T1*A1;
if (d == 0) {
writeln("infinity");
return;
}
if (v < 0) {
writeln(0);
return;
}
auto ans = 2 * (v / d + 1) - 1;
if (v % d == 0) 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.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
for (;;) {
auto rd = readln.split.map!(to!int), h = rd[0], w = rd[1];
if (h == 0 && w == 0) break;
foreach (i; 0..h) {
foreach (j; 0..w)
write((i + j) % 2 == 0 ? '#' : '.');
writeln;
}
writeln;
}
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/abc152/tasks/abc152_d
// math, combinatorics
import std.conv;
import std.stdio;
import std.string;
void main() {
int n = readln.chomp.to!int;
long[10][10] digits;
// count the numbers starting in i and ending in j
for(int i = 0; i <= n; i++)
digits[i.to!string[0] - '0'][i.to!string[$-1] - '0'] += 1L;
long answer = 0L;
for(int i = 1; i <= 9; ++i)
for(int j = 0; j <= 9; ++j)
answer += digits[i][j]*digits[j][i];
answer.writeln;
}
|
D
|
/+ dub.sdl:
name "A"
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, a, b;
sc.read(n, a, b);
import std.math;
if (abs(a-b) % 2 == 0) {
writeln("Alice");
} else {
writeln("Borys");
}
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
|
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, "next", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);
void main()
{
auto n = lread();
long ok = 10001, ng = -1;
while (abs(ok - ng) > 1)
{
auto mid = (ok + ng) / 2;
if (mid * 1000 >= n)
ok = mid;
else
ng = mid;
}
writeln(1000 * ok - n);
}
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;
import std.conv;
import std.array;
import std.string;
void main()
{
while (1) {
string[] input = split(readln());
int h = to!(int)(input[0]);
int w = to!(int)(input[1]);
if (h == 0 && w == 0) break;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if ((i + j) % 2 == 0) {
write("#");
} else {
write(".");
}
}
write("\n");
}
write("\n");
}
}
|
D
|
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import core.bitop;
void main ()
{
int n;
while (scanf (" %d", &n) > 0)
{
int m = (n + 31) / 32;
auto a1 = new uint [] [] (n, m);
auto a2 = new uint [] [] (n, m);
foreach (i; 0..n)
{
foreach (j; 0..n)
{
int c;
scanf (" %d", &c);
if (c)
{
a1[i][j >> 5] |= 1u << (j & 31);
a2[j][i >> 5] |= 1u << (i & 31);
}
}
}
auto b = new bool [n];
uint [] [] a;
void recur (int v)
{
b[v] = true;
foreach (u; 0..n)
{
if (!b[u] && (a[v][u >> 5] & (1u << (u & 31))))
{
recur (u);
}
}
}
bool ok = true;
b[] = false;
a = a1;
recur (0);
ok &= all !("a == true") (b[]);
b[] = false;
a = a2;
recur (0);
ok &= all !("a == true") (b[]);
writeln (ok ? "YES" : "NO");
}
}
|
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() {
long[] ans = new long[31];
ans[0] = 1;
foreach(i; 1..31) {
ans[i] += ans[i-1];
if (i>1) ans[i] += ans[i-2];
if (i>2) ans[i] += ans[i-3];
}
while(true) {
int n = readln.chomp.to!int;
if (n==0) break;
writeln(((ans[n]+1)/10+1)/365+1);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto T = readln.chomp.to!int;
foreach (_; 0..T) {
auto N = readln.chomp.to!int;
auto as = readln.split.to!(int[]);
auto xs = new int[](5001);
auto ls = new int[](5001);
foreach (i; 1..N+1) {
auto a = as[i-1];
if (xs[a]) {
if (xs[a] > 1) goto ok;
if (ls[a] != i-1) goto ok;
}
++xs[a];
ls[a] = i;
}
writeln("NO");
continue;
ok:
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.container;
import std.datetime;
void main()
{
auto n = readln.chomp.to!int;
bool[string] ids;
foreach (i; 0..n) {
auto x = readln.chomp;
ids[x] = 1;
}
auto m = readln.chomp.to!int;
bool s;
foreach (i; 0..m) {
auto x = readln.chomp;
if (ids.get(x, 0)) {
if (s) writeln("Closed by ", x);
else writeln("Opened by ", x);
s = !s;
} else {
writeln("Unknown ", x);
}
}
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
auto s = iota(3).map!(i => readln.chomp).array;
auto n = iota(3).map!(i => s[i].length.to!int).array;
// s[x] の左から k 番目に s[y] が重なることは出来るか
bool check(int x, int y, int k) {
if (k >= n[x]) {
return true;
}
foreach (i ; 0 .. n[y]) {
if (k + i >= n[x]) break;
if (s[x][k + i] == '?' || s[y][i] == '?') continue;
if (s[x][k + i] != s[y][i]) {
return false;
}
}
return true;
}
auto ok = new bool[][][](3, 3, 2001);
foreach (i ; 0 .. 3) {
foreach (j ; 0 .. 3) {
if (i == j) continue;
foreach (k ; 0 .. 2001) {
ok[i][j][k] = check(i, j, k);
}
}
}
int ans = inf;
foreach (lb ; -4000 .. 4001) {
foreach (lc ; -4000 .. 4001) {
bool valid = true;
if (abs(lb) >= 2000) {
}
else if (lb < 0) {
valid &= ok[1][0][-lb];
}
else {
valid &= ok[0][1][lb];
}
if (abs(lc) >= 2000) {
}
else if (lc < 0) {
valid &= ok[2][0][-lc];
}
else {
valid &= ok[0][2][lc];
}
if (abs(lb - lc) >= 2000) {
}
else if (lb < lc) {
valid &= ok[1][2][lc - lb];
}
else {
valid &= ok[2][1][lb - lc];
}
if (valid) {
int l = min(lb, lc, 0);
int r = max(lb + n[1], lc + n[2], n[0]);
chmin(ans, r - l);
}
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
|
D
|
import std.stdio, std.string, std.conv;
void main() {
int s = readln.chomp.to!int;
int h = s / 3600;
s %= 3600;
int m = s / 60;
s %= 60;
writeln(h, ":", m, ":", s);
}
|
D
|
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container;
import std.typecons;
void main() {
auto S = readln.chomp;
auto N = S.length;
Tuple!(int, int)[] arr;
int i = 0;
while(i < N) {
int r,l;
while(i < N && S[i]=='R') { i++; r++; }
while(i < N && S[i] == 'L') { i++; l++; }
arr ~= tuple(r,l);
}
foreach(a; arr) {
int r = a[0], l = a[1];
foreach(j; 0..(r-1)) {
write("0 ");
}
write((r+1) / 2 + l/ 2, " ");
write(r / 2 + (l+1)/2, " ");
foreach(j; 0..(l-1)) {
write("0 ");
}
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import core.bitop;
int n; rd(n);
int k=1;
while(k*2<=n) k*=2;
writeln(max(popcnt(n), popcnt(k-1)));
}
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
|
void main()
{
long x = rdElem;
Pair[] list;
foreach (i; 0L .. 3000L)
{
list ~= Pair(i, i ^^ 5);
if (i) list ~= Pair(-i, -i ^^ 5);
}
foreach (a; list)
{
foreach (b; list)
{
if (a.b - b.b == x)
{
writeln(a.a, " ", b.a);
return;
}
}
}
}
struct Pair
{
long a, b;
}
enum long mod = 10^^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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
int[] a; readA(n, a);
auto n1 = 0, n2 = 0, n3 = 0;
foreach (ai; a) {
if (ai%4 == 0) ++n1;
else if (ai%2 == 0) ++n2;
else ++n3;
}
writeln(n2 == 0 && n3 <= n1+1 || n2 > 0 && n3 <= n1 ? "Yes" : "No");
}
|
D
|
void main(){
int[] ngs = [7, 5, 3];
int x = _scan();
writeln(ngs.count(x)==1? "YES": "NO");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.algorithm;
long maximalModulus(long left, long right) {
if (right / 2 + 1 >= left) {
return right % (right / 2 + 1);
}
else {
long max = -1;
long i = 1;
long x = 1;
while (x > max + 1) {
x = ((right - 1) / i) + 1;
debug{writeln("x=", x, "right&x=", right%x, "max=", max);}
if (right%x > max) {
max = right%x;
}
if (x < left) {
return right % left;
}
++i;
}
return max;
}
}
// void find_mod(long left, long right)
// {
// long max_current = 0;
// long max_delimeter = 0;
// for (long a = right; a >= left; a--)
// {
// for (long b = max(a - 1, a / 2 + 1); b >= left ; b--)
// {
// auto current = a % b;
// max_current = max(max_current, current);
// if (max_current == b - 1)
// {
// writeln(max_current);
// debug{writeln("A",a," B",b);}
// return;
// }
// }
// }
// writeln(max_current);
// return;
// }
void main()
{
int n;
long l, r;
scanf("%d", &n);
getchar();
for (int k = 0; k < n; k++){
scanf("%ld %ld", &l, &r);
getchar();
// find_mod(l, r);
writeln(maximalModulus(l, r));
}
}
|
D
|
import std.stdio;
import std.string;
void main()
{
foreach (i; 0 .. 3)
{
auto tmp = readln.chop();
tmp[i].write();
}
writeln();
}
|
D
|
import std.stdio;
import std.array;
import std.algorithm;
import std.string;
import std.container;
import std.typecons;
int size(in string s) {
return cast(int)s.length;
}
void main() {
string s = readln.chomp;
immutable X = "ABC";
bool check(in string s) {
foreach (i, c; s) {
if (s[i] != X[i]) return false;
}
return true;
}
bool f(in string s) {
if (s.size < 3) return false;
if (s.size == 3) {
return check(s);
}
if (s.find("ABC").empty) return false;
bool r = false;
foreach (c; "ABC") {
string t = "" ~ c;
if (!s.replace("ABC", "").find(t).empty) continue;
r |= f(s.replace("ABC", t));
}
return r;
}
writeln(f(s) ? "Yes" : "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; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
auto cnt = new bool[](26);
foreach (c; S)
{
cnt[c-'a'] = true;
}
string ans;
foreach (i, e; cnt)
{
if (e == false)
{
ans = [cast(char)('a'+i)];
break;
}
}
writeln(ans == "" ? "None" : ans);
stdout.flush();
debug readln();
}
|
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 s = sread();
bool[] tmp = [false, false];
foreach (i; 0 .. s.length)
{
foreach (j; 0 .. s.length)
{
if (s[i] == 'C' && s[j] == 'F')
{
if (i < j)
{
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.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
@safe
long solve (const string s) {
enum m = 2019;
auto c = new int[m];
auto d = new int[m];
long res;
foreach (ch; s) {
c[0] += 1;
const int k = ch.to!int - 48;
d[] = 0;
int v = k;
foreach (j; 0 .. m) {
d[v] += c[j];
v += 10;
if (v >= m) v -= m;
}
swap (c, d);
res += c[0];
}
return res;
}
void main() {
auto s = readln.stripRight;
writeln (solve (s));
}
|
D
|
import std.stdio; // readln
import std.array; // split
import std.conv; // to
import std.typecons;
import std.range;
import std.algorithm;
void main(){
string[] s = split(readln());
int n = to!int(s[0]);
s = split(readln());
int[] a = new int[](n);
for(int i = 0; i < n; i++){
a[i] = to!int(s[i]);
a[i]--;
}
int cnt = 0;
for(int i = 0; i < n; i++){
if(i == a[a[i]]) cnt++;
}
writeln(cnt / 2);
}
|
D
|
import std;
void main() {
int n; scan(n);
int ans = 0;
bool[string] d;
foreach (_; 0..n) {
string s = read!string;
d[s] = true;
}
writeln(d.keys.length);
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
|
D
|
import std.stdio, std.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;
bool[char] set;
foreach (i; 0..N)
set[RD!char] = true;
writeln(set.keys.length == 3 ? "Three" : "Four");
stdout.flush();
debug readln();
}
|
D
|
void main() {
string[] tmp = readln.split;
int a = tmp[0].to!int, b = tmp[1].to!int;
string p = tmp[0];
int cnt;
foreach (i; a .. b+1) {
char[] q = p.dup;
reverse(q);
if (p == q) ++cnt;
p = p.succ;
}
cnt.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 chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons;
// }}}
// nep.scanner {{{
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string : chomp;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.chomp.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
}
// }}}
void main()
{
auto cin = new Scanner;
string s;
cin.scan(s);
writeln(s.count('1'));
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_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 M = RD;
auto edges = new long[][](N);
foreach (i; 0..M)
{
auto a = RD-1;
auto b = RD-1;
edges[a] ~= b;
edges[b] ~= a;
}
foreach (i; 0..N)
writeln(edges[i].length);
stdout.flush();
debug readln();
}
|
D
|
void main(){
int n = _scan();
int[] a = _scanln();
bool approve = true;
foreach(elm; a){
if(elm%2 == 0){
if( elm%3==0 || elm%5==0 )continue;
else{
approve = false;
break;
}
}
}
writeln(approve? "APPROVED": "DENIED");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio, std.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;
void solve() {
ulong answer;
bool nextKetaUp;
auto keta = N.length;
foreach(i; 0..keta) {
auto num = N[$-1-i..$-i].to!(int) + (nextKetaUp ? 1 : 0);
if (num == 10) continue;
nextKetaUp = false;
if (i < keta-1) {
auto next = N[$-2-i..$-1-i].to!(int);
if (num >= 5 && next >= 5) {
answer += 10 - num;
nextKetaUp = true;
continue;
}
}
if (num >= 6) {
answer += 10 - num;
nextKetaUp = true;
continue;
}
answer += num;
}
if (nextKetaUp) answer++;
writeln(answer);
}
solve();
}
|
D
|
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
int k = readln.chomp.to!int;
int[] done = new int[](k);
done[] = int.max;
done[1] = 1;
int[] queue = [1];
while (queue.length)
{
int node = queue.front;
queue = queue[1 .. $];
int next10 = (node * 10) % k;
if (done[node] < done[next10])
{
done[next10] = done[node];
queue = next10 ~ queue;
}
int next1 = (node + 1) % k;
if (done[node] + 1 < done[next1]) {
done[next1] = done[node] + 1;
queue ~= next1;
}
}
done[0].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);}}
enum MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long N = lread();
auto f = factorize(N);
long ans;
foreach (key, val; f)
{
long cnt = 1;
while ((cnt + 2) * (cnt + 1) / 2 <= val)
cnt++;
ans += cnt;
}
writeln(ans);
}
/// 素因数分解
long[long] factorize(long x)
{
assert(0 < x, "x is negative");
long[long] ps;
while ((x & 1) == 0)
{
x /= 2;
ps[2] = (2 in ps) ? ps[2] + 1 : 1;
}
for (long i = 3; i * i <= x; i += 2)
while (x % i == 0)
{
x /= i;
ps[i] = (i in ps) ? ps[i] + 1 : 1;
}
if (x != 1)
ps[x] = (x in ps) ? ps[x] + 1 : 1;
return ps;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto x = readln.chomp.to!int;
writeln(x < 1200 ? "ABC" : "ARC");
}
|
D
|
import std.stdio, std.algorithm, std.string;
void main()
{
readln();
auto s = readln().strip();
bool ok = true;
ok &= !canFind(s, "000");
ok &= !canFind(s, "11");
ok &= !s.startsWith("00");
ok &= !s.endsWith("00");
ok &= s != "0";
writeln(ok ? "Yes" : "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 S = readln.split[0];
int ans1, ans2;
foreach (i; 0 .. S.length) {
if (i % 2 == 0) {
S[i] == '0' ? ans1++ : ans2++;
}
else {
S[i] == '0' ? ans2++ : ans1++;
}
}
writeln(min(ans1, ans2));
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.math;
import std.format;
void main() {
string[] q;
foreach (string line; stdin.lines) {
if (line == "quit\n") break;
string op, clr;
auto s = line.chomp.split;
if (s.length == 1) {
op = s[0];
} else {
op = s[0];
clr = s[1];
}
switch (op) {
case "push":
q ~= clr;
break;
case "pop":
q.back.writeln;
q.popBack;
default:
}
}
}
|
D
|
void main() {
problem();
}
void problem() {
auto N = scan!ulong;
ulong solve() {
// Sum_{k=1..n} k/2 * floor(n/k) * floor(1 + n/k)
ulong ans;
foreach(k; 1..N+1) {
ulong x = k * cast(ulong)floor(cast(real)N/k) * cast(ulong)floor(1 + cast(real)N/k);
ans += x / 2;
}
return ans;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Queue = Tuple!(long, "from", long, "to");
// -----------------------------------------------
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;
import std.range;
void main()
{
auto w = readln.chomp.toLower;
string[] ss;
while(1){
auto line = readln.chomp;
if(line == "END_OF_TEXT") break;
ss ~= line.toLower.split;
}
writeln(ss.count(w));
}
|
D
|
import std.stdio,
std.string,
std.conv,
std.algorithm;
void main() {
int[] buf = readln.chomp.split.to!(int[]);
int a = buf[0] - 1, b = buf[1] - 1;
int K = 50;
char[100][100] m;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K * 2; j++) {
m[i][j] = '#';
}
}
for (int i = K; i < K * 2; i++) {
for (int j = 0; j < K * 2; j++) {
m[i][j] = '.';
}
}
for (int i = 1; i < K - 1; i += 2) {
if (a <= 0) break;
for (int j = 1; j < K * 2; j += 2) {
if (a <= 0) break;
m[i][j] = '.';
a--;
}
}
for (int i = K + 1; i < K * 2; i += 2) {
if (b <= 0) break;
for (int j = 1; j < K * 2; j += 2) {
if (b <= 0) break;
m[i][j] = '#';
b--;
}
}
writeln("100 100");
foreach(line; m) {
writeln(line);
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.