code
stringlengths 4
1.01M
| language
stringclasses 2
values |
---|---|
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() {
string s;
long k;
scan(s);
scan(k);
k--;
int pos = -1;
char nm = '1';
foreach (i ; 0 .. s.length) {
if (s[i] != '1') {
nm = s[i];
pos = i.to!int;
break;
}
}
if (nm == '1') {
writeln(1);
}
else {
if (k < pos) {
writeln(1);
}
else {
writeln(nm);
}
}
}
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;
void main(){
auto input=readln.chomp.split;
auto n=input[0].to!ulong;
auto a=input[1].to!ulong;
auto b=input[2].to!ulong;
auto ans=n/(a+b)*a;
ans+=n%(a+b)>a?a:n%(a+b);
writeln(ans);
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;
void main()
{
auto xyz = readln.split.to!(int[]);
int c;
xyz[0] -= xyz[2];
while (xyz[0] >= xyz[1] + xyz[2]) {
xyz[0] -= (xyz[1] + xyz[2]);
++c;
}
writeln(c);
} | 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()
{
string s = sread();
foreach (c; s)
if (c == '1')
{
write('9');
}
else if (c == '9')
{
write('1');
}
else
{
write(c);
}
writeln();
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
import std.numeric;
long a, b, x, y; rd(a, b, x, y);
auto g=gcd(x, y);
x/=g; y/=g;
writeln(min(a/x, b/y));
}
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
int[2][10^^5*2] DP;
void main()
{
auto S = readln.chomp.to!string;
foreach_reverse (i; 0..S.length) {
if (i == S.length-1) {
DP[i][0] = 1;
DP[i][1] = int.min;
} else if (i == S.length-2) {
DP[i][0] = S[i] == S[i+1] ? int.min : 2;
DP[i][1] = 1;
} else {
if (S[i] == S[i+1]) {
DP[i][0] = DP[i+1][1] + 1;
} else {
DP[i][0] = max(DP[i+1][0], DP[i+1][1]) + 1;
}
if (i >= S.length-3 || (DP[i] == DP[i+2] && S[i+1] == S[i+3])) {
DP[i][1] = DP[i+2][0] + 1;
} else {
DP[i][1] = max(DP[i+2][0], DP[i+2][1]) + 1;
}
}
}
writeln(max(DP[0][0], DP[0][1]));
} | 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);
}
enum MOD = (10 ^^ 9) + 7;
void main()
{
auto A = BigInt(readln().chomp());
auto B = BigInt(readln().chomp());
auto c = A.opCmp(B);
// writeln(c);
switch (c)
{
case -1:
writeln("LESS");
break;
case 0:
writeln("EQUAL");
break;
case 1:
writeln("GREATER");
break;
default:
assert(0);
}
}
| D |
void main() {
int n = readln.chomp.to!int;
if (n == 1) {
"Hello World".writeln;
} else {
writeln(readln.chomp.to!int + readln.chomp.to!int);
}
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons; | D |
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
void main() {
auto N = readln.chomp.to!int;
int ds(int x) {
int ret = 0;
while (x > 0) ret += x % 10, x /= 10;
return ret;
}
int ans = 1 << 29;
foreach (i; 1..N) {
int j = N - i;
ans = min(ans, ds(i) + ds(j));
}
ans.writeln;
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
void main() {
int N = to!int(chomp(readln()));
int res;
for(int i = 0; i <= N; i++) {
res += i;
}
res.writeln;
}
| D |
/+ dub.sdl:
name "C"
dependency "dunkelheit" version=">=0.9.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;
int main() {
Scanner sc = new Scanner(stdin);
scope(exit) assert(!sc.hasNext);
int n;
sc.read(n);
int[] a, b;
sc.read(a, b);
bool check(long f) {
long[51] g;
foreach (i; 0..51) {
long v = (1L << i);
foreach (j; 1..51) {
if (!(f & (1L << j))) continue;
v |= g[i % j];
}
g[i] = v;
}
foreach (i; 0..n) {
int x = a[i], y = b[i];
if (!(g[x] & (1L << y))) return false;
}
return true;
}
long z = 0;
foreach (i; 1..52) {
if (check(z)) break;
if (i == 51) {
writeln("-1");
return 0;
}
z |= (1L << i);
}
foreach_reverse (i; 1..51) {
if (!(z & (1L << i))) continue;
z ^= (1L << i);
if (check(z)) continue;
z ^= (1L << i);
}
writeln(z);
return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
import core.exception : RangeError;
private T* _data;
private uint len, cap;
@property bool empty() const { return len == 0; }
@property size_t length() const { return len; }
alias opDollar = length;
inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
ref inout(T) opIndex(size_t i) inout {
version(assert) if (len <= i) throw new RangeError();
return _data[i];
}
ref inout(T) front() inout { return this[0]; }
ref inout(T) back() inout { return this[$-1]; }
void reserve(size_t newCap) {
import core.memory : GC;
import core.stdc.string : memcpy;
import std.conv : to;
if (newCap <= cap) return;
void* newData = GC.malloc(newCap * T.sizeof);
cap = newCap.to!uint;
if (len) memcpy(newData, _data, len * T.sizeof);
_data = cast(T*)(newData);
}
void free() {
import core.memory : GC;
GC.free(_data);
}
void clear() {
len = 0;
}
void insertBack(T item) {
import std.algorithm : max;
if (len == cap) reserve(max(cap * 2, MINCAP));
_data[len++] = item;
}
alias opOpAssign(string op : "~") = insertBack;
void removeBack() {
assert(!empty, "StackPayload.removeBack: Stack is empty");
len--;
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */
// module dkh.foundation;
static if (__VERSION__ <= 2070) {
/*
Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
*/
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;
// import dkh.container.stackpayload;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
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 {
StackPayload!E buf;
while (succW()) {
buf ~= line.parse!E;
}
x = buf.data;
}
} else {
x = line.parse!T;
}
return true;
}
int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
void read(Args...)(auto ref Args args) {
import std.exception;
static if (args.length != 0) {
enforce(readSingle(args[0]));
read(args[1..$]);
}
}
bool hasNext() {
return succ();
}
}
/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
| D |
import std.stdio,std.conv,std.string;
void main()
{
auto num = readln.strip.to!long;
if (num < 1200) {
writeln("ABC");
}
else if (num < 2800) {
writeln("ARC");
}
else {
writeln("AGC");
}
}
| D |
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.numeric;
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);
int[] a; readA(n, a);
writeln(a.reduce!gcd);
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int m; rd(m);
writeln(24+(24-m));
}
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, 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, c, d; readV(a, b, c, d);
writeln((a-c).abs <= d || (a-b).abs <= d && (b-c).abs <= d ? "Yes" : "No");
}
| D |
import std.stdio,std.string,std.conv;
int main()
{
string[char] ID;
ID[' '] = "101";
ID['\''] = "000000";
ID[','] = "000011";
ID['-'] = "10010001";
ID['.'] = "010001";
ID['?'] = "000001";
ID['A'] = "100101";
ID['B'] = "10011010";
ID['C'] = "0101";
ID['D'] = "0001";
ID['E'] = "110";
ID['F'] = "01001";
ID['G'] = "10011011";
ID['H'] = "010000";
ID['I'] = "0111";
ID['J'] = "10011000";
ID['K'] = "0110";
ID['L'] = "00100";
ID['M'] = "10011001";
ID['N'] = "10011110";
ID['O'] = "00101";
ID['P'] = "111";
ID['Q'] = "10011111";
ID['R'] = "1000";
ID['S'] = "00110";
ID['T'] = "00111";
ID['U'] = "10011100";
ID['V'] = "10011101";
ID['W'] = "000010";
ID['X'] = "10010010";
ID['Y'] = "10010011";
ID['Z'] = "10010000";
string[string] Id;
Id["00000"] = "A";
Id["00001"] = "B";
Id["00010"] = "C";
Id["00011"] = "D";
Id["00100"] = "E";
Id["00101"] = "F";
Id["00110"] = "G";
Id["00111"] = "H";
Id["01000"] = "I";
Id["01001"] = "J";
Id["01010"] = "K";
Id["01011"] = "L";
Id["01100"] = "M";
Id["01101"] = "N";
Id["01110"] = "O";
Id["01111"] = "P";
Id["10000"] = "Q";
Id["10001"] = "R";
Id["10010"] = "S";
Id["10011"] = "T";
Id["10100"] = "U";
Id["10101"] = "V";
Id["10110"] = "W";
Id["10111"] = "X";
Id["11000"] = "Y";
Id["11001"] = "Z";
Id["11010"] = " ";
Id["11011"] = ".";
Id["11100"] = ",";
Id["11101"] = "-";
Id["11110"] = "'";
Id["11111"] = "?";
string s;
string str = "";
while((s = readln.chomp).length != 0)
{
foreach(i;0..s.length)
{
str ~= ID[s[i]];
}
while(str.length % 5 != 0)
{
str ~= "0";
}
string ans = "";
while(str.length != 0)
{
string temp = str[0..5];
ans ~= Id[temp];
str = str[5..$];
}
ans.writeln;
}
return 0;
} | D |
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
void main() {
string n = readln.chomp;
writeln(n.canFind('9') ? "Yes" : "No");
}
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 chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {
}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
str ~= s.to!(char[]).strip.split;
}
}
// }}}
void main() {
auto cin = new Scanner;
char[] s;
cin.scan(s);
size_t N = s.length;
size_t M = (N - 1) / 2;
size_t L = (N + 3) / 2;
char[] t = s[0 .. M];
char[] u = s[L - 1 .. $];
auto s_r = s.dup;
s_r.reverse;
auto t_r = t.dup;
t_r.reverse;
auto u_r = u.dup;
u_r.reverse;
if (s == s_r && t == t_r && u == u_r) {
writeln("Yes");
} else {
writeln("No");
}
}
| D |
void main() {
auto N = ri;
fact(N).writeln;
}
ulong fact(ulong n) {
if(n<=1) return 1;
else return n*fact(n-1)%(10UL^^9 + 7);
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
}
| D |
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;
enum INF = long.max/3;
enum MOD = 10L^^9+7;
//辞書順順列はiota(1,N),nextPermituionを使う
void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
import core.stdc.stdlib;
writeln(v);
exit(0);
}
T[] scanArray(T = long)()
{
static char[] scanBuf;
readln(scanBuf);
return scanBuf.split.to!(T[]);
}
dchar scanChar()
{
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
return cast(dchar)c;
}
T scanElem(T = long)()
{
import core.stdc.stdlib;
static auto scanBuf = appender!(char[])([]);
scanBuf.clear;
int c = ' ';
while (isWhite(c) && c != -1)
{
c = getchar;
}
while (!isWhite(c) && c != -1)
{
scanBuf ~= cast(char) c;
c = getchar;
}
return scanBuf.data.to!T;
}
dchar[] scanString(){
return scanElem!(dchar[]);
}
void main()
{
end((scanElem+scanElem)*scanElem/2);
}
| D |
const long mod=998244353;
const int M=1_000_00*4;
void main(){
import std.stdio, std.algorithm;
long n, a, b, k; rd(n, a, b, k);
auto fact=genFact(M, mod);
auto invFact=genInv(fact, mod);
long comb(long nn, long rr){
if(nn<rr) return 0;
long ret=fact[nn]%mod;
(ret*=invFact[rr])%=mod;
(ret*=invFact[nn-rr])%=mod;
return ret;
}
long tot=0;
for(long x=0; x<=n; x++)if(k-a*x>=0){
if((k-a*x)%b==0){
long y=(k-a*x)/b;
if(y>n) continue;
(tot+=comb(n, x)*comb(n, y)%mod)%=mod;
}
}
writeln(tot);
}
long[] genFact(int n, long mod){
auto fact=new long[](n);
fact[0]=fact[1]=1;
foreach(i; 2..n) fact[i]=i*fact[i-1]%mod;
return fact;
}
long[] genInv(long[] arr, long mod){
auto inv=new long[](arr.length);
inv[0]=inv[1]=1;
foreach(i, elem; arr[1..$]) inv[i]=powmod(arr[i], mod-2, mod);
return inv;
}
long powmod(long a, long x, long mod){
if(x==0) return 1;
else if(x==1) return a;
else if(x&1) return a*powmod(a, x-1, mod)%mod;
else return powmod(a*a%mod, x/2, mod);
}
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;
import std.string;
enum conv = [
'I':1,
'V':5,
'X':10,
'L':50,
'C':100,
'D':500,
'M':1000
];
void main()
{
foreach (input; stdin.byLine()){
int total = 0;
if (input.length == 1)
total = conv[input[0]];
else {
foreach (i; 1..input.length) {
if (conv[input[i - 1]] < conv[input[i]]) {
total -= conv[input[i - 1]];
} else {
total += conv[input[i - 1]];
}
}
total += conv[input[$ - 1]];
}
total.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();
long bignum = 1_000_000_007;
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;
}
}
auto manhattan(long x1, long y1, long x2, long y2)
{
return abs(y2 - y1) + abs(x2 - x1);
}
void main()
{
auto n = lread();
auto t = lread();
long c_multiple;
foreach (i; 1 .. n)
{
auto clock = lread();
auto tmp = gcd(t, clock);
t = t / tmp * clock;
}
t.writeln();
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!int;
writeln(n * 800 - (n/15) * 200);
}
| D |
import std.stdio, std.array, std.conv, std.string;
void main() {
string[] input = split(readln());
int[] a = new int[3];
for (int i = 0; i < 3; ++i) {
a[i] = to!int(input[i]);
}
if (a[0] < a[1] && a[1] < a[2]) {
writeln("Yes");
} else {
writeln("No");
}
} | D |
import std.stdio, std.conv, std.string;
void main()
{
auto ip = readln.split.to!(int[]), n = ip[0], m = ip[1];
writeln((n - 1)*(m - 1));
} | D |
import std.stdio,std.string,std.conv,std.algorithm;
void main(){
auto readline = to!int(readln().chomp());
for( ; 0 < readline ; readline-- ){
auto arr = readln().chomp().split();
check( to!int(arr[0]),to!int(arr[1]),to!int(arr[2]));
}
}
void check(int x,int y,int z){
if( x*x+y*y==z*z || x*x+z*z==y*y || y*y+z*z==x*x ){
writeln("YES");
}else{
writeln("NO");
}
} | D |
import std.stdio, std.conv, std.string, std.algorithm, std.range;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.chomp.to!int;
writeln(N % 500 <= A ? "Yes" : "No");
}
| D |
import std.stdio, std.conv, std.string, std.algorithm,
std.math, std.array, std.container, std.typecons;
void main() {
auto s = readln.chomp;
auto t = readln.chomp[0..$-1];
if(s==t) writeln("Yes");
else writeln("No");
}
| D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
void main()
{
auto n = readln.chomp.to!int;
auto a = new int[](n+1);
long res;
foreach (i; 1..n+1) {
a[i] = readln.chomp.to!int;
if (a[i-1]) {
auto num = min(a[i-1], a[i]);
a[i-1] -= num;
a[i] -= num;
res += num;
}
auto num = a[i] / 2;
res += num;
a[i] = a[i] % 2;
}
res.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 t = RD!int;
auto ans = new string[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto s = RD!string;
int l = n, r = -1;
foreach (int i; 0..n)
{
if (s[i] == '1')
{
l = i;
break;
}
}
foreach_reverse (int i; 0..n)
{
if (s[i] == '0')
{
r = i;
break;
}
}
if (l < r)
ans[ti] = s[0..l] ~ '0' ~ s[r+1..s.length];
else
ans[ti] = s[0..l] ~ s[r+1..s.length];
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
| D |
import std.stdio;
import core.stdc.stdio;
import std.typecons;
import std.algorithm;
void main(){
int n;
long h;
scanf("%d%lld",&n,&h);
long[] ds = new long[n];
long[] hs = new long[n-1];
for(int i=0;i<n-1;i++)
scanf("%lld%lld",&ds[i+1],&hs[i]);
for(int i=1;i<n;i++)
ds[i] += ds[i-1];
//ds.writeln;
long heal=0;
long ans=0;
int b=0;
int e=0;
alias Tuple!(int,"prev",int,"next") pn;
pn[] list = new pn[n];
for(int i=0;i<n;i++)
list[i] = pn(i,i);
for(int s=1;s<n;s++){
/*
s.writeln;
writeln(b," ",e," ",list[b].next);
writeln("heal ",heal);
writeln;
*/
while(h<=ds[s]-heal){
while(list[b].next != b){
int k = list[b].next;
if(min(ds[b]-heal,hs[b])<=min(ds[k]-heal,hs[k]))
b=k;
else
break;
}
list[b].prev = b;
long t = min(ds[b]-heal,ds[s]-heal-h+1);
//t.writeln;
if(t>=hs[b]){
long c = t/hs[b];
ans += c;
heal += hs[b]*c;
}else{
ans++;
heal += min(ds[b]-heal,hs[b]);
}
}
if(s==n-1)
break;
list[s].prev = e;
list[e].next = s;
e = s;
while(1){
int k=list[e].prev;
if(hs[k]<=hs[e]){
if(k==b){
list[e].prev = e;
b=e;
break;
}else{
list[e].prev = list[k].prev;
list[list[e].prev].next = e;
}
}else
break;
}
//writeln;
}
printf("%lld\n",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;
import std.container;
alias sread = () => readln.chomp();
long bignum = 1_000_000_007;
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
long a, b, c, k;
scan(a, b, c, k);
if (k % 2)
writeln(b - a);
else
writeln(a - b);
}
| D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
void solve()
{
auto N = readln.chomp.to!int;
auto ps = readln.split.to!(int[]);
auto ii = new size_t[](N);
foreach (i, ref p; ps) {
p -= 1;
ii[p] = i;
}
auto bs = new bool[](N);
size_t i = ii[0];
int n;
for (;;) {
bs[i] = true;
++i;
++n;
if (n == N) break;
if (i == N || bs[i]) {
i = ii[n];
continue;
}
if (ps[i] != n) {
writeln("No");
return;
}
}
writeln("Yes");
}
void main()
{
auto T = readln.chomp.to!int;
foreach (_t; 0..T) {
solve();
}
} | 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[] args) {
int n = readln.chomp.to!int;
string p = readln.chomp;
string s = readln.chomp;
for(int i = 0; i < n; i++){
if(p[i..$] == s[0..$-i]){
writeln(n+i);
return;
}
}
writeln(2*n);
} | D |
import std.stdio,
std.string,
std.conv;
void main() {
int[] buf = readln.chomp.split.to!(int[]);
int N = buf[0], A = buf[1], B = buf[2];
int d = B - A;
writeln(d & 1 ? "Borys" : "Alice");
}
| D |
import std.stdio, std.string, std.array, std.conv, std.algorithm;
void main() {
int n = readln.chomp.to!int;
string a = readln.chomp.split.join;
int m = readln.chomp.to!int;
string b = readln.chomp.split.join;
writeln(a < b ? 1 : 0);
}
| D |
import std.stdio;
import std.conv;
import std.string;
void main() {
string s;
while((s = readln()).length != 0) {
int [] c = [500, 100, 50, 10, 5, 1];
int res = 0;
int a;
a = to!int(chomp(s));
if(a == 0) break;
a = 1000 - a;
for(int i = 0; i < c.length; i++) {
if(a >= c[i]) {
res++;
a -= c[i];
i--;
}
}
writeln(res);
}
} | 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, d0; readV(n, d0);
int[] d; readA(n, d);
int nq; readV(nq);
int[] q; readA(nq, q);
auto a = new int[](n+1);
a[0] = d0;
foreach (i; 0..n)
a[i+1] = d[i] < a[i]*2 ? (a[i]-d[i]).abs : a[i];
auto b = new int[](n+1);
b[n] = 1;
foreach_reverse (i; 0..n)
b[i] = b[i+1] <= d[i]/2 ? b[i+1] : b[i+1]+d[i];
foreach (qi; q)
writeln(a[qi-1] >= b[qi] ? "YES" : "NO");
}
| D |
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to
void main()
{
string s = chomp(readln());
for(int i=0; i<18; ++i){
if(i == 5 || i == 13){
write(" ");
} else {
write(s[i]);
}
}
writeln(s[18]);
} | D |
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
long a, b, c, d;
scan(a, b, c, d);
if (a + b == c + d)
{
writeln("Balanced");
return;
}
if (a + b < c + d)
{
writeln("Right");
return;
}
writeln("Left");
}
| D |
import std.functional,
std.algorithm,
std.container,
std.typetuple,
std.typecons,
std.bigint,
std.string,
std.traits,
std.array,
std.range,
std.stdio,
std.conv,
std.format,
std.math;
void main()
{
auto o = readln.chomp;
auto e = readln.chomp;
string p;
if(o.length - e.length == 0){
foreach(i; 0..e.length){
p ~= o[i];
p ~= e[i];
}
}else{
foreach(i; 0..o.length){
p ~= o[i];
p ~= e[i];
}
p.popBack();
}
writeln(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;
alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Goods = Tuple!(long, "w", long, "v");
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 s = sread();
long cnt, left, right = s.length - 1;
bool batch = true;
while (left <= right)
{
if (s[left] == s[right])
left++, right--;
else if (s[left] == 'x')
cnt++, left++;
else if (s[right] == 'x')
cnt++, right--;
else
{
batch = false;
break;
}
}
if (batch)
writeln(cnt);
else
writeln(-1);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void main(){
auto ip1 = readln.chomp.to!int;
auto ip2 = readln.chomp.to!int;
auto ip3 = readln.chomp.to!int;
auto ip4 = readln.chomp.to!int;
(min(ip1, ip2) + min(ip3, ip4)).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 t = RD!int;
auto ans = new string[](t);
foreach (ti; 0..t)
{
auto n = RD!int;
auto s = RD!string;
foreach (i; 0..n)
{
ans[ti] ~= s[$/2];
}
}
foreach (e; ans)
writeln(e);
stdout.flush;
debug readln;
}
| D |
// Vicfred
// https://atcoder.jp/contests/abc176/tasks/abc176_c
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;
void main() {
long n = readln.chomp.to!long;
long[] a = readln.split.map!(to!long).array;
long last = a[0];
long ans = 0;
for(int i = 1; i < n; i++) {
if(a[i] < last)
ans += last - a[i];
else
last = a[i];
}
ans.writeln;
}
| D |
import std.stdio;
import std.string;
import std.conv;
void main() {
int c = 0;
int[] numstack;
string[] opstack;
int calc() {
ulong i = 0;
int x = numstack[i++];
foreach (op; opstack) {
switch (op) {
case "+":
x += numstack[i++];
break;
case "-":
x -= numstack[i++];
break;
case "*":
x *= numstack[i++];
break;
case "/":
x /= numstack[i++];
default: break;
}
}
return x;
}
for (int i = 0; ; i++) {
if (i % 2 == 0) {
int n = stdin.readln.chomp.to!int;
numstack ~= n;
} else {
string op = stdin.readln.chomp;
if (op == "=") {
calc.writeln;
break;
}
else opstack ~= op;
}
}
} | D |
import std.stdio; // ??\????????????????????????
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
import std.algorithm; // map?????????????????????
void main() {
int S = readln.chomp.to!int;
int h = S / 3600;
S = S - h * 3600;
int m = S / 60;
S = S - m * 60;
writeln(h, ":", m, ":", S);
} | D |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto a = readln.split.to!(int[]);
auto ch = ['A', 'B', 'C'];
auto mx = a.reduce!(max);
foreach (i; 0 .. 3) {
if (a[i] == mx) {
writeln(ch[i]);
return;
}
}
}
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 core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;
alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias SugarWater = Tuple!(long, "swater", long, "sugar");
T lread(T = long)()
{
return readln.chomp.to!T();
}
T[] aryread(T = long)()
{
return readln.split.to!(T[])();
}
void scan(TList...)(ref TList Args)
{
auto line = readln.split();
foreach (i, T; TList)
{
T val = line[i].to!(T);
Args[i] = val;
}
}
void main()
{
auto s = sread();
auto cost_right = new long[](s.length);
auto cost_left = new long[](s.length);
auto iter = iota(0, s.length);
long count;
foreach (i; iter)
{
if (s[i] == 'L')
cost_left[i] = ++count;
else
{
count = 0;
}
}
count = 0;
foreach_reverse (i; iter)
{
if (s[i] == 'R')
cost_right[i] = ++count;
else
{
count = 0;
}
}
auto ans = new long[](s.length);
foreach (i; iter)
{
if (s[i] == 'R')
{
if (cost_right[i] % 2)
ans[i + cost_right[i] - 1]++;
else
ans[i + cost_right[i]]++;
}
else
{
if (cost_left[i] % 2)
ans[i - cost_left[i] + 1]++;
else
ans[i - cost_left[i]]++;
}
}
formatwrite(ans);
// cost_left.writeln();
// cost_right.writeln();
}
void formatwrite(T)(T a)
{
foreach (i, e; a)
{
if (i != a.length - 1)
e.write(" ");
else
e.writeln();
}
} | D |
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.typecons;
void main()
{
auto n = readln.chomp.to!int;
int min, max = -1;
foreach (_; 0..n) {
auto ab = readln.split.to!(int[]);
if (ab[0] > max) {
max = ab[0];
min = ab[1];
}
}
writeln(max + min);
} | 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();
auto tmp = new long[](10 ^^ 5);
foreach (i; 1 .. 101)
{
foreach (j; 1 .. 101)
{
foreach (k; 1 .. 101)
{
long tmptmp;
tmptmp = i ^^ 2 + j ^^ 2 + k ^^ 2 + i * j + i * k + j * k;
if (tmptmp <= 10 ^^ 4)
{
tmp[tmptmp] += 1;
}
}
}
}
foreach (i; 1 .. n + 1)
{
writeln(tmp[i]);
}
}
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 |
void main()
{
long n = readln.chomp.to!long;
long a, b, ab;
long cnt;
foreach (i; 0 .. n)
{
string s = readln.chomp;
cnt += s.count("AB");
if (s[$-1] == 'A' && s[0] == 'B') ++ab;
else if (s[$-1] == 'A') ++a;
else if (s[0] == 'B') ++b;
}
if (ab > 0)
{
cnt += ab - 1;
if (max(a, b) > 0) cnt += min(a, b) + 1;
}
else
{
cnt += min(a, b);
}
cnt.writeln;
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
import std.stdio;
import std.string;
import std.algorithm;
import std.exception;
import std.conv;
import std.array;
import std.range;
int toplamGuzellikSayisi = 0;
void main() {
auto satirSayisi = stdin.readln.strip.to!int();
char[] hulkunHisleri;
for ( int i = 0; i < satirSayisi; i++ )
{
if ( i == satirSayisi - 1 )
{
if ( i % 2 )
hulkunHisleri ~= "I love it ";
else
hulkunHisleri ~= "I hate it ";
}
else if ( i % 2 )
hulkunHisleri ~= "I love that ";
else
hulkunHisleri ~= "I hate that ";
}
writeln(hulkunHisleri.chomp());
} | D |
void main() {
bool n, w, s, e;
auto S = rs;
foreach(c; S) {
switch(c) {
case 'N': n = true; break;
case 'W': w = true; break;
case 'S': s = true; break;
case 'E': e = true; break;
default: assert(0);
}
}
if(n && !s || !n && s || w && !e || !w && e) writeln("No");
else writeln("Yes");
}
// ===================================
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;
T readAs(T)() if (isBasicType!T) {
return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
return readln.split.to!T;
}
T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
res[i] = readAs!(T[]);
}
return res;
}
T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
auto res = new T[][](height, width);
foreach(i; 0..height) {
auto s = rs;
foreach(j; 0..width) res[i][j] = s[j].to!T;
}
return res;
}
int ri() {
return readAs!int;
}
double rd() {
return readAs!double;
}
string rs() {
return readln.chomp;
} | D |
// Your code here!
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.conv;
import std.string;
void main(){
auto ab = readln().chomp().split().map!(to!long);
auto a = ab[0];
auto b = ab[1];
solve(a, b).writeln();
}
long solve(long a, long b){
auto eastIdx = b - a;
long westLength = iota(1, eastIdx).sum;
return westLength - a;
} | D |
import std;
void main() {
auto N = readln.split[0].to!long;
auto A = readln.split.to!(long[]);
ulong[long] Aminus;
foreach (j; 0 .. N) {
if (j-A[j] !in Aminus) Aminus[j-A[j]] = 0;
Aminus[j-A[j]]++;
}
ulong ans;
foreach (i; 0 .. N) {
if (A[i]+i !in Aminus) continue;
ans += Aminus[A[i]+i];
}
writeln(ans);
}
| D |
void main() {
auto c = readMatrix!char(3, 3);
foreach(i; 0..3) c[i][i].write;
writeln;
}
// ===================================
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.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.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
void main() {
auto ABN = readln.split.to!(long[]);
auto A = ABN[0], B = ABN[1], N = ABN[2];
auto x = min(B-1, N);
writeln(cast(long) (floor(cast(double) A * cast(double) x / cast(double) B) - A * cast(double) floor(cast(double) x / cast(double) B)));
}
| D |
import std.stdio, std.string, std.conv;
void main()
{
readln().chomp().toUpper().writeln();
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto N = RD;
auto D = RD;
auto X = RD;
foreach (i; 0..N)
{
auto a = RD;
long b = 1;
++X;
while (b + a <= D)
{
++X;
b += a;
}
}
writeln(X);
stdout.flush();
debug readln();
}
| D |
void main() {
writeln(readln.split.join.to!int % 4 == 0 ? "YES" : "NO");
}
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni; | D |
void main()
{
dchar[] s = readln.chomp.to!(dchar[]);
long k = readln.chomp.to!long;
long n = s.length;
foreach (i, ref x; s)
{
if (i == n - 1)
{
s[i] = ((s[i] - 'a' + (k % 26)) % 26 + 'a').to!dchar;
}
else
{
long m = (26 - (s[i] - 'a')) % 26;
if (k >= m)
{
s[i] = 'a';
k -= m;
}
else
{
continue;
}
}
}
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.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto s = RD!string;
char best = s[0];
writeln("Mike");
foreach (c; s[1..$])
{
if (c <= best)
{
writeln("Mike");
}
else
{
writeln("Ann");
}
best = min(best, c);
}
stdout.flush();
debug readln();
} | D |
import std.stdio, std.algorithm, std.range, std.conv, std.string;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln
const int INF = 1_000_000_007;
void main() {
int n;
scanf("%d", &n);
int[] a = new int[n];
foreach (i; 0..n) scanf("%d", &a[i]);
int p = 0, m = -INF; long val = -INF;
foreach (parity; 0..2) {
long sum = 0;
int mx = -INF;
foreach (i; 0..n) {
if ((i&1) != parity) continue;
if (a[i] > 0) sum += a[i];
else mx = max(mx, a[i]);
}
if (sum == 0) sum = mx;
if (val < sum) {
p = parity;
val = sum;
if (sum == mx) m = mx;
else m = -INF;
}
}
writeln(val);
int[] ans;
int len = n;
int head = 0;
foreach_reverse (i; 0..n) {
if ((i&1) != p) continue;
if (a[i] <= 0) {
if (a[i] == m) {
m = -INF;
} else {
ans ~= i+1;
if (i == n-1) len--;
else if (i == 0) len--, head = 1;
else len -= 2;
}
}
}
if (p != head) ans ~= 1, len--;
foreach (i; 0..len/2) ans ~= 2;
writeln(ans.length);
foreach (i; ans) writeln(i);
}
| 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() {
string s;
scan(s);
auto ok = s[0] == 'A' && s[2 .. $ - 1].count!"a == 'C'" == 1;
foreach (ch ; s) {
if (ch == 'A' || ch == 'C') continue;
ok &= ('a' <= ch && ch <= 'z');
}
writeln(ok ? "AC" : "WA");
}
int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new int[][](n, 0);
foreach (i; 0 .. m) {
int u, v;
scan(u, v);
if (is1indexed) {
u--, v--;
}
adj[u] ~= v;
if (isUndirected) {
adj[v] ~= u;
}
}
return adj;
}
alias Edge = Tuple!(int, "to", int, "cost");
Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
auto adj = new Edge[][](n, 0);
foreach (i; 0 .. m) {
int u, v, c;
scan(u, v, c);
if (is1indexed) {
u--, v--;
}
adj[u] ~= Edge(v, c);
if (isUndirected) {
adj[v] ~= Edge(u, c);
}
}
return adj;
}
void yes(bool b) {
writeln(b ? "Yes" : "No");
}
void YES(bool b) {
writeln(b ? "YES" : "NO");
}
T[] readArr(T)() {
return readln.split.to!(T[]);
}
T[] readArrByLines(T)(int n) {
return iota(n).map!(i => readln.chomp.to!T).array;
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x > arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) {
if (x < arg) {
x = arg;
isChanged = true;
}
}
return isChanged;
}
| D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto n = RD!int;
writeln(n % 2 != 0 ? 0 : 2^^(n/2));
stdout.flush();
debug readln();
} | D |
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;
string FMT_F = "%.10f";
static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }
//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void main()
{
auto s = RD!string;
auto len = s.length;
bool flag;
foreach (i; 0..len)
{
if (i == 0) continue;
if (s[i] == '1')
{
flag = true;break;
}
}
auto ans = (len-1) / 2;
if (flag || (len-1) % 2 != 0)
{
++ans;
}
writeln(ans);
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;
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 n = lread();
auto s = new long[](n);
foreach (ref e; s)
e = lread();
auto score = s.sum();
if (!(score % 10))
{
long subscore;
foreach (e; s)
{
auto tmp = score - e;
if (tmp % 10)
subscore = max(tmp, subscore);
}
if(subscore)
score = subscore;
else
score = 0;
}
score.writeln();
}
| D |
import std.stdio;
import std.string;
void main(){
int w, h;
while(true){
scanf("%d %d", &h, &w);
if (w == 0 && h == 0) break;
foreach(i; 0..h){
foreach(j; 0..w){
write("#");
}
writeln();
}
writeln();
}
} | D |
import std.stdio,std.string,std.conv;
int main()
{
int sum = 0,count = 0;
double num = 0;
string s;
while((s = readln.chomp).length != 0)
{
count++;
string[] _s = s.split(",");
sum += _s[0].to!int * _s[1].to!int;
num += _s[1].to!int;
}
sum.writeln;
writeln(cast(int)((num/count) + 0.5));
return 0;
} | D |
import std.stdio, std.conv, std.array, std.algorithm, std.string, std.math;
void main() {
string s;
while ((s = readln()).length != 0) {
int[] nx;
if (to!uint(s.chomp) == 0) {break;}
for (uint i = 0; i < to!uint(s.chomp); ++i) {
nx ~= to!int(readln().chomp);
}
writeln(solve(nx));
}
}
int solve(int[] tx) {
if (negative_all(tx)) {
int max = -100000;
foreach(n ; tx) {
if (n > max) {
max = n;
}
}
return max;
}
int[] nx = reduce_by_sign(tx);
if (nx.length == 1) { return nx[0]; }
if (nx[0] < 0) { nx = nx[1..(nx.length)]; }
if (nx[nx.length-1] < 0) { nx = nx[0..(nx.length-1)]; }
/*for (uint i = 0; i < nx.length; ++i) {
if (nx[i] < 0) {
if (nx[i-1] >= abs(nx[i]) && nx[i+1] >= abs(nx[i])) {
int t = nx[i-1] + nx[i] + nx[i+1];
if (i+2 < nx.length) {
nx = nx[0..i-1] ~ [t] ~ nx[i+2..nx.length];
} else {
nx = nx[0..i-1] ~ [t];
}
}
}
}
int max = 0;
foreach(n ; nx) {
if (max < n) {
max = n;
}
}*/
int max = nx[0];
for (uint i = 0; i < nx.length; ++i) {
int max_ = nx[i];
int acc = max_;
for (uint j = i+1; j < nx.length; ++j) {
acc = acc + nx[j];
if (acc > max_) { max_ = acc; }
}
if (max_ > max) { max = max_; }
}
return max;
}
bool negative_all(int[] nx) {
foreach(n ; nx) {
if (n > 0) {
return false;
}
}
return true;
}
int[] reduce_by_sign(int[] nx) {
bool sign = (nx[0] >= 0);
uint index = 0;
int[] ret = [nx[0]];
for (uint i = 1; i < nx.length; ++i) {
if (sign != (0 <= nx[i])) {
sign = !sign;
ret ~= 0;
++index;
}
ret[index] += nx[i];
}
return ret;
} | 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 a,b,c;
scan(a,b,c);
auto t =[a + b, a + c, b + c];
t.reduce!(min).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;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){}
void jury(){}
void solve(){
long n = scan!long;
long ans;
foreach(long d; 1 .. n + 1){
long k = n / d;
// d + 2d + 3d + ... + kd
ans += d * k * (k + 1) / 2;
}
ans.writeln;
}
| 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(){
long n, m;
{
long[] tmp = readln.chomp.split.map!(to!long).array;
n = tmp[0], m = tmp[1];
}
long ans;
/*
long x = n * 2 + m;
long y = x / 4;
if(y > n) ans = y;
else ans = m / 2;
*/
if(n < m / 2) ans = n + (m - n * 2) / 4;
else ans = m / 2;
ans.writeln;
} | D |
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
std.typecons, std.container, std.format;
static import std.ascii;
// 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();
auto A = lreads(N);
auto m1 = new long[](N + 1);
m1[] = long.min;
auto m2 = new long[](N + 1);
m2[] = long.min;
foreach (i; 0 .. N)
{
m1[i + 1] = max(m1[i], A[i]);
}
foreach_reverse (i; 0 .. N)
{
m2[i] = max(m2[i + 1], A[i]);
}
foreach (i; 0 .. N)
{
max(m1[i], m2[i + 1]).writeln();
}
}
| 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 N = readln.split.to!(ulong[]);
string solve() {
if (N[0] == N[1] && N[0] == N[2]) return "No";
if (N[0] != N[1] && N[1] != N[2] && N[0] != N[2]) return "No";
return "Yes";
}
solve().writeln;
}
| D |
void main(){
int n = _scan();
int[] a = _scanln();
int ans;
for(int i=1; i<=a.length; i+=2){
if(a[i-1]&1)ans++;
}
ans.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 |
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
int n;
rd(n);
auto s = readln.chomp.to!(char[]);
int mx = 0;
foreach (i; 1 .. n) {
bool[char] map;
foreach (j; 0 .. i) {
map[s[j]] = true;
}
int c = 0;
foreach (j; i .. n) {
if (s[j] in map) {
c++;
map.remove(s[j]);
}
}
mx = max(mx, c);
}
writeln(mx);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
| D |
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;
void main()
{
auto n = readln.chomp.to!int;
int cnt;
foreach (i; 1..n/2+1) {
auto j = n - i;
if (i < j) {
cnt++;
}
}
cnt.writeln;
}
| D |
import std;
auto input()
{
return readln().chomp();
}
void main()
{
// long[] ary = to!(long[])(split(readln()));
auto ary = readln().split().to!(long[])();
// writeln(join(to!(string[])(ary), " "));
long a = ary[0];
long b = ary[1];
long c = ary[2];
long k = ary[3];
if (a >= k)
{
writeln(k);
}
else if (a + b >= k)
{
writeln(a);
}
else
{
writeln(a - (k - a - b));
}
}
| D |
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;
int s, v1, v2, t1, t2;
void main() {
scan(s, v1, v2, t1, t2);
int a, b;
a = 2*t1 + s*v1;
b = 2*t2 + s*v2;
if (a < b) {
writeln("First");
}
else if (a > b) {
writeln("Second");
}
else {
writeln("Friendship");
}
}
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.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 nk = readints;
int n = nk[0], k = nk[1];
writeln(n - k + 1);
}
| D |
import std.stdio, std.string, std.conv, std.algorithm;
void main(string[] args) {
auto x = readln().chomp.split.map!(to!int);
auto a = x[0]-x[1];
if(a<0){0.writeln;}else{a.writeln;}
} | D |
// import chie template :) {{{
import std.stdio,
std.algorithm,
std.array,
std.string,
std.math,
std.conv,
std.range,
std.container,
std.bigint,
std.ascii,
std.typecons;
// }}}
// nep.scanner {{{
class Scanner {
import std.stdio;
import std.conv : to;
import std.array : split;
import std.string : chomp;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin) {
this.file = file;
this.idx = 0;
}
private char[] next() {
if (idx < str.length) {
return str[idx++];
}
char[] s;
while (s.length == 0) {
s = file.readln.chomp.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)() {
return next.to!(T);
}
T[] nextArray(T)(size_t len) {
T[] ret = new T[len];
foreach (ref c; ret) {
c = next!(T);
}
return ret;
}
void scan()() {}
void scan(T, S...)(ref T x, ref S args) {
x = next!(T);
scan(args);
}
}
// }}}
void main() {
auto cin = new Scanner;
int a, b, c;
cin.scan(a, b, c);
writeln(a + b >= c ? "Yes" : "No");
}
| D |
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n, a, b; rd(n, a, b);
writeln(min(a*n, b));
}
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 |
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string;
import std.traits : isSomeString;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
{
this.file = file;
this.idx = 0;
fromString(s);
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.strip.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
void fromString(StrType)(StrType s) if (isSomeString!(StrType))
{
str ~= s.to!(char[]).strip.split;
}
}
//Digit count---{{{
int DigitNum(int num) {
int digit = 0;
while (num != 0) {
num /= 10;
digit++;
}
return digit;
}
//}}}
//}}}
void main() {
Scanner sc = new Scanner;
int N, A, B;
sc.scan(N, A, B);
int res = 0;
foreach (i; 0 .. N + 1) {
if (A <= num(i) && num(i) <= B)
res += i;
}
writeln(res);
}
int num(int n) {
if (n / 10 == 0) return n % 10;
return num(n / 10) + (n % 10);
}
| D |
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto rd = readln.split.to!(int[]), a = rd[0], b = rd[1];
auto pa = a == 1 ? 14 : a, pb = b == 1 ? 14 : b;
if (pa == pb) writeln("Draw");
else if (pa > pb) writeln("Alice");
else writeln("Bob");
}
| 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 cnt;
long N = lread();
long m = long.min;
foreach (_; 0 .. N)
{
long p = lread();
m.maxAssign(p);
cnt += p;
}
cnt -= m / 2;
writeln(cnt);
}
| D |
import std.stdio;
import std.string;
import std.conv;
import std.algorithm: canFind;
void main() {
string[] inputs = split(readln());
int A = to!int(inputs[0]);
int B = to!int(inputs[1]);
((A + B) % 24).writeln;
}
| D |
import std.stdio, std.conv, std.array;
import std.math;
void main(){
double r = readln.split[0].to!double;
r = 2 * PI * r;
printf("%lf\n",r);
} | D |
import std.stdio, std.string, std.conv;
void main() {
auto input = getStdin!(string[])[0].split(" ");
int w = input[0].to!(int);
int h = input[1].to!(int);
int x = input[2].to!(int);
int y = input[3].to!(int);
int r = input[4].to!(int);
if (x - r < 0 || x + r > w || y - r < 0 || y + r > h) {
"No".writeln;
}
else {
"Yes".writeln;
}
}
T getStdin(T)() {
string[] cmd;
string line;
while ((line = chomp(stdin.readln())) != "") cmd ~= line;
return to!(T)(cmd);
} | 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 n = read.to!int;
int x = read.to!int;
int[] ls;
foreach(i; 0 .. n) ls ~= read.to!int;
int sum;
int ans;
foreach(l; ls){
if(sum <= x) ans += 1;
sum += l;
}
if(sum <= x) ans += 1;
ans.writeln;
}
| D |
import std.stdio, std.string, std.algorithm, std.conv, std.array;
void main(){
auto nx=readln.split.map!(to!long).array;
auto n=nx[0], x=nx[1];
auto as=readln.split.map!(to!long).array;
auto c=0L;
long result=0;
foreach(a; as){
if(a+c>x){
result+=a+c-x;
c=-c+x;
}else{
c=a;
}
}
writeln(result);
}
| D |
import std.stdio;
import std.datetime;
import std.conv;
void main()
{
auto s = TimeOfDay.fromISOExtString(readln[0 .. $-1] ~ ":00");
auto t = readln;
auto d = dur!"hours"((t[0..2]).to!long)
+ dur!"minutes"(t[3..5].to!long);
writeln((s - d).toISOExtString[0..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)); }
//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 S = RD!string;
writeln(S[2] == S[3] && S[4] == S[5] ? "Yes" : "No");
stdout.flush;
debug readln;
} | D |
// unihernandez22
// https://atcoder.jp/contests/abc076/tasks/abc076_c
// string manipulation
import std.stdio;
import std.string;
void main() {
string s = readln.chomp;
string t = readln.chomp;
ulong idx = -1;
bool matched;
for(long i = (s.count-t.count); i >= 0; i--) {
if (s[i] == '?' || s[i] == t[0]) {
matched = true;
foreach(j; 0..t.count) {
if (s[i+j] != '?' && s[i+j] != t[j]) {
matched = false;
break;
}
}
if (matched) {
idx = i;
break;
}
}
}
if (idx == -1) {
writeln("UNRESTORABLE");
return;
}
foreach(i; 0..s.count) {
if (s[i] == '?' && (i < idx || i >= t.count+idx))
write("a");
else if (s[i] == '?')
write(t[i-idx]);
else
write(s[i]);
} writeln;
}
| D |
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
std.range, std.container, std.bigint, std.ascii, std.typecons;
// }}}
// nep.scanner {{{
class Scanner
{
import std.stdio : File, stdin;
import std.conv : to;
import std.array : split;
import std.string : chomp;
private File file;
private char[][] str;
private size_t idx;
this(File file = stdin)
{
this.file = file;
this.idx = 0;
}
private char[] next()
{
if (idx < str.length)
{
return str[idx++];
}
char[] s;
while (s.length == 0)
{
s = file.readln.chomp.to!(char[]);
}
str = s.split;
idx = 0;
return str[idx++];
}
T next(T)()
{
return next.to!(T);
}
T[] nextArray(T)(size_t len)
{
T[] ret = new T[len];
foreach (ref c; ret)
{
c = next!(T);
}
return ret;
}
void scan()()
{
}
void scan(T, S...)(ref T x, ref S args)
{
x = next!(T);
scan(args);
}
}
// }}}
void main()
{
auto cin = new Scanner;
char[] s;
cin.scan(s);
long sum;
foreach (i; 0 .. (1 << s.length - 1))
{
long res = s[0] - '0';
foreach (j; 0 .. s.length - 1)
{
if ((i >> j) & 1) {
sum += res;
res = s[j + 1] - '0';
}
else
{
res *= 10;
res += s[j + 1] - '0';
}
}
sum += res;
}
writeln(sum);
}
| D |
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.array;
void main() {
int sum = 0;
while(true) {
string line = readln.chomp;
bool prev_digit = false;
string number = "";
if (stdin.eof) break;
foreach(x; line) {
if (isDigit(x)) {
number ~= x;
prev_digit = true;
}
else if (prev_digit) {
sum += number.to!(int);
number = "";
prev_digit = false;
}
}
if (number != "") sum += number.to!(int);
}
writeln(sum);
} | 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.chomp;
auto B = readln.chomp;
bool[] tate;
for (int i = 0; i < N; i++) {
if (i == N - 1 || A[i] != A[i + 1]) tate ~= true;
else tate ~= false, i += 1;
}
long ans = 1;
long MOD = 10^^9 + 7;
long a, b;
for (int i = 0; i < tate.length; i++) {
if (i == 0 && tate[i]) {
a = 3;
b = 1;
} else if (i == 0 && !tate[i]) {
a = 3;
b = 2;
} else if (tate[i] && tate[i-1]) {
a = 2;
b = 1;
} else if (tate[i] && !tate[i-1]) {
a = 1;
b = 1;
} else if (!tate[i] && tate[i-1]) {
a = 2;
b = 1;
} else {
a = 3;
b = 1;
}
ans = ans * a * b % MOD;
}
ans.writeln;
}
| D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.