code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
void main()
{
long[] tmp = readln.split.to!(long[]);
long n = tmp[0], k = tmp[1];
long[] lists = new long[10^^5+1];
foreach (i; 0 .. n)
{
tmp = readln.split.to!(long[]);
long a = tmp[0], b = tmp[1];
lists[a] += b;
}
long num = 1;
foreach (i, x; lists)
{
if (num <= k && k < num + x)
{
i.writeln;
break;
}
num += 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nab = readln.split.to!(int[]);
auto N = nab[0];
auto A = nab[1];
auto B = nab[2];
writeln(min(N*A, B));
}
|
D
|
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import std.regex;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max / 5;
void main() {
writeln(readln.chomp.to!long ^ 1);
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach (i; 0 .. n)
fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach (ref e; res)
e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (y > 0 && t * y < x)
t++;
if (y < 0 && t * y > x)
t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (y > 0 && t * y > x)
t--;
if (y < 0 && t * y < x)
t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach (i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
template scanln(Args...) {
enum sep = " ";
enum n = () {
long n = 0;
foreach (Arg; Args) {
static if (is(Arg == class) || is(Arg == struct) || is(Arg == union)) {
n += Fields!Arg.length;
} else {
n++;
}
}
return n;
}();
enum fmt = n.rep!(() => "%s").join(sep);
enum argsString = () {
string[] xs = [];
foreach (i, Arg; Args) {
static if (is(Arg == class) || is(Arg == struct) || is(Arg == union)) {
foreach (T; FieldNameTuple!Arg) {
xs ~= "&args[%d].%s".format(i, T);
}
} else {
xs ~= "&args[%d]".format(i);
}
}
return xs.join(", ");
}();
void scanln(auto ref Args args) {
string line = readln.chomp;
static if (__VERSION__ >= 2074) {
mixin(
"line.formattedRead!fmt(%s);".format(argsString)
);
} else {
mixin(
"line.formattedRead(fmt, %s);".format(argsString)
);
}
}
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x >> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x >> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x >> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x >> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x >> 16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x >> 32 & 0x00000000ffffffffL);
return x;
}
}
|
D
|
import std.conv, std.stdio;
import std.algorithm, std.array, std.string, std.range;
void main()
{
auto buf = readln.chomp.split.to!(int[]);
(buf[0].c2 + buf[1].c2).writeln;
}
auto c2(in int n)
{
return n * (n - 1) / 2;
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
int id;
int s12, s23, s31;
int l, r;
while(n--){
auto args=readln.split.to!(int[]);
auto w=args[0], as=args[1..$];
int[] p=[1, 2, 3];
foreach(a; as){
if(a==0) swap(p[0], p[1]);
else swap(p[1], p[2]);
}
auto o1=p[0], o2=p[1], o3=p[2];
if(o1==1 && o2==2 && o3==3) id++;
if(o1==2 && o2==1 && o3==3) s12++;
if(o1==1 && o2==3 && o3==2) s23++;
if(o1==3 && o2==2 && o3==1) s31++;
if(o1==2 && o2==3 && o3==1) l++;
if(o1==3 && o2==1 && o3==2) r++;
}
if(id){
writeln("yes");
}else if(s12>=2 || s23>=2 || s31>=2){
writeln("yes");
}else if(l>=3 || r>=3){
writeln("yes");
}else if(l>=1 && r>=1){
writeln("yes");
}else if((l>=1 || r>=1) && s12>=1 && s23>=1){
writeln("yes");
}else if((l>=1 || r>=1) && s23>=1 && s31>=1){
writeln("yes");
}else if((l>=1 || r>=1) && s31>=1 && s12>=1){
writeln("yes");
}else{
writeln("no");
}
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import 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);
string s; readV(s);
foreach (i, c; s) {
if (i == a) {
if (c != '-') {
writeln("No");
return;
}
} else {
if (c < '0' || c > '9') {
writeln("No");
return;
}
}
}
writeln("Yes");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto HS = readln.split.to!(int[]);
int[] cs = [HS[0]-1, HS[0]];
foreach (h; HS[1..$]) {
if (cs.length == 1) {
auto c = cs[0];
if (h > c) {
cs = [h-1, h];
} else if (c == h) {
cs = [h];
} else {
writeln("No");
return;
}
} else {
if (h >= cs[1]) {
cs = [h-1, h];
} else if (h == cs[0]) {
cs = [h];
} else {
writeln("No");
return;
}
}
}
writeln("Yes");
}
|
D
|
import std.algorithm;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;
void main()
{
int n = to!int(readln().chomp());
if (n % 2 == 0)
{
writeln(n);
}
else
{
writeln(n * 2);
}
}
|
D
|
import std.stdio, std.conv, std.string;
void main(){
writeln(readln.chomp.to!int ^^3);
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;
void main(){
auto abc=readln.split.map!(to!int).array;
((abc[0]<=abc[2]&&abc[2]<=abc[1])?"Yes":"No").writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main()
{
string s;
while ((s=readln()).length != 0) {
int cnt = 0;
int n = to!(int)(chomp(s));
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
for (int l = 0; l < 10; l++) {
if (i + j + k + l == n) cnt++;
}
}
}
}
writeln(cnt);
}
}
|
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 cnt = new long[](S.length + 1);
foreach (i; 0 .. S.length)
if (S[i] == 'W')
cnt[i + 1]++;
foreach (i; 0 .. S.length)
cnt[i + 1] += cnt[i];
long ans;
foreach (i; 0 .. S.length)
if (S[i] == 'B')
{
ans += cnt[$ - 1] - cnt[i + 1];
}
writeln(ans);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long a, b, c;
scan(a, b, c);
foreach (i; 1 .. 10 ^^ 3)
{
if ((a * i) % b == c)
{
writeln("YES");
return;
}
}
writeln("NO");
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
import std;
void main() {
auto SW = readln.split.to!(int[]);
auto S = SW[1], W = SW[0];
writeln(W <= S ? "unsafe" : "safe");
}
|
D
|
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
void main()
{
auto input = readln.chomp.split().map!(to!long);
long n = input[0];
long k = input[1];
if (n % k == 0)
{
writeln("0");
}
else
{
writeln("1");
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto m=new int[](n), d=new int[](n);
auto v=new int[](n), s=new int[](n);
foreach(i; 0..n) rd(m[i], d[i], v[i], s[i]);
int f(int v){
return (v-1)%360+1;
}
auto days=new int[](361);
foreach(i; 0..n){
int st=(m[i]-1)*30+d[i];
int ed=st+v[i]-1;
foreach(_; 0..3){
foreach(x; 1..1500){
if(x<st){
chmax(days[f(x)], max(0, s[i]-(st-x)));
}else if(st<=x && x<=ed){
chmax(days[f(x)], s[i]);
}else{// ed<x
chmax(days[f(x)], max(0, s[i]-(x-ed)));
}
}
st+=360; ed+=360;
}
}
days[0]=100100100;
writeln(reduce!(min)(days));
}
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));
}
}
void chmax(T1, T2)(ref T1 x, T2 y){
if(x<y) x=y;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
for (;;) {
if (S.empty) break;
if (S.length >= 2 && S[0..2] == "hi") {
S = S[2..$];
} else {
writeln("No");
return;
}
}
writeln("Yes");
}
|
D
|
import std.stdio ,std.conv , std.string;
void main(){
auto input = readln();
foreach( i,c ; input ){
if(i%2==1){continue;}
write(c);
}
writeln("");
}
unittest{
}
T[] readLine( T = size_t )(){
T[] ret;
foreach( val ; readln().chomp().split() ){
ret ~= to!T(val);
}
return ret;
}
|
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);}
auto g = [0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0];
void main()
{
int x, y; readV(x, y); --x; --y;
writeln(g[x] == g[y] ? "Yes" : "No");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n, i; readV(n, i);
writeln(n-i+1);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new int[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
ans[ti] = n / 2;
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush;
debug readln;
}
|
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()
{
auto S = readln.strip;
long res;
foreach(c;S)res+=c=='+'?1:-1;
writeln(res);
}
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));
}
}
}
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
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long N = lread();
writeln(0);
stdout.flush();
long ok = 0;
long ng = N;
auto S = sread();
if (S == "Vacant")
return;
while (true)
{
long m = (ok + ng) / 2;
writeln(m);
stdout.flush();
auto s = sread();
if (s == "Vacant")
return;
if ((S != s) == (m & 1))
{
ok = m;
}
else
{
ng = m;
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.array;
import std.range;
import std.algorithm;
import std.conv;
import std.typecons;
string disp(bool result){
if(result){
return "Yay!";
}else{
return ":(";
}
}
bool solve(int a, int b){
if(a <= 8 && b <= 8){
return true;
}else{
return false;
}
}
void main(){
auto ab = readln().chomp().split().map!(to!int).array();
auto a = ab[0];
auto b = ab[1];
solve(a, b).disp().writeln();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
while (!S.empty) {
if (S.length >= 5 && S[$-5..$] == "dream") {
S = S[0..$-5];
} else if (S.length >= 7 && S[$-7..$] == "dreamer") {
S = S[0..$-7];
} else if (S.length >= 5 && S[$-5..$] == "erase") {
S = S[0..$-5];
} else if (S.length >= 6 && S[$-6..$] == "eraser") {
S = S[0..$-6];
} else {
writeln("NO");
return;
}
}
writeln("YES");
}
|
D
|
import std.array;
import std.range;
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
int bsearch(int[] a, int b) {
size_t lo=0,hi=a.length-1;
while(hi>=lo) {
size_t mi = (hi+lo)/2;
if(a[mi] > b) hi = mi - 1;
else lo = mi + 1;
}
return a[hi];
}
int[] uniq(int[] a)
{
int[] res;
foreach(v; a)
if(res.empty||res[$-1] != v) res ~= v;
return res;
}
void main()
{
while(true) {
int N,M;
scanf("%d%d", &N, &M);
if(N==0&&M==0) break;
int[] inp = new int[](N+1);
inp[0] = 0;
foreach(i; 0..N) {
scanf("%d", &inp[i+1]);
}
N++;
int[] add2 = new int[](N*N);
foreach(i; 0..N) foreach(j; 0..N)
add2[j*N + i] = inp[i] + inp[j];
add2.sort;
int[] a = uniq(add2);
int res;
foreach(v; a)
{
if(v > M) break;
res = max(res, v + bsearch(a, M-v));
}
writeln(res);
}
}
|
D
|
/+ dub.sdl:
name "B"
dependency "dunkelheit" version=">=0.9.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
int main() {
Scanner sc = new Scanner(stdin);
int n;
sc.read(n);
long[long] mp;
foreach (i; 0..n) {
long a, b;
sc.read(a, b);
mp[a] = b;
}
int m;
sc.read(m);
foreach (i; 0..m) {
long a, b;
sc.read(a, b);
if (a !in mp) mp[a] = b;
else mp[a] = max(mp[a], b);
}
writeln(mp.values.sum);
return 0;
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(Args...)(auto ref Args args) {
import std.exception;
static if (args.length != 0) {
enforce(readSingle(args[0]));
read(args[1..$]);
}
}
bool hasNext() {
return succ();
}
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
|
D
|
/+ dub.sdl:
name "B"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner, dcomp.algorithm;
int main() {
auto sc = new Scanner(stdin);
int n, m;
sc.read(n, m);
int[][] g = new int[][](n, m);
foreach (i; 0..n) {
foreach (j; 0..m) {
sc.read(g[i][j]); g[i][j]--;
}
}
int[] l = new int[n];
int[] cnt = new int[m];
n.iota.each!(x => cnt[g[x][0]]++);
bool[] used = new bool[m];
int ans = cnt.maximum;
while (true) {
foreach (i; 0..m) {
if (cnt[i] >= ans) {
used[i] = true;
}
}
foreach (i; 0..n) {
while (l[i] < m && used[g[i][l[i]]]) {
cnt[g[i][l[i]]]--;
l[i]++;
if (l[i] < m) cnt[g[i][l[i]]]++;
}
}
if (l.maximum == m) break;
ans = min(ans, cnt.maximum);
}
writeln(ans);
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);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;
import std.range.primitives;
import std.traits : isFloatingPoint, isIntegral;
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
while (r-l > 1) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
foreach (i; 0..cnt) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}
ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return minimum!pred(range, e);
}
E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}
ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return maximum!pred(range, e);
}
Rotator!Range rotator(Range)(Range r) {
return Rotator!Range(r);
}
struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
size_t cnt;
Range start, now;
this(Range r) {
cnt = 0;
start = r.save;
now = r.save;
}
this(this) {
start = start.save;
now = now.save;
}
@property bool empty() {
return now.empty;
}
@property auto front() {
assert(!now.empty);
import std.range : take, chain;
return chain(now, start.take(cnt));
}
@property Rotator!Range save() {
return this;
}
void popFront() {
cnt++;
now.popFront;
}
}
|
D
|
import std.algorithm.comparison;
import std.conv;
import std.stdio;
import std.string;
void main()
{
auto x = readln.strip.to!int;
auto result = 1;
foreach( int b; 1 .. x )
{
foreach( int p; 2 .. x )
{
auto bp = b ^^ p;
if( x < bp ) break;
result = max( result, bp );
}
}
writeln( result );
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;
void main() {
bool[] state = new bool[](3);
state[0] = true; state[1] = false; state[2] = false;
while(true) {
string line = readln.chomp;
if (stdin.eof) break;
auto data = line.split(",").map!((x) => to!(uint)(x[0] - 'A')).array;
swap(state[data[0]], state[data[1]]);
}
foreach(i, s; state) if(s) writeln(to!(char)(i + 'A'));
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip.dup;
auto n = s.length.to !(int);
string res;
foreach (i; 0..n + 1)
{
if (i < n)
{
s[i] ^= 3;
}
if (s.count ("ab") == s.count ("ba"))
{
res = s.idup;
}
if (i < n)
{
s[i] ^= 3;
}
}
writeln (res);
}
}
|
D
|
import std.stdio;
import std.string;
size_t lb(int[10][] arr, int n, int key) {
long left = -1;
long right = arr.length;
while(right - left > 1) {
long mid = left + (right - left) / 2;
if (arr[mid][n] >= key) right = mid;
else left = mid;
}
return right;
}
void main() {
int n;
scanf("%d\n", &n);
auto s = readln.chomp;
int[10][] lad = new int[10][n];
foreach(j; 0..10) {
if (j == s[0] - 48) {
++lad[0][j];
}
}
foreach(i; 1..n) {
foreach(j; 0..10) {
lad[i][j] = lad[i-1][j];
if (j == s[i] - 48) {
++lad[i][j];
}
}
}
int cnt;
foreach(i; 0..10) {
foreach(j; 0..10) {
foreach(k; 0..10) {
auto si = lb(lad, i, 1);
if (si >= n) continue;
auto sj = lb(lad, j, 1 + lad[si][j]);
if (sj >= n) continue;
auto sk = lb(lad, k, 1 + lad[sj][k]);
if (sk < n)
++cnt;
}
}
}
cnt.write;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
writeln(readln[5..7].to!int > 4 ? "TBD" : "Heisei");
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n;
scan(n);
writeln(n*(n + 1) / 2);
}
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() {
import std.stdio, std.string, std.conv, std.algorithm;
int a, b, c, d;
rd(a, b, c, d);
writeln(max(0, min(b, d) - max(a, c)));
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio;
import std.string;
import std.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.pipe!(s => writeln(s.front, s.length-2, s.back));
}
// ----------------------------------------------
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;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.array;
import std.range;
import std.regex;
void main(){
auto a=readln.chomp.to!int;
if(a<1200)writeln("ABC");
else if(a>=1200&&a<2800)writeln("ARC");
else if(a>=2800)writeln("AGC");
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
import std.math;
int main() {
string l;
l = readln().split("\n")[0];
string res = "";
foreach(char x; l) res = x ~ res;
write(res ~ "\n");
return 0;
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int t;
rd(t);
while (t--) {
long n, v, l, r;
rd(n, v, l, r);
auto num = (l - 1) / v;
num += n / v - r / v;
writeln(num);
}
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp;
foreach (i, c; s) {
if (i >= 1 && s[i-1] == c) {
writeln(i, " ", i+1);
return;
}
if (i >= 2 && s[i-2] == c) {
writeln(i-1, " ", i+1);
return;
}
}
writeln("-1 -1");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
const long INF = long.max/3;
const long MOD = 10L^^9+7;
void main() {
writeln(48 - readln.chomp.to!int);
}
// ----------------------------------------------
void scanln(Args...)(ref Args args) {
foreach(i, ref v; args) {
"%d".readf(&v);
(i==args.length-1 ? "\n" : " ").readf;
}
// ("%d".repeat(args.length).join(" ") ~ "\n").readf(args);
}
void times(alias fun)(int n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
import std.stdio, std.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 s = RD!string;
long cnt1, cnt2;
foreach (c; s)
{
if (c == ')')
{
if (cnt1 > 0)
{
--cnt1;
++ans[ti];
}
}
else if (c == '(')
{
++cnt1;
}
else if (c == ']')
{
if (cnt2 > 0)
{
--cnt2;
++ans[ti];
}
}
else
{
++cnt2;
}
}
}
foreach (e; ans)
{
writeln(e);
}
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() {
auto s = readln.chomp;
writeln(s.canFind('9') ? "Yes" : "No");
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm;
char[10^^5] SS;
char conv(char who, char what, char whom)
{
switch (who) {
case 'S':
switch (what) {
case 'o':
switch (whom) {
case 'S':
return 'S';
case 'W':
return 'W';
default:
}
break;
case 'x':
switch (whom) {
case 'S':
return 'W';
case 'W':
return 'S';
default:
}
break;
default:
}
break;
case 'W':
switch (what) {
case 'o':
switch (whom) {
case 'S':
return 'W';
case 'W':
return 'S';
default:
}
break;
case 'x':
switch (whom) {
case 'S':
return 'S';
case 'W':
return 'W';
default:
}
break;
default:
}
break;
default:
}
throw new Exception("Invalid charactor. [" ~ who ~ ", " ~ what ~ ", " ~ whom ~ "]");
}
char[] solve(long n, char[] zoo)
{
zoo.length = n+1;
for (size_t i = 2; i <= n; ++i)
zoo[i] = conv(zoo[i-1], SS[i-1], zoo[i-2]);
if (zoo[0] == zoo[n] && zoo[n-1] == conv(zoo[0], SS[0], zoo[1]))
return zoo[0..n];
return null;
}
void main()
{
auto n = readln.chomp.to!long;
foreach (i, s; readln.chomp) SS[i] = s;
auto ret = solve(n, ['S', 'S']);
if (!ret) ret = solve(n, ['S', 'W']);
if (!ret) ret = solve(n, ['W', 'S']);
if (!ret) ret = solve(n, ['W', 'W']);
if (ret)
writeln(ret);
else
writeln("-1");
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
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((lread() + lread()) * lread() / 2);
}
|
D
|
void main(){
import std.stdio, std.conv, std.string, std.algorithm;
long n, a, b, k; rd(n, a, b, k);
const long mod=998244353;
const int M=1_000_00*4;
static fact=new long[](M);
static inv_fact=new long[](M);
{ // init
fact[0]=fact[1]=1;
foreach(i; 2..M) fact[i]=i*fact[i-1]%mod;
long powmod(long a, long x){
if(x==0) return 1;
else if(x==1) return a;
else if(x&1) return a*powmod(a, x-1)%mod;
else return powmod(a*a%mod, x/2);
}
foreach(i; 0..M) inv_fact[i]=powmod(fact[i], mod-2);
}
long comb(long nn, long rr){
if(nn<rr) return 0;
long ret=fact[nn]%mod;
(ret*=inv_fact[rr])%=mod;
(ret*=inv_fact[nn-rr])%=mod;
return ret;
}
long tot=0;
for(long x=0; x<=n; x++)if(k-a*x>=0){
if((k-a*x)%b==0){
long y=(k-a*x)/b;
if(y>n) continue;
(tot+=comb(n, x)*comb(n, y)%mod)%=mod;
}
}
writeln(tot);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
|
D
|
import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm;
import std.bigint;
const char[] c = ['I', 'V', 'X', 'L', 'C', 'D', 'M'];
const int[] a = [1, 5, 10, 50, 100, 500, 1000];
void main()
{
while (true){
string s = readln().chomp();
if (s == "") break;
int sum, l;
for (int i = 0; i < s.length; i++){
for (int j = 0; j < 7; j++){
if (s[i] == c[j]){
if (l >= a[j]){
sum += a[j];
} else {
sum += a[j] - l * 2;
}
l = a[j];
}
}
}
writeln(sum);
}
}
|
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.to!int.recurrence!"a[n-1]&(a[n-1]-1)".until!"a==0".array.back.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
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
auto s=readln.chomp.to!(char[]);
writeln(s[0..($-8)]);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.format;
void main()
{
string s = chomp(readln());
int a = to!int(s.split(" ")[0]);
int b = to!int(s.split(" ")[1]);
int c = to!int(s.split(" ")[2]);
if ( a < b && b < c ) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], m = tmp[1];
writeln((n - 1) * (m - 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;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;
void main(){
string[8] map;
for(int i=0;i<8;i++) map[i] = readln().chomp();
writeln(90);
for(int j=0;j<8;j++){
for(int k=0;k<8;k++){
write(map[7-k][j]);
}
writeln();
}
writeln(180);
for(int j=0;j<8;j++){
for(int k=0;k<8;k++){
write(map[7-j][7-k]);
}
writeln();
}
writeln(270);
for(int j=0;j<8;j++){
for(int k=0;k<8;k++){
write(map[k][7-j]);
}
writeln();
}
}
|
D
|
import std.stdio, std.string, std.conv;
void main() {
string s = readln.chomp;
long mod = 1_000_000_007;
long[][] dp = new long[][](100001, 13);
dp[0][0] = 1;
foreach (i, x; s) {
if (x == '?') {
foreach (j; 0 .. 13) {
foreach (k; 0 .. 10) {
dp[i+1][(10*j+k)%13] = (dp[i+1][(j*10+k)%13] + dp[i][j]) % mod;
}
}
} else {
foreach (j; 0 .. 13) {
dp[i+1][(10*j+(x-'0'))%13] = (dp[i+1][(10*j+(x-'0'))%13] + dp[i][j]) % mod;
}
}
}
dp[s.length][5].writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.array;
import std.math;
void main(){
auto n=readln.chomp.to!int;
auto a=readln.chomp.to!int;
if(n%500<=a)writeln("Yes");
else writeln("No");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
int parse(string s)
{
int r;
if (s[0] == '0') {
r += s[1] - '0';
} else {
r += s[0..2].to!int;
}
r *= 60;
if (s[3] == '0') {
r += s[4] - '0';
} else {
r += s[3..5].to!int;
}
r *= 60;
if (s[6] == '0') {
r += s[7] - '0';
} else {
r += s[6..8].to!int;
}
return r;
}
void main()
{
for (;;) {
auto N = readln.chomp.to!int;
if (N == 0) return;
auto tt = new int[](60*60*24);
foreach (_; 0..N) {
auto t = readln.split;
++tt[parse(t[0])];
--tt[parse(t[1])];
}
int max_t = tt[0];
foreach (i; 1..tt.length) {
tt[i] += tt[i-1];
max_t = max(max_t, tt[i]);
}
writeln(max_t);
}
}
|
D
|
void main()
{
string s = rdStr;
s = s[0..$-2];
long len = s.length >> 1;
while (s[0..len] != s[len..$])
{
s = s[0..$-2];
--len;
}
s.length.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
|
//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 res = 0;
foreach (i; 0 .. s.length) {
int tmp;
foreach (j; i .. s.length) {
if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T')
tmp++;
else
break;
}
if (res < tmp)
res = tmp;
}
writeln(res);
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
N %= 10;
writeln(N == 3 ? "bon" : (N.among(2, 4, 5, 7, 9) ? "hon" : "pon"));
}
|
D
|
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
//END OF TEMPLATE
void main(){
auto k=scan!size_t;
auto s=scan!string;
(s.length<=k?s:s[0..k]~"...").writeln;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math; // math functions
void main()
{
auto rd = readln.split.to!(long[]), x = rd[0], y = rd[1];
writeln((x-y).abs <= 1 ? "Brown" : "Alice");
}
|
D
|
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to
void main()
{
string n = chomp(readln());
int a = to!int(n);
if(a%10 == a/100){
writeln("Yes");
} else {
writeln("No");
}
}
|
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];
if((A<C&&C<B)||(B<C&&C<A)){
writeln("Yes");
}else{
writeln("No");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
T[][] comb(T)(in T[] arr, in int k) pure nothrow {
if (k == 0) return [[]];
typeof(return) result;
foreach (immutable i, immutable x; arr)
foreach (suffix; arr[i + 1 .. $].comb(k - 1))
result ~= x ~ suffix;
return result;
}
int N;
string[10^^5] SS;
void main()
{
N = readln.chomp.to!int;
foreach (i; 0..N) SS[i] = readln.chomp;
long[5] march;
foreach (s; SS[0..N]) {
switch (s[0]) {
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:
}
}
auto cb = [0, 1, 2, 3, 4].comb(3);
long ret;
foreach (c; cb) ret += march[c[0]] * march[c[1]] * march[c[2]];
writeln(ret);
}
|
D
|
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv;
void main() {
auto a = map!(x => x.to!int)(readln.chomp.split);
if (a[0] + a[1] == a[2] + a[3]) {
writeln("Balanced");
} else if (a[0] + a[1] < a[2] + a[3]) {
writeln("Right");
} else {
writeln("Left");
}
}
|
D
|
import std.stdio, std.conv, std.array,std.string,std.algorithm;
void main()
{
auto n=readln.chomp.to!int,a=readln.split;
int ma=a[0].to!int,mi=a[0].to!int;
for(int i;i<n;i++){
ma=max(ma,a[i].to!int);
mi=min(mi,a[i].to!int);
}
writeln(ma-mi);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto o = readln.chomp, no = o.length;
auto e = readln.chomp, ne = e.length;
auto r = new char[](no+ne);
foreach (i, c; o) r[i*2] = c;
foreach (i, c; e) r[i*2+1] = c;
writeln(r);
}
|
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, core.bitop;
void main()
{
auto S = scanString;
foreach(i;0..3)
{
if(S[i]==S[i+1]){
writeln("Bad");
return;
}
}
writeln("Good");
return;
}
struct Vec2{
long x,y;
alias a=x, b=y;
}
struct Vec3{
long x,y,z;
alias a=x, b=y, c=z;
}
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;
}
}
string scanString()
{
return scanElem!string;
}
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[] divisors(long n)
{
long[] list;
void func(Factor[] fs, long n)
{
if(fs.empty){
list ~= n;
return;
}
foreach(c; 0..fs[0].c+1)
{
func(fs[1..$], n * (fs[0].n ^^ c));
}
}
func(factors(n), 1);
sort(list);
return list;
}
//nまでの素数のリスト
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.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
bool isReachable(string s, int fm, int to) {
assert(s[fm] == '.' && s[to] == '.');
int p = fm;
while (p < to) {
if (p + 2 <= to && s[p + 2] == '.') p += 2;
else if (s[p + 1] == '.') p++;
else return false;
}
return true;
}
bool findJumpPoint(string s, int lo, int hi) {
int n = cast(int)s.length;
for (int i = lo; i <= hi; i++) {
if (i + 2 >= n) break;
if (s[i..i+3] == "...") return true;
}
return false;
}
bool calc(string s, int a, int b, int c, int d) {
int n = cast(int)s.length;
bool reachOk = isReachable(s, a, c) && isReachable(s, b, d);
// a, b の移動は独立している
if (c < d) return reachOk;
// a は b を追い越す必要がある
return reachOk && findJumpPoint(s, b-1, d-1);
}
void main() {
int n, a, b, c, d; scan(n, a, b, c, d);
string s = read!string;
writeln(calc(s, a-1, b-1, c-1, d-1) ? "Yes" : "No");
}
|
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);}}
enum MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long H1, M1, H2, M2, K;
scan(H1, M1, H2, M2, K);
long L1 = H1 * 60 + M1;
long L2 = H2 * 60 + M2;
// dprint(H1, M1, H2, M2, K, L1, L2);
writeln(max(0, L2 - L1 - K));
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main() {
int s = readln.chomp.to!int;
writeln(s / 3600, ":", s / 60 % 60, ":", s % 60);
}
|
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.typecons;
final class InputReader {
private:
ubyte[] p, buffer;
bool eof;
bool rawRead () {
if (eof) {
return false;
}
p = stdin.rawRead (buffer);
if (p.empty) {
eof = true;
return false;
}
return true;
}
ubyte nextByte(bool check) () {
static if (check) {
if (p.empty) {
if (!rawRead ()) {
return 0;
}
}
}
auto r = p.front;
p.popFront ();
return r;
}
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
}
bool seekByte (in ubyte lo) {
while (true) {
p = p.find! (c => c >= lo);
if (!p.empty) {
return false;
}
if (!rawRead ()) {
return true;
}
}
}
template next(T) if (isSigned!T) {
T next () {
if (seekByte (45)) {
return 0;
}
T res;
ubyte b = nextByte!false ();
if (b == 45) {
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
T next () {
if (seekByte (48)) {
return 0;
}
T res = nextByte!false () - 48;
while (true) {
ubyte b = nextByte!true ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
T[] nextA(T) (in int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
//Kadane's algorithm
long maximumSubArraySum(R) (R range) if (isInputRange!R && isIntegral!(ElementType!R)) {
alias T = ElementType!R;
alias S = Tuple! (long, "best", long, "cur");
S next (in S s, in T x) {
S t;
t.cur = s.cur + x;
t.best = max (s.best, t.cur);
if (t.cur < 0) t.cur = 0;
return t;
}
return reduce!next (tuple!("best", "cur") (long.min, 0L), range).best;
}
bool test (in long[] a) {
long y = sum (a);
long best = y;
long cur = 0;
int l = 0;
foreach (x; a) {
cur += x;
++l;
if (best <= cur && l < a.length) {
return false;
}
if (cur < 0) {
cur = 0;
l = 0;
}
}
return true;
}
void main() {
auto r = new InputReader ();
immutable nt = r.next!uint ();
foreach (tid; 0 .. nt) {
immutable n = r.next!uint ();
auto a = r.nextA!(long)(n);
debug stderr.writeln (a);
auto b = a.dup;
b.reverse ();
writeln ((test (a) && test (b)) ? "YES" : "NO");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
void main()
{
foreach (line; stdin.byLine) {
string str = line.to!string.chomp;
foreach (i; 0..26) {
if (str.caesar(i).split.count!(s => s == "the" || s == "this" || s == "that") > 0) {
str = str.caesar(i);
break;
}
}
str.writeln;
}
}
string caesar(string str, int n)
{
string ret = "";
foreach (c; str) {
if (c == '.' || c == ' ') ret ~= c;
else if (c + n >= 'a' && c + n <= 'z') ret ~= c + n;
else ret ~= 'a' + c + n - 1 - 'z';
}
return ret;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
bool read(ref string str){
str=readln.chomp();
if(str==null)return false;
return true;
}
void main(){
string str;
while(read(str)){
string[] s=str.split(" ");
auto n1=s[0].to!int();
auto n2=s[1].to!int();
writeln(log10(n1+n2).to!int+1);
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias TOWN = Tuple!(long, "x", long, "y");
void main()
{
auto n = lread();
auto s = sread();
foreach(e; s)
{
auto next = (e - 'A' + n) % 26;
write(('A' + next).to!(char));
}
writeln();
}
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 product_MOD(long n)
{
long p_MOD = 1;
while (n > 0)
{
p_MOD *= n--;
p_MOD %= MOD;
}
return p_MOD;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp.to!(wchar[]);
int r = int.max;
foreach (i; 0..S.length-2) {
r = min(r, abs(753 - S[i..i+3].to!int));
}
writeln(r);
}
|
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;
long ans;
foreach (i; 0..N)
{
auto l = RD;
auto r = RD;
ans += r - l + 1;
}
writeln(ans);
stdout.flush();
debug readln();
}
|
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() {
int n, m;
scan(n, m);
long t = 100 * (n - m) + 1900 * m;
long ans = 2L^^m * t;
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
//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.functional;
final class InputReader {
private:
ubyte[] p, buffer;
bool eof;
bool rawRead () {
if (eof) {
return false;
}
p = stdin.rawRead (buffer);
if (p.empty) {
eof = true;
return false;
}
return true;
}
ubyte nextByte(bool check) () {
static if (check) {
if (p.empty) {
if (!rawRead ()) {
return 0;
}
}
}
auto r = p.front;
p.popFront ();
return r;
}
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
}
bool seekByte (in ubyte lo) {
while (true) {
p = p.find! (c => c >= lo);
if (!p.empty) {
return false;
}
if (!rawRead ()) {
return true;
}
}
}
template next(T) if (isSigned!T) {
T next () {
if (seekByte (45)) {
return 0;
}
T res;
ubyte b = nextByte!false ();
if (b == 45) {
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
T next () {
if (seekByte (48)) {
return 0;
}
T res = nextByte!false () - 48;
while (true) {
ubyte b = nextByte!true ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
T[] nextA(T) (in int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
pure
X genericPower(alias mul, X, Y) (X x, Y y, X one = 1.to!X)
if (isUnsigned!Y) {
X a = one, b = x;
while (y > 0) {
if (y & 1) {
a = binaryFun!mul (a, b);
}
b = binaryFun!mul (b, b);
y >>>= 1;
}
return a;
}
int test (uint[] a, const int m) {
sort (a);
a[] %= m;
auto d = new ulong[m];
auto x = new int[m];
foreach (f, i; a) {
if (f > 0) {
int k = i;
foreach (j; 0 .. m) {
d[k] += x[j];
if (--k < 0) k += m;
}
}
++x[i];
}
if (d[0] > 0) return 0;
debug stderr.writeln (d);
int mul (int i, int j) {
return (i * j) % m;
}
int res = 1;
foreach (k; 1 .. m) {
res = mul (res, genericPower!(mul, int, ulong)(k, d[k]));
}
return res;
}
void main() {
auto r = new InputReader ();
//immutable nt = r.next!uint ();
const n = r.next!uint ();
const m = r.next!uint ();
auto a = r.nextA!uint (n);
writeln (test (a, m));
}
|
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;
void main()
{
auto hw = readln.chomp.split.map!(to!int);
auto field = new string[](hw[0]);
foreach (i; 0..hw[0]) {
field[i] = readln.chomp;
}
int cnt;
foreach (y; 0..hw[0]-1) {
foreach (x; 0..hw[1]-1) {
bool f, a, c, e;
foreach (i; 0..2) {
foreach (j;0..2) {
if (field[y+i][x+j] == 'f') f = 1;
if (field[y+i][x+j] == 'a') a = 1;
if (field[y+i][x+j] == 'c') c = 1;
if (field[y+i][x+j] == 'e') e = 1;
}
}
if (f + a + c + e == 4) 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;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
void main() {
long[] as = readln.split.to!(long[]);
long I = as[0];
long O = as[1];
long J = as[3];
long L = as[4];
writeln(
O + max(
I*J*L==0 ? 0 : 3 + (I-1)/2*2 + (J-1)/2*2 + (L-1)/2*2,
I/2*2 + J/2*2 + L/2*2
)
);
}
// ----------------------------------------------
void scanln(Args...)(ref Args args) {
foreach(i, ref v; args) {
"%d".readf(&v);
(i==args.length-1 ? "\n" : " ").readf;
}
// ("%d".repeat(args.length).join(" ") ~ "\n").readf(args);
}
void times(alias fun)(int n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
import std.stdio, std.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 = N.iota.map!(_ => readln.chomp.to!int).array;
auto S = new int[](100001);
foreach (i; 0..100001)
S[i] = int.max;
S[0] = -1;
S[1] = A[0];
auto SS = S.assumeSorted;
int ans = 1;
foreach (i; 1..N) {
auto lb = SS.lowerBound(A[i]).length.to!int;
ans = max(ans, lb);
if (S[lb] > A[i])
S[lb] = A[i];
}
ans.writeln;
}
|
D
|
import std.stdio;
int main(string[] argv)
{
for (int i = 0; i < 1000; ++i)
writeln("Hello World");
return 0;
}
|
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;
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() {
auto rgb = readints;
int x = 100 * rgb[0] + 10 * rgb[1] + rgb[2];
writeln(x % 4 == 0 ? "YES" : "NO");
}
|
D
|
// Cheese-Cracker: cheese-cracker.github.io
void solve(){
long u = scan;
long v = scan;
long y = v * v;
long x = - (u * u);
writeln(x, " ", y);
}
void main(){
long tests = scan; // Toggle!
while(tests--) solve;
}
/************** ***** That's All Folks! ***** **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x", long, "y");
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto N = RD;
auto M = RD;
long m = -1;
if (N % 2 == 0)
m = N / 2;
long l = 1, r = N;
foreach (i; 0..M)
{
debug writeln(r-l, ":", N-(r-l) - (r-l));
if (m != -1)
{
if (m == r-l || (N-(r-l) - (r-l) == 2))
{
++l;
}
}
writeln(l, " ", r);
++l;
--r;
}
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
void main()
{
auto i = readln.chomp;
if (i[0] != 'A')
{
"WA".writeln;
return;
}
if (i[1].isUpper || i[$ - 1].isUpper)
{
"WA".writeln;
return;
}
long cntc;
foreach (c; i[2 .. $ - 1])
{
if (c == 'C')
{
cntc++;
}
if (c.isUpper && c != 'C')
{
"WA".writeln;
return;
}
}
if (cntc != 1)
{
"WA".writeln;
return;
}
"AC".writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm;
void main()
{
int b=0;
while(1){
auto a = readln.split.map!(to!int);
if(a[0]==0) break;
if(b) writeln();
int flag=0;
for(uint i=a[0];i<=a[1];++i){
if(i%4==0){
if(i%100==0){
if(i%400==0){
flag=1;
i.writeln();
}
}else{
flag=1;
i.writeln();
}
}
}
if(!flag) writeln("NA");
b=1;
}
}
|
D
|
import std.stdio, std.algorithm, std.array, std.string, std.conv;
void main()
{
int t;
scanf("%d", &t);
getchar();
foreach(_; 0..t)
{
long a,b,c;
scanf("%lld %lld %lld\n", &a, &b, &c);
writeln(max(0, max(b,c) - a + 1), ' ', max(0, max(a,c) - b + 1), ' ', max(0, max(a,b) - c + 1));
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.array;
void main(){
auto a=readln.chomp;
if(a=="oxx"||a=="xox"||a=="xxo")writeln(700+100);
else if(a=="oox"||a=="oxo"||a=="xoo")writeln(700+200);
else if(a=="ooo")writeln(700+300);
else writeln(700);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int a, b, t;
scan(a, b, t);
writeln(t / a * b);
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.stdio,std.math,std.string,std.conv,std.typecons,std.format;
import std.algorithm,std.range,std.array;
T[] readarr(T=long)(){return readln.chomp.split.to!(T[]);}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
//END OF TEMPLATE
void main(){
long n,k;
scan(n,k);
min(n%k,abs(n%k-k)).writeln;
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
auto S = sread();
writeln(max(S[0] - '0' - 1 + 9 * (S.length - 1), S.map!"a-'0'"().sum()));
}
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.conv;
enum long INF = long.max/5;
void main() {
while(solve()){}
}
bool solve() {
int n = readln.chomp.to!int;
if (n == 0) return false;
long[] as = new long[n];
foreach(i; 0..n) {
as[i] = readln.chomp.to!long;
}
kadane!(
long, max, -INF, "a+b", 0
)(as).writeln;
return true;
}
T kadane(
T, // 型
alias plusFun, // 加法の2項演算
T plusIdentity, // 加法の単位元
alias multFun, // 乗法の2項演算
T multIdentity // 乗法の単位元
)(T[] as) {
alias _plusFun = binaryFun!plusFun;
alias _multFun = binaryFun!multFun;
T res = plusIdentity;
T s = multIdentity;
foreach(a; as) {
s = _plusFun(_multFun(s, a), a);
res = _plusFun(res, s);
}
return res;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto n = readln.chomp.to!int;
auto as = readln.split.to!(int[]);
auto ss = new bool[](2000*n+1);
void solve(int i, int s) {
if (i == n) return;
solve(i+1, s);
s += as[i];
ss[s] = true;
solve(i+1, s);
}
solve(0, 0);
auto m = readln.chomp.to!int;
foreach (q; readln.split.to!(int[])) {
writeln(ss[q] ? "yes" : "no");
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void 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, m; readV(n, m);
auto s = new int[][](m);
foreach (i; 0..m) {
auto rd = rdsp;
int k; pick(rd, k);
s[i] = new int[](k);
foreach (j; 0..k) pick(rd, s[i][j]);
--s[i][];
}
int[] p; readA(m, p);
auto r = 0;
loop: foreach (i; 0..(1<<n)) {
foreach (j; 0..m) {
auto c = s[j].count!(k => ((i>>k)&1) == 1);
if (c%2 != p[j]) continue loop;
}
++r;
}
writeln(r);
}
|
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
void main()
{
long N = lread();
auto A = new long[](N);
foreach (i; 0 .. N)
A[i] = lread();
long s = cast(long) sqrt(cast(real) N);
long d = (N + s - 1) / s;
auto D = new long[](d);
D[] = long.min;
foreach (i; 0 .. N)
{
D[i / s] = D[i / s].max(A[i]);
}
// writeln(s, D);
foreach (i; 0 .. N)
{
long ans = long.min;
foreach (j, dv; D)
if (j != (i / s))
ans = ans.max(dv);
foreach (j; (i / s) * s .. min((i / s) * s + s, N))
{
if (j != i)
ans = ans.max(A[j]);
}
writeln(ans);
}
}
|
D
|
import std.string,
std.stdio,
std.conv;
void main() {
int[] xab = readln.chomp.split.to!(int[]);
int x = xab[0],
a = xab[1],
b = xab[2];
int z = b - a;
if (z <= 0) {
writeln("delicious");
} else if (0 < z && z <= x) {
writeln("safe");
} else {
writeln("dangerous");
}
}
|
D
|
void main() {
int n = readln.chomp.to!int;
writeln((n - 1) / 2);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv;
void main() {
long x, y;
auto s = map!(x => x.to!long)(readln.chomp.split);
x = s[0];
y = s[1];
long res = 0;
while (x <= y) {
x *= 2;
++res;
}
writeln(res);
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
auto nq = readints();
int n = nq[0], q = nq[1];
auto bit = new BinaryIndexTree(n);
for (int i = 0; i < q; i++) {
auto xs = readints();
switch (xs[0]) {
case 0: // add
bit.add(xs[1], xs[2]);
break;
case 1: // sum
int sum = bit.sum(xs[2]) - bit.sum(xs[1] - 1);
writeln(sum);
break;
default:
break;
}
}
}
class BinaryIndexTree {
private int[] _bit;
this(int n) {
_bit = new int[n + 1];
}
int sum(int p) {
int s = 0;
while (p > 0) {
s += _bit[p];
p -= p & -p;
}
return s;
}
void add(int p, int x) {
while (p < _bit.length) {
_bit[p] += x;
p += p & -p;
}
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.