code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
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;
auto t = readStr;
if(s == t[0 .. $-1]){
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
void main()
{
auto x = readln.split.map!(to!int);
auto t = x[1] - 1;
auto tp = readln.split.map!(to!int);
int i;
while (i < tp.length) {
if (i == t) break;
i += tp[i];
}
if (i == t) writeln("YES");
else writeln("NO");
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
auto tmp = readln.split.to!(long[]);
const H = tmp[0], W = tmp[1];
tmp = readln.split.to!(long[]);
const h = tmp[0], w = tmp[1];
writeln(H * W - (h * W + w * H - h * w));
}
|
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, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long h, w;
scan(h, w);
auto alphabets = new long[](26);
foreach (_; iota(h))
{
auto s = sread();
foreach (e; s)
alphabets[e - 'a']++;
}
long only, two, four;
foreach (e; alphabets)
{
if (e % 2)
only++;
else if (e % 4)
two++;
else
four++;
}
if (h % 2 && w % 2)
{
if (only == 1 && two <= h / 2 + w / 2)
writeln("Yes");
else
writeln("No");
}
else if (h % 2)
{
if (only == 0 && two <= w / 2)
writeln("Yes");
else
writeln("No");
}
else if (w % 2)
{
if (only == 0 && two <= h / 2)
writeln("Yes");
else
writeln("No");
}
else
{
if (only == 0 && two == 0)
writeln("Yes");
else
writeln("No");
}
}
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.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;
auto w = ["Sunny", "Cloudy", "Rainy"];
foreach (i; 0..3) {
if (s == w[i]) {
w[(i+1)%3].writeln;
}
}
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
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; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int k = scan!int;
string s = scan;
if(s.length > k) print(s[0 .. k] ~ "...");
else print(s);
}
|
D
|
void main() {
problem();
}
void problem() {
auto X = scan!long;
long solve() {
foreach(t; 1..999_999) {
if (t * X % 360 == 0) return t;
}
return 0;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.numeric, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
|
D
|
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/5;
enum long MOD = 10L^^9+7;
void main() {
bool[] bs = readln.chomp.map!"a=='<'".array;
long N = bs.length + 1;
long[] as = new long[N];
long[] cs = [];
foreach(i; 0..N) {
if (i==0 && bs[i]) {
cs ~= i;
} else if (i==N-1 && !bs[i-1]) {
cs ~= i;
} else if (i>0 && i<N-1 && !bs[i-1] && bs[i]) {
cs ~= i;
}
}
foreach(c; cs) {
foreach_reverse(i; 0..c) {
if (bs[i]) break;
as[i].ch!max(c-i);
}
foreach(i; c+1..N) {
if (!bs[i-1]) break;
as[i].ch!max(i-c);
}
}
as.sum.writeln;
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (t * y < x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (t * y > x) t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach(i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
void scanln(Args...)(auto ref Args args) {
enum sep = " ";
enum n = Args.length;
enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
static if (__VERSION__ >= 2071) {
readf!fmt(args);
} else {
enum argsTemp = n.iota.map!(
i => "&args[%d]".format(i)
).join(", ");
mixin(
"readf(fmt, " ~ argsTemp ~ ");"
);
}
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
return x;
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
auto T = readln.chomp;
auto ss = new int[](S.length+1);
foreach (i, c; S) {
ss[i+1] = ss[i];
if (c == 'A') {
ss[i+1] += 1;
} else {
ss[i+1] += 2;
}
ss[i+1] %= 3;
}
auto tt = new int[](T.length+1);
foreach (i, c; T) {
tt[i+1] = tt[i];
if (c == 'A') {
tt[i+1] += 1;
} else {
tt[i+1] += 2;
}
tt[i+1] %= 3;
}
auto Q = readln.chomp.to!int;
foreach (_q; 0..Q) {
auto abcd = readln.split.to!(int[]);
auto a = abcd[0]-1;
auto b = abcd[1];
auto c = abcd[2]-1;
auto d = abcd[3];
writeln((ss[b] - ss[a] + 3) % 3 == (tt[d] - tt[c] + 3) % 3 ? "YES" : "NO");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
void main() {
auto N = readln.chomp.to!int;
auto a = ['M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4];
auto b = new ulong[](5);
foreach(_; 0..N) {
auto c = readln.chomp[0];
if(c in a) b[a[c]]++;
}
auto A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
auto B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3];
auto C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
ulong res;
foreach(i; 0..10) {
res += b[A[i]] * b[B[i]] * b[C[i]];
}
res.writeln;
}
// M A R C H
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a,b,c,d;
scan(a, b, c, d);
if (a + b < c + d) {
writeln("Right");
}
else if (a + b > c + d) {
writeln("Left");
}
else {
writeln("Balanced");
}
}
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;
import std.range, std.algorithm, std.array;
void main() {
int a,b;
scan(a,b);
writeln(a*b % 2 ? "Odd" : "Even");
}
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.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 o = readln.chomp;
auto e = readln.chomp;
foreach (i; 0..(o.length + e.length)) {
if (i % 2) {
write(e[i/2]);
} else {
write(o[i/2]);
}
}
writeln("");
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
immutable MAX = 10 ^^ 5;
auto S = new long[](MAX + 2);
{
auto sieve = new bool[](MAX + 1);
sieve[] = true;
sieve[0] = sieve[1] = false;
foreach (i; 2 .. MAX + 1)
if (sieve[i])
{
foreach (j; 2 .. MAX)
if (i * j < sieve.length)
{
sieve[i * j] = false;
}
else
{
break;
}
}
auto is2017 = new bool[](MAX + 1);
foreach (i; 3 .. MAX + 1)
if (i & 1)
{
is2017[i] = sieve[i] && sieve[(i + 1) / 2];
}
// is2017.take(20).writeln();
foreach (i; 1 .. MAX + 1)
{
S[i] = S[i - 1] + is2017[i];
}
S[MAX + 1] = S[MAX];
// S.take(20).writeln();
}
long Q = lread();
foreach (_; 0 .. Q)
{
long l, r;
scan(l, r);
writeln(S[r] - S[l - 1]);
}
}
|
D
|
void main() {
int a = readln.chomp.to!int;
int b = readln.chomp.to!int;
int c = readln.chomp.to!int;
int d = readln.chomp.to!int;
writeln(min(a, b) + min(c, d));
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const T a, const T b) { return a > b ? a - b : b - a; }
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
T[] readToArray(T)() {
return readln.split.to!(T[]);
}
void main() {
const s = readln;
char prev = '\0';
bool nikui = false;
foreach(c; s) {
if (c == prev) {nikui = true; break;}
prev = c;
}
writeln(nikui ? "Bad" : "Good");
}
|
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; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }
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; }
long mod = pow(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; }
struct UnionFind
{
void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
bool same(long i, long j) { return root(i) == root(j); }
void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
long[] par;
}
void main()
{
auto cnt = new long[](4);
foreach (i; 0..3)
{
auto a = RD!long - 1;
auto b = RD!long - 1;
++cnt[a];
++cnt[b];
}
long cnt1, cnt2;
foreach (e; cnt)
{
if (e == 1) ++cnt1;
else if (e == 2) ++cnt2;
}
writeln(cnt1 == 2 && cnt2 == 2 ? "YES" : "NO");
stdout.flush();
}
|
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!(string, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto n = lread();
auto s = sread();
long cnt;
foreach (i; iota(n - 3 + 1))
{
if(s[i .. i + 3] == "ABC")
cnt++;
}
cnt.writeln();
}
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.range;
import std.string;
import std.algorithm;
import std.conv;
void main() {
ulong x = readln.chomp.to!ulong;
(x/11*2 + (x%11 <= 6 ? 1 : 2) + (x%11 == 0 ? -1 : 0)).writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
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; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int h1 = scan!int, m1 = scan!int, h2 = scan!int, m2 = scan!int, k = scan!int;
int x1 = h1 * 60 + m1, x2 = h2 * 60 + m2;
int ans = x2 - k - x1;
ans.writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
immutable inf = 10^^9 + 7;
void main() {
int n;
scan(n);
bool[] p = [true, true, false];
foreach (i ; 0 .. n) {
int win;
scan(win);
win--;
if (!p[win]) {
writeln("NO");
return;
}
foreach (j ; 0 .. 3) {
if (j != win) {
p[j] ^= 1;
}
}
}
writeln("YES");
}
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.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}
void main()
{
int n; readV(n);
int k; readV(k);
int[] x; readA(n, x);
auto r = 0;
foreach (xi; x) r += min(xi, k-xi);
writeln(r*2);
}
|
D
|
// 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;
string s;
void main() {
scan(s);
if (s.canFind('N') == s.canFind('S') && s.canFind('W') == s.canFind('E')) {
writeln("Yes");
}
else {
writeln("No");
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.array;
import std.algorithm;
import std.conv;
import std.numeric;
import std.string;
void main() {
auto s = readln.chomp;
auto t = new int[4];
foreach (i, j; s) {
t[i] = j.to!int - '0'.to!int;
}
foreach(i; 0..2) {
foreach(j; 0..2) {
foreach(k; 0..2) {
int a = t[0], b, c, d;
if (i == 0) b = t[1];
else b = -t[1];
if (j == 0) c = t[2];
else c = -t[2];
if (k == 0) d = t[3];
else d = -t[3];
if (a + b + c + d == 7) {
char op1, op2, op3;
if (i == 0) op1 = '+';
else op1 = '-';
if (j == 0) op2 = '+';
else op2 = '-';
if (k == 0) op3 = '+';
else op3 = '-';
writeln(t[0], op1, t[1], op2, t[2], op3, t[3], "=7");
return;
}
}
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto ks = readln.split.to!(int[]);
auto K = ks[0];
auto S = ks[1];
int r;
foreach (i; 0..K+1) {
foreach (j; 0..K+1) {
auto k = S - i - j;
if (0 <= k && k <= K) ++r;
}
}
writeln(r);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
long n;
scan(n);
long ans = 100000;
while (n > 0) {
ans = min(ans, abs(753 - n % 1000));
n /= 10;
}
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.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int N;
scan(N);
int ans;
foreach (i ; 0 .. N) {
int li, ri;
scan(li, ri);
ans += ri - li + 1;
}
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
long[string] b, r;
foreach (i; 0..N)
{
++b[RD!string];
}
auto M = RD;
foreach (i; 0..M)
{
++r[RD!string];
}
long ans;
foreach (key; b.keys)
{
ans = max(ans, max(0, b[key] - r.get(key, 0)));
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.uni; // unicode
void main()
{
auto s = readln.split;
writeln(s.map!"a[0]".array.toUpper);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
bool check(const char[] arr) {
auto p = arr[0];
foreach (e; arr[1..$]) {
if (p != e) return false;
}
return true;
}
void main()
{
auto s = readln.chomp;
if (check(s)) {
writeln(0);
return;
}
auto cs = s.uniq();
auto min = int.max;
foreach (c; cs) {
int cnt;
auto ss = s.dup;
while (!check(ss)) {
++cnt;
foreach (i, sc; ss) {
if (i == ss.length - 1) {
ss.length -= 1;
} else {
ss[i] = sc == c ? sc : ss[i+1];
}
}
}
if (cnt < min) min = cnt;
}
writeln(min);
}
|
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.split.to!(int[]);
auto ab = s[0] * s[1];
auto f = false;
foreach (i; 1..4) {
if (ab * i % 2) {
f = true;
}
}
if (f) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
string s = readln.chomp;
int w = readln.chomp.to!(int);
string ans = "";
for (int i = 0; i < s.length; i += w) {
ans ~= s[i];
}
writeln(ans);
}
|
D
|
import std.conv;
import std.stdio;
import std.array;
import std.range;
import std.string;
import std.algorithm;
void main()
{
int sum = 0;
foreach(_; 0..10) {
sum += readln().chomp().to!int;
}
writeln(sum);
}
|
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;
long a = 100;
long ans;
foreach (i; 1..10^^7)
{
a += a / 100;
if (a >= X)
{
ans = i;
break;
}
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int n = read.to!int;
long[] as, bs;
foreach(i; 0 .. n){
as ~= read.to!long;
bs ~= read.to!long;
}
long sum;
foreach(a; as) sum += a;
long best = sum;
foreach(i; 0 .. n){
long a = as[i], b = bs[i];
if(a <= b) continue;
if(b < best) best = b;
}
(sum - best).writeln;
}
/*
A君はできるだけ粘りたい。
B君よりも高い山を1つ残しておけばいくらでも粘れるので、
最終的には1つの山だけが残る形にするまで粘ることができる。
その際A君にとっては、残る山の高さは低いほうがよい。
つまり
「A君の方が高い山のうちでB君の高さが最も低いもの」
が残る山の高さ。
※これが無いときは初期状態で全ての山のABが一致しているときで、答えは0。
*/
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!int;
writeln("ABC", n);
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;
void main() {
auto S = readln.chomp.dup;
bool po() {
if (S[0] != 'A') return false;
if (S[2..$-1].count('C') != 1) return false;
foreach (i; 2..S.length-1) {
if (S[i] == 'C') S[i] = 'c';
}
return S[1..$].toLower == S[1..$];
}
writeln(po() ? "AC" : "WA");
}
|
D
|
void main(){
char alph = _scan!char();
( ('a'<=alph && alph<='z') ? 'a' : 'A').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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp.to!(char[]);
int X = 700;
if (S[0] == 'o') X += 100;
if (S[1] == 'o') X += 100;
if (S[2] == 'o') X += 100;
writeln(X);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
long disit_sum(long a)
{
long sum,disit_num;
foreach(disit;0 .. 9)
{
disit_num = a / pow(10, disit);
sum += disit_num % 10;
}
return sum;
}
void main()
{
long a,b,t;
scan(a,b,t);
long sum,i = 1,now = a;
while(now <= t)
{
sum += b;
i++;
now = i * a;
}
writeln(sum);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto T = readln.chomp.to!int;
auto A = readln.split.map!(to!long).array;
foreach (a; A) {
auto m = a % 14;
if (a <= 14) {
writeln("NO");
} else if (m != 0 && m <= 6) {
writeln("YES");
} else {
writeln("NO");
}
}
}
|
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;
int p;
bool ok(int s) {
int i = s / 50 % 475;
foreach (_; 0..25) {
i = (i * 96 + 42) % 475;
if (26 + i == p) return true;
}
return false;
}
void main() {
auto s = readln.split.map!(to!int);
p = s[0];
int x = s[1];
int y = s[2];
int ox = x;
while (x - 50 >= y) x -= 50;
while (!ok(x)) x += 50;
writeln(max(0, (x - ox + 50) / 100));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.string;
enum arrow { L,R,U,D };
void main(){
int n = readln.chomp.to!int();
const arrow[dchar] toArrow = [ 'L':arrow.L, 'R':arrow.R, 'U':arrow.U, 'D':arrow.D ];
foreach(i; 0..n){
auto score = readln.chomp.map!(a=>toArrow[a])();
writeln(score.isNatural? "Yes": "No");
}
}
bool isNatural(T)(T score){
arrow prev = cast(arrow)-1;
bool startLeft = true;
bool startRight = true;
bool startFoot = true;
foreach(s; score){
if(prev == s) return false;
if(s == arrow.L){
startLeft = startLeft && startFoot;
startRight = startRight && !startFoot;
}else if(s == arrow.R){
startLeft = startLeft && !startFoot;
startRight = startRight && startFoot;
}
if(!(startLeft || startRight)) return false;
prev = s;
startFoot ^= true;
}
return true;
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
writeln((s[0] == s[$-1]) ^ (s.length%2 != 0) ? "First" : "Second");
}
|
D
|
import std.stdio, std.conv, std.math, std.string, std.range, std.array,
std.algorithm;
void main(){
auto buf = readln().strip().split().map!(to!int)();
immutable N = buf[0];
auto a = readln().strip().split().map!(to!int)();
long[long] m;
long ans;
long shift;
foreach(ea; a) {
shift += ea;
m[ea-shift] += 1;
ans += m.get(-shift, 0);
}
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.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
writeln(180 * (N - 2));
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int n = readint;
bool[int] d;
for (int i = 0; i < n; i++) {
int x = readint;
d[x] = true;
}
writeln(d.keys.length);
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b; readV(a, b);
writeln(a - (a > b));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abck = readln.split.to!(long[]);
auto A = abck[0];
auto B = abck[1];
auto C = abck[2];
auto K = abck[3];
long r;
if (K > 0) {
r += min(K, A);
K -= min(K, A);
}
if (K > 0) {
K -= min(K, B);
}
if (K > 0) {
r -= min(K, C);
}
writeln(r);
}
|
D
|
void main()
{
long n = rdElem;
long[] a = n.rdCol;
writeln(a.any!"a & 1" ? "first" : "second");
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
auto s = readln.chomp;
auto x = "keyence";
auto ans = "NO";
for(int i = 0; i <= s.length; i ++){
for(int j = i; j <= s.length; j ++){
if(s[0 .. i] ~ s[j .. $] == x) ans = "YES";
}
}
ans.writeln;
}
|
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;
auto A = readln.chomp.to!long;
auto B = readln.chomp.to!long;
auto C = readln.chomp.to!long;
auto D = readln.chomp.to!long;
auto E = readln.chomp.to!long;
auto x = min(A, B, C, D, E);
writeln(4 + (N+x-1)/x);
}
|
D
|
// Vicfred
// https://atcoder.jp/contests/dp/tasks/dp_a
import std.algorithm;
import std.math;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main() {
const int n = readln.chomp.to!int;
const int[] h = readln.split.map!(to!int).array;
int[] dp = new int[n];
dp[1] = abs(h[1]-h[0]);
for(int i = 2; i < n; ++i)
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
dp[$-1].writeln;
}
|
D
|
import std.algorithm;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;
void main() {
auto input = readln.chomp.split.map!(to!long);
auto r = input.front;
input.popFront;
auto D = input.front;
input.popFront;
auto x = input.front;
input.popFront;
iota(10).each!(_ => writeln(x = r * x - D));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main(){
int x = readln().chomp().to!int();
writeln(x * x * x);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n, k;
scan(n, k);
auto w = new int[][][](2, k, k);
foreach (i ; 0 .. n) {
int xi, yi;
char ci;
scan(xi, yi, ci);
if (ci == 'B') yi += k;
int e = (xi / k % 2 + yi / k % 2) % 2;
w[e][xi % k][yi % k]++;
}
foreach (e ; 0 .. 2) {
foreach (i ; 0 .. k) {
foreach (j ; 1 .. k) {
w[e][i][j] += w[e][i][j-1];
}
}
foreach (j ; 0 .. k) {
foreach (i ; 1 .. k) {
w[e][i][j] += w[e][i-1][j];
}
}
}
int ans;
foreach (i ; 0 .. k) {
foreach (j ; 0 .. k) {
int t = w[0][k-1][k-1] - w[0][k-1][j] - w[0][i][k-1] + 2*w[0][i][j];
int s = w[1][i][k-1] + w[1][k-1][j] - 2*w[1][i][j];
ans = max(ans, t + s);
ans = max(ans, n - t - s);
}
}
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.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]), x = rd[0], t = rd[1];
writeln(max(x-t, 0));
}
|
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 a = aryread!string();
// writeln(a);
writeln(a[0][0], a[1][0], a[2][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
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int n, a, b; readV(n, a, b);
writeln(min(n*a, b));
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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 D = RD;
auto S = RD;
auto T = RD;
writeln(T*S >= D ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import core.stdc.stdio;
import std.algorithm;
void main(){
int[] map = new int[100000];
int[] t = new int[10000];
while(1){
int r,c;
scanf("%d%d",&r,&c);
if(r==0&&c==0)
break;
t[] = 0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
scanf("%d",&map[i*c+j]);
t[j] += 1-map[i*c+j];
}
}
int ans=0;
for(int i=0;i<(1<<r);i++){
int a=0;
for(int j=0;j<c;j++){
int s = t[j];
for(int k=0;k<r;k++){
if(i&(1<<k)){
if(map[k*c+j]==0)
s--;
else
s++;
}
}
a += max(s,r-s);
}
ans = max(a,ans);
}
printf("%d\n",ans);
}
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int a = (tmp[0] + 13) % 15, b = (tmp[1] + 13) % 15;
if (a > b) {
"Alice".writeln;
} else if (a < b) {
"Bob".writeln;
} else {
"Draw".writeln;
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n, m; readV(n, m);
int[] a; readA(n, a);
auto p = new int[][](m+1);
foreach (int i, ai; a) p[ai] ~= i;
auto k = 0, c = 0L;
foreach (i; 0..n-1)
if (a[i] > a[i+1]) {
++k;
c += a[i+1];
} else {
c += a[i+1]-a[i];
}
auto ans = c;
foreach (i; 1..m) {
c -= k;
foreach (j; p[i]) {
if (j > 0) {
--k;
c += a[j-1] > a[j] ? a[j]+m-a[j-1] : a[j]-a[j-1];
}
if (j < n-1)
++k;
}
ans = min(ans, c);
}
writeln(ans);
}
|
D
|
void main(){
int a, b;
scanf("%d %d", &a, &b);
int ans = (a + b)%24;
ans.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;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
void main(){
int totalTime = 0;
for(int i = 0; i < 4; i++){
totalTime += readln().chomp().to!int();
}
writeln(totalTime / 60);
writeln(totalTime % 60);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp;
writeln(s[1] == s[2] && (s[0] == s[1] || s[2] == s[3]) ? "Yes" : "No");
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int y, b, r;
scan(y, b, r);
int ans = 0;
foreach (i ; 1 .. y + 1) {
foreach (j ; 1 .. b + 1) {
foreach (k ; 1 .. r + 1) {
if (j == i + 1 && k == j + 1) {
ans = max(ans, i + j + k);
}
}
}
}
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.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
auto tmp = readln.split.to!(int[]);
writeln(tmp[0] * tmp[1] / 2);
}
|
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 X = scanElem;
auto a = X;
auto b = N-X;
long res = a+b;
if(a>b)swap(a,b);
while(b%a!=0){
res += ((b/a)*2)*a;
auto tmp=min(a,b);
a=b%a;
b=tmp;
}
res += ((b/a)*2-1)*a;
writeln(res);
}
long gcd(long a, long b)
{
if(b == 0) return a;
return gcd(b, a % b);
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(T[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio;
import std.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;
writeln(s[0..4], " ", s[4..$]);
}
|
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;
const long MOD = 998244353;
const int INF = 1 << 29;
void main() {
auto N = readln.chomp.to!int;
auto S = N.iota.map!(_ => readln.chomp).array;
auto dp = new int[](26);
fill(dp, INF);
dp[S.front.front - 'a'] = 1;
foreach (i; 1..N) {
dp[S[i].front - 'a'] = min(dp[S[i].front - 'a'],
dp[S[i-1].front - 'a'] + 1);
}
dp[S.back.front - 'a'].writeln;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int n, k; readV(n, k);
auto c = 0L;
foreach (b; k+1..n+1) {
c += n/b * (b-k);
if (k > 0)
c += max(0, n%b-k+1);
else
c += max(0, n%b-k);
}
writeln(c);
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional;
void main(){
(readln().chomp.isHaiku?"YES":"NO").writeln();
}
auto isHaiku(string str){
return ["5 7 5", "7 5 5", "5 5 7"].canFind(str);
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const N = readln.chomp.to!long;
const S = readln.chomp;
const K = readln.chomp.to!long;
S.map!(c => c != S[K-1] ? "*" : [c]).join.writeln;
}
|
D
|
void main(){
int n = _scan();
string s = readln().chomp();
writeln( s[0..n/2] == s[n/2..$]? "Yes": "No" );
}
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;
import std.conv;
import std.string;
void main(){
// input
int[] input;
for(auto i = 0; i < 3; i++){
input ~= to!int(readln().chomp());
}
immutable int start_money = input[0];
immutable int a_price = input[1];
immutable int b_price = input[2];
immutable int answer = (start_money - a_price) % b_price;
writeln(answer);
}
|
D
|
import std.stdio: readln, writeln;
import std.string: chomp, split;
import std.conv: to;
void main()
{
auto dataSet = chomp(readln()).split(" ");
int m = to!int(dataSet[0]),
f = to!int(dataSet[1]),
r = to!int(dataSet[2]);
while(1 + m || 1 + f || 1 + r)
{
if(0 == (1 + m) * (1 + f) || 30 > m + f) writeln("F");
else if(80 <= m + f) writeln("A");
else if(65 <= m + f) writeln("B");
else if(50 <= m + f) writeln("C");
else if(50 <= r) writeln("C");
else writeln("D");
dataSet = chomp(readln()).split(" ");
m = to!int(dataSet[0]),
f = to!int(dataSet[1]),
r = to!int(dataSet[2]);
}
}
|
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;
auto A = data[0].to!long, B = data[1].to!long;
long f(long n) { switch(n%4) {
case 0: return n;
case 1: return 1;
case 2: return 1+n;
case 3: return 0;
default: return 0;
} }
if (A == 1) writeln(f(B));
else { writeln(f(A-1) ^ f(B)); }
}
|
D
|
import std.stdio;
int main(string[] argv)
{
for(int i = 1;i <= 9;i++){
for(int j = 1;j <= 9;j++){
writeln(i,"x",j,"=",i*j);
}
}
return 0;
}
|
D
|
import std.stdio;
void main(string[] args)
{
foreach(int i ; 1..10)
{
foreach(int j; 1..10)
{
writeln(i,"x",j,"=",i*j);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;
import std.regex;
void main(){
auto z=readln.split.to!(int[]),a=z[0],b=z[1];
writeln(a*b-(a+b-1));
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int x;
scan(x);
auto ans = (x / 500) * 1000 + (x % 500) / 5 * 5;
writeln(ans);
}
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
|
D
|
import std.stdio, 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 op = RD!string;
auto B = RD;
long ans;
if (op == "+")
ans = A + B;
else
ans = A - B;
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv,
std.format,
std.math;
void main()
{
auto n = readln.chomp.to!int;
int i = 1;
while(true){
if(n < i^^2) break;
else i++;
}
writeln((i-1)^^2);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (ti; 0..t)
{
auto s = RD!string;
ans[ti] = long.max;
foreach (i; 0..s.length)
{
long cnt1;
foreach (j; 0..i)
{
if (s[j] == '0')
++cnt1;
}
long cnt2;
foreach (j; i..s.length)
{
if (s[j] == '0')
++cnt2;
}
debug writeln(cnt1, ":", cnt2);
ans[ti].chmin(min(cnt1, i-cnt1) + min(cnt2, s.length-i-cnt2));
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
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; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){}
void jury(){}
void solve(){
int n = scan!int;
int ans;
foreach(a; 1 .. n + 1){
ans += (n - 1) / a;
}
ans.print;
}
|
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 S = RD!string;
auto num = [S[$-1]].to!long;
writeln(num % 2);
stdout.flush;
debug readln;
}
|
D
|
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.numeric;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
p = stdin.rawRead (buffer);
}
final ubyte skipByte (ubyte lo) {
while (true) {
auto a = p[cur .. $];
auto r = a.find! (c => c >= lo);
if (!r.empty) {
cur += a.length - r.length;
return p[cur++];
}
p = stdin.rawRead (buffer);
cur = 0;
if (p.empty) return 0;
}
}
final ubyte nextByte () {
if (cur < p.length) {
return p[cur++];
}
p = stdin.rawRead (buffer);
if (p.empty) return 0;
cur = 1;
return p[0];
}
template next(T) if (isSigned!T) {
final T next () {
T res;
ubyte b = skipByte (45);
if (b == 45) {
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
final T next () {
T res = skipByte (48) - 48;
while (true) {
ubyte b = nextByte ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
}
void main() {
auto r = new InputReader;
immutable n = r.next!int;
immutable m = r.next!int;
auto x = uninitializedArray!(long[]) (n);
foreach (i; 0 .. n) x[i] = r.next!long;
immutable x0 = x[0];
long g;
foreach (i; 1 .. n) {
immutable dx = x[i] - x0;
if (i == 1) {
g = dx;
} else {
g = gcd (g, dx);
}
}
auto p = uninitializedArray!(long[]) (n);
foreach (i; 0 .. m) {
p[i] = r.next!long;
if (!(g % p[i])) {
writeln ("YES");
writeln (x[0], ' ', i + 1);
return;
}
}
writeln ("NO");
}
|
D
|
import std.stdio;
import std.ascii;
import core.stdc.stdio;
int main()
{
int t = readInt!int;
while (t--)
{
long x = readInt!long;
long m111 = 0;
bool can = false;
int maxrep = 20;
int i = 0;
while (m111 <= x && i < maxrep)
{
if ((x - m111) % 11 == 0)
{
can = true;
break;
}
m111 += 111;
i++;
}
if (can) writeln("YES"); else writeln("NO");
}
return 0;
}
/* INPUT ROUTINES */
int currChar;
static this()
{
currChar = getchar();
}
char topChar()
{
return cast(char) currChar;
}
void popChar()
{
currChar = getchar();
}
auto readInt(T)()
{
T num = 0;
int sgn = 0;
while (topChar.isWhite) popChar;
while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
if (sgn) return -num; return num;
}
string readString()
{
string res = "";
while (topChar.isWhite) popChar;
while (!topChar.isWhite) { res ~= topChar; popChar; }
return res;
}
|
D
|
import std.stdio;
int l,r;
void main()
{
scanf("%d %d", &l, &r);
long low = 1;
int ans = 0;
while(low<=r){
long x=low;
while(x<=r){
if(x>=l){
ans++;
}
x*=2;
}
low*=3;
}
printf("%d",ans);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto s1 = readln.chomp;
auto s2 = readln.chomp;
writeln(levenshteinDistance(s1, s2));
}
|
D
|
void main(){
real num = readln().chomp().replace(" ","").to!int();
writeln(num%sqrt(num)==0?"Yes":"No");
}
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.algorithm, std.conv, std.range, std.stdio, std.string;
const alpha = 26, a = 'a';
void main()
{
auto n = readln.chomp.to!size_t;
auto b = new int[](alpha), bs = new int[](alpha);
b[] = int.max;
foreach (_; 0..n) {
auto s = readln.chomp;
bs[] = 0;
foreach (c; s) ++bs[c-a];
foreach (i; 0..alpha) b[i] = min(b[i], bs[i]);
}
foreach (i; 0..alpha)
foreach (j; 0..b[i])
write(cast(char)(a+i));
writeln;
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
import core.bitop;
void main()
{
long N = lread();
auto X = sread();
ulong m = X.map!"a == '1'"().sum();
ulong plain0 = () {
if (m == 1)
return -1;
long ret;
foreach (i, c; X)
{
if (c == '1')
{
ret += powmod(2, X.length - i - 1, m - 1);
ret %= m - 1;
}
}
return ret;
}();
ulong plain1 = () {
long ret;
foreach (i, c; X)
{
if (c == '1')
{
ret += powmod(2, X.length - i - 1, m + 1);
ret %= m + 1;
}
}
return ret;
}();
foreach (i; 0 .. X.length)
{
if (X[i] == '1' && m == 1)
{
writeln(0);
continue;
}
ulong y = () {
if (X[i] == '1')
{
return ((m - 1) + plain0 - powmod(2, X.length - i - 1, m - 1)) % (m - 1);
}
return (plain1 + powmod(2, X.length - i - 1, m + 1)) % (m + 1);
}();
// dprint(i, X[i] == '1', y, plain0, plain1);
long ans = 1;
while (y != 0)
{
y = g(y);
ans++;
}
writeln(ans);
}
}
ulong g(ulong x)
{
return x % popcnt(x);
}
/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
if (n < 1)
return 1;
if (n & 1)
{
return x * powmod(x, n - 1, m) % m;
}
T tmp = powmod(x, n / 2, m);
return tmp * tmp % m;
}
|
D
|
import std.stdio,std.string,std.conv,std.array;
void main(){
int[26] arr;
for(;;){
auto rc = readln().chomp();
if(!rc){ break; }
foreach( c ; rc ){
if( 'a' <= c && c <= 'z' ){
arr[c-'a']++;
} else if ( 'A' <= c && c <= 'Z' ){
arr[c-'A']++;
}
}
}
foreach( key,i ; arr ){
writeln( to!char(key+'a')," : ",i );
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a,b,c,x;
scan(a);
scan(b);
scan(c);
scan(x);
int ans;
foreach(i;0..a+1){
foreach(j;0..b+1){
foreach(k;0..c+1){
if(500*i+100*j+50*k == x) ans++;
}
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv,
std.format,
std.math;
void main()
{
auto ip = readln.chomp;
if(ip[0] == ip[2]) writeln("=");
else if(ip[0] < ip[2]) writeln("<");
else writeln(">");
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int h, w;
rd(h, w);
int a, b;
rd(a, b);
auto p = h / a, q = w / b;
writeln((h - p * a) * w + h * (w - q * b) - ((h - p * a) * (w - q * 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
|
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;
}
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); // H[k]: s[0]*Ps[k]^(n-1) + s[1]*Ps[k]^(n-2) + ... + s[n-1]*Ps[k]^0
foreach (k, P; Ps) {
foreach (int i, c; s) {
H[k][i + 1] = (H[k][i] * P + cast(int)(c - 'a' + 1)) % mod;
}
}
}
long[] hash(int l, int r) { // [l, r)
auto hs = iota(0, Ps.length, 1).map!(delegate(k) {
return (H[k][r] - H[k][l] * modPow!mod(Ps[k], r - l) % mod + mod) % 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.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N, M;
scan(N, M);
auto adj = new int[][](N, 0);
foreach (i ; 0 .. M) {
int xi, yi;
scan(xi, yi);
xi--, yi--;
adj[xi] ~= yi;
}
auto ord = topSort(adj);
auto dp = new int[](N);
int ans;
foreach (v ; ord) {
ans = max(ans, dp[v]);
foreach (u ; adj[v]) {
chmax(dp[u], dp[v] + 1);
}
}
writeln(ans);
}
int[] topSort(int[][] adj) {
auto N = adj.length.to!int;
auto deg = new int[](N);
foreach (v ; 0 .. N) {
foreach (u ; adj[v]) {
deg[u]++;
}
}
int[] res;
int[] next;
foreach (v ; 0 .. N) {
if (!deg[v]) next ~= v;
}
while (!next.empty) {
int[] nn;
foreach (v ; next) {
res ~= v;
foreach (u ; adj[v]) {
deg[u]--;
if (!deg[u]) nn ~= u;
}
}
next = nn;
}
return res;
}
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.