akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k;cin>>n>>k;
  V<ll> po(0),ne(0);
  rep(i,0,n){
    ll x;cin>>x;
    if(x>=0)po.pb(x);
    else ne.pb(x);
  }
  sort(all(po));
  reverse(all(po));

  sort(all(ne));

  int pid=0,nid=0,pn=siz(po),nn=siz(ne);
  ll ans=1;

  while(k>0){

  if(k%2==0){
    if(pid+1<pn && nid+1<nn){
      if(po[pid]*po[pid+1]>ne[nid]*ne[nid+1]){
        ans*=(po[pid]*po[pid+1])%mod;
        pid+=2;
      }else{
        ans*=(ne[nid]*ne[nid+1])%mod;
        nid+=2;
      }
    }else if(pid+1<pn){
      ans*=(po[pid]*po[pid+1])%mod;
      pid+=2;
    }else if(nid+1<nn){
      ans*=(ne[nid]*ne[nid+1])%mod;
      nid+=2;
    }else{
      if(k>=2){
        ans*=(po.back()*(ne.back()+mod))%mod;
      }else{
        ans*=po.back();
      }
    }
    k-=2;
    ans+=mod;
    ans%=mod;
  }else{
    if(pn){
      pid++;
      ans*=po[0];
      --k;
    }else{
      nid++;
      reverse(all(ne));
      ans*=(ne[0]+mod);
      ans%=mod;
      --k;
    }
  }
  }

  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?


Measured memory_bytes: 5416
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    
    int p[N+1],ans = 0;
    string S;
    for(int i=1;i<=N;i++){
        cin >> p[i];
        if(i == p[i]){
            S += 'x';
            ans++;
        }
        else S += 'o';
    }
    
    for(int i=0;i<N-1;i++){
        if(S[i] == 'x' && S[i+1] == 'x'){
            ans--;
            S[i+1] = 'o';
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    string s;
    int ans = 0;

    cin >> s;

    rep(i, 0, 3)
    {
        if (s[i] == '1')
            ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<ll> a(N); cin >> a;
    sort(all(a));

    int ans = 0;
    ll sum = 0;
    rep(i, N-1) {
        sum += a[i];
        if (a[i+1] <= sum * 2) {
            ans++;
        } else {
            ans = 0;
        }
    }
    ans++;

    cout << ans << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int ans = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (i % 2 == 0) ans += A.at(i);
    else ans -= A.at(i);
  }

  cout << ans << "\n";
  for (int i = 0; i < N - 1; i++) {
    int next = A.at(i) * 2 - ans;
    cout << next << "\n";
    ans = next;
  }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N+1);
  for (int i=0; i<N; i++) cin >> A[i];
  A[N] = A[0]+K;
  int dist_max = A[1]-A[0];
  for (int i=1; i<N; i++) {
    dist_max = max(dist_max, A[i+1]-A[i]);
  }
  int ans = K-dist_max;
  cout << ans << endl;
}

Measured memory_bytes: 1152
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

num_,j = [1],1
for i in range(1,n+1):
  j*=i
  num_.append(j)

def cul(n_, lis_):
  l=[]
  for i in range(1,n+1):
  	l.append(i)
  sum_=0
  for i in range(1,n_):
    lenl=len(l)
    #print(lis_[i-1])
    #print(l.index(lis_[i-1])/lenl)
    #print(num_[-i])
    sum_+=l.index(lis_[i-1])/lenl*num_[-i]
    l.remove(lis_[i-1])
    #print(l)
  return sum_
  
k = abs(cul(n,p)-cul(n,q))
print(int(k))
      

Measured memory_bytes: 3064
from collections import defaultdict

def main():
    n, p = [int(e) for e in input().split()]
    s = input()

    cnt = 0
    if p == 2 or p == 5:
        cum = 0
        for i in range(n - 1, -1, -1):
            if int(s[i]) % p == 0:
                cum += 1

            cnt += cum

    else:
        D = {n: 0}
        exp = 1
        for i in range(n - 1, -1, -1):
            D[i] = (D[i + 1] + (int(s[i]) * exp % p)) % p
            exp *= 10
            exp %= p

        Di = defaultdict(int)
        Di[0] = 1
        for i in range(n - 1, -1, -1):
            Di[D[i]] += 1
            cnt += Di[D[i]] - 1

    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 67276
#include <cstdio>
#include <algorithm>
const int MAXN = 1e5+1;
typedef long long LL;
LL C[MAXN];
struct Node
{
	int num, idx;
	bool operator < (const Node &s) const
	{
		return num!=s.num ? num<s.num : idx<s.idx;
	}
}D[MAXN];
#define min(a,b) ((a)<(b)?(a):(b))
int main()
{
	int N, i, j, idx;
	scanf("%d", &N);
	for(i=1; i<=N; ++i)
		scanf("%d", &D[i].num), D[i].idx = i;
	std::sort(D+1, D+N+1);
	for(i=j=idx=N; i>0; i=j)
	{
		while(j>0 && D[i].num == D[j].num) --j;
		C[idx = min(idx, D[j+1].idx)] += LL(N-j) * (D[i].num - D[j].num);
	}
	for(i=1; i<=N; ++i)
		printf("%lld\n", C[i]);
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  int n,c=0,c2=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a=="A")c++;
    else{
      if(c!=0){
	c--;
	c2++;
      }
    }
  }
  if(c2*2==n)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3112
H, W = map(int, input().split(" "))
A=[]
for i in range(H):
    A.append ([int(i) for i in input().split()])

ret=[]
temp=0
N=0

for y in range(H):
    for x in range(W-1):
        if A[y][x] % 2 != 0:
            A[y][x] -= 1
            A[y][x+1] += 1
            ret.append(str(y+1) + " " + str(x+1) + " " + str(y+1) + " " + str(x+1+1))
            N+=1

for y in range(H-1):
    if A[y][W-1] % 2 != 0:
        A[y][W-1] -= 1
        A[y+1][W-1] += 1
        ret.append(str(y+1) + " " + str(W) + " " + str(y+1+1) + " " + str(W))
        N+=1
        
print (N)
for r in ret:
    print (r)

Measured memory_bytes: 16252
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

#define N 11

int main(int argc, char const *argv[])
{
	int n,w;
	int v;
	int ga[N];
	int h,ww;
	double inc;
	int i1,i2;

	while(1){
		cin>>n>>w;
		if(n+w==0) break;

		for(i1=0;i1<N;i1++) ga[i1]=0;

		h=0;
		ww=0;
		for(i1=0;i1<n;i1++){
			cin>>v;
			int temp=v/w;
			ga[temp]++;
			if(ga[temp]>h) h=ga[temp];
			if(temp>ww) ww=temp;	
		}

		inc=0.01;
		for(i1=0;i1<N;i1++){
			inc+=((double)ga[i1]/(double)h*(double)(ww-i1)/(double)ww);
		}

		cout<<inc<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
n = int(input())

# R[0]
minv = int(input())
maxv = - 10 ** 10

# R[1..N-1]
for j in range(1, n):
    r = int(input())
    maxv = max(maxv, r - minv)
    minv = min(minv, r)

print(maxv)

Measured memory_bytes: 7664
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<sstream>
#include<algorithm>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define sRead(x,y,z)  scanf("%d%d%d",&x,&y,&z)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define INF 0x3f3f3f3f
#define ll long long
#define mod  998244353
#define pdd pair<double,double>
const int N = 10010;
const int M=  2e5+5;
int main()
{
    ll n;
    cin>>n;
    ll sum = 0;
    for(int i = 1; i <= n;++i){
        ll a = n - i;
        if(i > a) break;
        if(i != a){
            sum ++;
        }
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    h = list(map(int, input().split()))
    compare = ''
    for i in range(n-1):
        if h[i] >= h[i+1]:
            compare += '1'
        else:
            compare += '0'
    print(max(list(map(len, compare.split('0')))))

if __name__ == '__main__':
    main()

Measured memory_bytes: 20484
import sys
sys.setrecursionlimit(10**7)
import fileinput

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)


for line in sys.stdin:
    x, y = map(int, line.split())
    print(gcd(x,y),lcm(x,y))


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define fef(i,a,b) for(ll i=a;i<=b;i++)
#define rer(i,a,b) for(ll i=b;i>=a;i--)
#define wew while(true)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "A.inp"
#define FILE_OUT "A.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define INF (ll(1000000007))
#define MAXN 300011
#define x first
#define y second
#define pii pair<int,int>
#define piii pair<int,pii>
#define pb push_back
#define endl "\n"
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> order_set;
typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> order_trie;
typedef long long ll;
class DisjointSet{ public:
    vector<int> parent;
    DisjointSet(int n): parent(n) { for(int i=0; i<n; i++) parent[i] = i; }
    void join(int a, int b) { parent[find(b)] = find(a); }
    int find(int a){ return a == parent[a] ? a : parent[a] = find(parent[a]); }
    bool check(int a, int b){ return find(a) == find(b); }
};
//---------END-------//

int S,F[MAXN];
int main(){
    //ofile;
    cin >> S;
    F[0]=1;
    for (int i=3;i<=S;i++)
        for (int j=0;j<=i-3;j++)
            (F[i]+=F[j])%=MOD;
    cout << F[S];

}



Measured memory_bytes: 3544
""" B
    https://atcoder.jp/contests/abc173/tasks/abc173_b
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, S):
    result = {
        "AC": 0,
        "WA": 0,
        "TLE": 0,
        "RE": 0
    }

    for s in S:
        result[s] += 1

    print("AC x {}".format(result["AC"]))
    print("WA x {}".format(result["WA"]))
    print("TLE x {}".format(result["TLE"]))
    print("RE x {}".format(result["RE"]))

if __name__ == "__main__":
    _N = readInteger()
    _S = [readString().strip() for _ in range(0, _N)]

    main(_N, _S)

Measured memory_bytes: 16656
#include<stdio.h>
main(){
  int a,b,c,i=0,j,k;
  scanf("%d %d %d",&a,&b,&c);
  while(a <= b){
    if(c%a == 0){
      i++;
    }
    a++;
 }
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 110;
int n,m,lim,mod,f[2][N][N];

int C[N][N],pw[N][N];
inline void init(int n){
	C[0][0]=1;
	For(i,1,n){
		C[i][0]=1;
		For(j,1,i) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	pw[0][0]=1;
	For(i,1,n){
		pw[i][0]=1;
		For(j,1,n) pw[i][j]=1ll*pw[i][j-1]*i%mod;
	}
}

inline void clear(int k){
	For(i,0,n) For(j,0,m) f[k][i][j]=0;
}

int main(){
	n=read(),m=read(),lim=read(),mod=read();
	init(max({n,m,lim}));
	f[0][0][0]=1;
	int cur=1;
	For(i,1,lim){
		cur^=1,clear(cur^1);
		For(j,0,n) For(k,0,m) if (f[cur][j][k]){
			int x=f[cur][j][k],y=1ll*pw[i][m-k]*pw[lim-i+1][k]%mod;
			For(l,0,n-j){
				f[cur^1][j+l][k]=(f[cur^1][j+l][k]+1ll*x*C[n-j][l])%mod;
				x=1ll*x*y%mod;
			}
		}

		cur^=1,clear(cur^1);
		For(j,0,n) For(k,0,m) if (f[cur][j][k]){
			int x=f[cur][j][k],y=1ll*pw[i][n-j]*pw[lim-i+1][j]%mod;
			For(l,0,m-k){
				f[cur^1][j][k+l]=(f[cur^1][j][k+l]+1ll*x*C[m-k][l])%mod;
				x=1ll*x*y%mod;
			}
		}

		cur^=1,clear(cur^1);
		For(j,0,n) For(k,0,m) if (f[cur][j][k]){
			int x=f[cur][j][k],y=1ll*(mod-pw[i][m-k])*pw[lim-i][k]%mod;
			For(l,0,n-j){
				f[cur^1][j+l][k]=(f[cur^1][j+l][k]+1ll*x*C[n-j][l])%mod;
				x=1ll*x*y%mod;
			}
		}

		cur^=1,clear(cur^1);
		For(j,0,n) For(k,0,m) if (f[cur][j][k]){
			int x=f[cur][j][k],y=1ll*(mod-pw[i][n-j])*pw[lim-i][j]%mod;
			For(l,0,m-k){
				f[cur^1][j][k+l]=(f[cur^1][j][k+l]+1ll*x*C[m-k][l])%mod;
				x=1ll*x*y%mod;
			}
		}
	}
	printf("%d\n",f[cur][n][m]);
}

Measured memory_bytes: 3916
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A =[]
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append((a,b))

now =0
A_sort =sorted(A,key=lambda x: x[1])
for  progress,deadline in A_sort:
    now +=progress
    if now <=deadline:
        ans ="Yes"
    else:
        ans ="No"
        break
print(ans)

Measured memory_bytes: 33416
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    int n = s.size();
    for(int i=0; i<n; ++i){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        rotate(s.begin(), s.begin() + 1, s.end());
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
def f(ss):
  n=len(ss)
  ct,res=0,0
  for i in range(n):
    if ss[i]=="x":
      ct+=1
    else:
      res+=ct
  return res
s=input()
s=s.replace("BC","y")
s=s.replace("A","x")
s+="z"
ans=0
chk=""
for i in range(len(s)):
  if s[i]=="x" or s[i]=="y":
    chk+=s[i]
  else:
    ans+=f(chk)
    chk=""
print(ans)


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N,M; cin >> N >> M;
    vector<int> a(M),b(M);
    vector<vi> vs(N);
    rep(i,M){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        vs[a[i]].emplace_back(b[i]);
    }
    rep(i,N){
        sort(all(vs[i]));
    }

    set<int> st;
    st.insert(N);
    for(int i=N-1;i>=0;i--){
        if(vs[i].size() == 0) continue;

        int x = *st.upper_bound(i);
        if(x > vs[i][0]){
            st.insert(i+1);
        }
    }
    cout << st.size() - 1 << endl;
}


Measured memory_bytes: 9540
#include <iostream>
using namespace std;

long long three[22];

void init() {
  long long c = 1;
  for (int i=0; i<22; i++) {
    three[i] = c;
    c = c * 3;
  }
}

int main() {
  init();
  long long N;
  cin >> N;
  int i = 0;
  for ( ; i<22; i++) {
    if (N <= three[i]) break;
  }
  cout << i << endl; 
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,a,n) for(int i=n;i>=a;--i)
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;

ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll n)
{
    ll r=1%P;
    for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
    return r;
}
int main()
{
    int x,y;
    int a,b,c;
    cin>>a>>b>>c>>x>>y;
    if(x>y)
        {
            swap(x,y);
            swap(a,b);
        }
    int ans=0;
    if(2*c<a+b)
    {
        ans+=2*c*x;
        y-=x;
        x=0;
    }
    if(2*c<a)
        a=2*c;
    if(2*c<b)b=2*c;
    ans+=a*x+b*y;
    cout<<ans<<endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,A,B,C,D;
  string S;
  cin>>N>>A>>B>>C>>D>>S;
  A--;
  B--;
  C--;
  D--;
  for(ll i=A;i+1<=C;i++){
    if(S[i]=='#'&&S[i+1]=='#'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(ll i=B;i+1<=D;i++){
    if(S[i]=='#'&&S[i+1]=='#'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  if(C<D){
    cout<<"Yes"<<endl;
    return 0;
  }

  for(ll i=B;i<=D;i++){
    if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    S = input().strip()
    T = input().strip()

    ans = 0 
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    
    return ans

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 67800
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
	int N,Q;
	string S;
	cin>>N>>Q>>S;
	vector<int> AC,l(Q),r(Q),ans(Q);
	for(int i=0;i<N-1;i++){
		char a=S[i],b=S[i+1];
		//cout<<"a="<<a<<endl;
		//cout<<"b="<<b<<endl;
		if(a=='A' && b=='C'){
			AC.push_back(i);
		}
	}
	//for(int i=0;i<AC.size();i++)cout<<AC[i]<<endl;

		for(int i=0;i<Q;i++){
			cin>>l[i]>>r[i];
			auto min=lower_bound(AC.begin(),AC.end(),l[i]-1);
			auto max=lower_bound(AC.begin(),AC.end(),r[i]-1);
			ans[i]=max-min;
		}
		for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
	
	return 0;
}


Measured memory_bytes: 2556
#include "bits/stdc++.h"
#define IOS ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define deb(x) cout << #x << " " << x << endl;
#define fi(i,a,b) for(int i = a; i<b; i++)
#define fd(i,a,b) for(int i = a; i>=b; i--)
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define N 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
using namespace std;

//*************************************************************************************

void solve () {

    int n, l; cin>>n>>l; string arr[n], ans = "";
    fi(i, 0, n){cin>>arr[i];}
    sort(arr, arr+n);
    fi(i, 0, n){ans+=arr[i];}
    cout<<ans<<endl;
}

int main(){

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    IOS;

    int t=1;
    while(t--){solve();}
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vll A(X);
  rep(i, X) cin >> A[i];
  vll B(Y);
  rep(i, Y) cin >> B[i];
  vll C(Z);
  rep(i, Z) cin >> C[i];

  sort(ALL(A), greater<ll>());
  sort(ALL(B), greater<ll>());
  sort(ALL(C), greater<ll>());
  vll ans;
  rep(i, X) {
    rep(j, Y) {
      rep(k, Z) {
        if ((i + 1) * (j + 1) * (k + 1) <= K)
          ans.pb({A[i] + B[j] + C[k]});
        else
          break;
      }
    }
  }
  sort(ALL(ans), greater<ll>());
  rep(i, K) {
    COUT(ans[i]);
  }
  return 0;
}

Measured memory_bytes: 4292
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int H, W, h, w;
	cin >> H >> W;
	cin >> h >> w;
	int m;
	cout << (H-h)*(W-w);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
 
const ll INF = 1e18;
 
ll dp[200005][4];

int main() {
  int n;
  cin>>n;
  ll a[n];
  rep(i,n) cin >> a[i];
  int k = 1+n%2;
  rep(i,n+1)rep(j,k+1) dp[i][j] = -INF;
  dp[0][0] = 0;
  rep(i,n) {
    rep(j,k+1) {
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]);
        if ((i+j)%2 == 0){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]+a[i]);
        }else{
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
  }
  ll ans = dp[n][k];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10992
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//~ using namespace __gnu_pbds; 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=2e5+5;
const int mod=1e9+7;	
const ll oo=1e18+5;

//~ typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	cin>>n;
	bool check=1;
	while(n--){
		int x;
		cin>>x;
		if(x%2==0){
			if(x%3&&x%5) check=0;
		}
	}
	if(check) cout<<"APPROVED";
	else cout<<"DENIED"; 
	return 0;	
}


Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    t1,t2 = map(int,ipt().split())
    a1,a2 = map(int,ipt().split())
    b1,b2 = map(int,ipt().split())
    d1 = t1*(a1-b1)
    d2 = t2*(a2-b2)
    if d1*(d1+d2) > 0:
        print(0)
    elif d1+d2 == 0:
        print("infinity")
    else:
        dt = d1+d2
        if abs(d1)%abs(dt):
            print(abs(d1)//abs(dt)*2+1)
        else:
            print(abs(d1)//abs(dt)*2)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 68748
#include <iostream>
#include <cstring>
#include <sstream>
#include <cctype>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){

	int a, b, x, y;
	cin >> a >> b;

	if (a > b){
		x = a; y = b; 
	}
	else { 
		x = b; y = a; 
	}

	while (x%y != 0){
		int t = y;
		y = x%y;
		x = t;
	}

	cout << y << endl;

	return 0;
}


Measured memory_bytes: 3096
//Reference : https://atcoder.jp/contests/abc167/submissions/13006878
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;
const int D = 60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    ll n, k;
    ll to[D][200005];
    cin >> n >> k;
    rep(i,0,n){
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i,0,D-1){
        rep(j,0,n){
            to[i+1][j] = to[i][to[i][j]];
        }
    }

    int v = 0;
    for(int i = D-1; i >= 0; i--){
        ll l = 1ll<<i;
        if(l <= k){
            k-=l;
            v = to[i][v];
        }
    }
    COUT(v+1);
}

Measured memory_bytes: 97416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;




int main(){
	int n, m;
	cin >> n >> m;


	vector<int>mp1(n,0);
	vector<int>mp2(n,0);
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		if (a == 0) {
			mp1[b]++;
		}
		else if (b == n-1) {
			mp2[a]++;
		}
	}

	bool fl = 0;
	rep(i, 0, n) {
		if (mp1[i] > 0 and mp2[i] > 0) {
			cout << "POSSIBLE" << endl;
			fl = 1;
			break;
		}
	}

	if (!fl) {
		cout << "IMPOSSIBLE" << endl;
	}



	
	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	char ar[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>ar[i][j];
		}
	}
	int cnt = 0;
	int no_black = 0;
	for(int mask_row=0;mask_row<(1<<h);mask_row++)
	{
		for(int mask_col=0;mask_col<(1<<w);mask_col++)
		{
			no_black = 0;
			for(int i=0;i<h;i++)
			{
				for(int j=0;j<w;j++)
				{
					if((mask_row & (1<<i)) == 0  &&  (mask_col & (1<<j))== 0)
					{
						if(ar[i][j] == '#')
						{
						   no_black++;
						}
					}
				}
			}
			if(no_black == k)
			{
				cnt++;
			}
		}
	}
	cout<<cnt<<"\n";
}

Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func abs(x float64) float64 {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n := scanInt()
	ave := 0.0
	type flame struct{ a, n int }
	fs := make([]flame, n)
	for i := range fs {
		fs[i].a, fs[i].n = scanInt(), i
		ave += float64(fs[i].a)
	}
	ave /= float64(n)

	d := math.MaxFloat64
	var ans int
	for _, f := range fs {
		if v := abs(ave - float64(f.a)); v < d {
			d = v
			ans = f.n
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


template <typename T>
T gcd(T a, T b) {
    while (b != 0) {
        T c = a;
        a = b;
        b = c % b;
    }
    return a;
}

template <typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> T;
    rep (i, N) {
        ll t;
        cin >> t;
        T.pb(t);
    }
    ll ans = T[0];
    auto it = T.begin();
    for (; it != T.end(); ++it) {
        ans = *it / gcd(ans, *it) * ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
a,b = gets.split.map(&:to_i)
ans = Array.new(100){|i|i < 50 ? "#"*100 : "."*100}

(a-1).times do |i|
    ans[(i/50)*2][(i%50)*2] = "."
end

(b-1).times do |i|
    ans[51+(i/50)*2][(i%50)*2] = "#"
end

puts "100 100"
puts ans

Measured memory_bytes: 3836
use std::io::stdin;

fn main() {
    let stdin = stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    let buf: Vec<i32> = buf.split_whitespace().map(|n| n.parse().unwrap()).collect();
    
    let ab = buf[0];
    let bc = buf[1];
    let ca = buf[2];
    
    let s = (ab + bc + ca) / 2;
    let S = ((s * (s - ab) * (s - bc) * (s - ca)) as f64).sqrt() as i32;
    
    println!("{}", S);
}


Measured memory_bytes: 4352
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Grid Compression
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 100;
const int MAX_W = 100;

/* typedef */

/* global variables */

char flds[MAX_H][MAX_W + 4];
bool uys[MAX_H], uxs[MAX_W];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);

  for (int y = 0; y < h; y++) {
    scanf("%s", flds[y]);
    for (int x = 0; x < w; x++)
      if (flds[y][x] == '#') uys[y] = uxs[x] = true;
  }

  for (int y = 0; y < h; y++)
    if (uys[y]) {
      for (int x = 0; x < w; x++)
	if (uxs[x]) putchar(flds[y][x]);
      putchar('\n');
    }
  return 0;
}


Measured memory_bytes: 256
a=list(input())
b=list(input())
c=list(input())

abc=[a,b,c]
abc_n=[0,0,0]
t=0

while(abc_n[t]<len(abc[t])):
  ti=t
  if abc[ti][abc_n[ti]]=='a':
    t=0
  elif abc[ti][abc_n[ti]]=='b':
    t=1
  else:
    t=2
  abc_n[ti]+=1

if t==0:
  print('A')
elif t==1:
  print('B')
else:
  print('C')
  

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N, D; cin >> N >> D;
    vector<long long>X(N);
    vector<long long>Y(N);
    int ans = 0;
    rep(i, N) {
        cin >> X[i] >> Y[i];
        long double a = sqrt(X[i] * X[i] + Y[i] * Y[i]);
        if (a <= D)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, k;
ll a[100100];

int main() {
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	cout << 1 + (n - k) / (k - 1) + ((n - k) % (k - 1) != 0) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}
vector<int> divisor(int x){
  vector<int> res;
  for(int i=1;i*i<=x;i++){
    if(x%i==0){
      res.emplace_back(i);
      if(i*i!=x) res.emplace_back(x/i);
    }
  }
  return res;
}

int main()
{
  int n;
  cin>>n;
  vector<bool> a(n);
  REP(i,n){
    int b;
    cin>>b;
    a[i]=b? 1:0;
  }

  vector<bool> ans(n,0);
  int v=0;
  REP(i,n){
    if(a[n-1-i]){
      v++;
      ans[n-1-i]=1;
      vector<int> f=divisor(n-i);
      for(auto p:f) a[p-1]=(!a[p-1]);
    }
  }
  cout<<v<<endl;
  bool f=0;
  REP(i,n){
    if(ans[i]){
      if(f) cout<<" ";
      f=1; 
      cout<<i+1;
    }
  }
  if(v!=0) cout<<endl;
  
  return 0;
}


Measured memory_bytes: 1152
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        arr: [usize; n],
    }

    let s = arr.iter().fold(0, |a, v| a^v);
    for a in arr {
        print!("{} ", a^s)
    }
}


Measured memory_bytes: 6384
main = interact (unlines . map step . lines)

step :: String -> String
step line = show $ countSplit 4 $ read line

countSplit :: Int -> Int -> Int
countSplit 1 n
    | n >= 0 && n <= 9  = 1
    | otherwise         = 0
countSplit m n
    | n >= 0            = sum [countSplit (m-1) (n-k) | k <- [0..9]]
    | otherwise         = 0

Measured memory_bytes: 4132
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> inputs(5);
    for (int i = 0; i < 5; i++) {
        cin >> inputs[i];
    }
    int k;
    cin >> k;
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            if (abs(inputs[i] - inputs[j]) > k) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int a = 1;
for (int i = 0; i<n; i++){
      if (a<k){
          a *= 2;
      }
      else{
          a += k;
      }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int int_cmp(const int *a, const int *b)
{
  if(*b > *a)
    return 1;
  if(*b < *a)
    return -1;
  if(*b == *a)
    return 0;
}

int main(void)
{
  int N, M;
  int A[100];
  long all_vote = 0;
  int i;
  
  scanf("%d%d", &N, &M);
  getchar();
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
    all_vote += A[i];
  }
  qsort((void *)A, N, sizeof(A[0]), (int (*)(const void *, const void *))(int_cmp));
  if(A[M-1] >= (double)all_vote/(4*M))
    puts("Yes");
  else
    puts("No");
  
  return 0;
}

Measured memory_bytes: 128
n,q = map(int,input().split())
s = list(input())

count = [0]*n

num = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        num += 1
    count[i] = num
count.insert(0,0)
count[-1] = count[-2]

for i in range(q):
    l,r = map(int,input().split())
    print(count[r-1] - count[l-1])

Measured memory_bytes: 6772
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int n, k;
    cin >> n >> k;

    cout << (n >= k * 2 - 1 ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    int x;
    cin >> x;
    int ans = 0;
    int max = 1000000000;
    int i = 1;
    for(int i = 0; i < max; i++){
        ans+=i;
        if(ans>=x){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int f[45];

int fibonacci(int x)
{
  if(x==0 || x==1){
    f[x]= 1;
    return f[x];
  }
  if(!f[x]){
    f[x]=fibonacci(x-1)+fibonacci(x-2);
  }
  return f[x];
}

int main()
{
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}



Measured memory_bytes: 2108
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	unordered_set<long long> ks;
	long long n;
	cin >> n;

	auto check = [&](long long k) {
		if(k==1) return false;
		long long pw = 1;
		while(pw>0&&pw<=n) {
			if(pw==n) return true;
			pw = pw * k;
		}
		pw = 1;
		while(pw>0&&pw<=n/(1+k)){
			if(n%pw==0&& (n/pw-1)%k==0) return true;
			pw=pw*k;
		}
		return false;
	};

	for(long long k = 1; k * k <= n; k++) {
		if(n % k != 0) continue;
		if(check(k)) ks.insert(k);
		if(check(n/k)) ks.insert(n/k);
	}
	for(long long k = 1; k * k <= n - 1; k++) {
		if( (n-1) % k != 0) continue;
		ks.insert(k);
		ks.insert((n-1)/k);
	}
	ks.erase(1);
	cout << ks.size();
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    if (K <= A)
    {
        cout << A - K << ' ' << B << endl;
    }
    else
    {
        K -= A;
        if (K <= B)
        {
            cout << 0 << ' ' << B - K << endl;
        }
        else
        {
            cout << 0 << ' ' << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;
    char table[h + 1][w + 1];
    for (int i = 1; i <= h; ++i)
    {
        for (int j = 1; j <= w; ++j)
        {
            cin >> table[i][j];
        }
    }
    for (int i = 1; i <= h; ++i)
    {
        bool index = true;
        for (int j = 1; j <= w; ++j)
        {
            if (table[i][j] == '#')
            {
                index = false;
                break;
            }
        }
        if (index == true)
        {
            for (int j = 1; j <= w; ++j)
            {
                table[i][j] = 'e';
            }
        }
    }
    for (int i = 1; i <= w; ++i)
    {
        bool index = true;
        for (int j = 1; j <= h; ++j)
        {
            if (table[j][i] == '#')
            {
                index = false;
                break;
            }
        }
        if (index == true)
        {
            for (int j = 1; j <= h; ++j)
            {
                table[j][i] = 'e';
            }
        }
    }
    for (int i = 1; i <= h; ++i)
    {
        bool index = true;
        for (int j = 1; j <= w; ++j)
        {
            if (table[i][j] != 'e')
            {
                index = false;
                cout << table[i][j];
            }
        }
        if (index == true)
            cout << flush;
        else
            cout << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)]

child = [[] for _ in range(N+1)]
par = [0]*(N+1)

for ab in AB:
    a,b = ab[0], ab[1]
    child[a].append(b)
    par[b] = a

k = 0
for i in range(1,N+1):
    l = len(child[i])
    if par[i] > 0:
        l += 1
    k = max(k, l)

print(k)
col = [0] * (N+1)
col[1] = 1
for i in range(1, N):
    cnt = 0
    for c in child[i]:
        cnt += 1
        col[c] = (col[i] + cnt) % k
        #print(col[c]+1)

for ab in AB:
    b = ab[1]
    print(col[b] + 1)


Measured memory_bytes: 77016
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let ans = max(0, v[0] - v[1] * 2);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352