code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto s = sread();
auto t = sread();
// writeln(s);
long ans = long.max;
foreach (i; 0 .. ((s.length - t.length) + 1))
{
// writeln(s[i .. (i + (t.length))]);
ans = min(ans, func(s[i .. (i + (t.length))], t));
}
writeln(ans);
}
long func(string s, string t)
{
long cnt;
foreach (i; 0 .. s.length)
{
if (s[i] != t[i])
{
cnt += 1;
}
}
return cnt;
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.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 d = readln.chomp.split.to!(int[]);
int res;
foreach (_; 0..2) {
if (d[0] > d[1]) {
res += d[0];
d[0]--;
} else {
res += d[1];
d[1]--;
}
}
res.writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
void main()
{
string s;
while( (s=readln.strip) != "0 0") {
auto n = map!(to!int)(s.strip.split);
for(int i=0;i<n[0];i++) {
for(int j=0;j<n[1];j++) {
write("#");
}
writeln();
}
writeln();
}
}
|
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.max/3;
enum MOD = 10L^^9+7;
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
import core.stdc.stdlib;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
auto A = scanElem;
writeln(A/3);
}
|
D
|
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;
void main()
{
auto ab = readln.split.to!(long[]);
(ab[0] - ab[1] + 1).writeln;
}
|
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() {
string s;
scan(s);
yes(s.canFind('7'));
}
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
immutable inf = 1<<30;
void main() {
int n, k;
scan(n);
scan(k);
int ans = inf;
void dfs(int i, int val) {
if (i == n) {
ans = min(ans, val);
return;
}
dfs(i + 1, val + k);
dfs(i + 1, val * 2);
}
dfs(0, 1);
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
long cnt;
void main()
{
long n, a, b;
scan(n, a, b);
auto t = n / (a + b);
auto r = n - t * (a + b);
writeln(a * t + min(a, r));
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import std.stdio;
import std.string;
import std.array;
import std.range;
import std.random;
import std.algorithm;
import std.conv;
void main(){
auto input = readln().chomp();
solve(input).writeln();
}
int solve(string input){
auto result = 0;
foreach(s; input){
if(s == '+'){
result++;
}else{
result--;
}
}
return result;
}
|
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);
foreach (i; 0 .. 1001)
{
if (((i * 8) / 100 == a) && ((i * 10) / 100 == b))
{
writeln(i);
return;
}
}
writeln(-1);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
import std.stdio, std.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(){
int a = read.to!int;
int b = read.to!int;
string ans;
if(a <= 8 && b <= 8) ans = "Yay!";
else ans = ":(";
ans.writeln;
}
|
D
|
import std.stdio;
import std.math;
import std.algorithm;
import std.conv;
long bisect(T)(T[] arr, T p) {
long u, t = arr.length-1;
long i = (u + t) / 2;
while(i != 0 && i != arr.length - 1 && (arr[i] > p || arr[i+1] <= p)) {
if (arr[i] > p) {
t = i;
}
else {
if (u == i)
u = i + 1;
else
u = i;
}
i = (t + u) / 2;
}
return i;
}
unittest {
assert(bisect!int([1, 2, 3, 4], 1) == 0);
assert(bisect!int([1, 2, 3, 4], 2) == 1);
assert(bisect!int([1, 2, 3, 4], 3) == 2);
assert(bisect!int([1, 2, 3, 4], 4) == 3);
}
void main() {
long a, b, q;
long[] s, t, x;
scanf("%ld %ld %ld", &a, &b, &q);
foreach (i;0..a+b+q) {
long y;
scanf("%ld", &y);
if (i < a) {
s ~= y;
}
else if (i < a + b) {
t ~= y;
}
else {
x ~= y;
}
}
s.sort!"a<b";
t.sort!"a<b";
s = -100000000000 ~ s ~ 100000000000;
t = -100000000000 ~ t ~ 100000000000;
foreach(x_;x) {
auto sc = s.bisect!long(x_);
auto tc = t.bisect!long(x_);
auto tsl = s[sc+1] - x_;
auto tsr = x_ - s[sc];
auto ttl = t[tc+1] - x_;
auto ttr = x_ - t[tc];
writeln([
max(tsr, ttr),
max(tsl, ttl),
tsr*2+ttl,
tsr+ttl*2,
tsl*2+ttr,
tsl+ttr*2
].reduce!((a, b) => min(a,b)));
}
}
|
D
|
import std.stdio,std.string,std.conv,std.array;
void main(){
for(;;){
auto rcs = readln().chomp().split();
auto n = to!int(rcs[0]);
auto x = to!int(rcs[1]);
if( n==0 && x==0 ){ break; }
int hit=0;
for( int a=1;a <= n-2; a++ ){
for( int b=a+1;b <= n-1; b++ ){
for( int c=b+1;c <= n; c++ ){
if( a+b+c == x ){
hit++;
}
}
}
}
writeln(hit);
}
}
|
D
|
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
void main() {
string s = readln.chomp;
string prev;
uint count = 0;
auto n = s.length;
for(uint i=0; i<n; i++) {
if (s[i..i+1] == prev) {
if (i+1 == n) break;
prev = s[i..i+2];
count++;
i++;
continue;
}
prev = s[i..i+1];
count++;
}
writeln(count);
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long a, b, c;
scan(a, b, c);
long l = 4 * a * b;
long r = (c - (a + b)) ^^ 2;
if(l < r && (a + b) < c)
writeln("Yes");
else
writeln("No");
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import std.stdio, std.conv, std.array, std.string;
import std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.sorting;
void main()
{
int N = readln().strip.to!int;
if(N==1)
{
writeln("Hello World");
}else{
auto r = readln().strip.to!int +
readln().strip.to!int;
writeln(r);
}
}
|
D
|
import std.stdio;
import std.string, std.conv, std.array, std.algorithm;
import std.uni, std.math, std.container;
import core.bitop, std.datetime;
void main(){
auto N = readln.chomp.to!int;
int ans = N * (N + 1) / 2;
ans.writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
auto n = read.to!long;
auto a = read.to!long;
auto b = read.to!long;
long[] ps;
foreach(i; 0 .. n) ps ~= read.to!long;
long c1, c2, c3;
foreach(p; ps){
if(p <= a) c1 += 1;
else if(p <= b) c2 += 1;
else c3 += 1;
}
long ans = n;
if(c1 < ans) ans = c1;
if(c2 < ans) ans = c2;
if(c3 < ans) ans = c3;
if(ans == n) ans = 0;
ans.writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
void main() {
auto tmp = readln.split.to!(int[]);
writeln(max(0, min(tmp[3], tmp[1]) - max(tmp[2], tmp[0])));
}
|
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
2
---+/
void main(string[] args) {
const N = readln.chomp.to!long;
(N.pow(3)).writeln;
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm;
long solve(long n, long m)
{
if (2*n > m)
return m / 2;
auto ret = n;
m -= n*2;
ret += m/4;
return ret;
}
void main()
{
auto nm = readln.split.to!(long[]);
writeln(solve(nm[0], nm[1]));
}
|
D
|
import std.conv;
import std.stdio;
import std.string;
void main()
{
auto r = readln.strip.to!int;
writeln( solve( r ) );
}
auto solve( in int r )
{
if( r < 1200 ) return "ABC";
if( r < 2800 ) return "ARC";
return "AGC";
}
|
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 H, W, K;
scan(H, W, K);
auto C = new string[](H);
foreach (i; 0 .. H)
C[i] = sread();
char[][] f(uint h, uint w)
{
auto ret = new char[][](H, W);
foreach (i; 0 .. H)
foreach (j; 0 .. W)
{
if ((h & (1 << i)) || (w & (1 << j)))
{
ret[i][j] = 'r';
}
else
{
ret[i][j] = C[i][j];
}
}
return ret;
}
long eval(char[][] s)
{
long ret;
foreach (i; 0 .. H)
foreach (j; 0 .. W)
ret += s[i][j] == '#';
return ret;
}
long ans;
foreach (i; 0 .. 1 << H)
foreach (j; 0 .. 1 << W)
{
auto s = f(i, j);
if (eval(s) == K)
ans++;
}
writeln(ans);
}
|
D
|
import std.stdio;
void main(){
auto cin = new Cin();
auto S = cin.line!string()[0];
bool succeed = false;
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" );
return;
}
auto solve(){
}
unittest{
}
import std.stdio,std.conv,std.string;
import std.algorithm,std.array,std.math;
class Cin
{
T[] line( T = size_t , string token = " " )( size_t m = 1 ){
T[] arr = [];
foreach( i ; 0..m ){
arr ~= this.read!T();
}
return arr;
}
T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){
T[][] arr = new T[][](m);
foreach( i ; 0..m ){
arr[i] = this.read!T(token);
}
return arr;
}
private T[] read( T = size_t )( string token = " " ){
T[] arr;
foreach( elm ; readln().chomp().split(token) ){
arr ~= elm.to!T();
}
return arr;
}
}
pure T[] span(T)( in T begein , in T end , in T step = 1 ){
assert( begin < end );
assert( 0 < step );
T[] arr;
for( T i = begein ; i < end ; i += step ){
arr ~= i;
}
return arr;
}
pure T[] map(T)( ref T[] args , T delegate(T) dlg ){
foreach( ref arg ; args ){
arg.dlg();
}
return args;
}
pure T sum(T)( in T[] args ){
T result = 0;
foreach( arg ; args ){
result += arg;
}
debug writeln( args , "\n" , arg );
return result;
}
pure T ave(T)( in T[] args ){
return args.sum()/args.length;
}
|
D
|
import std.stdio,std.conv,std.string,std.algorithm,std.array,std.math;
void main(){
auto s=readln().chomp().split().map!(to!int);
int a,b,c,d;
a=s[0];
b=s[1];
c=s[2];
d=s[3];
if(abs(c-a)<=d)
writeln("Yes");
else if(abs(b-a)<=d && abs(c-b)<=d)
writeln("Yes");
else
writeln("No");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
auto n = readln.chomp.to!int;
foreach (i; 0..n) {
auto as = readln.split.map!(to!int);
int l ,r;
bool f;
foreach (a; as) {
if (l < a) l = a;
else if (r < a) r = a;
else {
f = true;
}
}
writeln(f?"NO":"YES");
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto s = readln.chomp.split;
writeln(s[1] ~ s[0]);
}
|
D
|
void main()
{
string s = rdStr;
long n = s.length;
bool ok = true;
foreach (i; 0 .. n/2)
{
if (s[i] != s[n-i-1]) ok = false;
}
long m = (n - 1) / 2;
foreach (i; 0 .. m)
{
if (s[i] != s[m-i-1]) ok = false;
if (s[m+i+1] != s[n-i-1]) ok = false;
}
writeln(ok ? "Yes" : "No");
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.regex;
import std.range;
import core.exception;
void main() {
auto N = readln.chomp.to!int;
auto a = new int[](N);
foreach(i; 0..N) {
a[i] = readln.chomp.to!int;
}
bool[int] b;
foreach(i; 0..N+1) b[i] = false;
int current = 1, count;
while(true) {
if(b[current]) {
(-1).writeln;
return;
}
if(current == 2) {
count.writeln;
return;
}
b[current] = true;
current = a[current-1];
count++;
}
}
|
D
|
import std.stdio, std.conv, std.string, std.math;
void main(){
((a, b, h) => (a + b) * h / 2)(r, r, r).writeln;
}
int r() { return readln.chomp.to!int; }
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 998244353;
void main() {
auto s = readln.split.map!(to!long);
auto N = s[0].to!int;
auto A = s[1];
auto B = s[2];
auto K = s[3];
auto Comb = new Combination();
long ans = 0;
foreach (a; 0..N+1) {
long b = (K- a * A) / B;
if ((K - a * A) % B != 0) continue;
if (b < 0 || b > N) continue;
ans += Comb.comb(N, a.to!int) * Comb.comb(N, b.to!int) % MOD;
ans %= MOD;
}
ans.writeln;
}
class Combination {
immutable int MAX = 2*10^^6+1;
long[] modinv;
long[] f_mod;
long[] f_modinv;
this() {
modinv = new long[](MAX);
modinv[0] = modinv[1] = 1;
foreach(i; 2..MAX) {
modinv[i] = modinv[MOD.to!int % i] * (MOD - MOD / i) % MOD;
}
f_mod = new long[](MAX);
f_modinv = new long[](MAX);
f_mod[0] = f_mod[1] = 1;
f_modinv[0] = f_modinv[1] = 1;
foreach(i; 2..MAX.to!int) {
f_mod[i] = (i * f_mod[i-1]) % MOD;
f_modinv[i] = (modinv[i] * f_modinv[i-1]) % MOD;
}
}
long comb(int n, int k) {
if (n < k) return 0;
return f_mod[n] * f_modinv[n-k] % MOD * f_modinv[k] % MOD;
}
}
long powmod(long a, long x, long m) {
long ret = 1;
while (x) {
if (x % 2) ret = ret * a % m;
a = a * a % m;
x /= 2;
}
return ret;
}
|
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 N = lread();
auto T = lreads(N);
long ans = T[0];
foreach (t; T[1 .. $])
ans = lcm(ans, t);
writeln(ans);
}
T lcm(T)(T a, T b)
{
return a / gcd(a, b) * b;
}
|
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.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
auto n=scanElem;
writeln(n*800-n/15*200);
}
|
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 std.string : chomp;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.chomp.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 main()
{
auto cin = new Scanner;
int n, m;
cin.scan(n, m);
writeln((n - 1) * (m - 1));
}
|
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;
int[] AS, cs;
foreach (_; 0..N) AS ~= readln.chomp.to!int;
foreach (a; AS) {
if (cs.empty || cs[$-1] >= a) {
cs ~= a;
} else if (cs[0] < a) {
cs[0] = a;
} else {
int l, r = cs.length.to!int-1;
while (l+1 < r) {
auto m = (l+r)/2;
if (a > cs[m]) {
r = m;
} else {
l = m;
}
}
cs[r] = a;
}
}
writeln(cs.length);
}
|
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 S = readln.chomp.to!(char[]);
auto DP = new long[][](S.length, 13);
foreach (i, c; S) {
foreach (n; 0..10) {
if (c == '?' || n == c-'0') {
if (i == 0) {
DP[i][n] = 1;
} else {
foreach (j; 0..13) {
auto m = (j*10 + n) % 13;
DP[i][m] = (DP[i][m] + DP[i-1][j]) % P;
}
}
}
}
}
writeln(DP[$-1][5]);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main() {
auto n = to!int(readln.chomp());
auto a = to!int(readln.chomp());
writeln((n % 500) <= a ? "Yes" : "No");
}
|
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 main()
{
auto a = aryread();
// a.sort();
bool b = a[2] == a[0] && a[0] == a[1];
writeln(b ? "Yes" : "No");
}
|
D
|
import std.stdio;
import std.string;
import std.array;
import std.algorithm;
import std.conv;
import std.range;
import std.functional;
import std.bigint;
import std.typecons;
void main(string[] args) {
readln;
string s = readln.chomp;
enum Transit {
StoS,
StoW,
WtoS,
WtoW,
}
alias Reasoner = Tuple!(Transit, "assumption", Transit, "temp");
Reasoner[4] reasoner;
string[4] ans_candidate;
if (s[0] == 'o') {
reasoner[0].assumption = Transit.StoS;
ans_candidate[0] = "S";
reasoner[0].temp = Transit.StoS;
reasoner[1].assumption = Transit.StoW;
ans_candidate[1] = "W";
reasoner[1].temp = Transit.WtoW;
reasoner[2].assumption = Transit.WtoS;
ans_candidate[2] = "S";
reasoner[2].temp = Transit.StoW;
reasoner[3].assumption = Transit.WtoW;
ans_candidate[3] = "W";
reasoner[3].temp = Transit.WtoS;
} else if (s[0] == 'x') {
reasoner[0].assumption = Transit.StoS;
ans_candidate[0] = "S";
reasoner[0].temp = Transit.StoW;
reasoner[1].assumption = Transit.StoW;
ans_candidate[1] = "W";
reasoner[1].temp = Transit.WtoS;
reasoner[2].assumption = Transit.WtoS;
ans_candidate[2] = "S";
reasoner[2].temp = Transit.StoS;
reasoner[3].assumption = Transit.WtoW;
ans_candidate[3] = "W";
reasoner[3].temp = Transit.WtoW;
} else {
throw new Exception("input error");
}
auto o_table = [
Transit.StoS : Transit.StoS,
Transit.StoW : Transit.WtoW,
Transit.WtoS : Transit.StoW,
Transit.WtoW : Transit.WtoS,
];
auto x_table = [
Transit.StoS : Transit.StoW,
Transit.StoW : Transit.WtoS,
Transit.WtoS : Transit.StoS,
Transit.WtoW : Transit.WtoW,
];
foreach (c; s[1..$])
{
if (c == 'o') {
foreach(i; 0..4)
{
if (reasoner[i].temp.among(Transit.StoS, Transit.WtoS)) ans_candidate[i] ~= "S";
else ans_candidate[i] ~= "W";
reasoner[i].temp = o_table[reasoner[i].temp];
}
} else if (c == 'x') {
foreach(i; 0..4)
{
if (reasoner[i].temp.among(Transit.StoS, Transit.WtoS)) ans_candidate[i] ~= "S";
else ans_candidate[i] ~= "W";
reasoner[i].temp = x_table[reasoner[i].temp];
}
} else {
throw new Exception("input error");
}
}
foreach (i; 0..5) {
if (i == 4){
(-1).writeln;
break;
}
if (reasoner[i].temp == reasoner[i].assumption) {
ans_candidate[i].writeln;
break;
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
auto T = readln.chomp;
int[27] ss, ts;
foreach (i; 0..S.length) {
int s = S[i] - 'a' + 1;
int t = T[i] - 'a' + 1;
if (ts[s] == 0 || ts[s] == t) {
ts[s] = t;
} else {
writeln("No");
return;
}
if (ss[t] == 0 || ss[t] == s) {
ss[t] = s;
} else {
writeln("No");
return;
}
}
writeln("Yes");
}
|
D
|
import std.stdio, std.range, std.conv, std.string, std.array, std.functional;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;
void main()
{
string S;
// scanf("%s", &S);
S = readln().strip();
int res;
foreach(i; 0..S.length)
{
int count;
foreach(c; S[i..$])
{
if(
c=='A' ||
c=='C' ||
c=='G' ||
c=='T'
)
{
count++;
continue;
}
break;
}
res = max(res, count);
}
writeln(res);
}
|
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.chomp;
auto arr = ["Sunny", "Cloudy", "Rainy"];
int i = 0;
while (arr[i] != s) { ++i; }
auto ans = arr[(i+1) % 3];
ans.writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int n = scan!int;
print(["pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"][n % 10]);
}
|
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;
int[] r;
int n;
foreach (int i; 1..5000) {
n += i;
r ~= i;
if (n >= N) break;
}
if (n > N) {
r[n-N-1] = 0;
}
foreach (x; r) if (x) {
writeln(x);
}
}
|
D
|
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
void main() {
auto N = readln.chomp;
writeln(N.retro.retro.array == N.retro.array ? "Yes" : "No");
}
|
D
|
void main()
{
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], k = tmp[1];
writeln(k == 1 ? 0 : n - k);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.string, std.conv;
void main()
{
while(true)
{
int n=readln.chomp.to!int;
if(n==0) break;
if(n==1)
{
"deficient number".writeln;
continue;
}
int s=1;
for(int i=2; i*i <= n; ++i)
{
if(n/i*i==n)
{
if(i*i==n) s+=i;
else s+=i+n/i;
}
}
if(s<n) "deficient number".writeln;
else if(s>n) "abundant number".writeln;
else "perfect number".writeln;
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n, k;
scan(n, k);
auto dp = new long[](2*n + 1);
foreach (b ; 1 .. n + 1) {
if (b <= k) continue;
for (int r = b; r <= 2*n; r += b) {
dp[r - (b - k)]++;
dp[r]--;
}
debug {
writeln(b, ":", dp);
}
}
foreach (i ; 1 .. n + 1) {
dp[i] += dp[i - 1];
}
debug {
writeln(dp);
}
long ans;
foreach (i ; 1 .. n + 1) {
ans += dp[i];
}
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
|
void main(){
int[] ab = _scanln();
(ab[0]*ab[1]&1)?writeln("Odd"):writeln("Even");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;
void main()
{
int n = readln.chomp.to!int;
int l = int.max;
int r = int.min;
foreach (v; readln.chomp.split.map!(to!int)) {
l = min(l, v);
r = max(r, v);
}
writeln = r - l;
}
|
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 K = RD;
char[] inc2(char[] s, long i)
{
foreach_reverse (j; 0..i)
{
auto num = s[j+1] - '0';
s[j] = cast(char)(max(num-1, 0)+'0');
}
return s;
}
char[] inc(char[] s, long i)
{
auto x = s[i] - '0';
if (i+1 < s.length)
{
auto y = s[i+1] - '0';
if (y - x >= 0 && x+1 != 10)
{
++s[i];
return inc2(s, i);
}
else
{
return inc(s, i+1);
}
}
else
{
if (x == 9)
{
s ~= '1';
return inc2(s, i+1);
}
else
{
++s[i];
return inc2(s, i);
}
}
}
char[] ans = ['1'];
foreach (i; 0..K-1)
{
ans = inc(ans, 0);
}
ans.reverse();
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
/+ dub.sdl:
name "B"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.scanner;
// import dcomp.graph.dijkstra;
struct State {
int tm;
int col;
int opCmp(State r) {
if (tm < r.tm) return -1;
if (tm > r.tm) return 1;
return 0;
}
}
int main() {
auto sc = new Scanner(stdin);
int n, m;
sc.read(n, m);
int[][] g = new int[][](n);
State[][] dp = new State[][](12, n);
dp.each!(v => v[] = State(0, 0));
foreach (i; 0..m) {
int a, b;
sc.read(a, b); a--; b--;
g[a] ~= b;
g[b] ~= a;
}
int q;
sc.read(q);
foreach (i; 0..q) {
int v, d, c;
sc.read(v, d, c); v--;
dp[d][v] = State(i+1, c);
}
foreach_reverse (ph; 0..11) {
foreach (i; 0..n) {
dp[ph][i] = max(dp[ph][i], dp[ph+1][i]);
foreach (j; g[i]) {
dp[ph][i] = max(dp[ph][i], dp[ph+1][j]);
}
}
}
foreach (i; 0..n) {
writeln(dp[0][i].col);
}
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
//string or char[10] etc
//todo optimize
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
//static
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3]));
assert(equal(c[], "ab"));
assert(equal(d, "cde"));
assert(e == 1.0);
assert(equal(f, [1.0, 2.0]));
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File, writeln;
import std.datetime;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
foreach (i; 0..1_000_000) {
fout.writeln(3*i, " ", 3*i+1, " ", 3*i+2);
}
fout.close;
writeln("Scanner Speed Test(3*1,000,000 int)");
StopWatch sw;
sw.start;
Scanner sc = new Scanner(File(fileName, "r"));
foreach (i; 0..500_000) {
int a, b, c;
sc.read(a, b, c);
assert(a == 3*i);
assert(b == 3*i+1);
assert(c == 3*i+2);
}
foreach (i; 500_000..700_000) {
int[3] d;
sc.read(d);
int a = d[0], b = d[1], c = d[2];
assert(a == 3*i);
assert(b == 3*i+1);
assert(c == 3*i+2);
}
foreach (i; 700_000..1_000_000) {
int[] d;
sc.read(d);
assert(d.length == 3);
int a = d[0], b = d[1], c = d[2];
assert(a == 3*i);
assert(b == 3*i+1);
assert(c == 3*i+2);
}
writeln(sw.peek.msecs, "ms");
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;
import std.range.primitives;
import std.traits : isFloatingPoint, isIntegral;
//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
while (r-l > 1) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
foreach (i; 0..cnt) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
Rotator!Range rotator(Range)(Range r) {
return Rotator!Range(r);
}
struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
size_t cnt;
Range start, now;
this(Range r) {
cnt = 0;
start = r.save;
now = r.save;
}
this(this) {
start = start.save;
now = now.save;
}
@property bool empty() {
return now.empty;
}
@property auto front() {
assert(!now.empty);
import std.range : take, chain;
return chain(now, start.take(cnt));
}
@property Rotator!Range save() {
return this;
}
void popFront() {
cnt++;
now.popFront;
}
}
E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}
ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return minimum!pred(range, e);
}
E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}
ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "range must not empty");
auto e = range.front; range.popFront;
return maximum!pred(range, e);
}
unittest {
assert(minimum([2, 1, 3]) == 1);
assert(minimum!"a > b"([2, 1, 3]) == 3);
assert(minimum([2, 1, 3], -1) == -1);
assert(minimum!"a > b"([2, 1, 3], 100) == 100);
assert(maximum([2, 1, 3]) == 3);
assert(maximum!"a > b"([2, 1, 3]) == 1);
assert(maximum([2, 1, 3], 100) == 100);
assert(maximum!"a > b"([2, 1, 3], -1) == -1);
}
bool[ElementType!Range] toMap(Range)(Range r) {
import std.algorithm : each;
bool[ElementType!Range] res;
r.each!(a => res[a] = true);
return res;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/dijkstra.d */
// module dcomp.graph.djikstra;
// import dcomp.algorithm;
struct Dijkstra(T) {
T[] dist;
int[] from;
this(int n, T inf) {
dist = new T[n]; dist[] = inf;
from = new int[n];
}
}
Dijkstra!D dijkstra(D, T)(T g, int s, D inf = D.max) {
import std.conv : to;
import std.typecons : Tuple;
import std.container : make, Array, heapify;
int V = g.length.to!int;
auto dijk = Dijkstra!D(V, inf);
with (dijk) {
alias P = Tuple!(int, "to", D, "dist");
auto q = heapify!"a.dist>b.dist"(make!(Array!P)([P(s, D(0))]));
dist[s] = D(0);
from[s] = -1;
while (!q.empty) {
P p = q.front; q.popFront();
if (dist[p.to] < p.dist) continue;
foreach (e; g[p.to]) {
if (p.dist+e.dist < dist[e.to]) {
dist[e.to] = p.dist+e.dist;
from[e.to] = p.to;
q.insert(P(e.to, dist[e.to]));
}
}
}
}
return dijk;
}
Dijkstra!D dijkstraDense(D, T)(T g, int s, D inf = D.max) {
import std.conv : to;
import std.typecons : Tuple;
import std.container : make, Array, heapify;
import std.range : enumerate;
import std.algorithm : filter;
int V = g.length.to!int;
auto dijk = Dijkstra!D(V, inf);
with (dijk) {
alias P = Tuple!(int, "to", D, "dist");
bool[] used = new bool[](V);
dist[s] = D(0);
from[s] = -1;
while (true) {
//todo can optimize
auto rng = dist.enumerate.filter!(a => !used[a.index]);
if (rng.empty) break;
auto nx = rng.minimum!"a.value < b.value";
used[nx.index] = true;
P p = P(nx.index.to!int, nx.value);
if (dist[p.to] < p.dist) continue;
foreach (e; g[p.to]) {
if (p.dist+e.dist < dist[e.to]) {
dist[e.to] = p.dist+e.dist;
from[e.to] = p.to;
}
}
}
}
return dijk;
}
unittest {
import std.algorithm, std.conv, std.stdio, std.range;
import std.random;
import std.typecons;
import std.datetime;
alias E = Tuple!(int, "to", int, "dist");
writeln("Dijkstra Random100000");
void f(alias pred)() {
int n = uniform(1, 100);
int m = uniform(1, 1000);
E[][] g = new E[][n];
int[][] dist = new int[][](n, n);
foreach (i, ref v; dist) {
v[] = 10^^9;
}
iota(n).each!(i => dist[i][i] = 0);
foreach (i; 0..m) {
int a = uniform(0, n);
int b = uniform(0, n);
int c = uniform(0, 1000);
g[a] ~= E(b, c);
dist[a][b] = min(dist[a][b], c);
}
foreach (k; 0..n) {
foreach (i; 0..n) {
foreach (j; 0..n) {
dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
foreach (i; 0..n) {
auto dijk = pred!int(g, i, 10^^9);
foreach (j; 0..n) {
assert(dist[i][j] == dijk.dist[j]);
}
assert(dijk.from[i] == -1);
foreach (j; 0..n) {
if (i == j) continue;
if (dist[i][j] == 10^^9) continue;
int b = dijk.from[j];
assert(dijk.dist[j] == dist[i][b]+dist[b][j]);
}
}
}
auto ti = benchmark!(f!dijkstra, f!dijkstraDense)(100);
writeln(ti[0].msecs, "ms");
writeln(ti[1].msecs, "ms");
}
|
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()
{
long A, B;
scan(A, B);
if (B % A == 0)
{
writeln(A + B);
}
else
{
writeln(B - A);
}
}
|
D
|
import std;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
auto S = sread();
auto sum = new long[][](3, N + 1);
foreach (i; 0 .. N)
{
switch (S[i])
{
case 'R':
sum[0][i + 1] = 1;
break;
case 'G':
sum[1][i + 1] = 1;
break;
case 'B':
sum[2][i + 1] = 1;
break;
default:
assert(0);
}
}
foreach (i; 0 .. 3)
foreach (j; 0 .. N)
{
sum[i][j + 1] += sum[i][j];
}
long[] idx = [0, 1, 2];
long ans;
do
{
foreach (i; 0 .. N)
{
if (S[i] == "RGB"[idx[0]])
foreach (j; i + 1 .. N)
{
if (S[j] == "RGB"[idx[1]])
{
ans += sum[idx[2]][$ - 1] - sum[idx[2]][j + 1];
// writefln("%s %s %s", i, j, sum[$ - 1] - sum[j + 1]);
if (j + (j - i) < N && S[j + (j - i)] == "RGB"[idx[2]])
{
// writefln("%s %s %s", i, j, j + (j - i));
ans--;
}
}
}
}
}
while (nextPermutation(idx));
writeln(ans);
}
|
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 kt = readln.chomp.split.map!(to!int);
auto a = readln.chomp.split.map!(to!int).array;
int res;
int prev = -1;
foreach_reverse (n; 1..kt[0]+1) {
int index = -1;
int max_n;
foreach (i, e; a) {
if (e == n) {
index = i.to!int;
break;
}
if (i == prev) {
continue;
}
if (e > max_n) {
index = i.to!int;
max_n = e;
}
}
a[index]--;
if (prev == index) res++;
prev = index;
}
res.writeln;
}
|
D
|
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/3;
enum long MOD = 10L^^9+7;
void main() {
long[] xs = new long[4];
foreach(_; 0..3) {
long a, b;
scanln(a, b);
a--; b--;
xs[a]++;
xs[b]++;
}
if (xs.any!"a>=3") {
"NO".writeln;
} else {
"YES".writeln;
}
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (t * y < x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (t * y > x) t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach(i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
void scanln(Args...)(auto ref Args args) {
import std.meta;
template getFormat(T) {
static if (isIntegral!T) {
enum getFormat = "%d";
} else static if (isFloatingPoint!T) {
enum getFormat = "%g";
} else static if (isSomeString!T || isSomeChar!T) {
enum getFormat = "%s";
} else {
static assert(false);
}
}
enum string fmt = [staticMap!(getFormat, Args)].join(" ");
string[] inputs = readln.chomp.split;
foreach(i, ref v; args) {
v = inputs[i].to!(Args[i]);
}
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
private template RebindableOrUnqual(T)
{
static if (is(T == class) || is(T == interface) || isDynamicArray!T || isAssociativeArray!T)
alias RebindableOrUnqual = Rebindable!T;
else
alias RebindableOrUnqual = Unqual!T;
}
private auto extremum(alias map, alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
in
{
assert(!r.empty, "r is an empty range");
}
body
{
alias Element = ElementType!Range;
RebindableOrUnqual!Element seed = r.front;
r.popFront();
return extremum!(map, selector)(r, seed);
}
private auto extremum(alias map, alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
{
alias mapFun = unaryFun!map;
alias selectorFun = binaryFun!selector;
alias Element = ElementType!Range;
alias CommonElement = CommonType!(Element, RangeElementType);
RebindableOrUnqual!CommonElement extremeElement = seedElement;
// if we only have one statement in the loop, it can be optimized a lot better
static if (__traits(isSame, map, a => a))
{
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
if (selectorFun(r[i], extremeElement))
{
extremeElement = r[i];
}
}
}
else
{
while (!r.empty)
{
if (selectorFun(r.front, extremeElement))
{
extremeElement = r.front;
}
r.popFront();
}
}
}
else
{
alias MapType = Unqual!(typeof(mapFun(CommonElement.init)));
MapType extremeElementMapped = mapFun(extremeElement);
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
MapType mapElement = mapFun(r[i]);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r[i];
extremeElementMapped = mapElement;
}
}
}
else
{
while (!r.empty)
{
MapType mapElement = mapFun(r.front);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r.front;
extremeElementMapped = mapElement;
}
r.popFront();
}
}
}
return extremeElement;
}
private auto extremum(alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r);
}
// if we only have one statement in the loop it can be optimized a lot better
private auto extremum(alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r, seedElement);
}
auto minElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!map(r);
}
auto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!map(r, seed);
}
auto maxElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!(map, "a > b")(r);
}
auto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!(map, "a > b")(r, seed);
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
return x;
}
}
|
D
|
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
auto s = readln.chomp.to!int;
writeln(s / (60 * 60), ":", s % (60 * 60) / 60, ":", s % 60);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto A = readln.chomp.to!(char[]);
long N = A.length;
long[char] CNT;
foreach (a; A) {
if (a !in CNT) CNT[a] = 0;
++CNT[a];
}
long r = N * (N-1) / 2 + 1;
foreach (_, c; CNT) {
r -= (c * (c-1) / 2);
}
writeln(r);
}
|
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 = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Side = Tuple!(long, "from", long, "to");
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 main()
{
auto n = lread();
long[long] a;
foreach (i; iota(n))
{
auto tmp = lread();
if (!(tmp in a))
a[tmp] = 1;
else
a[tmp] = !a[tmp];
}
long ans;
foreach (e; a)
ans += e;
ans.writeln();
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;
void main()
{
auto n = readln.chomp.to!size_t;
auto r = 0;
loop: foreach (_; 0..n) {
auto a = readln.chomp.to!int;
if (a == 2) {
++r;
continue;
}
if (a % 2 == 0)
continue;
foreach (i; iota(3, a.to!real.sqrt.to!int + 1))
if (a % i == 0)
continue loop;
++r;
}
writeln(r);
}
|
D
|
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], m = tmp[1], c = tmp[2];
int[] b = readln.split.to!(int[]);
int cnt;
foreach (i; 0 .. n) {
int[] a = readln.split.to!(int[]);
int src = c;
foreach (j; 0 .. m) {
src += a[j] * b[j];
}
if (src > 0) ++cnt;
}
cnt.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
import core.stdc.stdio;
import std.algorithm;
import std.math;
import std.conv;
void main(){
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
int[] cs = new int[n];
int kc;
scanf("%d",&kc);
for(int i=0;i<n;i++){
scanf("%d",&cs[i]);
}
cs.sort!"a>b";
double ans = kc.to!double/a;
int csum = kc;
for(int i=0;i<n;i++){
csum+=cs[i];
ans = max(ans,csum.to!double/(a+b*(i+1)));
}
printf("%d\n",ans.floor.to!int);
}
|
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 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()
{
auto S = sread();
bool n, w, s, e;
foreach (c; S)
{
n = n || c == 'N';
w = w || c == 'W';
s = s || c == 'S';
e = e || c == 'E';
}
writeln(((n == s) && (w == e)) ? "Yes" : "No");
}
|
D
|
import std.stdio,std.string,std.conv;
void main(){
int sum;
while( 1 ){
auto rd = readln().chomp();
if( !rd ){ break; }
sum=0;
int d = to!int(rd);
for( int i=d; i<600; i+=d ){
sum += i*i*d;
}
writeln(sum);
}
}
|
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.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
auto a=scanString;
auto b=scanString;
auto c=scanString;
write(dchar(a[0]-'a'+'A'));
write(dchar(b[0]-'a'+'A'));
write(dchar(c[0]-'a'+'A'));
writeln();
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto s = sread();
long cnt = INF;
if (s.allEqual())
{
writeln(0);
return;
}
foreach (c; "abcdefghijklmnopqrstuvwxyz")
{
cnt = min(s.needchange(c), cnt);
}
cnt.writeln();
}
long needchange(string str, char c)
{
if (str.length == 1)
return 1;
auto newstr = new char[](str.length - 1);
foreach (i; iota(str.length - 1))
{
newstr[i] = (str[i] == c || str[i + 1] == c) ? c : str[i];
}
if (newstr.allEqual())
return 1;
else
return 1 + needchange(newstr.to!string, c);
}
bool allEqual(T)(T s)
{
bool ret = true;
foreach (i; iota(s.length - 1))
ret &= s[i] == s[i + 1];
return ret;
}
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 core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long a,b;
scan(a,b);
if(a*b%2)
{
writeln("Yes");
}
else
{
writeln("No");
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
import std.math;
auto solve(string s_)
{
auto NA = s_.split.map!(to!int)();
immutable N=NA[0], A=NA[1];
immutable xs=readln.split.map!(to!int).array();
immutable M=N*A+1;
auto dp = new long[][](N+1,M); dp[0][0]=1;
foreach(int k,x;xs)
{
foreach_reverse(j;0..k+1)
foreach(i;0..max(0,M-x))
dp[j+1][i+x]+=dp[j][i];
}
long c=0;
foreach(i;1..N+1) c+=dp[i][i*A];
return c;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
|
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 rgb = readln.chomp.split.map!(to!int);
writeln((rgb[0]*100+rgb[1]*10+rgb[2])%4?"NO":"YES");
}
|
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 s = RD!string;
long ans;
foreach (c; s)
{
if (c == '1')
++ans;
}
writeln(ans);
stdout.flush();
debug readln();
}
|
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() {
auto N = readln.chomp.map!(i => (i - '0').to!int).retro.array;
N ~= 0;
auto L = N.length.to!int;
auto dp = new int[][](L + 1, 2);
fillAll(dp, inf);
dp[0][0] = 0;
foreach (i ; 0 .. L) {
foreach (j ; 0 .. 2) {
foreach (d ; 0 .. 10) {
int x = N[i] + j;
if (d < x) {
chmin(dp[i + 1][1], dp[i][j] + d + 10 + d - x);
}
else {
chmin(dp[i + 1][0], dp[i][j] + d + d - x);
}
}
}
}
auto ans = dp[L][0];
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);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.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;
}
bool calc(int[] ds, int[] ts) {
int[int] map;
foreach (d; ds)
map[d]++;
foreach (t; ts) {
int x = map.get(t, 0);
if (x > 0) {
map[t]--;
}
else {
return false;
}
}
return true;
}
void main() {
readint;
auto ds = readints;
readint;
auto ts = readints;
writeln(calc(ds, ts) ? "YES" : "NO");
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm;
void main()
{
auto s = readln.strip;
writeln(700 + s.count('o') * 100);
}
|
D
|
import std.stdio;
import std.regex;
void main(){
auto io = new IO();
auto w = io.line!string()[0];
foreach( a ; alphaB ){
if( w.count(a) % 2 != 0 ){
writeln( "No" );
return;
}
}
writeln("Yes");
return;
}
import std.stdio,std.conv,std.string;
import std.algorithm,std.array,std.math;
immutable PRIME = 1_000_000_007;
immutable alphaB = "abcdefghijklmnopqrstuvwxyz";
immutable alphaU = "ABCDRFGHIJKLMNOPQRSTUVWXYZ";
class IO
{
T[] line( T = size_t , string token = " " )( size_t m = 1 ){
T[] arr = [];
foreach( i ; 0..m ){
arr ~= this.read!T();
}
return arr;
}
T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){
T[][] arr = new T[][](m);
foreach( i ; 0..m ){
arr[i] = this.read!T(token);
}
return arr;
}
private T[] read( T = size_t )( string token = " " ){
T[] arr;
foreach( elm ; readln().chomp().split(token) ){
arr ~= elm.to!T();
}
return arr;
}
void swap( T )( ref T x , ref T y ){
x = x^y;
y = x^y;
x = x^y;
}
}
// Array compute
// T -> T[]
pure T[] step( T = size_t )( in T begin , in T end , in T step = 1 ){
T[] ret = new T[]((end-begin)/step);
size_t i;
for( T n = begin ; n < end ; n += step ){
ret[i] = n;
i+=1;
}
return ret;
}
unittest{
assert( step(0,10,2) == [0,2,4,6,8] );
}
// T[] -> T[]
pure T[] fill( T )( T[] args , in T filling ){
foreach( ref arg ; args ){
arg = filling;
}
return args;
}
T[] map( T )( T[] args , T function(T) f ){
foreach( ref arg ; args ){
arg = f(arg);
}
return args;
}
unittest{
assert( [true,false,true,false].fill(true) == [true,true,true,true] );
assert( [1,-2,3,-4].map!int(x=>x*2) == [2,-4,6,-8] );
}
// operation
// T[] -> T number
pure T sum( T )( in T[] args ){
T ret = 0;
foreach( i ; 0..args.length ){
ret += args[i];
}
return ret;
}
pure real multi( in real[] args ){
real ret = 1.0;
foreach( i ; 0..args.length ){
ret *= args[i];
}
return ret;
}
pure T ave(T)( in T[] args ){
return args.sum()/args.length;
}
// Search
// T[] -> any
pure bool any( T )( in T[] args , in T target ){
foreach( arg ; args ){
if( arg == target ){return true;}
}
return false;
}
pure bool all( T )( in T[] args , in T cond ){
foreach( arg ; args ){
if( arg != cond ){return false;}
}
return true;
}
pure bool have( T )( in T[] args , in T[] target ... ){
bool[] found = new bool[](target.length);
foreach( arg ; args ){
foreach( i,t ; target ){
if( arg == t ){
found[i] = true;
}
}
}
foreach( f ; found ){
if( f == false ){return false;}
}
return true;
}
pure size_t count( T )( in T[] args , in T target ){
size_t c = 0;
foreach( arg ; args ){
c += ( arg == target ) ? 1 : 0 ;
}
return c;
}
|
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; }
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 A = RD;
auto B = RD;
auto T = RD;
writeln((T / A) * B);
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.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;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD!int;
auto X = RD!int;
auto Y = RD!int;
auto s = RD!string;
long ans;
foreach_reverse (i; 0..N)
{
if (N-1-i == X) break;
auto bit = N-1-i == Y ? '1' : '0';
if (s[i] != bit)
++ans;
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
void main()
{
string n = readln.chomp;
long total;
foreach (x; n)
{
total += x - '0';
}
max(total, (n[0] - '1') + 9 * (n.length - 1)).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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
int a, b;
foreach (i, c; S) {
if ((i%2 == 0 && c == '1') || (i%2 == 1 && c == '0')) ++a;
if ((i%2 == 0 && c == '0') || (i%2 == 1 && c == '1')) ++b;
}
writeln(min(a, b));
}
|
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 = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Mame = Tuple!(long, "point", long, "number");
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 main()
{
long n, k, q;
scan(n, k, q);
auto point = new long[](n);
foreach (i; iota(q))
{
auto a = lread();
point[a - 1]++;
}
foreach (i; iota(n))
{
auto lost = (q - point[i]);
if (lost >= k)
writeln("No");
else
writeln("Yes");
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
long P = 10^^9 + 7;
int[2*10^^5+1] CS;
long[2*10^^5+1] MEMO;
void main()
{
auto N = readln.chomp.to!int;
foreach (i; 0..N) {
CS[i] = readln.chomp.to!int;
}
int[2*10^^5+1] acc, right;
foreach_reverse(ii, c; CS[0..N]) {
int i = ii.to!int;
if (!acc[c]) {
acc[c] = i;
} else {
right[i] = acc[c];
acc[c] = i;
}
}
foreach_reverse (i; 0..N) {
if (i == N-1) {
MEMO[i] = 1;
} else {
long r = MEMO[i+1];
if (right[i] && right[i] != i+1) r = (r + MEMO[right[i]]) % P;
MEMO[i] = r;
}
}
writeln(MEMO[0]);
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "damage", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long a, b, c;
scan(a, b, c);
if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b))
{
writeln("Yes");
}
else
{
writeln("No");
}
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import 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();
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 main()
{
long n = lread();
string s = sread();
long max_same = 0;
foreach (i, e; s)
{
long[] lhs_alf = new long[26];
long[] rhs_alf = new long[26];
string lhs_str = s[0 .. i];
string rhs_str = s[i .. $];
input_to_array(lhs_str, lhs_alf);
input_to_array(rhs_str, rhs_alf);
long same = count_same(lhs_alf, rhs_alf);
max_same = max(same, max_same);
}
writeln(max_same);
}
void input_to_array(string s, long[] a)
{
long key;
foreach (i, e; s)
{
key = e - 'a';
a[key] = 1;
}
}
long count_same(long[] a, long[] b)
{
long count;
foreach (e; 0 .. a.length)
{
if(a[e] && b[e])
{
count++;
}
}
return count;
}
|
D
|
import std.stdio;
import std.array;
import std.string;
import std.conv;
int main()
{
import std.stdio;
auto input = split(chomp(readln()));
int a = to!int(input[0]);
int b = to!int(input[1]);
if (a <= b)
writeln(a);
else
writeln(a - 1);
return 0;
}
|
D
|
void main() {
problem();
}
void problem() {
auto A = scan!int;
auto B = scan!int;
auto C = scan!int;
auto K = scan!int;
int solve() {
int answer;
if (K <= A) return K;
if (K <= A+B) return A;
auto nokori = K - A - B;
return A - nokori;
}
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.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;
void main()
{
auto N = scanElem;
foreach(i;0..N)
{
if(scanElem%2==1){
writeln("first");
return;
}
}
writeln("second");
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio, 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!long;
auto A = readln.split[0].to!long;
auto B = readln.split[0].to!long;
auto C = readln.split[0].to!long;
auto D = readln.split[0].to!long;
auto E = readln.split[0].to!long;
auto M = min(A,B,C,D,E);
writeln(N%M == 0 ? N/M+4 : N/M+5);
}
|
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()
{
auto S = sread();
char[100] ans;
long i;
foreach (c; S)
{
if (c == 'B')
{
i = max(0, i - 1);
continue;
}
ans[i++] = c;
}
writeln(ans[0 .. i]);
}
|
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 n;
string s, t;
}
void parseInput(T)(out Input input, T file)
{
with (file) with (input)
{
n = readln().strip().to!int;
auto array = readln().strip().split();
s = array[0];
t = array[1];
}
}
auto main2(Input* input)
{
foreach (i; 0..input.n)
{
write(input.s[i]);
write(input.t[i]);
}
}
void main()
{
Input input = void;
parseInput(input, stdin);
main2(&input);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
void main() {
auto s = readln.split.map!(to!int);
auto n = s[0];
auto q = s[1];
auto st = new SegmentTree!(int, (a,b)=>a+b, 0)(n);
while (q--) {
s = readln.split.map!(to!int);
auto t = s[0];
auto x = s[1];
auto y = s[2];
if (t == 0) {
st.add(x, y);
} else {
st.query(x, y).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 core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on
void main()
{
long N, A, B;
scan(N, A, B);
auto S = sread();
long cnt;
long b;
foreach (i, c; S)
{
switch (c)
{
case 'a':
if (cnt < A + B)
{
cnt++;
writeln("Yes");
}
else
writeln("No");
break;
case 'b':
if (cnt < A + B && b < B)
{
b++;
cnt++;
writeln("Yes");
}
else
writeln("No");
break;
case 'c':
writeln("No");
break;
default:
break;
}
}
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto ip = readln.split.to!(int[]), A=ip[0], B=ip[1];
if(A<6) writeln(0);
else if(A<13) writeln(B/2);
else writeln(B);
}
|
D
|
void main() {
string[] s = readln.split;
writeln(s[0][0], s[1][0], s[2][0]);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import 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()
{
long N, A, B;
scan(N, A, B);
writeln(min(N * A, B));
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a, b;
scan(a, b);
if (a == 1) a = 14;
if (b == 1) b = 14;
if (a < b) {
writeln("Bob");
}
else if (a > b ) {
writeln("Alice");
}
else {
writeln("Draw");
}
}
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 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 H, W;
scan(H, W);
auto S = new string[](H);
foreach (i; 0 .. H)
S[i] = sread();
foreach (h; 0 .. H)
foreach (w; 0 .. W)
if (S[h][w] == '#')
{
if (0 < h && S[h - 1][w] == '#')
continue;
if (h + 1 < H && S[h + 1][w] == '#')
continue;
if (0 < w && S[h][w - 1] == '#')
continue;
if (w + 1 < W && S[h][w + 1] == '#')
continue;
writeln("No");
return;
}
writeln("Yes");
}
|
D
|
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
int generate()
{
Mt19937 gen;
string str = __DATE__ ~ __TIME__;
uint hash;
foreach (c; str)
{
hash = (hash * 9) + c;
}
gen.seed(hash);
return uniform(1, 1_000_000_000 + 1, gen);
}
enum SUBMIT = true;
bool test(long n)
{
static if (SUBMIT)
{
return query(n);
}
else
{
enum N = generate();
pragma(msg, N);
enum strN = N.to!string;
string strn = n.to!string;
return (n <= N && strn <= strN) || (n > N && strn >= strN);
}
}
bool query(T)(T n)
{
writeln("? ", n);
stdout.flush;
auto ans = readln;
return ans[0] == 'Y';
}
void main()
{
long l = 1;
long zero = 1;
for (; zero.test && zero <= 10_000_000_000L; zero *= 10, ++l)
{
}
--l;
zero /= 10;
long l2 = 1;
for (long z = 2;;)
{
if (z.test)
{
break;
}
z *= 10;
++l2;
}
if (l == 11)
{
long ans = 1;
foreach (i; 1 .. l2)
{
ans *= 10;
}
writeln("! ", ans);
stdout.flush;
return;
}
long left = zero;
long right = zero * 10;
while (right - left > 1)
{
long mid = (left + right) / 2;
bool res = test(10 * mid);
if (res)
{
right = mid;
}
else
{
left = mid;
}
}
writeln("! ", right);
stdout.flush;
}
|
D
|
import std.string;
import std.stdio;
import std.algorithm;
import std.conv;
import std.typecons;
void main() {
long[Tuple!(immutable(char), size_t)] dp;
long[char] checks;
auto s = readln.chomp;
auto t = readln.chomp;
foreach(c; s) {
checks[c] = 0;
}
bool check = true;
foreach(c; t) {
if (c !in checks) {
check = false;
}
}
if (check) {
size_t i;
foreach(c; t) {
auto key = tuple(c, i%s.length);
if (key in dp) {
i += dp[key];
}
else {
size_t j;
for(;j < s.length; ++j) {
auto p = (i + j) % s.length;
if (s[p] == c) break;
}
i += j+1;
dp[key] = j+1;
}
}
write(i);
}
else {
write(-1);
}
}
|
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 X, Y;
scan(X, Y);
long ans;
while (X <= Y)
ans++, X += X;
writeln(ans);
}
|
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 a = readints;
int ab = a[0], bc = a[1];
int area = ab * bc / 2;
writeln(area);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;
bool solve(int s, int g, int[] ns) {
auto N = ns.length;
auto DP = new bool[][](N+1, 8000*2+1);
void sv(int i, int n) {
if (!DP[i][n]) {
DP[i][n] = true;
if (i == N) return;
sv(i+1, n+ns[i]);
sv(i+1, n-ns[i]);
}
}
sv(0, s+8000);
return DP[N][g+8000];
}
void main()
{
int[] xs, ys;
int n, t;
auto s = readln.chomp;
foreach (c; s) {
if (c == 'T') {
if (n != 0) {
if (t%2 == 0) {
xs ~= n;
} else {
ys ~= n;
}
n = 0;
}
++t;
} else {
++n;
}
}
if (n != 0) {
if (t%2 == 0) {
xs ~= n;
} else {
ys ~= n;
}
}
int x;
if (s[0] != 'T') {
x = xs[0];
xs = xs[1..$];
}
auto xy = readln.split.to!(int[]);
auto gx = xy[0];
auto gy = xy[1];
writeln(solve(x, gx, xs) && solve(0, gy, ys) ? "Yes" : "No");
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.