akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ppb pop_back
#define nuenxfiu ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define TT int testcases;cin>>testcases;while(testcases--)
#define mk make_pair
#define MAX ((int)2e9+17)
#define mod ((int)1e9+7)
#define MOD 1000003
//int fact[1000007]={0};
#define N (int)1e6+10
int fpow(int n, int k, int p = mod) {int r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
using namespace std;



void solve()
{
	int n,m;
	cin>>n>>m;
	
	int h[n+1];
	
	vector<int>v[n+1];
	
	for(int i=1;i<n+1;i++)
	cin>>h[i];
	
	int a;
	int b;
	
	while(m--)
	{
		cin>>a>>b;
		v[a].pb(h[b]);
		v[b].pb(h[a]);
	}
	
	int cnt=0;
	
	for(int i=1;i<=n;i++)
	{
		if(v[i].size()==0)
		cnt++;
		else
		{
		sort(all(v[i]));
		if(v[i].back()<h[i])
		cnt++;
		}
	}
	
	//for(int i=1;i<=n;i++)
	//{
		//for(int j=0;j<v[i].size();j++)
		//cout<<v[i][j]<<" ";
		//cout<<endl;
//	}
	
	cout<<cnt<<endl;
	
}
signed main()
{
    
	nuenxfiu
	//TT
	solve();
     return 0;
}

Measured memory_bytes: 10240
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String[] a=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.next();
Set<String> s=new HashSet<>();
for(String x:a)
s.add(x);
System.out.println(s.size());
}}

Measured memory_bytes: 71052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
const ll mod = 1000000007;

int n, m;
vector<int> a;
int ans[100001];
int temp;
signed main() {
    cin >> n >> m;
    for (int i=0;i<m;i++) {
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(), a.end());

    if (!binary_search(a.begin(), a.end(), 1)) ans[1] = 1;
    if (!binary_search(a.begin(), a.end(), 2)) ans[2] = 1 + ans[1];
    for (int i=3;i<=n;i++) {
        ans[i] = ans[i-1] + ans[i-2];
        ans[i] %= mod;
        if (binary_search(a.begin(), a.end(), i)) {
            ans[i] = 0;
        }
        // cout << i << " " << ans[i] << endl;
    }
   cout << ans[n] << endl;
}

Measured memory_bytes: 1908
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359



int main() {
	ll N, M;
	ll L[50];
	ll sum = 0;
	cin >> N >> M;
	REP(i, N) {
		cin >> L[i];
	}
	sort(L, L + N);
	REP(i, M) {
		sum += L[N - i - 1];
	}
	cout << sum;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int ax,ay,bx,by;
	cin>>ax>>ay>>bx>>by;
	int x=bx-ax,y=by-ay;
	cout<<bx-y<<" "<<by+x<<" "<<ax-y<<" "<<ay+x;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

int main(){
   int N, K;
   std::cin >> N >> K;

   double ans = 0;
   for(int i=1; i<=N; ++i){
      int n = 1;
      int j = 0;
      while(i*n<K){
	 n *= 2;
	 j++;
      }
      ans += std::pow((double)0.5, j); 
   }
   std::cout << std::setprecision(12) << ans/N << std::endl;
   return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int la, lb, ra, rb;
    cin >> la >> lb >> ra >> rb;
    if(la + lb == ra + rb){
        cout << "Balanced" << endl;
    } else if(la + lb > ra + rb){
        cout << "Left" << endl;
    } else {
        cout << "Right" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int a[3]; cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);

	int ans = 0;
	while(a[1] != a[2]){
		ans++;
		a[1]++; a[0]++;
	}

	if((a[1]-a[0])%2 == 0) cout << ans+(a[1]-a[0])/2 << endl;
	else cout << ans+(a[1]-a[0]+1)/2 + 1 << endl;

	return 0;

}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int,input().split()))
    total = sum(A)
    counter = Counter(A)
    Q = int(input())
    for _ in range(Q):
        b,c = map(int,input().split())
        total = total - b*counter[b] + c*counter[b]
        counter[c] += counter[b]
        counter[b] = 0
        print(total)

if __name__ == '__main__':
    main()


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

using namespace std;

#define sp << " " <<
#define mod 998244353

const int p=998244353;
int n,f[10005][10005],sumr[5005];
char s[5005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)sumr[i]=sumr[i-1]+'2'-s[i];
	f[0][0]=1;
	for(int i=1;i<=2*n;i++)
		for(int j=max(0,i-2*min(i,n)+sumr[min(i,n)]);j<=sumr[min(i,n)];j++)
			f[i][j]=(f[i-1][j-1]+f[i-1][j])%p;
	int ans=0;
	for(int i=0;i<=2*n;i++)ans=(ans+f[2*n][i])%p;
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 156160
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int main()
{
	LL n,x;
	LL siz[52],eat[52];
	siz[0]=eat[0]=1;
	scanf("%lld%lld",&n,&x);
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		siz[i]=siz[i-1]*2+3;
		eat[i]=eat[i-1]*2+1;
	}
	for(int i=n;i>=0;i--)
	{
		if(x==0)
			break;
		if(x==siz[i])
		{
			ans+=eat[i];
			break;
		}
		if(x==1)
			break;
		if(x<=(siz[i-1]+1))
		{
			x--;
		}
		else
		{
			ans+=(eat[i-1]+1);
			x-=(siz[i-1]+2);
		}
	}
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	V a(n);
	SCAN(a);
	int i = 1, ans = 0;
	std::set<int> st;
	st.insert(1);
	while(true){
		if(i==2){
			printf("%d\n", ans);
			return 0;
		}
		ans++;
		i = a[i-1];
		if(st.count(i)) break;
		st.insert(i);
	}
	puts("-1");
	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for(int i=0; i < N; i++){
    cin >> W.at(i);
  }
  
  int ans = 100 * N;
  int diff;
  for(int t=0; t < N; t++){
    int S1 = 0;
    int S2 = 0;
    for(int i=0; i < t; i++){
      S1 += W.at(i);
    }
    for(int j=t; j < N; j++){
      S2 += W.at(j);
    }
    diff = max(S1,S2) - min(S1,S2);
    ans = min(ans, diff);
  }

      
  cout << ans << endl;
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,k;
  int d;	//365
  int c[26];
  int score[9490];
  int t[365] = {0};
  int day1[26] = {0};
  double x = 0.36787944117;
  int tmp1=-99999,tmp2=-99999;
  
  scanf("%d",&d);
  for(i=0;i<26;i++){
      scanf("%d ",&c[i]);
  }
  for(i=0;i<d*26;i++){
      scanf("%d ",&score[i]);
  }
  //st
  
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      if(score[i*26+j]-c[j]*(1+day1[j])>tmp1){
       	tmp1 =  score[i*26+j]-c[j];
        t[i] = j;
      }
      for(k=0;k<26;k++){
       day1[k] += 1; 
      }
      day1[t[i]] = 0;
    }
  }
  
  //en
  for(i=0;i<d;i++){
      printf("%d\n",t[i]+1);
  }
 return 0; 
}




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

int main()
{
   int i,j,k,l,m;
   vector<int>vec;
   cin>>l;
   for(i=0;i<l;i++)
   {
       cin>>j;
       vec.push_back(j);
   }
   sort(vec.begin(),vec.end());
   k=l/2;
   m=-(vec[k-1]-vec[k]);
   cout<<m<<endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;

ll powmod(ll x,ll n) {
  ll res = 1;
  rep(i,n) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll U = powmod(10,n), A = powmod(9,n), B = powmod(8,n);
  if(U < 2 * A) U += mod;
  ll ans = U - 2 * A + B;
  ans %= mod;
  ans = (ans + mod) % mod;
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <functional>
#include <cstdio>
using namespace std;

typedef pair<int,int> pii;

const int INF = 1e9;


void func(vector<pii> &dp, const vector<pii> &item, int S, int j){
	if( j < item.size() ){
		int x = 1 << item[j].first;
		if( !(x & S) ){
			pii p(dp[S].first + item[j].second, dp[S].second);
			if( dp[x | S] > p){
				dp[x | S] = p;
				func(dp, item, x | S, j + 1);
			}
		}
		
		func(dp, item, S, j + 1);
	}
}


void dijkstra(
	vector<vector<pii> > &dp,
	const vector<vector<pii> > &road,
	int n, int S
){


	typedef pair<pii,int> piii;

	priority_queue<piii,vector<piii>,greater<piii> > pq;
	for(int i = 0; i <= n; ++i){
		if( dp[i][S].first != INF ){
			pq.push( piii(dp[i][S], i) );
		}
	}

	while( !pq.empty() ){
		piii p = pq.top();
		pq.pop();

		int x = p.second;
		if( dp[x][S] != p.first ) continue;

		for(int j = 0; j < road[x].size(); ++j){
			int t = road[x][j].first;
			pii next(p.first.first, p.first.second + road[x][j].second);

			if(dp[t][S] > next){
				dp[t][S] = next;
				pq.push( piii(next, t) );
			}
		}
	}

}


int main(){
	int n;
	while(cin >> n, n != 0){
		vector<vector<string> > name(n + 1);
		vector<vector<int> > value(n + 1);
		string str;
		int v, k;
		
		for(int i = 1; i <= n; ++i){
			cin >> k;
			name[i].reserve(k);
			value[i].reserve(k);

			for(int j = 0; j < k; ++j){
				cin >> str >> v;
				name[i].push_back(str);
				value[i].push_back(v);
			}
		}
		
		int q;
		cin >> q;
		map<string,int> itemtable;
		for(int i = 0; i < q; ++i){
			cin >> str;
			itemtable[str] = i;
		}
		
		vector<vector<pii> > shop(n + 1);
		for(int i = 1; i <= n; ++i){
			for(int j = 0; j < name[i].size(); ++j){
				map<string,int>::iterator it = itemtable.find(name[i][j]);
				if( it != itemtable.end() ){
					shop[i].push_back( pii(it->second, value[i][j]) );
				}
			}
		}
		
		vector<vector<pii> > road(n + 1);
		int m, s, t, d;
		
		cin >> m;
		for(int i = 0; i < m; ++i){
			cin >> s >> t >> d;
			road[s].push_back( pii(t, d) );
			road[t].push_back( pii(s, d) );
		}
		
		int last = 1 << q;
		vector<vector<pii> > dp(n + 1, vector<pii>(last, pii(INF, INF) ) );
		dp[0][0] = pii(0, 0);

		for(int S = 0; S < last; ++S){
			dijkstra(dp, road, n, S);

			for(int i = 1; i <= n; ++i){
				func(dp[i], shop[i], S, 0);
			}
		}
		
		int cost = dp[0].back().first;
		int dist = dp[0].back().second;
		
		if( cost == INF ){
			cout << "impossible\n";
		}
		else{
			cout << cost << ' ' << dist << '\n';
		}
	}
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N,M;
bool check;

int main(){
    cin>>N>>M;
    char A[N][N],B[M][M];
    rep(i,N){
        rep(j,N){
            cin>>A[i][j];
        }
    }
    rep(i,M){
        rep(j,M){
            cin>>B[i][j];
        }
    }
    rep(i,N-M+1){
        rep(j,N-M+1){
            check=true;
            rep(k,M){
                rep(l,M){
                    if(A[i+k][j+l]!=B[k][l]){
                        check=false;
                        break;
                    }
                }
                if(!check)break;
            }
            if(check){
                out("Yes");
                return 0;
            }
        }
    }
    out("No");
}


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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    string s; cin >> s;
    ll answer = 0;
    ll cnt;
    for(int bit = 0; bit < (1<<s.size()); ++bit) {
        if(bit & (1<<s.size()-1)) break;
        cnt = 0;
        for(int i = 0; i < s.size(); ++i) {
            cnt = cnt*10 + (s[i]-'0');
            if(bit & (1<<i)) {
                answer += cnt;
                cnt = 0;
            }
        }
        answer += cnt;
    }
    cout << answer << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<"safe"<<endl;
  }
  else{
    cout<<"unsafe"<<endl;
  }
}


Measured memory_bytes: 3636
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	LL N,A,B;
	cin >> N >> A >> B;
	if(abs(A-B)%2==0){
		cout << abs(A-B)/2 << endl;
		return 0;
	}
	if(A>B){
		swap(A,B);
	}
	cout << min(A+abs(B-A-1)/2,(N-B+1)+abs(N-(A+N-B+1))/2) << endl;

	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a = 0;//日数
  int b = 0;//宿題の個数
  int c = 0;

  cin >> a >> b ;

  vector<int> vec(b);

  for(int k=0; k < b; k++){
      cin >> vec.at(k);
      c+=vec.at(k);
  }

  //sort(vec.begin(), vec.end());

  //cout << a << b << c << endl;

  if((a-c)>=0){
      cout << a - c << endl;
  }
  else{
      cout << -1 << endl;
  }
 
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>

using Int = long long int;
using std::pair;
using std::vector;

template <class T>
std::map<T, Int> compress(vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, Int> rev;
    for (Int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

int main() {
    int n;
    Int l;
    std::cin >> n >> l;

    vector<pair<Int, Int>> segs(n);
    vector<Int> xs;
    xs.reserve(n * 2);
    for (auto& p : segs) {
        std::cin >> p.first >> p.second;
        xs.push_back(p.first);
        xs.push_back(p.second);
    }

    auto revx = compress(xs);
    for (auto& p : segs) {
        p.first = revx[p.first];
        p.second = revx[p.second];
    }
    l = xs.size();

    std::sort(segs.begin(), segs.end());

    int min = 0;
    Int covered = 0, next = 0;
    for (auto p : segs) {
        if (p.first > covered) {
            ++min;
            covered = next;
        }
        next = std::max(next, p.second);
    }
    if (covered < l - 1) ++min;

    vector<int> imos(l, 0);
    for (auto p : segs) {
        ++imos[p.first];
        --imos[p.second];
    }
    imos.pop_back();
    std::partial_sum(imos.begin(), imos.end(), imos.begin());
    int max = n - *std::min_element(imos.begin(), imos.end()) + 1;

    std::cout << min << " " << max << std::endl;
    return 0;
}



Measured memory_bytes: 34360
s=input()
p,g=0,0
ans=0
for i in s:
    if i=="g":
        if p+1<=g:
            ans+=1
            p+=1
        else:
            g+=1
    if i=="p":
        if p+1<=g:
            p+=1
        else:    
            ans-=1
            g+=1
print(ans)   

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main() {
    int h, n;
    int sum = 0;
    cin >> h >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        sum += a;
    }
    cout << (sum >= h ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,p;
string s,t;

int main(){
    cin >> p;
    for(int i=0;i<p;i++){
        cin >> s >> t;
        n=s.size();
        m=t.size();
        vector<int> memo(m+1,0);
        for(int j=0;j<n;j++){
            vector<int> memo2(m+1,0);
            for(int k=0;k<m;k++){
                memo2[k]=max(memo2[k],memo[k]);
                memo[k+1]=max(memo[k+1],memo[k]);
                memo2[k+1]=memo[k]+(s[j]==t[k]);
            }
            memo2[m]=max(memo2[m],memo[m]);
            for(int k=0;k<m+1;k++){
                memo[k]=memo2[k];
            }
        }
        int c=0;
        for(int j=0;j<m+1;j++){
            c=max(memo[j],c);
        }
        cout << c << endl;
    }
}


Measured memory_bytes: 3160
from collections import defaultdict

n = int(input())
A = list(map(int,input().split()))

D = defaultdict(bool)

for i in range(2**n):
    tmp = 0
    for j in range(n):
        if i>>j & 1:
            tmp += A[j]
    D[tmp] = True

q = int(input())

M = list(map(int,input().split()))

for i in range(q):
    if D[M[i]]:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 6088
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll res = (k % 2 == 0 ? a - b : b - a);
  if((ll)abs(res) <= 1e18)
    cout << res << endl;
  else
    puts("Unfair");
  return 0;
}



Measured memory_bytes: 764
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: u64 = iter.next().unwrap().parse::<u64>().unwrap();
    let f: Vec<u64> = (&mut iter).take(5).map(|x| x.parse().unwrap()).collect();
    let mut min = 1u64 << 60;
    for i in 0..5 {
        min = std::cmp::min(f[i], min);
    }
    let x = if n % min == 0 {n / min} else {n / min + 1};
    println!("{}", x + 4);
}


Measured memory_bytes: 4352
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	long long A, B;
	char op;
	cin >> A >> op >> B;


	long long ret;
	if(op == '+')
		ret = A + B;
	else
		ret = A - B;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int n,k;
    int ans = 0;
    int p[1000];
    cin >> n;
    cin >> k;
    
    rep (i, n) {
        cin >> p[i];
    }
    sort(p, p+n);
    rep (i, k) {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3152
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : k : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    count :: Int -> Int
    count l = l * (n - l + 1) + 1
    c :: Int
    c = foldl step 0 . map count $ [k..(succ n)]
      where
        step x y = (x + y) `mod` modulus
  print c

modulus :: Int
modulus = 1000000007

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
#define w(x) int x;cin>>x;while(x--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define ppi pair<Sint,int>
#define ppl pair<ll,ll>
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define mset multiset
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll binpow(ll x, ll y, ll p){  ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}  
ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a % b); } 
bool parity(ll x,ll y){ bool f = ((x ^ y) < 0);return !f;}

int main()
{
    IOS

    int n,k;
    cin>>n>>k;
    vll v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
 
    vll dp(n,1e18);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                ll val=dp[i-j]+abs(v[i]-v[i-j]);
                if(dp[i]>val)
                    dp[i]=val;
            }
        }
    }    
    cout<<dp[n-1];
    
    return 0;

}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}


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

	cin >> a;

	int ans = 0;
	
	rep(i, 0, a) {
		
		int b;
		cin >> b;
		ans += calc(b);

	}

	cout << ans << endl;

}
	

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

int main(void){
    int A,B,C,D,E,F,G;
    cin >> A >> B >> C >> D >> E >> F;

    double max=0.0;
    int w=0,s=0;

    for(int x=0; x<F; x=x+100*A){
        for(int y=0; y<F; y=y+100*B){
            for(int u=0; u<F; u+=C){
                for(int v=0; v<F; v+=D){

                    if(x==0 and y==0) continue;
                    if(x+y+u+v>F) continue;
                    if(100*(u+v)>E*(x+y)) continue;

                    if((double)(u+v)/(double)(x+y+u+v)>=max){
                        max=(double)(u+v)/(double)(x+y+u+v);
                        w=x+y; s=u+v;
                    }
                }
            }
        }
    }

    cout << w+s << " " << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 10000000000007;




int main() {
  int N,M;
  cin >> N >> M;
  long long int A[M],B[M],C[M];

  for(int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;
    B[i]--;
  }
  long long int ma = C[0];
  long long int mi = C[0];
  for(int i = 0; i < M; i++) {
    if(ma < C[i]) ma = C[i];
    if(mi > C[i]) mi = C[i];
  }

  for(int i = 0; i < M; i++) {
    C[i] = -C[i];
  }

  long long int d[N];
  for(int i = 0; i < N; i++) {
    d[i] = INF;
  }
  d[0] = 0;
  int cnt = 0;
  bool updateFlag;
  while(true){
    updateFlag = false;
    for(int i = 0; i < M; i++){
      if(d[A[i]] != INF && d[B[i]] > d[A[i]] + C[i]){
        d[B[i]] = d[A[i]] + C[i];
        updateFlag = true;
      }
    }
    cnt += 1;
    if(cnt == N - 1) {
      break;
    }
  }
  long long int ans = d[N-1];
  bool neg[N];
  for(int i = 0; i < N; i++) {
    neg[i] = false;
  }
  cnt = 0;
  while(true){
    updateFlag = false;
    for(int i = 0; i < M; i++){
      if(d[A[i]] != INF && d[B[i]] > d[A[i]] + C[i]){
        d[B[i]] = d[A[i]] + C[i];
        neg[B[i]] = true;
      }
    }
    cnt += 1;
    if(cnt == N) {
      break;
    }
  }
  if(neg[N-1]) {
    cout << "inf" << endl;
  } else {
    cout << -ans << endl;
  }






  // 閉路






}


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

int main(void){
    int x[5];
    rep(i,5)cin>>x[i];
    rep(i,5)if(x[i]==0)cout<<i+1;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

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 MAX=5010;
using P=pair<ll,pair<int,int>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,S; cin >> N >> M >> S;
    struct edge{int to; int pay;ll cost;};
    vector<vector<edge>> G(N);
    for (int i=0;i<M;++i){
        int U,V,A; ll B; cin >> U >> V >> A >> B; --U,--V;
        G[U].emplace_back(edge{V,A,B});
        G[V].emplace_back(edge{U,A,B});
    }
    vector<int> C(N);
    vector<ll> D(N);
    for (int i=0;i<N;++i) cin >> C[i] >> D[i];
    vector<vector<ll>> dp(N,vector<ll>(MAX+1,IINF));
    dp[0][min(MAX,S)]=0;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push({0LL,{0,min(MAX,S)}});
    while(!pq.empty()){
        auto p=pq.top(); pq.pop();
        ll d=p.first; int v=p.second.first,c=p.second.second;
        if (dp[v][c]<d) continue;
        if (chmin(dp[v][min(MAX,c+C[v])],d+D[v]))
            pq.push({dp[v][min(MAX,c+C[v])],{v,min(MAX,c+C[v])}});
        for (auto &e:G[v]){
            if (c<e.pay) continue;
            if (chmin(dp[e.to][c-e.pay],dp[v][c]+e.cost))
                pq.push({dp[e.to][c-e.pay],{e.to,c-e.pay}});
        }
    }
    for (int i=1;i<N;++i){
        ll ans=IINF;
        for (int j=0;j<=MAX;++j) chmin(ans,dp[i][j]);
        cout << ans << '\n';
    }
}

Measured memory_bytes: 9328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
char a[2][60];

int main()
{
    int i,k,m;
    ll ans;
    ios::sync_with_stdio(false);
    cin>>m;
    cin>>a[0];
    cin>>a[1];
    if(a[0][0]==a[1][0])
    {
        ans=3;
        i=1;
        k=1;
    }
    else{
        ans=6;
        i=2;
        k=2;
    }
    while(i<m)
    {
        if(a[0][i]==a[1][i])
        {
            if(k==1) ans=ans*2%mod;
            i++;
            k=1;
        }
        else{
            if(k==1) ans=ans*2%mod;
            else ans=ans*3%mod;
            i+=2;
            k=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, K; cin >> N >> K;
	vector<int>A(N); rep(i, 0, N) { cin >> A[i]; }
	vector<int>F(N); rep(i, 0, N) { cin >> F[i]; }
	sort(all(A));
	sort(all(F));
	reverse(all(F));
	vector<int>v;
	rep(i, 0, N) {
		v.eb(A[i] * F[i]);
	}
	dump(A);
	dump(F);
	dump(v);

	auto f = [&](int m) {
		int k = K;
		rrep(i, 0, N) {
			if (A[i] * F[i] - m > 0) {
				int x = m / F[i];
				k -= A[i] - x;
			}
		}
		return k >= 0;

	};

	int l = -1, r = 1e13;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (f(m)) {
			r = m;
		}
		else {
			l = m;
		}
	}
	cout << r << endl;

	return 0;
}


Measured memory_bytes: 5620
#pragma region template 1.0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    ll N;
    cin >> N;
    vi A(N);
    REP(i, N)
    {
        cin >> A[i];
    }
    ll ans = 0;
    while (true)
    {
        bool flag = true;
        REP(i, N)
        {
            if (A[i] % 2 == 1)
            {
                flag = false;
            }
            A[i] /= 2;
        }
        if (not flag)
        {
            break;
        }
        ++ans;
    }
    OUT(ans);
}
#pragma endregion template

Measured memory_bytes: 256
let () =
  let result = ref 0 in
  let x =
    Scanf.scanf "%d" (fun x -> x) in
  let expo = Array.make (x+1) 0 in
  expo.(1) <- 1;

  for b = 2 to x do
    let v = ref (b * b) in
    while !v <= x do
      expo.(!v) <- 1;
      v := b * !v;
    done;
  done;

  for i = 0 to x do
  if expo.(i) = 1 then
    result := i
done;
  Printf.printf "%d\n" !result
    


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

int main()
{
  long n,m,k,ans,ma=LONG_MAX,mb=LONG_MAX;
  cin>>n>>m>>k;
  vector<long> a(n),b(m) ;
  for(long i = 0;i<n;i++){
    cin>>a[i];
    ma = min(ma,a[i]);
  }
  for(long i = 0;i<m;i++){
    cin>>b[i];
    mb = min(b[i],mb);
  }
  ans = ma+mb;
  for(long i = 0;i<k;i++){
    long x,y,p,dis;
    cin>>x>>y>>p;
    dis = a[x-1]+b[y-1] - p;
  	ans = min(ans,dis);
  }
  cout<<ans;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> A(N,vector<int>(N-1));
  for(int i=0;i<N;i++){
    for(int j=0;j<N-1;j++){
      cin >> A.at(i).at(j);
      A.at(i).at(j)--;
    }
  }

  int ans=1;
  set<pair<int,int>> S;
  int usedi=0;
  vector<pair<int,int>> used;
  for(int i=0;i<N;i++){
    pair<int,int> tmp=m_p(i,A.at(i).at(0));
    if(tmp.fi>tmp.se) swap(tmp.fi,tmp.se);

    if(S.count(tmp)){
      S.erase(tmp);
      used.p_b(tmp);
    }
    else  S.insert(tmp);
  }

  vector<int> now(N,0);
  while(1){
    if(S.empty() && usedi==sz(used)) break;
    if(usedi==sz(used)){
      cout << -1 << endl;
      return 0;
    }
    ans++;
    int end=sz(used);
    for(int i=usedi;i<end;i++){
      int tmp1=used.at(i).fi;
      int tmp2=used.at(i).se;
      now.at(tmp1)++;
      now.at(tmp2)++;
      if(now.at(tmp1)<N-1){
        pair<int,int> tmp=m_p(tmp1,A.at(tmp1).at(now.at(tmp1)));
        if(tmp.fi>tmp.se) swap(tmp.fi,tmp.se);

        if(S.count(tmp)){
          S.erase(tmp);
          used.p_b(tmp);
        }
        else  S.insert(tmp);
      }
      if(now.at(tmp2)<N-1){
        pair<int,int> tmp=m_p(tmp2,A.at(tmp2).at(now.at(tmp2)));
        if(tmp.fi>tmp.se) swap(tmp.fi,tmp.se);

        if(S.count(tmp)){
          S.erase(tmp);
          used.p_b(tmp);
        }
        else  S.insert(tmp);
      }
    }
    usedi=end;
  }
  cout << ans-1 << endl;

  return 0;
}

Measured memory_bytes: 11356
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    h,n = LI()
    ab = [LI() for _ in range(n)]
    r = [inf] * (h+10**4+2)
    r[0] = 0
    for a,b in ab:
        for i in range(h):
            t = r[i] + b
            if r[a+i] > t:
                r[a+i] = t

    return min(r[h:])


print(main())





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

int main(){
    vector<long long int> N(4);
    scanf("%lld%lld%lld%lld", &N[0], &N[1], &N[2], &N[3]);
    sort(N.begin(), N.end());
    puts(N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9 ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 764
// Comment
// Use W_i, Get S_i <= N <= 50
// think S_a / W_a >= S_b / W_b
// number of b >= S_a , then remove S_a b, add S_b a. It is more good.

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 50 + 5;

struct NODE {
	ll w;
	int s, ix;
	ll d;

	NODE(ll _w, int _s, int _ix, ll _d): w(_w), s(_s), ix(_ix), d(_d) {}
	bool operator<(const NODE other) const {
		return s * other.w < other.s * w;
	}
	void print() {
		printf("%lld %d %d %lld\n", w, s, ix, d);
	}
};

int N;
ll X, D;
ll C[MAX_N]; 
int P[MAX_N], S[MAX_N];
ll Dp[MAX_N * MAX_N * MAX_N];
int main() {
	cin >> N >> X >> D;
	scanf("%lld", &C[1]);
	for(int i=2; i<=N; i++) scanf("%lld%d", &C[i], &P[i]);
	for(int i=1; i<=N; i++) S[i] = 1;
	for(int i=N; i>=2; i--) {
		S[P[i]] += S[i];
		C[P[i]] += C[i];
	}
	vector<NODE> ns;
	for(int i=1; i<=N; i++) ns.emplace_back(C[i], S[i], i, i == 1 ? LINF : D);
	sort(ALL(ns));
	reverse(ALL(ns));
	//for(int i=0; i<N; i++) ns[i].print();
	
	for(int i=0; i<=N*N*N; i++) Dp[i] = LINF;
	Dp[0] = 0;

	for(int i=0; i<N; i++) {
		for(int j=N*N*N; j>=0; j--) {
			for(int k=1; k<=min(1ll*N, ns[i].d); k++) {
				if(j + ns[i].s*k > N*N*N) break;
				Dp[j+ns[i].s*k] = min(Dp[j+ns[i].s*k], Dp[j] + ns[i].w*k);
			}
		}
	}

	ll ans = 0;
	for(int k=N*N*N; k>=0; k--) {
		if(Dp[k] > X) continue;
		ll now = k;
		ll rest = X-Dp[k];
		for(int i=0; i<N; i++) {
			ll use = min(rest / ns[i].w, 1ll*ns[i].d-min(1ll*N, ns[i].d));
			rest -= use * ns[i].w;
			now += ns[i].s * use;
		}
		ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4656
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

vector<int> adj[5];
bool cnt = true;
bool vis[5];

void dfs(int src, int par = -1){
    vis[src] = true;
    if(adj[src].size() > 2){
        cnt = false;
        return;
    }
    for(int u : adj[src]){
        if(u == par) continue;
        dfs(u, src);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    f(i, 3){
        int u, v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    rep(i, 1, 4){
        cnt = true;
        memset(vis, false, sizeof(vis));
        dfs(i);
        bool ok = true;
        rep(j, 1, 4) ok &= vis[i];
        if(ok && cnt){
            cout<<"YES\n";
            return 0;
        }
    }
    cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=62,M=1e9+7;
int dp[N][2][2][2];
int32_t main(){
    int l,r;
    cin>>l>>r;
    forn(i,N){
        forn(fl,2){
            forn(fr,2){
                forn(bylo,2){
                    int&ans=dp[i][fl][fr][bylo];
                    forn(dx,2){
                        forn(dy,2){
                            if(dx>dy)continue;
                            if(!bylo&&dx!=dy)continue;
                            int bitl=l>>i&1;
                            int bitr=r>>i&1;
                            if(fl&&bitl&&!dx)continue;
                            if(fr&&!bitr&&dy)continue;
                            if(!i)ans++;
                            else{
                                (ans+=dp[i-1][fl&&bitl==dx][fr&&bitr==dy][bylo||dx])%=M;
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<dp[N-1][1][1][0]<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, d, e, k;
  in3(a, b, c);
  in3(d, e, k);
  if(e - a <= k)
    out("Yay!");
  else
    out(":(");
  memi;
}

Measured memory_bytes: 256
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i == j  == k:
        ans += gcd(i,j,k)
      elif i == j or j == k:
        ans += 3*gcd(i,j,k)
      else:
        ans += 6*gcd(i,j,k)
      # print(f'i,j,k:{i},{j},{k}, ans:{gcd(i,j,k)}')
print(ans)


Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int w[100000];
int v[100000];
int dp[100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,n;
    cin>>h>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];

    }
    for(int i=1;i<=99999;i++)
        dp[i]=1e9;
    for(int i=1;i<=n;i++)
    {

        for(int j=w[i];j<=h+10000;j++)
        {

            dp[j]=min(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    int ans=1e9;
    for(int i=h;i<=h+10000;i++)
    {

        ans=min(ans,dp[i]);
    }
    cout<<ans<<'\n';




}


Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
ll a[100];
void fun()
{
    a[0] = 2;
    a[1] = 1;
    FOR(i,2,86)
    {
        a[i] = a[i-2]+a[i-1];
    }
}
int main()
{
    int n;
    cin >> n;
    fun();
    cout << a[n] << endl;
    return 0;
}


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

int main() {
    string a, b;
    cin >> a >>b;
    if (a == b) {
        cout << "EQUAL" << endl;
    }
    else {
        if (a.length() > b.length()) {
            cout << "GREATER" << endl;
        }
        else if (a.length() < b.length()) {
            cout << "LESS" << endl;
        }
        else { // a.length() == b.length() but not a == b
            for (int i = 0; i < a.size(); i++) {
                if (a.at(i) > b.at(i)) {
                    cout << "GREATER" << endl;
                    break;
                }
                else if (a.at(i) < b.at(i)) {
                    cout << "LESS" << endl;
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	string b;
	int a1=0, b1=0;
	cin>>a>>b>>a1>>b1;
	string u;
	cin>>u;
	if(u==a)
	a1--;
	else if(u==b)
	b1--;
	cout<<a1<<" "<<b1<<endl;
	
	
} 

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

int main() {
	vector<ll> v(3);
	for (ll i = 0; i < 3; ++i)cin >> v[i];
	sort(v.begin(), v.end());
	if (v[0] == v[1] && v[1] != v[2])cout << "Yes" << endl;
	else if (v[0] != v[1] && v[1] == v[2])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256