code stringlengths 4 1.01M | language stringclasses 2 values |
|---|---|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int n, a, b;
scan(n, a, b);
writeln(min(n*a, b));
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
} | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto N = readln.chomp.to!int;
auto Comb = new Combination();
if (N == 2) {
writeln(1);
return;
}
if (N == 3) {
writeln(4);
return;
}
long ans = 0;
auto steps = new long[](N+1);
foreach (k; 2..N+1) {
steps[k] = Comb.comb(k-1, N-k-1) * Comb.fact(k) % MOD * Comb.fact(N-k-1) % MOD;
}
foreach_reverse(k; 2..N+1) {
if (steps[k] == 0) continue;
steps[k] = steps[k] - steps[k-1];
steps[k] = (steps[k] % MOD + MOD) % MOD;
ans = (ans + steps[k] * k % MOD) % MOD;
}
ans.writeln;
}
class Combination {
immutable int MAX = 2*10^^6+1;
immutable long MOD = 10^^9+7;
long[] modinv;
long[] f_mod;
long[] f_modinv;
this() {
modinv = new long[](MAX);
modinv[0] = modinv[1] = 1;
foreach(i; 2..MAX) {
modinv[i] = modinv[MOD.to!int % i] * (MOD - MOD / i) % MOD;
}
f_mod = new long[](MAX);
f_modinv = new long[](MAX);
f_mod[0] = f_mod[1] = 1;
f_modinv[0] = f_modinv[1] = 1;
foreach(i; 2..MAX.to!int) {
f_mod[i] = (i * f_mod[i-1]) % MOD;
f_modinv[i] = (modinv[i] * f_modinv[i-1]) % MOD;
}
}
long comb(int n, int k) {
if (n < 0 || k < 0 || n < k) return 0;
return f_mod[n] * f_modinv[n-k] % MOD * f_modinv[k] % MOD;
}
long fact(int n) {
if (n < 0) return 0;
return f_mod[n];
}
}
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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long h, w;
scan(h, w);
auto wall = new string[](h);
foreach (ref e; wall)
{
e = sread();
}
// wall.writeln();
bool ok = true;
foreach (i; iota(h))
{
foreach (j; iota(w))
{
if (wall[i][j] == '#')
{
ok &= canpaint(wall, i, j);
}
}
}
if (ok)
writeln("Yes");
else
writeln("No");
}
bool canpaint(ref string[] wall, long i, long j)
{
bool ret;
// i.write(" "), j.writeln();
if (i - 1 >= 0)
ret |= (wall[i - 1][j] == '#');
if (i + 1 < wall.length)
ret |= (wall[i + 1][j] == '#');
if (j - 1 >= 0)
ret |= (wall[i][j - 1] == '#');
if (j + 1 < wall[i].length)
ret |= (wall[i][j + 1] == '#');
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
int sum_p, max_p;
foreach (_; 0..N) {
auto p = readln.chomp.to!int;
sum_p += p;
max_p = max(max_p, p);
}
writeln(sum_p - max_p / 2);
} | D |
import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.range;
void main(){
auto F=readln.split.to!(int[]),A=F[0],B=F[1];
if(A+B>=24)writeln((A+B)-24);
else writeln(A+B);
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.format;
void main()
{
string s = chomp(readln());
string[] array = s.split(" ");
int W = to!int(array[0]);
int H = to!int(array[1]);
int x = to!int(array[2]);
int y = to!int(array[3]);
int r = to!int(array[4]);
// (0, 0) <= (x, y) <= (W, H)
int left = x - r;
int right = x + r;
if ( (0 <= left && left <= W) &&
(0 <= right && right <= W)) {
} else {
writeln("No");
return;
}
int upper = y + r;
int bottom = y - r;
if ( (0 <= upper && upper <= H) &&
(0 <= bottom && bottom <= H)) {
writeln("Yes");
} else {
writeln("No");
}
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
int binarySearch(alias pred, T)(in T[] arr, bool isLower = true)
{
int ok, ng;
if (isLower) { ok = cast(int)arr.length; ng = -1; }
else { ok = -1; ng = cast(int)arr.length; }
while (abs(ok-ng) > 1)
{
auto mid = (ok+ng) / 2;
if (unaryFun!pred(arr[mid]))
ok = mid;
else ng = mid;
}
return ok;
}
void main()
{
auto s = RD!string;
auto t = RD!string;
auto len = s.length;
auto next = new long[][](26);
foreach (i, c; s)
{
next[c-'a'] ~= i;
}
long i;
long ans;
bool f(long pos)
{
return pos >= i%len;
}
while (!t.empty)
{
auto n = next[t[0]-'a'];
auto l = binarySearch!(f)(n);
debug writeln(t[0], " ", i%len, " l:", l);
if (l == n.length)
{
i += len - i%len;
auto l2 = binarySearch!(f)(n);
debug writeln(t[0], " ", i%len, " l2:", l2);
if (l2 == n.length)
{
ans = -1;
break;
}
else
{
i = (i / len) * len + n[l2] + 1;
ans = i;
}
}
else
{
i = (i / len) * len + n[l] + 1;
ans = i;
}
t.popFront;
debug writeln(ans);
}
writeln(ans);
stdout.flush();
debug readln();
} | D |
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
void main() {
auto nm = readln.chomp.split.to!(int[]);
if(nm[0]==nm[1]) writeln("Yes");
else writeln("No");
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(long[]), x = rd[0], y = rd[1];
auto c = 1;
for (;;) {
x *= 2;
if (x > y) break;
++c;
}
writeln(c);
}
| D |
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;
string my_readln() { return chomp(readln()); }
void main()
{
auto tokens = my_readln().split();
auto A = tokens[0].to!uint;
auto B = tokens[1].to!uint;
auto C = tokens[2].to!uint;
writeln(A * B / 2);
stdout.flush();
} | D |
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
auto rd = readln.split.map!(to!int);
auto a = rd[0], b = rd[1], c = rd[2];
auto d = 0;
foreach (i; a..b + 1)
if (c % i == 0) ++d;
writeln(d);
} | 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 a = new int[][](3, 3);
foreach (i; 0..3) {
a[i] = readln.chomp.split.to!(int[]);
}
auto n = readln.chomp.to!int;
foreach (_; 0..n) {
auto b = readln.chomp.to!int;
foreach (i; 0..3) {
foreach (j; 0..3) {
if (a[i][j] == b) {
a[i][j] = -1;
}
}
}
}
auto f = false;
foreach (i; 0..3) {
int sum1, sum2, sum3, sum4;
foreach (j; 0..3) {
sum1 += a[i][j];
sum2 += a[j][i];
sum3 += a[j][j];
sum4 += a[j][2-j];
}
if (sum1 == -3 || sum2 == -3 || sum3 == -3 || sum4 == -3) {
f = true;
}
}
if (f) {
writeln("Yes");
} else {
writeln("No");
}
}
| D |
import std.conv, std.stdio;
import std.algorithm, std.array, std.string, std.range;
void main()
{
auto s = cast(ubyte[])readln.chomp;
(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No").writeln;
}
| 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;
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;
auto a = cin.nextArray!int(3);
writeln(min(abs(a[1] - a[0]) + abs(a[2] - a[1]), abs(a[2] - a[1]) + abs(a[0] - a[2]), abs(a[0] - a[2]) + abs(a[1] - a[0])));
}
| D |
// unihernandez22
// https://atcoder.jp/contests/abc076/tasks/abc076_c
// string manipulation
import std.stdio;
import std.string;
void main() {
string s = readln.chomp;
string t = readln.chomp;
ulong idx = -1;
bool matched;
foreach(i; 0..(s.count-t.count)+1) {
if (s[i] == '?' || s[i] == t[0]) {
matched = true;
foreach(j; 0..t.count) {
if (s[i+j] != '?' && s[i+j] != t[j]) {
matched = false;
break;
}
}
if (matched)
idx = i;
}
}
if (idx == -1) {
writeln("UNRESTORABLE");
return;
}
foreach(i; 0..s.count) {
if (s[i] == '?' && (i < idx || i >= t.count+idx))
write("a");
else if (s[i] == '?')
write(t[i-idx]);
else
write(s[i]);
} 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 n = readln.chomp.to!int;
auto s = readln.chomp.to!(char[]).array;
auto k = readln.chomp.to!int;
auto c = s[k-1];
foreach (ref e; s) {
if (e != c) {
e = '*';
}
}
s.writeln;
}
| D |
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s = readln.chomp;
writeln(s[0 .. min($, 4)] == "YAKI" ? "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.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto S = RD!string;
if (N % 2 == 1)
writeln("No");
else
{
bool ans = true;
foreach (i; 0..N/2)
{
if (S[i] != S[N/2+i])
ans = false;
}
writeln(ans ? "Yes" : "No");
}
stdout.flush();
debug readln();
} | D |
const int max = 1000000;
void main(){
int s = _scan();
int[int] dic;
dic[s]++;
// 初項sでa_1, ... なので2から始まる
foreach(i; 2..max+1){
if(s&1) s = 3*s +1;
else s = s/2;
dic[s]++;
if(dic[s]==2){
i.writeln();
break;
}
}
}
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;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main(){
auto N=readln.chomp.to!int;
auto K=readln.chomp.to!int;
auto X=readln.chomp.to!int;
auto Y=readln.chomp.to!int;
if(N>K)writeln(X*K+(N-K)*Y);
else writeln(N*X);
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int;
auto a = readln.chomp.to!int;
writeln(n*n-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;
void main() {
int n;
long x;
scan(n, x);
auto a = new long[](n + 1); // 長さ
auto b = new long[](n + 1); // Pの枚数
a[0] = b[0] = 1;
foreach (i ; 1 .. n + 1) {
a[i] = 2L*a[i-1] + 3;
b[i] = 2L*b[i-1] + 1;
}
long query(int L, long x) {
if (L == 0) {
return x == 1;
}
if (x <= 1) {
return 0;
}
else if (x < (a[L] + 1) / 2) {
return query(L-1, x - 1);
}
else if (x == (a[L] + 1) / 2) {
return b[L-1] + 1;
}
else if (x < a[L] - 1) {
return b[L-1] + 1 + query(L-1, x - (a[L] + 1) / 2);
}
else {
return 2*b[L-1] + 1;
}
}
long ans = query(n, x);
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, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int h, w;
scan(h, w);
auto map = new char[][](h, w);
iota(h).each!(i => map[i] = readln.chomp.to!(char[]));
if (map[0][0] != '#') {
writeln("Impossible");
return;
}
int pi, pj;
while (!(pi == h-1 && pj == w-1)) {
int ni = pi + 1, nj = pj;
if (ni < h && map[ni][nj] == '#') {
map[pi][pj] = '.';
pi = ni, pj = nj;
continue;
}
ni = pi, nj = pj + 1;
if (nj < w && map[ni][nj] == '#') {
map[pi][pj] = '.';
pi = ni, pj = nj;
continue;
}
writeln("Impossible");
return;
}
if (map[h-1][w-1] != '#') {
writeln("Impossible");
return;
}
map[h-1][w-1] = '.';
debug {
writefln("%(%-(%s %)\n%)", map);
}
foreach (i ; 0 .. h) {
foreach (j ; 0 .. w) {
if (map[i][j] == '#') {
writeln("Impossible");
return;
}
}
}
writeln("Possible");
return;
}
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.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;
alias Edge = Tuple!(int, "u", int, "v");
long[] f(long x) {
if (x == 0) {
long[] ans = new long[](42);
return ans;
} else if (x == 1) {
long[] ans = new long[](42);
ans[0] = 1;
return ans;
}
long b = x;
long[] ans;
if (b % 4 == 0 || b % 4 == 3) {
ans ~= 0;
} else {
ans ~= 1;
}
foreach (i; 1..42) {
long v = 1L << (i + 1);
if (b % v < v / 2) {
ans ~= 0;
} else if (b % v % 2 == 0) {
ans ~= 1;
} else {
ans ~= 0;
}
}
return ans;
}
void main() {
auto s = readln.split.map!(to!long);
auto A = s[0];
auto B = s[1];
A = max(0L, A-1);
long ans = 0;
long[] fa = f(A);
long[] fb = f(B);
foreach (i; 0..fa.length) {
ans |= (fa[i] ^ fb[i]) << i;
}
ans.writeln;
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto N = readln.chomp.to!long;
long[] AS;
long a_sum;
foreach (a; readln.split.to!(long[])) {
AS ~= a;
a_sum += a;
}
if (N == 1) {
writeln("YES");
return;
}
auto x = N*(N+1) / 2;
if (a_sum % x != 0) {
writeln("NO");
return;
}
auto K = a_sum / x;
long[] ds;
foreach (i; 0..N) ds ~= AS[(i+1)%N] - AS[i];
long k;
foreach (d; ds) {
if (d > K || (K-d) % N != 0) {
writeln("NO");
return;
}
k += (K-d) / N;
}
writeln(k == K ? "YES" : "NO");
} | D |
import std.stdio,std.conv,std.string;
void main(){
auto m=readln.chomp.to!int;
auto t=m/500;
auto f=(m%500)/5;
(t*1000+f*5).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 a, b; string op; readV(a, op, b);
writeln(op == "+" ? a+b : a-b);
}
| D |
import std.stdio, std.string, std.conv, std.algorithm;
void main() {
readln;
auto S = readln.chomp.map!(a => a == 'I' ? 1 : -1);
auto c = 0;
auto res = 0;
foreach (s; S) {
c += s;
res = max(res, c);
}
writeln(res);
}
| D |
import std.stdio;
import std.conv;
import std.string;
void main() {
int N = to!int(readln.chomp);
int i = 1;
while (i * i <= N) { i++; }
i--; i *= i;
i.writeln;
} | D |
void main() {
int n = readln.chomp.to!int;
long[] lucas = new long[n+1];
lucas[0] = 2, lucas[1] = 1;
foreach (i; 2 .. n+1) {
lucas[i] = lucas[i-1] + lucas[i-2];
}
lucas[n].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 : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;
void main(){
int cnt;
bool flag1 = false;
bool ans = true;
foreach( c; next!string ){
if( c == '4' ){
ans &= flag1 || cnt>0;
if( ++cnt > 2 ){
ans &= false;
}
flag1 = false;
}else if( c == '1' ){
flag1 = true;
cnt = 0;
}else{
ans &= false;
}
}
writeln = ans ? "YES" : "NO";
}
import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
assert(hasNext());
}
out
{
input.popFront;
}
body
{
return input.front.to!T;
}
T next( T : char )()
in
{
assert(hasNext());
}
out
{
input.front.popFront;
}
body
{
return input.front.front.to!T;
}
bool hasNext(){
if(input.length > 0){
if(input.front.length == 0){
input.popFront;
return hasNext;
}
return true;
}
string str = readln;
if(str.length > 0){
input ~= str.chomp.split(delim);
return hasNext;
}else{
return false;
}
}
void dbg(T...)(T vs)
{
import std.stdio : stderr;
foreach(v; vs)
stderr.write(v.to!string ~ " ");
stderr.write("\n");
}
T clone(T)(T v){
T v_;
static if(isInputRange!(T)){
foreach(ite; v){
v_ ~= ite.clone;
}
}else{
v_ = v;
}
return v_;
}
| 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);
long n, m;
sc.read(n, m);
n = min(n, 60);
writeln(m % (2L ^^ n));
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 std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto T = RD!int;
auto ans = new long[](T);
foreach (i; 0..T)
{
auto x = RD!(char[]);
auto y = RD!(char[]);
x.reverse;
y.reverse;
int pos;
while (y[pos] == '0')
++pos;
long tmp;
foreach (j; pos..x.length)
{
if (x[j] == '1')
{
debug writeln("j:pos ", j, " ", pos);
tmp = j - pos;
break;
}
}
ans[i] = tmp;
}
foreach (e; ans)
writeln(e);
stdout.flush();
debug readln();
} | D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.exception, std.random;
long a, b; rd(a, b);
// auto rnd=Random(unpredictableSeed);
// long a=uniform(1, 100, rnd), b=uniform(1, 100, rnd);
while(a>0 && b>0){
if(a>=b*2){
auto m=a/b;
if(m&1) m--;
enforce(m>=2);
a-=b*m;
}else if(a*2<=b){
auto m=b/a;
if(m&1) m--;
enforce(m>=2);
b-=a*m;
}else{
break;
}
}
writeln(a, " ", b);
// f(a, b);
}
void f(long a, long b){
import std.stdio;
while(a>0 && b>0){
if(a>=b*2) a-=b*2;
else if(a*2<=b) b-=a*2;
else break;
}
writeln(a, " ", b);
}
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 |
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;
// MIT-License https://github.com/kurokoji/nephele
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() {
Scanner sc = new Scanner;
int N;
long sum = 0;
sc.scan(N);
foreach (i; 1 .. N + 1) {
if (i % 3 != 0 && i % 5 != 0)
sum += i;
}
writeln(sum);
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 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, "damage", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long n, m, k;
scan(n, m, k);
// 総当り
bool flag;
foreach (i; iota(n + 1))
{
auto black = m * i;
foreach (_; iota(m + 1))
{
black += (n - 2 * i);
if (black == k)
flag = true;
}
}
if (flag)
writeln("Yes");
else
writeln("No");
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
| D |
import core.bitop, 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 dp = new long[][](4, S.length + 1);
dp[0][0] = 1;
foreach (i; 0 .. S.length)
{
dp[0][i + 1] = dp[0][i];
dp[1][i + 1] = dp[1][i];
dp[2][i + 1] = dp[2][i];
dp[3][i + 1] = dp[3][i];
if (S[i] == 'A')
{
dp[1][i + 1] += dp[0][i];
}
if (S[i] == 'B')
{
dp[2][i + 1] += dp[1][i];
}
if (S[i] == 'C')
{
dp[3][i + 1] += dp[2][i];
}
if (S[i] == '?')
{
// writeln(i);
dp[1][i + 1] += dp[0][i];
dp[2][i + 1] += dp[1][i];
dp[3][i + 1] += dp[2][i];
dp[0][i + 1] += dp[0][i] * 2;
dp[1][i + 1] += dp[1][i] * 2;
dp[2][i + 1] += dp[2][i] * 2;
dp[3][i + 1] += dp[3][i] * 2;
}
dp[0][i + 1] %= MOD;
dp[1][i + 1] %= MOD;
dp[2][i + 1] %= MOD;
dp[3][i + 1] %= MOD;
}
// writeln(dp[0]);
// writeln(dp[1]);
// writeln(dp[2]);
// writeln(dp[3]);
writeln(dp[3][S.length]);
}
| D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto r = readln.chomp.to!int;
writeln(3 * r * r);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
int[char] aa = ['J':0, 'O':1, 'I':2];
int N = readln.chomp.to!int;
string str = readln.chomp;
int[] dp = new int[2^^3];
dp[1] = 1;
foreach(char c; str) {
int[] _dp = dp.dup;
dp[] = 0;
foreach(int i; 0..2^^3) foreach(int j; 0..2^^3) {
if ((i&j)!=0 && (j&1<<aa[c])!=0) {
dp[j] = (_dp[i]+dp[j])%10007;
}
}
}
reduce!("(a+b)%10007")(0, dp).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 ip = readln.split.to!(ulong[]);
immutable x = ip[0], a = ip[1];
ulong ret;
if (x<a) ret = 0;
else ret = 10;
writeln(ret);
}
| D |
import std.stdio, std.algorithm, std.array, std.string, std.conv;
void main()
{
int t;
scanf("%d", &t);
foreach(_; 0..t)
{
int str_len;
scanf("%d", &str_len);
getchar();
auto str = readln.strip();
// writeln(str);
int[] check = new int[str_len];
bool flag = true;
for(int i = 0; i < str_len; i++)
{
if (flag == false)
break;
if (str[i] == 'a')
{
for (int j = i; j >= 0; j--)
{
check[j] += 1;
if (check[j] == 0)
{
writeln(j + 1,' ', i + 1);
flag = false;
}
}
}
else
{
for (int j = i; j >= 0; j--)
{
check[j] -= 1;
if (check[j] == 0)
{
writeln(j + 1,' ', i + 1);
flag = false;
}
}
}
}
if (flag)
writeln("-1 -1");
}
} | D |
import std.stdio;
import std.string;
import std.conv;
void main() {
string input = readln();
char X = input[0];
char Y = input[2];
if(X < Y) writeln("<");
else if(X > Y) writeln(">");
else writeln("=");
}
| D |
void main()
{
long n = rdElem;
long[string] list;
string s = rdStr;
++list[s];
foreach (i; 1 .. n)
{
string w = rdStr;
if (s[$-1] != w[0] || w in list)
{
"No".writeln;
return;
}
++list[w];
s = w;
}
"Yes".writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop; | D |
void main()
{
string s = readln.chomp;
s.count('1').writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio, std.algorithm, std.range, std.conv, std.string;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n;
scanf("%d", &n);
int[] a = new int[n];
int[] b = new int[n];
foreach (i; 0..n) scanf("%d", &a[i]);
foreach (i; 0..n) scanf("%d", &b[i]);
int ans = 0;
foreach (k; 0..29) {
int mask = (1<<k)-1;
int s = 0;
if (n&1) {
foreach (x; a) s ^= x>>k&1;
foreach (x; b) s ^= x>>k&1;
}
int[] c = new int[n];
c[] = b[]&mask;
sort(c);
auto sorted = assumeSorted(c);
foreach (x; a) {
x &= mask;
int l = n - to!int(sorted.lowerBound((1<<k)-x).length);
s ^= l&1;
}
ans |= s<<k;
}
writeln(ans);
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
auto s=readln.chomp.to!(char[]);
int x, y; rd(x, y);
auto n=s.length;
int[] dxs, dys;
for(int i=0, t=1; i<n; i++, t^=1){
int d=0;
while(i<n && s[i]=='F') i++, d++;
if(d==0) continue;
if(t&1) dxs~=d;
else dys~=d;
}
// wr(dxs); wr(dys);
auto xlen=dxs.length, ylen=dys.length;
auto xrec=new bool[][](xlen+1, 8000*3);
auto yrec=new bool[][](ylen+1, 8000*3);
auto ofse=8000*3/2;
xrec[0][ofse]=yrec[0][ofse]=true;
foreach(i; 0..xlen)for(auto j=0; j<=22000; j++){
if(xrec[i][j]){
xrec[i+1][j+dxs[i]]=true;
if((i>0) || (s[0]=='T')) xrec[i+1][j-dxs[i]]=true;
}
}
foreach(i; 0..ylen)for(auto j=0; j<=22000; j++){
if(yrec[i][j]){
yrec[i+1][j+dys[i]]=true;
yrec[i+1][j-dys[i]]=true;
}
}
if(xrec[xlen][x+ofse] && yrec[ylen][y+ofse]) writeln("Yes");
else writeln("No");
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) stderr.write(e, " ");
stderr.writeln();
} | D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
import std.math : abs;
int n;
rd(n);
auto m = n / 2 + 1;
writeln(m);
for (int i = 1, r = 1, c = 1; i <= n; i++) {
writeln(r, " ", c);
if (i & 1) {
c++;
} else {
r++;
}
}
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
| D |
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
void main() {
string s, maxls, maxas;
int[string] nums;
while( (s=readln()).length != 0 ){
string[] input = split(s);
foreach(int i, string ts; input){
nums[ts]++;
if(maxls.length<ts.length) maxls=ts;
}
}
int mn=-1;
foreach(string key, int n; nums){
if(mn<n){
mn=n;
maxas=key;
}
}
writeln(maxas, " ", maxls);
} | D |
void main(){
int d = _scan();
switch(d){
case 22: writeln("Christmas Eve Eve Eve"); break;
case 23: writeln("Christmas Eve Eve"); break;
case 24: writeln("Christmas Eve"); break;
default:writeln("Christmas"); break;
}
}
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;
import core.stdc.stdio;
import std.algorithm.comparison;
int f(int x, int cnt) {
return (x % 2 == 1 ? cnt : f(x / 2, cnt + 1));
}
void main() {
int n;
scanf("%d", &n);
int ans = 1 << 30;
foreach(i; 0..n) {
int x;
scanf("%d", &x);
ans = min(ans, f(x, 0));
}
writeln(ans);
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int;
if (n % 2 == 0) {
n.writeln;
} else {
writeln(2 * n);
}
}
| D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int n;
scan(n);
auto ans = (n + 1) / 2;
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 |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n, m;
rd(n, m);
writeln((2 ^^ m) * ((1900 * m) + (100 * (n - m))));
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
| D |
import 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(N % K == 0 ? 0 : 1);
stdout.flush();
debug readln();
}
| D |
module app;
import core.bitop;
import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;
struct Input
{
string s;
}
void parseInput(T)(out Input input, T file)
{
with (file) with (input)
{
s = readln().strip();
}
}
auto main2(Input* input)
{
with (input)
{
switch (s)
{
case "hi":
case "hihi":
case "hihihi":
case "hihihihi":
case "hihihihihi":
return "Yes";
default:
return "No";
}
}
}
alias retType = ReturnType!main2;
static if (!is(retType == void))
{
unittest { writeln("begin unittest"); }
auto _placeholder_ = ReturnType!main2.init;
unittest // example1
{
string example =
`hihi`;
if (example.empty) return;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
printResult(result);
assert(result == "Yes");
}
unittest // example2
{
string example =
`hi`;
if (example.empty) return;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
printResult(result);
assert(result == "Yes");
}
unittest // example3
{
string example =
`ha`;
if (example.empty) return;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
printResult(result);
assert(result == "No");
}
unittest { writeln("end unittest"); }
void parseExample(out Input input, string example)
{
struct Adapter
{
string[] _lines;
this(string input) { _lines = input.splitLines(); }
string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
}
parseInput(input, Adapter(example));
}
}
void printResult(T)(T result)
{
static if (isFloatingPoint!T) writefln("%f", result);
else writeln(result);
}
void main()
{
Input input = void;
parseInput(input, stdin);
static if (is(retType == void))
main2(&input);
else
{
auto result = main2(&input);
printResult(result);
}
}
| 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, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto k = lread();
long s;
foreach (i; iota(1, k + 1))
{
foreach (j; iota(1, k + 1))
{
auto tmp = gcd(i, j);
foreach (l; iota(1, k + 1))
{
s += gcd(tmp, l);
}
}
}
s.writeln();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
| D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
auto n=scanElem+scanElem;
if(n>=10)end("error");end(n);
}
| 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 n; readV(n);
foreach (i; 0..n/4+1)
if ((n-i*4)%7 == 0) {
writeln("Yes");
return;
}
writeln("No");
}
| D |
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
auto tmp = readln.split.to!(int[]);
auto H = tmp[0], W = tmp[1];
string[] A;
foreach (i; 0..H) {
auto as = readln.chomp;
if (as.all!(a => a == '.')) continue;
A ~= as;
}
bool[] flags = new bool[W];
foreach (i; 0..W) {
flags[i] = A.all!(as => as[i] == '.');
}
foreach (i; 0..A.length) {
foreach (j; 0..W) {
if (flags[j]) continue;
write(A[i][j]);
}
writeln;
}
}
| D |
import std.stdio, std.string, std.conv;
void main(){
auto ip = readln.split.to!(int[]);
writeln(ip[0] - ip[1] + 1);
} | D |
import std;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long A, B, C, D;
scan(A, B, C, D);
long t = (C + B - 1) / B;
long a = (A + D - 1) / D;
writeln((t <= a) ? "Yes" : "No");
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp;
foreach (c; N) if (c == '7') {
writeln("Yes");
return;
}
writeln("No");
} | D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
int n = readint;
int k = readint;
int ans = 1;
for (int i = 0; i < n; i++) {
ans = min(ans * 2, ans + k);
}
writeln(ans);
}
| D |
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
string my_readln() { return chomp(readln()); }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto S = my_readln;
auto tokens = my_readln.split;
auto K = tokens[0].to!ulong;
string ans;
foreach (i, e; S)
{
if (i == K - 1 || e != '1')
{
ans ~= e;
break;
}
}
writeln(ans);
stdout.flush();
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
int i;
foreach (c; readln.chomp.to!(char[])) {
if (c == '+') ++i;
if (c == '-') --i;
}
writeln(i);
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (i; 0..t)
{
auto n = RD!int;
auto s = RD!string;
long cnt1, cnt2;
foreach (j; 0..n)
{
if (s[j] == '1')
break;
++cnt1;
}
foreach_reverse (j; 0..n)
{
if (s[j] == '1')
break;
++cnt2;
}
if (cnt1 == n)
ans[i] = n;
else
ans[i] = n*2 - min(cnt1, cnt2)*2;
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush();
debug readln();
} | D |
import std.stdio, std.string, std.algorithm;
void main()
{
char[] input = chomp(readln()).dup;
char[] input2 = chomp(readln()).dup;
swap(input[0], input[2]);
if(input == input2) {
writeln("YES");
return;
} else {
writeln("NO");
return;
}
}
| D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long a,b;
scan(a,b);
if(a > 8 || b > 8)
{
writeln(":(");
}
else
{
writeln("Yay!");
}
} | D |
import std.stdio, std.string, std.conv;
void main() {
auto t = readln.split.to!(int[]);
writeln(t[0] <= t[2] && t[2] <=t[0]+t[1] ? "YES" : "NO");
}
| D |
import core.stdc.stdio;
import std.range;
import std.algorithm;
void main(){
int[] buf_p = new int[1001];
int[] buf_d = new int[1001*500];
while(1){
int n,m;
scanf("%d%d",&n,&m);
if(n==0&&m==0)
break;
int[] p = buf_p[0..++n];
foreach(ref v;p[1..$])
scanf("%d",&v);
p[0]=0;
int[] d=buf_d[0..n*(n-1)/2];
int c=0;
foreach(i;0..n)
foreach(j;i+1..n)
d[c++] = p[i]+p[j];
sort(d);
int ans;
foreach(v;d){
if(v*2>m)
break;
auto lb = d.assumeSorted.lowerBound(m+1-v);
if(!lb.empty)
ans=max(ans,v+lb[$-1]);
}
printf("%d\n",ans);
}
} | D |
/+ dub.sdl:
name "B"
dependency "dunkelheit" version="1.0.1"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner, dkh.algorithm;
int main() {
Scanner sc = new Scanner(stdin);
scope(exit) assert(!sc.hasNext);
string s;
sc.read(s);
if (s.count('o') + (15 - s.length.to!int) >= 8) {
writeln("YES");
} else {
writeln("NO");
}
return 0;
}
/* IMPORT /home/yosupo/Programs/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/Programs/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/Programs/dunkelheit/source/dkh/algorithm.d */
// module dkh.algorithm;
import std.traits : isFloatingPoint, isIntegral;
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
while (r-l > 1) {
T md = l + (r-l) / 2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
foreach (i; 0..cnt) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
import std.range.primitives;
E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}
ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "minimum: range must not empty");
auto e = range.front; range.popFront;
return minimum!pred(range, e);
}
E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}
ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "maximum: range must not empty");
auto e = range.front; range.popFront;
return maximum!pred(range, e);
}
Rotator!Range rotator(Range)(Range r) {
return Rotator!Range(r);
}
struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
size_t cnt;
Range start, now;
this(Range r) {
cnt = 0;
start = r.save;
now = r.save;
}
this(this) {
start = start.save;
now = now.save;
}
@property bool empty() const {
return now.empty;
}
@property auto front() const {
assert(!now.empty);
import std.range : take, chain;
return chain(now, start.take(cnt));
}
@property Rotator!Range save() {
return this;
}
void popFront() {
cnt++;
now.popFront;
}
}
/* IMPORT /home/yosupo/Programs/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;
private File f;
this(File f) {
this.f = f;
}
private char[512] lineBuf;
private 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) {
assert(succW());
x[i] = line.parse!E;
}
} else {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(Args...)(auto ref Args args) {
import std.exception : enforce;
static if (args.length != 0) {
enforce(readSingle(args[0]));
read(args[1..$]);
}
}
bool hasNext() {
return succ();
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
| D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int x;
scan(x);
int ans = 1;
foreach (i ; 2 .. x + 1) {
for (int d = i*i; d <= x; d *= i) {
ans = max(ans, d);
}
}
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 |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
auto S = sread();
long[string] D;
foreach (i; 0 .. N)
{
auto K = D.keys;
foreach (key; K)
{
if (key.length == 3)
continue;
D[key ~ S[i]] = 1;
}
D[S[i .. i + 1]] = 1;
}
writeln(D.keys.filter!"a.length == 3"().map!"1"().sum());
}
| D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
long[] arr = [N];
for (long i = 2; i*i <= N; ++i)
{
if (N % i == 0)
{
arr ~= i;
}
}
auto x = arr[$-1];
auto y = N / x;
writeln(x+y-2);
stdout.flush();
debug readln();
} | D |
import std.stdio,std.string,std.conv,std.array,std.algorithm;
void main(){
for(;;write("\n")){
auto a = readln().chomp().split();
if( a[0]=="0" && a[1]=="0" ){ break; }
int h=to!int(a[0]) , w=to!int(a[1]);
foreach(y;0..h){
foreach(x;0..w){
if( 0<x && x<w-1 && 0<y && y<h-1 ){
write(".");
}else{
write("#");
}
}
write("\n");
}
}
} | D |
/+ dub.sdl:
name "B"
dependency "dcomp" version=">=0.7.3"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.dungeon;
int main() {
Scanner sc = new Scanner(stdin);
int h, w;
sc.read(h, w);
auto dh = DungeonHelper(h, w);
char[][] g = new char[][h];
foreach (i; 0..h) {
sc.read(g[i]);
}
foreach (i; 0..h) {
foreach (j; 0..w) {
if (g[i][j] != '.') continue;
char c = '0';
foreach (d; 0..8) {
auto u = dh.move8([j, i], d);
int ni = u[1], nj = u[0];
if (!dh.isInside(u)) continue;
if (g[ni][nj] == '#') c++;
}
g[i][j] = c;
}
writeln(g[i]);
}
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/dungeon.d */
// module dcomp.dungeon;
struct DungeonHelper {
immutable static int[2][4] d4 = [
[1, 0], [0, 1], [-1, 0], [0, -1],
];
immutable static int[2][8] d8 = [
[1, 0],
[1, 1],
[0, 1],
[-1, 1],
[-1, 0],
[-1, -1],
[0, -1],
[1, -1],
];
int h, w;
this(int h, int w) {
this.h = h; this.w = w;
}
bool isInside(int[2] p) const {
int x = p[0], y = p[1];
return 0 <= x && x < w && 0 <= y && y < h;
}
int getID(int[2] p) const {
int x = p[0], y = p[1];
return y*w+x;
}
int[2] move(int[2] p, int dir) const {
int[2] res;
res[] = p[] + d4[dir][];
return res;
}
int[2] move8(int[2] p, int dir) const {
int[2] res;
res[] = p[] + d8[dir][];
return res;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
// import dcomp.array;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
FastAppender!(E[]) buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;
T[N] fixed(T, size_t N)(T[N] a) {return a;}
struct FastAppender(A, size_t MIN = 4) {
import std.algorithm : max;
import std.conv;
import std.range.primitives : ElementEncodingType;
import core.stdc.string : memcpy;
private alias T = ElementEncodingType!A;
private T* _data;
private uint len, cap;
@property size_t length() const {return len;}
bool empty() const { return len == 0; }
void reserve(size_t nlen) {
import core.memory : GC;
if (nlen <= cap) return;
void* nx = GC.malloc(nlen * T.sizeof);
cap = nlen.to!uint;
if (len) memcpy(nx, _data, len * T.sizeof);
_data = cast(T*)(nx);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void opOpAssign(string op : "~")(T item) {
if (len == cap) {
reserve(max(MIN, cap*2));
}
_data[len++] = item;
}
void insertBack(T item) {
this ~= item;
}
void removeBack() {
len--;
}
void clear() {
len = 0;
}
ref inout(T) back() inout { assert(len); return _data[len-1]; }
ref inout(T) opIndex(size_t i) inout { return _data[i]; }
T[] data() {
return (_data) ? _data[0..len] : null;
}
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/
| D |
import std.stdio;
import std.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()
{
int cnt;
foreach (line; stdin.byLine) {
auto s = line.chomp;
auto t = s.dup.reverse;
if (s == t) cnt++;
}
cnt.writeln;
} | D |
// import chie template :) {{{
import std.stdio,
std.algorithm,
std.array,
std.string,
std.math,
std.conv,
std.range,
std.container,
std.bigint;
// }}}
void main() {
int n = readln.chomp.to!int;
writeln(24 + (24 - n));
}
| D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int k = readint;
int even = k / 2;
writeln(even * (k - even));
}
| 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 n, k; readV(n, k);
writeln(n == k ? 1 : (n-2)/(k-1)+1);
}
| D |
void main()
{
long[] tmp = readln.split.to!(long[]);
long n = tmp[0], a = tmp[1], b = tmp[2];
max(0, (n - 2) * (b - a) + 1).writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto st = readln.split.to!(string[]);
writeln(st[1] ~ st[0]);
} | 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 readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}
void main()
{
int n; readV(n);
int[] a; readC(n, a); a[] -= 1;
auto v = new bool[](n), c = 0, b = 0;
v[0] = true;
for (;;) {
b = a[b];
if (v[b]) {
writeln(-1);
return;
}
++c;
if (b == 1) {
writeln(c);
return;
}
v[b] = true;
}
}
| D |
import std.stdio;
import std.algorithm;
import std.conv;
import std.numeric;
import std.math;
import std.string;
void main()
{
auto tokens = split(chomp(readln()));
auto N = to!ulong(tokens[0]);
auto T = to!ulong(tokens[1]);
ulong c_min;
c_min = ulong.max;
foreach (i; 0..N)
{
auto tokens1 = split(chomp(readln()));
auto c = to!ulong(tokens1[0]);
auto t = to!ulong(tokens1[1]);
if (t <= T && c < c_min)
{
c_min = c;
}
}
if (c_min == ulong.max) writeln("TLE");
else writeln(c_min);
stdout.flush();
} | D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long A, B, C, X, Y;
scan(A, B, C, X, Y);
long ans = long.max;
ans = ans.min(A * X + B * Y);
ans = ans.min(min(X, Y) * C * 2 + max(0, X - min(X, Y)) * A + max(0, Y - min(X, Y)) * B);
ans = ans.min(max(X, Y) * C * 2);
writeln(ans);
}
| D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
import std.numeric;
int n;
rd(n);
long l = 1;
long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
while (n--) {
long t;
rd(t);
l = lcm(l, t);
}
writeln(l);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
| D |
import 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(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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (ti; 0..t)
{
auto s = RD!string;
if (s.length % 2) continue;
bool ok = true;
long cnt0, cnt1, cnt2;
foreach (c; s)
{
if (c == '(')
++cnt0;
else if (c == '?')
++cnt2;
else
{
--cnt0;
if (cnt0 < 0)
{
--cnt2;
++cnt0;
}
if (cnt2 < 0)
{
ok = false;
break;
}
}
}
if (!ok) continue;
long cnt3, cnt4;
foreach_reverse (i; 0..s.length)
{
if (s[i] == '(')
{
++cnt3;
if (cnt3 > 0)
break;
}
else if (s[i] == ')')
{
--cnt3;
}
else
{
++cnt4;
}
}
ans[ti] = cnt0 <= cnt4;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
debug readln;
} | D |
import std.stdio; // ??\????????????????????????
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
import std.algorithm; // map?????????????????????
void main() {
auto input = readln.split.map!(to!int);
auto a = input[0];
auto b = input[1];
auto c = input[2];
if (a < b && b < c) {
writeln("Yes");
} else {
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(){
int n = read.to!int;
long[] as;
foreach(i; 0 .. n) as ~= read.to!long;
int[long] ac;
foreach(a; as){
if(a !in ac) ac[a] = 0;
ac[a] += 1;
}
string ans;
if(ac.keys.length > 3) ans = "No";
else if(ac.keys.length == 3){
long[] ks = ac.keys;
if(ac[ks[0]] == ac[ks[1]] && ac[ks[1]] == ac[ks[2]]
&& (ks[0] ^ ks[1]) == ks[2]) ans = "Yes";
else ans = "No";
}
else if(ac.keys.length == 2){
long[] ks = ac.keys;
if(ac[ks[0]] == ac[ks[1]] * 2 && (ks[0] ^ ks[0]) == ks[1]) ans = "Yes";
else if(ac[ks[0]] * 2 == ac[ks[1]] && (ks[0] ^ ks[1]) == ks[1]) ans = "Yes";
else ans = "No";
}
else if(ac.keys.length == 1){
long[] ks = ac.keys;
if(ks[0] == 0) ans = "Yes";
else ans = "No";
}
ans.writeln;
}
| D |
import std.stdio;
import std.string;
import std.conv,std.array,std.datetime;
void main(){
while(1){
auto cs = readln().chomp().split();
if( cs[0]=="0" ){ break; }
final switch( Date( 2004, to!int(cs[0]), to!int(cs[1])).dayOfWeek() ){
case 0:writeln("Sunday");break;
case 1:writeln("Monday");break;
case 2:writeln("Tuesday");break;
case 3:writeln("Wednesday");break;
case 4:writeln("Thursday");break;
case 5:writeln("Friday");break;
case 6:writeln("Saturday");break;
}
}
} | D |
import std.stdio,
std.conv,
std.array,
std.string;
void main() {
int n = to!int(chomp(readln()));
while(n--) {
string[] l = split(readln());
int a = to!int(l[0]);
int b = to!int(l[1]);
int c = to!int(l[2]);
if(a*a==b*b+c*c
||b*b==c*c+a*a
||c*c==a*a+b*b) {
writeln("YES");
}
else {
writeln("NO");
}
}
} | D |
// Cheese-Cracker: cheese-cracker.github.io
void play(){
int n, m;
n = rd!int;
m = rd!int;
int summ = 0, el;
foreach(i; 0..n){
el = rd!int;
summ += el;
}
if(summ == m){
writeln("YES");
}else{
writeln("NO");
}
}
int main(){
long t = 1;
t = rd; // Toggle!
while(t--) play(); // Let's play!
stdout.flush;
return 0;
}
/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x", long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int l, r, a; rd(l, r, a);
if(l>r) swap(l, r);
if(r-l>=a){writeln((l+a)*2); return;}
a-=(r-l);
if(a&1) a--;
writeln(r*2+a);
}
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
auto T = readln.chomp;
int[26] cs, ds;
foreach (i; 0..S.length) {
auto s = S[i] - 'a';
auto t = T[i] - 'a';
if (cs[s] == 0 && ds[t] == 0) {
cs[s] = t+1;
ds[t] = s+1;
} else if (cs[s] != t+1 || ds[t] != s+1) {
writeln("No");
return;
}
}
writeln("Yes");
} | 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();
foreach_reverse (i; 1 .. S.length - 1)
{
if (i % 2 == 0 && S[0 .. i / 2] == S[i / 2 .. i])
{
writeln(i);
return;
}
}
}
| 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, y;
cin.scan(x, y);
if (y % 2 == 0 && x * 2 <= y && y <= x * 4) {
writeln("Yes");
} else {
writeln("No");
}
}
| D |
import std.stdio, std.algorithm, std.array, std.string, std.conv;
void main() {
auto s = readln.chomp.to!(dchar[]);
if (s.length == 3) s.reverse();
writeln(s);
}
| D |
const int m=10000000+10;
bool[m] pp;
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
if(n==1){
writeln(0);
return;
}
if(n==2){
writeln(0);
return;
}
mp();
int cnt=0;
for(int p=1; p<=n; p++){
if(pp[p] && pp[p+2]){
cnt++;
}
}
writeln(cnt*2);
}
void mp(){
foreach(i; 0..m) pp[i]=true;
pp[0]=pp[1]=false;
for(int i=2; i*i<=m; i++){
if(pp[i]){
for(int j=2; i*j<m; j++){
pp[i*j]=false;
}
}
}
}
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.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto s = readln.chomp;
auto l_res = new int[](s.length + 1);
auto r_res = new int[](s.length + 1);
foreach (i; 0..s.length) {
if (s[i] == '<') {
l_res[i+1] = l_res[i] + 1;
}
if (s[$-1-i] == '>') {
r_res[$-1-i-1] = r_res[$-1-i] + 1;
}
}
long res;
foreach (i; 0..l_res.length) {
res += max(l_res[i], r_res[i]);
}
res.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.container;
import std.datetime;
void main()
{
while (1) {
auto x = readln.chomp.split.map!(to!int).array;
if (x[0] == 0) break;
x[1]--;
int winner, sum;
foreach (i; 0..x[0]) {
auto a = readln.chomp.to!int;
if (i == x[1]) winner = a;
sum += a;
}
if (!winner) writeln(0);
else {
writeln(sum * (100-x[2]) / winner);
}
}
} | D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.