code stringlengths 4 1.01M | language stringclasses 2
values |
|---|---|
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return read... | 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 n = readln.chomp.to!int;
auto a = readln.chomp.... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;
void main()
{
auto abc = readln.split.to!(int[]).uniq.array;
writeln(abc.length == 1 ? "Yes" : "No");
} | 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 s = new bool[](10^^6 + 1);
s[] = 1;
s[0] = s[1] = 0;
for (int p = 2; p*p <= 10^^6; p++) {
if (s[p]) {
for (int q =... | D |
void main(){
auto S = readln().chomp();
auto T = readln().chomp();
if ( S[] == T[0..$-1] ){
writeln("Yes");
} else {
writeln("No");
}
}
import std;
string readStr(){
return readln().chomp();
}
T[] readLine( T = long )(){
return readln().split().to!(T[])();
} | D |
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
ulong MOD =... | 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;
import std.concurrency;
void times(alias fun)(int n) {
foreach(i... | 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 = "%.15f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r... | D |
import std;
void main() {
int n; scan(n);
int m = n % 10;
if (m == 3) writeln("bon");
else if (m == 0 || m == 1 || m == 6 || m == 8) writeln("pon");
else writeln("hon");
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { ret... | D |
void main()
{
long k = rdElem;
string s = rdStr;
if (s.length <= k) s.writeln;
else writeln(s[0..k], "...");
}
enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
ali... | 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()
{
long x, y; readV(x, y);
writeln(... | D |
unittest
{
assert( [ "575" ].parse.expand.solve == "Yes" );
assert( [ "123" ].parse.expand.solve == "No" );
assert( [ "812" ].parse.expand.solve == "No" );
}
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
stdin.byLineCopy.parse.expand.solve.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(... | 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);
string t; re... | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
char[] input = readln().dup;
input[5] = ' ';
input[13] = ' ';
input.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 H = readln.chomp.to!int;
auto W = readln.chomp.to!int;
writeln((N - W + 1) * (N - H + 1));
} | 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 ... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_... | D |
void main() {
auto O = rs, E = rs;
foreach(i; 0..O.length) {
O[i].write;
if(!(i > E.length-1)) E[i].write;
}
writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
im... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto lr = readln.split.to!(long[]);
auto L = lr[0];
auto R = lr[1]+1;
long x = long.max;
foreach (l; L..min(L+2020, R)) {
foreach (r; l+1..min(L+2020,R)) {
x = m... | D |
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], q = tmp[1];
string s = readln.chomp;
int[] dp = new int[n];
foreach (i; 1 .. n) {
int cnt;
if (s[i-1] == 'A' && s[i] == 'C') {
++cnt;
}
dp[i] += dp[i-1] + cnt;
}
foreach (i; 0 .. q)... | D |
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
long n, m, x;
scan(n, m, x);
auto 参考書の値段とアルゴリズム = new long[]... | 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(... | 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.functi... | D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
int k;
while ((k = readint) !=... | 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;
import std.typecons;
void main() {
auto N = readln.chomp.to!int;
int[] prices;
foreach(i; 0..50000) {
auto price = cast(int)(1.08f * cast(real)i);
if ... | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.random;
void main() {
auto x = readln.chomp.split.map!(to!int);
auto a = x[0];
auto b = x[1];
auto op = a == b ? "==" : a > b ... | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main()
{
auto N = readln.chomp.to!int;
bool[int] data;
foreach(_; 0..N){
auto A = readln.chomp.to!int;
if(A in data)
data.remove(A);
else
data[A] = true;
}
writeln(data.... | D |
import std.stdio, std.conv, std.string, std.array, std.algorithm,
std.numeric, std.math, std.range;
void main()
{
string s = readln.strip;
long[] xs = new long[](s.length);
char prev = 'x';
bool last_even = false;
long last_marked = -1;
long next = 0;
long next_1 = 0;
foreach (i; 0... | 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=(... | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
static import std.ascii;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return r... | 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!long;
auto fs = new long[](1001);
foreach (long i; 0..1001) fs[i] = i^^5;
foreach (i; 0..1001) {
foreach (j; 0..1001) {
if (fs[i] - fs[j] ==... | D |
import std.stdio, std.string, std.conv, std.algorithm, std.math;
void main()
{
while(true)
{
auto inp = readln.split.map!(to!int);
if(!inp[0] && !inp[1] && !inp[2]) break;
real a = inp[0], b = inp[1], c = inp[2];
real r = min(a * a + b * b, b * b + c * c, c * c + a * a).sqrt;
... | D |
void main()
{
int n = readln.chomp.to!int;
int[] a = readln.split.to!(int[]);
auto cnt4 = a.count!(x => x % 4 == 0);
auto cnt2 = a.count!(x => x % 4 != 0 && x % 2 == 0);
if (cnt4 >= n / 2) "Yes".writeln;
else if (cnt4 >= (n - cnt2 + 1) / 2) "Yes".writeln;
else "No".writeln;
}
import std.s... | D |
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
stri... | 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;
int sum2d(int[][] A, int r1, int c1, int r2, int c2) {
return A[r2+1][c2+1] - A[r2+1][c1] - A[r1][c2+1] + A[r1][c1];... | 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", ... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
readln;
long r;
foreach (a; readln.split.to!(long[])) r += a-1;
writeln(r);
} | D |
import std.stdio;
import std.conv;
import std.string;
void main()
{
int[] input = readln.split.to!(int[]);
int k = input[0];
int s = input[1];
long ans = 0;
foreach_reverse (i; 0..k + 1) {
foreach_reverse (j; 0..k + 1) {
auto tmp = s - i - j;
if (tmp <= k && tmp >= ... | 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 N = readln.chomp.to!int;
auto A = readln.split.map!(to!long).array;
long a = 0, b = A.sum;
... | D |
// Cheese-Cracker: cheese-cracker.github.io
void theCode(){
int n = scan!int;
auto arr = scanArray!int;
auto freq = new int[2*n + 5];
auto take = new int[2*n + 5];
arr.each!(a => ++freq[a]);
ll cnt = 0;
for(int i = 0; i <= 2*n+1; ++i){
if(freq[i]){ freq[i] += take[i];}
if(fr... | 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 = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () ... | 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(... | 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;
// }}}
// nep.scanner {{{
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import ... | D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.range;
auto s=readln.chomp.to!(char[]);
int[char] cnt;
foreach(c; s){
if(!(c in cnt)) cnt[c]=1;
}
auto mi=s.length;
foreach(tg; cnt.keys){
int i=-1, j;
int r=0;
while(j<s.length){
if(s[j]==tg){
... | 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 Q = readln.chomp.to!int;
foreach (_; 0..Q) {
auto ab = readln.split.to!(long[]);
auto A = ab[0];
auto B = ab[1];
if (A > B) swap(A,... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
int n;
foreach (c; readln.chomp) if (c == '2') ++n;
writeln(n);
} | D |
import std.stdio, std.array, std.conv, std.string;
void main() {
while (true) {
string[] input = split(readln());
if (input[1] == "?") break;
writeln(calc(input));
}
}
int calc(string[] s) {
int a = to!int(s[0]), b = to!int(s[2]);
string op = s[1];
if (op == "+") return a + b;
if (op == "-")... | D |
void main()
{
auto io = new IO();
auto N = io.line!size_t()[0];
auto input = io.line!size_t();
size_t pair = 0;
foreach( i,v ; input ){
if( i<v-1 && i==input[v-1]-1 ){
pair++;
}
}
writeln(pair);
}
import std.stdio,std.string,std.conv;
class IO
{
string str( size_t lines = 1 )
{
return readln()... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nk = readln.split.to!(long[]);
auto N = nk[0];
ulong K = nk[1];
long[31] rs;
foreach (_; 0..N) {
auto ab = readln.split.to!(long[]);
ulong A = ab[0];
aut... | 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 ... | D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
foreach (line; stdin.byLine) {
auto x = line.split.map!(to!int).array;
int sum;
foreach (i; 0..x[2]... | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main(){
auto A=readln.chomp;
writeln(A.count('1'));
} | D |
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], m = tmp[1];
int[] a = new int[n+1];
foreach (i; 0 .. m) {
tmp = readln.split.to!(int[]);
int l = tmp[0] - 1, r = tmp[1];
++a[l];
--a[r];
}
foreach (i; 0 .. n) {
a[i+1] += a[i];
}
a.... | D |
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;
void main(){
int sScore = 0; int tScore = 0;
string[] sInput = readln().split();
string[] tInput = readln().split();
foreach(string s; sInput){
sScore += s.to!int();
}
foreach(string s; tInput)... | D |
import std.stdio, std.array, std.conv, std.string, std.algorithm, std.math;
void main() {
auto n = readln.chomp.to!int;
auto a = readln.chomp.split;
for (int i = n - 1; i >= 0; i--) {
write(a[i]);
if (i != 0) { write(" "); }
}
writeln;
} | 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;
auto DP = new int[][](N.length+1, 2);
DP[0][0] = 0;
DP[0][1] = 1;
foreach (i; 0..N.length) {
auto n = (N[i] - '0').to!int;
... | D |
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
class BIT {
int[] data;
this(int n) {
data = new int[n+1];
}
BIT dup() {
BIT ret = new BIT(to!int(data.length));
ret.data = data.dup;
return ... | D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
void main() {
char a;
scan(a);
writeln('a' <= a && a <= 'z' ? 'a' : 'A');
}
void scan(T...)(ref T args) {
auto line = readln.split; // ... | 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 ... | D |
import std.stdio, std.string, std.conv, std.range, std.algorithm;
void main() {
auto w = readln.chomp;
int[char] char_count;
auto beautiful = true;
foreach (c; w) {
char_count[c]++;
}
if (char_count.values.all!"a % 2 == 0") {
"Yes".writeln;
} else {
"No".writeln;
}
}
| D |
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
impor... | D |
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
void main()
{
long[] n_and_k;
long n;
long k;
n_and_k = readln.split.to!(long[]);
n = n_and_k[0];
k = n_and_k[1];
writeln(min(n % k, k - n % k));
}
| 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 = sread();
long sum_n;
foreach (i; 0 .. n.length)
{
// writeln(n[i] - '0');
sum_n += (n[i] - '0');
}
// write... | D |
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
void main(){
int sum = 0;
int num = 0;
int count = 0;
while(true){
auto s = readln();
if(stdin.eof()) break;
string[] n1 = split(chomp(s),',');
int[2] n;
n = [to!int(n1[0]),to!int(n1[1])];
sum += n[0] * n[1];
num += n[1... | D |
import std.stdio;
import std.string;
import std.math;
import std.conv;
import std.algorithm;
import std.bigint;
void main(){
while(true){
long n = to!long(chomp(readln()));
if(n == 0) break;
long[] a;
a ~= 0;
a ~= to!long(chomp(readln()));
for(long i=1;i<n;i++){
a ~= a[i] + to!long(chomp(readln()));
}... | D |
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
long n = read.to!long;
... | 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;
void main() {
int n, w;
scan(n, w);
auto ws = new int[](n);
auto v = new int[](n);
int vs;
foreach (i ; 0 .. n) {
... | D |
void main()
{
long n, k;
rdVals(n, k);
long[] a = rdRow;
long[] b = new long[n+1];
foreach (i, x; a)
{
b[i+1] = b[i] + x;
}
long[] list = new long[n*(n+1)>>1];
long idx;
foreach (i; 0 .. n)
{
foreach (j; i .. n)
{
list[idx++] = b[j+1] - b... | 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.functi... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!int;
auto d = new int[](n);
foreach (i; 0..n) d[i] = readln.chomp.to!int;
writeln(d.sort().uniq.walkLength);
}
| 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 x, a, b; readV(x, a, b);
if... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]), a = rd[0], b = rd[1], c = rd[2];
writeln(b-a == c-b ? "YES" : "NO");
}
| D |
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
auto input = readln.split.to!(int[]);
int N = input[0], D = input[1];
int[][] ps = new int[][N];
foreach(ref p; ps) {
p = readln.split.to!(int[]);
}
int[] tbl = ne... | D |
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s;
scan(s);
auto cnt = new int[](3);
foreach (ch ; s) {
cnt[ch - 'a']++;
}
cnt.sort();
int k = cnt[0];
b... | 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 n = readln().chomp().to!int;
if(n==0) break;
int[] k = readln().split().to!(int[]);
int l... | 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;
auto c = new char[](s.length);
int index;
foreach (i; 0..... | D |
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
writeln(readln.chomp.split.to!(int[]).reduce!"a-b"+1);
}
| 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(... | 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();
long bignum... | 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(int[] xs) {
... | D |
import std.stdio, std.algorithm;
void main() {
auto p = new long[2001];
foreach (i; 0 .. 1001) foreach (j; 0 .. 1001)
p[i + j]++;
while (true) {
if (stdin.eof) break;
int N; scanf("%d\n", &N);
long ans;
foreach (i; 0 .. min(N, 2000) + 1) if (0 <= N - i && N - i <= 20... | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
readln.split.to!(int[]).reduce!"max(a-b, 0)".writeln;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
... | D |
import std.stdio, std.range, std.conv, std.string, std.array, std.functional, std.math;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;
import std.typecons;
struct Pair{
long a;... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
int[][10^^5+1] GP;
bool[10^^5+1] CS;
int[10^^5+1] PS;
int find_path(int N)
{
auto ss = [[0, 0]];
for (;;) {
auto h = ss[0];
auto i = h[0];
auto s = h[1];
ss = ss[1..$];
... | D |
import std.conv;
import std.array;
import std.string;
import std.algorithm;
import std.stdio;
void main() {
ulong r = 1;
enum ulong RMax = 1000000000000000000UL;
enum ulong EMax = 100000UL;
readln;
auto a = readln.chomp.split(' ').map!(to!ulong).array;
foreach (e;a) {
if (e == 0) {
writeln("0");
retur... | 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 {
... | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int n, m;
scan(n, m);
auto p = readln.split.to!(int[]);
p[] -= 1;
auto uf = UnionFind(n);
foreach (i ; 0 .. m) {
in... | D |
module app;
import core.bitop;
import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
struct Input
{
int a;
int b;
}
void parseInput(T)(out Input input, T file)
{
with (file) with (input)
{
a = readln().strip().to!int;
b = readln().strip().to!int;
}... | 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(... | D |
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{
auto line = readln().split();
if (line.length < args.length) return;
foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
};
void read(T..... | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int h, w; scan(h, w);
if (h == 1 && w == 1) {
writeln("No");
return;
}
auto ban = new char[][](h, w);
iota(h).e... | D |
import std.stdio;
import std.conv;
import std.string;
void main()
{
string[] buf;
int w,h;
buf = split(readln());
w = to!(int)(buf[0]);
h = to!(int)(buf[1]);
writeln(w*h,' ',2*w+2*h);
} | D |
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.math;
void main(){
int n = readln.chomp.to!int;
int[] tmp = readln.chomp.split.map!(to!int).array;
int t = tmp[0], a = tmp[1];
int[] hs = readln.chomp.split.map!(to!int).array;
real f(int x){
return abs(a.to!real - (t.to!real - x.to!real * ... | 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_r... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nhw = readln.split.to!(int[]);
auto N = nhw[0];
auto H = nhw[1];
auto W = nhw[2];
int r;
foreach (_; 0..N) {
auto ab = readln.split.to!(int[]);
if (ab[0] >=... | D |
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;
void main()
{
auto s = readln.... | D |
/+ dub.sdl:
name "B"
dependency "dcomp" version=">=0.7.4"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
Scanner sc = new Scanner(stdin);
int n;
sc.read(n);
static struct E { int to; int idx; }
E[][] g = new E[][](n);
fo... | D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int h, w, k;
rd(h, w, k);
const int mod = 10 ^^ 9 + 7;
auto dp = new int[](w);
dp[0] = 1;
foreach (_; 0 .. h) {
auto nex = new int[](w);
foreach (bit; 0 .. (1 << (w - 1))) {
if (bit & (bit >> 1))
continue;
f... | D |
import std.stdio;
import std.math;
void main()
{
int n, m;
int[] a, b;
scanf("%d %d", &n, &m);
a.length = n;
b.length = m;
foreach (i; 0 .. n) scanf("%d", &a[i]);
foreach (i; 0 .. m) scanf("%d", &b[i]);
int result;
while (b.length) {
if (a.length == 0) break;
if (b[0] < a[0]) {
b = b[1..$];
} else {
... | D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.