akhauriyash/Code-Regression huggingface dataset:
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(ALL(a), greater<ll>());

  if(n == 2) {
    cout << a[0] << endl;
    return 0;
  }

  if(n == 3) {
    cout << a[0] + a[1] << endl;
    return 0;
  }

  if(n == 4) {
    cout << a[0] + a[1] + a[1] << endl;
    return 0;
  }

  ll ans = a[0] + a[1] + a[1];

  REP(i, n - 4) {
    ll j = i / 2;
    ans += a[2 + j];
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

void fizzbuzz(int a[], int n) {
    int i;
    for(i = 0; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0) {
            a[i] = i;
        }
        else a[i] = 0;
    }
}

long long int sum(int a[], int n) {
    long long int s = 0, i;
    for(i = 0; i <= n; i++) {
        s += a[i];
    }
    return s;
}

int main() {
    int n;
    cin >> n;
    int a[n+1];
    fizzbuzz(a, n);
    cout << sum(a, n) << endl;
    return 0;
}

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

const int LIMIT = 200002;
int N, C, s[100000], t[100000], c[100000];
int imos[LIMIT], sm[LIMIT], ans;

int main() {
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        scanf("%d %d %d", &s[i], &t[i], &c[i]);
    }
    for (int i = 1; i <= C; i++) {
        for (int j = 0; j < LIMIT; j++) imos[j] = 0;
        for (int j = 0; j < N; j++) if(c[j] == i) imos[s[j]*2-1]++, imos[t[j]*2+1]--;
        for (int j = 1; j < LIMIT; j++) imos[j] += imos[j-1];
        for (int j = 0; j < LIMIT; j++) if(imos[j]) sm[j]++;
    }
    for (int i = 0; i < LIMIT; i++) {
        ans = max(ans, sm[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int cal(int n){
    int ret=0;
    while(n%100==0){
        n /= 100;
        ret++;
    }

    return ret;
}

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

    int cnt=0, ans=0;
    while(cnt<N){
        ans++;
        if(cal(ans)==d){
            cnt++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> S(N,0);
  for(int i=0;i<N;i++){
    cin >> S[i];
  }
  int Q,x,sum=0;
  cin >> Q;
  for(int i=0;i<Q;i++){
    cin >> x;
    bool exist = false;
    int U=-1,L=N,M;
    while(L-U>1){
      M=(U+L)/2;
      //cout << M <<" ";
      if(S[M]>x){
        L=M;
      }else if(S[M]<x){
        U=M;
      }else{
        exist = true;
        //cout << "#"<<x ;
        break;
      }
    }
    //cout << endl;
    if(exist){
      sum ++;
    }
  }
  cout << sum << endl;
}


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

int main(){
	long m;
	scanf(" %ld", &m);
	for(long i=0; i<m; ++i){
		string s;
		string list[5000];
		long count=0;
		
		cin >> s;
		long size=s.size();
		
		for(int j=1; j<=size-1; ++j){
			string a=s.substr(0,j)	;
			string b=s.substr(j,size-j);
			
			for(int p=0; p<2; ++p){
				if(p) reverse(a.begin(), a.end());
				
				for(int q=0; q<2; ++q){
					reverse(b.begin(), b.end());
					
					for(int r=0; r<2; ++r){
						string tmp="";
						if(r==0) tmp+=b+a;
						else tmp+=a+b;
						//cout << tmp <<endl;
						
						bool flag=true;
						for(long x=0; x<count; ++x){
							if(tmp==list[x]){
								flag=false;
								break;	
							}	
						}
						
						if(flag) list[count++]=tmp;
							
					}
				}
				
			}
			
		}
		
		//for(long x=0; x<count; ++x) cout << " " << list[x] << endl;
		
		printf("%ld\n", count);
	}
	return 0;
}

Measured memory_bytes: 1340
#include <iostream>
#include <cstring>
#include <map>
#include <iterator>
using namespace std;

int main()
{
    map<int ,int >q;
    int n;
    cin >> n;
    int sum = 0;
    map<int , int>::iterator it;
    while(n--)
    {
        int temp;
        cin >> temp;
        it = q.find(temp);
        if(it == q.end())
        {
            q[temp] = 1;
            sum++;
        }else{
            if(q[temp]==1)
            {
                q[temp]=0;
                sum--;
            }else{
                q[temp]=1;
                sum++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
N, A, B = list(map(int, input().split()))


def num_sum(n):
    p = list(map(int, str(n)[::-1]))
    _sum = 0
    for _i in range(len(p)):
        _sum += p[_i]
    return _sum


ans = 0
for i in range(N+1):
    if A <= num_sum(i) <= B:
        ans += i

print(ans)


Measured memory_bytes: 3060
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}

ll N;
ll M;
ll K;
vl A;
vl B;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    cin >> M;
    cin >> K;
    A = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    B = vl(M);
    for(int i = 0; i < M; ++i){
        cin >> B[i];
    }
    solve();
}

// 1 <= N, M <= 200000
// 1 <= K <= 10^9
// 1 <= A_i, B_i <= 10^9
// 入力中の値はすべて整数である。

// ll N, ll M, ll K, vl A, vl B
// 読むことのできる本の最大数を表す整数を出力せよ。
void solve(){
    vl a(N+1),b(M+1);
    rep(i,N)a[i+1]=A[i]+a[i];
    rep(i,M)b[i+1]=B[i]+b[i];
    ll ans=0;
    repe(i,N){
        if(K-a[i]<0)continue;
        ll cnt=upper_bound(all(b),K-a[i])-b.begin()-1;
        chmax(ans,i+cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll x,k,t;
    cin>>x>>k>>t;
    ll ans=t;
    ll m=k;
    while (k<x){
        k+=m;
        ans+=t;
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 1000005;

llint n, cnt = 1, sol;
string s[MAXN];
int p[MAXN][26], val[MAXN], siz[MAXN];
int dp[MAXN][26];

void ubaci (string t) {
    int len = t.size();
    int curr = 1;
    for (int i = len - 1; i >= 0; i--) {
        if (p[curr][t[i] - 'a'] == 0) p[curr][t[i] - 'a'] = ++cnt;
        curr = p[curr][t[i] - 'a'];
    }
    val[curr]++;
}

void dfs (int x) {
    siz[x] += val[x];
    for (int i = 0; i < 26; i++) {
        int sus = p[x][i];
        if (sus == 0) continue;
        dfs(sus);
        siz[x] += siz[sus];
        for (int j = 0; j < 26; j++) {
            if (i != j) dp[x][j] += dp[sus][j]; else dp[x][j] += siz[sus];
        }
    }
}

void upit (string t) {
    int len = t.size();
    int curr = 1;
    for (int i = len - 1; i > 0; i--) {
        curr = p[curr][t[i] - 'a'];
    }
    sol += dp[curr][t[0] - 'a'];
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
        ubaci(s[i]);
    }
    dfs(1);
    for (int i = 1; i <= n; i++) upit(s[i]);
    for (int i = 1; i <= cnt; i++) sol -= val[i]*val[i] - val[i] * (val[i] - 1) / 2;
    cout << sol;
    return 0;
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll a,b,c;
	cin>>a>>b>>c;
	if (a<=c&&c<=b){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int N;
void hprintf(int a[]){
    int i;
    for (i = 0; i < N; i++){
        if (i != N - 1){
            printf("%d ", a[i]);
        }
        else{
            printf("%d\n", a[i]);
        }
    }
    
}
int main(void){
    scanf("%d", &N);
    int a[N];
    int i, j;
    int tunc;
    for (int i = 0; i < N; i++)
        scanf("%d", &a[i]);
    hprintf(a);
    for (i = 1; i < N; i++)
    {
        for (j = 0; j < i; j++){
            if(a[i] < a[j]){
                tunc = a[i];
                a[i] = a[j];
                a[j] = tunc;
            }
        }
        hprintf(a);
    }

    return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int p[]=new int[n];
		for(int i=0;i<n;i++) {
			p[i]=scan.nextInt();
		}
		scan.close();
		int cnt=0;
		int check=-1;
		for(int i=0;i<n;i++) {
			if(i+1!=p[i]) {
				cnt++;
				if(check==-1)check=p[i];
				else {
					p[i]=check;
				}
				if(cnt>2)break;
			}
		}
		if(cnt==0||cnt==2)System.out.println("YES");
		else System.out.println("NO");
	}
}

Measured memory_bytes: 22100
S = input()
T = input()

A = len(S)
B = len(T)

dp = [[0] * (B+1) for _ in range(A+1)]
    
for i in range(1, A+1):
    for j in range(1, B+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

lcs_len = dp[A][B]
i = A
j = B
ans = ""
while lcs_len > 0:
    if S[i-1] == T[j-1]:
        ans = S[i-1] + ans
        i -= 1
        j -= 1
        lcs_len -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        
print(ans)  

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

int main() {
  int n, p; cin >> n;
  string s;
  vector<tuple<string, int, int>> a;
  for(int i=1; i<=n; i++) {
    cin >> s >> p;
    p = -p;
    a.emplace_back(tie(s,p,i));
  }

  sort(a.begin(), a.end());

  for(int i=0; i<n; i++) {
    string s; int p, id;
    tie(s, p, id) = a[i];
    cout << id << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, M;
    cin >> N >> M;
    vector<int> c(100000, 0);
    for (int i = 2; i < 100000; i++) {
        while(M % i == 0){
            c[i]++;
            M = M / i;
        }
    }
    

    vector<ll> inv(40); inv[1] = 1;
    for (int i = 2; i < 40; i++) {
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
    }

    
    ll ans = 1;
    for (int i = 2; i < 100000; i++) {
        if(c[i] != 0){
            for (int j = 0; j < c[i]; j++) {
                ans = ans * (c[i] + N - 1 - j) % MOD;
                ans = ans * inv[j+1] % MOD;
            }
        }
    }

    if(M != 1){
        ans = ans * N % MOD;
    }
    printf("%lld\n", ans);

}

Measured memory_bytes: 3756
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}
void in(){} template<typename Head,typename... Tail> void in(Head&& head,Tail&&... tail){cin>>head;in(forward<Tail>(tail)...);}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;
  ll d;
  in(n,d);
  ll x,y;
  int cnt=0;
  rep(i,n){
    in(x,y);
    if(x*x+y*y<=d*d)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int main(void)
{
	int ct;
	char* rp;
	char retu[1000];
	scanf("%d",&ct);
	//fflush(stdin);
	getchar();
	for(int f1=0;f1<ct;f1++){
		gets(retu);
		while(1){
			if(strstr(retu,"Hoshino")==NULL){
				break;
			}
			if(rp=strstr(retu,"Hoshino")){
				rp+=6;
				*rp='a';
			}
		}
		printf("%s\n",retu);
	}
	return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>

int main (void)
{
	int input1;
	int hour,minute,second;
	
	scanf("%d",&input1);
	hour = input1 / 3600;
	minute = (input1 % 3600) / 60;
	second = input1 % 60 ;
	printf("%d:%d:%d\n",hour,minute,second);
	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];
    ll a = 0,b = 0,c = 0;

    ll ans = 0;
    if(A[0] == 0){
        a++;
        ans = 3;
    }

    rep(i,1,N){
        ll x = 0;
        bool flag = false;
        if(a == A[i]){
            x++;
            a++;
            flag = true;
        }
        if(b == A[i]){
            x++;
            if(!flag){
                b++;
                flag = true;
            }
        }
        if(c == A[i]){
            x++;
            if(!flag){
                c++;
                flag = true;
            }
        }
        ans *= x;
        ans %= MOD;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4004
#include <iostream>
#include <vector>
#include <numeric>

int main(void)
{
	int num;
	std::vector<std::vector<int> > vec;
	vec.resize(2);
	std::cin >> num;
	vec[0].resize(num);
	vec[1].resize(num);
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < num; j++) {
			std::cin >> vec[i][j];
		}
	}
	int max = 0;
	for (int i = 0; i < num; i++) {
		std::vector<int> v = vec[0];
		int sum = std::accumulate(v.begin(), v.begin() + i + 1 , 0);
		v = vec[1];
		sum += std::accumulate(v.begin() + i, v.end(), 0);
		if (sum >= max)
			max = sum;
	}
	std::cout << max << std::endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
const int MAX = 10000001; 
int factor[MAX] = { 0 }; 

void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 
main(){
	lli n;
	cin>>n;
	
	generatePrimeFactors(); 

	
	lli count = 0,sum = 0;
	for(lli i=1;i<=n;i++)
	{
		sum += i*calculateNoOFactors(i);
	}
	
	cout<<sum<<"\n";
	
}

Measured memory_bytes: 42688
N=int(input())
alpha=[chr(ord('a') + i) for i in range(26)]
l=[]
def ans(le,alp):
   s=len(set(alp))
   if le==N:
      l.append(alp)
      return
   for i in range(s+1):
      ans(le+1,alp+alpha[i])
ans(1,"a")
for i in l:
   print(i)

Measured memory_bytes: 17192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int width,height;
int gyou_stand_time[50000];
int retu_stand_time[50000];
int gyou_sit_time[50000];
int retu_sit_time[50000];

int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int get_upper_num(const int* arr,int max,int target) {
	int left,right,mid;
	left=0;right=max-1;
	while(left<=right) {
		mid=(left+right)/2;
		if(arr[mid]<=target)left=mid+1;
		else right=mid-1;
	}
	return max-(right+1);
}

int main(void) {
	int query_num,i;
	int q_isretu,q_id,q_order;
	int result;
	while(1) {
		scanf("%d%d%d",&height,&width,&query_num);
		if(height==0 && width==0 && query_num==0)break;
		memset(gyou_stand_time,0,sizeof(gyou_stand_time));
		memset(retu_stand_time,0,sizeof(retu_stand_time));
		memset(gyou_sit_time,0,sizeof(gyou_sit_time));
		memset(retu_sit_time,0,sizeof(retu_sit_time));
		for(i=1;i<=query_num;i++) {
			scanf("%d%d%d",&q_isretu,&q_id,&q_order);
			if(q_isretu) {
				if(q_order) {
					retu_stand_time[q_id]=i;
					retu_sit_time[q_id]=0;
				} else {
					retu_sit_time[q_id]=i;
					retu_stand_time[q_id]=0;
				}
			} else {
				if(q_order) {
					gyou_stand_time[q_id]=i;
					gyou_sit_time[q_id]=0;
				} else {
					gyou_sit_time[q_id]=i;
					gyou_stand_time[q_id]=0;
				}
			}
		}
		qsort(retu_stand_time,width,sizeof(int),qsort_comp);
		qsort(retu_sit_time,width,sizeof(int),qsort_comp);
		result=0;
		for(i=0;i<height;i++) {
			if(gyou_stand_time[i]>gyou_sit_time[i]) {
				result+=width-get_upper_num(
					retu_sit_time,width,gyou_stand_time[i]);
			} else {
				result+=get_upper_num(
					retu_stand_time,width,gyou_sit_time[i]);
			}
		}
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 1484
def fun(m):
    ans = 0
    for i in range(n):
        ans += max(a[i] - m//f[i], 0)
    if ans<=m_:
        return True
    return False

n,m_ = [int(j) for j in input().split()]
a = [int(j) for j in input().split()]
f = [int(j) for j in input().split()]
a = sorted(a)
f = sorted(f)[::-1]
b = []
for i in range(n):
    b.append(a[i]*f[i])
l = 0
r = max(b)

while l<=r:
    # print(l,r)
    m = l + (r-l)//2
    if fun(m)==True:
        r = m
        if l==r:
            break
    elif fun(m)==False:
        l = m+1
print(m)

Measured memory_bytes: 122572
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c)              c.begin(), c.end()
#define CC(x) cout << (x) << endl
#define rep(i,n) for(int i=0;i<n;i++)
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define EPS 1e-9
typedef unsigned long long ull;
using namespace std;

int main()
{

    ll x,y,a;cin >> x >>y;
    ll sum=0;
    for(int i=0;i<y;i++){
        cin >>a;sum+=a;
    }
    if(sum>=x)
        cout << "Yes"<<endl;
    else
        cout <<"No"<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	ll a;
	cin>>a; cout<<a+a*a+a*a*a<<endl;
	return 0;
}

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

string solve(string str)
{
    int n = str.length();
    int cl[n + 1][n + 1];

    memset(cl, 0, sizeof(cl));

    string res;
    int lres = 0;

    int i, in = 0;
    for (i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (str[i - 1] == str[j - 1] && cl[i - 1][j - 1] < (j - i)) {
                cl[i][j] = cl[i - 1][j - 1] + 1;

                if (cl[i][j] > lres) {
                    lres = cl[i][j];
                    in = max(i, in);
                }
            } else
                cl[i][j] = 0;
        }
    }

    if (lres > 0)
        for (i = in - lres + 1; i <= in; i++)
            res.push_back(str[i - 1]);

    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int l;
    cin >> l;
    string str;
    cin >> str;
    cout << solve(str).length() << '\n';
    return 0;
}


Measured memory_bytes: 97920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin >> n;
    set<int> st;
    rep(i,n){
        int a;
        cin >> a;
        st.insert(a);
    }
    if(st.size()!=n){
        cout << "NO" << endl;
    }
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12996
s = int(input())
MOD = 10**9 + 7
C = [0]*(s + 1)
C[0] = 1
for n in range(3, s+1): # n:[3,s]
    for i in range(3, n+1): # i:[3,n]
        C[n] += C[n-i]
        C[n] %= MOD
print(C[s])


Measured memory_bytes: 9068
#include <iostream>
#include "stdio.h"
#include "string.h"
using namespace std;
const int N = 50;
const int X = 50;
int Y[N];

long long solve(int n, int a){
	long long dp[n+1][2 * n * X + 1] = {{0}};
	memset(dp,0,sizeof(long long) * (n+1) * (2*n*X+1));

// 	for(int j = 0; j <= n; j++) {
// 		for(int t = 0; t <= 2 * n * X; t++){
// 			cout << dp[j][t] << " ";
// 		}
// 		cout << endl;
// 	}
	dp[0][n * X] = 1;
	for(int j = 1; j <= n; j++) {
		for(int t = 0; t <= 2 * n * X; t++){
			if(t-Y[j-1] < 0 || t-Y[j-1] > 2 * n * X)
				dp[j][t] = dp[j-1][t];
			else
				dp[j][t] = dp[j-1][t] + dp[j-1][t - Y[j-1]];
		}
	}
	return dp[n][n*X]-1;
}

int main(){
	int n,a;
	cin >> n >> a;
	for(int i = 0; i < n;i++){
		int x; cin >> x;
		Y[i] = x - a;
	}
	cout << solve(n,a) << endl;
}



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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> l(n);
  for (auto &x : l) cin >> x;
  sort(l.begin(), l.end());
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      for (int k = j+1; k < n; ++k) {
        if (l[i]+l[j]>l[k] && l[i] != l[j] && l[j] != l[k]) ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<bitset>
#include<random>
#include<cstdint>
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
ll inf=1ll<<29;

struct BIT{
      ll n;
      vector<ll> bit_;
      BIT(ll n_){
            n=n_;
            rep0(i,n) bit_.push_back(0);
      }
      void add(int index,ll w){
            for(int x=index;x<=n;x+=(x&(-x))) bit_[x]+=w;
      }
      int sum1to(ll index){
            int ret=0;
            for(int x=index;x>0;x-=(x&(-x))) ret+=bit_[x];
            return ret;
      }
      int sum(ll a,ll b){
            if(a==1) return sum1to(b);
            else return sum1to(b)-sum1to(a-1);
      }
};
int main(){
      int n;
      cin>>n;
      BIT bit(n);
      ll a[n];
      ll b[n];
      rep0(i,n){
            cin>>a[i];
            b[i]=a[i];
      }
      sort(b,b+n);
      map<ll,ll> mp;
      rep0(i,n){
            mp[b[i]]=i+1;
      }
      rep0(i,n){
            a[i]=mp[a[i]];
      }
      ll ans=0;
      rep0(i,n){
            ans+=(i-bit.sum(1,a[i]));
            bit.add(a[i],1);
      }
      cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 19988
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main(){
    string s;
    int n,m;
    cin>>s;
    rep(i,(int)(s.size()-1)){
        if(s[i]=='A'&&s[i+1]=='C')return puts("Yes")*0;
    }
    cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a, b, c, x, num = 0;
  cin >> a >> b >> c >> x;

  for(int i = 0; i <= a; i++){
    int left = x - i*500;
    if(left >= 0){
      for(int j = 0; j <= b; j++){
	int left2 = left - j*100;
	if(left2 >= 0){
	  if((left2 % 50 == 0) && (left2 / 50 <= c))
	    num++;
	}
      }
    }
  }

  cout << num;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MAXN 100005
#define mod 998244353
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
int a[105];
int main(){
    ios::sync_with_stdio(false);
    #define int ll
    int n,m;
    cin>>n>>m;
    double s=0;
    for(int i=0;i<n;i++){
        cin>>a[i];s+=a[i];
    }
    double k=s/(4.0*m);
    bool y=1;
    sort(a,a+n,greater<int>());
    for(int i=0;i<m;i++){
        if(a[i]<k){
            y=0;
        }
    }
    if(y)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
    [a, b, c, d] <- fmap read . words <$> getLine :: IO [Int]
    let ab = abs (b - a)
    let bc = abs (c - b)
    let ac = abs (c - a)
    if (ac <= d) || (ab <= d && bc <= d)
        then putStrLn "Yes"
        else putStrLn "No"


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	if(H%h==0 && W%w==0){
		cout << "No" << endl;
		return 0;
	}else if(W%w!=0){
		int s[W+1];
		int p=W/w, q=W%w;
		for(int i=0; i<=W; i++){
			s[i]=-(i/w);
			if(i%w==q) s[i]+=p+1;
		}

		cout << "Yes" << endl;
		for(int i=1; i<=H; i++){
			for(int j=1; j<=W; j++){
				cout << s[j]-s[j-1] << " ";
			}
			cout << endl;
		}
	}else{
		int s[H+1];
		int p=H/h, q=H%h;
		for(int i=0; i<=H; i++){
			s[i]=-(i/h);
			if(i%h==q) s[i]+=p+1;
		}

		cout << "Yes" << endl;
		for(int i=1; i<=H; i++){
			for(int j=1; j<=W; j++){
				cout << s[i]-s[i-1] << " ";
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[200010];
int main()
{
	int N;
	cin >> N;
	for (int i = 1; i < N; i++) {
		int a;
		cin >> a;
		a--;
		cnt[a]++;
	}
	for (int i = 0; i < N; i++) {
		cout << cnt[i] << endl;
	}
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <ostream>
#include <istream>
#include <typeinfo>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <limits>
#include <fstream>
#include <array>
#include <list>
#include <bitset>
#include <functional>
#include <random>
#include <cstring>
#include <chrono>
#include<string>
using namespace std;
#define endl "\n"
#define ll long long int
#define ld long double
#define AREA(a,b) (a*b)
#define f(i, n) for (int i = 0; i < (n); i++)
#define rof(i, n) for (int i = ((n) - 1); i >= 0; i--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector<ll>
#define pb push_back
#define mx 1000005
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//
//bool checkset(ll n,ll k){
//    if(n&(1<<(k-1)))
//        return true;
//    return false;
//}

int findminsum(int v[],int n,int summ,int sum){
    if(n==0){
        return abs((sum-summ) - summ);
    }
    return min(findminsum(v, n-1, summ+v[n-1], sum),
               findminsum(v, n-1, summ, sum));
}

#define ASCII_VALUES 256

void testcases(){
    ll d,s,t;
    cin>>d>>s>>t;
    if((s*t)>=d){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}



int main(){
    boost;
//    ll test;
//    cin>>test;
//    ll t=1;
//    while(test--){
//        cout<<"Case #"<<t<<": ";
//        testcases();
//        t++;
//    }
   testcases();
}


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

template <typename T>
inline T read(){
	T x=0,f=1;char c=getchar();
	while(!isdigit(c)){	if(c=='-') f=-f;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf=1e9+1e7,MAXN=2e5+1e1;

int t[MAXN],n,T,p=2,ans=0,cnt=0,tmp=0;

int main(void){

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d",&n,&T),cnt=T;
	for(int i=1;i<=n;i++) t[i]=readint;
	while(p<=n){
		if(t[p]>cnt) ans+=cnt-tmp,cnt=tmp=t[p];
		else while(t[p]<=cnt && p<=n) cnt=t[p++]+T/*,printf("cnt = %d , ",cnt)*/;
		// printf("ans = %d , cnt = %d , tmp = %d\n",ans,cnt,tmp);
	}
	printf("%d\n",ans+cnt-tmp);

	return 0;
}

Measured memory_bytes: 4496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll X;
    cin >> X;
    ll ans = 0;
    ans += (X/11)*2;
    X -= (X/11)*11;
    if(X != 0){
        if(X <= 6){
            ans += 1;
        }else{
            ans += 2;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3616
# import queue
def main():
    N = int(input())
    if N == 1:
        print(0)
        return
    n = N
    prime = [True for i in range(10**6+1)]
    prime[0] = False
    prime[1] = False
    for i in range(2, len(prime)):
        if prime[i] == True:
            for j in range(i*2, len(prime), i):
                prime[j] = False

    ans = 0
    for i in range(len(prime)):
        if prime[i] == True and n % i == 0:
            p = i
            flag = False
            while n % p == 0:
                ans += 1
                n = n//p
                p *= i
            while n % i == 0:
                n = n//i
    if 1 < n:
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 148004
#include<iostream>
#include<vector>
using namespace std;
int main(void){
  string data;
  cin >> data;
  vector<char> num;
  for (int i = 0; i < (int)data.size(); i++){
    char ch = data.at(i);
    if(ch=='B'&&num.size()!=0){
      num.pop_back();
    }else if(ch=='B'&&num.size()==0){
      continue;
    }else{
      num.push_back(ch);
    }
  }
  for (int i = 0; i < num.size();i++){
    cout << num.at(i);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n-1);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	for (int i = 0; i < n-1; i++) {
		cin >> c[i];
	}

	int ans = 0;
	ans += accumulate(b.begin(), b.end(),0);

	for (int i = 0; i < n - 1; i++) {
		if ((a[i]+1) == (a[i + 1]))ans += c[a[i]-1];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    vector<vector<long long>>adj,dp;
    #define MOD 1000000007
    long long dfs(int v,int p,int colour){
        if(dp[v][colour]!=-1) return dp[v][colour];
        else{
            dp[v][colour]=1;
            
            for(int i=0;i<adj[v].size();i++){
                // long long sub;
                if(adj[v][i]!=p){
                    if(colour==0)
                        dp[v][colour]*=dfs(adj[v][i],v,1)%MOD;
                    else{
                        dp[v][colour]*=(dfs(adj[v][i],v,0)+dfs(adj[v][i],v,1))%MOD;
                    }
                    // dp[v][colour]*=sub;
                 dp[v][colour]%=MOD;
                }
                
            }
            return dp[v][colour]%MOD;
        }
        
    }
    int main(){
        long n;
        cin>>n;
        adj.resize(n+1,vector<long long>(0));
        dp.resize(n+1,vector<long long>(2,-1));
        for(int i=0;i<n-1;i++){
            int x,y;
            cin>>x>>y;
            adj[x].push_back(y);
            adj[y].push_back(x);
        }
        long long ans=(dfs(1,-1,0)+dfs(1,-1,1))%MOD;
        // cout<<dp[1][0];
        cout<<ans;
        return 0;
    }

Measured memory_bytes: 19584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int p_min = Integer.MAX_VALUE;
		for(int i = 0; i < 3; i++){
			p_min = Math.min(p_min, sc.nextInt());
		}
		
		int d_min = Integer.MAX_VALUE;
		for(int i = 0; i < 2; i++){
			d_min = Math.min(d_min, sc.nextInt());
		}
		
		System.out.println((p_min + d_min - 50));
	}

}

Measured memory_bytes: 12000
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
m = [i + 1 for i in range(n)]
c = 0
for i in itertools.permutations(m):
    c += 1
    if list(i) == p:
        a = c
    if list(i) == q:
        b = c
print(abs(a - b))

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


int main() {
  string s;
  cin >> s;
  set<char> a;
  for(int i=0;i<4;i++){
    a.insert(s.at(i));
  }
  if(a.size()==2)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
 
vector<P>v[100009];
int n,used[100009];
 
int dfs(int now){
  used[now]=0;
  r(i,v[now].size()){
    int nex=v[now][i].fi;
    int y=v[now][i].se;
    if(used[nex]!=-1)continue;
    dfs(nex);
  }
}
 
signed main(){
  int sum=0,m;
  memset(used,-1,sizeof(used));
  cin>>n>>m;
  r(i,m){
    int a,b,c;
    cin>>a>>b>>c; a--; b--;
    v[a].push_back(P(b,0));
    v[b].push_back(P(a,0));
  }
  r(i,n){
    if(used[i]!=-1)continue;
    dfs(i);
    sum++;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 11776
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a);
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef double db;
const int N = 1e5+100;
const db EPS = 1e-9;
using namespace std;

void dbg() {cout << "\n";}
template<typename T, typename... A> void dbg(T a, A... x) {cout << a << ' '; dbg(x...);}
#define logs(x...) {cout << #x << " -> "; dbg(x);}

int n,k,a[N],ans,rem[N];
vector<int> G[N];

void dfs(int x){
    rem[x] = 1;
    for(auto &y:G[x]){
        dfs(y);
        if(rem[y] == k && a[y] != 1) ans++, rem[y] = 0;
        rem[x] = max(rem[x],rem[y]+1);
    }
}

int main()
{
    scanf("%d%d",&n,&k);
    rep(i,1,n) scanf("%d",&a[i]);
    if(a[1] != 1) a[1] = 1, ans++;
    rep(i,2,n) G[a[i]].push_back(i);
    dfs(1);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <set>
using namespace std;
int main(){
    long long h,w,n;
    cin >> h >> w >> n;
    long long a[n][2];
    for (int i=0; i<n; i++){
        cin >> a[i][0]>> a[i][1];
    }
    set<pair<long long,long long>> t;
    multiset<pair<long long,long long>> s;
    for (long long  i=0; i<n; i++){
        for (long long j=-2; j<=0; j++){
            for (long long k=-2; k<=0; k++){
                long long x=a[i][0]+j,y=a[i][1]+k;
                if (x>=1 && x<=h-2 && y>=1 && y<=w-2){
                    s.insert(make_pair(x,y));
                    t.insert(make_pair(x,y));
                }
            }
        }
    }
    long long zero;
    zero=(h-2)*(w-2)-t.size();
    cout << zero <<endl;
    for (int i=1; i<10; i++){
        long long num=0;
        for (auto co:t){
            if (s.count(co)==i){
                num++;
            }
        }
        cout << num <<endl;
    }
}

Measured memory_bytes: 116096
#include<iostream>
using namespace std;
int main()
{
	int n;
	while( cin >> n ){
		if( n < 1200 )	cout << "ABC" << endl;
		else if( 1200 <= n && n < 2800 )	cout << "ARC" << endl;
		else	cout << "AGC" << endl;
	}
	
	return 0;
}

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

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

	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];

	int hp = h;
	for(int i=0; i<n; i++) {
		hp -= a[i];
	}
	if(hp <= 0) {
		cout << "Yes";
	} else {
		cout << "No";
	}

}


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

using namespace std;
using ll = long long;

#include <bits/stdc++.h>
using namespace std;

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < (int)s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

int main()
{
    string s;
    cin >> s;
    __int128_t n = parse(s);
    if(n & 1){cout << 0 << endl; return 0;}
    ll cnt = 0;
    __int128_t p = 10;
    while(p <= n) {
        cnt += n / p;
        p *= 5;
    }
    cout << cnt << endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int x;
    cin >> x;

    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>

int main(){
    int n,i;
    int v[20]={0};
    int c[20]={0};
    int ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
        if(v[i]-c[i] > 0){
            ans += v[i]-c[i];
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n, k;

void solve(){
    cin >> n >> k;
    ll t = n / k;
    ll N = n - (t * k);
    cout << min(n, min(abs(N-k), N));
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
A,B,m=map(int,input().split())
a=[int(j) for j in input().split()]
b=[int(j) for j in input().split()]

ans=min(a)+min(b)
for i in range(m):
    x,y,c=[int(j) for j in input().split()]
    ans=min(ans,a[x-1]+b[y-1]-c)

print(ans)



Measured memory_bytes: 18488
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  string s;
  cin >> s;

  ll ans = 0;
  ll n = s.length(), res = 0;
  rep(i, n) {
    if (s[i] == 'W') {
      ans += i - res;
      res++;
    }
  }
  cout << ans << '\n';




  
  return 0;
}

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

int main()
{
    int m, n;

    while( cin >> m )
    {
        if( m == 0 )
            break;
        
        cin >> n;
        
        int cnt = 0;

        for( int i = m; i <= n; i++ )
        {
            int j = i;
            while( j % 2 == 0 )
                j /= 2;
            while( j % 3 == 0 )
                j /= 3;
            while( j % 5 == 0 )
                j /= 5;
            if( j == 1 )
                cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}



Measured memory_bytes: 3048
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int d = sc.nextInt();
    int x = sc.nextInt();
    
    int one = r*x-d;
    int two = r*one-d;
    int three = r*two-d;
    int four = r*three-d;
    int five = r*four-d;
    int six = r*five-d;
    int seven = r*six-d;
    int eight = r*seven-d;
    int nine = r*eight-d;
    int ten = r*nine-d;

    System.out.println(one);
    System.out.println(two);    
    System.out.println(three);
    System.out.println(four);  
    System.out.println(five);
    System.out.println(six); 
    System.out.println(seven);
    System.out.println(eight); 
    System.out.println(nine);
    System.out.println(ten); 
    }
}

Measured memory_bytes: 35560