akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.range;
class State
{
    public:
    bool[] xx;
    int[] yy;
    bool[] zz;
    bool[] ww;
    Chunks!(dchar[]) board;
}
bool ad(State state, int y)
{
    if (y == 8)
    {
        for (y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                if (state.board[x][y] == 'Q')
                {
                    if (state.yy[x] != y)
                        return false;
                }
            }
        }
        return true;
    }
   for (int x = 0; x < 8; x++)
   {
       if (state.xx[x] || state.zz[x + y] || state.ww[y - x + 8 - 1])
           continue;
       state.yy[y] = x;
       state.xx[x] = true;
       state.zz[x + y] = true;
       state.ww[y - x + 8 - 1] = true;
       
       if (ad(state, y + 1))
       {
           return true;
       }
       state.ww[y - x + 8 - 1] = !true;
       state.zz[x + y] = !true;
       state.xx[x] = !true;
       state.yy[y] = 0;
   }
   return false;
}
void main()
{
    auto b = new dchar[8 * 8];
    b.fill(' ');
    State state = new State();
    state.xx = new bool[8];
    state.yy = new int[8];
    state.zz = new bool[8 * 2];
    state.ww = new bool[8 * 2];
    state.board = b.chunks(8);;
    foreach (i; iota(readln().strip.to!int))
    {
        int x, y;
        scanf("%d %d", &x, &y);
        state.board[x][y] = 'Q';
    }

    ad(state, 0);
    for (int y = 0; y < 8; y++)
    {
        for (int x = 0; x < 8; x++)
        {
            if (state.xx[x] && state.yy[y] == x)
                write('Q');
            else
                write('.');
        }
        writeln();
    }
}


Measured memory_bytes: 2488
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  long long n,m;
  cin >> n >> m;
  long long p=1000000007;
  long long h=0,w=0;
  long long u;
  cin >> u;
  rep(i,n-1){
    long long y;
    cin >> y;
    h=(h+(y-u)*(i+1)*(n-1-i))%p;
    u=y;
  }
  long long l;
  cin >> l;
  rep(i,m-1){
    long long y;
    cin >> y;
    w=(w+(y-l)*(i+1)*(m-1-i))%p;
    l=y;
  }
  cout << h*w%p << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int yoko,tate;
int x,y;

main(){
while(1){
	
  scanf("%d%d",&tate,&yoko);
  for(x=1;tate>=x;x++){
   for(y=1;yoko>=y;y++){
   printf("#");
   if(yoko==y){printf("\n");}
   if(yoko==y&&tate==x){printf("\n");}
   }
  }
  if(yoko==0&&tate==0){
  return 0;}
}  
}  
  

Measured memory_bytes: 572
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long int n,s=0;
    cin>>n;
    for(int i=1,g; i<=n; i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                g=__gcd(j,k);
                s=__gcd(g,i)+s;
            }
        }
    }
    cout<<s;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;
ll mul(ll x,ll y){
    return (1ll* (x%mod1)*(y%mod1));
}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
//ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    //freopen("error.txt" , "w" , stderr) ;
    #endif
    string s,t;
    cin>>s>>t;
    ll n = s.size();
    ll m = t.size();
    fo(i,n){
    	if(s[i]!=t[i]){
    		cout<<"No"<<endl;
    		return 0;
    	}
    }
    if(m == n+1){
    	cout<<"Yes"<<endl;
    }
    

    


}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[2]*10+a[1] +a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <iomanip>

const double kEpsilon = 1e-10;
inline bool equals(double a, double b)
{
    return fabs(a - b) < kEpsilon;
}

class Point
{
  public:
    double x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y)
    {
    }

    Point operator+(const Point &p)
    {
        return Point(x + p.x, y + p.y);
    }
    Point operator-(const Point &p)
    {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(const double k)
    {
        return Point(x * k, y * k);
    }

    double SquaredNorm()
    {
        return x * x + y * y;
    }
    double abs()
    {
        return sqrt(this->SquaredNorm());
    }

    bool operator<(const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator==(const Point &p) const
    {
        return fabs(x - p.x) < kEpsilon && fabs(y - p.y) < kEpsilon;
    }

    double dot(const Point &p) const
    {
        return x * p.x + y * p.y;
    }
    double cross(const Point &p) const
    {
        return x * p.y - y * p.x;
    }
};

Point projection(Point &p1, Point &p2, Point &p)
{
    auto q = p2 - p1;
    auto a = q.dot(p - p1) / q.SquaredNorm();
    return p1 + q * a;
}

int main()
{

    Point p1, p2, p, r;

    std::cin >> p1.x >> p1.y >> p2.x >> p2.y;

    int n;
    std::cin >> n;

    for (size_t i = 0; i < n; ++i)
    {
        std::cin >> p.x >> p.y;
        r = projection(p1, p2, p);
        std::cout << std::setprecision(20);
        std::cout << r.x << " " << r.y << std::endl;
    }
}



Measured memory_bytes: 3292
#include <stdio.h>

int main(void){
  float taiju;

  while(1){

    scanf("%f",&taiju);
    if(feof(stdin)){
      break;
    }
    else if(taiju<=48.00){
      printf("light fly\n");
    }
    else if(48.00<taiju&&taiju<=51.00){
      printf("fly\n");
    }
    else if(51.00<taiju&&taiju<=54.00){
      printf("bantam\n");
    }
    else if(54.00<taiju&&taiju<=57.00){
      printf("feather\n");
    }
    else if(57.00<taiju&&taiju<=60.00){
      printf("light\n");
    }
    else if(60.00<taiju&&taiju<=64.00){
      printf("light welter\n");
    }
    else if(64.00<taiju&&taiju<=69.00){
      printf("welter\n");
    }
    else if(69.00<taiju&&taiju<=75.00){
      printf("light middle\n");
    }
    else if(75.00<taiju&&taiju<=81.00){
      printf("middle\n");
    }
    else if(81.00<taiju&&taiju<=91.00){
      printf("light heavy\n");
    }
    else{
      printf("heavy\n");
    }
  }

  return(0);
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+100,Base=1e4;
bool mark[N];
int n,x;
int main()
{
	scanf("%d%d",&x,&n);
	for (int i=1;i<=n;i++)
	{
		int now;
		scanf("%d",&now);
		mark[Base+now]=1;
	}
	if (!mark[Base+x])
	{
		printf("%d\n",x);
		return 0;
	}
	int st=Base+x,one;
	for (int i=st;i<=st+1000;i++)
	if (!mark[i])
	{
		one=i;
		break;
	}
	for (int i=st;i>=st-1000;i--)
	if (!mark[i])
	{
		if (abs(i-st)<=abs(st-one))
		{
			printf("%d\n",i-Base);
			return 0;
		}
		else printf("%d\n",one-Base);
		break;
	}
	return 0;
}

Measured memory_bytes: 3828
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,i,j,f[105][105];
char s[105][105];
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%s",s[i]+1);
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			f[i][j]=1<<30;
	f[1][1]=(s[1][1]=='#');
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
		{
			f[i][j+1]=min(f[i][j+1],f[i][j]+(s[i][j+1]=='#'&&s[i][j]=='.'));
			f[i+1][j]=min(f[i+1][j],f[i][j]+(s[i+1][j]=='#'&&s[i][j]=='.'));
		}
	printf("%d",f[n][m]);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

	int n;
	char p;
	int x;
	int c=0;
	bool f=true;

	cin>>n;

	for(int i=0;i<n;i++){
		cin>>p>>x;
		if(p=='(') c+=x;
		else c-=x;
		if(c<0){
			f=false;
		}
	}

	if(f&&c==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  string s, t;
  cin >> n >> s >> t;
  REP(i, 0, n + 1) {
    string q = s + t.substr(n - i);
    if (q.substr(q.length() - n, q.length()) == t) {
      cout << q.length() << endl;
      return 0;
    }
  }
  assert (0);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);

		int N = Integer.parseInt(in.readLine());

		System.out.println((N - 2) * 180);
	}

}


Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <utility>

int Partition( std::vector<std::pair<char, int>>& v, int p, int r ){
    int x = v[r].second;
    int i = p - 1;
    for( int j = p; j < r; ++j ){
        if( v[j].second <= x ){
            v[++i].swap( v[j] );
        }
    }
    v[i+1].swap( v[r] );
    return i + 1;
}

void QuickSort( std::vector<std::pair<char, int>>& v, int p, int r ){
    if( p < r ){
        int q = Partition( v, p, r );
        QuickSort( v, p, q-1 );
        QuickSort( v, q+1, r );
    }
}

constexpr int fIndex = -3;

int BinarySearch( std::vector<std::pair<char, int>>& v, int key ){
    int left = 0;
    int right = v.size();
    int mid;
    //std::cout << key << ": ";
    while( left < right ){
        mid = ( left + right ) / 2;
        if( v[mid].second == key ){
            //std::cout << key;
            return mid;
        }else if( key < v[mid].second ){
            right = mid;
        }else{
            left = mid + 1;
        }
        
        if( key == 1 ){
            //std::cout << v[mid] << " ";
        }
    }
    return fIndex;
}

// code below cause TLE
// std::string CheckStable( const std::vector<std::pair<char, int>>& initial, const std::vector<std::pair<char, int>>& sorted ){
//     int N = sorted.size();
//     int key;
//     for( int i = 0; i < N; ++i ){
//         if( sorted[i].second == sorted[i+1].second ){
//             key = sorted[i].second;
//             for( j = i+1; sorted[j] == key; ++j ){
//                 if( initial[i] )
//             }
//         }
//     }
//     return "Stable";
// }

std::string CheckStable( std::vector<std::pair<char, int>>& initial, std::vector<std::pair<char, int>>& sorted ){
    int N = sorted.size();
    for( int i = 0; i < N; ++i ){
        for( int j = i+1; j < N; ++j ){
            if( initial[i].second == initial[j].second ){
                for( int a = 0/*BinarySearch( sorted, initial[i].second )*/; a < N; ++a ){
                    if( sorted[a].second == initial[i].second ){
                        for( int b = a+1; b < N; ++b ){
                            if( initial[i] == sorted[b] &&
                                initial[j] == sorted[a] ){
                                return "Not stable";
                            }
                        }
                    }
                }
            }
        }
    }
    return "Stable";
}

int main(){
    int n;
    std::cin.tie(0);
    std::cin >> n;

    std::vector<std::pair<char, int>> cards( n );
    int number;
    char symbol;
    for( auto& elem : cards ){
        std::cin >> symbol >> number;
        elem = std::make_pair( symbol, number );
    }

    std::vector<std::pair<char, int>> input( cards );

    QuickSort( cards, 0, cards.size()-1 );

    std::cout << CheckStable( input, cards ) << "\n";
    for( const auto& elem : cards ){
        std::cout << elem.first << " " << elem.second << "\n";
    }
}


Measured memory_bytes: 4308
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#include<set>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i32 n;
cin >> n;
vector<i32> a(n);
i32 aa = 0;
rep(i,n) {
    cin >> a[i];
    aa = max(aa,a[i]);
}
vector<bool> is_prime(aa + 1,true);
is_prime[0] = is_prime[1] = false;
vector<i32> rec(aa + 1,1e9);
for(i32 i = 2; i <= aa; i++){
    if(is_prime[i]){
        rec[i] = i;
        for(i32 j = 2 * i; j <= aa; j += i){
            is_prime[j] = false;
            if(rec[j] == 1e9)rec[j] = i;
        }
    }
}
vector<i32> judge(aa + 1);
vector<i32> A = a;
rep(i,n){
    set<i32> st;
    while(A[i] != 1){
        if(!st.count(rec[A[i]]))
        judge[rec[A[i]]]++;
        st.insert(rec[A[i]]);
        A[i] /= rec[A[i]];
    }
}
bool b = true;
for(i32 i = 2; i <= aa; i++){
    if(judge[i] >= 2)b = false;
}
i32 k = a[0];
rep(i,n)k = gcd(a[i],k);

if(b && k == 1){
    cout << "pairwise coprime" << endl;
}else if(!b && k == 1){
    cout << "setwise coprime" << endl;
}else{
    cout << "not coprime" << endl;
}
}

Measured memory_bytes: 34584
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	vector<int>A(9);
	IN(A);
	
	int N;
	cin >> N;
	set<int> B;
	for (int i = 0; i < N; ++i) {
		int b;
		cin >> b;
		B.insert(b);
	}
	//////////////
	for (int i = 0; i < 9; ++i) {
		if (B.find(A[i]) != B.end()) {
			A[i] = 0;
		}
	}
	vector<vector<int>> C = {
		{0,1,2},{3,4,5},{6,7,8},
		{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6} };
	for (int i = 0; i < C.size(); ++i) {
		bool flag = true;
		for (int k = 0; k < 3; ++k) {
			if (A[C[i][k]] !=0) {
				flag = false;
			}
		}
		if (flag == true) {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
if N<=5:
    print(N)
    exit()
dp = [float('INF')]*(N+1)
dp[0] = 0
num6,num9 = 6,9
d6d9 = set()
while num6<=N:
    d6d9.add(num6)
    num6 *= 6
while num9<=N:
    d6d9.add(num9)
    num9 *= 9
for i,x in itertools.product(range(N+1),d6d9):
    if i+x>=N+1:
        continue
    dp[i+1] = min(dp[i+1],dp[i]+1)
    dp[i+x] = min(dp[i+x],dp[i]+1)
print(dp[-1])


Measured memory_bytes: 7796
import sys
import numpy as np
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()],np.int64)
ans = 0
cnt = 0
minA = np.argmin(A)
leftA = A[:minA]
rightA = A[minA+1:]
x = len(leftA)
y = len(rightA)
for i in [x,y]:
    ans += i // (K-1)
    cnt += i % (K-1)
if cnt % (K-1) == 0:
    ans += cnt // (K-1)
else:
    ans += 1 + cnt // (K-1)
print(ans)

Measured memory_bytes: 23440
import java.util.*;
public class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    
	    int H=sc.nextInt();	    
	    int W=sc.nextInt();	    
	    int h=sc.nextInt();	    
	    int w=sc.nextInt();	   
	    
	    System.out.println((H-h)*(W-w));

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	k--;
	cout << a[k] << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
 
 
def main():
 
    n_haku = int(input())
    k_haku = int(input())
    x_yen = int(input())
    y_yen = int(input())
    
    if n_haku <= k_haku:
        ryokin = x_yen * n_haku
    else:
        ryokin = x_yen * k_haku + y_yen * (n_haku - k_haku)

    print(ryokin)    
    
    return 0
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
def get_sieve_of_eratosthenes_new(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

primelist=get_sieve_of_eratosthenes_new(10**5)
subprimelist=[(primelist[i]+1)//2 for i in range(0,len(primelist))]
primeset=set(primelist)
subprimeset=set(subprimelist)
real=list(primeset&subprimeset)
real=[2*real[i]-1 for i in range(0,len(real))]
real.sort()

Q=int(input())
l=[0]*Q
r=[0]*Q
for i in range(0,Q):
    l[i],r[i]=map(int,input().split())
for i in range(0,Q):
    if r[i]<3 or l[i]>99877:
        print(0)
    else:
        s=0
        t=0
        start=0
        end=len(real)-1
        while end-start>1:
            test=(end+start)//2
            if real[test]>=l[i]:
                end=test
            else:
                start=test
        if real[start]>=l[i]:
            s=start
        else:
            s=end
        start=0
        end=len(real)-1
        while end-start>1:
            test=(end+start)//2
            if r[i]>=real[test]:
                start=test
            else:
                end=test
        if r[i]>=real[end]:
            t=end
        else:
            t=start
        print(t-s+1)


Measured memory_bytes: 57392
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

const ll N=1e4+5;

ll mod=1e9+7;
ll mem[N][105][2],n;
int d;

string k;

ll dp(int pos,int m,bool flag)
{
    if (pos==n)
    {
        return (m==0);
    }
    if (mem[pos][m][flag]!=-1)return mem[pos][m][flag];
    ll ans=0;
    for (int i=0;i<=(flag?9:(k[pos]-'0'));i++)
    {
        ans+=dp(pos+1,(m+i)%d,flag|i<(k[pos]-'0'));
        ans%=mod;
    }
    ans%=mod;
    return mem[pos][m][flag]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin >> k >> d;
    n=k.length();
    ll ans=dp(0,0,0)-1;
    if (ans==-1)ans=mod-1;
    cout << ans << endl;
    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  string s = "No";
  if(a == b && a != c) s = "Yes";
  if(a == c && a != b) s = "Yes";
  if(c == b && a != c) s = "Yes";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int n,d;
int inds[114514];
vi a;
int main(){
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

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

    int n;
    cin >> n;

    vvi g(n, vi(n, INT_MAX));

    rep(i, 0, n) {
        rep(j, 0, n) {
            cin >> g[i][j];
            if (g[i][j] == -1) { g[i][j] = INT_MAX; }
        }
    }

    vector<bool> seen(n, false);
    vi d(n, INT_MAX);
    vi p(n, -1);

    d[0] = 0;

    while (true) {
        // Mimimum cost to connect T and V-T.
        int minv = INT_MAX;
        // A vertex in V-T, which has minimum cost.
        int u = -1;

        rep(i, 0, n) {
            if (!seen[i] && minv > d[i]) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) { break; }

        // Append u into T.
        seen[u] = true;

        // Calculate minimum distance between u and v in V-T.
        rep(v, 0, n) {
            if (!seen[v] && g[u][v] != INT_MAX) {
                if (d[v] > g[u][v]) {
                    d[v] = g[u][v];
                    p[v] = u;
                }
            }
        }
    }

    int sum = 0;
    rep(i, 0, n) {
        if (p[i] != -1) { sum += g[i][p[i]]; }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// 1 - indexed
template <typename T>
struct BIT
{
   vector<T> bit;

   BIT(int sz) : bit(sz + 1, 0) {}

   // sum of [1, k]
   T sum(int k)
   {
      T res = 0;
      for (int x = k; x > 0; x -= x & -x)
         res += bit[x];
      return res;
   }

   void add(int k, T w)
   {
      for (int x = k; x < bit.size(); x += x & -x)
         bit[x] += w;
   }

   // sum of [x, y)
   T getSum(int x, int y)
   {
      return sum(y - 1) - sum(x - 1);
   }

   // find an index i s.t. a[1] + a[2] + ⋯ + a[x] ≧ w
   T lower_bound(T w)
   {
      if (w <= 0)
         return 0;

      T x = 0;
      int p = 1, N = bit.size();

      while (2 * p <= N)
         p *= 2;

      for (T k = p; k > 0; k /= 2)
      {
         if (x + k <= N && bit[x + k] < w)
         {
            w -= bit[x + k];
            x += k;
         }
      }

      return x + 1;
   }
};

int main()
{

   int N, Q;
   cin >> N >> Q;
   vector<int> c(N + 1);
   for (int i = 0; i < N; i++)
   {
      cin >> c[i + 1];
   }

   vector<vector<pair<int, int>>> queries(N + 1, vector<pair<int, int>>());

   for (int i = 0; i < Q; i++)
   {
      int l, r;
      cin >> l >> r;
      queries[l].emplace_back(r, i);
   }

   for (int i = 1; i <= N; i++)
   {
      sort(queries[i].begin(), queries[i].end());
   }

   vector<priority_queue<int, vector<int>, greater<int>>> pos(N + 1);

   for (int i = 1; i <= N; i++)
   {
      pos[c[i]].push(i);
   }

   BIT<int> bit(N + 1);

   for (int i = 1; i <= N; i++)
   {
      if (pos[i].empty())
         continue;
      bit.add(pos[i].top(), 1);
      pos[i].pop();
   }

   vector<int> ans(Q);

   for (int l = 1; l <= N; l++)
   {
      for (auto q : queries[l])
      { // 左端がlのクエリ
         int R = q.first + 1, ind = q.second;
         ans[ind] = bit.getSum(l, R);
      }

      bit.add(l, -1);
      if (pos[c[l]].empty())
         continue;

      int nxt = pos[c[l]].top();
      pos[c[l]].pop();
      bit.add(nxt, 1);
   }

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

Measured memory_bytes: 62556
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

int main() {
    string s;
    cin >> s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
mod = 10**18 + 3

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(1341)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod

K = int(input())
seg = 2**7
OT = 'EESSTTIIVVAALL'

L = [0]*301
for i in range(300, -1, -1):
    ci = sum(comb(j+i, i)*2**j for j in range(8)) 
    L[i] = K//ci
    K %= ci
    

ans = 'F'*K + 'ESTIVAL'
for l in L:
    ans = l*'F' + OT + ans

print(ans)

Measured memory_bytes: 40688
# include <iostream>
# include <iomanip>

int main() {
	int a, b;
	int ans_i;
	double ans_d;
	std::cin >> a >> b;

	ans_i = a / b;
	ans_d = static_cast<double>(a) / static_cast<double>(b);
	std::cout << std::setprecision(14);
	std::cout << std::fixed;
	std::cout << ans_i << " " << a % b << " " << ans_d << std::endl;

	std::cin >> a;
	return 0;
}

Measured memory_bytes: 3276
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i= 0; i < n; i++) {
			a[i] =Integer.parseInt(sc.next());
		}
		Arrays.sort(a);
		int ans = a[n-1]-a[0];
		System.out.println(ans);
	}
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> d;
  for (auto e : a) {
    const auto i = upper_bound(d.begin(), d.end(), e, greater<int>()) - d.begin();
    if (i == d.size()) {
      d.push_back(e);
    } else {
      d[i] = e;
    }
  }
  cout << d.size() << endl;
  return 0;
}


Measured memory_bytes: 1276
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(n - k):
        print("YNeos"[1 - (A[i + k] > A[i])::2])
resolve()

Measured memory_bytes: 94056
h,w = map(int,input().split())
m = [[j for j in list(input())] for i in range(h)]
def check(i,j):

    if i+1 < h and m[i+1][j] == '#' or \
        i-1 >= 0 and m[i-1][j] == '#' or \
        j+1 < w and m[i][j+1] == '#' or \
        j - 1 >= 0 and m[i][j-1] == '#':
        return True
    return False

for i in range(h):
    for j in range(w):
        if m[i][j] == '.':
            continue
        if not check(i,j):
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
  int ax,bx;
  double a,b;
  cin >> a >> b;
  bool can=false;
  int ans=-1;
  for(int i=13;i<=1000;i++){
    ax=i*0.08;
    bx=i*0.1;
    if(bx==b && ax==a){
      can=true;
      ans=i;
      break;
    }
  }
  if(can) cout << ans << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[10];
        for(int i = 0; i < 10; i++){
            a[i] = sc.nextInt();
        }
        int top1 = 0;
        int top2 = 0;
        int top3 = 0;
        int num1 = 0;
        int num2 = 0;
        for(int i = 0; i < 10; i++){
            if(a[i] > top1){
                top1 = a[i];
                num1 = i;
            }
        }
        for(int i = 0; i < 10; i++){
            if(i == num1){
                continue;
            }else if(a[i] > top2){
                top2 = a[i];
                num2 = i;
            }
        }
        for(int i = 0; i < 10; i++){
            if(i == num1 || i == num2){
                continue;
            }else if(a[i] > top3){
                top3 = a[i];
            }
        }
        System.out.println(top1);
        System.out.println(top2);
        System.out.println(top3);
    }
}



Measured memory_bytes: 26028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
vector<int> vec[100010];
P d[100010];
bool bl[100010];

void dfs(int x, int y) {
	if (bl[x])return;
	bl[x] = true;
	d[x].first = 1;
	d[x].second = 1;
	for (int i = 0; i < vec[x].size(); i++) {
		int s = vec[x][i];
		if (s == y)continue;
		dfs(s, x);
		d[x].first *= d[s].second;
		d[x].second *= (d[s].first + d[s].second);
		d[x].first %= mod;
		d[x].second %= mod;
	}
}

signed main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	dfs(1, 0);
	cout << (d[1].first + d[1].second) % mod << endl;
}


Measured memory_bytes: 14336
import sys
readline = sys.stdin.readline
read = sys.stdin.read
 
n,m,s = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    u,v,a,b = [int(i) for i in readline().split()]
    u -= 1
    v -= 1
    g[u].append((v,a,b))
    g[v].append((u,a,b))
 
 
cd = [int(i) for i in read().split()]
c = cd[::2]
d = cd[1::2]
 
 
from heapq import *
INF = 1<<61
M = 2500
if s >= M: s = M-1
dist = [[INF]*M for _ in range(n)] #startからの最短距離
dist[0][s] = 0
q = [(0,s,0)] #(そこまでの距離、銀の枚数、点)
 
while q:
    dv,num,v = heappop(q)
    if dist[v][num] < dv: continue
    if num+c[v] < M and dv+d[v] < dist[v][num+c[v]]:
        dist[v][num+c[v]] = dv + d[v]
        heappush(q, (dv + d[v], num+c[v] ,v))
    for to,a,b in g[v]:
        if num >= a and dv + b < dist[to][num-a]:
            dist[to][num-a] = dv + b
            heappush(q, (dv + b, num-a ,to))
    #print(q)
 
for i in range(1,n):
    print(min(dist[i]))

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

int main(){
    int n;
    cin >> n;
    if (n % 10 == 3){
        cout << "bon" << endl;
    }
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }

    return 0;
}

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

const int maxn = 3e3 + 10;
ll a[maxn];
ll DP[maxn][maxn][2];
ll sum[maxn];
int N;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for(int i = 1; i <= N; ++i){
        cin >> a[i];
        DP[i][i][0] = a[i];
        DP[i][i][1] = 0;
        sum[i] = sum[i - 1] + a[i];
    }
    for(int len = 2; len <= N; ++len){
        for(int i = 1; i + len - 1 <= N; ++i){
            int j = i + len - 1;
            ll L0 = DP[i + 1][j][1] + a[i];
            ll R0 = DP[i][j - 1][1] + a[j];
            ll L1 = DP[i + 1][j][0];
            ll R1 = DP[i][j - 1][0];
            if(L0 > R0){
                DP[i][j][0] = L0;
                DP[i][j][1] = L1;
            }
            else if(L0 == R0){
                if(L1 <= R1){
                    DP[i][j][0] = L0;
                    DP[i][j][1] = L1;
                }
                else{
                    DP[i][j][0] = R0;
                    DP[i][j][1] = R1;
                }
            }
            else{
                DP[i][j][0] = R0;
                DP[i][j][1] = R1;
            }
        }
    }
    cout << DP[1][N][0] - DP[1][N][1] << endl;
}


Measured memory_bytes: 141568
// Jai Sai Ram
//Always help me!
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll> adj[300001];
ll vis[100001];
ll dis[100001];
vector<ll> levels[100001];

void solve()
{
    ll i,j,k,l,m,n,o,p,q,r,t;
    cin>>n;
    n^=1LL;
    cout<<n<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(0);
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 12988
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD!string;
	auto B = RD!string;
	auto C = RD!string;

	writeln(A[$-1] == B[0] && B[$-1] == C[0] ? "YES" : "NO");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char s[101];
	scanf("%s",s);
	int i,len=0,e=0;
	for(i=0;s[i]!='\0';i++) len++;
	for(i=0;i<len;i+=2) if(s[i]=='L') e=1;
	for(i=1;i<len;i+=2) if(s[i]=='R') e=1;
	printf(e==0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;


int main(){
    int a, b;
    cin >> a >> b;
    if(a>=13){
        cout << b << endl;
    }
    else if(a>=6){
        cout << b/2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
S = input()

if 2019 < int(S[0:4]):
    print('TBD')

elif 2019 == int(S[0:4]):

    if 4 < int(S[5:7]):
        print('TBD')
    elif 4 == int(S[5:7]):
        if 30 < int(S[8:10]):
            print('TBD')
        elif 30 >= int(S[8:10]):
            print('Heisei')
    else:
        print('Heisei')
    

else:
    print('Heisei')

Measured memory_bytes: 3064
import math

m=999999
s=int(math.sqrt(m)+1)
li=[0]*m
li[0]=1
for i in range(1,s):
    if li[i]==0:
        li[i*2+1::i+1]=[1 for e in range(len(li[i*2+1::i+1]))]
while True:
    try:n=int(input())
    except:break
    print(len([i for i in li[:n:] if i==0]))
    

Measured memory_bytes: 28388
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    cout << (int)(log(N)/log(K))+1 << endl;
    return 0;
 
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto ans = new int[](N*N);
    foreach (i; 0..N) ans[A[i] - 1] = i + 1;
    
    auto front = N.iota.array;
    auto back = N.iota.map!(i => N - i - 1).array;

    auto pq1 = new BinaryHeap!(Array!(Tuple!(int, int)), "a[0] > b[0]");
    auto pq2 = new BinaryHeap!(Array!(Tuple!(int, int)), "a[0] > b[0]");
    foreach (i; 1..N) pq1.insert(tuple(A[i] - 1, i + 1));
    pq2.insert(tuple(A[0] - 1, 1));

    foreach (i; 0..N*N) {
        if (ans[i] > 0) {
            continue;
        } else if (!pq1.empty) {
            auto t = pq1.front;
            auto pos = t[0];
            auto num = t[1];
            if (pos < i) {
                writeln("No");
                return;
            }
            ans[i] = num;
            front[num-1] -= 1;
            if (front[num-1] == 0) {
                pq1.removeFront;
                if (num != N) pq2.insert(tuple(pos, num));
            }
        } else if (!pq2.empty) {
            auto t = pq2.front;
            auto pos = t[0];
            auto num = t[1];
            if (pos > i) {
                writeln("No");
                return;
            }
            ans[i] = num;
            back[num-1] -= 1;
            if (back[num-1] == 0) pq2.removeFront;
        } else {
            writeln("No");
            return;
        }
    }

    writeln("Yes");
    ans.map!(a => a.to!string).join(" ").writeln;
}


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

//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

constexpr int h = 9;
int n, q;
lint v[1 << 18], w[1 << 18], dp[10][MAX];
vector<pii> qs[1 << 18];
lint ans[MAX];

void dfs(int t, int d) {
    if (d <= h) {
        dp[d][0] = 0;
        For(i, 1, MAX) {
            dp[d][i] = max(dp[d][i - 1], dp[d - 1][i]);
            if (i >= w[t]) chmax(dp[d][i], dp[d - 1][i - w[t]] + v[t]);
        }
    }
    for (auto [id, L] : qs[t]) {
        if (d <= h)
            ans[id] = dp[d][L];
        else {
            ans[id] = 0;
            vector<lint> vs, ws;
            for (int td = d, tt = t; td > h; --td, tt /= 2) {
                vs.push_back(v[tt]);
                ws.push_back(w[tt]);
            }
            rep(S, 1 << vs.size()) {
                lint tv = 0, tw = 0;
                rep(i, vs.size()) if (S >> i & 1) {
                    tv += vs[i];
                    tw += ws[i];
                }
                if (tw <= L) chmax(ans[id], dp[h][L - tw] + tv);
            }
        }
    }
    if (t * 2 <= n) dfs(t * 2, d + 1);
    if (t * 2 + 1 <= n) dfs(t * 2 + 1, d + 1);
}

int main() {
    scanf("%d", &n);
    For(i, 1, n + 1) scanf("%lld%lld", &v[i], &w[i]);
    scanf("%d", &q);
    rep(i, q) {
        int t, L;
        scanf("%d%d", &t, &L);
        qs[t].emplace_back(i, L);
    }
    rep(i, MAX) dp[0][i] = 0;
    dfs(1, 1);
    rep(i, q) printf("%lld\n", ans[i]);
}

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

int main() {
  int H,W;
  string s[60]; //
  const char empty = '.'; //空きマス
  const char mine = '#'; //爆弾マス
  const char edge = ' '; //終端
  int count;
  
  //要素数の取得
  cin >> H >> W;
  
  //初期設定
  for (int i=0;i<=W+1;i++){
    s[0] += edge;
  }
  for (int i=1;i<=H;i++) {
    cin >> s[i];
    s[i] = edge + s[i] + edge;
  }
  for (int i=0;i<=W+1;i++){
    s[H+1] += edge;
  }
  
  //処理開始
  for (int i=1;i<=H;i++){
    for (int j=1;j<=W;j++){
      count = 0;
      if (s[i][j]==empty) {
        //空マスの場合は地雷を数える
        if (s[i-1][j-1]==mine) count += 1; //左上
        if (s[i-1][j  ]==mine) count += 1; //上
        if (s[i-1][j+1]==mine) count += 1; //右上
        if (s[i  ][j-1]==mine) count += 1; //左
        if (s[i  ][j+1]==mine) count += 1; //右
        if (s[i+1][j-1]==mine) count += 1; //左下
        if (s[i+1][j  ]==mine) count += 1; //下
        if (s[i+1][j+1]==mine) count += 1; //右下
        //数えた結果を代入
        cout << count;
      } else {
        cout << s[i][j];
      }
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
///////////////////////////

#define N 100005
ll n;
set<ll>v[N];
bool nouse[N];
string s;
void debri(ll k){
    nouse[k]=true;
    for(auto x:v[k]){
        v[x].erase(k);
        if(v[x].size()<=1&&s[x-1]=='B'){
            debri(x);
        }
    }
    v[k].clear();
}
bool check(){
    ll count=0;
    rep(i,0,n-1){
        if(s[i]=='W')count++;
    }
    if(count<=1){
        cout<<count<<endl;
        return true;
    }
    return false;
}
ll col[N];
ll dp[N];
void dfs(ll id,ll par){
    if(par==-1){
        rep(i,1,n){
            if(v[i].size()==0)dp[i]=-inf;
            else dp[i]=0;
        }
    }
    if(col[id]==0)dp[id]++;
    vector<ll>res;
    for(auto x:v[id]){
        if(x==par)continue;
        dp[x]+=dp[id];
        dfs(x,id);
    }
}

int main(){fastio
    cin>>n;
    rep(i,1,n-1){
        ll a,b;cin>>a>>b;
        v[a].insert(b);v[b].insert(a);
    }
    cin>>s;
    if(check()){
        return 0;
    }
    rep(i,1,n){
        if(s[i-1]=='B'&&v[i].size()==1){
            debri(i);
        }
    }
    /*
    rep(i,1,n){
        cout<<i<<":";
        for(auto x:v[i])cout<<x<<" ";cout<<endl;
    }*/
    ll newn=0;
    ll ans=0;
    rep(i,1,n){
        if(v[i].size()>=1){
            newn++;
            col[i]=((s[i-1]=='B')+v[i].size())%2;
            if(col[i]==0)ans++;
        }
    }
    //rep(i,1,n)cout<<col[i]<<" ";cout<<endl;
    ans+=2*(newn-1);
    rep(i,1,n){
        if(v[i].size()>=1){
            dfs(i,-1);
            rep(j,1,n){
                if(v[j].size()>=1&&dp[i]<dp[j])i=j;
            }
            //rep(x,1,n)cout<<dp[x]<<" ";cout<<endl;
            dfs(i,-1);
            rep(j,1,n){
                if(v[j].size()>=1&&dp[i]<dp[j])i=j;
            }
           // rep(x,1,n)cout<<dp[x]<<" ";cout<<endl;
            cout<<ans-2*dp[i]<<endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 20812