code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
bool[] alp = new bool[](26);
string s = readln.chomp;
foreach (ch ; s) {
alp[ch - 'a'] = 1;
}
foreach (i ; 0 .. 26) {
if (!alp[i]) {
writeln(('a' + i).to!char);
return;
}
}
writeln("None");
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Train = Tuple!(long, "c", long, "s", long, "f");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
auto n = lread();
auto t = new Train[](n - 1);
foreach (i; iota(n - 1))
{
long c, s, f;
scan(c, s, f);
t[i] = Train(c, s, f);
}
foreach (i; iota(n))
{
long elapsed;
foreach (e; t[i .. $])
{
if (elapsed % e.f)
elapsed += e.f - (elapsed % e.f);
if (elapsed < e.s)
elapsed = e.s;
elapsed += e.c;
}
elapsed.writeln();
}
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on
void main()
{
long N, M;
scan(N, M);
auto ans = new bool[](N);
ans[0] = true;
auto cnt = new long[](N);
cnt[] = 1;
foreach (_; 0 .. M)
{
long x, y;
scan(x, y);
x--, y--;
ans[y] = ans[y] || ans[x];
cnt[y]++;
cnt[x]--;
if (cnt[x] == 0)
ans[x] = false;
}
ans.sum().writeln();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
int main()
{
string s = readln();
write(toUpper(s));
return 0;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.conv;
void main() {
auto N = r;
auto ip = readln.split.to!(int[]), D = ip[0], X = ip[1];
int count;
foreach(_; 0..N) {
count += ceil(D / r.to!real).to!int;
//count++;
}
(count + X).writeln;
}
int r() {
return readln.chomp.to!int;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rgb = readln.split.joiner.array.to!int;
writeln(rgb % 4 == 0 ? "YES" : "NO");
}
|
D
|
import std;
void main() {
int n, m; scan(n, m);
auto hs = readints;
int[][] adj;
foreach (_; 0..n) adj ~= [[]];
foreach (_; 0..m) {
int a, b; scan(a, b);
a--; b--;
adj[a] ~= b;
adj[b] ~= a;
}
int ans = 0;
for (int i = 0; i < hs.length; i++) {
bool ok = true;
foreach (e; adj[i]) {
if (hs[i] <= hs[e]) {
ok = false;
break;
}
}
if (ok) ans++;
}
writeln(ans);
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(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(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 long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto k = RD;
auto h = RDA;
while (k > 0)
{
bool ok;
foreach (i; 0..n-1)
{
if (h[i] < h[i+1])
{
--k;
++h[i];
ans[ti] = i+1;
ok = true;
break;
}
}
if (!ok)
{
ans[ti] = -1;
break;
}
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
class Tree
{
Tree[26] children;
long[26] counts;
char c;
this(char c) {
this.c = c;
}
void add(string s) {
assert(this.c == '\n');
auto last = s[$-1];
if (children[last - 'a'] is null) {
children[last - 'a'] = new Tree(last);
}
long[26] cs;
children[last - 'a'].add(s[0..$-1], cs);
foreach (i, c; cs) this.counts[i] += c;
}
void add(string s, ref long[26] cs) {
if (s.empty) {
++cs[this.c - 'a'];
return;
}
auto last = s[$-1];
if (children[last - 'a'] is null) {
children[last - 'a'] = new Tree(last);
}
children[last - 'a'].add(s[0..$-1], cs);
foreach (i, c; cs) this.counts[i] += c;
cs[this.c - 'a'] = 1;
}
long count(string s) {
if (s[$-1] == '\n') s = s[0..$-1];
auto c = s[$-1];
if (s.length == 1) {
return this.counts[c - 'a'] - 1;
} else {
return this.children[c - 'a'].count(s[0..$-1]);
}
}
}
void main()
{
auto N = readln.chomp.to!int;
auto tree = new Tree('\n');
string[] ss;
foreach (_; 0..N) {
auto s = readln.chomp;
tree.add(s);
ss ~= s;
}
long r;
foreach (s; ss) r += tree.count(s);
writeln(r);
}
|
D
|
import std.conv;
import std.stdio;
import std.string;
void main()
{
auto s = readln.strip;
writeln( solve( s ) );
}
auto solve( in string s )
{
auto checkA = false;
auto checkC = false;
auto checklower = true;
foreach( i, c; s )
{
if( i == 0 && c == 'A' )
{
checkA = true;
continue;
}
if( 2 <= i && i <= s.length - 2 && c == 'C' && !checkC )
{
checkC = true;
continue;
}
if( c < 'a' || 'z' < c )
{
checklower = false;
break;
}
}
if( checkA && checkC && checklower ) return "AC";
else return "WA";
}
|
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(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
long a = read.to!long;
long b = read.to!long;
long c = read.to!long;
long d = read.to!long;
long m = (c / gcd(c, d)) * d;
log("m:", m);
long bx = b - b / c - b / d + b / m;
long ax = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / m;
log("ax:", ax, "bx:", bx);
long ans = bx - ax;
ans.writeln;
}
long gcd(long a, long b){
if(a % b == 0) return b;
if(a < b) return gcd(b, a);
else return gcd(b, a % b);
}
long lcm(long a, long b){
return (a / gcd(a, b) * b);
}
|
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 n = RD!int;
auto l = RD!int;
auto r = RD!int;
long ans1;
long x = 1;
foreach (i; 0..l)
{
ans1 += x;
x *= 2;
}
ans1 += n - l;
long ans2;
long y = 1;
foreach (i; 0..r)
{
ans2 += y;
y *= 2;
}
ans2 += (y/2) * (n - r);
writeln(ans1, " ", ans2);
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }
void main() {
int x = readln.chomp.to!int;
writeln((x < 1200 ? "ABC" : "ARC"));
}
|
D
|
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }
bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
void main() {
try {
for (; ; ) {
const numCases = readInt();
foreach (caseId; 0 .. numCases) {
const S = readToken();
int sum, zero, even;
foreach (c; S) {
const d = c - '0';
sum += d;
if (d == 0) {
++zero;
}
if (d % 2 == 0) {
++even;
}
}
const ans = (sum % 3 == 0 && zero >= 1 && even >= 2);
writeln(ans ? "red" : "cyan");
}
}
} catch (EOFException e) {
}
}
|
D
|
void main(){
int[] vals = inln();
( ((vals[2]+0.5)/vals[0]).to!int()*vals[1] ).writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
// 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
int N, M;
int[][int] RS;
int[200000] IS;
void main()
{
auto nm = readln.split.to!(int[]);
N = nm[0];
M = nm[1];
foreach (_; 0..M) {
auto ab = readln.split.to!(int[]);
auto a = ab[0] - 1;
auto b = ab[1] - 1;
RS[a] ~= b;
RS[b] ~= a;
}
IS[0] = 1;
foreach (i; 0..N) {
if (IS[i] == 1 && i in RS) {
foreach (j; RS[i]) {
if (IS[j] == 0) IS[j] = i == 0 ? 1 : 2;
}
}
}
writeln( IS[N-1] == 2 ? "POSSIBLE" : "IMPOSSIBLE" );
}
|
D
|
module app;
import core.bitop;
import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
struct Input
{
int n;
int k;
int[] h;
}
void parseInput(T)(out Input input, T file)
{
with (file) with (input)
{
auto nk = readln().strip().split();
n = nk[0].to!int;
k = nk[1].to!int;
auto array = readln().strip().split();
h = array.map!(a=>a.to!int).array;
}
}
struct Output
{
}
auto main2(Input* input)
{
uint result = 0;
foreach (h; input.h)
{
if (h >= input.k)
result++;
}
return result;
}
unittest { writeln("begin unittest"); }
unittest // example1
{
string example =
`4 150
150 140 100 200`;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
writeln(result);
assert(result == 2);
}
unittest // example2
{
string example =
`1 500
499`;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
writeln(result);
assert(result == 0);
}
unittest // example3
{
string example =
`5 1
100 200 300 400 500`;
Input input = void;
parseExample(input, example);
auto result = main2(&input);
writeln(result);
assert(result == 5);
}
unittest { writeln("end unittest"); }
void parseExample(out Input input, string example)
{
struct Adapter
{
string[] _lines;
this(string input) { _lines = input.splitLines(); }
string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
}
parseInput(input, Adapter(example));
}
void main()
{
Input input = void;
parseInput(input, stdin);
auto result = main2(&input);
writeln(result);
}
|
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 N = RD;
foreach (i; 0..N)
write("a");
writeln();
void f(long n, char c)
{
foreach_reverse (i; 1..n)
{
string pre;
foreach (j; 0..i)
pre ~= c;
pre ~= cast(char)(c+1);
debug writeln("i:", i);
void g(string str, long remain, char d)
{
if (remain == 0)
{
writeln(pre ~ str);
return;
}
foreach (i; 'a'..cast(char)(d+1))
{
g(str ~ i, remain-1, cast(char)max(d, i+1));
}
}
g("", N-i-1, cast(char)(c+2));
}
}
f(N, 'a');
stdout.flush;
debug readln;
}
|
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 = lread();
auto A = aryread();
long ans = long.max;
foreach (x; -100 .. 100 + 1)
{
long cost;
foreach (a; A)
cost += (x - a) ^^ 2;
ans = ans.min(cost);
}
writeln(ans);
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm;
void main(){
auto s = readln.strip;
long a = 0;
long b = 0;
foreach (i, c; s) {
if ((i % 2 == 0) == (c == '1')) {
a++;
} else {
b++;
}
}
writeln(min(a, b));
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
string s = chomp(readln());
int n = to!int(s.length);
int K;
scanf("%d", &K);
string[] S;
foreach (len; 1..K+1) {
foreach (i; 0..n-len+1) {
S ~= s[i..i+len];
}
}
writeln(S.sort.uniq.array[K-1]);
}
|
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;
bool[long] set;
foreach (i; 0..N)
{
auto d = RD;
set[d] = true;
}
writeln(set.keys.length);
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm, std.array, std.container, std.range;
import std.numeric, std.math, std.bigint, std.random;
import std.string, std.uni, std.regex, std.conv;
import std.bitmanip, core.bitop;
import std.stdio, std.typecons;
void main()
{
auto w = readln.chomp;
auto r = 0;
for (;;) {
auto t = readln.chomp;
if (t == "END_OF_TEXT") break;
auto ti = t.split;
r += ti.count!(a => icmp(a, w) == 0);
}
writeln(r);
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!long;
foreach (h; 1L..3501L)
foreach (m; h..3501L) {
auto a = 4*h*m-n*(h+m);
auto b = n*h*m;
if (a > 0 && b % a == 0) {
writeln(h, " ", m, " ", b/a);
return;
}
}
}
|
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 n = readln.chomp.to!int;
auto s = readln.chomp;
int m;
foreach (i; 1..n-1) {
auto a = s[0..i];
auto b = s[i..$];
int[int] cnt1;
int[int] cnt2;
foreach (e; a) {
cnt1[e]++;
}
foreach (e; b) {
cnt2[e]++;
}
int lm;
foreach (k; cnt1.keys) {
if (cnt2.get(k, 0)) {
lm++;
}
}
m = max(m, lm);
}
m.writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto x = readln.chomp.split.to!(int[]);
writeln(x[0]-1+(x[0]<=x[1]));
}
|
D
|
void main(){
auto ABCK = readLine!long();
auto A = ABCK[0];
auto B = ABCK[1];
auto C = ABCK[2];
auto K = ABCK[3];
if( K <= A ){
K.writeln();
} else if( K <= A+B ) {
A.writeln();
} else {
(A - (K-(A+B))).writeln();
}
return;
}
import std;
string readStr(){
return readln().chomp();
}
T[] readLine( T = long )(){
return readln().split().to!(T[])();
}
|
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(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 long[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto x = RD!int;
auto a = RDA;
ans[ti] = a.sum;
(){
foreach (cnt; 1..10^^5)
{
foreach (i; 0..n)
{
if (a[i] % x) return;
auto y = a[i] / x;
ans[ti] += y * x^^cnt;
a[i] = y;
}
}}();
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
void main() {
auto l = readln.chomp.split.map!(to!int).array;
int n = l[0], c = l[1];
long[][] cc = new long[][](31, 200010);
long[] imos = new long[](200010);
for (int i = 0; i < n; ++i) {
auto m = readln.chomp.split.map!(to!int).array;
cc[m[2] - 1][2 * m[0] - 1] += 1;
cc[m[2] - 1][2 * m[1]] -= 1;
}
for (int i = 0; i < c; ++i) {
for (int j = 1; j <= 200000; ++j) {
cc[i][j] += cc[i][j - 1];
if (cc[i][j - 1] == 0 && cc[i][j] > 0) {
imos[j] += 1;
}
else if (cc[i][j] == 0 && cc[i][j - 1] > 0) {
imos[j] -= 1;
}
}
}
long ans;
for (int i = 1; i <= 200000; ++i) {
imos[i] += imos[i - 1];
if (ans < imos[i]) ans = imos[i];
}
ans.writeln;
}
|
D
|
void main(){
string input;
input = readln().chomp().dup;
string ans;
foreach(elm; input){
if(elm == 'B'){
if( ans.length==0 )continue;
ans.popBack();
}else{
ans ~= elm;
}
}
writeln(ans.length==2? ans[$-2..$]: ans[0..$] );
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
// 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, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
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); }
void main() {
auto size = readln.chomp.to!int;
auto words = readln.split.to!(string[]);
void solve() {
string result;
foreach(i; 0..size) {
result ~= words[0][i];
result ~= words[1][i];
}
result.writeln;
}
solve();
}
|
D
|
void main()
{
long n, q;
rdVals(n, q);
auto st = SegTree!("a + b", long, 0)(n);
foreach (i; 0 .. q)
{
long com, x, y;
rdVals(com, x, y);
--x;
if (com) st.query(x, y).writeln;
else st.update(x, st[x]+y);
}
}
struct SegTree(alias pred, T, T init)
{
import core.bitop;
alias F = binaryFun!pred;
long n;
T[] tree;
this(long n)
{
this.n = n == 1 ? 1 : 1L << bsr(n-1) + 2;
tree.length = this.n << 1;
tree[] = init;
}
ref T opIndex(long idx) pure nothrow
{
return tree[idx+this.n];
}
void update(long idx, T x)
{
idx += this.n;
this.tree[idx] = x;
while (idx >>= 1)
{
tree[idx] = F(tree[(idx<<1)], tree[(idx<<1)+1]);
}
}
T query(long x, long y)
{
T l = init, r = init;
for (x += this.n, y += this.n; x < y; x >>= 1, y >>= 1)
{
if (x & 1) l = F(l, tree[x++]);
if (y & 1) r = F(tree[--y], r);
}
return F(l, r);
}
}
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
|
void main()
{
long n = rdElem;
long[] h = rdRow;
long[] dp = new long[n];
dp[1] = abs(h[0] - h[1]);
foreach (i; 2 .. n)
{
dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
}
dp[n-1].writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
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, std.algorithm;
void main()
{
while(true)
{
auto input=readln.split.map!(to!int);
if(input[0]==0&&input[1]==0) break;
int m=input[1]-input[0];
int th, fiv, han;
for(; m>=1000; ++th) m-=1000;
for(; m>=500; ++fiv) m-=500;
for(; m>=100; ++han) m-=100;
writeln(han, " ", fiv, " ", th);
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void main()
{
auto N = readln.chomp.to!int;
auto a = readln.split.to!(int[]);
int count;
foreach(i; a)
{
while(i % 2 == 0)
{
i /= 2;
count++;
}
}
writeln(count);
}
//writeln("滲み出す混濁の紋章 不遜なる狂気の器 湧き上がり 否定し 痺れ 瞬き 眠りを妨げる 爬行する鉄の王女 絶えず自壊する泥の人形 結合せよ 反発せよ 地に満ち己の無力を知れ 破道の九十 黒棺")
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math : abs;
void main()
{
auto N = to!int(split(readln())[0]);
int[] A = [0];
A ~= to!(int[])(split(readln()));
int X = 0;
foreach (i; 0..N) {
X += abs(A[i] - A[i+1]);
}
X += abs ( A[$-1] - A[0] );
foreach ( i; 1..N ) {
writeln(X - abs(A[i] - A[i-1]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]));
}
writeln(X - abs(A[N] - A[N-1]) - abs(A[N] - A[0]) + abs(A[N-1] - A[0]));
}
|
D
|
import std.stdio,std.string,std.conv;
int main()
{
string s;
while((s = readln.chomp).length != 0)
{
string[] _s = s.split(",");
int n = _s[0].to!int;
double w = _s[1].to!double;
double h = _s[2].to!double;
if(25.0 <= w/(h*h))
{
n.writeln;
}
}
return 0;
}
|
D
|
/* imports all std modules {{{*/
import
std.algorithm,
std.array,
std.ascii,
std.base64,
std.bigint,
std.bitmanip,
std.compiler,
std.complex,
std.concurrency,
std.container,
std.conv,
std.csv,
std.datetime,
std.demangle,
std.encoding,
std.exception,
std.file,
std.format,
std.functional,
std.getopt,
std.json,
std.math,
std.mathspecial,
std.meta,
std.mmfile,
std.net.curl,
std.net.isemail,
std.numeric,
std.parallelism,
std.path,
std.process,
std.random,
std.range,
std.regex,
std.signals,
std.socket,
std.stdint,
std.stdio,
std.string,
std.system,
std.traits,
std.typecons,
std.uni,
std.uri,
std.utf,
std.uuid,
std.variant,
std.zip,
std.zlib;
/*}}}*/
/+---test
3
1 3 2
3 1 2
---+/
/+---test
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
---+/
/+---test
3
1 2 3
1 2 3
---+/
void main(string[] args) {
const N = readln.chomp.to!long;
const A = readln.split.map!(to!long).array;
const B = readln.split.map!(to!long).array;
long a, b, i;
auto arr = iota(1, N+1).array;
do {
if (arr.equal(A)) a = i;
if (arr.equal(B)) b = i;
++i;
} while (arr.nextPermutation);
(a-b).abs.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.numeric;
void main()
{
auto n = readln.chomp.to!int;
int[string] cnt;
int m;
foreach (_; 0..n) {
auto s = readln.chomp;
cnt[s]++;
m = max(cnt[s], m);
}
auto keys = cnt.keys;
sort(keys);
foreach (k; keys) {
if (cnt[k] == m) {
writeln(k);
}
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
const ma = 10 ^^ 5;
void main()
{
auto n = readln.chomp.to!size_t;
auto a = readln.split.to!(int[]);
auto b = new int[](ma);
foreach (ai; a) {
if (ai > 0) ++b[ai-1];
++b[ai];
if (ai < ma-1) ++b[ai+1];
}
writeln(b.reduce!max);
}
|
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, K;
scan(N, K);
long ans;
foreach (k; K .. N + 2)
{
long m = k * (k - 1) / 2;
long M = N * (N + 1) / 2 - (N - k + 1) * (N - k) / 2;
ans += max(M - m + 1, 0);
ans %= 1000000007;
}
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[]);
writeln(ip[0] + ip[1]/2);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto s = readln.chomp;
auto r = ['R', 'U', 'D'];
auto l = ['L', 'U', 'D'];
bool f;
foreach (i; 0..s.length) {
if (i % 2 && l.find(s[i]).empty) {
f = true;
} else if (i % 2 == 0 && r.find(s[i]).empty) {
f = true;
}
}
if (f) {
writeln("No");
} else {
writeln("Yes");
}
}
|
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 nab = readints;
int n = nab[0], a = nab[1], b = nab[2];
writeln(min(n * a, b));
}
|
D
|
import std.stdio : writeln;
void main() {
int n,a,b;
scan(n,a,b);
long ans;
foreach (i ; 1 .. n + 1) {
int d = digitSum(i);
if (a <= d && d <= b) {
ans += i;
}
}
writeln(ans);
}
int digitSum(int x) {
return x > 0 ? digitSum(x / 10) + x % 10 : 0;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.array : split;
import std.conv : to;
import std.range.primitives;
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, std.regex, std.range, std.ascii, std.algorithm;
void main(){
auto S = readln.chomp;
auto F = S[0..2].to!int;
auto R = S[2..$].to!int;
if((1<=F&&F<=12) && (1<=R&&R<=12)) writeln("AMBIGUOUS");
else if(1<=F&&F<=12) writeln("MMYY");
else if(1<=R&&R<=12) writeln("YYMM");
else writeln("NA");
}
|
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];
const s = H.iota.map!(_ => readln.chomp).array;
foreach (y; 0..H) {
foreach (x; 0..W) {
if (s[y][x] == '.') continue;
long[2][] n;
if (0 < x) n ~= [x-1,y];
if (0 < y) n ~= [x,y-1];
if (x < W-1) n ~= [x+1,y];
if (y < H-1) n ~= [x,y+1];
if (n.all!(p => s[p[1]][p[0]] == '.')) {
writeln("No");
return;
}
}
}
writeln("Yes");
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm.searching, std.algorithm.iteration;
void main()
{
auto N = readln().strip.to!int;
int[] pList = [];
foreach(i; 0..N)
{
pList ~= readln().strip.to!int;
}
writeln(pList.sum - pList.reduce!"a<b?b:a" / 2);
}
|
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()
{
long n, m; readV(n, m);
if (n > m) swap(n, m);
if (n == 1) {
if (m == 1)
writeln(1);
else
writeln(m-2);
} else {
writeln((n-2)*(m-2));
}
}
|
D
|
import std.stdio, std.string, std.array, std.conv;
void main() {
int[] tmp = readln.chomp.split.to!(int[]);
int w = tmp[0], h = tmp[1], x = tmp[2], y = tmp[3], r = tmp[4];
writeln(0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h ? "Yes" : "No");
}
|
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(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 int[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto a = RDA!int(-1);
auto cnt = new int[](n);
foreach (e; a)
++cnt[e];
ans[ti] = cnt.maxElement;
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
void main()
{
string s = readln.chomp;
string t = readln.chomp;
long[][] alpha = new long[][](26);
foreach (i, x; s)
{
alpha[x-'a'] ~= i + 1;
}
long n = s.length.to!long;
long cnt;
long index;
foreach (x; t)
{
auto a = alpha[x-'a'].assumeSorted;
if (a.empty)
{
cnt = -1;
break;
}
auto l = a.upperBound(index);
if (l.empty)
{
++cnt;
index = a[0];
}
else
{
index = l[0];
}
}
writeln(cnt != -1 ? cnt * n + index: cnt);
}
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;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int a, b, c, d, e;
scan(a);scan(b);scan(c);scan(d);scan(e);
int x = 10;
if (a % 10) x = min(x, a % 10);
if (b % 10) x = min(x, b % 10);
if (c % 10) x = min(x, c % 10);
if (d % 10) x = min(x, d % 10);
if (e % 10) x = min(x, e % 10);
int ans = (a + 9) / 10 * 10
+ (b + 9) / 10 * 10
+ (c + 9) / 10 * 10
+ (d + 9) / 10 * 10
+ (e + 9) / 10 * 10
- 10 + x;
writeln(ans);
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
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.array, std.conv, std.typecons, std.algorithm;
long impl(long n, long w, const ref long[] ws, const ref long[] vs, ref long[][] dp) {
if(dp[n][w] == -1) {
const auto prev_w = w-ws[n-1];
const auto yes = prev_w >= 0 ? impl(n-1, prev_w, ws, vs, dp) + vs[n-1] : -1;
const auto no = impl(n-1, w, ws, vs, dp);
dp[n][w] = max(yes, no, dp[n][w]);
}
return dp[n][w];
}
long solve(long n, long w, const ref long[] ws, const ref long[] vs) {
auto dp = new long[][](n+1, w+1);
foreach(ref v ; dp[]) { v[] = -1;}
dp[0][] = 0;
return impl(n, w, ws, vs, dp);
}
void main() {
immutable i1 = readln.split.to!(long[]);
immutable n = i1[0], w = i1[1];
auto ws = new long[n];
auto vs = new long[n];
for(auto i = 0; i < n; i++) {
auto input = readln.split.to!(long[]);
ws[i] = input[0];
vs[i] = input[1];
}
writeln(solve(n, w, ws, vs));
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
void main()
{
auto n=map!(to!int)(readln.strip.split);
int cnt = 0;
for(int i = n[0];i<=n[1];i++)
if(n[2] % i == 0)
cnt++;
writeln(cnt);
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.7.4"
+/
import std.stdio, std.algorithm, std.range, std.conv, std.math;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.geo.primitive, dcomp.geo.circle, dcomp.geo.polygon;
bool solve() {
alias P = Point2D!double;
alias L = Line2D!double;
alias C = Circre2D!double;
P[] pol = new P[3];
foreach (i; 0..3) {
double x, y;
if (sc.read(x, y) != 2) return false;
pol[i] = P(x, y);
}
C c;
double x, y, r;
sc.read(x, y, r);
c = C(P(x, y), r);
double ma = -1e9, mi = 1e9;
foreach (i; 0..3) {
ma = max(ma, (pol[i]-c.p).abs);
mi = min(mi, distSP(L(pol.at(i), pol.at(i+1)), c.p));
}
if (sgn(ma, c.r) != -1) {
writeln("b");
return true;
}
if (contains(pol, c.p) != 0 && sgn(c.r, mi) != -1) {
writeln("a");
return true;
}
if (sgn(mi, c.r) != -1) {
writeln("c");
return true;
}
writeln("d");
return true;
}
int main() {
EPS!double = 1e-10;
while (solve()) {}
return 0;
}
Scanner sc;
static this() {
sc = new Scanner(stdin);
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;
T[N] fixed(T, size_t N)(T[N] a) {return a;}
struct FastAppender(A, size_t MIN = 4) {
import std.algorithm : max;
import std.conv;
import std.range.primitives : ElementEncodingType;
import core.stdc.string : memcpy;
private alias T = ElementEncodingType!A;
private T* _data;
private uint len, cap;
@property size_t length() const {return len;}
bool empty() const { return len == 0; }
void reserve(size_t nlen) {
import core.memory : GC;
if (nlen <= cap) return;
void* nx = GC.malloc(nlen * T.sizeof);
cap = nlen.to!uint;
if (len) memcpy(nx, _data, len * T.sizeof);
_data = cast(T*)(nx);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void opOpAssign(string op : "~")(T item) {
if (len == cap) {
reserve(max(MIN, cap*2));
}
_data[len++] = item;
}
void insertBack(T item) {
this ~= item;
}
void removeBack() {
len--;
}
void clear() {
len = 0;
}
ref inout(T) back() inout { assert(len); return _data[len-1]; }
ref inout(T) opIndex(size_t i) inout { return _data[i]; }
T[] data() {
return (_data) ? _data[0..len] : null;
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/geo/polygon.d */
// module dcomp.geo.polygon;
// import dcomp.geo.primitive;
inout(Point2D!R) at(R)(inout Point2D!R[] pol, size_t i) {
return pol[i<pol.length?i:i-pol.length];
}
int contains(R)(Point2D!R[] pol, Point2D!R p) {
import std.algorithm : swap;
int res = -1;
foreach (i; 0..pol.length) {
auto a = pol.at(i) - p, b = pol.at(i+1) - p;
if (ccw(a, b, Point2D!R(0, 0)) == 0) return 1;
if (a.y > b.y) swap(a, b);
if (a.y <= 0 && 0 < b.y) {
if (cross(a, b) < 0) res *= -1;
}
}
return res+1;
}
R area2(R)(Point2D!R[] pol) {
R u = 0;
foreach (i; 0..pol.length) {
auto a = pol.at(i), b = pol.at(i+1);
u += cross(a, b);
}
return u;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
// import dcomp.array;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
bool f = succW();
assert(f);
x[i] = line.parse!E;
}
} else {
FastAppender!(E[]) buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
import core.bitop : popcnt;
static if (!__traits(compiles, popcnt(ulong.max))) {
public import core.bitop : popcnt;
int popcnt(ulong v) {
return popcnt(cast(uint)(v)) + popcnt(cast(uint)(v>>32));
}
}
bool poppar(ulong v) {
v^=v>>1;
v^=v>>2;
v&=0x1111111111111111UL;
v*=0x1111111111111111UL;
return ((v>>60) & 1) != 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/geo/circle.d */
// module dcomp.geo.circle;
// import dcomp.geo.primitive;
struct Circre2D(R) {
Point2D!R p;
R r;
this(Point2D!R p, R r) {
this.p = p;
this.r = r;
}
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/geo/primitive.d */
// module dcomp.geo.primitive;
import std.traits;
template EPS(R) {
R EPS;
}
int sgn(R)(R a) {
static if (isFloatingPoint!R) {
import std.math : isNaN;
assert(!isNaN(EPS!R));
}
if (a < -EPS!R) return -1;
if (a > EPS!R) return 1;
return 0;
}
int sgn(R)(R a, R b) {
return sgn(b-a);
}
struct Point2D(T) {
T[2] d;
this(T x, T y) {this.d = [x, y];}
this(T[2] d) {this.d = d;}
@property ref inout(T) x() inout {return d[0];}
@property ref inout(T) y() inout {return d[1];}
ref inout(T) opIndex(size_t i) inout {return d[i];}
auto opOpAssign(string op)(in Point2D r) {
return mixin("this=this"~op~"r");
}
auto opBinary(string op:"+")(in Point2D r) const {return Point2D(x+r.x, y+r.y);}
auto opBinary(string op:"-")(in Point2D r) const {return Point2D(x-r.x, y-r.y);}
static if (isFloatingPoint!T) {
T abs() {
import std.math : sqrt;
return (x*x+y*y).sqrt;
}
T arg() {
import std.math : atan2;
return atan2(y, x);
}
Point2D rot(T ar) {
import std.math : cos, sin;
auto cosAr = cos(ar), sinAr = sin(ar);
return Point2D(x*cosAr - y*sinAr, x*sinAr + y*cosAr);
}
}
}
bool near(T)(Point2D!T a, Point2D!T b) if (isIntegral!T) {
return a == b;
}
bool near(T)(Point2D!T a, Point2D!T b) if (isFloatingPoint!T) {
return !sgn((a-b).abs);
}
T dot(T)(in Point2D!T l, in Point2D!T r) {
return l[0]*r[0] + l[1]*r[1];
}
T cross(T)(in Point2D!T l, in Point2D!T r) {
return l[0]*r[1] - l[1]*r[0];
}
int ccw(R)(Point2D!R a, Point2D!R b, Point2D!R c) {
import std.stdio;
assert(!near(a, b));
if (near(a, c) || near(b, c)) return 0;
int s = sgn(cross(b-a, c-a));
if (s) return s;
if (dot(b-a, c-a) < 0) return 2;
if (dot(a-b, c-b) < 0) return -2;
return 0;
}
struct Line2D(R) {
Point2D!R x, y;
this(Point2D!R x, Point2D!R y) {
this.x = x;
this.y = y;
}
Point2D!R vec() const { return y-x; }
}
R distLP(R)(Line2D!R l, Point2D!R p) if (isFloatingPoint!R) {
import std.math : abs;
return abs(cross(l.vec, p-l.x) / l.vec.abs);
}
R distSP(R)(Line2D!R s, Point2D!R p) if (isFloatingPoint!R) {
import std.algorithm : min;
auto s2 = Point2D!R(-s.vec.y, s.vec.x);
if (ccw(s.x, s.x+s2, p) == 1) return (s.x-p).abs;
if (ccw(s.y, s.y+s2, p) == -1) return (s.y-p).abs;
return min((s.x-p).abs, (s.y-p).abs, distLP(s, p));
}
int argcmp(T)(Point2D!T l, Point2D!T r) if (isIntegral!T) {
int sgn(Point2D!T p) {
if (p[1] < 0) return -1;
if (p[1] > 0) return 1;
if (p[0] < 0) return 2;
return 0;
}
int lsgn = sgn(l);
int rsgn = sgn(r);
if (lsgn < rsgn) return -1;
if (lsgn > rsgn) return 1;
T x = cross(l, r);
if (x > 0) return -1;
if (x < 0) return 1;
return 0;
}
/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm, std.range, std.typecons, std.numeric, std.math;
void main() {
long n = readln.strip.to!long;
auto ps = readln.strip.split(" ").to!(long[]).array;
long cnt = 0;
foreach (i; 0..n) {
if (ps[i] != i+1) {
cnt++;
}
}
if (cnt <= 2) {
writeln("YES");
} else {
writeln("NO");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm.searching;
void main(){
auto str = readln.chomp;
if(str[2] == str[3] && str[4] == str[5])
{
"Yes".writeln;
}
else
{
"No".writeln;
}
}
|
D
|
import std.stdio,
std.string,
std.conv,
std.algorithm;
void main() {
long[] buf = readln.chomp.split.to!(long[]);
long N = buf[0], K = buf[1];
if (K == 0) {
writeln(N * N);
return;
}
long ans;
for (int i = 1; i <= N; i++) {
ans += max(0, (i - K) * (N / i));
ans += max(0, (N % i) + (1 - K));
}
writeln(ans);
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const as = readln.split.to!(long[]);
writeln(as.reduce!max - as.reduce!min);
}
|
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 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;
}
long count(int x) {
return ((powmod(10, x, MOD) - powmod(10, x-1, MOD)) % MOD + MOD) % MOD;
}
void main() {
auto S = readln.chomp.to!int;
long ans = 0;
// f(l) <= 7
{
auto A = new int[](10^^7*5);
for (int k = 1; k <= 8; ++k) {
for (int i = 10^^(k-1); i < 10^^k && i < 10^^7*5; ++i) {
A[i] = k;
}
}
for (int l = 1, r = 1, cnt = 0; l < 10^^7; cnt -= A[l], l += 1) {
if (r < l) r = l, cnt = 0;
while (cnt < S) cnt += A[r], r += 1;
if (cnt == S) (ans += 1) %= MOD;
}
}
// f(l) >= 8
{
int[] factors;
int T = S / 8;
for (int i = 1; i * i <= S; ++i) {
if (S % i != 0) continue;
if (i * i != S) factors ~= S / i;
factors ~= i;
}
foreach (f; factors) {
if (S / f < 8) continue;
(ans += count(S / f) - f) %= MOD;
ans = (ans + MOD) % MOD;
}
(ans += T) %= MOD;
}
ans.writeln;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
void main()
{
int t=0;
foreach(s;stdin.byLine())
{
int n=0;
foreach(c;s)
if('0'<=c && c<='9') n=n*10+c-'0';
else t+=n,n=0;
t+=n;
}
writeln(t);
}
|
D
|
void main()
{
string s = readln.chomp;
writeln(s.countUntil("YAKI") == 0 ? "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.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.math;
import std.regex;
import std.range;
void main() {
auto X = readln.chomp.to!int, A = readln.chomp.to!int, B = readln.chomp.to!int;
auto tmp = X - A;
(tmp % B).writeln;
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int n = readint;
int k = readint;
int x = readint;
int y = readint;
int ans = min(n, k) * x + max(0, n - k) * y;
writeln(ans);
}
|
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;
auto A = RD;
writeln(N * N - A);
stdout.flush();
debug readln();
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]);
auto a = rd[0], b = rd[1], c = rd[2], d = rd[3], e = rd[4], f = rd[5];
auto ansW = 0, ansS = 0, ansK = real(0);
foreach (i; 0..f/a+1)
foreach (j; 0..f/b+1) {
auto w = i*a + j*b;
if (w*100 > f) continue;
auto s = w*e;
foreach (k; 0..s/c+1)
foreach (l; 0..s/d+1) {
auto t = k*c + l*d;
if (t > s || t+w*100 > f) continue;
auto m = t.to!real / (t+w*100);
if (m >= ansK) {
ansW = w;
ansS = t;
ansK = m;
}
}
}
writeln(ansW*100+ansS, " ", ansS);
}
|
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; }
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 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 main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (ti; 0..t)
{
auto A = RD;
auto B = RD;
auto x = B;
long digit;
while (x != 0)
{
x /= 10;
++digit;
}
debug writeln(B, ":", 10^^(digit)-1);
if (B == 10^^(digit)-1)
{
ans[ti] = A * digit;
}
else
{
ans[ti] = A * (digit-1);
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.conv;
import std.stdio;
import std.string;
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()
{
ulong A, B;
scan(A, B);
writeln(f(A - 1) ^ f(B));
}
ulong f(ulong x)
{
auto mod = x % 4;
switch (mod)
{
case 0:
return x;
case 1:
return 1;
case 2:
return x ^ 1;
case 3:
return 0;
default:
assert(0);
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm;
void main() {
int n = readln.chomp.to!int;
int[] a = new int[n];
int[] b = readln.chomp.split.to!(int[]);
a[0] = b[0], a[1] = b[0];
foreach (i; 1 .. n-1) {
a[i] = min(a[i], b[i]);
a[i+1] = b[i];
}
a.sum.writeln;
}
|
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;
}
int calc(int k, int[] ws) {
bool match(int limit) {
int n = 0;
int sum = 0;
foreach (w; ws) {
if (sum + w <= limit) {
sum += w;
}
else {
sum = w;
n++;
if (n > k)
return false;
}
}
return n + 1 <= k;
}
int lo = ws.reduce!max;
int hi = 1_000_000_000;
int ans = hi;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (match(m)) {
ans = min(ans, m);
hi = m - 1;
}
else {
lo = m + 1;
}
}
return ans;
}
void main() {
auto nk = readints();
int n = nk[0], k = nk[1];
int[] ws;
for (int i = 0; i < n; i++) {
ws ~= readint();
}
writeln(calc(k, ws));
}
|
D
|
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;
enum long INF = long.max/3;
enum long MOD = 10L^^9+7;
void main() {
long N, K;
scanln(N, K);
long[] as = readln.split.to!(long[]);
long T = 45;
long[][] bss = new long[][](T, 2);
foreach(i; 0..T) {
foreach(a; as) {
foreach(j; 0..2) {
bss[i][j] += ((a&(1L<<i))^((cast(long)j)<<i));
}
}
}
long ans = 0;
long k = 0;
foreach_reverse(i; 0..T) {
long x = k | (1L<<i);
if (x > K || bss[i][0] >= bss[i][1]) {
ans += bss[i][0];
} else {
ans += bss[i][1];
k = x;
}
}
ans.writeln;
}
// ----------------------------------------------
void times(alias fun)(long n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
// `(x+y-1)/y` will only work for positive numbers ...
T t = x / y;
if (t * y < x) t++;
return t;
}
T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
T t = x / y;
if (t * y > x) t--;
return t;
}
ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
return lhs = fun(lhs, rhs);
}
unittest {
long x = 1000;
x.ch!min(2000);
assert(x == 1000);
x.ch!min(3, 2, 1);
assert(x == 1);
x.ch!max(100).ch!min(1000); // clamp
assert(x == 100);
x.ch!max(0).ch!min(10); // clamp
assert(x == 10);
}
mixin template Constructor() {
import std.traits : FieldNameTuple;
this(Args...)(Args args) {
// static foreach(i, v; args) {
foreach(i, v; args) {
mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
}
}
}
void scanln(Args...)(auto ref Args args) {
import std.meta;
template getFormat(T) {
static if (isIntegral!T) {
enum getFormat = "%d";
} else static if (isFloatingPoint!T) {
enum getFormat = "%g";
} else static if (isSomeString!T || isSomeChar!T) {
enum getFormat = "%s";
} else {
static assert(false);
}
}
enum string fmt = [staticMap!(getFormat, Args)].join(" ");
string[] inputs = readln.chomp.split;
foreach(i, ref v; args) {
v = inputs[i].to!(Args[i]);
}
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
private template RebindableOrUnqual(T)
{
static if (is(T == class) || is(T == interface) || isDynamicArray!T || isAssociativeArray!T)
alias RebindableOrUnqual = Rebindable!T;
else
alias RebindableOrUnqual = Unqual!T;
}
private auto extremum(alias map, alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
in
{
assert(!r.empty, "r is an empty range");
}
body
{
alias Element = ElementType!Range;
RebindableOrUnqual!Element seed = r.front;
r.popFront();
return extremum!(map, selector)(r, seed);
}
private auto extremum(alias map, alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
is(typeof(unaryFun!map(ElementType!(Range).init))))
{
alias mapFun = unaryFun!map;
alias selectorFun = binaryFun!selector;
alias Element = ElementType!Range;
alias CommonElement = CommonType!(Element, RangeElementType);
RebindableOrUnqual!CommonElement extremeElement = seedElement;
// if we only have one statement in the loop, it can be optimized a lot better
static if (__traits(isSame, map, a => a))
{
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
if (selectorFun(r[i], extremeElement))
{
extremeElement = r[i];
}
}
}
else
{
while (!r.empty)
{
if (selectorFun(r.front, extremeElement))
{
extremeElement = r.front;
}
r.popFront();
}
}
}
else
{
alias MapType = Unqual!(typeof(mapFun(CommonElement.init)));
MapType extremeElementMapped = mapFun(extremeElement);
// direct access via a random access range is faster
static if (isRandomAccessRange!Range)
{
foreach (const i; 0 .. r.length)
{
MapType mapElement = mapFun(r[i]);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r[i];
extremeElementMapped = mapElement;
}
}
}
else
{
while (!r.empty)
{
MapType mapElement = mapFun(r.front);
if (selectorFun(mapElement, extremeElementMapped))
{
extremeElement = r.front;
extremeElementMapped = mapElement;
}
r.popFront();
}
}
}
return extremeElement;
}
private auto extremum(alias selector = "a < b", Range)(Range r)
if (isInputRange!Range && !isInfinite!Range &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r);
}
// if we only have one statement in the loop it can be optimized a lot better
private auto extremum(alias selector = "a < b", Range,
RangeElementType = ElementType!Range)
(Range r, RangeElementType seedElement)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
!is(typeof(unaryFun!selector(ElementType!(Range).init))))
{
return extremum!(a => a, selector)(r, seedElement);
}
auto minElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!map(r);
}
auto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!map(r, seed);
}
auto maxElement(alias map = (a => a), Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
return extremum!(map, "a > b")(r);
}
auto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)
(Range r, RangeElementType seed)
if (isInputRange!Range && !isInfinite!Range &&
!is(CommonType!(ElementType!Range, RangeElementType) == void))
{
return extremum!(map, "a > b")(r, seed);
}
}
// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
ulong popcnt(ulong x) {
x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
return x;
}
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
void main() {
auto n = readln.chomp.to!int;
auto p = readln.chomp.split.to!(int[]);
int count=0, minimum=n+1;
for(int i=0; i<n; i++) {
if(p[i]<=minimum) {
count++;
minimum = min(minimum, p[i]);
}
}
writeln(count);
}
|
D
|
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }
bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
void main() {
try {
for (; ; ) {
const A = readInt();
int a = A;
for (int p = 2; p <= a; ++p) {
for (; a % p == 0; ) {
write(p);
a /= p;
}
}
writeln();
}
} catch (EOFException e) {
}
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.typecons;
import std.variant;
size_t[] solve(string a, string b) {
size_t[] result;
foreach (i; 0 .. a.length) {
if (a[i] != b[i]) {
result.assumeSafeAppend ~= i + 1;
result.assumeSafeAppend ~= 1;
result.assumeSafeAppend ~= i + 1;
}
}
return result;
}
void main() {
long tt = readln().chomp.to!long;
foreach (t; 0 .. tt) {
readln();
string a = readln().chomp;
string b = readln().chomp;
if (a == b) {
writeln("0");
}
else {
auto arr = solve(a, b);
writeln(arr.length, " ", arr.map!(to!string).join(" "));
}
}
}
// 00A00B 00C00D
// b11a11 00C00D
// 0A00B1 00C00D
|
D
|
import std.algorithm;
import std.range;
import std.stdio;
import std.string;
immutable string str = "Bulbasaur";
void main ()
{
string s;
while ((s = readln.strip) != "")
{
int [256] num;
foreach (char c; s)
{
num[c] += 1;
}
int res = int.max;
foreach (char c; str)
{
int d = cast (int) (str.count (c));
res = min (res, num[c] / d);
}
writeln (res);
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
void get(Args...)(ref Args args)
{
import std.traits, std.meta, std.typecons;
static if (Args.length == 1) {
alias Arg = Args[0];
static if (isArray!Arg) {
args[0] = readln.split.to!Arg;
} else static if (isTuple!Arg) {
auto input = readln.split;
static foreach (i; 0..Fields!Arg.length) {
args[0][i] = input[i].to!(Fields!Arg[i]);
}
} else {
args[0] = readln.chomp.to!Arg;
}
} else {
auto input = readln.split;
assert(input.length == Args.length);
static foreach (i; 0..Args.length) {
args[i] = input[i].to!(Args[i]);
}
}
}
void get_lines(Args...)(size_t N, ref Args args)
{
import std.traits, std.range;
static foreach (i; 0..Args.length) {
static assert(isArray!(Args[i]));
args[i].length = N;
}
foreach (i; 0..N) {
static if (Args.length == 1) {
get(args[0][i]);
} else {
auto input = readln.split;
static foreach (j; 0..Args.length) {
args[j][i] = input[j].to!(ElementType!(Args[j]));
}
}
}
}
void solve()
{
int N, Q; get(N, Q);
long[] AS; get(AS);
int p;
foreach (i, a; AS) if (a == N) {
p = i.to!int;
break;
}
long sum_a = N;
long min_a, max_a;
void update(long a) {
if (min_a == -1) {
if (a < max_a) {
sum_a += max_a;
max_a = -1;
min_a = a;
} else {
max_a = a;
}
} else {
if (a > min_a) {
sum_a -= min_a;
min_a = -1;
max_a = a;
} else {
min_a = a;
}
}
}
if (p < N-1) {
max_a = -1; min_a = AS[p+1];
foreach (i; p+2..N) update(AS[i]);
if (max_a != -1) sum_a += max_a;
}
if (p > 0) {
max_a = -1; min_a = AS[p-1];
foreach_reverse (i; 0..p-1) update(AS[i]);
if (max_a != -1) sum_a += max_a;
}
writeln(sum_a);
}
void main()
{
int T; get(T);
foreach (_; 0..T) solve();
}
|
D
|
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }
bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
enum E = 20;
enum LIM = 2 * 10^^5 + 10;
void main() {
auto sums = new int[][](E, LIM + 1);
foreach (e; 0 .. E) {
foreach (i; 0 .. LIM) {
sums[e][i + 1] = sums[e][i] + (i >> e & 1);
}
}
try {
for (; ; ) {
const numCases = readInt();
foreach (caseId; 0 .. numCases) {
const L = readInt();
const R = readInt() + 1;
int ans;
foreach (e; 0 .. 20) {
chmax(ans, sums[e][R] - sums[e][L]);
}
ans = (R - L) - ans;
writeln(ans);
}
}
} catch (EOFException e) {
}
}
|
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)); }
T binarySearch(alias pred, T)(T ok, T ng)
{
while (abs(ok-ng) > 1)
{
auto mid = (ok+ng)/2;
if (unaryFun!pred(mid)) ok = mid;
else ng = mid;
}
return ok;
}
void main()
{
auto t = RD!int;
auto ans = new long[](t);
foreach (ti; 0..t)
{
auto s = RD!string;
auto cnt = new long[][](s.length+1, 3);
foreach (i; 0..s.length)
{
auto num = s[i]-'1';
cnt[i+1] = cnt[i].dup;
++cnt[i+1][num];
}
int tmp = int.max;
foreach (int i; 0..cast(int)s.length)
{
bool f(int j)
{
auto x = cnt[j].dup;
x[] -= cnt[i][];
return x[0] != 0 && x[1] != 0 && x[2] != 0;
}
auto r = binarySearch!(f)(cast(int)s.length+1, i);
if (r != s.length+1)
{
tmp.chmin(r-i);
}
}
if (tmp != int.max)
{
ans[ti] = tmp;
}
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush;
debug readln;
}
|
D
|
/+ dub.sdl:
name "A"
dependency "dunkelheit" version="1.0.1"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner, dkh.algorithm;
int main() {
Scanner sc = new Scanner(stdin);
scope(exit) assert(!sc.hasNext);
int n, m;
int[] v;
sc.read(n, m, v);
bool calc(int md) {
int bk = 0;
foreach (d; v) {
//[d, d + md]
int nx = m + 10;
if (bk <= d + md) nx = min(nx, max(bk, d));
if (d + md >= m && bk <= d + md - m) nx = bk;
if (nx == m + 10) return false;
bk = nx;
}
return true;
}
writeln(binSearch!(md => calc(md))(-1, m));
return 0;
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/algorithm.d */
// module dkh.algorithm;
import std.traits : isFloatingPoint, isIntegral;
T binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {
while (r-l > 1) {
T md = l + (r-l) / 2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
T binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {
foreach (i; 0..cnt) {
T md = (l+r)/2;
if (!pred(md)) l = md;
else r = md;
}
return r;
}
import std.range.primitives;
E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);
}
ElementType!Range minimum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "minimum: range must not empty");
auto e = range.front; range.popFront;
return minimum!pred(range, e);
}
E maximum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range) {
import std.algorithm, std.functional;
return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);
}
ElementType!Range maximum(alias pred = "a < b", Range)(Range range) {
assert(!range.empty, "maximum: range must not empty");
auto e = range.front; range.popFront;
return maximum!pred(range, e);
}
Rotator!Range rotator(Range)(Range r) {
return Rotator!Range(r);
}
struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
size_t cnt;
Range start, now;
this(Range r) {
cnt = 0;
start = r.save;
now = r.save;
}
this(this) {
start = start.save;
now = now.save;
}
@property bool empty() const {
return now.empty;
}
@property auto front() const {
assert(!now.empty);
import std.range : take, chain;
return chain(now, start.take(cnt));
}
@property Rotator!Range save() {
return this;
}
void popFront() {
cnt++;
now.popFront;
}
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
private File f;
this(File f) {
this.f = f;
}
private char[512] lineBuf;
private char[] line;
private bool succW() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (!line.empty && line.front.isWhite) {
line.popFront;
}
return !line.empty;
}
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
line = lineBuf[];
f.readln(line);
if (!line.length) return false;
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else static if (isStaticArray!T) {
foreach (i; 0..T.length) {
assert(succW());
x[i] = line.parse!E;
}
} else {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(Args...)(auto ref Args args) {
import std.exception : enforce;
static if (args.length != 0) {
enforce(readSingle(args[0]));
read(args[1..$]);
}
}
bool hasNext() {
return succ();
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto T = readln.chomp.to!int;
foreach (_t; 0..T) {
auto nk = readln.split.to!(int[]);
auto N = nk[0];
auto K = nk[1];
int[] as;
bool has;
foreach (a; readln.split.to!(int[])) {
if (a == K) has = true;
as ~= a;
}
if (!has) {
writeln("no");
continue;
}
if (N == 1) {
writeln(has ? "yes" : "no");
continue;
}
foreach (i, a; as[0..$-1]) {
if (a == K) {
if (as[i+1] >= K) goto ok;
if (i+2 < N && as[i+2] >= K) goto ok;
} else if (a > K) {
if (as[i+1] >= K) goto ok;
if (i+2 < N && as[i+2] >= K) goto ok;
}
}
writeln("no");
continue;
ok:
writeln("yes");
}
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int t;
rd(t);
while (t--) {
long s, a, b, c;
rd(s, a, b, c);
auto n = s / c;
writeln(n + n / a * b);
}
}
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.algorithm;
import std.array;
int main()
{
int n;
scanf("%d", &n);
int x = 0, y = 0;
for (int z, i = 0; i < n; i++) {
scanf("%d", &z);
if (z % 2 == 1) x = x + 1;
else y = y + 1;
}
int ans;
if (x < y) ans = x;
else {
ans = y;
x = x - y;
ans = ans + x / 3;
}
writeln(ans);
return 0;
}
|
D
|
import std.stdio;
import std.string;
void main ()
{
while (readln.strip != "")
{
writeln (25);
}
}
|
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 main()
{
auto t = RD!int;
auto ans = new int[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto a = RDA;
foreach (i; 0..n)
{
if (a[i] == 0)
{
++a[i];
++ans[ti];
}
}
auto s = a.sum;
if (s == 0)
++ans[ti];
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new string[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto m = (n+3) / 4;
foreach (i; 0..n-m)
ans[ti] ~= "9";
foreach (i; 0..m)
ans[ti] ~= "8";
}
foreach (e; ans)
{
writeln(e);
}
stdout.flush;
debug readln;
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(size_t[]), h = rd[0], w = rd[1];
foreach (_; 0..h) {
auto c = readln.chomp;
writeln(c);
writeln(c);
}
}
|
D
|
void main() {
string[] ab = readln.split;
int n = (ab[0] ~ ab[1]).to!int;
int m = n.to!double.sqrt.to!int;
writeln(n == m * m ? "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.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.math;
int n; rd(n);
int cur=0, x=0, y=0;
while(n--){
int t, nx, ny; rd(t, nx, ny);
auto d=(nx-x).abs+(ny-y).abs;
if(d>(t-cur)){writeln("No"); return;}
auto r=(t-cur)-d;
if(r&1){writeln("No"); return;}
cur=t; x=nx; y=ny;
}
writeln("Yes");
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
void wr(T...)(T x){
import std.stdio;
foreach(e; x) write(e, " ");
writeln();
}
|
D
|
import std;
int calc(long k, int[] a) {
a = [0] ~ a;
auto used = new long[a.length];
used[] = -1;
int p = 1;
long step = 0;
while (true) {
if (step == k) {
return p;
}
if (used[p] != -1) {
// writeln("loop ", step - used[p]);
auto m = (k - used[p]) % (step - used[p]);
// writeln("m ", m);
m += used[p];
for (int i = 0; i < a.length; i++) {
if (used[i] == m) return i;
}
}
used[p] = step++;
// writeln(p, " -> ", a[p]);
p = a[p];
}
return 0;
}
// ダブリングによる解法
int calc2(long k, int[] a) {
auto N = a.length;
const C = 100;
auto dub = new int[][](C, N);
// k = 0 のとき(2^k = 0)
for (int i = 0; i < N; i++)
dub[0][i] = a[i] - 1;
// k > 0 のとき
for (int i = 0; i < C-1; i++) {
for (int j = 0; j < N; j++) {
dub[i+1][j] = dub[i][dub[i][j]];
}
}
// k ステップで到達するノード
auto step = k;
int now = 0;
for (int i = 0; ; i++) {
if (step % 2 == 1) now = dub[i][now];
step /= 2;
if (step == 0) break;
}
return now + 1;
}
void main() {
long n, k; scan(n, k);
auto a = readints;
writeln(calc2(k, a));
}
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
enum P = 10L^^9+7;
void main()
{
auto S = readln.chomp;
auto N = S.length;
auto DP = new long[][](N+1, 4);
DP[0][0] = 1;
foreach (i, c; S) {
foreach (j; 0..4) DP[i+1][j] = DP[i][j] * (c == '?' ? 3 : 1) % P;
switch (c) {
case 'A': (DP[i+1][1] += DP[i][0]) %= P; break;
case 'B': (DP[i+1][2] += DP[i][1]) %= P; break;
case 'C': (DP[i+1][3] += DP[i][2]) %= P; break;
default:
(DP[i+1][1] += DP[i][0]) %= P;
(DP[i+1][2] += DP[i][1]) %= P;
(DP[i+1][3] += DP[i][2]) %= P;
}
}
writeln(DP[N][3]);
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
void main()
{
auto reader = readln.split;
int r = reader[0].to!int;
writeln(3 * r * r);
}
|
D
|
import std.stdio, std.string, std.array, std.conv;
int[] factors(int n) {
int[] result;
while (n % 2 == 0) {
result ~= 2;
n /= 2;
}
for (int i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
result ~= i;
n /= i;
}
}
if (n != 1) result ~= n;
return result[];
}
void main() {
int n = readln.chomp.to!int;
int[] a = factors(n);
write(n, ":");
foreach (x; a) {
write(" ", x);
}
writeln;
}
|
D
|
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
int x, a; scan(x, a);
if (x < a) writeln(0);
else writeln(10);
}
|
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.split.to!(long[]).countUntil!"a==0" + 1);
}
// ----------------------------------------------
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(){
string s = readln().chomp();
writeln(s.count("A")%3==0? "No": "Yes");
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
void main() {
auto s = readln.chomp.split.map!(to!char).array;
if (s[0] < s[1]) "<".writeln;
else if (s[0] > s[1]) ">".writeln;
else "=".writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(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; }
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;
auto A = RD-1;
auto B = RD-1;
auto d = B - A;
writeln(d % 2 == 0 ? d/2 : min(A, N-B-1) + (d+1)/2);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nmxy = readln.split.to!(int[]);
auto X = nmxy[2];
auto Y = nmxy[3];
auto xs = readln.split.to!(int[]);
auto ys = readln.split.to!(int[]);
int xmax = int.min, ymin = int.max;
foreach (x; xs) xmax = max(xmax, x);
foreach (y; ys) ymin = min(ymin, y);
foreach (z; X..Y) {
++z;
if (xmax < z && ymin >= z) {
writeln("No War");
return;
}
}
writeln("War");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
foreach(i; 1..1000000) {
int n = readln.chomp.to!int;
if (n==0) break;
writeln("Case "~i.to!string~": "~n.to!string);
}
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.