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

const int INF = 1e9+5;

void print(std::vector<std::vector<long long> > A){
	for(int i = 0; i<A.size(); i++){
		for(int j = 0; j<A[i].size(); j++){
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}

long long knapsack(std::vector<long long> V, std::vector<int> W, int w){
	std::vector<std::vector<long long> > k(V.size()+1, std::vector<long long> (w+1));
	for(int i = 0; i<=V.size(); i++){
		for(int j = 0; j<=w; j++){
			if(i == 0 || j == 0)
				k[i][j] = 0;
			else if(j>=W[i-1])
				k[i][j] = max(k[i-1][j], V[i-1] + k[i-1][j-W[i-1]]);
			else
				k[i][j] = k[i-1][j];
		}
	}
	
	return k[V.size()][w];
}

int main(){
	int n, w;
	cin>>n>>w;
	std::vector<long long> value;
	std::vector<int> weights;

	for(int i = 0; i<n; i++){
		long long v, W;
		cin>>W>>v;
		value.push_back(v);
		weights.push_back(W);
	}

	long long ans = knapsack(value, weights, w);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...)
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int a, b, c;
	cin >> a >> b >> c;
	cout << c-min(a-b, c) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//freopen("input.txt" , "r" , stdin);
//freopen("output.txt" , "w" , stdout);
#define ll long long
#define endl  '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REP1(i1,n)  for(ll i=1;i<n;i++)
#define pb push_back
#define mk make_pair
int main()
{
   IOS
   ll ans=0;
   for(ll i=1;i<=5;i++)
   {
       ll x;
       cin>>x;
       if(x==0)
        ans=i;

   }
   cout<<ans<<endl;

    //for(ll i=0;i<len;i++)cout<<v[i]<<" ";
}


/*

Alhamdulilla...

*/


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

int main(){
  int A,B,ans=0,i;
  int64_t K;
 
  cin>>A>>B>>K;
  if(A>B)
    i=B;
  else
    i=A;
  while(1){
    if(A%i==0&&B%i==0)
      ans++;
    if(ans==K){
      cout<<i<<endl;
      break;
    }
    i--;
  }
}


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

int main(){
    int n,k;cin>>n>>k;
    vector<long long> H(n);
    for(int i=0;i<n;i++) cin>>H[i];
    sort(H.begin(),H.end());

    long long sum=0;
    for(int i=0;i<n-k;i++){
        sum+=H[i];
    }

    cout<<sum<<endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n + 1];
        int count = 0;
        for (int i = 1; i <= n; i++) {
            arr[sc.nextInt()] = i;
        }
        arr[0] = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 1; i <= n; i++) {
            if (arr[i] < arr[i - 1]) {
                max = Math.max(count, max);
                count = 1;
            } else {
                count++;
            }
        }
        max = Math.max(count, max);
        System.out.println(n - max);
    }
}


Measured memory_bytes: 85760
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <chrono>

using namespace std;

const int MAXN = 100000;

int x;

struct Exam {
    int b;
    int l;
    int u;

    long long total() const {
        return 1LL * b * l + 1LL * (x - b) * u;
    }

    long long partial(long long a) {
        if (a <= b)
            return 1LL * a * l;
        else
            return 1LL * b * l + 1LL * (a - b) * u;
    }

    bool operator < (const Exam &other) const {
        return total() > other.total();
    }
};

Exam v[1 + MAXN];
long long sum[1 + MAXN];
priority_queue<pair<int, int> > upHeap;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > downHeap;

bool check(int n, long long limit, long long taken) {
    if (1LL * n * x == taken)
        return sum[n] >= limit;
    long long r = taken % x, c = taken / x;
    bool found = false;
    for (int i = 1; i <= n; i++)
        if (i <= c)
            found |= sum[c + 1] - v[i].total() + v[i].partial(r) >= limit;
        else
            found |= sum[c] + v[i].partial(r) >= limit;
    return found;
}

int main() {
    //ifstream cin("input.in");
    int n;
    cin >> n >> x;
    long long limit = 0;
    for (int i = 1; i <= n; i++) {
        cin >> v[i].b >> v[i].l >> v[i].u;
        limit += 1LL * v[i].b * v[i].l;
    }
    sort(v + 1, v + n + 1);
    for (int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + v[i].total();
    long long left = 0, right = 1LL * n * x, answer = 1LL * n * x;
    while (left <= right) {
        long long middle = (left + right) / 2;
        if (check(n, limit, middle)) {
            answer = middle;
            right = middle - 1;
        }
        else
            left = middle + 1;
    }
    cout << answer << "\n";
    return 0;
}







Measured memory_bytes: 2176
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int main(){
  int N, M;

  cin >> N;
  //VL D = VL(N, 0);
  map<ll, int> m;
  REP(i, 0, N){
    ll tmp;
    cin >> tmp;
    m[tmp]++;
  }

  cin >> M;

  if(N < M){
    cout << "NO" << endl;
    return 0;
  }

  REP(i, 0, M){
    ll in;
    cin >> in;

    if(m[in] > 0){
      m[in]--;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" <<endl;

  return 0;
}


Measured memory_bytes: 12800
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    Integer L[] = new Integer[M];
    Integer R[] = new Integer[M];
    for(int i=0; i<M; i++){
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }
    int left = L[0];
    int right = R[0];
    for(int i=1; i<M; i++){
      if(left < L[i]) left = L[i];
      if(right > R[i]) right = R[i];
    }
    int ans;
    if(left > right) ans = 0;
    else ans = right - left + 1;
    System.out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 88668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <bitset>
using namespace std;

typedef long long ll;

ll sum(ll n) {
	return (n*(n + 1)) / 2;
}

int main() {
	cin.sync_with_stdio(false); cin.tie(nullptr);
	ll n; cin >> n; 
	ll sol = 0;
	for (ll a = 1; a <= n; ++a) sol += a * sum(n / a);
	cout << sol << endl;
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>

using namespace std;

int pow(int a, int b) {
    if (b < 0) return 0;
    int ans = 1;
    for (int i = 0; i < b; ++i) ans *= a;
    return ans;
}

int main() {
    int n, ans = 1;
    cin >> n;
    for (int i = 2; i * i <= n; ++i) for (int j = 2; pow(i, j) <= n; ++j) if (ans < pow(i, j)) ans = pow(i, j);
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i=0;i<N;i++){
    cin >> v.at(i);
  }
  int count=0;
  for (int i=0;i<N;i++){
    for (int j=0;j<N;j++){
      if(i!=j)
        count += v[i]*v[j];
    }
  }
  cout << count/2 << endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
const int maxn=1000000;
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);
void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
const int nn=1e5+5;
void solve() {
      int n;
      cin>>n;
      int arr[n];
      for(int i=0;i<n;++i) cin>>arr[i];

      sort(arr,arr+n);
      reverse(arr,arr+n);
        if(n==1){
            cout<<0<<"\n";
            return;
        }
        if(n==2)
        {
            cout<<arr[0]<<"\n";
            return;
        }
      int sum=arr[0];
      int left=n-2;
      int last;
      for(int i=1;i<n;++i)
      {
          sum+=arr[i]*2;
          last=arr[i];
          left-=2;
          if(left<=0) break;
      }
      //cout<<sum<<" "<<last<<"\n";
      if((n-2)%2!=0) cout<<sum-last;
      else
      cout<<sum;



}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //fillprime();
    //int t;cin>>t;while(t--)
        solve();
}

Measured memory_bytes: 5312
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;


int main(){
    int N;
    string A,B,C;
    cin>>N>>A>>B>>C;
    int ans = 0;
    for(int i = 0;i <N;i++){
        if(A[i]!=B[i]){
            if(A[i]==C[i]){
                ans += 1;
            }else if(B[i]==C[i]){
                ans += 1;
            }else{
                ans += 2;
            }
        }else{
            if(A[i]==C[i]){
                ;
            }else{
                ans += 1;
            }
        }
    }
    cout<<ans<<endl;
}


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

lr = []
for i in range(m):
    l = list(map(int, input().split()))
    lr.append(l)

count = 0
minimum = 0
maxmum = 10**9
for i in range(m):
    minimum = max(minimum, lr[i][0])
    maxmum = min(maxmum, lr[i][1])

if(maxmum >= minimum):
    print(maxmum - minimum + 1)
else:
    print(0)

Measured memory_bytes: 60120
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, k, a[109], dp[100009];
int solve(int left)
{
    if(left<0)
        return 0;
    if(left==0)
        return 1 ;
    int &ans=dp[left];
    if(ans!=-1)
        return ans ;
    for(int i=0; i<n; i++)
        ans=max(ans,solve(left-a[i]));
    ans=1-ans;
    return ans ;
}
int main()
{
    IO
    memset(dp, -1, sizeof dp);
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];
    cout<<((1-solve(k)) ? "First" : "Second");
}


Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 105;

int n;
int s[maxn];
int dp[maxn][15];
bool v[maxn][15];
int main(){
	while(cin >> n){
		for(int i = 1;i <= n;i++){
			scanf("%d",s + i);
		}
		memset(dp,0,sizeof(dp));
		memset(v,false,sizeof(v));
		v[0][0] = 1;
		for(int i = 1;i <= n;i++){
			for(int j = 0;j < 10;j++){
				if(v[i - 1][j]){
					v[i][j] = 1;
					dp[i][j] = max(dp[i][j],dp[i - 1][j]);}
				int from = (j - s[i] % 10 + 10) % 10;
				if(v[i - 1][from]){
					v[i][j] = 1;
					dp[i][j] = max(dp[i][j],dp[i - 1][from] + s[i]);
				}
			}
		}
		/*for(int i = 1;i <= n;i++){
			for(int j = 0;j < 10;j++){
				printf("dp[%d][%d] = %d\n",i,j,dp[i][j]);
			}
		}
*/
		int ans = 0;
		for(int i = 1;i < 10;i++){
			ans = max(ans,dp[n][i]);
		}
		cout << ans << endl;
	}
	return 0;
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  ll ans = 0;
  for (int i = 0; i * R <= N; i++) {
    for (int j = 0; i * R + j * G <= N; j++) {
      int k = N - i * R - j * G;
      if (k % B == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n, h;

int main(void)
{
	cin >> h;
	
	llint cnt = 0;
	for(;h;h/=2) cnt++;
	cout << (1LL<<cnt)-1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    
    int N,M;cin>>N>>M;
    vector<int> A(N),B(M);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    
    ll dp[N+1][M+1];
    vector<ll> sum(M+1,0);
    
    for(int i=0;i<N+1;i++){
        for(int j=0;j<M+1;j++){
            dp[i][j]=0;
        }
    }
    
    for(int i=1;i<=N;i++){
        vector<ll> C(M+1,0);
        for(int j=1;j<=M;j++){
            if(A[i-1]==B[j-1]){
                dp[i][j]=(sum[j-1]+1)%mod;
            }
        }
        for(int j=1;j<=M;j++){
            C[j]=(C[j-1]+dp[i][j])%mod;
        }
        for(int j=1;j<=M;j++){
            sum[j]=(sum[j]+C[j])%mod;
        }
    }
    
    ll ans=1;
    
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            ans=(ans+dp[i][j])%mod;
            //if(j>=2) cout<<" "<<dp[i][j];
            //else cout<<dp[i][j];
        }
        //cout<<endl;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 31616
/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
const int inf= INT_MAX;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{ 
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
void update(vi &ft,int ind,int val){for(int i=ind;i<ft.size();i+=lsone(i))ft[i]+=val;}
int query(vi &ft,int ind){
	int sum=0;
	for(int i=ind;i;i-=lsone(i))sum+=ft[i];
	return sum;
	}
signed main()
{
	IOS
	int n,q;
	cin>>n>>q;
	vi c(n);
	map<int,set<int>> mapp;
	vi ft(n+2,0);
	
	fr(i,0,n)
	{
		 cin>>c[i];
		 if(!mapp.count(c[i]))
		 {
		 	 update(ft,i+1,1);
		 }
		 mapp[c[i]].insert(i);
	}
	//vi ft(n+1,0);
	vector<ppi> queries(q);
	fr(i,0,q)
	{
		cin>>queries[i].fi.fi>>queries[i].fi.se;
		queries[i].se=i;
	}
	sort(all(queries));
	int cur=0;
	int ans[q];
	fr(i,0,n)
	{
		while(cur<queries.size()&&queries[cur].fi.fi==i+1)
		{
			ans[queries[cur].se]=query(ft,queries[cur].fi.se)-query(ft,queries[cur].fi.fi-1);
		 	cur++;
		}
		
			set<int> & v=mapp[c[i]];       
			v.erase(v.begin());
			//v.pop_back();
			if(v.size())update(ft,*v.begin()+1,1);
			update(ft,i+1,-1);
		
	}
	fr(i,0,q)cout<<ans[i]<<endl;
	
}



Measured memory_bytes: 85920
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

ll N,C;
ll D[30][30];
ll c[500][500];

ll count[3][30]; //グループiで色がjの数
ll cost[3][30]; //グループiを色jにした場合の違和感

int main(){
    cin >> N >> C;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            cin >> D[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> c[i][j];
        }
    }

    for(int i=0;i<3;i++){
        for(int j=0;j<C;j++){
            count[i][j] = 0;
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            count[(i+j)%3][c[i][j]-1]++;
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<C;j++){
            cost[i][j] = 0;
        }
    }

    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<3;k++){
                cost[k][j] += count[k][i] * D[i][j];
            }
        }
    }

    ll score = 1e12;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            if(i==j) continue;
            for(int k=0;k<C;k++){
                if(i==k || j==k) continue;
                score = min(score, cost[0][i]+cost[1][j]+cost[2][k]);
            }
        }
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 2176
int main(void)
{

  int a,b,c;
  int max;
  int flag=0;

  scanf("%d",&a);
  max = a;
  scanf("%d",&b);
  if(b>max){max=b;flag=1;}
  scanf("%d",&c);
  if(c>max){max=c;flag=2;}
  if(flag==0){printf("%d\n",10*max+b+c);}
  else if(flag==1){printf("%d\n",10*max+a+c);}
  else{printf("%d\n",10*max+b+a);}
  return 0;
}


Measured memory_bytes: 128
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();

    if (a > b) {
      System.out.println(a + a-1);
    }

    if (b > a) {
      System.out.println(b + b-1);
    }

    if (a == b) {
      System.out.println(a + b);
    }



  }
}


Measured memory_bytes: 20948
import java.util.*;
public class Main{
  public static Map<String, Long> map = new HashMap<>();
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int[] x = new int[N];
    for(int i = 0; i < N; i++){
      x[i] = sc.nextInt();
    }
    long result = ans(x, 0, 0, 0, A);
    System.out.println(result-1);
  }
  
  public static long ans(int[] array, int index, int sum, int n, int A){
    int[] tmp = {index, sum, n};
    if(map.containsKey(Arrays.toString(tmp))){
      return map.get(Arrays.toString(tmp));
    }
    
    if(index == array.length){
      if(A * n == sum){
        return 1L;
      }else{
        return 0L;
      }
    }
    
    long result = ans(array, index+1, sum+array[index], n+1, A) +
              ans(array, index+1, sum, n, A);
    map.put(Arrays.toString(tmp), result);
    return result;
  }
}

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

string s;
long long c[26];
long long v;
int main(){
	for (int i = 0; i <= 25; i++)c[i] = 0;
	cin >> s;
	for (int i = 0; i <= s.length() - 1; i++) {
		if (s[i] == 'a') c[0]++;
		if (s[i] == 'b') c[1]++;
		if (s[i] == 'c') c[2]++;
		if (s[i] == 'd') c[3]++;
		if (s[i] == 'e') c[4]++;
		if (s[i] == 'f') c[5]++;
		if (s[i] == 'g') c[6]++;
		if (s[i] == 'h') c[7]++;
		if (s[i] == 'i') c[8]++;
		if (s[i] == 'j') c[9]++;
		if (s[i] == 'k') c[10]++;
		if (s[i] == 'l') c[11]++;
		if (s[i] == 'm') c[12]++;
		if (s[i] == 'n') c[13]++;
		if (s[i] == 'o') c[14]++;
		if (s[i] == 'p') c[15]++;
		if (s[i] == 'q') c[16]++;
		if (s[i] == 'r') c[17]++;
		if (s[i] == 's') c[18]++;
		if (s[i] == 't') c[19]++;
		if (s[i] == 'u') c[20]++;
		if (s[i] == 'v') c[21]++;
		if (s[i] == 'w') c[22]++;
		if (s[i] == 'x') c[23]++;
		if (s[i] == 'y') c[24]++;
		if (s[i] == 'z') c[25]++;
	}
	v = s.length();
	long long ans = v*(v - 1) / 2 + 1;
	for (int i = 0; i <= 25; i++) {
		if (c[i] >= 2) {
			ans -= c[i] * (c[i] - 1) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
class dsu{
    public:
    unordered_map<int,int> p,sz;
    void make_set(int x)
    {
        p[x] = x;
        sz[x]+=1;
    }
    int find(int x)
    {
        if(x == p[x])return x;
        return p[x] = find(p[x]);
    }
    void merge(int a,int b)
    {
        a = find(a);
        b = find(b);
        if(a == b)return;
        if(sz[a]<sz[b])swap(a,b);
        p[b] = a;
        sz[a]+=sz[b];
        sz.erase(b);
    }
};
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = (res*a);
        b>>=1;
        a*=a;
    }
    return res;
}
class wemen{
public:
    int b,i,r;
    wemen(){

    }
    bool operator<(const wemen& o){
        if(b!=o.b)return b>o.b;
        else if(i!=o.i)return i>o.i;
        else return r>=o.r;
    }
};
void online_judge(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int kmp(string s){
    vector<int> lps(s.size(),0);
    for(int i = 1; i<lps.size(); ++i){
        int prev_index = lps[i-1];
        while(prev_index>0&&s[i]!=s[prev_index]){
            prev_index = lps[prev_index-1];
        }
        lps[i] = prev_index+(s[i] == s[prev_index]?1:0);
    }
    return lps[lps.size()-1];
}
int ask1(int node){
    cout<<1<<' '<<node<<endl;
    int ans;
    cin>>ans;
    return ans;
}
int ask2(int node,int y){
    cout<<2<<' '<<node<<' '<<y<<endl;
    int ans;
    cin>>ans;
    return ans;

}
const int mxn = 2e3;
vector<pair<int,int>> adj[mxn+1];
int n,x,y;
int main()
{
    fastio();
    cin>>n>>x>>y;
    fori(i,1,n+1)adj[i].clear();
    adj[x].pb({1,y});
    adj[y].pb({1,x});
    fori(i,1,n){
        adj[i].pb({1,i+1});
        adj[i+1].pb({1,i});
    }
    set<pair<int,int>> dij;
    vector<int> d(n+1,INT_MAX);
    unordered_map<int,ll> mp;
    for(int i = 1; i<=n;i++){
        int s = i;
        dij.clear();
        d.clear();
        d.assign(n+1,INT_MAX);
        dij.insert({0,s});
        d[s] = 0;
        while(!dij.empty()){
            pair<int,int> p = *dij.begin();
            dij.erase(dij.begin());
            int v = p.ss;
            int dis = p.ff;
            mp[dis]++;
            d[v] = dis;
            for(auto it:adj[v]){
                int to = it.ss;
                int len = it.ff;
                if(d[to]>d[v]+len){
                    if(dij.find({d[to],to})!=dij.end())dij.erase({d[to],to});
                    d[to] = d[v]+len;
                    dij.insert({d[to],to});
                }
            }
        }
    }
    for(int i = 1; i<n; i++){
        if(mp.find(i)!=mp.end())cout<<mp[i]/2<<endl;
        else cout<<0<<endl;
    }
}

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

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

using ll = long long;

constexpr int MAX_N = 1e5;
constexpr int MAX_K = 1e2;
constexpr ll INF = 1LL << 60;

int h[MAX_N];
ll dp[MAX_N+MAX_K];

int main() {
  int N, K;
  cin >> N >> K;
  for (int i{}; i < N; ++i)
    cin >> h[i];

  fill_n(dp, MAX_N+MAX_K, INF);
  dp[0] = 0;
  for (int i{}; i < N-1; ++i) {
    for (int j{1}; j <= K; ++j) {
      chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    }
  }

  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,ans=0;
cin >> n;
int a[n];
for(int i=0;i<n;i++){
	cin >> a[i];
}

for(int i=0;i<n;i++){
	if(a[i]%2==1){
		break;
	}
	a[i]=a[i]/2;
	if(i==n-1){
		ans++;
		i=0;
	}
}
cout << ans << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))


Measured memory_bytes: 59312
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int X, Y;
  scanf("%d", &X);
  scanf("%d", &Y);
  if (Y>=2*X && Y<=4*X && Y%2==0){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 3180
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll INF = 10000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
int ps[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
		ps[i] = 1;
	}
}

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

	int p = parent(pr[x]);
	ps[x] = ps[p];
	return pr[x] = p;
}

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

	if (px == py) return 0;

	ll sum = ps[px] + ps[py];
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	ll rel = ps[px] * ps[py];
	ps[px] = sum;
	ps[py] = sum;

	return rel;
}
ll at[30][30];
ll bt[30][30];
ll ar[30];
ll upt[30][30][30];
ll mid(ll x, ll y, ll z) {
	if (x <= y && y <= z) {
		return y;
	}
	else if (y <= x && x <= z) {
		return x;
	}
	else return z;
}
int c[30];
ll ggd(ll x, ll v) {

	if (v == 0) return 0;
	ll rem = x % v;
	ll di = ((x / v) * v) * 2;
	ll r = di + x;
	return r + ggd(v, rem) - rem;

}
//]


void solv() {

	int n, m;
	cin >> n >> m;
	uini(n);
	ll sum = 0;
	for (size_t i = 1; i < n; i++)
	{
		sum += i;
	}

	int a[100010], b[100010];
	for (size_t i = 0; i < m; i++)
	{
		cin >> a[i] >> b[i];
	}

	ll res[100010];
	for (int i = m - 1; i >= 0; i--)
	{
		ll rel = unit(a[i], b[i]);
		res[i] = sum;
		sum -= rel;
	}
	for (size_t i = 0; i < m; i++)
	{
		ll r = res[i];
		cout << max(0LL,res[i]) << endl;
	}
	//string s;
	//cin >> s;

	//cin >> n >> m;
	//fill(memo, memo + n, -1);
	//for (size_t i = 0; i < m; i++)
	//{
	//	int p, q,c;
	//	cin >> p >> q >> c;
	//	co[p, q] = c;
	//	co[q, p] = co[p, q];
	//	ve[p].push_back(q);
	//	ve[q].push_back(p);
	//}

	//
	//cout << rec(1, 0) << endl;

}


int main() {
	solv();

	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

template<typename T>
istream& operator >>(istream& is, vector<T>& vec){
    for(T& x: vec) is >>x;
    return is;
}
int main() {
    int N;
    vector<char>s(1000);
	cin>>N;
	FOR(i,(N/4)+1){
		FOR(k,(N/7)+1){
			if(i*4+k*7==N){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}


int main(){
    ll h,w;
    cin >> h >> w;
    if(h%3==0 || w%3==0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = h * w;

    ll A[2] = {h/3, h/3+1};
    ll B[2] = {w/2, w/2+1};
    
    rep(i,2)rep(j,2){
        ll a = A[i], b = B[j];
        ll pcs[3] = {a*w, (h-a)*b, (h-a)*(w-b)};

        // rep(k,3) cout << pcs[i] << " ";
        // cout << endl;

        chmin(ans, *max_element(pcs, pcs+3) - *min_element(pcs, pcs+3));
    }

    ll AA[2] = {w/3, w/3+1};
    ll BB[2] = {h/2, h/2+1};
    rep(i,2)rep(j,2){
        ll a = AA[i], b = BB[j];
        ll pcs[3] = {a*h, (w-a)*b, (w-a)*(h-b)};

        // rep(k,3) cout << pcs[i] << " ";
        // cout << endl;

        chmin(ans, *max_element(pcs, pcs+3) - *min_element(pcs, pcs+3));
    }

    if(w > h) swap(w,h); // always h >= w
    chmin(ans, w);

    cout << ans << 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 repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int a,b;
  cin >>a>>b;
  
  if((a+b)%2==0) {
    cout << (a+b)/2 << endl;
  }
      
    else puts(  "IMPOSSIBLE");

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{int  n,x,q,y;
long long sum = 0;
cin>>n;
map<int ,int> mp;
for(int i = 0;i<n;i++)
{
    cin>>x;
    mp[x]++;
    sum+=x;
}
cin>>q;
vector<pair<int ,int>> p;
for(int i = 0;i<q;i++)
{
cin>>x>>y;
p.push_back(make_pair(x,y));
}
for(int i = 0;i<q;i++)
{
    if(mp.find(p[i].first)!=mp.end())
    {
           int count =  mp[p[i].first];
           mp[p[i].first]  =0 ;
           mp[p[i].second] += count;
           sum+=count*(p[i].second-p[i].first);
        cout<<sum<<endl;
    }
    else
    cout<<sum<<endl;
}

// cout<<s<<endl;
    return 0;
}

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

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

const long long INF = 1LL << 60;

int main(){
  vector<int> a;
  for(int i=1; i<=100; i*=2){
    a.push_back(i);
  }

  int n;
  cin >> n;

  cout << *(upper_bound(all(a), n)-1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
    int k;
    string s;

    cin >> k;
    cin >> s;

    string str;
    if(s.length() <= k){
        str = s;
    }
    else{
        str = s.substr(0, k) + "...";
    }

    cout << str << endl;

    return 0;

}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
   string s;
   cin>>s;
   
   int cnt=0;
   rep(i,n-1){
       if(s[i]==s[i+1]){
           cnt++;
       }
   }
   cout<<n-cnt<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a; cin>>a;
	string s; cin>>s;
	if (a<3200) cout<<"red";
	else  cout<<s<<endl;
	return 0;
}


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

#define int long long
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define inf (int)1000000007

signed main() {
  string n;
  cin >> n;
  int s0 = 0;
  int s1 = inf;
  rrep(i, n.size()) {
    int x = n[i] - '0';
    int n0 = min(s0 + x, s1 + x + 1);
    int n1 = min(s0 + 10 - x, s1 + 10 - (x + 1));
    s0 = n0;
    s1 = n1;
  }
  cout << min(s0, s1 + 1) << endl;
}


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

int main() {
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  vector<int> num(3); cin >> num[0] >> num[1] >> num[2];
  int K; cin >> K;

  sort(num.begin(), num.end(), greater<int>());

  int total = num[1] + num[2];
  for (int i = 0; i < K; i++) {
    num[0] *= 2;
  }

  total += num[0];
  
  cout << total << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int x = in.nextInt();

    if (x == 2) {
      out.println(2);
      out.close();
      System.exit(0);
    }

    if (x % 2 == 0) x++;

    main:
    for (;;x++) {
      int sqrt = (int) Math.sqrt(x);
      for (int j = 2; j <= sqrt; j++) {
        if (x % j == 0)
          continue main;
      }
      out.println(x);
      break;
    }

    out.close();
  }

  static class InputReader {

    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      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 long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

Measured memory_bytes: 23124
#include<iostream>

using namespace std;

int main(void){
    int i, j;

    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            cout << i + 1 << "x" << j + 1 << "=" << (i + 1) * (j + 1) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2996
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = (1 << 18) + 10;
int n, q;
int v[maxN], w[maxN];
int V[18], W[18];
int SZ = 0;
int Ve[(1 << 12) + 10], We[(1 << 12) + 10];
const int BUBEN = 12;
vector < pair < int, int > > gg[(1 << (BUBEN + 1)) + 5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
//    n = (1 << 18) - 1;
    for (int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
    }
    for (int ii = 1; ii <= min(n, (1 << 12) - 1); ii++) {
        int v = ii;
        SZ = 0;
        while (v) {
            V[SZ] = ::v[v];
            W[SZ] = ::w[v];
            v /= 2;
            SZ++;
        }
        assert(SZ <= 12);
        int h1 = SZ;
        memset(Ve, 0, sizeof Ve);
        memset(We, 0, sizeof We);
        for (int i = 0; i < h1; i++) {
            Ve[1 << i] = V[i];
            We[1 << i] = W[i];
        }
        for (int j = 0; j < h1; j++) {
            for (int i = 0; i < (1 << h1); i++) {
                if (i & (1 << j)) {
                    Ve[i] += Ve[i ^ (1 << j)];
                    We[i] += We[i ^ (1 << j)];
                }
            }
        }
        for (int i = 0; i < (1 << h1); i++) {
            gg[ii].emplace_back(We[i], Ve[i]);
        }
        sort(gg[ii].begin(), gg[ii].end());
        for (int i = 1; i < gg[ii].size(); i++) {
            gg[ii][i].second = max(gg[ii][i].second, gg[ii][i - 1].second);
        }
    }
    cin >> q;
    while (q--) {
        int v, L;
        cin >> v >> L;
        vector < pair < int, int > > all;
        while (v > (1 << 12) - 1) {
            all.emplace_back(::w[v], ::v[v]);
            v /= 2;
        }
        int tot = all.size();
        int best = 0;
        for (int mask = 0; mask < (1 << tot); mask++) {
            int vv = 0;
            int ww = 0;
            for (int c = 0; c < tot; c++) {
                if (mask & (1 << c)) {
                    vv += all[c].second;
                    ww += all[c].first;
                }
            }
            if (ww > L) continue;
            assert(!gg[v].empty());
            auto it = upper_bound(gg[v].begin(), gg[v].end(), make_pair(L - ww, (int)1e9)) - gg[v].begin();
            assert(it > 0);
            best = max(best, vv + gg[v][it - 1].second);
        }
        cout << best << '\n';
    }
    return 0;
}


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

int main() {
  int n, q;
  int ret = 0;
  scanf("%d", &n);
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  cin >> q;
  vector<int> t(q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &t[i]);
  }
  for (auto &&var : t) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (s[mid] == var) {
        ret++;
        break;
      } else if (var < s[mid])
        right = mid;
      else
        left = mid + 1;
    }
  }
  printf("%d\n", ret);

  return 0;
}



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

int main(void){
    int n,m,l;
    cin>>n>>m>>l;
    vector<vector<int64_t> > a(110,vector<int64_t>(110)),b(110,vector<int64_t>(110)),c(110,vector<int64_t>(110));
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a.at(i).at(j);
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin>>b.at(i).at(j);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                c.at(i).at(j)+=a.at(i).at(k)*b.at(k).at(j);
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j==l-1)cout<<c.at(i).at(j)<<endl;
            else cout<<c.at(i).at(j)<<" ";
        }
    }
}



Measured memory_bytes: 3320
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val l = (1..n).map { sc.nextInt() }.sorted()
  val d = l.map { it.toDouble() }

  var count = 0L
  for (i in 0..n-3) {
    val a = l[i]
    for (j in i+1..n-2) {
      val b = l[j]
      val ab = a + b
      val from = j + 1
      var r = d.binarySearch(element = ab.toDouble() - 0.1, fromIndex = from, toIndex = n -1)
      if (r < 0) r = r.inv()
      if (ab > l[r]) r++
      count += Math.max(0, r-from)
    }
  }


  println(count)

}


Measured memory_bytes: 52160
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var cities = new List<City>();
            for (int i = 0; i < N; i++)
            {
                var inputs = ReadLongs();
                cities.Add(new City { X = inputs[0], Y = inputs[1] });
            }

            var rootSum = 0D;
            for (int i = 0; i < N; i++)
            {
                for (int j = i; j < N; j++)
                {
                    if (i == j) continue;
                    rootSum += GetLength(cities[i], cities[j]);
                }
            }

            return 2 * rootSum / N;
        }

        private static double GetLength(City city1, City city2)
        {
            return Math.Sqrt(Math.Pow(city1.X - city2.X, 2) + Math.Pow(city1.Y - city2.Y, 2));
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }

    class City
    {
        public long X { get; set; }
        public long Y { get; set; }
    }
}


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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    string s;
    cin >> s;
    int ans = 0;
    string back;
    string current = "A";
    rep(i, s.size()) {
        if (i == 0) {
            back = s[i];
            ans++;
            continue;
        }
        if (current != "A") {
            current += s[i];
            if (current != back) {
                ans++;
                back = current;
                current = "A";
            }
        }
        else {
            string c = "";
            c += s[i];
            if (back != c) {
                back = s[i];
                ans++;
            }
            else {
                current = s[i];
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 640