akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  unordered_set<int> data;
  int buf;
  for(int i=0; i<N; i++){
    cin >> buf;
    if(data.count(buf)){
      data.erase(buf);
    }
    else{
      data.insert(buf);
    }
  }
  
  cout << data.size() << endl;
}

Measured memory_bytes: 4388
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<queue>
#define llong long long
using namespace std;

const int N = 2e5;
const llong INF = 1000000000000000000ll;
struct Element
{
	llong x,y;
	bool operator <(const Element &arg) const {return x>arg.x;}
} a[N+3];
priority_queue<Element> pq;
int n;
llong mx,mn,mxx,mny;
llong ans;

void solve1()
{
	for(int i=1; i<=n; i++) pq.push(a[i]);
	llong cur = mxx,cury = INF;
	for(int i=1; i<n; i++)
	{
		Element tmp = pq.top(); pq.pop();
		cur = max(cur,tmp.y); cury = min(cury,tmp.y);
		ans = min(ans,(mx-mn)*(cur-min(pq.top().x,cury)));
//		printf("%lld %lld %lld\n",tmp.x,cury,cur);
	}
}

void solve2()
{
	ans = min(ans,(mx-mny)*(mxx-mn));
}

int main()
{
	scanf("%d",&n); mn = mny = INF;
	for(int i=1; i<=n; i++)
	{
		scanf("%lld%lld",&a[i].x,&a[i].y);
		if(a[i].x>a[i].y) {swap(a[i].x,a[i].y);}
		mx = max(mx,a[i].y); mxx = max(mxx,a[i].x);
		mn = min(mn,a[i].x); mny = min(mny,a[i].y);
	}
	ans = INF;
	solve1();
	solve2();
	printf("%lld\n",ans);
	return 0;
}
/*
11
10 19
4 7
20 28
7 18
2 4
3 9
4 22
14 24
2 6
6 13
14 20
*/

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int a;
    ll b,n;
    cin >> a >> b >> n;
    ll ans=0;
    /*
    for(ll x=0; x<=n; x++){
        chmax(ans, (a*x)/b - a*(x/b) );
        cout << ans << endl;
    }
    cout << ans << endl;
    */
    ll nx=(n/b)*b-1;
    //cout << nx << endl;
    cout << max( (a*n)/b - a*(n/b) , (a*nx)/b - a*(nx/b) ) << endl;
    //cout << (a*n)/b - a*(n/b) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a%3==0) printf("Possible");
    else if(b%3==0) printf("Possible");
    else if((a+b)%3==0) printf("Possible");
    else printf("Impossible");
    return 0;
}

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

using namespace std;

using ll = long long;

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

    int d = 1;
    ll cnt = 1;

    vector<int> res;

    for(int div = 1; div <= 100; ++div) {
        if(a % div == 0 && b % div == 0) {
            res.push_back(div);
        }
    }

    cout << res.at(res.size()-k) << endl;

    // while(cnt != k) {

    //     d++;

    //     if (a%d == 0 && b%d == 0) {
    //         // cout << "ok:" << d << endl;
    //         cnt++;
    //     }        
    // }


    // cout << d << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    ll ans = 0;
    rep(i,N-1){
        if(S[i] == S[i+1]){
           ans++; 
        }
    }
    ans = min(N-1, ans+K*2);
    cout << ans << endl;
}

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

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long int ll;
typedef vector<ii> vii;
typedef vector<ll> vll;

string s, ans;
int i, j;
int main() {
	cin >> s;
	reverse(s.begin(), s.end());
	i = s.find("LAVITSEF");
	i += 8;
	ans = "";
	for(j = i; j < s.size(); j++)
		ans += s[j];
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<int, int>pint;

int cnt(string s){
	int ret = 0;
	rep(i, 1, s.size()) {
		if (s[i - 1] == 'A' && s[i] == 'B')ret++;
	}
	return ret;
}

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

	int ans = 0;
	int c1 = 0;
	int c2 = 0;
	int c3 = 0;
	rep(i, 0, n) {
		string temp;
		cin >> temp;
		ans += cnt(temp);
		char ini = temp[0];
		char la = temp[temp.size()-1];
		if (ini == 'B' && la == 'A')c1++;
		else if (ini == 'B' && la != 'A')c2++;
		else if (ini != 'B' && la == 'A')c3++;
	}
	if (c1 == 0)cout << ans + min(c2,c3) << endl;
	else if (c2 == 0 && c3 == 0)cout <<ans +  c1 - 1 << endl;
	else cout << ans + c1 + min(c2, c3) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

bitset<2155> prime;
Vi p;
ll po3[2155];
map<ll,int> M;
ll opp(ll x)
{
	ll op=1;
	for(int y:p)
	{
		if(x%y==0)
		{
			ll c=po3[y];
			while(x%y==0)
			{
				c/=y;
				x/=y;
			}
			op*=c;
		}
	}
	if(x==1)return op;
	if(op<=(ll)1e10/(x*x))
	{
		return op*x*x;
	}
	ll z=(ll)sqrt(x);
	if(z*z==x && op<=(ll)1e10/z)
	{
		op*=z;
		return op;
	}
	else return -1;
}
int main(){
	prime.set();
	prime[0]=prime[1]=0;
	fup(i,2,2154,1)
		{
			if(!prime[i])continue;
			fup(j,i+i,2154,i)
				prime[j]=0;
		}
	p.pb(2);
	fup(i,3,2154,2)if(prime[i])p.pb(i);
	fup(i,1,2154,1)po3[i]=1LL*i*i*i;
	int n;
	scanf("%d",&n);
	fup(i,0,n-1,1)
	{
		ll x;
		scanf("%lld",&x);
		for(int y:p)
			while(x%po3[y]==0)x/=po3[y];
		M[x]++;
	}
	int ans=0;
	if(M.find(1)!=M.end())
	{
		ans++;
		M.erase(1);
	}
	while(!M.empty())
	{
		auto it=M.begin();
		ll y=opp(it->X);
		auto it2=M.find(y);
		if(it2!=M.end())
		{
			ans+=max(it->Y,it2->Y);
			M.erase(it);
			M.erase(it2);
		}
		else
		{
			ans+=it->Y;
			M.erase(it);
		}
	}
	printf("%d",ans);
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int R, C, K;
  cin >> R >> C >> K;
  vector<vector<int64_t>> V(R, vector<int64_t>(C, 0));
  rep(i, K) {
    int r, c, v;
    cin >> r >> c >> v;
    r--, c--;
    V[r][c] = v;
  }
  vector<vector<vector<int64_t>>> DP(
      4, vector<vector<int64_t>>(R + 1, vector<int64_t>(C + 1, 0)));
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C; ++j) {
      for (int k = 2; k >= 0; --k) {
        DP[k + 1][i][j] = max(DP[k + 1][i][j], DP[k][i][j] + V[i][j]);
      }

      rep(k, 4) {
        rep(l, 4) { DP[l][i + 1][j] = max(DP[l][i + 1][j], DP[k][i][j]); }
        for (int l = k; l < 4; ++l)
          DP[l][i][j + 1] = max(DP[l][i][j + 1], DP[k][i][j]);
      }
    }
  }

  int64_t answer = max(DP[3][R - 1][C], DP[3][R][C - 1]);
  cout << answer << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	string s;
	cin >> s;
	ll a = 0, b = 0;
	REP(i, s.length()) if (s[i] == '0') ++a; else ++b;
	cout << (min(a, b) * 2) << endl;
	return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}


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

int main(){
	int N,M,K;
	cin>>N>>M>>K;
	long long A[N],B[M],a[N+1],b[M+1];
	rep(i,N) cin>>A[i];
	rep(i,M) cin>>B[i];

	a[0]=0;
	b[0]=0;
	for(int i=1;i<=N;i++)a[i] = a[i-1] + A[i-1];

	for(int j=1;j<=M;j++)b[j] = b[j-1] + B[j-1];

	int ans=0;
	int j=M;
	rep(i,N+1){
		if(K-a[i]<0)break;
		
		while(b[j]>K-a[i] && j>=0){
			j-=1;
		}
		ans = max(ans,i+j);//ansよりi+jが大きかったら更新
		if(i==N) break;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 9888
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> A(N), B(N);
  rep (i, N) cin >> A[i];
  rep (i, N) cin >> B[i];

  rep (i, N-1) A[i+1] += A[i];
  rep (i, N-1) B[i+1] += B[i];

  long ans = A[0] + B[N-1];

  rep (i, N) {
    long tmp = A[i] + B[N-1];
    if (i > 0) tmp -= B[i-1];
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> cb(8, vector<int>(8));
int dr[8] = {0, 1, 1, 1, 0, -1, -1, -1},
    dc[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

bool is_ok_loc(int r, int c) {
    // r cに置けるかどうか
    rep(i, 8) {
        // 8方向に存在するかどうか
        // cout << "dir " << dr[i] << dc[i] << endl;
        int tr=r, tc=c;
        while(tr>=0 && tr<8 && tc>=0 && tc<8) {
            if (cb[tr][tc]) {
                // cout << "not ok loc" << tr << tc << endl;
                return false;
            }
            tr += dr[i];
            tc += dc[i];
        }
        // is_ok = is_ok || ok_dir;
    }
    return true;
}

int main() {
    cout << fixed << setprecision(10);
    int k; cin >> k;
    // vector<vector<int>> b(8, vector<int>(8));
    vector<vector<int>> b = cb;
    set<int> uc, ur;
    rep(i, k) {
        int r, c; cin >> r >> c;
        b[r][c] = 1;
        ur.insert(r);
        uc.insert(c);
    }
    vector<int> nuc, nur;
    rep(i, 8) {
        if (!ur.count(i)) {
            nur.emplace_back(i);
        }
        if (!uc.count(i)) {
            nuc.emplace_back(i);
        }
    }
    do {
        cb = b;
        bool ok = true;
        rep(i, nuc.size()) {
            // cout << "check " << nur[i] << " " << nuc[i] << endl;
            if (!is_ok_loc(nur[i], nuc[i])) {
                // cout << nur[i] << nuc[i] << " not ok" << endl;
                ok = false;
                break;
            }
            cb[nur[i]][nuc[i]] = 1;
        }
        if (ok) {
            rep(i, 8) {
                rep(j, 8) {
                    if (cb[i][j]) {
                        cout << 'Q';
                    } else {
                        cout << '.';
                    }
                }
                cout << endl;
            }
            return 0;
        }
    } while (next_permutation(nuc.begin(), nuc.end()));
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a == c)
		cout << a + b << "\n";
	else if (a + b < a + c && a + b < b + c)
		cout << a + b << "\n";
	else if (a + c < b + c)
		cout << a + c << "\n";
	else
		cout << b + c << "\n";
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;

main(){
    int n,m;ll k;
    cin>>n>>m>>k;
    ll a[n+1]={0},b[m+1]={0};
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    for(int i=1;i<=n;i++) a[i]+= a[i-1];
    for(int i=1;i<=m;i++) b[i]+= b[i-1];
    int idx,temp,ans=0;
    for(int i=0;i<=n;i++){
        if(a[i]>k) break;
        if(a[i]==k) temp=i;
           else{int idx = lower_bound(b,b+m,k-a[i]) - b;
           if(b[idx]!=(k-a[i])) --idx;
            temp = i+idx;
        }
        ans = max(ans,temp);
    }
    cout<<ans;
}

Measured memory_bytes: 6756
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

int main(){
  ll n; cin>>n;
  ll happy[n][3];
  for(int i=0;i<n;i++){
    cin>>happy[i][0]>>happy[i][1]>>happy[i][2];
  }

  ll dp[n][3];

  for(int i=0;i<n;i++){
    dp[i][0]=dp[i][1]=dp[i][2]=0;
  }
  
  dp[0][0]=happy[0][0];
  dp[0][1]=happy[0][1];
  dp[0][2]=happy[0][2];

  for(int i=1;i<n;i++){
    for(int j=0;j<3;j++){
      int x=(j+1)%3;
      int y=(j+2)%3;
      dp[i][j]=max(dp[i-1][x]+happy[i][j],dp[i-1][y]+happy[i][j]);
    }
  }

  ll result=max(dp[n-1][0],dp[n-1][1]);
  result=max(dp[n-1][2],result);

  cout<<result<<endl;
}

Measured memory_bytes: 4992
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    judge=False
    for j in range(i+1,n)[::-1]:
        if a[j-1]>a[j]:
            a[j-1],a[j]=a[j],a[j-1]
            judge=True
            cnt+=1

print(*a)
print(cnt)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define read(x) scanf("%d",&x)
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn];

int main() {
    int n;
    read(n);
    long long sum=1e18;
    for(int i=1;i<=n;i++) {
        read(a[i]);
        a[i]-=i;
    }
    sort(a+1,a+1+n);
    for(int i=n/2-1;i<=n/2+1;i++) {
        LL tmp=0;
        for(int j=1;j<=n;j++) {
            tmp+=abs(a[j]-a[i]);
        }
        sum=min(sum,tmp);
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-10
//#define p 2173412051LL
#define sz 2

using namespace std;

vector< int > e[ 51 ];
bool need[ 21 ][ 51 ];
int id[ 51 ][ 51 ];
int fa[ 51 ];
int dep[ 51 ];
ll f[ 51 ][ 1048576 ];

void dfs( int );

int main() {
	int n, m;
	int x, y, fk, tmp;
	scanf( "%d", &n );
	for( int i = 1; i < n; ++i ) {
		scanf( "%d%d", &x, &y );
		e[ x ].push_back( y );
		e[ y ].push_back( x );
		id[ y ][ x ] = id[ x ][ y ] = i;
	}
	dfs( 1 );
	scanf( "%d", &m );
	fk = 1 << m;
	for( int i = 1; i <= m; ++i ) {
		scanf( "%d%d", &x, &y );
		while( x != y ) {
			if( dep[ x ] > dep[ y ] ) {
				need[ i ][ id[ x ][ fa[ x ] ] ] = true;
				x = fa[ x ];
			} else if( dep[ x ] < dep[ y ] ) {
				need[ i ][ id[ y ][ fa[ y ] ] ] = true;
				y = fa[ y ];
			} else {
				need[ i ][ id[ x ][ fa[ x ] ] ] = true;
				x = fa[ x ];
				need[ i ][ id[ y ][ fa[ y ] ] ] = true;
				y = fa[ y ];
			}
		}
	}
	f[ 0 ][ 0 ] = 1;
	for( int i = 1; i < n; ++i ) {
		tmp = 0;
		for( int j = 1; j <= m; ++j ) {
			tmp <<= 1;
			if( need[ j ][ i ] )
				tmp |= 1;
		}
		for( int j = 0; j < fk; ++j ) {
			f[ i ][ j ] += f[ i - 1 ][ j ];
			f[ i ][ j | tmp ] += f[ i - 1 ][ j ];
		}
	}
	printf( "%lld", f[ n - 1 ][ fk - 1 ] );
	dfs( 1 );
}

void dfs( int x ) {
	for( int i = 0; i < e[ x ].size(); ++i ) {
		if( e[ x ][ i ] == fa[ x ] )
			continue;
		dep[ e[ x ][ i ] ] = dep[ x ] + 1;
		fa[ e[ x ][ i ] ] = x;
		dfs( e[ x ][ i ] );
	}
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        
        if (n==0) {
            break;
        }
        
        for (int i=0; i<n; i++) {
            int pm, pe, pj;
            cin >> pm >> pe >> pj;
            
            if (pm==100 || pe==100 || pj==100) {
                cout << 'A' << endl;
            }
            else if (pm+pe>=180) {
                cout << 'A' << endl;
            }
            else if (pm+pe+pj>=240) {
                cout << 'A' << endl;
            }
            else if (pm+pe+pj>=210) {
                cout << 'B' << endl;
            }
            else if (pm+pe+pj>=150 && (pm>=80 || pe>=80)) {
                cout << 'B' << endl;
            }
            else {
                cout << 'C' << endl;
            }
        }
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    multiset<int> rest;
    rep(i,pow(2,N)){
        int A;
        cin >> A;
        rest.insert(A);
    }
    auto it=rest.end();
    it--;
    multiset<int> done;
    done.insert(*it);
    rest.erase(it);
    rep(i,N){
        multiset<int> killed;
        for (auto x=done.begin();x!=done.end();x++){
            auto itr=rest.lower_bound(*x);
            if (itr==rest.begin()){
                cout << "No" << endl;
                return 0;
            }
            itr--;
            killed.insert(*itr);
            rest.erase(itr);
        }
        for (auto x=killed.begin();x!=killed.end();x++){
            done.insert(*x);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 18688
import math
A,B,H,M = map(int,input().split())


h = H * 30 + 0.5 * M
m = 6 * M
hh = abs(h - m)
mm = 360 - hh

if hh <= mm:
    c = hh
else:
    c = mm

c = math.radians(c)

C = (A * A) + (B * B) - (2 * A * B * math.cos(c))
print(math.sqrt(C))

"""
A = int(input())
B = int(input())
H = int(input())
M = int(input())
"""

Measured memory_bytes: 9316
#include<iostream>
using namespace std;
int main() {
	int a, b;
	char s[100];
	cin >> a>>b;
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	s[b - 1] += 32;
	for (int i = 0; i < a; i++) {
		cout << s[i];
	}
		cout<< endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));

//        System.out.println(solve(new Scanner(ex)));
    }

    private static final String ex = "3 3\n" +
            "1 2\n" +
            "1 3\n" +
            "2 3";

    private static int solve(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");
        int N = Integer.parseInt(split[0]);
        int M = Integer.parseInt(split[1]);

        boolean[][] graph = new boolean[N][N];
        int[][] edges = new int[M][2];
        for (int i = 0; i < M; i ++) {
            split = scanner.nextLine().split(" ");
            int a = Integer.parseInt(split[0]) - 1;
            int b = Integer.parseInt(split[1]) - 1;

            graph[a][b] = true;
            graph[b][a] = true;

            edges[i] = new int[] {a, b};
        }

        int count = 0;
        for (int i = 0; i < edges.length; i ++) {
            int a = edges[i][0];
            int b = edges[i][1];

            graph[a][b] = false;
            graph[b][a] = false;

            if (! isComplete(0, graph)) {
                count ++;
            }

            graph[a][b] = true;
            graph[b][a] = true;
        }

        return count;
    }

    private static boolean isComplete(int start, boolean[][] graph) {
        Queue<Integer> queue = new LinkedList<>();
        Set<Integer> visited = new HashSet<>();

        queue.add(start);
        visited.add(start);

        while (queue.size() > 0) {
            int cur = queue.poll();

            List<Integer> next = new LinkedList<>();

            for (int i = 0; i < graph[cur].length; i ++) {
                if (graph[cur][i] && ! visited.contains(i)) {
                    visited.add(i);
                    queue.add(i);
                }
            }
        }

        return visited.size() == graph.length;
    }
}

Measured memory_bytes: 23764
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	k := scanInt()
	n := scanInt()
	a := scanInts(n)

	ma := 0
	sum := 0
	for i := 1; i < n; i++ {
		ma = max(ma, a[i]-a[i-1])
		sum += a[i]-a[i-1]
	}
	ma = max(ma, k-a[n-1]+a[0])
	sum +=k-a[n-1]+a[0]

	fmt.Fprintln(wr, sum-ma)
}


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

using namespace std;

#define MAX 1000000

long long cnt = 0;

void insertion_sort(int A[MAX], int N, int Gi) {
  for (int i = Gi; i < N; i++) {
    int v = A[i];
    int j = i - Gi;

    while (j > -1 && A[j] > v) {
      A[j + Gi] = A[j];
      j -= Gi;
      cnt++;
    }
    A[j + Gi] = v;
  }
}

void shell_sort(int A[MAX], int N, vector<int> *G) {
  for (int h = 1; ; ) {
    if (h > N) {
      break;
    }
    (*G).push_back(h);
    h = 3*h + 1;
  }

  for (int i = (*G).size() - 1; i > -1; i--) {
    insertion_sort(A, N, (*G)[i]);
  }
}

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

  static int A[MAX] = { 0 };
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> G;
  shell_sort(A, N, &G);

  cout << G.size() << endl;

  for (int i = G.size() - 1; i > -1; i--) {
    cout << G[i];
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;

  cout << cnt << endl;

  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 7012
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

int A[200009];

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

	int N; cin >> N;
	for (int i = 1; i <= N-1; i++) {
		int num;
		cin >> num;
		A[num]++;
	}
	for (int i = 1; i <= N; i++) {
		cout << A[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 4364
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  if(n<10){
    cout <<n;
  }else if(n<100){
    cout <<9;
  }else if(n<1000){
    cout <<n-90;
  }else if(n<10000){
    cout << 909;
  }else if(n<100000){
    cout <<n-90-9000;
  }else{
    cout << 90909;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <bitset>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

#define snd second
#define fst first

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }

const int MAXX = 5042;
int n;
vector <vector<int>> e;
vector <int> f;
vector <int> v;

bool dfs(int x) {
    vector <pair<int, int>> w;
    for (auto& y : e[x]) {
        if (!dfs(y)) {
            return false;
        }
        w.emplace_back(v[y], f[y]);
    }

    bitset<MAXX> b;
    b.reset();
    b.set(0);
    int s = 0;
    for (auto& p : w) {
        b = (b << p.first) | (b << p.second);
        s += p.first + p.second;
    }

    for (int i = v[x]; i >= 0; --i) {
        if (b.test(i)) {
            f[x] = s - i;
            return true;
        }
    }
    return false;
}

int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif
    while (cin >> n) {
        e.resize(n);
        for (int i = 0; i < n; ++i) {
            e.clear();
        }
        for (int i = 1; i < n; ++i) {
            int x;
            cin >> x;
            --x;
            e[x].push_back(i);
        }
        v = vector<int>(n, 0);
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
        }
        f = vector<int>(n, 0);
        cout << (dfs(0)? "POSSIBLE" : "IMPOSSIBLE") << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;


    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
};


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

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

template<class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

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

    int N;
    cin >> N;
    FOR(i, 1, 10) {
        if (N % i == 0) {
            int a = N / i;
            if (1 <= a && a <= 9) {
                cout << "Yes";
                return 0;
            }
        }
    }


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


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
# 単価が安い順に店を並べる
sorted_AB = sorted(AB, key=lambda x: x[0])

money = 0
cnt = 0
for a, b in sorted_AB:
    tmp = min(b, M - cnt)
    cnt += tmp
    money += a * tmp
    if cnt == M:
        break
print(money)


Measured memory_bytes: 29140
s=input()
sub=[]
tri=[]
for i in range(len(s)):
  if(i+2<=len(s)-1):
    tri.append(int(s[i])*100+int(s[i+1])*10+int(s[i+2]))
for j in range(len(tri)):
  sub.append(abs(tri[j]-753))
  
print(min(sub))  

Measured memory_bytes: 3064
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::*;

use std::string::*;

struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }

    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }

    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let s: String = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();

        return s.parse::<T>().ok().unwrap();
    }

    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn prime_factorization(n: i64) -> HashMap<i64, i64> {
    let mut n = n;
    let mut res = HashMap::new();
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            let count = res.entry(i).or_insert(0);
            *count += 1;
        }
        i += 1;
    }

    if n > 1 {
        res.insert(n, 1);
    }

    return res;
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n = sc.read();
    let mut a = Vec::new();
    let mut b = Vec::new();
    for _ in 0..n {
        let aa: i64 = sc.read();
        let bb: i64 = sc.read();
        a.push(aa);
        b.push(bb);
    }

    a.sort();
    b.sort();

    if n % 2 == 1 {
        let mid_a = a[n / 2];
        let mid_b = b[n / 2];
        println!("{}", mid_b - mid_a + 1);
    } else {
        let mid_a = a[n / 2 - 1] + a[n / 2];
        let mid_b = b[n / 2 - 1] + b[n / 2];
        println!("{}", mid_b - mid_a + 1);
    }
}

Measured memory_bytes: 5892
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

typedef vector<vector<lint>> mat;

mat mtx{
    {1,0,1,0},//F(N-1),F(N-2),...,F(N-K)の係数
    {1,0,0,0},
    {0,1,0,0},
    {0,0,1,0}
}; // K次正方行列

vector<lint> F{0,0,1,1}; //F(1)~F(K)の値

mat mul(mat &A,mat &B){
    mat C(A.size(),vector<lint>(B[0].size()));
    rep(i,A.size()) rep(j,B.size()) rep(k,B[0].size()){
        C[i][k]=(C[i][k]+A[i][j]*B[j][k])%MOD;
    }
    return C;
}

mat powmat(mat A,lint n){
    mat B(A.size(),vector<lint>(A.size()));
    rep(i,A.size()) B[i][i]=1;
    while(n){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

lint calc(lint n){ //F(N)の計算
    if(n==0) return 0;
    mat A=mtx;
    A=powmat(A,n-1);
    lint res=0;
    rep(i,A.size()) res=(res+A[A.size()-1][i]*F[A.size()-1-i])%MOD;
    return res;
}

int main(void){
    lint S;
    cin >> S;
    cout << calc(S) << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e14+4;
const int Nmax=2e5+1;
const int Nd=61;

int main(){
  int n; cin>>n;
  vector<string> name(n);
  vector<ll> m(5,0);
  rep(i,n) {
    cin>>name[i];
    //cout<<name[i][0];
    if(name[i][0]=='M') m[0]++;
    if(name[i][0]=='A') m[1]++;
    if(name[i][0]=='R') m[2]++;
    if(name[i][0]=='C') m[3]++;
    if(name[i][0]=='H') m[4]++;
  }

  ll ans=0;
  ll now=0;
  rep(i,4){
    for(int j=i+1;j<5;j++){// i,jを除く
      now=1;
      rep(k,5){
        if(k!=i && k!=j){
          now*=m[k];
        }
      }
      ans+=now;
    }
  }
  cout<<ans<<endl;







  return 0;
}


Measured memory_bytes: 6324
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    ll n;cin>>n;
    vector<char> v;
    ll tmp=n,a=26;
    while(tmp>0){
            tmp--;
            char ch='a'+tmp%a;
            tmp/=a;
            v.push_back(ch);
    }
    for(auto it=v.rbegin();it!=v.rend();it++)cout<<*it;

 
return 0;
}

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

int main() {
  int n,m;
  cin >> n;
 vector<int> x(n),y(n);

  for (int i=0;i<n;i++)
   cin >> x.at(i);
  
  for (int i=0;i<n;i++) {
    int M=0;
    
    for (int j=0;j<n;j++) {
      for (int k=0;k<n;k++) {
       if(x.at(j)>=x.at(k)&&x.at(j)>M)
        M=x.at(j);
      }//fork
    }//forj

    for (int j=0;j<n;j++) {
      if (x.at(j)==M) {
        x.at(j)=0;
      }//if
    }//forj
    
  y.at(i)=M;

  }//fori
  for (int i=0;i<n;i++) {
    if (y.at(i)!=0)
      m++;
  }
  cout << m << endl;
}

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

int main() {
	int a,b;
	cin >> a >> b;
	int counter = 0;
	for(int i = a;i <= b; i++){
		if(i % 10 == 0)continue;
		string sample = to_string(i);
		if(sample[0] == sample[4] && sample[1] == sample[3]){
			//cout << i << endl;
			counter++;
		}
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int n, m, x, a;
	bool b[110] = { false };
	scanf("%d%d%d", &n, &m, &x);
	int tox = 0;
	int frx = 0;
	for (int i = 0; i < m; i++) {
		scanf("%d", &a);
		b[a] = true;
	}
	for (int i = 1; i < x; i++) {
		if (b[i])tox++;
	}
	for (int i = x + 1; i < n; i++) {
		if (b[i])frx++;
	}
	printf("%d",min(tox, frx));
	return 0;
}

Measured memory_bytes: 128
import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])

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

#define int long long

const int mod = 1e9+7;

int N;
vector<int> C;
int dp[222222];

signed main() {
  cin >> N;
  C.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }

  dp[0] = 1;
  map<int, int> mp;
  for (int i = 0; i < C.size(); i++) {
    dp[i+1] = dp[i];
    if (i > 0 and C[i-1] == C[i]) {
      continue;
    }

    if (mp.count(C[i])) {
      // dp[i+1] += dp[mp[C[i]]+1];
      dp[i+1] = ((dp[i+1] % mod) + (dp[mp[C[i]]+1]%mod)) % mod;
    }

    mp[C[i]] = i;
  }

  cout << dp[C.size()] << endl;

  return 0;
}

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

#define lint long long

using namespace std;

int main()
{
  int h,n,sum=0;
  cin >> h >> n;

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

  if(sum>=h){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 55;
const int maxm = 20;
LL dp[maxn][1<<maxm];
int G[maxn][maxn], n,m, cover[maxn]; vector<PII> edge;

LL dfs(const int i, const int mask)
{
    if (i == n-1)
        return mask+1 == (1<<m);
    LL& ans = dp[i][mask];
    if (-1 == ans) {
        ans = 0;
        ans += dfs(i+1, mask|cover[i]);
        ans += dfs(i+1, mask);
    }
    return ans;
}

void dfs(const int u, const int v, set<PII>& p)
{
    if (u == v)
        return;
    FOR(i,1,n+1) if (G[u][i] == 1 && G[u][i]+G[i][v] == G[u][v]) {
        p.insert(PII(u,i));
        p.insert(PII(i,u));
        dfs(i,v,p);
    }
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n) {
        FOR(i,0,maxn) FOR(j,0,maxn)
            G[i][j] = i==j ? 0 : inf;
        edge.clear();
        FOR(i,0,n-1) {
            int u,v; cin >> u >> v;
            G[u][v] = G[v][u] = 1;
            edge.push_back(PII(u,v));
        }
        FOR(k,1,n+1) FOR(i,1,n+1) FOR(j,1,n+1)
            G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
        memset(cover,0,sizeof(cover));
        cin >> m;
        FOR(i,0,m) {
            int u,v; cin >> u >> v;
            set<PII> path;
            dfs(u,v,path);
            FOR_ALL(p,path) {
                int j = 0;
                for (; j < n-1; j++)
                    if (edge[j] == *p)
                        break;
                cover[j] |= 1<<i;
            }
        }
        memset(dp,-1,sizeof(dp));
        cout << dfs(0,0) << endl;
    }
    return 0;
}


Measured memory_bytes: 450816
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 1000003;
using namespace std;


const int max_comb=1000010;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

ll comb(int a, int b){     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(int a, int b){     // P(a,b) = a! * (a-b)!^(-1)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
    }
    return;
}

int main(int argc, char* argv[])
{
    int Q;
    scanf("%d", &Q);

    pre_comb();
    int i;
    for(i=0; i<Q; i++) {
        int x, d, n;
        scanf("%d%d%d", &x, &d, &n);

        ll ans;
        if(d%MOD==0) {
            ans = mpow(x,n);
        }
        else {
            ll tmp = MOD - ((x%MOD) * minv(d))%MOD;
            ll tmp2 = tmp - n + 1;
            if(tmp2<=0) {
                ans=0;
            }
            else {
                ans = (perm(tmp, n) * mpow((MOD-d%MOD), n))%MOD;
            }
        }
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 16512
// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

int main(){

	int ans=0;
	
	for(int i=1;i<=5;i++){
		int x; cin>>x;
		if(x==0){
			ans=i;
			break;
		}
	}

	cout<<ans<<endl;

	return 0;
} 

Measured memory_bytes: 3592
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, s, d, t;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    ll ans = 0;
    scanf("%lld%lld", &s, &d);
    if(s * d < 0) {
      s = -s;
      while( s ) {
        if(s % 2) ans++;
        s /= 2;
      }
      while( d ) {
        if(d % 2) ans++;
        d /= 2;
      }
    } else if(s * d > 0) {
      if(s < 0) t = s, s = d, d = t, s = -s, d = -d;
      while(s != d) {
        if(s % 2) ans++, s++;
        if(d % 2) ans++;
        s /= 2, d /= 2; 
      }
    } else {
      if(s < 0) t = s, s = d, d = t, d = -d;
      while( d ) {
        if(d % 2) ans++;
        d /= 2;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll H, W, h, w;

	cin >> H >> W >> h >> w;

	cout << (H - h) * (W - w) << endl;
}

Measured memory_bytes: 256