code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
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!int);
auto N = s[0];
auto M = s[1];
auto A = s[2];
auto B = s[3];
auto ans = new dchar[][](N, M);
bool solve(bool hoge) {
foreach (i; 0..N) fill(ans[i], '.');
int a = A;
int b = B;
if (N >= 3 && M >= 3 && N % 2 == 1 && M % 2 == 1 && hoge) {
if (a >= 1) {
ans[$-3][$-3] = '<';
ans[$-3][$-2] = '>';
}
if (a >= 2) {
ans[$-1][$-2] = '<';
ans[$-1][$-1] = '>';
}
if (b >= 1) {
ans[$-3][$-1] = '^';
ans[$-2][$-1] = 'v';
}
if (b >= 2) {
ans[$-2][$-3] = '^';
ans[$-1][$-3] = 'v';
}
a -= 2;
b -= 2;
}
if (N % 2 == 1)
for (int c = 0; c < M - M % 2 && ans[$-1][c] == '.' && ans[$-1][c+1] == '.' && a > 0; c += 2)
ans[$-1][c] = '<', ans[$-1][c+1] = '>', a -= 1;
if (M % 2 == 1)
for (int r = 0; r < N - N % 2 && ans[r][$-1] == '.' && ans[r+1][$-1] == '.' && b > 0; r += 2)
ans[r][$-1] = '^', ans[r+1][$-1] = 'v', b -= 1;
int r = 0, c = 0;
while (r < N - N % 2 && c < M - M % 2 && a > 0 && ans[r][c] == '.') {
ans[r][c] = '<';
ans[r][c+1] = '>';
if (a >= 2) {
ans[r+1][c] = '<';
ans[r+1][c+1] = '>';
}
a -= 2, c += 2;
if (c >= M - M % 2) r += 2, c = 0;
}
while (r < N - N % 2 && c < M - M % 2 && b > 0 && ans[r][c] == '.') {
ans[r][c] = '^';
ans[r+1][c] = 'v';
if (b >= 2) {
ans[r][c+1] = '^';
ans[r+1][c+1] = 'v';
}
b -= 2, c += 2;
if (c >= M - M % 2) r += 2, c = 0;
}
return a <= 0 && b <= 0;
}
if (solve(false)) {
writeln("YES");
ans.each!writeln;
} else if (solve(true)) {
writeln("YES");
ans.each!writeln;
} else {
writeln("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;
enum inf = 10L^^15;
enum mod = 10L ^^ 9 + 7;
void main() {
int n, k;
scan(n, k);
auto a = readln.split.to!(int[]);
auto dp = new long[][](n + 1, k + 1);
dp[0][0] = 1;
foreach (i ; 1 .. n + 1) {
foreach (j ; 0 .. k + 1) {
dp[i][j] = dp[i-1][j];
if (j > 0) {
dp[i][j] += dp[i][j-1];
dp[i][j] %= mod;
}
if (j - a[i-1] - 1 >= 0) {
dp[i][j] += mod - dp[i-1][j-a[i-1]-1];
dp[i][j] %= mod;
}
}
}
debug {
writefln("%(%s\n%)", dp);
}
auto ans = dp[n][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
|
unittest
{
assert( [ "aca", "accc", "ca" ].parse.expand.solve == "A" );
assert( [ "abcb", "aacb", "bccc" ].parse.expand.solve == "C" );
}
import std.conv;
import std.range;
import std.stdio;
import std.typecons;
void main()
{
stdin.byLineCopy.parse.expand.solve.writeln;
}
auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
auto a = input.front;
input.popFront;
auto b = input.front;
input.popFront;
auto c = input.front;
return tuple( a, b, c );
}
auto solve( string a, string b, string c )
{
auto ss = [ a, b, c ];
auto t = 0L;
while( 0 < ss[ t ].length )
{
auto n = ss[ t ][ 0 ] - 'a';
ss[ t ].popFront;
t = n;
}
auto ans = "A".dup;
ans[ 0 ] += t;
return ans;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long A, B, C;
scan(A, B, C);
writeln(min(C, B / A));
}
|
D
|
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;
void main(){
while(true){
auto s = readln();
if(stdin.eof()) break;
int n = to!int(chomp(s));
int ans = 1;
for(int i=1;i<=n;i++)
ans += i;
writeln(ans);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;
import std.math;
void main(){
auto z=readln.split.map!(to!int);
auto A=z[0]+z[1];
auto B=z[0]-z[1];
auto C=z[0]*z[1];
writeln(max(A,B,C));
}
|
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;
int calc(string s) {
int n = cast(int)s.length;
int[] ws = new int[s.length]; // [0, i] の白の個数
for (int i = 0; i < s.length; i++) {
if (s[i] == '.') ws[i]++;
if (i > 0) ws[i] += ws[i-1];
}
// [l, r] の白の個数
int countW(int l, int r) {
return ws[r] - (l > 0 ? ws[l-1] : 0);
}
// [l, r] の黒の個数
int countB(int l, int r) {
return (r - l + 1) - countW(l, r);
}
int ans = countW(0, n-1); // 全ての白を黒にするコスト
for (int i = 0; i < n; i++) {
// [0, i] を白、[i+1, n-1] を黒にするコスト
int b = countB(0, i);
int w = i == n - 1 ? 0 : countW(i + 1, n - 1);
ans = min(ans, b + w);
}
return ans;
}
void main() {
readint;
string s = read!string;
int ans = calc(s);
writeln(ans);
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
auto S = sread();
writeln(S == "ABC" ? "ARC" : "ABC");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;
long P = 10^^9+7;
long[10000] F, RF;
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
long inv(long x)
{
return pow(x, P-2);
}
void init()
{
F[0] = F[1] = 1;
foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;
{
RF[$-1] = 1;
auto x = F[$-1];
auto k = P-2;
while (k) {
if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
x = x^^2 % P;
k /= 2;
}
}
foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}
long comb(N)(N n, N k)
{
if (k > n) return 0;
auto n_b = F[n]; // n!
auto nk_b = RF[n-k]; // 1 / (n-k)!
auto k_b = RF[k]; // 1 / k!
auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!
return (n_b * nk_b_k_b) % P; // n! / (n-k)!k!
}
long perm(N)(N n, N k)
{
if (k > n) return 0;
auto n_b = F[n];
auto n_k_b = RF[n-k];
return (n_b * n_k_b) % P;
}
void main()
{
init();
auto nk = readln.split.to!(long[]);
auto N = nk[0];
auto K = nk[1];
writeln(comb(N+K-1, K-1));
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!long).array;
auto B = new long[](N+1);
foreach (i; 0..N) B[i+1] = B[i] + A[i];
auto dp = new long[][](N, N);
foreach (i; 0..N) foreach (j; 0..N) if (i != j) dp[i][j] = 1L << 59;
foreach (len; 2..N+1) {
foreach (i; 0..N-len+1) {
int j = i + len - 1;
foreach (k; i..j) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + B[j+1] - B[i]);
}
}
}
dp[0][N-1].writeln;
}
|
D
|
void main()
{
long[] tmp = rdRow;
long n = tmp[0], p = tmp[1];
long[] a = rdRow;
long odd = a.count!(x => (x & 1) == 1);
long even = n - odd;
if (odd == 0) writeln(p ? 0 : 1L << even);
else writeln(1L << (n - 1));
}
T rdElem(T = long)()
{
//import std.stdio : readln;
//import std.string : chomp;
//import std.conv : to;
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
dchar[] rdDchar()
{
//import std.conv : to;
return rdStr.to!(dchar[]);
}
T[] rdRow(T = long)()
{
//import std.stdio : readln;
//import std.array : split;
//import std.conv : to;
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
//import std.range : iota;
//import std.algorithm : map;
//import std.array : array;
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
//import std.range : iota;
//import std.algorithm : map;
//import std.array : array;
return iota(col).map!(x => rdRow!T).array;
}
void wrMat(T = long)(T[][] mat)
{
//import std.stdio : write, writeln;
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.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;
bool solve (string s, string t)
{
if ((s.length % 2) != (t.length % 2))
{
s = s[1..$];
}
int pos = 0;
bool skip = false;
foreach (ref c; s)
{
if (skip)
{
skip = false;
continue;
}
if (t[pos] == c)
{
pos += 1;
}
else
{
skip = true;
}
if (pos == t.length)
{
return true;
}
}
return false;
}
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
auto t = readln.strip;
writeln (solve (s, t) ? "YES" : "NO");
}
}
|
D
|
void main() {
auto N = ri;
if(N%2==1) writeln(N*2);
else writeln(N);
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
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;
enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto n = lread();
auto a = aryread();
long current = 1, count;
foreach(e; a)
{
if(e == current)
current++;
else
count++;
}
if(current == 1 && count > 0)
writeln(-1);
else
writeln(count);
}
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;
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.math;
void main() {
auto input = getStdin!(int[])()[0];
auto result = pow(input, 3);
result.writeln;
}
T getStdin(T)() {
string[] cmd;
string line;
while ((line = chomp(stdin.readln())) != "") cmd ~= line;
return to!(T)(cmd);
}
|
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;
final class InputReader {
private:
ubyte[] p, buffer;
bool eof;
bool rawRead () {
if (eof) {
return false;
}
p = stdin.rawRead (buffer);
if (p.empty) {
eof = true;
return false;
}
return true;
}
ubyte nextByte(bool check) () {
static if (check) {
if (p.empty) {
if (!rawRead ()) {
return 0;
}
}
}
auto r = p.front;
p.popFront ();
return r;
}
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
}
bool seekByte (in ubyte lo) {
while (true) {
p = p.find! (c => c >= lo);
if (!p.empty) {
return false;
}
if (!rawRead ()) {
return true;
}
}
}
template next(T) if (isSigned!T) {
T next () {
if (seekByte (45)) {
return 0;
}
T res;
ubyte b = nextByte!false ();
if (b == 45) {
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte!true ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
T next () {
if (seekByte (48)) {
return 0;
}
T res = nextByte!false () - 48;
while (true) {
ubyte b = nextByte!true ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
T[] nextA(T) (in int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
void main() {
auto r = new InputReader ();
immutable nt = r.next!uint ();
foreach (tid; 0 .. nt) {
const uint h = r.next!uint ();
const uint w = r.next!uint ();
auto a = new char[][](h, w);
foreach (j; 0 .. h) {
foreach (i; 0 .. w) {
if (i || j) write ('B'); else write('W');
}
writeln;
}
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main(){
string str;
while((str = readln()).length != 0){
int n = to!int(chomp(str));
int cv;
foreach(a; 0 .. 10){
foreach(b; 0 .. 10){
foreach(c; 0 .. 10){
int d = n - a - b - c;
if(0 <= d && d <= 9){
cv++;
}
}
}
}
writeln(cv);
}
}
|
D
|
import std.algorithm;
import std.array;
import std.container;
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;
long calc(string s) {
long ans = 0;
int w = 0;
for (int i = cast(int) s.length - 1; i >= 0; i--) {
if (s[i] == 'W') w++;
else if (s[i] == 'B') {
ans += w;
}
}
return ans;
}
void main() {
string s = read!string;
writeln(calc(s));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
int[10^^5] BS;
void main()
{
auto nk = readln.split.to!(int[]);
auto N = nk[0];
auto K = nk[1];
size_t i;
int cnt;
char fst, lst;
foreach (j, s; readln.chomp) {
if (!j) {
fst = lst = s;
}
if (lst != s) {
BS[i++] = cnt * (lst == '0' ? -1 : 1);
lst = s;
cnt = 0;
}
++cnt;
}
BS[i] = cnt * (lst == '0' ? -1 : 1);
auto len = i+1;
int max_c, cur;
i = 0;
size_t j = 0;
for (;;) {
cur += abs(BS[j]);
if (BS[j] < 0) --K;
++j;
while (i < len && K < 0) {
cur -= abs(BS[i]);
if (BS[i] < 0) ++K;
++i;
}
max_c = max(max_c, cur);
if (j == len) break;
}
writeln(max_c);
}
|
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;
auto leftList = new long[N+1];
foreach (i; 0..N) leftList[i+1] = S[i] == 'E' ? 1 : 0;
foreach (i; 0..N) leftList[i+1] += leftList[i];
auto rightList = new long[N+1];
foreach (i; 0..N) rightList[i+1] = S[i] == 'W' ? 1 : 0;
foreach (i; 0..N) rightList[i+1] += rightList[i];
iota(N+1).map!(i => rightList[i] + leftList[$-1] - leftList[i]).reduce!min.writeln;
}
|
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() {
while(true) {
long[] input = readln.split.to!(long[]);
if (stdin.eof) break;
long gcd = gcd(input[0], input[1]);
writeln(gcd, " ", input[0]*input[1]/gcd);
}
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long T = lread();
foreach (i; 0 .. T)
{
long N, M, A, B;
scan(N, M, A, B);
floor_sum(N, M, A, B).writeln();
}
}
long floor_sum(long n, long m, long a, long b)
{
long ans;
if (m <= a)
{
ans += (n - 1) * n * (a / m) / 2;
a %= m;
}
if (m <= b)
{
ans += n * (b / m);
b %= m;
}
long y_max = (a * n + b) / m, x_max = (y_max * m - b);
if (y_max == 0)
return ans;
ans += (n - (x_max + a - 1) / a) * y_max;
ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
return ans;
}
|
D
|
import std.stdio;
import std.string;
void main() {
auto s = readln.chomp;
foreach (i;0..s.length) {
write('x');
}
writeln();
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;
immutable int inf = 1<<20;
void main(){
int N, M, a, b, c;
readVars(N, M);
auto cost = new int[][](N, N);
foreach(i ; 0 .. N){
foreach(j ; i + 1 .. N){
cost[i][j] = inf;
cost[j][i] = inf;
}
}
foreach (i ; 0 .. M){
readVars(a, b, c);
cost[a - 1][b - 1] = c;
cost[b - 1][a - 1] = c;
}
//writefln("%(%s\n%)", cost);
auto dist = new int[][](N, N);
foreach (i ; 0 .. N){
foreach (j ; i + 1 .. N){
dist[i][j] = cost[i][j];
dist[j][i] = dist[i][j];
}
}
//writefln("%(%s\n%)", dist);
foreach(k ; 0 .. N){
foreach(i ; 0 .. N){
foreach(j ; i + 1 .. N){
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
dist[j][i] = dist[i][j];
}
}
}
int ans;
foreach(i ; 0 .. N){
foreach(j ; i + 1 .. N){
if(cost[i][j] < inf && dist[i][j] != cost[i][j]){
ans++;
}
}
}
writeln(ans);
}
void readVars(T...)(auto ref T args){
auto line = readln.split;
foreach(ref arg ; args){
arg = line.front.to!(typeof(arg));
line.popFront;
}
if(!line.empty){
throw new Exception("args num < input num");
}
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto N = readln.chomp.to!int;
auto H = readln.split.map!(to!int).array;
auto A = readln.split.map!(to!long).array;
const int MAX = 2*10^^5 + 10;
auto st = new SegmentTree!(long, max, 0L)(MAX);
foreach (i; 1..MAX) st.assign(i, -(1L << 59));
foreach (i; 0..N) {
auto v1 = st.query(0, H[i]-1);
auto v2 = st.query(H[i], H[i]);
st.assign(H[i], max(v1+A[i], v2));
}
st.query(0, MAX).writeln;
}
class SegmentTree(T, alias op, T e) {
T[] table;
int size;
int offset;
this(int n) {
size = 1;
while (size <= n) size <<= 1;
size <<= 1;
table = new T[](size);
fill(table, e);
offset = size / 2;
}
void assign(int pos, T val) {
pos += offset;
table[pos] = val;
while (pos > 1) {
pos /= 2;
table[pos] = op(table[pos*2], table[pos*2+1]);
}
}
void add(int pos, T val) {
pos += offset;
table[pos] += val;
while (pos > 1) {
pos /= 2;
table[pos] = op(table[pos*2], table[pos*2+1]);
}
}
T query(int l, int r) {
return query(l, r, 1, 0, offset-1);
}
T query(int l, int r, int i, int a, int b) {
if (b < l || r < a) {
return e;
} else if (l <= a && b <= r) {
return table[i];
} else {
return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;
void main()
{
auto N = readln.chomp.to!(char[]);
if (N.length == 1) {
writeln(N);
return;
}
long ret, r;
foreach (i, d; N) {
if (!i) {
long s = d-49;
if (!s) s = 1;
s *= (9L^^(N.length-1));
ret = s;
r = d-48;
} else if (i == N.length-1) {
ret = max(ret, r * (d-48));
} else {
long s = d-49;
if (!s) {
r *= d-48;
continue;
}
s = r * s * 9L^^(N.length-i-1);
ret = max(ret, s);
r *= d-48;
}
}
writeln(ret);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; long y; rd(n, y);
for(int i=0; i<=n; i++)for(int j=0; i+j<=n; j++){
auto k=n-(i+j);
if(10000*i+5000*j+1000*k == y){
writeln(i, " ", j, " ", k); return;
}
}
writeln(-1, " ", -1, " ", -1);
}
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;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;
void main(){
while(true){
int[] list;
auto s1 = readln();
int n = s1.chomp().to!int;
if(n == 0) break;
for(int i=0;i<n;i++){
int t = readln().chomp().to!int;
list ~= t;
}
list.sort();
long ans;
for(int i=1;i<n;i++){
int s = to!int(list.length);
ans += list[i-1] * (s-i);
}
writeln(ans);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto s = readln.chomp.to!(dchar[]);
foreach (i, c; s) if (i % 2 == 0) write(c);
writeln("");
}
|
D
|
import std.stdio;
import std.string;
import std.array;
import std.algorithm;
import std.conv;
void main() {
auto n = readln.chomp.to!int;
auto a = readln.chomp.split(' ').map!(to!int).array;
auto counts = new int[n];
foreach (e;a) {
++counts[e - 1];
}
foreach (e;counts) {
writeln(e);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
auto p = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1];
int x, y;
scan(x, y);
writeln(p[x] == p[y] ? "Yes" : "No");
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
long[(10^^6)*2+50] F, RF;
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
long inv(long x)
{
return pow(x, P-2);
}
void init()
{
F[0] = F[1] = 1;
foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;
{
RF[$-1] = 1;
auto x = F[$-1];
auto k = P-2;
while (k) {
if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
x = x^^2 % P;
k /= 2;
}
}
foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}
long comb(N)(N n, N k)
{
if (k > n) return 0;
auto n_b = F[n]; // n!
auto nk_b = RF[n-k]; // 1 / (n-k)!
auto k_b = RF[k]; // 1 / k!
auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!
return (n_b * nk_b_k_b) % P; // n! / (n-k)!k!
}
void main()
{
init();
auto K = readln.chomp.to!long;
auto S = readln.chomp;
auto len = S.length.to!long;
long x;
foreach (k; 0..K+1) {
auto y = comb(len+K, len+k) * pow(25, K-k) % P;
(x += y) %= P;
}
writeln(x);
}
|
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, x = scan!int, t = scan!int;
int ans = (n + x - 1) / x * t;
ans.writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int;
writeln(n/3);
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
// 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!(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, m;
cin.scan(n, m);
alias Point = Tuple!(long, "x", long, "y");
Point[] st, area;
foreach (i; 0 .. n) {
long x, y;
cin.scan(x, y);
st ~= Point(x, y);
}
foreach (i; 0 .. m) {
long x, y;
cin.scan(x, y);
area ~= Point(x, y);
}
foreach (s; st) {
long mini = long.max;
size_t idx;
foreach (i, e; area) {
if (mini > abs(e.x - s.x) + abs(e.y - s.y)) {
mini = abs(e.x - s.x) + abs(e.y - s.y);
idx = i + 1;
}
}
writeln(idx);
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto a = RD;
auto b = RD;
writeln((a+b)/2 + (a+b)%2);
stdout.flush();
debug readln();
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container;
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;
void main()
{
long N, M;
scan(N, M);
auto uf = UnionFind(N);
foreach (_; 0 .. M)
{
long X, Y, Z;
scan(X, Y, Z);
uf.unite(X - 1, Y - 1);
}
uf.size.writeln();
}
struct UnionFind
{
private long[] rank;
long[] data;
long size;
this(long N)
{
this.rank = new long[](N);
this.data = iota!long(N).array;
this.size = N;
}
long find(long x)
{
if (data[x] == x)
return x;
long r = this.find(data[x]);
data[x] = r;
return r;
}
void unite(long x, long y)
{
long rx = find(x);
long ry = find(y);
if (rx != ry)
{
this.size--;
if (rank[rx] == rank[ry])
{
data[rx] = ry;
rank[ry]++;
}
else if (rank[rx] < rank[ry])
data[rx] = ry;
else
data[ry] = rx;
}
}
bool isSame(long x, long y)
{
return this.find(x) == this.find(y);
}
}
|
D
|
void main() {
auto S = rs;
auto K = readAs!ulong;
ulong z_c;
bool gotNonZero = false;
char nonZeroNum;
if(S[0] != '1') {
writeln(S[0]);
return;
}
foreach(i; S~' ') {
if(gotNonZero) {
if(z_c >= K) writeln(1);
else writeln(nonZeroNum);
return;
}
if(S[0] == '1') {
z_c++;
if(S.length == 1) {
writeln(1);
return;
}
S = S[1..$];
} else {
gotNonZero = true;
nonZeroNum = S[0];
}
}
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
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.count('+').to!int - s.count('-').to!int);
}
|
D
|
import std.functional,
std.algorithm,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
void main() {
int[] XYZ = readln.chomp.split.to!(int[]);
int X = XYZ[0],
Y = XYZ[1],
Z = XYZ[2];
int n = X - Z;
writeln(n / (Y + Z));
}
|
D
|
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
import std.math;
void main()
{
auto buf = readln.chomp.split.to!(size_t[]);
immutable n = buf[0], m = buf[1];
auto g = new size_t[][](n, 0);
foreach (i; 0..m)
{
buf = readln.chomp.split.to!(size_t[]);
g[buf[0] - 1] ~= buf[1] - 1;
g[buf[1] - 1] ~= buf[0] - 1;
}
auto visited = new bool[n];
auto answer = new size_t[n];
size_t[] queue = [0];
while (!queue.empty)
{
auto v = queue[0];
queue = queue[1..$];
foreach (next; g[v])
{
if (visited[next])
continue;
answer[next] = v;
visited[next] = true;
queue ~= next;
}
}
if (!visited.all)
return "No".writeln;
"Yes".writeln;
foreach (a; answer[1..$])
(a + 1).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
void main()
{
long A, B;
scan(A, B);
foreach (x; 0 .. 10000)
{
if (A == (x * 8 / 100) && B == (x * 10 / 100))
{
writeln(x);
return;
}
}
writeln(-1);
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.array, std.string;
import std.range;
void main(string[] args) {
auto input = readln().chomp.split.map!(to!int);
if(input[0] <= 8 && input[1] <= 8){
"Yay!".writeln;
}else{
":(".writeln;
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
string[] str = ["dream", "dreamer", "erase", "eraser"];
long pos = S.length, lastPos = pos;
bool isWrong;
while (pos != 0)
{
foreach (e; str)
{
auto len = e.length;
if (pos-len >= 0 && S[pos-len..pos] == e)
{
pos -= len;
break;
}
}
if (pos == lastPos)
{
isWrong = true;
break;
}
lastPos = pos;
}
writeln(isWrong ? "NO" : "YES");
stdout.flush();
//readln();
}
|
D
|
import std;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long a, b;
scan(a, b);
if ((a <= 9) && (b <= 9))
{
writeln(a * b);
}
else
{
writeln(-1);
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
auto binary_search(long key, long[] l)
{
long left = 0; //lの左端
long right = l.length - 1; //lの右端
while (right >= left)
{
long mid = left + (right - left) / 2; //区間の真ん中
if (l[mid] == key)
{
return mid;
}
else if (l[mid] > key)
{
right = mid - 1;
}
else if (l[mid] < key)
{
left = mid + 1;
}
}
return -1;
}
// auto a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910];
// auto a = aryread();
// writeln(a);
// long len_a = a.length;
// writeln(len_a);
// long ans;
// ans = binary_search(51, a);
// writeln(ans);
|
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 n = readln.split[0].to!int;
auto n1 = n/100, n2 = (n - n1*100)/10, n3 = (n - n1*100 - n2*10);
if (n1 == 1) n1 = 9; else if (n1 == 9) n1 = 1;
if (n2 == 1) n2 = 9; else if (n2 == 9) n2 = 1;
if (n3 == 1) n3 = 9; else if (n3 == 9) n3 = 1;
writeln(n1*100 + n2*10 + n3);
}
|
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() {
while (true) {
int n, w, h;
int s, t;
scan(n);
if (!n) return;
scan(w, h);
auto bd = new int[][](w + 1, h + 1);
foreach (i ; 0 .. n) {
int xi, yi;
scan(xi, yi);
bd[xi][yi]++;
}
scan(s, t);
solve(n, w, h, s, t, bd);
}
}
void solve(int n, int w, int h, int s, int t, int[][] bd) {
int ans;
foreach (i ; 1 .. w - s + 2) {
foreach (j ; 1 .. h - t + 2) {
int cnt;
foreach (k ; i .. i + s) {
foreach (l ; j .. j + t) {
cnt += bd[k][l];
}
}
ans = max(ans, cnt);
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
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.typecons;
import std.numeric, std.math;
import core.bitop;
string FMT_F = "%.10f";
T RD(T = long)() { 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 = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto A = RD;
auto B = RD;
auto X = RDR.ARR;
long ans;
foreach (i; 0..N-1)
{
auto d = (X[i+1] - X[i]) * A;
ans += min(d, B);
}
writeln(ans);
stdout.flush();
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
void main()
{
bool[3] cups;
cups[0] = true;
while(true)
{
auto line = readln;
if(!line)break;
auto f = line.chomp.split(",");
swap(cups[f[0][0] - 'A'], cups[f[1][0] - 'A']);
}
foreach(i, cup; cups)
{
if(cup) writeln(cast(char)('A' + i));
}
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/+---test
aabbaa
---+/
/+---test
aaaccacabaababc
---+/
void main(string[] args) {
const S = readln.chomp;
long ans;
string prev;
string cur;
foreach (i, s; S) {
cur ~= s;
if (cur != prev) {
prev = cur;
cur = "";
++ans;
}
}
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!int;
auto S = readln.chomp;
auto ls = new bool[][](N, 10);
auto rs = new bool[][](N, 10);
foreach (i; 0..N) {
if (i != 0) {
foreach (j; 0..10) {
ls[i][j] = ls[i-1][j];
}
}
ls[i][S[i] - '0'] = true;
}
foreach_reverse (i; 0..N) {
if (i != N-1) {
foreach (j; 0..10) {
rs[i][j] = rs[i+1][j];
}
}
rs[i][S[i] - '0'] = true;
}
auto rr = new bool[](1000);
foreach (i; 1..N-1) {
foreach (a; 0..10) foreach (c; 0..10) {
if (ls[i-1][a] && rs[i+1][c]) rr[a*100 + (S[i] - '0')*10 + c] = true;
}
}
int res;
foreach (i, r; rr) if (r) {
++res;
}
writeln(res);
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.math, std.typecons;
int n, z, w; rd(n, z, w);
auto a=readln.split.to!(int[]);
auto mm=new int[][](n, 2);
foreach(i; 0..n) fill(mm[i], -1);
int f(int i, int t, int x, int y){
if(i==n) return (x-y).abs;
if(mm[i][t]>=0) return mm[i][t];
int ret;
if(t){
ret=-1;
foreach(j; i..n) ret=max(ret, f(j+1, t^1, a[j], y));
}else{
ret=1_000_000_000+1;
foreach(j; i..n) ret=min(ret, f(j+1, t^1, x, a[j]));
}
return mm[i][t]=ret;
}
writeln(f(0, 1, z, w));
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
void main() {
string a = readln.chomp;
string b = readln.chomp;
if (a.length > b.length) {
"GREATER".writeln;
} else if (a.length < b.length) {
"LESS".writeln;
} else {
if (a > b) {
"GREATER".writeln;
} else if (a < b) {
"LESS".writeln;
} else {
"EQUAL".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
|
void main(){
int n = _scan();
int a, b;
if(n==2){
a = _scan();
b = _scan();
}
writeln( n==1? "Hello World": ( a+b ).to!string);
}
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.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;
int k = read.to!int;
char[] as = readln.chomp.to!(char[]);
int l0, r0, l1, r1;
bool f0, f1;
foreach(int i, a; as){
if(a == '1'){
if(! f0) l0 = i, f0 = 1;
r0 = i;
}
else{
if(! f1) l1 = i, f1 = 1;
r1 = i;
}
}
if(r0 - l0 + 1 <= k || r1 - l1 + 1 <= k){
// can take in one move
"tokitsukaze".writeln;
return;
}
if(r0 - l0 + 1 >= k + 2 || r1 - l1 + 1 >= k + 2){
// flips {l + 1, ..., r - 1} or so
"once again".writeln;
return;
}
if(l0 <= k - 1 && r0 >= n - k || l1 <= k - 1 && r1 >= n - k){
// First cannot avoid taking one stone
"quailty".writeln;
return;
}
"once again".writeln;
}
/*
Second can always mimic the First. So,
- First wins at his first move.
- Whatever move First plays, Second wins at the next move.
*/
|
D
|
void main(){
int n = _scan();
int ans;
if(n<600)ans=8;
else if(n<800)ans=7;
else if(n<1000)ans=6;
else if(n<1200)ans=5;
else if(n<1400)ans=4;
else if(n<1600)ans=3;
else if(n<1800)ans=2;
else if(n<2000)ans=1;
ans.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 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 H, W;
scan(H, W);
auto A = new string[](H);
foreach (i; 0 .. H)
A[i] = sread();
auto dp = new long[][](H, W);
dp[0][0] = 1;
foreach (h; 0 .. H - 1)
{
foreach (w; 0 .. W - 1)
if (A[h][w] == '.')
{
dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % MOD;
dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % MOD;
}
if (A[h][W - 1] == '.')
dp[h + 1][W - 1] = (dp[h + 1][W - 1] + dp[h][W - 1]) % MOD;
}
foreach (w; 0 .. W - 1)
if (A[H - 1][w] == '.')
dp[H - 1][w + 1] = (dp[H - 1][w + 1] + dp[H - 1][w]) % MOD;
writeln(dp[$ - 1][$ - 1]);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp.to!int;
auto n = X / 100;
auto d = X % 100;
int c;
while (d >= 5) {
d -= 5;
++c;
}
if (d >= 4) {
d -= 4;
++c;
}
if (d >= 3) {
d -= 3;
++c;
}
if (d >= 2) {
d -= 2;
++c;
}
if (d >= 1) {
++c;
}
writeln(c <= n ? 1 : 0);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
import std.typecons : Tuple;
alias Edge = Tuple!(int, "to", int, "cost");
void main() {
int n,m;
scan(n,m);
auto adj = new Edge[][](n, 0);
foreach (i ; 0 .. m) {
int a, b, c;
scan(a, b, c);
a--, b--;
adj[a] ~= Edge(b, c);
}
auto mark = new int[](n);
auto top = new int[](0);
bool heiro = 0;
void visit(int i) {
if (mark[i] == 2) {
return;
}
else if (mark[i] == 1) {
heiro = 1;
return;
}
else {
mark[i] = 1;
foreach (e ; adj[i]) {
visit(e.to);
}
mark[i] = 2;
top ~= i;
return;
}
}
foreach (i ; 0 .. n) {
if (!mark[i]) {
visit(i);
}
}
if (heiro) {
writeln("No");
return;
}
top.reverse();
debug {
writeln(top);
}
immutable inf = 10L^^17;
auto d = new long[](n);
d[] = inf;
d[top.front] = 0;
foreach (i ; top) {
foreach (e ; adj[i]) {
if (d[e.to] == inf) {
d[e.to] = d[i] + e.cost;
}
else {
if (d[e.to] != d[i] + e.cost) {
writeln("No");
return;
}
}
}
}
writeln("Yes");
}
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.algorithm, std.array;
auto solve(string s_) {
immutable N = s_.to!int();
auto ab = new long[2][N];
foreach(ref v;ab) v = readln.split.map!(to!long).array();
long c=0;
foreach_reverse(ref v;ab) {
immutable a=v[0], b=v[1];
c+=(b-(a+c)%b)%b;
}
return c;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
|
D
|
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.math;
void main() {
auto N = readln.chomp.to!ulong;
writeln(pow(N, 3));
}
|
D
|
import std.stdio,std.string,std.algorithm;void main(){readln.split.sort.join(" ").writeln;}
|
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;
int a, b;
void main() {
int a, b, c;
scan(a, b, c);
writeln(min(min(a + b, b + c), a + c));
}
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.string;
import std.conv;
import std.algorithm;
void main() {
int r = readln.chomp.to!(int);
if (r < 1200) {
writeln("ABC");
}
else if (r < 2800) {
writeln("ARC");
}
else {
writeln("AGC");
}
}
|
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 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; }
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 int[](t);
foreach (i; 0..t)
{
auto n = RD!int;
int a, b = int.max;
foreach (j; 0..n)
{
auto l = RD!int;
auto r = RD!int;
a = max(a, l);
b = min(b, r);
}
if (a <= b)
ans[i] = 0;
else
ans[i] = a-b;
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush();
debug readln();
}
|
D
|
void main() {
int n = readln.chomp.to!int;
int[] a = readln.split.to!(int[]);
int hp = a[0];
foreach (i; 1 .. n) {
hp = gcd(hp, a[i]);
}
hp.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.string;
void main(){
auto s=readln.chomp;
foreach(i;0..s.length-1)if(s[i]==s[i+1]){
writeln(i+1," ",i+2);
return;
}
foreach(i;0..s.length-2)if(s[i]==s[i+2]){
writeln(i+1," ",i+3);
return;
}
writeln("-1 -1");
}
|
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 cell = new uint[][](N * 2, N * 2);
long[2][] b, r;
foreach (i; 0..N)
{
r ~= [RD!long, RD!long];
cell[r[$-1][0]][r[$-1][1]] = 1;
}
foreach (i; 0..N)
{
b ~= [RD!long, RD!long];
cell[b[$-1][0]][b[$-1][1]] = 2;
}
auto dp = new long[](N*2);
long ans;
foreach_reverse (i; 1..N*2)
{
foreach_reverse (j; 1..N*2)
{
if (cell[i][j] == 2)
{
//stderr.writeln("b ", i, ":", j);
foreach (k; 0..j+1)
++dp[k];
}
if (cell[i-1][j-1] == 1 && dp[j] > 0)
{
//stderr.writeln(dp);
//stderr.writeln(i-1, ":", j-1);
++ans;
auto x = dp[j];
foreach (k; j..N*2)
{
if (dp[k] != x) break;
--dp[k];
}
foreach_reverse (k; 0..j)
{
--dp[k];
}
//stderr.writeln(dp);
}
}
}
writeln(ans);
stdout.flush();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto m = readln.chomp.to!int;
writeln(48 - m);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto x = RD!int;
auto a = RDA;
auto s = a.sum;
if (s % x)
{
ans[ti] = n;
continue;
}
auto b = new long[](n+1);
foreach (i; 0..n)
{
b[i+1] = (b[i] + a[i]) % x;
}
ans[ti] = -1;
foreach (i; 0..n)
{
if (b[i] != 0 || b[n-i] != 0)
{
ans[ti] = n-i;
break;
}
}
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush;
debug readln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long A, B;
scan(A, B);
lcm(A, B).writeln();
}
T lcm(T)(T a, T b)
{
return (a * b) / gcd(a, b);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
void main()
{
auto N = readln.chomp.to!long;
auto s = readln.chomp.to!(char[]);
auto DP = new long[][](N, N);
foreach (i; 0..N) DP[0][i] = 1;
foreach (i; 1..N) {
long c;
if (s[i-1] == '<') {
foreach_reverse (j; 0..N-i+1) {
DP[i][j] = c;
c = (c + DP[i-1][j]) % P;
}
} else {
foreach (j; 0..N-i+1) {
c = (c + DP[i-1][j]) % P;
DP[i][j] = c;
}
}
}
writeln(DP[$-1][0]);
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0], b = tmp[1], c = tmp[2], d = tmp[3];
writeln(abs(a-c) <= d || max(abs(a-b), abs(b-c)) <= d ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;
|
D
|
import std.stdio;
import std.math;
import std.conv;
import std.string;
void main() {
const int MAX = 1000000;
int[MAX] p;
p[2] = 1;
for (int i = 3; i < MAX; i++) {
if (i % 2 == 0) {
p[i] = p[i-1];
} else if (isPrime(i)) {
p[i] = p[i-1] + 1;
} else {
p[i] = p[i-1];
}
}
foreach (string line; stdin.lines) {
int n = line.chomp.to!int;
p[n].writeln;
}
}
bool isPrime(double e) {
bool res = true;
for (int i = 3; i <= sqrt(e); i += 2) {
if (e % i == 0) {
res = false;
break;
}
}
return res;
}
|
D
|
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
void main() {
int n=to!int(readln().strip());
for(int i=0;i<n;i++){
auto bs=readln().split().map!(to!int)().array();
int s1=-1,s2=-1;
bool flag = true;
for(int j=0;j<10;j++){
if(s1<bs[j]&&bs[j]-s1<bs[j]-s2)s1=bs[j];
else if(s2<bs[j]&&bs[j]-s1>bs[j]-s2)s2=bs[j];
else if(s1<bs[j]) s1=bs[j];
else if(s2<bs[j]) s2=bs[j];
else {flag=false;break;}
}
if(flag) writeln("YES");
else writeln("NO");
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
string n; rd(n);
if(n[0]=='9' || n[1]=='9') writeln("Yes");
else writeln("No");
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
import std.format;
import std.array;
import std.math;
import std.string;
import std.container;
void main() {
int N, T; readlnTo(N, T);
int ans = int.max;
foreach(i; 0..N) {
int c, t; readlnTo(c, t);
if (t <= T)
ans = min(c, ans);
}
if (ans == int.max) "TLE".writeln;
else ans.writeln;
}
// helpers
void readlnTo(T...)(ref T t) {
auto s = readln.split;
assert(s.length == t.length);
foreach(ref ti; t) {
ti = s[0].to!(typeof(ti));
s = s[1..$];
}
}
|
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 a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto h = readln.chomp.to!int;
writeln((a+b)*h/2);
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
auto A = aryread();
long[long] cnt;
foreach (a; A)
{
cnt[a] = cnt.get(a, 0) + 1;
}
long ans;
foreach (key, value; cnt)
{
if (key <= value)
{
ans += value - key;
continue;
}
ans += value;
}
writeln(ans);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n;
scan(n);
writeln(800*n - (n/15)*200);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto K = RD;
auto big = (N - 1) * (N - 2) / 2;
if (K > big)
{
writeln(-1);
}
else
{
auto edges = new bool[][](N, N);
auto diff = K;
long m = N * (N-1) / 2 - diff;
foreach (i; 0..N)
{
foreach (j; i+1..N-1)
{
if (diff == 0) break;
edges[i][j] = true;
--diff;
}
}
writeln(m);
foreach (i; 0..N)
{
foreach (j; i+1..N)
{
if (edges[i][j]) continue;
writeln(i+1, " ", j+1);
}
}
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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 N = RD;
auto M = RD;
auto Q = RD;
auto abcd = new long[][](Q);
foreach (i; 0..Q)
{
abcd[i] = [RD-1, RD-1, RD, RD];
}
long dfs(long[] arr)
{
if (arr.length == N)
{
long score;
foreach (i; 0..Q)
{
auto a = abcd[i][0];
auto b = abcd[i][1];
auto c = abcd[i][2];
auto d = abcd[i][3];
if (arr[b]-arr[a] == c)
score += d;
}
return score;
}
long res;
foreach (i; arr[$-1]..M+1)
{
res.chmax(dfs(arr ~ i));
}
return res;
}
long ans;
foreach (i; 1..M+1)
{
ans.chmax(dfs([i]));
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math,std.random;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...) (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
int read(){int n;read(n);return n;}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
auto dot(R1,R2)(R1 a,R2 b){ElementType!(R1) res=0;for(;!a.empty&&!b.empty;a.popFront(),b.popFront())res+=a.front*b.front;return res;}
struct infIota{int i=0;enum empty=false;int front(){return i;}void popFront(){i++;}}
int calc(int n){
if (n < 10) return 0;
int [] ns;
while(n){ns ~= n % 10;n /= 10;}
int [] res;
auto tens = ()=> infIota().map!"10^^a";
foreach(i;1 .. ns.length){
res ~= ns[0..i].dot(tens()) * ns[i..$].dot(tens());
}
return 1 + calc(res.reduce!(max));
}
void main(){
read().times({ read().calc.writeln; });
}
|
D
|
import core.stdc.stdio;
import std.typecons;
import std.conv;
import std.container;
import std.algorithm;
void main(){
int n,m,x;
scanf("%d%d%d",&n,&m,&x);
int[] hs = new int[n];
for(int i=0;i<n;i++)
scanf("%d",&hs[i]);
alias Tuple!(long,"cost",int,"idx") ci;
ci[][] graph = new ci[][n];
for(int i=0;i<m;i++){
int a,b;
long t;
scanf("%d%d%lld",&a,&b,&t);
--a;
--b;
if(hs[a]>=t)
graph[a] ~= ci(t,b);
if(hs[b]>=t)
graph[b] ~= ci(t,a);
}
alias Tuple!(long,"cost",long,"down",int,"idx") cdi;
alias BinaryHeap!(cdi[],"a>b") pq;
pq q = pq(new cdi[400000],0);
q.insert(cdi(max(0,hs[n-1]-x),0,0));
long ans=-1;
bool[] visited = new bool[n];
while(!q.empty){
cdi t = q.front;
q.removeFront;
with(t){
if(idx==n-1){
ans=cost;
break;
}
if(visited[idx])
continue;
visited[idx] = true;
foreach(cs;graph[idx]){
if(!visited[cs.idx]){
cdi nx;
nx.idx = cs.idx;
nx.down = down+cs.cost;
if(x-nx.down>hs[cs.idx])
nx.down = x-hs[cs.idx];
if(x-nx.down<hs[n-1])
nx.cost = hs[n-1]-(x-nx.down);
nx.cost += nx.down;
q.insert(nx);
}
}
}
}
printf("%lld\n",ans);
}
|
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 K, N;
scan(K, N);
auto A = aryread();
auto D = new long[](N + 1);
D[0] = (K - A[$ - 1]) + A[0];
foreach (i; 0 .. N)
{
D[i + 1] = A[i + 1] - A[i];
}
(K - D.reduce!(max)()).writeln();
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto a = readln.chomp.to!int;
auto b = readln.chomp.to!int;
auto c = readln.chomp.to!int;
auto d = readln.chomp.to!int;
auto e = readln.chomp.to!int;
auto k = readln.chomp.to!int;
if((b-a) <= k && (c-a) <= k && (d-a) <= k && (e-a) <= k && (c-b) <= k && (d-b) <= k && (e-b) <= k && (d-c) <= k && (e-c) <= k && (e-d) <= k){
writeln("Yay!");
} else {
writeln(":(");
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int % 500;
if (readln.chomp.to!int >= n) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
long[10^^5+50] F, RF;
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
void init()
{
F[0] = F[1] = 1;
foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;
{
RF[$-1] = 1;
auto x = F[$-1];
auto k = P-2;
while (k) {
if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
x = x^^2 % P;
k /= 2;
}
}
foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}
void main()
{
init();
auto N = readln.chomp.to!int;
auto S = readln.chomp.to!(char[]);
int[] PS;
PS.length = N*2;
int x;
foreach (i, c; S) {
if (c == 'B') {
if (x%2 == 0) {
PS[i] = 1;
++x;
} else {
PS[i] = -1;
--x;
}
} else {
if (x%2 == 0) {
PS[i] = -1;
--x;
} else {
PS[i] = 1;
++x;
}
}
}
if (x != 0 || PS[0] == -1 || PS[$-1] == 1) {
writeln(0);
return;
}
int mc;
long r = 1;
foreach_reverse (p; PS) {
if (p == -1) {
++mc;
} else {
r = (r * mc--) % P;
}
}
writeln((r * F[N]) % P);
}
|
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("2018" ~ s[4..$]);
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
auto S = sread();
auto T = sread();
char[char] d;
foreach (i; 0 .. S.length)
{
if (S[i] in d)
{
dprint(i, S[i], T[i]);
if (d[S[i]] != T[i])
{
writeln("No");
return;
}
}
else
{
d[S[i]] = T[i];
}
}
auto k = d.values.map!(to!long).array;
k.sort();
writeln(k.walkLength == k.uniq.walkLength ? "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;
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;
void main()
{
long N,K;
scan(N,K);
char[] S = sread().dup;
S[K-1] -= 'A' - 'a';
writeln(S);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
bool acgt(char c) {
return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}
void main()
{
auto S = readln.chomp.to!(char[]);
int max_l = 0;
foreach (int i; 0..cast(int)S.length) {
if (!acgt(S[i])) continue;
auto j = i;
while (j < S.length && acgt(S[j])) ++j;
max_l = max(max_l, j-i);
}
writeln(max_l);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto nk = aryread();
bool b = (nk[0] + 1) / 2 >= nk[1];
writeln(b ? "YES" : "NO");
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto A = RDA;
auto B = RDA;
long ans;
foreach (i; 0..N)
{
auto x = min(A[i], B[i]);
ans += x;
A[i] -= x;
B[i] -= x;
auto y = min(A[i+1], B[i]);
ans += y;
A[i+1] -= y;
B[i] -= y;
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
void main() {
problem();
}
void problem() {
auto X = scan!int;
auto Y = scan!int;
string solve() {
foreach(a; 0..51) {
foreach(b; 0..26) {
if (a + b == X && 2*a + 4*b == Y) return "Yes";
}
}
return "No";
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
void main()
{
auto S = readln.chomp.to!(char[]);
if (S.length == 3) S.reverse();
writeln(S);
}
|
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;
immutable long mod = 10^^9 + 7;
int n;
int[] a;
void main() {
scan(n);
a = readln.split.to!(int[]);
// 2回でてくるものを探す
auto cnt = new int[](n + 1);
foreach (i ; 0 .. n + 1) {
cnt[a[i]]++;
}
auto x = -1;
foreach (i ; 1 .. n + 1) {
if (cnt[i] == 2) {
x = i;
break;
}
}
// 左にあるもの、右にあるものの個数をカウント
int L, R;
foreach (i ; 0 .. n + 1) {
if (a[i] == x) {
L = i;
break;
}
}
foreach_reverse (i ; 0 .. n + 1) {
if (a[i] == x) {
R = n - i;
break;
}
}
auto fact = new long[](n + 2);
auto fact_r = new long[](n + 2);
fact[0] = 1L;
fact_r[0] = 1L;
foreach (i ; 1 .. n + 2) {
fact[i] = (i * fact[i - 1]) % mod;
}
fact_r[n + 1] = modpow(fact[n + 1], mod - 2, mod);
foreach_reverse (i ; 0 .. n + 1) {
fact_r[i] = ((i + 1) * fact_r[i + 1]) % mod;
}
debug {
writeln("fact:", fact);
writeln("fact_r:", fact_r);
}
long binom(int n, int k) {
return fact[n] * fact_r[n - k] % mod * fact_r[k] % mod;
}
foreach (k ; 1 .. n + 2) {
long ans = binom(n + 1, k);
if (L + R >= k - 1) {
ans -= binom(L + R, k - 1);
if (ans < 0) ans += mod;
}
writeln(ans);
}
}
T modpow(T)(T x, T y, T mod){
return y ? modpow(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1;
}
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;
void main() {
auto input = getStdin!(string[]);
foreach (line; input) {
auto num = line.split(" ").to!(int[]);
int width = num[1];
int height = num[0];
if (width == 0 && height == 0) break;
for (int i_h = 0; i_h < height; i_h++) {
for (int j_w = 0; j_w < width; j_w++) {
if (i_h % 2 == 0 && j_w % 2 == 0 || i_h % 2 == 1 && j_w % 2 == 1) {
"#".write;
}
else {
".".write;
}
if (j_w == width - 1)
"".writeln;
}
}
"".writeln;
}
}
T getStdin(T)() {
string[] cmd;
string line;
while ((line = chomp(stdin.readln())) != "") cmd ~= line;
return to!(T)(cmd);
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.array;
import std.numeric, std.math, std.typecons, std.container, core.bitop;
void main() {
int n,a,b;
scan(n,a,b);
writeln((b-a)&1 ? "Borys" : "Alice");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main() {
while(true) {
string [] s = split(readln());
int H = to!int(s[0]);
int W = to!int(s[1]);
if(H==0 && W==0) break;
for(int i=0;i<H;i++) {
for(int j=0;j<W;j++) {
if((i+j) % 2 ==0) {
write("#");
} else {
write(".");
}
}
writeln();
}
writeln();
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.