code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const N = readln.chomp.to!long;
const S = readln.chomp;
auto whiteCount = new long[N+1];
auto blackCount = new long[N+1];
foreach (i; 0..N) {
whiteCount[i+1] = S[i] == '.' ? 1 : 0;
blackCount[i+1] = S[i] == '#' ? 1 : 0;
}
foreach (i; 0..N) {
whiteCount[i+1] += whiteCount[i];
blackCount[i+1] += blackCount[i];
}
// 0..i番目までが全部白、i..n番目までが全部黒にする
iota(N+1).map!(i => blackCount[i] + whiteCount[N] - whiteCount[i]).reduce!min.writeln;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n;
scan(n);
auto p = iota(n).map!(i => readln.chomp.to!int - 1).array;
auto a = new int[](n);
foreach (i ; 0 .. n) {
if (p[i] == 0) {
a[0] = 1;
continue;
}
a[p[i]] = a[p[i] - 1] + 1;
}
debug {
writeln(a);
}
auto ans = n - a.reduce!max;
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;
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 std.regex;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/5;
void main() {
writeln(readln.chomp=="ABC"?"ARC":"ABC");
}
// ----------------------------------------------
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 (y > 0 && t * y < x) t++;
if (y < 0 && t * y > x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (y > 0 && t * y > x) t--;
if (y < 0 && 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;
}
}
}
template scanln(Args...) {
enum sep = " ";
enum n = (){
long n = 0;
foreach(Arg; Args) {
static if (is(Arg == class) || is(Arg == struct) || is(Arg == union)) {
n += Fields!Arg.length;
} else {
n++;
}
}
return n;
}();
enum fmt = n.rep!(()=>"%s").join(sep);
enum argsString = (){
string[] xs = [];
foreach(i, Arg; Args) {
static if (is(Arg == class) || is(Arg == struct) || is(Arg == union)) {
foreach(T; FieldNameTuple!Arg) {
xs ~= "&args[%d].%s".format(i, T);
}
} else {
xs ~= "&args[%d]".format(i);
}
}
return xs.join(", ");
}();
void scanln(auto ref Args args) {
string line = readln.chomp;
static if (__VERSION__ >= 2074) {
mixin(
"line.formattedRead!fmt(%s);".format(argsString)
);
} else {
mixin(
"line.formattedRead(fmt, %s);".format(argsString)
);
}
}
}
// 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);
}
}
}
}
// 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
|
void main()
{
long[] tmp = rdRow;
long k = tmp[0], x = tmp[1];
writeln(500 * k >= x ? "Yes" : "No");
}
T rdElem(T = long)()
{
//import std.stdio : readln;
//import std.string : chomp;
//import std.conv : to;
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
dchar[] rdDchar()
{
//import std.conv : to;
return rdStr.to!(dchar[]);
}
T[] rdRow(T = long)()
{
//import std.stdio : readln;
//import std.array : split;
//import std.conv : to;
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
//import std.range : iota;
//import std.algorithm : map;
//import std.array : array;
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
//import std.range : iota;
//import std.algorithm : map;
//import std.array : array;
return iota(col).map!(x => rdRow!T).array;
}
void wrMat(T = long)(T[][] mat)
{
//import std.stdio : write, writeln;
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
immutable int mod = 10 ^^ 9 + 7;
immutable int limit = 1003;
void add (ref int a, int b)
{
a = (a + b) % mod;
}
void main ()
{
auto h = new int [limit];
h[1] = 0;
foreach (i; 2..limit)
{
h[i] = h[popcnt (i)] + 1;
}
string s;
while ((s = readln.strip) != "")
{
auto k = readln.strip.to !(int);
if (k == 0)
{
writeln (1);
continue;
}
auto n = s.length.to !(int);
auto f = new int [2] [] [] (n + 1, n + 1);
f[0][0][0] = 1;
foreach (i; 0..n)
{
int lim = (s[i] == '1');
foreach (j; 0..i + 1)
{
foreach (prevLess; 0..2)
{
foreach (cur; 0..2)
{
if ((cur > lim) && !prevLess)
{
continue;
}
int nextLess = prevLess ||
(cur < lim);
add (f[i + 1][j + cur]
[nextLess], f[i][j]
[prevLess]);
}
}
}
}
add (f[n][1][1], mod - 1);
int res = 0;
foreach (j; 1..n + 1)
{
if (h[j] == k - 1)
{
add (res, f[n][j][0]);
add (res, f[n][j][1]);
}
}
writeln (res);
}
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;
void main()
{
int n, m;
readln.chomp.split.tie(n, m);
char[][] field = new char[][](n);
foreach (ref a; field) {
a = readln.chomp.dup;
}
int[] cnt = new int[](m);
foreach (a; field) {
foreach (i, v; a) {
if (v == '0') {
continue;
}
cnt[i]++;
}
}
debug verbose(cnt);
bool ok = false;
foreach (i; 0..n) {
// ignore i-th
bool flag = true;
foreach (j; 0..m) {
if (field[i][j] == '0') {
continue;
}
flag &= cnt[j] > 1;
}
ok |= flag;
}
writeln = ok ? "YES" : "NO";
}
void tie(R, Args...)(R arr, ref Args args)
if (isRandomAccessRange!R || isArray!R)
in
{
assert (arr.length == args.length);
}
body
{
foreach (i, ref v; args) {
alias T = typeof(v);
v = arr[i].to!T;
}
}
void verbose(Args...)(in Args args)
{
stderr.write("[");
foreach (i, ref v; args) {
if (i) stderr.write(", ");
stderr.write(v);
}
stderr.writeln("]");
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
while (true) {
int n, a, b, c, x;
scan(n, a, b, c, x);
if (!n) return;
auto y = readln.split.to!(int[]);
solve(n, a, b, c, x, y);
}
}
void solve(int n, int a, int b, int c, int x, int[] y) {
int pos;
foreach (i ; 0 .. 10^^4 + 1) {
if (i > 0) x = nextrand(a, b, c, x);
if (x == y[pos]) {
pos++;
if (pos == n) {
writeln(i);
return;
}
}
}
writeln(-1);
}
int nextrand(int a, int b, int c, int x) {
return (a*x + b) % c;
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;
import std.datetime.systime : Clock;
class InputReader {
private:
ubyte[] p;
ubyte[] buffer;
size_t cur;
public:
this () {
buffer = uninitializedArray!(ubyte[])(16<<20);
p = stdin.rawRead (buffer);
}
final ubyte skipByte (ubyte lo) {
while (true) {
auto a = p[cur .. $];
auto r = a.find! (c => c >= lo);
if (!r.empty) {
cur += a.length - r.length;
return p[cur++];
}
p = stdin.rawRead (buffer);
cur = 0;
if (p.empty) return 0;
}
}
final ubyte nextByte () {
if (cur < p.length) {
return p[cur++];
}
p = stdin.rawRead (buffer);
if (p.empty) return 0;
cur = 1;
return p[0];
}
template next(T) if (isSigned!T) {
final T next () {
T res;
ubyte b = skipByte (45);
if (b == 45) {
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 - (b - 48);
}
} else {
res = b - 48;
while (true) {
b = nextByte ();
if (b < 48 || b >= 58) {
return res;
}
res = res * 10 + (b - 48);
}
}
}
}
template next(T) if (isUnsigned!T) {
final T next () {
T res = skipByte (48) - 48;
while (true) {
ubyte b = nextByte ();
if (b < 48 || b >= 58) {
break;
}
res = res * 10 + (b - 48);
}
return res;
}
}
final T[] nextA(T) (int n) {
auto a = uninitializedArray!(T[]) (n);
foreach (i; 0 .. n) {
a[i] = next!T;
}
return a;
}
}
void main() {
auto r = new InputReader;
immutable n = r.next!int;
immutable k = r.next!int;
immutable a = r.nextA!int(k).idup;
auto c = new int[n + 1];
auto first = new int[n+1];
first[] = int.max;
auto last = new int[n+1];
last[] = int.min;
foreach_reverse (i, j; a) {
first[j] = i.to!int;
++c[j];
}
foreach (i, j; a) {
last[j] = i.to!int;
}
int res;
foreach (i; 1 .. n + 1) {
foreach (delta; -1 .. 2) {
int j = i + delta;
if (j >= 1 && j <= n) {
if (first[i] > last[j]) ++res;
}
}
}
writeln (res);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
void main() {
int n;
scanf("%d\n", &n);
auto hs = readln.chomp.split.to!(int[]);
int m = hs[0];
foreach(h; hs){
if (m - h > 1) {
write("No");
return;
}
m = max(m, h);
}
write("Yes");
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main()
{
string s = readln().chomp;
int n = s.to!(int);
if (s[$ - 1] == '0' ||
s[$ - 1] == '2' ||
s[$ - 1] == '4' ||
s[$ - 1] == '6' ||
s[$ - 1] == '8' ) {
writeln(s);
} else {
writeln(n*2);
}
}
|
D
|
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
import std.numeric;
void main()
{
immutable n = readln.chomp.to!int;
auto a = readln.chomp.split.to!(int[]);
int i = 1;
a = a.find(i);
if (a.empty)
return (-1).writeln;
while (!a.empty)
{
i += 1;
a = a.find(i);
}
(n-i+1).writeln;
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int N;
int[] A;
scan(N);
A = readln.split.to!(int[]);
long ans;
void dfs(int i, int even) {
if (i == N) {
if (!even) ans++;
return;
}
dfs(i + 1, even * ((A[i] - 1) & 1));
dfs(i + 1, even * (A[i] & 1));
dfs(i + 1, even * ((A[i] + 1) & 1));
}
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 std.stdio, std.conv, std.string, std.math;
void main(){
auto ip = readln.split.to!(int[]);
if(ip[2] >= ip[0] && ip[2] <= ip[1]){
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
import std.numeric;
void main(){
foreach(string line; lines(stdin))
writeln(patternN(line.parse!int));
}
int patternN(int N = 1)(int n){
static if(N == 4){
if(n >= 0 && n < 10)
return 1;
else
return 0;
}else{
if(n < 0)
return 0;
int sum;
foreach(i; 0..10)
sum += patternN!(N+1)(n - i);
return sum;
}
}
|
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 A, B, C;
scan(A, B, C);
foreach (x; 1 .. 1_000_000)
{
if (A * x % B == C)
{
writeln("YES");
return;
}
}
writeln("NO");
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, 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 N, M;
scan(N, M);
auto A = aryread();
long t = A.sum();
long cnt;
foreach (i; 0 .. N)
{
if (t <= 4 * M * A[i])
cnt++;
}
writeln(cnt < M ? "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.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 = 998244353;
//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)); }
int[] f(const(int[]) a, const(int[]) b)
{
auto t = a.dup; t[] += b[]; return t;
}
struct SegTree(T)
{
T[] data;
T init;
void initialize(T[] _data, T _init)
{
init = _init;
size_t n = 1; while (n < _data.length) n *= 2; data.length = n*2-1;
foreach (i; 0.._data.length) data[i+n-1] = _data[i];
foreach (i; _data.length..n) data[i+n-1] = _init.dup;
foreach_reverse (i; 0..n-1) data[i] = f(data[i*2+1], data[i*2+2]);
}
T query(size_t l, size_t r) const
{
size_t n = (data.length+1) / 2; l += n-1; r += n-1; T res = f(init, data[l]);
while (l < r)
{
if ((l & 1) == 0) res = f(res, data[l]);
if ((r & 1) == 0) res = f(res, data[r-1]);
l = l/2; r = (r-1)/2;
}
return res;
}
void update(size_t i, T v)
{
i += (data.length+1) / 2 - 1; data[i] = v;
while (i != 0) { i = (i-1)/2; data[i] = f(data[i*2+1], data[i*2+2]); }
}
}
void main()
{
auto N = RD;
auto S = RD!string;
auto Q = RD;
auto arr = new int[][](N, 26);
foreach (i; 0..N)
{
auto num = S[i] - 'a';
arr[i][num] = 1;
}
auto dummy = new int[](26);
SegTree!(int[]) st;
st.initialize(arr, dummy);
long[] ans;
foreach (qi; 0..Q)
{
auto type = RD;
if (type == 1)
{
auto i = RD-1;
auto c = RD!string;
auto num = c[0] - 'a';
auto x = new int[](26);
x[num] = 1;
st.update(i, x);
}
else
{
auto l = RD-1;
auto r = RD;
auto res = st.query(l, r);
long cnt;
foreach (i; 0..26)
{
if (res[i] != 0)
++cnt;
}
ans ~= cnt;
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
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 a = "CODEFESTIVAL2016";
string str = readln.chomp;
int ans = 0;
foreach(i; 0..a.length) {
if (a[i]!=str[i])ans++;
}
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(){
string s = scan, t = scan;
int n = s.length.to!int, m = t.length.to!int;
int ans = n;
foreach(i; 0 .. n){
if(i + m > n) continue;
int tmpans;
foreach(j; 0 .. m){
if(s[i + j] != t[j]) tmpans += 1;
}
ans.lowerTo(tmpans);
}
ans.writeln;
}
|
D
|
void main(){
if(inelm() >= 30){
writeln("Yes");
}else{
writeln("No");
}
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
// 1要素のみの入力
T inelm(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] inln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
return ln;
}
|
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 N = RD!long;
auto Y = RD!long;
long r1 = (Y % 5000) / 1000;
long r5 = (Y % 10000) / 5000;
long r10 = Y / 10000;
while (r1 + r5 + r10 < N)
{
if (r1 + r5 + r10 + 4 <= N && r5 > 0)
{
--r5;
r1 += 5;
}
else if (r10 > 0)
{
--r10;
r5 += 2;
}
else break;
}
if (r1 + r5 + r10 != N)
{
writeln("-1 -1 -1");
}
else
{
writeln(r10, " ", r5, " ", r1);
}
stdout.flush();
}
|
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.numeric;
void main()
{
auto k = readln.chomp.to!int;
long sum;
foreach (int i; 1..k+1) {
foreach (int j; 1..k+1) {
auto t = gcd(i, j);
foreach (int l; 1..k+1) {
sum += gcd(t, l);
}
}
}
sum.writeln;
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= 100; j++) {
if (i * 4 + j * 7 == n) {
writeln("Yes");
return;
}
}
}
writeln("No");
}
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;
import std.string;
/+
const int LEFT = 0;
const int RIGHT = 1;
const int UP = 2;
const int DOWN = 3;
+/
enum {
LEFT,
RIGHT,
UP,
DOWN
}
void main()
{
string[9] kabe;
int x, y;
int direction;
foreach (i; 0..9) {
kabe[i] = readln().chomp;
kabe[i].length = 18;
}
x = 0;
y = 0;
direction = RIGHT;
move(&x, &y, direction);
while (x != 0 || y != 0) {
if (isKabe(kabe, x, y, getLeft(direction)))
direction = getLeft(direction);
else if (isKabe(kabe, x, y, direction))
{}
else if (isKabe(kabe, x, y, getRight(direction)))
direction = getRight(direction);
else
direction = getRight(getRight(direction));
move(&x, &y, direction);
}
writeln();
}
bool isKabe(string[9] kabe, int x, int y, int dir)
{
final switch (dir) {
case LEFT:
if (x <= 0) return false;
return (kabe[y*2][x-1] == '1');
break;
case RIGHT:
if (x >= 4) return false;
return (kabe[y*2][x] == '1');
break;
case UP:
if (y <= 0) return false;
return (kabe[y*2-1][x] == '1');
break;
case DOWN:
if (y >= 4) return false;
return (kabe[y*2+1][x] == '1');
break;
}
return false;
}
int getLeft(int dir)
{
final switch (dir) {
case LEFT: return DOWN; break;
case RIGHT: return UP; break;
case UP: return LEFT; break;
case DOWN: return RIGHT; break;
}
return 0;
}
int getRight(int dir)
{
final switch (dir) {
case LEFT: return UP; break;
case RIGHT: return DOWN; break;
case UP: return RIGHT; break;
case DOWN: return LEFT; break;
}
return 0;
}
void move(int* x, int* y, int dir)
{
final switch (dir) {
case LEFT:
(*x)--;
write("L");
break;
case RIGHT:
(*x)++;
write("R");
break;
case UP:
(*y)--;
write("U");
break;
case DOWN:
(*y)++;
write("D");
break;
}
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import 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 n = read.to!int;
int[] ss;
foreach(i; 0 .. n) ss ~= read.to!int;
int sum = ss.reduce!"a + b"();
int ans;
if(sum % 10 != 0) ans = sum;
else{
int m = sum;
foreach(s; ss){
if(s < m && (sum - s) % 10 != 0) m = s;
}
ans = sum - m;
}
ans.writeln;
}
|
D
|
void main() {
auto n = ri;
writeln(n/3);
}
// ===================================
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;
}
long rl() {
return readAs!long;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
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 ni = readints;
int n = ni[0], i = ni[1];
writeln(n + 1 - i);
}
|
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()
{
auto N = sread();
writeln((N[0] == '7' || N[1] == '7' || N[2] == '7') ? "Yes" : "No");
}
|
D
|
import std.stdio, std.string, std.conv;
void main()
{
auto n = readln.split.to!(int[]), a = n[0], b = n[1];
int m;
if((a + b) % 2 == 0){
m = 0;
} else {
m = 1;
}
writeln((a + b) / 2 + m);
}
|
D
|
import std.stdio, std.string, std.algorithm, std.conv;
int[] a;
void main(){
string[] s;
while (1) {
s = split(readln());
a = [];
foreach (i; s) a ~= to!int(i);
if (a[0] == 0) break;
writeln(solve(0, 0));
}
}
int solve(int p, int n){
if (n > 21) return 0;
if (p >= a.length) return n;
if (a[p] == 1) return max(solve(p+1, n+1), solve(p+1, n+11));
if (a[p] > 10) a[p] = 10;
return solve(p+1, n+a[p]);
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 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 main()
{
auto q = RD!int;
auto ans = new long[2][][](q);
foreach (i; 0..q)
{
auto b = RD;
auto w = RD;
if (max(b, w)-1 > min(b, w)*3)
{
continue;
}
long x, y;
if (b > w)
{
x = 2;
y = 3;
ans[i] ~= [[x, y], [x+1, y]];
--b;
--w;
++x;
}
else
{
x = y = 2;
ans[i] ~= [[x, y], [x+1, y]];
--w;
--b;
++x;
}
auto dir = [[1, 0], [0, 1], [0, -1]];
while (b != 0 || w != 0)
{
if ((x+y)%2 == 0)
{
auto m = cast(int)min(3, max(1, b-w));
foreach (j; 0..m)
{
auto dx = dir[j][0];
auto dy = dir[j][1];
ans[i] ~= [x+dx, y+dy];
--b;
}
++x;
}
else
{
auto m = cast(int)min(3, max(1, w-b));
foreach (j; 0..m)
{
auto dx = dir[j][0];
auto dy = dir[j][1];
ans[i] ~= [x+dx, y+dy];
--w;
}
++x;
}
}
}
foreach (e; ans)
{
if (e.length == 0)
writeln("NO");
else
{
writeln("YES");
foreach (ee; e)
{
writeln(ee[0], " ", ee[1]);
}
}
}
stdout.flush();
debug readln();
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] 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()
{
real A, B;
scan(A, B);
foreach (x; 1 .. 10_000)
{
// writeln(x, " ", (x * 108) / 100);
if (A == floor(x * 0.08) && B == floor(x * 0.1))
{
writeln(x);
return;
}
}
writeln(-1);
}
|
D
|
void main()
{
dchar[] c = rdDchar;
dchar[] d = rdDchar;
dchar[] e = c.dup;
dchar[] f = d.dup;
reverse(e);
reverse(f);
writeln(c == f && d == e ? "YES" : "NO");
}
enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
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.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 abx = readints;
int a = abx[0], b = abx[1], x = abx[2];
if (a <= x && x <= a + b)
writeln("YES");
else
writeln("NO");
}
|
D
|
void main() {
problem();
}
void problem() {
auto N = scan!int;
auto D = scan!long;
auto P = N.iota.map!(_ => Point(scan!long, scan!long)).array;
long solve() {
long ans;
auto d = D*D;
foreach(p; P) {
auto dd = p.x*p.x + p.y*p.y;
if (dd <= d) ans++;
}
return ans;
}
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 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;
}
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long N, M;
scan(N, M);
long f(long x)
{
long ans = 1;
foreach (i; 1 .. x + 1)
{
ans = (ans * i) % MOD;
}
return ans;
}
if (N == M)
{
writeln((f(N) ^^ 2 % MOD) * 2 % MOD);
}
else if (abs(N - M) == 1)
{
writeln(f(N) * f(M) % MOD);
}
else
{
writeln(0);
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!ptrdiff_t;
auto a = readln.split.to!(int[]);
if (n == 1) {
write(a[0]);
} else if (n % 2 == 0) {
for (auto i = n-1; i >= 1; i -= 2) write(a[i], " ");
for (auto i = 0; i <= n-2; i += 2) write(a[i], i == n-2 ? "" : " ");
} else {
for (auto i = n-1; i >= 0; i -= 2) write(a[i], " ");
for (auto i = 1; i <= n-2; i += 2) write(a[i], i == n-2 ? "" : " ");
}
writeln;
}
|
D
|
void main() {
long m = readln.chomp.to!long;
long x, y;
foreach (i; 0 .. m) {
long[] tmp = readln.split.to!(long[]);
long d = tmp[0], c = tmp[1];
x += c, y += d * c;
}
writeln(x - 1 + (y - 1) / 9);
}
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
|
// 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 = lread();
long ans;
foreach (b; 1 .. 500)
foreach (p; 2 .. 500)
if (b ^^ p <= X)
{
ans = ans.max(b ^^ p);
}
writeln(ans);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void main()
{
auto ip = readln.split.to!(int[]);
if(ip[1] == 100) ip[1]++;
writeln(100 ^^ ip[0] * ip[1]);
}
//writeln("滲み出す混濁の紋章 不遜なる狂気の器 湧き上がり 否定し 痺れ 瞬き 眠りを妨げる 爬行する鉄の王女 絶えず自壊する泥の人形 結合せよ 反発せよ 地に満ち己の無力を知れ 破道の九十 黒棺")
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto b = readln.chomp;
if (b == "A") {
writeln("T");
} else if (b == "T") {
writeln("A");
} else if (b == "C") {
writeln("G");
} else {
writeln("C");
}
}
|
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;
if (N == 0) {
writeln(0);
return;
}
char[] r;
foreach (i; 0..40) {
if (N == 0) break;
if (abs(N) & (1<<i)) {
r ~= '1';
N -= (-2)^^i;
} else {
r ~= '0';
}
}
r.reverse();
writeln(r);
}
|
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;
}
void main() {
2.rep!(() => readln.chomp.to!BigInt).pipe!(
a => a[0]>a[1]?"GREATER":a[0]<a[1]?"LESS":"EQUAL"
).writeln;
}
// ----------------------------------------------
// 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) {
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
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
long ans = long.max;
foreach (x; 1 .. N)
{
if (N < x * x)
break;
if (N % x != 0)
continue;
ans = ans.min((x - 1) + ((N / x) - 1));
}
writeln(ans);
}
|
D
|
void main()
{
long n = readln.chomp.to!long;
long[] a = readln.split.to!(long[]);
long ud;
long cnt = 1;
foreach (i; 1 .. n)
{
if (ud == 0)
{
if (a[i] > a[i-1]) ud = 1;
if (a[i] < a[i-1]) ud = -1;
}
else
{
if (ud == 1 && a[i] < a[i-1])
{
ud = 0;
++cnt;
}
if (ud == -1 && a[i] > a[i-1])
{
ud = 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.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.string, std.conv, std.range, std.algorithm;
void main() {
auto N = readln.chomp.to!int;
((1 + N) * N / 2).writeln;
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;
void main() {
auto N = readln.chomp.to!int;
auto ans = new int[](N+1);
int tmp = 1;
foreach (i; 2..N+1) {
if (ans[i] != 0) continue;
for (int j = i; j <= N; j += i) {
ans[j] = tmp;
}
tmp += 1;
}
ans[2..$].map!(to!string).join(" ").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, "l ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto n = lread();
auto a = new long[](n);
auto b = new long[](n);
foreach (i; iota(n))
{
long a_, b_;
scan(a_, b_);
a[i] = a_;
b[i] = b_;
}
long count;
foreach_reverse (i; iota(n))
{
auto m = ((a[i] + count) % b[i]);
if(m)
count += b[i] - m;
}
count.writeln();
}
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.range,
std.string,
std.conv,
std.math,
std.algorithm;
void main(){
int base = 100000;
real p = 1.05;
int n = readln.chomp.to!int;
n.iota.each!((e){
base *= p;
base += (base % 1000) ? 1000 - base % 1000 : 0;
});
writeln(base);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void main()
{
auto hwk = readln.split.to!(int[]);
auto H = hwk[0];
auto W = hwk[1];
auto K = hwk[2];
char[][] MAP;
foreach (_; 0..H) MAP ~= readln.chomp.to!(char[]);
int res;
foreach (y; 0..1<<H) foreach (x; 0..1<<W) {
int b;
foreach (i; 0..H) foreach (j; 0..W) if (MAP[i][j] == '#' && (y & (1<<i)) && (x & (1<<j))) ++b;
if (b == K) ++res;
}
writeln(res);
}
|
D
|
void main()
{
long[] tmp = readln.split.to!(long[]);
long a = tmp[0], b = tmp[1];
if (a * b <= 0)
{
"Zero".writeln;
}
else if (a < 0 && b < 0 && (b - a) % 2 == 0)
{
"Negative".writeln;
}
else
{
"Positive".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.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto str = readln.chomp.dup;
auto q = readln.chomp.to!size_t;
foreach (_; 0..q) {
auto rd = readln.split, cmd = rd[0];
auto a = rd[1].to!int, b = rd[2].to!int;
switch (cmd) {
case "print":
writeln(str[a..b+1]);
break;
case "reverse":
auto t = str[a..b+1];
t.reverse();
break;
case "replace":
auto p = rd[3];
str[a..b+1][] = p[];
break;
default:
assert(0);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto ad = readln.split.to!(int[]);
auto a = ad[0];
auto b = ad[1];
auto c = ad[2];
auto d = ad[3];
writeln(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d) ? "Yes" : "No");
}
|
D
|
import std.stdio,
std.array,
std.conv,
std.string,
std.algorithm,
std.math;
void main(){
string s;
for(;;){
s=readln();
if(stdin.eof()) break;
int num = to!int(chomp(s));
int result = 0;
int[] nums = new int[num];
for(int i=0;i < num;++i) nums[i] = 1;
nums[0] = 0;
for(int i=1;i < sqrt(cast(double)num);++i){
if(nums[i] == 1){
for (int j = (i+1); (i+1) * j <= num; j++) nums[(i+1) * j - 1] = 0;
}
}
for(int i = 0;i < num; ++i){
if(nums[i] == 1)++result;
}
writeln(result);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto N = readln.to!(wchar[]);
writeln(N[0] == '9' || N[1] == '9' ? "Yes" : "No");
}
|
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 nk = readln.split.to!(long[]);
auto n = nk[0];
auto k = nk[1];
long a;
long b;
foreach (i; 1 .. n + 1)
{
if (i % k == 0)
{
a++;
}
}
if (k % 2 == 0)
{
foreach (i; 1 .. n + 1)
{
if (i % k == k / 2)
{
b++;
}
}
}
(a ^^ 3 + b ^^ 3).writeln;
}
|
D
|
import std.stdio;
import std.string;
bool isK(C)(C[] a) {
if (a.length <= 1) return true;
size_t l = 0, r = a.length - 1;
while (l < r) {
if (a[l] != a[r]) {
return false;
}
++l;
--r;
}
return true;
}
void main() {
auto s = readln.chomp;
if (s.isK && s[0.. $ / 2].isK && s[$ / 2 + 1..$].isK) {
writeln("Yes");
} else {
writeln("No");
}
}
|
D
|
import std.stdio, std.conv, std.array,std.string,std.algorithm;
void main()
{
auto n=readln.chomp.to!int;
long ans=1;
for(int i=1;i<=n;i++){
ans*=i;
ans%=1000000000+7;
}
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;
int readint() {
return readln.chomp.to!int;
}
int[] readints() {
return readln.split.map!(to!int).array;
}
void main() {
auto xs = readints;
long q = xs[0];
long h = xs[1];
long s = xs[2];
long d = xs[3];
long one = min(q * 4, h * 2, s);
long two = min(one * 2, d);
auto n = readint;
long ans = (n / 2) * two + (n % 2) * one;
writeln(ans);
}
|
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 n; readV(n);
string s; readV(s);
auto t = s.map!(si => si == 'o').array;
auto calc(bool[] a)
{
foreach (i; 1..n-1) a[i+1] = a[i-1]^a[i]^t[i];
if (a[0] == (a[$-2]^a[$-1]^t[$-1]) && a[1] == (a[$-1]^a[0]^t[0]))
return true;
else
return false;
}
auto a = new bool[](n);
foreach (i0; 0..2)
foreach (i1; 0..2) {
a[0] = i0 == 1;
a[1] = i1 == 1;
if (calc(a)) {
foreach (i; 0..n)
write(a[i] ? "S" : "W");
writeln;
return;
}
}
writeln(-1);
}
|
D
|
void main() {
int a = readln.chomp.to!int;
int b = readln.chomp.to!int;
int h = readln.chomp.to!int;
writeln((a + b) * h / 2);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.array, std.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 N = readln.chomp.to!int;
auto A = readln.split.map!(to!int).array;
int ans = 0;
for (int i = 1; i < N; ++i) {
if (A[i] == A[i-1]) {
ans += 1;
i += 1;
}
}
ans.writeln;
}
|
D
|
import std.stdio, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
immutable int[dchar] L = ['I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000];
foreach(w;stdin.byLine())
{
int s=0,t=0,c=0;
foreach(n;w.map!(a=>L[a])())
{
if(n==c) t+=c;
if(n>c) s-=t,t=c=n;
if(n<c) s+=t,t=c=n;
}
writeln(s+t);
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
writeln(2^^cast(int)readln.chomp.to!int.log2);
}
|
D
|
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;
scan(s);
writeln(s[0 .. $ - 8]);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
int maxN = 10^^6;
int[] f, f_odd;
for(int n=1; ;n++) {
f ~= func(n);
if (f.back > maxN) break;
if (f.back%2!=0) f_odd~= f.back;
}
int INF = 1<<30;
int[] ary = new int[maxN+1];
ary[] = INF;
ary[0] = 0;
while(true) {
foreach(int i; 0..maxN) {
if (ary[i]<INF) {
for(int n=0; n<f.length; n++) {
if (i+f[n]<=maxN) {
ary[i+f[n]] = min(ary[i+f[n]], ary[i]+1);
} else {
break;
}
}
}
}
if (ary[maxN] < INF) break;
}
int[] _ary = new int[maxN+1];
_ary[] = INF;
_ary[0] = 0;
while(true) {
foreach(int i; 0..maxN) {
if (_ary[i]<INF) {
for(int n=0; n<f_odd.length; n++) {
if (i+f_odd[n]<=maxN) {
_ary[i+f_odd[n]] = min(_ary[i+f_odd[n]], _ary[i]+1);
} else {
break;
}
}
}
}
if (_ary[maxN] < INF) break;
}
while(true) {
int N = readln.chomp.to!int;
if (N==0) break;
writeln(ary[N], " ", _ary[N]);
}
}
int func(int n) {
return n*(n+1)*(n+2)/6;
}
|
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] && ip[1] < ip[2]) 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 n, m; readV(n, m);
writeln((n-1)*(m-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 N = lread();
auto A = aryread!ulong();
bool b = A.reduce!((a, b) => a ^ b) == 0;
writeln(b ? "Yes" : "No");
}
|
D
|
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
long k, n;
cin.scan(k, n);
long[] a = cin.nextArray!long(n);
long[] ar = a.dup;
foreach (e; a) {
ar ~= k + e;
}
long[] tmp;
foreach (e; a) {
tmp ~= k - e;
}
tmp ~= ar;
long res = long.max;
foreach (i; 0 .. n) {
size_t cur = i + n;
res = min(res, tmp[cur - (n - 1)] + tmp[cur], tmp[cur + n - 1] - tmp[cur]);
}
writeln(res);
}
|
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 t = RD!int;
auto ans = new long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto a = RDA;
long m = a[0];
long x;
foreach (i; 0..n)
{
auto d = m - a[i];
if (d > 0)
{
foreach (j; 0..32)
{
auto bit = 1L << j;
if (d & bit)
{
x.chmax(j+1);
}
}
}
m.chmax(a[i]);
}
ans[ti] = x;
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
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()
{
immutable int MD = 10 ^^ 9 + 7;
auto s = readln.chomp.to!(dchar[]);
s.reverse();
debug { s.writeln; }
int[] digs;
foreach (i; 0 .. 10) { digs ~= i; }
auto dp = new int[][] (s.length + 1, 13);
dp[0][0] = 1;
int mult = 1;
foreach (i, c; s) {
int[] toCheck;
if (c == '?') {
toCheck = digs;
} else {
int e = c - '0';
toCheck ~= e;
}
foreach (d; toCheck) {
int added = (d.to!long * mult) % 13;
foreach (j; 0 .. 13) {
dp[i+1][(j + added) % 13] = (dp[i+1][(j + added) % 13] + dp[i][j]) % MD;
}
}
mult = (mult.to!long * 10) % 13;
}
debug { dp.each!writeln; }
dp[s.length][5].writeln;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int n, a;
scan(n);
scan(a);
if (n % 500 <= a) {
writeln("Yes");
}
else {
writeln("No");
}
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
struct Queue(T) {
private {
size_t cap, head, tail;
T[] data;
}
this (size_t n) in {
assert(n > 0, "The capacity of a queue must be a positive integer.");
} body {
cap = n + 1;
data = new T[](cap);
}
void clear() {
head = tail = 0;
}
bool empty() {
return head == tail;
}
bool full() {
return head == (tail + 1) % cap;
}
size_t length() {
return head <= tail ? tail - head : cap - head + tail;
}
T front() in {
assert(!empty, "The queue is empty.");
} body {
return data[head];
}
void removeFront() in {
assert(!empty, "The queue is empty.");
} body {
(++head) %= cap;
}
alias popFront = removeFront;
void insertBack(T x) in {
assert(!full, "The queue is full.");
} body {
data[tail++] = x;
tail %= cap;
}
alias insert = insertBack;
T[] array() {
return head <= tail ? data[head .. tail].dup : data[head .. $] ~ data[0 .. tail];
}
string toString() {
import std.format : format;
if (head <= tail) {
return format("[%(%s, %)]", data[head .. tail]);
}
else {
return format("[%(%s, %)", data[head .. $]) ~ format(", %(%s, %)]", data[0 .. tail]);
}
}
}
|
D
|
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }
void main(string[] args){
if(args.length > 1 && args[1] == "-debug"){
if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
else DEBUG_LEVEL = 1;
}
long a = read.to!long;
long b = read.to!long;
long c = read.to!long;
if(a == b && b == c) "Yes".writeln;
else "No".writeln;
}
|
D
|
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
T readNum(T)(){
return readStr.to!T;
}
T[] readNums(T)(){
return readStr.split.to!(T[]);
}
string readStr(){
return readln.chomp;
}
void main(){
auto s = readStr;
auto t = readStr;
if(s == t[0 .. $-1]){
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.container;
void main()
{
auto x = readln.split.map!(to!int);
auto t = x[1] - 1;
auto tp = readln.split.map!(to!int);
int i;
while (i < tp.length) {
if (i == t) break;
i += tp[i];
}
if (i == t) writeln("YES");
else writeln("NO");
}
|
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[]);
const H = tmp[0], W = tmp[1];
tmp = readln.split.to!(long[]);
const h = tmp[0], w = tmp[1];
writeln(H * W - (h * W + w * H - h * w));
}
|
D
|
unittest
{
assert( [ "abaababaab" ].parse.expand.solve == 6 );
assert( [ "xxxx" ].parse.expand.solve == 2 );
assert( [ "abcabcabcabc" ].parse.expand.solve == 6 );
assert( [ "akasakaakasakasakaakas" ].parse.expand.solve == 14 );
}
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
stdin.byLineCopy.parse.expand.solve.writeln;
}
auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
auto s = input.front.strip;
return tuple( s );
}
auto solve( string s )
{
for( auto i = ( s.length - 1 ) - ( s.length - 1 ) % 2; 2 <= i; i -= 2 )
{
auto t = s[ 0 .. i ];
if( t[ 0 .. $ / 2 ] == t[ $ / 2 .. $ ] ) return t.length;
}
assert( false );
}
|
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, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long h, w;
scan(h, w);
auto alphabets = new long[](26);
foreach (_; iota(h))
{
auto s = sread();
foreach (e; s)
alphabets[e - 'a']++;
}
long only, two, four;
foreach (e; alphabets)
{
if (e % 2)
only++;
else if (e % 4)
two++;
else
four++;
}
if (h % 2 && w % 2)
{
if (only == 1 && two <= h / 2 + w / 2)
writeln("Yes");
else
writeln("No");
}
else if (h % 2)
{
if (only == 0 && two <= w / 2)
writeln("Yes");
else
writeln("No");
}
else if (w % 2)
{
if (only == 0 && two <= h / 2)
writeln("Yes");
else
writeln("No");
}
else
{
if (only == 0 && two == 0)
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.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!ulong;
auto v = readln.split.to!(ulong[]);
ulong[] v_odd, v_even;
iota(1, n, 2).each!(x => v_even ~= v[x]);
iota(0, n, 2).each!(x => v_odd ~= v[x]);
ulong[] count_odd, count_even; count_odd.length = 10^^5+1; count_even.length = 10^^5+1;
foreach(num; v_odd) { ++count_odd[num]; }
foreach(num; v_even) { ++count_even[num]; }
ulong odd_i, even_i;
(10^^5+1).iota.each!( x => odd_i = count_odd [x] < count_odd [odd_i] ? odd_i : x ),
(10^^5+1).iota.each!( x => even_i = count_even[x] < count_even[even_i] ? even_i : x );
if (odd_i != even_i) {
writeln(v_odd.length - count_odd[odd_i] + v_even.length - count_even[even_i]);
}
else {
ulong odd_i_, even_i_;
ulong e, o;
// second most frequent
e = count_even[even_i], count_even[even_i] = 0;
(10^^5+1).iota.each!( x => even_i_ = count_even[x] < count_even[even_i_] ? even_i_ : x );
o = count_odd[odd_i], count_odd[odd_i] = 0;
(10^^5+1).iota.each!( x => odd_i_ = count_odd[x] < count_odd[odd_i_] ? odd_i_ : x );
writeln(
min(v_odd.length - o + v_even.length - count_even[even_i_],
v_odd.length - count_odd[odd_i_] + v_even.length - e
)
);
}
}
|
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;
auto w = ["Sunny", "Cloudy", "Rainy"];
foreach (i; 0..3) {
if (s == w[i]) {
w[(i+1)%3].writeln;
}
}
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
immutable long MOD = 10^^9 + 7;
long[] F, FI;
void main() {
auto N = readln.chomp.to!int;
auto G = new int[][](N);
foreach (_; 0..N-1) {
auto s = readln.split.map!(to!int);
G[s[0]-1] ~= s[1]-1;
G[s[1]-1] ~= s[0]-1;
}
F = new long[](N+1);
FI = new long[](N+1);
F[0] = FI[0] = 1;
foreach (i; 1..N+1) F[i] = F[i-1] * i % MOD;
foreach (i; 1..N+1) FI[i] = FI[i-1] * powmod(i, MOD-2, MOD) % MOD;
int c = -1;
int c2 = -1;
int[] A;
int dfs(int n, int p) {
bool center = true;
int s = 0;
int[] a;
foreach (m; G[n]) {
if (m == p) continue;
int t = dfs(m, n);
if (t > N / 2) center = false;
s += t;
a ~= t;
}
if (N - s - 1 > N / 2) {
center = false;
}
if (center && c == -1) {
c = n;
A = a.dup ~ (N - s - 1);
} else if (center) {
c2 = n;
}
return s + 1;
}
dfs(0, -1);
if (c2 != -1) {
writeln(F[N/2] * F[N/2] % MOD);
return;
}
int M = A.length.to!int;
auto dp = new long[][](M+1, N+1);
dp[0][0] = 1;
foreach (i; 0..M) {
foreach (j; 0..N) {
if (dp[i][j] == 0) continue;
foreach (k; 0..A[i]+1) {
dp[i+1][j+k] += dp[i][j] * perm(A[i], k) % MOD * comb(A[i], k) % MOD;
dp[i+1][j+k] %= MOD;
}
}
}
long ans = 0;
foreach (i; 0..N+1) {
long tmp = dp[M][i] * F[N-i] % MOD;
if (i % 2 == 1) tmp *= -1;
ans += tmp;
ans %= MOD;
}
ans = (ans + MOD) % MOD;
ans.writeln;
}
long comb(long n, long r) {
return F[n] * FI[n-r] % MOD * FI[r] % MOD;
}
long perm(long n, long r) {
return F[n] * FI[n-r] % 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
|
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 k = scan!int;
string s = scan;
if(s.length > k) print(s[0 .. k] ~ "...");
else print(s);
}
|
D
|
void main() {
problem();
}
void problem() {
auto X = scan!long;
long solve() {
foreach(t; 1..999_999) {
if (t * X % 360 == 0) return t;
}
return 0;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.numeric, 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;
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/5;
enum long MOD = 10L^^9+7;
void main() {
bool[] bs = readln.chomp.map!"a=='<'".array;
long N = bs.length + 1;
long[] as = new long[N];
long[] cs = [];
foreach(i; 0..N) {
if (i==0 && bs[i]) {
cs ~= i;
} else if (i==N-1 && !bs[i-1]) {
cs ~= i;
} else if (i>0 && i<N-1 && !bs[i-1] && bs[i]) {
cs ~= i;
}
}
foreach(c; cs) {
foreach_reverse(i; 0..c) {
if (bs[i]) break;
as[i].ch!max(c-i);
}
foreach(i; c+1..N) {
if (!bs[i-1]) break;
as[i].ch!max(i-c);
}
}
as.sum.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) {
enum sep = " ";
enum n = Args.length;
enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
static if (__VERSION__ >= 2071) {
readf!fmt(args);
} else {
enum argsTemp = n.iota.map!(
i => "&args[%d]".format(i)
).join(", ");
mixin(
"readf(fmt, " ~ argsTemp ~ ");"
);
}
}
// 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);
}
}
}
}
// 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.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 = 998244353;
//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 A = RD;
auto B = RD;
auto M = RD;
auto a = RDA;
auto b = RDA;
auto xyc = new long[][](M);
foreach (i; 0..M)
{
xyc[i] = [RD-1, RD-1, RD];
}
auto pos_a = a.MIN_POS;
auto pos_b = b.MIN_POS;
long ans = a[pos_a] + b[pos_b];
foreach (i; 0..M)
{
auto x = xyc[i][0];
auto y = xyc[i][1];
auto c = xyc[i][2];
auto t = a[x]+b[y]-c;
ans.chmin(t);
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
void main() {
string s, t, u;
uint a, b;
auto st = readln.chomp.split(" ");
s = st[0];
t = st[1];
auto ab = readln.chomp.split(" ");
a = to!uint(ab[0]);
b = to!uint(ab[1]);
u = readln.chomp;
if (u == s) {
--a;
} else if (u == t) {
--b;
}
writeln(a, " ", b);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
int[] ary = [1,5,10,50,100,500];
writeln(readln.split.to!(int[]).enumerate.map!(a => ary[a.index]*a.value).sum>=1000 ? 1: 0);
}
|
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;
auto ss = new int[](S.length+1);
foreach (i, c; S) {
ss[i+1] = ss[i];
if (c == 'A') {
ss[i+1] += 1;
} else {
ss[i+1] += 2;
}
ss[i+1] %= 3;
}
auto tt = new int[](T.length+1);
foreach (i, c; T) {
tt[i+1] = tt[i];
if (c == 'A') {
tt[i+1] += 1;
} else {
tt[i+1] += 2;
}
tt[i+1] %= 3;
}
auto Q = readln.chomp.to!int;
foreach (_q; 0..Q) {
auto abcd = readln.split.to!(int[]);
auto a = abcd[0]-1;
auto b = abcd[1];
auto c = abcd[2]-1;
auto d = abcd[3];
writeln((ss[b] - ss[a] + 3) % 3 == (tt[d] - tt[c] + 3) % 3 ? "YES" : "NO");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
void main() {
auto N = readln.chomp.to!int;
auto a = ['M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4];
auto b = new ulong[](5);
foreach(_; 0..N) {
auto c = readln.chomp[0];
if(c in a) b[a[c]]++;
}
auto A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2];
auto B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3];
auto C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4];
ulong res;
foreach(i; 0..10) {
res += b[A[i]] * b[B[i]] * b[C[i]];
}
res.writeln;
}
// M A R C H
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a,b,c,d;
scan(a, b, c, d);
if (a + b < c + d) {
writeln("Right");
}
else if (a + b > c + d) {
writeln("Left");
}
else {
writeln("Balanced");
}
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a,b;
scan(a,b);
writeln(a*b % 2 ? "Odd" : "Even");
}
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.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 o = readln.chomp;
auto e = readln.chomp;
foreach (i; 0..(o.length + e.length)) {
if (i % 2) {
write(e[i/2]);
} else {
write(o[i/2]);
}
}
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()
{
immutable MAX = 10 ^^ 5;
auto S = new long[](MAX + 2);
{
auto sieve = new bool[](MAX + 1);
sieve[] = true;
sieve[0] = sieve[1] = false;
foreach (i; 2 .. MAX + 1)
if (sieve[i])
{
foreach (j; 2 .. MAX)
if (i * j < sieve.length)
{
sieve[i * j] = false;
}
else
{
break;
}
}
auto is2017 = new bool[](MAX + 1);
foreach (i; 3 .. MAX + 1)
if (i & 1)
{
is2017[i] = sieve[i] && sieve[(i + 1) / 2];
}
// is2017.take(20).writeln();
foreach (i; 1 .. MAX + 1)
{
S[i] = S[i - 1] + is2017[i];
}
S[MAX + 1] = S[MAX];
// S.take(20).writeln();
}
long Q = lread();
foreach (_; 0 .. Q)
{
long l, r;
scan(l, r);
writeln(S[r] - S[l - 1]);
}
}
|
D
|
import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison;
long count;
void main()
{
readln();
int[] list = readln().split.to!(int[]);
mergeSort(list);
writeln(count);
}
int[] merge(int[] a, int[] b)
{
int[] res;
res.reserve(a.length+b.length);
while(a.length != 0 && b.length != 0)
{
if(a.front < b.front)
{
res ~= a.front;
a.popFront();
}else{
count+=a.length;
res ~= b.front;
b.popFront();
}
}
res ~= a ~ b;
return res;
}
int[] mergeSort(int[] list)
{
if(list.length == 0)
return list;
if(list.length == 1)
return list;
auto mid = list.length / 2;
auto a = mergeSort(list[0..mid]);
auto b = mergeSort(list[mid..$]);
return merge(a, b);
}
sizediff_t minIndex(alias pred="a<b", R) (R list)
if(isForwardRange!R && !isInfinite!R && is(typeof(binaryFun!pred(list.front, list.front))))
{
assert(!list.empty);
typeof(list.front) min = list.front;
sizediff_t minPos;
sizediff_t curPos;
for(list.popFront(); !list.empty; list.popFront())
{
curPos++;
if(binaryFun!pred(list.front, min))
{
min = list.front;
minPos = curPos;
}
}
return minPos;
}
|
D
|
void main() {
int a = readln.chomp.to!int;
int b = readln.chomp.to!int;
int c = readln.chomp.to!int;
int d = readln.chomp.to!int;
writeln(min(a, b) + min(c, d));
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;
T diff(T)(const T a, const T b) { return a > b ? a - b : b - a; }
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
T[] readToArray(T)() {
return readln.split.to!(T[]);
}
void main() {
const s = readln;
char prev = '\0';
bool nikui = false;
foreach(c; s) {
if (c == prev) {nikui = true; break;}
prev = c;
}
writeln(nikui ? "Bad" : "Good");
}
|
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; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }
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; }
long mod = pow(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; }
struct UnionFind
{
void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
bool same(long i, long j) { return root(i) == root(j); }
void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
long[] par;
}
void main()
{
auto cnt = new long[](4);
foreach (i; 0..3)
{
auto a = RD!long - 1;
auto b = RD!long - 1;
++cnt[a];
++cnt[b];
}
long cnt1, cnt2;
foreach (e; cnt)
{
if (e == 1) ++cnt1;
else if (e == 2) ++cnt2;
}
writeln(cnt1 == 2 && cnt2 == 2 ? "YES" : "NO");
stdout.flush();
}
|
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!(string, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
auto n = lread();
auto s = sread();
long cnt;
foreach (i; iota(n - 3 + 1))
{
if(s[i .. i + 3] == "ABC")
cnt++;
}
cnt.writeln();
}
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.range;
import std.string;
import std.algorithm;
import std.conv;
void main() {
ulong x = readln.chomp.to!ulong;
(x/11*2 + (x%11 <= 6 ? 1 : 2) + (x%11 == 0 ? -1 : 0)).writeln;
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.