code
stringlengths 4
1.01M
| language
stringclasses 2
values |
---|---|
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;
}
}
long apple(long a)
{
return a * 3;
}
void main()
{
long a, p;
scan(a, p);
p += apple(a);
writeln(p / 2);
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int n = scan!int;
int[] as = scan!int(n);
int amax = as[0];
foreach(a; as) amax.raiseTo(a);
int[] acnt = new int[](amax + 1);
foreach(a; as) acnt[a] += 1;
string ans = "Possible";
foreach(a, cnt; acnt){
if(a * 2 < amax){
if(cnt > 0) ans = "Impossible";
}
if(a * 2 == amax){
if(cnt != 1) ans = "Impossible";
}
if(a * 2 == amax + 1){
if(cnt != 2) ans = "Impossible";
}
if(a * 2 > amax + 1){
if(cnt <= 1) ans = "Impossible";
}
}
ans.writeln;
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], b = tmp[1], c = tmp[2];
writeln(min(c, b/a));
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;
import std.range;
import std.typecons;
void main()
{
for(string[] inputs; (inputs = readln.split)[0] != "0";)
writeln( solve( inputs[0].to!int, inputs[1].to!int ) );
}
int[][] G, D;
bool[][][] M;
int solve(int n, int m)
{
G = new int[][](n, n);
D = new int[][](n, 2);
M = new bool[][][](n, n, 2);
foreach(i; 0..n){
foreach(j; 0..n){
G[i][j] = (i == j ? 0 : int.max / 2);
M[i][j][0] = M[i][j][1] = false;
}
D[i][0] = D[i][1] = int.max / 2;
}
foreach(_; 0..m){
auto inputs = readln.split;
int a = inputs[0].to!int, b = inputs[1].to!int, c = inputs[2].to!int;
G[a - 1][b - 1] = c;
G[b - 1][a - 1] = c;
M[a - 1][b - 1][0] = true;
M[b - 1][a - 1][0] = true;
}
foreach(i; 0..n)
foreach(j; 0..n)
foreach(k; 0..n)
if(M[i][k][0] && M[k][j][0])
M[i][j][1] = true;
dfs(n, 0, 1, 0);
return min(D[n - 1][0], D[n - 1][1]);
}
void dfs(int n, int now, int magic, int cost)
{
if(D[now][magic] <= cost) return;
D[now][magic] = cost;
foreach(next; 0..n){
if(M[now][next][0]) dfs(n, next, magic, cost + G[now][next]);
if(M[now][next][1] && 0 < magic) dfs(n, next, magic - 1, cost);
}
}
/*
現在いる場所、そこまでの費用、特別乗車券を使ったかどうかで最小値を更新するDFSをします。
特別乗車券を使えるのはi,jの間にパス2の経路が存在する場合だけなので、それをMに記録していきます。
あるkを選択する時iからk、kからjまでの経路が存在すれば特別乗車券が使えます。
*/
/*
2 1
1 2 5
3 2
1 2 5
2 3 5
6 9
1 2 7
1 3 9
1 5 14
2 3 10
2 4 15
3 4 11
3 5 2
4 5 9
4 6 8
0 0
*/
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto N = RD!string;
long cnt;
foreach (c; N)
{
cnt += c-'0';
}
writeln(cnt % 9 == 0 ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
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 x = readln.chomp.split.to!(int[]);
auto a = new int[](3);
a[0] = x[0] * x[1];
a[1] = x[0] + x[1];
a[2] = x[0] - x[1];
writeln(max(a[2],max(a[0], a[1])));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
auto data = readln().split();
auto S = data[0].to!string();
auto first = S;
auto num = 0;
foreach (c; S) { if (c == '1') num++; }
writeln(2*min( num, S.length-num ));
}
|
D
|
import std.stdio;
void main() {
int n;
scanf("%u", &n);
int a5, a0;
while(n--) {
int t;
scanf("%u", &t);
if(t == 5) a5++;
else a0++;
}
if(a0 == 0) {
write(-1);
return;
}
int m, c;
foreach(i; 0..a5)
if((m += 5) % 9 == 0) c = i + 1;
if(!c)
a0 = 1;
while(c--) write(5);
while(a0--) write(0);
}
|
D
|
/+ dub.sdl:
name "D"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
Scanner sc = new Scanner(stdin);
int H, W, d;
sc.read(H, W, d);
string s = "RYGB";
int[][] res = new int[][](H, W);
foreach (i; 0..H) {
foreach (j; 0..W) {
int y = (i-j + 10000*d) / d;
int x = (i+j + 10000*d) / d;
write(s[y%2*2+x%2]);
}
writeln();
}
return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
|
D
|
import std.conv;
import std.math;
import std.stdio;
import std.string;
private const JUMP_TIME = 1;
private const EAT_TIME = 1;
void main() {
auto
trees_count = read(),
position = read(),
time = position + EAT_TIME;
foreach (i; 1 .. trees_count) {
auto tree = read();
time += abs(position - tree) + EAT_TIME + JUMP_TIME;
position = tree;
}
stdout.write(time);
}
int read() {
return to!int(strip(stdin.readln()));
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto S = readln.chomp;
auto N = S.length.to!int;
auto K = readln.chomp.to!int;
auto dp = new int[][][](N, N, K+1);
foreach (i; 0..N) dp[i][i][0] = 1;
if (K > 0) foreach (i; 0..N-1) dp[i][i+1][S[i]!=S[i+1]] = 2;
else foreach (i; 0..N-1) if (S[i] == S[i+1]) dp[i][i+1][0] = 2;
foreach (len; 1..N+1) {
foreach (il; 0..N-len+1) {
foreach (k; 0..K+1) {
int ir = il + len - 1;
if (il > 0) dp[il-1][ir][k] = max(dp[il-1][ir][k], dp[il][ir][k]);
if (ir < N - 1) dp[il][ir+1][k] = max(dp[il][ir+1][k], dp[il][ir][k]);
if (il > 0 && ir < N - 1) {
int cost = S[il-1] != S[ir+1];
if (k + cost <= K) {
dp[il-1][ir+1][k+cost] = max(dp[il-1][ir+1][k+cost], dp[il][ir][k] + 2);
}
}
}
}
}
dp[0][N-1].reduce!max.writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
auto a = lread();
(a%2?a*2:a).writeln();
}
|
D
|
import std.stdio;import std.conv;import std.string;
void main(){ writeln( (readln().chomp().to!int())^^3 ); }
|
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 a=scanElem,b=scanElem,c=scanElem;
if(a<=c&&b>=c)end("Yes");end("No");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abc = readln.split.to!(long[]);
auto A = abc[0];
auto B = abc[1];
auto C = abc[2];
int r;
foreach (_; 0..1000) {
if (A%2 == 1 || B%2 == 1 || C%2 == 1) {
writeln(r);
return;
}
++r;
auto a = (B+C)/2;
auto b = (A+C)/2;
auto c = (A+B)/2;
A = a;
B = b;
C = c;
}
writeln(-1);
}
|
D
|
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
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;
void main() {
string s = read!string;
int[char] d;
foreach (c; s) {
d[c]++;
}
bool ok = d.values.all!(e => e == 2);
writeln(ok ? "Yes" : "No");
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/abc177/tasks/abc177_b
// implementation, string manipulation
import std.algorithm;
import std.stdio;
import std.string;
void main() {
string s = readln.strip;
string t = readln.strip;
long minima = t.length;
for(int i = 0; i + t.length <= s.length; ++i) {
long mismatches = 0;
for(int j = 0; j < t.length; ++j)
if(t[j] != s[i + j])
mismatches += 1;
minima = min(minima, mismatches);
}
minima.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, std.format, std.bitmanip, std.numeric;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
long k;
cin.scan(k);
long res;
foreach (i; 1 .. k + 1) {
foreach (j; 1 .. k + 1) {
foreach (l; 1 .. k + 1) {
res += gcd(gcd(i, j), l);
}
}
}
writeln(res);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
struct Cmb
{
void init(size_t n)
{
long powmod(long a, long p)
{
long ans = 1;
long mul = a;
while (p > 0)
{
if ((p & 1) == 1)
ans.modm(mul);
p >>= 1;
mul.modm(mul);
}
return ans;
}
++n;
fact = new long[2][](n);
fact[0][0] = 1;
foreach (i; 1..n)
{
fact[i][0] = fact[i-1][0];
fact[i][0].modm(i);
}
fact[n-1][1] = powmod(fact[n-1][0], mod - 2);
foreach_reverse (i; 0..n-1)
{
fact[i][1] = fact[i+1][1];
fact[i][1].modm(i+1);
}
}
long get(size_t n, size_t r)
{
long res = fact[n][0];
res.modm(fact[r][1]);
res.modm(fact[n-r][1]);
return res;
}
long[2][] fact;
}
void main()
{
auto n = RD!int;
auto m = RD!int;
Cmb cmb;
cmb.init(m);
long ans;
foreach (i; 1..n-1)
{
long pat = cmb.get(n-2, i);
pat.modm(i);
ans.moda(pat);
}
long pat2;
foreach (i; n-1..m+1)
{
pat2.moda(cmb.get(i-1, n-2));
}
ans.modm(pat2);
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
auto n = read.to!long;
auto q = read.to!long;
long[] as;
foreach(i; 0 .. n) as ~= read.to!long;
debug writeln("as: ", as);
long[] bs;
foreach_reverse(a; as) bs ~= a;
debug writeln("bs: ", bs);
long[] sums;
foreach(i; 0 .. n){
if(i == 0) sums ~= bs[i];
else sums ~= sums[$ - 1] + bs[i];
}
debug writeln("sums: ", sums);
long[] evensums;
for(int i = 0; i * 2 < n; i ++){
if(i == 0) evensums ~= bs[i * 2];
else evensums ~= evensums[$ - 1] + bs[i * 2];
}
debug writeln("evensums: ", evensums);
long evensum = evensums[$ - 1];
debug writeln("evensum: ", evensum);
long[] cs;
for(int i = 0; i * 2 < n; i ++) cs ~= bs[i] + bs[i * 2];
debug writeln("cs: ", cs);
foreach(t; 0 .. q){
auto x = read.to!long;
auto i = uplimit(0, (n - 1) / 2, i => (x * 2 <= cs[i]));
if(i < 0) i = 0;
debug writeln("x: ", x, " i: ", i);
auto ans = sums[i] + evensum - evensums[i];
ans.writeln;
}
}
// fをみたす最大(二分探索; binary search)
long uplimit(long a, long c, bool delegate(long) f){
if(f(c)) return c;
if(! f(a)) return a - 1;
while(a + 1 < c){
long b = (a + c) / 2;
if(f(b)) a = b;
else c = b;
}
return a;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto ni = readln.split.to!(int[]);
writeln(ni[0] - ni[1] + 1);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
void main()
{
auto tokens = split(chomp(readln()));
auto n = to!int(tokens[0]);
auto m = to!int(tokens[1]);
string s = chomp(readln());
int[][] node;
node.length = n;
foreach (i; 0..m)
{
auto tokens2 = split(chomp(readln()));
auto n1 = to!int(tokens2[0]) - 1;
auto n2 = to!int(tokens2[1]) - 1;
node[n1] ~= n2;
node[n2] ~= n1;
}
bool[] nodeS;
nodeS.length = n;
fill(nodeS, true);
void compute(int i)
{
bool isDone1 = false, isDone2 = false;
char c1 = s[i];
foreach (j; node[i])
{
if (!nodeS[j]) continue;
char c2 = s[j];
if (c1 == c2) isDone1 = true;
else isDone2 = true;
}
if (!isDone1 || !isDone2)
{
nodeS[i] = false;
foreach (j; node[i])
{
if (!nodeS[j]) continue;
compute(j);
}
}
}
foreach (i, node2; node)
{
compute(cast(int)i);
}
bool isComplete = false;
foreach (e; nodeS) if (e) isComplete = true;
writeln(isComplete ? "Yes" : "No");
stdout.flush();
}
|
D
|
void main()
{
string n = rdStr;
writeln(n.canFind('7') ? "Yes" : "No");
}
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.stdio, std.conv, std.string;
long search(long n, long k, long cur)
{
if (n == 0) { return cur; }
long a = search(n-1, k, cur+k);
long b = search(n-1, k, cur*2);
return (a>b) ? b : a;
}
void main() {
long n, k;
scanf("%d %d", &n ,&k);
writeln(search(n, k, 1));
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
void main(){
int n = readln.chomp.to!int;
int[] as = readln.chomp.split.map!(to!int).array;
int c = 0;
foreach(a; as) if(a % 2) c += 1;
string ans;
if(c % 2) ans = "NO"; else ans = "YES";
ans.writeln;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
void main()
{
auto tokens = split(chomp(readln()));
auto x1 = to!int(tokens[0]);
auto y1 = to!int(tokens[1]);
auto x2 = to!int(tokens[2]);
auto y2 = to!int(tokens[3]);
int dx = x2 - x1;
int dy = y2 - y1;
int x3 = x2 + -1 * dy;
int y3 = y2 + dx;
int dx2 = x3 - x2;
int dy2 = y3 - y2;
int x4 = x3 + -1 * dy2;
int y4 = y3 + dx2;
writeln(x3, " ", y3, " ", x4, " ", y4);
stdout.flush();
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
readln.chomp.map!(c => c == '+' ? +1 : -1).sum.writeln;
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int x = tmp[0], y = tmp[1], z = tmp[2];
writeln((x - z) / (y + z));
}
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, std.algorithm;
void main(){
int n, m, q; rd(n, m, q);
auto cul=new int[][](n+1, n+1);
foreach(_; 0..m){
int l, r; rd(l, r);
cul[l][r]++;
}
for(int i=1; i<=n; i++){
foreach(j; 0..n) cul[i][j+1]+=cul[i][j];
}
while(q--){
int l, r; rd(l, r);
int num=0;
for(int i=l; i<=r; i++){
num+=cul[i][r]-cul[i][i-1];
}
writeln(num);
}
}
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;
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();
auto ans = new long[](n + 1);
foreach (i; 0 .. n)
{
ans[a[i]] = i + 1;
}
// writeln(ans);
foreach (i; 1 .. (ans.length))
{
write(ans[i], ' ');
}
}
//https://rclone.org/
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.array,std.conv,std.algorithm,std.range,std.string;
void main(string[] args) {
string[2] a;
a[0] = readln.chomp;
a[1] = readln.chomp;
if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0]){
"YES".writeln;
}else{
"NO".writeln;
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long a, b;
scan(a, b);
bool x = a <= 8 && b <= 8;
writeln(x?"Yay!":":(");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
void main()
{
auto input = readln.chomp.split.to!(long[]);
long a = input[0];
long b = input[1];
long x = input[2];
writeln((a <= x && x <= a + b)?"YES":"NO");
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long A, B;
scan(A, B);
writeln(A < 10 && B < 10 ? A * B : -1);
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
void main() {
while (true) {
auto input = readln.chomp.split.map!(to!int);
if (input.array == [0, 0]) break;
int n = input[0];
int x = input[1];
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = i+1; j <= n; j++) {
for (int k = j+1; k <= n; k++) {
if (i + j + k == x) {
cnt++;
}
}
}
}
cnt.writeln;
}
}
|
D
|
void main() {
int[][] c = new int[][](3, 3);
foreach (i; 0 .. 3) {
int[] tmp = readln.split.to!(int[]);
foreach (j, x; tmp) {
c[i][j] = x;
}
}
bool ok = true;
foreach (i; 1 .. 3) {
int[] diff = new int[3];
foreach (j; 0 .. 3) {
diff[j] = c[i][j] - c[i-1][j];
}
if (!diff.all!(x => x == diff[0])) {
ok = false;
}
}
writeln(ok ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
auto N = readln.chomp.to!int;
if (N == 0) {
writeln(0);
return;
}
int[] po;
while (N != 0) {
const c = abs(N % 2);
po ~= c;
N = (N - c) / (-2);
}
po.retro.each!write;
writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons, std.math;
void main() {
ulong N = readln.chomp.to!ulong;
ulong res = ulong.max;
ulong m = 1 + cast(ulong)ceil(sqrt(cast(double)N));
foreach(i; 1..m) {
if(N % i == 0) {
ulong j = N / i;
res = min(res, i+j-2);
}
}
res.writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.math;
void main() {
int n = stdin.readln.chomp.to!int;
long debt = 100000;
foreach(i;0..n) {
debt += debt * 0.05;
debt = (((debt / 1000.0).ceil) * 1000).to!long;
}
debt.writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto s = RD!string;
writeln(s[0] ~ to!string(s.length-2) ~ s[$-1]);
stdout.flush();
debug readln();
}
|
D
|
/+ dub.sdl:
name "B"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
auto sc = new Scanner(stdin);
int n, m;
sc.read(n, m);
int[] deg = new int[n];
foreach (i; 0..m) {
int a, b;
sc.read(a, b); a--; b--;
deg[a]++; deg[b]++;
}
if (deg.filter!(x => x%2 == 1).empty) {
writeln("YES");
} else {
writeln("NO");
}
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
|
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 R = RD;
writeln(R < 1200 ? "ABC" : R < 2800 ? "ARC" : "AGC");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
void main() {
auto d = readln.chomp.to!(char[]);
d.reverse;
d.writeln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, M;
scan(N, M);
auto S = sread();
auto T = sread();
long g = gcd(N, M);
foreach (i; 0 .. g)
{
if (S[i * (N / g)] != T[i * (M / g)])
{
writeln(-1);
return;
}
}
writeln((N * M) / g);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int m;
scan(m);
auto ans = 24 - m + 24;
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.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*
(1からNではなく、0からN-1として考える)
0からiまでを並べ、s[0 .. i] に従い、最後が j で終わる場合の数をxs[i][j]とする
xs[0][0] = 1
xs[0][j] = 0
s[i] = '<' の場合
xs[i][j] = sum(j'; 0 .. j) xs[i - 1][j']
s[i] = '>' の場合
xs[i][j] = sum(j'; j .. i) xs[i - 1][j']
このsumは愚直にループを回すとTLEになるが、累積和ならOK
求めるものは sum(j; 0 .. j) xs[n][j]
----------------------------------------
*/
const mod = 1_000_000_007;
void main(){
long n = read.to!long;
string s = readln.chomp;
long[][] xs = new long[][](n, n);
xs[0][0] = 1;
debug writeln("i:", 0, " xs:", xs);
foreach(i; 1 .. n){
if(s[i - 1] == '<'){
long sum = 0;
foreach(j; 0 .. i + 1){
if(j > 0) sum += xs[i - 1][j - 1], sum %= mod;
debug writeln("i:", i, " j:", j, " sum:", sum);
xs[i][j] = sum;
}
}
else{
long sum = 0;
foreach_reverse(j; 0 .. i + 1){
if(j < i) sum += xs[i - 1][j], sum %= mod;
debug writeln("i:", i, " j:", j, " sum:", sum);
xs[i][j] = sum;
}
}
debug writeln("i:", i, " xs:", xs);
}
long ans = 0;
foreach(j; 0 .. n) ans += xs[n - 1][j], ans %= mod;
ans.writeln;
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
auto xs = readints;
int a = xs[0], b = xs[1], c = xs[2], d = xs[3];
if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
writeln("Yes");
}
else writeln("No");
}
|
D
|
import std.stdio, std.conv, std.algorithm, std.array, std.string;
void main(){
int n = to!int(readln.chomp);
foreach(_; 0..n){
auto ns = array(map!(to!int)(readln.chomp.split));
writeln(solve(ns) ? "YES" : "NO");
}
}
bool solve(int[] ns){
foreach(bit; 0..1<<ns.length){
int[2] prev;
bool ok = true;
foreach(i; 0..ns.length){
if(prev[(bit>>i)&1] < ns[i]){
prev[(bit>>i)&1] = ns[i];
}
else{
ok = false;
break;
}
}
if(ok){
return true;
}
}
return false;
}
|
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 mod = 10L^^9 + 7;
enum inf = 10^^9;
void main() {
int n, ma, mb;
scan(n, ma, mb);
auto a = new int[](n);
auto b = new int[](n);
auto c = new int[](n);
foreach (i ; 0 .. n) {
scan(a[i], b[i], c[i]);
}
auto dp = new int[][][](n + 1, 401, 401);
fillAll(dp, inf);
dp[0][0][0] = 0;
foreach (i ; 1 .. n + 1) {
foreach (ag ; 0 .. 401) {
foreach (bg ; 0 .. 401) {
dp[i][ag][bg] = dp[i-1][ag][bg];
if (ag - a[i-1] >= 0 && bg - b[i-1] >= 0) {
dp[i][ag][bg] = min(dp[i][ag][bg],
dp[i-1][ag - a[i-1]][bg - b[i-1]] + c[i-1]);
}
}
}
}
long ans = inf;
int aa = ma, bb = mb;
while (aa <= 400 && bb <= 400) {
debug {
writeln(dp[n][aa][bb]);
}
ans = min(ans, dp[n][aa][bb]);
aa += ma;
bb += mb;
}
writeln(ans < inf ? ans : -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;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
long MOD = 10L^^9+7;
void main() {
readln.chomp.to!long.iota.map!"a+1".fold!(
(a, b) => a*b%MOD
)(1L).writeln;
}
// ----------------------------------------------
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto A = lreads(N);
A[] -= 1;
auto visited = new bool[](N);
long ans;
long cur = 0;
while (cur != 1)
{
if (visited[cur])
{
writeln(-1);
return;
}
visited[cur] = true;
cur = A[cur];
ans++;
}
writeln(ans);
}
|
D
|
void main()
{
long n = rdElem;
string s = rdStr;
long len = s.length;
foreach (i; 0 .. 4)
{
string t;
t ~= (i & 1 ? 'S' : 'W'), t ~= ((i >> 1) & 1 ? 'S' : 'W');
foreach (j; 1 .. len+1)
{
if ((t[j] == 'S') == (s[j%len] == 'o')) t ~= t[j-1];
else t ~= (t[j-1] == 'S' ? 'W' : 'S');
}
if (t[0..2] != t[len..len+2]) continue;
t[0..len].writeln;
return;
}
writeln(-1);
}
enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import std.algorithm,
std.string,
std.array,
std.range,
std.stdio,
std.conv;
void main() {
int n = readln.chomp.to!int;
int m = 1;
while (m < n) {
m *= 2;
}
writeln(m / (m == n ? 1 : 2));
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
s[0..$-8].writeln;
}
|
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];
writeln(a < b && b < c ? "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 n = RD;
auto m = RD;
writeln((n-1)*(m-1));
stdout.flush();
debug readln();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
string[] inputs = split(readln());
int A = to!int(inputs[0]);
int B = to!int(inputs[1]);
if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) "Possible".writeln;
else "Impossible".writeln;
}
|
D
|
import std.algorithm;
import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.string;
void main() {
string s = readln.strip;
int w = 0, l = 0;
foreach (i, h; s) {
if (i % 2 == 0 && h == 'p') {
l++;
} else if (i % 2 == 1 && h == 'g') {
w++;
}
}
writeln(w - l);
}
|
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();
auto a = new long[](n);
n.iota.each!(x => a[x] = lread());
auto dp = new long[][](n, 2);
dp[0][0] = a[0] / 2;
dp[0][1] = a[0] ? (a[0] - 1) / 2 : -INF;
foreach (i; iota(n - 1))
{
dp[i + 1][0] = max(dp[i][0] + a[i + 1] / 2, dp[i][1] + (a[i + 1] + 1) / 2);
dp[i + 1][1] = a[i + 1] ? max(dp[i][0] + (a[i + 1] - 1) / 2, dp[i][1] + a[i + 1] / 2) : -INF;
}
// dp.each!(x => x.writeln());
max(dp[n - 1][0], dp[n - 1][1]).writeln();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
void main() {
string s = readln.chomp;
long ind;
long cnt;
long op;
while (ind < s.length)
{
if (s[ind] == 'A')
{
++cnt;
}
else
{
if (ind < s.length - 1 &&s[ind] == 'B' && s[ind+1] == 'C')
{
op += cnt;
++ind;
}
else
{
cnt = 0;
}
}
++ind;
}
op.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
writeln(s[0] == s[2] ? "Yes" : "No");
}
|
D
|
/+ dub.sdl:
name "F"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.datastructure.lazyseg;
int main() {
auto sc = new Scanner(stdin);
int n, m;
sc.read(n, m);
int[] l = new int[n], r = new int[n];
int[][] rg = new int[][m+2];
foreach (i; 0..n) {
sc.read(l[i], r[i]);
rg[r[i]] ~= i;
}
auto seg = LazySeg!(int, int, (a, b) => min(a, b), (a, b) => a+b, (a, b) => a+b, 10^^9, 0)(m+2);
foreach (i; 0..m+2) {
seg.add(i, i+1, -(10^^9) + i);
}
int ans = min(n, m);
int off = n;
foreach_reverse (ri; 2..m+2) {
//right use [ri .. m+1]
int buf = m+1 - ri;
//add r[i] = ri
foreach (i; rg[ri]) {
off--;
// writeln("wow ", l[i]);
seg.add(0, l[i], 1);
}
// writeln("debug : ", iota(ri).map!(a => seg[0..a].sum()).map!(to!string).join(" "));
// writeln(buf, " ", off, " ", seg[0..ri-1].sum());
ans = min(ans, buf + off + seg[0..ri-1].sum());
}
writeln(n - ans);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/datastructure/lazyseg.d */
// module dcomp.datastructure.lazyseg;
struct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {
const int n, sz, lg;
T[] d;
L[] lz;
@disable this();
this(int n) {
import std.algorithm : fill, each;
import core.bitop : bsr;
if (n == 0) return;
int lg = n.bsr;
if ((2^^lg) < n) lg++;
this.n = n;
this.sz = 2^^lg;
this.lg = lg;
d = new T[](2*this.sz);
d.each!((ref x) => x = eT);
lz = new L[](2*this.sz);
lz.each!((ref x) => x = eL);
}
private void lzAdd(int k, L x) {
d[k] = opTL(d[k], x);
lz[k] = opLL(lz[k], x);
}
private void push(int k) {
if (lz[k] == eL) return;
lzAdd(2*k, lz[k]);
lzAdd(2*k+1, lz[k]);
lz[k] = eL;
}
T sum(int a, int b, int l, int r, int k) {
if (b <= l || r <= a) return eT;
if (a <= l && r <= b) return d[k];
push(k);
int md = (l+r)/2;
return opTT(sum(a, b, l, md, 2*k),
sum(a, b, md, r, 2*k+1));
}
T single(int k) {
k += sz;
foreach_reverse (int i; 1..lg+1) {
push(k>>i);
}
return d[k];
}
T sum(int a, int b) {
assert(0 <= a && a <= b && b <= n);
return sum(a, b, 0, sz, 1);
}
void add(int a, int b, L x, int l, int r, int k) {
if (b <= l || r <= a) return;
if (a <= l && r <= b) {
lzAdd(k, x);
return;
}
push(k);
int md = (l+r)/2;
add(a, b, x, l, md, 2*k);
add(a, b, x, md, r, 2*k+1);
d[k] = opTT(d[2*k], d[2*k+1]);
}
void add(int a, int b, L x) {
assert(0 <= a && a <= b && b <= n);
add(a, b, x, 0, sz, 1);
}
@property int opDollar() const {return sz;}
struct Range {
LazySeg* seg;
int start, end;
@property T sum() {
return seg.sum(start, end);
}
}
int[2] opSlice(size_t dim)(int start, int end) {
assert(0 <= start && start <= end && end <= sz);
return [start, end];
}
Range opIndex(int[2] rng) {
return Range(&this, rng[0], rng[1]);
}
void opIndexOpAssign(string op : "+")(L x, int[2] rng) {
add(rng[0], rng[1], x);
}
}
|
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;
scan(A, B, C);
if (B < A)
swap(A, B);
writeln(A <= C && C <= B ? "Yes" : "No");
}
|
D
|
import std.stdio,
std.string,
std.conv;
void main() {
int N = to!int(readln.chomp);
int[char] hash;
for (int i = 0; i < N; i++) {
string s = readln.chomp;
if ("MARCH".count(s[0])) {
hash[s[0]]++;
}
}
int[] a = hash.values ~ [0, 0, 0, 0, 0];
long ans = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
for (int k = j + 1; k < 5; k++) {
ans += 1L * a[i] * a[j] * a[k];
}
}
}
writeln(ans);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abc = readln.split.to!(long[]);
auto A = abc[0];
auto B = abc[1];
auto C = abc[2];
writeln((A+B >= C ? C : A+B+1) + B);
}
|
D
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*
ビットDP
x[m]: ビットマップmで表されるうさぎたちがなすグループの得点
m = (1<<i) | m' であるとき
x[m] = x[m'] + sum(j; (1<<i) & j)(a[i, j])
y[m]: ビットマップmで表されるうさぎたちを最適にグループ分けしたときの得点
y[m] = max(x[m], max(m'; m' subsetof m)(y[m'] + y[m - m']))
※subsetof は、 m - m' == m ^ m' として実装できる
これは(2^16)×(2^16)なのでオーダー的にはTLEだが、がんばれば通るだろう
定数倍をがんばる
*/
long tmp, dt; // 高速化
void main(){
int n = read.to!int;
long[][] as = new long[][](16, 16);
foreach(i; 0 .. n) foreach(j; 0 .. n) as[i][j] = read.to!long;
debug StopWatch sw;
debug sw.start();
long[] xs = new long[](1<<n);
foreach(i; 0 .. n){
foreach(m; 0 .. 1<<i){
xs[1<<i | m] = xs[m];
foreach(j; 0 .. i){
if(1<<j & m) xs[1 << i | m] += as[i][j];
}
}
}
debug writeln("xs:", xs[0 .. 1<<n]);
long[] ys = new long[](1<<n);
foreach(m; 0 .. 1<<n){
ys[m] = xs[m];
int t = 1, u = m - 1; // u は m - t のこと
while(t < u){
if((m ^ t) == u){ // t が m のサブセットであるとき
tmp = ys[t] + ys[u];
if(tmp > ys[m]) ys[m] = tmp;
t += 1, u -= 1;
}
else{
// t の最後の桁と同じだけ上げる(例:10110100 がだめだったら、100の位がだめということなので、+100する)
dt = (t ^ (t - 1)) & t;
t += dt, u -= dt;
}
}
}
debug writeln("ys:", ys[0 .. 1<<n]);
ys[(1<<n) - 1].writeln;
debug writeln(sw.peek().msecs);
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, A, B;
scan(N, A, B);
writeln((MOD * 2 + powmod(2, N) - 1 - c(N, A) - c(N, B)) % MOD);
}
long c(long n, long k)
{
long a = 1, b = 1;
foreach (i; 0 .. k)
{
a = a * (n - i) % MOD;
b = b * (i + 1) % MOD;
}
return a * powmod(b, MOD - 2) % MOD;
}
/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
if (n < 1)
return 1;
if (n & 1)
{
return x * powmod(x, n - 1, m) % m;
}
T tmp = powmod(x, n / 2, m);
return tmp * tmp % m;
}
|
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;
}
int calc(string s) {
int ans = 0;
int lo = 0;
int hi = cast(int) s.length - 1;
while (lo < hi) {
if (s[lo] == s[hi]) {
lo++;
hi--;
}
else if (s[lo] == 'x') {
lo++;
ans++;
}
else if (s[hi] == 'x') {
hi--;
ans++;
}
else {
return -1;
}
}
return ans;
}
void main() {
auto s = readln.chomp;
writeln(calc(s));
}
|
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;
int cnt;
foreach (i; 0..n) {
if (i+3 > s.length) break;
if (s[i..i+3] == "ABC") {
cnt++;
}
}
cnt.writeln;
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
void main() {
long x = readln.chomp.to!long;
long left = 0;
long right = x + 1;
while (right - left > 1) {
long mid = (left + right) / 2;
long five = mid / 2;
long six = mid - five;
if (five * 5 + six * 6 < x) {
left = mid;
} else {
right = mid;
}
}
right.writeln;
}
|
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;
auto cs = new long[](25820);
cs[1] = 2;
foreach (i; 2..25820) {
cs[i] = cs[i-1] + (i-1) * 3 + 2;
}
foreach (_; 0..T) {
auto N = readln.chomp.to!int;
int res;
while (N >= 2) {
++res;
if (N >= cs[$-1]) {
N -= cs[$-1];
} else {
int l = 1, r = cs.length.to!int-1;
while (l+1 < r) {
auto m = (l+r)/2;
if (N >= cs[m]) {
l = m;
} else {
r = m;
}
}
N -= cs[l];
}
}
writeln(res);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
long x, y;
scan(x, y);
if (x < y || x % y) {
writeln(x);
}
else {
writeln(-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;
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[long] ary;
foreach (i; 0 .. n)
{
ary[a[i]] = ary.get(a[i], 0) + 1;
}
foreach (value; ary)
{
if (value > 1)
{
writeln("NO");
return;
}
}
writeln("YES");
}
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.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
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 N = RD!long;
auto a = RDR.split.to!(long[]);
long cnt2, cnt4;
foreach (e; a)
{
if (e % 4 == 0) ++cnt4;
else if (e % 2 == 0) ++cnt2;
}
long cnt1 = N - cnt2 - cnt4;
auto ans = cnt1 + cnt4 == N ? cnt4 >= cnt1 - 1 : cnt4 >= cnt1;
writeln(ans ? "Yes" : "No");
stdout.flush();
}
|
D
|
void main()
{
string t = rdStr;
string s;
foreach (x; t)
{
if (x == 'P' || x == 'D') s ~= x;
else s ~= 'D';
}
s.writeln;
}
enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import std.stdio;
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 x = readln.chomp.to!int;
if (x == 7 || x == 5 || x == 3) {
writeln("YES");
} else {
writeln("NO");
}
}
|
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 minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
auto inp = sread();
auto A = new long[](4);
foreach (i; 0 .. 4)
A[i] = inp[i] - '0';
// writeln(A);
foreach (x; 0 .. (1 << 3))
{
long sum = A[0];
foreach (i; 0 .. 3)
{
sum += A[i + 1] * ((-1) ^^ ((x & (1 << i)) != 0));
// writeln(A[i + 1] * ((-1) ^^ ((x & (1 << i)) != 0)));
}
// writeln(sum);
if (sum == 7)
{
write(A[0]);
foreach (i; 0 .. 3)
{
write(['+', '-'][((x & (1 << i)) >> i)]);
write(A[i + 1]);
}
writeln("=7");
return;
}
// else
// writeln(sum);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto c = readln.chomp[0];
writeln(cast(string)[c+1]);
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
auto ab = reads!string;
string a = ab[0], b = ab[1];
writeln(a == b ? "H" : "D");
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/abc166/tasks/abc166_e
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main() {
long n = readln.chomp.to!long;
long[] a = readln.split.map!(to!long).array;
long[long] y;
foreach(idx; 0..n) {
long x = idx+1+a[idx];
if(x in y)
y[x] += 1;
else
y[x] = 1;
}
long answer = 0;
foreach(i; 0..n) {
long x = i+1-a[i];
if(x in y)
answer += y[x];
}
answer.writeln;
}
|
D
|
import std.stdio,
std.string,
std.conv,
std.algorithm;
void main() {
int N = readln.chomp.to!(int);
int[string] s;
for (int i = 0; i < N; i++) {
s[readln.chomp]++;
}
int M = readln.chomp.to!(int);
for (int i = 0; i < M; i++) {
s[readln.chomp]--;
}
int ans = s.values.reduce!(max);
writeln(ans >= 0 ? ans : 0);
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
char[] s = readln.chomp.to!(char[]);
int ans = 10000;
foreach(c; s){
int x = solve(s, c);
if(x < ans) ans = x;
}
bool flag = 1;
foreach(c; s) if(c != s[0]) flag = 0;
if(flag) ans = 0;
ans.writeln;
}
int solve(char[] s, char c){
char[] s1 = s;
int count;
while(1){
bool flag = 1;
char[] s2;
for(int i = 0; i < s1.length - 1; i ++){
if(s1[i] == c || s1[i + 1] == c) s2 ~= c;
else{
flag = 0;
s2 ~= ' ';
}
}
s1 = s2;
count += 1;
if(flag) break;
}
return count;
}
|
D
|
void main() {
problem();
}
void problem() {
const N = scan!long;
void solve() {
bool[string] items;
foreach(_; 0..N) {
const item = scan;
items[item] = true;
}
writeln(items.keys.length);
}
solve();
}
// ----------------------------------------------
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 Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main()
{
readln();
auto s = readln();
foreach (c; s)
{
if (c == 'Y'){
writeln("Four");
return;
}
}
writeln("Three");
}
|
D
|
import std;
import core.bitop;
// dfmt off
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[]);
void aryWrite(T = long)(T[] ary){ ary.map!(x => x.text()).join(' ').writeln(); }
alias Pair = Tuple!(long, "H", long, "W", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
auto s = sread();
auto k = lread();
auto ans = new char[](s.length);
foreach (i, e; s)
{
auto diff = ('z' - e + 1) % 26;
// diff.writeln();
if (diff <= k)
{
ans[i] = 'a';
k -= diff;
}
else
{
ans[i] = e;
}
}
ans[$ - 1] += k % 26;
ans.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.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp.to!(wchar[]);
long[immutable(wchar[])][18] omemo;
long solve(int i, wchar[] rs_, wchar[] bs_) {
if (i == N) {
auto rs = rs_.dup;
reverse(rs);
auto bs = bs_.dup;
reverse(bs);
long[long][long] memo;
long dp(int i, int j) {
if (i + j == N) return 1L;
if (i in memo && j in memo[i]) return memo[i][j];
long r1, r2;
if (i < bs.length && S[N+i+j] == bs[i]) r1 = dp(i+1, j);
if (j < rs.length && S[N+i+j] == rs[j]) r2 = dp(i, j+1);
return memo[i][j] = r1 + r2;
}
auto ret = dp(0, 0);
return ret;
} else {
auto key = (rs_ ~ "|" ~ bs_).idup;
if (key in omemo[i]) return omemo[i][key];
return omemo[i][key] = solve(i+1, rs_ ~ S[i], bs_) + solve(i+1, rs_, bs_ ~ S[i]);
}
}
writeln(solve(0, [], []));
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
long a, b, c;
scan(a, b, c);
auto n = lread();
while (a >= b)
{
b *= 2;
n -= 1;
}
// writeln(a, b, c);
// writeln(n);
if (c * 2 ^^ n > b)
{
writeln("Yes");
}
else
{
writeln("No");
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
bool f;
if (s[0] != 'A') {
f = true;
}
if (!(s[1] >= 'a' && s[1] <= 'z')) {
f = true;
}
if (!(s[$-1] >= 'a' && s[$-1] <= 'z')) {
f = true;
}
auto c_num = s[2..$-1].count!(x=>x == 'C');
auto s_num = s[2..$-1].count!(x=>x>='a' && x<='z');
if (c_num != 1) {
f = true;
}
if (s_num != s[2..$-1].length.to!int - 1) {
f = true;
}
if (f) {
writeln("WA");
} else {
writeln("AC");
}
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto A = aryread();
foreach (a; A)
if (a % 2 == 0)
{
if (a % 3 != 0 && a % 5 != 0)
{
writeln("DENIED");
return;
}
}
writeln("APPROVED");
}
|
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 cnt = new int[](3);
foreach (e; s) {
cnt[e-'a']++;
}
if (abs(cnt[0]-cnt[1]) < 2 && abs(cnt[1]-cnt[2]) < 2 && abs(cnt[0]-cnt[2]) < 2) {
writeln("YES");
} else {
writeln("NO");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main()
{
auto line = chomp(readln()).split(" ");
int H = to!int(line[0]),
W = to!int(line[1]);
while(H || W)
{
foreach(int i; 0 .. H)
{
writeln(repeat("#", W));
}
writeln();
line = chomp(readln()).split(" ");
H = to!int(line[0]);
W = to!int(line[1]);
}
}
string repeat(string s, int n)
{
string r;
while(n)
{
if(n % 2)
{
r ~= s;
}
n >>= 1;
s ~= s;
}
return r;
}
|
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, K;
scan(N, K);
int ans = K;
foreach (i ; 0 .. N - 1) {
ans *= K - 1;
}
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abt = readln.split.to!(int[]);
auto A = abt[0];
auto B = abt[1];
auto T = abt[2];
writeln(B * (T / A));
}
|
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!int;
auto AS = readln.split.to!(int[]);
auto ps = new int[](10^^6+1);
foreach (a; AS) {
for (int i = 2; i^^2 <= a; ++i) {
if (a%i == 0) {
ps[i] += 1;
while (a%i == 0) a /= i;
}
}
if (a != 1) ps[a] += 1;
}
auto pc = true;
foreach (p; ps) {
if (p == N) {
writeln("not coprime");
return;
} else if (p > 1) {
pc = false;
}
}
writeln(pc ? "pairwise coprime" : "setwise coprime");
}
|
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;
alias Edge = Tuple!(int, "to", int, "idx");
void main() {
int N;
scan(N);
auto adj = new Edge[][](N, 0);
foreach (i ; 0 .. N - 1) {
int ai, bi;
scan(ai, bi);
ai--, bi--;
adj[ai] ~= Edge(bi, i);
adj[bi] ~= Edge(ai, i);
}
int M;
scan(M);
auto useEdge = new ulong[](M);
ulong dfs(int u, int p, int v) {
foreach (e ; adj[u]) if (e.to != p) {
if (e.to == v) {
return 1UL << e.idx;
}
auto b = dfs(e.to, u, v);
if (b != 0) {
return b | (1UL << e.idx);
}
}
return 0;
}
foreach (i ; 0 .. M) {
int ui, vi;
scan(ui, vi);
ui--, vi--;
useEdge[i] = dfs(ui, -1, vi);
}
debug {
writeln(useEdge);
}
long ans;
foreach (s ; 0 .. (1 << M)) {
ulong b;
foreach (i ; 0 .. M) {
if (s & (1 << i)) {
b |= useEdge[i];
}
}
auto p = s.popcnt % 2;
auto t = (-1)^^p * 2L^^(N - 1 - b._popcnt);
ans += t;
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.stdio, std.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 a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
int k;
scan(k);
writeln(a[k - 1]);
}
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto S = readln.chomp;
writeln((S[0] == S[$-1] && S.length%2 == 0) || (S[0] != S[$-1] && S.length%2 == 1) ? "First" : "Second");
}
|
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;
writeln((n-2) * 180);
};
|
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;
auto A = new long[](N);
foreach (i; 0..N)
A[i] = RD;
auto B = new long[](N+1);
auto C = new long[](N+1);
foreach (i; 0..N)
{
B[i+1] = max(B[i], A[i]);
}
foreach_reverse (i; 0..N)
{
C[i] = max(C[i+1], A[i]);
}
foreach (i; 0..N)
{
writeln(max(B[i], C[i+1]));
}
stdout.flush();
debug readln();
}
|
D
|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int x, a, b;
scan(x, a, b);
if (b - a <= 0) {
writeln("delicious");
}
else if (b - a <= x) {
writeln("safe");
}
else {
writeln("dangerous");
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.