code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
void main(){
int[] n = _scanln();
foreach(i; 0..n[0]+1 ){
if(n[1] == 2*i + 4*(n[0]-i)){
writeln("Yes");
return;
}
}
writeln("No");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
string s;
s = readln().chomp;
int n = s.length.to!int;
if (s[n-1] == '1') {
writeln(-1);
return;
}
if (s[0] == '0') {
writeln(-1);
return;
}
foreach (i; 0..n-1) {
if (s[i] != s[n-2-i]) {
writeln(-1);
return;
}
}
int v = 2, front = 2;
writeln(1,' ',2);
foreach (i; 1..n-1) {
v++;
writeln(front,' ',v);
if (s[i] == '1') {
front = v;
}
}
}
|
D
|
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;
import std.datetime.systime : Clock;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
p = stdin.rawRead (buffer);
}
final ubyte skipByte (ubyte lo) {
while (true) {
auto a = p[cur .. $];
auto r = a.find! (c => c >= lo);
if (!r.empty) {
cur += a.length - r.length;
return p[cur++];
}
p = stdin.rawRead (buffer);
cur = 0;
if (p.empty) return 0;
}
}
final ubyte nextByte () {
if (cur < p.length) {
return p[cur++];
}
p = stdin.rawRead (buffer);
if (p.empty) return 0;
cur = 1;
return p[0];
}
template next(T) if (isSigned!T) {
final T next () {
T res;
ubyte b = skipByte (45);
if (b == 45) {
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
final T next () {
T res = skipByte (48) - 48;
while (true) {
ubyte b = nextByte ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
final T[] nextA(T) (int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
void main() {
auto r = new InputReader;
immutable n = r.next!int;
auto a = r.nextA!int (n);
int res;
foreach (i; 1 .. n) {
auto x = a[i - 1], y = a[i];
if (x == 2 && y == 3 || x == 3 && y == 2) {
writeln ("Infinite");
return;
}
if (x == 1 && y == 2) {
res += 3;
if (i >= 2 && a[i - 2] == 3) --res;
} else if (x == 1 && y == 3) {
res += 4;
} else if (x == 2 && y == 1) {
res += 3;
} else if (x == 3 && y == 1) {
res += 4;
}
/*
else if (x == 3 && y == 2) {
res += 4;
}
*/
debug stderr.writeln (x, " ", y, " ", res);
}
writeln ("Finite");
writeln (res);
}
|
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 A = nab[1];
auto B = nab[2];
writeln(A%2 == B%2 ? "Alice" : "Borys");
}
|
D
|
import std.algorithm,
std.string,
std.array,
std.range,
std.stdio,
std.conv;
void main() {
string[] n = readln.chomp.split("");
if (n[0] == n[2]) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
void main()
{
int n, m;
readln.chomp.split.tie(n, m);
char[][] board = new char[][](n);
foreach (i; 0..n) {
board[i] = readln.chomp.dup;
}
bool yes = true;
enum OFS = [
[0, 1],
[1, 0],
[-1, 0],
[0, -1],
[1, 1],
[1, -1],
[-1, 1],
[-1, -1]
];
foreach (y; 0..n) {
foreach (x; 0..m) {
if (board[y][x] == '*') {
continue;
}
int v;
if (board[y][x] == '.') {
v = 0;
} else {
v = board[y][x] - '0';
}
int cnt = 0;
foreach (d; OFS) {
int nx = x + d[0];
int ny = y + d[1];
if (nx < 0 || m <= nx
|| ny < 0 || n <= ny) {
continue;
}
if (board[ny][nx] == '*') {
++cnt;
}
}
yes &= v == cnt;
}
}
writeln = yes ? "YES" : "NO";
}
void tie(R, Args...)(R arr, ref Args args)
if (isRandomAccessRange!R || isArray!R)
in
{
assert (arr.length == args.length);
}
body
{
foreach (i, ref v; args) {
alias T = typeof(v);
v = arr[i].to!T;
}
}
void verbose(Args...)(in Args args)
{
stderr.write("[");
foreach (i, ref v; args) {
if (i) stderr.write(", ");
stderr.write(v);
}
stderr.writeln("]");
}
|
D
|
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;
void main()
{
long A = scanElem;
long B = scanElem;
long C = scanElem;
if(A>B)swap(A,B);
if(A<C&&C<B){
writeln("Yes");
}else{
writeln("No");
}
}
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
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
long a = read.to!long;
long b = read.to!long;
long c = read.to!long;
long ans;
if(c > a + b + 1) ans = b + (a + b + 1);
else ans = b + c;
ans.writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long A, B;
scan(A, B);
bool b = (A * B) % 2 == 0;
writeln(!b ? "Odd" : "Even");
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto o = sread();
auto e = sread();
auto s = (o.length) + (e.length);
foreach (i; 0 .. s)
{
if (i % 2 == 0)
{
write(o[i / 2]);
}
else
{
write(e[i / 2]);
}
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto a = RD;
auto s = RD!string;
writeln(a >= 3200 ? s : "red");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
enum lim = 2 * 10^^5;
void main() {
auto s = eratos(lim);
auto t = new bool[](lim);
foreach (i ; 3 .. lim) {
if (s[i] && s[(i + 1) / 2]) {
t[i] = true;
}
}
auto ts = new int[](lim + 1);
foreach (i ; 1 .. lim + 1) {
ts[i] = ts[i - 1] + t[i - 1];
}
int q;
scan(q);
foreach (i ; 0 .. q) {
int li, ri;
scan(li, ri);
ri++;
int ans = ts[ri] - ts[li];
writeln(ans);
}
}
bool[] eratos(int n) {
auto s = new bool[](n);
s[] = true;
s[0] = s[1] = false;
for (int p = 2; p*p < n; p++) {
if (s[p]) {
for (int d = p*p; d < n; d += p) {
s[d] = false;
}
}
}
return s;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;
void main()
{
auto n = readln.chomp.to!int;
foreach (i; 1..n+1) {
auto x = i;
if (x % 3 == 0) {
write(" ", i);
continue;
}
while (x) {
if (x % 10 == 3) {
write(" ", i);
break;
}
x /= 10;
}
}
writeln("");
}
|
D
|
import std.stdio,std.string,std.conv,std.array;
void main(){
int[4][] data;
for(int i=0;;i++){
auto rd = readln().chomp();
if(rd){
data.length = i+1;
auto abcd = split(rd);
data[i][0] = to!int(abcd[0]);
data[i][1] = to!int(abcd[1]);
data[i][2] = to!int(abcd[2]);
data[i][3] = to!int(abcd[3]);
}else{
break;
}
}
for( int i=0;i<data.length;i+=2 ){
int hit=0;
if( data[i][0] == data[i+1][0] ){ hit+=1; }
if( data[i][1] == data[i+1][1] ){ hit+=1; }
if( data[i][2] == data[i+1][2] ){ hit+=1; }
if( data[i][3] == data[i+1][3] ){ hit+=1; }
write( hit , " " );
int blow=0;
if( data[i][0] == data[i+1][1] ){ blow+=1; }
if( data[i][0] == data[i+1][2] ){ blow+=1; }
if( data[i][0] == data[i+1][3] ){ blow+=1; }
if( data[i][1] == data[i+1][0] ){ blow+=1; }
if( data[i][1] == data[i+1][2] ){ blow+=1; }
if( data[i][1] == data[i+1][3] ){ blow+=1; }
if( data[i][2] == data[i+1][0] ){ blow+=1; }
if( data[i][2] == data[i+1][1] ){ blow+=1; }
if( data[i][2] == data[i+1][3] ){ blow+=1; }
if( data[i][3] == data[i+1][0] ){ blow+=1; }
if( data[i][3] == data[i+1][1] ){ blow+=1; }
if( data[i][3] == data[i+1][2] ){ blow+=1; }
writeln( blow );
}
}
|
D
|
void main(){
string s = readln().chomp();
char tmpc;
foreach(ch; s){
if(tmpc == ch){
writeln("Bad");
return;
}
tmpc = ch;
}
writeln("Good");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio, std.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!long;
long a = 0;
long b = 0;
foreach (i; 0..10^^6) {
b += 1;
a += b;
if (a >= N) {
b.writeln;
return;
}
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long N = lread();
bool[long] D;
foreach (_; 0 .. N)
{
long A = lread();
D[A] = (A in D) ? !D[A] : true;
}
D.values.sum().writeln();
}
|
D
|
import std.stdio, std.algorithm, core.bitop;
void main(){
int A, B, K, ans;
scanf("%d%d%d", &A, &B, &K);
foreach(bit; 0..1<<10)if(popcnt(bit) <= K){
ans = max(ans, test(A, B, bit));
}
writeln(ans);
}
int test(int A, int B, int bit){
int carry = 0, ten = 1, C = 0;
for(;A;A/=10, B/=10, ten*=10, bit>>=1){
int x = A%10, y = B%10;
if(x - carry >= y){
C += ten * (x - carry - y);
carry = 0;
}
else{
C += ten * (x - carry + 10 - y);
carry = (bit&1) ? 0 : 1;
}
}
return C;
}
|
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()
{
int N, Q;
scan(N, Q);
auto uf = dsu(N);
foreach (_; 0 .. Q)
{
int t, u, v;
scan(t, u, v);
if (t == 0)
{
uf.merge(u, v);
}
else
{
writeln(uf.same(u, v) ? 1 : 0);
}
}
}
struct dsu
{
public:
this(int n)
{
_n = n, parent_or_size = new int[](n);
parent_or_size[] = -1;
}
int merge(int a, int b)
{
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
int x = leader(a), y = leader(b);
if (x == y)
return x;
if (-parent_or_size[x] < -parent_or_size[y])
{
auto tmp = x;
x = y;
y = tmp;
}
parent_or_size[x] += parent_or_size[y];
parent_or_size[y] = x;
return x;
}
bool same(int a, int b)
{
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}
int leader(int a)
{
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0)
return a;
return parent_or_size[a] = leader(parent_or_size[a]);
}
int size(int a)
{
assert(0 <= a && a < _n);
return -parent_or_size[leader(a)];
}
int[][] groups()
{
auto leader_buf = new int[](_n), group_size = new int[](_n);
foreach (i; 0 .. _n)
{
leader_buf[i] = leader(i);
group_size[leader_buf[i]]++;
}
auto result = new int[][](_n);
foreach (i; 0 .. _n)
result[i].reserve(group_size[i]);
foreach (i; 0 .. _n)
result[leader_buf[i]] ~= i;
int[][] filtered;
foreach (r; result)
if (r.length != 0)
filtered ~= r;
return filtered;
}
private:
int _n;
int[] parent_or_size;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (ti; 0..t)
{
auto a = RD!string;
auto b = RD!string;
auto c = RD!string;
bool ok = true;
foreach (i; 0..a.length)
{
if (a[i] == c[i] || b[i] == c[i]) continue;
ok = false;
break;
}
ans[ti] = ok;
}
foreach (e; ans)
{
writeln(e ? "YES" : "NO");
}
stdout.flush;
debug readln;
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int k, s; readV(k, s);
auto ans = 0;
foreach (x; 0..k+1)
foreach (y; 0..k+1) {
auto z = s-x-y;
if (z >= 0 && z <= k) ++ans;
}
writeln(ans);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
char A, B;
scan(A, B);
writeln((A == B) ? "H" : "D");
}
|
D
|
void main() {
string s1 = readln.chomp;
string s2 = readln.chomp;
string s3 = readln.chomp;
writeln(s1[0], s2[1], s3[2]);
}
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.algorithm;
import std.array;
import std.range;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;
alias FairyPos = Tuple!(int,int);
void main(){
auto blue_num = readln.chomp.to!int;
string[] blues;
foreach(i; iota(0, blue_num)) {
blues ~= readln.chomp;
}
auto red_num = readln.chomp.to!int;
string[] reds;
foreach(i; iota(0, red_num)) {
reds ~= readln.chomp;
}
auto pluss = get_num_by_string(blues);
// writeln(pluss);
auto minus = get_num_by_string(reds);
// writeln(minus);
int[string] scores;
foreach(str, num; pluss) {
int minus_score = str in minus ? minus[str] : 0;
scores[str] = pluss[str] - minus_score;
}
int max_num;
foreach(score; scores) {
max_num = score > max_num ? score : max_num;
}
max_num.writeln;
}
int[string] get_num_by_string(string[] raw){
int[string] result;
raw.each!((str){
if(str in result){
result[str]++;
}else{
result[str] = 1;
}
});
return result;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, core.bitop;
int r, c;
int[] sb;
void main() {
string s = readln.chomp;
int n = s.length.to!int;
bool[] e = new bool[](26);
foreach (ch ; s) {
e[ch - 'a'] = 1;
}
if (e.count(1) == 1) {
writeln(0);
return;
}
int ans = 1000;
foreach (char ch; 'a' .. 'z' + 1) {
if (!e[ch - 'a']) continue;
auto t = s.dup;
int cnt;
foreach (i ; 0 .. n - 1) {
cnt++;
foreach (j ; 0 .. n - 1 - i) {
if (t[j + 1] == ch) {
t[j] = ch;
}
}
bool flag = true;
foreach (j ; 0 .. n - 1 - i) {
if (t[j] != ch) {
flag = false;
break;
}
}
debug {
stderr.writeln(t[0 .. n - 1 - i]);
}
if (flag) break;
}
ans = min(ans, cnt);
}
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);
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int q = read.to!int;
foreach(t; 0 .. q){
long a = read.to!long;
long b = read.to!long;
if(a == b) (a * 2 - 2).writeln;
else{
long r = sqrt((a * b - 1).to!real).to!long;
if(r * (r + 1) < a * b) (r * 2 - 1).writeln;
else (r * 2 - 2).writeln;
}
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void main()
{
string s; readV(s);
auto b = new bool[](26);
foreach (c; s) b[c-'a'] = true;
foreach (i; 0..26)
if (!b[i]) {
writeln(dchar(i+'a'));
return;
}
writeln("None");
}
|
D
|
void main()
{
string s = readln.chomp;
long n = s.countUntil('C');
long m = -1;
if (n != -1)
{
m = s[n+1..$].countUntil('F');
}
writeln(m != -1 ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
void main() {
problem();
}
void problem() {
const S = scan;
auto N = S.length;
long solve() {
if (N < 4) return 0;
const P = 2019;
long ans;
auto cs = new long[](P);
cs[0] = 1;
long x, t = 1;
foreach_reverse (c; S) {
x = ((c-'0').to!long * t + x) % P;
t = (t * 10) % P;
ans += cs[x];
++cs[x];
}
return ans;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
import std.bigint, std.functional;
const MOD = 100_000_000_7;
// -----------------------------------------------
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int n;
scan(n);
auto a = iota(n).map!(i => readln.chomp.to!int).array;
foreach (s ; 0 .. 1<<n) {
int deg;
foreach (i ; 0 .. n) {
if (s & (1 << i)) {
deg += a[i];
deg %= 360;
}
else {
deg -= a[i];
deg %= 360;
}
}
if (deg == 0) {
writeln("YES");
return;
}
}
writeln("NO");
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
/+ dub.sdl:
name "D"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
Scanner sc = new Scanner(stdin);
int n; long k;
sc.read(n, k);
long[] a = new long[n];
long[] b = new long[n];
foreach (i; 0..n) {
sc.read(a[i], b[i]);
}
long ans = 0;
void query(long z) {
long sm = 0;
foreach (i; 0..n) {
if (!(~z & a[i])) sm += b[i];
}
// writeln(z, " ", sm);
ans = max(ans, sm);
}
query(k);
foreach (i; 0..40) {
if (!(k & (1L<<i))) continue;
query(k ^ (1L<<i) | ((1L<<i)-1));
}
writeln(ans);
return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
*/
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;
void main()
{
auto n = readln.chomp.to!int;
bool[string] cnt;
foreach (_; 0..n) {
auto s = readln.chomp;
cnt[s] = true;
}
cnt.keys.length.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
int main() {
int[string] hash;
int n = to!int(readln.chomp);
string[] s = readln.chomp.split;
foreach (ref c; s) {
hash[c]++;
}
writeln(hash.length == 3 ? "Three" : "Four");
return (0);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
import core.bitop;
alias H = Tuple!(int, "r", string, "s");
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp;
long[H] ls, rs;
foreach (b; 0..(1<<N)) {
auto ll = new char[](N);
auto rr = new char[](N);
int j, k = N-1, l, m = N-1;
foreach (i; 0..N) {
if (b & (1<<i)) {
ll[j++] = S[i];
rr[m--] = S[2*N-i-1];
} else {
ll[k--] = S[i];
rr[l++] = S[2*N-i-1];
}
}
auto r = popcnt(b);
++ls[H(r, ll.to!string)];
++rs[H(r, rr.to!string)];
}
long r;
foreach (k, v; rs) {
auto l = H(N - k.r, k.s);
if (l in ls) r += v * ls[l];
}
writeln(r);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
writeln(readln.to!(wchar[]).count!(c => c == '1'));
}
|
D
|
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
void main() {
immutable ip = readln.split.to!(ulong[]);
immutable n = ip[0], m = ip[1];
auto ls = new ulong[m];
auto rs = new ulong[m];
for(ulong i = 0; i < m; i++) {
immutable ip1 = readln.split.to!(ulong[]);
immutable l = ip1[0], r = ip1[1];
ls[i] = l;
rs[i] = r;
}
ulong max_l = ls[0], min_r = rs[0];
ulong invalid = false;
for (ulong i = 1; i < m; i++) {
if (ls[i] > max_l) max_l = ls[i];
if (rs[i] < min_r) min_r = rs[i];
if (max_l > min_r) {invalid = true; break;}
}
writeln(invalid ? 0 : min_r-max_l+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()
{
auto s = sread();
auto t = cast(ubyte[]) s.dup;
bool b = t.sort().uniq().array().length == s.length;
writeln(b ? "yes" : "no");
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], b = tmp[1], t = tmp[2];
writeln(t / a * b);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
/+ dub.sdl:
name "F"
dependency "dcomp" version=">=0.7.4"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
Scanner sc = new Scanner(stdin);
int k;
// sc.read(k);
k = 38;
int n = k*(k-1)+1;
bool[][] g = new bool[][](n, n);
foreach (i; 0..k) {
g[i][0] = true;
g[0][i] = true;
}
foreach (i; 0..k) {
int s = 1 + i * (k-1);
foreach (j; 0..k-1) {
g[s+j][i] = true;
g[i][s+j] = true;
}
}
foreach (i; 0..k-1) {
int si = k + i * (k-1);
foreach (j; 0..k-1) {
int sj = k + j * (k-1);
foreach (l; 0..k-1) {
int f = (i * j) % (k-1);
g[si + l][sj + (l + f) % (k-1)] = true;
}
}
}
/* foreach (i; 0..n) {
foreach (j; 0..n) {
write(g[i][j] ? '#' : '.');
}
writeln();
}*/
writeln(n, " ", k);
foreach (i; 0..n) {
foreach (j; 0..n) {
if (g[i][j]) {
write(j+1, " ");
}
}
writeln();
}
return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
// import dcomp.array;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
FastAppender!(E[]) buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;
T[N] fixed(T, size_t N)(T[N] a) {return a;}
struct FastAppender(A, size_t MIN = 4) {
import std.algorithm : max;
import std.conv;
import std.range.primitives : ElementEncodingType;
import core.stdc.string : memcpy;
private alias T = ElementEncodingType!A;
private T* _data;
private uint len, cap;
@property size_t length() const {return len;}
bool empty() const { return len == 0; }
void reserve(size_t nlen) {
import core.memory : GC;
if (nlen <= cap) return;
void* nx = GC.malloc(nlen * T.sizeof);
cap = nlen.to!uint;
if (len) memcpy(nx, _data, len * T.sizeof);
_data = cast(T*)(nx);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void opOpAssign(string op : "~")(T item) {
if (len == cap) {
reserve(max(MIN, cap*2));
}
_data[len++] = item;
}
void insertBack(T item) {
this ~= item;
}
void removeBack() {
len--;
}
void clear() {
len = 0;
}
ref inout(T) back() inout { assert(len); return _data[len-1]; }
ref inout(T) opIndex(size_t i) inout { return _data[i]; }
T[] data() {
return (_data) ? _data[0..len] : null;
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
import core.bitop : popcnt;
static if (!__traits(compiles, popcnt(ulong.max))) {
public import core.bitop : popcnt;
int popcnt(ulong v) {
return popcnt(cast(uint)(v)) + popcnt(cast(uint)(v>>32));
}
}
bool poppar(ulong v) {
v^=v>>1;
v^=v>>2;
v&=0x1111111111111111UL;
v*=0x1111111111111111UL;
return ((v>>60) & 1) != 0;
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/
|
D
|
void main()
{
long k = rdElem - 1;
long[] a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
a[k].writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
long ans1;
foreach (i, c; S)
{
if ([c].to!long == i % 2) ++ans1;
}
long ans2;
foreach (i, c; S)
{
if ([c].to!long != i % 2) ++ans2;
}
writeln(min(ans1, ans2));
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
enum lim = 10^^5 + 1;
void main() {
int N, W;
scan(N, W);
auto w = new int[](N);
auto v = new int[](N);
iota(N).each!(i => scan(w[i], v[i]));
auto dp = new long[](lim);
dp[] = infl;
dp[0] = 0;
foreach (i ; 0 .. N) {
foreach_reverse (j ; v[i] .. lim) {
chmin(dp[j], dp[j - v[i]] + w[i]);
}
}
foreach_reverse (i ; 0 .. lim) {
if (dp[i] <= W) {
writeln(i);
return;
}
}
}
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;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
T readNum(T)(){
return readStr.to!T;
}
T[] readNums(T)(){
return readStr.split.to!(T[]);
}
string readStr(){
return readln.chomp;
}
void main(){
int n = readNum!int;
writeln(180 * (n - 2));
}
|
D
|
import std.stdio;
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
void main() {
auto input = readln.split;
auto a = input[0].to!int;
auto b = input[1].to!int;
writeln(a * b, " ", 2 * (a + b));
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
auto a=scanElem;
auto b=scanElem;
auto c=scanElem;
if(b-a==c-b)end("YES");end("NO");
}
|
D
|
import std.stdio, std.string, std.conv;
import std.algorithm;
void main() {
auto input = getStdin!(string[]);
string needle = input[0].toLower;
string[] haystack = input[1..$-1].join(" ").replace(".", "").replace(",", "").toLower.split(" ");
auto count = haystack.count(needle);
count.writeln;
}
T getStdin(T)() {
string[] cmd;
string line;
while ((line = chomp(stdin.readln())) != "") cmd ~= line;
return to!(T)(cmd);
}
|
D
|
void main() {
auto S = rs;
string str = "keyence";
if(S == str) { writeln("YES"); return; }
foreach(i; 0..str.length) {
auto l = str[0..i];
auto r = str[i..$];
if(S.startsWith(l) && S.endsWith(r)) {
writeln("YES");
return;
}
}
writeln("NO");
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio, std.range, std.conv, std.string, std.math;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
void main() {
long N = readln().strip.to!long;
long minCount=long.max;
for (long i = 0; i < 5; ++i) {
long n = readln().strip.to!long;
minCount = min(n, minCount);
}
writeln(ceil(N/(minCount.to!real)-1).to!long+5);
}
|
D
|
void main()
{
string s = rdStr;
string t;
foreach (x; s)
{
if (x == 'B')
{
if (t.length) t = t[0..$-1];
}
else
{
t ~= x;
}
}
t.writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import 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 A = scanElem;
auto B = scanElem;
writeln(A-B+1);
}
long gcd(long a, long b)
{
if(b == 0) return a;
return gcd(b, a % b);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(T[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;
string my_readln() { return chomp(readln()); }
void main()
{//try{
auto tokens = split(my_readln());
auto N = to!ulong(tokens[0]);
long[] h;
foreach (token; split(my_readln()))
{
h ~= to!long(token);
}
ulong[] costs;
costs.length = N;
fill(costs, ulong.max);
costs[0] = 0;
foreach (i; 0..N-2)
{
costs[i+1] = min(costs[i+1], costs[i] + abs(h[i] - h[i+1]));
costs[i+2] = min(costs[i+2], costs[i] + abs(h[i] - h[i+2]));
}
costs[N-1] = min(costs[N-1], costs[N-2] + abs(h[N-2] - h[N-1]));
writeln(costs[N-1]);
stdout.flush();
/*}catch (Throwable e)
{
writeln(e.toString());
}
readln();*/
}
|
D
|
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto N = RD!long;
bool ans = true;
long[2] pos;
long lastTime;
foreach (i; 0..N)
{
auto t = RD!long;
auto x = RD!long;
auto y = RD!long;
auto d = abs(x - pos[0]) + abs(y - pos[1]);
auto use_t = t - lastTime;
if (d > use_t || (use_t - d) % 2 == 1)
{
ans = false;
break;
}
pos = [x, y];
lastTime = t;
}
writeln(ans ? "Yes" : "No");
stdout.flush();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto X = RD;
long ans = 2;
if (X != 2)
{
foreach (i; X..10^^9)
{
bool ok = true;
for (long j = 2; j*j <= X; ++j)
{
if (i % j == 0)
{
ok = false;
break;
}
}
if (ok)
{
ans = i;
break;
}
}
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
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;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto A = RD;
auto B = RD;
writeln(A >= 13 ? B : A >= 6 ? B/2 : 0);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.algorithm, std.range;
void main() {
auto N = readln.split[0].to!int;
auto H = readln.split.to!(int[]);
H ~= int.max;
auto maxNum = 0;
auto num = 0;
size_t i = 0;
while(i < H.length - 1) {
if(H[i+1]<=H[i]) {
num++;
} else {
maxNum = max(maxNum, num);
num = 0;
}
i++;
}
maxNum.writeln;
}
|
D
|
void main() {
("A" ~ rs[8] ~ "C").writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int x = tmp[0], y = tmp[1] / 2;
writeln(x + y);
}
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.conv,std.string,std.algorithm;
void main(){
auto nab = readln.chomp.split.map!(to!int);
int n=nab[0],a=nab[1],b=nab[2];
if(n*a<b) writeln(n*a);
else writeln(b);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
long d, t, s;
scan(d, t, s);
double tmp = double(d) / double(s);
// writeln(tmp);
if (tmp <= t)
{
writeln("Yes");
}
else
{
writeln("No");
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long A, B;
scan(A, B);
if (A == B)
{
writeln("Draw");
return;
}
if (A == 1 || (B != 1 && B < A))
{
writeln("Alice");
}
else
{
writeln("Bob");
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math, std.typecons;
void main() {
int n, t;
scan(n, t);
auto imos = new int[](t + 2);
foreach (i ; 0 .. n) {
int li, ri; scan(li, ri);
imos[li]++;
imos[ri]--;
}
foreach (i ; 0 .. t + 1) {
imos[i + 1] += imos[i];
}
writeln(imos.reduce!max);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto A = RD;
auto B = RD;
writeln((A + B) % 24);
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.map!(to!int);
auto w = rd[0], h = rd[1], x = rd[2], y = rd[3], r = rd[4];
writeln(x >= r && x <= w - r && y >= r && y <= h - r ? "Yes" : "No");
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons;
// }}}
// nep.scanner {{{
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string : chomp;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.chomp.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
}
// }}}
void main()
{
auto cin = new Scanner;
int n, m, x;
cin.scan(n, m, x);
int[] a = cin.nextArray!int(m);
int t;
for (int i = x; i <= n; i++)
{
foreach (e; a)
{
if (e == i) t++;
}
}
int y;
for (int i = x; i >= 0; i--)
{
foreach (e; a)
{
if (e == i) y++;
}
}
writeln(min(t, y));
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto s = sread();
auto a = s[0 .. $ - 1].all!(c => c == s[0]);
auto b = s[1 .. $].all!(c => c == s[1]);
writeln((a || b) ? "Yes" : "No");
}
|
D
|
import core.stdc.stdio;
import std.algorithm;
void main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=0;i<k;i++){
int a,b;
scanf("%d%d",&a,&b);
int m = min(a,n+1-a,b,n+1-b);
printf("%d\n",(m-1)%3+1);
}
}
|
D
|
import std.stdio, std.range, std.conv, std.string, std.array, std.functional;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;
void main()
{
auto N = readln().strip.to!(long);
foreach(n; N..1000)
{
if(n%10 == n/10%10 && n%10 == n/100%10)
{
writeln(n);
return;
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
// fold was added in D 2.071.0.
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);
}
}
}
void main() {
readln.chomp.find!"a=='A'".retro.find!"a=='Z'".array.length.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
import std.math;
import std.range;
void main() {
auto S = readln.chomp.dup;
auto T = readln.chomp.dup;
auto findResult = iota(S.length-T.length+1).retro
.find!(i =>
iota(T.length)
.all!(j => S[i+j] == T[j] || S[i+j] == '?'));
if (findResult.length == 0) {
writeln("UNRESTORABLE");
return;
}
auto minPos = findResult[0];
S = S.replace("?", "a");
S[minPos..minPos+T.length] = T;
writeln(S);
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv,
std.format,
std.math;
void main()
{
auto r = readln.chomp.to!int;
auto g = readln.chomp.to!int;
writeln(2*g-r);
}
|
D
|
import std.stdio;
import std.array;
import std.algorithm;
import std.string;
import std.conv;
void main(string[] argv)
{
long x = readln.chomp.to!long;
long a = readln.chomp.to!long;
long b = readln.chomp.to!long;
x -= a;
writeln(x%b);
}
|
D
|
import std.stdio;
import std.string;
import std.range;
import std.conv;
void main()
{
auto N = readln.chomp.to!int;
auto K = readln.chomp.to!int;
auto X = readln.chomp.to!int;
auto Y = readln.chomp.to!int;
if(N>K){
writeln((K*X)+((N-K)*Y));
}else{
writeln(N*X);
}
}
|
D
|
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) {
stderr.writeln(arg);
}
int size(T)(in T s) {
return cast(int)s.length;
}
const H = 19;
const W = 15;
const INF = int.max / 2;
void main() {
auto F = new string[19];
foreach (ref L; F) L = readln.chomp;
int sy, sx;
void find_init_pos() {
foreach (i; 0 .. H) {
foreach (j; 0 .. W) {
if (F[i][j] == 'O') {
sy = i;
sx = j;
return;
}
}
}
}
find_init_pos();
if (! (F[H - 2].any!((c) => c == 'X') || F[H - 1].any!((c) => c == 'X'))) {
writeln(-1);
return;
}
bool[W][H] used;
bool dfs(int cy, int cx, int d) {
if (d == 0) return false;
//log([cy, cx, t, d]);
for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) {
if (dy == 0 && dx == 0) continue;
int y = cy + dy, x = cx + dx;
if (! (0 <= y && y < H && 0 <= x && x < W && F[y][x] == 'X' && !used[y][x])) continue;
while (0 <= y && y < H && 0 <= x && x < W && F[y][x] == 'X' && !used[y][x]) {
y += dy;
x += dx;
}
if (y == H - 1 && 0 <= x && x < W) return true;
if (y >= H) return true;
if (x < 0 || x >= W) continue;
y = cy + dy, x = cx + dx;
while (0 <= y && y < H && 0 <= x && x < W && F[y][x] == 'X' && !used[y][x]) {
used[y][x] = true;
y += dy;
x += dx;
}
if (dfs(y, x, d - 1)) return true;
y -= dy, x -= dx;
while (y != cy || x != cx) {
used[y][x] = false;
y -= dy;
x -= dx;
}
}
}
return false;
}
for (int d = 1; d <= 20; d++) {
if (dfs(sy, sx, d)) {
writeln(d);
return;
}
}
writeln(-1);
}
|
D
|
import std.stdio,std.ascii,std.conv,std.string,std.algorithm,std.range,std.functional,std.math,core.bitop;
void main()
{
auto a=readln.chomp.to!int;
auto b=readln.chomp.to!int;
writeln((a*a)-b);
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
import std.string;
void main()
{
while (1) {
string[] input = split(readln());
int m = to!(int)(input[0]);
int f = to!(int)(input[1]);
int r = to!(int)(input[2]);
if ( m == -1 && f == -1 && r == -1) break;
if (r == -1) r = 0;
char g;
if (m == -1 || f == -1) g = 'F';
else if (m + f >= 80) g = 'A';
else if (m + f >= 65 && m + f < 80) g = 'B';
else if (m + f >= 50 && m + f < 65) g = 'C';
else if (m + f >= 30 && m + f < 50) {
if (r >= 50) g = 'C';
else g = 'D';
} else g = 'F';
writeln(g);
}
}
|
D
|
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;
void main() {
auto s = readln.chomp;
auto c = s.count!(x => x == 'R');
if (c == 2 && s[1] != 'R') {
writeln(1);
} else {
writeln(c);
}
}
|
D
|
void main()
{
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], b = tmp[1];
if (a + b == 15)
{
"+".writeln;
}
else if (a * b == 15)
{
"*".writeln;
}
else
{
"x".writeln;
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.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 ab = readints;
int a = ab[0], b = ab[1];
writeln((a - 1) * (b - 1));
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!int).array;
int odd, two, four;
foreach (a; A) {
if (a % 2 == 1) odd += 1;
else if (a % 4 == 0) four += 1;
else two += 1;
}
int mode = 0;
foreach (i; 0..N) {
if (mode == 0) {
if (odd > 0) odd -= 1, mode = 4;
else if (two > 0) two -= 1, mode = 2;
else four -= 1, mode = 0;
} else if (mode == 2) {
if (two > 0) two -= 1, mode = 2;
else if (four > 0) four -= 1, mode = 0;
else {writeln("No"); return;}
} else if (mode == 4) {
if (four > 0) four -= 1, mode = 0;
else {writeln("No"); return;}
}
}
writeln("Yes");
}
|
D
|
void main(){
int x = _scan();
( (x/500)*1000 + (x%500)/5*5).writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
// 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 input = aryread!string();
writeln(input[0].to!long + (input[1] == "+" ? 1 : -1) * input[2].to!long);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto n = readln.chomp.to!int;
auto l = new long[](n+1);
l[0] = 2;
l[1] = 1;
foreach (i; 2..n+1) {
l[i] = l[i-1] + l[i-2];
}
l[n].writeln;
}
|
D
|
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int [] get (string s)
{
auto f = new int [10];
foreach (c; s)
{
f[c - '0']++;
}
f[2] += f[5];
f[5] = 0;
f[6] += f[9];
f[9] = 0;
return f;
}
void main ()
{
string s;
while ((s = readln ().strip ()) != null)
{
string t = readln ().strip ();
auto f = get (s);
auto g = get (t);
int res = int.max;
foreach (i; 0..10)
{
if (f[i] > 0)
{
res = min (res, g[i] / f[i]);
}
}
writeln (res);
}
}
|
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);
scan(m);
int ans;
if (n > 30) {
ans = m;
}
else {
ans = m % 2^^n;
}
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto n = RD;
auto m = RD;
auto q = RD!int;
auto g = gcd(n, m);
auto l1 = n / g;
auto l2 = m / g;
auto ans = new bool[](q);
foreach (i; 0..q)
{
auto sx = RD;
auto sy = RD-1;
auto ex = RD;
auto ey = RD-1;
long pos1, pos2;
if (sx == 1)
pos1 = sy / l1;
else
pos1 = sy / l2;
if (ex == 1)
pos2 = ey / l1;
else
pos2 = ey / l2;
ans[i] = pos1 == pos2;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto S = RD!string;
int p;
foreach_reverse (i; 0..n)
{
if (S[i] != ')')
{
p = i+1;
break;
}
}
ans[ti] = p*2 < n;
}
foreach (e; ans)
writeln(e ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
D
|
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
int test () {
auto s = readln.strip;
auto t = readln.strip;
immutable l = s.length.to!int;
auto next = new int[26][l+1];
next[l][] = l;
foreach_reverse (i; 0 .. l) {
next[i][] = next[i+1][];
immutable k = s[i].to!int - 97;
next[i][k] = i;
}
foreach (c; t) {
immutable k = c.to!int - 97;
if (next[0][k] >= l) return -1;
}
int i, res;
foreach (c; t) {
immutable k = c.to!int - 97;
while (true) {
i = next[i][k];
if (i >= l) {
++res;
i = 0;
} else {
break;
}
}
++i;
}
res++;
return res;
}
void main() {
immutable nt = readln.strip.to!int;
foreach (tid; 0 .. nt) {
writeln (test ());
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n, m, q; rd(n, m, q);
auto s=readln.chomp.to!(char[]);
auto t=readln.chomp.to!(char[]);
auto ok=new bool[](s.length+1);
for(int i=0; i+t.length<=s.length; i++){
if(s[i..(i+t.length)]==t) ok[i]=true;
}
while(q--){
int l, r; rd(l, r);
l--; r--;
int w=0;
for(int i=l; i<=r; i++){
if(ok[i] && i+t.length-1<=r) w++;
}
writeln(w);
}
}
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;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
readln.strip.length.writeln;
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s;
scan(s);
int n = s.length.to!int;
long ans;
foreach (i ; 0 .. n) {
foreach (j ; i + 1 .. n) {
foreach (k ; j + 1 .. n) {
if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') ans++;
}
}
}
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);
}
}
}
struct Queue(T) {
private {
int N, head, tail;
T[] data;
}
this(int n) {
N = n + 1;
data = new T[](N);
}
bool empty() {
return head == tail;
}
bool full() {
return (tail + 1) % N == head;
}
T front() {
return data[head];
}
void push(T x) {
assert(!full);
data[tail++] = x;
tail %= N;
}
void pop() {
assert(!empty);
head = (head + 1) % N;
}
void clear() {
head = tail = 0;
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;
void main()
{
auto a = readln.split.to!(long[]);
auto N = a[0];
auto A = a[1];
auto B = a[2];
auto C = a[3];
auto D = a[4];
foreach (i; 0..N-1) {
auto l = A + C * i - D * (N-i-1);
auto r = A + D * i - C * (N-i-1);
if (l <= B && B <= r) {
writeln("YES");
return;
}
}
writeln("NO");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto ab = readln.split.to!(int[]);
auto A = ab[0];
auto B = ab[1];
writeln(max(A+B, A-B, A*B));
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto t = RD!int;
auto ans = new int[][](t, 26);
foreach (i; 0..t)
{
auto s = RD!string;
long cnt = 1;
char last = s[0];
foreach (j; 1..s.length)
{
if (s[j] == last)
{
++cnt;
}
else
{
if (cnt % 2 == 1)
{
ans[i][last-'a'] = 1;
}
cnt = 1;
last = s[j];
}
}
if (cnt % 2 == 1)
{
ans[i][last-'a'] = 1;
}
}
foreach (e; ans)
{
foreach (i; 0..e.length)
{
if (e[i] == 1)
write(cast(char)('a'+i));
}
writeln();
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
void main()
{
auto S = readln.chomp;
auto DP = new long[][](S.length+1, 4);
DP[S.length][3] = 1;
foreach_reverse (i; 0..S.length) {
auto c = S[i];
foreach (j; 0..4) {
if (c == 'A' || c == '?') {
DP[i][j] = (DP[i][j] + DP[i+1][j]) % P;
if (j == 0) DP[i][j] = (DP[i][j] + DP[i+1][j+1]) % P;
}
if (c == 'B' || c == '?') {
DP[i][j] = (DP[i][j] + DP[i+1][j]) % P;
if (j == 1) DP[i][j] = (DP[i][j] + DP[i+1][j+1]) % P;
}
if (c == 'C' || c == '?') {
DP[i][j] = (DP[i][j] + DP[i+1][j]) % P;
if (j == 2) DP[i][j] = (DP[i][j] + DP[i+1][j+1]) % P;
}
}
}
writeln(DP[0][0]);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Cake = Tuple!(long, "beauty", long, "tasty", long, "popular");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
auto r = lread();
(3 * (r ^^ 2)).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()
{
long N = lread();
auto A = aryread();
auto B = aryread();
long a, b;
foreach (i; 0 .. N)
{
a += max((B[i] - A[i]) / 2, 0);
b += max(A[i] - B[i], 0);
}
writeln(a < b ? "No" : "Yes");
}
|
D
|
import std.stdio;
import std.string;
void main()
{
auto S = readln().chomp();
if ((S == "AAA") || (S == "BBB"))
{
writeln("No");
return;
}
writeln("Yes");
}
|
D
|
void main() {
int n = readln.chomp.to!int;
string[] w = new string[n];
int ok = true;
foreach (i; 0 .. n) {
string s = readln.chomp;
if (i > 0) {
if (s[0] != w[i-1][$-1] || w.canFind(s)) {
ok = false;
break;
}
}
w[i] = s;
}
writeln(ok ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto K = s[1];
auto A = readln.split.map!(to!int).array;
auto dp = new long[][](N+1, K+10);
dp[0][K] = 1;
foreach (i; 0..N) {
foreach (j; 0..K+1) {
(dp[i+1][max(0, j-A[i])] += dp[i][j]) %= MOD;
(dp[i+1][j+1] -= dp[i][j]) %= MOD;
}
foreach (j; 0..K+1) {
(dp[i+1][j+1] += dp[i+1][j]) %= MOD;
}
}
long ans = (dp[N][0] + MOD) % MOD;
ans.writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
string[3] s;
scan(s[0]);
scan(s[1]);
scan(s[2]);
long[3] n;
long p;
while (n[p] < s[p].length)
{
auto x = p;
p = s[x][n[x]] - 'a';
n[x]++;
}
writeln("ABC"[p]);
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.