akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; IN(s);
    cout << "2018";
    OUT(s.substr(4,9));

    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 FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//

int main(){
   ll n,k;cin>>n>>k;
   ll ans;
   ans=k;
   if(n!=1){
   rep(i,n-1){
      ans*=k-1;
   }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

ll n, u, v;
ll mx;
ll disu[100005];
ll disv[100005];
ll vis[100005];
vl ad[100005];

void bfs(ll a)
{
	queue <pair <ll, ll> > q;
	q.push(mp(a, 0));
	vis[a] = 1;
	while(!q.empty())
	{
		pair <ll, ll> tmp = q.front();
		ll lev = tmp.ss;
		ll ver = tmp.ff;
		q.pop();
		if(a == u)
			disu[ver] = lev;
		else
			disv[ver] = lev;
		ll i;
		fr(i, 0, ad[ver].size())
		{
			if(!vis[ad[ver][i]])
			{
				vis[ad[ver][i]] = 1;
				q.push(mp(ad[ver][i], lev + 1));
			}
		}
	}
}

void dfs(ll a)
{
	vis[a] = 1;
	ll i, j, k;
	if(disu[a] <= disv[a])
		mx = max(mx, disv[a]);
	fr(i,0,ad[a].size())
		if(!vis[ad[a][i]])
			dfs(ad[a][i]);
}

int main()
{
	FAST;
	ll i, j, k, l;
	cin >> n >> u >> v;
	mx = -1;
	fr(i,0,n-1)
	{
		ll t1, t2;
		cin >> t1 >> t2;
		ad[t1].pb(t2);
		ad[t2].pb(t1);
	}
	fr(i,1,n+1)
		vis[i] = 0;
	bfs(u);
	fr(i,1,n+1)
		vis[i] = 0;
	bfs(v);
	fr(i,1,n+1)
		vis[i] = 0;
	dfs(v);
	cout << mx - 1;
}


Measured memory_bytes: 10752
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n>>m;
    cout<<n*m<<endl;
    return 0;
}



Measured memory_bytes: 3644
#include<iostream>

using namespace std;

const int MAX_N = 100000;

int N, M;
int Set[MAX_N+1]; 

int start;
int endo;


int main() {
    cin >> N >> M;
    for(int i = 1; i < N+1; i++) {
        Set[i] = 1;
    }
    start = 0;
    endo = N+1;
    for(int i = 0; i < M; i++) {
        int tmp_l, tmp_r;
        cin >> tmp_l >> tmp_r;
        if (start <= tmp_l) {
            for(int j = 1; j < tmp_l; j++) {
                Set[j] = 0;
            }
            start = tmp_l;
        }
        if (endo >= tmp_r) {
            for(int j = tmp_r+1; j < N+1; j++) {
                Set[j] = 0;
            }
            endo = tmp_r;
        }   
    }
    int ans = 0;
    for(int i = 1; i < N+1; i++) {
        if(Set[i] == 1) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
function read_a_line(Type)
  map(x->parse(Type, x), split(readline()))
end

N,M = read_a_line(Int)

shops = map(x->begin c = read_a_line(Int); (c[1], c[2]); end, 1:N)

sort!(shops)

res = 0

for (cost, amo) in shops
  bought = min(M, amo)
  res += cost*bought
  M -= bought
end

println(res)


Measured memory_bytes: 156420
#include<iostream>

using namespace std;

int main(void) {
    string S;
    cin >> S;

    int char1 = S[0];
    int char2 = -1;

    int cnt1 = 0;
    int cnt2 = 0;

    bool flag = true;

    for (int i = 1; i < S.size(); i++) {
        if (char2 == -1 && char1 != S[i]) {
            char2 = S[i];
        }
        else if (char1 == S[i]) {
            cnt1++;
        }
        else if (char2 == S[i]) {
            cnt2++;
        }
        else {
            flag = false;
        }
    }

    if (flag && cnt1 != cnt2) {
        flag = false;
    }

    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int k;
typedef long long ll;
ll n;
const ll mod=1e9+7,sz=2<<17;
int l[sz],r[sz];
ll dp[101][sz];
main()
{
    cin>>n>>k;
    int id=0;
    for(int i=1;i*i<=n;i++)l[id]=r[id]=i,id++;
    int T=l[id-1];
    if(T*T==n)T--;
    for(;T>=1;T--)
    {
        l[id]=r[id-1]+1;
        r[id++]=n/T;
    }
    for(int i=0;i<id;i++)dp[0][i]=r[i]-l[i]+1;
    for(int i=0;i<k-1;i++)
    {
        for(int j=1;j<id;j++)dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
        for(int j=0;j<id;j++)dp[i+1][j]=(dp[i+1][j]+dp[i][id-j-1]*(r[j]-l[j]+1)%mod)%mod;
    }

    ll ans=0;
    for(int j=0;j<id;j++)ans=(ans+dp[k-1][j])%mod;
    cout<<ans<<endl;
}

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

int main(){
    string S;
    cin >> S;
    long long ans = 0;
    int bits = S.length() - 1;
    for(int i=0;i<(1 << bits);i++){
        int left = 0;
        for(int b=0;b<bits;b++){
            if(i & (1 << b)){
                ans += stoll(S.substr(left, b-left+1));
                left = b+1;
            }
        }
        ans += stoll(S.substr(left, bits-left+1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int i = 0; i <= K; i ++) {
    for (int j = 0; j <= K; j ++) {
      int s = S - i - j;
      if (0 <= s && s <= K) ans ++;
    }
  }
  cout << ans << endl;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	int n,a,b;
	int sum=0;
	std::cin >> n >> a >> b;
	for ( int i = 1 ; i < n+1 ; i++ ) {
		int ans=0;
		std::string num = std::to_string(i);
		for ( char c : num ) {
			ans += c - '0';
		}
		if (a<=ans && ans<=b) sum += i;
	}
	std::cout << sum << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	//Scanner scanner = new Scanner("3 5 4 2 0 0 8 8");
		Scanner scanner = new Scanner(System.in);
		int a;
		int b;
		while(true){
			a = scanner.nextInt();
			b = scanner.nextInt();
			if(a == 0 && b == 0){
				break;
			}else if(a > b){
				System.out.println(b + " " + a);
			}else{
				System.out.println(a + " " + b);
			}
		}
	}	
}

Measured memory_bytes: 33612
n=int(input())
a=list(map(int,input().split()))

cnt1=0
cnt2=0
cnt4=0

for i in a:
  if i%2==1:
    cnt1+=1
  elif i%4==0:
    cnt4+=1
  elif i%2==0:
    cnt2+=1

if cnt2!=0:
  if cnt4>=cnt1:
    print('Yes')
  else:
    print('No')
else:
  if cnt4+1>=cnt1:
    print('Yes')
  else:
    print('No')

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

using namespace std;

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


int main() {
	int K;
	int sum = 0;
	cin >> K;
	for (int i = 1; i < K+1; i++) {
		for (int j = 1; j < K+1; j++) {
			for (int k = 1; k < K+1; k++) {
				sum = sum + gcd(gcd(i, j), k);
			}
		}
	}
	cout << sum << endl;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = reader.readLine().split(" ");
        double result = Double.parseDouble(input[0]) / Integer.parseInt(input[1]);
        System.out.println(result);
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

using namespace std;

int main()
{
  int n;
  cin>>n;
  long a[300000];
  for(int i=0;i<3*n;i++){
    cin>>a[i];
  }
  sort(a,a+3*n,greater<int>());

  long ans=0;
  int b=1;
  for(int i=0;i<n;i++){
    ans+=a[b];
    b+=2;
  }
  cout<<ans<<endl;
  return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int abs(int n, int m){
    if(n-m<0) return -(n-m);
    else return n-m;
}

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    bool res = true;
    if(abs(a,b) > k) res = false;
    if(abs(a,c) > k) res = false;
    if(abs(a,d) > k) res = false;
    if(abs(a,e) > k) res = false;
    if(abs(b,c) > k) res = false;
    if(abs(b,d) > k) res = false;
    if(abs(b,e) > k) res = false;
    if(abs(c,d) > k) res = false;
    if(abs(c,e) > k) res = false;
    if(abs(d,e) > k) res = false;

    if(res) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

N = max(X,Y)
ans = 10**10

for i in range(2*N+1):
    price = C * i + A * max(0,X-i//2) + B * max(0,Y-i//2)
    ans = min(ans,price)

print(ans)

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	count := 0
	for i := a; i <= b; i++ {
		if c%i == 0 {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG
#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++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n;
  cin >> n;
  vivi a(10);
  rep(i,n){
    rep(j,10){
      int p;
      cin >> p;
      if(p) a[j].push_back(i);
    }
  }
  vivi p(n,vi(11));
  rep(i,n){
    rep(j,11){
      cin >> p[i][j];
    }
  }
  int ans = -inf;
  for(int tmp = 1;tmp < (1<<10);tmp++){
    vi cnt(n,0);
    int kamo = 0;
    rep(i,10){
      if(tmp & (1<<i)){
        for(auto s:a[i]){
          cnt[s]+=1;
        }
      }
    }
    rep(i,n){
      kamo += p[i][cnt[i]];
    }
    ans = max(ans,kamo);
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
// Last modify : 2019年01月23日 星期三 23时04分32秒
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int main()
{
    int n, x;
    while (cin >> n)
    {
        set<int> S;
        for (int i = 0; i < n; i++) 
        {
            cin >> x;
            S.insert(x);
        }
        cout << S.size() << endl;
    }
    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100007;
int n, m, v, p, a[N];

bool ok(int x) {
    int sc = a[x] + m;
    if(sc < a[p-1]) return false;

    int votes = m*v;
    int mv = (p-1)*m + (n-x)*m;
    for(int i = p-1; i < x; ++i) {
        mv += min(m, sc-a[i]);
    }

    return mv >= votes;
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> v >> p;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a+n, greater<int>());

    int l = p-1, r = n;
    while(r-l > 1) {
        int mid = l + (r-l)/2;
        if(ok(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }

    cout << l+1 << endl;
    
    return 0;
}


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

using namespace std;

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

bool isleap(int y) {
	return y % 4 == 0 ? (y % 100 == 0 ? (y % 400 == 0 ? true : false) : true) : false;
}

int daycount(int y, int m, int d) {
	int res = 0;
	int ny = 1, nm = 1;
	
	while (true) {
		if (ny == y && nm == m) {
			res += d;
			break;
		}
		
		int plus = 31;
		if (nm == 2 || nm == 4 || nm == 6 || nm == 9 || nm == 11) plus--;
		if (nm == 2) {
			plus--;
			if (!isleap(ny)) plus--;
		}
		
		res += plus;
		
		if (++nm == 13) {
			ny++;
			nm = 1;
		}
	}
	return res;
}

int main() {
	int y1, m1, d1, y2, m2, d2;
	while (true) {
		cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
		if (y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0) break;
		
		cout << daycount(y2, m2, d2) - daycount(y1, m1, d1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<ll> A[1001];
	int q,n;
	cin >> n >> q;
	while(q--){
		int x,y,z;
		cin >> x >> y;
		if(x==0)cin>>z;
		if(x==0){
			A[y].push_back(z);
		}else if(x==1){
			for(int i=0;i<A[y].size();i++){
				cout << A[y][i];
				if(i!=A[y].size()-1)cout << " ";
			}
			cout << endl;
		}else{
			A[y].clear();
		}
	}
}


Measured memory_bytes: 8836
#include<iostream>
#include<vector>
#include<string.h>

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0) break;
		
		char vote[100];
		for(int i = 0;i < n;i++){
			cin >> vote[i];
		}
		
		int cand[26];
		memset(cand,0,sizeof(cand));
		char sc;
		int sn = 0;
		int vmax = 0;
		int maxn = 0;
		for(int i = 0;i < n;i++){
			cand[vote[i]-'A']++;
			if(cand[vote[i] - 'A'] > vmax){
				vmax = cand[vote[i] - 'A'];
				maxn = vote[i] - 'A';
			}
			bool win = true;
			int rem = n - 1 - i;
			if(rem > 0){
				for(int j = 0;j < 26;j++){
					if(j != maxn){
						if(cand[j] + rem >= vmax){
							win = false;
							break;
						}
					}
				}
				if(win == true){
					sc = 'A' + maxn;
					sn = i+1;
					break;
				}
			}else{
				bool tie = false;
				for(int j = 0;j < 26;j++){
					if(j != maxn){
						if(cand[j] == vmax){
							tie = true;
							break;
						}
					}
				}
				if(tie == false){
					sc = 'A' + maxn;
					sn = n;
				}
			}
		}
		if(sn == 0){
			cout << "TIE" << endl;
		}else{
			cout << sc << " " << sn << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3080
//by xiqiao
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<=1000000;i++){
		if(a%2==1 || b%2==1 || c%2==1){
			printf("%d\n",i);return 0;
		}
		int x=a/2,y=b/2,z=c/2;
		a=y+z;b=x+z;c=x+y;
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define REP(i,a,b) for(int i=a;i<b;i++)
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f first
#define s second
#define INF 0x3f3f3f3f3f3f3f3f
#define point complex <double> 
#define pi acos(-1)
#define mod 1000000007

const int N = 1e5 + 5;

using namespace std;
int arr[N];
ll dp[N];

int main() {

	HS
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	memset(dp, INF, sizeof(dp));
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(arr[i - 1] - arr[i]), dp[i - 2] + abs(arr[i - 2] - arr[i]));
	}

	cout << dp[n - 1];

	return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 1e5 + 10;

int A[N], B[N], n;
int fa[N];

int find(int x){
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

void Union(int u, int v){
	u = find(u), v = find(v);
	if(u ^ v) fa[u] = v;
}

map<int, int> M;
map<int, queue<int> > T;

int main(){
	
	scanf("%d", &n);

	int S = 0;
	For(i, 1, n) scanf("%d", &A[i]), S ^= A[i];
	For(i, 1, n) scanf("%d", &B[i]);
	
	int x = 0;
	For(i, 1, n) if(A[i] != B[i]) A[++x] = A[i], B[x] = B[i];
	n = x;

	For(i, 1, n) fa[i] = i, M[A[i]]++;

	int pos = 0;
	For(i, 1, n) if(!M[B[i]]){
		if(pos || B[i] != S){
			puts("-1");
			return 0;
		}
		pos = i;
	}
	else --M[B[i]];

	int ans = n;
	For(i, 1, n) if(B[i] == S){
		--ans;
		break;
	}

	For(i, 1, n){
		auto &q = T[A[i]];
		if(!q.empty()) Union(i, q.front());
		q.push(i);
	}
	For(i, 1, n){
		auto &q = T[B[i]];
		if(!q.empty()) Union(i, q.front()), q.pop();
	}

	For(i, 1, n) if(fa[i] == i) ++ans;
	printf("%d\n", ans);

	return 0;
}

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

int main () {
  long long N, M, K, a, b, ans = 0;
  cin >> N >> M >> K;
  vector<long long> A(N+1,0), B(M+1,0);
  for (long long i = 0; i < N; i++) {
    cin >> a;
    A[i+1] = A[i] + a;
  }
  for (long long i = 0; i < M; i++) {
    cin >> b;
    B[i+1] = B[i] + b;
  }
  long long j;
  for (long long i = 0; i <= N; i++) {
    if (A[i] > K) break;
    j = upper_bound(B.begin(), B.end(), K-A[i]) - B.begin() - 1;
    j = max(0LL,min(j,M));
    ans = max(ans, i+j);
    
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 6408
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  vi A(3);
  rep(i, 3) cin >> A[i];
  sort(all(A));
  int ans = A[2] - A[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php

while (true) {
    fscanf(STDIN, '%d %d', $H, $W);
    if (!($H || $W)) { break; }

    $rects[] = draw($H, $W);
}

echo implode(PHP_EOL, $rects), PHP_EOL;

function draw($H, $W)
{
    $const = 300;
    $line  = str_repeat('#.', ($const / 2) + 1);

    for ($i = 0; $i < $H; $i++) {
        $first = ($i % 2 == 0) ? (0) : (1);
        $cols[] = sprintf('%s%s', substr($line, $first, $W), PHP_EOL);
    }
    return implode('', $cols);
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

bool check = 0;
bool boo = 0;
int maxx = 0;
long long ans = 0;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．

// vector
// sum: accumulate(ALl(x),0)
int main()
{
    INIT;
    int N, K, M, L;
    cin >> N >> K;
    vi v(N);

    rep(i, K)
    {
        cin >> M;
        rep(j, M)
        {
            cin >> L;
            v[L - 1]++;
        }
    }
    for (auto &i : v)
        i = !i;
    cout << accumulate(ALL(v), 0) << endl;
    return 0;
}


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

int main()
{
	map<string,vector<int> > dict;
	string str;
	int page;
	while(cin >> str >> page)
		dict[str].push_back(page);
	for(map< string,vector<int> >::iterator it = dict.begin();it!=dict.end();it++){
		sort(it->second.begin(),it->second.end());
		cout << it->first << endl;
		for(unsigned i=0;i<it->second.size();i++){
			cout << it->second[i];
			if(i<it->second.size()-1)
				cout << " ";
			else
				cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
const ull mod=(ull)212370440130137957ll;
const ull base=131;
char s[200001];
ull a[200001];
ull has(char *s){
    ull ans=0;
    for (int i=0;s[i]!='\0';i++)
        ans=(ans*base+(ull)s[i])%mod;
    return ans;
}
int main(){
    int n;
    scanf("%d",&n);
    int ans=1;
    for (int i=1;i<=n;i++){
        char s[100001]={0};
        scanf("%s",s),a[i]=has(s);
    }sort(a+1,a+n+1);
    for (int i=2;i<=n;i++)
        if(a[i]-a[i-1])ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3396
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/
bool check(ll a[],ll k,ll n)
{
    vector<ll> v;
    v.pb(0);
    f(i,n)
    {
        if(a[i]==v.back()+1) v.pb(a[i]);
    }

    if(v.size()<k+1) return 0;

    f(i,k+1) if(v[i]!=i) return 0;
    return 1;
}
void solve()
{
    ll n;
    cin>>n;

    ll a[n];
    f(i,n) cin>>a[i];

    ll lo=1,hi=n,ans=-1;

    while(lo<=hi)
    {
        ll mid=(lo+hi)/2;
        if(check(a,mid,n))
        {
            ans=max(ans,mid);
            lo=mid+1;
        }
        else hi=mid-1;
    }
    if(ans==-1) ans=n+1;
    cout<<n-ans<<"\n";

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
ll mod[2] = {1000000007, 998244353};
ll base[2] = {532345034, 783920481};
//ll base[2] = {2, 3};
ll N;
string S;
ll pos[260000];
ll rh[260000][2];
map<l_l, ll> mp;

ll beki(ll a, ll b, ll mod) {
    if(b == 0) return 1;
    if(b < 0) {
        ll INV = beki(a, -b, mod);
        return beki(INV, mod - 2, mod);
    }
    ll ret = beki(a, b / 2, mod);
    ret = ret * ret % mod;
    if(b % 2 == 1) {
        ret = ret * a % mod;
    }
    return ret;
}

int main() {
    //cout.precision(10);
    cin >> N;
    cin >> S;
    S = "#" + S;
    for(int index = 0; index <= 1; index++) {
        for(int i = 1; i <= N; i++) {
            pos[i] = pos[i - 1];
            rh[i][index] = rh[i - 1][index];
            if(S[i] == '<') {
                pos[i]--;
            }
            if(S[i] == '>') {
                pos[i]++;
            }
            if(S[i] == '+') {
                rh[i][index] = (rh[i][index] + beki(base[index], pos[i], mod[index])) % mod[index];
            }
            if(S[i] == '-') {
                rh[i][index] = (mod[index] + rh[i][index] - beki(base[index], pos[i], mod[index])) % mod[index];
            }
            //cerr << i << " " << pos[i] << " " << rh[i][index] << endl;
        }
    }
    for(int i = 0; i <= N; i++) {
        //cerr << i << " " << rh[i][0] << " " << rh[i][1] << endl;
    }
    ll ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        ll HASH[2];
        for(int j = 0; j <= 1; j++) {
            //HASH[j] = (rh[N][j] - rh[i + 1][j] + mod[j]) % mod[j];
            HASH[j] = rh[i + 1][j];
        }
        mp[{HASH[0], HASH[1]}]++;
        //cerr << "ADDED " << HASH[0] << " " << HASH[1] << endl;
        for(int j = 0; j <= 1; j++) {
            HASH[j] = rh[i][j] + beki(base[j], pos[i], mod[j]) * rh[N][j];
            HASH[j] %= mod[j];
            //HASH[j] = (mod[j] - HASH[j]) % mod[j];
        }
        //cerr << "SEARCHING " << HASH[0] << " " << HASH[1] << endl;
        ans += mp[{HASH[0], HASH[1]}];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 37772
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int N,x;
  cin >> N >> x;
  long long int a[N];
  for (int i=0;i<N;i++)cin >> a[i];
  sort (a,a+N);
  int j=0,count=0;
  while (a[j]<=x){
  	x-=a[j];
    count++;
    j++;
    if(j==N){
      if (x!=0) count--;
      break;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		if (A % 2 == 0 || B % 2 == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions

def main():
    x,y = map(int, input().split())

    for i in range(x+1):
        leg = 2*i + 4*(x-i)
        if y == leg:
            print('Yes')
            return
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 72664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#define REP(i, n) for (int i = 0; i < (n); i++) 

using namespace std;

using ll = long long;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<class T> using maxheap = priority_queue<T, vector<T>, less<T>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int Q;
  cin >> Q;
  maxheap<ll> L;
  minheap<ll> R;
  ll ans = 0;
  while (Q--) {
    int type;
    cin >> type;
    if (type == 1) {
      ll a, b;
      cin >> a >> b;
      ans += b;
      L.push(a);
      R.push(a);
      if (L.top() > R.top()) {
        ll l = L.top(); L.pop();
        ll r = R.top(); R.pop();
        ans += l - r;
        L.push(r);
        R.push(l);
      }
    } else {
      cout << L.top() << ' ' << ans << '\n';
    }
  }
}


Measured memory_bytes: 4588
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		int N = scan.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;i++) {
			H.add(scan.nextInt());
		}
		scan.close();

		int min = 100;
		int result = 0;

		for(int i=-100;i<=101;i++) {
			if(!H.contains(i)) {
				int tmp2 = X-i;
				if(tmp2<0) {
					tmp2 = i-X;
				}
				if(tmp2<min) {
					min = tmp2;
					result = i;
				}
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 36176
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        long[] s = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Console.WriteLine(solve(s[0], s[1]));
    }
    static long solve(long n, long m) {
        long count = 0;
        if(n==1 && m==1) count = 1;
        else if(n == 1 || m == 1) count = n * m - 2;
        else count = n*m - (2*(m+n)-4);
        return count;
    }
}

Measured memory_bytes: 13396
K, N = map(int, input().split())
A = list(map(int, input().split()));

max_len = 0

for i in range(N):
    l = A[i] - A[i-1]
    if l < 0:
        l += K
    if(max_len < l):
        max_len = l

print(K - max_len)

Measured memory_bytes: 25804
import math

def equals(a, b):
    return abs(a - b) < 1e-10


class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)

    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)

    def __mul__(self, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

    def __truediv__(self, a):
        return Point(self.x / a, self.y / a)

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def dot(a, b):
    return a.x * b.x + a.y * b.y


def cross(a, b):
    return a.x * b.y - a.y * b.x


def project(s, p):
    base = s.p2 - s.p1
    r = dot(p - s.p1, base) / base.norm()
    return s.p1 + base * r


def reflect(s, p):
    return p + (project(s, p) - p) * 2


if __name__ == '__main__':
    x1, y1, x2, y2 = [int(v) for v in input().split()]
    s = Segment(Point(x1, y1), Point(x2, y2))
    q = int(input())
    ans = []
    for i in range(q):
        x, y = [int(v) for v in input().split()]
        p = Point(x, y)
        ans.append(reflect(s, p))

    for v in ans:
        print('{0:.10f} {1:.10f}'.format(v.x, v.y))


Measured memory_bytes: 6016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc158/tasks/abc158_b
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long n = inputLongArray[0];
            long a = inputLongArray[1];
            long b = inputLongArray[2];
            long ans = (n / (a + b)) * a;
            long amari = n % (a + b);
            ans += Math.Min(amari, a);


            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int INF = 1e9;
const int MAX_K = 1<<10;

struct P{
    int v,w;
    P(){}
    P(int v, int w):v(v),w(w){}
};
bool operator<(const P &a, const P &b){return a.w<b.w;}
P operator+(const P &a, const P &b){return {a.v+b.v,a.w+b.w};}
ostream &operator<<(ostream &os, const P &a){
    return os<<"("<<a.w<<","<<a.v<<")";
}

vector<P> S[MAX_K];

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vector<P> nodes(N);
    rep(i,N){
        int v,w; cin>>v>>w;
        nodes[i] = P(v,w);
    }
    S[0].pb(P(0,0));
    int K = min(MAX_K,N+1);
    FOR(i,1,K-1){
        int p = i/2;
        for(P e:S[p]){
            S[i].pb(e);
            S[i].pb(e+nodes[i-1]);
        }
        sort(all(S[i]));
        int M = S[i].size();
        int m=1;
        FOR(j,1,M-1){
            if (S[i][m-1].v < S[i][j].v){
                S[i][m++] = S[i][j];
            }
        }
        S[i].erase(S[i].begin()+m, S[i].end());
    }
    // for(P e:nodes){
    //     cout<<e<<" ";
    // }cout<<endl;
    // rep(v,K){
    //     for(P e:S[v]){
    //         cout<<e<<" ";
    //     }cout<<endl;
    // }

    int Q; cin>>Q;
    while(Q--){
        int v,L; cin>>v>>L;
        vector<P> ps;
        ps.pb(P(0,0));
        while(v>=K){
            int M = ps.size();
            rep(i,M){
                ps.pb(ps[i]+nodes[v-1]);
            }
            v>>=1;
        }
        int ans=0;
        for(P e:ps){
            if (L<e.w) continue;
            auto itr = upper_bound(all(S[v]), P(0,L-e.w)); itr--;
            chmax(ans,e.v+itr->v);
        }
        cout<<ans<<"\n";
    }
    return 0;
}


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

int main () {
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  rep(i, m) cin >> x[i];
  sort(x.begin(), x.end());

  vector<int> d(m - 1);
  rep(i, m - 1) d[i] = abs(x[i] - x[i + 1]);
  sort(d.begin(), d.end(), greater<int>());

  int ans = 0;
  for (int i = n - 1; i < m - 1; i++) ans += d[i];

  cout << ans << endl;

}
  


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

using namespace std;

int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	if(C <= B && A <= C)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 12;
int c[N];
int a[N][N];

int main() {
  int n, m, X;
  cin >> n >> m >> X;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  vector<int> cnt(m);
  int ret = INF;
  for (int k = 1; k < (1 << n); ++k) {
    fill(cnt.begin(), cnt.end(), 0);
    int cur = 0;
    for (int i = 0; i < n; ++i) {
      if (k & (1 << i)) {
        cur += c[i];
        for (int j = 0; j < m; ++j) {
          cnt[j] += a[i][j];
        }
      }
    }
    bool found = false;
    for (int j = 0; j < m; ++j) {
      if (cnt[j] < X) found = true;
    }
    if (!found) ret = min(ret, cur);
  }
  if (ret == INF) ret = -1;
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 1000000007 
#define MAX 100005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
typedef long long int ll;
using namespace __gnu_pbds;
using namespace std;
//using namespace boost::multiprecision;

#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>

ll fact[MAX],inv_fact[MAX];

ll modular_expo(ll x,ll n)
{
	ll ans = 1;
	while(n)
	{
		if(n&1)
		ans = (ans * x)%MOD;
		x = (x*x)%MOD;
		n = n>>1;
	}
	return ans%MOD;
}

void fun()
{
	fact[0] = 1;
	for(ll i=1;i<MAX;i++)
	fact[i] = (fact[i-1] * i)%MOD;
	inv_fact[MAX-1] = modular_expo(fact[MAX-1],MOD-2);
	for(ll i=MAX-2;i>=0;i--)
	inv_fact[i] = (inv_fact[i+1] * (i+1))%MOD;
}


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

//fun();

ll t=1;
//cin>>t;

while(t--)
{
	long double b;
	ll a;
	cin>>a>>b;
	
	cout<<(ll)(a*b*100)/100<<"\n";
}



return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if(a*n >= b){
        cout << b << endl;
    }
    else{
        cout << n*a << endl;
    }
}

Measured memory_bytes: 3604
#!/usr/bin/env python3

from sys import stdin


def main():
    N, M = map(int, stdin.readline().split())
    A = list(map(int, stdin.readline().split()))

    sum_a = sum(A)
    if sum_a <= N:
        print(N - sum_a)
    else:
        print('-1')


if __name__ == "__main__":
    main()


Measured memory_bytes: 10056
# wrong answer...
# 正解はこちら　https://img.atcoder.jp/diverta2019/editorial.pdf

import math
N = int(input())
l = []
for i in range(N):
   l.append(input())

default = sum([i.count('AB') for i in l])

#only末尾Aの数
a = sum([i[-1]=='A' and i[0]!='B' for i in l])
#only先頭Bの数
b = sum([i[0]=='B' and i[-1]!='A' for i in l])
#先頭Bかつ末尾Aの数
ab = sum([i[0]=='B' and i[-1]=='A' for i in l])

num = 0
if ab == 0:
    num = min(a, b)
elif a + b > 0: # a, bの少なくとも一方は0出ない場合
    num = min(a, b) + ab
else:
    num = ab -1

print(num + default)


Measured memory_bytes: 3700
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n = 3, k;
    cin >> k;
    vi c(k + 1);
    ll ans = 0;
    for (int i = 1; i <= k; i++)
    {
        c[i] = inq(k / i, n);
    }
    for (int i = k; i >= 1; i--)
    {
        for (int j = i + i; j <= k; j += i)
        {
            c[i] = (c[i] - c[j] + MOD) % MOD;
        }
    }
    for (int i = 1; i <= k; i++) ans = (ans + c[i] * i) % MOD;
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 3608