code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
void main()
{
dchar[] s = readln.chomp.to!(dchar[]);
dchar[] t = s.dup;
reverse(t);
long cnt;
foreach (i; 0 .. s.length/2)
{
if (s[i] != t[i]) ++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.string, std.conv;
void main()
{
while(true)
{
int n=readln.chomp.to!int;
if(!n)break;
int num;
for(int i=1; i<n; ++i)
{
int sum;
for(int j=i; j<n; ++j)
{
sum+=j;
if(sum == n) ++num;
else if(sum > n) break;
}
}
num.writeln;
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
int sum = 0;
foreach(int i; 0..5) {
sum += max(40, readln.chomp.to!int);
}
writeln(sum/5);
}
|
D
|
import std;
void main(){
int n, k;
int[] as;
scanf("%d %d\n", &n, &k);
auto mem = new bool[n];
foreach(_i; 0..k) {
int d;
scanf("%d", &d);
foreach (_j; 0..d) {
int a;
scanf("%d", &a);
mem[a-1] |= true;
}
}
mem.count!"!a".writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto S_ = readln.chomp.to!(wchar[]);
auto T = readln.chomp.to!(wchar[]);
wchar[] S;
foreach_reverse (i; 0..S_.length - T.length + 1) {
auto s = S_.dup;
foreach_reverse (j; 0..T.length) {
if (S_[i+j] == '?')
s[i+j] = T[j];
else if (S_[i+j] != T[j])
goto loop;
}
S = s;
break;
loop:
}
if (S) {
foreach (ref c; S) if (c == '?') c = 'a';
writeln(S);
} else {
writeln("UNRESTORABLE");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp;
if (N%2 == 1) {
writeln("No");
return;
}
foreach (i; 0..N/2) {
if (S[i] != S[N/2+i]) {
writeln("No");
return;
}
}
writeln("Yes");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n, k; readV(n, k);
int[] d; readA(k, d);
auto b = new bool[](10);
foreach (di; d) b[di] = true;
auto isOK(int n)
{
while (n > 0) {
if (b[n%10]) return false;
n /= 10;
}
return true;
}
foreach (i; n..100000)
if (isOK(i)) {
writeln(i);
return;
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main(){
while(true){
auto s = readln();
if(stdin.eof()) break;
real w = to!real(chomp(s));
if(w <= 48.0) writeln("light fly");
else if(w <= 51.0) writeln("fly");
else if(w <= 54.0) writeln("bantam");
else if(w <= 57.0) writeln("feather");
else if(w <= 60.0) writeln("light");
else if(w <= 64.0) writeln("light welter");
else if(w <= 69.0) writeln("welter");
else if(w <= 75.0) writeln("light middle");
else if(w <= 81.0) writeln("middle");
else if(w <= 91.0) writeln("light heavy");
else writeln("heavy");
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void main()
{
int n; readV(n);
int a; readV(a);
writeln(n*n-a);
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const N = readln.chomp.to!long;
iota(1,N+1).filter!(x => x < 10 || (100 <= x && x < 1000) || (10000 <= x && x < 100000)).walkLength.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;
immutable long MOD = 10^^9 + 7;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto K = s[1];
auto Comb = new Combination(100000);
foreach (i; 1..K+1) {
long x = Comb.comb(N-K+1, i);
long y = Comb.comb(K-1, i -1);
writeln(x * y % MOD);
}
}
class Combination {
long[] modinv;
long[] f_mod;
long[] f_modinv;
this(int size) {
modinv = new long[](size);
modinv[0] = modinv[1] = 1;
foreach(i; 2..size) {
modinv[i] = modinv[MOD.to!int % i] * (MOD - MOD / i) % MOD;
}
f_mod = new long[](size);
f_modinv = new long[](size);
f_mod[0] = f_mod[1] = 1;
f_modinv[0] = f_modinv[1] = 1;
foreach(i; 2..size) {
f_mod[i] = (i * f_mod[i-1]) % MOD;
f_modinv[i] = (modinv[i] * f_modinv[i-1]) % MOD;
}
}
long comb(long n, long k) {
if (n < k) return 0;
return f_mod[n.to!int] * f_modinv[(n-k).to!int] % MOD * f_modinv[k.to!int] % MOD;
}
}
long powmod(long a, long x, long m) {
long ret = 1;
while (x) {
if (x % 2) ret = ret * a % m;
a = a * a % m;
x /= 2;
}
return ret;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp.to!(char[]);
auto T = readln.chomp.to!(char[]);
int r;
foreach (i; 0..3) if (S[i] == T[i]) ++r;
writeln(r);
}
|
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 R, G, B, N;
scan(R, G, B, N);
long ans;
foreach (r; 0 .. N / R + 1)
{
long M = N - r * R;
foreach (g; 0 .. M / G + 1)
{
if ((M - g * G) % B == 0)
ans++;
}
}
writeln(ans);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.array;
int n; rd(n);
long[int] freq;
auto y=new int[](n);
auto ng=new bool[](n);
foreach(i; 0..n){
auto s=readln.chomp.to!(char[]);
char[] st;
foreach(c; s){
if(c=='('){
st~='(';
}else{
if(st.length>0){
if(st.back=='(') st=st[0..($-1)];
else st~=')';
}else{
st~=')';
}
}
}
int x=0;
foreach(c; st){
if(c=='(') x++;
else x--;
}
if(st.length>=2 && (st[0]==')' && st[$-1]=='(')){ng[i]=true; continue;}
y[i]=x;
if(x in freq) freq[x]++;
else freq[x]=1;
hell:;
}
long tot=0;
foreach(i; 0..n)if(ng[i]==false){
if(y[i]>=0 && (-y[i] in freq)){
tot+=freq[-y[i]];
}
// writeln(tot);
}
writeln(tot);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
|
D
|
import std.stdio;
import std.algorithm;
void main()
{
int n;
scanf("%d", &n);
bool[] used = new bool[n];
char[] gender = new char[n];
int[] from = new int[n];
int[] to = new int[n];
for (int i = 0; i < n; i++) {
char[10] s;
scanf("%s%d%d", s.ptr, &from[i], &to[i]);
gender[i] = s[0];
}
int res = 0;
for (int i = 1; i <= 366; i++) {
char[2] genders = ['F', 'M'];
int[2] found = [0, 0];
for (int j = 0; j < 2; j++) {
for (int k = 0; k < n; k++) {
if (!used[k] && gender[k] == genders[j] && from[k] <= i && to[k] >= i) {
found[j]++;
}
}
}
res = max(res, min(found[0], found[1]));
}
printf("%d\n", 2 * res);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (i; 0..t)
{
auto a = RD!int;
auto b = RD!int;
auto x = min(a, b);
auto y = cast(long)max(a, b);
auto arr = new bool[](x);
foreach (j; 1..10^^5)
{
auto z = (y*j) % x;
arr[cast(int)z] = true;
}
bool ok = true;
foreach (j; 0..arr.length)
{
if (arr[j] == false)
{
ok = false;
break;
}
}
ans[i] = ok;
}
foreach (e; ans)
{
writeln(e ? "Finite" : "Infinite");
}
stdout.flush();
debug readln();
}
|
D
|
module _;
void main() {
import std.stdio;
import std.string, std.conv;
int n = readln.strip.to!int;
auto s = readln.strip;
bool check(int limit, ref string co, bool doco) {
int r = 0, b = 0;
foreach(ch; s) {
if (ch == '(') {
if (r < limit) {
r++;
if (doco) co ~= '0';
} else if (b < limit) {
b++;
if (doco) co ~='1';
} else {
return false;
}
} else {
if (r > 0) {
r--;
if (doco) co ~= '0';
} else if (b > 0) {
b--;
if (doco) co ~='1';
} else {
// impossible
return false;
}
}
}
return true;
}
string ans = "";
int l = 0, r = n;
while (l < r-1) {
int mid = (l+r)/2;
if (check(mid, ans, false)) {
r = mid;
} else {
l = mid;
}
}
check(r, ans, true);
writeln(ans);
}
|
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 T = RD!int;
foreach (i; 0..T)
{
auto n = RD!int;
auto s = RD!int;
auto t = RD!int;
auto x = min(s, t);
writeln(n - x + 1);
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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 s = RD!string;
if (k == 0)
ans[ti] = true;
else if (n <= k*2)
continue;
else
{
int l, r = n-1;
int cnt;
while (l < r)
{
if (s[l] != s[r])
break;
++l; --r;
++cnt;
}
ans[ti] = cnt >= k;
}
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.15f";
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 M = RD;
auto K = RD;
bool ans;
foreach (i; 0..N+1)
{
foreach (j; 0..M+1)
{
auto x = i * M + j * N - (i * j * 2);
if (x == K)
ans = true;
}
}
writeln(ans ? "Yes" : "No");
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
string a, b; readV(a, b);
auto n = (a ~ b).to!int;
writeln(n.nsqrt^^2 == n ? "Yes" : "No");
}
pure T nsqrt(T)(T n)
{
import std.algorithm, std.conv, std.range, core.bitop;
if (n <= 1) return n;
T m = 1 << (n.bsr/2+1);
return iota(1, m).map!"a * a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}
|
D
|
void main()
{
string s = rdStr;
long len = s.length;
long[][] dp = new long[][](len+1, 4);
dp[0][0] = 1;
foreach (i, x; s)
{
long c = (x == '?' ? 3 : 1);
foreach (j; 0 .. 4)
{
dp[i+1][j] = (dp[i+1][j] + c * dp[i][j]) % mod;
if (j == 3) continue;
if (x == '?' || j == x - 'A')
{
dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
}
}
}
dp[len][3].writeln;
}
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.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 r = RD;
writeln((r^^2)*3);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio,std.string,std.conv,std.algorithm;
import std.algorithm:rev=reverse;
int main(){
auto s=readln.chomp.dup;
foreach(t;s[1..3]){
if(t!=s[0]){
writeln("Yes");
return 0;
}
}
writeln("No");
return 0;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long A, B, C;
scan(A, B, C);
writeln(min(C, B / A));
}
|
D
|
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;
void main(){
while(true){
auto s = readln();
if(stdin.eof()) break;
int n = to!int(chomp(s));
int ans = 1;
for(int i=1;i<=n;i++)
ans += i;
writeln(ans);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;
import std.math;
void main(){
auto z=readln.split.map!(to!int);
auto A=z[0]+z[1];
auto B=z[0]-z[1];
auto C=z[0]*z[1];
writeln(max(A,B,C));
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
auto S = sread();
writeln(S == "ABC" ? "ARC" : "ABC");
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
bool solve (string s, string t)
{
if ((s.length % 2) != (t.length % 2))
{
s = s[1..$];
}
int pos = 0;
bool skip = false;
foreach (ref c; s)
{
if (skip)
{
skip = false;
continue;
}
if (t[pos] == c)
{
pos += 1;
}
else
{
skip = true;
}
if (pos == t.length)
{
return true;
}
}
return false;
}
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
auto t = readln.strip;
writeln (solve (s, t) ? "YES" : "NO");
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.math;
void main() {
auto input = getStdin!(int[])()[0];
auto result = pow(input, 3);
result.writeln;
}
T getStdin(T)() {
string[] cmd;
string line;
while ((line = chomp(stdin.readln())) != "") cmd ~= line;
return to!(T)(cmd);
}
|
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;
final class InputReader {
private:
ubyte[] p, buffer;
bool eof;
bool rawRead () {
if (eof) {
return false;
}
p = stdin.rawRead (buffer);
if (p.empty) {
eof = true;
return false;
}
return true;
}
ubyte nextByte(bool check) () {
static if (check) {
if (p.empty) {
if (!rawRead ()) {
return 0;
}
}
}
auto r = p.front;
p.popFront ();
return r;
}
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
}
bool seekByte (in ubyte lo) {
while (true) {
p = p.find! (c => c >= lo);
if (!p.empty) {
return false;
}
if (!rawRead ()) {
return true;
}
}
}
template next(T) if (isSigned!T) {
T next () {
if (seekByte (45)) {
return 0;
}
T res;
ubyte b = nextByte!false ();
if (b == 45) {
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
T next () {
if (seekByte (48)) {
return 0;
}
T res = nextByte!false () - 48;
while (true) {
ubyte b = nextByte!true ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
T[] nextA(T) (in int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
void main() {
auto r = new InputReader ();
immutable nt = r.next!uint ();
foreach (tid; 0 .. nt) {
const uint h = r.next!uint ();
const uint w = r.next!uint ();
auto a = new char[][](h, w);
foreach (j; 0 .. h) {
foreach (i; 0 .. w) {
if (i || j) write ('B'); else write('W');
}
writeln;
}
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main(){
string str;
while((str = readln()).length != 0){
int n = to!int(chomp(str));
int cv;
foreach(a; 0 .. 10){
foreach(b; 0 .. 10){
foreach(c; 0 .. 10){
int d = n - a - b - c;
if(0 <= d && d <= 9){
cv++;
}
}
}
}
writeln(cv);
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const N = readln.chomp.to!long;
const S = readln.chomp;
auto leftList = new long[N+1];
foreach (i; 0..N) leftList[i+1] = S[i] == 'E' ? 1 : 0;
foreach (i; 0..N) leftList[i+1] += leftList[i];
auto rightList = new long[N+1];
foreach (i; 0..N) rightList[i+1] = S[i] == 'W' ? 1 : 0;
foreach (i; 0..N) rightList[i+1] += rightList[i];
iota(N+1).map!(i => rightList[i] + leftList[$-1] - leftList[i]).reduce!min.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, core.bitop;
// dfmt on
void main()
{
long T = lread();
foreach (i; 0 .. T)
{
long N, M, A, B;
scan(N, M, A, B);
floor_sum(N, M, A, B).writeln();
}
}
long floor_sum(long n, long m, long a, long b)
{
long ans;
if (m <= a)
{
ans += (n - 1) * n * (a / m) / 2;
a %= m;
}
if (m <= b)
{
ans += n * (b / m);
b %= m;
}
long y_max = (a * n + b) / m, x_max = (y_max * m - b);
if (y_max == 0)
return ans;
ans += (n - (x_max + a - 1) / a) * y_max;
ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
return ans;
}
|
D
|
import std.stdio;
import std.string;
void main() {
auto s = readln.chomp;
foreach (i;0..s.length) {
write('x');
}
writeln();
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;
immutable int inf = 1<<20;
void main(){
int N, M, a, b, c;
readVars(N, M);
auto cost = new int[][](N, N);
foreach(i ; 0 .. N){
foreach(j ; i + 1 .. N){
cost[i][j] = inf;
cost[j][i] = inf;
}
}
foreach (i ; 0 .. M){
readVars(a, b, c);
cost[a - 1][b - 1] = c;
cost[b - 1][a - 1] = c;
}
//writefln("%(%s\n%)", cost);
auto dist = new int[][](N, N);
foreach (i ; 0 .. N){
foreach (j ; i + 1 .. N){
dist[i][j] = cost[i][j];
dist[j][i] = dist[i][j];
}
}
//writefln("%(%s\n%)", dist);
foreach(k ; 0 .. N){
foreach(i ; 0 .. N){
foreach(j ; i + 1 .. N){
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
dist[j][i] = dist[i][j];
}
}
}
int ans;
foreach(i ; 0 .. N){
foreach(j ; i + 1 .. N){
if(cost[i][j] < inf && dist[i][j] != cost[i][j]){
ans++;
}
}
}
writeln(ans);
}
void readVars(T...)(auto ref T args){
auto line = readln.split;
foreach(ref arg ; args){
arg = line.front.to!(typeof(arg));
line.popFront;
}
if(!line.empty){
throw new Exception("args num < input num");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;
void main()
{
auto N = readln.chomp.to!(char[]);
if (N.length == 1) {
writeln(N);
return;
}
long ret, r;
foreach (i, d; N) {
if (!i) {
long s = d-49;
if (!s) s = 1;
s *= (9L^^(N.length-1));
ret = s;
r = d-48;
} else if (i == N.length-1) {
ret = max(ret, r * (d-48));
} else {
long s = d-49;
if (!s) {
r *= d-48;
continue;
}
s = r * s * 9L^^(N.length-i-1);
ret = max(ret, s);
r *= d-48;
}
}
writeln(ret);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; long y; rd(n, y);
for(int i=0; i<=n; i++)for(int j=0; i+j<=n; j++){
auto k=n-(i+j);
if(10000*i+5000*j+1000*k == y){
writeln(i, " ", j, " ", k); return;
}
}
writeln(-1, " ", -1, " ", -1);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) write(e, " ");
writeln();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto s = readln.chomp.to!(dchar[]);
foreach (i, c; s) if (i % 2 == 0) write(c);
writeln("");
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
auto p = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1];
int x, y;
scan(x, y);
writeln(p[x] == p[y] ? "Yes" : "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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
long[(10^^6)*2+50] F, RF;
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
long inv(long x)
{
return pow(x, P-2);
}
void init()
{
F[0] = F[1] = 1;
foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;
{
RF[$-1] = 1;
auto x = F[$-1];
auto k = P-2;
while (k) {
if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
x = x^^2 % P;
k /= 2;
}
}
foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}
long comb(N)(N n, N k)
{
if (k > n) return 0;
auto n_b = F[n]; // n!
auto nk_b = RF[n-k]; // 1 / (n-k)!
auto k_b = RF[k]; // 1 / k!
auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!
return (n_b * nk_b_k_b) % P; // n! / (n-k)!k!
}
void main()
{
init();
auto K = readln.chomp.to!long;
auto S = readln.chomp;
auto len = S.length.to!long;
long x;
foreach (k; 0..K+1) {
auto y = comb(len+K, len+k) * pow(25, K-k) % P;
(x += y) %= P;
}
writeln(x);
}
|
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, x = scan!int, t = scan!int;
int ans = (n + x - 1) / x * t;
ans.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;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int;
writeln(n/3);
}
|
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 a = RD;
auto b = RD;
writeln((a+b)/2 + (a+b)%2);
stdout.flush();
debug readln();
}
|
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.count('+').to!int - s.count('-').to!int);
}
|
D
|
import std.functional,
std.algorithm,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
void main() {
int[] XYZ = readln.chomp.split.to!(int[]);
int X = XYZ[0],
Y = XYZ[1],
Z = XYZ[2];
int n = X - Z;
writeln(n / (Y + Z));
}
|
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);
foreach (x; 0 .. 10000)
{
if (A == (x * 8 / 100) && B == (x * 10 / 100))
{
writeln(x);
return;
}
}
writeln(-1);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.array, std.string;
import std.range;
void main(string[] args) {
auto input = readln().chomp.split.map!(to!int);
if(input[0] <= 8 && input[1] <= 8){
"Yay!".writeln;
}else{
":(".writeln;
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
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;
string[] str = ["dream", "dreamer", "erase", "eraser"];
long pos = S.length, lastPos = pos;
bool isWrong;
while (pos != 0)
{
foreach (e; str)
{
auto len = e.length;
if (pos-len >= 0 && S[pos-len..pos] == e)
{
pos -= len;
break;
}
}
if (pos == lastPos)
{
isWrong = true;
break;
}
lastPos = pos;
}
writeln(isWrong ? "NO" : "YES");
stdout.flush();
//readln();
}
|
D
|
import std;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long a, b;
scan(a, b);
if ((a <= 9) && (b <= 9))
{
writeln(a * b);
}
else
{
writeln(-1);
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
auto binary_search(long key, long[] l)
{
long left = 0; //lの左端
long right = l.length - 1; //lの右端
while (right >= left)
{
long mid = left + (right - left) / 2; //区間の真ん中
if (l[mid] == key)
{
return mid;
}
else if (l[mid] > key)
{
right = mid - 1;
}
else if (l[mid] < key)
{
left = mid + 1;
}
}
return -1;
}
// auto a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910];
// auto a = aryread();
// writeln(a);
// long len_a = a.length;
// writeln(len_a);
// long ans;
// ans = binary_search(51, a);
// writeln(ans);
|
D
|
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto n = readln.split[0].to!int;
auto n1 = n/100, n2 = (n - n1*100)/10, n3 = (n - n1*100 - n2*10);
if (n1 == 1) n1 = 9; else if (n1 == 9) n1 = 1;
if (n2 == 1) n2 = 9; else if (n2 == 9) n2 = 1;
if (n3 == 1) n3 = 9; else if (n3 == 9) n3 = 1;
writeln(n1*100 + n2*10 + n3);
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
while (true) {
int n, w, h;
int s, t;
scan(n);
if (!n) return;
scan(w, h);
auto bd = new int[][](w + 1, h + 1);
foreach (i ; 0 .. n) {
int xi, yi;
scan(xi, yi);
bd[xi][yi]++;
}
scan(s, t);
solve(n, w, h, s, t, bd);
}
}
void solve(int n, int w, int h, int s, int t, int[][] bd) {
int ans;
foreach (i ; 1 .. w - s + 2) {
foreach (j ; 1 .. h - t + 2) {
int cnt;
foreach (k ; i .. i + s) {
foreach (l ; j .. j + t) {
cnt += bd[k][l];
}
}
ans = max(ans, cnt);
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
void main()
{
bool[3] cups;
cups[0] = true;
while(true)
{
auto line = readln;
if(!line)break;
auto f = line.chomp.split(",");
swap(cups[f[0][0] - 'A'], cups[f[1][0] - 'A']);
}
foreach(i, cup; cups)
{
if(cup) writeln(cast(char)('A' + i));
}
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/+---test
aabbaa
---+/
/+---test
aaaccacabaababc
---+/
void main(string[] args) {
const S = readln.chomp;
long ans;
string prev;
string cur;
foreach (i, s; S) {
cur ~= s;
if (cur != prev) {
prev = cur;
cur = "";
++ans;
}
}
ans.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp;
auto ls = new bool[][](N, 10);
auto rs = new bool[][](N, 10);
foreach (i; 0..N) {
if (i != 0) {
foreach (j; 0..10) {
ls[i][j] = ls[i-1][j];
}
}
ls[i][S[i] - '0'] = true;
}
foreach_reverse (i; 0..N) {
if (i != N-1) {
foreach (j; 0..10) {
rs[i][j] = rs[i+1][j];
}
}
rs[i][S[i] - '0'] = true;
}
auto rr = new bool[](1000);
foreach (i; 1..N-1) {
foreach (a; 0..10) foreach (c; 0..10) {
if (ls[i-1][a] && rs[i+1][c]) rr[a*100 + (S[i] - '0')*10 + c] = true;
}
}
int res;
foreach (i, r; rr) if (r) {
++res;
}
writeln(res);
}
|
D
|
void main() {
string a = readln.chomp;
string b = readln.chomp;
if (a.length > b.length) {
"GREATER".writeln;
} else if (a.length < b.length) {
"LESS".writeln;
} else {
if (a > b) {
"GREATER".writeln;
} else if (a < b) {
"LESS".writeln;
} else {
"EQUAL".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
|
void main(){
int n = _scan();
int a, b;
if(n==2){
a = _scan();
b = _scan();
}
writeln( n==1? "Hello World": ( a+b ).to!string);
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.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;
int k = read.to!int;
char[] as = readln.chomp.to!(char[]);
int l0, r0, l1, r1;
bool f0, f1;
foreach(int i, a; as){
if(a == '1'){
if(! f0) l0 = i, f0 = 1;
r0 = i;
}
else{
if(! f1) l1 = i, f1 = 1;
r1 = i;
}
}
if(r0 - l0 + 1 <= k || r1 - l1 + 1 <= k){
// can take in one move
"tokitsukaze".writeln;
return;
}
if(r0 - l0 + 1 >= k + 2 || r1 - l1 + 1 >= k + 2){
// flips {l + 1, ..., r - 1} or so
"once again".writeln;
return;
}
if(l0 <= k - 1 && r0 >= n - k || l1 <= k - 1 && r1 >= n - k){
// First cannot avoid taking one stone
"quailty".writeln;
return;
}
"once again".writeln;
}
/*
Second can always mimic the First. So,
- First wins at his first move.
- Whatever move First plays, Second wins at the next move.
*/
|
D
|
void main(){
int n = _scan();
int ans;
if(n<600)ans=8;
else if(n<800)ans=7;
else if(n<1000)ans=6;
else if(n<1200)ans=5;
else if(n<1400)ans=4;
else if(n<1600)ans=3;
else if(n<1800)ans=2;
else if(n<2000)ans=1;
ans.writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format, std.datetime;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long H, W;
scan(H, W);
auto A = new string[](H);
foreach (i; 0 .. H)
A[i] = sread();
auto dp = new long[][](H, W);
dp[0][0] = 1;
foreach (h; 0 .. H - 1)
{
foreach (w; 0 .. W - 1)
if (A[h][w] == '.')
{
dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % MOD;
dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % MOD;
}
if (A[h][W - 1] == '.')
dp[h + 1][W - 1] = (dp[h + 1][W - 1] + dp[h][W - 1]) % MOD;
}
foreach (w; 0 .. W - 1)
if (A[H - 1][w] == '.')
dp[H - 1][w + 1] = (dp[H - 1][w + 1] + dp[H - 1][w]) % MOD;
writeln(dp[$ - 1][$ - 1]);
}
|
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;
auto n = X / 100;
auto d = X % 100;
int c;
while (d >= 5) {
d -= 5;
++c;
}
if (d >= 4) {
d -= 4;
++c;
}
if (d >= 3) {
d -= 3;
++c;
}
if (d >= 2) {
d -= 2;
++c;
}
if (d >= 1) {
++c;
}
writeln(c <= n ? 1 : 0);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
import std.typecons : Tuple;
alias Edge = Tuple!(int, "to", int, "cost");
void main() {
int n,m;
scan(n,m);
auto adj = new Edge[][](n, 0);
foreach (i ; 0 .. m) {
int a, b, c;
scan(a, b, c);
a--, b--;
adj[a] ~= Edge(b, c);
}
auto mark = new int[](n);
auto top = new int[](0);
bool heiro = 0;
void visit(int i) {
if (mark[i] == 2) {
return;
}
else if (mark[i] == 1) {
heiro = 1;
return;
}
else {
mark[i] = 1;
foreach (e ; adj[i]) {
visit(e.to);
}
mark[i] = 2;
top ~= i;
return;
}
}
foreach (i ; 0 .. n) {
if (!mark[i]) {
visit(i);
}
}
if (heiro) {
writeln("No");
return;
}
top.reverse();
debug {
writeln(top);
}
immutable inf = 10L^^17;
auto d = new long[](n);
d[] = inf;
d[top.front] = 0;
foreach (i ; top) {
foreach (e ; adj[i]) {
if (d[e.to] == inf) {
d[e.to] = d[i] + e.cost;
}
else {
if (d[e.to] != d[i] + e.cost) {
writeln("No");
return;
}
}
}
}
writeln("Yes");
}
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.algorithm, std.array;
auto solve(string s_) {
immutable N = s_.to!int();
auto ab = new long[2][N];
foreach(ref v;ab) v = readln.split.map!(to!long).array();
long c=0;
foreach_reverse(ref v;ab) {
immutable a=v[0], b=v[1];
c+=(b-(a+c)%b)%b;
}
return c;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
|
D
|
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.math;
void main() {
auto N = readln.chomp.to!ulong;
writeln(pow(N, 3));
}
|
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;
int a, b;
void main() {
int a, b, c;
scan(a, b, c);
writeln(min(min(a + b, b + c), a + c));
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
int r = readln.chomp.to!(int);
if (r < 1200) {
writeln("ABC");
}
else if (r < 2800) {
writeln("ARC");
}
else {
writeln("AGC");
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new int[](t);
foreach (i; 0..t)
{
auto n = RD!int;
int a, b = int.max;
foreach (j; 0..n)
{
auto l = RD!int;
auto r = RD!int;
a = max(a, l);
b = min(b, r);
}
if (a <= b)
ans[i] = 0;
else
ans[i] = a-b;
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string;
void main(){
auto s=readln.chomp;
foreach(i;0..s.length-1)if(s[i]==s[i+1]){
writeln(i+1," ",i+2);
return;
}
foreach(i;0..s.length-2)if(s[i]==s[i+2]){
writeln(i+1," ",i+3);
return;
}
writeln("-1 -1");
}
|
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)() { 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 cell = new uint[][](N * 2, N * 2);
long[2][] b, r;
foreach (i; 0..N)
{
r ~= [RD!long, RD!long];
cell[r[$-1][0]][r[$-1][1]] = 1;
}
foreach (i; 0..N)
{
b ~= [RD!long, RD!long];
cell[b[$-1][0]][b[$-1][1]] = 2;
}
auto dp = new long[](N*2);
long ans;
foreach_reverse (i; 1..N*2)
{
foreach_reverse (j; 1..N*2)
{
if (cell[i][j] == 2)
{
//stderr.writeln("b ", i, ":", j);
foreach (k; 0..j+1)
++dp[k];
}
if (cell[i-1][j-1] == 1 && dp[j] > 0)
{
//stderr.writeln(dp);
//stderr.writeln(i-1, ":", j-1);
++ans;
auto x = dp[j];
foreach (k; j..N*2)
{
if (dp[k] != x) break;
--dp[k];
}
foreach_reverse (k; 0..j)
{
--dp[k];
}
//stderr.writeln(dp);
}
}
}
writeln(ans);
stdout.flush();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto m = readln.chomp.to!int;
writeln(48 - m);
}
|
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 A, B;
scan(A, B);
lcm(A, B).writeln();
}
T lcm(T)(T a, T b)
{
return (a * b) / gcd(a, b);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
void main()
{
auto N = readln.chomp.to!long;
auto s = readln.chomp.to!(char[]);
auto DP = new long[][](N, N);
foreach (i; 0..N) DP[0][i] = 1;
foreach (i; 1..N) {
long c;
if (s[i-1] == '<') {
foreach_reverse (j; 0..N-i+1) {
DP[i][j] = c;
c = (c + DP[i-1][j]) % P;
}
} else {
foreach (j; 0..N-i+1) {
c = (c + DP[i-1][j]) % P;
DP[i][j] = c;
}
}
}
writeln(DP[$-1][0]);
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], b = tmp[1], c = tmp[2], d = tmp[3];
writeln(abs(a-c) <= d || max(abs(a-b), abs(b-c)) <= d ? "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.uni;
|
D
|
import std.stdio;
import std.math;
import std.conv;
import std.string;
void main() {
const int MAX = 1000000;
int[MAX] p;
p[2] = 1;
for (int i = 3; i < MAX; i++) {
if (i % 2 == 0) {
p[i] = p[i-1];
} else if (isPrime(i)) {
p[i] = p[i-1] + 1;
} else {
p[i] = p[i-1];
}
}
foreach (string line; stdin.lines) {
int n = line.chomp.to!int;
p[n].writeln;
}
}
bool isPrime(double e) {
bool res = true;
for (int i = 3; i <= sqrt(e); i += 2) {
if (e % i == 0) {
res = false;
break;
}
}
return res;
}
|
D
|
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
void main() {
int n=to!int(readln().strip());
for(int i=0;i<n;i++){
auto bs=readln().split().map!(to!int)().array();
int s1=-1,s2=-1;
bool flag = true;
for(int j=0;j<10;j++){
if(s1<bs[j]&&bs[j]-s1<bs[j]-s2)s1=bs[j];
else if(s2<bs[j]&&bs[j]-s1>bs[j]-s2)s2=bs[j];
else if(s1<bs[j]) s1=bs[j];
else if(s2<bs[j]) s2=bs[j];
else {flag=false;break;}
}
if(flag) writeln("YES");
else writeln("NO");
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
string n; rd(n);
if(n[0]=='9' || n[1]=='9') writeln("Yes");
else writeln("No");
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
import std.format;
import std.array;
import std.math;
import std.string;
import std.container;
void main() {
int N, T; readlnTo(N, T);
int ans = int.max;
foreach(i; 0..N) {
int c, t; readlnTo(c, t);
if (t <= T)
ans = min(c, ans);
}
if (ans == int.max) "TLE".writeln;
else ans.writeln;
}
// helpers
void readlnTo(T...)(ref T t) {
auto s = readln.split;
assert(s.length == t.length);
foreach(ref ti; t) {
ti = s[0].to!(typeof(ti));
s = s[1..$];
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto h = readln.chomp.to!int;
writeln((a+b)*h/2);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n;
scan(n);
writeln(800*n - (n/15)*200);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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 N = RD;
auto M = RD;
auto Q = RD;
auto abcd = new long[][](Q);
foreach (i; 0..Q)
{
abcd[i] = [RD-1, RD-1, RD, RD];
}
long dfs(long[] arr)
{
if (arr.length == N)
{
long score;
foreach (i; 0..Q)
{
auto a = abcd[i][0];
auto b = abcd[i][1];
auto c = abcd[i][2];
auto d = abcd[i][3];
if (arr[b]-arr[a] == c)
score += d;
}
return score;
}
long res;
foreach (i; arr[$-1]..M+1)
{
res.chmax(dfs(arr ~ i));
}
return res;
}
long ans;
foreach (i; 1..M+1)
{
ans.chmax(dfs([i]));
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import core.stdc.stdio;
import std.typecons;
import std.conv;
import std.container;
import std.algorithm;
void main(){
int n,m,x;
scanf("%d%d%d",&n,&m,&x);
int[] hs = new int[n];
for(int i=0;i<n;i++)
scanf("%d",&hs[i]);
alias Tuple!(long,"cost",int,"idx") ci;
ci[][] graph = new ci[][n];
for(int i=0;i<m;i++){
int a,b;
long t;
scanf("%d%d%lld",&a,&b,&t);
--a;
--b;
if(hs[a]>=t)
graph[a] ~= ci(t,b);
if(hs[b]>=t)
graph[b] ~= ci(t,a);
}
alias Tuple!(long,"cost",long,"down",int,"idx") cdi;
alias BinaryHeap!(cdi[],"a>b") pq;
pq q = pq(new cdi[400000],0);
q.insert(cdi(max(0,hs[n-1]-x),0,0));
long ans=-1;
bool[] visited = new bool[n];
while(!q.empty){
cdi t = q.front;
q.removeFront;
with(t){
if(idx==n-1){
ans=cost;
break;
}
if(visited[idx])
continue;
visited[idx] = true;
foreach(cs;graph[idx]){
if(!visited[cs.idx]){
cdi nx;
nx.idx = cs.idx;
nx.down = down+cs.cost;
if(x-nx.down>hs[cs.idx])
nx.down = x-hs[cs.idx];
if(x-nx.down<hs[n-1])
nx.cost = hs[n-1]-(x-nx.down);
nx.cost += nx.down;
q.insert(nx);
}
}
}
}
printf("%lld\n",ans);
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto c = readln.chomp.to!int;
auto d = readln.chomp.to!int;
auto e = readln.chomp.to!int;
auto k = readln.chomp.to!int;
if((b-a) <= k && (c-a) <= k && (d-a) <= k && (e-a) <= k && (c-b) <= k && (d-b) <= k && (e-b) <= k && (d-c) <= k && (e-c) <= k && (e-d) <= k){
writeln("Yay!");
} else {
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;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int % 500;
if (readln.chomp.to!int >= n) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
long[10^^5+50] F, RF;
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
void init()
{
F[0] = F[1] = 1;
foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;
{
RF[$-1] = 1;
auto x = F[$-1];
auto k = P-2;
while (k) {
if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
x = x^^2 % P;
k /= 2;
}
}
foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}
void main()
{
init();
auto N = readln.chomp.to!int;
auto S = readln.chomp.to!(char[]);
int[] PS;
PS.length = N*2;
int x;
foreach (i, c; S) {
if (c == 'B') {
if (x%2 == 0) {
PS[i] = 1;
++x;
} else {
PS[i] = -1;
--x;
}
} else {
if (x%2 == 0) {
PS[i] = -1;
--x;
} else {
PS[i] = 1;
++x;
}
}
}
if (x != 0 || PS[0] == -1 || PS[$-1] == 1) {
writeln(0);
return;
}
int mc;
long r = 1;
foreach_reverse (p; PS) {
if (p == -1) {
++mc;
} else {
r = (r * mc--) % P;
}
}
writeln((r * F[N]) % P);
}
|
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;
writeln("2018" ~ s[4..$]);
}
|
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;
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;
void main()
{
long N,K;
scan(N,K);
char[] S = sread().dup;
S[K-1] -= 'A' - 'a';
writeln(S);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
bool acgt(char c) {
return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}
void main()
{
auto S = readln.chomp.to!(char[]);
int max_l = 0;
foreach (int i; 0..cast(int)S.length) {
if (!acgt(S[i])) continue;
auto j = i;
while (j < S.length && acgt(S[j])) ++j;
max_l = max(max_l, j-i);
}
writeln(max_l);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto nk = aryread();
bool b = (nk[0] + 1) / 2 >= nk[1];
writeln(b ? "YES" : "NO");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto S = readln.chomp.to!(char[]);
if (S.length == 3) S.reverse();
writeln(S);
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.array;
import std.numeric, std.math, std.typecons, std.container, core.bitop;
void main() {
int n,a,b;
scan(n,a,b);
writeln((b-a)&1 ? "Borys" : "Alice");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main() {
while(true) {
string [] s = split(readln());
int H = to!int(s[0]);
int W = to!int(s[1]);
if(H==0 && W==0) break;
for(int i=0;i<H;i++) {
for(int j=0;j<W;j++) {
if((i+j) % 2 ==0) {
write("#");
} else {
write(".");
}
}
writeln();
}
writeln();
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.math;
int f(int x, int y) {
return x - y + 1;
}
void main() {
int n = readln.strip.to!int;
int h = readln.strip.to!int;
int w = readln.strip.to!int;
writeln(f(n, h) * f(n, w));
}
|
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);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
string[2] s;
s[0] = sread();
s[1] = sread();
foreach (i; 0 .. s[0].length + s[1].length)
write(s[i & 1][i / 2]);
writeln();
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons;
// }}}
// nep.scanner {{{
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string : chomp;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.chomp.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
}
// }}}
int[] getTable() {
bool[] era = new bool[100010];
era[2 .. $] = true;
for (int i = 0; i * i < era.length; i++)
{
if (!era[i]) continue;
for (int j = i + i; j < era.length; j += i)
{
era[j] = false;
}
}
int[] res = new int[100010];
foreach (i; 0 .. era.length)
{
if (era[i] && era[(i + 1) / 2])
{
res[i] = 1;
}
}
foreach (i; 1 .. res.length) {
res[i] += res[i - 1];
}
return res;
}
void main()
{
static auto imos = getTable;
auto cin = new Scanner;
int q;
cin.scan(q);
foreach (i; 0 .. q) {
int l, r;
cin.scan(l, r);
writeln(imos[r] - imos[l - 1]);
}
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n, a, b;
scan(n, a, b);
auto ans = powmod(2, n);
long na = f(n, a);
long nb = f(n, b);
ans -= (na + nb) % mod;
if (ans < 0) ans += mod;
ans--;
if (ans < 0) ans += mod;
writeln(ans);
}
long f(int n, int a) {
long res = 1;
foreach (i ; 0 .. a) {
res *= (n - i);
res %= mod;
res *= powmod(a - i, mod - 2);
res %= mod;
}
return res;
}
long powmod(long x, long y) {
return y > 0 ? powmod(x, y >> 1)^^2 % mod * x^^(y & 1) % mod : 1L;
}
struct ModComb {
int _N;
long[] _fact, _factinv;
long _mod;
this(int n, long mod = 1_000_000_007L) {
_N = n;
_fact = new long[](_N + 1);
_factinv = new long[](_N + 1);
_mod = mod;
_fact[0] = 1;
foreach (i ; 1 .. _N + 1) {
_fact[i] = (_fact[i-1] * i) % mod;
}
_factinv[_N] = _powmod(_fact[_N], mod - 2);
foreach_reverse (i ; 0 .. _N) {
_factinv[i] = (_factinv[i+1] * (i+1)) % mod;
}
}
long c(int n, int k) {
if (k < 0 || k > n) return 0;
return f(n) * finv(n - k) % _mod * finv(k) % _mod;
}
long p(int n, int r) {
if (r < 0 || r > n) return 0;
return f(n) * finv(n - r) % _mod;
}
long f(int n) {
return _fact[n];
}
long finv(int n) {
return _factinv[n];
}
long _powmod(long x, long y) {
return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
}
}
unittest {
auto mc = ModComb(1_000_000);
assert(mc.c(5, 2) == 10);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);
void main() {
string s = readln.chomp;
foreach (i;0..3) if (s[i] == s[i + 1]) {
writeln("Bad");
return;
}
writeln("Good");
}
|
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 n = RD!int;
auto s = RD!string;
auto cnt = new long[](26);
foreach (i; 0..n)
{
auto c = s[i] - 'a';
++cnt[c];
}
foreach (i; 0..26)
{
auto c = cast(char)('a'+i);
foreach (j; 0..cnt[i])
ans[ti] ~= c;
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
alias route = Tuple!(long, "From", long, "To");
long bignum = 1_000_000_007;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long x, y;
scan(x, y);
if (x % y)
{
foreach (n; 0 .. y)
{
if(n * x % y)
{
writeln(n * x);
return;
}
}
}
else
{
writeln(-1);
}
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main ()
{
string a;
while ((a = readln.strip) != "")
{
auto n = a.length.to !(int);
int [char] w;
foreach (c; a)
{
w[c] += 1;
}
auto res = 1 + (n * (n - 1L)) / 2;
foreach (k, v; w)
{
res -= (v * (v - 1L)) / 2;
}
writeln (res);
}
}
|
D
|
import std.functional,
std.algorithm,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
void main() {
long N = readln.chomp.to!long;
bool[long] A;
foreach (_; 0..N) {
long a = readln.chomp.to!long;
if (a in A) {
A[a] = !A[a];
} else {
A[a] = true;
}
}
long ans;
foreach (k, v; A) {
if (v) { ans++; }
}
writeln(ans);
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.