code
stringlengths 3
1.01M
| language
stringclasses 2
values |
---|---|
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
auto sc = new Scanner(stdin);
long n, a, b;
sc.read(n, a, b);
if (a > b) {
writeln(0);
return 0;
}
if (a == b) {
writeln(1);
return 0;
}
if (n == 1) {
writeln(0);
return 0;
}
if (n == 2) {
writeln(1);
return 0;
}
writeln((b-a)*(n-2)+1);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
| D |
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const tmp = readln.split.to!(long[]);
const N = tmp[0], K = tmp[1];
const a = N/K;
const b = (K&1) ? 0 : (N+K/2)/K;
writeln(a^^3 + b^^3);
}
| 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 a = RD;
auto b = RD;
auto c = RD;
auto d = RD;
long ans = a * c;
ans.chmax(a*d);
ans.chmax(b*c);
ans.chmax(b*d);
writeln(ans);
stdout.flush;
debug readln;
}
| D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n, k; readV(n, k);
int[] a; readA(n, a);
auto b = new bool[](k+1);
foreach (i; 1..k+1)
b[i] = a.any!(ai => i-ai >= 0 && !b[i-ai]);
writeln(b[$-1] ? "First" : "Second");
}
| D |
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
iota(readln().chomp().to!int()).map!(_=>readln().chomp().replace("Hoshino","Hoshina")).array().join("\n").writeln();
} | D |
void main()
{
int[] abc = readln.split.to!(int[]);
writeln(abc.all!(x => x == abc[0]) ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
int[] maps = new int[256];
int[] mapt = new int[256];
int sn = 1, tn = 1;
bool check(char sc, char tc) {
if(maps[sc]==0) maps[sc] = sn++;
if(mapt[tc]==0) mapt[tc] = tn++;
return maps[sc]==mapt[tc];
}
bool solve() {
auto s = readln.chomp;
auto t = readln.chomp;
for(int i=0; i<s.length; i++) if(!check(s[i], t[i])) return false;
return true;
}
void main() {
if(solve()) writeln("Yes");
else writeln("No");
}
| 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 long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto r = RD!string;
auto b = RD!string;
long c1, c2;
foreach (i; 0..n)
{
if (r[i] > b[i])
++c1;
else if (r[i] < b[i])
++c2;
}
if (c1 > c2)
ans[ti] = -1;
else if (c1 < c2)
ans[ti] = 1;
}
foreach (e; ans)
{
writeln(e == -1 ? "RED" : e == 1 ? "BLUE" : "EQUAL");
}
stdout.flush;
debug readln;
} | 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; }
void main(){
long n = read.to!long;
long k = read.to!long;
if(n >= k * 2 - 1) writeln("YES");
else writeln("NO");
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto s=readln.chomp.to!(char[]);
auto vo=['a', 'e', 'i', 'o', 'u', 'y'],
used=new bool[](s.length);
while(true){
auto found=false;
foreach(i; 0..(s.length)){
if(used[i]) continue;
if(canFind(vo, s[i])==false) continue;
if(i+1<s.length){
if(used[i+1]) continue;
if(canFind(vo, s[i+1])){
s=s[0..(i+1)]~s[(i+2)..$];
found=true; break;
}
}
}
if(found==false) break;
}
writeln(s);
}
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 |
void main() {
problem();
}
void problem() {
auto X = scan!long;
const DELTA = 0.000001L;
long solve() {
long theta;
real x = sin(PI*theta/180L);
real y = cos(PI*theta/180L);
while(true) {
theta += X;
x += sin(PI*theta/180L);
y += cos(PI*theta/180L);
[x, y, PI].deb;
if (-DELTA <= x && x <= +DELTA && -DELTA <= y && y <= +DELTA) break;
}
return theta / X + 1;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.numeric, 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 File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (i; 0..t)
{
auto x = RD;
auto y = RD;
bool[long] set;
set[x] = true;
while (x < y)
{
if (x % 2 == 0)
x = x * 3 / 2;
else
--x;
if (set.get(x, false))
break;
set[x] = true;
}
ans[i] = x >= y;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush();
debug readln();
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
alias route = Tuple!(long, "From", long, "To");
long bignum = 1_000_000_007;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
auto n = lread();
auto march = new long[](5);
long ans;
foreach (_; 0 .. n)
{
auto s = sread();
auto head = s[0];
switch (head)
{
case 'M':
march[0]++;
break;
case 'A':
march[1]++;
break;
case 'R':
march[2]++;
break;
case 'C':
march[3]++;
break;
case 'H':
march[4]++;
break;
default:
break;
}
}
foreach (i; 0 .. (1 << 5))
{
long tmp = 1;
if (i.popcnt == 3)
{
foreach (j; 0 .. march.length)
{
if(i & (1 << j))
tmp *= march[j];
}
ans += tmp;
}
}
ans.writeln();
} | D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
writeln(s[0..5], " ", s[6..13], " ", s[14..19]);
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
long N = lread();
long H = lread();
long W = lread();
writeln((N - W + 1) * (N - H + 1));
}
| 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 L = scanElem+scanElem;
auto R = scanElem+scanElem;
if(L<R){
writeln("Right");
}else if(L>R){
writeln("Left");
}else{
writeln("Balanced");
}
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;
void main(){
auto q=readln.split.to!(int[]),a=q[0],b=q[1];
if(a*b%2==0)writeln("Even");
else writeln("Odd");
} | 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;
struct Katana{
long a, b;
}
void main()
{
long Q = scanElem;
bool[] prime;
prime.length = 10^^5+1;
foreach(n; primes(10^^5))
{
prime[n] = true;
}
long[] nList;
nList.length = prime.length;
foreach(i; 3..nList.length)
{
if(i%2==0){
nList[i] = nList[i-1];
continue;
}
nList[i] = nList[i-2] + ((prime[i] && prime[(i+1)/2]) ? 1 : 0);
}
foreach(i; 0..Q)
{
auto l = scanElem;
auto r = scanElem;
writeln(nList[r]-nList[l-1]);
}
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
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)()
{
char[] 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);
}
}
}
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);
}
}
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;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
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 |
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
auto input = readln.split.to!(ulong[]);
ulong L = input[0], R = input[1];
int ans = int.max;
ulong end = L + min(R - L, 2019) + 1;
foreach(i; L..(end - 1)) {
foreach(j; (i+1)..end) {
ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
}
}
ans.writeln;
}
| D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int N;
string s;
scan(N);
scan(s);
auto r = new long[](N + 1);
auto g = new long[](N + 1);
auto b = new long[](N + 1);
foreach (i ; 1 .. N + 1) {
r[i] = r[i - 1] + (s[i - 1] == 'R');
g[i] = g[i - 1] + (s[i - 1] == 'G');
b[i] = b[i - 1] + (s[i - 1] == 'B');
}
long ans;
foreach (i ; 0 .. N) {
if (s[i] == 'R') {
ans += g[i] * (b[N] - b[i + 1]);
ans += b[i] * (g[N] - g[i + 1]);
}
if (s[i] == 'G') {
ans += r[i] * (b[N] - b[i + 1]);
ans += b[i] * (r[N] - r[i + 1]);
}
if (s[i] == 'B') {
ans += r[i] * (g[N] - g[i + 1]);
ans += g[i] * (r[N] - r[i + 1]);
}
foreach (j ; 1 .. N) {
if (i - j < 0 || i + j >= N) break;
if (s[i - j] != s[i] && s[i] != s[i + j] && s[i - j] != s[i + j]) {
ans--;
}
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
auto 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);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
| D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto c = readln.chomp.to!int;
auto d = readln.chomp.to!int;
writeln(min(a,b) + min(c,d));
}
| D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
long bignum = 1_000_000_007;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
long manhattan(long x1, long y1, long x2, long y2)
{
return abs(x2 - x1) + abs(y2 - y1);
}
void main()
{
auto s = sread();
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.math, std.string, std.range, std.array, std.algorithm, std.typecons;
void main(){
int[4] m;
foreach(immutable int i; 0 .. 3) {
auto buf = readln().strip().split().map!(to!int)();
m[buf[0]-1] ++;
m[buf[1]-1] ++;
}
foreach(immutable i; m) {
if(i >= 3) {
writeln("NO");
return;
}
}
writeln("YES");
}
| D |
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
void main(){
string s = readln.chomp;
int scount;
int tcount;
foreach(c; s){
if(c == 'S') scount += 1;
else{
if(scount > 0) scount -= 1;
else tcount += 1;
}
}
int ans = tcount * 2;
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;
import std.container;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias t = Tuple!(string, "name", long, "y");
void main()
{
auto x = lread();
auto n = (x + 5 + 6 - 1) / (5 + 6);
if (5 * (n - 1) + 6 * n >= x)
{
writeln(2 * n - 1);
}
else
{
writeln(2 * n);
}
}
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;
}
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.exception;
long x, y; rd(x, y);
if(x==y) writeln(-1);
else if(x<y) writeln(x);
else writeln(x%y==0 ? -1 : x);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) write(e, " ");
writeln();
} | D |
import std.stdio;
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 f = false;
foreach (i; 1..n+1) {
auto d = (i * 1.08).to!int;
if (d == n) {
writeln(i);
return;
}
}
writeln(":(");
}
| D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void main()
{
int n; readV(n);
int[int] h;
foreach (_; 0..n) {
int a; readV(a);
h[a]++;
}
auto r = 0;
foreach (v; h.values)
if (v%2 == 1) ++r;
writeln(r);
}
| D |
import std.stdio, std.string, std.conv;
bool isPrime(int x) {
if (x < 2) return false;
if (x == 2) return true;
if (x % 2 == 0) return false;
for (int i = 3; i * i <= x; i += 2) {
if (x % i == 0) return false;
}
return true;
}
void main() {
int n = readln.chomp.to!int;
int cnt = 0;
foreach (i; 0 .. n) {
int x = readln.chomp.to!int;
if (isPrime(x)) ++cnt;
}
cnt.writeln;
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
class Process{
private:
string _name;
int _time;
public:
@property{
string name() const { return _name; }
int time() const { return _time; }
}
this(string n, int t){
_name = n;
_time = t;
}
void print(int t) {
writeln(name, " ", t);
}
void sub(int a){
_time -= a;
}
}
int main(char[][]argv)
{
string[] str = readln.split();
int n = str[0].to!int(), q = str[1].to!int(), t = 0;
Process[] p;
for(int i = 0; i < n; ++i){
str = readln.split();
p ~= new Process(str[0], str[1].to!int());
}
while(p.length != 0){
//writeln("t : ", t);
//foreach(e; p){
// writeln("p.name : ", e.name, " p.time : ", e.time);
//}
//writeln();
p[0].sub(q);
if(p[0].time <= 0){
p[0].print(p[0].time + t + q);
t += p[0].time + q;
p = p[1..$];
}
else{
t += q;
auto tmp = p[0];
p = p[1..$];
p ~= tmp;
}
}
return 0;
} | D |
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
long h = read.to!long;
long w = read.to!long;
long ans = long.max;
long p;
p = p1(h, w); if(p < ans) ans = p;
p = p2(h, w); if(p < ans) ans = p;
p = p3(h, w); if(p < ans) ans = p;
p = p4(h, w); if(p < ans) ans = p;
p = p5(h, w); if(p < ans) ans = p;
p = p6(h, w); if(p < ans) ans = p;
p = p7(h, w); if(p < ans) ans = p;
p = p8(h, w); if(p < ans) ans = p;
ans.writeln;
}
long p1(long h, long w){
long a = (h / 3) * w;
long b = (h / 3) * w;
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p2(long h, long w){
long a = h * (w / 3);
long b = h * (w / 3);
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p3(long h, long w){
long a = (h / 3) * w;
long b = (h - h / 3) * (w / 2);
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p4(long h, long w){
long a = h * (w / 3);
long b = (h / 2) * (w - w / 3);
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p5(long h, long w){
long a = ((h + 2) / 3) * w;
long b = (h - (h + 2) / 3) * (w / 2);
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p6(long h, long w){
long a = h * ((w + 2) / 3);
long b = (h / 2) * (w - (w + 2) / 3);
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p7(long h, long w){
long a = ((h + 2) / 3) * w;
long b = ((h + 2) / 3) * w;
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
long p8(long h, long w){
long a = h * ((w + 2) / 3);
long b = h * ((w + 2) / 3);
long c = h * w - a - b;
return max(a, b, c) - min(a, b, c);
}
| 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();
if (N & 1)
{
writeln(0);
return;
}
long x = 10;
long ans;
while (x <= N)
{
ans += N / x;
x *= 5;
}
writeln(ans);
}
| D |
void main() {
int n = readln.chomp.to!int;
int people;
foreach (i; 0 .. n) {
int[] tmp = readln.split.to!(int[]);
int l = tmp[0], r = tmp[1];
people += r - l + 1;
}
people.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
void main()
{
readln()[0].write;
readln()[1].write;
readln()[2].writeln;
}
| D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto s = RD!string;
long ans;
auto cnt = new long[](26);
foreach (i; 0..26)
{
auto tokens = s.split(['a'+i]);
long len;
foreach (token; tokens)
{
len = max(len, token.length);
}
cnt[i] = len;
}
char c = cast(char)('a' + MIN_POS(cnt));
while (true)
{
bool ok = true;
foreach (cc; s)
{
if (cc != c)
{
ok = false;
break;
}
}
if (ok) break;
++ans;
string ns;
auto streaks = new long[](s.length);
long streak;
foreach (i; 0..s.length-1)
{
if (s[i] == c || s[i+1] == c)
{
ns ~= c;
streaks[i] = streak;
streak = 0;
}
else
{
ns ~= s[i];
++streak;
}
}
/*if (s[$-1] == c)
{
ns ~= c;
long pos = MIN_POS!"a > b"(streaks);
long mid = max(pos-1,0);
s = ns[0..mid] ~ ns[mid+1..$];
}
else*/
{
s = ns;
}
debug writeln(s);
}
writeln(ans);
stdout.flush();
debug readln();
}
| 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.container;
import std.random;
void main() {
while (1) {
auto x = readln.chomp.split;
if (x[1] == "?") break;
if (x[1] == "+") writeln(x[0].to!int+x[2].to!int);
if (x[1] == "-") writeln(x[0].to!int-x[2].to!int);
if (x[1] == "*") writeln(x[0].to!int*x[2].to!int);
if (x[1] == "/") writeln(x[0].to!int/x[2].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;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
string s;
scan(s);
int n = s.length.to!int;
auto tp = new int[](n + 1);
tp[0] = 1;
foreach (i; 1 .. n + 1) {
tp[i] = tp[i-1] * 10 % 2019;
}
long ans;
int t;
auto cnt = new int[](2020);
cnt[0] = 1;
foreach (i; 0 .. n) {
(t += (s[n - 1 - i] - '0') * tp[i]) %= 2019;
ans += cnt[t];
cnt[t]++;
}
writeln(ans);
}
void scan(T...)(ref T args) {
auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args)
if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args)
if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
| D |
import std.stdio, std.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, m;
scan(n, m);
auto cnt = new int[](n);
cnt[] = 1;
auto canRed = new bool[](n);
canRed[0] = 1;
foreach (i ; 0 .. m) {
int xi, yi;
scan(xi, yi);
xi--, yi--;
if (canRed[xi]) {
canRed[yi] = true;
}
cnt[xi]--;
cnt[yi]++;
if (cnt[xi] == 0) {
canRed[xi] = false;
}
debug {
writefln("cnt: %(%s %)", cnt);
writefln("red: %(%b %)", canRed);
}
}
int ans = canRed.count!"a".to!int;
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;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto n = lread();
auto a = aryread();
// writeln(a);
long cnt;
foreach (i; 0 .. n)
{
if (a[a[i] - 1] == i + 1)
{
// writeln(a[a[i] - 1]);
cnt += 1;
}
}
writeln(cnt / 2);
}
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.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 times(alias fun)(int n) {
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
void main() {
readln.split.join.to!int.pipe!(
a => a%4==0 ? "YES":"NO"
).writeln;
}
// ----------------------------------------------
// 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;
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.map!(to!char).array;
auto k = readln.chomp.to!int;
foreach (i; 0..s.length-1) {
if (s[i] == 'a') continue;
if (26 - (s[i] - 'a') > k) continue;
k -= 26 - (s[i] - 'a');
s[i] = 'a';
}
s[$-1] = ('a' + (s[$-1] - 'a' + k) % 26).to!char;
s.writeln;
}
| D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
readln.chomp.count!(x=>x=='1').writeln;
}
| D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto S = RD!string;
/*long N = 2*(10^^5);
auto SS = new char[][](1);
foreach (i; 0..1)
{
SS[i] = new char[](N);
foreach (j; 0..N)
SS[i][j] = dice(0.5, 0.5) == 0 ? '.' : '#';
}
foreach (S; SS)
{ writeln(S);*/
long[] cnt = [0];
char last = S[0];
foreach (i; 0..N)
{
if (S[i] == last)
{
++cnt[$-1];
}
else
{
cnt ~= 1;
last = S[i];
}
}
debug writeln(cnt);
auto b_pos = S[0] == '#' ? 0 : 1;
auto b = new long[](cnt.length+100);
auto w = new long[](cnt.length+100);
foreach (i, e; cnt)
{
b[i+1] = b[i];
if (i % 2 == b_pos)
b[i+1] += e;
}
foreach_reverse (i, e; cnt)
{
w[i] = w[i+1];
if (i % 2 != b_pos)
w[i] += e;
}
long ans = long.max;
foreach (i; 0..cnt.length+1)
{
ans = min(ans, w[i] + b[i]);
}
writeln(ans);
stdout.flush();
//}
debug readln();
} | D |
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
readln;
readln.split.reverse.join(" ").writeln;
} | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto N = readln.chomp.to!int;
auto A = new int[][](N, N);
foreach (i; 0..N) A[i][] = -1;
foreach (i; 0..N) {
int a = readln.chomp.to!int;
foreach (j; 0..a) {
auto s = readln.split.map!(to!int);
auto x = s[0] - 1;
auto y = s[1];
A[i][x] = y;
}
}
int ans = 0;
foreach (mask; 0..1<<N) {
bool ok = true;
foreach (i; 0..N) {
if (mask & (1 << i)) {
foreach (j, a; A[i]) {
if (a == 0) {
if (mask & (1 << j)) {
ok = false;
break;
}
} else if (a == 1) {
if (!(mask & (1 << j))) {
ok = false;
break;
}
}
}
if (!ok) {
break;
}
}
}
if (ok) ans = max(ans, mask.popcnt);
}
ans.writeln;
} | D |
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;
void main(){
int c = 0;
while(true){
auto s = split(readln());
int a = to!int(s[0]);
int b = to!int(s[1]);
if(a==0&&b==0) break;
bool ifna = true;
if(c)
writeln("");
c++;
for(int i=a;i<=b;i++){
bool flg = false;
if(i%4==0){
if(i%100==0){
if(i%400==0) flg = true;
}else flg = true;
}
if(flg){
writeln(i);
ifna = false;
}
}
if(ifna) writeln("NA");
}
} | D |
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
long n, k;
scan(n, k);
writeln(k * (k - 1) ^^ (n - 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.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 w = RD!string;
auto cnt = new long[](26);
foreach (e; w)
++cnt[e-'a'];
bool ans = true;
foreach (e; cnt)
if (e % 2 != 0)
ans = false;
writeln(ans ? "Yes" : "No");
stdout.flush();
debug readln();
} | D |
import std.stdio;
import std.conv;
import std.array;
void main()
{
auto reader = readln.split;
int A = reader[0].to!int;
int B = reader[1].to!int;
int T = reader[2].to!int;
writeln(T / A * B);
}
| D |
void main()
{
long k = rdElem - 1;
long[] a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
a[k].writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop; | 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();
void dfs(long len, long m, string s)
{
if (len == N)
{
writeln(s);
return;
}
foreach (x; 0 .. m)
dfs(len + 1, m, s ~ cast(char)('a' + x));
dfs(len + 1, m + 1, s ~ cast(char)('a' + m));
}
dfs(0, 0, "");
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
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();
auto A = new long[](N);
foreach (i; 0 .. N)
{
A[i] = lread();
}
if (A[0] != 0)
{
writeln(-1);
return;
}
long ans;
foreach_reverse (i; 1 .. N)
{
long diff = A[i] - A[i - 1];
if (diff == 1)
{
ans++;
continue;
}
if (1 < diff)
{
writeln(-1);
return;
}
ans += A[i];
}
writeln(ans);
}
| D |
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
void main() {
auto nm = readln.chomp.split.map!(to!long);
long n = nm[0];
long m = nm[1];
long atom = min(n, m / 2);
m -= atom * 2;
long next = m / 4;
writeln = atom + next;
}
| 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 X = RD;
auto A = RD;
auto B = RD;
writeln(B <= A ? "delicious" : B - A <= X ? "safe" : "dangerous");
stdout.flush();
debug readln();
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long A, B, C;
scan(A, B, C);
bool b = B - A == C - B;
writeln(b?"YES":"NO");
}
| 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 a, b; readV(a, b);
auto c = new bool[][](100, 100);
foreach (i; 50..100) c[i][] = true;
foreach (i; 0..a-1) {
auto y = i/50*2, x = i%50*2;
c[y][x] = true;
}
foreach (i; 0..b-1) {
auto y = i/50*2+51, x = i%50*2;
c[y][x] = false;
}
writeln("100 100");
foreach (i; 0..100) {
foreach (j; 0..100)
write(c[i][j] ? "." : "#");
writeln;
}
}
| D |
import std;
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}
T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}
void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;}
void scan(TList...)(ref TList Args){auto line = readln.split;
foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}}
void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length);
static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}}
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);
long ans;
ans += min(K, A);
K -= min(K, A);
K -= min(K, B);
ans -= min(K, C);
writeln(ans);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;
void main() {
string input;
while ((input = readln.chomp).length != 0) {
auto line = input.map!(a => a.to!int - '0').array;
while (line.length > 1) {
for (int i = 0; i < (line.length - 1); i++) {
line[i] = line[i] + line[i+1];
}
line.popBack;
}
writeln(line.front % 10);
}
} | 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;
auto S = RD!string;
auto T = RD!string;
string ans;
foreach (i; 0..S.length)
{
ans ~= [S[i], T[i]];
}
writeln(ans);
stdout.flush;
debug readln;
} | D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
int[] h; readA(n, h);
auto dp = new int[](n);
dp[0] = 0; dp[1] = (h[1]-h[0]).abs;
foreach (i; 2..n)
dp[i] = min(dp[i-1] + (h[i]-h[i-1]).abs, dp[i-2] + (h[i]-h[i-2]).abs);
writeln(dp[$-1]);
}
| D |
void main() {
long[] tmp = readln.split.to!(long[]);
long a = tmp[0], b = tmp[1], x = tmp[2];
writeln(b / x - (a == 0 ? -1 : (a - 1) / x));
}
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.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;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto X = s[1] - 1;
auto Y = s[2] - 1;
auto D = new int[][](N, N);
foreach (i; 0..N) foreach (j; 0..N) D[i][j] = abs(i - j);
D[X][Y] = D[Y][X] = 1;
foreach (i; 0..N) foreach (j; 0..N) D[i][j] = min(D[i][j], abs(i - X) + 1 + abs(j - Y));
foreach (i; 0..N) foreach (j; 0..N) D[i][j] = min(D[i][j], abs(i - Y) + 1 + abs(j - X));
auto ans = new int[](N+1);
foreach (i; 0..N) foreach (j; i+1..N) ans[D[i][j]] += 1;
ans[1..N].each!writeln;
} | D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
max(0, scanElem-scanElem).writeln;
}
| D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long A, B, C;
scan(A, B, C);
bool b = C <= A + B;
writeln(b ? "Yes" : "No");
}
| D |
void main() {
problem();
}
void problem() {
const N = scan!long;
const K = scan!long;
long solve() {
long ans;
long[long] counts;
long minimal = 0;
long maximam = N;
foreach(i; 1..N+2) {
counts[i] = maximam - minimal + 1;
minimal += i;
maximam += (N - i);
}
foreach(n; K..N+2) {
ans = (ans + counts[n]) % MOD;
}
return ans;
}
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");
const MOD = 100_000_000_7;
// -----------------------------------------------
| D |
import std.stdio, std.string, std.conv, std.math, std.regex;
void main()
{
auto n = readln.split.to!(int[]);
if(abs(n[1] - n[0]) < abs(n[2] - n[0])){
writeln('A');
} else {
writeln('B');
}
} | D |
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;
void main()
{
auto s = readln.chomp;
bool ok = true;
foreach (i, e; s) {
if (i % 2 == 0) {
ok &= e == 'R' || e == 'U' || e == 'D';
} else {
ok &= e == 'L' || e == 'U' || e == 'D';
}
}
writeln(ok ? "Yes" : "No");
} | D |
import std;
bool calc(int k, int a, int b) {
// return a <= b / k * k;
return (a + k - 1) / k * k <= b;
}
void main() {
int k; scan(k);
int a, b; scan(a, b);
writeln(calc(k, a, b) ? "OK" : "NG");
}
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;
| D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;
import core.stdc.stdlib;
void main()
{
char[] S = readln.strip.to!(char[]);
auto a = S[0..2].to!int;
auto b = S[2..4].to!int;
;
bool isYYMM=b>0&&b<=12;
bool isMMYY=a>0&&a<=12;
if(isYYMM&&isMMYY){
writeln("AMBIGUOUS");
return;
}
if(isYYMM||isMMYY){
if(isYYMM){
writeln("YYMM");
return;
}else{
writeln("MMYY");
return;
}
}else{
writeln("NA");
return;
}
}
long gcd(long a, long b)
{
if(b == 0) return a;
return gcd(b, a % b);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
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!(T[]);
}
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));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] 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);
}
}
}
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);
}
}
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;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
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 |
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
void main() {
auto value =[6, 4, 3, 2];
foreach (i; 0..4) {
auto a = readln.split.map!(to!int);
writeln(value[a[0]-1] * a[1] * 1000);
}
} | 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 readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}
void main()
{
int h, w; readV(h, w);
string[] s; readC(h, s);
auto b = new int[][](h+2, w+2);
foreach (i; 0..h)
foreach (j; 0..w)
b[i+1][j+1] = s[i][j] == '#';
foreach (i; 1..h+1)
foreach (j; 1..w+1) {
if (!b[i][j]) continue;
auto r = b[i-1][j]+b[i+1][j]+b[i][j-1]+b[i][j+1];
if (r == 0) {
writeln("No");
return;
}
}
writeln("Yes");
}
| D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
int t, a; readV(t, a); t *= 1000; a *= 1000;
int[] h; readA(n, h);
auto d = 10^^9, p = 0;
foreach (int i, hi; h) {
auto e = (t-hi*6-a).abs;
if (e < d) {
p = i+1;
d = e;
}
}
writeln(p);
}
| 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()
{
auto r = -1;
foreach (i; 1..11) {
if (!ask(10L^^i)) {
r = i;
break;
}
}
if (r == -1) {
foreach (i; 1..11) {
if (ask(10L^^i-1)) {
writeln("! ", 10L^^(i-1));
return;
}
}
}
auto mi = 10L^^(r-1), ma = 10L^^r-1;
while (ma-mi > 1) {
auto c = (ma+mi)/2;
if (ask(c*10)) ma = c;
else mi = c;
}
writeln("! ", ask(mi*10) ? mi : ma);
}
auto ask(long n)
{
writeln("? ", n);
stdout.flush();
string s; readV(s);
return s == "Y";
}
| 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() {
string n;
scan(n);
if (n[0 .. 3].to!int % 111 == 0 || n[1 .. 4].to!int % 111 == 0) {
writeln("Yes");
}
else {
writeln("No");
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
struct Queue(T) {
private {
int N, head, tail;
T[] data;
}
this(int n) {
N = n + 1;
data = new T[](N);
}
bool empty() {
return head == tail;
}
bool full() {
return (tail + 1) % N == head;
}
T front() {
return data[head];
}
void push(T x) {
assert(!full);
data[tail++] = x;
tail %= N;
}
void pop() {
assert(!empty);
head = (head + 1) % N;
}
void clear() {
head = tail = 0;
}
} | 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 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n, m;
scan(n, m);
writeln(n == m ? "Yes" : "No");
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
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.stdio, std.range;
int N;
immutable W = 10, M = 12;
immutable dy = [-2,-2,-2,-1,-1,0,0,1,1,2,2,2], dx = [-1,0,1,-2,2,-2,2,-2,2,-1,0,1];
immutable ddy = [-1,-1,-1,0,0,0,1,1,1], ddx = [-1,0,1,-1,0,1,-1,0,1];
int[] ys, xs;
void main(){
for(;init;){
writeln(solve ? "OK" : "NA");
}
}
bool init(){
ys = []; xs = [];
int y, x;
scanf("%d%d", &y, &x);
ys ~= y; xs ~= x;
if(y == 0 && x == 0){
return false;
}
scanf("%d", &N);
foreach(_; 0..N){
scanf("%d%d", &y, &x);
ys ~= y; xs ~= x;
}
return true;
}
bool solve(){
auto dp = new bool[][](N + 1, 9);
dp[0][4] = true;
foreach(i; 0..N){
foreach(j; 0..9)if(dp[i][j]){
foreach(k; 0..M){
int ny = ys[i] + ddy[j] + dy[k], nx = xs[i] + ddx[j] + dx[k];
if(0<=ny && ny<W && 0<=nx && nx<W)foreach(l; 0..9){
if(ys[i+1] + ddy[l] == ny && xs[i+1] + ddx[l] == nx){
dp[i+1][l] = true;
}
}
}
}
}
return count(dp[N], true) > 0;
} | 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() {
string s;
scan(s);
int n = s.length.to!int;
int ans;
foreach (i ; 0 .. n / 2) {
if (s[i] != s[n - 1 - i]) ans++;
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
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;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main()
{
auto nums = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6];
int n;
scanf("%d", &n);
int len = n / 2;
while (len > 0)
{
foreach_reverse (i; 0..10)
if ((len - 1) * 2 <= n - nums[i])
{
write(i);
n -= nums[i];
break;
}
len = len - 1;
}
} | D |
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
void main(){
string s = readln.chomp;
long ans;
for(long x = 0; x < 2 ^^ (s.length - 1); x ++){
long a = 0, tmp = ("" ~ s[0]).to!long;
for(int i = 0; i < s.length - 1; i ++){
if(x & 2 ^^ i){
tmp *= 10, tmp += ("" ~ s[i + 1]).to!long;
}
else{
a += tmp, tmp = ("" ~ s[i + 1]).to!long;
}
}
if(tmp > 0) a += tmp, tmp = 0;
ans += a;
}
ans.writeln;
} | D |
import core.stdc.stdio;
import std.stdio;
void main(){
int n;
scanf("%d",&n);
char[] buf = new char[n+1];
scanf("%s",buf.ptr);
buf = buf[0..n];
bool[] used = new bool[n];
int[] op = new int[n];
bool Solve(char[] data,int c){
used[] = false;
int ic=n;
int a;
for(int i=n-1;i>=0;i--)
if(a<c&&data[i]=='O')
while(--ic>i)
if(!used[ic]&&data[ic]=='I'){
used[ic]=true;
used[i]=true;
a++;
break;
}
if(a!=c)
return false;
int os=0;
foreach(int i,u;used)
if(u&&data[i]=='O')
op[os++]=i;
int oi=-1;
foreach(int i,u;used)
if(!u&&data[i]!='O')
while(++oi<os)
if(op[oi]>i){
a--;
break;
}
return a==0;
}
int l,r=n+1;
while(r-l>1){
int m=(r+l)/2;
if(Solve(buf,m))
l=m;
else
r=m;
}
printf("%d\n",l);
} | D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
string s; rd(s);
if(s.length<4){writeln("No"); return;}
auto t="YAKI";
foreach(i; 0..t.length){
if(s[i]!=t[i]){writeln("No"); return;}
}
writeln("Yes");
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
} | D |
import std.stdio, std.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 / 2;
auto S = readln.chomp;
auto T = S[0..N];
writeln(T ~ T == S ? "Yes" : "No");
}
| 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.to!int;
int an = s;
int[int] cnt;
foreach (i; 2..1_000_001) {
cnt[an]++;
int am;
if (an % 2) {
am = 3 * an + 1;
} else {
am = an / 2;
}
if (cnt.get(am, 0)) {
writeln(i);
break;
} else {
an = am;
}
}
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main(){
auto N=readln.chomp.to!int;
auto K=readln.chomp.to!int;
auto X=readln.chomp.to!int;
auto Y=readln.chomp.to!int;
if(N>K){
writeln(X*K+(N-K)*Y);
}
else writeln(N*X);
} | D |
import std.stdio;
import std.string;
import std.conv;
void main() {
auto N =readln.chomp.to!int;
auto A =readln.chomp.to!int;
writeln(N*N-A);
} | D |
import std.stdio;
import std.array;
import std.conv;
void main()
{
while (1) {
auto input = to!(int[])(split(readln()));
int total = input[0] + input[1];
if (input[0] == -1 && input[1] == -1 && input[2] == -1) break;
if (input[0] == -1 || input[1] == -1) {
writeln("F");
} else if (total >= 80) {
writeln("A");
} else if (total >= 65) {
writeln("B");
} else if (total >= 50) {
writeln("C");
} else if (total >= 30) {
if (input[2] >= 50)
writeln("C");
else
writeln("D");
} else {
writeln("F");
}
}
} | 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() {
int n;
long x;
scan(n, x);
auto a = new long[](n + 1); // 長さ
auto b = new long[](n + 1); // Pの枚数
a[0] = b[0] = 1;
foreach (i ; 1 .. n + 1) {
a[i] = 2L*a[i-1] + 3;
b[i] = 2L*b[i-1] + 1;
}
long query(int L, long x) {
if (L == 0) {
return x == 1;
}
if (x <= 1) {
return 0;
}
else if (x < (a[L] + 1) / 2) {
return query(L-1, x - 1);
}
else if (x == (a[L] + 1) / 2) {
return b[L-1] + 1;
}
else if (x < a[L] - 1) {
return b[L-1] + 1 + query(L-1, x - (a[L] + 1) / 2);
}
else {
return 2*b[L-1] + 1;
}
}
long ans = query(n, x);
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.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto S = readln.chomp;
if (S == "RRR") {
writeln(3);
} else if (S == "SRR" || S == "RRS") {
writeln(2);
} else if (S == "SSS") {
writeln(0);
} else {
writeln(1);
}
} | D |
#!/usr/bin/rdmd
import std.stdio;
void main()
{
foreach(i ; 1..10)
foreach(j ; 1..10)
writeln(i, "x", j, "=", i*j);
} | D |
void main(){
int a, b;
char op;
scanf("%d %c %d", &a, &op,&b);
writeln(op=='+'?a+b:a-b);
}
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() {
int n = readln.chomp.to!int;
string s = readln.chomp;
int x, xmax;
foreach (c; s) {
if (c == 'I') ++x;
else --x;
xmax = max(xmax, x);
}
xmax.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio;
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!long;
long res;
foreach (i; 1..n+1) {
auto x = (i.to!long) ^^ 2;
if (x > n) break;
res = x;
}
res.writeln;
}
| D |
import std.stdio, std.string, std.conv, std.ascii, std.array;
void main()
{
foreach(_; 0 .. readln.chomp.to!int)
{
line = readln.chomp;
add.writeln;
}
}
string line;
int add()
{
int lhs = mul;
loop:
while(true)
{
switch(line[0])
{
case '+':
line.popFront;
lhs += mul;
break;
case '-':
line.popFront;
lhs -= mul;
break;
default:
break loop;
}
}
return lhs;
}
int mul()
{
int lhs = prim;
loop:
while(true)
{
switch(line[0])
{
case '*':
line.popFront;
lhs *= prim;
break;
case '/':
line.popFront;
lhs /= prim;
break;
default:
break loop;
}
}
return lhs;
}
int prim()
{
int r;
if(line[0] == '(')
{
line.popFront;
r = add;
line.popFront;
}
else if(line[0] == '-')
{
line.popFront;
r = -mul;
}
else while(line[0] != '=')
{
if(line[0].isDigit)
{
r = r * 10 + (line[0] - '0');
line.popFront;
}
else break;
}
return r;
} | D |
import std.stdio;
void main(string[] args) {
int n;
int[1440] time;
scanf("%d", &n);
for ( int i = 0; i < 1440; i++ ) {
time[ i ] = 0;
}
int h, m;
for ( int i = 0; i < n; i++ ) {
scanf("%d:%d", &h, &m);
time[h*60+m] = 1;
}
int mm=0;
int cur=0;
int cur1=0;
int t = 0;
for ( int i = 0; i < 1440; i++){
if (time[i] == 0){
cur = cur + 1;
}
else {
if (t == 0){
cur1 = cur;
cur = 0;
t = 1;
}
if (cur > mm){
mm = cur;
}
cur = 0;
}
}
if (cur+cur1 > mm){
mm = cur+cur1;
}
writeln(mm/60/10,mm/60%10,":",mm%60/10,mm%60%10);
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nmk = readln.split.to!(int[]);
auto N = nmk[0];
auto M = nmk[1];
auto K = nmk[2];
foreach (y; 0..N+1) {
foreach (x; 0..M+1) {
if (x*y + (M-x)*(N-y) == K) {
writeln("Yes");
return;
}
}
}
writeln("No");
return;
} | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto x = readln.chomp.replace(" ", "").to!int;
auto y = sqrt(x.to!double);
if ( y - y.to!int > 0) {
writeln("No");
} else {
writeln("Yes");
}
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto s = readln.chomp;
auto cnt = 0;
char last = s[0];
foreach (c; s[1..$]) {
if (c != last) {
++cnt;
last = c;
}
}
writeln(cnt);
} | 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.container;
import std.random;
void main() {
int i;
while (1) {
auto n = readln.chomp.to!int;
if (!n) break;
writeln("Case ", ++i, ": ", n);
}
} | D |
void main() {
int n = readln.chomp.to!int;
writeln(n / 1000 ? "ABD" : "ABC");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni; | D |
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
string[] ss = readln.split;
foreach (i, ref arg ; args) arg = ss[i].parse!int;
}
void main() {
string s = readln.chomp;
bool can = true;
if (s=="AAA" || s=="BBB") can = false;
writeln(can ? "Yes" : "No");
}
| D |
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- 28