code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio;
void main(){
for(int i = 1; i < 10; ++i){
for(int j = 1; j < 10; ++j){
writeln(i,"x",j,"=",i*j);
}
}
}
|
D
|
import std.stdio;
void main(){
foreach(i; 1..10)
foreach(j; 1..10)
writeln(i,"x",j,"=",i*j);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long a,b;
scan(a,b);
((a - 1) * (b - 1)).writeln();
}
|
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 n;
int[] a;
void main() {
scan(n);
a = readln.split.to!(int[]);
int b1, b2, b3;
foreach (ai ; a) {
if (ai & 1) {
b1++;
}
else if (ai & 3) {
b2++;
}
else {
b3++;
}
}
writeln(b1 <= b3 + !b2 ? "Yes" : "No");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static 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 S = RD!string;
auto T = RD!string;
long ans;
foreach (i; 0..3)
{
if (S[i] == T[i])
++ans;
}
writeln(ans);
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.string;
void main() {
auto s = readln.split.map!(to!long);
auto N = s[0].to!int;
auto K = s[1];
auto A = readln.split.map!(to!long).array;
long X = 0;
auto B = K.bsr + 1;
bool less = false;
foreach_reverse (i; 0..B) {
if (!less && !(K & (1L << i))) {
continue;
}
long y = 0;
long z = 0;
foreach (a; A) {
if (a & (1L << i)) {
y += 1;
} else {
z += 1;
}
}
if (y > z) {
if (!less) less = true;
} else {
X += (1L << i);
}
}
long ans = 0;
foreach (a; A) ans += (X ^ a);
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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }
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;
if (n % 2) continue;
for (long i = 1; i*i <= n; ++i)
{
if (n % i) continue;
if (i*i*2 == n || i*i*4 == n)
{
ans[ti] = true;
}
}
}
foreach (e; ans)
{
writeln(e ? "YES" : "NO");
}
stdout.flush;
debug readln;
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
immutable int infinity = int.max / 2;
immutable int NA = -1;
void main ()
{
string s;
while ((s = readln.strip) != "")
{
auto t = readln.strip;
auto k = s.length.to !(int);
auto n = t.length.to !(int);
auto p = new int [k];
p[] = NA;
int [] stack;
foreach (j; 0..k)
{
if (s[j] == '.')
{
if (!stack.empty)
{
p[j] = stack.back;
stack.popBack ();
stack.assumeSafeAppend ();
}
}
else
{
stack ~= j;
}
}
auto f = new int [] [] (2, k + 1);
int b = 0;
f[b][0] = 0;
foreach (j; 1..k + 1)
{
f[b][j] = f[b][j - 1] + 1;
if (p[j - 1] != NA)
{
f[b][j] = min (f[b][j], f[b][p[j - 1]]);
}
}
foreach (i; 0..n)
{
b ^= 1;
f[b][] = infinity;
foreach (j; i + 1..k + 1)
{
f[b][j] = f[b][j - 1] + 1;
if (t[i] == s[j - 1])
{
f[b][j] = min (f[b][j], f[!b][j - 1]);
}
if (p[j - 1] != NA)
{
f[b][j] = min (f[b][j], f[b][p[j - 1]]);
}
}
}
writeln (f[b][k]);
}
}
|
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;
immutable long MOD = 10^^6 + 3;
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;
}
int gaussianElimination(ref long[][] org_mat, ref long[] ret) {
int N = org_mat.length.to!int;
auto mat = new long[][](N, N+1);
foreach (i; 0..N)
foreach (j; 0..N+1)
mat[i][j] = org_mat[i][j];
foreach (i; 0..N) {
long maxval = 0;
int maxrow = -1;
foreach (j; i..N)
if (abs(mat[j][i]) > maxval)
maxval = abs(mat[j][i]), maxrow = j;
if (maxval == 0)
return -1;
swap(mat[i], mat[maxrow]);
foreach (j; i+1..N+1)
mat[i][j] = mat[i][j] * powmod(mat[i][i], MOD-2, MOD) % MOD;
mat[i][i] = 1;
foreach (j; 0..N) {
if (j == i) continue;
long mul = mat[j][i];
foreach (k; i..N+1) {
(mat[j][k] -= mul * mat[i][k] % MOD) %= MOD;
mat[j][k] = (mat[j][k] + MOD) % MOD;
}
}
}
foreach (i; 0..N)
ret[i] = mat[i][N];
return 0;
}
long[] B;
long ask(long x) {
writeln("? ", x);
debug {
long res = 0;
foreach (i; 0..11) (res += B[i] * powmod(x, i, MOD) % MOD) %= MOD;
return res;
}
stdout.flush;
return readln.chomp.to!long;
}
void ans(long x) {
writeln("! ", x);
return;
}
void main() {
debug {
B = new long[](11);
B[0] = 1000002;
B[2] = 1;
}
int N = 11;
auto mat = new long[][](N, N+1);
foreach (i; 0..N) {
foreach (j; 0..N) mat[i][j] = powmod(i, j, MOD);
mat[i][N] = ask(i);
}
auto A = new long[](N);
gaussianElimination(mat, A);
foreach (i; 0..MOD) {
long res = 0;
foreach (j; 0..N) (res += A[j] * powmod(i, j, MOD) % MOD) %= MOD;
if (res == 0) {
ans(i);
return;
}
}
ans(-1);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.array;
int n; rd(n);
auto a=readln.split.to!(int[]);
if(a.length%2==0){writeln("No"); return;}
if(a.front%2==1 && a.back%2==1){
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, 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 N = readln.chomp.to!int;
auto S = readln.chomp;
if (N == 1) {
writeln("Yes");
return;
}
auto cnt = new int[](26);
foreach (s; S) cnt[s - 'a'] += 1;
bool ok = false;
foreach (i; 0..26) if (cnt[i] >= 2) ok = true;
writeln(ok ? "Yes" : "No");
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
import std.numeric;
void main() {
int n = readln.chomp.to!int;
long sum = 0;
for(int i=1; i<=n; i++) {
if(!(i%3==0 || i%5==0)) sum += i;
}
writeln(sum);
}
|
D
|
void main(){
long n = _scan!long();
long[] a = _scanln!long();
long q = _scan!long();
long[long] dic;
long ans;
// 合計値と参照辞書の作成
foreach(elm; a){
ans += elm;
dic[elm]++;
}
// replace 操作
foreach(i; 0..q){
long[] bc = _scanln!long();
ans += bc[1]*dic.get(bc[0], 0) - bc[0]*dic.get(bc[0], 0);
dic[bc[1]] += dic.get(bc[0], 0);
dic[bc[0]] = 0;
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 std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
void main()
{
auto S = readln.chomp;
auto DP = new long[][](S.length, 4);
foreach (ref dp; DP) dp[] = -1;
long solve(int i, int s) {
if (i == S.length) return s == 3 ? 1 : 0;
if (DP[i][s] == -1) {
long r;
auto c = S[i];
if (c == 'A' || c == '?') {
r = (r + solve(i+1, s)) % P;
if (s == 0) r = (r + solve(i+1, s+1)) % P;
}
if (c == 'B' || c == '?') {
r = (r + solve(i+1, s)) % P;
if (s == 1) r = (r + solve(i+1, s+1)) % P;
}
if (c == 'C' || c == '?') {
r = (r + solve(i+1, s)) % P;
if (s == 2) r = (r + solve(i+1, s+1)) % P;
}
DP[i][s] = r;
}
return DP[i][s];
}
writeln(solve(0, 0));
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
import std.math;
void main(string[] args)
{
auto n = to!int(strip(readln));
int[1001] a;
auto x = split(strip(readln));
foreach (j; 0 .. n)
{
a[to!int(x[j])]++;
}
int count;
int ze = s(a);
while(ze >= 1)
{
count += ze - 1;
ze = s(a);
}
writeln(count);
}
int s(int[] a)
{
int count;
foreach (i, val ; a)
{
if (val >= 1)
count++;
a[i]--;
}
return count;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
char x, y;
scan(x, y);
if (x < y) {
writeln("<");
}
else if (x > y) {
writeln(">");
}
else {
writeln("=");
}
}
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 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()
{
long A, B, C;
scan(A, B, C);
writeln(C - min(A - B, C));
}
|
D
|
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to
import std.math;
import std.algorithm;
void main()
{
string n = chomp(readln());
int N = to!int(n); // 第0要素を整数に変換
string[] input = split(readln());
int a = to!int(input[0]);
int min = a,max = a;
for(int i =1;i<N;i++){
a = to!int(input[i]);
if(min > a){
min = a;
}
if(max < a){
max = a;
}
}
writeln(max - min);
}
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
import std.range;
import std.array;
import std.conv;
void main()
{
while(1){
auto N = readln().chomp().to!uint;
if(N == 0)
break;
auto seq = readln().chomp().split();
uint state;
uint cnt;
uint lastState = 0;
foreach(e; seq){
bool bUpdate;
if(((state & 1) == 0 || (state & 2) == 0) && (e == "lu" || e == "ru")){
bUpdate = true;
state += e == "lu" ? 1 : 2;
}
else if((state & 1) == 1 && e == "ld"){
bUpdate = true;
state -= 1;
}else if((state & 2) == 2 && e == "rd"){
bUpdate = true;
state -= 2;
}
if(bUpdate && (state == 3 || state == 0) && lastState != state){
lastState = state;
++cnt;
}
}
writeln(cnt);
}
}
|
D
|
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;
void main()
{
for (;;) {
auto rd = readln.split.map!(to!int);
auto m = rd[0], f = rd[1], r = rd[2];
if (m == -1 && f == -1 && r == -1) break;
if (m == -1 || f == -1)
writeln("F");
else if (m + f >= 80)
writeln("A");
else if (m + f >= 65 && m + f < 80)
writeln("B");
else if (m + f >= 50 && m + f < 65)
writeln("C");
else if (m + f >= 30 && m + f < 50) {
if (r >= 50)
writeln("C");
else
writeln("D");
}
else
writeln("F");
}
}
|
D
|
import std.stdio, std.conv, std.string, std.range, std.algorithm;
void main() {
int d = readln.chomp.to!int;
("Christmas " ~ repeat("Eve", 25 - d).join(" ")).writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm;
import std.uni, std.range, std.math, std.container, std.datetime;
import core.bitop, std.typetuple, std.typecons;
immutable long MOD = 1_000_000_007;
alias tie = TypeTuple;
alias triplet = Tuple!(int, int, int);
void main(){
int A, B, C;
readVars(A, B, C);
if (C % gcd(A, B) == 0) {
writeln("YES");
} else {
writeln("NO");
}
}
int gcd(int x, int y){
return y ? gcd(y, x % y) : x;
}
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
|
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], m = tmp[1];
string[] a = new string[n], b = new string[m];
foreach (i; 0 .. n) {
a[i] = readln.chomp;
}
foreach (i; 0 .. m) {
b[i] = readln.chomp;
}
bool ok;
foreach (i; 0 .. n-m+1) {
foreach (j; 0 .. n-m+1) {
bool check = true;
foreach (k; 0 .. m) {
if (a[j+k][i..i+m] != b[k]) {
check = false;
}
}
if (check) ok = true;
}
}
writeln(ok ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp.to!(char[]);
auto K = readln.chomp.to!long;
if (S.length == 1) {
writeln(K/2);
return;
}
long[] ns;
long cnt;
char last;
foreach (c; S) {
if (cnt && last != c) {
ns ~= cnt;
cnt = 0;
}
++cnt;
last = c;
}
ns ~= cnt;
if (ns.length == 1) {
writeln(S.length * K / 2);
return;
}
long r;
foreach (n; ns[1..$-1]) r += n/2 * K;
if (S[0] == S[$-1]) {
r += ns[0]/2;
r += ns[$-1]/2;
r += (ns[0] + ns[$-1])/2 * (K-1);
} else {
r += ns[0]/2 * K;
r += ns[$-1]/2 * K;
}
writeln(r);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum mod = 10L^^9 + 7;
enum inf = 10^^9;
void main() {
int n, m;
scan(n, m);
auto c = new int[][](n, n);
foreach (i ; 0 .. n) {
foreach (j ; 0 .. n) {
if (i != j) {
c[i][j] = inf;
}
}
}
foreach (i ; 0 .. m) {
int ai, bi, ci;
scan(ai, bi, ci);
ai--, bi--;
c[ai][bi] = c[bi][ai] = ci;
}
auto dist = new int[][](n, n);
foreach (i ; 0 .. n) {
foreach (j ; 0 .. n) {
dist[i][j] = c[i][j];
}
}
foreach (k ; 0 .. n) {
foreach (i ; 0 .. n) {
foreach (j ; 0 .. n) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
int ans;
foreach (i ; 0 .. n) {
foreach (j ; i + 1 .. n) {
if (c[i][j] == inf) continue;
if (c[i][j] > dist[i][j]) {
ans++;
}
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
bool test (string s) {
if (s.length % 2) return false;
foreach (i; 0 .. s.length) {
if (i % 2) {
if (s[i] != 'i') return false;
} else {
if (s[i] != 'h') return false;
}
}
return true;
}
void main() {
string s = readln.stripRight;
writeln (test (s) ? "Yes" : "No");
}
|
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 N;
sc.scan(N);
foreach (i; 0 .. 100) {
foreach (j; 0 .. 100) {
if ((i * 4) + (j * 7) == N) {
writeln("Yes");
return;
} else if ((j * 4) + (i * 7) == N) {
writeln("Yes");
return;
}
}
}
writeln("No");
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dunkelheit" version=">=0.9.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
int main() {
Scanner sc = new Scanner(stdin);
int n;
string s;
sc.read(n, s);
int ans = 10^^9;
int wc, ec = s.count('E').to!int;
foreach (c; s) {
if (c == 'E') ec--;
ans = min(ans, wc+ec);
if (c == 'W') wc++;
}
writeln(ans);
return 0;
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
import std.exception;
enforce(readSingle(x));
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
read!enforceEOF(args);
}
}
void read(bool enforceEOF = false, Args...)(auto ref Args args) {
import std.exception;
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
enforce(readSingle(args[0]));
read!enforceEOF(args);
}
}
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
|
D
|
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
int B = readln.chomp.to!int;
foreach(i; 1..10) {
foreach(k; 1..10) {
if(B == i*k) {
"Yes".writeln;
return;
}
}
}
"No".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 s = readln.chomp.split;
if (s[0][$-1] == s[1][0] && s[1][$-1] == s[2][0]) {
writeln("YES");
} else {
writeln("NO");
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
writeln(readln.chomp.to!int / 3);
}
|
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;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
alias sread = () => readln.chomp();
void main()
{
auto n = lread();
bool alleven = true;
foreach(i;0..n)
{
auto a = lread();
alleven = alleven && (a % 2 == 0);
}
auto ans = (!alleven)?"first":"second";
ans.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;
import std.ascii;
void times(alias pred)(int n) {
foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = pred();
return res;
}
void main() {
readln.chomp.map!(a => a=='p' ? -1:1).sum.pipe!"a/2".writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long N = lread();
long K = lread();
long m = long.max;
foreach (i; 0 .. N + 1)
{
long a = (2 ^^ i) + (K * (N - i));
// long b = (1 + K * (N - i)) + (2 ^^ i);
// writeln(a);
m.minAssign(a);
}
writeln(m);
}
|
D
|
void main()
{
string s = readln.chomp;
long k = readln.chomp.to!long;
long n = s.countUntil!(x => x != '1');
if (n == -1 || n >= k)
{
s[0].writeln;
}
else
{
s[n].writeln;
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
void main() {
string s = readln.chomp;
int cnt;
foreach (x; s) {
if (x == '+') ++cnt;
else --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.uni;
|
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 M = s[1];
auto K = s[2];
long C = 1;
foreach (i; 1..N*M-1) {
C = C * i % MOD;
}
foreach (i; 1..K-1) {
C = C * powmod(i, MOD-2, MOD) % MOD;
}
foreach (i; 1..(N*M-2-(K-2))+1) {
C = C * powmod(i, MOD-2, MOD) % MOD;
}
long ans = 0;
long tmp = 0;
foreach (i; 0..N) {
long right = N - i - 1;
long left = i;
tmp = (tmp + right * (right + 1) / 2 * M) % MOD;
tmp = (tmp + left * (left + 1) / 2 * M) % MOD;
}
ans += tmp * C % MOD * M % MOD;
ans %= MOD;
tmp = 0;
foreach (i; 0..M) {
long right = M - i - 1;
long left = i;
tmp = (tmp + right * (right + 1) / 2 * N) % MOD;
tmp = (tmp + left * (left + 1) / 2 * N) % MOD;
}
ans += tmp * C % MOD * N % MOD;
ans %= MOD;
ans = ans * powmod(2, MOD-2, MOD) % MOD;
ans.writeln;
}
long powmod(long a, long x, long m) {
long ret = 1;
while (x) {
if (x % 2) ret = ret * a % m;
a = a * a % m;
x /= 2;
}
return ret;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
string f = readln.chomp;
string s = readln.chomp;
auto n = f.length;
bool flag = true;
foreach (i; 0..n) {
flag &= f[i] == s[$ - 1 - i];
}
writeln = flag ? "YES" : "NO";
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void main()
{
auto ip = readln.split.to!(int[]);
if(ip[0] <= 8 && ip[1] <= 8) writeln("Yay!");
else writeln(":(");
}
//writeln("滲み出す混濁の紋章 不遜なる狂気の器 湧き上がり 否定し 痺れ 瞬き 眠りを妨げる 爬行する鉄の王女 絶えず自壊する泥の人形 結合せよ 反発せよ 地に満ち己の無力を知れ 破道の九十 黒棺")
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n, m;
scanf("%d%d", &n, &m);
bool[][] g = new bool[][](n,n);
foreach (i; 0..n) foreach (j; 0..n) {
if (i != j) g[i][j] = true;
}
foreach (i; 0..m) {
int a, b;
scanf("%d%d", &a, &b);
a--;
b--;
g[a][b] = g[b][a] = false;
}
//if (n*(n-1)/2 == m) {
// int s = n/2, t = n-s;
// m -= s*t;
// writeln(m);
// return;
//}
int[] color = new int[n];
color[] = -1;
int[] cnt;
bool dfs(int v, int c) {
if (color[v] != -1) {
if (color[v] != c) return false;
return true;
}
color[v] = c;
cnt[c]++;
foreach (u; 0..n) {
if (g[v][u]) {
if (!dfs(u,c^1)) return false;
}
}
return true;
}
int l = 0;
int[] a;
foreach (i; 0..n) {
if (color[i] != -1) continue;
cnt = new int[2];
if (!dfs(i,0)) {
writeln(-1);
return;
}
cnt.sort;
l += cnt[0];
if (cnt[0] < cnt[1]) a ~= cnt[1]-cnt[0];
}
bool[] dp = new bool[n+1];
dp[0] = true;
foreach (x; a) {
foreach_reverse (i; 0..n-x+1) {
dp[i+x] |= dp[i];
}
}
int ans = m;
int im = n*(n-1)/2-m;
foreach (i; 0..n+1) {
if (!dp[i]) continue;
int s = l+i, t = n-s;
ans = min(ans, m-(s*t-im));
}
writeln(ans);
}
|
D
|
import std.stdio, std.string, std.algorithm, std.conv, std.range, std.array;
void main() {
readln();
auto inp = readln().chomp.split;
string[] b1, b2;
for(int i; i<inp.length; i++){
auto a = inp[i];
if(i%2==0){b1 ~= a;}
else{b2 ~= a;}
}
if(inp.length%2==0){b2.reverse(); (b2 ~ b1).join(" ").writeln;}
else{b1.reverse(); (b1 ~ b2).join(" ").writeln;}
}
|
D
|
void main() {
int x = readln.chomp.to!int;
bool[] ok = new bool[x+1];
ok[1] = true;
for (int i = 2; i * i <= x; ++i) {
for (int j = 2; i ^^ j <= x; ++j) {
ok[i^^j] = true;
}
}
foreach_reverse (i, y; ok) {
if (y) {
i.writeln;
break;
}
}
}
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.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 d, n; readV(d, n);
writeln((n == 100 ? 101 : n)*100^^d);
}
|
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 inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
auto d = ['A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'];
char a;
scan(a);
writeln(d[a]);
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
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.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto nk = readln.split.to!(int[]);
auto N = nk[0];
auto K = nk[1];
readln;
int cnt = 1;
N -= K;
--K;
while (N > 0) {
++cnt;
N -= K;
}
writeln(cnt);
}
|
D
|
import std.stdio,
std.string,
std.conv;
void main() {
int[][] c;
for (int i = 0; i < 3; i++) {
c ~= to!(int[])(readln.chomp.split);
}
int[3] a, b;
// a[0] = 0 と仮定
foreach (i, e; c[0]) {
b[i] = e;
}
for (int i = 1; i < 3; i++) {
a[i] = c[i][i] - b[i];
}
bool f = true;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
// writeln(c[i][j], " == ", a[i], " + ", b[j]);
f = f & (c[i][j] == a[i] + b[j]);
}
}
writeln(f ? "Yes" : "No");
}
|
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();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
ulong MIDDLE = 100_000;
alias Pair = Tuple!(long, "flag", long, "num");
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 n = lread();
auto s = n * (n - 1) / 2;
s.writeln();
}
|
D
|
import core.stdc.stdlib;
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.numeric;
import std.stdio;
import std.string;
// void toBaseMinus2(in long rest, in long digit, in string result)
// {
// // stderr.writeln(rest, ", ", digit, ", ", result.dup.reverse);
// if (rest == 0)
// {
// if (result == "")
// {
// writeln("0");
// }
// else
// {
// writeln(result.dup.reverse);
// }
// exit(0);
// }
// else
// {
// long d = pow(-2, digit);
// if (abs(d) < abs(n))
// {
// toBaseMinus2(rest, digit + 1, result ~ '0');
// toBaseMinus2(rest - d, digit + 1, result ~ '1');
// }
// }
// }
// long n;
void main()
{
// n = readln.chomp.to!long;
// toBaseMinus2(n, 0, "");
// string s;
// long digit = 0;
// while(true) {
// pow(-2, digit);
// }
// for (long k = 30; 0 <= k; --k)
// {
// auto d = pow(-2, k);
// if (d <= n)
// {
// n -= d;
// s ~= '1';
// }
// else
// {
// s ~= '0';
// }
// }
// writeln(s.dup.reverse);
long n = readln.chomp.to!long;
long digit = 0;
string result;
while (n != 0)
{
if (n % pow(2, digit + 1) == 0)
{
result ~= '0';
++digit;
}
else
{
n -= pow(-2, digit);
result ~= '1';
++digit;
}
}
if (result == "")
{
writeln("0");
}
else
{
auto dup = result.dup;
reverse(dup);
writeln(dup);
}
}
|
D
|
import std.stdio, std.string, std.conv;
long solve(long n) {
import std.algorithm;
long result = long.max;
for (long i = 1; i * i <= n; ++i) {
if (n % i == 0) result = min(result, i+n/i-2);
}
return result;
}
void main() {
long n = readln.chomp.to!long;
solve(n).writeln;
}
|
D
|
import std.stdio,
std.string;
void main(){
int w, h;
while(true){
scanf("%d %d", &h, &w);
if( w== 0&&h == 0) break;
for(int i = 0; i < h; ++i){
for(int j = 0; j < w; ++j){
if (i == 0 || i == h-1){
write("#");
}
else if (j == 0 || j == w-1){
write("#");
}else{
write(".");
}
}
writeln();
}
writeln();
}
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
int n = read.to!int;
int m = read.to!int;
bool[] xs;
xs.length = n + 1;
foreach(i; 1 .. n + 1) xs[i] = 0;
foreach(i; 0 .. m){
int a = read.to!int;
int b = read.to!int;
xs[a] = !xs[a];
xs[b] = !xs[b];
}
string ans = "YES";
foreach(x; xs) if(x) ans = "NO";
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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
//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;
auto m = RD;
auto k = RD-1;
if (m < n-1) continue;
auto cnt = n * (n-1) / 2;
if (m > cnt) continue;
long kk;
if (n == 1)
kk = 0;
else if (m == cnt)
kk = 1;
else
kk = 2;
debug writeln("kk:", kk);
if (kk < k)
ans[ti] = true;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
void main() {
auto S = readln.chomp;
string solve(string input) {
foreach(c; ['a','b','c']) {
if (!input.canFind(c)) return "No";
}
return "Yes";
}
solve(S).writeln;
}
|
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() {
scan(a, b);
if (!(a > 0 || b < 0)) {
writeln("Zero");
}
else if (b < 0 && (b - a + 1) & 1) {
writeln("Negative");
}
else {
writeln("Positive");
}
}
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() {
problem();
}
void problem() {
auto a = scan;
string solve() {
return a[$-1] == 's' ? a ~ "es" : a ~ "s";
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
long a, b, c, d, e, f;
rd(a, b, c, d, e, f);
/*
100b/(a+b) < 100b'/(a'+b')
100b*(a'+b') < 100b'*(a+b)
*/
long mx_w=100*a, mx_s;
for(long w1=100*a; w1<=f; w1+=100*a){
for(long w2=0; w2<=f; w2+=100*b){
for(long s1=0; s1<=f; s1+=c){
for(long s2=0; s2<=f; s2+=d){
// cap?
if(w1+w2+s1+s2 > f) continue;
// dissolved?
if(e*(w1+w2)/100 < s1+s2) continue;
if(mx_s*((w1+w2)+(s1+s2)) < (s1+s2)*(mx_w+mx_s)){
mx_w=w1+w2; mx_s=s1+s2;
}
}
}
}
}
writeln(mx_w+mx_s, " ", mx_s);
}
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.string;
import std.conv;
import std.algorithm;
import std.math;
void main() {
int input;
immutable limitList = 500000;
bool[] listNumbers = new bool[](limitList);
int[] listPrimeNumbers;
listNumbers.fill(true);
foreach (i; 2..limitList.to!double.sqrt.to!int) {
if (listNumbers[i]) {
for (int j = i*2; j < limitList; j += i) listNumbers[j] = false;
}
}
foreach (i; 2..listNumbers.length) {
if (listNumbers[i]) {
listPrimeNumbers ~= i.to!int;
}
}
while ((input = readln.chomp.to!int) != 0) {
ulong sum = 0;
foreach (i; 0..listPrimeNumbers.length) {
if (i == input) break;
sum += listPrimeNumbers[i];
}
writeln(sum);
}
}
|
D
|
void main() {
(rs.canFind("9") ? "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.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio;
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;
enum long MOD = 10L^^9+7;
void main() {
string s = readln.chomp;
bool ok = true;
long N = s.length;
foreach(i; 0..N) {
ok &= s[i] == s[N-i-1];
}
foreach(i; 0..(N-1)/2) {
ok &= s[i] == s[(N-1)/2-1-i];
}
foreach(i; (N+3)/2..N) {
ok &= s[i] == s[N-i-1];
}
writeln(ok ? "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.functional,
std.algorithm,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
ulong M = 10UL^^9 + 7;
ulong fact(ulong n) {
if (n <= 1) { return 1; }
else {
return n * fact(n - 1) % M;
}
}
void main() {
ulong n = readln.chomp.to!ulong;
writeln(fact(n));
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
auto sc = new Scanner(stdin);
long q, h, s, d;
sc.read(q, h, s, d);
h = min(h, 2*q);
s = min(s, 2*h);
d = min(d, 2*s);
long n;
sc.read(n); n *= 4;
long sm = 0;
sm += n / 8 * d; n %= 8;
sm += n / 4 * s; n %= 4;
sm += n / 2 * h; n %= 2;
sm += n / 1 * q; n %= 1;
writeln(sm);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
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.range, std.conv, std.algorithm, std.typecons;
void main(){
alias Tuple!(int, "x", int, "y") Point;
int W, H, N;
auto input = readln.split.map!(to!int);
W = input[0], H = input[1], N = input[2];
int total;
Point before;
foreach (i; 0..N) {
input = readln.split.map!(to!int);
Point p;
p.x = input[0], p.y = input[1];
if (i > 0) {
int dx = p.x - before.x, dy = p.y - before.y;
if (dx * dy > 0) {
dx = dx > 0 ? dx : -dx;
dy = dy > 0 ? dy : -dy;
total += max(dx, dy);
} else {
dx = dx > 0 ? dx : -dx;
dy = dy > 0 ? dy : -dy;
total += dx + dy;
}
}
before = p;
}
total.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n;
scanf("%d", &n);
int[] a = new int[n];
foreach (i; 0..n) scanf("%d", &a[i]);
int[int] t;
t[0] = 0;
long ans = 0;
foreach (i; 0..n) {
int[int] prev;
swap(prev, t);
prev[0]++;
foreach (x; prev.byKey()) {
if ((x&a[i]) == 0) {
ans += prev[x];
int y = x|a[i];
if (y in t) {
t[y] += prev[x];
} else {
t[y] = prev[x];
}
}
}
if (!(0 in t)) {
t[0] = 0;
}
}
writeln(ans);
}
|
D
|
import std.stdio,std.string,std.conv;
int main()
{
int[char] roman = ['I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000];
string s;
while((s = readln.chomp).length != 0)
{
int ans = 0;
for(int i=0;i<s.length-1;i++)
{
if(roman[s[i]] >= roman[s[i+1]]) ans += roman[s[i]];
else ans -= roman[s[i]];
}
ans += roman[s[s.length-1]];
writeln(ans);
}
return 0;
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
auto m = 0, a = 1;
foreach (i; 1..n+1) {
auto r = i.bsf;
if (r > m) {
a = i;
m = r;
}
}
writeln(a);
}
pragma(inline) {
pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }
pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
import core.bitop;
pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}
|
D
|
import std.stdio,std.string,std.conv,std.algorithm,std.range,std.array;
void main(){
foreach(_;0..readln.chomp.to!int){
readln.replace("Hoshino","Hoshina").write;
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long a, b;
scan(a, b);
writeln((a - 1) * (b - 1));
}
|
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, M;
scan(N, M);
auto f = factorize(M);
long ans = 1;
auto C = Combination_mod(500000);
foreach (key, val; f)
{
ans *= C(val + N - 1, val);
ans %= MOD;
}
writeln(ans);
}
T[U] factorize(T = long, U = long)(T x)
{
assert(0 < x, "x is negative");
long[long] ps;
while ((x & 1) == 0)
x /= 2, ps[2] = (2 in ps) ? ps[2] + 1 : 1;
for (long i = 3; i * i <= x; i += 2)
while (x % i == 0)
x /= i, ps[i] = (i in ps) ? ps[i] + 1 : 1;
if (x != 1)
ps[x] = (x in ps) ? ps[x] + 1 : 1;
return ps;
}
/// Number of k-combinations % m (precalculated)
alias Combination_mod = Combination_modImpl!long;
struct Combination_modImpl(T)
{
T _n, _m;
T[] _fact, _factinv;
this(T maxnum, T mod = 10 ^^ 9 + 7)
{
_n = maxnum, _m = mod, _fact = new T[](_n + 1), _factinv = new T[](_n + 1), _fact[0] = 1;
foreach (i; 1 .. _n + 1)
_fact[i] = _fact[i - 1] * i % _m;
T powmod(T x, T n, T m)
{
if (n < 1)
return 1;
if (n & 1)
{
return x * powmod(x, n - 1, m) % m;
}
T tmp = powmod(x, n / 2, m);
return tmp * tmp % m;
}
foreach (i; 0 .. _n + 1)
_factinv[i] = powmod(_fact[i], _m - 2, _m);
}
T opCall(T n, T k, T dummy = 10 ^^ 9 + 7)
{
return n < k ? 0 : ((_fact[n] * _factinv[n - k] % _m) * _factinv[k] % _m);
}
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
int main() {
int[] hs;
string l;
readln();
while((l = readln()).length >= 2){
int a, b, c;
a = to!int(l.split()[0]), b = to!int(l.split()[1]), c = to!int(l.split()[2]);
if(a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b) printf("YES\n");
else printf("NO\n");
}
return 0;
}
|
D
|
import std.stdio;
import core.stdc.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
void main() {
int n,a; scanf("%d%d",&n,&a);
int x = n % 500;
writeln(x <= a ? "Yes" : "No");
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
writeln("2018" ~ S[4..$]);
stdout.flush();
debug readln();
}
|
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() {
string S, T;
readlnTo(S);
readlnTo(T);
int[] a = new int[26];
int[] b = new int[26];
a.fill(-1);
b.fill(-1);
bool ok = true;
foreach(i; 0..S.length) {
auto s = S[i] - 'a';
auto t = T[i] - 'a';
if (a[s] >= 0) {
ok = ok && (a[s] == t);
}
if (b[t] >= 0) {
ok = ok && (b[t] == s);
}
if (a[s] < 0) a[s] = t;
if (b[t] < 0) b[t] = s;
}
writeln(ok ? "Yes" : "No");
}
// 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, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto data = readln.split;
auto H = data[0].to!int, W = data[1].to!int;
data = readln.split;
auto h = data[0].to!int, w = data[1].to!int;
writeln(H*W - h*W - w*H + h*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;
import std.container;
alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Mame = Tuple!(long, "point", long, "number");
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();
if (s == "Sunny")
writeln("Cloudy");
if (s == "Cloudy")
writeln("Rainy");
if (s == "Rainy")
writeln("Sunny");
}
|
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 t = RD!int;
auto ans = new int[](t);
foreach (ti; 0..t)
{
auto s = RD!string;
int cnt, cnt_b;
foreach_reverse (i; 0..s.length)
{
if (s[i] == 'B')
++cnt_b;
else if (cnt_b >= 1)
{
--cnt_b;
cnt += 2;
}
}
cnt += cnt_b - (cnt_b % 2);
ans[ti] = cast(int)s.length - cnt;
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = pred();
return res;
}
int INF = int.max;
void main() {
int N = readln.chomp.to!int;
int[] ary = new int[N+1];
ary[0..$] = INF;
int l = 0;
int r = 1;
foreach(i; 0..N+1) {
if (!(l<r)) break;
foreach(j; l..r) {
if (j>N) break;
ary[j] = min(ary[j], i);
}
l = r;
r = r+i+1;
}
int k = N;
while(k > 0) {
ary[k].writeln;
k -= ary[k];
}
}
|
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 s = sread();
auto t = sread();
if (s == t)
{
writeln(s.length);
return;
}
long ans = -1;
foreach (i; 0 .. n)
{
if (func(s, t, i))
{
ans = max(ans, i);
}
}
// writeln(ans);
writeln((s.length + t.length) - ans);
}
bool func(string s, string t, long x)
{
if (s[($ - x) .. $] == t[0 .. x])
{
return true;
}
return false;
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp;
writeln(n[0] == n[2] ? "Yes" : "No");
}
|
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()
{
long K, X;
scan(K, X);
write(X - K + 1);
foreach (i; 1 .. K * 2 - 1)
{
write(" ", X - K + i + 1);
}
writeln();
}
|
D
|
import std.stdio;
import std.array;
import std.conv;
void main(){
string[] input = readln.split;
int A = input[0].to!int;
int B = input[1].to!int;
int C = input[2].to!int;
int cnt;
while(C > 0){
C--;
cnt++;
if(B > 0){
B--;
cnt++;
}
else if(A > 0){
A--;
}
else{
break;
}
}
if(B > 0) cnt += B;
write(cnt);
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
int tot = 0;
for (int i = 1; i <= n; i += 2) {
int k = 2;
for (int j = 2; j * j <= i; j++) {
if (i % j == 0)
k += 2;
}
if (k == 8) {
tot++;
}
}
writeln(tot);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
long k, a, b;
scan(k, a, b);
long ans;
if (k <= a) {
ans = 1;
}
else if (a <= b) {
ans = -1;
}
else {
ans = 2L * ((k - b - 1) / (a - b)) + 1;
}
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.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
int[] group(string s, string t) {
int[] gs;
auto n = s.length;
int p = 0;
while (p < s.length) {
if (s[p] == t[p]) {
gs ~= 1;
p += 1;
}
else {
gs ~= 0;
p += 2;
}
}
return gs;
}
void main() {
readln;
auto s = readln.chomp;
auto t = readln.chomp;
const MOD = 1000000007L;
auto gs = group(s, t);
long ans = 1;
// writeln(gs);
if (gs[0] == 0)
ans = 6;
else
ans = 3;
for (int i = 1; i < gs.length; i++) {
int prev = gs[i - 1];
int next = gs[i];
if (prev == 0) { // 横
if (next == 0) {
ans = (ans * 3) % MOD;
}
}
else {
if (next == 0) {
ans = (ans * 2) % MOD; // 上下で色かえ
}
else if (next == 1) {
ans = (ans * 2) % MOD;
}
}
}
writeln(ans);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp;
int s, r;
foreach (c; X) {
if (c == 'S') {
++s;
} else if (s > 0) {
--s;
} else {
++r;
}
}
writeln(s + r);
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
auto nq = readints();
int n = nq[0], q = nq[1];
for (int i = 0; i < q; i++) {
auto xs = readints();
if (xs[0] == 0) {
int s = xs[1];
int t = xs[2];
int x = xs[3];
add(s, t + 1, x, 0, 0, N / 2);
}
else {
int s = xs[1];
int v = sum(s, s + 1, 0, 0, N / 2);
writeln(v);
}
}
}
///////////////////////////////////////
const int N = 1 << 18; // ???????????°
int[N * 2] _data;
int[N * 2] _datb;
/// [a, b) ??? x ???????????????
/// k ????????????????????§????????? [l, r) ???????????????
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
_data[k] += x;
}
else if (l < b && a < r) {
_datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
/// [a, b) ??????????±???????
/// k ????????????????????§????????? [l, r) ???????????????]
int sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a)
return 0;
if (a <= l && r <= b)
return _data[k] * (r - l) + _datb[k];
int ret = (min(b, r) - max(a, l)) * _data[k];
ret += sum(a, b, k * 2 + 1, l, (l + r) / 2);
ret += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return ret;
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
auto S = readln.chomp;
long[] Ls;
long[] Rs;
foreach (i; 0..S.length) {
if (S[i] == 'L') Ls ~= i;
else Rs ~= i;
}
auto Lss = assumeSorted(Ls);
auto Rss = assumeSorted(Rs);
auto result = new long[S.length];
foreach (i; 0..S.length) {
// i番目の子供が10^100回後にどこにいるか
if (S[i] == 'L') {
// Rsの中でi未満のもの
auto j = Rss.lowerBound(i).back;
// このRまでにi-j回移動している
if ((i-j) % 2 == 0) {
// 残り移動回数が偶数回なら、このマスで終わる
result[j]++;
} else {
// 奇数回なら反対側で終わる
result[j+1]++;
}
} else {
// Lsの中でiを超えるもの
auto j = Lss.upperBound(i).front;
// このLまでにj-i回移動している
if ((j-i) % 2 == 0) {
// 残り移動回数が偶数回なら、このマスで終わる
result[j]++;
} else {
// 奇数回なら反対側で終わる
result[j-1]++;
}
}
}
result.map!(to!string).join(" ").writeln;
}
|
D
|
void main() {
problem();
}
void problem() {
auto N = scan!int;
int countF(int n) {
int c;
foreach(x; 1..101) {
auto tx = x^^2;
if (tx > n) break;
foreach(y; x..101) {
auto ty = tx + y^^2 + x*y;
if (ty > n) break;
foreach(z; y..101) {
auto t = ty + z^^2 + y*z + z*x;
if (t > n) break;
if (t == n) {
if (x == y && y == z) {
c++;
continue;
}
if (x != y && y != z) {
c += 6;
continue;
}
c += 3;
}
}
}
}
return c;
}
void solve() {
foreach(i; 1..N+1) {
countF(i).writeln;
}
}
solve();
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
|
D
|
import std.stdio;
import std.conv;
import std.array;
void main(){
string x = readln.split[0];
if (x == "3" || x == "5" || x == "7"){
writeln("YES");
}else{
writeln("NO");
}
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
auto a = readln.splitter.map !(to !(int)).array;
bool [int] b;
b[a[0]] = true;
foreach (i; 1..n)
{
if (a[i] <= a[i - 1])
{
a[i] += 1;
}
b[a[i]] = true;
}
writeln (b.length);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
int main()
{
string str;
while((str = readln()).length != 0)
{
int d = str.chomp.to!int;
int value = 0,s = 0;
while(value != 600-d)
{
value += d;
int line = value*value;
s += line * d;
}
writeln(s);
}
return 0;
}
|
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!long;
if (N%2 == 1 || N <= 10) {
writeln(0);
} else {
long r;
N /= 10;
while (N) {
r += N;
N /= 5;
}
writeln(r);
}
}
|
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()
{//try{
auto tokens = split(my_readln());
auto S = to!string(tokens[0]);
ulong best = 999;
foreach (i; 0..S.length-2)
{
auto num = abs(to!long(S[i..i+3]) - 753);
if (num < best)
best = num;
}
writeln(best);
stdout.flush();
/*}catch (Throwable e)
{
writeln(e.toString());
}
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()
{
int a, b; readV(a, b);
writeln(a*b%2 == 0 ? "No" : "Yes");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.range;
void main() {
auto S = readln.chomp.to!(char[]);
auto ni = (iota('a', 'z').chain('z'.only)).find!(c => !S.canFind(c));
ni.empty ? writeln("None") : writeln(ni.front);
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto C = new long[](N - 1);
auto S = new long[](N - 1);
auto F = new long[](N - 1);
foreach (i; 0 .. N - 1)
{
scan(C[i], S[i], F[i]);
}
foreach (i; 0 .. N - 1)
{
long t;
foreach (j; i .. N - 1)
{
long s = max(S[j], ((t + F[j] - 1) / F[j]) * F[j]);
t = s + C[j];
}
writeln(t);
}
writeln(0);
}
|
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 T = S.to!(dchar[]);
T.reverse();
S = T.to!string;
auto N = S.length.to!int;
auto A = new long[](2020);
A[0] = 1;
int tmp = 0;
auto tmps = new int[](N+1);
auto ten = 1;
foreach (i, s; S) {
tmp += ten * (s - '0');
tmp %= 2019;
ten = ten * 10 % 2019;
A[tmp] += 1;
tmps[i+1] = tmp;
}
long ans = 0;
foreach_reverse (i, s; S) {
A[tmp] -= 1;
ans += A[tmp];
tmp = tmps[i];
}
ans.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
writeln(readln.split.join.to!int % 4 == 0 ? "YES" : "NO");
}
|
D
|
// Cheese-Cracker: cheese-cracker.github.io
void solve(){
auto n = scan;
auto m = scan;
long a = n / 3;
long b = m / 3;
long lefa = n % 3;
long lefb = m % 3;
long res = lefb * a + lefa * b + min(lefa, lefb) + (a * b * 3);
writeln(res);
}
void main(){
long tests = scan; // Toggle!
while(tests--) solve;
}
/************** ***** That's All Folks! ***** **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x", long, "y");
|
D
|
import std.stdio,
std.string,
std.conv;
void main() {
string s = readln.chomp;
int K = readln.chomp.to!(int);
// s.to!(char[]);
char[] ans;
foreach (char c; s[0..(s.length - 1)]) {
if (c == 'a') {
ans ~= c;
}
else if ('z' - c + 1 <= K) {
ans ~= 'a';
K -= 'z' - c + 1;
}
else {
ans ~= c;
}
}
char c = s[s.length - 1];
for (int i = 0; i < K % 26; i++) {
if (c == 'z') {
c = 'a';
}
else {
c = (c + 1).to!(char);
}
}
writeln(ans ~ c);
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.