code
stringlengths 4
1.01M
| language
stringclasses 2
values |
|---|---|
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
T readNum(T)(){
return readStr.to!T;
}
T[] readNums(T)(){
return readStr.split.to!(T[]);
}
string readStr(){
return readln.chomp;
}
void main(){
bool finished = false;
auto tax = readNums!int;
foreach(i; 0 .. 1001){
if(floor(i * 0.08) == tax[0] && floor(i * 0.1) == tax[1]){
i.writeln;
finished = true;
break;
}
}
if(!finished){
writeln(-1);
}
}
|
D
|
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long N = lread();
auto A = new long[][](N);
foreach (i; 0 .. N)
A[i] = aryread();
long ans;
auto B = new long[][](N, N);
foreach (i; 0 .. N)
foreach (j; i + 1 .. N)
{
ans += A[i][j];
bool b = true;
foreach (k; 0 .. N)
{
if (i == k || j == k)
continue;
if (A[i][j] == A[i][k] + A[k][j] && b)
{
ans -= A[i][j];
b = false;
}
if (A[i][k] + A[k][j] < A[i][j])
{
writeln(-1);
return;
}
}
}
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.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }
void main()
{
auto t = RD!int;
auto ans = new long[][](t);
foreach (ti; 0..t)
{
auto a = RD;
auto b = RD;
if (a == b)
{
ans[ti] = [0, 0];
continue;
}
if (a > b)
swap(a, b);
auto d = b - a;
auto rem = b % d;
ans[ti] = [d, min((d-rem) % d, rem)];
}
foreach (e; ans)
writeln(e[0], " ", e[1]);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;
void main()
{
while (1) {
auto n = readln.chomp.to!int;
if (!n) break;
auto m = new int[][](n);
foreach (i; 0..n) {
auto x = readln.chomp.split.map!(to!int).array;
if (x[0] == 0) continue;
m[i] ~= x[1..$];
}
auto y = readln.chomp.split.map!(to!int).array[1..$];
int[] res;
foreach (i; 0..n) {
int cnt;
foreach (e; y) {
foreach (me; m[i]) {
if (me == e) cnt++;
}
}
if (cnt == y.length) {
res ~= i + 1;
}
}
if (res.length == 1) {
res[0].writeln;
} else {
writeln(-1);
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto data = readln.split;
auto N = data[0].to!int;
int[] prime_list = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,91,97];
if (1<=N && N<=5) { 0.writeln; return; }
auto order_list = prime_list.map!(a => order(a, N));
ulong c2 = order_list.count!"a>=b"(2), c4 = order_list.count!"a>=b"(4),
c14 = order_list.count!"a>=b"(14), c24 = order_list.count!"a>=b"(24), c74 = order_list.count!"a>=b"(74);
writeln( c74 + c4*(c4-1)/2 * (c2-2) + c24*(c2-1) + c14*(c4-1));
}
// how many times can n! be devided by prime
int order(int prime, int n) {
auto power = prime;
int result;
while (true) {
auto a = n / power;
if (a != 0) result += a;
else break;
power *= prime;
}
return result;
}
|
D
|
import std.stdio;
import std.string;
import std.range;
import std.conv;
void main()
{
/*auto N = readln.chomp.to!int;
auto D = readln.chomp.to!int;
*/
auto ip = readln.split.to!(int[]), D = ip[0], N = ip[1];
if(N==100){
writeln(101*100^^D);
}else{
writeln(100^^D*N);
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
string s; readV(s);
writeln(s.predSwitch("A", "T", "T", "A", "C", "G", "G", "C"));
}
|
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()
{
int[3][3] c;
foreach (i; 0..3) {
c[i] = readln.chomp.split.to!(int[]);
}
auto h1 = c[0][0] - c[0][1];
auto h2 = c[0][0] - c[0][2];
auto h3 = c[0][1] - c[0][2];
auto v1 = c[0][0] - c[1][0];
auto v2 = c[0][0] - c[2][0];
auto v3 = c[1][0] - c[2][0];
bool f;
foreach (i; 1..3) {
if (h1 != c[i][0] - c[i][1]) {
f = true;
}
if (h2 != c[i][0] - c[i][2]) {
f = true;
}
if (h3 != c[i][1] - c[i][2]) {
f = true;
}
if (v1 != c[0][i] - c[1][i]) {
f = true;
}
if (v2 != c[0][i] - c[2][i]) {
f = true;
}
if (v3 != c[1][i] - c[2][i]) {
f = true;
}
}
if (f) {
writeln("No");
} else {
writeln("Yes");
}
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long N = lread();
writeln(N * (N - 1) / 2);
// iota(N - 1).map!"a+1"().sum().writeln();
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n, k; rd(n, k);
auto dp=new int[][](4, k+10);
const int mod=998244353;
void add(ref int x, int y){
x+=y;
if(x>=mod) x-=mod;
}
dp[0][1]=dp[3][1]=1;
dp[1][2]=dp[2][2]=1;
for(int i=1; i<n; i++){
auto nex=new int[][](4, k+10);
foreach(s; 0..(1<<2)){
for(int j=1; j<=k; j++){
foreach(t; 0..(1<<2)){
if(s==t){
add(nex[t][j], dp[s][j]);
}else if((s^t)==((1<<2)-1)){
if(s==0 || s==3){
if(j+1<=k){
add(nex[t][j+1], dp[s][j]);
}
}else{
if(j+2<=k){
add(nex[t][j+2], dp[s][j]);
}
}
}else if((s==0 || s==3) && (t==1 || t==2)){
if(j+1<=k){
add(nex[t][j+1], dp[s][j]);
}
}else{
add(nex[t][j], dp[s][j]);
}
}
}
}
dp.swap(nex);
}
int tot=0;
foreach(i; 0..(1<<2)) (tot+=dp[i][k])%=mod;
writeln(tot);
}
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));
}
|
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); }
import std.bigint, std.functional;
void main() {
auto I = readln.split.to!(long[]);
auto A = cast(real)(I[0]);
auto B = cast(real)(I[1]);
auto C = cast(real)(I[2]);
bool solve() {
return A + B + 2f*(A.sqrt*B.sqrt) < C;
}
writeln(solve() ? "Yes" : "No");
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string;
void main()
{
auto a = readln.chomp;
auto b = readln.chomp;
writeln(
a.length > b.length ? "GREATER" :
a.length < b.length ? "LESS" :
a > b ? "GREATER" :
a < b ? "LESS" :
"EQUAL"
);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.string, std.array;
void main()
{
const N = readln.chomp.to!long;
auto ans = long.max;
for (long i = 1; i*i <= N; ++i) {
if (N%i == 0) ans = ans.min(i+N/i-2);
}
ans.writeln;
}
|
D
|
import std.conv, std.stdio, std.string, std.array, std.range, std.algorithm;
string s = "CODEFORCES";
void main() {
char[] t = readln.strip.dup;
int len;
foreach (i, e; s) {
if (e == t[i]) {
++len;
}
else {
break;
}
}
if (len == 10) {
writeln("YES");
return;
}
len = 0;
int j;
foreach_reverse (i, e; s) {
if (e == t[$ - j - 1]) {
++len;
}
else {
break;
}
++j;
}
if (len == 10) {
writeln("YES");
return;
}
char[] begin, end;
foreach (i, e; s) {
if (e == t[i]) {
begin ~= t[i];
}
else {
break;
}
}
j = 0;
foreach_reverse (i, e; s) {
if (e == t[$ - j - 1]) {
end ~= t[$ - j - 1];
}
else {
break;
}
++j;
}
if ((begin ~ end).length >= 10) {
writeln("YES");
return;
}
writeln("NO");
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!long).array;
if (N == 2) {
A.reduce!max.writeln;
return;
}
auto L = new long[](N);
auto R = new long[](N);
L[0] = A.front;
R[N-1] = A.back;
foreach (i; 1..N) L[i] = gcd(L[i-1], A[i]);
foreach_reverse (i; 0..N-1) R[i] = gcd(R[i+1], A[i]);
long ans = 1;
foreach (i; 0..N) {
long l = i == 0 ? 0 : L[i-1];
long r = i == N - 1 ? 0 : R[i+1];
ans = max(ans, gcd(l, r));
}
ans.writeln;
}
|
D
|
import std.stdio;
import std.algorithm;
void main() {
int w, h, n;
scanf("%d\n%d\n%d", &w, &h, &n);
write((n + max(w,h) - 1) / max(w, h));
}
|
D
|
void main()
{
long[] tmp = rdRow;
long n = tmp[0], k = tmp[1];
long result = (n / k) ^^ 3;
if (!(k & 1))
{
result += ((n + k / 2) / k) ^^ 3;
}
result.writeln;
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void 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.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
ulong MIDDLE = 100_000;
alias Pair = Tuple!(long, "flag", long, "num");
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 x = lread();
long current, t = 1;
while(current < x)
current += t++;
(t - 1).writeln();
}
|
D
|
void main()
{
long n = rdElem;
Input[] input = n.rdCol!Input;
foreach (x; 0 .. 101)
{
foreach (y; 0 .. 101)
{
long h;
foreach (a; input)
{
if (a.h) h = a.h + abs(a.x-x) + abs(a.y-y);
}
bool ok = true;
foreach (a; input)
{
if (a.h != max(0, h-abs(a.x-x)-abs(a.y-y)))
{
ok = false;
break;
}
}
if (ok)
{
writeln(x, " ", y, " ", h);
return;
}
}
}
}
struct Input
{
long x, y, h;
}
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 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.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
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 st = readln.split.to!(string[]);
void solve() {
writeln(st[1] ~ st[0]);
}
solve();
}
|
D
|
import std.algorithm;
import std.range;
import std.math;
import std.regex;
import std.array;
import std.container;
import std.stdio;
import std.string;
import std.conv;
string[] readStrs() { return readln.chomp.split(' '); }
T[] readInts(T)() { return readln.chomp.split(' ').map!(to!T).array(); }
T readInt(T)() { return readln.chomp.to!T; }
void main()
{
writeln(solve());
}
long solve()
{
int N = readInt!int;
int[] As = readInts!int;
int[] vs = new int[N];
foreach(i; 0 .. N)
vs[As[i]] += 1;
if(N % 2 == 0){
foreach(i; 0 .. N){
if(vs[i] != 0 && i % 2 != 1) return 0;
if(vs[i] != 0 && vs[i] != 2) return 0;
}
return computeABP(2, N/2, 1_000_000_007);
}else{
foreach(i; 0 .. N){
if(vs[i] != 0 && i % 2 != 0) return 0;
if(i != 0 && vs[i] != 0 && vs[i] != 2) return 0;
if(i == 0 && vs[i] != 1) return 0;
}
return computeABP(2, N/2, 1_000_000_007);
}
}
long computeABP(int a, int b, int p)
{
if(b == 0) return 1;
else if(b % 2 == 0){
long d = computeABP(a, b/2, p);
return (d * d) % p;
}else{
return (a * computeABP(a, b-1, p)) % p;
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
long[] t;
bool[] b;
void main()
{
long N = lread;
t = new long[](N + 1);
b = new bool[](N + 1);
foreach (i; 0 .. N)
t[i + 1] = lread();
solve(1).max(-1).writeln();
}
long solve(long n)
{
if (b[n])
return long.min;
if (n == 2)
return 0;
b[n] = true;
return solve(t[n]) + 1;
}
|
D
|
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto data = readln.split;
auto N = data[0].to!int, T = data[1].to!int;
int cost = 10_000;
foreach (i; 0 .. N) {
data = readln.split;
auto c = data[0].to!int, t = data[1].to!int;
if (t <= T && c < cost) { cost = c; }
}
if (cost == 10_000) writeln("TLE");
else writeln(cost);
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
int a, b, h;
scan(a);
scan(b);
scan(h);
writeln((a + b) * h / 2);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
long P = 10^^9+7;
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
void main()
{
auto nm = readln.split.to!(long[]);
writeln(pow(nm[0], nm[1]));
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;
alias R = Tuple!(long, "x", long, "y", long, "p");
void main()
{
auto N = readln.chomp.to!int;
R[] rs;
foreach (_; 0..N) {
auto r = readln.split.to!(long[]);
auto x = r[0];
auto y = r[1];
auto p = r[2];
rs ~= R(x, y, p);
}
auto xs = new long[][](N, 1<<N);
auto ys = new long[][](N, 1<<N);
foreach (b; 0..2^^N) {
foreach (i, r; rs) {
xs[i][b] = abs(r.x) * r.p;
ys[i][b] = abs(r.y) * r.p;
foreach (j; 0..N) if (b & (1<<j)) {
xs[i][b] = min(xs[i][b], abs(r.x - rs[j].x) * r.p);
ys[i][b] = min(ys[i][b], abs(r.y - rs[j].y) * r.p);
}
}
}
auto res = new long[](N+1);
res[] = long.max;
foreach (b; 0..3^^N) {
int c;
uint x, y;
foreach (i; 0..N) {
if (b%3 == 1) {
x |= (1<<i);
++c;
} else if (b%3 == 2) {
y |= (1<<i);
++c;
}
b /= 3;
}
long s;
foreach (i; 0..N) s += min(xs[i][x], ys[i][y]);
res[c] = min(res[c], s);
}
foreach (r; res[0..N+1]) writeln(r);
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
long A, B, C, X, Y;
scan(A, B, C, X, Y);
long a = max(X, Y) * 2 * C;
long b = X * 2 * C + max(0, Y - X) * B;
long c = Y * 2 * C + max(0, X - Y) * A;
long d = X * A + Y * B;
// writeln(a, b, c, d);
writeln(min(a, b, c, d));
}
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.numeric;
import std.math;
import std.string;
void main()
{
auto n = to!int(chomp(readln()));
long[] t;
foreach (i; 0..n)
{
t ~= to!long(chomp(readln()));
}
long lcm(long a, long b)
{
if (a < b)
{
auto tmp = a;
a = b;
b = tmp;
}
auto r = a % b;
long x = a, y = b;
while (r != 0)
{
x = y;
y = r;
r = x % y;
}
return b / y * a;
}
auto result = t[0];
foreach (e; t[1..$])
{
result = lcm(result, e);
}
writeln(result);
stdout.flush();
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
writeln(n*800-(n/15)*200);
}
|
D
|
void main()
{
long n, m, q;
rdVals(n, m, q);
long[] a = new long[q], b = new long[q], c = new long[q], d = new long[q];
foreach (i; 0 .. q)
{
rdVals(a[i], b[i], c[i], d[i]);
--a[i], --b[i];
}
long result;
void dfs(long[] arr)
{
if (arr.length == n)
{
long point;
foreach (i; 0 .. q)
{
if (arr[b[i]] - arr[a[i]] == c[i])
{
point += d[i];
}
}
result = max(result, point);
return;
}
foreach (i; arr[$-1] .. m+1)
{
dfs(arr ~ i);
}
}
dfs([1]);
result.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.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math,std.random,std.concurrency;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...) (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
int read(){int n;read(n);return n;}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
auto infIota = (int i=0) => new std.concurrency.Generator!int({for(;;)yield(i++);});
auto dot(R1,R2)(R1 a,R2 b){ElementType!(R1) res=0;for(;!a.empty&&!b.empty;a.popFront(),b.popFront())res+=a.front*b.front;return res;}
int calc(int n){
if (n < 10) return 0;
int [] ns;
while(n){ns ~= n % 10;n /= 10;}
int [] res;
auto tens = ()=> iota(ns.length).map!"10^^a";
foreach(i;1 .. ns.length){
res ~= ns[0..i].dot(tens()) * ns[i..$].dot(tens());
}
return 1 + calc(res.reduce!(max));
}
void main(){
read().times({ read().calc.writeln; });
}
|
D
|
import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }
T[] readToArray(T)() {
return readln.split.to!(T[]);
}
void readInto(T...)(ref T ts) {
auto ss = readln.split;
foreach(ref t; ts) {
t = ss.front.to!(typeof(t));
ss.popFront;
}
}
// 冪乗をmod取りつつ計算
@nogc @safe pure ulong modPow(ulong a, ulong n, ulong m) {
ulong r = 1;
while (n > 0) {
if(n % 2 != 0) r = r * a % m;
a = a * a % m;
n /= 2;
}
return r;
}
// フェルマーの小定理から乗法逆元を計算
// 定理の要請により法は素数
@nogc @safe pure ulong modInv(ulong a, ulong m) {
return modPow(a, m-2, m);
}
// mod取りつつ順列を計算
@nogc @safe pure ulong modPerm(ulong n, ulong k, ulong m) {
if (n < k) return 0;
ulong r = 1;
for (ulong i = n-k+1; i <= n; i++) {
r *= i;
r %= m;
}
return r;
}
// mod取りつつ順列を計算
@nogc @safe pure ulong modFact(ulong n, ulong m) {
return modPerm(n, n, m);
}
// mod取りつつ組み合わせを計算
// modInvを使っているので法は素数
@nogc @safe pure ulong modComb(ulong n, ulong r, ulong m) {
return modPerm(n, r, m)*modInv(modFact(r, m), m) % m;
}
immutable ulong MOD = 1000000007;
void main() {
ulong n, d;
readInto(n, d);
writeln((n+2*d)/(2*d+1));
}
|
D
|
import std.algorithm,
std.string,
std.range,
std.stdio,
std.conv;
void main() {
int N = readln.chomp.to!int;
string S = readln.chomp;
char l = '(',
r = ')';
int ls,
rs;
int als;
foreach (c; S) {
if (c == l) { ls++; }
else { rs++; }
if (ls - rs < 0) {
als++;
ls = 0;
rs = 0;
}
}
als.iota.each!(_ => write(l));
write(S);
(ls-rs).iota.each!(_ => write(r));
writeln;
}
|
D
|
void main(){
import std.stdio;
auto x = readln.dup;
x[3] = '8';
writeln(x);
}
|
D
|
import std.stdio;
import std.string, std.conv, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons;
import core.bitop, std.datetime, std.range;
void main(){
auto rd = readln.split.to!(int[]);
auto n = rd[0], q = rd[1];
auto ds = new int[][](n, 1);
auto n2s = iota(n).array;
foreach(i ; 0 .. n){
ds[i][0] = i;
}
foreach(lp ; 0 .. q){
rd = readln.split.to!(int[]);
auto c = rd[0], x = rd[1], y = rd[2];
if(c == 0){
merge(ds, n2s, x, y);
} else{
writeln(n2s[x] == n2s[y] ? 1 : 0);
}
}
}
void merge(int[][] ds, int[] n2s, int x, int y){
auto u = n2s[x];
auto v = n2s[y];
if(u == v) return;
if(ds[u].length > ds[v].length) swap(u, v);
ds[v] ~= ds[u];
foreach(z ; ds[u]){
n2s[z] = v;
}
delete ds[u];
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto s = readln.chomp.to!(char[]);
char[] S;
for (size_t i; i < s.length; ++i) {
if (i < s.length-1 && s[i] == 'B' && s[i+1] == 'C') {
S ~= 'X';
++i;
} else {
S ~= s[i];
}
}
long[] C;
C.length = S.length;
long cnt;
foreach (i, c; S) {
if (c == 'A') {
++cnt;
} else if (c != 'X') {
cnt = 0;
}
C[i] = cnt;
}
long r;
foreach (i, c; S) if (c == 'X') r += C[i];
writeln(r);
}
|
D
|
void main() {
string s = readln.chomp;
char[] acgt = ['A', 'C', 'G', 'T'];
int cnt, ans;
foreach (x; s) {
if (acgt.canFind(x)) {
++cnt;
ans = max(ans, cnt);
} else {
ans = max(ans, cnt);
cnt = 0;
}
}
ans.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;
|
D
|
void main()
{
int[] tmp = readln.split.to!(int[]);
int n = tmp[0], k = tmp[1];
writeln((n + 1) / 2 >= k ? "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, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int a, b, c;
long k;
scan(a, b, c, k);
writeln(k & 1 ? b - a : a - b);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int n, a, b, c;
scan(n, a, b, c);
auto x = iota(n).map!(i => readln.chomp.to!int).array;
long ans = inf6;
foreach (s ; 1 .. 1 << n) {
long tmp;
int la;
foreach (j ; 0 .. n) {
if (s & (1 << j)) {
la += x[j];
tmp += 10;
}
}
tmp -= 10;
foreach (t ; 1 .. 1 << n) {
auto ttmp = tmp;
int lb;
if (s & t) continue;
foreach (k ; 0 .. n) {
if (t & (1 << k)) {
lb += x[k];
ttmp += 10;
}
}
ttmp -= 10;
foreach (u ; 1 .. 1 << n) {
if ((s | t) & u) continue;
auto tttmp = ttmp;
int lc;
foreach (e ; 0 .. n) {
if (u & (1 << e)) {
lc += x[e];
tttmp += 10;
}
}
tttmp -= 10;
tttmp += abs(la - a) + abs(lb - b) + abs(lc - c);
ans = min(ans, tttmp);
}
}
}
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[]);}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;
void main()
{
string s;
while( (s=readln.strip) != "0 0") {
auto n = map!(to!int)(s.strip.split);
int h = n[0], w = n[1];
foreach(i;0..h) {
foreach(j;0..w) {
write((i+j)%2==0 ? '#':'.');
}
writeln();
}
writeln();
}
}
|
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;
int[][] ab = new int[][](10,10);
for(int i=1; i<=n; i++) {
int a = i;
while(a>=10) a/=10;
int b = i%10;
ab[a][b]++;
}
long result = 0;
for(int i=0; i<10; i++) for(int j=0; j<10; j++) {
result += ab[i][j]*ab[j][i];
}
writeln(result);
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
void main() {
int N = readln.chomp.to!int;
string s = readln.chomp;
string t = readln.chomp;
(N+1).iota.countUntil!(
i => s[i..$] == t[0..$-i]
).pipe!(a => a+N).writeln;
}
// ----------------------------------------------
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
|
D
|
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
auto args=readln.split.to!(int[]);
if((args[2]-args[1])&1){
writeln("Borys");
}else{
writeln("Alice");
}
}
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.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void scan(T...)(ref T a) {
string[] ss = readln.split;
foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
int calc(int[][] g) {
int n = cast(int)g.length;
auto ind = new int[n];
auto gg = new int[][](n, n);
int[][] q;
for (int i = 0; i < n; i++) {
// i 番目の対戦相手
int index = ind[i]++;
if (index == n) continue;
int t = g[i][index]; // 相手
int a = min(i, t);
int b = max(i, t);
gg[a][b]++;
if (gg[a][b] == 2) {
q ~= [a, b];
}
}
int match = 0;
bool update = true;
int date = 0;
auto used = new bool[n];
while (update) {
used[] = false;
update = false;
int[][] qq;
while (q.length > 0) {
auto x = q[$-1]; q.popBack();
int a = x[0];
int b = x[1];
if (!used[a] && !used[b]) {
used[a] = used[b] = true;
match++;
// writeln("match ", a, " ", b);
update = true;
int aIndex = ind[a]++;
if (aIndex < n-1) { // 次の対戦相手
int t = g[a][aIndex];
int mi = min(a, t);
int ma = max(a, t);
gg[mi][ma]++;
if (gg[mi][ma] == 2) {
qq ~= [mi, ma];
}
}
int bIndex = ind[b]++;
if (bIndex < n-1) {
int t = g[b][bIndex];
int mi = min(b, t);
int ma = max(b, t);
gg[mi][ma]++;
if (gg[mi][ma] == 2) {
qq ~= [mi, ma];
}
}
}
}
for (int i = 0; i < qq.length; i++) q ~= qq[i];
if (update) date++;
}
if (match == n * (n - 1) / 2) return date;
return -1;
}
void main() {
int n; scan(n);
int[][] g;
for (int i = 0; i < n; i++) {
g ~= readints.map!(e => e - 1).array;
}
writeln(calc(g));
}
|
D
|
import std;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
int n = scan!int;
long p = scan!long;
long[] as = scan.split("").to!(long[]);
long ans;
if(10 % p == 0){
foreach(i, a; as) if(a % p == 0) ans += i + 1;
}
else{
int[long] cnt = [0: 1];
long x = 0;
long m = 1;
foreach_reverse(a; as){
x += a * m, x %= p;
m *= 10, m %= p;
if(x !in cnt) cnt[x] = 0;
ans += cnt[x];
cnt[x] += 1;
}
}
ans.writeln;
}
|
D
|
import std.algorithm;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
auto t = readln.strip;
auto m = s.length;
auto n = t.length;
auto g = gcd (m, n);
auto x = s[0..g];
auto r = x;
while (r.length % m != 0 || r.length % n != 0)
{
r ~= x;
}
writeln ((r[0..m] == s && r[0..n] == t) ? r : "-1");
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
auto r = 0;
for (auto i = 105; i <= n; i += 2) {
auto f = 0;
foreach (j; 1..i+1)
if (i%j == 0) ++f;
if (f == 8) ++r;
}
writeln(r);
}
|
D
|
import std.stdio;
import std.string;
void main() {
int a;
scanf("%d\n", &a);
auto s = readln.chomp;
if (a >= 3200) s.write;
else "red".write;
}
|
D
|
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
auto readInts() {
return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
return readInts()[0];
}
auto readLongs() {
return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
return readLongs()[0];
}
void readlnTo(T...)(ref T t) {
auto s = readln().split();
assert(s.length == t.length);
foreach(ref ti; t) {
ti = s[0].to!(typeof(ti));
s = s[1..$];
}
}
const real eps = 1e-10;
void main(){
auto dp = new int[](1000001);
foreach(i; iota(1, dp.length.to!int)) {
int k = i;
while(k % 2 == 0) {
k /= 2;
}
while(k % 3 == 0) {
k /= 3;
}
while(k % 5 == 0) {
k /= 5;
}
if(k == 1) {
dp[i] = dp[i-1] + 1;
} else {
dp[i] = dp[i-1];
}
}
while(true) {
auto l = readInts();
if(l.length == 1) {
return;
}
auto m = l[0];
auto n = l[1];
writeln(dp[n] - dp[m-1]);
}
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int a, b; readV(a, b);
if (b%a == 0)
writeln(a+b);
else
writeln(b-a);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
auto n = readln.chomp.to!int;
auto s = readln.chomp;
long rc, gc, bc;
foreach (i; 0..n) {
if (s[i] == 'R') rc++;
else if (s[i] == 'G') gc++;
else bc++;
}
auto cnt = rc * gc * bc;
foreach (int i; 0..n) {
foreach (int j; i+1..n) {
if (s[i] == s[j]) continue;
auto k = 2*j - i;
if (k >= n) continue;
if (s[i] == s[k] || s[j] == s[k]) continue;
cnt--;
}
}
cnt.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;
long P = 10^^9+7;
long[10^^5+50] F, RF;
void init()
{
F[0] = F[1] = 1;
foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;
{
RF[$-1] = 1;
auto x = F[$-1];
auto k = P-2;
while (k) {
if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
x = x^^2 % P;
k /= 2;
}
}
foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}
long pow(long x, long n) {
long y = 1;
while (n) {
if (n%2 == 1) y = (y * x) % P;
x = x^^2 % P;
n /= 2;
}
return y;
}
long inv(long x)
{
return pow(x, P-2);
}
void main()
{
init();
auto N = readln.chomp.to!long;
auto r = F[N];
long d = 1, p = 1, c = 1;
foreach (i, x; readln.split.to!(long[])) {
if (x < d) {
r = (r - p * (N-i-1) % P * F[N-c] % P + P) % P;
d -= 2;
p = p * (i+2-c) % P;
++c;
}
d += 2;
}
writeln(r);
}
|
D
|
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;
alias Tuple!(int, "x", int, "y") Point;
auto move = [[-1, 0], [0, 1], [1, 0], [0, -1]];
void main(){
string input;
Point[200] points;
points[0] = Point(0, 0);
while((input = readln.chomp) != "0"){
int n = input.to!int;
if(n == 1){
"1 1".writeln;
continue;
}
points[1..n] = Point.init;
foreach(i; 1..n){
auto line = readln.split;
int base = line[0].to!int;
int dir = line[1].to!int;
points[i] = Point(points[base].x + move[dir][0], points[base].y + move[dir][1]);
}
auto result = reduce!(q{max(a, b.x)}, q{min(a, b.x)}, q{max(a, b.y)}, q{min(a, b.y)})(tuple(0, 0, 0, 0), points[0..n]);
writeln(result[0] - result[1] + 1, " ", result[2] - result[3] + 1);
}
}
|
D
|
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;
auto readInts() {
return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
return readInts()[0];
}
auto readLongs() {
return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
return readLongs()[0];
}
const real eps = 1e-10;
void main(){
bool[string] kagi;
auto N = readInt();
for(int i; i < N; ++i) {
auto s = readln().strip();
kagi[s] = true;
}
auto M = readInt();
auto opened = false;
for(int i; i < M; ++i) {
auto s = readln().strip();
if((s in kagi) !is null) {
if(opened) {
writeln("Closed by ", s);
} else {
writeln("Opened by ", s);
}
opened = !opened;
} else {
writeln("Unknown ", s);
}
}
}
|
D
|
/+ dub.sdl:
name "C"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio;
// import dcomp.scanner;
int main() {
auto sc = new Scanner(stdin);
long x;
sc.read(x);
long sm;
foreach (i; 1..1000000) {
sm += i;
if (sm >= x) {
writeln(i);
break;
}
}
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
string[] buf;
private bool succ() {
while (!buf.length) {
if (f.eof) return false;
buf = f.readln.split;
}
return true;
}
private bool readSingle(T)(ref T x) {
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
//string or char[10] etc
x = buf.front;
buf.popFront;
} else {
static if (isStaticArray!T) {
//static
assert(buf.length == T.length);
}
x = buf.map!(to!E).array;
buf.length = 0;
}
} else {
x = buf.front.to!T;
buf.popFront;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3]));
assert(equal(c[], "ab"));
assert(equal(d, "cde"));
assert(e == 1.0);
assert(equal(f, [1.0, 2.0]));
}
|
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;
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;
bool canReach(string s, int fm, int to) {
assert(s[fm] == '.' && s[to] == '.');
int p = fm;
while (p < to) {
if (p + 2 <= to && s[p + 2] == '.') p += 2;
else if (s[p + 1] == '.') p++;
else return false;
}
return true;
}
bool canJumpOver(string s, int lo, int hi) {
int n = cast(int)s.length;
for (int i = lo; i <= hi; i++) {
if (i + 2 >= n) break;
if (s[i..i+3] == "...") return true;
}
return false;
}
bool calc(string s, int a, int b, int c, int d) {
int n = cast(int)s.length;
bool reachOk = canReach(s, a, c) && canReach(s, b, d);
// a, b の移動は独立している
if (c < d) return reachOk;
// a は b を追い越す必要がある
return reachOk && canJumpOver(s, b-1, d-1);
}
void main() {
int n, a, b, c, d; scan(n, a, b, c, d);
string s = read!string;
writeln(calc(s, a-1, b-1, c-1, d-1) ? "Yes" : "No");
}
|
D
|
import std.stdio, std.string, std.conv, std.array, std.algorithm;
void main() {
auto S = readln.chomp.to!int;
writeln(S/3600, ":", S % 3600 / 60, ":", S % 60);
}
|
D
|
void main() {
bool[string] dict;
foreach(i; 0..ri) {
auto ip = readln.split, command = ip[0], str = ip[1];
switch(command) {
case "insert":
dict[str] = true;
break;
case "find":
if(str in dict && dict[str]) "yes".writeln;
else "no".writeln;
break;
default:
break;
}
}
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio, std.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 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; }
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;
long[] p;
for (long i = 2; i*i <= n; ++i)
{
if (n % i == 0)
{
p ~= i;
p ~= n/i;
}
}
long ans = n;
foreach (e; p)
{
ans = gcd(ans, e);
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
int main()
{
while (true) {
string[] s1 = readln.chomp.split;
int n = s1[0].to!int;
int m = s1[1].to!int;
int a = s1[2].to!int;
if (n == 0 && m == 0 && a == 0) break;
int max = -1;
int[1001][1001] N;
for (int i = 0; i < 1001; i++)
for (int j = 0; j < 1001; j++)
N[i][j] = i;
bool flag = true;
for (int i = 0; i < m; i++) {
string[] s2 = readln.chomp.split;
int h = s2[0].to!int;
int p = s2[1].to!int;
int q = s2[2].to!int;
N[p][h] = q;
N[q][h] = p;
}
max = 1000;
while (max) {
a = N[a][max];
--max;
}
writeln(a);
}
return 0;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
auto S = readln.chomp.to!(char[]);
foreach (ref c; S) {
auto x = c - 'A';
x = (x + N) % 26;
c = ('A' + x).to!char;
}
writeln(S);
}
|
D
|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
int w, h, a, b;
void main() {
scan(h, w, a, b);
auto c = ModCombo(w + h);
long ans;
foreach (i ; 0 .. h - a) {
(ans += c.binom(b + i - 1, i) * c.binom(w + h - b - i - 2, h - i - 1) % c.mod) %= c.mod;
}
writeln(ans);
}
struct ModCombo {
private {
immutable long _mod;
long[] _f;
long[] _finv;
long _powmod(long x, long y, long mod) {
return y > 0 ? _powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1L;
}
}
@property {
long mod() {return _mod;}
long f(int n) {return _f[n];}
long finv(int n) {return _finv[n];}
}
this (int N, long mod = 10^^9 + 7) {
_mod = mod;
_f = new long[](N + 1);
_finv = new long[](N + 1);
_f[0] = _finv[0] = 1L;
foreach (i ; 1 .. N + 1) {
_f[i] = i * _f[i - 1] % _mod;
}
_finv[N] = _powmod(_f[N], _mod - 2, _mod);
foreach_reverse (i ; 1 .. N) {
_finv[i] = (i + 1) * _finv[i + 1] % _mod;
}
}
long perm(int n, int k) {
return _f[n] * _finv[k] % _mod;
}
long binom(int n, int k) {
return _f[n] * _finv[k] % _mod * _finv[n - k] % _mod;
}
long H(int n, int k) {
if (n == 0 && k == 0) return 1L;
return _f[n + k - 1] * _finv[k] % _mod * _finv[n - 1] % _mod;
}
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*
誰の子にもなっていない頂点は、根
1人の子になっている頂点は、それが親
2人以上の子になっている頂点は親が不明
親の候補の個数を記憶
根から、幅優先探索でたどっていく
親が不明の頂点についたらそこで止まる。探索はしない
(早くついたということはそれはショートカットルートだった)
親の候補の個数を減らす
1だったらそれが本当の親
*/
class Node{
Node parent;
Node[] kids;
Node[] parents;
long count;
long id;
this(long id){
this.id = id;
}
}
class X{
Node from;
Node to;
this(Node from, Node to){
this.from = from, this.to = to;
}
}
void main(){
long n = read.to!long;
long m = read.to!long;
Node[] nodes;
foreach(i; 0 .. n) nodes ~= new Node(i);
foreach(i; 0 .. n - 1 + m){
long a = read.to!long - 1;
long b = read.to!long - 1;
nodes[a].kids ~= nodes[b];
nodes[b].parents ~= nodes[a];
}
Node root;
foreach(nd; nodes){
if(nd.parents.length == 0) nd.parent = null, root = nd;
else nd.count = nd.parents.length;
}
X[] queue;
long ix = 0;
foreach(nd; root.kids) queue ~= new X(root, nd);
while(ix < queue.length){
X x = queue[ix];
if(x.to.count == 1){
x.to.parent = x.from;
foreach(nd; x.to.kids) queue ~= new X(x.to, nd);
}
else x.to.count -= 1;
ix += 1;
}
foreach(nd; nodes){
if(nd.parent) writeln(nd.parent.id + 1);
else writeln(0);
}
}
|
D
|
// Cheese-Cracker: cheese-cracker.github.io
void solve(){
auto n = scan;
auto arr = scanArray;
long gcd1 = arr[0];
for(int i = 2; i < n; i += 2){
gcd1 = gcd(gcd1, arr[i]);
}
long gcd2 = arr[1];
for(int i = 3; i < n; i += 2){
gcd2 = gcd(gcd2, arr[i]);
}
show(gcd1, gcd2);
bool f = 1;
for(int i = 1; i < n; i += 2){
if(arr[i] % gcd1 == 0){
f = 0;
break;
}
}
if(f){
writeln(gcd1);
return;
}
f = 1;
for(int i = 0; i < n; i += 2){
if(arr[i] % gcd2 == 0){
f = 0;
break;
}
}
if(f){
writeln(gcd2);
return;
}
writeln(0);
}
void main(){
long tests = scan; // Toggle!
while(tests--) solve;
}
/************** ***** That's All Folks! ***** **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x", long, "y");
|
D
|
import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;
string my_readln() { return chomp(readln()); }
void main()
{//try{
auto tokens = split(my_readln());
auto X = to!ulong(tokens[0]);
if (X == 7 || X == 5 || X == 3)
writeln("YES");
else
writeln("NO");
stdout.flush();
/*}catch (Throwable e)
{
writeln(e.toString());
}
readln();*/
}
|
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()
{
readln;
readln.chomp.split.map!(a=>a.to!int - 1).sum.writeln;
}
|
D
|
void main()
{
long a, b, k;
rdVals(a, b, k);
foreach (i; 0 .. k)
{
if (i & 1)
{
b >>= 1;
a += b;
}
else
{
a >>= 1;
b += a;
}
}
writeln(a, " ", b);
}
enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const tmp = readln.split.to!(long[]);
writeln(iota(tmp[1] - tmp[0]).sum - tmp[0]);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto N = readln.chomp;
writeln(to!char(N[0] + 1));
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;
void main() {
char a, b;
scan(a, b);
writeln(a == b ? "H" : "D");
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio,std.conv,std.string,std.algorithm,std.array;
void main(){
auto a=readln();
auto b=readln();
auto c=readln();
char A,B,C;
A=a[0];
B=b[1];
C=c[2];
write(A);
write(B);
write(C);
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; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }
void main()
{
auto A = RD;
auto B = RD;
auto N = RD;
if (N >= B)
writeln(A*(B-1)/B);
else
writeln(A*N/B);
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.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
auto s = sread();
uint x;
foreach (i, c; s)
x |= 1 << (c - 'a');
// writefln("%b", x);
if (x == (1 << 26) - 1)
{
writeln("None");
return;
}
foreach (c; 'a' .. 'z' + 1)
if ((x & (1 << (c - 'a'))) == 0)
{
writeln(cast(char) c);
return;
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N;
scan(N);
auto x = new int[](N);
auto y = new int[](N);
iota(N).each!(i => scan(x[i], y[i]));
x[] -= 1;
y[] -= 1;
int L = 10^^5;
auto adj = new int[][](2 * L, 0);
foreach (i ; 0 .. N) {
adj[x[i]] ~= y[i] + L;
adj[y[i] + L] ~= x[i];
}
auto visited = new bool[](2 * L);
long ans;
long cx, cy;
void dfs(int v) {
visited[v] = true;
(v >= L ? cy : cx)++;
foreach (u ; adj[v]) {
if (!visited[u]) dfs(u);
}
}
foreach (i ; 0 .. 2 * L) {
cx = cy = 0;
if (!visited[i]) {
dfs(i);
}
ans += cx * cy;
}
ans -= N;
writeln(ans);
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
string s;
while ((s = readln.strip) != "")
{
auto t = readln.split;
bool ok = t.any !(r => r[0] == s[0] || r[1] == s[1]);
writeln (ok ? "YES" : "NO");
}
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto X = readln.chomp.to!long;
auto K = readln.chomp.to!int + 2;
auto RR = 0 ~ readln.split.map!(to!long).array ~ 10L^^10;
auto R = (K-1).iota.map!(i => RR[i+1] - RR[i]).array;
auto Q = readln.chomp.to!int;
auto T = new long[](Q);
auto A = new long[](Q);
foreach (i; 0..Q) {
auto s = readln.split.map!(to!long);
T[i] = s[0];
A[i] = s[1];
}
long[] sim0 = [0, X];
long[] simX = [X, 0];
long[] simN = [0, X];
long ub = -1;
long lb = 1L << 59;
int q = 0;
foreach (t; 0..K-1) {
for ( ; q < Q && RR[t] <= T[q] && T[q] < RR[t+1]; q++) {
debug {writeln([RR[t], T[q], RR[t+1]]);}
debug {sim0.writeln; simX.writeln;}
long ans;
if (A[q] <= ub) {
ans = max(0, sim0[0] - T[q] + RR[t]);
} else if (A[q] >= lb) {
ans = max(0, simX[0] - T[q] + RR[t]);
} else if (t % 2 == 0) {
ans = max(0, simN[0] + A[q] - T[q] + RR[t]);
} else {
ans = max(0, simN[0] - A[q] - T[q] + RR[t]);
}
if (t % 2)
ans = X - ans;
ans.writeln;
}
long d0 = min(sim0[0], R[t]);
sim0[0] -= d0;
sim0[1] += d0;
swap(sim0[0], sim0[1]);
long dX = min(simX[0], R[t]);
simX[0] -= dX;
simX[1] += dX;
swap(simX[1], simX[0]);
simN[0] -= R[t];
simN[1] += R[t];
swap(simN[0], simN[1]);
if (t % 2 == 0)
ub = max(ub, -simN[1]);
else
lb = min(lb, simN[1]);
}
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto T = readln.chomp.to!int;
auto A = new int[](26);
auto B = new int[](26);
bool ok() {
return 26.iota.map!(i => A[i] >= B[i]).all;
}
while (T--) {
A[] = 0;
B[] = 0;
auto P = readln.chomp;
auto S = readln.chomp;
if (P.length > S.length) {
writeln("NO");
continue;
}
foreach (p; P) A[p-'a'] += 1;
foreach (i; 0..P.length) B[S[i]-'a'] += 1;
if (ok) {
writeln("YES");
continue;
}
bool hoge = false;
foreach (i; P.length..S.length) {
B[S[i]-'a'] += 1;
B[S[i-P.length.to!int]-'a'] -= 1;
if (ok) {
writeln("YES");
hoge = true;
break;
}
}
if (!hoge) {
writeln("NO");
}
}
}
|
D
|
import std.stdio;
void main() {
foreach (i; 0 .. 1000)
writeln("Hello World");
}
|
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
3 1 2
2 5 4
3 6
---+/
/+---test
4
2 3 4 1
13 5 8 24
45 9 15
---+/
/+---test
2
1 2
50 50
50
---+/
void main(string[] args) {
readln;
const A = readln.split.map!(x => x.to!long-1).array;
const B = readln.split.map!(to!long).array;
const C = readln.split.map!(to!long).array;
const N = A.length;
long ans = B[A[0]];
foreach (i; 1..N) {
ans += B[A[i]];
if (A[i-1]+1 == A[i]) {
ans += C[A[i-1]];
}
}
ans.writeln;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto X = readln.chomp.to!long;
long x = 100;
foreach (t; 1..10000) {
x = (x.to!double * 1.01).to!long;
if (x >= X) {
writeln(t);
return;
}
}
}
|
D
|
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);
void main() {
int n = read();
auto hs = reads();
int ans = 1;
foreach (i ; 1..n) {
ans += hs[0..i].reduce!(max) <= hs[i];
}
writeln(ans);
}
|
D
|
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }
void main(string[] args){
if(args.length > 1 && args[1] == "-debug"){
if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
else DEBUG_LEVEL = 1;
}
long n = read.to!long;
long m = read.to!long;
long a = 1, b = n;
foreach(i; 0 .. m){
long l = read.to!long;
long r = read.to!long;
if(l > a) a = l;
if(r < b) b = r;
}
long ans = b - a + 1;
if(ans < 0) ans = 0;
ans.writeln;
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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 A = RD;
auto B = RD;
auto C = RD;
auto K = RD;
while (A >= B)
{
B *= 2;
--K;
}
while (B >= C)
{
C *= 2;
--K;
}
writeln(K >= 0 ? "Yes" : "No");
stdout.flush;
debug readln;
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;
struct Word {
string s;
int last;
}
void main() {
int[char] v = [
'a' : 0,
'e' : 1,
'i' : 2,
'o' : 3,
'u' : 4
];
int vowel (char c) {
return v.get(c, -1);
}
immutable n = readln.strip.to!int;
auto a = new string[n];
size_t maxlen;
foreach (i; 0 .. n) {
a[i] = readln.strip;
maxlen = max(maxlen, a[i].length);
}
auto l = new int[][5 * (maxlen+1)];
foreach (i; 0 .. n) {
int t, last = -1;
foreach (c; a[i]) {
int x = vowel (c);
if (x >= 0){
++t;
last = x;
}
}
l[5 * t + last] ~= i;
}
alias T = Tuple!(int, int);
T[] b;
T[] c;
foreach (k; 1 .. maxlen+1) {
int[] tail;
foreach (i; 0 .. 5) {
auto idx = 5 * k + i;
int cur = -1;
foreach (j; l[idx]) {
if (cur >= 0) {
b ~= tuple (cur, j);
cur = -1;
} else {
cur = j;
}
}
if (cur >= 0) tail ~= cur;
}
foreach (i; 0 .. tail.length / 2) {
c ~= tuple (tail[2*i], tail[2*i+1]);
}
}
immutable bl = b.length;
immutable cl = c.length;
auto m = min (bl, (bl + cl) / 2);
c ~= b[m .. $];
writeln (m);
foreach (i; 0 .. m) {
int p12 = b[i][0], p22 = b[i][1];
int p11 = c[i][0], p21 = c[i][1];
writeln (a[p11], ' ', a[p12]);
writeln (a[p21], ' ', a[p22]);
}
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
int [] [] board;
foreach (row; 0..n * 2)
{
board ~= readln.splitter.map !(to !(int)).array;
}
auto res = 0L;
foreach (row; n..n * 2)
{
foreach (col; n..n * 2)
{
res += board[row][col];
}
}
res += min (board[n][0], board[$ - 1][0],
board[n][n - 1], board[$ - 1][n - 1],
board[0][n], board[n - 1][n],
board[0][$ - 1], board[n - 1][$ - 1]);
writeln (res);
}
}
|
D
|
void main() {
(ri < 1200 ? "ABC" : "ARC").writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
|
D
|
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.typecons, std.numeric, std.math;
void main()
{
auto nw = readln.split.to!(int[]);
auto N = nw[0];
auto W = nw[1];
int[] vs, ws;
foreach (_; 0..N) {
auto vw = readln.split.to!(int[]);
vs ~= vw[0];
ws ~= vw[1];
}
auto DP = new int[][](N+1, W+1);
foreach (i; 0..N) {
foreach (j; 0..W+1) {
auto w = j-ws[i];
if (w >= 0) {
DP[i+1][w] = max(DP[i+1][w], DP[i][j] + vs[i]);
}
DP[i+1][j] = max(DP[i+1][j], DP[i][j]);
}
}
int r = -1;
foreach (dp; DP[N]) r = max(r, dp);
writeln(r);
}
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n, m; readV(n, m);
auto c = new int[](n+1);
foreach (_; 0..m) {
int a, b; readV(a, b);
if (a == 1) c[b]++;
if (b == n) c[a]++;
}
writeln(c.canFind(2) ? "POSSIBLE" : "IMPOSSIBLE");
}
|
D
|
import std.stdio;
import std.typecons;
import std.algorithm;
void main() {
long n, m;
scanf("%ld %ld", &n, &m);
Tuple!(long, long)[] ss;
foreach(i;0..n) {
long a, b;
scanf("%ld %ld", &a, &b);
ss ~= tuple(a, b);
}
ss.sort!((a, b) => a[0] < b[0]);
long p;
foreach(s; ss) {
if (m <= 0) break;
p += s[0] * min(m, s[1]);
m -= s[1];
}
write(p);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Face = Tuple!(char, "dir", long, "num", bool, "edge");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
void main()
{
long n, k, i, cnt;
scan(n, k);
auto s = sread();
s ~= (s[n - 1] == 'R') ? 'L' : 'R';
auto f = new Face[](0);
while (++i < s.length)
{
if (s[i - 1] == s[i])
{
cnt++;
}
else
{
f ~= Face(s[i - 1], cnt + 1, false);
cnt = 0;
}
}
f[0].edge = true, f[$ - 1].edge = true;
f = f.filter!(x => x.dir != s[0]).array();
// f.each!(x => x.writeln());
long happy = n - 1;
f = f[min(k, f.length) .. $];
happy -= f.length * 2;
// f.writeln();
if(!f.empty && f[$ - 1].edge)
happy++;
happy.writeln();
}
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;
void main() {
int[32] a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
a[readln.chomp.to!int-1].writeln;
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.chomp;
foreach (i; 0..N-1) {
if (A[i] == '1' && A[i+1] == '1') {
writeln("No");
return;
}
}
foreach (i; 0..N) {
if (A[i] == '1') continue;
bool ok1 = (i == 0) || (i > 0 && A[i-1] == '0');
bool ok2 = (i == N-1) || (i < N-1 && A[i+1] == '0');
if (ok1 && ok2) {
writeln("No");
return;
}
}
writeln("Yes");
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
int N;
scan(N);
auto a = readln.split.to!(int[]);
a[] -= 1;
auto cnt = new long[](N);
foreach (ai ; a) {
cnt[ai]++;
}
long tot;
foreach (i ; 0 .. N) {
tot += cnt[i] * (cnt[i] - 1) / 2;
}
foreach (k ; 0 .. N) {
auto nm = a[k];
long ans;
if (cnt[nm] < 2) {
ans = tot;
}
else {
ans = tot - (cnt[nm] * (cnt[nm] - 1) / 2);
ans += (cnt[nm] - 1) * (cnt[nm] - 2) / 2;
}
writeln(ans);
}
}
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
void yes(bool ok, string y = "Yes", string n = "No") {
return writeln(ok ? y : n);
}
|
D
|
void main(){
int p, q, r;
scanf("%d %d %d", &p, &q, &r);
min(p+q, p+r, q+r).writeln();
}
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;
// 1要素のみの入力
T _scan(T= int)(){
return to!(T)( readln().chomp() );
}
// 1行に同一型の複数入力
T[] _scanln(T = int)(){
T[] ln;
foreach(string elm; readln().chomp().split()){
ln ~= elm.to!T();
}
return ln;
}
|
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;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
auto A = M.iota.map!(_ => readln.split.map!(to!int).array).array;
auto P = readln.split.map!(to!int).array;
int ans = 0;
foreach (mask; 0..(1<<N)) {
bool ok = true;
foreach (i; 0..M) {
int p = 0;
foreach (j; 1..A[i].length.to!int) {
int x = A[i][j] - 1;
if (mask & (1 << x)) {
p ^= 1;
}
}
if (p != P[i]) {
ok = false;
break;
}
}
ans += ok;
}
ans.writeln;
}
|
D
|
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, 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 N = readInt();
writeln(180 * (N - 2));
}
} catch (EOFException e) {
}
}
|
D
|
import std.stdio;
void main()
{
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);
printf("%d %d\n", n*m, 2*(n+m));
}
|
D
|
// Cheese-Cracker: cheese-cracker.github.io
void theCode(){
ll n = scan;
auto arr = scanArray;
ll odd = 0;
for(int i = 0; i < 2*n; ++i){
if(arr[i] % 2 == 1){
++odd;
}
}
if(odd == n){
writeln("Yes");
}else{
writeln("No");
}
}
void main(){
long tests = scan; // Toggle!
while(tests--) theCode();
}
/********* That's All Folks! *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x", long, "y");
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;
void main(){
auto n = readln().chomp().to!int();
auto s = readln();
solve(n, s).writeln();
}
int solve(int n, string s){
int[] kindNums;
foreach(cutPlace; 1..n) {
auto right = s[0..cutPlace];
auto left = s[cutPlace..$];
char[] collection;
foreach(ch; right) {
if(left.find(ch).length != 0){
if(collection.find(ch).length == 0){
collection ~= ch;
}
}
}
kindNums ~= collection.length.to!int();
}
return kindNums.sort!("a>b")()[0];
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.