code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std;
void main() {
auto S = readln.split[0];
if (S == "ABC") writeln("ARC");
else writeln("ABC");
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
static import std.ascii;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long K, X;
scan(K, X);
writeln(500 * K < X ? "No" : "Yes");
}
|
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 X = RD;
auto Y = RD;
auto Z = RD;
writeln(Z, " ", X, " ", Y);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.array;
import std.string;
import std.conv;
void main() {
int x = to!int(chomp(readln()));
writeln(x * x * x);
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
long a = read.to!long;
long b = read.to!long;
long c = read.to!long;
int count = 0;
while(count < 10000){
if(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
long a2 = b / 2 + c / 2;
long b2 = a / 2 + c / 2;
long c2 = a / 2 + b / 2;
a = a2, b = b2, c = c2;
count += 1;
}
else break;
}
int ans;
if(count > 1000) ans = -1;
else ans = count;
ans.writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto S = RD!string;
auto T = RD!string;
long ans = long.max;
foreach (i; 0..S.length-T.length+1)
{
long cnt;
foreach (j; 0..T.length)
{
if (S[i+j] != T[j])
++cnt;
}
ans.chmin(cnt);
}
writeln(ans);
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;
import std.algorithm, std.container;
void main()
{
long A = scanElem;
long B = scanElem;
long cost;
for(int i =0 ;i < 2;i++)
{
if(A<B){
cost += B;
B--;
}else{
cost += A;
A--;
}
}
writeln(cost);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
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.string, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
auto s = readln().chomp();
string t;
for(int i=0; i<s.length; )
{
if(startsWith(s[i..$],"apple")) t~="peach", i+=5;
else if(startsWith(s[i..$],"peach")) t~="apple", i+=5;
else t~=s[i], ++i;
}
writeln(t);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
long n, x, t;
scan(n, x, t);
// writeln(n, x, t);
long cnt;
long time;
foreach (_; 0 .. 10 ^^ 7)
{
cnt += x;
time += t;
// writeln(cnt);
if (cnt >= n)
{
writeln(time);
return;
}
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.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 a = readln.chomp;
auto b = readln.chomp;
auto c = readln.chomp;
int res;
foreach (i; 0..n) {
int[char] cnt;
cnt[a[i]]++;
cnt[b[i]]++;
cnt[c[i]]++;
res += cnt.keys.length.to!int - 1;
}
res.writeln;
}
|
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() {
readint();
auto ss = readints();
bool[int] map;
foreach (s; ss)
map[s] = true;
readint();
auto ts = readints();
int ans = 0;
foreach (t; ts) {
auto p = t in map;
if (p != null)
ans++;
}
writeln(ans);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n, k; rd(n, k);
auto x=new long[](n), y=new long[](n);
foreach(i; 0..n) rd(x[i], y[i]);
long mn=5_000_000_000_000_000_000;
foreach(i1; 0..n)foreach(i2; (i1+1)..n){
foreach(j1; 0..n)foreach(j2; (j1+1)..n){
auto x1=x[i1], x2=x[i2];
auto y1=y[j1], y2=y[j2];
if(x1>x2) swap(x1, x2);
if(y1>y2) swap(y1, y2);
// if((x2-x1)*(y2-y1)>=mn) continue;
int cnt=0;
foreach(t; 0..n){
if(x1<=x[t] && x[t]<=x2 && y1<=y[t] && y[t]<=y2) cnt++;
}
if(cnt>=k) mn=min(mn, (x2-x1)*(y2-y1));
}
}
writeln(mn);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;
void main() {
int a, b, c, x, y;
scan(a, b, c, x, y);
int ans = min(x, y) * min(2*c, a + b);
if (x > y) {
ans += (x - y) * min(2*c, a);
}
else {
ans += (y - x) * min(2*c, b);
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.functional;
void main() {
auto N = readln.chomp.to!long;
auto n = N;
auto f = 0;
while (n > 0) {
f += n % 10;
n /= 10;
}
writeln(N % f == 0 ? "Yes" : "No");
}
|
D
|
import std.functional,
std.algorithm,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
void main() {
string s = readln.chomp;
int c;
foreach (i; 0..s.length-1) {
if (s[i] != s[i + 1]) {
c++;
}
}
writeln(c);
}
|
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 q = RD!int;
auto ans = new long[](q);
foreach (qi; 0..q)
{
auto u = RD;
auto v = RD;
auto uc = popcnt(u);
auto vc = popcnt(v);
if (v >= u && vc <= uc)
{
int c1, c2;
bool ok = true;
foreach (i; 0..32)
{
auto bit = 1L << i;
if (u & bit)
++c1;
if (v & bit)
++c2;
if (c2 > c1)
ok = false;
}
ans[qi] = ok;
}
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush;
debug readln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long A, B;
scan(A, B);
foreach (x; 1 .. 10_000)
{
// writeln(x, " ", (x * 108) / 100);
if (A == (x * 108) / 100 - x && B == (x * 110) / 100 - x)
{
writeln(x);
return;
}
}
writeln(-1);
}
|
D
|
import std.stdio;
void main(){
string c1=readln();
string c2=readln();
if(c1[0]==c2[2]&&c1[1]==c2[1]&&c1[2]==c2[0])
writeln("YES");
else
writeln("NO");
}
|
D
|
import std.stdio,std.string,std.conv;
int main()
{
int n;
while((n = readln.chomp.to!int) != 0)
{
int ans = 0;
while((n /= 5) != 0)
{
ans += n;
}
ans.writeln;
}
return 0;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp.to!int;
int r = 1;
foreach (i; 1..X+1) {
foreach (j; 2..X+1) {
if (i^^j <= X) r = max(r, i^^j);
}
}
writeln(r);
}
|
D
|
import std.stdio, std.string, std.array;
import std.algorithm, std.regex;
void main(){
"ATA CGC".find(readln[0])[1].writeln;
}
|
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;
long[][] c;
foreach (i; 0..3)
{
c ~= RDR.split.to!(long[]);
}
bool ans = false;
long[3] xs, ys;
foreach (x0; 0..101)
{
xs[0] = x0;
ys[0] = c[0][0] - xs[0];
foreach (x1; 0..101)
{
xs[1] = x1;
ys[1] = c[1][0] - xs[0];
foreach (x2; 0..101)
{
bool ng = false;
xs[2] = x2;
ys[2] = c[2][0] - xs[0];
foreach (i; 0..3)
{
foreach (j; 1..3)
{
if (c[i][j] != xs[j] + ys[i])
{
ng = true;
}
}
}
ans |= !ng;
}
}
}
writeln(ans ? "Yes" : "No");
stdout.flush();
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
long N;
scan(N);
auto ans = N * (N - 1) / 2;
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
void main()
{
long a, b, c;
rdVals(a, b, c);
if (a + b >= c)
{
"No".writeln;
return;
}
long x = a * b;
long y = c - a - b;
writeln(4 * x < y * y ? "Yes" : "No");
}
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
|
void main()
{
long n = rdElem;
long result = inf;
for (long i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
result = min(result, i+n/i-2);
}
}
result.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
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
if (n == 1) {
writeln("Hello World");
} else {
int a, b;
rd(a);
rd(b);
writeln(a + b);
}
}
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
|
void main(){
import std.stdio, std.conv, std.string, std.algorithm;
int n; rd(n);
int f(int x){
int ret=0;
while(x>0){
ret+=x%10;
x/=10;
}
return ret;
}
int mn=1_000_000_000;
for(int a=1; a<n; a++){
int b=n-a;
mn=min(mn, f(a)+f(b));
}
writeln(mn);
}
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.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime;
void main() {
auto n = readln.chomp.to!int;
writeln(n*(n+1)/2);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto n = lread();
// writeln(n);
long 余り = n % 100;
// writeln(余り);
long これだけ個買える = (n - 余り) / 100;
// writeln(これだけ個買える);
if (これだけ個買える * 5 >= 余り)
{
writeln(1);
}
else
{
writeln(0);
}
}
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
|
/+ dub.sdl:
name "D"
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);
scope(exit) sc.read!true;
import std.typecons;
alias E = Tuple!(int, "to", long, "dist");
int n, m;
sc.read(n, m);
E[][] g = new E[][n];
foreach (i; 0..m) {
int l, r; long d;
sc.read(l, r, d); l--; r--;
g[l] ~= E(r, d);
g[r] ~= E(l, -d);
}
bool[] vis = new bool[n];
long[] pot = new long[n];
bool ok = true;
void dfs(int p) {
vis[p] = true;
foreach (e; g[p]) {
if (vis[e.to]) {
ok &= pot[e.to] == pot[p] + e.dist;
continue;
}
pot[e.to] = pot[p] + e.dist;
dfs(e.to);
}
}
foreach (i; 0..n) {
if (vis[i]) continue;
dfs(i);
}
writeln(ok ? "Yes" : "No");
return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Program/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(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
import std.exception;
enforce(readSingle(x));
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
read!enforceEOF(args);
}
}
void read(bool enforceEOF = false, Args...)(auto ref Args args) {
import std.exception;
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
enforce(readSingle(args[0]));
read!enforceEOF(args);
}
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
|
D
|
import std.stdio, std.string, std.conv, std.math;
void main() {
int n = readln.chomp.to!int;
long debt = 100000;
foreach(i;0..n) debt = ((((debt + (debt*0.05)) / 1000.0).ceil) * 1000).to!long;
debt.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;
import core.stdc.stdlib;
void main()
{
auto N = scanElem;
auto M = scanElem;
long[] list;
list.length = N;
foreach(i; 0..M)
{
auto a = scanElem;
auto b = scanElem;
if(a>b)swap(a,b);
list[a-1]++;
list[b-1]--;
}
foreach(i; 1..N)
{
list[i] += list[i-1];
}
list = list[0..$-1];
writeln(list.any!"a%2!=0"?"NO":"YES");
}
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 readln.strip;
}
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.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto s = readln.chomp;
int[char] k;
foreach (e; s) {
k[e]++;
}
if (k.keys.length == 3) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.algorithm;
void main()
{
for(string s_; (s_=readln().chomp()).length;)
{
auto ab = s_.split.map!(to!int)();
immutable a=ab[0], b=ab[1];
if(0<a) writeln("Positive");
else if(a<=0 && 0<=b) writeln("Zero");
else if(b<0 && (b-a)%2==0) writeln("Negative");
else if(b<0 && (b-a)%2==1) writeln("Positive");
else assert(false);
}
}
|
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);
foreach (cmb ; 0 .. 16) {
string t;
t ~= (cmb & 1) ? "AKIH" : "KIH";
t ~= (cmb & 2) ? "AB" : "B";
t ~= (cmb & 4) ? "AR" : "R";
t ~= (cmb & 8) ? "A" : "";
if (s == t) {
writeln("YES");
return;
}
}
writeln("NO");
}
struct UnionFind {
private {
int N;
int[] p;
int[] rank;
}
this (int n) {
N = n;
p = iota(N).array;
rank = new int[](N);
}
int find_root(int x) {
if (p[x] != x) {
p[x] = find_root(p[x]);
}
return p[x];
}
bool same(int x, int y) {
return find_root(x) == find_root(y);
}
void unite(int x, int y) {
int u = find_root(x), v = find_root(y);
if (u == v) return;
if (rank[u] < rank[v]) {
p[u] = v;
}
else {
p[v] = u;
if (rank[u] == rank[v]) {
rank[u]++;
}
}
}
}
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;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto k = readln.chomp.to!int;
auto h = k / 2;
if (k % 2) {
writeln((h+1) * h);
} else {
writeln(h * h);
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int n;
scan(n);
while (n > 0) {
if (n % 10 == 9) {
writeln("Yes");
return;
}
n /= 10;
}
writeln("No");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
auto rs = S.dup;
rs.reverse();
if (S != rs) {
writeln("No");
return;
}
auto N = S.length;
auto s = S[0..(N-1)/2];
rs = s.dup;
rs.reverse();
if (s != rs) {
writeln("No");
return;
}
s = S[(N+3)/2-1..$];
rs = s.dup;
rs.reverse();
if (s != rs) {
writeln("No");
return;
}
writeln("Yes");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void get(Args...)(ref Args args)
{
import std.traits, std.meta, std.typecons;
static if (Args.length == 1) {
alias Arg = Args[0];
static if (isArray!Arg) {
static if (isSomeChar!(ElementType!Arg)) {
args[0] = readln.chomp.to!Arg;
} else {
args[0] = readln.split.to!Arg;
}
} else static if (isTuple!Arg) {
auto input = readln.split;
static foreach (i; 0..Fields!Arg.length) {
args[0][i] = input[i].to!(Fields!Arg[i]);
}
} else {
args[0] = readln.chomp.to!Arg;
}
} else {
auto input = readln.split;
assert(input.length == Args.length);
static foreach (i; 0..Args.length) {
args[i] = input[i].to!(Args[i]);
}
}
}
void get_lines(Args...)(size_t N, ref Args args)
{
import std.traits, std.range;
static foreach (i; 0..Args.length) {
static assert(isArray!(Args[i]));
args[i].length = N;
}
foreach (i; 0..N) {
static if (Args.length == 1) {
get(args[0][i]);
} else {
auto input = readln.split;
static foreach (j; 0..Args.length) {
args[j][i] = input[j].to!(ElementType!(Args[j]));
}
}
}
}
void main()
{
int T; get(T);
while (T--) {
int N; get(N);
int[] as, bs;
auto d = N;
foreach_reverse (i; 2..N) {
if (i == 448 || i == 22 || i == 5 || i == 3 || i == 2) {
as ~= d;
as ~= d;
bs ~= i;
bs ~= i;
d = i;
} else {
as ~= i;
bs ~= d;
}
}
writeln(as.length);
foreach (i; 0..as.length) writeln(as[i], " ", bs[i]);
}
}
|
D
|
void main(){
int n = inelm();
( 800*n - (n/15).to!int()*200).writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
// 1要素のみの入力
T inelm(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] inln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
return ln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto ha = readln.split.to!(int[]);
auto H = ha[0];
auto A = ha[1];
writeln((H+A-1)/A);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n, m; rd(n, m);
auto g=new int[][](n, 0);
foreach(_; 0..m){
int a, b; rd(a, b);
a--; b--;
g[a]~=b; g[b]~=a;
}
auto c=new int[](n);
fill(c, -1);
bool dfs(int i, int w, int p=-1){
c[i]=w;
bool ret=true;
foreach(j; g[i])if(j!=p){
if(c[j]==-1) ret&=dfs(j, w^1, i);
else if((c[j]^w)==0) ret=false;
}
return ret;
}
if(dfs(0, 0)){
long w=0;
foreach(e; c)if(e==0) w++;
writeln(w*(long(n)-w)-m);
}else{
writeln(long(n)*(n-1)/2-m);
}
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import std.stdio, std.string, std.conv, std.math, std.regex;
void main()
{
auto n = readln.split.to!(int[]);
writeln((n[0] - 1) * (n[1] - 1));
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}
void main()
{
int[] a; readC(5, a);
int k; readV(k);
writeln(a[4]-a[0] <= k ? "Yay!" : ":(");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto T = readln.chomp.to!int;
foreach (_; 0..T) {
auto N = readln.chomp.to!long;
writeln(N);
}
}
|
D
|
void main() {
int n = readln.chomp.to!int;
string s = readln.chomp;
auto g = s.group.array;
string bra, ket;
foreach (i; 0 .. n) {
bra ~= '(';
ket ~= ')';
}
int l, r;
foreach (x; g) {
if (x[0] == '(') {
r += x[1].to!int;
} else {
int tmp = x[1].to!int;
if (r - tmp >= 0) {
r -= tmp;
} else {
l += tmp - r;
r = 0;
}
}
}
writeln(bra[0..l], s, ket[0..r]);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio,std.conv,std.string,std.algorithm;
void main(){
auto s=readln();
writeln("2018",s[4..10],);
}
|
D
|
// Cheese-Cracker: cheese-cracker.github.io
const ll PRIME = 10^^9 + 7;
void play(){
ll n, x, pos;
n = rd; x = rd; pos = rd;
ll clo = x-1, chi = n - x;
ll res = 1;
int lo = 0, hi = n.to!int;
while(lo < hi){
int midd = (lo + hi)/2;
show(midd, pos, clo, chi);
if(midd <= pos){
if(pos != midd){
res *= clo;
res %= PRIME;
--clo;
}
lo = midd + 1;
}else{
res *= chi;
res %= PRIME;
--chi;
hi = midd;
}
}
assert(lo - 1 == pos);
ll left = chi + clo;
show(left);
foreach(i; 1..left+1){
res *= i;
res %= PRIME;
}
writeln(res);
}
int main(){
long t = 1;
/* t = rd; // Toggle! */
while(t--) play(); // Let's play!
stdout.flush;
return 0;
}
/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x", long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.to!(dchar[]);
auto T = readln.to!(dchar[]);
dchar[dchar] smemo, tmemo;
foreach (i, s; S) {
auto t = T[i];
if (s in smemo && t in tmemo) {
if (smemo[s] != t || tmemo[t] != s) {
writeln("No");
return;
}
} else if (s in smemo || t in tmemo) {
writeln("No");
return;
} else {
smemo[s] = t;
tmemo[t] = s;
}
}
writeln("Yes");
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
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 H = RD;
auto W = RD;
auto h = RD;
auto w = RD;
writeln(H*W - (h*W+w*H-h*w));
stdout.flush();
}
|
D
|
import std.algorithm,
std.string,
std.range,
std.array,
std.stdio,
std.conv;
bool check(string s) {
if (s.length % 2) { return false; }
string a = s[0..$/2],
b = s[$/2..$];
return a == b;
}
void main() {
string s = readln.chomp;
size_t del = 1;
while (del < s.length - 1) {
if (check(s[0..$-del])) {
break;
} else {
del++;
}
}
writeln(s[0..$-del].length);
}
|
D
|
import std;
import core.bitop;
// dfmt off
ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
void aryWrite(T = long)(T[] ary){ ary.map!(x => x.text()).join(' ').writeln(); }
alias Pair = Tuple!(long, "H", long, "W");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long a, b, c, k;
scan(a, b, c, k);
writeln(k % 2 ? b - a : a - b);
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/abc168/tasks/abc168_a
import std.stdio;
import std.conv;
import std.string;
void main() {
int n = readln.chomp.to!int;
n = n%10;
switch(n) {
case 0, 1, 6, 8:
writeln("pon");
break;
case 3:
writeln("bon");
break;
default:
writeln("hon");
break;
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto K = readln.chomp.to!int;
auto S = readln.chomp;
if (S.length <= K) {
writeln(S);
} else {
writeln(S[0..K], "...");
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto s = sread();
bool b = s[0] == s[2];
writeln(b ? "Yes" : "No");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abc = readln.split.to!(int[]);
auto A = abc[0];
auto B = abc[1];
auto C = abc[2];
writeln((A < C && C < B) || (B < C && C < A) ? "Yes" : "No");
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto s=new char[][](n);
foreach(i; 0..n) s[i]=readln.chomp.to!(char[]);
long[char] cnt;
cnt['M']=cnt['A']=cnt['R']=cnt['C']=cnt['H']=0L;
foreach(i; 0..n){
auto c=s[i][0];
if(c in cnt) cnt[c]++;
}
char[int] p;
p[0]='M'; p[1]='A'; p[2]='R'; p[3]='C'; p[4]='H';
long fun(int i, char[] h){
if(h.length==3){
long ret=1;
foreach(c; h) ret*=cnt[c];
return ret;
}else if(i>=5){
return 0L;
}else{
long ret=0;
foreach(j; i..5)
ret+=fun(j+1, h~p[j]);
return ret;
}
}
writeln(fun(0, []));
}
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.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto data = readln.split.to!(int[]);
auto A = data[0], B = data[1], C = data[2];
if (A+B >= C-1) writeln(B+C);
else writeln( B + A+B+1 );
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.array;
import std.string;
import std.math;
import std.functional;
import std.range;
import std.typecons;
import std.format;
void main(string[] args) {
readln.solve.writeln;
}
auto solve(string line1) {
auto _ = line1.chomp.split.map!(to!int).array;
int a = _[0];
int b = _[1];
int c = _[2];
int d = _[3];
if (a + b > c + d) {
return "Left";
} else if (a + b < c + d) {
return "Right";
} else {
return "Balanced";
}
}
|
D
|
void main() {
auto O = rs, E = rs;
foreach(i, v; E) {
write(O[i]);
write(v);
}
if(O.length - E.length == 1) writeln(O[$-1]);
else writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
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
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long N = lread();
auto V = new long[](N);
auto W = new long[](N);
foreach (i; 0 .. N)
scan(V[i], W[i]);
auto memo = new long[][](min(2 ^^ 10 + 1, N + 1), 10 ^^ 5 + 2);
foreach (i; 1 .. memo.length)
{
foreach (j; 0 .. 10 ^^ 5 + 1)
{
memo[i][j] = memo[i][j].max(memo[i / 2][j]);
memo[i][min(j + W[i - 1], 10 ^^ 5 + 1)] = memo[i][min(j + W[i - 1], 10 ^^ 5 + 1)].max(
memo[i / 2][j] + V[i - 1]);
}
}
long solve(long v, long l)
{
long[] I;
long i = v;
while (memo.length <= i)
I ~= i, i /= 2;
// writeln(I);
long ans;
foreach (ulong state; 0UL .. 2UL ^^ I.length + 1)
{
long value, weight;
foreach (j; 0 .. I.length)
if ((1 << j) & state)
{
value += V[I[j] - 1];
weight += W[I[j] - 1];
}
if (l < weight)
continue;
ans = ans.max(memo[i][l - weight] + value);
}
return ans;
}
long Q = lread();
foreach (_; 0 .. Q)
{
long v, l;
scan(v, l);
solve(v, l).writeln();
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
int idx(char c) {
switch (c) {
case 'R': return 0;
case 'G': return 1;
default: return 2;
}
return -1;
}
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp;
auto MEMO = new int[][](N, 3);
foreach (i, c; S) {
if (i) foreach (j; 0..3) MEMO[i][j] += MEMO[i-1][j];
MEMO[i][idx(c)] += 1;
}
long r;
foreach (i; 1..N-1) {
auto m = S[i];
foreach (j; 0..i) {
if (S[j] == m) continue;
auto n = S[j];
char l;
if (m != 'R' && n != 'R') {
l = 'R';
} else if (m != 'G' && n != 'G') {
l = 'G';
} else {
l = 'B';
}
r += MEMO[N-1][idx(l)] - MEMO[i][idx(l)];
if (i + (i-j) < N && S[i + (i-j)] == l) r -= 1;
}
}
writeln(r);
}
|
D
|
/+ dub.sdl:
name "F"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.functional;
int n;
int[][] g;
int[] gsm;
int main() {
auto sc = new Scanner(stdin);
int m;
sc.read(n, m);
calc.init([[0, 1<<n], [0, n-1], [0, n-1]]);
g = new int[][](n, n);
foreach (i; 0..m) {
int a, b, c;
sc.read(a, b, c); a--; b--;
g[a][b] = g[b][a] = c;
}
gsm = new int[1<<n];
foreach (f; 0..1<<n) {
foreach (x; 0..n) {
if (!(f & (1<<x))) continue;
foreach (y; x+1..n) {
if (!(f & (1<<y))) continue;
gsm[f] += g[x][y];
}
}
}
writeln(calc((1<<n)-1, 0, n-1));
return 0;
}
int calcBase(int f, int s, int t) {
if (s > t) return calc(f, t, s);
assert(f & (1<<s));
assert(f & (1<<t));
int ans = 10^^9;
if (g[s][t]) {
for (int w = 0; w < f; w = ((w | ~f) + 1) & f) {
if (!(w & (1<<s))) continue;
if ( (w & (1<<t))) continue;
ans = min(ans, gsm[f] - gsm[w] - gsm[f^w] - g[s][t]);
}
}
foreach (z; 0..n) {
if (!(f & (1<<z))) continue;
if (z == s || z == t) continue;
for (int w = 0; w < f; w = ((w | ~f) + 1) & f) {
if (!(w & (1<<s))) continue;
if ( (w & (1<<z))) continue;
if ( (w & (1<<t))) continue;
int sm = calc(w|(1<<z), s, z) + calc(f^w, z, t);
ans = min(ans, sm + gsm[f] - gsm[w|(1<<z)] - gsm[f^w]);
}
}
return ans;
}
memoCont!calcBase calc;
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/modint.d */
// module dcomp.modint;
// import dcomp.numeric.primitive;
struct ModInt(uint MD) if (MD < int.max) {
import std.conv : to;
uint v;
this(int v) {this(long(v));}
this(long v) {this.v = (v%MD+MD)%MD;}
static auto normS(uint x) {return (x<MD)?x:x-MD;}
static auto make(uint x) {ModInt m; m.v = x; return m;}
auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}
auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}
auto opBinary(string op:"*")(ModInt r) const {return make((long(v)*r.v%MD).to!uint);}
auto opBinary(string op:"/")(ModInt r) const {return this*inv(r);}
auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}
static ModInt inv(ModInt x) {return ModInt(extGcd!int(x.v, MD)[0]);}
string toString() {return v.to!string;}
}
struct DModInt(string name) {
import std.conv : to;
static uint MD;
uint v;
this(int v) {this(long(v));}
this(long v) {this.v = ((v%MD+MD)%MD).to!uint;}
static auto normS(uint x) {return (x<MD)?x:x-MD;}
static auto make(uint x) {DModInt m; m.MD = MD; m.v = x; return m;}
auto opBinary(string op:"+")(DModInt r) const {return make(normS(v+r.v));}
auto opBinary(string op:"-")(DModInt r) const {return make(normS(v+MD-r.v));}
auto opBinary(string op:"*")(DModInt r) const {return make((long(v)*r.v%MD).to!uint);}
auto opBinary(string op:"/")(DModInt r) const {return this*inv(r);}
auto opOpAssign(string op)(DModInt r) {return mixin ("this=this"~op~"r");}
static DModInt inv(DModInt x) {
return DModInt(extGcd!int(x.v, MD)[0]);
}
string toString() {return v.to!string;}
}
template isModInt(T) {
const isModInt =
is(T : ModInt!MD, uint MD) || is(S : DModInt!S, string s);
}
T[] factTable(T)(size_t length) if (isModInt!T) {
import std.range : take, recurrence;
import std.array : array;
return T(1).recurrence!((a, n) => a[n-1]*T(n)).take(length).array;
}
T[] invFactTable(T)(size_t length) if (isModInt!T) {
import std.algorithm : map, reduce;
import std.range : take, recurrence, iota;
import std.array : array;
auto res = new T[length];
res[$-1] = T(1) / iota(1, length).map!T.reduce!"a*b";
foreach_reverse (i, v; res[0..$-1]) {
res[i] = res[i+1] * T(i+1);
}
return res;
}
T[] invTable(T)(size_t length) if (isModInt!T) {
auto f = factTable!T(length);
auto invf = invFactTable!T(length);
auto res = new T[length];
foreach (i; 1..length) {
res[i] = invf[i] * f[i-1];
}
return res;
}
/* 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/numeric/primitive.d */
// module dcomp.numeric.primitive;
import std.traits;
T pow(T, U)(T x, U n) if (!isFloatingPoint!T && isIntegral!U) {
return pow(x, n, T(1));
}
T pow(T, U)(T x, U n, T e) if (isIntegral!U) {
while (n) {
if (n & 1) e *= x;
x *= x;
n /= 2;
}
return e;
}
T lcm(T)(in T a, in T b) {
import std.numeric : gcd;
return a / gcd(a,b) * b;
}
T[3] extGcd(T)(in T a, in T b)
if (!isIntegral!T || isSigned!T)
{
if (b==0) {
return [1, 0, a];
} else {
auto e = extGcd(b, a%b);
return [e[1], e[0]-a/b*e[1], e[2]];
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/functional.d */
// module dcomp.functional;
struct memoCont(alias pred) {
import core.exception : RangeError;
import std.range, std.algorithm, std.conv;
import std.string : join;
import std.traits : ReturnType, ParameterTypeTuple, isIntegral;
import std.typecons : tuple, Tuple;
import std.meta;
alias R = ReturnType!pred;
alias Args = ParameterTypeTuple!pred;
static assert (allSatisfy!(isIntegral, Args));
static immutable N = Args.length;
int[2][N] rng;
int[N] len;
R[] dp;
bool[] used;
void init(int[2][N] rng) {
this.rng = rng;
len = rng[].map!(a => a[1]-a[0]+1).array;
int sz = len.reduce!"a*b";
dp = new R[sz];
used = new bool[sz];
}
R opCall(Args args) {
int idx, base = 1;
foreach (i, v; args) {
version(assert) {
if (v < rng[i][0] || rng[i][1] < v) {
throw new RangeError;
}
}
assert(rng[i][0] <= v && v <= rng[i][1]);
idx += base*(v - rng[i][0]);
base *= len[i];
}
if (used[idx]) return dp[idx];
used[idx] = true;
auto r = pred(args);
dp[idx] = r;
return r;
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
|
D
|
import std.stdio,std.conv,std.string,std.algorithm,std.array,std.math;
void main(){
auto sa=readln().split();
auto sb=readln().split();
auto sc=readln().split();
auto sd=readln().split();
int a,b,c,d,ans=0;
a=to!int(sa[0]);
b=to!int(sb[0]);
c=to!int(sc[0]);
d=to!int(sd[0]);
if(a<b)
ans+=a;
else
ans+=b;
if(c<d)
ans+=c;
else
ans+=d;
writeln(ans);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
T readNum(T)(){
return readStr.to!T;
}
T[] readNums(T)(){
return readStr.split.to!(T[]);
}
string readStr(){
return readln.chomp;
}
void main(){
auto s = readStr;
bool dif;
foreach(i; 0 .. 3){
if(s[i] == s[i+1]) dif = true;
}
writeln(dif ? "Bad" : "Good");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp;
int c;
foreach (i; 0..N-2) {
if (S[i..i+3] == "ABC") ++c;
}
writeln(c);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum A = "AKIHABARA";
void main()
{
auto S = readln.chomp;
size_t i, j;
while (i < S.length && j < A.length) {
if (S[i] == A[j]) {
++i; ++j;
} else if (A[j] == 'A') {
++j;
} else {
writeln("NO");
return;
}
}
writeln((i == S.length && j >= A.length-1) ? "YES" : "NO");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
int main() {
string str = chomp(readln);
int val = to!(int)(str);
int h = val/3600; val %= 3600;
int m = val/60; val %= 60;
int s = val;
writeln(h, ":", m, ":", s);
return 0;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s;
scan(s);
int n = s.length.to!int;
auto a = new int[](n + 1);
foreach (i ; 0 .. n) {
a[i + 1] = a[i] ^ (1<<(s[i] - 'a'));
}
debug {
writeln(a);
}
auto opt = new int[](n + 1);
auto dp = new int[](1<<26);
dp[] = n;
dp[0] = 0;
foreach (i ; 1 .. n + 1) {
int tmp = dp[a[i]];
foreach (j ; 0 .. 26) {
tmp = min(tmp, dp[a[i] ^ (1<<j)]);
}
opt[i] = tmp + 1;
dp[a[i]] = min(dp[a[i]], opt[i]);
}
debug {
writeln(opt);
}
writeln(opt[n]);
}
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;
import std.array;
import std.math;
import std.conv;
void main(){
string str;
while((str = readln()).length != 0){
string[] input = split(str);
int a = to!int(input[0]);
int b = to!int(input[1]);
writeln(digit(a + b));
}
}
uint digit(in int num){
if(num <= 0) return 0;
else
return cast(uint)log10(num) + 1;
}
|
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]);
ulong[] a, b, c;
foreach (i; 0..N)
{
auto tokens2 = split(my_readln());
{
a ~= to!ulong(tokens2[0]);
b ~= to!ulong(tokens2[1]);
c ~= to!ulong(tokens2[2]);
}
}
ulong[3][] bn;
bn.length = N;
bn[0][0] = a[0];
bn[0][1] = b[0];
bn[0][2] = c[0];
foreach (i; 0..N-1)
{
bn[i+1][0] = max(bn[i][1], bn[i][2]) + a[i+1];
bn[i+1][1] = max(bn[i][0], bn[i][2]) + b[i+1];
bn[i+1][2] = max(bn[i][0], bn[i][1]) + c[i+1];
}
writeln(max(max(bn[N-1][0], bn[N-1][1]), bn[N-1][2]));
stdout.flush();
/*}catch (Throwable e)
{
writeln(e.toString());
}
readln();*/
}
|
D
|
import std.stdio, std.string, std.ascii;
void main() {
string s = readln.chomp;
writeln( (s.length >= 6 && s.count!(isDigit) >= 1 && s.count!(isUpper) >= 1 && s.count!(isLower) >= 1) ? "VALID" : "INVALID" );
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long K, S;
scan(K, S);
long ans;
foreach (x; 0 .. K + 1)
foreach (y; 0 .. K + 1)
{
if (x + y <= S && S - (x + y) <= K)
{
ans++;
}
}
writeln(ans);
}
|
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 K = RD;
string s = "ACL";
string ans;
foreach (i; 0..K)
ans ~= s;
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
long n, m;
scan(n, m);
if (n > m) swap(n, m);
if (n == 1 && m == 1) {
writeln(1);
}
else if (n == 1) {
writeln(m - 2);
}
else {
writeln((n-2)*(m-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
|
import std.stdio;
import std.conv;
import std.array;
import std.string;
import std.algorithm;
void main() {
int n;
n = to!int(chomp(readln()));
int res = 0;
for(int i = 0; i < n; i++) {
string [] t;
int l, r;
t = chomp(readln()).split();
l = to!int(t[0]);
r = to!int(t[1]);
res += r-l+1;
}
writeln(res);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
int N, M;
string[100] NS, MS;
void main()
{
N = readln.chomp.to!int;
foreach (i; 0..N) NS[i] = readln.chomp;
M = readln.chomp.to!int;
foreach (i; 0..M) MS[i] = readln.chomp;
auto ns = NS[0..N];
auto ms = MS[0..M];
int max_p;
foreach (s; ns) {
int p;
foreach (n; ns) if (n == s) ++p;
foreach (m; ms) if (m == s) --p;
max_p = max(max_p, p);
}
writeln(max_p);
}
|
D
|
// import chie template :) {{{
static if (__VERSION__ < 2090) {
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format,
std.bitmanip, std.numeric;
} else {
import std;
}
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan(T...)(ref T args) {
foreach (ref arg; args) {
arg = next!(typeof(arg));
}
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
// alias {{{
alias Heap(T, alias less = "a < b") = BinaryHeap!(Array!T, less);
alias MinHeap(T) = Heap!(T, "a > b");
// }}}
// memo {{{
/*
- ある値が見つかるかどうか
<https://dlang.org/phobos/std_algorithm_searching.html#canFind>
canFind(r, value); -> bool
- 条件に一致するやつだけ残す
<https://dlang.org/phobos/std_algorithm_iteration.html#filter>
// 2で割り切れるやつ
filter!"a % 2 == 0"(r); -> Range
- 合計
<https://dlang.org/phobos/std_algorithm_iteration.html#sum>
sum(r);
- 累積和
<https://dlang.org/phobos/std_algorithm_iteration.html#cumulativeFold>
// 今の要素に前の要素を足すタイプの一般的な累積和
// 累積和のrangeが帰ってくる(破壊的変更は行われない)
cumulativeFold!"a + b"(r, 0); -> Range
- rangeをarrayにしたいとき
array(r); -> Array
- 各要素に同じ処理をする
<https://dlang.org/phobos/std_algorithm_iteration.html#map>
// 各要素を2乗
map!"a * a"(r) -> Range
- ユニークなやつだけ残す
<https://dlang.org/phobos/std_algorithm_iteration.html#uniq>
uniq(r) -> Range
- 順列を列挙する
<https://dlang.org/phobos/std_algorithm_iteration.html#permutations>
permutation(r) -> Range
- ある値で埋める
<https://dlang.org/phobos/std_algorithm_mutation.html#fill>
fill(r, val); -> void
- バイナリヒープ
<https://dlang.org/phobos/std_container_binaryheap.html#.BinaryHeap>
// 昇順にするならこう(デフォは降順)
BinaryHeap!(Array!T, "a > b") heap;
heap.insert(val);
heap.front;
heap.removeFront();
- 浮動小数点の少数部の桁数設定
// 12桁
writefln("%.12f", val);
- 浮動小数点の誤差を考慮した比較
<https://dlang.org/phobos/std_math.html#.approxEqual>
approxEqual(1.0, 1.0099); -> true
- 小数点切り上げ
<https://dlang.org/phobos/std_math.html#.ceil>
ceil(123.4); -> 124
- 小数点切り捨て
<https://dlang.org/phobos/std_math.html#.floor>
floor(123.4) -> 123
- 小数点四捨五入
<https://dlang.org/phobos/std_math.html#.round>
round(4.5) -> 5
round(5.4) -> 5
*/
// }}}
void main() {
auto cin = new Scanner;
long a, b, n;
cin.scan(a, b, n);
long maxi;
if (n < b) {
maxi = a * n / b;
} else {
maxi = a * (b - 1) / b;
auto t = min(b * 2 - 1, n);
maxi = max(maxi, a * t / b - a * (t / b));
}
writeln(maxi);
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int calc(char[] s, char mas) {
int n = s.length.to!int;
if (s.count(mas) == n) return 0;
char[] t = new char[n-1];
foreach (i; 0..n-1) {
t[i] = s[i];
if (s[i+1] == mas) t[i] = s[i+1];
}
return 1+calc(t, mas);
}
int main() {
auto sc = new Scanner(stdin);
char[] s;
sc.read(s);
int n = s.length.to!int;
int ans = 100;
foreach (c; 'a'..cast(char)('z'+1)) {
if (s.count(c) == 0) continue;
ans = min(ans, calc(s, c));
}
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);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
string str = readln();
write(toUpper(str));
}
|
D
|
import std.stdio;
void main(){
int n = 1000;
while(n--)
writeln("Hello World");
}
|
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 s = RD!(char[]);
auto K = RD;
foreach (i, c; s)
{
auto num = c - 'a';
if (num == 0) continue;
if (26-num > K) continue;
s[i] = 'a';
K -= 26-num;
}
if (K != 0)
{
auto num = s[$-1] - 'a';
debug writeln(num, " ", K, " ", ((num+K)%26));
s[$-1] = [cast(char)('a'+((num+K)%26))].to!string[0];
}
writeln(s);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n;
scanf("%d", &n);
int[] a = new int[n];
int[] b = new int[n];
bool same = true;
foreach (i; 0..n) {
scanf("%d%d", &a[i], &b[i]);
if (a[i] != b[i]) same = false;
}
if (same) {
writeln(0);
return;
}
long ans = 0;
int[] x;
foreach (i; 0..n) {
if (a[i] <= b[i]) {
ans += b[i];
} else {
x ~= b[i];
}
}
x.sort;
foreach (i; 1..x.length) {
ans += x[i];
}
writeln(ans);
}
|
D
|
import std.stdio;
import std.string;
void main() {
string ans = "WA";
char[] s = readln.strip.dup;
if (s[0] == 'A') {
ulong c = 0;
foreach(i, e; s[0..$ - 1]) {
if (e == 'C' && i > 1) {
c = i;
break;
}
}
if (c > 1) {
ans = "AC";
foreach(i, e; s) {
if (i == 0 || i == c)
continue;
if (e < 97 || e > 122) {
ans = "WA";
break;
}
}
}
}
writeln(ans);
}
|
D
|
import std.stdio,std.conv,std.string,std.array;
void main(){
auto x=readln.chomp.split;
int a = to!int(x[0]), b = to!int(x[1]);
if(a<b){writeln("a < b");}
if(a>b){writeln("a > b");}
if(a==b){writeln("a == b");}
}
|
D
|
import std.stdio, std.string, std.algorithm, std.range, std.conv, std.math;
void main() {
auto NK = readln.chomp.split.map!(to!int);
auto N = NK[0];
auto K = NK[1];
(K * pow(K - 1, N - 1)).writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.range;
//standard input/output
void main()
{
auto S = readln.chomp;
int res = 700;
if(S[0] == 'o') res += 100;
if(S[1] == 'o') res += 100;
if(S[2] == 'o') res += 100;
writeln(res);
/*
int res = 700;
foreach(i; S) if(i == 'o') res += 100;
writeln(res);
*/
/*
int res = 700;
res += 100 * S.count('o');
writeln(res);
*/
}
|
D
|
import std.string;
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
int n,s;
long[1001][11] dp;
void main(){
dp[0][0] = 1;
for(int i=0;i<=100;i++){
for(int j=9;j>=1;j--){
for(int k=0;k<=1000;k++){
if(0<=i+k&&i+k<=1000)
dp[j][i+k] += dp[j-1][k];
}
}
}
while(true){
auto ss = split(readln());
n = to!int(ss[0]);
s = to!int(ss[1]);
if(n == 0 && s == 0) break;
writeln(dp[n][s]);
}
}
|
D
|
void main()
{
string n = rdStr;
long len = n.length;
long total;
foreach (x; n)
{
total += x - '0';
}
max(total, (n[0]-'1')+9*(len-1)).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
|
void main() {
problem();
}
void problem() {
auto N = scan!ulong;
ulong solve() {
// Sum_{k=1..n} k/2 * floor(n/k) * floor(1 + n/k)
ulong ans;
foreach(k; 1..N+1) {
ulong x = N / k;
ans += x * (2*k + (x - 1) * k) / 2;
}
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 Queue = Tuple!(long, "from", long, "to");
// -----------------------------------------------
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int x = tmp[0], a = tmp[1], b = tmp[2];
if (a - b >= 0) {
"delicious".writeln;
} else if (a - b + x >= 0) {
"safe".writeln;
} else {
"dangerous".writeln;
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.conv, std.string, std.math, std.algorithm;
void main(){
auto ip = readln.split.to!(int[]);
if(ip[1] - ip[0] == ip[2] - ip[1]) "YES".writeln;
else "NO".writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
int[] buf = readln.chomp.split.to!(int[]);
int a = buf[0], b = buf[1];
int ans = a - 1 + (a <= b ? 1 : 0);
writeln(ans);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;
void main() {
string input = "4823108376";
while ((input = readln.chomp).length != 0) {
while (input.length > 1) {
string output;
for (int i = 0; i < input.length-1; i++) {
output ~= (((input[i] - '0')+(input[i+1] - '0'))%10).to!string;
}
input = output;
}
writeln(input);
}
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
static import std.ascii;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, K;
scan(N, K);
writeln(N - K + 1);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main()
{
string input = chomp(readln());
int output = to!(int)(input);
output = output*output*output;
writeln(output);
}
|
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);
scope(exit) sc.read!true;
int k;
long[] a;
sc.read(k, a);
long dw = 2, up = 2;
foreach_reverse(d; a) {
long mi = (dw + d - 1) / d * d;
dw = max(dw, mi);
long ma = up / d * d;
up = min(up, ma);
if (up < dw) {
writeln("-1");
return 0;
}
up += d-1;
}
writeln(dw, " ", up);
return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Program/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(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
import std.exception;
enforce(readSingle(x));
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
read!enforceEOF(args);
}
}
void read(bool enforceEOF = false, Args...)(auto ref Args args) {
import std.exception;
static if (args.length == 0) {
enforce(enforceEOF == false || !succ());
} else {
enforce(readSingle(args[0]));
read!enforceEOF(args);
}
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
long a, b;
scan(a, b);
if (13 <= a)
{
writeln(b);
}
else if (6 <= a)
{
writeln(b / 2);
}
else
{
writeln(0);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.algorithm;
void main() {
auto input = getStdin!(string[]);
string s = input[0] ~ input[0];
string p = input[1];
if (s.count(p) > 0) {
"Yes".writeln;
}
else {
"No".writeln;
}
}
T getStdin(T)() {
string[] cmd;
string line;
while ((line = chomp(stdin.readln())) != "") cmd ~= line;
return to!(T)(cmd);
}
|
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 MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Mame = Tuple!(long, "point", long, "number");
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 s = sread();
bool easy = true;
foreach (i; iota(s.length))
{
if (i % 2)
{
if (s[i] == 'R')
easy = false;
}
else
{
if (s[i] == 'L')
easy = false;
}
// (i + 1).writeln(" ", s[i]);
}
if (easy)
writeln("Yes");
else
writeln("No");
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.