code
stringlengths 4
1.01M
| language
stringclasses 2
values |
---|---|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto x = readln.chomp.split.to!(int[]);
if (x[0] > 8 || x[1] > 8) {
writeln(":(");
} else {
writeln("Yay!");
}
}
| 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.numeric;
void main()
{
auto s = readln.chomp;
auto p = ["dreamer", "dream", "eraser", "erase"];
int i = s.length.to!int;
a:while (i > 0) {
foreach (e; p) {
if (e.length > i) {
continue;
}
if (s[i-e.length..i] == e) {
i -= e.length;
continue a;
}
}
break a;
}
if (i == 0) {
writeln("YES");
} else {
writeln("NO");
}
}
| D |
void main()
{
string s = rdStr;
string now;
string bef;
long cnt;
foreach (x; s)
{
now ~= x;
if (now != bef)
{
bef = now;
now = "";
++cnt;
}
}
cnt.writeln;
}
T rdElem(T = long)()
{
//import std.stdio : readln;
//import std.string : chomp;
//import std.conv : to;
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
dchar[] rdDchar()
{
//import std.conv : to;
return rdStr.to!(dchar[]);
}
T[] rdRow(T = long)()
{
//import std.stdio : readln;
//import std.array : split;
//import std.conv : to;
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
//import std.range : iota;
//import std.algorithm : map;
//import std.array : array;
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
//import std.range : iota;
//import std.algorithm : map;
//import std.array : array;
return iota(col).map!(x => rdRow!T).array;
}
void wrMat(T = long)(T[][] mat)
{
//import std.stdio : write, writeln;
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.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 N = readln.chomp.to!int;
auto S = readln.chomp;
int r;
foreach (i; 0..1000) {
auto a = i/100;
auto b = (i/10)%10;
auto c = i%10;
int d;
foreach (j; 0..N) {
if (d == 0 && S[j] - '0' == a) {
++d;
} else if (d == 1 && S[j] - '0' == b) {
++d;
} else if (d == 2 && S[j] - '0' == c) {
++r;
break;
}
}
}
writeln(r);
} | D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
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() {
string A, B;
scan(A);
scan(B);
if (A == B) {
writeln("EQUAL");
return;
}
bool g;
if (A.length > B.length) {
g = true;
}
else if (A.length < B.length) {
g = false;
}
else {
g = A > B;
}
writeln(g ? "GREATER" : "LESS");
}
| 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);
if (n == 1) {
writeln("Hello World");
} else {
int a; readV(a);
int b; readV(b);
writeln(a+b);
}
}
| D |
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
auto x = lread();
if ((400 <= x) && (x <= 599))
{
writeln(8);
}
else if ((600 <= x) && (x <= 799))
{
writeln(7);
}
else if ((800 <= x) && (x <= 999))
{
writeln(6);
}
else if ((1000 <= x) && (x <= 1199))
{
writeln(5);
}
else if ((1200 <= x) && (x <= 1399))
{
writeln(4);
}
else if ((1400 <= x) && (x <= 1599))
{
writeln(3);
}
else if ((1600 <= x) && (x <= 1799))
{
writeln(2);
}
else if ((1800 <= x) && (x <= 1999))
{
writeln(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, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp.to!int;
auto DP = new int[][](6, 10^^5+1);
int solve(int i, int x) {
if (i == 6) return x == 0 ? 1 : -1;
if (DP[i][x] != 0) return DP[i][x];
int r = solve(i+1, x);
if (x >= 100 + i) r = max(r, solve(i, x - (100+i)));
DP[i][x] = r;
return DP[i][x];
}
writeln(solve(0, X) == 1 ? 1 : 0);
} | D |
import std.stdio,std.string,std.conv;
int main()
{
string s;
int count_1 = 0,count_2 = 0;
while((s = readln.chomp).length != 0)
{
string[] _s = s.split(",");
int len1 = _s[0].to!int;
int len2 = _s[1].to!int;
int len3 = _s[2].to!int;
if(len3*len3 == len1*len1 + len2*len2) count_1++;
if(len1 == len2) count_2++;
}
writeln(count_1);
writeln(count_2);
return 0;
} | D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void main()
{
int h, w; readV(h, w);
dchar[][] s; readC(h, s);
auto isBakudan(int i, int j)
{
if (i < 0 || i >= h || j < 0 || j >= w) return false;
return s[i][j] == '#';
}
foreach (i; 0..h)
foreach (j; 0..w) {
if (s[i][j] == '#') continue;
int r = 0;
foreach (di; -1..2)
foreach (dj; -1..2)
if (di != 0 || dj != 0) r += isBakudan(i+di, j+dj);
s[i][j] = cast(dchar)('0'+r);
}
foreach (si; s) writeln(si);
}
| D |
import std.stdio,std.conv,std.string,std.math;
void main(){
double money = 100000;
while(true){
char[] buf;
stdin.readln(buf);
double x = buf.chomp().to!double();
if(0 <= x && x <= 100){
for(int i = 0;i < x;i++){
money *= 1.05;
if(money - (money/1000).to!int() * 1000 != 0){
money = ((money/1000 + 1).to!int())*1000;
}
}
break;
}
}
writeln(money.to!int());
} | 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, M;
scan(N, M);
auto c = new int[](N);
foreach (i ; 0 .. M) {
int ai, bi;
scan(ai, bi);
ai--, bi--;
c[ai]++;
c[bi]++;
}
auto ok = c.all!(ci => ci % 2 == 0);
writeln(ok ? "YES" : "NO");
}
| D |
import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional, std.bigint, std.random;
void main() {
auto S = readln.chomp;
if (S[0] == S[1]) {
writeln("1 2");
return;
}
foreach (i; 0..S.length-2) {
if (S[i] == S[i+1] || S[i+1] == S[i+2] || S[i+2] == S[i]) {
writeln(i+1, " ", i+3);
return;
}
}
writeln("-1 -1");
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int n; readV(n);
int[] a, b; readM(n, a, b);
int[] c, d; readM(n, c, d);
auto g = GraphW!()(n*2+2);
foreach (i; 0..n)
foreach (j; 0..n)
if (a[i] < c[j] && b[i] < d[j])
g.addEdge(i, n+j, 1);
foreach (i; 0..n) {
g.addEdge(n*2, i, 1);
g.addEdge(n+i, n*2+1, 1);
}
auto r = FordFulkerson!(typeof(g)).fordFulkerson(g, n*2, n*2+1);
writeln(r);
}
struct GraphW(N = int, W = int, W i = 10^^9)
{
alias Node = N, Wt = W, inf = i;
struct Edge { Node src, dst; Wt wt; alias cap = wt; }
Node n;
Edge[][] g;
alias g this;
this(Node n) { this.n = n; g = new Edge[][](n); }
void addEdge(Node u, Node v, Wt w) { g[u] ~= Edge(u, v, w); }
void addEdgeB(Node u, Node v, Wt w) { g[u] ~= Edge(u, v, w); g[v] ~= Edge(v, u, w); }
}
template FordFulkerson(Graph)
{
import std.algorithm, std.container, std.traits;
alias Node = TemplateArgsOf!Graph[0], Wt = TemplateArgsOf!Graph[1];
struct EdgeR { Node src, dst; Wt cap, flow; Node rev; }
Wt fordFulkerson(ref Graph g, Node s, Node t)
{
auto n = g.n, adj = withRev(g, n), visited = new bool[](n);
Wt augment(Node u, Wt cur)
{
if (u == t) return cur;
visited[u] = true;
foreach (ref e; adj[u]) {
if (!visited[e.dst] && e.cap > e.flow) {
auto f = augment(e.dst, min(e.cap - e.flow, cur));
if (f > 0) {
e.flow += f;
adj[e.dst][e.rev].flow -= f;
return f;
}
}
}
return 0;
}
Wt flow;
for (;;) {
visited[] = false;
auto f = augment(s, g.inf);
if (f == 0) break;
flow += f;
}
return flow;
}
EdgeR[][] withRev(ref Graph g, Node n)
{
auto r = new EdgeR[][](n);
foreach (gi; g)
foreach (e; gi) {
r[e.src] ~= EdgeR(e.src, e.dst, e.cap, 0, cast(Node)(r[e.dst].length));
r[e.dst] ~= EdgeR(e.dst, e.src, 0, 0, cast(Node)(r[e.src].length) - 1);
}
return r;
}
}
| D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N, tk, ao;
scan(N, tk, ao);
tk--, ao--;
auto adj = new int[][](N, 0);
foreach (i ; 0 .. N - 1) {
int ai, bi;
scan(ai, bi);
ai--, bi--;
adj[ai] ~= bi;
adj[bi] ~= ai;
}
auto par = new int[](N);
par[] = -1;
auto height = new int[](N);
height[] = -1;
auto depth = new int[](N);
depth[] = -1;
void dfs(int v, int p, int dep) {
par[v] = p;
depth[v] = dep;
foreach (u ; adj[v]) if (u != p) {
dfs(u, v, dep + 1);
chmax(height[v], height[u]);
}
height[v] += 1;
}
dfs(ao, -1, 0);
debug {
writeln(par);
writeln(depth);
writeln(height);
}
int pos = tk;
int upc = (depth[tk] + 1) / 2 - 1;
int ans = upc;
while (upc--) {
pos = par[pos];
}
ans += height[pos] + (depth[tk] % 2 == 0);
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
| D |
import std.stdio, std.string, std.conv;
enum N = 110000;
enum M = 10000;
immutable hurui = {
bool[N + 1] table;
table[] = true;
table[0 .. 2] = false;
for(int i = 2; i * i <= N; ++i)
{
if(table[i])
{
for(int j = 2; i * j <= N; j++)
{
table[i * j] = false;
}
}
}
return table;
}();
immutable res = {
int[M + 1] table;
int sum, index;
for(int i = 1; i <= N && index < M; ++i)
{
if(hurui[i]) table[++index] = (sum += i);
}
return table;
}();
void main()
{
while(true)
{
int n = readln.chomp.to!int;
if(!n) break;
res[n].writeln;
}
} | D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.range;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
const int N = 1_000_000;
auto tab = new bool[N];
tab[] = true;
for (int i = 2 + 2; i < N; i += 2)
tab[i] = false;
for (int i = 3; i < N; i += 2) {
if (tab[i]) {
for (int j = i + i; j < N; j += i) {
tab[j] = false;
}
}
}
auto sum = new int[N];
for (int i = 2; i < N; i++) {
sum[i] = sum[i - 1] + (tab[i] ? 1 : 0);
}
string s;
while ((s = readln.chomp).length > 0) {
int n = s.to!int;
writeln(sum[n]);
}
} | D |
import std.stdio;
import std.string;
import std.conv;
void main()
{
auto N = chomp(readln());
writeln((N[0] == '9' || N[1] == '9') ? "Yes" : "No");
} | D |
import std.stdio,std.string,std.array,std.algorithm,std.range,std.conv;
int main(){
auto s=readln.chomp;
auto n=s.length;
if(s==s.rev){
auto s1=s.dup[0..(n-1)/2];
if(s1==s1.rev){
auto s2=s.dup[(n+3)/2-1..$];
if(s2==s2.rev){
"Yes".writeln;
return 0;
}
}
}
"No".writeln;
return 0;
}
auto rev(const char[] s){
auto ss=s.dup;
foreach(i;0..ss.length/2){
ss[i]=ss[$-i-1];
}
return ss;
} | 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 = 998244353;
void main() {
long n, a, b, k;
scan(n, a, b, k);
auto fact = new long[](n + 1);
fact[0] = 1;
foreach (i ; 1 .. n + 1) {
fact[i] = (fact[i-1] * i) % mod;
}
auto rfact = new long[](n + 1);
rfact[n] = powmod(fact[n], mod - 2, mod);
foreach_reverse (i ; 0 .. n) {
rfact[i] = (rfact[i+1] * (i + 1)) % mod;
}
long comb(long n, long k) {
return fact[n] * rfact[k] % mod * rfact[n-k] % mod;
}
long ans;
foreach (i ; 0 .. n + 1) {
if ((k - i*a) % b != 0) continue;
long j = (k - i*a) / b;
if (j < 0 || j > n) continue;
ans += comb(n, i) * comb(n, j) % mod;
ans %= mod;
}
writeln(ans);
}
long powmod(long x, long y, long m) {
return y > 0 ? powmod(x, y>>1, m)^^2 % m * x^^(y&1) % m : 1;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
| D |
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;
void main(){
while(true){
auto s = readln();
if(stdin.eof()) break;
s = chomp(s);
int ans = 0;
for(int i=0;i<s.length;i++){
char c = s[i];
int n1,n2;
if(c == 'I') n1 = 1;
else if (c=='V') n1 = 5;
else if (c=='X') n1 = 10;
else if (c=='L') n1 = 50;
else if (c=='C') n1 = 100;
else if (c=='D') n1 = 500;
else if (c=='M') n1 = 1000;
if(i<to!int(s.length)-1){
c = s[i+1];
if(c == 'I') n2 = 1;
else if (c=='V') n2 = 5;
else if (c=='X') n2 = 10;
else if (c=='L') n2 = 50;
else if (c=='C') n2 = 100;
else if (c=='D') n2 = 500;
else if (c=='M') n2 = 1000;
if(n1 < n2){
n1 = n2 - n1;
i++;
}
}
ans += n1;
}
writeln(ans);
}
} | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!int;
writeln(0.bitSet(n.bsr));
}
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); }
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;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
int maxN = 10^^6;
int[] f, f_odd;
for(int n=1; ;n++) {
f ~= func(n);
if (f.back > maxN) break;
if (f.back%2!=0) f_odd~= f.back;
}
int INF = 1<<30;
int[] ary = new int[maxN+1];
ary[] = INF;
ary[0] = 0;
foreach(int i; 0..maxN) {
if (ary[i]<INF) {
for(int n=0; n<f.length; n++) {
if (i+f[n]<=maxN) {
ary[i+f[n]] = min(ary[i+f[n]], ary[i]+1);
} else {
break;
}
}
}
}
int[] _ary = new int[maxN+1];
_ary[] = INF;
_ary[0] = 0;
foreach(int i; 0..maxN) {
if (_ary[i]<INF) {
for(int n=0; n<f_odd.length; n++) {
if (i+f_odd[n]<=maxN) {
_ary[i+f_odd[n]] = min(_ary[i+f_odd[n]], _ary[i]+1);
} else {
break;
}
}
}
}
while(true) {
int N = readln.chomp.to!int;
if (N==0) break;
writeln(ary[N], " ", _ary[N]);
}
}
int func(int n) {
return n*(n+1)*(n+2)/6;
} | D |
import std.stdio, std.string, std.algorithm, std.conv;
void main(){
auto a = readln.split.map!(to!int);
writeln(a[0]<a[1]&&a[1]<a[2] ? "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; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (i; 0..t)
{
auto a = RD;
auto b = RD;
auto n = RD;
long x, y;
if (n == 0)
{
x = a;
}
else if ((n-1) % 3 != 0)
{
x = a;
}
if (n % 3 != 0)
{
y = b;
}
ans[i] = x^y;
}
foreach (e; ans)
writeln(e);
stdout.flush();
debug readln();
} | D |
import std.stdio,
std.string,
std.conv,
std.algorithm;
void main(){
int count = readln().chomp.to!int;
string[] lines;
foreach(i; 0..count){
lines.length++;
lines[i] = readln().chomp;
}
foreach(line; lines){
auto num = line.split.map!(to!int);
int d;
foreach(n1; num)
foreach(n2; num)
foreach(n3; num)
if((n1*n1) == (n2*n2) + (n3*n3))
d++;
if(d != 0)
writeln("YES");
else
writeln("NO");
}
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto N = readln.chomp.to!int;
auto A = readln.chomp.to!int;
writeln(N % 500 <= A ? "Yes" : "No");
} | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp;
writeln(s.length/2 - s.count('p'));
}
| 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 T = readln.chomp;
writeln(T[0..S.length] == S ? "Yes" : "No");
} | D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto s = readln.chomp.to!(char[]);
auto t = readln.chomp.to!(char[]);
int[char] f1, f2;
foreach (c; s) {
if (c in f1)
f1[c]++;
else
f1[c] = 1;
}
foreach (c; t) {
if (c in f2)
f2[c]++;
else
f2[c] = 1;
}
int[] a, b;
foreach (cnt; f1)
a ~= cnt;
foreach (cnt; f2)
b ~= cnt;
if (a.length != b.length) {
writeln("No");
return;
}
sort(a);
sort(b);
bool ok = true;
foreach (i; 0 .. a.length) {
ok &= a[i] == b[i];
}
writeln(ok ? "Yes" : "No");
}
void rd(T...)(ref T x) {
import std.stdio, std.string, std.conv;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
| D |
import 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 N = lread();
long prev;
long ans;
foreach (_; 0 .. N)
{
long A = lread();
if (0 < prev && A != 0)
{
ans++;
A--;
}
ans += A / 2;
prev = A & 1;
}
writeln(ans);
}
| D |
/+ dub.sdl:
name "sol_ysp"
dependency "dunkelheit" version="1.0.1"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
int main() {
Scanner sc = new Scanner(stdin);
scope(exit) assert(!sc.hasNext);
string s;
sc.read(s);
s ~= "A";
long ans, a_cnt;
size_t pos = 0;
while (pos < s.length) {
if (s[pos] == 'A') {
a_cnt++;
pos++;
} else if (s[pos..pos+2] == "BC") {
ans += a_cnt;
pos += 2;
} else {
a_cnt = 0;
pos++;
}
}
writeln(ans);
return 0;
}
/* 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);
}
}
}
}
/* 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;
private File f;
this(File f) {
this.f = f;
}
private char[512] lineBuf;
private 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) {
assert(succW());
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(Args...)(auto ref Args args) {
import std.exception : enforce;
static if (args.length != 0) {
enforce(readSingle(args[0]));
read(args[1..$]);
}
}
bool hasNext() {
return succ();
}
}
/*
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 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 A, B, C, K;
scan(A, B, C, K);
writeln((K & 1) ? (B - A) : (A - B));
}
| D |
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
string s = read!string;
if (s == "Sunny") writeln("Cloudy");
else if (s == "Cloudy") writeln("Rainy");
else if (s == "Rainy") writeln("Sunny");
}
| D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long N = lread();
long n = N % 10;
auto ans = [
"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"
];
writeln(ans[n]);
}
| D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
long x;
long pos;
foreach (i; 0..N)
{
x += i+1;
pos = i+1;
if (x >= N)
break;
}
long y = x - N;
foreach (i; 0..pos)
{
if (i+1 == y) continue;
writeln(i+1);
}
stdout.flush;
debug readln;
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto line = readln.chomp;
auto enil = line.dup;
reverse(enil);
writeln(line == enil ? "Yes" : "No");
} | D |
import std.stdio, std.string, std.conv, std.algorithm;
void main()
{
while(1){
auto n = readln.chomp.to!int;
if(n==0) break;
int s=1;
int max=50000001;
for(int i=2;i<n/2;++i){
if(n%i==0){
if(i<max){
s+=(i+n/i);
max = n/i;
if(i==max)
s -= i;
}else break;
}else if(i>max) break;
}
if(s<n || n==1) writeln("deficient number");
else if(s==n) writeln("perfect number");
else writeln("abundant number");
}
} | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
import std.math;
void main() {
auto cnt = new int[](5);
int n;
scan(n);
foreach (i ; 0 .. n) {
string s;
scan(s);
switch (s[0]) {
case 'M':
cnt[0]++;
break;
case 'A':
cnt[1]++;
break;
case 'R':
cnt[2]++;
break;
case 'C':
cnt[3]++;
break;
case 'H':
cnt[4]++;
break;
default:
break;
}
}
long ans;
foreach (i ; 0 .. 5) {
foreach (j ; i + 1 .. 5) {
foreach (k ; j + 1 .. 5) {
ans += 1L * cnt[i] * cnt[j] * cnt[k];
}
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
| D |
import std.stdio, std.algorithm, std.array, std.string, std.conv;
void main()
{
int t;
scanf("%d", &t);
foreach(_; 0..t)
{
int str_len;
scanf("%d", &str_len);
getchar();
auto str = readln.strip();
// writeln(str);
uint[] arr = new uint[str_len];
for(int i = 0; i < str_len; i++)
{
arr[i] = to!uint(str[i..i + 1]);
}
auto zeros = new uint[str_len];
long res = 0;
int last_non_null = str_len - 1;
while (arr != zeros)
{
if (arr[last_non_null] == 0){
last_non_null--;
}
else
{
if (last_non_null != str_len - 1)
res += 1;
res += arr[last_non_null];
arr[last_non_null] = 0;
last_non_null--;
}
}
writeln(res);
}
} | D |
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
long n = read.to!long;
long m = read.to!long;
bool[long] f1;
bool[long] f2;
foreach(i; 0 .. m){
long a = read.to!long;
long b = read.to!long;
if(a == 1) f1[b] = 1;
if(b == 1) f1[a] = 1;
if(a == n) f2[b] = 1;
if(b == n) f2[a] = 1;
}
string answer = "IMPOSSIBLE";
foreach(i; 1 .. m + 1){
if((i in f1) && (i in f2)) answer = "POSSIBLE";
}
answer.writeln;
} | 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() {
auto s = readln.chomp.to!(char[]);
long ans;
while (!s.empty) {
if (s.length == 1) break;
if (s.front == s.back) {
s.popFront();
s.popBack();
}
else if (s.front == 'x') {
ans++;
s.popFront();
}
else if (s.back == 'x') {
ans++;
s.popBack();
}
else {
writeln(-1);
return;
}
}
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 |
module bbb;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 N = readln.chomp.to!int;
auto s = readln.split.map!(to!int);
auto Ga = s[0];
auto Sa = s[1];
auto Ba = s[2];
s = readln.split.map!(to!int);
auto Gb = s[0];
auto Sb = s[1];
auto Bb = s[2];
long solve(long n, long g1, long g2, long s1, long s2, long b1, long b2) {
long[][] X;
if (g1 < g2) X ~= [g1, g2];
if (s1 < s2) X ~= [s1, s2];
if (b1 < b2) X ~= [b1, b2];
long ans = n;
if (X.length == 0) return n;
else if (X.length == 1) return n / X.front[0] * X.front[1] + n % X.front[0];
else if (X.length == 2) {
foreach (i; 0..n+1) {
long j = n - i;
long tmp = i / X[0][0] * X[0][1] + j / X[1][0] * X[1][1] + i % X[0][0] + j % X[1][0];
ans = max(ans, tmp);
}
}
else {
foreach (i; 0..n+1) {
foreach (j; 0..n-i+1) {
long k = n - i - j;
if (b1 >= b2) k = 0;
//long tmp = i / g1 * g2 + j / s1 * s2 + k / b1 * b2 + i % g1 + j % s1 + k % b1;
long tmp = i / X[0][0] * X[0][1] + j / X[1][0] * X[1][1] + k / X[2][0] * X[2][1] + i % X[0][0] + j % X[1][0] + k % X[2][0];
ans = max(ans, tmp);
}
}
}
return ans;
}
auto M = solve(N, Ga, Gb, Sa, Sb, Ba, Bb);
auto L = solve(M, Gb, Ga, Sb, Sa, Bb, Ba);
L.writeln;
}
| D |
void main() {
auto N = ri;
auto S = rs;
ulong res;
foreach(i; 0..S.length - 2) {
if(S[i..i+3] == "ABC") res++;
}
res.writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
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, 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 char[][][](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto s = new char[][](n);
foreach (i; 0..n)
s[i] = RD!(char[]);
bool f(int num)
{
int cnt0, cnt1;
foreach (int i; 0..n)
{
foreach (int j; 0..n)
{
if (s[i][j] == '.') continue;
++cnt1;
int p = (n*3 + j - i) % 3;
if (p != num) continue;
int x;
{
char c;
int cnt;
foreach (k; max(0, j - 2)..min(n, j + 3))
{
if (s[i][k] != c)
{
c = s[i][k];
cnt = 1;
}
else
{
++cnt;
if (cnt == 3)
{
++x;
break;
}
}
}
}
{
char c;
int cnt;
foreach (k; max(0, i - 2)..min(n, i + 3))
{
if (s[k][j] != c)
{
c = s[k][j];
cnt = 1;
}
else
{
++cnt;
if (cnt == 3)
{
++x;
break;
}
}
}
}
if (x != 0)
{
s[i][j] = s[i][j] == 'O' ? 'X' : 'O';
++cnt0;
}
}
}
return cnt0 <= (cnt1 / 3);
}
auto ss = new char[][](n, n);
foreach (i; 0..n)
ss[i][] = s[i][];
foreach (i; 0..3)
{
foreach (j; 0..n)
s[j][] = ss[j][];
auto r = f(i);
debug writeln("i:", i);
if (r) break;
}
ans[ti] = s;
}
foreach (e; ans)
{
foreach (ee; e)
writeln(ee);
}
stdout.flush;
debug readln;
} | D |
import std.stdio; // ??\????????????????????????
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
import std.algorithm; // map?????????????????????
void main() {
auto input = readln.split.map!(to!int);
auto a = input[0];
auto b = input[1];
if (a > b) {
writeln("a > b");
} else if (a < b){
writeln("a < b");
} else {
writeln("a == b");
}
} | D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long N = lread();
auto ans = new long[](10_000_000);
foreach (x; 1 .. 500)
foreach (y; 1 .. 500)
foreach (z; 1 .. 500)
{
long n = x * x + y * y + z * z + x * y + y * z + z * x;
// dprint(x, y, z, n);
ans[n]++;
}
foreach (i; 1 .. N + 1)
{
writeln(ans[i]);
}
}
| D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto n = readln.chomp.to!int;
auto s = readln.chomp.array;
foreach (ref e; s) {
auto d = (e - 'A' + n) % 26;
e = 'A' + d;
}
s.writeln;
}
| D |
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
T readNum(T)(){
return readStr.to!T;
}
T[] readNums(T)(){
return readStr.split.to!(T[]);
}
string readStr(){
return readln.chomp;
}
void main(){
auto t = readStr;
auto s = t.replace("?", "D");
writeln(s);
}
| D |
void main() {
int x = readln.chomp.to!int;
writeln(x == 7 || x == 5 || x == 3 ? "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.container;
import std.typecons; | 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, a, b;
scan(n,a,b);
if (!n) return;
auto p = iota(n).map!(i => readln.chomp.to!int).array;
solve(n,a,b,p);
}
}
void solve(int n, int a, int b, int[] p) {
int difmax, ans;
foreach (i ; a .. b + 1) {
if (difmax <= p[i-1] - p[i]) {
difmax = p[i-1] - p[i];
ans = i;
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
} | D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;
void main()
{
int N = scanElem!int;
int M = scanElem!int;
int[] nList;
nList.length = N + 1;
foreach(i;0..M)
{
int s = scanElem!int;
int g = scanElem!int;
if(nList[s]==0)
{
nList[s] = g;
}else{
nList[s] = min(nList[s], g);
}
}
int count;
int end;
foreach(s, g; nList)
{
if(g==0) continue;
if(end <= s)
{
count++;
end = g;
}
end = min(end, g);
}
writeln(count);
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
T scanElem(T = long)()
{
string res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
} | D |
void main(){
char[] val = inln!char();
writeln( (val[0]=='H')^(val[1]=='H')?'D':'H');
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
// 1要素のみの入力
T inelm(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] inln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
return ln;
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
// int n=6, m=10;
// auto c=new int[][](n, m);
// auto dir=[[-1, -1], [-1, 0], [-1, 1], [0, 1], [1, 1], [1, 0], [1, -1], [0, -1]];
// foreach(i; 0..n)foreach(j; 0..m){
// c[i][j]^=1;
// foreach(d; dir){
// auto ni=i+d[0], nj=j+d[1];
// if(ni<0 || ni>=n || nj<0 || nj>=m) continue;
// c[ni][nj]^=1;
// }
// }
// foreach(i; 0..n) writeln(c[i]);
// writeln(313*2+1591*2);
long n, m; rd(n, m);
if(n==1 && m==1) writeln(1);
else if(n==1) writeln(m-2);
else if(m==1) writeln(n-2);
else writeln(n*m-((n-1)*2+(m-1)*2));
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
} | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
int H, W;
auto dy = [0, 0, 1, -1], dx = [1, -1, 0, 0];
char[][] board;
void main(){
for(;init;){
writeln(solve);
}
}
bool init(){
auto input = map!(to!int)(readln.chomp.split);
H = input[0];
W = input[1];
board = new char[][](H);
foreach(ref line; board){
line = to!(char[])(readln.chomp);
}
return H > 0;
}
int solve(){
int ans = 0;
foreach(y; 0..H){
foreach(x; 0..W){
if(board[y][x] != '.'){
++ans;
dfs(y, x, board[y][x]);
}
}
}
return ans;
}
void dfs(int y, int x, char col){
board[y][x] = '.';
foreach(k; 0..4){
int ny = y + dy[k], nx = x + dx[k];
if(0<=ny && ny<H && 0<=nx && nx<W && board[ny][nx] == col){
dfs(ny, nx, col);
}
}
} | D |
// Vicfred
// https://atcoder.jp/contests/abc165/tasks/abc165_b
// simulation
import std.conv;
import std.stdio;
import std.string;
void main() {
long x = readln.chomp.to!long;
long current = 100;
long answer = 0;
while(current < x) {
current += current/100;
answer += 1;
}
answer.writeln;
}
| D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
readln.chomp.count!"a == '1'".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;
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()
{
writeln("ABC" ~ sread());
}
| D |
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto ip = readln.split.to!(int[]), N=ip[0], M=ip[1];
int L = 0;
int R = N;
foreach(i; 0..M){
auto LR = readln.split.to!(int[]);
L = max(L, LR[0]);
R = min(R, LR[1]);
}
if(L<=R) writeln(R-L+1);
else writeln(0);
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long N, M;
scan(N, M);
long[] cnt = new long[](N);
foreach (_; 0 .. M)
{
long a, b;
scan(a, b);
cnt[a - 1]++;
cnt[b - 1]++;
}
foreach (c; cnt)
writeln(c);
}
| D |
// Vicfred
// https://atcoder.jp/contests/abc155/tasks/abc155_b
// simulation
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main() {
int n = readln.chomp.to!int;
int[] a = readln.split.map!(to!int).array;
foreach(item; a) {
if(item%2 == 0 && item%3 != 0 && item%5 != 0) {
writeln("DENIED");
return;
}
}
writeln("APPROVED");
}
| 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() {
long a, b, c, d;
scan(a, b, c, d);
auto ans = f(b, c, d) - f(a - 1, c, d);
writeln(ans);
}
long f(long x, long c, long d) {
return x - (x / c) - (x / d) + (x / lcm(c, d));
}
long lcm(long a, long b) {
return a / gcd(a, b) * b;
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
int[char] cnt;
foreach (e; s) {
cnt[e]++;
}
if (s.length == cnt.keys.length) {
writeln("yes");
} else {
writeln("no");
}
}
| 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 = "0" ~ readln.chomp;
auto N = S.length.to!int;
auto dp = new int[][](N+1, 2);
foreach (i; 0..N+1) dp[i][] = 1 << 29;
dp[0][0] = 0;
foreach (i; 0..N) {
int d = S[N - i - 1] - '0';
dp[i+1][0] = min(dp[i][0] + d, d == 9 ? 1 << 29 : dp[i][1] + d + 1);
dp[i+1][1] = min(d == 0 ? 1 << 29 : dp[i][0] + 10 - d, dp[i][1] + 9 - d);
}
dp[N][0].writeln;
}
| D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
void main() {
auto s = readln.strip.splitter;
immutable int n = s.front.to!int;s.popFront;
immutable int m = s.front.to!int;
int problems, penalty;
int[int] c;
bool[int] d;
foreach (qid; 0 .. m) {
s = readln.strip.splitter;
immutable int k = s.front.to!int;s.popFront;
bool ac = s.front.front == 'A';
if (ac) {
auto ptr = k in d;
if (ptr is null) {
++problems;
int t = c.get (k, 0);
penalty += t;
d[k] = true;
}
} else {
c[k] = c.get (k, 0) + 1;
}
}
writeln (problems, ' ', penalty);
}
| 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 nk = readln.chomp.split.map!(to!int);
auto num = 1;
foreach (i; 0..nk[0]) {
if (i==0) num *= nk[1];
else num *= nk[1]-1;
}
num.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 File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto n = RD!int;
auto ans = new int[](n);
foreach (i; 0..n)
{
auto c = RD!int;
auto sum = RD!int;
auto x = sum / c;
auto y = sum % c;
ans[i] += ((x+1)^^2) * y;
ans[i] += (x^^2) * (c - y);
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
} | D |
import std.algorithm,
std.string,
std.range,
std.stdio,
std.conv;
void main() {
int[char] dic;
foreach (c; readln.chomp) {
if (c !in dic) {
dic[c] = 1;
} else {
dic[c]++;
}
}
writeln(dic.values.all!(n => n % 2 == 0) ? "Yes" : "No");
} | D |
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;
bool solve(int[] p, int t) {
if (p.empty) return t == 0;
if (t == 0) return true;
if (t < 0) return false;
int n = p.front;
p.popFront;
if (solve(p, t-n)) return true;
if (solve(p, t)) return true;
return false;
}
void main() {
auto n = readln.chomp.to!int;
auto a = readln.chomp.split.map!(to!int).array;
auto q = readln.chomp.to!int;
auto m = readln.chomp.split.map!(to!int).array;
foreach (m_i; m) {
if (solve(a, m_i)) {
"yes".writeln;
} else {
"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;
void main()
{
while (1) {
auto n = readln.chomp.to!int;
if (n == -1) break;
n.to!string(4).writeln;
}
} | D |
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int n = read.to!int;
int d = read.to!int;
long[][] xs = new long[][](n, d);
foreach(i; 0 .. n) foreach(k; 0 .. d){
xs[i][k] = read.to!long;
}
int ans = 0;
foreach(i; 0 .. n) foreach(j; 0 .. i){
long u2;
foreach(k; 0 .. d) u2 += (xs[i][k] - xs[j][k] ) * (xs[i][k] - xs[j][k]);
long u = (u2.to!real + 0.1).sqrt.to!long;
if(u * u == u2) ans += 1;
}
ans.writeln;
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto lrd = readln.split.to!(int[]);
auto L = lrd[0];
auto R = lrd[1];
auto d = lrd[2];
int c;
foreach (i; L..R+1) if (i%d == 0) ++c;
writeln(c);
} | 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!(long[]);
writeln(i[0]+1-i[1]);
}
| D |
import std.algorithm;
import std.array;
import std.stdio;
import std.conv;
import std.string;
import std.range;
void main(){
size_t w, h, sx, sy;
char[][] data = new char[][](20, 20);
while(true){
auto input = readln.split;
w = input[0].to!int;
h = input[1].to!int;
if(!(w | h)){
break;
}
foreach(i; 0..h){
foreach(j, c; readln.chomp){
data[i][j] = c;
if(c == '@'){
sx = j;
sy = i;
data[i][j] = '#';
}
}
}
data.dfs(sx, sy, w, h).writeln;
}
}
auto move = [[1, 0], [0, 1], [-1, 0], [0, -1]];
size_t dfs(char[][] data, size_t sx, size_t sy, size_t w, size_t h){
size_t count = 1;
foreach(i; 0..4){
size_t x = sx + move[i][0];
size_t y = sy + move[i][1];
if(0 <= x && x < w && 0 <= y && y < h && data[y][x] != '#'){
data[y][x] = '#';
count += dfs(data, x, y, w, h);
}
}
return count;
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto n = readln.chomp.to!int;
int cx, cy, ct;
auto f = false;
foreach (_; 0..n) {
auto x = readln.chomp.split.to!(int[]);
x[0] -= ct;
auto d = x[1] - cx + x[2] - cy;
if (x[0] - d >= 0 && (x[0] - d) % 2 == 0) {
cx = x[1];
cy = x[2];
ct += x[0];
} else {
f = true;
break;
}
}
if (f) {
writeln("No");
} else {
writeln("Yes");
}
}
| D |
void main() {
auto N = ri;
auto s = rs;
if(s.count!"a == 'R'" > s.count!"a == 'B'") writeln("Yes");
else writeln("No");
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
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, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }
void main() {
int a,b,c;
scanf("%d%d%d", &a,&b,&c);
writeln(a+b >= c ? "Yes" : "No");
auto _ = readln(); // dbg
} | D |
void main() {
problem();
}
void problem() {
auto K = scan!int;
auto A = scan!int;
auto B = scan!int;
bool solve() {
foreach(i; A..B+1) {
if (i % K == 0) return true;
}
return false;
}
writeln(solve() ? "OK" : "NG");
}
// ----------------------------------------------
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.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto A = RD;
auto B = RD;
A = A == 1 ? 14 : A;
B = B == 1 ? 14 : B;
writeln(A == B ? "Draw" : A < B ? "Bob" : "Alice");
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, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto K = s[1];
auto S = readln.chomp;
auto cnt = new int[](26);
foreach (i; 0..N) cnt[S[i]-'A'] += 1;
int ans = 1 << 29;
foreach (i; 0..K) ans = min(ans, cnt[i]);
writeln(ans * K);
}
| 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;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
int n, h, w;
cin.scan(n, h, w);
int res;
foreach (i; 0 .. n) {
int y, x;
cin.scan(y, x);
res += min(y / h, x / w);
}
writeln(res);
}
| D |
import std.stdio;
import std.string;
import std.functional;
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;
// void main(string[] args)でもいい.
void main() {
auto ab = readln.split.to!(int[]);
writeln(ab[0] * ab[1]);
}
| D |
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv, std.typecons, std.math;
import std.functional;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.graph.maxflow;
long f(int le, int p, long d) {
int q = le-1-p;
long up = 0;
foreach (p2; p..le) {
int q2 = le-1-p2;
if (p2 >= q2) break;
up += 9*(10L^^q2 - 10L^^p2);
}
if (abs(d) > up) return 0;
if (p == q) {
if (d == 0) return 10;
return 0;
}
if (p > q) {
if (d == 0) return 1;
return 0;
}
long sm = 0;
foreach (i; 0..10) {
foreach (j; 0..10) {
if (p == 0 && j == 0) continue;
sm += memoize!f(le, p+1, d - (i-j)*(10L^^q - 10L^^p));
}
}
return sm;
}
int main() {
auto sc = new Scanner(stdin);
long D;
sc.read(D);
long sm = 0;
foreach (le; 1..19) {
sm += f(le, 0, D);
/* long d = D;
long sm = 0;
foreach (i; 0..le) {
int j = le-1-i;
if (i >= j) break;
long f = (10L^^j) - (10L^^i);
writeln(d / f);
d %= f;
}
if (d) continue;*/
}
writeln(sm);
return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/container/deque.d */
// module dcomp.container.deque;
struct Deque(T, bool mayNull = true) {
import core.exception : RangeError;
import core.memory : GC;
import std.range : ElementType, isInputRange;
import std.traits : isImplicitlyConvertible;
struct Payload {
T *d;
size_t st, length, cap;
@property bool empty() const { return length == 0; }
alias opDollar = length;
ref inout(T) opIndex(size_t i) inout {
version(assert) if (length <= i) throw new RangeError();
return d[(st+i >= cap) ? (st+i-cap) : st+i];
}
private void expand() {
import std.algorithm : max;
assert(length == cap);
auto nc = max(size_t(4), 2*cap);
T* nd = cast(T*)GC.malloc(nc * T.sizeof);
foreach (i; 0..length) {
nd[i] = this[i];
}
d = nd; st = 0; cap = nc;
}
void clear() {
st = length = 0;
}
void insertFront(T v) {
if (length == cap) expand();
if (st == 0) st += cap;
st--; length++;
this[0] = v;
}
void insertBack(T v) {
if (length == cap) expand();
length++;
this[length-1] = v;
}
void removeFront() {
assert(!empty, "Deque.removeFront: Deque is empty");
st++; length--;
if (st == cap) st = 0;
}
void removeBack() {
assert(!empty, "Deque.removeBack: Deque is empty");
length--;
}
}
struct RangeT(A) {
alias T = typeof(*(A.p));
alias E = typeof(A.p.d[0]);
T *p;
size_t a, b;
@property bool empty() const { return b <= a; }
@property size_t length() const { return b-a; }
@property RangeT save() { return RangeT(p, a, b); }
@property RangeT!(const A) save() const {
return typeof(return)(p, a, b);
}
alias opDollar = length;
@property ref inout(E) front() inout { return (*p)[a]; }
@property ref inout(E) back() inout { return (*p)[b-1]; }
void popFront() {
version(assert) if (empty) throw new RangeError();
a++;
}
void popBack() {
version(assert) if (empty) throw new RangeError();
b--;
}
ref inout(E) opIndex(size_t i) inout { return (*p)[i]; }
RangeT opSlice() { return this.save; }
RangeT opSlice(size_t i, size_t j) {
version(assert) if (i > j || a + j > b) throw new RangeError();
return typeof(return)(p, a+i, a+j);
}
RangeT!(const A) opSlice() const { return this.save; }
RangeT!(const A) opSlice(size_t i, size_t j) const {
version(assert) if (i > j || a + j > b) throw new RangeError();
return typeof(return)(p, a+i, a+j);
}
}
alias Range = RangeT!Deque;
alias ConstRange = RangeT!(const Deque);
alias ImmutableRange = RangeT!(immutable Deque);
Payload* p;
private void I() { if (mayNull && !p) p = new Payload(); }
private void C() const {
version(assert) if (mayNull && !p) throw new RangeError();
}
static if (!mayNull) {
@disable this();
}
private this(Payload* p) {
this.p = p;
}
this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {
p = new Payload();
foreach (v; values) {
insertBack(v);
}
}
this(Range)(Range r)
if (isInputRange!Range &&
isImplicitlyConvertible!(ElementType!Range, T) &&
!is(Range == T[])) {
p = new Payload();
foreach (v; r) {
insertBack(v);
}
}
static Deque make() { return Deque(new Payload()); }
@property bool havePayload() const { return (!mayNull || p); }
@property bool empty() const { return (!havePayload || p.empty); }
@property size_t length() const { return (havePayload ? p.length : 0); }
alias opDollar = length;
ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }
ref inout(T) front() inout {C; return (*p)[0]; }
ref inout(T) back() inout {C; return (*p)[$-1]; }
void clear() { if (p) p.clear(); }
void insertFront(T v) {I; p.insertFront(v); }
void insertBack(T v) {I; p.insertBack(v); }
alias stableInsertBack = insertBack;
void removeFront() {C; p.removeFront(); }
void removeBack() {C; p.removeBack(); }
Range opSlice() {I; return Range(p, 0, length); }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/graph/maxflow.d */
// module dcomp.graph.maxflow;
// import dcomp.container.deque;
struct maxFlowInfo(C) {
C flow;
bool[] dual;
}
maxFlowInfo!(C) maxFlow(C, C EPS, T)(T g, int s, int t) {
assert(s != t);
import std.algorithm : map;
import std.range : array;
import std.conv : to;
int n = g.length.to!int;
int[] level = new int[n];
int[] iter = new int[n];
void bfs() {
level[] = -1; level[s] = 0;
auto que = Deque!int(s);
while (!que.empty) {
int v = que.back; que.removeBack();
foreach (e; g[v]) {
if (e.cap <= EPS) continue;
if (level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.insertBack(e.to);
}
}
}
}
C dfs(int v, int t, C f) {
import std.algorithm : min;
if (v == t) return f;
auto edgeList = g[v][iter[v]..$];
foreach (ref e; edgeList) {
if (e.cap <= EPS) continue;
if (level[v] < level[e.to]) {
C d = dfs(e.to, t, min(f, e.cap));
if (d <= EPS) continue;
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
iter[v]++;
}
return 0;
}
C flow = 0;
while (true) {
bfs();
if (level[t] < 0) break;
iter[] = 0;
while (true) {
C f = dfs(s, t, C.max);
if (!f) break;
flow += f;
}
}
auto mfInfo = maxFlowInfo!C();
mfInfo.flow = flow;
mfInfo.dual = level.map!"a == -1".array;
return mfInfo;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
size_t n;
scanf("%ld\n", &n);
size_t[ubyte[]] map;
foreach(i; 0..n) {
auto l = readln.chomp.representation.dup;
l.sort!"a<b";
immutable key = l.dup;
if (key in map) {
++map[key];
}
else {
map[key] = 1;
}
}
size_t ans;
foreach(key; map.keys) {
ans += map[key] * (map[key] - 1) / 2;
}
ans.write;
}
| 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() {
string s;
scan(s);
auto n = s.length.to!int;
int a;
foreach (i ; 0 .. n) {
if (s[i] == 'A') {
a = i;
break;
}
}
int z = n;
foreach_reverse (i ; 0 .. n) {
if (s[i] == 'Z') {
z = i;
break;
}
}
auto ans = z - a + 1;
writeln(ans);
}
| D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
void main() {
auto s = readln.strip;
int t;
for (size_t i = 0, j = s.length - 1; i < j; i++,j--) {
if (s[i] != s[j]) ++t;
}
writeln (t);
}
| D |
import std.stdio, std.string, std.conv;
void main()
{
while(true)
{
int n=readln.chomp.to!int;
if(!n)break;
int num;
for(int i=1; i<n; ++i)
{
int sum;
for(int j=i; j<n; ++j)
{
sum+=j;
if(sum == n) ++num;
else if(sum > n) break;
}
}
num.writeln;
}
} | D |
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }
void main() {
long x = readln.chomp.to!long;
long sum(long n) { // 隨ャ0鬆・°繧臥ャャn-1鬆・∪縺ァ縺ョ蜥・//
return (n / 2) * 11L + 6 * (n % 2);
}
long lb = 0, ub = cast(long)(1e15 + 1);
while (lb + 1 < ub) {
long mid = (lb + ub) / 2;
if (sum(mid) < x) {
lb = mid;
} else {
ub = mid;
}
}
writeln(ub);
}
| D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void main()
{
string s; readV(s);
string t; readV(t);
auto ns = s.length.to!int, nt = t.length.to!int;
loop: foreach_reverse (i; 0..ns-nt+1) {
auto u = s.dup;
foreach (j; 0..nt) {
if (u[i+j] == '?') {
u[i+j] = t[j];
} else {
if (u[i+j] != t[j]) continue loop;
}
}
foreach (ref ui; u)
if (ui == '?') ui = 'a';
writeln(u);
return;
}
writeln("UNRESTORABLE");
}
| D |
//
import std.stdio,std.array,std.conv;
void main(){
auto sr=readln.split;
int r=to!int(sr[0]);
auto sg=readln.split;
int g=to!int(sg[0]);
writeln(g*2-r);
} | 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 S = RD!string;
auto T = RD!string;
long ans;
foreach (i; 0..S.length)
{
if (S[i] != T[i])
++ans;
}
writeln(ans);
stdout.flush;
debug readln;
}
| D |
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
void main() {
auto N = readln.chomp.to!int;
auto S = readln;
int total = 0;
foreach(i; 0..N) {
if (i == 0) {
total++;
continue;
}
if (S[i-1] == S[i]) continue;
total++;
}
writeln(total);
}
| D |
void main() {
int x = readln.chomp.to!int;
int a = readln.chomp.to!int;
int b = readln.chomp.to!int;
writeln((x - a) % b);
}
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;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
void main()
{
auto s = readln.chomp;
auto t = readln.chomp;
foreach (i; 0 .. s.length)
{
bool flag = true;
foreach (k, c; s)
flag &= (t[(k + i) % t.length] == c);
if (flag)
{
"Yes".writeln;
return;
}
}
"No".writeln;
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
int c;
foreach (i; 1..N+1) {
if (i < 10 || (100 <= i && i < 1000) || (10000 <= i && i < 100000)) ++c;
}
writeln(c);
} | D |
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(e1; 1..10){ foreach(e2; 1..10){ writeln(e1, "x", e2, "=", e1*e2); } }
} | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
void main()
{
auto n = readln().chomp().to!int;
int cnt4, cnt2, cnt1;
foreach(e; readln().chomp().splitter(' ').map!(to!int)){
if(e % 4 == 0){
++cnt4;
}else if(e % 2 != 0){
++cnt1;
}else
++cnt2;
}
if(cnt2 != 0)
writeln(cnt4 >= cnt1 ? "Yes" : "No");
else
writeln(cnt4+1 >= cnt1 ? "Yes" : "No");
} | D |
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int n = scan!int;
int a = n / 500;
int b = (n - 500 * a) / 5;
int ans = a * 1000 + b * 5;
ans.writeln;
}
| D |
import std.stdio, std.conv, std.string, std.regex, std.math, std.array, std.algorithm;
void main(){
auto ip = readln.split;
int A = ip[0].to!int;
int B = ip[2].to!int;
char op = ip[1].to!char;
if(op == '+'){
writeln(A + B);
} else if(op == '-'){
writeln(A - B);
}
} | D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.