code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;
void main() {
int n;
scan(n);
int ans = 1;
while (ans <= n / 2) {
ans *= 2;
}
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.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 H = RD;
auto A = RD;
writeln((H+A-1) / A);
stdout.flush;
debug readln;
}
|
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, m;
scan(n, m);
auto adj = new int[][](n, 0);
foreach (i ; 0 .. m) {
int ai, bi;
scan(ai, bi);
ai--, bi--;
adj[ai] ~= bi;
adj[bi] ~= ai;
}
bool nibu = true;
auto col = new int[](n);
col[] = -1;
col[0] = 0;
void dfs(int u) {
foreach (v ; adj[u]) {
if (col[v] == -1) {
col[v] = col[u] ^ 1;
dfs(v);
}
else if (col[v] == col[u]) {
nibu = false;
return;
}
}
}
dfs(0);
debug {
writeln(col);
}
int x = col.count!"a == 0".to!int;
int y = n - x;
long ans;
if (nibu) {
ans = 1L * x * y - m;
}
else {
ans = 1L * n * (n - 1) / 2 - m;
}
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;
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()
{
int a, e, k;
foreach (i; 0..6) {
if (i == 0) a = readln.chomp.to!int;
else if (i == 4) e = readln.chomp.to!int;
else if (i == 5) k = readln.chomp.to!int;
else readln;
}
if (e - a <= k) {
writeln("Yay!");
} else {
writeln(":(");
}
}
|
D
|
import std.stdio, std.string, std.conv;
void main(){
auto ip = readln.chomp.to!(dchar[]);
ip[3] = '8';
writeln(ip);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp.to!(char[]);
auto t = readln.chomp.to!(char[]);
bool[char] done;
auto f = true;
foreach (i; 0..s.length) {
if (s[i] != t[i]) {
if (done.get(s[i], true) && done.get(t[i], true)) {
foreach (j; i+1..s.length) {
if (s[j] == t[i]) {
s[j] = s[i];
} else if (s[j] == s[i]) {
s[j] = t[i];
}
}
s[i] = t[i];
} else {
f = false;
break;
}
}
done[s[i]] = false;
}
if (f) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
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 = lreads(N);
auto dp = new long[][](2, N + 1);
dp[0][] = dp[1][] = long.min;
dp[0][0] = 0;
foreach (i; 0 .. N)
{
dprint(dp[0][i], dp[1][i]);
if (dp[1][i] != long.min)
{
long a = A[i] + 1;
long r = (a < 2) ? 0 : a % 2;
dp[r][i + 1] = dp[r][i + 1].max(dp[1][i] + a / 2);
}
if (dp[1][i] != long.min)
{
long a = A[i];
long r = (a < 2) ? 0 : a % 2;
dp[r][i + 1] = dp[r][i + 1].max(dp[1][i] + a / 2);
}
if (dp[0][i] != long.min)
{
long a = A[i];
long r = (a < 2) ? 0 : a % 2;
dp[r][i + 1] = dp[r][i + 1].max(dp[0][i] + a / 2);
}
}
writeln(max(dp[0][N], dp[1][N]));
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
if (s.length % 2) s.length -= 1;
else s.length -= 2;
while (s[0..s.length/2] != s[s.length/2..$]) {
s.length -= 2;
}
writeln(s.length);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum next = [
"Sunny": "Cloudy",
"Cloudy": "Rainy",
"Rainy": "Sunny"
];
void main()
{
writeln(next[readln.chomp]);
}
|
D
|
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
void main()
{
switch (readln.chomp[$-1])
{
case '0', '1', '6', '8':
return "pon".writeln;
case '2', '4', '5', '7', '9':
return "hon".writeln;
default:
return "bon".writeln;
}
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;
class SegmentTree {
int[] table;
int N, table_size;
this(int n) {
N = n;
table_size = 1;
while (table_size < n) table_size *= 2;
table_size *= 2;
table = new int[](table_size);
}
void add(int pos, int num) {
add_rec(0, 0, table_size/2-1, pos, num);
}
void add_rec(int i, int left, int right, int pos, int num) {
table[i] += num;
if (left == right)
return;
auto mid = (left + right) / 2;
if (pos <= mid)
add_rec(i*2+1, left, mid, pos, num);
else
add_rec(i*2+2, mid+1, right, pos, num);
}
int sum(int pl, int pr) {
return sum_rec(0, pl, pr, 0, table_size/2-1);
}
int sum_rec(int i, int pl, int pr, int left, int right) {
if (pl > right || pr < left)
return 0;
else if (pl <= left && right <= pr)
return table[i];
else
return
sum_rec(i*2+1, pl, pr, left, (left+right)/2) +
sum_rec(i*2+2, pl, pr, (left+right)/2+1, right);
}
}
void main() {
alias Tuple!(int, "l", int, "r") Seg;
int N, M;
scanf("%d %d", &N, &M);
int l, r;
auto segs = new Seg[][](M+1);
foreach (i; 0..N) {
scanf("%d %d", &l, &r);
segs[r-l+1] ~= Seg(l, r);
}
auto st = new SegmentTree(M+2);
foreach (d; 1..M+1) {
foreach (s; segs[d-1]) {
N -= 1;
st.add(s.l, 1);
st.add(s.r+1, -1);
}
int ans = N;
for (int i = d; i <= M; i += d) {
ans += st.sum(0, i);
}
ans.writeln;
//writeln(d, " ", ans, " ", N);
}
}
|
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 N = scanElem;
auto S = readln.strip;
auto T = readln.strip;
long res;
foreach(i;1..N+1)
{
if(S[$-i..$]==T[0..i])
{
res=i;
}
}
writeln(N*2-res);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio,
std.range,
std.conv;
import std.math;
void main(){
int w, h;
while(true){
scanf("%d %d", &h, &w);
if(h == 0 && w == 0) break;
foreach(i; 0..h){
foreach(j; 0..w){
write(((i+j)%2) ? "." : "#");
}
writeln();
}
writeln();
}
}
|
D
|
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
{
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType))
{
str ~= s.to!(char[]).strip.split;
}
}
//Digit count---{{{
int DigitNum(int num) {
int digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
//}}}
//}}}
void main() {
Scanner sc = new Scanner;
int a, b;
sc.scan(a, b);
if ((a * b) % 2 == 0)
writeln("Even");
else
writeln("Odd");
}
|
D
|
import std.conv, std.stdio, std.string;
void main()
{
auto a = readln.chomp.to!int;
auto s = readln.chomp;
((3200 <= a) ? s : "red").writeln;
}
|
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
*/
// }}}
bool[100001] makePrimeTable() {
bool[100001] ret;
ret[2 .. $] = true;
for (size_t i = 2; i * i < ret.length; ++i) {
if (!ret[i]) continue;
for (size_t j = i + i; j < ret.length; j += i) {
ret[j] = false;
}
}
return ret;
}
void main() {
auto cin = new Scanner;
int q;
cin.scan(q);
enum isPrime = makePrimeTable;
long[] tot = new long[100001];
foreach (i; 0 .. tot.length) {
tot[i] = (i & 1) && isPrime[i] && isPrime[(i + 1) / 2];
}
foreach (i; 1 .. tot.length) {
tot[i] += tot[i - 1];
}
foreach (i; 0 .. q) {
int l, r;
cin.scan(l, r);
writeln(tot[r] - tot[l - 1]);
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const tmp = readln.split.to!(int[]);
writeln(tmp[1] % tmp[0] == 0 ? tmp[0] + tmp[1] : tmp[1] - tmp[0]);
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.numeric;
void main() {
string x;
scan(x);
int st, ans;
foreach (ch ; x) {
if (ch == 'S') {
st++;
}
else {
if (st > 0) {
st--;
}
else {
ans++;
}
}
}
ans += st;
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.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n, a, b, c, d;
scan(n, a, b, c, d);
auto s = readln.chomp;
a--, b--, c--, d--;
bool ac, bd;
ac = bd = true;
foreach (i ; a .. c) {
if (s[i] == '#' && s[i + 1] == '#') {
ac = false;
break;
}
}
foreach (i ; b .. d) {
if (s[i] == '#' && s[i + 1] == '#') {
bd = false;
break;
}
}
bool dc;
if (c < d) {
dc = true;
}
else {
foreach (i ; b - 1 .. d) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
dc = true;
break;
}
}
}
yes(ac && bd && dc);
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long a, b, c, d, k;
scan(a, b, c, d, k);
long h;
if (b < d)
h += (c - a) * 60 + (d - b);
else
h += (c - a - 1) * 60 + (d - b) + 60;
writeln(h - k);
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import std.stdio;
import std.conv;
import std.math;
void main() {
double n;
scanf("%lf", &n);
auto y = n / 1.08;
auto n2 = n.to!int;
auto y2 = y.ceil.to!int;
if (floor(y2 * 1.08).to!int == n2 || floor((y2+1) * 1.08).to!int == n2) {
y2.write;
}
else {
":(".write;
}
}
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm;
void main() {
auto a = readln.split.map!(to!int);
writeln("a ", a[0] == a[1] ? "==" : (a[0] < a[1] ? "<" : ">"), " 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()
{
auto s = sread();
auto tmp = new long[](4); //北西南東
foreach (i; 0 .. s.length)
{
if (s[i] == 'N')
{
tmp[0] = 1;
}
else if (s[i] == 'W')
{
tmp[1] = -1;
}
else if (s[i] == 'S')
{
tmp[2] = -1;
}
else if (s[i] == 'E')
{
tmp[3] = 1;
}
}
// writeln(tmp);
if (tmp[0] + tmp[2] == 0 && tmp[1] + tmp[3] == 0)
{
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 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 q = RD!int;
auto ans = new long[](q);
foreach (i; 0..q)
{
auto n = RD;
long cnt;
while (n != 1)
{
if (n % 2 == 0)
{
n /= 2;
}
else if ((n * 2) % 3 == 0)
{
n = (n * 2) / 3;
}
else if ((n * 4) % 5 == 0)
{
n = (n * 4) /5;
}
else
{
cnt = -1;
break;
}
++cnt;
}
ans[i] = cnt;
}
foreach (e; ans)
writeln(e);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n;
scan(n);
int[string] a;
foreach (i ; 0 .. n) {
auto s = readln.chomp;
if (s in a) {
a[s]++;
}
else {
a[s] = 1;
}
}
int m;
scan(m);
foreach (i ; 0 .. m) {
auto s = readln.chomp;
if (s in a) {
a[s]--;
}
else {
a[s] = -1;
}
}
int ans;
foreach (i ; a.byValue) {
ans = max(ans, i);
}
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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long a, b, n;
scan(a, b, n);
writeln((a * min(b - 1, n) / b) - a * ((min(b - 1, n) / 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
|
import std.algorithm;
import std.range;
import std.stdio;
import std.string;
immutable int letters = 26;
void main ()
{
string s;
while ((s = readln.strip) != "")
{
auto a = new int [] [letters];
foreach (int i, c; s.map !(x => x - 'a').array)
{
a[c] ~= i;
}
int n = cast (int) (s.length);
int res = int.max;
foreach (b; a.filter !(x => !x.empty))
{
debug {writeln (b);}
int cur = b[0];
foreach (j; 1..b.length)
{
cur = max (cur, (b[j] - b[j - 1] - 1));
}
cur = max (cur, n - b[$ - 1] - 1);
res = min (res, cur);
}
writeln (res);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;
void main() {
int n, m;
scan(n, m);
auto cnt = new int[](n);
auto red = new bool[](n);
cnt[] = 1;
red[0] = 1;
foreach (i ; 0 .. m) {
int xi, yi;
scan(xi, yi);
xi--, yi--;
if (red[xi]) {
red[yi] = 1;
if (cnt[xi] - 1 == 0) red[xi] = 0;
}
cnt[xi]--;
cnt[yi]++;
}
auto ans = iota(n).count!(i => red[i] && cnt[i] > 0);
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
|
void main(){
int n = _scan();
int[string] dic;
foreach(i; 0..n){
dic[readln().chomp()]++;
}
dic.length.writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio,std.string,std.conv;
int main()
{
string s;
while((s = readln.chomp).length != 0)
{
string[] _s = s.split(" ");
int a = _s[0].to!int;
int b = _s[1].to!int;
int n = _s[2].to!int;
int ans = 0;
a %= b;
foreach(i;0..n)
{
a *= 10;
ans += (a/b);
a %= b;
}
ans.writeln;
}
return 0;
}
|
D
|
void main(){
string s = readln().chomp();
s.count('1').writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
long n; rd(n);
long m=1;
while(m<n){
if((n&m)!=m){
writeln(m);
return;
}
m*=2;
}
writeln(n+1);
}
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.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.ascii;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
bool calc(string s) {
if (s[0] != 'A') return false;
if (s[2..$-1].count!(c => c == 'C') != 1) return false;
if (s.count!(c => isUpper(c)) > 2) return false;
return true;
}
void main() {
auto s = readln.chomp;
writeln(calc(s) ? "AC" : "WA");
}
|
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;
alias C = Tuple!(int, int);
immutable C[] dirs = [
tuple (1, 0),
tuple (-1, 0),
tuple (0, 1),
tuple (0, -1)
];
enum inf = int.max;
void main() {
auto s = readln.strip.splitter;
immutable int h = s.front.to!int;s.popFront;
immutable int w = s.front.to!int;
auto a = new char[][h];
foreach (j; 0 .. h) {
auto z = readln;
a[j] = z[0 .. w].dup;
}
auto d = new int[][](h, w);
void clear () {
foreach (j; 0 .. h) foreach (i; 0 .. w) d[j][i] = inf;
}
C[] bfs (in int sy, in int sx, out int dy, out int dx, out int dist) {
d[sy][sx] = 0;
C[] q;
q ~= C (sy, sx);
int left = 0;
while (left < q.length) {
auto t = q[left++];
immutable int y = t[0], x = t[1];
dy = y;
dx = x;
foreach (const ref p; dirs) {
immutable j = y + p[0];
if (j < 0 || j >= h) continue;
immutable i = x + p[1];
if (i < 0 || i >= w) continue;
if (d[j][i] < inf || a[j][i] == '#') continue;
q ~= C (j, i);
d[j][i] = d[y][x] + 1;
}
}
dist = d[dy][dx];
return q;
}
int res;
foreach (j; 0 .. h) foreach (i; 0 .. w) if (a[j][i] != '#') {
int y, x, dd;
clear ();
bfs (j, i, y, x, dd);
res = max (res, dd);
}
/*
C[] u;
clear ();
foreach (j; 0 .. h) foreach (i; 0 .. w) if (a[j][i] != '#' && d[j][i] == inf) {
int y, x, dd;
bfs (j, i, y, x, dd);
u ~= tuple (y, x);
}
clear ();
int res;
foreach (p; u) {
int y, x, dd;
res = max (res, dd);
}
*/
writeln (res);
}
|
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;
void main()
{
auto dp = new long[][](11, 1001);
dp[0][0] = 1;
foreach (i; 0..101) {
foreach_reverse (j; i..1001) {
foreach_reverse (k; 1..10) {
dp[k][j] += dp[k-1][j-i];
}
}
}
while (1) {
auto ns = readln.split.map!(to!int);
if (!(ns[0] | ns[1])) break;
dp[ns[0]][ns[1]].writeln;
}
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
long a, b, x;
rd(a, b, x);
long mod = 1_000_000_000 + 7;
auto k = (x - a + 1 + (a - b - 1)) / (a - b);
if (k < 0) {
k = 0;
}
auto ans = x % mod + (k % mod) * (b % mod);
writeln(ans % mod);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
for(int n; 0!=(n=readln().chomp().to!int()); )
{
immutable a = iota(n).map!(_=>readln().chomp().to!int()).array().idup;
int m=int.min;
auto dp = new int[][](n,n);
foreach(i;0..n)
foreach(j;i..n)
m=max(m,dp[i][j]=(i<j?dp[i][j-1]:0)+a[j]);
writeln(m);
}
}
|
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 N = RD;
auto arr = new long[](N+1);
arr[] = 1;
foreach (i; 2..N+1)
{
long x = i;
while (x <= N)
{
++arr[x];
x += i;
}
}
long ans;
foreach (i; 1..N+1)
{
ans += i * arr[i];
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/abc134/tasks/abc134_c
// greedy
import std.algorithm;
import std.stdio;
import std.conv;
import std.string;
void main() {
const long n = readln.chomp.to!long;
long[] as = new long[n];
foreach(i; 0..n) {
as[i] = readln.chomp.to!long;
}
const long maxima = as.maxCount[0];
const long count = as.maxCount[1];
long second = -1;
for(long i = 0; i < n; i++) {
if(as[i] > second && as[i] != maxima) {
second = as[i];
}
}
foreach(item; as) {
if(item == maxima && count == 1) {
second.writeln;
continue;
}
maxima.writeln;
}
}
|
D
|
import std.stdio, std.string, std.conv, std.math;
void main() {
auto ip = readln.split.to!(int[]);
if(0 <= (ip[1] - ip[2])){
writeln("delicious");
} else if(ip[0] >= abs(ip[1] - ip[2])){
writeln("safe");
} else {
writeln("dangerous");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto abc = readln.chomp.split(" ").map!(to!int);
writeln(
abc[1] - abc[0] == abc[2] - abc[1] ? "YES" : "NO"
);
}
|
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(b < a ? a-1 : a);
stdout.flush();
debug readln();
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "begin", long, "end");
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();
if(s.remove_before || s.remove_bitween)
writeln("YES");
else
writeln("NO");
}
bool remove_before(string s)
{
auto test = s[$ - 7 .. $];
// writeln(test);
if (test == "keyence")
return true;
return false;
}
bool remove_bitween(string s)
{
auto lim = iota(1, 8);
foreach (i; lim)
{
auto test = s[0 .. i] ~ s[$ - "keyence".length + i .. $];
// test.writeln();
if(test == "keyence")
return true;
}
return false;
}
|
D
|
void main() {
long n = readln.chomp.to!long;
long[] a = new long[5];
foreach (i; 0 .. 5) {
a[i] = readln.chomp.to!long;
}
long m = a.reduce!min;
writeln((n + m - 1) / m + 4);
}
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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
string[] ST = new string[](2);
scan(ST[0], ST[1]);
string ans;
foreach (i; 0 .. 2 * N)
{
ans ~= ST[i & 1][i / 2];
}
writeln(ans);
}
|
D
|
/+ dub.sdl:
name "C"
dependency "dcomp" version=">=0.3.2"
lflags "-stack_size" "100000000"
+/
import std.algorithm, std.conv, std.range, std.stdio;
// import dcomp.scanner;
int[128][1001] dp;
int calc(int n, int d) {
if (n == 1) return d;
if (dp[n][d] != -1) return dp[n][d];
int ans = 0;
foreach (i; 0..128) {
ans = max(ans, calc(n-1, d^i) + i);
}
return dp[n][d] = ans;
}
int main(string[] argv) {
auto sc = new Scanner();
int t;
sc.read(t);
foreach (i; 0..1001) {
dp[i][] = -1;
}
foreach (unused; 0..t) {
int n, d;
sc.read(n, d);
writeln(calc(n, d));
}
return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File, stdin;
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 = stdin) {
this.f = f;
}
string[] buf;
private bool succ() {
while (!buf.length) {
if (f.eof) return false;
buf = f.readln.split;
}
return true;
}
private bool readSingle(T)(ref T x) {
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
//string or char[10] etc
x = buf.front;
buf.popFront;
} else {
static if (isStaticArray!T) {
//static
assert(buf.length == T.length);
}
x = buf.map!(to!E).array;
buf.length = 0;
}
} else {
x = buf.front.to!T;
buf.popFront;
}
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);
}
}
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3]));
assert(equal(c[], "ab"));
assert(equal(d, "cde"));
assert(e == 1.0);
assert(equal(f, [1.0, 2.0]));
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/+---test
4
10 30 40 20
---+/
/+---test
2
10 10
---+/
/+---test
6
30 10 60 10 60 50
---+/
void main(string[] args) {
readln;
const heights = readln.split.map!(to!long).array;
const N = heights.length;
auto dp = new long[N];
foreach (i; 0..N-1) {
dp[i+1] = dp[i] + abs(heights[i] - heights[i+1]);
if (i >= 1) {
dp[i+1] = dp[i+1].min(dp[i-1] + abs(heights[i-1] - heights[i+1]));
}
}
dp[$-1].writeln;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n;
scan(n);
auto s = readln.chomp;
int rc, bc;
foreach (ch ; s) {
if (ch == 'R') rc++;
else bc++;
}
auto ans = rc > bc;
writeln(ans ? "Yes" : "No");
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.stdio;
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;
void main()
{
auto n = readln.chomp.to!int;
auto area = new int[][](n+1, n+1);
foreach (i; 1..n+1) {
auto tmp = readln.chomp.split.map!(to!int).array;
foreach (j; 1..n+1) {
area[i][j] = tmp[j-1] + area[i-1][j] + area[i][j-1] - area[i-1][j-1];
}
}
auto res = int.min;
foreach (i; 1..n+1) {
foreach (j; 1..n+1) {
foreach (k; 0..i) {
foreach (l; 0..j) {
res = max(res, area[i][j] - area[k][j] - area[i][l] + area[k][l]);
}
}
}
}
res.writeln;
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
immutable long MOD = 10^^9 + 7;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto K = s[1];
long ans = 0;
foreach (i; K..N+2) {
long mn = 1L * i * (i - 1) / 2;
long mx = 1L * N * (N + 1) / 2 - 1L * (N - i) * (N - i + 1) / 2;
ans += (mx - mn + 1) % MOD;
ans %= MOD;
}
ans.writeln;
}
|
D
|
import core.stdc.stdio;
import std.algorithm;
void main(){
int n;
scanf("%d",&n);
int[] a = new int[n];
long sum;
foreach(ref v;a){
scanf("%d",&v);
sum+=v;
}
bool Solve(long m){
int g=114514;
int c,e,f;
long cs,es,fs=sum;
while(c<g){
bool ok = true;
while(cs<m){
cs+=a[e];
es-=a[e];
e=(e+1)%n;
if(e==c)
ok=false;
}
if(!ok)
goto next;
while(es<m){
es+=a[f];
fs-=a[f];
f=(f+1)%n;
if(f==c)
ok=false;
}
if(!ok)
goto next;
if(fs>=m)
return true;
next:;
g=min(g,e);
fs+=a[c];
cs-=a[c];
c++;
}
return false;
}
long l=0;
long r=sum/3+1;
while(r-l>1){
long m=(l+r)/2;
if(Solve(m))
l=m;
else
r=m;
}
printf("%lld\n",l);
}
|
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 N = scanElem;
auto A = scanElem;
auto B = scanElem;
writeln(min(N*A,B));
}
|
D
|
void main(){
int a, b;
scanf("%d %d", &a, &b);
if(a==1)a=100; if(b==1)b=100;
if(a>b)writeln("Alice");
else if(a<b)writeln("Bob");
else writeln("Draw");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
// 1要素のみの入力
T inelm(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] inln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
return ln;
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n, k; rd(n, k);
auto s=readln.chomp.to!(char[]);
int[char] freq;
foreach(c; s){
if(c in freq) freq[c]++;
else freq[c]=1;
}
int mn=10^^9;
for(char c='A'; c<'A'+k; c++){
if(c in freq) mn=min(mn, freq[c]);
else mn=min(mn, 0);
}
writeln(mn*k);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
|
D
|
import std.stdio,std.conv,std.algorithm,std.array;
int[] raia(){ return readln().split().map!(to!int).array; } //read as int[]
string[] rasa(){ return readln().split(); } //read as string[]
void main()
{
auto it = raia();
auto W = it[0]; auto H = it[1];
auto x = it[2]; auto y = it[3]; auto r = it[4];
if( x-r>= 0 && x+r <= W &&
y-r>= 0 && y+r <= H )
{ writeln("Yes"); }
else
{ writeln("No"); }
}
|
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 nm = readNums!int;
if(nm[0] == nm[1]){
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
/+ dub.sdl:
name "C"
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);
long x, y;
sc.read(x, y);
int c = 1;
while (x*2 <= y) {
x *= 2;
c++;
}
writeln(c);
return 0;
}
/* IMPORT /Users/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 /Users/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 /Users/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 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);
}
}
}
/*
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.array, std.conv, std.string;
void main() {
string[] input = split(readln());
int a = to!int(input[0]), b = to!int(input[1]), c = to!int(input[2]);
int ans = 0;
for (int i = a; i <= b; ++i) {
if (c % i == 0) 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; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
long ans;
foreach (i; 0..S.length/2)
{
if (S[i] != S[$-1-i])
++ans;
}
writeln(ans);
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;
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;
}
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
long x;
scan(x);
bool check(long y) {
long c = 11 * (y / 2);
if (y % 2) c += 6;
return c >= x;
}
long ng = 0, ok = x;
while (abs(ok - ng) > 1) {
auto md = (ok + ng) / 2;
(check(md) ? ok : ng) = md;
}
auto ans = ok;
writeln(ans);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
void main() {
int n = readln.chomp.to!int;
for (int i = 0; i < n; i++) {
string X = readln.chomp;
string Y = readln.chomp;
lcs(X, Y).writeln;
}
}
int lcs(string x, string y) {
int[][] dp = new int[][](y.length + 1, x.length + 1);
for (int i = 1; i <= y.length; i++) {
for (int j = 1; j <= x.length; j++) {
if (x[j - 1] == y[i - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
return dp[$ - 1][$ - 1];
}
|
D
|
void main() {
writeln(-readln.chomp.to!int + 2 * readln.chomp.to!int);
}
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() {
(rs.startsWith("YAKI") ? "Yes" : "No").writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
void main() {
auto N = ri;
auto S = rs;
if(S[0..N/2] == S[N/2..$]) writeln("Yes");
else 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;
import std.string;
import std.conv;
import std.algorithm;
void main() {
auto s = readln().split()[0].to!int();
if (s==4 || s==2 || s==1) { writeln("4"); return; }
auto i = 1;
while(true) {
if (s == 1) { writeln(i+1); return; }
i++;
s = f(s);
}
}
int f(int n) {
return n%2 == 0 ? n/2 : 3*n + 1;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
alias Pair = Tuple!(int, "a", int, "b");
void main() {
int A, B;
scan(A, B);
auto ans = max(0, A - 2*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);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto a = readln.splitter.map !(to !(int)).array;
writeln (min (a[0], a[1]) < max (a[2], a[3]) &&
min (a[2], a[3]) < max (a[0], a[1]) ? "YES" : "NO");
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long A, B, C;
scan(A, B, C);
long c;
foreach_reverse (i; 1 .. 101)
{
if (A % i == 0 && B % i == 0)
{
c++;
if (C == c)
{
writeln(i);
return;
}
}
}
}
|
D
|
import std.stdio;
void main()
{
for (int i = 1; i <= 9; i++){
for (int j = 1; j <= 9; j++){
writeln(i, "x", j, "=", i * j);
}
}
}
|
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;
void main(){
auto ip = readln.split.to!(int[]);
writeln((ip[0] - 1)*(ip[1] - 1));
}
//writeln("滲み出す混濁の紋章 不遜なる狂気の器 湧き上がり 否定し 痺れ 瞬き 眠りを妨げる 爬行する鉄の王女 絶えず自壊する泥の人形 結合せよ 反発せよ 地に満ち己の無力を知れ 破道の九十 黒棺")
|
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;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
long n = read.to!long;
long[] as = readln.split.map!(to!long).array;
int oddcount;
int x4count;
foreach(a; as){
if(a % 4 == 0) x4count += 1;
if(a % 2 == 1) oddcount += 1;
}
string ans;
if(oddcount + x4count == n){
if(oddcount - 1 <= x4count) ans = "Yes";
else ans = "No";
}
else{
if(oddcount <= x4count) ans = "Yes";
else ans = "No";
}
ans.writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
int maximizeHapiness(int money)
{
int hapiness500 = money / 500 * 1000;
int hapiness5 = (money%500) / 5 * 5;
return hapiness500 + hapiness5;
}
void main(){
string[] input = split(readln());
auto money = to!int(input[0]);
writeln(maximizeHapiness(money));
}
|
D
|
void main() {
string[] tmp = readln.split;
int a = tmp[0].to!int, b = tmp[2].to!int;
string op = tmp[1];
writeln(op == "+" ? a + b : 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.numeric;
import std.container;
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.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 N = RD;
long ans;
foreach (i; 1..N)
{
auto cnt = (N-1) / i;
ans += cnt;
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
ElementType!R x = r.front;
r.popFront();
foreach (y; r) x.amax(y);
return x;
}
auto minE(R)(R r) if (isInputRange!R) {
ElementType!R x = r.front;
r.popFront();
foreach (y; r) x.amin(y);
return x;
}
/*}}}*/
/+---test
5
4 2 5 1 3
---+/
/+---test
4
4 3 2 1
---+/
/+---test
6
1 2 3 4 5 6
---+/
/+---test
8
5 7 4 2 6 8 1 3
---+/
/+---test
1
1
---+/
void main(string[] args) {
const N = readln.chomp.to!long;
const P = readln.split.map!(to!long).array;
long m = long.max, ans;
foreach (p; P) {
if (p <= m) ++ans;
m.amin(p);
}
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) { x.modm(y.modpow(mod - 2)); }
void main()
{
writeln("NO");
stdout.flush;
debug readln;
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.exception;
auto args=readln.split.to!(int[]);
auto n=args[0], a=args[1], b=args[2];
int mx=0;
for(int ka=1; ka<n; ka++){
auto kb=n-ka;
auto xa=a/ka, xb=b/kb;
mx=max(mx, min(xa, xb));
}
writeln(mx);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) write(e, " ");
writeln();
}
|
D
|
//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;
enum string vowels = "aeiou";
void main() {
int k = readln.strip.to!int;
char[] z;
z.reserve (k);
for (int h = 5; h * h <= k; ++h) {
if (k % h == 0) {
int w = k / h;
foreach (i; 0 .. h) {
foreach (j; 0 .. w) {
z ~= vowels[(i + j) % 5];
}
}
writeln (z);
return;
}
}
writeln (-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, std.bitmanip;
void main() {
auto N = readln.chomp.to!long;
if (N % 2 == 0) {
writeln(N / 2);
return;
}
long f = 2;
for (; f * f <= N; ++f) {
if (N % f == 0) {
writeln(1 + (N - f) / 2);
return;
}
}
writeln(1);
}
|
D
|
import std.stdio;
void main()
{
int n;
scanf("%d", &n);
printf("%lld\n", 1 + 6L * n * (n + 1) / 2);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
void main() {
auto X = readln.chomp.to!long;
foreach (a; 1..X+1) {
foreach (b; 1..X+1) {
if (a % b == 0 && a * b > X && a < b * X) {
writeln(a, " ", b);
return;
}
}
}
writeln(-1);
}
|
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!long;
long s;
foreach (i; 1..N+1) {
if (i%3 != 0 && i%5 != 0) s += i;
}
writeln(s);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range, core.bitop;
void main()
{
auto PP = new long[](10^^5*2+1);
foreach (i; 1..10^^5*2+1) {
PP[i] = PP[i % popcnt(i)] + 1;
}
auto N = readln.chomp.to!int;
auto X = readln.chomp;
long bc;
foreach (b; X) if (b == '1') ++bc;
auto cs = new long[][](N, 2);
auto xs = new long[][](N, 2);
long x1 = 1, x2 = 1;
foreach_reverse (i, b; X) {
if (i != N-1) {
cs[i][0] = cs[i+1][0];
cs[i][1] = cs[i+1][1];
}
if (b == '1') {
if (bc > 1) (cs[i][0] += x1) %= (bc-1);
(cs[i][1] += x2) %= (bc+1);
}
xs[i][0] = x1;
xs[i][1] = x2;
if (bc > 1) (x1 *= 2) %= (bc-1);
(x2 *= 2) %= (bc+1);
}
x1 = 0;
x2 = 0;
foreach (i, b; X) {
if (b == '1') {
if (bc == 1) {
writeln(0);
} else {
auto n = x1 + (i == N-1 ? 0 : cs[i+1][0]);
writeln(PP[n % (bc-1)] + 1);
}
if (bc > 1) (x1 += xs[i][0]) %= (bc-1);
(x2 += xs[i][1]) %= (bc+1);
} else {
auto n = x2 + xs[i][1] + (i == N-1 ? 0 : cs[i+1][1]);
writeln(PP[n % (bc+1)] + 1);
}
}
}
|
D
|
module app;
import std.stdio;
import std.algorithm;
import std.range;
import std.array;
import std.string;
import std.conv;
void main(string[] args) {
auto five_hund = readln.chop.to!int;
auto one_hund = readln.chop.to!int;
auto fifty = readln.chop.to!int;
immutable auto target_yen = readln.chop.to!int;
int answer;
foreach(fh; iota(0, five_hund+1)) {
foreach(oh; iota(0, one_hund+1)) {
foreach(f; iota(0, fifty+1)) {
if(fh*500 + oh*100 + f*50 == target_yen){
answer++;
}
}
}
}
writeln(answer);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto hw = readln.split.to!(int[]);
auto h = hw[0];
auto w = hw[1];
auto ab = readln.split.to!(int[]);
auto a = ab[0];
auto b = ab[1];
writeln(h * w - (h / a) * (w / b) * a * b);
}
|
D
|
import std.algorithm;
import std.range;
import std.ascii;
import std.array;
import std.container;
import std.conv;
import std.numeric;
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;
}
long modPow(long mod)(long x, long n) {
if (n == 0) return 1;
if (n % 2 == 0) return modPow!mod(x * x % mod, n / 2);
return x * modPow!mod(x % mod, n - 1) % mod;
}
long extgcd(long a, long b, ref long x, ref long y) {
long g = a; x = 1; y = 0;
if (b != 0) {
g = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
return g;
}
long inverse(long mod)(long v) {
long x, y;
if (extgcd(v, mod, x, y) == 1) return (x + mod) % mod;
return 0;
}
class RollingHash(long[] Ps, long mod) {
string s;
int N;
long[][] H;
this(in string s) {
this.s = s;
this.N = s.size;
this.H = new long[][](Ps.length, N + 1);
foreach (k, P; Ps) {
long x = 1;
foreach (int i, c; s) {
H[k][i + 1] = (H[k][i] + x * cast(int)(c - 'a' + 1)) % mod;
x = (x * P) % mod;
}
}
}
long[] hash(int l, int r) { // [l, r)
auto hs = iota(0, Ps.length, 1).map!(delegate(k) {
long h = (H[k][r] - H[k][l] + mod) % mod;
return h * modPow!mod(inverse!mod(Ps[k]), l) % mod;
});
return hs.array;
}
}
void main() {
int N, M; scanf("%d %d\n", &N, &M);
auto s = readln.chomp;
auto hasher = new RollingHash!([991, 9999991], cast(long)(1e9+7))(s);
int l = 0, r = 1;
bool[long[]] appeared;
foreach (_; 0 .. M) {
auto q = readln.chomp;
switch (q) {
case "L++": l++; break;
case "L--": l--; break;
case "R++": r++; break;
case "R--": r--; break;
default: assert(false);
}
appeared[hasher.hash(l, r).idup] = true;
}
writeln(appeared.keys.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 N = RD;
auto R = RD;
writeln(N >= 10 ? R : R + 100 * (10 - N));
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;
void main() {
long N, A, B;
scan(N, A, B);
auto d = abs(A - B);
if (d % 2 == 0) {
writeln(d / 2);
return;
}
auto ans = min(A - 1, N - B) + (d + 1) / 2;
writeln(ans);
}
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
|
D
|
module app;
import core.bitop;
import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
struct Input
{
long h;
}
void parseInput(T)(out Input input, T file)
{
with (file) with (input)
{
h = readln().strip().to!long;
}
}
struct Output
{
}
auto main2(Input* input)
{
return beat(input.h);
}
long beat(long n)
{
if (n == 1)
return 1;
else
return 1 + beat(n / 2) * 2;
}
unittest { writeln("begin unittest"); }
unittest // example1
{
string example =
`2`;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
writeln(result);
assert(result == 3);
}
unittest // example2
{
string example =
`4`;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
writeln(result);
assert(result == 7);
}
unittest // example3
{
string example =
`1000000000000`;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
writeln(result);
assert(result == 1099511627775);
}
unittest { writeln("end unittest"); }
void parseExample(out Input input, string example)
{
struct Adapter
{
string[] _lines;
this(string input) { _lines = input.splitLines(); }
string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
}
parseInput(input, Adapter(example));
}
void main()
{
Input input = void;
parseInput(input, stdin);
auto result = main2(&input);
writeln(result);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
auto data = readln().split();
auto A = data[0].to!int(), B = data[1].to!int(), C = data[2].to!int();
writeln(min(B/A, C));
}
|
D
|
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
int n = readln.chomp.to!int;
long min = 1;
long sum = readln.chomp.to!long - 1;
foreach (i; 1..n) {
long a = readln.chomp.to!long;
sum += (a - 1) / (min + 1);
if (min + 1 == a) {
min++;
}
}
sum.writeln;
}
|
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 N = RD;
auto K = RD;
auto cnt = new long[](10^^5+1);
foreach (i; 0..N)
{
auto a = RD;
auto b = RD;
cnt[a] += b;
}
long pos, ans;
foreach (i, e; cnt)
{
pos += e;
if (pos >= K)
{
ans = i;
break;
}
}
writeln(ans);
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.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto A = RD;
auto B = RD;
writeln(min(A*N, B));
stdout.flush();
debug readln();
}
|
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, std.format;
// }}}
// 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()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
int n, m;
cin.scan(n, m);
writeln(n * (n - 1) / 2 + m * (m - 1) / 2);
}
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
void main() {
int a, b;
foreach(c; readln().chomp()) {
if (c == '0') ++a;
if (c == '1') ++b;
}
write(min(a, b) * 2);
}
|
D
|
import std;
void main(){
auto S = readln().chomp();
if (S == "ABC") writeln("ARC");
else if (S == "ARC") writeln("ABC");
else writeln("入力も正しくできないんですか!!!");
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!int).array;
bool[int] S;
for (int i = 0; i * i <= 10^^6; ++i) {
S[i*i] = true;
}
int ans = -(10^^6)-1;
foreach (a; A) if (!(a in S)) ans = max(ans, a);
ans.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 d=readln.chomp.to!int;
write("Christmas");
foreach(i; 0..25-d) {
write(" Eve");
}
writeln("");
}
|
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;
void main(string[] args) {
readln;
readln.solve.writeln;
}
auto solve(string input) {
return input.split.map!(to!int).map!(a => divCount(a, 2)).minElementAlt;
// return input.split.map!(to!int).map!(a => divCount(a, 2)).minElement;
}
unittest {
assert(solve("8 12 40") == 2, "1");
assert(solve("5 6 8 10") == 0, "2");
assert(solve("382253568 723152896 37802240 379425024 404894720 471526144") == 8, "3");
}
// ----------------------------------------
pure auto minElementAlt(Range)(Range r)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm: min;
auto res = r.front;
foreach(v; r) {
res = min(v, res);
}
return res;
} unittest {
assert([4, 6, 3, 0, 1].minElementAlt == 0);
}
pure auto divCount(int n, int base) {
auto count = 0;
while (n % base == 0) {
n /= base;
count++;
}
return count;
} unittest {
assert(divCount(12, 2) == 2);
assert(divCount(125, 2) == 0);
assert(divCount(81, 3) == 4);
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/+---test
5
1 2 1 1 3
---+/
/+---test
4
1 3 2 1
---+/
/+---test
5
1 2 3 4 5
---+/
/+---test
1
1000000000
---+/
void main(string[] args) {
readln;
auto H = readln.split.map!(to!long).array;
long prev = H[0];
foreach (ref height; H[1..$]) {
if (prev < height) --height;
if (prev > height) {
"No".writeln;
return;
}
prev = height;
}
"Yes".writeln;
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.