akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, char> pic;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	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 COM(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;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
ll merge(ll *a, int left, int mid, int right) {
	ll n1 = mid - left;
	ll n2 = right - mid;
	vector<int> L(n1 + 1);
	vector<int> R(n2 + 1);
	for (size_t i = 0; i < n1; i++)
	{
		L[i] = a[left + i];
	}
	for (size_t i = 0; i < n2; i++)
	{
		R[i] = a[mid + i];
	}

	L[n1] = INF;
	R[n2] = INF;
	ll i = 0;
	ll j = 0;
	ll r = 0;
	for (size_t k = left; k < right; k++)
	{
		if (L[i] <= R[j]) {
			a[k] = L[i];
			i++;
		}
		else {
			a[k] = R[j];
			r += n1 - i;
			j++;
		}
	}
	return r;
}
ll mergeSort(ll *a, int left, int right) {
	ll res = 0;
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		res = mergeSort(a, left, mid);
		res += mergeSort(a, mid, right);
		res += merge(a, left, mid, right);
	}
	return res;
}

void solv() {
	int n;
	cin >> n;
	ll a[200010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	cout << mergeSort(a, 0, n) << endl;
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 5108
/*行列の積*/

#include<stdio.h>

#define N 100

int miner(int,int);

int main(){
  int n,i,j,k,l;
  int r[N+1],s[N+1],m[N+1][N+1];
  int min;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d%d",&r[i],&s[i]);
  }

  for(i=1;i<=n;i++) m[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=100000000;
      for(k=i;k<=j-1;k++){
	min=m[i][k]+m[k+1][j]+r[i]*s[k]*s[j];
        if(miner(m[i][j],min) == min) m[i][j]=min;
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}

int miner(int x,int y){
  return x>y ? y : x;
}




Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>


int f(int n){
  int res=0;
  while(n){
    res++;
    n/=10;
  }

  return (res%2);
}

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

  int n;
  cin>>n;

  int ans=0;
  FOR(i,1,n+1){
    ans+=f(i);
  }

  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  int S = 0;
  int x = N;
  while (x > 0) {
    S += x % 10;
    x /= 10;
  }
  if (N % S == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  int mi = 10000;
  for(int i = 1; i < N; i++){
    int A, B, a=0, b=0;
    A = i;
    B = N - i;
    while( A > 0){
      a += A % 10;
      A /= 10;
    }
     while( B > 0){
      b += B % 10;
      B /= 10;
    }
    int sum;
    sum = a + b;
    if( mi > sum )
      mi = sum;
  }
  cout << mi << endl;
}

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

int Q, H, S, D, N;

void agc019a() {
  int L1 = min(min(4 * Q, 2 * H), min(2 * Q + H, S));
  int L2 = min(2 * L1, D);
  if (N % 2 == 0) {
    cout << (ll)L2 * (N / 2) << '\n';
  }
  else {
    cout << (ll)L2 * (N / 2) + L1 << '\n';
  }
  return;
}

int main() {
  cin >> Q >> H >> S >> D >> N;
  agc019a();
  return 0;
}

Measured memory_bytes: 256
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in(),n=t.inr().split("").map(function(t){return(parseInt(t,36)-10+e)%26}).map(function(t){return String.fromCharCode(t+65)}).join("");console.log(n)}}]);


Measured memory_bytes: 9536
#include<iostream>
int main()
{
  long n = 0;
  long count = 0;
  std::cin>>n;
  for(long a = 1; a < n; a++)
  {
    int b = n%a;
    if(b==0)
      count += (n / a) - 1;
    else
      count += (n - b) / a;
  }
  std::cout<<count;
}

Measured memory_bytes: 3160
#include<iostream>
using namespace std;
int main()
{
  int n, a, b, c;
  cin >> n;
  a = n / 100;
  b = (n / 10) % 10;
  c = n % 10;
  if(a == 1)
    a = 9;
  else a = 1;
  if(b == 1)
    b = 9;
  else b = 1;
  if(c == 1)
    c = 9;
  else c = 1;
  cout << 100 * a + 10 * b + c;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <float.h>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>
#include <stack>
#include <queue>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

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


int main() {
	int n;
	cin >> n;
	vector<int> v(n + 1);
	vector<int> c(n - 1);
	rep(i, n)
		cin >> v[i];
	int piv = 0;
	int result = 1;
	rep(i, n - 1) {
		if (v[i + 1] - v[i] < 0) {
			c[i] = -1;
		}
		else if (v[i + 1] == v[i]) {
			c[i] = 0;
		}
		else {
			c[i] = 1;
		}
	}
	int i = 0;
	while (i < n - 1) {
		while (i < n - 1) {
			if (c[i] != 0)
				break;
			i++;
		}
		int p = c[i];
		while (i < n - 1) {
			if (c[i] * p < 0) {
				result++;
				break;
			}
			i++;
		}
		i++;
	}
	cout << result << endl;

}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#include<algorithm>
using namespace std;

const int maxn=1e6+100;
int n,m,f[maxn],d[maxn];

int get(int x)
{
    if(f[x]==x) return x;
    int r=get(f[x]);
    d[x]=d[f[x]]+d[x];
    return f[x]=r;
}


int fix(int x,int y,int z)
{
    int fx=get(x);
    int fy=get(y);
    if (fx==fy) return z==d[y]-d[x];
    f[fy]=fx;
    d[fy]=d[x]+z-d[y];
    return 1;
}

int main()
{
    int lose=1;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%d %d %d",&x,&y,&z);
        if(lose) lose=fix(x,y,z);
    }
    if(lose) printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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


ll y[100009];

int main()
{
    ll n;
    cin>>n;
    for (ll i=0; i<n; i++)
    {
        cin>>y[i];
    }
    ll ans=0,p=0,ans2=0;/*avali +*/
    for (ll i=0; i<n; i++)
    {
        p+=y[i];
        if (i%2==0)//+
        {
            if (p<=0)
            {
                ans+=abs(p);
                ans ++;
                p=1;
            }
        }
        else
        {
            if (p>=0)
            {
                ans+=abs(p);
                ans++;
                p=-1;
            }
        }
    }
    p=0;
    for (ll i=0; i<n; i++)
    {
        p+=y[i];
        if (i%2!=0)//+
        {
            if (p<=0)
            {
                ans2+=abs(p);
                ans2 ++;
                p=1;
            }
        }
        else
        {
            if (p>=0)
            {
                ans2+=abs(p);
                ans2++;
                p=-1;
            }
        }
    }
    cout<<min(ans,ans2);

}


Measured memory_bytes: 1024
program ABC137B
    implicit none
    integer(8)::N,i
    real(8)::out=0
    real(8),allocatable,dimension(:)::A
    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)

    do i=1,N
        out=out+1/A(i)
    end do

    print'(f0.10)',1/out
    
end program ABC137B

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

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

  vector<int> a1(n);
  rep(i, n) cin >> a1.at(i);
  vector<int> a2(n);
  rep(i, n) cin >> a2.at(i);

  vector<int> sum_a1(n + 1);
  for (int i = 1; i <= n; i++) {
    sum_a1.at(i) = sum_a1.at(i - 1) + a1.at(i - 1);
  }
  vector<int> sum_a2(n + 1);
  for (int i = 1; i <= n; i++) {
    sum_a2.at(i) = sum_a2.at(i - 1) + a2.at(i - 1);
  }

  int max_candies = 0;
  for (int i = 1; i <= n; i++) {
    int candies = sum_a1.at(i);
    candies += sum_a2.at(n) - sum_a2.at(i - 1);
    max_candies = max(max_candies, candies);
  }

  cout << max_candies << endl;
  return 0;
}

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

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i=0; i<M; i++) {
    cin >> B[i];
  }
  vector<vector<int>> A(N, vector<int>(M));
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      cin >> A[i][j];
    }
  }
  int ans = 0;
  for (int i=0; i<N; i++) {
    int sum = 0;
    for (int j=0; j<M; j++) {
      sum += A[i][j]*B[j];
    }
    if (sum+C>0) {
      ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
n, m = map(int, input().split()) 

a = []
for i in range(n):
  a.append(list(input().split()))
  a[i] = [int(n) for n in a[i]]

b = []
for i in range(m):
  b.append(int(input()))

tasizan = 0
for i in range(n):
  for j in range(m):
    tasizan += (a[i][j]*b[j])
  print(tasizan)
  tasizan = 0


Measured memory_bytes: 6012
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 21000000000
#define MAX 210000
#define MOD 998244353
typedef long long ll;
typedef pair<int,ll> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    string s;
    cin>>s;
    if(s.substr(0,4)=="YAKI") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	pii a[55];
	for(int i=0;i<n;i++)
	{
		cin>>a[i].first>>a[i].second;
	}
	vector <pii> vec;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==j) continue;
			vec.push_back(mp(a[i].first-a[j].first,a[i].second-a[j].second));
		}
	}
	sort(all(vec));
	int res=0;
	for(int i=0,j=0;i<n*(n-1);i=j)
	{
		int len=0;
		for(j=i;j<n*(n-1);j++)
		{
			if(vec[j]==vec[i]) len++;else break;
		}
		res=max(len,res);
	}
	cout<<n-res<<endl;
	return 0;
}

Measured memory_bytes: 256
#define ll long long
    #define pub push_back
    #define pob pop_back
    #define puf push_front
    #define pof pop_front
    #define mp make_pair
    #define fo(i , n) for(ll i = 0 ; i < n ; i++)
    //#include<bits/stdc++.h>
    #include<iomanip>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<iostream>
    #include<vector>
    #include<string>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    ll pi = acos(-1) ;
    ll z =  998244353 ;
    ll inf = 100000000000000000 ;
    ll p1 = 37 ;
    ll p2 = 53 ;
    ll mod1 =  202976689 ;
    ll mod2 =  203034253 ;
    ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
    ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
    ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
    ll max(ll a , ll b){if(a > b) return a ; return b ;}
    ll min(ll a , ll b){if(a < b) return a ; return b ;}
    ll left(ll i){return ((2*i)) ;}
    ll right(ll i){return ((2*i) + 1) ;}
    void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    using namespace std ;
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    // ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
    // s.find_by_order(i)  itertor to ith element (0 indexed)
    ll cnt = 1 ;

    void solve()
    {
        ll n , m ;
        cin >> n >> m ;
        ll sum = 0 ;
        vector<ll> arr ;
        fo(i , n)
        {
            ll u ;
            cin >> u ;
            arr.pub(u) ;
            sum += arr[i] ;
        }
        sort(arr.begin() , arr.end()) ;
        reverse(arr.begin() , arr.end()) ;
        ll lim = sum + (4*m) - 1 ;
        lim /= (4*m) ;
        if(arr[m-1] < lim)
            cout << "No" << endl ;
        else
            cout << "Yes" << endl ;
        return ;

    }

    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
       /* #ifndef ONLINE_JUDGE
        freopen("inputf.txt" , "r" , stdin) ;
        freopen("outputf.txt" , "w" , stdout) ;
        freopen("error.txt" , "w" , stderr) ;
        #endif*/
        
        ll t ;
        //cin >> t ;
        t = 1 ;
        while(t--)
        {
            solve() ;
        }
        //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";*/

        return 0;
    }

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



int main() {
int N;
cin >> N;
string S;
cin >> S;
int ans = 0;
int suii = 0;
for(int i = 0; i< N; i++){
if(S[i] == 'I') suii++;
else suii--;
ans = max(ans, suii);


}
cout << ans << endl;
}

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

struct Point{
    int x, y;
};

int main() {
    int n;
    cin >> n;
    
    for(int i = 0; i < n; i++){
        Point a[4];
        for(int i = 0; i < 4; i++){
            cin >> a[i].x >> a[i].y;
        }
        double naiseki;
        double val1x, val1y, val2x, val2y;
        double var1, var2;
        val1x = (a[1].x-a[0].x);//*(a[1].x-a[0].x) + (a[1].y-a[0].y)*(a[1].y-a[0].y);
        val1y = (a[1].y-a[0].y);//*(a[1].x-a[0].x) + (a[1].y-a[0].y)*(a[1].y-a[0].y);
        
        val2x = (a[3].x-a[2].x);//*(a[3].x-a[2].x) + (a[3].y-a[2].y)*(a[3].y-a[2].y);
        val2y = (a[3].y-a[2].y);//*(a[3].x-a[2].x) + (a[3].y-a[2].y)*(a[3].y-a[2].y);

        naiseki = val1x*val2x + val1y*val2y;

        var1 = sqrt(val1x*val1x+val1y*val1y);
        var2 = sqrt(val2x*val2x+val2y*val2y);
        double tmp;
        tmp = var1*var2;
        //cout << "naiseki:" << naiseki << " " << "tmp:" << tmp <<  endl;
        if(naiseki == 0){
            cout << 1 << endl;
        }
        else if(fabs(naiseki-tmp) < 0.00000001  || fabs(naiseki+tmp) < 0.00000001){
            cout << 2 << endl;
        }
        else {
            cout << 0 << endl;
        }
        
    }
    return 0;
}




Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1LL<<60;

ll w[110], W;
int v[110], N;
ll dp[110][100010];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++)cin >> w[i] >> v[i];

    for (int i = 0; i < 110; i++)for (int sum_v = 0; sum_v < 100010; sum_v++)dp[i][sum_v] = INF;
    dp[0][0] = 0;

    for (int i = 0; i < N; i++)
    {
        for (int sum_v = 0; sum_v <= 100000; sum_v++)
        {
            if (sum_v >= v[i]) dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v-v[i]] + w[i]);
        
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
    int ans = 0;

    for (int sum_v = 0; sum_v < 100010; sum_v++)if (dp[N][sum_v] <= W) ans = sum_v;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 89480
mycode = r'''
# distutils: language=c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: infer_types=True
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

# cythonライブラリよみこみ
from libcpp.vector cimport vector as Vec

# define 
ctypedef long long LL
ctypedef Vec[LL] VLL #vector[long long]
ctypedef LL[::1] Arr

import numpy as np


# 読み込みはpython側で行う
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.readline #文字列読み込む時はこっち

cdef LL a_int(): return int(readline())

def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

cdef LL N=a_int()
#この問題ではnumpyも使える柔軟さを紹介しよう
# 一括に処理する際は生のnumpyで良いが、indexアクセスに関しては非常に低速である。
# そういうときはtyped memoryviewという形式にする。
# といっても実態はnumpyと同じなので、numpyの関数の引数にする事ができる。ただし、ファンシーインデックスとメソッドの利用はできない。

cdef Arr A = ints() 
# せっかくなのでAの各要素は何回割れるか記録しておこう
cdef VLL candi =VLL()
cdef LL cnt, a, i
#for a in A: #この書き方はかなり遅くなるので注意が必要 #Cっぽい書き方が基本的に早いことを押さえていれば大丈夫
for i in range(len(A)):
    a=A[i]
    cnt=0
    while a%2==0: #まだ2で割れるなら
        a//=2
        cnt+=1
    candi.push_back(cnt)
#print(candi) #vectorをpython objectとして扱う場合、cythonは自動的にlistとして変換してくれる
print(min(candi))

'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


Measured memory_bytes: 28072
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] x = new int[2020];
	int[] empty = new int[2021];
	for(int i=1;i<2021;i++) empty[i]=0;
	for(int i=0;i<n;i++){
		x[i+1]=sc.nextInt();
		empty[x[i+1]]=1;
	}
	int m = sc.nextInt();
	int a;
	for(int i=0;i<m;i++){
		a=sc.nextInt();
		if(empty[x[a]+1]==0&&x[a]!=2019){
			empty[x[a]+1]=1;
			empty[x[a]]=0;
			x[a]++;
		}
	}
	for(int i=0;i<n;i++){
		System.out.println(x[i+1]);
	}

    }
}



Measured memory_bytes: 26504
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

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

int main(){
  int n;
  cin >> n;
  char s[n+2];
  bool x=false;
  if(n%2)x=true;
  rep(i,n)cin >> s[i];
  rep(i,n/2){
    if(s[i]!=s[i+n/2]){
      x=true;
      break;}
  }
  if(x) cout << "No";
  else cout << "Yes";
}


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

int main(){
  int n,i;
  cin>>n;
  vector<double> a(n),tmp(n);
  rep(i,n)cin>>a[i];
  tmp=a;
  sort(tmp.begin(),tmp.end());
  rep(i,n){
    int ans=lower_bound(tmp.begin(),tmp.end(),a[i])-tmp.begin();
    ans*=3;
    ans+=upper_bound(tmp.begin(),tmp.end(),a[i])-lower_bound(tmp.begin(),tmp.end(),a[i])-1;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

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


typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

vector<Weight> dijkstra2(const Graph &g, int s) {
  int n = g.size();
  vector<Weight> dist(n, INF);
  dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return dist;
}


int main() {
  int n;
  while(cin >> n,n) {
    Graph g(10);
    int m = 0;
    while(n--) {
      int a,b,c;
      cin >> a >> b >> c;
      g[a].push_back(Edge(a,b,c));
      g[b].push_back(Edge(b,a,c));
      m = max(max(m, a), b);
    }
    m++;
    g.resize(m);
    int res, mi = INF;
    REP(i, m) {
      vector<int> d = dijkstra2(g, i);
      int sum = 0;
      REP(j, m)
        sum += d[j];
      if (mi > sum) {
        mi = sum;
        res = i;
      }
    }
    cout << res << " " << mi << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
 
int main() {
    int n;
    cin >> n;
    int cnt1=0,cnt2=0,cnt3=0, ans=0;  
    rep(i, 0, n){
        string a;
        cin >> a;
        int m = a.size();
        rep(j, 0, m-1){
            if(a[j]=='A'&&a[j+1]=='B')ans++;
        }
        if(a[0]!='B'&& a[m-1]=='A')cnt1++;
        if(a[0]=='B'&& a[m-1]!='A')cnt2++;
        if(a[0]=='B'&& a[m-1]=='A')cnt3++;
    }
    //cout << ans << endl;
    if(cnt1>cnt2){
        ans += cnt2+cnt3;
    }
    if(cnt1<cnt2){
        ans += cnt1+cnt3;
    }
    if(cnt1 == cnt2){
        if(cnt1==0)ans += max(0, (cnt3 -1)); 
        else ans += cnt1+cnt3;
    }
    cout << ans << endl;
    //cout << cnt1 << cnt2 << cnt3 << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

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

			String str = sc.next();

			//インデックスは0からスタートするので，奇数番目の文字は偶数のインデックスになる
		    for(int i = 0; i < str.length(); i ++){
		    	if (str.charAt(i) == '9'){
				    System.out.println("Yes");
				    return;
		    	}
		    }
		    System.out.println("No");

		}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N);
  int a, count = 0;
  for(int i = 0; i < N; i++) {
    cin >> a;
    if (N < a) count++;
    else data.at(a - 1)++;
  }
  for(int i = 0; i < N; i++) {
    if (data.at(i) == 0) continue;
    if(data.at(i) < i + 1) count += data.at(i);
    else if (data.at(i) > i + 1) count += data.at(i) - i - 1;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
}

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        System.out.println((n - 1) * (m - 1));
    }
}

Measured memory_bytes: 21204
// binary tree
#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 30

struct Node{
    int p,l,r;
};

Node T[MAX];
int D[MAX], H[MAX];

int setHight(int u);
void setDepth(int u, int d);
void print(int u);

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for(int i = 0; i < n; i++){
        int id, left, right;
        cin >> id >> left >> right;
        T[id].l = left; T[id].r = right;
        T[left].p = id; T[right].p = id; 
    }

    int root;
    for(int i = 0; i < n; i++){
        if(T[i].p == NIL) root = i;
    }
    
    setHight(root);
    setDepth(root,0);

    for(int i = 0; i < n; i++){
        print(i);
    }

}

int setHight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].l != NIL) h1 = setHight(T[u].l) + 1;
    if(T[u].r != NIL) h2 = setHight(T[u].r) + 1;
    return H[u] = (h1 > h2) ? h1 : h2;
}

void setDepth(int u, int d){
    if(u == NIL) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r, d+1);
}

void print(int u){
    cout << "node " << u << ": parent = " << T[u].p;
    // sibling
    int deg = 0;
    if(T[u].p != NIL && T[T[u].p].l != NIL && T[T[u].p].l != u) {cout << ", sibling = " << T[T[u].p].l;}
    else if(T[u].p != NIL && T[T[u].p].r != NIL && T[T[u].p].r != u) {cout << ", sibling = " << T[T[u].p].r;}
    else cout << ", sibling = " << -1;

    if(T[u].l != NIL) deg++;
    if(T[u].r != NIL) deg++;

    cout << ", degree = " << deg << ", depth = " << D[u] << ", height = " << H[u];

    if(T[u].p == NIL) cout << ", root" << endl;
    else if(T[u].l == NIL && T[u].r == NIL) cout << ", leaf" << endl;
    else cout << ", internal node" << endl;

}


Measured memory_bytes: 3120
using System;
using System.Collections.Generic;

namespace P0029_EnglishSentence
{
    class Program
    {
        static void Main(string[] args)
        {
            var words = ReadLine().Split(' ');
            
            var ht = new Dictionary<string, int>();
            
            foreach (var word in words)
            {
                if (ht.ContainsKey(word)) 
                {
                    ht[word] += 1;
                }
                else 
                {
                    ht.Add(word, 1);
                }
            }

            string a = "";
            string b = "";
            int maxi = 0;
            int maxl = 0;

            foreach (var word in ht.Keys)
            {
                if (maxi < ht[word]) 
                {
                    maxi = ht[word];
                    a = word;
                }
                if (maxl < word.Length)
                {
                    maxl = word.Length;
                    b = word;
                }
            }

            Console.WriteLine(a + " " + b);

        }

        private const int READLINE_BUFFER_SIZE = 1024;

        private static string ReadLine()
        {
            System.IO.Stream inputStream = Console.OpenStandardInput(READLINE_BUFFER_SIZE);
            byte[] bytes = new byte[READLINE_BUFFER_SIZE];
            int outputLength = inputStream.Read(bytes, 0, READLINE_BUFFER_SIZE);
            //Console.WriteLine(outputLength);
            char[] chars = System.Text.Encoding.UTF7.GetChars(bytes, 0, outputLength);
            return new string(chars);
        }

    }
}

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  ll A,B,C;
  cin >> A >> B >> C;

  ll ans = abs(A/2 * B * C - (A-A/2) * B * C);
  ans = min(ans,abs(B/2 * A * C - (B-B/2) * A * C));
  ans = min(ans,abs(C/2 * A * B - (C-C/2) * A * B));

  cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;

ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

string s, t;

ll solve(void)
{
	cin >> s >> t;

	ll cnt = 0;
	for (int i = 0; i < s.length(); i++)
		if (s[i] == t[i]) cnt ++;

	cout << cnt << endl;

	return 0;
}



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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

int f (int n)
{
    int ans = 0;
    for(int x = 1; x * x <= n; x++)
        for(int y = 1; x * x + y * y + x * y <= n; y++)
        {
            int a = 1;
            int b = x + y;
            int c = x * x + y * y + x * y - n;
            if(b * b - 4 * a * c < 0)
                continue;
            double delta = sqrt(b * b - 4 * a * c);
            double x1 = (-b - delta) / (2 * a);
            double x2 = (-b + delta) / (2 * a);
            if(int(x1) == x1 && x1 > 0)
                ans++;
            if(int(x2) == x2 && x2 > 0)
                ans++;
        }
    return ans;
}

int n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cout << f(i) << "\n";
    return 0;
}


Measured memory_bytes: 3560
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b = list(map(int, input().split()))
if 1<=a<=9 and 1<=b<=9:
    ans = a*b
else:
    ans = -1
print(ans)

Measured memory_bytes: 61952
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

const string YES = "YES";
const string NO = "NO";

void solve(std::vector<long long> a, std::vector<long long> b){
    map<ll, ll> mp;
    rep(i, 3){
        mp[a[i]]++;
        mp[b[i]]++;
    }
    ll cnt = 0;
    for(auto x: mp){
        if(x.second & 1)
            cnt ++;
    }
    if (cnt > 2)
        cout << NO << endl;
    else
        cout << YES << endl;
}

int main(){
    std::vector<long long> a(3);
    std::vector<long long> b(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp
k = gets.to_i
s.size.times{|i|
	toa = (?z.ord + 1 - s[i].ord) % 26
	if toa <= k
		s[i] = 'a'
		k -= toa
	end
}
s[-1] = ((s[-1].ord-?a.ord+k)%26 + ?a.ord).chr
puts s


Measured memory_bytes: 2044
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int N=256;
int a[N],b[N];
int main()
{
    string a;
    cin>>a;
    int ans=0;
    for(int i=0; i<a.size(); i++)
    {
        int num=0;
        if(a[i]=='R')
            while(a[i]=='R')
            {
                num++;
                i++;
            }
        ans=max(num,ans);
    }
    printf("%d",ans);
    return 0;
}


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    ll c, s;
    cin >> s >> c;
    ull ans;
    if(2 * s >= c) ans = c / 2;
    else{
        ans = s;
        c -= s * 2;
        ans += c / 4;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+13;
const ll mod=1e9+7; 
ll a[maxn];
ll b[maxn];
ll c[maxn];
int main()
{
	ll n;
    a[0]=b[0]=c[0]=1ll;
	for(int i=1;i<=maxn;i++) a[i]=1ll*a[i-1]*10%mod;
    for(int i=1;i<=maxn;i++) b[i]=1ll*b[i-1]*9%mod;
    for(int i=1;i<=maxn;i++) c[i]=1ll*c[i-1]*8%mod;
	scanf("%lld",&n);
	ll ans=0;
	ans+=a[n];
	ans%=mod;
	ans-=1ll*2*b[n];
	ans=(ans+2*mod)%mod;
	ans=(ans+c[n]%mod)%mod;
	printf("%lld",ans);
 } 

Measured memory_bytes: 27256
#include <algorithm>
#include <iostream>
using namespace std;
int A[4];
char OP[3];

bool search(int i, int N) {
  if (i == 3) {
    return (N == 7);
  }
  bool ret0 = search(i + 1, N + A[i + 1]);
  if (ret0 == true) {
    OP[i] = '+';
    return true;
  }
  bool ret1 = search(i + 1, N - A[i + 1]);
  if (ret1 == true) {
    OP[i] = '-';
    return true;
  }
  return false;
}

int main(void) {
  int N;
  cin >> N;
  for (int i = 0; i < 4; i++) {
    A[3 - i] = N % 10;
    N /= 10;
  }
  search(0, A[0]);
  for (int i = 0; i < 3; i++)
    cout << A[i] << OP[i];
  cout << A[3] << "=7" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
      	//入力
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var A = input[0];
        var B = input[1];
		
      	//処理
        var ans=0;
      	if(A<B)
          ans=B+B-1;
      	else if(A>B)
          ans=A+A-1;
      	else
          ans=A+B;
		
      	//出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        x: usize,
        y: usize,
        a: usize,
        b: usize,
        c: usize,
        p: [usize;a],
        q: [usize;b],
        r: [usize;c],
    }

    let mut v = Vec::with_capacity(a + b + c);
    for x in p {
        v.push((x, b'R'));
    }
    for x in q {
        v.push((x, b'G'));
    }
    for x in r {
        v.push((x, b'W'));
    }

    v.sort_unstable_by_key(|x| 1000_000_000 - x.0);
    let mut red = 0;
    let mut green = 0;
    let mut white = 0;
    let mut ans = 0;
    for i in 0..v.len() {
        match v[i].1 {
            b'R' => {
                if red < x {
                    ans += v[i].0;
                    red += 1;
                }
            }
            b'G' => {
                if green < y {
                    ans += v[i].0;
                    green += 1;
                }
            }
            b'W' => {
                ans += v[i].0;
                white += 1;
            }
            _ => panic!(),
        }
        if red + green + white == x + y {
            break;
        }
    }

    println!("{}", ans);
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

int X, t;
int main() {
    std::cin >> X >> t;
    std::cout << std::max(X-t, 0) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    for(int i=a.size()-1;i>=b.size()-1;i--){
        int fail=0;
        for(int j=b.size()-1;j>=0;j--){
            if(a[i+j-b.size()+1]=='?'||a[i+j-b.size()+1]==b[j]){

            }
            else{
                fail=1;
                break;
            }
        }
        if(!fail){
            for(int j=b.size()-1;j>=0;j--){
                a[i+j-b.size()+1]=b[j];
            }
            for(char c:a){
                if(c=='?')putchar('a');
                else putchar(c);
            }
            return 0;
        }
    }
    puts("UNRESTORABLE");
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=(a+b)/2;
    System.out.println( c*2==(a+b)?c:"IMPOSSIBLE" );
  }
}


Measured memory_bytes: 23636
#include <iostream>

int main()
{
    int n, k, x, y;
    std::cin >> n >> k >> x >> y;

    if (n <= k)
    {
        std::cout << x * n << std::endl;
    }
    else
    {
        std::cout << x * k + y * (n - k) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    ll A;
    long double B;
    cin >> A >> B;
    long double x = A*B;
    ll ans = x;
    COUT(ans);
}


Measured memory_bytes: 3732
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         String input = infile.readLine();
         char[] arr = input.toCharArray();
         int cnt = 0;
         for(int x: arr)
            cnt += x-'0';
         int[] dp = new int[N+1];
         for(int v=1; v <= N; v++)
         {
            int bc = Integer.bitCount(v);
            dp[v] = dp[v%bc]+1;
         }
         int plus = cnt+1;
         int minus = cnt-1;
         int val1 = 0;
         int val2 = 0;
         for(int i=N-1; i >= 0; i--)
         {
            int b = N-1-i;
            if(arr[i] == '1')
            {
               val1 += (int)power(2, b, plus);
               if(minus > 0)
                  val2 += (int)power(2, b, minus);
               if(val1 >= plus)  val1-=plus;
               if(val2 >= minus) val2-=minus;
            }
         }
         StringBuilder sb = new StringBuilder();
         for(int i=0; i < N; i++)
         {
            int b = N-1-i;
            int res = 0;
            if(arr[i] == '0')
            {
               int newval = val1+(int)power(2, b, plus);
               newval %= plus;
               res = 1+dp[newval];
            }
            else if(minus > 0)
            {
               int newval = val2-(int)power(2, b, minus);
               if(newval < 0) newval += minus;
               res = 1+dp[newval];
            }
            sb.append(res+"\n");
         }
         System.out.print(sb);
      }
      public static long power(long x, long y, long p) 
      { 
          long res = 1L;      
          x = x % p;  
          while(y > 0) 
          { 
              if((y & 1)==1) 
                  res = (res * x) % p; 
              y = y >> 1;  
              x = (x * x) % p;  
          } 
          return res; 
      } 
   }

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

typedef pair<int,int> PII;

int main(){
	char c;
	int a,b,d;
	cin>>a>>c>>b>>c>>d;

	if(a<=2019&&b<=4&&d<=30)
		cout<<"Heisei"<<endl;
	else
		cout<<"TBD"<<endl;
}

Measured memory_bytes: 256