code stringlengths 4 1.01M | language stringclasses 2
values |
|---|---|
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 n = readint;
bool[int] m;... | 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;
import std.conv;
import std.string;
const int DATA = 200;
int main() {
int[] digit = new int[DATA];
int i;
for(i=0; i<DATA; i++) {
string[] data = chomp(readln).split(" ");
if(stdin.eof()) break;
int val = to!(int)(data[0]) + to!(int)(data[1]);
int dig = 1;
while((val/=10) ... | D |
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
int N = readln.chomp.to!int;
char[] S = readln.chomp.dup;
foreach(ref c; S) {
c = ((c - 'A' + N) % 26) + 'A';
}
S.writeln;
}
| D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
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.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N;
scan(N);
auto a = new in... | D |
// Vicfred
// https://atcoder.jp/contests/abc162/tasks/abc162_f
// dynamic programming, cumulative sum
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main() {
long n = readln.chomp.to!long;
long[] b = readln.split.map!(to!long).array;
long[] a;
a ~= 0... | 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;
import std.algorithm;
import core.stdc.stdio;
import core.memory;
void main(){
while(true){
GC.collect;
int[][4][23] nextTown;
int[4] beTown;
beTown[] = -1;
int[10][10] mapData;
int[] dx = [0,-1,0,1];
int[] dy = [-1,0,1,0];
int w,h;
scanf("%d%d",&w,&h);
if(w==0&&h==0)
break;
for(int i=... | D |
import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import std.bigint;
bool is_prime(long x) {
if (x <= 1 || x % 2 == 0) return false;
long i = 3;
while ... | D |
void main() {
rs.count!(i => i == '2').writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typ... | 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() {
string s = readln.chomp;
int w;
scan(w);
foreach (i ; 0 .. (s.length.to!int + w - 1) / w ) {
write(s[i*w]);
}
write... | D |
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int N, M;
scan(N, M);
auto a = readln.split.to!(int[]);
... | D |
import std.stdio, std.ascii;
void main() {
auto d = readln.dup;
foreach (c; d) {
if (c.isLower) c.toUpper.write;
else c.toLower.write;
}
} | 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 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.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N;
scan(N);
auto A = readln.split.to!(i... | D |
void main()
{
long x = rdElem;
long now = 100;
long year;
while (now < x)
{
now += now / 100;
++year;
}
year.writeln;
}
enum long mod = 10^^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... | 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[] a) {
... | 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 main() {
writeln("ABC", readln.cho... | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
int hi = N;
int lo = 1... | D |
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;
// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : ... | 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 |
#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
void main()
{
for(string S; (S=readln().chomp()).length; )
{
auto nm = S.split().map!(to!int)();
auto n=nm[0], m=nm[1];
auto d = new int[][](n,n);
foreach(i;0..m)
{
a... | D |
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
void main(){
auto a=map!(to!int)(readln.chomp.split);
if(a[0]>a[1])
writeln("a > b");
else if(a[0]<a[1])
writeln("a < b");
else
writeln("a == b");
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto a = readln[0];
switch (a) {
case 'A': .. case 'Z':
writeln("A");
return;
default:
writeln("a");
return;
}
} | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1];
writeln(k * (k-1) ^^ (n-1));
}
| D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;
void main() {
writeln(readln.chomp.count!"a == 'o'" * 100 + 700);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.prim... | D |
import std.stdio;
import std.string;
void main()
{
bool flg = false;
bool[char] num;
foreach(char a;readln.chomp())
if(a in num) num[a] = !num[a];
else num[a] = true;
foreach(bool a;num)
flg |= a;
writeln(flg? "No" : "Yes");
}
| 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 ps = new int[](10^^6+1);
foreach (i; 2..10^^6+1) if (ps[i] == 0) {
auto x = i;
while (x <= 10^^6) {
ps[x] = i;
x += i;
... | 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[])();}
... | D |
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.7.1"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner, dcomp.array;
void main() {
auto sc = new Scanner(stdin);
int x, y, z;
sc.read(x, y, z);
string[] s;
foreach (i; 0..x) {
s... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;
void main()
{
auto n = readln.chomp.to!size_t;
auto ai = readln.split.to!(int[]);
auto q = readln.chomp.to!size_t;
auto mi = readln.split.to!(int[]);
auto ri = new bool[](q);
foreach (i; 0..1 << n) {
auto s = ai.in... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto s = readln.chomp, n = s.length;
writeln((n % 2 == 0) ^ (s[0] == s[$-1]) ? "Second" : "First");
}
| D |
import std.stdio, std.string, std.conv;
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], m = tmp[1];
int[][] s = new int[][](m);
foreach (i; 0 .. m) {
int[] ss = readln.split.to!(int[]);
ss = ss[1..$];
foreach (x; ss) {
s[i] ~= x - 1;
}
... | D |
import std;
import core.bitop;
// dfmt off
ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
void aryWrite(T = long)(T[] ary){ ary.map!(x => x.text()).join(' ')... | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;
void main()
{
readln;
readln.chomp.split.array.reverse.join(" ").writeln;
} | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TL... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]), x = rd[0], a = rd[1], b = rd[2];
if (b-a <= 0)
writeln("delicious");
else if (b-a <= x)
writeln("safe");
else
writeln("dangerous");
}
| D |
// Cheese-Cracker: cheese-cracker.github.io
void theCode(){
int n = scan!int;
ll[] arr = scanArray;
ll minn = arr[0];
for(int i = 0; i < n; ++i){
minn = minn & arr[i];
}
writeln(minn);
}
void main(){
long tests = scan; // Toggle!
while(tests--) theCode();
}
/********* ... | 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.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;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
auto n = lread();
if (n % 2 == 0)
{
writeln((n / 2) - 1);
}
else
{
writeln((n - 1) / 2);
}
}
void scan(L...)(ref... | 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;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.c... | 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!(int[]);
auto N = nk[0];
auto K = nk[1];
auto bs = new int[][](K*2, K*2);
foreach (_; 0..N) {
auto xyc = readln.split;
auto x = xyc[0].to!in... | D |
void main(){
int n = _scan();
string[] st = readln().chomp().split();
char[] ans;
foreach(i; 0..n){
ans ~= st[0][i];
ans ~= st[1][i];
}
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行に同... | D |
void main()
{
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], k = tmp[1];
writeln(n - k + 1);
}
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.as... | D |
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*
a[i]: i番目を踏むときの最善
漸化式は
a... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto rdx = readln.split.to!(long[]);
auto r = rdx[0];
auto D = rdx[1];
auto x = rdx[2];
foreach (_; 0..10) {
x = r*x-D;
writeln(x);
}
} | D |
import std;
auto input()
{
return readln().chomp();
}
alias sread = () => readln.chomp();
void main()
{
long N;
scan(N);
// writeln(N);
long 今の時間 = 0;
long 今のx座標 = 0;
long 今のy座標 = 0;
long dist = 0;
bool check = true;
long time = 0;
foreach (i; 0 .. N)
{
long T,... | 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 |
void main() {
problem();
}
void problem() {
const N = scan!int;
const X = scan!int;
const Y = scan!int;
void solve() {
int[int] counts;
foreach(i; 1..N) {
foreach(j; i+1..N+1) {
auto liner = j - i;
auto linerIToX = X - i;
if (linerIToX < 0) linerIToX *= -1;
au... | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto N = readln.chomp.to!int;
auto edges = new int[][](N);
foreach (i; 0..N-1) {
auto s = readln.split.map... | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int a, b;
scan(a, b);
if (a >= 13) {
... | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = (... | 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 |
void main() {
auto S = rs;
("A" ~ S[8] ~ "C").writeln;
}
// ===================================
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.t... | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n, a, b;
scan(n, a, b);
writeln(min(a*n, b));
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitiv... | D |
void main() {
problem();
}
void problem() {
auto D = scan!int;
auto T = scan!int;
auto S = scan!int;
bool solve() {
return T * S >= D;
}
writeln(solve() ? "Yes" : "No");
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.conta... | 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.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.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b; readV(a, b);
if (a ==... | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
auto A = readln.split.map!(to!int).array;
... | D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.... | 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;
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;
int n,s;
int saiki(int n1,int u,int m){
if(n1 > s) return 0;
else if(m==1){
int d = s-n1;
if(d <= 9 && (u & (1<<d))==0... | 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;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[]... | D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
for (;;) {
auto rd = readln.split.map!(to!int), n = rd[0], x = rd[1];
if (n == 0 && x == 0) break;
auto r = 0;
foreach (i; 1..n+1)
foreach (j; i+1..n+1) {
auto k = x - i - j;
if (k > j && k <= n) ++... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto x = readln.split[1].to!long;
auto as = readln.split.to!(long[]);
auto last = as[0];
long let = 0;
foreach (a; as[1..$]) {
long d;
if (a+last > x) {
d = (a+last) - x;
let += ... | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = (... | D |
import std.stdio, std.conv, std.string, std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.math, std.random, std.range;
void main()
{
const MOD = 1000000007;
int[] input = readln().split.to!(int[]);
int H = input[0];
int W = input[1];
int K = input[2];
int[][] dp;
... | D |
import std.conv;
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
void main() {
auto vars = readln.split.map!(to!int).array;
auto idxTask = iota(1, vars[0] + 1).map!(a => a * 5).array;
auto sumFoldTask = cumulativeFold!((a, b) => a + b)(idxTask).array;
int count;
foreach (idx, el; s... | 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[1001] 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 ... | 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;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializ... | 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[])();}
... | D |
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional;
void main()
{
auto x = readln.chomp.to!long;
if (x < 7) {
writeln(1);
} else if (x < 12) {
writeln(2);
} else {
auto ret = (x / 11) * 2;
writeln(ret + (x%11 == 0 ? 0 : x%11 > 6 ? ... | D |
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 |
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;
int ri () {
return readln.stripRight.to!int;
}
string slow (string z, int k) {
auto s = z.dup;
f... | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto R = readln.chomp.to!int;
auto G = readln.chomp.to!int;
writeln(2 * G - R);
} | D |
import std.stdio, std.conv, std.string, std.array;
void main(){
int check,cnt=0;
auto n = readln.chomp.to!int;
for(uint i;i<n;++i){
check = 0;
auto s = readln.chomp.to!int;
for(uint x=1;x*x<s;++x){
if((s+x+1)%(x*2+1)==0){
check=1;
break;
}
}
if(check==0) cnt++;
}
cnt.writeln;
} | D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; rd(n);
auto mns=new int[](8);
fill(mns, 1000000000);
foreach(_; 0..n){
auto args=readln.split.to!(char[][]);
int kind=0;
foreach(c; args[1]){
kind^=(1<<(c-'A'));
}
mns[kind]=min(mns[kind], args[0].to!(int));
... | D |
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N, M;
scan(N, M);
auto a =... | 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 main() {
readln.chomp.startsWith("... | D |
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
void main() {
int N = readln.chomp.to!int;
string S = readln.chomp;
int ans = 0;
char prev = '0';
foreach(c; S) {
if(c != prev) ans++;
prev = c;
}
ans.writeln;
}
| D |
void main() {
auto s = ri;
int[] a;
a ~= s;
while(true) {
auto v = a.back;
auto p = f(v);
if(a.canFind(p)) {
writeln(a.length+1);
return;
}
else a ~= p;
}
}
int f(int n) {
if(n % 2 == 0) return n / 2;
else return 3*n + 1;
}
// ===================================
import std.stdio;
import std.st... | D |
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int x... | D |
module simple;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, core.stdc.string;
immutable long MOD = 998244353;
void main() {
auto N = readln.chomp.to!int;
auto A = ... | D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto s = readln.chomp.to!(char[]);
auto t = readln.chomp.to!(char[]);
foreach (i; 0 .. s.length) {
if (s == t) {
writeln("Yes");
return;
}
s = s[$ - 1] ~ s[0 .. ($ - 1)];
}
writeln("No");
}
void rd(T...)(ref T ... | 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[])();}
... | 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.c... | D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
auto data = readln().split();
auto A = data[0].to!int(), B = data[1].to!int(), K = data[2].to!int();
int[] list;
foreach_reverse(i; 1 .. min(A, B)+1) {
if (A % i == 0 && B % i == 0) list ~= i;
}
writel... | 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;
long f(long n) {
if... | 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() {
foreach(int i;1..10) foreach(int j; 1..10) {
writeln(i, "x"... | D |
void main() {
int[] tmp = readln.split.to!(int[]);
int a = tmp[0] - 1, b = tmp[1] - 1;
writeln(a * b);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons; | D |
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 |
void main() {
writeln(readln.chomp.to!double.sqrt.to!int ^^ 2);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
void main() {
immutable i = readln.split.to!(ulong[]);
immutable R = i[0], G = i[1], B = i[2], N = i[3];
ulong cnt = 0;
for(ulong r = 0; r <= N / R; r++) {
... | 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!(x => x.to!int-1).array;
auto st = new S... | D |
import std.stdio; void main () {writeln ("NO");}
| D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.