code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto N = readln.chomp.to!int;
writeln((N+999)/1000 * 1000 - N);
}
|
D
|
void main()
{
long n = readln.chomp.to!long;
long[5] cnts;
string t = "MARCH";
foreach (i; 0 .. n)
{
string s = readln.chomp;
foreach (j, x; t)
{
if (x == s[0]) ++cnts[j];
}
}
long result;
foreach (i; 0 .. 3)
{
foreach (j; i+1 .. 4)
{
long mul = cnts[i] * cnts[j];
foreach (k; j+1 .. 5)
{
result += mul * cnts[k];
}
}
}
result.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
void main()
{
int n = readln.chomp.to!int;
int h = readln.chomp.to!int;
int w = readln.chomp.to!int;
writeln((n - h + 1) * (n - w + 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.ascii;
import std.uni;
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
auto ab = readints;
int a = ab[0], b = ab[1];
writeln(a * b % 2 == 0 ? "Even" : "Odd");
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
iota(1, readln.chomp.to!(int)+1).count!(x => x % 2 == 1 && iota(1,x+1).count!(i => x % i == 0) == 8).writeln;
}
|
D
|
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
string[] ss = readln.split;
foreach (i, ref arg ; args) arg = ss[i].parse!int;
}
void main() {
int a; scan(a);
string s = readln.chomp;
writeln(a < 3200 ? "red" : s);
}
|
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; }
/*
桁の数字の和 digit sum
----------------------------------------
「1 以上 j99999... (9がi個) 以下の整数のうち、桁の数字の和を D でわったあまりが r であるものの個数」を
xs[i][j][r] とする。
xs[0][j][r] = (j == r? 1: 0)
xs[i][0] = xs[i - 1][9] である
xs[i][j] は、xs[i][j - 1] に、「xs[i - 1][9] を j だけずらしたもの」を項ごとにたしたもの
具体的には
xs[i][j][r] = xs[i][j - 1][r] + xs[i - 1][9][(r + d - j) % d]
K = 47185, D = 50 の場合
・39999 以下 …… xs[4][3][0]
・46999 以下 …… xs[3][6][46]
・47099 以下 …… xs[2][0][39]
・47179 以下 …… xs[1][7][38]
・47184 以下 …… xs[0][4][30]
・47185
に分けて求める
----------------------------------------
*/
const mod = 1_000_000_007;
void main(){
string kstr = readln.chomp;
long d = read.to!long;
long[][][] xs;
xs ~= [[]];
foreach(j; 0 .. 10){
xs[0] ~= [[]];
foreach(r; 0 .. d){
if(j == 0){
if(r == 0) xs[0][j] ~= 1;
else xs[0][j] ~= 0;
}
else if(j % d == r) xs[0][j] ~= xs[0][j - 1][r] + 1;
else xs[0][j] ~= xs[0][j - 1][r];
}
}
foreach(i; 1 .. kstr.length + 1){
xs ~= [[]];
foreach(j; 0 .. 10){
xs[i] ~= [[]];
foreach(r; 0 .. d){
debug writeln("i:", i, " j:", j, " r:", r, " xs:", xs);
if(j == 0) xs[i][j] ~= xs[i - 1][9][r];
else xs[i][j] ~= (xs[i][j - 1][r] + xs[i - 1][9][(r + d * j - j) % d]) % mod;
}
}
}
long ans;
long offset = 0;
foreach(iv, c; kstr){
long i = kstr.length - 1 - iv;
debug writeln("iv:", iv, " c:", c, " i:", i, " offset:", offset);
if(c >= '1') ans += xs[i][c - '1'][offset], ans %= mod;
offset += d - (c - '0'), offset %= d;
debug writeln("ans:", ans);
}
if(offset == 0) ans += 1, ans %= mod;
ans += mod - 1, ans %= mod; //「0」が含まれてしまうので
ans.writeln;
}
|
D
|
import std.algorithm;
import std.string;
import std.stdio;
void main() {
readln;
string s = readln.chomp;
if (s.length < 3) {
writeln("0");
return;
}
auto c = count(s, 'R') * count(s, 'G') * count(s, 'B');
foreach (i;1..(s.length + 1) / 2) {
for (size_t j = 0;j + i + i < s.length;++j) {
if (cast(int)s[j] + s[j + i] + s[j + i + i] == 0x52 + 0x47 + 0x42) {
--c;
}
}
}
writeln(c);
}
|
D
|
import std.stdio, std.string;
void main() {
string s = readln.chomp;
bool ok = true;
foreach (i; 1 .. 4) {
if (s[i] == s[i-1]) ok = false;
}
writeln(ok ? "Good" : "Bad");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = pred();
return res;
}
void main() {
string str = readln.chomp;
for(int i=0; i+1<str.length; i++) {
if (i>=0 && str[i..i+2]=="ST") {
str = str[0..i]~str[i+2..$];
i -= 2;
}
}
str.length.writeln;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;
string my_readln() { return chomp(readln()); }
void main()
{
auto tokens = my_readln().split();
auto N = tokens[0].to!uint;
long[] a;
foreach (token; my_readln.split)
{
a ~= token.to!long;
}
auto dp = new long[][](3005, 3005);
foreach_reverse (i; 0..N)
{
foreach (j; i+1..N+1)
{
long turn = (N - (j - i)) % 2 == 0 ? 1 : -1;
auto r1 = dp[i][j-1] + a[j-1] * turn;
auto r2 = dp[i+1][j] + a[i] * turn;
auto r = turn == 1 ? max(r1, r2) : min(r1, r2);
dp[i][j] = r;
}
}
writeln(dp[0][N]);
stdout.flush();
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto x = readln.chomp.to!long;
long r = x / 11L * 2;
if (x%11L >= 7) {
r += 2;
} else if (x%11L >= 1) {
r += 1;
}
writeln(r);
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv;
void main()
{
auto ip = readln.split.to!(int[]);
if(ip[0] == ip[1]) writeln("a == b");
else if(ip[0] > ip[1]) writeln("a > b");
else writeln("a < b");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.math;
import std.array;
void main(){
int N = readln().chomp().to!int();
int[] nums;
int[] primes;
for(int i = 0; i < N; i++){ nums ~= readln().chomp().to!int(); }
foreach(int n; nums){
bool isPrime = true;
for(int i = 2; i <= sqrt(n.to!float()); i++){
if(n % i == 0){
isPrime = false;
break;
}
}
if(isPrime){ primes ~= n; }
}
primes.length.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;
// 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()
{
auto S = sread();
auto L = new long[](S.length);
L[0] = 0;
foreach (i; 1 .. S.length)
L[i] = S[i] == 'L' ? L[i - 1] : i;
auto R = new long[](S.length);
R[$ - 1] = S.length - 1;
foreach_reverse (i; 0 .. S.length - 1)
R[i] = S[i] == 'R' ? R[i + 1] : i;
auto ans = new long[](S.length);
// writeln(R, L);
foreach (i; 0 .. S.length)
{
if (S[i] == 'L')
{
long d = i - L[i];
// writeln("L",d);
ans[L[i] + (d & 1)]++;
}
else if (S[i] == 'R')
{
long d = R[i] - i;
// writeln("R",d);
ans[R[i] - (d & 1)]++;
}
}
write(ans[0]);
foreach (v; ans[1 .. $])
write(" ", v);
writeln();
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
auto n = lread();
auto x = new long[](10 ^^ 6 + 10);
foreach (i; 1 .. 101)
{
foreach (j; 1 .. 101)
{
foreach (k; 1 .. 101)
{
long tmp = 0;
tmp = i ^^ 2 + j ^^ 2 + k ^^ 2 + i * j + j * k + i * k;
if (tmp <= 10 ^^ 4)
{
x[tmp - 1] += 1;
}
}
}
}
foreach (i; 0 .. n)
{
writeln(x[i]);
}
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
import std.array;
int n;
rd(n);
auto a = readln.split.map!((s) => (s == "T" ? 1 : 0)).array;
int f(int x, int y) {
return (x - y <= 0);
}
//
auto t = f(a[0], a[1]);
foreach (i; 2 .. n) {
t = f(t, a[i]);
}
if (t) {
writeln("T");
} else {
writeln("F");
}
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
writeln(readln.chomp.to!int.among(7,5,3) ? "YES" : "NO");
}
|
D
|
import std.stdio, std.conv, std.algorithm, std.string, std.container;
void main(){
SList!int list;
while(true){
auto line = readln.chomp;
if(line.length == 0){
break;
}
auto input = line.to!int;
if(input){
list.insertFront(input);
}else{
list.front.writeln;
list.removeFront;
}
}
}
|
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[] high = new long[1000];
high[0] = 1;
foreach (e; 1 .. 1000)
{
high[e] = high[e - 1] + (e + 1);
}
long a, b;
scan(a, b);
long dif = abs(a - b);
writeln(high[dif - 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;
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 C = sread()[0];
writeln(cast(char)(C + 1));
}
|
D
|
void main() {
string s = readln.chomp;
int diff = 1000;
foreach (i; 2 .. s.length) {
int x;
foreach_reverse (j; 0 .. 3) {
x += (s[i-j] - '0') * 10 ^^ j;
}
diff = min(diff, abs(x-753));
}
diff.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
|
void main() {
auto c = readMatrix!char(3, 3);
foreach(i; 0..3) c[i][i].write;
writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto abn = readln.split.to!(long[]);
auto A = abn[0];
auto B = abn[1];
auto N = abn[2];
auto x = min(N, B-1);
writeln((A*x)/B - A*(x/B));
}
|
D
|
void main() {
int[] ab = readln.split.to!(int[]);
writeln(ab.all!"a % 2 == 1" ? "Yes" : "No");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
bool[char] set;
foreach (c; readln.chomp)
{
set[c] = true;
}
foreach (c; 'a' .. 'z')
{
if (c !in set)
{
c.writeln;
return;
}
}
if ('z' !in set)
"z".writeln;
else
"None".writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;
void main() {
int n = readln.chomp.to!int;
int[] c = new int[](n), s = new int[](n), f = new int[](n);
for (int i = 0; i < n - 1; ++i) {
auto l = readln.chomp.split.map!(to!int).array;
c[i] = l[0];
s[i] = l[1];
f[i] = l[2];
}
for (int i = 0; i < n - 1; ++i) {
int ans = s[i];
for (int j = i; j < n - 1; ++j) {
ans += c[j];
if (j == n - 2) {
break;
}
int wait;
if (ans <= s[j + 1]) {
ans += (s[j + 1] - ans);
}
else {
if (ans % f[j + 1] != 0) {
wait = ((ans + f[j + 1]) / f[j + 1]) * f[j + 1] - ans;
ans += wait;
}
}
}
writeln(ans);
}
writeln(0);
return;
}
|
D
|
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv,
std.format,
std.math;
void main()
{
while(true){
auto ip = readln.split;
auto a = ip[0].to!int, b = ip[2].to!int;
if(ip[1] == "?") break;
ip[1].predSwitch(
"+", a + b,
"-", a - b,
"*", a * b,
"/", a / b).writeln;
}
}
|
D
|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s = readln.chomp;
string t = "CF";
while (!t.empty) {
if (s.empty) {
writeln("No");
return;
}
if (t.front == s.front) {
t.popFront();
}
s.popFront();
}
writeln("Yes");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.math;
int n, k; rd(n, k);
auto a=new long[n];
auto b=new long[n];
foreach(i; 0..n) rd(a[i], b[i]);
long mx=0;
foreach(pos; 0..32){
long vsum=0;
if(k&(1<<pos))foreach(i; 0..n){
if(a[i]&(1<<pos)) continue;
bool ok=true;
foreach(j; (pos+1)..32){
ok &= (((k&(1<<j)) | (a[i]&(1<<j))) == (k&(1<<j)));
}
if(ok) vsum+=b[i];
}
mx=max(mx, vsum);
}
long mx2=0;
foreach(i; 0..n){
bool ok=true;
foreach(j; 0..32){
ok &= (((k&(1<<j)) | (a[i]&(1<<j))) == (k&(1<<j)));
}
if(ok) mx2+=b[i];
}
writeln(max(mx, mx2));
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int n; readV(n);
string[] s; readA(n, s);
writeln(s.canFind("Y") ? "Four" : "Three");
}
|
D
|
void main(){
ulong x = _scan!ulong();
ulong dep = 100;
ulong yy = 0;
while( 1 ){
if( dep >= x ){
yy.writeln();
return;
}
yy++;
dep += dep/100;
}
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio, std.conv, std.array,std.string;
void main()
{
auto a=readln;
int aa=0;
if(a[0]=='1')aa++;
if(a[1]=='1')aa++;
if(a[2]=='1')aa++;
writeln(aa);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD!string;
writeln("ABC" ~ N);
stdout.flush();
debug readln();
}
|
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 readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}
void main()
{
int n, m; readV(n, m);
int[] l, r; readC(m, l, r);
writeln(max(0, r.reduce!min - l.reduce!max + 1));
}
|
D
|
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;
void main(){
auto nm=readln.split.map!(to!int).array;
int[][] abs;
foreach(i;0..nm[1])abs~=readln.split.map!(to!int).array;
foreach(n;1..nm[0]+1)writeln(abs.count!(ab=>ab[0]==n||ab[1]==n));
}
|
D
|
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
std.functional, std.container, std.typecons;
ulong gcd(ulong a, ulong b) {
if(b == 0) return a;
return gcd(b, a % b);
}
ulong lcm(ulong a, ulong b) {
return (a * b) / gcd(a, b);
}
void main() {
auto input = readln.split.to!(ulong[]);
ulong A = input[0], B = input[1], C = input[2], D = input[3];
ulong f(ulong n) {
return (B/n)-((A-1)/n);
}
ulong num = f(C) + f(D) - f(lcm(C, D));
(B - A + 1 - num).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;
enum mod = 1_000_000_007L;
void main() {
int N;
scan(N);
auto x = new int[][](N, 0);
auto y = new int[][](N, 0);
foreach (i ; 0 .. N) {
int Ai;
scan(Ai);
while (Ai--) {
int xi, yi;
scan(xi, yi);
xi--;
if (yi) {
x[i] ~= xi;
}
else {
y[i] ~= xi;
}
}
}
int ans;
foreach (s ; 0 .. (1 << N)) {
bool ok = true;
foreach (j ; 0 .. N) if (s & (1 << j)) {
foreach (xk ; x[j]) {
if (!(s & (1 << xk))) {
ok = false;
}
}
foreach (yk ; y[j]) {
if (s & (1 << yk)) {
ok = false;
}
}
}
if (ok) ans = max(ans, s.popcnt);
}
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.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
int a, b, c;
foreach (s; readln.chomp) {
switch (s) {
case 'a': ++a; break;
case 'b': ++b; break;
case 'c': ++c; break;
default:
}
}
writeln(abs(a-b) < 2 && abs(b-c) < 2 && abs(c-a) < 2 ? "YES" : "NO");
}
|
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;
int calc(int a) {
return (a + a + 1 + a + 2 + a + 7 + a + 8 + a + 9 + a + 14 + a + 15 + a + 16) % 11;
}
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto K = s[1];
long ans = 0;
if (N < 3) {
writeln(-1);
return;
}
if (N < 50) {
for (int i = 0, a = 1; i < N - 2; ++i, a = (a + 7) % 11)
for (int j = a; j < a + 5; ++j)
ans += calc(j) == K;
ans.writeln;
return;
}
for (int i = 0, a = 1; i < 11; ++i, a = (a + 7) % 11)
for (int j = a; j < a + 5; ++j)
ans += calc(j) == K;
ans *= (N - 2) / 11L;
for (int i = 0, a = 1; i < (N - 2) % 11; ++i, a = (a + 7) % 11)
for (int j = a; j < a + 5; ++j)
ans += calc(j) == K;
ans.writeln;
}
|
D
|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;
int n, m;
bool[] a;
bool[] b;
void main() {
scan(n, m);
a = new bool[](n + 1);
b = new bool[](n + 1);
int u, v;
foreach (i ; 0 .. m) {
scan(u, v);
if (u == 1) a[v] = true;
if (v == n) b[u] = true;
}
foreach (i ; 1 .. n) {
if (a[i] && b[i]) {
writeln("POSSIBLE");
return;
}
}
writeln("IMPOSSIBLE");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto as = "abcdefghij";
char[] ss;
ss.length = N;
void solve(int i, int j) {
if (i == N) {
writeln(ss);
return;
}
foreach (k; 0..j+2) {
ss[i] = as[k];
solve(i+1, max(j, k));
}
}
solve(0, -1);
}
|
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(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 p, q, r;
scan(p, q, r);
(p + q).min(p + r).min(q + r).writeln();
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
auto a = readln.strip.map !(q{a - '0'}).array;
auto b = readln.strip.map !(q{a - '0'}).array;
int mex (int lo, int hi)
{
bool [3] c;
foreach (i; lo..hi)
{
c[a[i]] = true;
c[b[i]] = true;
}
int res = 0;
while (c[res])
{
res += 1;
}
return res;
}
auto f = new int [n + 1];
f[0] = 0;
f[1] = mex (0, 1);
foreach (i; 2..n + 1)
{
foreach (j; 1..3)
{
f[i] = max (f[i], mex (i - j, i) + f[i - j]);
}
}
writeln (f[n]);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;
void main()
{
auto N = readln.chomp.to!long;
long r;
foreach (i; 1..N+1) {
auto d = N/i;
r += d * (d+1) / 2 * i;
}
writeln(r);
}
|
D
|
import std.stdio, std.string, std.algorithm, std.array;
void main()
{
int t;
scanf("%d", &t);
getchar();
foreach(i; 0..t){
auto str = readln.strip();
string result;
while (str.length > 0)
{
result ~= str[0];
str = str.stripLeft(str[0]);
}
if (result.length > 3)
writeln(2);
else if (result == "0")
writeln(1);
else if (result == "1")
writeln(0);
else if (result == "01" || result == "10")
writeln(1);
else if (result == "101")
writeln(1);
else
writeln(2);
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new bool[](t);
foreach (ti; 0..t)
{
auto n = RD;
auto a = RD;
auto b = RD;
long x = 1;
if (a == 1)
{
auto rem = n - x;
ans[ti] = rem % b == 0;
}
else
{
while (x <= n)
{
if ((n-x) % b == 0)
{
ans[ti] = true;
break;
}
x *= a;
}
}
}
foreach (e; ans)
writeln(e ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
int[] S;
int n;
char last;
foreach (c; readln.chomp) {
if (last && last == c) {
++n;
} else {
if (n) S ~= n;
last = c;
n = 1;
}
}
S ~= n;
if (S.length == 1) {
writeln(S[0]);
return;
}
while (S.length > 2) {
if (S[0] < S[$-1]) {
S[1] += S[0];
S = S[1..$];
} else {
S[$-2] += S[$-1];
S = S[0..$-1];
}
}
writeln(max(S[0], S[1]));
}
|
D
|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
immutable inf = 10^^9 + 7;
int c, v0, v1, a, l;
void main() {
scan(c, v0, v1, a, l);
int r;
int cnt;
while (true) {
cnt++;
r += min(v0 + a * (cnt - 1), v1);
if (r >= c) {
writeln(cnt);
return;
}
r -= l;
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int a, b; scan(a, b);
int ans = (a - 1) + (a <= b);
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
auto tmp = readln.split.to!(long[]);
auto K = tmp[0], A = tmp[1], B = tmp[2];
if (B - A <= 2) {
writeln(1 + K);
} else {
// A-1回最初に叩く
const tataki = max(0, A-1);
K -= tataki;
long pt = 1 + tataki;
// 残り回数が1以下になるまで2回ずつ消費し、B-Aだけ稼ぐ
const urikai = K/2;
K -= urikai * 2;
pt += (B-A) * urikai;
// 残り回数叩く
if (K == 1) pt++;
writeln(pt);
}
}
|
D
|
module sigod.codeforces.p298C;
import std.algorithm;
import std.stdio;
import std.string;
void main()
{
string a = stdin.readln().strip();
string b = stdin.readln().strip();
size_t a_count = a.count('1');
if (a_count % 2 == 1) ++a_count;
size_t b_count = b.count('1');
stdout.writeln(a_count >= b_count ? "YES" : "NO");
}
|
D
|
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto X = RD!long;
auto Y = RD!long;
long ans;
while (X <= Y / 2)
{
X *= 2;
++ans;
}
writeln(ans + 1);
stdout.flush();
}
|
D
|
import std.algorithm;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;
void main() {
auto input = readln.chomp.split.map!(to!long);
auto r = input.front;
input.popFront;
auto D = input.front;
input.popFront;
auto x = input.front;
input.popFront;
iota(10).each!((_){
x = r * x - D;
writeln(x);
});
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
while (true) {
int r0, w0, c, r;
scan(r0, w0, c, r);
if (!r0) return;
int ans;
while (r0 < w0*c) {
r0 += r;
ans++;
}
writeln(ans);
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main(){
int x = readln().chomp().to!int();
writeln(x * x * x);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;
void main()
{
auto N = readln.chomp.to!int;
int r, b;
foreach (c; readln.chomp.to!(char[])) {
if (c == 'R') {
++r;
} else if (c == 'B') {
++b;
}
}
writeln(r > b ? "Yes" : "No");
}
|
D
|
module main;
import std.stdio;
int main(string[] argv)
{
int n,k;
scanf("%d", &n);
int [] a = new int[1005];
int [] b = new int[1005];
int [] c = new int[1005];
for(int i = 1; i<=n; i++)
scanf("%d:%d", &a[i],&b[i]);
for(int i=1;i<=n;i++)
{
c[i]=a[i]*60+b[i];//printf("%d ",c[i]);
}
for(int i=1;i<=n;i++)
{
int minn=100000000,pla=0,j;
for(j=i;j<=n;j++)
{
if(c[j]<minn)
{
minn=c[j];
pla=j;
}
}
//printf("pla:%d",pla);
int t=c[pla];
c[pla]=c[i];
c[i]=t;
}
int ans=0;
for(int i=1;i<n;i++)
{
//printf("%d ",c[i]);
if(c[i+1]-c[i]>ans) ans=c[i+1]-c[i];
}
if(n==1)
{
printf("23:59");
return 0;
}
else
{
if(1440-c[n]+c[1]>ans) ans=1440-c[n]+c[1];
ans--;
printf("%02d:%02d",ans/60,ans%60);
}
return 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 abc = readints;
int a = abc[0], b = abc[1], c = abc[2];
if (a + b >= c)
writeln("Yes");
else
writeln("No");
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b; readV(a, b);
writeln(a.predSwitch!"a<=b"(5, 0, 12, b/2, 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;
enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto a = lread();
auto b = lread();
writeln(6 - a - b);
}
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
void main() {
auto S = rs;
int i = S[0..2].to!int;
int j = S[2..$].to!int;
bool YYMM = j <= 12 && 1 <= j;
bool MMYY = i <= 12 && 1 <= i;
if(YYMM && MMYY) writeln("AMBIGUOUS");
else if(YYMM) writeln("YYMM");
else if(MMYY) writeln("MMYY");
else writeln("NA");
}
// ===================================
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.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
module AOJ_Volume0028;
import std.stdio,std.string,std.conv;
int main()
{
int[101] count;
int max;
string s;
while((s = readln.chomp).length != 0)
{
int value = s.to!int;
count[value]++;
}
max = count[0];
foreach(i;0..100)
{
if(max < count[i]) max = count[i];
}
foreach(i;0..100)
{
if(max == count[i]) writeln(i);
}
return 0;
}
|
D
|
import std.stdio, std.string, std.conv;
void main() {
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], x = tmp[1];
int[] l = readln.split.to!(int[]);
int d, cnt = 1;
foreach (i; 0 .. n) {
d += l[i];
if (d > x) break;
++cnt;
}
cnt.writeln;
}
|
D
|
void main()
{
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], h = tmp[1], w = tmp[2];
int cnt;
foreach (i; 0 .. n)
{
int[] ab = readln.split.to!(int[]);
int a = ab[0], b = ab[1];
if (a >= h && b >= w) ++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.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
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[] dx = [-2,-2,-2,-1,-1,0,0,1,1,2,2,2];
int[] dy = [1,0,-1,2,-2,2,-2,2,-2,1,0,-1];
int[] spx,spy;
int tl;
bool saiki(int x,int y,int n){
if(tl==n) return true;
bool ans = false;
for(int i=0;i<12;i++){
int nx,ny;
nx = x + dx[i];
ny = y + dy[i];
if(0<=nx&&nx<=9&&0<=ny&&ny<=9){
if(abs(nx-spx[n])<=1 && abs(ny-spy[n])<=1){
ans = ans || saiki(nx,ny,n+1);
}
}
}
return ans;
}
void main(){
while(true){
int x,y;
auto s = readln().split().to!(int[]);
x = s[0];
y = s[1];
if(x==0&&y==0) break;
spx = new int[10];
spy = new int[10];
int n = readln().chomp().to!int;
tl = n;
auto s1 = readln().split().to!(int[]);
for(int i=0;i<n;i++){
spx[i] = s1[2*i];
spy[i] = s1[2*i+1];
}
writeln(saiki(x,y,0) ? "OK" : "NA");
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.map!(to!int), a = rd[0], b = rd[1], c = rd[2];
auto r = iota(a, b+1).count!(i => c % i == 0);
writeln(r);
}
|
D
|
void main(){
string s = readln().chomp();
if( s[2] == s[3] && s[4] == s[5])writeln("Yes");
else writeln("No");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto s = sread();
auto t = sread();
if (s.length < t.length)
{
writeln("UNRESTORABLE");
return;
}
long insert = -1;
foreach (i; iota(s.length - t.length + 1))
{
if (is_pass(s[i .. i + t.length], t))
insert = i;
}
if (insert >= 0)
{
fill_a(s, t, insert).writeln();
}
else
{
writeln("UNRESTORABLE");
}
}
bool is_pass(string pat, string str)
{
bool ret = true;
foreach (i; iota(pat.length))
{
if (pat[i] == '?')
continue;
ret &= (pat[i] == str[i]);
}
return ret;
}
auto fill_a(string s, string t, long insert)
{
string ret;
foreach (i, e; s)
{
if (i >= insert && i < insert + t.length)
{
ret ~= t[i - insert];
}
else
{
ret ~= (e == '?' ? 'a' : e);
}
}
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 std.stdio, std.string, std.conv;
import std.algorithm, std.array;
auto solve(string S) {
immutable N = S.length.to!int();
immutable s = S.map!(c=>(c-'0').to!long()).array();
auto v = new long[][](N,N);
v[0][]=s;
foreach(i;1..N)
foreach(j;0..N-i)
v[i][j]=v[i-1][j]*10+s[i+j];
long t=0;
foreach(i;0..N)
foreach(j;0..i+1)
t+=v[N-1-i][j]*(1L<<max(0,j-1))*(1L<<max(0,i-j-1));
return t;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
|
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 calc(string s, int k) {
auto cs = new char[s.length];
for (int i = 0; i < s.length; i++) {
cs[i] = s[i] != s[k - 1] ? '*' : s[i];
}
writeln(cs);
}
void main() {
readint;
string s = read!string;
int k = readint;
calc(s, k);
}
|
D
|
import std.stdio,std.string,std.conv,std.array;
void main(){
loop:for(;;){
auto rcs = readln().chomp().split();
auto a = to!int(rcs[0]);
auto b = to!int(rcs[2]);
final switch(rcs[1]){
case "+":writeln(a+b);break;
case "-":writeln(a-b);break;
case "*":writeln(a*b);break;
case "/":writeln(a/b);break;
case "?":break loop;
}
}
}
|
D
|
void main() {
int s = readln.chomp.to!int;
bool[] a = new bool[1000001];
int cnt = 1;
while (!a[s]) {
a[s] = true;
++cnt;
if (s % 2) s = 3 * s + 1;
else s /= 2;
}
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 std.stdio, std.string, std.algorithm, std.range, std.conv;
void main()
{
// ①入力
auto N = readln.chomp.to!int;
auto A = readln.chomp.to!int;
// ②処理
int res = N^^2-A;
// ③出力
writeln(res);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.math;
int main()
{
string s;
while((s=readln.chomp).length != 0)
{
double value = s.to!double;
double min_t = value/9.8;
double just = 4.9*min_t*min_t;
int number = cast(int)((just+10)/5.0);
writeln(number);
}
return 0;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;
void main()
{
auto S = readln.strip;
long res;
foreach(long l;0..S.length)
{
foreach(long r;l..S.length)
{
long lcount = max(l-1, 0);
long rcount=S.length;
rcount-=r+2;
rcount = max(rcount, 0);
long count;
count = 1<<lcount+rcount;
res += S[l..r+1].to!long * count;
}
}
writeln(res);
}
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));
}
}
}
long scanULong(){
long x;
while(true){
const c = getchar;
if(c<'0'||c>'9'){
break;
}
x = x*10+c-'0';
}
return x;
}
T scanElem(T = string)()
{
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;
void main(){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
writeln(i,"x",j,"=",i*j);
}
}
}
|
D
|
void main()
{
long x = rdElem;
long result;
result += x / 500 * 1000;
x %= 500;
result += x / 5 * 5;
result.writeln;
}
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, 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() {
long x, y;
scan(x, y);
writeln(abs(x - y) < 2 ? "Brown" : "Alice");
}
long dsum(long b, long n) {
return n < b ? n : dsum(b, n / b) + (n % b);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
void main() {
string[] inputs = split(stdin.readln());
auto a = to!(int)(inputs[0]),
op = to!(char)(inputs[1]),
b = to!(int)(inputs[2]);
writeln((op == '+') ? (a + b) : (a - b));
}
|
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; }
/*
まず0の耳がない場合を考える
その場合は、端から端まで歩くとしてよい。各耳に1が入る
そして同じ箇所を往復することにより2ずつ石を入れれるので2で割った余りだけ見ればよい
(a[i] - 1) % 2
1 1 0 0 1 0 0 1 0 1 0 1
などとなっている
両端から折り返して、どこかからどこかまでをカバーする
そこまでに含まれてしまう0の数と、真ん中に含まれてしまう1の数が、調整しなければならない個数
1 1 0 0 1 0 0 1 0 1 0 1
~~~ * ~~*~~~*~~
真ん中に含まれる0の数 - 真ん中に含まれる1の数 が最大になればよい
これは尺取り法でできる
--------------------------------------------------------------------------------
さて0の耳がある場合については…
0の場合にも対応できるように改良する
2をどんどん引いて、0、1、2のいずれかにする
1 1 0 0 1 2 0 1 2 1 2 1
0というのはもともとの0
1というのは先程の言い方でいう0
2というのは先程の言い方でいう1
外れた場合 これを基準とする
0→ペナ0
1→ペナa
2→ペナa
外側に入った場合 p
0→ペナ2 (+2)
1→ペナ1 (-(a-1))
2→ペナ0 (-a)
中央に入った場合 q
0→ペナ1 (+1)
1→ペナ0 (-a)
2→ペナ1 (-(a-1))
点iから始めて、左に行って帰ってくる場合の最良を x[i]
点j - 1から始めて、右に行って帰ってくる場合の最良を y[j]
x[i] = min(x[i - 1] + p[i], 0)
y[j] = min(y[j + 1] + p[j], 0)
点i以左から始めて、点iに帰ってくる場合の最良を x2[i]
点j以右から始めて、点jに帰ってくる場合の最良を y2[i]
x2[i] = min(x[i], x2[i - 1] + q[i]);
y2[i] = min(y[j], y2[j + 1] + q[j]),
求めるものは min(x2[i] + y2[i])
*/
void main(){
long l = read.to!long;
long[] as;
foreach(i; 0 .. l) as ~= read.to!long;
debug writeln("as:", as);
long[] ps, qs;
foreach(i; 0 .. l){
long a = as[i];
if(a == 0) ps~= 2, qs ~= 1;
else if(a % 2 == 1) ps ~= -(a - 1), qs ~= -a;
else ps ~= -a, qs ~= -(a - 1);
}
debug writeln("ps:", ps);
debug writeln("qs:", qs);
long[] xs = new long[](l + 1);
xs[0] = 0;
foreach(i; 1 .. l + 1) xs[i] = min(xs[i - 1] + ps[i - 1], 0);
debug writeln("xs:", xs);
long[] ys = new long[](l + 1);
ys[l] = 0;
foreach_reverse(i; 0 .. l) ys[i] = min(ys[i + 1] + ps[i], 0);
debug writeln("ys:", ys);
long[] x2s = new long[](l + 1);
x2s[0] = xs[0];
foreach(i; 1 .. l + 1) x2s[i] = min(x2s[i - 1] + qs[i - 1], xs[i]);
debug writeln("x2s:", x2s);
long[] y2s = new long[](l + 1);
y2s[l] = ys[l];
foreach_reverse(i; 0 .. l) y2s[i] = min(y2s[i + 1] + qs[i], ys[i]);
debug writeln("y2s:", y2s);
long sum;
foreach(a; as) sum += a;
debug writeln("sum:", sum);
long ans = sum + 10;
foreach(i; 0 .. l + 1) ans = min(ans, sum + x2s[i] + y2s[i]);
ans.writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto n = RD!int;
auto ans = new bool[](n);
foreach (i; 0..n)
{
auto s1 = RD!string;
auto s2 = RD!string;
bool ok = true;
char last;
size_t pos;
foreach (c; s2)
{
if (pos >= s1.length)
{
if (c == last) continue;
else
{
ok = false;
break;
}
}
if (c == s1[pos])
{
++pos;
last = c;
continue;
}
else if (c == last) continue;
else
{
ok = false;
break;
}
}
if (pos < s1.length) ok = false;
ans[i] = ok;
}
foreach (e; ans)
writeln(e ? "YES" : "NO");
stdout.flush();
debug readln();
}
|
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 A = s[1];
auto B = s[2];
int ans = 0;
int x;
foreach (i; 1..10000) {
if (A/i == 0 || B/i == 0) {
x = min(A, B);
} else {
x = i;
}
if (A/x + B/x >= N) {
ans = max(ans, x);
}
}
ans.writeln;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
int main(string[] argv)
{
int n, p1, m;
scanf("%d %d %d", &n, &p1, &m);
long p = p1;
long [] d = new long[n + 1];
long [] t = new long[n + 1];
for(int i = 0; i < n; i++) {
scanf("%lld %lld", &t[i], &d[i]);
}
d[n] = 1152921504606846976L;
t[n] = m + 1;
long curday = 1;
long money = 0;
long answer = 0;
for(int i = 0; i <= n; i++) {
long lastday = t[i];
long needdays = 0;
if (money >= 0) {
needdays = money / p;
}
if (lastday - curday > needdays) {
answer += (lastday - curday) - needdays;
}
money -= p * (lastday - curday + 1);
curday = lastday + 1;
money += d[i];
if (money < 0) {
answer++;
}
}
printf("%lld\n", answer);
return 0;
}
|
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.stdlib;
bool solve() {
auto N = readln.chomp.to!int;
int pa = 0, pb = 0;
bool ok = true;
while (N--) {
auto s = readln.split.map!(to!int);
auto a = s[0];
auto b = s[1];
if (a < b) ok = false;
if (a < pa) ok = false;
if (b < pb) ok = false;
int da = a - pa;
int db = b - pb;
if (db > da) ok = false;
pa = a;
pb = b;
}
return ok;
}
void main() {
auto T = readln.chomp.to!int;
while (T--) writeln(solve ? "YES" : "NO");
}
|
D
|
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.regex;
void main() {
auto HW = readln.chomp.split.map!(to!int);
auto H = HW[0];
foreach (_; 0 .. H) {
auto C = readln;
C.write;
C.write;
}
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
auto r = lread();
writeln(r ^^ 2);
}
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, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto S = readln.chomp;
foreach (i; 0..S.length-1) if (S[i..i+2] == "AC") {
writeln("Yes");
return;
}
writeln("No");
}
|
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 isPrime(int n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
void main() {
string s;
while ((s = readln.chomp) != null) {
int n = s.to!int;
int ans = 0;
for (int i = 1; i <= n; i++) {
int a = i;
int b = n - i + 1;
if (isPrime(a) && isPrime(b))
ans++;
}
writeln(ans);
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto n = RD;
auto cnt = new long[30][](n);
foreach (i; 0..n)
{
auto S = RD!string;
foreach (c; S)
{
++cnt[i][c-'a'];
}
}
string ans;
foreach (i; 0..30)
{
long least = long.max;
foreach (j; 0..n)
{
least = min(least, cnt[j][i]);
}
foreach (j; 0..least) ans ~= i + 'a';
}
writeln(ans);
stdout.flush();
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int a; readV(a);
int b; readV(b);
int c; readV(c);
int x; readV(x);
int r = 0;
foreach (i; 0..a+1)
foreach (j; 0..b+1)
foreach (k; 0..c+1)
if (i*500+j*100+k*50 == x) ++r;
writeln(r);
}
|
D
|
void main() {
string[] tmp = readln.split;
string x = tmp[0], y = tmp[1];
if (x < y) {
'<'.writeln;
} else if (x > y) {
'>'.writeln;
} else {
'='.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;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;
void main()
{
auto nm = readln.split.map!(to!int);
auto co = readln.split.map!(to!int);
auto dp = new int[](nm[0] + 1);
dp[] = int.max;
foreach (c; co) {
if (c > nm[0]) continue;
dp[c] = 1;
}
foreach (i; 1..nm[0]) {
foreach (c; co) {
if (i+c > nm[0]) continue;
dp[i+c] = min(dp[i+c], dp[i]+1);
}
}
dp[nm[0]].writeln;
}
|
D
|
import std.algorithm;
import std.range;
import std.ascii;
import std.array;
import std.container;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) {
stderr.writeln(arg);
}
long modPow(long mod)(long x, long n) {
if (n == 0) return 1;
if (n % 2 == 0) return modPow!mod(x * x % mod, n / 2);
return x * modPow!mod(x % mod, n - 1) % mod;
}
class RollingHash(long[] Ps, long mod) {
string s;
long[][] H;
this(in string s) {
this.s = s;
auto N = s.length;
this.H = new long[][](Ps.length, N + 1); // H[k]: s[0]*Ps[k]^(n-1) + s[1]*Ps[k]^(n-2) + ... + s[n-1]*Ps[k]^0
foreach (k, P; Ps) {
foreach (int i, c; s) {
H[k][i + 1] = (H[k][i] * P + cast(int)(c - 'a' + 1)) % mod;
}
}
}
long[] hash(int l, int r) { // [l, r)
auto hs = iota(0, Ps.length, 1).map!(delegate(k) {
return (H[k][r] - H[k][l] * modPow!mod(Ps[k], r - l) % mod + mod) % mod;
});
return hs.array;
}
}
void main() {
int N, M; scanf("%d %d\n", &N, &M);
auto s = readln.chomp;
auto hasher = new RollingHash!([991, 9999991], cast(long)(1e9+7))(s);
int l = 0, r = 1;
bool[long[]] appeared;
foreach (_; 0 .. M) {
auto q = readln.chomp;
switch (q) {
case "L++": l++; break;
case "L--": l--; break;
case "R++": r++; break;
case "R--": r--; break;
default: assert(false);
}
appeared[hasher.hash(l, r).idup] = true;
}
writeln(appeared.keys.length);
}
|
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 bignum = 1_000_000_007;
alias SugarWater = Tuple!(long, "swater", long, "sugar");
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,c;
scan(a,b,c);
max(0, (c - a + b)).writeln();
}
|
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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n, m, xc, yc; readV(n, m, xc, yc);
int[] x; readA(n, x);
int[] y; readA(m, y);
x ~= xc; y ~= yc;
writeln(x.reduce!max < y.reduce!min ? "No War" : "War");
}
|
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;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.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 gen(){
}
void jury(){
}
void solve(){
int x = scan!int;
(1 - x).print;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;
string FMT_F = "%.10f";
T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto S = RD!string;
long[2] cnt;
foreach (c; S)
{
++cnt[[c].to!long];
}
writeln(min(cnt[0], cnt[1]) * 2);
stdout.flush();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
long MOD = 10L^^9+7;
void main() {
int N = readln.chomp.to!int;
getPrimes(N).map!(p =>
N.iota.map!"a+1".map!((n) {
long res = 0;
while(n%p == 0) {
n/=p;
res++;
}
return res;
}).fold!((a, b) => (a+b)%MOD)(1L)
).fold!((a, b) => a*b%MOD)(1L).writeln;
}
int[] getPrimes(int limit) {
bool[] isPrimes = new bool[limit+1];
isPrimes[2..$] = true;
for (int i=2; i*i<=isPrimes.length; i++) {
if (isPrimes[i]) {
for (int j=i*i; j<isPrimes.length; j+=i) {
isPrimes[j] = false;
}
}
}
int[] primes = [];
foreach (int i, flg; isPrimes) {
if (flg) primes ~= i;
}
return primes;
}
// ----------------------------------------------
// 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);
}
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int d, g;
scan(d, g);
auto p = new int[](d);
auto c = new int[](d);
foreach (i ; 0 .. d) {
scan(p[i], c[i]);
}
int ans = 1<<30;
foreach (s ; 0 .. (1<<d)) {
int score;
int toita;
foreach (i ; 0 .. d) {
if (s & (1<<i)) {
score += 100*(i+1)*p[i];
score += c[i];
toita += p[i];
}
}
foreach_reverse (i ; 0 .. d) {
if (score >= g) {
break;
}
if (s & (1<<i)) {
continue;
}
int t = min(p[i], (g - score + (i+1)*100 - 1) / ((i+1)*100));
score += t*(i+1)*100;
toita += t;
}
ans = min(ans, toita);
}
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.