akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#pragma region Segment Tree
template <typename X>
struct SegTree
{
    using FX = function<X(X, X)>;

    int n;
    FX f, u;
    const X id;
    vector<X> dat;
    SegTree(int n_, FX f_, FX u_, X id_) : n(), f(f_), u(u_), id(id_)
    {
        n = 1 << (int)(log2(n_) + 1);
        dat = vector<X>(2 * n + 1, id_);
    }
    void set(int i, X x)
    {
        dat[i + n] = x;
    }
    void build()
    {
        for (int i = n - 1; i >= 1; i--)
        {
            dat[i] = f(dat[i * 2], dat[i * 2 + 1]);
        }
    }

    // update according to u(dat[i],x);
    void update(int i, X x)
    {
        int k = i + n;
        dat[k] = u(dat[k], x);
        while (k / 2)
        {
            k /= 2;
            dat[k] = f(dat[k * 2], dat[k * 2 + 1]);
        }
    }

    X query(int a, int b, int k, int l, int r)
    {
        if (a <= l && b >= r)
        {
            return dat[k];
        }
        else if (b <= l || a >= r)
        {
            return id;
        }
        int newK = k * 2;
        X vl = query(a, b, newK, l, (l + r) / 2);
        X vr = query(a, b, newK + 1, (l + r) / 2, r);
        return f(vl, vr);
    }

    // query according to reduce([a,b), f, id)
    X query(int a, int b)
    {
        return query(a, b, 1, 0, n);
    }
};
#pragma endregion

int main()
{
    int n;
    cin >> n;
    auto f = [](int a, int b) { return gcd(a, b); };
    auto u = [](int a, int b) { return b; };
    SegTree<int> st(n, f, u, 0);
    rep(i, n)
    {
        int a;
        cin >> a;
        st.set(i, a);
    }
    st.build();

    int argmax = -1, maxi = 0;

    rep(i, n)
    {
        int l = st.query(0, i), r = st.query(i + 1, n);

        int now = gcd(l, r);
        if (now > maxi)
        {
            argmax = i;
            maxi = now;
        }
    }
    cout << maxi << endl;

    return 0;
}

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

int l , r , k ;

void input ( ) {
    cin >> l >> r >> k ;
}

void solve ( ) {
    cout << ( r / k ) - ( ( l - 1 ) / k ) << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 3576
import java.util.*;
class Main{
    static List<int[]>[] to;
    static long[] dist;
    static int n;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        //距離ありの隣接リスト
        to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
        }
        for(int i = 0; i < n-1; i++){
            int a = scanner.nextInt()-1;
            int b = scanner.nextInt()-1;
            int d = scanner.nextInt();
            to[a].add(new int[]{b,d});
            to[b].add(new int[]{a,d});
        }
        int query = scanner.nextInt();
        int k = scanner.nextInt()-1;
        long[] distK = calcDist(k);

        while(query-- > 0){
            int p = scanner.nextInt()-1;
            int q = scanner.nextInt()-1;
            System.out.println(distK[p] + distK[q]);
        }
    }
    public static long[] calcDist(int p){
        dist = new long[n];
        dfs(p, 0, -1);
        return dist;
    }
    public static void dfs(int p, long d, int par){
        for(int[] qData : to[p]){
            int q = qData[0];
            int PtoQ = qData[1];
            if(q == par){continue;}
            dist[q] = d + PtoQ;
            dfs(q,d+PtoQ,p);
        }
    }
}

Measured memory_bytes: 182992
#include <iostream>
#include <string>

using namespace std;

int main() {
	string abc = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
	string s;
	while (getline(cin, s)) {
		while (true) {
			string::size_type index = s.find("the");
			string::size_type index2 = s.find("this");
			string::size_type index3 = s.find("that");
			if (index != string::npos || index2 != string::npos || index3 != string::npos) {
				break;
			}
			for (int i = 0; i < s.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (s[i] == abc[j]) {
						s[i] = abc[j+1];
						break;
					}
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
count = 0

def merge(a, left, mid, right):
    global count
    L = [0] * (mid - left + 1)
    R = [0] * (right - mid + 1)

    for i in range(len(L)):
        if i  == len(L) - 1:
            L[i] = float('inf')
        else:
            L[i] = a[left+i]
    
    for i in range(len(R)):
        if i == len(R) - 1:
            R[i] = float('inf')
        else:
            R[i] = a[mid+i]

    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            if i != len(L) - 1 and j != len(R) - 1:
                count += len(L) - i - 1
            a[k] = R[j]
            j += 1

def mergeSort(a, left, right):
    if left+1 < right:
        mid = int((left + right) / 2)
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)

l = int(input())
a = list(map(int, input().split()))

mergeSort(a, 0, l)
print(count)


Measured memory_bytes: 27484
import heapq
N,K = map(int, input().split())
*V, = map(int, input().split())
#N, K = 6, 4
#V = [-10, 8, 2, 1, 2, 6]
motimono = []
ans = []

if K >= N: # 操作回数のほうが大きいなら、全部取り出してから何個戻すかを考える
    K -= N
    heapq.heapify(V)
    ans.append(sum(V))
    for i in range(K):
        if len(V)>0:
            heapq.heappop(V)
        ans.append(sum(V))
    print(max(ans))

else:
    V *= 2 # 前後からの取り出しを楽にするためにこうしておく
    #print(V)
    for j in range(1,K+1): # 取り出す個数
        for i in range(N-j, N+1): # 何番目から取り出すか
            motimono = V[i:i+j]
            #print(str(j), str(i), motimono)
            ans.append(sum(motimono))
            #print(ans)
            heapq.heapify(motimono)
            for i in range(K-j): # 戻す個数
                if len(motimono)>0:
                    heapq.heappop(motimono)
                ans.append(sum(motimono))
    print(max(ans))

Measured memory_bytes: 3316
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

using namespace std;

int main() {

	long a, b, c, sum, n, flag = 0, m, count = 0, h[100001], g[100001] = {0},e,f,d;

	cin >> a >> b ;

	for (int i = b - a + 1; i < a + b; i++) {

		cout << i <<' ';
	}
	
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

  int n, ans = 0, good = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> good;
    while(good % 2 == 0){
      ans++;
      good /= 2;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
using pli=pair<int64_t, int>;
using mii=map<int, int>;

struct node {
    mii edge;
    bool done = false;
    int64_t cost = -1;

    bool operator<(const node &rhs) const {
        if (rhs.cost == -1 && this->cost == -1) {
            return false;
        } else if (rhs.cost == -1) {
            return true;
        } else if (this->cost == -1) {
            return false;
        }
        return this->cost < rhs.cost;
    }

    bool operator>(const node &rhs) const {
        return rhs < *this;
    }

    void update_cost(int64_t x) noexcept {
        if (x < 0) {
            cerr << "Illegal Argument in node.update_cost: x=" << x << endl;
            exit(1);
        }
        if (this->cost == -1 || this->cost > x) {
            this->cost = x;
        }
    }
};

int main() {
    int N, M;
    cin >> N >> M;

    vector<node> nodes(N);
    mii cover;
    for (auto i = 0; i < M; i++) {
        int L, R, C;
        cin >> L >> R >> C;
        if (cover.count(L - 1) == 0) {
            cover[L - 1] = R - 1;
        } else {
            cover[L - 1] = max(cover[L - 1], R - 1);
        }

        if (nodes.at(L - 1).edge.count(R - 1) == 0) {
            nodes.at(L - 1).edge[R - 1] = C;
        } else {
            nodes.at(L - 1).edge[R - 1] = min(nodes.at(L - 1).edge[R - 1], C);
        }

        if (nodes.at(R - 1).edge.count(L - 1) == 0) {
            nodes.at(R - 1).edge[L - 1] = C;
        } else {
            nodes.at(R - 1).edge[L - 1] = min(nodes.at(R - 1).edge[L - 1], C);
        }
    }

    if (cover.count(0) == 0) {
        cout << -1 << endl;
        return 0;
    }

    auto range = cover.at(0);
    for (auto i = 1; i < N && i <= range; i++) {
        if (cover.count(i) == 0) {
            continue;
        }
        range = max(range, cover.at(i));
        if (range == N - 1) {
            break;
        }
    }

    if (range != N - 1) {
        cout << -1 << endl;
        return 0;
    }

    for (auto i = N - 1; i > 0; i--) {
        nodes.at(i).edge[i - 1] = 0;
    }

    priority_queue<pli, vector<pli>, greater<>> q;

    nodes.at(0).cost = 0;
    q.emplace(0, 0);

    do {
        auto top = q.top();
        q.pop();
        nodes.at(top.second).done = true;
        for (auto e:nodes.at(top.second).edge) {
            nodes.at(e.first).update_cost(top.first + e.second);
            if (!nodes.at(e.first).done) {
                q.emplace(nodes.at(e.first).cost, e.first);
            }
        }
    } while (!q.empty());

    cout << nodes.at(N - 1).cost << endl;
    return 0;
}


Measured memory_bytes: 22260
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORALL(i, m) for( auto i = m.begin(); i != m.end() ; ++i )
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define TM_T template <class T>
using namespace std;
typedef long long ll;
TM_T T inp(){T it;cin >> it;return it;}

ll N,K;
vector<ll> li;
vector<ll> dp;

int input(){
  cin >> N >> K;
  REP(i,N) li.push_back( inp<ll>() );
}

int main()
{
  input();
  
  REP(i,K+1) dp.push_back(0);
  REP(i,K+1) {
    vector<ll> tmp;
    FORALL(v,li) if (i-(*v)>=0) tmp.push_back(dp[i-(*v)]);
    sort(ALL(tmp));
    ll key = 0;
    FORALL(v,tmp){
      if (key!=(*v)) continue; else key++;
    }
    dp[i] = key;
  }
  //REP(i,K+1) cout << dp[i] << endl;
  if ( dp[K] != 0 ) cout << "First" << endl; else cout << "Second" << endl;
  
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
long long p(long long t){
    return t*t*t*t*t;
}
int main(){
    long long X;
    cin >> X;
    long long a = 0;
    while(1){
        int flag = 0;
        if(a == 0){
            long long b = -1*X;
            long long B = pow((double)b, 0.2);
            if(p(B) == b){
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
        else{
            long long b = p(a) - X;
            if(b <= 0) {
                b *= -1;
                flag = 1;
            } 
            long long B = pow((double)b, 0.2);
            if(p(B) == b){
                if(flag == 1){
                    cout << a << ' ' << -1*B << endl;
                    return 0;
                }
                cout << a << ' ' << B << endl;
                return 0;
            }
        }
        a++;
    }
}

Measured memory_bytes: 4024
#include <iostream>
#include <math.h>
using namespace std;
 
int main() {
  int X;
  cin >> X;
  int a = floor(X / 100);
  int b = X % 100;
  if (a * 5 >= b)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
# include <stdio.h>

int main(){
    char num[4];
    scanf("%s", num);
    int a = 0;
    
    if (num[0] == '9')
        a = 1;
    if (num[1] == '9')
        a = 1;
    if (a == 1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(input()) for _ in range(N)] + [0]

ans = 0

for i in range(N):
    ans += A[i]//2
    if A[i]%2==1 and A[i+1]>0:
        ans += 1
        A[i+1] -= 1
        
print(ans)

Measured memory_bytes: 7840
def mx(p,w,h,l):
    if h<=c/2:
        if w==0:
            p[h][w]+=p[h-1][w]
        elif w==l-1:
            p[h][w]+=p[h-1][w-1]
        else:
            p[h][w]+=max(p[h-1][w],p[h-1][w-1])
    else:
        p[h][w]+=max(p[h-1][w],p[h-1][w+1])
    return p
c=0
p=[]
while 1:
    try:
        p.append(map(int, raw_input().split(',')))
        c+=1
    except:
        break

for h in range(1,c):
    l=len(p[h])
    for w in range(l):
        p=mx(p,w,h,l)
print p[c-1][0]

Measured memory_bytes: 6536
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
#define mod 1000000007
#define N 2000007
ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res%mod;
}
ll ncr(ll n,ll k){
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro)%mod;
}

void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
vector<ll> parent;
ll find(ll p) {
    if(parent[p]==p) return parent[p];
    return parent[p]=find(parent[p]); 
}
void unun(ll a,ll b) {
    ll r1=find(a);
    ll r2=find(b);
    if(r1!=r2) parent[r2]=r1;
}
vector<ll> v,ans,arr;
vector<vector<ll>> adj;
void dfs(ll src ,ll p=-1) {
    if(v.empty() || arr[src]>v.back()) {
        v.pb(arr[src]);
        ans[src]=v.size();
        for(auto itr: adj[src]) {
            if(itr==p) continue;
            dfs(itr,src);
        }
        v.pop_back();
    }
    else {
        ll lb=lower_bound(v.begin(),v.end(),arr[src])-v.begin();
        ll temp=v[lb];
        v[lb]=arr[src];
        ans[src]=v.size();
        for(auto itr: adj[src]) {
            if(itr==p ) continue;
            dfs(itr,src);
        }
        v[lb]=temp;
    }
}
void solve() {
    ll n,a,b;
    cin>>n;
    ans = vector<ll>(n);
    arr = vector<ll>(n);
    adj = vector<vector<ll>>(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n-1;i++) {
        cin>>a>>b;
        a--;
        b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(0);
    for(auto itr: ans) cout<<itr<<"\n";

}   


int main(void){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<endl;
    }
    return 0; 

}


Measured memory_bytes: 28764
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=1e6+50,mod=1e9+7;
int h,lim,p[N],cnt,dat[N],inv[N],idat[N],sum[N],ans;
vector<pii>v[N];
int read(){
    int x=0,c;
    while(!isdigit(c=getchar()));
    while(isdigit(c))x=x*10+c-48,c=getchar();
    return x;
}
int main(){
    scanf("%d",&h);lim=1<<h;cnt=lim>>1;
    inv[1]=1;
    for(int i=2;i<lim;i++)
        inv[i]=mod-1ll*mod/i*inv[mod%i]%mod;
    for(int i=cnt,x;i<lim;i++)v[i].pb(mp(i,read()+cnt-1));
    dat[1]=idat[1]=1;
    for(int i=2;i<lim;i++)
        dat[i]=1ll*dat[i>>1]*i%mod,
        idat[i]=1ll*idat[i>>1]*inv[i]%mod;
    for(int i=1;i<lim;i++)idat[i]=1ll*i*idat[i]%mod*idat[i]%mod;
    for(int i=cnt-1;i;i--){
        v[i]=v[i<<1];
        for(int j=0;j<v[i<<1|1].size();j++)
            v[i].pb(v[i<<1|1][j]);
    }
    for(int i=1;i<cnt;i++){
        for(int j=0;j<v[i<<1].size();j++){
            int x=v[i<<1][j].first,y=v[i<<1][j].second,yy=y;
            while(y)sum[y]=(sum[y]+1ll*dat[x]*idat[i]%mod*dat[yy])%mod,y>>=1;
        }
        for(int j=0;j<v[i<<1|1].size();j++){
            int x=v[i<<1|1][j].first,y=v[i<<1|1][j].second,yy=y;
            int tmp=0;
            while(y)tmp=(tmp+1ll*sum[y]*(idat[y]-idat[y>>1]))%mod,y>>=1;
            ans=(ans+1ll*tmp*dat[yy]%mod*dat[x])%mod;
        }
        for(int j=0;j<v[i<<1].size();j++){
            int y=v[i<<1][j].second;while(y)sum[y]=0,y>>=1;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 54804
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define print(a) {for(auto xxxxx : (a)) cout << xxxxx << ' '; cout << '\n';}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

ll next(){ll x; cin >> x; return x;}
const int maxn = 1e5 + 3, intf = 2e9;
const ll inf = 2e18, mod = 998244353;
const ld eps = 1e-6;


void solve(){
	set <string> a;
	int n; cin >> n;
	while(n--){
		string s; cin >> s;
		a.insert(s);
	}
	cout << a.size();
}


signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
    
    for (int t = 1; t--;) {
    	solve();
    }

	return 0;
}
/*


*/



Measured memory_bytes: 19200
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if(n == 3) {
        cout << 2 << ' ' << 5 << ' ' << 63 << endl;
        return 0;
    }
    int sum = 0;
    vi ans(n);
    int six[] = {2, 3, 4, 6};
    int x = 0;
    rep(i, n/4) {
        rep(j, 4) {
            int num = six[j] + i*6;
            ans[i*4+j] = num;
            sum += num;
            sum %= 6;
            x = num;
        }
    }

    if(!(n%4)) {
        if(sum) {
            ans[n-1] += 3;
        }
    } else {
        switch(n%4) {
            case 1:
                if(sum) {
                    ans[n-1] = x+3;
                } else {
                    ans[n-1] = x+6;
                }
                break;
            case 2:
                if(sum) {
                    ans[n-2] = x+3;
                    ans[n-1] = x+6;
                } else {
                    ans[n-2] = x+2;
                    ans[n-1] = x+4;
                }
                break;
            case 3:
                if(sum) {
                    ans[n-1] = x+2;
                    ans[n-2] = x+3;
                    ans[n-3] = x+4;
                } else {
                    ans[n-1] = x+2;
                    ans[n-2] = x+4;
                    ans[n-3] = x+6;
                }
                break;
        }
    }

    rep(i, n) {
        cout << ans[i] << (i == n-1?'\n':' ');
    }
}

Measured memory_bytes: 3664
N, x = map(int, input().split())
A = list(map(int, input().split()))
B = A[::-1]

ansA = 0
ansB = 0

for i in range(N-1):
  if A[i] > x:
    ansA += A[i] - x
    A[i] -= A[i] - x
  
  s = A[i] + A[i+1]
  if s > x:
    ansA += s - x
    A[i+1] -= s - x

for i in range(N-1):
  if B[i] > x:
    ansB += B[i] - x
    B[i] -= B[i] - x
  
  s = B[i] + B[i+1]
  if s > x:
    ansB += s - x
    B[i+1] -= s - x
  
print(min(ansA, ansB))

Measured memory_bytes: 14548
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (100010)

int n;
vector<int> e[N];
int parent[N];
int depth[N];
int ans, k;



int dfs(int v, int p){
	int x;
	int re = 0;

	f(i, e[v].size()){
		if (e[v][i] != p){
			x = dfs(e[v][i], v);
			re = max(re, x);
		}
	}
		re++;
		if (re >= k&&p!=0&&v!=0){
			ans++;
			re = 0;
		}
	return re;
}


int main(void){
	int x, y;
	int q;
	ans = 0;
	scanf("%d %d", &n,&k);
	f(i, n){
		scanf("%d", &x);
		if (i == 0){
			if (x != 1)ans++;
		}
		else{
			e[i].push_back(x - 1);
			e[x - 1].push_back(i);
		}
	}
	dfs(0,-1);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 13568
import sys
input = sys.stdin.readline
import itertools

H, W, K = map(int, input().split())
S = [input() for i in range(H)]
Col = [[] for i in range(W)]
for j in range(W):
    for i in range(H):
        Col[j].append(S[i][j])
Ans = 10**9
for lst in itertools.product([0,1], repeat=H-1):
    ran = []
    ans = sum(lst)
    l = 0
    for i, x in enumerate(lst, 1):
        if x == 1:
            ran.append((l, i))
            l = i
    ran.append((l, H))
    cnt = [0] * len(ran)
    endflg = 0
    for j in range(W):
        flg = 0
        for i, (l, r) in enumerate(ran):
            c = Col[j][l:r].count('1')
            if c > K:
                ans = 10**9
                endflg = 1
                break
            if cnt[i] + c > K:
                flg = 1
                break
        if endflg:
            break
        if flg:
            ans += 1
            for i, (l, r) in enumerate(ran):
                cnt[i] = Col[j][l:r].count('1')
        else:
            for i, (l, r) in enumerate(ran):
                cnt[i] += Col[j][l:r].count('1')
    Ans = min(Ans, ans)
print(Ans)


Measured memory_bytes: 46684
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=0;
  string a,b,c;
  cin>>n>>a>>b>>c;
  rep(i,n){
    if(a[i]==b[i] && b[i]==c[i]){
      
    }else if(a[i]==b[i] && b[i]!=c[i] || a[i]==c[i] && a[i]!=b[i] || b[i]==c[i] && a[i]!=b[i]){
      ans+=1;
    }else{
      ans+=2;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
using namespace std;
long long length[53];
long long num[53];
long long dfs(long long n, long long x) {
	if (n == 0) {
		if (x == 0)return 0;
		if (x == 1)return 1;
	}
	if (x == 0)return 0;
	if (x == 1)return 0;
	if (x > 1 && x <= 1+length[n - 1])return dfs(n - 1, x - 1);
	if (x == 1 + length[n - 1] + 1)return 1 + num[n - 1];
	if (x == length[n])return num[n];
	return num[n-1]+1+dfs(n - 1,x-2-length[n-1]);
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	length[0] = 1;
	num[0] = 1;
	for (int i = 1; i <= 50; i++) {
		length[i] = length[i - 1] * 2 + 3;
		num[i] = num[i - 1] * 2 + 1;
	}
	long long n, x;
	cin >> n >> x;
	cout << dfs(n, x);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
    int i;
    int z,y,x,w,v,u,t,s;
    while(1){
        scanf("%d %d %d",&a,&b,&c);
        if(a == 0 && b==0 &&c==0) break;
        z=a*a;
        y=b*b;
        x=c*c;
        scanf("%d",&d);
        for(i=0;i<d;i++)
        {
            scanf("%d",&w);

            v=2*w;
            u=v*v;
            if(z+y<u || z+x<u || y+x<u) printf("OK\n");
            else printf("NA\n");
        }

    }
    return 0;
}

Measured memory_bytes: 0
N = int(input())
blank = 2
h = list(map(int,input().split())) + [0] * blank
INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])

Measured memory_bytes: 20476
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		int[] arr = r.ria();
		int[] d = r.riaml(arr[0]);
		Arrays.sort(d);
		int c = 0;
		for(int ad : d) {
			c++;
			arr[1] -= ad;
		}
		while(arr[1] >= d[0]) {
			arr[1] -= d[0];
			c++;
		}
		print(c);	
	}
	//a & b =1...k=1/2
	// k > a & b
	
	public static int getDigitSum(int n) {
		String str = ""+n;
		int sum = 0;
		for(int i = 0; i<str.length();i++) {
			sum += Integer.parseInt(""+str.charAt(i));
		}
		return sum;
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static void swap(int[] arr, int pos1, int pos2) {
		int temp = arr[pos1];
		arr[pos1] = arr[pos2];
		arr[pos2] = temp;
	}
	public static void swap(long[] arr, int pos1, int pos2) {
		long temp = arr[pos1];
		arr[pos1] = arr[pos2];
		arr[pos2] = temp;
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>

using namespace std;

int main(void){
    unsigned long long a, b, k;
    cin >> a >> b >> k;

    if (k >= a + b){
        cout << "0 0" << endl;
        return 0;
    }

    else if (a >= k){
        cout << a - k << " " << b << endl;
        return 0;
    }
    else if(k>a&&(k-a)<=b){
        cout << "0 " << b - (k - a) << endl;
        return 0;
    }

    return 0;
}

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

const int maxn = 100+10;

char s[maxn];
ll f[maxn][5];

ll dp(int pos, int sta, bool lim) {
    if(sta<0)
        return 0;
    if(pos==0) {
        if(sta==0)
            return 1;
        else
            return 0;
    }
    if(!lim && f[pos][sta]>=0)
        return f[pos][sta];
    int up = 9;
    if(lim)
        up = s[pos]-'0';
    ll res = 0;
    for(int i=0; i<=up; i++) {
        if(i)
            res += dp(pos-1, sta-1, lim && i==up);
        else
            res += dp(pos-1, sta, lim && i==up);
    }
    if(!lim)
        f[pos][sta] = res;
    return res;
}

int main() {
    scanf("%s", s+1);
    int len = strlen(s+1);
    for(int i=1; i<=len/2; i++)
        swap(s[i], s[len-i+1]);
    int k;
    scanf("%d", &k);
    memset(f, -1, sizeof(f));
    printf("%lld\n", dp(strlen(s+1), k, true));
    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    vec<vec<int> > c(3, vec<int>(3));
    
    REP(j, 3){
        cin >> c[0][j];
    }
    FOR(i, 3, 1){
        cin >> c[i][0];
        int t = c[i][0] - c[0][0];
        FOR(j, 3, 1){
            cin >> c[i][j];
            if(c[i][j] - c[0][j] != t){
                cout << "No" << el;return;
            }
        }
    }
    cout << "Yes" << el;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int A, B, C;
string sol() {
    rep(i, 1, 101) if ((A * i) % B == C) return "YES";
    return "NO";
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> A >> B >> C;
    cout << sol() << endl;
}

Measured memory_bytes: 256
import heapq
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N-1)]
C = list(map(int,input().split()))
C.sort(reverse=True)

es = [[] for i in range(N)]
for a,b in src:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

maxdeg = root = 0
for i,ee in enumerate(es):
    if len(ee) > maxdeg:
        maxdeg = len(ee)
        root = i

hq = [(-maxdeg, root)]
heapq.heapify(hq)

ans = [None] * N
ci = 0
ansval = -C[0]
while hq:
    d,v = heapq.heappop(hq)
    ans[v] = C[ci]
    ansval += C[ci]
    ci += 1
    for to in es[v]:
        if ans[to] is not None: continue
        heapq.heappush(hq, (-len(es[to]),to))

print(ansval)
print(*ans)

Measured memory_bytes: 9308
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  string ans = "";
  for(int i = 0; i < s.length(); ++i) {
    if(s[i] == '0') ans.push_back('0');
    else if(s[i] == '1') ans.push_back('1');
    else
      if(ans.length() > 0) ans.pop_back();
  }
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 256
def Dis(X,Y,p):
    D = 0
    for x, y in zip(X, Y):
        dis = abs(x - y) ** p
        D += dis 
    result = D ** (1/p)
    print(result)
def Dis_Che(X, Y):
    print(max(abs(x-y) for x, y in zip(X, Y)))

n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

for p in range(1,4):
    Dis(X, Y, p)
Dis_Che(X,Y)


Measured memory_bytes: 5644
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstdio>   
#include <cmath>
#include <atcoder/math>
#include <atcoder/dsu>


using namespace std;
using namespace atcoder;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
      a[i]--; b[i]--;
    }
    dsu d(n);
    rep(i,m){
        d.merge(a[i],b[i]);
    }
    vector<bool> parent(n);
    rep(i,n){
        int l = d.leader(i);
  //    cout << i << ": " << d.leader(i) << endl;
        if(!parent[l]) parent[l] = true;
    }
    int ans = 0;
    rep(i,n){
//	cout << i << ":" << parent[i] << endl;      
    if(parent[i]) ans++;
    }
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 4580
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m, x = MAP()
a = LIST()
ans1 = 0
for i in range(x, n + 1):
    ans1 += 1 if i in a else 0
ans2 = 0
for i in range(x + 1):
    ans2 += 1 if i in a else 0
print(min(ans1, ans2))

Measured memory_bytes: 59884
#include <iostream>
#include <string>
#include <stack>
using namespace std;

typedef stack<char> P;

int main()
{
     const char s[5] = "()[]";
     string str;
     while (getline(cin, str), str.size() > 1) {
          P p;
          bool flag  =true;
          for (int i = 0; i < str.size(); i++) {
               if (str[i] == s[0] || str[i] == s[2]) p.push(str[i]);
               else if (str[i] == s[1] || str[i] == s[3]) {
                    if (p.size() < 1) {
                         flag = false;
                         break;
                    } else if (str[i] == s[1] && p.top() == s[0]) p.pop();
                    else if (str[i] == s[3] && p.top() == s[2]) p.pop();
                    else {
                         flag = false;
                         break;
                    }
               }
          }
          if (flag && p.size() == 0) cout << "yes" << endl;
          else cout << "no" << endl;
     }

     return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll k,x;
	cin>>k>>x;
	if(k*500>=x){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG


int main(void)
{
  int N;
  int R;
  cin >> N >> R;
  if(N>=10)
  {
    cout << R;
  }
  else
  {
    cout << R + 100*(10-N);
  }
  
  
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(void) {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool flag = true;
    rep(i, n) {
        if(a[i]%2==0) {
            if(a[i]%3!=0&&a[i]%5!=0)
                flag = false;
        }
    }
    if(flag)
        cout << "APPROVED";
    else
        cout << "DENIED";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int p1,p2,p3,j1,j2;
int main(){
    cin >> p1 >> p2 >> p3 >> j1 >> j2;
    cout<<min(min(p1,p2),p3)+ min(j1,j2) - 50<<endl;
    return 0;
}

Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int N;
	std::cin >> N;
	std::vector<int>V(N);
	std::vector<int>C(N);
	std::vector<int>A(N);
	int sum = 0;
	for (int i = 0;i < N;++i) {
		std::cin >> V[i];
	}
	for (int i = 0;i < N;++i){
		std::cin >> C[i];
		A[i] = V[i] - C[i];
		if (A[i] > 0) {
			sum += A[i];
		}
	}
	std::cout << sum << std::endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;cin>>n>>m;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(), a.end());
  map<int, int> mp;
  for(int i=0;i<m;i++){
    int b,c;cin>>b>>c;
    mp[c]+=b;
  }
  ll res=0;
  auto mp_kv = mp.rbegin();
  ll mp_k = mp_kv->first;
  ll mp_v = mp_kv->second;
  mp.erase(mp_k);
  for(int i=0;i<n;i++){
    if(mp_v<=0&&mp.size()==0){
      res += a[i];
      continue;
    }

    if(mp_v<=0&&mp.size()>0){
      mp_kv = mp.rbegin();
      mp_k = mp_kv->first;
      mp_v = mp_kv->second;
      mp.erase(mp_k);
    }

    if(a[i]<mp_k){
      mp_v--;
      res += mp_k;
    }else {
      res += a[i];
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 5376
use std::io::*;
use std::str::FromStr;
use std::clone::Clone;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


struct BIT {
    n: usize, 
    data: Vec<i64>,
}

impl BIT {
    fn new(n: usize) -> BIT {
        let mut vec = vec![0; n+1];
        BIT {
            n: n, 
            data: vec
        }
    }

    fn add(&mut self, i: usize, x: i64) {
        let mut i: i32 = i as i32;
        while i <= (self.n as i32) {
            self.data[i as usize] += x;
            i = i + (i & -i);
        }
    }

    // [1, i] での和
    fn sum(&mut self, i: usize) -> i64 {
        let mut i: i32 = i as i32;
        let mut ret: i64 = 0;
        while i > 0 {
            ret += self.data[i as usize];
            i = i - (i & -i);
        }
        return ret
    }
}

fn main() {
    let n: usize = read();
    let q: usize = read();

    let mut tree = BIT::new(n);

    for _ in 0..q {
        let com: u8 = read();
        let x: usize = read();
        let y: i64 = read();
        if com == 0 {
            tree.add(x, y);
        } else {
            println!("{}", tree.sum(y as usize) - tree.sum(x-1));
        }
    }
}


Measured memory_bytes: 5044
import fractions

a, b, c, d = map(int, input().split())

cd = (c*d) // fractions.gcd(c, d)
am = (a-1)//c + (a-1)//d - (a-1)//cd
bm = b//c + b//d - b//cd

print((b-a+1) - (bm-am))


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,s=0;
  cin>>n;
  vector<int> d(n);
  for(auto &i:d)cin>>i;
  for(int i=0;i<n-1;++i)for(int j=i+1;j<n;++j)s+=d[i]*d[j];
  cout<<s;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#include <algorithm>
 
using namespace std;
 
long long int sum = 0;
 
 
void merge(int A[],int left,int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1],R[n2+1];
    for(int i = 0; i < n1; i++) L[i] = A[left + i];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] =  INT_MAX;
 
    int i = 0, j = 0;
    for(int k = left;k < right; k++){
        if(L[i] < R[j]){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
            sum += n1 - i;
        }
    }
}
 
void mergeSort(int A[],int left,int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    mergeSort(A,0,n);
 
    printf("%lld\n",sum);
 
}


Measured memory_bytes: 4304
#include <bits/stdc++.h>

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b; cin >> a >> b;
    int ans = max(0, a - 2 * b);
    cout << ans << endl;

    return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, c1, c2;
  cin >> n;
  vecll x(n), t(n);
  forll(i, 0, n)
	cin >> x[i];
  t = x;
  sort(t.begin(), t.end());
  c1 = t[n / 2 - 1];
  c2 = t[n / 2];
  forll(i, 0, n){
	if(x[i] <= c1)
	  cout << c2 << endl;
	else
	  cout << c1 << endl;
  }
}


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

int main()
{
    long long N,A,B,C,D,E;
    cin >> N >> A >> B >> C >> D >> E;
    auto vmin = min(min(min(A, B), min(C, D)), E);
    cout<<((N-1)/vmin + 5)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <cmath>
#include <stack>
using namespace std;
#define fio ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



ll N, k;
stack<char> ans;
int main(){
	scanf("%lld", &N);
	while (N) {
		ans.push(abs(N%2) + '0');
		if (N > 0)
			N >>= 1;
		else
			N = (N - 1) / 2;
		N *= -1;
	}
	bool flag = 0;
	while (!ans.empty() && ans.top() == '0') ans.pop();
	while (!ans.empty()) {
		printf("%c", ans.top());
		flag = 1;
		ans.pop();
	}
	if (!flag) printf("0");

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		String b = sc.next();
		String[] ary = b.split("");
		int answer = 0;
		String ACGT = "ACGT";
		int x = 0;
		for (String str : ary) {
			if (ACGT.indexOf(str) >= 0) {
				x++;
			} else {
				if (answer < x) {
					answer = x;
				}
				x = 0;
			}
		}

		answer = Math.max(answer, x);

		System.out.println(answer);

	}

}


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

int main(){
	int n; cin>>n;
	vector<char>a(n);
	bool p=false,w=false,g=false,y=false;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]=='P'){
			p=true;
		}
		else if(a[i]=='W'){
			w=true;
		}
		else if(a[i]=='G'){
			g=true;
		}
		else if(a[i]=='Y'){
			y=true;
		}
	}
	int ans=0;
	if(p){
		ans++;
	}
	if(w){
		ans++;
	}
	if(g){
		ans++;
	}
	if(y){
		ans++;
	}
	if(ans==3){
		cout<<"Three"<<endl;
	}
	else{
		cout<<"Four"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256