code
stringlengths 4
1.01M
| language
stringclasses 2
values |
---|---|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
int n = readint;
for (int i = 0; i < n; i++) {
auto s = readln.chomp;
auto t = s.replace("Hoshino", "Hoshina");
writeln(t);
}
}
|
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.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
int n = readln.chomp.to!int;
int[] p = readln.chomp.split.map!(to!int).array;
int cnt = 0;
for (int i = 0; i < n - 1; ++i) {
if (p[i] == i + 1) {
swap(p[i], p[i + 1]);
++cnt;
}
}
if (p[$ - 1] == n) {
swap(p[$ - 1], p[$ - 2]);
++cnt;
}
cnt.writeln;
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
long n, m;
scan(n, m);
writeln((n - 1) * (m - 1));
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.array;
void main()
{
ulong D = 1000000007;
string S = readln.chomp;
ulong[] b_mod = new ulong[13];
b_mod[0] = 1;
ulong[] c_mod;
foreach (char c; S){
c_mod = new ulong[13];
for (int i = 0; i < 13; i++){
if (c != '?'){
int c_n = c - '0';
int m = (i * 10 + c_n) % 13;
c_mod[m] += b_mod[i];
c_mod[m] %= D;
} else {
for (int j = 0; j < 10; j++){
int m = (i * 10 + j) % 13;
c_mod[m] += b_mod[i];
c_mod[m] %= D;
}
}
}
for (int i = 0; i < 13; i++) b_mod[i] = c_mod[i];
}
writeln(c_mod[5]);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.conv;
void main() {
auto n = (readln.chomp.to!int % 500);
auto A = readln.chomp.to!int;
if(n > A) "No".writeln;
else "Yes".writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 A = RD;
auto B = RD;
auto C = RD;
writeln(A == B && B == C ? "Yes" : "No");
stdout.flush();
debug readln();
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
auto S = sread();
auto T = sread();
auto f = new char[](100);
auto g = new char[](100);
foreach (i; 0 .. S.length)
{
if (f[S[i] - 'a'] == char.init && g[T[i] - 'a'] == char.init)
{
f[S[i] - 'a'] = T[i];
g[T[i] - 'a'] = S[i];
continue;
}
if (f[S[i] - 'a'] != T[i] || g[T[i] - 'a'] != S[i])
{
writeln("No");
return;
}
}
writeln("Yes");
}
|
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();
bool eval(string s)
{
return s.length % 2 == 0 && s[0 .. $ / 2] == s[$ / 2 .. $];
}
foreach_reverse (i; 0 .. S.length)
{
if (eval(S[0 .. i]))
{
writeln(i);
return;
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nk = readln.split.to!(int[]);
auto K = nk[1]-1;
auto S = readln.chomp.to!(char[]);
if (S[K] == 'A') {
S[K] = 'a';
} else if (S[K] == 'B') {
S[K] = 'b';
} else if (S[K] == 'C') {
S[K] = 'c';
}
writeln(S);
}
|
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() {
int n, k;
scan(n, k);
bool ok = (n + 1) / 2 >= k;
auto ans = ok ? "YES" : "NO";
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
|
void main(){
string[] weather = ["Sunny", "Cloudy", "Rainy", "Sunny"];
string now = readln().chomp();
weather = weather.find(now);
weather[1].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.string, std.array, std.conv;
void main() {
string[] board = ["#", "."];
while (true) {
int[] tmp = readln.chomp.split.to!(int[]);
int h = tmp[0], w = tmp[1];
if (h == 0 && w == 0) break;
foreach (i; 0 .. h) {
foreach (j; 0 .. w) {
write(board[(i+j)%2]);
}
writeln;
}
writeln;
}
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
void main() {
int n;
scan(n);
auto ans = (n + 999) / 1000 * 1000 - n;
writeln(ans);
}
void scan(T...)(ref T args) {
auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args)
if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args)
if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
long m, a, r, c, h;
foreach (_; 0..N) {
switch (readln[0]) {
case 'M': ++m; break;
case 'A': ++a; break;
case 'R': ++r; break;
case 'C': ++c; break;
case 'H': ++h; break;
default:
}
}
writeln(
m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h +
a*r*c + a*r*h + a*c*h +
r*c*h
);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
writeln(readln.chomp.replace(",", " "));
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void main(){
auto ip = readln.split.to!(int[]);
if(ip[0] * ip[1] % 2 == 0){
writeln("Even");
} else {
writeln("Odd");
}
}
|
D
|
import std.array : split;
import std.conv : to;
import std.stdio;
import std.string : strip;
private {
string[] temp;
}
void main() {
read();
int n = get!int(0);
int[] h = new int[n];
int[] a = new int[n];
foreach (i; 0 .. n) {
read();
h[i] = get!int(0);
a[i] = get!int(1);
}
int count = 0;
foreach (i, hi; h) {
foreach (j, aj; a) {
if (i != j && hi == aj)
++count;
}
}
stdout.write(count);
}
void read() {
temp = split(strip(stdin.readln()));
}
T get(T)(int p) {
return to!(T)(temp[p]);
}
|
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 s = readln.chomp;
writeln(a >= 3200 ? s : "red");
}
|
D
|
import std.conv;
import std.stdio;
import std.array;
import std.range;
import std.string;
import std.algorithm;
void main()
{
while(true)
{
auto n = readln.chomp.to!int;
if(n == 0) break;
auto hs = readln.split.map!(a => a.to!int()).array;
foreach(i; 0..(n+1)) {
if(isCommonDiff(hs[0..i] ~ hs[(i+1)..(n+1)])) {
writeln(hs[i]);
break;
}
}
}
}
bool isCommonDiff(int[] ary)
{
auto n = ary[1] - ary[0];
foreach(i; 2..ary.length) {
if(ary[i] - ary[i-1] != n) {
return false;
}
}
return true;
}
|
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; readV(n);
int[] a; readA(n, a);
auto dp = new long[][](n, n);
foreach (i; 0..n)
dp[i][i] = (n%2 == 1 ? 1 : -1) * a[i];
foreach (j; 0..n)
foreach_reverse (i; 0..j)
if ((n-(j-i+1))%2 == 0)
dp[i][j] = max(dp[i+1][j]+a[i], dp[i][j-1]+a[j]);
else
dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j]);
writeln(dp[0][n-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;
// dfmt on
void main()
{
long X = lread();
if (X <= 6)
{
writeln(1);
return;
}
long ans = X / (5 + 6) * 2;
long x = X % (5 + 6);
foreach (i; 0 .. 100)
{
if (x <= 0)
{
writeln(ans);
return;
}
x -= (i & 1) ? 5 : 6;
ans++;
}
}
|
D
|
import std;
void main() {
int h1, m1, h2, m2, k; scan(h1, m1, h2, m2, k);
int a = h1 * 60 + m1;
int b = h2 * 60 + m2;
writeln(max(0, b - a - k));
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto n = RD!int;
auto s = RD!string;
int l, cnt, ans;
foreach (i; 0..n)
{
if (s[i] == ')')
--cnt;
else
{
if (cnt == -1)
{
ans += i - l + 1;
}
++cnt;
}
if (cnt == 0)
{
l = i+1;
}
}
if (cnt != 0)
writeln(-1);
else
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
void main() {
uint n = readln.strip.to!int;
auto s = readln[0 .. n];
auto l = s.count ('L');
auto r = s.count ('R');
writeln (l + r + 1);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.map!(to!int), a = rd[0], b = rd[1];
if (a == b) writeln("a == b");
else writeln(a > b ? "a > b" : "a < b");
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!size_t;
bool[int] buf;
foreach (_; 0..n) {
auto a = readln.chomp.to!int;
if (a in buf) {
buf.remove(a);
} else {
buf[a] = true;
}
}
writeln(buf.length);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto w=new int[](n), h=new int[](n);
foreach(i; 0..n) rd(w[i], h[i]);
int cur=1_000_000_000+1;
foreach(i; 0..n){
if(cur<min(w[i], h[i])){
writeln("NO");
return;
}
if(cur>=max(w[i], h[i])) cur=max(w[i], h[i]);
else cur=min(w[i], h[i]);
}
writeln("YES");
}
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.array;
import std.conv;
import std.math;
import std.string;
void main()
{
int[] addinput = new int[200];
int anslength;
string s;
int i = -1;
while( (s=readln()).length > 1 )
{
i ++;
anslength = i;
string[] input = split(s);
int a = to!int(input[0]);
int b = to!int(input[1]);
addinput[i] = cast(int)log10(a + b) + 1;
}
for(int j = 0; j <= anslength; j++)
{
writeln(addinput[j]);
}
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
void main() {
int n = readln.strip.to!int;
auto s = readln.strip;
foreach (c; s) {
auto i = c.to!int - 65;
i = (i + n) % 26;
write((65+i).to!char);
}
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;
auto nc = s.count('N');
auto wc = s.count('W');
auto sc = s.count('S');
auto ec = s.count('E');
auto f = true;
if ((!nc && sc) || (nc && !sc)) {
f = false;
}
if ((!wc && ec) || (wc && !ec)) {
f = false;
}
if (f) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b; readV(a, b);
auto c = b-a;
writeln(c*(c+1)/2-b);
}
|
D
|
import std.stdio, std.string, std.algorithm, std.range, std.conv;
void main(){
while(true){
auto input = readln.split;
int n = input[0].to!int, k = input[1].to!int;
if(n == 0 && k == 0) break;
auto G = new int[][](n + 1, n + 1);
foreach(ref g; G){
g[] = int.max;
}
foreach(Unused; 0..k){
input = readln.split;
int op = input[0].to!int;
if(op == 1){
int a = input[1].to!int, b = input[2].to!int, cost = input[3].to!int;
if(cost < G[a][b]){
G[a][b] = cost;
G[b][a] = cost;
}
}else if(op == 0){
int start = input[1].to!int, end = input[2].to!int;
auto d = new int[](n + 1);
auto MST = new bool[](n + 1);
d[] = int.max;
d[start] = 0;
while(true){
int min = int.max;
int u;
foreach(i; 1..n + 1){
if(!MST[i] && min > d[i]){
min = d[i];
u = i;
}
}
if(u == 0) break;
MST[u] = true;
foreach(v; 1..n + 1){
if(!MST[v] && G[u][v] != int.max && G[u][v] + d[u] < d[v]){
d[v] = G[u][v] + d[u];
}
}
}
if(d[end] == int.max) (-1).writeln;
else d[end].writeln;
}
}
}
}
|
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, p;
scan(n, p);
if (n == 0 && p == 0) return;
auto m = new int[](n);
int pos;
int wan = p;
while (true) {
if (wan == 0) {
wan += m[pos];
m[pos] = 0;
}
else {
wan--;
m[pos]++;
}
if (m[pos] == p) break;
(++pos) %= n;
}
writeln(pos);
}
}
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.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;
void main() {
auto tmp = readln.split.to!(int[]);
auto A = tmp[0], B = tmp[1];
iota(1,4).any!(C => A * B * C % 2 == 1).pipe!(b => b ? "Yes" : "No").writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
string s = readln.chomp;
long w = read.to!long;
string ans;
foreach(i, c; s){
if(i % w == 0) ans ~= c;
}
ans.writeln;
}
|
D
|
import std.stdio : readln, writeln;
import std.array : split;
import std.conv : to;
import std.typecons;
import std.algorithm : map;
import std.string : chomp;
char[Tuple!(int, int)] field;
int W, H;
void dfs(int x, int y, char f) {
field[tuple(x, y)] = '.';
foreach (dx; [-1, 1]) {
int nx = x + dx;
if (0 <= nx && nx < W
&& field[tuple(nx, y)] == f) dfs(nx, y, f);
}
foreach (dy; [-1, 1]) {
int ny = y + dy;
if (0 <= ny && ny < H
&& field[tuple(x, ny)] == f) dfs(x, ny, f);
}
}
void main() {
while (1) {
auto input = map!(to!int)(split(chomp(readln()))[0 .. 2]);
H = input[0], W = input[1];
if (W == 0 && H == 0) break;
field = field.init;
foreach (int y; 0 .. H)
foreach (int x, char f; readln()[0 .. W])
field[tuple(x, y)] = f;
int res = 0;
foreach (xy; field.keys) {
char f = field[tuple(xy[0], xy[1])];
switch (f) {
case '#': case '@': case '*':
dfs(xy[0], xy[1], f);
res++;
break;
default:
break;
}
}
writeln(res);
}
}
|
D
|
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
alias Queue=DList;auto enq(T)(ref Queue!T q,T e){q.insertBack(e);}T deq(T)(ref Queue!T q){T e=q.front;q.removeFront;return e;}
alias Stack=SList;auto push(T)(ref Stack!T s,T e){s.insert(e);}T pop(T)(ref Stack!T s){T e=s.front;s.removeFront;return e;}
struct UnionFind(T){T[T]u;ulong[T] rank;@property{bool inc(T e){return e in u;}auto size(){return u.keys.length;}auto dup(){T[] child=u.keys;T[] parent=u.values;auto res=UnionFind!T(child);child.each!(e=>res.add(e));size.iota.each!(i=>res.unite(child[i],parent[i]));return res;}}this(T e){e.add;}this(T[] es){es.each!(e=>e.add);}auto add(T a,T b=a){assert(b.inc);u[a]=a;rank[a];if(a!=b)unite(a,b);}auto find(T e){if(u[e]==e)return e;return u[e]=find(u[e]);}auto same(T a,T b){return a.find==b.find;}auto unite(T a,T b){a=a.find;b=b.find;if(a==b)return;if(rank[a]<rank[b])u[a]=b;else{u[b]=a;if(rank[a]==rank[b])rank[a]++;}}}
struct PriorityQueue(T,alias less="a<b"){BinaryHeap!(T[],less) heap;@property{bool empty(){return heap.empty;}auto length(){return heap.length;}auto dup(){return PriorityQueue!(T,less)(array);}T[] array(){T[] res;auto tp=heap.dup;foreach(i;0..length){res~=tp.front;tp.removeFront;}return res;}void push(T e){heap.insert(e);}void push(T[] es){es.each!(e=>heap.insert(e));}}T look(){return heap.front;}T pop(){T tp=look;heap.removeFront;return tp;}this(T e){ heap=heapify!(less,T[])([e]);} this(T[] e){ heap=heapify!(less,T[])(e);}}
//END OF TEMPLATE
void main(){
auto n=scan!ulong;
bool[string] s;
foreach(i;0..n)
s[scan!string()]=true;
s.keys.length.writeln;
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void 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; readV(n);
int[] h; readA(n, h);
writeln(1 + iota(1, n).count!(i => h[0..i].all!(hi => hi <= h[i])));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
void main() {
readln.chomp.count!"a=='1'".writeln;
}
// ----------------------------------------------
void scanln(Args...)(ref Args args) {
foreach(i, ref v; args) {
"%d".readf(&v);
(i==args.length-1 ? "\n" : " ").readf;
}
// ("%d".repeat(args.length).join(" ") ~ "\n").readf(args);
}
void times(alias fun)(int n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
// 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);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
import 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;
void main(){
int N, M, l, r, x;
readVars(N, M);
auto p = readln.split.to!(int[]);
int cnt;
foreach(i ; 0 .. M){
readVars(l, r, x);
l--;
x--;
cnt = 0;
foreach(j ; l .. r){
cnt += (p[j] < p[x]);
}
if (cnt == x - l) {
writeln("Yes");
} else {
writeln("No");
}
}
}
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 solve(){
}
void main(){
string s = instr();
(700+s.count('o')*100).writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
alias instr = () => readln().chomp();
T inelm(T= int)(){ return to!(T)( readln().chomp() ); }
T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main(){
int[] str = readln.chomp.split.to!(int[]);
int time = str[0];
int qty = str[1];
int duration = str[2];
writeln(duration / time * qty);
}
|
D
|
void main()
{
long n = rdElem;
Graph[] g;
foreach (i; 1 .. n)
{
foreach (j; i+1 ..n+1)
{
if (i + j != (n + !(n & 1))) g ~= Graph(i, j);
}
}
g.length.writeln;
foreach (x; g)
{
writeln(x.a, " ", x.b);
}
}
struct Graph
{
long a, b;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
/+ dub.sdl:
name "C"
dependency "dunkelheit" version=">=0.9.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
long calc(long[] a) {
int n = a.length.to!int;
if (a[0]) return -1;
long sm = 0;
foreach (i; 1..n) {
if (a[i-1]+1 < a[i]) return -1;
if (a[i-1]+1 == a[i]) {
sm++;
} else {
sm += a[i];
}
}
return sm;
}
int main() {
Scanner sc = new Scanner(stdin);
int n;
sc.read(n);
long[] a = new long[n];
foreach (i; 0..n) sc.read(a[i]);
writeln(calc(a));
return 0;
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
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 /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/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.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int n = readint;
writeln(180 * (n - 2));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;
void main(){
auto Z=readln.split.to!(int[]),a=Z[0],b=Z[1];
if(a<=b)writeln(a);
else writeln(a-1);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
auto head = S[0..7];
auto tail = S[$-7..$];
foreach (i; 0..8) {
if (head[0..i] ~ tail[i..7] == "keyence") {
writeln("YES");
return;
}
}
writeln("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();
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;
}
}
auto manhattan(long x1, long y1, long x2, long y2)
{
return abs(y2 - y1) + abs(x2 - x1);
}
void main()
{
auto n = lread();
auto transport = new long[](5);
foreach (i; 0 .. 5)
{
transport[i] = lread();
}
auto minimam = transport.reduce!(min);
auto most = (n + (minimam - 1)) / minimam;
writeln(most + 4);
}
|
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 t = RD!int;
auto ans = new bool[](t);
foreach (ti; 0..t)
{
auto x = RD;
auto n = RD!int;
auto m = RD!int;
foreach (i; 0..n)
{
if (x <= 19) break;
x = x / 2 + 10;
}
ans[ti] = x <= m*10;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
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;
void main() {
writeln(readln.chomp.to!int^^3);
}
|
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;
// }}}
// tbh.scanner {{{
class Scanner {
import std.stdio;
import std.conv : to;
import std.array : split;
import std.string : chomp;
private File file;
private dchar[][] str;
private uint idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
private dchar[] next() {
if (idx < str.length) {
return str[idx++];
}
dchar[] s;
while (s.length == 0) {
s = file.readln.chomp.to!(dchar[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(uint len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
}
// }}}
void main() {
auto cin = new Scanner;
int n = cin.next!int;
int nx, ny, nt;
foreach (i; 0 .. n) {
int t = cin.next!int - nt;
int x = cin.next!int, y = cin.next!int;
int d = abs(x - nx) + abs(y - ny);
if (t < d) {
writeln("No");
return;
}
if (!(d % 2 == t % 2)) {
writeln("No");
return;
}
}
writeln("Yes");
}
|
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;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!int).array;
long ans = 0;
foreach (a; A) {
while (a % 2 == 0) ans += 1, a /= 2;
}
ans.writeln;
}
|
D
|
void main()
{
int n = readln.chomp.to!int;
string s = readln.chomp;
writeln(s.count('R') > s.count('B') ? "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;
/* Hello World Program in D Programming */
void main(string[ ] args)
{
int n;
scanf("%d", &n);
int[211111] a;
int a_len = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
a[a_len] = a[i];
++a_len;
while (a_len > 1 && a[a_len - 1] == a[a_len - 2]) {
--a_len;
++a[a_len - 1];
}
}
printf("%d\n", a_len);
for (int i = 0; i < a_len; ++i) {
printf("%d ", a[i]);
}
printf("\n");
return;
}
|
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);
}
}
// }}}
void main()
{
auto cin = new Scanner;
int a, b, c;
cin.scan(a, b, c);
if (a + b >= c)
{
writeln("Yes");
}
else
{
writeln("No");
}
}
|
D
|
module main;
import core.stdc.stdio;
int max(int a,int b){
if(a>b) return a; else return b;
}
int main(){
int n;
scanf("%d",&n);
if(n==1){
printf("23:59");
return 0;
}
int [] arr=new int[105];
for(int i=0;i<n;i++){
int a,b;
scanf("%d:%d",&a,&b);
//printf("%d %d",a,b);
arr[i]=a*60+b;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(arr[i]<arr[j]){
int t=arr[i];
arr[i]=arr[j];
arr[j]=t;
}
}
}
// for(int i=0;i<n;i++){
// printf("%d ",arr[i]);
// }
int ans=arr[0]+(24*60-arr[n-1]);
for(int i=0;i<n-1;i++){
ans=max(ans,arr[i+1]-arr[i]);
}
ans--;
printf("%02d:%02d",ans/60,ans%60);
return 0;
}
|
D
|
import std;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, K;
scan(N, K);
long base = powmod(10, 100, MOD);
long ans;
long a;
foreach (i; 0 .. K)
{
a = (a + i);
}
long b;
foreach (i; 0 .. K)
{
b = (b + N - i);
}
foreach (i; K .. N + 1)
{
ans = (MOD + ans + b - a + 1) % MOD;
// writefln("%s %s", i, N - i);
// writeln(b - a + 1);
a += i;
b += N - i;
}
writeln(ans + 1);
}
/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
if (n < 1)
return 1;
if (n & 1)
{
return x * powmod(x, n - 1, m) % m;
}
T tmp = powmod(x, n / 2, m);
return tmp * tmp % m;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int x, a, b;
scan(x, a, b);
writeln(abs(x - a) < abs(x - b) ? "A" : "B");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
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 a = readln.chomp.split.to!(int[]);
min(a[0]*a[1], a[2]).writeln;
}
|
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 s = readln.chomp;
auto mae = s[0..2].to!int;
auto ato = s[$-2..$].to!int;
if (1 <= mae && mae <= 12 && 1 <= ato && ato <= 12) {
writeln("AMBIGUOUS");
}
else if (1 <= mae && mae <= 12) {
writeln("MMYY");
}
else if (1 <= ato && ato <= 12) {
writeln("YYMM");
}
else {
writeln("NA");
}
}
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.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp;
auto hi = new int[](s.length + 1);
foreach (i, c; s)
hi[i + 1] = hi[i] + c.predSwitch('\\', -1, '_', 0, '/', 1);
auto maxH = hi.reduce!(max);
auto fs1 = hi.findSplitBefore([maxH]), hiL = fs1[0], hiMR = fs1[1];
hiMR.reverse();
auto fs2 = hiMR.findSplitBefore([maxH]), hiR = fs2[0], hiM = fs2[1];
auto aiL = hiL.calcAreas;
auto aiM = hiM.calcAreas; aiM.reverse();
auto aiR = hiR.calcAreas; aiR.reverse();
auto ai = aiL ~ aiM ~ aiR;
writeln(ai.sum);
write(ai.length);
ai.each!(a => write(" ", a));
writeln;
}
int[] calcAreas(int[] hi)
{
int[] areas;
int maxH = int.min, area = 0;
foreach (i, h; hi) {
if (h < maxH) {
area += 2 * (maxH - h) + hi[i - 1] - h;
} else if (h == maxH) {
if (area > 0) {
areas ~= area / 2;
area = 0;
}
} else {
maxH = h;
}
}
return areas;
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n, m;
rd(n, m);
struct E {
int u, v;
}
auto edges = new E[](m);
foreach (i; 0 .. m) {
rd(edges[i].u, edges[i].v);
edges[i].u--;
edges[i].v--;
}
int b = 0;
foreach (i; 0 .. m) {
auto g = new int[][](n);
foreach (j; 0 .. m) {
if (i != j) {
g[edges[j].u] ~= edges[j].v;
g[edges[j].v] ~= edges[j].u;
}
}
auto vis = new bool[](n);
void f(int i) {
vis[i] = true;
foreach (j; g[i]) {
if (!vis[j]) {
f(j);
}
}
}
f(0);
if (!reduce!((res, v) => (res && v))(true, vis)) {
b++;
}
}
writeln(b);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to
void main()
{
string n = chomp(readln());
int a = to!int(n);
if(a/100%10 == a/10%10 && (a/100%10 == a/1000 || a/100%10 == a%10)){
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;
void main()
{
int[31] stu;
foreach (i; 0..28) {
stu[readln.chomp.to!int]++;
}
foreach (i; 1..31) {
if (!stu[i]) i.writeln;
}
}
|
D
|
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;
void main() {
writeln(readln.chomp.split.map!(to!long).take(2).reduce!"a * b" / 2);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto s = readln.chomp;
writeln(s[0..4]~" "~s[4..$]);
}
|
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;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
p = stdin.rawRead (buffer);
}
final ubyte skipByte (ubyte lo) {
while (true) {
auto a = p[cur .. $];
auto r = a.find! (c => c >= lo);
if (!r.empty) {
cur += a.length - r.length;
return p[cur++];
}
p = stdin.rawRead (buffer);
cur = 0;
if (p.empty) return 0;
}
}
final ubyte nextByte () {
if (cur < p.length) {
return p[cur++];
}
p = stdin.rawRead (buffer);
if (p.empty) return 0;
cur = 1;
return p[0];
}
template next(T) if (isSigned!T) {
final T next () {
T res;
ubyte b = skipByte (45);
if (b == 45) {
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
final T next () {
T res = skipByte (48) - 48;
while (true) {
ubyte b = nextByte ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
final T[] nextA(T) (int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
void main() {
auto r = new InputReader;
auto nt = r.next!uint;
foreach (tid; 0 .. nt) {
immutable n = r.next!uint;
immutable m = r.next!uint;
auto a = r.nextA!uint (n);
auto b = r.nextA!uint (m);
a[] -= 1;
b[] -= 1;
auto rank = new uint[n];
foreach (i; 0 .. n) {
rank[a[i]] = i;
}
long res = m;
int e;
int cur;
foreach (i; 0 .. m) {
if (rank[b[i]] > cur) {
cur = rank[b[i]];
res += 2 * (rank[b[i]] + e);
}
--e;
}
writeln (res);
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp.dup, ns = s.length;
auto t = readln.chomp, nt = t.length;
loop: foreach_reverse (i; 0..ns-nt+1) {
foreach (j; 0..nt)
if (s[i+j] != '?' && s[i+j] != t[j]) continue loop;
s[i..i+nt][] = t[];
writeln(s.replace("?", "a"));
return;
}
writeln("UNRESTORABLE");
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto r = readln.chomp.to!int;
auto g = readln.chomp.to!int;
writeln(2*g-r);
}
|
D
|
import std.conv;
import std.stdio;
import std.string;
void main(){
int N = readln.chomp.to!int;
writeln(factorial(N));
}
long factorial(long N){
if(N == 1)
return 1;
else
return N * factorial(N-1);
}
|
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 N = lread();
auto S1 = sread();
auto S2 = sread();
long[] S;
{
long i = 0;
while (i < N)
{
if (S1[i] == S2[i])
{
S ~= 1;
i++;
}
else
{
S ~= 2;
i += 2;
}
}
}
long ans = (S[0] == 1) ? 3 : 6;
foreach (i; 1 .. S.length)
{
if (S[i] == 1)
{
ans *= (S[i - 1] == 1) ? 2 : 1;
}
else
{
ans *= (S[i - 1] == 1) ? 2 : 3;
}
ans %= MOD;
}
writeln(ans);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto x = readln.chomp.to!int;
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
writeln((x-a)%b);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto N = readln.chomp.to!int;
auto dp = new long[][](N+1, 2);
dp[0][1] = 1;
auto imos = new long[](3*N);
long INV = powmod(N-1, MOD-2, MOD);
long ans = 0;
foreach (i; 0..N) {
(dp[i+1][0] += dp[i][1] * (N - 1) % MOD) %= MOD; // 1のあとに2〜N
(dp[i+1][1] += dp[i][1]) %= MOD; // 1のあとに1
(dp[N][0] += dp[i][0] * (N - 1) % MOD) %= MOD; // 2〜Nのあとに2〜N (無限ループ)
// 2〜Nのあとに1
(imos[i+2] += dp[i][0] * INV % MOD) %= MOD;
(imos[i+N+1] -= dp[i][0] * INV % MOD) %= MOD;
(imos[i+1] += imos[i]) %= MOD;
(dp[i+1][1] += imos[i+1]) %= MOD;
}
foreach (i; N..3*N-1) {
(imos[i+1] += imos[i]) %= MOD;
(ans += imos[i+1]) %= MOD;
}
ans = (ans + dp[N].sum % MOD + 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 std.conv, std.stdio, std.algorithm, std.string, std.range, std.math;
void main() {
const input = readln.split.map!(to!int).array;
max(input[0]-input[1]*2, 0).writeln;
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
long n, m;
rd(n, m);
import std.math : sqrt;
for (long k = m; k >= 1; k--) {
if (m >= k * n && (m - k * n) % k == 0) {
writeln(k);
return;
}
}
import std.exception : enforce;
enforce(false);
}
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.algorithm;
import std.array;
import std.conv;
import std.math;
import std.numeric;
import std.stdio;
import std.string;
void main()
{
string s = readln.chomp;
string t = readln.chomp;
for (long diff = 0; diff < s.length; ++diff)
{
char[] n;
n.length = s.length;
for (long i = 0; i < s.length; ++i)
{
long d = i + diff;
if (s.length <= d)
{
d %= s.length;
}
n[i] = s[d];
}
if (n == t)
{
writeln("Yes");
return;
}
}
writeln("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;
void main() {
foreach(int i;1..10) foreach(int j; 1..10) {
writeln(i, "x", j, "=", i*j);
}
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
immutable int letters = 26;
string solve (string s)
{
int [letters] d;
foreach (ref c; s)
{
d[c - 'a'] += 1;
}
foreach (let; 0..letters)
{
if (d[let] == 1)
{
string res;
res ~= cast (char) (let + 'a');
d[let] -= 1;
foreach (x; 0..letters)
{
foreach (y; 0..d[x])
{
res ~= cast (char) (x + 'a');
}
}
return res;
}
}
foreach (let; 0..letters)
{
if (d[let] > 0)
{
string res;
res ~= cast (char) (let + 'a');
d[let] -= 1;
string [2] add;
foreach (x; 0..letters)
{
foreach (y; 0..d[x])
{
add[x > let] ~= cast (char) (x + 'a');
}
}
if (add[0].length <= add[1].length + 1)
{
while (!add[0].empty || !add[1].empty)
{
foreach (v; 0..2)
{
if (!add[v].empty)
{
res ~= add[v][0];
add[v].popFront ();
}
}
}
return res;
}
if (add[1].empty || add[1].front == add[1].back)
{
res ~= add[1];
res ~= add[0];
return res;
}
auto second = add[1][0];
res ~= second;
add[1].popFront ();
res ~= add[0];
foreach (i, ref c; add[1])
{
if (c != second)
{
res ~= c;
res ~= add[1][0..i];
res ~= add[1][i + 1..$];
return res;
}
}
assert (false);
}
}
assert (false);
}
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
writeln (solve (s));
}
}
|
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;
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;
}
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int N;
scan(N);
auto s = readln.chomp;
int x;
int ans;
foreach (ch ; s) {
if (ch == 'I') {
x++;
chmax(ans, x);
}
else {
x--;
chmax(ans, x);
}
}
writeln(ans);
}
|
D
|
import std.stdio;
import core.stdc.stdio;
void main() {
uint n, r = 1;
scanf(`%u`, &n);
uint l = 3;
foreach(i; 0..n) {
uint k;
scanf(`%u`, &k);
uint a = k / 10;
uint b = k % 10;
if(l == a) r++;
l = b;
}
write(r);
}
|
D
|
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
void main() {
immutable i = readln.split.to!(ulong[]);
immutable R = i[0], G = i[1], B = i[2], N = i[3];
ulong cnt = 0;
for(ulong r = 0; r <= N / R; r++) {
const ulong r_val = r * R;
if (r_val > N) break;
else if (r_val == N) cnt++;
else {
for(ulong g = 0; g <= N / G; g++) {
const ulong g_val = r*R + g*G;
if (g_val > N) break;
else if (g_val == N) cnt++;
else {
const ulong rem = (N - g_val) % B;
if (rem == 0) {
cnt++;
}
}
}
}
}
writeln(cnt);
}
|
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;
auto U = RD;
auto R = RD;
auto D = RD;
auto L = RD;
foreach (i; 0..2^^4)
{
auto arr = new int[](4);
arr[0] = i & 1;
arr[1] = (i>>1) & 1;
arr[2] = (i>>2) & 1;
arr[3] = (i>>3) & 1;
debug writeln(arr);
auto u = n - arr[0] - arr[1];
auto r = n - arr[1] - arr[2];
auto d = n - arr[2] - arr[3];
auto l = n - arr[3] - arr[0];
if (inside(U, 2 - arr[0] - arr[1], u+1) && inside(R, 2 - arr[1] - arr[2], r+1) &&
inside(D, 2 - arr[2] - arr[3], d+1) && inside(L, 2 - arr[3] - arr[0], l+1))
{
ans[ti] = true;
break;
}
}
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
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 N = readln.chomp.to!int;
auto S = readln.chomp;
foreach (i; 0..N-1) {
if (S[i] > S[i+1]) {
writeln("YES");
writeln(i+1, " ", i+2);
return;
}
}
writeln("NO");
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
void main()
{
int n, k;
readln.chomp.split.tie(n, k);
if (2 * (n - 2) < k) {
"NO".writeln;
return;
}
"YES".writeln;
char[][] ans = new char[][](4, n);
foreach (i; 0..4) {
foreach (j; 0..n) {
ans[i][j] = '.';
}
}
// vertical
for (int i = 1; i <= 2; ++i) {
if (k < n - 2) {
break;
}
for (int j = 1; j < n - 1; ++j) {
ans[i][j] = '#';
}
k -= n - 2;
}
immutable MID = n / 2;
if (k % 2 == 1) {
ans[2][MID] = '#';
--k;
}
for (int i = 1; k > 0; ++i) {
ans[2][MID - i] = ans[2][MID + i] = '#';
k -= 2;
}
foreach (s; ans) {
foreach (c; s) {
c.write;
}
writeln;
}
}
void tie(R, Args...)(R arr, ref Args args)
if (isRandomAccessRange!R || isArray!R)
in
{
assert (arr.length == args.length);
}
body
{
foreach (i, ref v; args) {
alias T = typeof(v);
v = arr[i].to!T;
}
}
void verbose(Args...)(in Args args)
{
stderr.write("[");
foreach (i, ref v; args) {
if (i) stderr.write(", ");
stderr.write(v);
}
stderr.writeln("]");
}
|
D
|
module _;
void main() {
import std.stdio, std.conv, std.string;
int n =readln.strip.to!int;
int[char] cnt;
foreach(i; 0..n) {
cnt[readln[0]]++;
}
int ans = 0;
foreach(k; cnt.byKey) {
ans += cnt[k]*(cnt[k]-1)/2;
int half = cnt[k]/2;
ans -= half * (cnt[k]-half);
}
writeln(ans);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto r = readln.chomp.to!int;
writeln(r * r);
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.7.3"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
Scanner sc = new Scanner(stdin);
string s;
sc.read(s);
if (s.count("AC")) {
writeln("Yes");
} else {
writeln("No");
}
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
// import dcomp.array;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
FastAppender!(E[]) buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;
T[N] fixed(T, size_t N)(T[N] a) {return a;}
struct FastAppender(A, size_t MIN = 4) {
import std.algorithm : max;
import std.conv;
import std.range.primitives : ElementEncodingType;
import core.stdc.string : memcpy;
private alias T = ElementEncodingType!A;
private T* _data;
private uint len, cap;
@property size_t length() const {return len;}
bool empty() const { return len == 0; }
void reserve(size_t nlen) {
import core.memory : GC;
if (nlen <= cap) return;
void* nx = GC.malloc(nlen * T.sizeof);
cap = nlen.to!uint;
if (len) memcpy(nx, _data, len * T.sizeof);
_data = cast(T*)(nx);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void opOpAssign(string op : "~")(T item) {
if (len == cap) {
reserve(max(MIN, cap*2));
}
_data[len++] = item;
}
void insertBack(T item) {
this ~= item;
}
void removeBack() {
len--;
}
void clear() {
len = 0;
}
ref inout(T) back() inout { assert(len); return _data[len-1]; }
ref inout(T) opIndex(size_t i) inout { return _data[i]; }
T[] data() {
return (_data) ? _data[0..len] : null;
}
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/
|
D
|
import std.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;
}
bool isPrime(int n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
void main() {
string s;
while ((s = readln.chomp) != null) {
int n = s.to!int;
int ans = 0;
for (int i = 1; i <= n; i++) {
int a = i;
int b = n - i + 1;
if (isPrime(a) && isPrime(b))
ans++;
}
writeln(ans);
}
}
|
D
|
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
string[] ss = readln.split;
foreach (i, ref arg ; args) arg = ss[i].parse!int;
}
void main() {
int a,b; scan(a,b);
writeln(max(a+b, a-b, a*b));
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
long bignum = 1_000_000_007;
auto dp = new long[](100_100);
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 n, m;
scan(n, m);
auto denger = new long[](m);
foreach (ref e; denger)
{
e = lread();
}
long[] tmp = [0];
auto need = step(denger ~ tmp, n);
need.writeln();
}
long step(long[] denger, long n)
{
ulong j;
if (denger[j] != 1)
dp[0] = 1;
else
j++;
if (denger[j] != 2)
dp[1] = dp[0] + 1;
else
j++;
foreach (i; 2 .. n)
{
if (i == denger[j] - 1)
{
dp[i] = 0;
j++;
}
else
{
dp[i] = (dp[i - 1] + dp[i - 2]) % bignum;
}
}
return dp[n - 1];
}
|
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 bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");
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 n = lread();
auto all_have = new long['z' - 'a' + 1];
foreach (i; 0 .. n)
{
auto s = sread();
auto now = new long['z' - 'a' + 1];
foreach (e; s)
{
if (!i)
all_have[e - 'a']++;
now[e - 'a']++;
}
foreach (e; 'a' .. 'z' + 1)
{
all_have[e - 'a'] = min(now[e - 'a'], all_have[e - 'a']);
}
}
foreach (i, e; all_have)
{
if(e)
{
long j;
while(j++ < e)
write(cast(char)('a' + i));
}
}
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;
void main(){
int n;
long x;
{
long[] tmp = readln.chomp.split.map!(to!long).array;
n = cast(int) tmp[0];
x = tmp[1];
}
long[] as = readln.chomp.split.map!(to!long).array;
long[][] qs;
qs.length = n;
for(int i = 0; i < n; i ++){
for(int k = 0; k < n; k ++){
int j = i - k;
if(j < 0) j += n;
long u = as[j];
if(qs[i].length && qs[i][$ - 1] < u) u = qs[i][$ - 1];
qs[i] ~= u;
}
}
long ans = long.max;
for(int k = 0; k < n; k ++){
long a = x * k;
foreach(q; qs){
a += q[k];
}
ans = min(ans, a);
}
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;
void main()
{
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto c = readln.chomp.to!int;
auto x = readln.chomp.to!int;
int cnt;
foreach (i; 0..a+1) {
foreach (j; 0..b+1) {
foreach (k; 0..c+1) {
if (i*500+j*100+k*50 == x) {
cnt++;
}
}
}
}
cnt.writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
auto A = scanChar;
auto B = scanChar;
if(A<B)end("<");
if(A>B)end(">");
end("=");
}
|
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() {
int a, b, c;
scan(a, b, c);
int ans = max(0, c - (a - b));
writeln(ans);
}
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.algorithm;
void main()
{
import std.stdio, std.conv, std.string;
readln.chomp.to!int.solve.writeln;
}
int solve(int x)
{
auto result = int.max;
foreach (i; 0..x+1)
result = min(result, simulate(x, i));
return result;
}
int simulate(int x, int i)
{
return i.withdraw(6) + (x - i).withdraw(9);
}
int withdraw(int x, int radix)
{
int result;
while (x)
{
result += x % radix;
x /= radix;
}
return result;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
static import std.ascii;
// 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 H = lread();
long cnt;
long ans = 1;
while (1 < H)
{
H /= 2;
cnt++;
ans += 2 ^^ cnt;
}
writeln(ans);
}
|
D
|
void main() {
problem();
}
void problem() {
auto N = scan.map!(x => x - '0').array;
bool solve() {
ulong sumDecimal;
foreach(n; N) sumDecimal += n;
return sumDecimal % 9 == 0;
}
writeln(solve() ? "Yes" : "No");
}
// ----------------------------------------------
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, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!long;
char[] res;
while (N) {
auto n = N % 26;
if (n == 0) {
n = 25;
N -= 1;
} else {
n -= 1;
}
res ~= 'a' + n.to!char;
N /= 26;
}
res.reverse();
writeln(res);
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
void main() {
if(readln.chomp=="ABC") writeln("ARC");
else writeln("ABC");
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.