Collections of solutions I've created while training CP. .mysticq for explanation of the solutions
#include<bits/stdc++.h>usingnamespacestd;
/* TYPES */#definell long long
#definepii pair<int, int>
#definepll pair<ll, ll>
#definevi vector<int>
#definevll vector<ll>
#definemii map<int, int>
/* UTILS */#definefi first
#definese second
#definepb push_back
#defineeb emplace_back
#defineMOD 1000000007
#definePI 3.1415926535897932384626433832795
#defineread(type) readInt<type>()
#defineall(x) x.begin(),x.end()
llmin(lla,intb) { if (a<b) returna; returnb; }
llmin(inta,llb) { if (a<b) returna; returnb; }
llmax(lla,intb) { if (a>b) returna; returnb; }
llmax(inta,llb) { if (a>b) returna; returnb; }
llgcd(lla,llb) { if (b==0) returna; returngcd(b, a%b); }
lllcm(lla,llb) { returna/gcd(a,b)*b; }
stringto_upper(stringa) { for (inti=0;i<(int)a.size();++i) if (a[i]>='a'&&a[i]<='z') a[i]-='a'-'A'; returna; }
stringto_lower(stringa) { for (inti=0;i<(int)a.size();++i) if (a[i]>='A'&&a[i]<='Z') a[i]+='a'-'A'; returna; }
boolprime(lla) { if (a==1) return0; for (inti=2;i<=round(sqrt(a));++i) if (a%i==0) return0; return1; }
voidyes() { cout<<"YES\n"; }
voidno() { cout<<"NO\n"; }
/****** Template of Fast I/O Methods *********/template<typenameT>inlinevoidwrite(Tx)
{
inti=20;
charbuf[21];
// buf[10] = 0;buf[20] ='\n';
do
{
buf[--i] =x % 10+'0';
x/= 10;
}while(x);
do
{
putchar(buf[i]);
} while (buf[i++] !='\n');
}
template<typenameT>inlineTreadInt()
{
Tn=0,s=1;
charp=getchar();
if(p=='-')
s=-1;
while((p<'0'||p>'9')&&p!=EOF&&p!='-')
p=getchar();
if(p=='-')
s=-1,p=getchar();
while(p>='0'&&p<='9') {
n= (n<< 3) + (n<< 1) + (p-'0');
p=getchar();
}
returnn*s;
}
intmax1=INT_MAX;
intmain() {
ios::sync_with_stdio(0); cin.tie(0);
intc;
c=read(int);
write(c);
return0;
}importjava.util.*;
importjava.io.*;
publicclasstemplate{
publicstaticvoidmain(Stringargs[]) throwsIOException {
}
finalprivatestaticintBUFFER_SIZE = 1 << 16;
privatestaticDataInputStreamdin = newDataInputStream(System.in);
privatestaticbyte[] buffer = newbyte[BUFFER_SIZE];
privatestaticintbufferPointer = 0, bytesRead = 0;
staticPrintWriterpr = newPrintWriter(newBufferedWriter(newOutputStreamWriter(System.out)));
publicstaticStringreadLine() throwsIOException {
byte[] buf = newbyte[64]; // line lengthintcnt = 0, c;
while ((c = Read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
returnnewString(buf, 0, cnt);
}
publicstaticStringread() throwsIOException {
byte[] ret = newbyte[1024];
intidx = 0;
bytec = Read();
while (c <= ' ') {
c = Read();
}
do {
ret[idx++] = c;
c = Read();
} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
returnnewString(ret, 0, idx);
}
publicstaticintreadInt() throwsIOException {
intret = 0;
bytec = Read();
while (c <= ' ')
c = Read();
booleanneg = (c == '-');
if (neg)
c = Read();
do {
ret = ret * 10 + c - '0';
} while ((c = Read()) >= '0' && c <= '9');
if (neg)
return -ret;
returnret;
}
publicstaticlongreadLong() throwsIOException {
longret = 0;
bytec = Read();
while (c <= ' ')
c = Read();
booleanneg = (c == '-');
if (neg)
c = Read();
do {
ret = ret * 10 + c - '0';
} while ((c = Read()) >= '0' && c <= '9');
if (neg)
return -ret;
returnret;
}
publicstaticdoublereadDouble() throwsIOException {
doubleret = 0, div = 1;
bytec = Read();
while (c <= ' ')
c = Read();
booleanneg = (c == '-');
if (neg)
c = Read();
do {
ret = ret * 10 + c - '0';
} while ((c = Read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = Read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
returnret;
}
privatestaticvoidfillBuffer() throwsIOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
privatestaticbyteRead() throwsIOException {
if (bufferPointer == bytesRead)
fillBuffer();
returnbuffer[bufferPointer++];
}
publicvoidclose() throwsIOException {
if (din == null)
return;
din.close();
}
staticvoidprint(Objecto) {
pr.print(o);
}
staticvoidprintln(Objecto) {
pr.println(o);
}
staticvoidflush() {
pr.flush();
}
staticvoidprintln() {
pr.println();
}
staticvoidexit() throwsIOException {
din.close();
pr.close();
System.exit(0);
}
}importsys; input=sys.stdin.readlinefrommathimport*defcin(x=-1):
ifx!=-1:
return [int(input()) foriinrange(x)]
else:
test=list(map(int, input().split()))
iflen(test) ==1:
returntest[0]
else:
returntestdefcins(x=-1):
ifx!=-1:
return [input() foriinrange(x)]
else:
test=list(map(str, input().split()))
iflen(test) ==1:
returntest[0]
else:
returntest