code
stringlengths 4
1.01M
| language
stringclasses 2
values |
---|---|
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[]);
if (x[0]+x[1]<x[2] || x[0] > x[2]) {
writeln("NO");
} else {
writeln("YES");
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
long mod = 10^^9 + 7;
//long mod = 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 N = RD;
auto D = RD;
auto X = new long[](N);
auto Y = new long[](N);
foreach (i; 0..N)
{
X[i] = RD;
Y[i] = RD;
}
long ans;
foreach (i; 0..N)
{
if(X[i]^^2 + Y[i]^^2 <= D^^2)
++ans;
}
writeln(ans);
stdout.flush;
debug readln;
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;
alias FactorizeResult = ulong[101];
void main() {
const N = readln.chomp.to!int;
FactorizeResult table;
foreach (i; 1..N+1) {
table[] += primeFactorize(i)[];
}
ulong func(ulong i, int r) {
if (r > 75) return 0;
if (i == 101) {
return r == 75 ? 1 : 0;
}
ulong result = 0;
foreach (x; [0,2,4,14,24,74].filter!(y => y <= table[i])) {
result += memoize!func(i+1,r * (x+1));
}
return result;
}
writeln(func(0,1));
}
FactorizeResult primeFactorize(int x) {
if (x == 1) {
FactorizeResult result;
return result;
}
int y = 2;
while (true) {
if (x % y == 0) {
auto po = memoize!primeFactorize(x/y);
po[y]++;
return po;
} else {
y++;
}
}
}
|
D
|
void main()
{
long x = rdElem;
bool[] lists = new bool[x+1];
lists[1] = true;
for (long i = 2; i * i <= x; ++i)
{
for (long j = i * i; j <= x; j *= i)
{
lists[j] = true;
}
}
foreach_reverse (i, y; lists)
{
if (y)
{
i.writeln;
return;
}
}
}
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.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto b = RD!string;
if (b == "A")
writeln("T");
else if (b == "T")
writeln("A");
else if (b == "C")
writeln("G");
else
writeln("C");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
void main() {
auto N = readln.chomp.to!ulong;
ulong sum = 0;
for(ulong i=0; i<N; i++) {
sum += i;
}
writeln(sum);
}
|
D
|
import std.stdio;
import std.conv;
import std.algorithm;
import std.math;
void main() {
long n;
scanf("%ld", &n);
long m = long.max;
foreach(i; 1..n.to!double.sqrt.ceil.to!size_t+2) {
if (n % i == 0) {
m = min(i + n/i-2, m);
}
}
m.write;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main() {
while(true) {
string [] s = split(readln());
int H = to!int(s[0]);
int W = to!int(s[1]);
if(H==0 && W==0) break;
for(int i=0;i<H;i++) {
for(int j=0;j<W;j++) {
if(i==0 || i==H-1 || j==0 || j==W-1) {
write("#");
} else {
write(".");
}
}
writeln();
}
writeln();
}
}
|
D
|
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
void main() {
int n;
scanf("%d", &n);
int[] p = new int[n];
foreach(i; 0..n) {
scanf("%d", &p[i]);
p[i]--;
}
int[] a;
bool prev = true;
int s = 0;
bool judge(int[] a) {
//writeln(a);
int n = a.length.to!int;
if (n == 0) return true;
if (n%2 == 0) {
n--;
a = a[0..n];
}
foreach (i; 0..n) {
if (i%2 == 0) {
if (a[i] < 0 || a[i] >= n) return false;
if (a[i]%2 == 1) return false;
} else {
if (a[i] != i) return false;
}
}
int l = -1, r = -1;
foreach (i; 0..n) {
if (i%2) continue;
if (a[i] < i) {
if (a[i] < l) return false;
l = a[i];
} else {
if (a[i] < r) return false;
r = a[i];
}
}
return true;
}
foreach (i; 0..n) {
if (p[i] == i) {
if (prev) {
if (!judge(a)) {
writeln("No");
return;
}
a = new int[0];
s = i+1;
} else {
a ~= p[i]-s;
}
prev = true;
} else {
if (!prev) {
if (!judge(a)) {
writeln("No");
return;
}
a = new int[0];
s = i;
a ~= p[i]-i;
} else {
a ~= p[i]-s;
}
prev = false;
}
}
if (!judge(a)) {
writeln("No");
} else {
writeln("Yes");
}
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
ulong debt(ulong x, int n) {
if(n > 0) {
ulong m = x * 105 / 100;
if(m % 1000 > 0) m = (m / 1000 + 1) * 1000;
return debt(m, n - 1);
}
else return x;
}
void main() {
int n = to!int(chomp(readln()));
writeln(debt(100000, n));
}
|
D
|
void main() {
string s = readln.chomp;
writeln(s[0], s.length - 2, s[$-1]);
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.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 = 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 K = RD;
auto cnt = N / K;
auto ans = cnt^^3;
if (K % 2 == 0)
{
auto cnt2 = (N+K/2) / K;
ans += cnt2^^3;
}
writeln(ans);
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto X = RD;
long ans, pos;
foreach (i; 1..X+1)
{
pos += i;
if (pos >= X)
{
ans = i;
break;
}
}
writeln(ans);
stdout.flush();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
struct BloodData {
int number;
string bloodGroup;
}
void main() {
string[] input = new string[](2);
BloodData[] list;
int[] count = [0, 0, 0, 0];
while ((input = readln.chomp.split(",")).length != 0) {
BloodData temp = {number:input[0].to!int, bloodGroup:input[1]};
list ~= temp;
}
foreach (data; list) {
if (data.bloodGroup == "A") {
count[0]++;
} else if (data.bloodGroup == "B") {
count[1]++;
} else if (data.bloodGroup == "AB") {
count[2]++;
} else if (data.bloodGroup == "O") {
count[3]++;
}
}
foreach (num; count) {
writeln(num);
}
}
|
D
|
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
auto solve(string s_) {
auto NAB = s_.split.map!(to!long)();
immutable N=NAB[0], A=NAB[1], B=NAB[2];
if(A>B || (A<B && N<2)) return 0;
return (B-A)*(N-2)+1;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.range;
void main(){
auto N = readln.chomp.to!int;
if(N/10==9 || N%10==9) writeln("Yes");
else writeln ("No");
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
long n, k;
rd(n, k);
long tot = 0;
for (long a = 1; a <= n; a++) {
if ((a * 2) % k == 0) {
auto x = (a + n) / k - (a + 1 + k - 1) / k + 1;
tot += x * x;
}
}
writeln(tot);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
|
D
|
import std.stdio, std.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 = 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 A = RD;
auto B = RD;
auto ans = max(A, B) - min(A, B);
if (ans % 2 == 1)
writeln("IMPOSSIBLE");
else
writeln(max(A, B) - ans / 2);
stdout.flush();
debug readln();
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
auto n = lread();
long[] tmp = [1, 2, 4, 8, 16, 32, 64];
long ans = -1;
foreach (i; 0 .. tmp.length)
{
if (n >= tmp[i])
{
// writeln(tmp[i]);
ans = max(ans, tmp[i]);
}
}
writeln(ans);
}
long func(long n)
{
long cnt;
while (n % 2 == 0)
{
n /= 2;
cnt += 1;
}
return cnt;
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
void arywrite(T)(T a)
{
a.map!text.join(' ').writeln;
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
auto n = readln.chomp.to!int;
foreach (i; 0..n) {
readln.replace("Hoshino", "Hoshina").write;
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}
void main()
{
int n; readV(n);
auto a = new int[][](2); foreach (i; 0..2) readA(n, a[i]);
auto r = 0;
foreach (i; 0..n)
r = max(r, a[0][0..i+1].sum + a[1][i..$].sum);
writeln(r);
}
|
D
|
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n, m;
rd(n, m);
int[] a;
for (int i = 2; i * i <= m; i++) {
if (m % i == 0) {
int cnt = 0;
while (m % i == 0) {
cnt++;
m /= i;
}
a ~= cnt;
}
}
if (m > 1) {
a ~= 1;
}
const long mod = 10 ^^ 9 + 7;
const size_t M = 10 ^^ 5 * 2;
static long[M] fac, inv;
{ // init
fac[0] = fac[1] = 1;
foreach (i; 2 .. M)
fac[i] = i * fac[i - 1] % mod;
long _pow(long a, long x) {
if (x == 0)
return 1;
else if (x == 1)
return a;
else if (x & 1)
return a * _pow(a, x - 1) % mod;
else
return _pow(a * a % mod, x / 2);
}
foreach (i; 0 .. M)
inv[i] = _pow(fac[i], mod - 2);
}
long cmb(long nn, long rr) {
if (nn < rr)
return 0;
return fac[nn] * inv[rr] % mod * inv[nn - rr] % mod;
}
long tot = 1;
foreach (e; a) {
(tot *= cmb(e + n - 1, e)) %= 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;
void main()
{
int t;
scanf("%d", &t);
getchar();
foreach(_; 0..t)
{
int n;
scanf("%d", &n);
getchar();
auto d = n % 7;
if (d == 0)
writeln(n);
else {
int m = n % 10;
if (m >= d)
writeln(n - d);
else {
writeln(n + 7 - (n+7) % 7);
}
}
}
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
const xs = 5.iota.map!(_ => readln.chomp.to!int).array;
const k = readln.chomp.to!int;
foreach (i; 0..5) {
foreach (j; i+1..5) {
if (xs[j] - xs[i] > k) {
writeln(":(");
return;
}
}
}
writeln("Yay!");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;
void main()
{
readln;
int right;
int left;
auto s = readln.chomp;
foreach(c; s) {
if (c == '(') {
++right;
} else {
--right;
if (right < 0) {
++left;
right = 0;
}
}
}
writeln = '('.repeat.take(left).array ~ s ~ ')'.repeat.take(right).array;
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto abc = readln.split.to!(int[]);
writeln(abc[0] == abc[1] ? abc[2] : abc[0] == abc[2] ? abc[1] : abc[0]);
}
|
D
|
import std.stdio, std.array, std.conv, std.algorithm, std.string, std.numeric, std.range;
void main() {
auto a = readln.strip.to!int;
auto b = readln.strip.to!int;
auto c = readln.strip.to!int;
auto d = readln.strip.to!int;
auto e = readln.strip.to!int;
min(a*e, max(b,b+(e-c)*d)).writeln;
}
|
D
|
import std.algorithm;
import std.container;
import std.exception;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
immutable int MED_L = 1 << 17;
immutable int MAX_L = MED_L << 1;
void main ()
{
int n, m;
while (scanf (" %d %d", &n, &m) > 0)
{
auto a = new int [n];
foreach (i; 0..n)
{
scanf (" %d", &a[i]);
}
auto b = new int [n];
foreach (i; 0..n)
{
scanf (" %d", &b[i]);
}
auto x = new int [m];
auto y = new int [m];
auto z = new int [m];
auto t = new int [MAX_L];
t[] = -1;
void mark (int q, int lo, int hi)
{
lo += MED_L;
hi += MED_L;
while (lo <= hi)
{
if (lo & 1)
{
debug {writefln ("t[%s] = %s", lo, q);}
t[lo] = q;
lo++;
}
if (!(hi & 1))
{
debug {writefln ("t[%s] = %s", hi, q);}
t[hi] = q;
hi--;
}
lo >>= 1;
hi >>= 1;
}
}
int value (int p)
{
int res = b[p];
int q = -1;
for (int s = p + MED_L; s > 0; s >>= 1)
{
q = max (q, t[s]);
}
if (q != -1)
{
debug {writefln ("q = %s, p = %s", q, p);}
debug {writefln ("index = %s + %s - %s = %s",
x[q], p, y[q],
x[q] + p - y[q]);}
res = a[x[q] + p - y[q]];
}
return res;
}
foreach (j; 0..m)
{
int k;
scanf (" %d", &k);
if (k == 1)
{
scanf (" %d %d %d", &x[j], &y[j], &z[j]);
x[j]--;
y[j]--;
mark (j, y[j], y[j] + z[j] - 1);
}
else if (k == 2)
{
int p;
scanf (" %d", &p);
debug {writefln ("p = %d", p);}
p--;
int v = value (p);
printf ("%d\n", v);
}
else
{
assert (false);
}
}
}
}
|
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, k; readV(n, k); --k;
dchar[] s; readV(s);
s[k] = s[k].toLower;
writeln(s);
}
|
D
|
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
auto s = readln.strip;
if (s.all !(q{a != '>'}) || s.all !(q{a != '<'}))
{
writeln (n);
continue;
}
int res = n;
foreach (i; 0..n)
{
if (s[i] != '-' && s[(i + 1) % n] != '-')
{
res -= 1;
}
}
writeln (res);
}
}
|
D
|
void main()
{
dchar[] s = readln.chomp.to!(dchar[]);
if (s.length == 3) reverse(s);
s.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
string s;
scan(s);
int n = s.length.to!int + 1;
s = ">" ~ s ~ "<";
auto a = new int[](n);
a[] = inf;
int rec(int i) {
debug {
writeln("i: ", i);
}
if (a[i] != inf) {
return a[i];
}
a[i] = 0;
if (s[i] == '<') {
chmax(a[i], rec(i - 1) + 1);
}
if (s[i + 1] == '>') {
chmax(a[i], rec(i + 1) + 1);
}
return a[i];
}
long ans;
foreach (i ; 0 .. n) {
ans += rec(i);
}
debug {
writeln(a);
}
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
|
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;
T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }
void main()
{
auto N = RD!long;
long[char] cnt;
cnt['M'] = 0;
cnt['A'] = 0;
cnt['R'] = 0;
cnt['C'] = 0;
cnt['H'] = 0;
foreach (i; 0..N)
{
auto name = RD;
auto c = cnt.get(name[0], -1);
if (c != -1) ++cnt[name[0]];
}
long ans = 0;
auto keys = cnt.keys;
foreach (i; 0..5)
{
foreach (j; i+1..5)
{
foreach (k; j+1..5)
{
ans += cnt[keys[i]] * cnt[keys[j]] * cnt[keys[k]];
}
}
}
writeln(ans);
stdout.flush();
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.algorithm;
import std.range;
void main(){
auto A=readln.chomp.to!(char[]);
writeln(A.replace(","," "));
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
void main() {
auto ip = readln.split.to!(int[]),
A=ip[0],B=ip[1],C=ip[2],D=ip[3];
if(A+B>C+D) {
writeln("Left");
}
else if(A+B==C+D){
writeln("Balanced");
} else {
writeln("Right");
}
}
|
D
|
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
void main() {
auto l = readln.chomp.split.map!(to!int);
((l[0] * l[1]) % 2 ? "Odd" : "Even").writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
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(){
int a = read.to!int;
string s = readln.chomp;
if(a < 3200) s = "red";
s.writeln;
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.algorithm, std.math;
void main()
{
auto ns = readln.chomp;
auto ret = ns.count;
auto n = ns.to!ulong;
for (ulong a = 2; a^^2 <= n; ++a) {
if (n%a) continue;
auto b = n/a;
int i = 1;
for (; b > 9; ++i) b /= 10;
if (i < ret) ret = i;
}
writeln(ret);
}
|
D
|
/+ dub.sdl:
name "C"
dependency "dcomp" version=">=0.7.3"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
int main() {
Scanner sc = new Scanner(stdin);
string s;
sc.read(s);
int n = s.length.to!int;
int ans = 0;
int l = 0, r = n-1;
while (l < r) {
char c = s[l];
char d = s[r];
if (c == d) {
l++; r--;
continue;
}
if (c == 'x') {
ans++;
l++;
continue;
}
if (d == 'x') {
ans++;
r--;
continue;
}
writeln(-1);
return 0;
}
writeln(ans);
return 0;
}
/* IMPORT /home/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 /home/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 /home/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;
}
}
/*
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.algorithm, std.conv, std.array, std.string, std.math;
int[][52] SS;
dchar[52] CS;
long N = 1000000007;
void main()
{
auto n = readln.chomp.to!int;
auto s1 = readln.chomp.to!(dchar[]);
auto s2 = readln.chomp.to!(dchar[]);
auto j = 0;
for (auto i = 0; i < n; ++i) {
if (s1[i] == s2[i]) {
if (i == 0) {
SS[j] = [];
} else if (s1[i-1] == s2[i-1]) {
SS[j] = [j-1];
} else {
SS[j] = [j-2, j-1];
}
} else {
if (i == 0) {
SS[j++] = [];
SS[j] = [j-1];
} else if (s1[i-1] == s2[i-1]) {
SS[j] = [j-1];
++j;
SS[j] = [j-2, j-1];
} else {
SS[j] = [j-2];
++j;
SS[j] = [j-2, j-1];
}
++i;
}
++j;
}
long[immutable(dchar)[]][52] memo;
long solve(int i) {
if (i == n) return 1;
immutable(dchar)[] key;
foreach (j; (i-2 < 0 ? 0 : i-2)..i) key ~= CS[j];
if (key in memo[i]) return memo[i][key];
auto cls = 0b111;
foreach (j; SS[i]) {
switch (CS[j]) {
case 'R':
cls &= 0b011;
break;
case 'G':
cls &= 0b101;
break;
case 'B':
cls &= 0b110;
break;
default:
}
}
long ret;
if (cls & 0b100) {
CS[i] = 'R';
ret = (ret + solve(i+1)) % N;
}
if (cls & 0b010) {
CS[i] = 'G';
ret = (ret + solve(i+1)) % N;
}
if (cls & 0b001) {
CS[i] = 'B';
ret = (ret + solve(i+1)) % N;
}
return memo[i][key] = ret;
}
writeln(solve(0));
}
|
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 = "%.15f";
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 = 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 x = RD;
if (x > 1 && x < 2*N-1)
{
writeln("Yes");
auto ans = new long[](2*N-1);
auto M = 2*N-1;
auto mid = M / 2;
if (N == 2)
{
ans = [1, 2, 3];
}
else
{
foreach (i; mid..M)
{
ans[i] = (x+i-mid-1)%M+1;
}
foreach (i; 0..mid)
{
ans[i] = (x+mid+i)%M+1;
}
}
foreach (e; ans)
writeln(e);
}
else
writeln("No");
stdout.flush();
debug readln();
}
|
D
|
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
int N;
scan(N);
auto lb = (100 * N + 107) / 108;
auto ub = (100 * (N + 1) + 107) / 108;
foreach (x ; lb .. ub) {
if (x * 108 / 100 == N) {
writeln(x);
return;
}
}
writeln(":(");
}
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.string, std.conv, std.algorithm;
void main(){
auto a = readln.split.map!(to!int);
if(a[0]>a[1]) writeln("a > b");
else if(a[0]<a[1]) writeln("a < b");
else writeln("a == b");
}
|
D
|
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
void main() {
while(true) {
int n = readln.chomp.to!int;
if (n==0) break;
(n/4).iota.map!(_ => readln.chomp.to!int).reduce!"a+b".writeln;
}
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long n = lread();
auto s = new string[n];
foreach (ref e; s)
{
e = sread();
}
long count;
auto first_b = new long[n];
auto last_a = new long[n];
foreach (i, e; s)
{
foreach (j; 0 .. e.length - 1)
{
if (e[j .. j + 2] == "AB")
{
count++;
}
}
if (e[0] == 'B')
{
first_b[i]++;
}
if (e[$ - 1] == 'A')
{
last_a[i]++;
}
}
long allequal;
foreach (i; 0 .. n)
{
if (first_b[i] == last_a[i])
{
allequal++;
}
}
auto mintwo = min(first_b.sum, last_a.sum);
if (allequal == n && mintwo != 0)
{
count--;
}
writeln(count + mintwo);
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;
immutable int INF = 1 << 29;
void main() {
auto X = readln.chomp.to!long;
long[] F;
for (long i = 1; i * i <= X; ++i) {
if (X % i == 0) {
F ~= i;
if (i * i != X) {
F ~= X / i;
}
}
}
foreach (f; F) for (long a = f, b = 0; a^^5-b^^5 <= X; ++a, ++b) {
if (a^^5 - b^^5 == X) {
writeln(a, " ", b);
return;
}
}
foreach (f; F) for (long a = f-1, b = -1; a >= 0; --a, --b) {
if (a^^5 - b^^5 == X) {
writeln(a, " ", b);
return;
}
}
}
|
D
|
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!size_t;
auto co = 0, c2 = 0, c4 = 0;
auto rd = readln.splitter;
foreach (_; 0..n) {
auto a = rd.front.to!int; rd.popFront();
if (a % 2 != 0) ++co;
else if (a % 4 != 0) ++c2;
else ++c4;
}
writeln(c2 > 0 && co <= c4 || c2 == 0 && co <= c4+1 ? "Yes" : "No");
}
|
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() {
char[] ts;
ts = readln.chomp.to!(char[]);
long N = ts.length;
foreach(i; 0..N) {
if (ts[i] == '?') ts[i] = 'D';
}
ts.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 (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
|
import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.algorithm;
void main() {
auto input = readln.split.map!(to!int);
int K = input[0], S = input[1];
int ans = 0;
foreach (x; 0 .. K + 1) {
foreach (y; 0 .. K + 1) {
int z = S - (x + y);
if (z >= 0 && K >= z) {
ans++;
}
}
}
writeln(ans);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long a, b;
scan(a, b);
long d = b - a;
long ha = (d - 1) * d / 2;
writeln(ha - a);
}
|
D
|
import std.stdio, std.conv, std.string, std.math, std.algorithm;
void main(){
auto ip = readln.chomp;
if(ip[0] == 'H'){
if(ip[2] == 'H') 'H'.writeln;
else if(ip[2] == 'D') 'D'.writeln;
} else if(ip[0] == 'D') {
if(ip[2] == 'H') 'D'.writeln;
else if(ip[2] == 'D') 'H'.writeln;
}
}
|
D
|
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
while (true) {
auto rd = readln.split;
auto a = rd[0].to!int, op = rd[1], b = rd[2].to!int;
if (op == "?") break;
switch (op) {
case "+": writeln(a + b); break;
case "-": writeln(a - b); break;
case "*": writeln(a * b); break;
case "/": writeln(a / b); break;
default: assert(0);
}
}
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
void main(){
string s = readln.chomp;
int f = 0;
foreach(c; s){
if(f == 0 && c == 'C') f = 1;
if(f == 1 && c == 'F') f = 2;
}
string ans;
if(f == 2) ans = "Yes";
else ans = "No";
ans.writeln;
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto n = readln.strip.to !(int);
auto a = readln.splitter.map !(to !(int)).array;
int [] levels;
levels ~= 1;
int cur = 0;
int prev = 1;
foreach (i; 2..n)
{
if (a[i] < a[i - 1])
{
cur -= 1;
if (cur < 0)
{
levels ~= i - prev;
prev = i;
cur = levels.back - 1;
}
}
}
writeln (levels.length);
}
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;
void main(){
readln;
string[] inputs = readln.chomp.split;
writeln(solve(inputs));
}
string solve(in string[] inputs){
foreach(color; inputs) {
if(color == "Y"){
return "Four";
}
}
return "Three";
}
|
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.to!long;
long money = 100;
long cnt;
while (x > money) {
money = (money * 1.01).to!long;
cnt++;
}
cnt.writeln;
}
|
D
|
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;
void main() {
writeln("ABC"~readln.chomp);
}
|
D
|
import std;
alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
void main()
{
long n, m;
scan(n, m);
// writeln(n, m);
auto 正解したか = new bool[](n + 1);
auto WAの回数 = new long[](n + 1);
foreach (_; 0 .. m)
{
long p;
string s;
scan(p, s);
// writeln(p, s);
if ((正解したか[p] == false) && (s == "WA"))
{
WAの回数[p] += 1;
}
else if (s == "AC")
{
正解したか[p] = true;
}
}
// writeln(正解したか);
// writeln(WAの回数);
long 正解数, ペナルティ;
foreach (i; 0 .. 正解したか.length)
{
正解数 += 正解したか[i];
}
// writeln(正解数);
foreach (i; 0 .. WAの回数.length)
{
if (正解したか[i] == true)
{
ペナルティ += WAの回数[i];
}
}
writeln(正解数, ' ', ペナルティ);
}
void scan(L...)(ref L A)
{
auto l = readln.split;
foreach (i, T; L)
{
A[i] = l[i].to!T;
}
}
|
D
|
void main() {
problem();
}
void problem() {
auto N = scan!ulong;
ulong solve() {
auto primes = primeFactoring(N);
int[ulong] primeCounts;
foreach(p; primes) {
primeCounts[p]++;
}
ulong answer;
foreach(p; primeCounts.keys) {
const count = primeCounts[p];
int sumCount;
foreach(i; 1..count+1) {
sumCount += i;
if (sumCount > count) break;
answer++;
}
}
return answer;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
ulong[] primeFactoring(ulong target)
{
ulong s = target.to!float.sqrt().floor.to!ulong;
ulong num = target;
ulong[] primes;
for (ulong i = 2; i <= s; i++) {
if (num % i != 0) continue;
while (num%i == 0) {
num /= i;
primes ~= i;
}
}
if (num > s) primes ~= num;
return primes;
}
// -----------------------------------------------
|
D
|
import std.stdio, std.string, std.algorithm, std.range, std.conv, std.typecons, std.math;
void main(){
auto x = readln.chomp.to!int;
writeln(x < 1200 ? "ABC" : "ARC");
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on
void main()
{
auto 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
];
long K = lread();
writeln(A[K - 1]);
}
|
D
|
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;
long check(long n)
{
long i=1;
while(n>0)
{
n-=i;
i++;
}
return n==0?i:-1;
}
void main()
{
auto N = scanElem;
if(N==1)
{
writeln("Yes");
writeln("2");
writeln("1 1");
writeln("1 1");
return;
}
long k = check(N);
if(k==-1)
{
writeln("No");
return;
}
writeln("Yes");
writeln(k);
long[] space = [0];
foreach(i; 0..k)
{
write(k-1);
write(" ");
foreach(s; space)
{
write(s+1);
write(" ");
}
foreach(n; 1..k-space.length)
{
write(space[$-1]+n+1);
write(" ");
}
writeln("");
space ~= space[$-1]+k-1-i;
space[0..$-2]+=1;
if(i==k-2) space=space[0..$-1];
}
}
class UnionFind{
UnionFind parent = null;
void merge(UnionFind a)
{
if(same(a)) return;
a.root.parent = this.root;
}
UnionFind root()
{
if(parent is null)return this;
return parent = parent.root;
}
bool same(UnionFind a)
{
return this.root == a.root;
}
}
void scanValues(TList...)(ref TList list)
{
auto lit = readln.splitter;
foreach (ref e; list)
{
e = lit.fornt.to!(typeof(e));
lit.popFront;
}
}
T[] scanArray(T = long)()
{
return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
t.length = n;
foreach (ref e; t)
{
auto line = readln.split;
foreach (i, ref v; e.tupleof)
{
v = line[i].to!(typeof(v));
}
}
}
T scanElem(T = long)()
{
char[] res;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
res ~= cast(char) c;
c = getchar;
}
return res.strip.to!T;
}
template fold(fun...) if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
static if (S.length < 2)
{
return reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
struct Factor
{
long n;
long c;
}
Factor[] factors(long n)
{
Factor[] res;
for (long i = 2; i ^^ 2 <= n; i++)
{
if (n % i != 0)
continue;
int c;
while (n % i == 0)
{
n = n / i;
c++;
}
res ~= Factor(i, c);
}
if (n != 1)
res ~= Factor(n, 1);
return res;
}
long[] primes(long n)
{
if(n<2)return [];
auto table = new long[n+1];
long[] res;
for(int i = 2;i<=n;i++)
{
if(table[i]==-1) continue;
for(int a = i;a<table.length;a+=i)
{
table[a] = -1;
}
res ~= i;
}
return res;
}
bool isPrime(long n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i ^^ 2 <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
|
D
|
import std.stdio, std.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; }
/*
ナップサック問題(価値の上限が小さい)
xs[i][v]: i番目まで(index <= i)で、価値vを達成するのに必要な容量
xs[0][0] = 0
xs[0][v] = infinity
xs[i][v] = min(
ws[i], // i個目を取る前提 v - vs[i] < 0 の場合
xs[i - 1][v - vs[i]] + ws[i], // i個目を取る前提 v - vs[i] >= 0
xs[i - 1][v] // i個目を取らない前提
)
求めるものは
xs[n - 1][v] <= npw であるような最大のv
*/
void main(){
long n = read.to!long;
long npw = read.to!long;
long[] ws, vs;
foreach(i; 0 .. n){
ws ~= read.to!long;
vs ~= read.to!long;
}
long infty = npw * 100;
long vmax;
foreach(v; vs) vmax += v;
long[][] xs = [[0]];
foreach(v; 1 .. vmax + 1) xs[0] ~= infty;
foreach(i; 0 .. n){
long[] q = [];
foreach(v; 0 .. vmax + 1){
q ~= min(
xs[$ - 1][v],
(v - vs[i] < 0)? ws[i]: xs[$ - 1][v - vs[i]] + ws[i]
);
}
debug writeln("q:", q, " i:", i);
xs ~= q;
}
long ans;
foreach(v; 0 .. vmax + 1) if(xs[n][v] <= npw) ans = v;
ans.writeln;
}
|
D
|
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
long n, m;
long cal(long use)
{
long s = n + use / 2;
long c2 = (m - use) / 2;
return min(s, c2);
}
void main() {
auto nm = readln.chomp.split.map!(to!long);
n = nm[0];
m = nm[1];
long left = 0;
long right = m + 1;
while (right - left > 2) {
long midL = (left * 2 + right) / 3;
long midR = (left + right * 2) / 3;
long resL = midL.cal;
long resR = midR.cal;
if (resL < resR) {
left = midL;
} else {
right = midR;
}
}
debug stderr.writeln([left, right]);
debug stderr.writeln([left.cal, cal((left * 2 + right) / 3), cal((left + right * 2) / 3), right.cal]);
// cal((left + right * 2) / 3) がそれ? よく分からないので全部試す…
long ans = 0;
for (long ite = left; ite < right; ++ite) {
ans = max(ans, ite.cal);
}
ans.writeln;
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void minAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) min(dst, src);
}
void maxAssign(T, U = T)(ref T dst, U src)
{
dst = cast(T) max(dst, src);
}
void main()
{
long x, a, b;
scan(x, a, b);
long z = b - a;
if (z <= 0)
{
writeln("delicious");
return;
}
bool c = z <= x;
writeln(c ? "safe" : "dangerous");
}
|
D
|
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
void main() {
auto abc = readints;
int a = abc[0], b = abc[1], c = abc[2];
writeln(b - a == c - b ? "YES" : "NO");
}
|
D
|
void main() {
problem();
}
void problem() {
auto L = scan!long;
auto R = scan!long;
auto d = scan!long;
long solve() {
long ans;
foreach(i; L..R+1) {
if (i % d == 0) ans++;
}
return ans;
}
solve().writeln;
}
// ----------------------------------------------
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
// -----------------------------------------------
|
D
|
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void main()
{
int n; readV(n);
long[] a; readA(n, a);
auto b = cumulativeSum(a), m = 10L^^18;
foreach (i; 1..n)
m = min(m, (b[0..i] - b[i..$]).abs);
writeln(m);
}
class CumulativeSum(T)
{
size_t n;
T[] s;
this(T[] a)
{
n = a.length;
s = new T[](n+1);
s[0] = T(0);
foreach (i; 0..n) s[i+1] = s[i] + a[i];
}
T opSlice(size_t l, size_t r) { return s[r]-s[l]; }
size_t opDollar() { return n; }
}
auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto xy = readln.split.to!(long[]);
auto X = xy[0];
auto Y = xy[1];
auto a = X;
long r;
while (a <= Y && a ) {
++r;
a *= 2;
}
writeln(r);
}
|
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() {
immutable long MOD = 10^^9 + 7;
auto N = readln.chomp.to!int;
auto A = N.iota.map!(_ => readln.chomp.to!long).array;
auto X = A.reduce!"a^b"();
auto B = new bool[](40);
foreach (a; A) B[bsf(a)] = true;
int ans = 0;
foreach_reverse (i; 0..33) {
if ((X >> i) & 1) {
if (!B[i]) {
writeln(-1);
return;
}
ans += 1;
X ^= (1L << (i + 1)) - 1;
}
}
writeln(X == 0 ? ans : -1);
}
|
D
|
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void main()
{
auto nk = readln.split.to!(int[]);
writeln(nk[0] - nk[1] + 1);
}
|
D
|
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void 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);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
long N = lread();
long pt, px, py;
foreach (_; 0 .. N)
{
long t, x, y;
scan(t, x, y);
long d = abs(px - x) + abs(py - y);
// writeln(d);
if (t - pt < d)
{
writeln("No");
return;
}
if (((t - pt) - d) % 2 == 1)
{
writeln("No");
return;
}
pt = t;
px = x;
py = y;
}
writeln("Yes");
}
|
D
|
import std.stdio,std.conv,std.string;
void main(){
int sum;
auto N = readln().chomp().to!int();
auto list = readArray!int();
foreach( elm ; list ){
while( elm%2 == 0 ){
elm /= 2;
sum++;
}
}
writeln(sum);
}
T[] readArray(T)(){
T[] ret;
foreach( elm ; readln().split() ){
ret ~= elm.to!T();
}
return ret;
}
|
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!long;
long r;
foreach (x; 1..N) {
if (x^^2 > N) break;
if (N%x == 0) {
auto m = N/x - 1;
if (x*m + x == N && N/m == N%m) r += m;
}
}
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[] 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 X = lread();
while (true)
{
long l = factorize(X).length;
if (l == 1)
{
writeln(X);
return;
}
X++;
}
}
/// 素因数分解
long[] factorize(long x)
{
assert(0 < x, "x is negative");
long[] result;
while ((x & 1) == 0)
{
x /= 2;
result ~= 2;
}
for (long i = 3; i * i <= x; i += 2)
while (x % i == 0)
{
x /= i;
result ~= i;
}
if (x != 1)
result ~= x;
return result;
}
|
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 x = RD;
auto a = RD;
auto b = RD;
writeln(abs(x - a) < abs(x - b) ? "A" : "B");
stdout.flush();
debug readln();
}
|
D
|
import std;
bool calc(int k, int a, int b) {
return a <= b / k * k;
}
void main() {
int k; scan(k);
int a, b; scan(a, b);
writeln(calc(k, a, b) ? "OK" : "NG");
}
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 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;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
alias sread = () => readln.chomp();
enum MOD = 10 ^^ 9 + 7;
void main()
{
auto S = sread();
solve(S).writeln();
}
string solve(string S)
{
long a = S[0 .. 2].to!long();
long b = S[2 .. $].to!long();
if ((12 < a && b == 0) || (12 < b && a == 0) || (12 < a && 12 < b) || S == "0000")
return "NA";
if (a <= 12 && b <= 12 && !(a == 0 || b == 0))
return "AMBIGUOUS";
if (a <= 12 && a != 0)
return "MMYY";
return "YYMM";
}
|
D
|
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
void main(){
string s = readln.chomp;
int[] ans = [-1, -1];
// search for "aa"
for(int i = 0; i < s.length - 1; i ++){
if(s[i] == s[i + 1]) ans = [i + 1, i + 2];
}
// search for "aba"
for(int i = 0; i < s.length - 2; i ++){
if(s[i] == s[i + 2]) ans = [i + 1, i + 3];
}
ans.map!(to!string).join(" ").writeln;
}
|
D
|
import std.stdio; // readln
import std.array; // split
import std.conv; // to
import std.typecons;
bool[][] g;
void main(){
string[] s = split(readln());
int N = to!int(s[0]);
int M = to!int(s[1]);
g = new bool[][](N,N);
alias Tuple!(int,int) pair;
pair[] p = new pair[](M);
for(int i = 0; i < M; i++){
s = split(readln());
int a = to!int(s[0]);
int b = to!int(s[1]);
a--; b--;
p[i] = pair(a,b);
g[a][b] = g[b][a] = true;
}
int cnt = 0;
for(int i = 0; i < M; i++){
bool[] used = new bool[](N);
foreach (ref elem; used) {
elem = false;
}
g[p[i][0]][p[i][1]] = g[p[i][1]][p[i][0]] = 0;
dfs(0,used);
g[p[i][0]][p[i][1]] = g[p[i][1]][p[i][0]] = 1;
if(!check(used)){
cnt++;
}
}
writeln(cnt);
}
void dfs(int cur, bool[] used){
used[cur] = true;
for(int i = 0; i < g.length; i++){
if(g[cur][i] && !used[i]){
dfs(i, used);
}
}
}
bool check(bool[] used){
for(int i = 0; i < used.length; i++){
if(!used[i]) return false;
}
return true;
}
|
D
|
void main(){
string n = readln().chomp();
int cnt, ans;
foreach(i; 0..n.length){
if(cnt==0)cnt++;
else if(n[i-1]==n[i])cnt++;
else cnt=1;
ans = max(cnt, ans);
}
( ans>=3?"Yes":"No" ).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, std.numeric;
void main()
{
auto N = readln.chomp.to!int;
foreach (x; N..1000) {
if (x/100 == (x/10)%10 && (x/10)%10 == x%10) {
writeln(x);
return;
}
}
}
|
D
|
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string s = readln.chomp;
writeln(s[0 .. 4], " ", s[4 .. $]);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.string, std.algorithm, std.range, std.conv, std.typecons, std.math;
void main(){
auto S = readln.chomp;
ulong min = 0, max = 0;
foreach (i,c; S) {
if (c == 'A') {
min = i;
break;
}
}
foreach_reverse (i,c; S) {
if (c == 'Z') {
max = i;
break;
}
}
writeln(max - min + 1);
}
|
D
|
import std.stdio;
import std.conv;
import std.array;
void main()
{
int N = readln.split[0].to!int;
auto reader = readln.split;
int[] a = new int[N];
for(uint i = 0; i < N; i++){
a[i] = reader[i].to!int;
}
int cnt = 0;
for(uint i = 0; i < N; i++){
if (a[i] != i + 1) cnt++;
}
if (cnt == 0 || cnt == 2){
writeln("YES");
} else {
writeln("NO");
}
}
|
D
|
import std.stdio;
void main() {
auto s = readln();
if(s[2]==s[3] && s[4]==s[5]) writeln("Yes");
else writeln("No");
}
|
D
|
void main()
{
long a = rdElem, b = rdElem, c = rdElem;
long s = 3 * c;
long[][] x = new long[][](3, 3);
x[0][0] = a, x[0][1] = b, x[0][2] = s - a - b;
x[1][0] = 4 * c - 2 * a - b, x[1][1] = c, x[1][2] = 2 * a + b - 2 * c;
x[2][0] = a + b - c, x[2][1] = s - b - c, x[2][2] = s - a - c;
x.wrMat;
}
enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;
T rdElem(T = long)()
if (!is(T == struct))
{
return readln.chomp.to!T;
}
alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);
T rdElem(T)()
if (is(T == struct))
{
T result;
string[] input = rdRow!string;
assert(T.tupleof.length == input.length);
foreach (i, ref x; result.tupleof)
{
x = input[i].to!(typeof(x));
}
return result;
}
T[] rdRow(T = long)()
{
return readln.split.to!(T[]);
}
T[] rdCol(T = long)(long col)
{
return iota(col).map!(x => rdElem!T).array;
}
T[][] rdMat(T = long)(long col)
{
return iota(col).map!(x => rdRow!T).array;
}
void rdVals(T...)(ref T data)
{
string[] input = rdRow!string;
assert(data.length == input.length);
foreach (i, ref x; data)
{
x = input[i].to!(typeof(x));
}
}
void wrMat(T = long)(T[][] mat)
{
foreach (row; mat)
{
foreach (j, compo; row)
{
compo.write;
if (j == row.length - 1) writeln;
else " ".write;
}
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;
|
D
|
import std.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;
void main() {
auto N = readln.chomp.to!int;
auto X = new long[](N);
auto S = new long[](N);
foreach (i; 0..N) {
auto s = readln.split.map!(to!long);
X[i] = s[0];
S[i] = s[1];
}
long[] Y;
foreach (i; 0..N) {
Y ~= S[i];
if (i < N - 1) Y ~= X[i] - X[i+1];
}
long ans = 0;
long tmp = 0;
for (int i = 0, j = 0; i < N * 2 - 1; ++i) {
if (j < i) {
j = i;
tmp = 0;
}
while (j < N * 2 - 1 && tmp + Y[j] >= 0) {
tmp += Y[j];
++j;
ans = max(ans, tmp);
}
}
ans.writeln;
}
|
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;
char last;
int cnt;
foreach (c; S) {
if (c != last) ++cnt;
last = c;
}
writeln(cnt);
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
void main() {
int times;
while((times = readln.chomp.to!(int)) != 0){
char[] str = cast(char[])readln.chomp;
for(int i = 0; i < times; i++) {
char[] next_str;
char prev;
uint n = 1;
prev = str[0];
foreach(s; str[1..$]) {
if (prev == s) ++n;
else {
next_str ~= text(n, prev);
prev = s;
n = 1;
}
}
next_str ~= text(n, prev);
str = next_str;
}
writeln(str);
}
}
|
D
|
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
void main()
{
auto n = readln.chomp.to!int;
foreach (_; 0..n) {
auto str = readln.chomp;
char[] res;
res ~= str[0];
char pre = res[0];
for (int p = 1; p < str.length; p += 3) {
if (str[p..p+2] == "->" && res[$-1] == pre) {
res ~= str[p+2];
} else if (str[p..p+2] == "<-" && res[0] == pre) {
res = str[p+2] ~ res;
}
pre = str[p+2];
}
res.writeln;
}
}
|
D
|
import std.stdio, std.math, std.conv, std.array, std.string, std.algorithm;
void main() {
string str;
while((str = readln()).length != 0) {
double v = to!double(str.chomp);
double t = (v/9.8)^^2 * 4.9;
int nt = to!int(floor(to!real(t)));
int h = nt + (5 - nt%5);
writeln((h+5)/5);
}
}
|
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 n = RD!string;
foreach (c; n)
{
ans[ti].chmax(c-'0');
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
|
D
|
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
std.random, std.typecons, std.container;
ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
long cnt;
void main()
{
auto x = lread();
long th = x / 500;
long five = (x - 500 * th) / 5;
writeln(1000 * th + 5 * five);
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
|
D
|
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
int n;
scan(n);
int ans;
foreach (i ; 0 .. n + 1) {
if (i*i <= n) {
ans = i*i;
}
else {
break;
}
}
writeln(ans);
}
void scan(T...)(ref T args) {
string[] line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
|
D
|
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable long MOD = 10^^9 + 7;
void main() {
auto s = readln.split;
auto N = s[0].to!int;
auto L = s[1].to!long;
auto A = s[2].to!long;
long[] T, X;
foreach (i; 0..N) {
s = readln.split;
T ~= s[0].to!long;
X ~= s[1].to!long;
}
T ~= L;
X ~= 0;
long t = 0;
long ans = 0;
foreach (i; 0..N+1) {
long interaval = T[i] - t;
ans += interaval / A;
t = T[i] + X[i];
}
ans.writeln;
}
|
D
|
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
immutable int dirs = 4;
immutable int [dirs] dRow = [ -1, 0, +1, 0];
immutable int [dirs] dCol = [ 0, -1, 0, +1];
immutable char [dirs] dName = ['N', 'W', 'S', 'E'];
void main ()
{
auto tests = readln.strip.to !(int);
foreach (test; 0..tests)
{
auto s = readln.strip;
alias Coord = Tuple !(int, q{row}, int, q{col});
auto cur = Coord (0, 0);
bool [Coord] vis;
int res = 0;
foreach (char c; s)
{
auto dir = dName[].countUntil (c);
cur.row += dRow[dir];
cur.col += dCol[dir];
res += (cur in vis) ? 1 : 5;
vis[cur] = true;
cur.row += dRow[dir];
cur.col += dCol[dir];
}
writeln (res);
}
}
|
D
|
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD!int;
auto s = RD!string;
long[2] ans;
foreach (i; 1..N)
{
if (s[i-1] > s[i])
{
ans = [i-1, i];
break;
}
}
if (ans == [0, 0])
writeln("NO");
else
{
writeln("YES");
writeln(ans[0]+1, " ", ans[1]+1);
}
stdout.flush();
debug readln();
}
|
D
|
import std.stdio;
import std.ascii;
import std.algorithm;
import std.array;
import core.stdc.stdio;
int main()
{
int t = readInt!int;
while(t--)
{
string astr = readString;
auto a = new int[](astr.length);
auto count = new int[](4);
foreach(i, ref ai; a)
{
switch(astr[i])
{
case 'A': ai = 0; break;
case 'N': ai = 1; break;
case 'T': ai = 2; break;
case 'O': ai = 3; break;
default: assert(0);
}
count[ai]++;
}
long minops = long.min;
int[] minA;
foreach(test; [[0, 1, 2, 3],[0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1],
[1, 0, 2, 3], [1, 0, 3, 2], [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], [1, 3, 2, 0],
[2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0], [2, 3, 0, 1], [2, 3, 1, 0],
[3, 0, 1, 2], [3, 0, 2, 1], [3, 1, 0, 2], [3, 1, 2, 0], [3, 2, 0, 1], [3, 2, 1, 0]])
{
int[] testOrig;
foreach(ti; test)
{
foreach(i; 0 .. count[ti])
{
testOrig ~= ti;
}
}
long value = fixString(testOrig, a);
if (value > minops)
{
minops = value;
minA = testOrig;
}
}
string mapi = "ANTO";
string ans;
foreach(ai; minA)
{
ans ~= mapi[ai];
}
writeln(ans);
}
return 0;
}
long fixString(int[] orig, int[] dest)
{
int[][] pos = new int[][](4);
auto ft = FT(cast(int)orig.length);
foreach(i, a; dest)
{
pos[a] ~= cast(int) i;
}
long res = 0;
foreach(i, a; orig)
{
int posCh = pos[a][0];
pos[a] = pos[a][1 .. $];
ft.add(posCh, 1);
res += posCh - ft.sum(0, posCh - 1);
}
return res;
}
struct FT {
int[] bit;
int n;
this(int n) {
this.n = n;
bit = new int[](n);
}
int sum(int r) {
int ret = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
ret += bit[r];
return ret;
}
int sum(int l, int r) {
return sum(r) - sum(l - 1);
}
void add(int idx, int delta) {
for (; idx < n; idx = idx | (idx + 1))
bit[idx] += delta;
}
};
/* INPUT ROUTINES */
int currChar;
static this()
{
currChar = getchar();
}
char topChar()
{
return cast(char) currChar;
}
void popChar()
{
currChar = getchar();
}
auto readInt(T)()
{
T num = 0;
int sgn = 0;
while (topChar.isWhite) popChar;
while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
if (sgn) return -num; return num;
}
string readString()
{
string res = "";
while (topChar.isWhite) popChar;
while (!topChar.isWhite) { res ~= topChar; popChar; }
return res;
}
|
D
|
module main;
import std.stdio : writeln, stdin;
import core.stdc.stdio;
int main(string[] argv)
{
int n, l, r;
scanf("%d %d %d", &n, &l, &r);
l = l - 1;
r = r - 1;
int [] arr = new int[n];
int [] b = new int[n];
for(int i = 0; i<n; i++)
scanf("%d", &arr[i]);
for (int i = 0; i < n; i++)
scanf("%d", &b[i]);
for (int i = 0; i < l; i++) {
if (arr[i] != b[i]) {
writeln("LIE");
return 0;
}
}
for (int i = r + 1; i < n; i++) {
if (arr[i] != b[i]) {
writeln("LIE");
return 0;
}
}
writeln("TRUTH");
return 0;
}
|
D
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.