akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100000
#define SENTINEL 200000000

struct Card {
  char suit;
  int value;
};

struct Card L[ MAX / 2 + 2 ], R[ MAX / 2 + 2 ];

void merge( struct Card [] , int , int , int , int );
void mergeSort( struct Card [] , int , int, int );
void quickSort( struct Card [] , int , int , int );
int partition(struct Card [], int , int , int );


int main() {
  int i,n,v;
  struct Card A[MAX],B[MAX];
  char s[10];
  int stable = 1;
  
 
  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ) {
    scanf("%s %d",s,&v);
    
    A[i].suit = B[i].suit = s[0];
    A[i].value = B[i].value = v;
  }

  mergeSort ( A , n , 0 , n );
  quickSort ( B , n , 0 , n-1 );

  for( i = 0 ; i < n ; i++ ) {
    if( A[i].suit != B[i].suit ) stable = 0;
  }

  if( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");

  for( i = 0 ; i < n ; i++ ) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



  void mergeSort ( struct Card A[] , int n , int left , int right ) {
    int mid;

    if( left + 1 < right ) {
      mid = ( left + right ) / 2;
      mergeSort ( A , n , left , mid );
      mergeSort ( A , n , mid , right );
      merge ( A , n , left , mid , right);
    }
  }

void merge ( struct Card A[] , int n , int left , int mid , int right ) {
    int i , j , k;
    int n1 = mid - left;
    int n2 = right - mid;

    for( i = 0 ; i < n1 ; i++ ) {
      L[i] = A[ left + i ];
    }
    for( i = 0 ; i < n2 ; i++ ) {
      R[i] = A[ mid + i ];
    }

    L[n1].value = R[n2].value = SENTINEL;

    i = j = 0;

    for( k = left ; k < right ; k++ ) {
      if( L[i].value <= R[j].value ) {
	A[k] = L[i++];
      }
      else {
	A[k] = R[j++];
      }
    }
  }

  void quickSort (struct Card A[] , int n , int p , int r ) {
    int q;
    if( p < r ) {
      q = partition( A , n , p , r );
      quickSort( A , n , p , q-1 );
      quickSort( A , n , q+1 , r );
    }
  }

  int partition( struct Card A[] , int n , int p, int r ) {
    int i,j;
    struct Card t,x;
    
    x = A[r];
    i = p-1;
    
    for( j = p ; j < r ; j++ ) {
      if( A[j].value <= x.value ){
	i++;
	t = A[i];
	A[i] = A[j];
	A[j] = t;
      }
    }

    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;
    return i+1;
  }

Measured memory_bytes: 2956
/*
 * N 個の整数 a1,a2,..,aN が与えられます。えび君はこれらを書き換えて全て同じ整数にしようとしています。各ai(1≦i≦N)は高々一回しか書き換えられません(書き換えなくても良い)。
 * 整数xを整数yに書き換えるとき、コストが(x−y)^2かかります。仮にai=aj(i≠j)だとしても、ひとつ分のコストで同時に書き換えることは出来ません。
 * えび君が目的を達成するのに必要なコストの総和の最小値を求めてください。
 */

import java.util.*;
	public class Main{
		public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            // 入力
            int n = Integer.parseInt(sc.next());
            int[] nums = new int[n];
            int sum = 0;

            for(int i=0; i<n; i++){
            	nums[i] = Integer.parseInt(sc.next());
            	sum += nums[i];
            }
            
            long goal = Math.round((sum*1.0)/n);
            long ret = 0;
            
            for(int i=0; i<n; i++){
            	ret += (goal - nums[i]) * (goal - nums[i]);
            }
            
            // 出力
            System.out.println(ret);

            sc.close();
        }
    }
	

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int x,y,z;cin>>x>>y>>z;
  pr(z,x,y);
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    bool flag = true;
    for(int i=0; i<s.length();i++){
        if(i%2==0 && s[i]=='L'){
            flag = false;
            break;
        }
        if(i%2!=0 && s[i]=='R'){
            flag = false;
            break;
        }
        
    }
    cout<< (flag ? "Yes" :"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[123];

int main(){
	scanf("%s", s);
	REP(i, strlen(s)) s[i] = 'x';
	printf("%s\n", s);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,j,cout = 0;
	char s[4];
	scanf("%s",&s);
	
	for(i = 0; i < 4; i++){
		for(j = 0; j < 4; j++){
			if(s[i] == s[j]){
				cout++;
			}
		}
	}
	
	if(cout == 8){
		printf("Yes\n");
	}
	
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

// 二部グラフ判定
vector<ll> color;
bool dfs(mat G,ll v,ll cur = 0) {
  color[v] = cur;
  for(auto next_v : G[v]) {
    // 隣接頂点がすでに色確定していた場合
    if (color[next_v] != -1) {
      if (color[next_v] == cur) return false; // 同じ色が隣接したらダメ
      continue;
    }

    // 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
    if (!dfs(G, next_v , 1 - cur)) return false;
  }
  return true;
}

int main(){

  ll n,m;
  cin >> n >> m;

  mat G(n);
  vec a(m),b(m);
  for(ll i=0;i<m;i++){
    cin >> a[i] >> b[i];
    G[a[i]-1].push_back(b[i]-1);
    G[b[i]-1].push_back(a[i]-1);
  }
  
  vec d(n,-1);
  d[0]=0;
  queue<ll> q;
  q.push(0);
  while(!q.empty()){
    ll v=q.front();
    q.pop();
    for(ll i=0;i<G[v].size();i++){
      if(d[G[v][i]]!=-1)continue;
      d[G[v][i]]=d[v]+1;
      q.push(G[v][i]);
    }
  }
  bool ok=true;
  for(ll i=0;i<m;i++){
    if((d[a[i]-1]-d[b[i]-1])%2==0)ok=false;
  }

  color=vec(n,-1);
  if(!ok){
    cout << n*(n-1)/2-m << endl;
  }
  else{
    ll b=0;
    for(ll i=0;i<n;i++)b+=(d[i]&1);
    cout << b*(n-b)-m << endl;
  }


}

Measured memory_bytes: 12504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

#define REP(i,n) for (int i=0;i<(n);++i)
#define REP2(i,n) for (int i=0;i<=(n);++i)
#define REP3(i,n) for (int i=1;i<=(n);++i)


int main() {

	int K,S;
	cin >> K >> S;


	int res;
	res = 0;
	REP(i, K+1) {
		int x, y, z;
		REP(j, K+1) {
			x = i;
			y = j;
			z = S - i - j;
			if ((z >= 0)&&(z<=K)) {
				++res;
			}
		}
	}
	
	cout << res << endl;

	int end;
	cin >> end;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    set<int> s;
    forn(i, 3){
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size() << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

long long n;
long long k;
vector<long long> fact;
vector<long long> inv_fact;
long long mult(long long a, long long b){
    return (a * b % mod);
}
long long pw(long long a, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1){
            res = res * 1ll * a % mod;
        }
        a = a * 1ll * a % mod;
        n >>= 1;
    }
    return res;
}
long long inv(long long x){
    return pw(x, mod - 2);
}
long long calc_c(long long n, long long k){
    return mult(mult(fact[n], inv_fact[n - k]), inv_fact[k]);
}
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        /// freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n >> k;
    fact.resize(n + 7);
    inv_fact.resize(n + 7);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i ++){
        fact[i] = mult(fact[i - 1], i);
        inv_fact[i] = inv(fact[i]);
    }

    long long res = 0;
    for(int z = 0; z < n; z ++){
        if(z > k){
            break;
        }
        res = (res + mult(calc_c(n, z), calc_c(n - 1, n - z - 1))) % mod;
    }
    cout << res << "\n";
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    int n;
    cin>>n;
    
    double ans=ceil(n/1.08);
    
    if(floor(ans*1.08)==n) cout<<ans<<endl;
    else cout<<":("<<endl;
    
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int n;
    cin >> n;
    vector<int> ans(n, 0);
    for (int i = 1; i < n; i++) {
        int e;
        cin >> e;
        ans[--e]++;
    }
    
    for (const auto &e : ans) cout << e << '\n';
    return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define chmin(a,b) a = min((a), (b))
#define chmax(a,b) a = max((a), (b))
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1000000000000000;

int main()
{
    int n;
    cin >> n;
    vector<pll> HP(n);
    rep(i, 0, n) cin >> HP[i].first >> HP[i].second;
    sort(HP.begin(), HP.end(), [](pll a, pll b)
        {
            ll ca = min(a.first, b.first - a.second);
            ll cb = min(b.first, a.first - b.second);
            return ca > cb;
        });

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF));
    rep(i, 0, n+1) dp[i][0] = 0;

    rep(i, 0, n)
        rep(j, 0, n)
        {
            chmin(dp[i+1][j+1], dp[i][j+1]);
            if (dp[i][j] <= HP[i].first)
                chmin(dp[i+1][j+1], dp[i][j]+HP[i].second);
        }

    int ans = 0;
    rep(i, 0, n+1) if (dp[n][i] < INF) ans = i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 195968
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();
    char[] a = new char[n];
    a = s.toCharArray();
    int count = 0;
    String ans_str = "Yes";

    for(char c = 'a';c <= 'z';c++){
    	count = 0;
    	for(int i = 0 ; i < n ; i++){
    		if(a[i] == c){
    			count++;
    		}
    	}
    	if(count % 2 != 0){
    		ans_str = "No";
    		break;
    	}
    }    
    System.out.println(ans_str);
  }
}


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

using namespace std;

typedef long long ll;

int main() {
    int K, N;

    scanf("%d %d", &K, &N);
    vector<int> hs(N);

    for (int i = 0; i < N; i++)
        scanf("%d", &hs[i]);

    ll total = 0, mx = -1;
    for (int i = 1; i < N; i++) {
        ll dist = hs[i] - hs[i - 1];
        total += dist;
        mx = max(mx, dist);
    }
    ll dist = K - hs[N - 1] + hs[0];
    total += dist;
    mx = max(mx, dist);

    printf("%lld\n", total - mx);

    return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int c = 0;
  for (int x=0; x<=K; x++) {
    for (int y=0; y<=K; y++) {
      int z = S - y - x;
      if (z >= 0 && z <= K) c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

  int debt = 100;
  
  for ( int i = 0; i < n; i++ )
    {
      debt *= 1050;
      
      if ( debt % 1000 != 0 )
        debt = debt / 1000 + 1;
      else
        debt /= 1000;
    }
  cout << debt * 1000 << endl;
  
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int nums[N];
    for(int i = 0; i < N; i++){
        cin >> nums[i];
    }
    sort(nums, nums + N, greater<int>());
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(i % 2){
            ans -= nums[i];
        }else{
            ans += nums[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  while(cin>>n){
    if(n>36)cout<<0<<endl;
    else{
      int sum,ans=0;
      rep(i,10){
        rep(j,10){
          rep(k,10){
            sum=(i+j+k);
            if(n-sum>=0&&n-sum<10)ans++;
          }
        }
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    set<int> se;
    REP(i,N){
        int tmp;
        cin >> tmp;
        if(se.find(tmp) == se.end()){
            ans++;
            se.insert(tmp);
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

const ll INF=1e10+100;

class DisjointSet{
    public:
    vector<ll> rank,p;
    DisjointSet(){}
    DisjointSet(ll size){
        rank.resize(size,0);
        p.resize(size,0);
        rep(i,size) makeSet(i);
    }
    void makeSet(ll x){ //頂点数が一つ。初期化。
        p[x] = x;
        rank[x] = 0;
    }
    bool same(ll x,ll y){
        return findSet(x) == findSet(y);
    }
    void unite(ll x, ll y){
        link(findSet(x),findSet(y));
    }
    void link(ll x, ll y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }
        else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }
    ll findSet(ll x){
        if(x!=p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

class Edge{
    public:
    ll source,target,cost;
    Edge(ll source=0,ll target=0,ll cost=0):
    source(source),target(target),cost(cost){}
    bool operator < (const Edge &e) const{
        return cost < e.cost; //Edgeのオブジェクトをソートできるように。
    }
};
ll kruskal(ll n,vector<Edge> edges){
    ll totalCost = 0; //コスト合計
    sort(edges.begin(),edges.end()); //辺の重みでソート
    DisjointSet dset = DisjointSet(n+1); //要素数はnでも良さそう
    //木の高さと親を入れる配列を用意し、頂点が一つのものを用意して初期化。
    rep(i,n) dset.makeSet(i); //既に初期化しているから必要ないのでは？
    ll source,target;
    rep(i,edges.size()){
        Edge e = edges[i];
        if(!dset.same(e.source,e.target)){ //sourceとtargetが同じ木でないとき
            totalCost += e.cost;
            dset.unite(e.source,e.target);
            
        }
    }
    return totalCost;
}

int main()
{
    ll n;
    cin >> n;
    vector<Edge> edges;
    map<pll,ll> m;
    vector<pll> p(n),q(n);
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        p[i].fi=x;
        p[i].se=y;
        q[i].fi=y;
        q[i].se=x;
        m[make_pair(x,y)]=i;
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    
    rep(i,n-1){
        edges.push_back(Edge(m[p[i]],m[p[i+1]],min(abs(p[i+1].fi-p[i].fi),abs(p[i+1].se-p[i].se))));
        edges.push_back(Edge(m[make_pair(q[i].se,q[i].fi)],m[make_pair(q[i+1].se,q[i+1].fi)],min(abs(q[i+1].fi-q[i].fi),abs(q[i+1].se-q[i].se))));
    }
    cout << kruskal(n,edges) << endl;
    return 0;
} 

Measured memory_bytes: 23632
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

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

    vector<int> a(n+1);
    vector<int> b(n);
    REP(i,n+1) cin >> a[i];
    REP(i,n) cin >> b[i];

    ll ans = 0;
    int prev = 0;

    REP(i,n) {
        ans += min(a[i],b[i]+prev);
        prev = max(0,b[i] - max(0,a[i] - prev));
    }
    ans += min(a[n],prev);

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	ll N,A[3],B[3];
	cin >> N;
	FOR(i,0,3)cin>>A[i];
	FOR(i,0,3)cin>>B[i];
	ll M = 5000*5002;
	vector<ll> dpAB(M,0),dpBA(M,0);
	FOR(i,0,M){
		FOR(j,0,3){
			if(i+A[j]<M)
				dpAB[i+A[j]] = max(dpAB[i+A[j]],dpAB[i]+(B[j]-A[j]));
			if(i+B[j]<M)
				dpBA[i+B[j]] = max(dpBA[i+B[j]],dpBA[i]+(A[j]-B[j]));
		}
	}
	cout << dpBA[dpAB[N]+N]+dpAB[N]+N << endl;
}

Measured memory_bytes: 391040
main = do
  mat <- map read . words <$> getContents
  let ans = any (check mat) [-1000 .. 1000]
  putStrLn $ if ans then "Yes" else "No"

check [c11,c12,c13,c21,c22,c23,c31,c32,c33] x = a2+b2==c22 && a2+b3==c23 && a3+b1==c31 && a3+b2==c32 && a3+b3==c33
  where
    b1 = c11 - x
    b2 = c12 - x
    b3 = c13 - x
    a2 = c21 - b1
    a3 = c31 - b1

Measured memory_bytes: 1020
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
	map<string,int> len,times;
	vector<string> brain;

	string ts;
	int maxlength = 0;
	int maxcount = 0;
	string AL,AC;

	while(cin >> ts) {
		if(times.count(ts)>0) {
			times[ts] += 1;
		} else {
			times.insert(make_pair(ts,1));
			len.insert(make_pair(ts,ts.length()));
			brain.push_back(ts);
		}

	}
	for(int i=0;i<len.size(); i++) {
		if(len[brain[i]] > maxlength) {
			maxlength = len[brain[i]];
			AL = brain[i];
		}
		if(times[brain[i]] > maxcount) {
			maxcount = times[brain[i]];
			AC = brain[i];
		}
	}
	cout << AC << " " << AL << endl;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


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

  int a, b, c;

  cin >> a >> b >> c;

  if (a == b && b == c) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }

  return 0;
}


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

int main()
{
  int64_t N, n, X, x = 1, p = 1, ans = 0;
  cin >> N >> X;
  X--;
  stack<int64_t> A, P;
  for (int64_t i = 0; i <= N; i++)
  {
    A.push(x);
    x = 2 * x + 3;
    P.push(p);
    p = 2 * p + 1;
  }
  while (!A.empty())
  {
    n = A.top(), p = P.top();
    A.pop();
    P.pop();
    if (X == n / 2)
    {
      ans += p / 2 + 1;
      break;
    }
    else if (X > n / 2)
    {
      ans += p / 2 + 1;
      X = X - n / 2 - 1;
    }
    else
    {
      X--;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

const int MOD = 1000000007;
int modpow(int a, int p){
    if(p == 0){
        return 1;
    }
    int t = modpow(a, p / 2);
    if(p % 2 == 0){
        return t * t % MOD;
    }
    return t * t % MOD * a % MOD;
}
int modinv(int a) { return modpow(a, MOD - 2); }

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if(x != y) {
            if(data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
};

bool f(string s){
    int N = s.length();
    if(N < 2)
        return true;
    for(signed i = 0; i < N; i++){
        if(s[i] != s[N-i-1])
            return false;
    }
    return true;
}

signed main() {
    string s;
    cin >> s;
    bool flag = true;
    int N = s.length();
    if(!f(s))
        flag = false;
    string s1 = s.substr(0, (N - 1) / 2);
    if(!f(s1))
        flag = false;
    string s2 = s.substr((N + 3) / 2 - 1, N);
    if(!f(s2))
        flag = false;
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a, b, ab, x, y = map(int, input().split())
if a+b <= 2*ab:
    print(a*x+b*y)
    exit()
ans = 0
if x >= y:
    if a >= 2*ab:
        ans = ab*2*x
    else:
        ans = ab*2*y + a*abs(x-y)
else:
    if b >= 2*ab:
        ans = ab*2*y
    else:
        ans = ab*2*x + b*abs(x-y)
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"):
    #print(*c, sep='\n')
    for _ in range(10):
        for i in range(10):
            for j in range(10):
                for k in range(10):
                    c[i][j] = min(c[i][j], c[i][k]+c[k][j])
    #print(*c, sep='\n')
    cost = 0
    for a in A:
        for aa in a:
            if aa == -1:
                continue
            cost += c[aa][1]
    return cost


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    c = [[int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1)]  # type: "List[List[int]]"
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    print(solve(H, W, c, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

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

	vector<int> a(n);

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

	double sum = 0;

	for (int i = 0; i < n; i++) {
		sum += (double) 1 / a[i];
	}

	cout << fixed << setprecision(11) << 1 / sum << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    s = input()
    print(s+'es' if s[-1]=='s' else s+'s')






main()



Measured memory_bytes: 9916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int h,w;
int boomsum = 0;
vector<vector<char>> maze(10,vector<char>(10,'.'));

int dfs(int a,int b){
  if(a<1 || h<a) return 0;
  if(b<1 || w<b) return 0;
  if(maze[a][b] == '.') return 0;
  if(a==h && b==w) return 1;
  return 1 + max(dfs(a+1,b),dfs(a,b+1));
}

int main(){
  cin >> h >> w;
  int check = 0;
  rep1(i,h) rep1(j,w){
    cin >> maze[i][j];
    check += (maze[i][j]=='#');
  }
  if(dfs(1,1) == check) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3576
input = gets.to_i

sum = 0

(1..input).each do |a|
  if a % 3 == 0 && a % 5 == 0
    next
  elsif a % 5 == 0
    next
  elsif a % 3 == 0
    next
  else
    sum += a
  end
end

puts sum


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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, a[101];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            ans = ans + a[i] * a[j];
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3648
//Patwari26
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define M_PI       3.14159265358979323846
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    cout<<setprecision(15);
    ll r;
    cin>>r;
    cout<<(2*r*M_PI)<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 3740
def grade(half, end, reexam):
    points = half + end
    if half == -1 or end == -1:
        return 'F'
    else:    
        if points >= 80:
            return 'A'
        elif points >= 65:
            return 'B'
        elif points >= 50:
            return 'C'
        elif points >= 30:
            if reexam >= 50:
                return 'C'
            else:
                return 'D'
        else:
            return 'F'

while 1:
    half, end, reexam = map(int, input().split())
    if half == end == reexam == -1:
        break
    else:
        print(grade(half, end, reexam))


Measured memory_bytes: 5596
/**
*    author:  Dooloper
*    created: 11.07.2020 21:06:39
**/

#include <bits/stdc++.h>

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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(1010101);
  rep(i,n+1) a[i] = 0;
  for(int i = 1; i <= 100; i++){
    for(int j = 1; j <= 100; j++){
      for(int k = 1; k <= 100; k++){
        ll ans = 0;
        ans = i*i + j*j + k*k + i*j + j*k + k*i;
        a[ans]++;
      }
    }
  }
  for(int i = 1; i <= n; i++) cout << a[i] << endl;
  return 0;
}

Measured memory_bytes: 11096
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<string>
#include<math.h>
#define ll long long int 
#define loop(a,b,i) for(int i=a;i<b;i++)
#define loopr(a,b,i) for(int i=n-1;i>=0;i--)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

//bool checkprime(int n) 
//{ 
//    if (n <= 1) 
//        return false; 
//    for (int i = 2; i < n; i++) 
//        if (n % i == 0) 
//            return false; 
//  
//    return true; 
//} 

int main() 
{ 
	string s;
	cin>>s;
	int n=s.length();
	if(s[n-1]=='s')
	{
		s=s+"es";
	}
	else
	{
		s+='s';
	}
	cout<<s;
	
return 0; 
} 

Measured memory_bytes: 3624
n,m=map(int,input().split())
fin=[False]*(10**5+10)
pena=0
corr=0
tmp=[0]*(10**5+10)
for _ in range(m):
  p,s=input().split()
  p=int(p)
    
  if fin[p]==True:
    continue
    
  if s=="WA":
    tmp[p]=tmp[p]+1
  if s=="AC":
    corr+=1
    pena+=tmp[p]
    fin[p]=True
        
print(corr,pena)

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

struct Graph
{
    int N;
    vector<vector<int>> red_neighbors, blue_neighbors;

    Graph(const int N) : N(N), red_neighbors(N), blue_neighbors(N) {}

    void add_red_edge(const int a, const int b)
    {
        red_neighbors[a].push_back(b);
        red_neighbors[b].push_back(a);
    }

    void add_blue_edge(const int a, const int b)
    {
        blue_neighbors[a].push_back(b);
        blue_neighbors[b].push_back(a);
    }

    int solve(const int X, const int Y) const
    {
        auto blue_depths = vector<int>(N);
        auto blue_parents = vector<int>(N);
        const function<void(int, int)> blue_dfs = [&](const int v, const int parent)
        {
            for (const auto w : blue_neighbors[v]) if (w != parent)
            {
                blue_depths[w] = blue_depths[v]+1;
                blue_parents[w] = v;
                blue_dfs(w, v);
            }
        };
        blue_parents[Y] = Y;
        blue_dfs(Y, -1);

        const auto blue_distance_1 = [&](const int v, const int w)
        {
            return blue_parents[v] == w || blue_parents[w] == v;
        };

        const auto blue_distance_2 = [&](const int v, const int w)
        {
            return blue_parents[blue_parents[v]] == w ||
                   blue_parents[blue_parents[w]] == v ||
                   blue_parents[v] == blue_parents[w];
        };

        auto red_distances = vector<int>(N, -1);
        auto win = false;
        const function<void(int, int)> red_dfs = [&](const int v, const int parent)
        {
            if (red_distances[v] >= blue_depths[v]) return;

            for (const auto w : red_neighbors[v]) if (w != parent)
            {
                if (!(blue_distance_1(v, w) || blue_distance_2(v, w)))
                    win = true;
                else
                {
                    red_distances[w] = red_distances[v]+1;
                    red_dfs(w, v);
                }
            }
        };
        red_distances[X] = 0;
        red_dfs(X, -1);

        if (win) return -1;
        else
        {
            auto result = 0;
            for (auto v = 0; v < N; v++)
                if (red_distances[v] != -1)
                    result = max(result, 2*blue_depths[v]);
            return result;
        }
    }
};

int main()
{
    int N, X, Y; cin >> N >> X >> Y;
    X--; Y--;

    auto graph = Graph(N);

    for (auto i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        graph.add_red_edge(a, b);
    }

    for (auto i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        graph.add_blue_edge(a, b);
    }

    cout << graph.solve(X, Y) << endl;
}


Measured memory_bytes: 38652
import java.util.Scanner;
public class Main
{
	static int base[][]=new int[12][12];
	static int ans;
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			
			String str;
			for(int i=0;i<12;i++)
			{
				str=in.next();
				for(int j=0;j<12;j++)
				{
					if(str.charAt(j)=='0')
						base[i][j]=0;
					else if(str.charAt(j)=='1')
						base[i][j]=1;
				}
			}
			ans=0;
			for(int i=0;i<12;i++)
				for(int j=0;j<12;j++)
				{
					if(base[i][j]==1)
					{
						solve(i,j);
						ans++;
					}
				}
			System.out.println(ans);
			
		}
	}
	public static void solve(int m, int n)
	{
		if((0<=m&&m<12)&&(0<=n&&n<12))
		{
			if(base[m][n]==0||base[m][n]==2)
				return ;
			else if(base[m][n]==1)
			{
				base[m][n]=2;
				if(m-1>=0&&base[m-1][n]==1)
					solve(m-1,n);
				if(m+1<12&&base[m+1][n]==1)
					solve(m+1,n);
				if(n-1>=0&&base[m][n-1]==1)
					solve(m,n-1);
				if(n+1<12&&base[m][n+1]==1)
					solve(m,n+1);
			}
		}
	}
}

Measured memory_bytes: 12000
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
const long long INF = 1000000010;

struct Store
{
    long long a, b;
    Store(long long _a, long long _b):a(_a), b(_b){};
};

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

    vector<Store> store;
    vector<long long> bs;
    rep(i, 0, N)
    {
        long long a, b;
        cin >> a >> b;

        if (a == 0)
            bs.push_back(b);
        else
            store.push_back(Store(a, b));
    }

    // sort
    sort(store.begin(), store.end(), [](const Store&si, const Store&sj)
    {
        return (si.b+1)*sj.a<(sj.b+1)*si.a;
    });

    // dynamic programming
    int max_num = 30;
    vector<long long> dp(max_num, INF);
    dp[0] = 0;
    rep(i, 0, store.size())
    {
        Store& s = store[i];
        rrep(n, max_num, 1)
            dp[n] = min(dp[n], (1+s.a)*(1+dp[n-1])+s.b);
    }

    // take cumulative sum of store with a=0
    sort(bs.begin(), bs.end());
    vector<long long> csum = {0};
    for (long long b: bs)
        csum.push_back(b+csum.back()+1);
    
    int ans = 0;
    rep(n, 0, max_num)
    {
        // cout << n << ' ' << dp[n] << endl;
        if (dp[n]<=T)
        {
            int num = upper_bound(csum.begin(), csum.end(), T-dp[n]) - csum.begin() - 1;
            ans = max(ans, num+n);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6512
#include<stdio.h>
int S[1000000],n;
int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(S[mid] == key){
            return 1;
        }

        if(key > S[mid]) left = mid + 1;

        else if(key < S[mid]){
            right = mid;
        }


    }
    return 0;
}

int main(){
    int i,j,T,sum,q;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&S[i]);
    }
    scanf("%d",&q);
    for(j = 0;j < q;j++){
        scanf("%d",&T);
        if(binarySearch(T)){
            sum++;
        }
    }
        printf("%d\n",sum);

        return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

map <int, int> divisor_count;
bool is_prime[100000];
const long long MOD = 1000000007;
const int MAX = 200001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];

int BIT_SIZE = 64;
long long power(long long m, long long n){
    long long ans = 1;
    long long tmp = m;
    for(int i = 0; i < BIT_SIZE; i++){
        //cout << ans << endl;
        if(((n >> i) & 1) == 1){
            ans = ans * tmp % MOD;
        }
        tmp = (tmp * tmp) % MOD;
    }
    return ans;
}

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

    //set prime array
    for(int i = 0; i < int(sqrt(M)) + 1; i++){
        is_prime[i] = true;
    }
    for(int i = 2; i < int(sqrt(M)) + 1; i++){
        if(!is_prime[i]){
            continue;
        }
        for(int j = 2 * i; j < int(sqrt(M)) + 1; j += i){
            is_prime[j] = false;
        }
    }
    /* 
    for(int i = 0; i <int(sqrt(M)) + 1; i++){
        cout << is_prime[i] << " ";
    }
    cout << endl;
    */

    //get prime divisors of M
    int tmp = M;
    for(int i = 2; i < int(sqrt(M)) + 1; i++){
        if(!is_prime[i]){
            continue;
        }
        if(tmp % i == 0 && divisor_count.find(i) == divisor_count.end()){
            divisor_count[i] = 0;
        }
        while(tmp % i == 0){
            tmp /= i;
            divisor_count[i] += 1;
        }
    }
    if(tmp != 1){
        divisor_count[tmp] = 1;
    }

    long long ans = 1;
    for(auto it = divisor_count.begin(); it != divisor_count.end(); it++){
        ans = (ans * comb((long long) (N - 1) + (long long) (it->second), N - 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// step[i] := ?????? 0 ????????¨????????¨????????????????????? i ???????????????????????¨????????¢
// ans [i] := ?????? i ????????¨????????¨????????????????????? i ???????????????????????¨????????¢
// ?????? i ??????????????????????????§???????????? 1 ???????????????????????????????????\?????? 2 ?????????
// ???????????£???????????????????????? 2 * (n-1) - ans[i] ??§??????

int step[100010], ans[100010];
vector<int> G[100010];

void dfs(int idx, int par) {
    for(auto to : G[idx]) {
        if(to == par) continue;
        dfs(to, idx);
        step[idx] = max(step[idx], step[to] + 1);
    }
}

void dfs2(int idx, int d_par, int par) {
    vector<pii> rec;
    rec.push_back(pii(0, -1));
    for(auto to : G[idx]) {
        if(to == par) rec.push_back(pii(d_par + 1, to));
        else rec.push_back(pii(step[to] + 1, to));
    }
    sort(rec.rbegin(), rec.rend());
    ans[idx] = rec[0].first;
    for(auto to : G[idx]) {
        if(to == par) continue;
        dfs2(to, rec[ rec[0].second == to ].first, idx);
    }
}

signed main() {
    int n; cin >> n;
    rep(i,0,n-1) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0, -1);
    dfs2(0, 0, -1);
    rep(i,0,n) cout << (n-1) * 2 - ans[i] << endl;
    return 0;
}

Measured memory_bytes: 32064