code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio, std.array, std.conv, std.algorithm, std.string, std.numeric, std.range;
void main() {
auto n = readln.strip.to!int;
foreach(i; 0..n){
readln.chomp.replace("Hoshino", "Hoshina").writeln();
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nk = readln.split.to!(int[]);
auto N = nk[0];
auto K = nk[1];
int r;
while (N) {
++r;
N /= K;
}
writeln(r);
}
|
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()
{
readln;
auto p = readln.chomp.split.map!(to!int).array;
int cnt;
foreach (i; 0..p.length-1) {
if (i+1 == p[i]) {
swap(p[i], p[i+1]);
cnt++;
}
}
if (p.length == p[$-1]) {
swap(p[$-2], p[$-1]);
cnt++;
}
cnt.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
immutable MAX_INPUT = 1000;
immutable MAX_COUNT = 1000;
int main(string[] argv)
{
int Count;
string[] Ans;
Count = readln().chomp().to!int();
if(Count <= MAX_COUNT){
for(int i = 0;i < Count;i++){
string[] tmp = readln().chomp().split(" ");
int[3] rect;
rect[0] = tmp[0].to!int();
rect[1] = tmp[1].to!int();
rect[2] = tmp[2].to!int();
foreach(int j;rect){
if (!judge(j)) break;
}
for(int j = 0;j < 3;j++){
if(rect[0] < rect[j]){
int t = rect[0];
rect[0] = rect[j];
rect[j] = t;
}
}
if(isTriangle(rect[1],rect[2],rect[0])){
Ans ~= "YES";
}else{
Ans ~= "NO";
}
}
}
foreach(string str;Ans){
writeln(str);
}
return 0;
}
bool judge(int x){
if(1 <= x && x <= MAX_INPUT){
return true;
}
return false;
}
bool isTriangle(int x,int y,int z){
x = x * x;
y = y * y;
z = z * z;
if (x + y == z){
return true;
}
return false;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
auto S = sread();
auto dp = new long[][](S.length + 1, 13);
dp[0][0] = 1;
foreach (i; 0 .. S.length)
{
if (S[i] == '?')
{
foreach (j; 0 .. 13)
{
foreach (k; 0 .. 10)
{
auto m = (j * 10 + k) % 13;
dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD;
}
}
}
else
{
foreach (j; 0 .. 13)
{
auto k = S[i] - '0';
auto m = (j * 10 + k) % 13;
dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD;
}
}
}
writeln(dp[S.length][5]);
}
|
D
|
void main() {
auto N = ri, A = ri;
(N % 500 <= A ? "Yes" : "No").writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto S = RD!string;
auto T = RD!string;
writeln(S == T[0..$-1] && S.length+1 == T.length ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
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;
}
}
//Digit count---{{{
int DigitNum(int num) {
int digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
//}}}
//}}}
void main() {
Scanner sc = new Scanner;
int H, W;
int h, w;
sc.scan(H, W);
sc.scan(h, w);
writeln((H * W) - ((h * W) + ((H - h) * w)));
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
auto len = S.length;
long ans;
foreach (i; 1..len)
{
auto len2 = len - i;
if (len2 % 2 == 1) continue;
bool ok = true;
foreach (j; 0..len2/2)
{
if (S[j] != S[len2/2+j])
{
ok = false;
break;
}
}
if (ok)
{
ans = len2;
break;
}
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
long ans, cnt;
foreach (c; S)
{
if (c == 'A' || c == 'C' || c == 'G' || c == 'T')
{
++cnt;
}
else
{
ans = max(ans, cnt);
cnt = 0;
}
}
ans = max(ans, cnt);
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
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 + 1) as ~= read.to!long;
long[] bs;
foreach(i; 0 .. n) bs ~= read.to!long;
long ans;
foreach(i; 0 .. n){
long k;
if(bs[i] <= as[i]) k = bs[i];
else k = as[i];
ans += k, bs[i] -= k, as[i] -= k;
if(bs[i] <= as[i + 1]) k = bs[i];
else k = as[i + 1];
ans += k, bs[i] -= k, as[i + 1] -= k;
}
ans.writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto X = RD;
auto Y = RD;
bool ans = inside(Y, X*2, X*4+1);
ans &= Y % 2 == 0;
writeln(ans ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
D
|
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
int res = s.length.to !(int);
int a = 0, b = 0;
foreach (c; s)
{
if (c == 'A')
{
a += 1;
}
else
{
b += 1;
if (a > 0 && b > 0)
{
a -= 1;
b -= 1;
res -= 2;
}
else if (b >= 2)
{
b -= 2;
res -= 2;
}
}
}
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 = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto K = RD;
auto S = RD!string;
if (S.length <= K)
writeln(S);
else
{
writeln(S[0..K], "...");
}
stdout.flush;
debug readln;
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto N = lread();
long ok = (N + 1);
long ng = -1;
while (abs(ok - ng) > 1)
{
long mid = (ok + ng) / 2;
if (((mid + 1) * ((mid + 1) + 1)) / 2 >= N)
{
ok = mid;
}
else
{
ng = mid;
}
}
// writeln(ok + 1);
foreach (i; 1 .. (ok + 1) + 1)
{
// writeln('t', (ok + 1) * ((ok + 1) + 1) / 2 - i);
if ((ok + 1) * ((ok + 1) + 1) / 2 - i == N)
{
continue;
}
else
{
writeln(i);
}
}
}
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
|
// 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 N = lread();
long a = 1, b = 1;
foreach (_; 0 .. N)
{
long T, A;
scan(T, A);
long ng = 0;
long ok = (1000000000000000000 + max(T, A) - 1) / max(T, A);
dprint((1000000000000000000 - 1 + max(T, A)), ok, T, A);
while (abs(ng - ok) > 1)
{
long m = (ok + ng) / 2;
long x = T * m;
long y = A * m;
if (x < a || y < b)
{
ng = m;
}
else
{
ok = m;
}
}
a = T * ok;
b = A * ok;
dprint(ok, a, b);
}
writeln(a + b);
}
|
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;
if (n[0] == n[2]) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
void main()
{
auto reader = readln.split;
int A = reader[0].to!int;
int B = reader[1].to!int;
int C = reader[2].to!int;
if ((A < C && C < B) || (A > C && C > B)) 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.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 string[](t);
foreach (ti; 0..t)
{
auto s1 = RD!string;
auto s2 = RD!string;
auto len = lcm(s1.length, s2.length);
while (ans[ti].length < len)
{
ans[ti] ~= s1;
}
string s3;
while (s3.length < len)
{
s3 ~= s2;
}
foreach (i; 0..s3.length)
{
if (ans[ti][i] != s3[i])
{
ans[ti].length = 0;
break;
}
}
}
foreach (e; ans)
{
writeln(e.empty ? "-1" : e);
}
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
auto edges = new int[][](N);
foreach (_; 0..M) {
s = readln.split.map!(to!int);
auto a = s[0] - 1;
auto b = s[1] - 1;
edges[a] ~= b;
edges[b] ~= a;
}
auto used = new bool[](N);
foreach (i; edges[0]) {
foreach (j; edges[i]) {
used[j] = true;
}
}
writeln(used[N - 1] ? "POSSIBLE" : "IMPOSSIBLE");
}
|
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 n = lread();
auto s = sread(), c = "RGB";
long color = 3, count;
auto pair = new long[][](n + 1, color);
foreach(i; iota(n))
{
foreach (j; iota(color))
{
pair[i + 1][j] = pair[i][j] + (s[i] == c[j]);
}
}
foreach (i; iota(n - 2))
{
foreach (j; iota(i + 1, n - 1))
{
if(s[i] == s[j])
continue;
auto tmp = color.iota.sum() - c.countUntil(s[i]) - c.countUntil(s[j]);
count += pair[n][tmp] - pair[j + 1][tmp];
if(j + (j - i) < n && c[tmp] == s[j + (j - i)])
count--;
}
}
count.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.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto S = readln.chomp;
auto N = S.length.to!int;
int ans = 0;
for (int p = 0, q = N-1; p < q; ) {
if (S[p] == S[q]) {
p += 1;
q -= 1;
} else if (S[p] == 'x') {
ans += 1;
p += 1;
} else if (S[q] == 'x') {
ans += 1;
q -= 1;
} else {
writeln(-1);
return;
}
}
ans.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math : abs;
import core.stdc.stdlib : exit;
void main()
{
auto A = to!int(split(readln())[0]);
auto B = to!int(split(readln())[0]);
auto C = to!int(split(readln())[0]);
auto D = to!int(split(readln())[0]);
writeln( (A < B ? A : B) + (C < D ? C : D) );
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
auto s = new char[][](2, n);
foreach (i; 0 .. 2)
s[i] = readln.chomp.to!(char[]);
const long mod = 10 ^^ 9 + 7;
auto dp = new long[][](2, n);
if (s[0][0] == s[1][0])
dp[0][0] += 3;
else
dp[1][1] += 6;
foreach (i; 1 .. n) {
if (s[0][i] == s[1][i]) {
dp[0][i] = (dp[0][i - 1] * 2 + dp[1][i - 1]) % mod;
} else if (i >= 2) {
dp[1][i] = (dp[0][i - 2] * 2 + dp[1][i - 2] * 3) % mod;
}
}
writeln((dp[0][n - 1] + dp[1][n - 1]) % mod);
}
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
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
if (n % 3 < 2) {
writeln(1, " ", 1, " ", n - 2);
} else {
writeln(1, " ", 2, " ", n - 3);
}
}
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.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
T binarySearch(alias pred, T)(T ok, T ng)
{
while (abs(ok-ng) > 1)
{
auto mid = (ok+ng)/2;
if (unaryFun!pred(mid)) ok = mid;
else ng = mid;
}
return ok;
}
void main()
{
auto t = RD!int;
auto ans = new int[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
while (true)
{
auto r = binarySearch!((long a) => a*(a+1) + a*(a-1)/2 <= n)(0L, 10L^^9);
if (r == 0) break;
++ans[ti];
n -= r*(r+1) + r*(r-1)/2;
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
auto a = new int[](n);
foreach (i; 0 .. n)
rd(a[i]);
bool[int] map;
foreach (e; a) {
if (e in map)
map.remove(e);
else
map[e] = true;
}
writeln(map.length);
}
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.string;
import std.conv;
import std.algorithm;
void main() {
auto s = readln.chomp;
auto y = new int[s.length];
int begin, i;
char mode = 'R';
foreach(c; s) {
if (c != mode && mode == 'R') {
y[i-1] += (i-begin+1)/2;
y[i] += (i-begin+1)/2 + (i-begin+1)%2;
begin = i;
mode = 'L';
}
else if (c != mode) {
y[begin-1] += (i-begin-1)/2 + (i-begin-1)%2;
y[begin] += (i-begin-1)/2;
begin = i;
mode = 'R';
}
++i;
}
y[begin-1] += (i-begin-1)/2 + (i-begin-1)%2;
y[begin] += (i-begin-1)/2;
y.map!(i => i.to!string).join(' ').write;
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
auto ans = new long[](25_000_000);
foreach (x; 1 .. 200)
foreach (y; 1 .. 200)
foreach (z; 1 .. 200)
{
ans[x * x + y * y + z * z + x * y + y * z + z * x]++;
}
foreach (i; 1 .. N + 1)
{
writeln(ans[i]);
}
}
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
void main() {
int n;
scanf("%d\n", &n);
int incl, lb, ra, half;
for(size_t i;i < n; ++i){
auto l = readln.chomp;
incl += l.count("AB");
auto b = l[0] == 'B';
auto a = l[$-1] == 'A';
if (a) ++ra;
if (b) ++lb;
if ((a || b) && (a != b)) ++half;
}
if (min(ra,lb) > 0 && half == 0) --incl;
write(incl + min(lb, ra));
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
auto a = readln.split.to!(int[]);
int o, t, f;
foreach (e; a) {
if (e % 4 == 0)
f++;
else if (e % 2 == 0)
t++;
else
o++;
}
t %= 2;
o += t;
if (o <= f + 1) {
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));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
char[] r;
foreach (c; readln.chomp) {
if (c == '?') {
r ~= 'D';
} else {
r ~= c;
}
}
writeln(r);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp.to!int;
writeln(X == 7 || X == 5 || X == 3 ? "YES" : "NO");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
auto r = 1000;
foreach (i; 0..s.length-2)
r = min(r, (s[i..i+3].to!int - 753).abs);
writeln(r);
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
void main(){
auto input_1 = readln.chomp;
auto input_2 = readln.chomp;
auto input_3 = readln.chomp;
auto answer = "" ~ input_1[0] ~ input_2[1] ~ input_3[2];
writeln(answer);
}
|
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 s1 = RD!string;
auto s2 = RD!string;
auto s3 = RD!string;
string ans = [cast(char)(s1[0]-'a'+'A'), cast(char)(s2[0]-'a'+'A'), cast(char)(s3[0]-'a'+'A')];
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int q;
rd(q);
while (q--) {
long n, a, b;
rd(n, a, b);
auto ans = n * a;
if (n & 1) {
ans = min(ans, n / 2 * b + a);
} else {
ans = min(ans, n / 2 * b);
}
writeln(ans);
}
}
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;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
long n, m;
scan(n, m);
auto 杯 = new long[](n);
杯[] = 1;
// writeln(杯);
auto 色 = new bool[](n); //赤色true
// writeln(色);
色[0] = true;
// writeln(色);
foreach (_; 0 .. m)
{
long x, y;
scan(x, y);
// writeln(x, y);
// writeln("杯", 杯);
杯[x - 1] -= 1;
杯[y - 1] += 1;
// writeln(杯);
if (色[x - 1])
{
色[y - 1] = true;
}
if (杯[x - 1] == 0)
{
色[x - 1] = false;
}
// writeln("色", 色);
}
long cnt;
foreach (i; 0 .. n)
{
if ((杯[i] > 0) && (色[i] == true))
{
cnt += 1;
}
}
writeln(cnt);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.string;
void main(){
writeln(toUpper(chomp(readln())));
}
|
D
|
import std.stdio;
void main()
{
foreach (i; 0..1000) {
writeln("Hello World");
}
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;
void main(){
immutable n = readln.chomp.to!int;
auto d_x = readln.chomp.split.map!(to!int);
auto days = d_x[0];
auto rest = d_x[1];
int[] as;
as.length = n;
as.each!((ref a){
a = readln.chomp.to!int;
});
auto answer = rest;
iota(0,n).each!((p){
auto day = 1;
while(day <= days){
answer++;
day += as[p];
}
});
answer.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;
void main(){
auto Q=readln.split.to!(int[]),r=Q[0],g=Q[1],b=Q[2];
if((100*r+10*g+b)%4==0)writeln("YES");
else writeln("NO");
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm, std.range;
void main() {
auto N = readln.split[0].to!int;
auto A = readln.split.to!(int[]);
auto B = readln.split.to!(int[]);
auto C = readln.split.to!(int[]);
int result = 0;
int before = -1;
foreach(a; A) {
result += B[a - 1];
if (before != -1 && a - before == 1) {
result += C[before - 1];
}
before = a;
}
result.writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
auto s = readln.chomp.to!(char[]);
int k;
scan(k);
int N = s.length.to!int;
foreach (i ; 0 .. N) {
if (s[i] == 'a') continue;
int x = 'z' - s[i] + 1;
if (x <= k) {
k -= x;
s[i] = 'a';
}
}
k %= 26;
if (k > 0) {
s[$ - 1] = (s[$ - 1] + k).to!char;
}
writeln(s);
}
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;
void main() {
writeln("ABC" ~ readln());
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
if (S[0] != 'A' || !inside(S[1]-'a', 0, 26) || !inside(S[$-1]-'a', 0, 26))
{
debug writeln("A", " ", S[1]-'a');
writeln("WA");
}
else
{
debug writeln("B");
bool ok = true;
long cnt;
foreach (c; S)
{
if (c == 'C')
++cnt;
else if (!inside(S[1]-'a', 0, 26))
ok = false;
}
debug writeln(cnt, " ", ok);
if (cnt != 1) ok = false;
writeln(ok ? "AC" : "WA");
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm, std.array;
void main()
{
int n, m;
scanf("%d %d", &n, &m);
int[] map;
map.length=n;
for (int i = 0; i < m; i++) {
int from, to;
scanf("%d %d", &from, &to);
from--;
to--;
map[from]++;
map[to]++;
}
foreach(routenum; map) {
writeln(routenum);
}
}
|
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 K = readln.chomp.to!int;
auto N = S.length.to!int;
auto dp = new long[][][](N+1, 2, K+1);
dp[0][0][0] = 1;
foreach (i; 0..N) foreach (j; 0..2) foreach (k; 0..K+1) foreach (d; 0..10) {
if (d != 0 && k == K) continue;
if (j == 0 && d > S[i] - '0') continue;
dp[i+1][j||(d<S[i]-'0')][k+(d!=0)] += dp[i][j][k];
}
long ans = dp[N][0][K] + dp[N][1][K];
ans.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;
long ans = 700;
foreach (c; S)
{
if (c == 'o')
ans += 100;
}
writeln(ans);
stdout.flush();
debug readln();
}
|
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;
bool calc(string s) {
int[char] d;
foreach (c; s) {
d[c]++;
}
return d.values.all!(e => e % 2 == 0);
}
void main() {
auto s = read!string;
writeln(calc(s) ? "Yes" : "No");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b, t; readV(a, b, t);
writeln(t/a*b);
}
|
D
|
void main()
{
long n = rdElem;
void dfs(string s, long len, long cnt)
{
if (len == n)
{
s.writeln;
return;
}
foreach (i; 0 .. cnt+2)
{
long num = max(cnt, (s[len-1] - 'a') + 1);
if (i <= num) dfs(s~lowercase[i], len+1, num);
}
}
dfs("a", 1, 0);
}
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
|
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);
auto c1 = s.length.iota.count!(i => s[i] != (i%2 ? '0' : '1'));
auto c2 = s.length.iota.count!(i => s[i] != (i%2 ? '1' : '0'));
writeln(min(c1, c2));
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
struct Spl{auto r="".splitter;auto rd(){r=readln.splitter;}auto bd(T)(ref T t){t=r.front.to!T;r.popFront;}}
auto _s = Spl();
auto getV(T...)(ref T t){foreach(ref u;t)_s.bd(u);}
auto getA(T)(size_t n,ref T t){t=new T(n);foreach(ref u;t)_s.bd(u);}
auto readV(T...)(ref T t){_s.rd; getV(t);}
void main()
{
int p, q, r; readV(p, q, r);
writeln(min(p+q, q+r, r+p));
}
|
D
|
import std.stdio, std.string, std.algorithm, std.array;
void main()
{
int t;
scanf("%d", &t);
getchar();
foreach(i; 0..t){
int n, s;
scanf("%d %d", &n, &s);
auto num_zero = (n - 1) / 2;
writeln(s / (n - num_zero));
}
}
|
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 L, R, D;
scan(L, R, D);
long ans;
foreach (x; L .. R + 1)
{
if (x % D == 0)
{
ans++;
// writeln(x);
}
}
writeln(ans);
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;
import core.stdc.stdlib;
void main()
{
auto M = scanElem;
auto K = scanElem;
if(K >= pow(2, M)){
writeln(-1);
return;
}
if(M==0){
if(K==0){
writeln("0 0");
return;
}else{
writeln(-1);
return;
}
}
if(M==1){
if(K==0)
{
writeln("0 0 1 1");
return;
}
writeln(-1);
return;
}
if(K==0){
foreach(i; 0..pow(2, M))
{
write(i);
write(" ");
write(i);
write(" ");
}
writeln("");
return;
}
foreach(i; 0..pow(2, M))
{
if(K==i)continue;
write(i);
write(" ");
}
write(K);
write(" ");
foreach_reverse(i; 0..pow(2, M))
{
if(K==i)continue;
write(i);
write(" ");
}
write(K);
write(" ");
}
long gcd(long a, long b)
{
if(b == 0) return a;
return gcd(b, a % b);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(T[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio, std.conv, std.array,std.string,std.algorithm;
void main()
{
auto input=readln.split;
writeln(max(input[0].to!int*input[1].to!int,input[2].to!int*input[3].to!int));
}
|
D
|
void main()
{
long[] tmp = readln.split.to!(long[]);
long x = tmp[0], y = tmp[1];
writeln(log2(y/x).to!long + 1);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
enum P = 10L^^9+7;
void main()
{
auto N = readln.chomp.to!int;
auto DP = new long[][](N+1, 4);
DP[0][0] = 1;
foreach (i; 0..N) {
(DP[i+1][0] += DP[i][0] * 8 % P) %= P;
(DP[i+1][1] += DP[i][0] + DP[i][1] * 9 % P) %= P;
(DP[i+1][2] += DP[i][0] + DP[i][2] * 9 % P) %= P;
(DP[i+1][3] += DP[i][1] + DP[i][2] + DP[i][3] * 10 % P) %= P;
}
writeln(DP[N][3]);
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.4.0"
+/
import std.stdio, std.range, std.algorithm, std.conv;
import core.bitop;
// import dcomp.scanner;
void main() {
auto sc = new Scanner(stdin);
int n;
sc.read(n);
int[][] g = new int[][](n);
foreach(i; 0..n-1) {
int a, b;
sc.read(a, b); a--; b--;
g[a] ~= b; g[b] ~= a;
}
long dfs(int p, int b) {
long one, two;
foreach (d; g[p]) {
if (d == b) continue;
long x = dfs(d, p);
two |= one & x;
one |= x;
}
int off = two ? two.bsr + 1 : 0;
one = ((one >> off) + 1) << off;
return one;
}
writeln(dfs(0, -1).bsr);
}
/* 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;
}
string[] buf;
private bool succ() {
while (!buf.length) {
if (f.eof) return false;
buf = f.readln.split;
}
return true;
}
private bool readSingle(T)(ref T x) {
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
//string or char[10] etc
x = buf.front;
buf.popFront;
} else {
static if (isStaticArray!T) {
//static
assert(buf.length == T.length);
}
x = buf.map!(to!E).array;
buf.length = 0;
}
} else {
x = buf.front.to!T;
buf.popFront;
}
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);
}
}
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3]));
assert(equal(c[], "ab"));
assert(equal(d, "cde"));
assert(e == 1.0);
assert(equal(f, [1.0, 2.0]));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto abc = readln.split.to!(int[]);
writeln(abc[2] <= abc[0] + abc[1] ? "Yes" : "No");
}
|
D
|
import std.stdio;
import std.algorithm;
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 = split(my_readln());
auto X = to!ulong(tokens[0]);
auto Y = to!ulong(tokens[1]);
writeln(X + Y / 2);
stdout.flush();
}
|
D
|
import std;
bool calc(int k, int a, int b) {
for (int i = 0; i <= b; i++) {
auto x = i * k;
if (a <= x && x <= b) return true;
}
return false;
}
void main() {
int k; scan(k);
int a, b; scan(a, b);
writeln(calc(k, a, b) ? "OK" : "NG");
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int a, b;
scan(a);
scan(b);
writeln(6 - a - b);
}
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 core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
auto s = sread();
auto a = s[0 .. 2].to!(long);
auto b = s[2 .. 4].to!(long);
if(a <= 12 && b <= 12)
{
if(a == 0 && b == 0)
{
writeln("NA");
}
else if(a == 0)
{
writeln("YYMM");
}
else if(b == 0)
{
writeln("MMYY");
}
else
{
writeln("AMBIGUOUS");
}
}
else if(a > 12)
{
if(b == 0 || b > 12)
{
writeln("NA");
}
else
{
writeln("YYMM");
}
}
else
{
if(a == 0 || a > 12)
{
writeln("NA");
}
else
{
writeln("MMYY");
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto l = readln.split.to!(int[]);
auto H = l[0];
auto W = l[1];
auto A = l[2];
auto B = l[3];
char[][] R;
R.length = H;
foreach (h; 0..H) {
foreach (w; 0..W) {
bool x;
if (h < B) x = !x;
if (w < A) x = !x;
R[h] ~= x ? '1' : '0';
}
}
foreach (r; R) writeln(r);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nx = readln.split.to!(int[]);
auto N = nx[0];
auto X = nx[1];
int r = 1, d;
foreach (l; readln.split.to!(int[])) {
d += l;
if (d > X) break;
++r;
}
writeln(r);
}
|
D
|
import std.stdio, std.string;
void main(){
auto s = readln().chomp();
if( s.length == 4 && s[1]==s[2] &&
(s[0] == s[1] || s[2] == s[3]))
writeln("Yes");
else writeln("No");}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
bool[11] vars;
string input;
bool check() {
string[] eq = input.split("=");
bool val(string s) {
int index = 0;
bool parse() {
if (s[index] == 'T') {
index++;
return true;
}
if (s[index] == 'F') {
index++;
return false;
}
if ('a' <= s[index] && s[index] <= 'k') {
bool x = vars[s[index] - 'a'];
index++;
return x;
}
if (s[index] == '-') {
index++;
return (!parse);
}
if (s[index] == '(') {
index++;
bool x = parse;
if (s[index] == '*') {
index++;
bool y = parse;
assert(s[index] == ')');
index++;
return (x & y);
} else if (s[index] == '+') {
index++;
bool y = parse;
assert(s[index] == ')');
index++;
return (x | y);
} else { //
assert(s[index] == '-' && s[index+1] == '>');
index += 2;
bool y = parse;
assert(s[index] == ')');
index++;
return (y | (!x));
}
}
assert(0);
}
return parse;
}
return val(eq[0]) == val(eq[1]);
}
void main() {
test: while (true) {
input = readln.chomp;
if (input == "#") break;
for (int i = 0; i < (1 << 11); i++) {
for (int j = 0; j < 11; j++) {
vars[j] = (i & (1 << j)) ? true : false;
}
if (!check) {
"NO".writeln;
continue test;
}
}
"YES".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 n; readV(n);
writeln((n+110)/111*111);
}
|
D
|
import std.stdio;
import std.string;
import std.format;
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.concurrency;
import std.traits;
import std.uni;
import std.regex;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/5;
void main() {
string s = readln.chomp;
writeln(s[2]==s[3] && s[4]==s[5] ? "Yes" : "No");
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (y > 0 && t * y < x) t++;
if (y < 0 && t * y > x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (y > 0 && t * y > x) t--;
if (y < 0 && t * y < x) t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach(i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
void scanln(Args...)(auto ref Args args) {
enum sep = " ";
enum n = Args.length;
enum fmt = n.rep!(()=>"%s").join(sep);
string line = readln.chomp;
static if (__VERSION__ >= 2074) {
line.formattedRead!fmt(args);
} else {
enum argsTemp = n.iota.map!(
i => "&args[%d]".format(i)
).join(", ");
mixin(
"line.formattedRead(fmt, " ~ argsTemp ~ ");"
);
}
}
// 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);
}
}
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
return x;
}
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.math;
import std.string;
void main()
{
uint ans = 0 - 1;
int[] a = readln.split.to!(int[]);
foreach (i; 0..3){
foreach (j; 0..3) {
foreach (k; 0..3) {
int t_ans = 0;
if (i == j || j == k || k == i)
continue;
t_ans += abs(a[j]-a[i]);
t_ans += abs(a[j]-a[k]);
ans = min(ans, t_ans);
}
}
}
writeln(ans);
}
|
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;
long idx = -1;
bool matched;
for(long i = (s.count-t.count); i >= 0; i--) {
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;
break;
}
}
}
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.algorithm;
import std.string;
import std.conv;
import std.math;
void main(){
int ans = 0;
while(true){
auto s = readln();
if(stdin.eof()) break;
s = chomp(s);
for(int i=0;i<s.length;i++){
char c = s[i];
if('1' <= c && c <= '9' ){
int temp = 0;
while('0' <= s[i+temp] && s[i+temp] <= '9'){
temp++;
if(i+temp==s.length) break;
}
ans += to!int(s[i..i+temp]);
i += temp;
}
}
}
writeln(ans);
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto N = readln.chomp.to!int;
auto S = readln.chomp.to!(char[]);
auto K = readln.chomp.to!int;
char C = S[K-1];
foreach(i; 0..N){
if(S[i] != C){
S[i] = '*';
}
}
writeln(S);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main() {
string input;
const string[] classBoxing = ["light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"];
while ((input = readln.chomp).length != 0) {
double weight = input.to!double;
uint index;
if (weight <= 48.00) {
index = 0;
} else if (weight <= 51.00) {
index = 1;
} else if (weight <= 54.00) {
index = 2;
} else if (weight <= 57.00) {
index = 3;
} else if (weight <= 60.00) {
index = 4;
} else if (weight <= 64.00) {
index = 5;
} else if (weight <= 69.00) {
index = 6;
} else if (weight <= 75.00) {
index = 7;
} else if (weight <= 81.00) {
index = 8;
} else if (weight <= 91.00) {
index = 9;
} else {
index = 10;
}
writeln(classBoxing[index]);
}
}
|
D
|
import std.algorithm,
std.string,
std.range,
std.stdio,
std.conv;
void main() {
int N = readln.chomp.to!int,
K = readln.chomp.to!int,
X = readln.chomp.to!int,
Y = readln.chomp.to!int;
int ans;
if (N <= K) {
ans = N * X;
} else {
int cost1 = K * X,
cost2 = (N - K) * Y;
ans = cost1 + cost2;
}
writeln(ans);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
writeln(readln.chomp.to!int ^^ 2 - readln.chomp.to!int);
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;
import std.typecons;
import std.math;
void main(){
string s = readln().chomp();
string t = readln().chomp();
solve(s,t).writeln();
}
string solve(string s,string t){
string result;
string doubleS = s ~ s;
result = !find(doubleS, t).empty ? "Yes" : "No";
return result;
}
|
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();
long ans;
foreach (stat; 0 .. (1 << (S.length - 1)))
{
long score;
long tmp = S[0] - '0';
foreach (i; 1 .. S.length)
{
// writeln(tmp, " ", i, " ", stat & (1 << (i - 1)));
if (stat & (1 << (i - 1)))
{
// writeln(tmp);
score += tmp;
tmp = S[i] - '0';
continue;
}
tmp = tmp * 10 + (S[i] - '0');
}
score += tmp;
// writefln("%05b %s", stat, score);
ans += score;
}
writeln(ans);
}
|
D
|
import std.stdio;
void main(){
foreach(i;1..10)
foreach(j;1..10)
writeln(i,"x",j,"=",i * j);
}
|
D
|
import std.stdio;
int main() {
for(int i=1; i<=9; i++) for(int j=1; j<=9; j++) printf("%dx%d=%d\n", i, j, i*j);
return 0;
}
|
D
|
import std.stdio,std.string,std.conv;
int main()
{
string s;
while((s = readln.chomp).length != 0)
{
bool flag = true;
for(int i=0;i<7;i += 3)
{
if(s[i] != 's' && s[i] == s[i+1] && s[i+1] == s[i+2])
{
s[i].writeln;
flag = false;
break;
}
}
if(flag)
{
foreach(i;0..3)
{
if(s[i] != 's' && s[i] == s[i+3] && s[i+3] == s[i+6])
{
s[i].writeln;
flag = false;
break;
}
}
}
if(flag)
{
if(s[0] != 's' && s[0] == s[4] && s[4] == s[8])
{
s[0].writeln;
flag = false;
}
}
if(flag)
{
if(s[2] != 's' && s[2] == s[4] && s[4] == s[6])
{
s[2].writeln;
flag = false;
}
}
if(flag)
{
writeln("d");
}
}
return 0;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
while (1) {
auto n = readln.chomp.to!int;
if (!n) break;
int[] list;
int cnt;
foreach (i; 0..n) {
auto x = readln.chomp.to!int;
foreach (e; list) {
if (x < e) cnt++;
}
list ~= x;
}
cnt.writeln;
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 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 main()
{
auto N = RD;
auto s = new string[](N);
auto t = new long[](N);
foreach (i; 0..N)
{
s[i] = RD!string;
t[i] = RD;
}
auto X = RD!string;
long ans;
bool f;
foreach (i; 0..N)
{
if (f)
{
ans += t[i];
}
else
{
if (s[i] == X)
{
f = true;
}
}
}
writeln(ans);
stdout.flush;
debug readln;
}
|
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, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long r, g, b, n;
scan(r, g, b, n);
long cnt;
foreach (i; iota(n / r + 1))
{
foreach (j; iota(n / g + 1))
{
auto k = n - (i * r) - (j * g);
if (k >= 0 && k % b == 0)
{
// writefln("i is %s, j is %s, k is %s", i, j, k);
cnt++;
}
}
}
cnt.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;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto n = lread();
auto p = aryread();
// writeln(p);
auto min_x = new long[](n); //i番目にiまでの最小値
min_x[0] = p[0];
foreach (i; 1 .. n)
{
min_x[i] = min(min_x[i - 1], p[i]);
}
// writeln(min_x);
long cnt;
foreach (i; 0 .. n)
{
if (p[i] <= min_x[i])
{
cnt += 1;
}
}
writeln(cnt);
}
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, 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 n = RD!int;
auto k = RD!int;
auto a = RD!string;
auto b = RD!string;
auto aa = new int[](26);
auto bb = new int[](26);
foreach (i; 0..n)
{
++aa[a[i]-'a'];
++bb[b[i]-'a'];
}
auto c = new int[](26);
foreach (i; 0..26)
{
c[i] = aa[i] - bb[i];
}
bool ok = true;
foreach (i; 0..25)
{
if (c[i] < 0)
{
ok = false;
break;
}
else if (c[i] % k)
{
ok = false;
break;
}
else
{
c[i+1] += c[i];
}
}
if (c[$-1] != 0)
ok = false;
ans[ti] = ok;
}
foreach (e; ans)
{
writeln(e ? "Yes" : "No");
}
stdout.flush;
debug readln;
}
|
D
|
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.numeric;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
p = stdin.rawRead (buffer);
}
final ubyte skipByte (ubyte lo) {
while (true) {
auto a = p[cur .. $];
auto r = a.find! (c => c >= lo);
if (!r.empty) {
cur += a.length - r.length;
return p[cur++];
}
p = stdin.rawRead (buffer);
cur = 0;
if (p.empty) return 0;
}
}
final ubyte nextByte () {
if (cur < p.length) {
return p[cur++];
}
p = stdin.rawRead (buffer);
if (p.empty) return 0;
cur = 1;
return p[0];
}
template next(T) if (isSigned!T) {
final T next () {
T res;
ubyte b = skipByte (45);
if (b == 45) {
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
final T next () {
T res = skipByte (48) - 48;
while (true) {
ubyte b = nextByte ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
final T[] nextA(T) (int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
void main() {
auto r = new InputReader;
foreach (t; 0 .. r.next!uint) {
auto a = r.next!uint;
auto b = r.next!uint;
writeln (gcd (a, b) == 1 ? "Finite" : "Infinite");
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
auto s=readln.chomp.to!(char[]);
auto pat=['a', 'i', 'u', 'e', 'o'];
int tot=0;
foreach(char c; s){
if('0'<=c && c<='9'){
int x=c-'0';
if(x&1) tot++;
}else{
if(count(pat, c)>0) tot++;
}
}
writeln(tot);
}
/*
vowel => even
odd => NOT vowel
*/
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) write(e, " ");
writeln();
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
void main() {
auto s = readln.split.map!(to!long).array;
auto B = s[0];
auto K = s[1];
auto A = readln.split.map!(to!long).array;
long X = 0;
B %= 2;
foreach (i, a; A) {
if (i != K - 1) {
X += B * a % 2;
X %= 2;
} else {
X += a % 2;
X %= 2;
}
}
writeln(X ? "odd" : "even");
}
|
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 = 998244353;
void main() {
auto S = readln.chomp;
auto N = S.length.to!int;
S ~= S;
char prev = S[0];
int tmp = 0;
int ans = 0;
foreach (i; 0..2*N) {
if (S[i] == prev) {
tmp = 1;
} else {
tmp += 1;
}
ans = max(ans, tmp);
prev = S[i];
}
ans = min(ans, N);
ans.writeln;
}
|
D
|
import std.stdio,std.conv,std.algorithm,std.array;
int[] raia() { return readln().split().map!(to!int).array; } //read stdin as int[]
void main(){
for(auto i =0; i< 10000;i++)
{auto it = raia();
if(it[0] == 0 && it[1] == 0){ return;}
else if( it[0] > it[1]){
writeln(it[1]," ",it[0]);
}else{
writeln(it[0]," ",it[1]);
}
}
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main()
{
long n;
long sum;
n = readln.chomp.to!(long);
for (long i = 1; i <= n; i++) {
if (i % 15 == 0) {
continue;
}
if (i % 3 == 0) {
continue;
}
if (i % 5 == 0) {
continue;
}
sum += i;
}
writeln(sum);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;
void main() {
int n, m, k; scan(n, m, k);
foreach (i ; 0 .. n + 1) {
foreach (j ; 0 .. m + 1) {
if ((m - j)*i + (n - i)*j == k) {
writeln("Yes");
return;
}
}
}
writeln("No");
}
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;
void main() {
auto n = readln.split.join.to!int;
foreach (i ; 0 .. n) {
if (i*i > n) break;
if (i*i == n) {
writeln("Yes");
return;
}
}
writeln("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
|
void main() {
int a = readln.chomp.to!int;
int b = readln.chomp.to!int;
int c = readln.chomp.to!int;
int x = readln.chomp.to!int;
int cnt;
foreach (i; 0 .. a+1) {
foreach (j; 0 .. b+1) {
int tmp = (x - 500 * i - 100 * j) / 50;
if (0 <= tmp && tmp <= c) ++cnt;
}
}
cnt.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
writeln(readln.chomp.to!int <= 999 ? "ABC" : "ABD");
}
|
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()
{
while (1) {
auto field = new char[14][14];
field[0][] = '0';
field[$-1][] = '0';
foreach (i; 1..13) {
field[i][] = '0';
auto str = readln.chomp;
foreach (j; 1..13) {
field[i][j] = str[j-1];
}
}
int cnt;
foreach (i; 1..13) {
foreach (j; 1..13) {
if (field[i][j] == '0') continue;
void solve(int x, int y) {
field[x][y] = '0';
for (int i = -1; i <= 1; i+=2) {
if (field[x][y+i] == '1')
solve(x, y+i);
if (field[x+i][y] == '1')
solve(x+i, y);
}
}
cnt++;
solve(i,j);
}
}
cnt.writeln;
if (!readln) break;
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.