code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
void main() {
int n = readln.chomp.to!int;
string s = readln.chomp;
int cnt;
foreach (i; 1 .. n) {
int tmp;
foreach (x; lowercase) {
if (s[0..i].canFind(x) && s[i..$].canFind(x)) {
++tmp;
}
}
cnt = max(cnt, tmp);
}
cnt.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 core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
ulong n = readln.chomp.to!ulong;
ulong[] a = readln.chomp.split.map!(to!ulong).array;
// ulong[] a = make(50 * 10_000_000_000_000_000L);
// ulong n = a.length;
ulong k = 0;
ulong cnt = 0;
for (;;) {
ulong trg = 0;
ulong trg_index = 0;
foreach (i, v; a) {
if (trg < v) {
trg = v;
trg_index = i;
}
}
if (trg < n) {
break;
}
ulong sub = trg / n;
k += sub;
a[trg_index] -= sub * n;
foreach (i, ref v; a) {
if (i == trg_index) {
continue;
}
v += sub;
}
++cnt;
}
// stderr.writeln("loop count : ", cnt);
k.writeln;
}
ulong[] make(ulong k)
{
enum N = 50;
long v = k / N;
immutable remain = k % N;
ulong[] arr;
foreach (i; 0..N) {
if (i < remain) {
arr ~= v + N * 2 - remain;
} else {
arr ~= v + N - (remain + 1);
}
}
return arr;
}
|
D
|
import std;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
string s;
s = input();
// writeln(s);
string key;
key = "keyence";
// riteln(s[0 .. 7]);
// if (s[0 .. 7] == key)
// {
// writeln("YES");
// return;
// }
// writeln(s[$ - 7 .. $]);
// if (s[$ - 7 .. $] == key)
// {
// writeln("YES");
// return;
foreach (i; 0 .. key.length)
{
string tmp = s[0 .. i] ~ s[$ - (7 - i) .. $];
if (tmp == key)
{
writeln("YES");
return;
}
}
writeln("NO");
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
import std.stdio;
import std.array;
import std.string;
import std.container;
import std.ascii;
import std.random;
import std.algorithm;
import std.conv;
import std.range;
import std.math;
import std.format;
import std.typecons;
import std.numeric;
import std.datetime;
/*
??????????????????, ?????§??¨?????¨, ??¨?????????, ????????????????????????????????????
*/
/**
src???????????°??????G, dst???King's Graph??§??????Gemb
*/
int n, m, u, v, c;
edge[][] g;
void main() {
n = readln.chomp.to!int;
g = new edge[][](n, 0);
for (int i = 0; i < n-1; ++i) {
auto l = readln.chomp.split.map!(to!int).array;
g[l[0]] ~= edge(l[0], l[1], l[2]);
g[l[1]] ~= edge(l[1], l[0], l[2]);
}
edge e = treeDiameter(g);
writeln(e.cost);
}
/***************************************************************************/
// c++???pair??£??????
struct pair {
int first, second;
}
struct edge {
int u, v, cost;
}
class queue(T) {
T[] p;
this() {}
this(T p) {
this.p ~= p;
}
~this() {}
void push(T x) {
p ~= x;
}
void pop() {
assert(p.length > 0);
p.popFront();
}
T front() {
assert(p.length > 0);
return p[0];
}
bool empty() {
if (p.length == 0) return true;
else return false;
}
}
// pair(??´???, ??´??????????????????)
edge treeDiameter(edge[][] graph) {
int s;
pair d1, d2; // pair(distance, vertex)
bool[] used = new bool[](n);
d1 = dfs(graph, used, pair(0, s));
used[] = false;
d2 = dfs(graph, used, pair(0, d1.second));
if (d1.second > d2.second) swap(d1.second, d2.second);
return edge(d1.second, d2.second, d2.first);
}
// ?????????????????????????????????????????????????????????????????????????????¨???????????§????????¢?????????
pair dfs(edge[][] graph, bool[] used, pair p) {
used[p.second] = true;
pair ret = p;
foreach(nv; graph[p.second]) {
if (!used[nv.v]) {
pair tmp = dfs(graph, used, pair(p.first + nv.cost, nv.v));
if (ret.first < tmp.first) {
ret = tmp;
}
}
}
return ret;
}
/***************************************************************************/
|
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, k;
scan(n, k);
int ans = n - k + 1;
writeln(ans);
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.stdio, std.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 n = scan!int;
int x = scan!int - 1, y = scan!int - 1;
int[] ans = new int[](n);
foreach(i; 0 .. n) foreach(j; 0 .. i){
int d = min(abs(i - j), abs(i - y) + abs(j - x) + 1, abs(i - x) + abs(j - y) + 1);
ans[d] += 1;
}
foreach(an; ans[1 .. $]) an.print;
}
|
D
|
import core.bitop;
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()
{
auto a = readln.chomp.split.map!(to!int);
writeln = max(0, a[0] - a[1]);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void main(){
auto ip = readln.split.to!(int[]);
((ip[0] + ip[1]) >= ip[2] ? "Yes" : "No").writeln;
}
|
D
|
void main(){
string[] s = inln!string();
string ans;
foreach(elm; s)ans ~= elm[0];
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.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void main()
{
int n, a, b; readV(n, a, b);
writeln(min(n*a, b));
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
auto ab = readints;
int a = ab[0], b = ab[1];
if (a == 1) a += 13;
if (b == 1) b += 13;
if (a == b) writeln("Draw");
else if (a > b) writeln("Alice");
else writeln("Bob");
}
|
D
|
import std;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
void main()
{
long h, m;
scan(h, m);
auto s = new string[](h);
foreach (i; 0 .. h)
{
s[i] = sread();
}
//writeln(s);
foreach (i; 0 .. h)
{
foreach (j; 0 .. m)
{
if (s[i][j] == '#')
{
if ((i != 0 && s[i - 1][j] == '#') || (i != h - 1
&& s[i + 1][j] == '#') || (j != 0 && s[i][j - 1] == '#')
|| (j != m - 1 && s[i][j + 1] == '#'))
{
continue;
}
writeln("No");
return;
}
}
}
writeln("Yes");
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
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+b)%24);
}
|
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)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto N = RD!long;
auto M = RD!long;
writeln((N == 1 ? 1 : max(0, N-2)) * (M == 1 ? 1 : max(0, M-2)));
stdout.flush();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
auto Px = [-1, 0, 1, 0];
auto Py = [ 0, 1, 0,-1];
void main()
{
auto line = split(readln()).map!(a => to!int(a));
int z = 0;
auto ret = solve(line[z++], line[z++], line[z++], line[z++], line[z++]);
writeln(ret ? "Yes" : "No");
}
bool solve(int W, int H, int x, int y, int r)
{
for (int i = 0; i < 4; i++) {
auto px = x - Px[i] * r;
auto py = y - Py[i] * r;
if (!(0 <= py && py <= H && 0 <= px && px <= W)) {
return false;
}
}
return true;
}
|
D
|
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
void main() {
immutable ip = readln.split.to!(ulong[]);
immutable n = ip[0], x = ip[1];
immutable ls = readln.split.to!(ulong[]);
ulong cnt = 0;
ulong xi = 0;
while(xi <= x && cnt <= n) {
xi += ls[cnt++];
}
writeln(cnt);
}
|
D
|
// import chie template :) {{{
static if (__VERSION__ < 2090) {
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format,
std.bitmanip, std.numeric;
} else {
import std;
}
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan(T...)(ref T args) {
foreach (ref arg; args) {
arg = next!(typeof(arg));
}
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
// alias {{{
alias Heap(T, alias less = "a < b") = BinaryHeap!(Array!T, less);
alias MinHeap(T) = Heap!(T, "a > b");
// }}}
// memo {{{
/*
- ある値が見つかるかどうか
<https://dlang.org/phobos/std_algorithm_searching.html#canFind>
canFind(r, value); -> bool
- 条件に一致するやつだけ残す
<https://dlang.org/phobos/std_algorithm_iteration.html#filter>
// 2で割り切れるやつ
filter!"a % 2 == 0"(r); -> Range
- 合計
<https://dlang.org/phobos/std_algorithm_iteration.html#sum>
sum(r);
- 累積和
<https://dlang.org/phobos/std_algorithm_iteration.html#cumulativeFold>
// 今の要素に前の要素を足すタイプの一般的な累積和
// 累積和のrangeが帰ってくる(破壊的変更は行われない)
cumulativeFold!"a + b"(r, 0); -> Range
- rangeをarrayにしたいとき
array(r); -> Array
- 各要素に同じ処理をする
<https://dlang.org/phobos/std_algorithm_iteration.html#map>
// 各要素を2乗
map!"a * a"(r) -> Range
- ユニークなやつだけ残す
<https://dlang.org/phobos/std_algorithm_iteration.html#uniq>
uniq(r) -> Range
- 順列を列挙する
<https://dlang.org/phobos/std_algorithm_iteration.html#permutations>
permutation(r) -> Range
- ある値で埋める
<https://dlang.org/phobos/std_algorithm_mutation.html#fill>
fill(r, val); -> void
- バイナリヒープ
<https://dlang.org/phobos/std_container_binaryheap.html#.BinaryHeap>
// 昇順にするならこう(デフォは降順)
BinaryHeap!(Array!T, "a > b") heap;
heap.insert(val);
heap.front;
heap.removeFront();
- 浮動小数点の少数部の桁数設定
// 12桁
writefln("%.12f", val);
- 浮動小数点の誤差を考慮した比較
<https://dlang.org/phobos/std_math.html#.approxEqual>
approxEqual(1.0, 1.0099); -> true
- 小数点切り上げ
<https://dlang.org/phobos/std_math.html#.ceil>
ceil(123.4); -> 124
- 小数点切り捨て
<https://dlang.org/phobos/std_math.html#.floor>
floor(123.4) -> 123
- 小数点四捨五入
<https://dlang.org/phobos/std_math.html#.round>
round(4.5) -> 5
round(5.4) -> 5
*/
// }}}
void main() {
auto cin = new Scanner;
int n, h, w;
int cnt;
cin.scan(n, h, w);
foreach (i; 0 .. n) {
int a, b;
cin.scan(a, b);
if (h <= a && w <= b) cnt++;
}
writeln(cnt);
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
long a, b, x, y, z;
scan(a, b);
scan(x, y, z);
writeln(max(0, 2*x + y - a) + max(0, y + 3*z - b));
}
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
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
long x, y; rd(x, y);
long count(long st, long ed){
if(st>ed) return 0;
long ret=1;
while(st*2<=ed) st*=2, ret++;
return ret;
}
writeln(max(count(x, y), count(x+1, y)));
}
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
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
struct P {
int y, x;
}
auto xs = new int[](n), ys = new int[](n);
bool[P] seen;
foreach (i; 0 .. n) {
rd(xs[i], ys[i]);
if (i > 0) {
seen[P(xs[i], ys[i])] = true;
}
}
auto vy = new int[](n), vx = new int[](n);
foreach (i; 0 .. n) {
rd(vx[i], vy[i]);
}
foreach (i; 0 .. n) {
auto tx = xs[0] + vx[i], ty = ys[0] + vy[i];
foreach (j; 0 .. n) {
if (i != j) {
auto p = P(tx - vx[j], ty - vy[j]);
if ((p in seen) == null || !seen[p]) {
goto hell;
}
seen[p] = false;
}
}
writeln(tx, " ", ty);
return;
hell:
// revert
foreach (j; 1 .. n) {
seen[P(xs[j], ys[j])] = true;
}
}
import std.exception : enforce;
enforce(false);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
string INF = "|";
string[] input;
while(true) {
input = readln.split;
if (input == ["0", "0", "0", "0"]) break;
int n = input[0].to!int;
int a = input[1].to!int;
int s = input[2].to!int;
int g = input[3].to!int;
string[] vertices = new string[n];
vertices[] = INF;
Edge[] edges = new Edge[a];
foreach(int i; 0..a) {
input = readln.split;
int from = input[1].to!int;
int to = input[0].to!int;
string cost = input[2];
if (from == to) {
edges[i] = Edge(from, vertices.length.to!int, cost);
edges ~= Edge(vertices.length.to!int, to, "");
vertices ~= INF;
} else {
edges[i] = Edge(from, to, cost);
}
}
vertices[g] = "";
bool flg = false;
for (int count=0; count<6*vertices.length; count++) {
for (int i=0; i<edges.length; i++) {
string value = edges[i].cost~vertices[edges[i].from];
if (value < vertices[edges[i].to] && vertices[edges[i].from]!=INF) {
vertices[edges[i].to] = value;
if (count>=vertices.length-1 && edges[i].to==s) {
flg = true;
}
}
}
}
writeln(vertices[s] == INF || flg ? "NO":vertices[s]);
}
}
struct Edge {
int from, to;
string cost;
this(int from, int to, string cost) {
this.from = from;
this.to = to;
this.cost = cost;
}
}
|
D
|
import std.stdio, std.string, std.conv;
void main()
{
int a,b;
scanf("%d %d",&a, &b);
writeln(2*b-a);
}
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
void main() {
readln;
auto a = readln.chomp.dup;
int count;
int left, right = cast(int)a.length - 1;
for (;;) {
while (left < a.length) {
if (a[left] == 'W') {
break;
}
++left;
}
while (right >= 0) {
if (a[right] == 'R') {
break;
}
--right;
}
if (right < left) {
break;
}
++left;
--right;
++count;
}
writeln(count);
}
|
D
|
import std.stdio;
import std.string;
import std.range;
import std.conv;
void main()
{
auto X = readln.chomp.to!int;
auto A = readln.chomp.to!int;
auto B = readln.chomp.to!int;
writeln((X-A)%B);
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto N = readln.chomp.to!int;
auto K = readln.chomp.to!int;
auto X = readln.chomp.to!int;
auto Y = readln.chomp.to!int;
if(N-K <= 0){
writeln(N*X);
}else{
writeln(K*X + (N-K)*Y);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto ab = readln.split.to!(int[]);
auto A = ab[0];
auto B = ab[1];
writeln(max(0, A - B*2));
}
|
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
|
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 A, B, C, D, E, F;
scan(A, B, C, D, E, F);
int ans_w = 100*A, ans_s = 0;
foreach (x ; 0 .. 31) {
foreach (y ; 0 .. 31) {
int water = 100 * (A * x + B * y);
if (water == 0) continue;
int L = min((A*x + B*y) * E, F - 100*(A*x + B*y));
if (L < 0) break;
foreach (w ; 0 .. 3001) {
if (L - C*w < 0) break;
int z = (L - C*w) / D;
//if (z < 0) break;
int sugar = C*w + D*z;
if (ans_s * (water + sugar) < sugar * (ans_w + ans_s)) {
ans_w = water;
ans_s = sugar;
debug {
writeln(ans_w, " ", ans_s);
}
}
}
}
}
writeln(ans_w + ans_s, " ", ans_s);
}
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,std.algorithm;
void main(){
while(1){
auto rd = readln().chomp();
if(rd){
auto v = to!double( rd );
auto t = v/9.8;
auto y = 4.9*t*t;
for(int i=1;i<100000;i++){
if( y <= 5*i-5 ){
writeln(i);
break;
}
}
}else{
break;
}
}
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;
void main(){
auto n=readln.chomp.to!int;
auto as=readln.split.map!(to!long).array;
long fromNega;
long fromPosi;
long currentNega;
long currentPosi;
foreach(i,a;as){
currentNega+=a;
currentPosi+=a;
if(i%2){
if(currentNega>=0){
fromNega+=currentNega+1;
currentNega=-1;
}
if(currentPosi<=0){
fromPosi+=-currentPosi+1;
currentPosi=+1;
}
}else{
if(currentNega<=0){
fromNega+=-currentNega+1;
currentNega=+1;
}
if(currentPosi>=0){
fromPosi+=currentPosi+1;
currentPosi=-1;
}
}
}
writeln(min(fromNega,fromPosi));
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
import std.string;
import std.algorithm;
int main(string[] argv)
{
while (1)
{
auto s = readln().chomp().split().map!(to!int);
int mf = s[0] + s[1];
if (s[0] + s[1] + s[2] == -3) break;
if (s[0] == -1 || s[1] == -1) writeln("F");
else if (80 <= mf) writeln("A");
else if (65 <= mf) writeln("B");
else if (50 <= mf) writeln("C");
else if (30 <= mf)
if (50 <= s[2]) writeln("C");
else writeln("D");
else writeln("F");
}
return 0;
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; long x; readV(n, x);
auto h = new long[](n), p = new long[](n);
h[0] = 1; p[0] = 1;
foreach (i; 0..n) {
h[i+1] = h[i]*2+3;
p[i+1] = p[i]*2+1;
}
long pat(int i, long x)
{
if (i == 0) return 1;
if (x == 1) return 0;
else if (x <= h[i-1]+1) return pat(i-1, x-1);
else if (x == h[i-1]+2) return p[i-1]+1;
else if (x <= h[i-1]*2+2) return p[i-1]+1+pat(i-1, x-h[i-1]-2);
else return p[i-1]*2+1;
}
writeln(pat(n, 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;
long solve(size_t i, long sum) {
if (i == S.length) return sum;
long r;
foreach (j; i+1..S.length+1) {
r += solve(j, sum + S[i..j].to!long);
}
return r;
}
writeln(solve(0, 0));
}
|
D
|
import std.stdio : writeln;
void main()
{
foreach(i; 1..10){
foreach(j; 1..10){
writeln(i, "x", j, "=", i*j);
}
}
}
|
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, std.datetime;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long X = lread();
long ans;
ans += (X / 500) * 1000;
ans += ((X % 500) / 5) * 5;
writeln(ans);
}
|
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;
int n;
void main(){
n = readln.chomp.to!int;
bool[][] xss;
foreach(i; 0 .. n){
xss ~= readln.chomp.map!(x => (x == '#')).array;
}
int donecolumncount = 0;
foreach(j; 0 .. n){
bool f = 1;
foreach(i; 0 .. n){
if(!xss[i][j]) f = 0;
}
if(f) donecolumncount += 1;
}
int cmin = n + 1;
foreach(i; 0 .. n){
int c = 0;
foreach(j; 0 .. n){
if(!xss[i][j]){
c += 1;
if(i == j){
int f = 1;
foreach(ii; 0 .. n){
if(xss[ii][j]) f = 0;
}
c += f;
}
}
}
if(c < cmin) cmin = c;
}
int ans;
if(cmin > n) ans = -1;
else ans = cmin + n - donecolumncount;
ans.writeln;
}
|
D
|
import std.stdio,std.string,std.conv,std.array;
void main(){
//for(;;){
auto rc = readln().chomp();
auto transTable1 = makeTrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
writeln( translate(rc, transTable1) );
//}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
long[] make_lucas()
{
long[] ls = [2,1];
for (int i = 2; i < 87; ++i) {
ls ~= ls[i-1] + ls[i-2];
}
return ls;
}
enum LS = make_lucas();
void main()
{
writeln(LS[readln.chomp.to!int]);
}
|
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 S = readln.chomp;
auto T = readln.chomp;
long hatena = 0;
foreach (s; S) if (s == '?') hatena += 1;
auto cnt2 = new long[](26);
foreach (s; S) if (s != '?') cnt2[s - 'a'] += 1;
auto cnt = new long[](26);
foreach (t; T) cnt[t - 'a'] += 1;
long hi = 10^^7;
long lo = 0;
auto hoge = new long[](26);
long h;
while (hi - lo > 1) {
long mid = (hi + lo) / 2;
foreach (i; 0..26) hoge[i] = cnt[i] * mid - cnt2[i];
h = hatena;
foreach (i; 0..26) h -= max(0, hoge[i]);
if (h >= 0) lo = mid;
else hi = mid;
}
foreach (i; 0..26) cnt[i] = cnt[i] * lo - cnt2[i];
int p = 0;
while (p < 26 && cnt[p] <= 0) p += 1;
auto ans = new char[](S.length);
foreach (i; 0..S.length) {
if (S[i] == '?' && p < 26) {
ans[i] = (p.to!char + 'a').to!char;
cnt[p] -= 1;
while (p < 26 && cnt[p] <= 0) p += 1;
} else if (S[i] == '?' && p >= 26){
ans[i] = 'z';
} else {
ans[i] = S[i];
}
}
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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new long[](t);
auto arr = new long[]((10^^5) * 3);
foreach (i; 1..(10^^5) * 3)
{
arr[i] = arr[i-1] ^ i;
}
foreach (ti; 0..t)
{
auto a = RD!int;
auto b = RD!int;
auto x = arr[a-1] ^ b;
if (x == 0)
ans[ti] = a;
else if (x == a)
ans[ti] = a + 2;
else
ans[ti] = a + 1;
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto par=new int[](n);
par[0]=-1;
foreach(int i; 1..n){
int p; rd(p);
par[i]=(p-1);
}
auto leaf=new bool[](n);
foreach(i; 0..n){
auto c=count(par, i);
if(c==0) leaf[i]=true;
}
foreach(i; 0..n)if(leaf[i]==false){
int c=0;
foreach(j; 0..n){
if(par[j]==i && leaf[j]) c++;
}
if(c<3){writeln("No"); return;}
}
writeln("Yes");
}
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
|
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 solve() {
auto N = readln.chomp.to!int;
auto S = readln.chomp;
int pos = -1;
foreach (i; 0..N) if (S[i] == '8') {
pos = i;
break;
}
if (pos == -1 || N - pos < 11) {
writeln("NO");
} else {
writeln("YES");
}
}
void main() {
auto T = readln.chomp.to!int;
while (T--) solve;
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;
import core.checkedint;
void main()
{
int x, y;
readln.chomp.split.tie(x, y);
if (x == y) {
writeln = "=";
} else {
real a = y * log10(cast(real)x);
real b = x * log10(cast(real)y);
debug verbose(a, b);
if (abs(a - b) < 1e-9) {
writeln = "=";
} else {
writeln = a < b ? "<" : ">";
}
}
}
void tie(R, Args...)(R arr, ref Args args)
if (isRandomAccessRange!R || isArray!R)
in
{
assert (arr.length == args.length);
}
body
{
foreach (i, ref v; args) {
alias T = typeof(v);
v = arr[i].to!T;
}
}
void verbose(Args...)(in Args args)
{
stderr.write("[");
foreach (i, ref v; args) {
if (i) stderr.write(", ");
stderr.write(v);
}
stderr.writeln("]");
}
|
D
|
import std.stdio, std.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 s = readln.split.map!(to!long);
auto N = s[0];
auto K = s[1];
long x = K % 2 == 1 ? K / 2 : K / 2 - 1;
x += 1;
long hi = x;
long lo = 0;
while (hi - lo > 1) {
long m1 = (hi + lo) / 2;
long m2 = K - m1;
if (m1 < m2 && m2 <= N) {
hi = m1;
} else {
lo = m1;
}
}
writeln(x - hi);
}
|
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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new string[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto m = RD!int;
string[] a, b;
foreach (i; 0..n)
a ~= RD!string;
foreach (i; 0..n-1)
b ~= RD!string;
auto cnt = new long[][](m, 26);
foreach (i; 0..n)
{
foreach (j; 0..m)
{
++cnt[j][a[i][j]-'a'];
}
}
foreach (i; 0..n-1)
{
foreach (j; 0..m)
{
--cnt[j][b[i][j]-'a'];
}
}
foreach (i; 0..n)
{
bool ok = true;
foreach (j; 0..m)
{
if (cnt[j][a[i][j]-'a'] != 1)
{
ok = false;
break;
}
}
if (ok)
{
ans[ti] = a[i].idup;
break;
}
}
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 t = RD!int;
auto ans = new string[](t);
foreach (ti; 0..t)
{
auto s = RD!string;
if (s.length >= 2)
{
if (s[$-2..$] == "po")
{
ans[ti] = "FILIPINO";
continue;
}
if (s.length >= 4)
{
if (s[$-4..$] == "desu" || s[$-4..$] == "masu")
{
ans[ti] = "JAPANESE";
continue;
}
if (s.length >= 5)
{
if (s[$-5..$] == "mnida")
{
ans[ti] = "KOREAN";
continue;
}
}
}
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s, t;
scan(s);
scan(t);
int n = s.length.to!int, m = t.length.to!int;
auto dp = new int[][](n + 1, m + 1);
foreach (i ; 1 .. n + 1) {
dp[i][0] = i;
}
foreach (j ; 1 .. m + 1) {
dp[0][j] = j;
}
foreach (i ; 1 .. n + 1) {
foreach (j ; 1 .. m + 1) {
dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + (s[i-1] != t[j-1]));
}
}
writeln(dp[n][m]);
}
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;
void main()
{
const N = readln().chomp().to!long();
ulong sum = 0;
foreach (i; 1 .. N + 1)
{
if (i % 3 == 0) continue;
if (i % 5 == 0) continue;
sum += i;
}
writeln(sum);
}
|
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;
}
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long N = lread();
long X, Y;
scan(X, Y);
foreach (_; 1 .. N)
{
long T, A;
scan(T, A);
long na = (X + T - 1) / T;
long nb = (Y + A - 1) / A;
long n = max(na, nb);
X = n * T;
Y = n * A;
}
writeln(X + Y);
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
T scanElem(T = long)()
{
string res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
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;
}
void main()
{
string N = scanElem!string;
long[4][] dp = new long[4][N.length+1];
dp[0][0] = 1;
foreach(i, c; N)
{
dp[i+1][0] = c=='?' ? dp[i][0]*3 : dp[i][0];
dp[i+1][1] = c=='?' ? dp[i][1]*3 : dp[i][1];
dp[i+1][2] = c=='?' ? dp[i][2]*3 : dp[i][2];
dp[i+1][3] = c=='?' ? dp[i][3]*3 : dp[i][3];
if(c=='A' || c=='?')dp[i+1][1] += dp[i][0];
if(c=='B' || c=='?')dp[i+1][2] += dp[i][1];
if(c=='C' || c=='?')dp[i+1][3] += dp[i][2];
dp[i+1][]%=10^^9+7;
}
writeln(dp[$-1][3]);
}
|
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_007;
void main() {
int x, a;
scan(x, a);
writeln(x < a ? 0 : 10);
}
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 Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
long cnt;
void main()
{
auto s = sread();
if (s == "AAA" || s == "BBB")
writeln("No");
else
writeln("Yes");
}
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.algorithm;
import std.array;
void main() {
auto tmp = readln.split.map!(s => s.chomp[0]).array;
auto X = tmp[0];
auto Y = tmp[1];
writeln(X == Y ? "=" : X < Y ? "<" : ">");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto n = readln.chomp.to!int;
int[string] words;
auto f = true;
auto prev = readln.chomp;
words[prev]++;
foreach (i; 1..n) {
auto w = readln.chomp;
if (words.get(w, 0) || prev[$-1] != w[0]) {
f = false;
} else {
words[w]++;
}
prev = w;
}
if (f) {
writeln("Yes");
} else {
writeln("No");
}
}
|
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() {
auto s = iota(3).map!(i => readln.chomp.map!(ch => ch - 'a').array).array;
int p = 0;
while (!s[p].empty) {
int np = s[p].front;
s[p].popFront();
p = np;
}
writeln((p + 'A').to!char);
}
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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto dp = new long[](N + 2);
dp[] = long.max;
dp[0] = 0;
foreach (i; 0 .. N)
{
dp[i + 1] = dp[i + 1].min(dp[i] + 1);
{
long tmp = 6;
while (i + tmp <= N)
dp[i + tmp] = dp[i + tmp].min(dp[i] + 1), tmp *= 6;
}
{
long tmp = 9;
while (i + tmp <= N)
dp[i + tmp] = dp[i + tmp].min(dp[i] + 1), tmp *= 9;
}
}
writeln(dp[N]);
}
|
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, c; readV(a, b, c);
writeln(min(b/a, c));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto N = readln.chomp;
int s;
foreach (c; N) s += (c - '0').to!int;
writeln(s%9 == 0 ? "Yes" : "No");
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N, K;
scan(N, K);
auto X = new long[](10 ^^ 5 + 1);
foreach (_; 0 .. N)
{
long a, b;
scan(a, b);
X[a] += b;
}
foreach (i; 0 .. X.length)
{
K -= X[i];
if (0 >= K)
{
writeln(i);
return;
}
}
}
|
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();
void main()
{
auto stack = DList!long();
auto s = sread();
long cnt;
foreach(e; s)
{
if(stack.empty || stack.back == e)
{
stack.insertBack(e);
}
else
{
cnt += 2;
stack.removeBack();
}
}
cnt.writeln();
}
|
D
|
import std.stdio,std.conv,std.string;
void main(){
foreach(_;0..readln.chomp.to!int){
int point,base,_out;
while(1){
final switch(readln.chomp){
case "HIT":
if(base==3)++point;
else ++base;
break;
case "HOMERUN":
point+=base+1;
base=0;
break;
case "OUT":
++_out;
break;
}
if(_out==3)break;
}
point.writeln;
}
}
|
D
|
void main()
{
long[] tmp = readln.split.to!(long[]);
long n = tmp[0], t = tmp[1];
long[] a = readln.split.to!(long[]);
long x = t;
foreach (i; 0 .. n-1)
{
x += min(t, a[i+1]-a[i]);
}
x.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
auto a = readln.splitter.map !(to !(int)).array;
int lo = int.max;
int hi = 0;
bool ok = true;
foreach (i; 0..n)
{
lo = min (lo, a[i] - hi);
hi = max (hi, a[i] - lo);
ok &= (lo >= 0 && lo + hi == a[i]);
debug {writeln (lo, " ", hi, " ", ok);}
}
writeln (ok ? "YES" : "NO");
}
}
|
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;
long n, s;
void main() {
scan(n);
scan(s);
if (n == s) {
writeln(n + 1);
return;
}
for (long b = 2; b*b <= n; b++) {
if (f(b, n) == s) {
writeln(b);
return;
}
}
long ans = n + 1;
for (long p = 1; p*p < n; p++) {
long b = (n - s) / p + 1;
if (f(b, n) == s) {
ans = b;
}
}
writeln(ans == n + 1 ? -1 : ans);
}
long f(long b, long n) {
if (b < 2) return 0;
return n < b ? n : f(b, n / b) + (n % b);
}
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.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, c; readV(a, b, c);
auto v = new bool[](b);
foreach (i; 1..b+1) {
auto m = a*i%b;
if (m == c) {
writeln("YES");
return;
} else if (v[m]) {
writeln("NO");
return;
}
v[m] = true;
}
}
|
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 M = RD;
auto A = new string[](N);
auto B = new string[](M);
foreach (i; 0..N)
A[i] = RD!string;
foreach (i; 0..M)
B[i] = RD!string;
bool ans;
(){
foreach (y; 0..N-M+1)
{
foreach (x; 0..N-M+1)
{
bool ok = true;
foreach (i; 0..M)
{
foreach (j; 0..M)
{
if (A[y+i][x+j] != B[i][j])
{
ok = false;
break;
}
}
}
if (ok)
{
ans = true;
return;
}
}
}}();
writeln(ans ? "Yes" : "No");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.array;
void main()
{
auto reader = readln.split;
int N = reader[0].to!int;
int K = reader[1].to!int;
string S = readln.chomp;
int[] cnt;
int beforeI = 0;
if (S[0] == '0') cnt ~= 0;
foreach (i; 0..N){
if (S[i] != S[beforeI]){
cnt ~= i - beforeI;
beforeI = i;
}
}
cnt ~= N - beforeI;
if (S[N - 1] == '0') cnt ~= 0;
ulong cntLen = cnt.length;
int sumRange = K * 2 + 1;
int sum = 0;
foreach (i; 0..sumRange){
if (i >= cntLen) break;
sum += cnt[i];
}
int ans = sum;
for (uint i = 2; i + sumRange - 1 < cntLen; i += 2){
sum -= cnt[i - 2];
sum -= cnt[i - 1];
sum += cnt[i + sumRange - 2];
sum += cnt[i + sumRange - 1];
if (sum > ans) ans = sum;
}
writeln(ans);
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
auto s = readln.chomp.to!(char[]);
int sum = 0;
foreach (c; s[1 .. $]) {
if (c == 'E')
sum++;
}
auto mn = sum;
foreach (i; 1 .. n) {
if (s[i - 1] == 'W')
sum++;
if (s[i] == 'E')
sum--;
mn = min(mn, sum);
}
writeln(mn);
}
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 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 N = lread();
long i = 1;
long ans;
while (true)
{
char[4] t = ['0', '3', '5', '7'];
string s;
long j = i;
bool[] b = new bool[](4);
while (j != 0)
{
b[j % 4] = true;
s = t[j % 4] ~ s;
j /= 4;
}
if (!b[0] && b[1 .. $].all!(x => x))
{
// writefln("%d %s", i, s);
if (N < s.to!long)
{
writeln(ans);
return;
}
ans++;
}
i++;
}
}
|
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 f = true;
if (!(s.length % 2)) {
foreach (i; 0..s.length/2) {
if (s[i*2..i*2+2] != "hi") {
f = false;
break;
}
}
} else {
f = false;
}
if (f) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto s = readln.chomp.to!(char[]);
char[] t;
foreach (i; 0 .. (s.length)) {
if (i % 2 == 0) {
t ~= s[i];
}
}
writeln(t);
}
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;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
auto n = lread();
auto a = aryread();
auto ans = new long[](2 * (10 ^^ 5) + 10);
foreach (i; 0 .. n - 1)
{
ans[a[i]] += 1;
}
foreach (i; 1 .. n + 1)
{
writeln(ans[i]);
}
}
//https://rclone.org/
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
import std.stdio,std.string,std.array;
void main(){
string line,sw;
size_t total=0;
sw = readln().chomp();
while( 1 ){
line = readln().chomp();
if( line == "END_OF_TEXT" ){ break; }
foreach( w ; line.split() ){
if( toLower(w) == toLower(sw) ) total++;
}
}
writeln( total );
}
|
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 X = RD;
auto T = RD;
writeln((N+X-1)/X * T);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
void position(int n, int row, int col, char[6][1000] rows)
{
rows[row][col] = rows[row][col + 1] = '+';
printf("YES\n");
for (int i = 0; i < n; i++) {
printf("%s\n", rows[i].ptr);
}
}
void main()
{
int n;
scanf("%d", &n);
char[6][1000] rows;
for (int i = 0; i < n; i++) {
scanf("%s", rows[i].ptr);
}
for (int i = 0; i < n; i++) {
if (rows[i][0] == 'O' && rows[i][1] == 'O') {
position(n, i, 0, rows);
return;
}
if (rows[i][3] == 'O' && rows[i][4] == 'O') {
position(n, i, 3, rows);
return;
}
}
printf("NO\n");
}
|
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(){
(readln.chomp.to!int / 3).writeln;
}
|
D
|
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
string my_readln() { return chomp(readln()); }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto tokens = my_readln.split;
auto N = tokens[0].to!long;
auto A = my_readln;
auto B = my_readln;
auto C = my_readln;
ulong ans;
foreach (i; 0..N)
{
ulong cnt;
if (A[i] != B[i]) ++cnt;
if (A[i] != C[i]) ++cnt;
if (B[i] != C[i]) ++cnt;
if (cnt == 2) ++ans;
else if (cnt == 3) ans += 2;
}
writeln(ans);
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!(long, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto s = sread();
long pcnt;
foreach (e; s)
pcnt += e == 'p' ? 1 : 0;
writeln(s.length / 2 - pcnt);
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
/+ dub.sdl:
name "D"
dependency "dcomp" version=">=0.7.3"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.algorithm;
int main() {
Scanner sc = new Scanner(stdin);
int n, k;
sc.read(n, k);
int[2][] p = new int[2][n];
foreach (i; 0..n) {
sc.read(p[i][0], p[i][1]);
}
int calc(int l, int r, int o, int u) {
int c;
foreach (d; p) {
if (l <= d[0] && d[0] <= r && o <= d[1] && d[1] <= u) {
c++;
}
}
return c;
}
long ans = 5 * (10L^^18);
foreach (a; 0..n) {
foreach (b; a..n) {
foreach (c; b..n) {
foreach (d; c..n) {
auto xv = [p[a][0], p[b][0], p[c][0], p[d][0]];
auto yv = [p[a][1], p[b][1], p[c][1], p[d][1]];
int l = xv.minimum;
int r = xv.maximum;
int o = yv.minimum;
int u = yv.maximum;
int C = calc(l, r, o, u);
if (C < k) continue;
ans = min(ans, long(r-l)*(u-o));
}
}
}
}
writeln(ans);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
version (X86) static if (__VERSION__ < 2071) {
import core.bitop : bsf, bsr, popcnt;
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
// import dcomp.array;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
FastAppender!(E[]) buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;
import std.range.primitives;
import std.traits : isFloatingPoint, isIntegral;
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
while (r-l > 1) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
foreach (i; 0..cnt) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}
ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return minimum!pred(range, e);
}
E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}
ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return maximum!pred(range, e);
}
Rotator!Range rotator(Range)(Range r) {
return Rotator!Range(r);
}
struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
size_t cnt;
Range start, now;
this(Range r) {
cnt = 0;
start = r.save;
now = r.save;
}
this(this) {
start = start.save;
now = now.save;
}
@property bool empty() {
return now.empty;
}
@property auto front() {
assert(!now.empty);
import std.range : take, chain;
return chain(now, start.take(cnt));
}
@property Rotator!Range save() {
return this;
}
void popFront() {
cnt++;
now.popFront;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;
T[N] fixed(T, size_t N)(T[N] a) {return a;}
struct FastAppender(A, size_t MIN = 4) {
import std.algorithm : max;
import std.conv;
import std.range.primitives : ElementEncodingType;
import core.stdc.string : memcpy;
private alias T = ElementEncodingType!A;
private T* _data;
private uint len, cap;
@property size_t length() const {return len;}
bool empty() const { return len == 0; }
void reserve(size_t nlen) {
import core.memory : GC;
if (nlen <= cap) return;
void* nx = GC.malloc(nlen * T.sizeof);
cap = nlen.to!uint;
if (len) memcpy(nx, _data, len * T.sizeof);
_data = cast(T*)(nx);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void opOpAssign(string op : "~")(T item) {
if (len == cap) {
reserve(max(MIN, cap*2));
}
_data[len++] = item;
}
void insertBack(T item) {
this ~= item;
}
void removeBack() {
len--;
}
void clear() {
len = 0;
}
ref inout(T) back() inout { assert(len); return _data[len-1]; }
ref inout(T) opIndex(size_t i) inout { return _data[i]; }
T[] data() {
return (_data) ? _data[0..len] : null;
}
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/
|
D
|
// Cheese-Cracker: cheese-cracker.github.io
void theCode(){
ll n = scan;
ll tim = (n / 2) * 5;
if(n % 2 != 0) tim += 5;
tim = max(tim, 15);
writeln(tim);
}
void main(){
long tests = scan; // Toggle!
while(tests--) theCode();
}
/********* That's All Folks! *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x", long, "y");
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;
void main() {
int a, b, c, x, y;
scan(a, b, c, x, y);
int ans = 1<<30;
foreach (i ; 0 .. 2 * 10^^5 + 1) {
int xr = max(0, x - i / 2);
int yr = max(0, y - i / 2);
int tmp = xr * a + yr * b + i * c;
ans = min(ans, tmp);
}
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;
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() {
int ans = 0;
foreach (c; readln.chomp)
if (c == '+')
ans++;
else
ans--;
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;
void main() {
auto c = new string[](2);
c[0] = readln.chomp;
c[1] = readln.chomp;
string ans = (equal(c[0], c[1].retro)) ? "YES" : "NO";
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 A = RD;
auto B = RD;
writeln(A <= 8 && B <= 8 ? "Yay!" : ":(");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string, std.conv;
void main()
{
while(true)
{
int num = readln.chomp.to!int, cnt;
if(!num)break;
while(num) cnt += num /= 5;
cnt.writeln;
}
}
|
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[] xs = readln.chomp.map!"a=='o'".array;
long n = xs.length;
long t = xs.count!"a";
writeln((15 - n) + t>=8 ? "YES" : "NO");
}
// ----------------------------------------------
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);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
private template RebindableOrUnqual(T)
{
static if (is(T == class) || is(T == interface) || isDynamicArray!T || isAssociativeArray!T)
alias RebindableOrUnqual = Rebindable!T;
else
alias RebindableOrUnqual = Unqual!T;
}
private auto extremum(alias map, alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
in
{
assert(!r.empty, "r is an empty range");
}
body
{
alias Element = ElementType!Range;
RebindableOrUnqual!Element seed = r.front;
r.popFront();
return extremum!(map, selector)(r, seed);
}
private auto extremum(alias map, alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
{
alias mapFun = unaryFun!map;
alias selectorFun = binaryFun!selector;
alias Element = ElementType!Range;
alias CommonElement = CommonType!(Element, RangeElementType);
RebindableOrUnqual!CommonElement extremeElement = seedElement;
// if we only have one statement in the loop, it can be optimized a lot better
static if (__traits(isSame, map, a => a))
{
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
if (selectorFun(r[i], extremeElement))
{
extremeElement = r[i];
}
}
}
else
{
while (!r.empty)
{
if (selectorFun(r.front, extremeElement))
{
extremeElement = r.front;
}
r.popFront();
}
}
}
else
{
alias MapType = Unqual!(typeof(mapFun(CommonElement.init)));
MapType extremeElementMapped = mapFun(extremeElement);
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
MapType mapElement = mapFun(r[i]);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r[i];
extremeElementMapped = mapElement;
}
}
}
else
{
while (!r.empty)
{
MapType mapElement = mapFun(r.front);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r.front;
extremeElementMapped = mapElement;
}
r.popFront();
}
}
}
return extremeElement;
}
private auto extremum(alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r);
}
// if we only have one statement in the loop it can be optimized a lot better
private auto extremum(alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r, seedElement);
}
auto minElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!map(r);
}
auto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!map(r, seed);
}
auto maxElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!(map, "a > b")(r);
}
auto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!(map, "a > b")(r, seed);
}
}
// 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;
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.ascii;
import std.concurrency;
import std.traits;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
const long INF = long.max/3;
const long MOD = 10L^^9+7;
void main() {
int N = 3;
int[][] css = N.rep!(() =>readln.split.to!(int[]));
int[] as = new int[N];
int[] bs = new int[N];
as[0] = 0;
foreach(j; 0..N) {
bs[j] = css[0][j] - as[0];
}
foreach(i; 1..N) {
as[i] = css[i][0] - bs[0];
}
foreach(i; 0..N) foreach(j; 0..N) {
if (css[i][j] != as[i] + bs[j]) {
"No".writeln;
return;
}
}
"Yes".writeln;
}
// ----------------------------------------------
void scanln(Args...)(auto ref Args args) {
import std.meta;
template getFormat(T) {
static if (isIntegral!T) {
enum getFormat = "%d";
} else static if (isFloatingPoint!T) {
enum getFormat = "%g";
} else static if (isSomeString!T || isSomeChar!T) {
enum getFormat = "%s";
} else {
static assert(false);
}
}
enum string str = [staticMap!(getFormat, Args)].join(" ") ~ "\n";
// readf!str(args);
mixin("str.readf(" ~ Args.length.iota.map!(i => "&args[%d]".format(i)).join(", ") ~ ");");
}
void times(alias fun)(int n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (__traits(isIntegral, T)) {
// `(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 (__traits(isIntegral, T)) {
T t = x / y;
if (t * y > x) t--;
return t;
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto n = RD!int;
auto k = RD!int;
auto s = RD!string;
foreach (i; 0..n)
{
if (i == 0)
{
if (n == 1)
{
if (k != 0)
write("0");
else
write(s[i]);
}
else
{
if (k == 0 || s[i] == '1')
write(s[i]);
else
{
--k;
write("1");
}
}
}
else
{
if (k == 0 || s[i] == '0')
write(s[i]);
else
{
--k;
write("0");
}
}
}
writeln();
stdout.flush();
debug readln();
}
|
D
|
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
void main()
{
auto n = readln.chomp.to!long;
string result;
while (n != 0)
{
long m = n % -2;
// writeln([n,m]);
n /= -2;
result = ((m == 0) ? "0" : "1") ~ result;
if (m == -1)
{
n++;
}
}
if (result.length == 0)
{
writeln("0");
}
else
{
writeln(result);
}
}
|
D
|
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
void main() {
auto N = readln.chomp.to!ulong;
ulong answer = N-1;
for(ulong i = 1; i * i <= N; i++) {
if (N % i != 0) continue;
auto j = N/i;
auto candidate = i-1 + j-1;
if (candidate < answer) answer = candidate;
}
writeln(answer);
}
|
D
|
void main() {
int x = readln.chomp.to!int;
int d = x / 100, r = x % 100;
writeln(d >= (r + 4) / 5 ? 1 : 0);
}
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.string, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
int c=0;
foreach(s;stdin.byLine())
{
bool f=true;
foreach(i;0..s.length/2+1)
if(s[i]!=s[$-i-1])
{ f=false;break;}
if(f) ++c;
}
writeln(c);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;
void main(){
auto S=readln.chomp;
if(S[0]=='a' && S[1]=='b' && S[2]=='c')writeln("Yes");
else if(S[0]=='a' && S[1]=='c' && S[2]=='b')writeln("Yes");
else if(S[0]=='b' && S[1]=='a' && S[2]=='c')writeln("Yes");
else if(S[0]=='b' && S[1]=='c' && S[2]=='a')writeln("Yes");
else if(S[0]=='c' && S[1]=='b' && S[2]=='a')writeln("Yes");
else if(S[0]=='c' && S[1]=='a' && S[2]=='b')writeln("Yes");
else writeln("No");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main() {
while (true) {
auto input = readln().split;
if (input.length == 0) break;
writeln(to!int(input[0]) + to!int(input[1]));
}
}
|
D
|
void main() {
writeln(48 - 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
|
module app;
import core.bitop;
import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;
struct Input
{
string s;
}
void parseInput(T)(out Input input, T adapter)
{
with (input)
{
s = adapter.readln();
}
}
struct Output
{
}
auto main2(Input* input)
{
if (input.s[$-1] == 's')
return input.s ~ "es";
else
return input.s ~ "s";
}
alias retType = ReturnType!main2;
static if (!is(retType == void))
{
unittest { writeln("begin unittest"); }
auto _placeholder_ = ReturnType!main2.init;
unittest // example1
{
string example =
`apple`;
if (example.empty) return;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
printResult(result);
assert(result == "apples");
}
unittest // example2
{
string example =
`bus`;
if (example.empty) return;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
printResult(result);
assert(result == "buses");
}
unittest // example3
{
string example =
`box`;
if (example.empty) return;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
printResult(result);
assert(result == "boxs");
}
unittest { writeln("end unittest"); }
void parseExample(out Input input, string example)
{
parseInput(input, new StringAdapter(example));
}
}
class StdinAdapter
{
// readf!"%s"は使えない
// https://issues.dlang.org/show_bug.cgi?id=19820
uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
string readln() { return std.stdio.readln().strip(); }
}
class StringAdapter
{
import std.format;
string _s;
this(string input) { _s = input; }
uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
string readln()
{
string ret;
auto i = _s.countUntil("\n");
if (i == -1) { ret = _s; _s = ""; }
else { ret = _s[0..i]; _s = _s[i+1..$]; }
return ret;
}
}
void printResult(T)(T result)
{
static if (isFloatingPoint!T) writefln("%f", result);
else writeln(result);
}
void main()
{
Input input = void;
parseInput(input, new StdinAdapter());
static if (is(retType == void))
main2(&input);
else
{
auto result = main2(&input);
printResult(result);
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;
void main() {
readln.chomp.to!int.pipe!(K => (K+1)/2 * (K/2)).writeln;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a, b;
scan(a, b);
auto map = new char[][](100, 100);
fillAll(map, '.');
foreach (i ; 0 .. 50) {
foreach (j ; 0 .. 50) {
map[i][j] = '#';
}
}
a--;
foreach (i ; 0 .. 25) {
foreach (j ; 0 .. 25) {
if (a == 0) {
goto B1;
}
a--;
map[2*i][2*j] = '.';
}
}
B1:
b--;
foreach (i ; 0 .. 25) {
foreach (j ; 0 .. 50) {
if (b == 0) {
goto B2;
}
b--;
map[50 + 2*i + 1][2*j] = '#';
}
}
B2:
writeln("100 100");
foreach (i ; 0 .. 100) {
writeln(map[i]);
}
}
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 s = readln.chomp;
writeln(s.canFind('9') ? "Yes" : "No");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto h = readln.chomp.to!int;
writeln((a + b) * h / 2);
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.