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;
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;
foreach (c; s) {
switch (c) {
case '1': write('9'); break;
case '9': write('1'); break;
default: write(c); break;
}
}
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
auto N = split(readln())[0].to!int();
auto L = split(readln()).map!(x => to!int(x));
auto sum = reduce!("a + b")(L);
foreach (i; 0 .. N) {
if (sum-L[i] <= L[i] ) { writeln("No"); return; }
}
writeln("Yes");
} | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main(){
if(readln.chomp.to!int == 1){
writeln("Hello World");}
else{
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
writeln(a+b);}
} | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!int;
writeln(n*(n+1)/2);
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto A = new long[](N);
auto B = new long[](N);
foreach (i; 0 .. N)
scan(A[i], B[i]);
long ans;
foreach_reverse (i; 0 .. N)
{
ans += (B[i] - ((A[i] + ans) % B[i])) % B[i];
}
writeln(ans);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.range;
void main() {
auto ip = readln.split.to!(int[]), A = ip[0], B = ip[1], C = ip[2], D = ip[3];
if(B <= C || D <= A) 0.writeln;
else if(A <= C) (B < D ? B - C : D - C).writeln;
else (B < D ? B - A : D - A).writeln;
}
| D |
void main(){
int n = _scan();
(n^^3).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;
import std.string;
import std.conv;
import std.algorithm;
void main(){
auto z=readln.split.to!(int[]),a=z[0],b=z[1],c=z[2];
if(a+b<=a+c&&a+b<=b+c)writeln(a+b);
else if(a+c<=a+b&&a+c<=b+c)writeln(a+c);
else if(b+c<=a+b&&b+c<=a+c)writeln(b+c);
} | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 10^^6;
void main() {
int r;
scan(r);
writeln(r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC");
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
} | D |
import std.stdio,std.conv;
long[2001] a,b;
long n,x,y,ans;
void main()
{
scanf(" %d",&n);
for(int i=0;i<n;++i)
{
scanf(" %d %d",&x,&y);
++a[to!uint(x+y)];
++b[to!uint(1000+x-y)];
}
for(int i=0;i<=2000;++i)
{
if(a[i]>1) ans+=a[i]*(a[i]-1)/2;
if(b[i]>1) ans+=b[i]*(b[i]-1)/2;
}
writeln(ans);
}
| D |
void main()
{
long x = rdElem;
long result = ceil(0.5 * (-1 + sqrt(1.0 + 8.0 * x))).to!long;
result.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 |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int q;
rd(q);
int l = 0, r = 0; // [l, r)
auto pos = new int[](2 * 10 ^^ 5 + 1);
while (q--) {
char t;
int x;
rd(t, x);
if (t == 'L') {
pos[x] = --l;
} else if (t == 'R') {
pos[x] = r++;
} else {
writeln(min(pos[x] - l, r - pos[x] - 1));
}
}
}
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;
void main(){
auto cin = new Cin();
auto ab = cin.line!long();
if( ab[0] <= 0 && 0 <= ab[1] ){
writeln("Zero");
} else if( ab[1]<0 && (ab[1]-ab[0])%2==0 ){
writeln("Negative");
} else {
writeln("Positive");
}
//sum.writeln();
}
auto solve(){
}
unittest{
}
import std.stdio,std.conv,std.string;
import std.algorithm,std.array;
class Cin
{
T[] line( T = size_t , string token = " " )( size_t m = 1 ){
T[] arr = [];
foreach( i ; 0..m ){
arr ~= this.read!T();
}
return arr;
}
T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){
T[][] arr = new T[][](m);
foreach( i ; 0..m ){
arr[i] = this.read!T(token);
}
return arr;
}
private T[] read( T = size_t )( string token = " " ){
T[] arr;
foreach( elm ; readln().chomp().split(token) ){
arr ~= elm.to!T();
}
return arr;
}
} | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
immutable long MOD = 10^^9 + 7;
void main() {
auto N = readln.chomp.to!int;
auto S = readln.chomp;
auto dp = new long[][](N, N);
dp[0][] = 1;
foreach (i; 1..N) {
if (S[i-1] == '>') {
long s = dp[i-1][N-i];
foreach_reverse (j; 0..N-i) {
(dp[i][j] += s) %= MOD;
(s += dp[i-1][j]) %= MOD;
}
} else {
long s = dp[i-1][0];
foreach (j; 0..N-i) {
(dp[i][j] += s) %= MOD;
(s += dp[i-1][j+1]) %= MOD;
}
}
}
long ans = 0;
foreach (j; 0..N)
(ans += dp[N-1][j]) %= MOD;
ans.writeln;
}
| D |
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto N = readln.split.to!(int[]), a=N[0], b=N[1], c=N[2], d=N[3];
if(abs(c-a)<=d||(abs(b-a)<=d&&abs(c-b)<=d)) writeln("Yes");
else 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;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto s = sread();
bool b = s[0] == '9' || s[1] == '9';
writeln(b ? "Yes" : "No");
}
| D |
void main() {
problem();
}
void problem() {
auto a = scan!long;
auto b = scan!long;
auto c = scan!long;
auto d = scan!long;
long solve() {
if ((b <= 0 && c >= 0) || (a >= 0 && d <= 0)) {
return -1 * min(abs(a), abs(b)) * min(abs(c), abs(d));
}
return max(a*c, b*d);
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
| D |
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()
{
immutable mod = 1_000_000_000 + 7;
auto n = readln.chomp.to!int;
long res = 1;
foreach (i; 1..n+1) {
res *= i;
res %= mod;
}
res.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 q, h, s, d;
scan(q, h, s, d);
// writeln(q, ' ', h, ' ', s, ' ', d);
auto n = lread();
// writeln(n, "L買いたい");
long x = 4 * q; //0.25で作った1
long y = 2 * h; //0.5で作った1
// writeln("1: ", s);
// writeln("0.25で作った1: ", x);
// writeln("0.5で作った1: ", y);
// writeln("2: ", d);
// writeln("0.25で作った2: ", x * 2);
// writeln("0.5で作った2: ", y * 2);
long min_1 = min(s, x, y);
long min_2 = min(d, x * 2, y * 2, min_1 * 2);
// writeln(min_1);
// writeln(min_2);
if (n == 1)
{
writeln(min_1);
return;
}
if (n % 2 != 0)
{
writeln(min((n / 2) * min_2 + min_1, min_1 * n));
return;
}
else
{
writeln(min(min_1 * n, min_2 * (n / 2)));
return;
}
}
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.array;
import std.math;
void main()
{
auto reader = readln.split;
int A = reader[0].to!int;
int B = reader[1].to!int;
int diff = abs(A - B);
if (diff % 2 == 0){
writeln((A + B) / 2);
} else {
writeln("IMPOSSIBLE");
}
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;
import std.format;
void main()
{
int n = readln.chomp.to!int;
long[] t = new long[](n);
foreach (ref v; t) {
v = readln.chomp.to!long;
}
long ite = 1;
foreach (v; t) {
ite = lcm(ite, v);
}
writeln = ite;
}
long lcm(long a, long b)
{
return a / gcd(a, b) * b;
}
long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
| D |
module AOJ_Volume0101;
import std.stdio,std.string,std.conv,std.array;
int main()
{
int n = readln.chomp.to!int;
while(n--)
{
string s = readln.chomp;
replace(s,"Hoshino","Hoshina").writeln;
}
return 0;
} | 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 main()
{
auto N = RD;
auto K = RD;
long ans = 1;
while (N >= K)
{
++ans;
N /= K;
}
writeln(ans);
stdout.flush;
debug readln;
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto edges = new long[][](N);
foreach (i; 0..N)
{
auto S = RD!string;
foreach (j, c; S)
{
if (c == '1')
{
edges[i] ~= j;
}
}
}
/*while (true){
auto N = 5;
auto S = new char[][](N, N);
foreach (i; 0..N)
{
auto num = uniform(0, N-1);
if (i != 0)
{
auto pos = uniform(0, i);
S[i][pos] = '1';
S[pos][i] = '1';
}
foreach (j; 0..num)
{
auto pos = i;
while (pos == i)
{
pos = uniform(0, N);
}
S[i][pos] = '1';
S[pos][i] = '1';
}
}
auto edges = new long[][](N);
foreach (i; 0..N)
{
foreach (j, c; S[i])
{
if (c == '1')
{
edges[i] ~= j;
}
}
}
foreach (i; 0..N)
{
foreach (to; edges[i])
writeln(i, " ", to);
}
long _ans = -1;
foreach (i1; 0..N)
{
foreach (i2; 0..N)
{
foreach (i3; 0..N)
{
foreach (i4; 0..N)
{
foreach (i5; 0..N)
{
auto list = [i1, i2, i3, i4, i5];
auto set = new bool[](N);
foreach (e; list)
set[e] = true;
long cnt;
foreach (e; set)
if (e) ++cnt;
if (cnt <= _ans) continue;
auto close = new bool[](N);
bool dfs(long from, long par)
{
if (close[from]) return true;
close[from] = true;
foreach (to; edges[from])
{
if (to == par) continue;
if (list[to] == list[from]-1 || list[to] == list[from]+1)
{
auto r = dfs(to, from);
if (!r) return false;
}
else
return false;
}
return true;
}
auto r = dfs(0, 0);
if (r)
{
_ans = cnt;
debug writeln(list);
}
}
}
}
}
}
debug writeln("ans:", _ans);*/
long bfs(long pos)
{
long[2][] open = [[pos, -1]];
auto dist = new long[](N);
dist[] = -1;
dist[pos] = 0;
while (!open.empty)
{
auto n = open.front; open.popFront;
auto from = n[0];
auto par = n[1];
foreach (to; edges[from])
{
if (to == par) continue;
if (dist[to] != -1)
{
auto diff = dist[from]+1 - dist[to];
if (diff != 0 && diff != 2)
return -1;
continue;
}
dist[to] = dist[from] + 1;
open ~= [to, from];
}
}
long p = dist.MIN_POS!"a > b"();
debug writeln("dist:", dist);
return dist[p]+1;
}
long ans = -1;
foreach (i; 0..N)
{
auto r = bfs(i);
debug writeln(r);
/*if (r == -1)
{
ans = -1;
break;
}*/
ans = max(ans, r);
}
writeln(ans);
//if (_ans != ans) break;
stdout.flush();
debug readln();
} | 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, d;
scan(n, d);
auto c = 2*d + 1;
auto ans = (n + c - 1) / c;
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, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
writeln(s.length/2-s.count('p'));
}
| D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto s = readln.chomp.to!(char[]);
auto t = readln.chomp.to!(char[]);
char[char] map;
foreach (i; 0 .. s.length) {
if (s[i] in map) {
if (t[i] != map[s[i]]) {
writeln("No");
return;
}
} else {
map[s[i]] = t[i];
}
}
char[char] map2;
foreach (i; 0 .. t.length) {
if (t[i] in map2) {
if (s[i] != map2[t[i]]) {
writeln("No");
return;
}
} else {
map2[t[i]] = s[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 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 A, B, C;
scan(A, B);
long a, b;
scan(a, b);
writeln((A * B) - (a * B) - (A * b) + (a * b));
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto ss = readln.chomp;
while (ss) {
ss = ss[0..$-2];
auto l = ss.length;
if (ss[0..l/2] == ss[l/2..$]) {
writeln(l);
return;
}
}
} | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;
void main() {
auto S = readln.chomp;
auto T = readln.chomp;
auto N = S.length.to!int;
auto M = T.length.to!int;
auto A = readln.split.map!(to!int).array;
auto B = new int[](N);
foreach (i; 0..N) {
B[A[i]-1] = i;
}
int hi = N;
int lo = M - 1;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
int cnt = 0;
int del = N - mid;
foreach (i; 0..N) {
if (B[i] < del)
continue;
if (S[i] == T[cnt])
cnt += 1;
if (cnt >= M)
break;
}
if (cnt >= M)
hi = mid;
else
lo = mid;
}
(N-hi).writeln;
}
| D |
void main()
{
int[] tmp = readln.split.to!(int[]);
int m1 = tmp[0], d1 = tmp[1];
tmp = readln.split.to!(int[]);
int m2 = tmp[0], d2 = tmp[1];
writeln(m1 != m2 && d1 > d2 ? 1 : 0);
}
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.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
void main() {
auto S = readln.chomp;
writeln(S == "Sunny" ? "Cloudy" : S == "Cloudy" ? "Rainy" : "Sunny");
}
| D |
import std;
void main() {
int n; scan(n);
int m = n % 10;
if (m == 3) writeln("bon");
else if ([0, 1, 6, 8].canFind(m)) writeln("pon");
else writeln("hon");
}
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 |
// 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 K = lread();
auto S = sread();
if (S.length <= K)
{
writeln(S);
return;
}
writeln(S[0 .. K], "...");
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto T = readln.chomp.to!int;
foreach (_t; 0..T) {
auto nn = readln.split.to!(int[]);
auto N = nn[0];
auto A = nn[1];
auto B = nn[2];
auto C = nn[3];
auto D = nn[4];
if ((A-B)*N > (C+D) || (A+B)*N < (C-D)) {
writeln("No");
} else {
writeln("Yes");
}
}
} | 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*i<n;++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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
long A, B, C;
scan(A, B, C);
if (B < A)
swap(A, B);
bool b = A < C && C < B;
writeln(b ? "Yes" : "No");
}
| 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 N = readln.chomp.to!int;
int[] as;
int[3] ns;
foreach (c; readln.chomp) {
auto a = c - '1';
++ns[a];
as ~= a;
}
foreach (ref a; as) {
if (ns[1] == 0) {
a /= 2;
} else if (a == 2) {
a = 0;
}
}
// Lucas' theorem
auto ls = new bool[](N);
ls[0] = true;
loop: foreach (x; 1..N) {
static foreach (i; 0..20) if (((N-1)&(1<<i)) < (x&(1<<i))) continue loop;
ls[x] = true;
}
int x;
foreach (i, a; as) if (ls[i]) x ^= a;
writeln(x == 1 ? ns[1] > 0 ? 1 : 2 : 0);
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto ab = readln.split.to!(int[]);
writeln((ab[0]&1) == 1 && (ab[1]&1) == 1 ? "Odd" : "Even");
} | 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 O = RD!string;
auto E = RD!string;
string ans;
foreach (i; 0..E.length)
{
ans ~= [O[i]] ~ [E[i]];
}
if (O.length > E.length)
ans ~= O[$-1];
writeln(ans);
stdout.flush();
debug readln();
} | D |
import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
auto solve(string s_){
immutable K = s_.chomp.to!int();
if(K<13) return K.to!string();
string a;
void add(int i){ a~=(i+'0').to!char(); }
immutable M=18;
auto dp = new int[10][M];
dp[1][]=1;
auto t=9;
foreach(i;2..M) foreach(j;0..10){
auto n=dp[i-1][j];
if(j>0) n+=dp[i-1][j-1];
if(j<9) n+=dp[i-1][j+1];
dp[i][j]=n;
if(j==0) continue;
if(t+n<K){
t+=n;
continue;
}
a.reserve(i);
add(j);
auto p=j;
foreach_reverse(m;1..i){
foreach(k;max(0,p-1)..min(10,p+2)){
if(t+dp[m][k]>=K){
add(k);
p=k;
break;
}
t+=dp[m][k];
}
}
return a;
}
return a;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); } | 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.stdlib;
void main() {
auto N = readln.chomp.to!int;
auto S = readln.chomp;
auto R = new int[](N+1);
auto G = new int[](N+1);
auto B = new int[](N+1);
foreach (i; 0..N) R[i+1] += R[i] + (S[i]=='R');
foreach (i; 0..N) G[i+1] += G[i] + (S[i]=='G');
foreach (i; 0..N) B[i+1] += B[i] + (S[i]=='B');
long ans = 0;
foreach (i; 0..N) foreach (k; i+2..N) if (S[i] != S[k]) {
int par = (k - i + 1) % 2;
int mid = (k + i) / 2;
if ((S[i] == 'R' && S[k] == 'G') || (S[i] == 'G' && S[k] == 'R')) {
ans += B[k+1] - B[i];
if (par) ans -= S[mid] == 'B';
} else if ((S[i] == 'R' && S[k] == 'B') || (S[i] == 'B' && S[k] == 'R')) {
ans += G[k+1] - G[i];
if (par) ans -= S[mid] == 'G';
} else if ((S[i] == 'B' && S[k] == 'G') || (S[i] == 'G' && S[k] == 'B')) {
ans += R[k+1] - R[i];
if (par) ans -= S[mid] == 'R';
}
}
ans.writeln;
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
writeln(min(lread(), lread()) + min(lread(), lread()));
}
| D |
import std.stdio, std.string, std.conv, std.algorithm, std.range, std.array, std.typecons;
void main() {
auto s = readln.strip;
if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
writeln("Bad");
} else {
writeln("Good");
}
}
| D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void main()
{
auto N = RD;
auto S = RD!string;
long ans;
foreach (i; 0..N-2)
{
if (S[i..i+3] == "ABC")
++ans;
}
writeln(ans);
stdout.flush;
debug readln;
}
| D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
int n = readint;
bool[int] m;
for (int i = 0; i < n; i++) {
int x = readint;
if (x in m) {
m[x] = !m[x];
}
else {
m[x] = true;
}
}
int ans = 0;
foreach (k, v; m) {
if (v)
ans++;
}
writeln(ans);
}
| D |
import std.stdio;
import std.conv;
import std.string;
const int DATA = 200;
int main() {
int[] digit = new int[DATA];
int i;
for(i=0; i<DATA; i++) {
string[] data = chomp(readln).split(" ");
if(stdin.eof()) break;
int val = to!(int)(data[0]) + to!(int)(data[1]);
int dig = 1;
while((val/=10) != 0) dig++;
digit[i] = dig;
}
for(int j=0; j<i; j++) writeln(digit[j]);
return 0;
} | D |
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
int N = readln.chomp.to!int;
char[] S = readln.chomp.dup;
foreach(ref c; S) {
c = ((c - 'A' + N) % 26) + 'A';
}
S.writeln;
}
| 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, N;
scan(H, N);
auto A = new long[](N);
auto B = new long[](N);
foreach (i; 0 .. N)
scan(A[i], B[i]);
auto dp = new long[](10 ^^ 4 * 2);
foreach (i; 1 .. dp.length)
dp[i] = long.max;
long ans = long.max;
foreach (i; 0 .. H)
foreach (j; 0 .. N)
if (dp[i] != long.max)
{
long damage = i + A[j];
dp[damage] = min(dp[i] + B[j], dp[damage]);
if (H <= damage)
{
ans = min(ans, dp[damage]);
}
}
writeln(ans);
}
| 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;
scan(N);
auto a = new int[](N);
auto b = new int[](N);
auto c = new int[](N);
foreach (i ; 0 .. N) {
scan(a[i], b[i], c[i]);
}
auto dp = new int[][](N, 3);
dp[0][0] = a[0];
dp[0][1] = b[0];
dp[0][2] = c[0];
foreach (i ; 1 .. N) {
foreach (j ; 0 .. 3) {
if (j == 0) {
chmax(dp[i][j], max(dp[i - 1][1], dp[i - 1][2]) + a[i]);
}
else if (j == 1) {
chmax(dp[i][j], max(dp[i - 1][0], dp[i - 1][2]) + b[i]);
}
else {
chmax(dp[i][j], max(dp[i - 1][0], dp[i - 1][1]) + c[i]);
}
}
}
auto ans = max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]);
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 |
// Vicfred
// https://atcoder.jp/contests/abc162/tasks/abc162_f
// dynamic programming, cumulative sum
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main() {
long n = readln.chomp.to!long;
long[] b = readln.split.map!(to!long).array;
long[] a;
a ~= 0;
a ~= b;
long[] cumulative = new long[n+1];
long[] dp = new long[n+1];
cumulative[1] = a[1];
for(long i = 3; i <= n; i++)
cumulative[i] = cumulative[i-2]+a[i];
for(long i = 2; i <= n; i++) {
if(i%2 == 1)
dp[i] = max(dp[i-1], dp[i-2]+a[i]);
else {
dp[i] = max(cumulative[i-1], dp[i-2]+a[i]);
}
}
dp[n].writeln;
}
| D |
import std.stdio;
import std.algorithm;
import core.stdc.stdio;
import core.memory;
void main(){
while(true){
GC.collect;
int[][4][23] nextTown;
int[4] beTown;
beTown[] = -1;
int[10][10] mapData;
int[] dx = [0,-1,0,1];
int[] dy = [-1,0,1,0];
int w,h;
scanf("%d%d",&w,&h);
if(w==0&&h==0)
break;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
scanf("%d",&mapData[i][j]);
}
}
int tc=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(mapData[i][j] == 0){
mapData[i][j] = 255;
}else if(mapData[i][j] == 1){
mapData[i][j] = tc++;
}else{
mapData[i][j] = 114;
}
}
}
bool[] sl = new bool[tc];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(mapData[i][j] < 23){
for(int k=0;k<4;k++){
int ny=i+dy[k],nx=j+dx[k];
while(0<=nx&&nx<w&&0<=ny&&ny<h){
if(mapData[ny][nx] < 23)
nextTown[mapData[i][j]][k] ~= mapData[ny][nx];
ny += dy[k];
nx += dx[k];
}
}
}
if(mapData[i][j] == 114){
for(int k=0;k<4;k++){
int ny=i+dy[k],nx=j+dx[k];
while(0<=nx&&nx<w&&0<=ny&&ny<h){
if(mapData[ny][nx] < 23){
if(beTown[k] == -1)
beTown[k] = mapData[ny][nx];
sl[mapData[ny][nx]]=true;
}
ny += dy[k];
nx += dx[k];
}
}
}
}
}
int[int] now;
for(int k=0;k<4;k++){
if(beTown[k] >= 0){
now[(beTown[k]<<tc)|(1<<beTown[k])] = 1;
}
}
for(int _=1;_<tc;_++){
int[int] next;
foreach(int state,int num;now){
for(int k=0;k<4;k++){
foreach(s;nextTown[state>>tc][k]){
if((state&(1<<s))==0){
int idx = (s<<tc)|(1<<s)|(state&((1<<tc)-1));
int* np = idx in next;
if(np == null)
next[idx] = num;
else
(*np)+=num;
break;
}
}
}
}
swap(now,next);
}
int ans=0;
foreach(int state,int num;now){
if(sl[state>>tc]){
ans += num;
}
}
printf("%d\n",ans);
}
} | D |
import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import std.bigint;
bool is_prime(long x) {
if (x <= 1 || x % 2 == 0) return false;
long i = 3;
while (i*i <= x) {
if (x % i == 0)
return false;
i += 2;
}
return true;
}
void main() {
auto N = readln.chomp.to!long;
if (N == 2) writeln(1);
else if (N == 3) writeln(1);
else if (N == 5) writeln(1);
else if (N % 2 == 0) writeln(2);
else if (is_prime(N)) writeln(1);
else if (is_prime(N-2)) writeln(2);
else writeln(3);
}
| D |
void main() {
rs.count!(i => i == '2').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.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
string s = readln.chomp;
int w;
scan(w);
foreach (i ; 0 .. (s.length.to!int + w - 1) / w ) {
write(s[i*w]);
}
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 std.stdio, std.ascii;
void main() {
auto d = readln.dup;
foreach (c; d) {
if (c.isLower) c.toUpper.write;
else c.toLower.write;
}
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long N = lread();
long D, X;
scan(D, X);
long sum;
foreach (_; 0 .. N)
{
long A = lread();
sum += (D + (A - 1)) / A;
}
writeln(X + sum);
}
| 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()
{
char r, g, b;
scan(r, g, b);
string s = [r, g, b];
writeln((s.to!long % 4 == 0) ? "YES" : "NO");
}
| D |
void main()
{
long x = rdElem;
long now = 100;
long year;
while (now < x)
{
now += now / 100;
++year;
}
year.writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop; | D |
import std.stdio;
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;
void main() {
writeln("ABC", readln.chomp);
}
// ----------------------------------------------
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.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
int hi = N;
int lo = 1;
foreach (i; 0..M) {
s = readln.split.map!(to!int);
lo = max(lo, s[0]);
hi = min(hi, s[1]);
}
if (lo > hi) {
writeln(0);
} else {
writeln(hi - lo + 1);
}
}
| D |
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;
// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
{
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType))
{
str ~= s.to!(char[]).strip.split;
}
}
//Digit count---{{{
int DigitNum(int num) {
int digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
//}}}
//}}}
void main() {
Scanner sc = new Scanner;
string S;
sc.scan(S);
int cntC;
int pos;
if (S.front != 'A') {
writeln("WA");
return;
}
foreach (i; 2 .. S.length - 1) {
if (S[i] == 'C') {
cntC++;
pos = to!int(i);
}
}
if (cntC != 1) {
writeln("WA");
return;
}
foreach (i; 0 .. S.length) {
if (i != 0 && i != pos) {
if ('A' <= S[i] && S[i] <= 'Z') {
writeln("WA");
return;
}
}
}
writeln("AC");
}
| 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-1;
auto B = RD;
auto C = RD;
auto D = RD;
auto cnt1 = B / C;
auto cnt2 = B / D;
auto cnt3 = B / lcm(C, D);
auto cnt4 = A / C;
auto cnt5 = A / D;
auto cnt6 = A / lcm(C, D);
auto ans = B - (cnt1 + cnt2) + cnt3;
ans -= A - (cnt4 + cnt5) + cnt6;
writeln(ans);
stdout.flush();
debug readln();
} | D |
#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
void main()
{
for(string S; (S=readln().chomp()).length; )
{
auto nm = S.split().map!(to!int)();
auto n=nm[0], m=nm[1];
auto d = new int[][](n,n);
foreach(i;0..m)
{
auto abc = readln().split().map!(to!int)();
d[abc[0]-1][abc[1]-1]=abc[2];
}
foreach(k;0..n)
foreach(i;0..n)
foreach(j;0..n)
{
auto c = min(d[i][k],d[k][j]);
d[i][j] += c;
d[i][k] -= c;
d[k][j] -= c;
}
auto t = 0;
foreach(i;0..n)
foreach(j;0..n)
t += d[i][j];
writeln(t);
}
}
| D |
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
void main(){
auto a=map!(to!int)(readln.chomp.split);
if(a[0]>a[1])
writeln("a > b");
else if(a[0]<a[1])
writeln("a < b");
else
writeln("a == b");
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto a = readln[0];
switch (a) {
case 'A': .. case 'Z':
writeln("A");
return;
default:
writeln("a");
return;
}
} | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;
void main() {
writeln(readln.chomp.count!"a == 'o'" * 100 + 700);
}
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;
void main()
{
bool flg = false;
bool[char] num;
foreach(char a;readln.chomp())
if(a in num) num[a] = !num[a];
else num[a] = true;
foreach(bool a;num)
flg |= a;
writeln(flg? "No" : "Yes");
}
| 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 ps = new int[](10^^6+1);
foreach (i; 2..10^^6+1) if (ps[i] == 0) {
auto x = i;
while (x <= 10^^6) {
ps[x] = i;
x += i;
}
}
auto N = readln.chomp.to!int;
auto ns = new int[](10^^6+1);
foreach (a; readln.split.to!(int[])) {
while (a != 1) {
auto p = ps[a];
ns[p] += 1;
while (a % p == 0) a /= p;
}
}
auto pc = true;
foreach (p; ns) {
if (p == N) {
writeln("not coprime");
return;
} else if (p > 1) {
pc = false;
}
}
writeln(pc ? "pairwise coprime" : "setwise coprime");
} | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
string N = sread();
auto dp = new long[][](2, N.length + 1);
dp[0][] = long.min;
dp[1][] = long.min;
dp[0][0] = 0;
foreach (i; 0 .. N.length)
{
dp[0][i + 1] = dp[0][i + 1].max(dp[0][i] + N[i] - '0');
dp[1][i + 1] = dp[1][i + 1].max(dp[0][i] + N[i] - '0' - 1, dp[1][i] + 9);
}
writeln(max(dp[0][N.length], dp[1][N.length]));
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp, n = s.length;
writeln((n % 2 == 0) ^ (s[0] == s[$-1]) ? "Second" : "First");
}
| 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()
{
readln;
readln.chomp.split.array.reverse.join(" ").writeln;
} | 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;
// 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
long M;
long query(long[] A, long lhs, long rhs, long clhs, long crhs, long current = 1)
{
if (lhs == rhs)
return long.min;
if (rhs <= clhs || crhs <= lhs)
return long.min;
if (lhs <= clhs && crhs <= rhs)
return A[current];
long m = (lhs + rhs) / 2;
long cm = (clhs + crhs) / 2;
long l = query(A, lhs, rhs, clhs, cm, current * 2);
long r = query(A, lhs, rhs, cm, crhs, current * 2 + 1);
return max(l, r);
}
void main()
{
long N = lread();
M = 2 ^^ (cast(long) ceil(log2(N)));
auto A = new long[](2 * M);
A[] = long.min;
foreach (i; 0 .. N)
{
A[A.length - M + i] = lread();
}
foreach_reverse (d; 0 .. cast(long) ceil(log2(N)))
{
foreach (i; 0 .. 2 ^^ d)
{
long p = 2 ^^ d + i;
A[p] = max(A[p * 2], A[p * 2 + 1]);
}
}
foreach (i; 0 .. N)
{
writeln(query(A, 0, i, 0, M).max(query(A, i + 1, M, 0, M)));
}
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]), x = rd[0], a = rd[1], b = rd[2];
if (b-a <= 0)
writeln("delicious");
else if (b-a <= x)
writeln("safe");
else
writeln("dangerous");
}
| 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 N = RD;
auto S = RD!string;
long ans;
foreach (i; 1..N-1)
{
auto cnt1 = new bool[](26);
foreach (j; 0..i)
{
cnt1[S[j]-'a'] = true;
}
auto cnt2 = new bool[](26);
foreach (j; i..N)
{
cnt2[S[j]-'a'] = true;
}
long cnt;
foreach (j; 0..26)
{
if (cnt1[j] && cnt2[j])
++cnt;
}
ans = max(ans, cnt);
}
writeln(ans);
stdout.flush();
debug readln();
}
| D |
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
auto n = lread();
if (n % 2 == 0)
{
writeln((n / 2) - 1);
}
else
{
writeln((n - 1) / 2);
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
| D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long A, B, C, K;
scan(A, B, C, K);
writeln(min(A, K) - min(C, max(0, K - A - B)));
}
| 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 K = "keyence";
foreach (i; 0 .. S.length + 1)
foreach (j; i .. S.length + 1)
{
if (K == S[0 .. i] ~ S[j .. $])
{
writeln("YES");
return;
}
}
writeln("NO");
}
| D |
void main(){
int n = _scan();
string[] st = readln().chomp().split();
char[] ans;
foreach(i; 0..n){
ans ~= st[0][i];
ans ~= st[1][i];
}
ans.writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
| D |
void main()
{
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], k = tmp[1];
writeln(n - k + 1);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*
a[i]: i番目を踏むときの最善
漸化式は
a[i + 1] = min(a[i - 1] + abs(h[i + 1] - h[i - 1]), a[i] + abs(h[i + 1] - h[i]))
*/
void main(){
long n = read.to!long;
long[] hs = readln.chomp.split.map!(to!long).array;
long[] as = [0, abs(hs[1] - hs[0])];
foreach(i; 2 .. n){
as ~= min(as[i - 2] + abs(hs[i] - hs[i - 2]), as[i - 1] + abs(hs[i] - hs[i - 1]));
}
as[n - 1].writeln;
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto rdx = readln.split.to!(long[]);
auto r = rdx[0];
auto D = rdx[1];
auto x = rdx[2];
foreach (_; 0..10) {
x = r*x-D;
writeln(x);
}
} | D |
import std;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
void main()
{
long N;
scan(N);
// writeln(N);
long 今の時間 = 0;
long 今のx座標 = 0;
long 今のy座標 = 0;
long dist = 0;
bool check = true;
long time = 0;
foreach (i; 0 .. N)
{
long T, X, Y;
scan(T, X, Y);
// writeln(T, X, Y);
time = T - 今の時間; //3=6-0
// writeln("TT:", T);
// writeln("tt", t);
// writeln("time", time);
dist = abs(X - 今のx座標) + abs(Y - 今のy座標);
//writeln("dist:", dist);
if (dist > time)
{
check = false;
}
if ((time - dist) % 2 != 0)
{
check = false;
}
今のx座標 = X;
今のy座標 = Y;
今の時間 = T;
}
if (check)
{
writeln("Yes");
}
else
{
writeln("No");
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
| D |
void main() {
problem();
}
void problem() {
const N = scan!int;
const X = scan!int;
const Y = scan!int;
void solve() {
int[int] counts;
foreach(i; 1..N) {
foreach(j; i+1..N+1) {
auto liner = j - i;
auto linerIToX = X - i;
if (linerIToX < 0) linerIToX *= -1;
auto winded = j - Y;
if (winded < 0) winded *= -1;
winded += linerIToX + 1;
deb([i, j, liner, winded]);
auto distance = min(liner, winded);
counts[distance]++;
}
}
foreach(i; 1..N) {
writeln(i in counts ? counts[i] : 0);
}
}
solve();
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
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 |
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
ElementType!R x = r.front;
r.popFront();
foreach (y; r) x.amax(y);
return x;
}
auto minE(R)(R r) if (isInputRange!R) {
ElementType!R x = r.front;
r.popFront();
foreach (y; r) x.amin(y);
return x;
}
/*}}}*/
/+---test
5
10 4 8 7 3
---+/
/+---test
7
4 4 5 6 6 5 5
---+/
/+---test
4
1 2 3 4
---+/
void main(string[] args) {
readln;
const H = readln.split.map!(to!long).array;
auto dp = new long[H.length];
dp[$-1] = 0;
foreach_reverse (i; 0..H.length-1) {
if (H[i] >= H[i+1]) dp[i] = dp[i+1] + 1;
}
dp.maxE.writeln;
}
| D |
void main() {
auto S = rs;
("A" ~ S[8] ~ "C").writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
} | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n, a, b;
scan(n, a, b);
writeln(min(a*n, b));
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
| D |
void main() {
problem();
}
void problem() {
auto D = scan!int;
auto T = scan!int;
auto S = scan!int;
bool solve() {
return T * S >= D;
}
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.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);
if (a == 1) a = 14;
if (b == 1) b = 14;
writeln(a > b ? "Alice" : a < b ? "Bob" : "Draw");
}
| 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=scanElem;
auto b=scanElem;
writeln((a+b)%24);
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
for (;;) {
auto rd = readln.split.map!(to!int), n = rd[0], x = rd[1];
if (n == 0 && x == 0) break;
auto r = 0;
foreach (i; 1..n+1)
foreach (j; i+1..n+1) {
auto k = x - i - j;
if (k > j && k <= n) ++r;
}
writeln(r);
}
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto x = readln.split[1].to!long;
auto as = readln.split.to!(long[]);
auto last = as[0];
long let = 0;
foreach (a; as[1..$]) {
long d;
if (a+last > x) {
d = (a+last) - x;
let += d;
}
last = a-d < 0 ? 0 : a-d;
}
writeln(let);
} | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "begin", long, "end");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long n, m;
scan(n, m);
if(n == m)
writeln("Yes");
else
writeln("No");
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
| 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) {
auto a = r.nextA!ulong(3);
sort (a);
auto s = sum (a);
long m = (s + 1) / 2;
if (a[2] > m) {
writeln ("No");
} else {
writeln ("Yes");
}
}
}
| D |
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional;
void main()
{
auto x = readln.chomp.to!long;
if (x < 7) {
writeln(1);
} else if (x < 12) {
writeln(2);
} else {
auto ret = (x / 11) * 2;
writeln(ret + (x%11 == 0 ? 0 : x%11 > 6 ? 2 : 1));
}
} | D |
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;
int ri () {
return readln.stripRight.to!int;
}
string slow (string z, int k) {
auto s = z.dup;
for (int i = 0; i + k <= s.length; ++i) {
reverse (s[i .. i + k]);
}
return s.idup;
}
void research (int k) {
string p = "1234567890";
foreach (i; 1 .. k + 1) {
stderr.writeln (slow (p[0 .. k], i));
}
}
void reseach0 () {
research (5);
stderr.writeln;
research (6);
stderr.writeln;
research (7);
stderr.writeln;
research (9);
}
void main() {
debug reseach0 ();
const nt = ri ();
foreach (tid; 0 .. nt) {
const n = ri ();
const s = readln.stripRight;
auto z = new byte[2*n];
foreach (i; 0 .. 2*n) z[i] = s[i%n].to!byte;
int best = n - 1;
byte[] ans = z[0 .. n].dup;
reverse (ans);
auto u = new byte[n];
foreach_reverse (k; 0 .. n - 1) {
u[] = z[k .. k + n][];
/*
123456 0
234561 1
345612 2
456321 3
561234 4
654321 5
123456789 0
234567891 1
345678921 2
456789123 3
567894321 4
678912345 5
789654321 6
891234567 7
987654321 8
*/
if ((k & 1) != (n & 1)) {
reverse (u[n - k .. n]);
}
if (cmp (u, ans) <= 0) {
ans = u.dup;
best = k;
}
}
foreach (i; ans) {
write(i.to!char);
}
writeln;
writeln (best+1);
}
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto R = readln.chomp.to!int;
auto G = readln.chomp.to!int;
writeln(2 * G - R);
} | D |
import std.stdio, std.conv, std.string, std.array;
void main(){
int check,cnt=0;
auto n = readln.chomp.to!int;
for(uint i;i<n;++i){
check = 0;
auto s = readln.chomp.to!int;
for(uint x=1;x*x<s;++x){
if((s+x+1)%(x*2+1)==0){
check=1;
break;
}
}
if(check==0) cnt++;
}
cnt.writeln;
} | D |
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void main() {
readln.chomp.startsWith("YAKI").pipe!(a=>a?"Yes":"No").writeln;
}
// ----------------------------------------------
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.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
int N = readln.chomp.to!int;
string S = readln.chomp;
int ans = 0;
char prev = '0';
foreach(c; S) {
if(c != prev) ans++;
prev = c;
}
ans.writeln;
}
| D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.