akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  ll ans = 0, n = 0;

  cin >> n;

  for(ll i = 1; i <= n; i++) ans += i * (n - i + 1ll);

  for(int i = 1; i < n; i++) {
    ll u, v;
    cin >> u >> v;
    if(u > v) swap(u, v);
    ans -= u * (n - v + 1ll);
  }

  cout << ans;

  return 0;
}
/*

*/


Measured memory_bytes: 3660
#define _USE_MATH_DEFINES
#pragma region include
#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>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
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;

int N,M;
vector<LL> X,Y,Z;

LL cal(int x,int y,int z){
	vector<LL> R(N);
	for(int i=0;i<N;++i){
		R[i] = X[i]*x + Y[i]*y+Z[i]*z;
	}
	sort(R.begin(),R.end());
	LL ret = 0;
	for(int i=0;i<M;++i){
		ret += R[N-1-i];
	}
	return ret;
}
void solve(){
	cin>>N>>M;
	X=vector<LL>(N);
	Y=vector<LL>(N);
	Z=vector<LL>(N);
	for(int i=0;i<N;++i){
		cin>>X[i]>>Y[i]>>Z[i];
	}
	
	LL ans = 0;
	LL res;
	ans = max(ans,cal(1,1,1));
	ans = max(ans,cal(1,1,-1));
	ans = max(ans,cal(1,-1,1));
	ans = max(ans,cal(1,-1,-1));
	ans = max(ans,cal(-1,1,1));
	ans = max(ans,cal(-1,1,-1));
	ans = max(ans,cal(-1,-1,1));
	ans = max(ans,cal(-1,-1,-1));
	
	cout << ans << endl;
}

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

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
  string s;
  cin >> s;
  if(s[1] == s[2] && (s[0] == s[1] || s[2] == s[3])){
  	cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<vector<ll>> s(H, vector<ll>(W,0));
    vector<vector<bool>> visited(H, vector<bool>(W,0));
    ll wcnt = 0;
    rep(i, H) {
        rep(j, W) {
            char c;
            cin >> c;
            if (c == '.') {
                s[i][j] = 0;
                wcnt++;
            } else {
                s[i][j] = -1;
            }
        }
    }

    visited[0][0] = true;

    queue<P> st;
    st.push(P(0,0));
    while(!st.empty()) {
        P p = st.front();
        st.pop();
        if (p.first - 1 >= 0 && !visited[p.first-1][p.second] && s[p.first-1][p.second] == 0) {
            s[p.first-1][p.second] = s[p.first][p.second] + 1;
            st.push(P(p.first-1, p.second));
            visited[p.first-1][p.second] = true;
        }
        if (p.first + 1 < H && !visited[p.first+1][p.second] && s[p.first+1][p.second] == 0) {
            s[p.first+1][p.second] = s[p.first][p.second] + 1;
            st.push(P(p.first+1, p.second));
            visited[p.first+1][p.second] = true;
        }
        if (p.second - 1 >= 0 && !visited[p.first][p.second-1] && s[p.first][p.second-1] == 0) {
            s[p.first][p.second-1] = s[p.first][p.second] + 1;
            st.push(P(p.first, p.second-1));
            visited[p.first][p.second-1] = true;
        }
        if (p.second + 1 < W && !visited[p.first][p.second+1] && s[p.first][p.second+1] == 0) {
            s[p.first][p.second+1] = s[p.first][p.second] + 1;
            st.push(P(p.first, p.second+1));
            visited[p.first][p.second+1] = true;
        }
    }
    if (s[H-1][W-1] == 0) {
        print(-1);
    } else {
        print(wcnt - s[H-1][W-1]-1);
    }
    
    return 0;
}

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

using namespace std;

int main()
{
	string str;
	int n;

	cin >> str;
	for (cin >> n; n > 0; n--) {
		string op;
		cin >> op;

		if (op == "print") {
			int a, b;

			cin >> a >> b;
			cout << str.substr(a, b - a + 1) << endl;
		} else if (op == "reverse") {
			int a, b;
			string t;

			cin >> a >> b;
			t = str.substr(a, b - a + 1);
			reverse(t.begin(), t.end());
			str.replace(a, b - a + 1, t);
		} else if (op == "replace") {
			int a, b;
			string p;

			cin >> a >> b >> p;
			str.replace(a, b - a + 1, p);
		}
	}
}

Measured memory_bytes: 3228
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (k, n) = InputLine.to_ia
  a = InputLine.to_ia

  d = [nil] * n
  (n - 1).times{|i| d[i] = a[i + 1] - a[i]}
  d[n - 1] = a[0] + (k - a[n - 1])
  
  puts (k - d.max).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 16968
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n=3;
  int c11,c12,c13,c21,c22,c23,c31,c32,c33;
  cin>>c11>>c12>>c13>>c21>>c22>>c23>>c31>>c32>>c33;

  if((c11-c12 == c21-c22) && (c21-c22 == c31-c32))
  {
    if((c11-c13== c21-c23)&&( c21-c23 == c31-c33))

    {
      if((c12-c13== c22-c23)&& (c22-c23 == c32-c33)) {cout<<"Yes"<<endl; return 0;}
    }
  }
  cout<<"No"<<endl;

}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

from itertools import permutations

def main():
    n = int(input())
    town = [tuple(map(int,input().split())) for i in range(n)]
    p = [i for i in range(n)]

    distsum = 0
    count = 0
    for p2 in permutations(p):
        for i in range(1,n):
            d1 = town[p2[i]]
            d2 = town[p2[i-1]]
            distsum += ((d1[0]-d2[0]) ** 2 + (d1[1]-d2[1]) ** 2) ** 0.5
        count += 1

    print(distsum / count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    int a[200005], b[200005];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    int p;
    int s = 0;
    for(p = 0; p < n; p++){
        if(s + a[p] <= k) s += a[p];
        else break;
    }
    int ans = p;
    int q = 0;
    while(true){
        while(q < m && s + b[q] <= k){
            s += b[q];
            q++;
        }
        ans = max(ans, p + q);
        if(p <= 0) break;
        p--;
        s -= a[p];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5196
#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;

typedef pair <int, int> pii;

const int N = 2e3 + 6, inf = 1e9 + 7;
int n, ans = inf;
string s;
vector <int> G[N];
int val[N], num[N], change;

int get_cnt (int v, int par, int h = 1) {
	int res = (s[v] == '1') * h;
	for (int u: G[v])
		if (u != par)
			res += get_cnt(u, v, h + 1);
	return res;
}

void can (int v, int par) {
	vector <int> arr;
	int sum = 0;
	val[v] = num[v] = 0;

	for (int u: G[v])
		if (u != par) {
			can(u, v);
			if (change == false)
				return ;
			if (val[u] + num[u]) {
				arr.push_back(val[u] + num[u]);
				sum += val[u] + num[u];

				num[v] += num[u];
				val[v] += val[u] + num[u];
			}
		}

	if (arr.size()) {
		sort(arr.begin(), arr.end());
		if (sum % 2) {
			sum--;
			arr.back()--;
			sort(arr.begin(), arr.end());
		}

		if (2 * arr.back() > sum) {
			if (change <= 2 * (sum - arr.back())) {
				change = 0;
				return ;
			}
			change -= 2 * (sum - arr.back());
			val[v] -= 2 * (sum - arr.back());
		}
		else {
			if (change <= sum) {
				change = 0;
				return ;
			}
			change -= sum;
			val[v] -= sum;
		}
	}

	if (s[v] == '1')
		num[v]++;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> s;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;

		G[v].push_back(u);
		G[u].push_back(v);
	}

	for (int i = 0; i < n; i++) {
		vector <pii> vec;
		int sum = 0;

		for (int v: G[i]) {
			int val = get_cnt(v, i);
			if (val) {
				sum += val;
				vec.push_back({val, v});
			}
		}

		if (vec.empty()) {
			ans = 0;
			continue;
		}

		if (vec.size() == 1 || sum % 2)
			continue;

		sort(vec.begin(), vec.end());
		change = max(0, 2 * vec.back().first - sum);

		can(vec.back().second, i);
		if (change == false)
			ans = min(ans, sum);
	}


	cout << (ans == inf? -1: ans / 2) << "\n";
	return 0;
}

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

int main()
{

 int a;
 int b;
 int c;
 vector<int> v;
 
 cin >> a >> b >> c;

 v.push_back ( a );
 v.push_back ( b );
 v.push_back ( c );

 sort(v.begin(), v.end());

 a = v[0];
 b = v[1];
 c = v[2];

 cout << a << " " << b << " " << c << endl;

}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    deque<char> dq;
    for (Int i = 0; i < (Int)s.size(); i++) {
        dq.push_back(s[i]);
    }
    bool rev = false;
    Int q;
    cin >> q;
    for (Int i = 0; i < q; i++) {
        Int t;
        cin >> t;
        if (t == 1) {
            rev = not rev;
        }
        else {
            Int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (not rev) {
                    dq.push_front(c);
                }
                else {
                    dq.push_back(c);
                }
            }
            else {
                if (not rev) {
                    dq.push_back(c);
                }
                else {
                    dq.push_front(c);
                }
            }
        }
    }
    if (rev) {
        while (not dq.empty()) {
            cout << dq.back();
            dq.pop_back();
        }
    }
    else {
        while (not dq.empty()) {
            cout << dq.front();
            dq.pop_front();
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
int a[100010],n,x;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		if(a[i]==i)
		{
			swap(a[i],a[i+1]);
			x++;
		}
	printf("%d",x); 
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

int main(){
    string n; cin >> n;
    for(int i = 0; i<n.size(); i++){
        if(n[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] problems = new int[N];
        int[] was = new int[N];

        for (int i = 0; i < M; i++) {
            final int p = sc.nextInt() - 1;
            boolean isAC = sc.next().equals("AC");
            if (isAC) {
                problems[p] = 1;
            } else {
                if (problems[p] != 1) {
                    was[p]++;
                }
            }
        }
        int wa = 0;
        for (int i = 0; i < N; i++) {
            if (problems[i] == 1) {
                wa += was[i];
            }
        }
        System.out.println(Arrays.stream(problems).sum() + " " +wa);
    }
}


Measured memory_bytes: 64192
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<string> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<vector<int> > dp(N, vector<int>(M, 0));
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (A[i][j] == '.') {
				if (i > 0 && A[i - 1][j] == '.')dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
				if (j > 0 && A[i][j - 1] == '.')dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp.back().back() << endl;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main()
{


    string st;
    int i,cw=0,cb=0,c1w=0,c1b=0,ans,n;
    cin >> st;
    n=st.size();
    for(i=0; i<st.size(); i++)
    {
        if(st[i]=='1' && i%2==0)cw++;
        if(st[i]=='0' && i%2==1)cb++;

    }
    ans=n-(cw+cb);
    for(i=0; i<st.size(); i++)
    {
        if(st[i]=='1' && i%2==1)c1w++;
        if(st[i]=='0' && i%2==0)c1b++;
    }
    ans=min(ans,n-(c1w+c1b));
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 512
W,H,N=map(int,input().split())
A=[]
right=W
left=0
top=H
under=0

for i in range(N):
  A.append(list(map(int,input().split())))
  if A[i][2]==1:
    if left<A[i][0]:
      left=A[i][0]
  if A[i][2]==2:
    if right>A[i][0]:
      right=A[i][0]
  if A[i][2]==3:
    if under<A[i][1]:
      under=A[i][1]
  if A[i][2]==4:
    if top>A[i][1]:
      top=A[i][1]

print(max(0,top-under)*max(0,right-left))


Measured memory_bytes: 3064
import bisect
n=input()
a=sorted(map(int,input().split()))
m=a[-1]
q=bisect.bisect_right(a,m/2)
p=q-1
if abs(m/2-a[p])>abs(m/2-a[q]):print(m,a[q])
else:print(m,a[p])

Measured memory_bytes: 20108
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	int n;
	cin >> n; 
	int cnt = 0;
	for(int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		if(x != i) cnt++;
		}
		if(cnt == 0 || cnt == 2) cout << "YES" << endl;
		else cout << "NO" << endl;
		return;
}
	
	

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 
 


Measured memory_bytes: 3636
#include <iostream>
int main(void) {
  int N, sum = 0;
  uint64_t a,comp;
  std::cin >> N;
  for(int i = 0; i < N; i++) {
    std::cin >> a;
    comp = 1;
    while(comp > 0) {
      if(comp & a)
        break;
      comp <<= 1;
      sum++;
    }
  }
  std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using P = complex<ld>;
using edge = struct { int to; ld cost; };
using edges = vector<edge>;
using graph = vector<edges>;

namespace std {
  bool operator<(const P& a, const P& b) {
    return (real(a) != real(b)) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

bool operator<(const edge &e1, const edge &e2) {
  return (e1.cost != e2.cost) ? e1.cost > e2.cost : e1.to < e2.to;
}

const ld INF = 1e12;

graph G;
vector<ld> d;

double cross(const P& a, const P& b) {
  return imag(conj(a) * b);
}
double dot(const P& a, const P& b) {
  return real(conj(a) * b);
}

void dijkstra(int s) {
  int N = G.size();
  priority_queue<edge> pq;
  d.assign(N, INF); d[s] = 0.0;
  pq.push({s, 0.0});
  while (!pq.empty()) {
    edge e = pq.top(); pq.pop();
    int u = e.to;
    if (d[u] < e.cost) continue;
    for (auto&& v : G[u]) {
      if (d[v.to] > d[u] + v.cost) {
        d[v.to] = d[u] + v.cost;
        pq.push({v.to, d[v.to]});
      }
    }
  }
}

int main() {
  P s, t; {
    int x, y;
    cin >> x >> y; s = {x, y};
    cin >> x >> y; t = {x, y};
  }
  int N; cin >> N;
  vector<P> p(N + 2); // p = {s, p1, p2, ..., pN, t}
  p[0] = s; p[N + 1] = t;
  vector<int> r(N + 2, 0);
  for (int i = 1; i <= N; ++i) {
    int x, y;
    cin >> x >> y >> r[i]; p[i] = {x, y};
  }
  G.resize(p.size());
  for (int i = 0; i < p.size(); ++i) {
    for (int j = 0; j < p.size(); ++j) {
      G[i].push_back({j, max(0.0L, abs(p[i] - p[j]) - r[i] - r[j])});
      G[j].push_back({i, max(0.0L, abs(p[i] - p[j]) - r[i] - r[j])});
    }
  }
  dijkstra(0);
  cout << fixed << setprecision(10) << d[N + 1] << endl;
  return 0;
}


Measured memory_bytes: 75312
#include<iostream>
using namespace std;
int main(){
    int n, q;
    string s;
    cin >> n >> q >> s;
    int l, r, counter=0, m[n];
    m[0] = 0;
    for(int i=1;i<n;i++){
        if(s[i] == 'C' && s[i - 1] == 'A') counter++;
        m[i] = counter;
    }
    for(int i=0;i<q;i++){
        cin >> l >> r;
        cout << m[r - 1] - m[l - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
using namespace std;

template<typename T> class RangeUpdateSegTree {
  int size = 1;
  size_t time = 1;
  std::vector<pair<size_t, T>> tree; // 1-indexed

public:
  RangeUpdateSegTree(const int n = 0) {
    while (size < n) size *= 2;
    tree.resize(size * 2);
  }

  RangeUpdateSegTree(const int n, const T &x) {
    while (size < n) size *= 2;
    tree.assign(size * 2, {0, x});
  }

  template<typename InputIterator> RangeUpdateSegTree(InputIterator first, InputIterator last) {
    size_t n = std::distance(first, last);
    while (size < n) size *= 2;
    tree.resize(size * 2);

    auto result = tree.begin() + size;
    while (first != last) {
      result->second = *first;
      ++result, ++first;
    }
  }

  // [l, r)
  void update(int l, int r, const T &x) {
    for (l += size, r += size; l < r; l /= 2, r /= 2) {
      if (l & 1) tree[l++] = {time, x};
      if (r & 1) tree[--r] = {time, x};
    }
    time++;
  }

  const T operator[](int i) const {
    pair<size_t, T> p = tree[i += size];
    while (i /= 2) p = max(p, tree[i]);
    return p.second;
  }
};

class RangeUnionFind {
  RangeUpdateSegTree<int> rust;

public:
  RangeUnionFind(const int n) {
    vector<int> ufInit(n);
    iota(all(ufInit), 0);
    rust = RangeUpdateSegTree<int>(all(ufInit));
  }

  int root(int x) {
    int a = rust[x];
    if (a == x) return x;
    int b = root(a);
    rust.update(x, x + 1, b);
    return b;
  }

  bool same(const int a, const int b) { return root(a) == root(b); }

  void unite(int a, int b) { // unite [a, b)
    int r = root(a);
    if (a == b) return;
    rust.update(a, b, r);
  }
};

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  multimap<int, int> w;
  vector<int> d(m + q), a(m + q), b(m + q);
  rep(i, m + q) cin >> d[i] >> a[i] >> b[i];
  rep(i, m + q) w.emplace(d[i] << 1 | (i < m), i);
  vector<int> ans(q);
  RangeUnionFind ruf(n);
  for (auto &p : w) {
    int i = p.second;
    if (i < m) {
      ruf.unite(a[i] - 1, b[i]);
    } else {
      ans[i - m] = b[i] <= a[i] || ruf.same(a[i] - 1, b[i] - 1);
    }
  }
  for (auto &x : ans) cout << (x ? "Yes" : "No") << endl;
}



Measured memory_bytes: 19472
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

double dp[3001][3001];
int main() {

  int n;
   cin >> n;
   vector<double> p(n);
   rep(i,n)cin>>p[i];

  dp[0][0] =1;

  rep(i,n){
    for(int j=0;j<=i;j++){
      dp[i+1][j+1] += dp[i][j]*p[i];
      dp[i+1][j] += dp[i][j]*(1.0-p[i]);
    }
  }

  double res = 0;
  for(int j=(n+1)/2;j<=n;j++){
    res+=dp[n][j];
  }
  cout<<fixed<<setprecision(10)<<res<<endl;

  return 0;
}

Measured memory_bytes: 68992
N = int(input())

high_sets = [list(map(int, input().split())) for _ in range(N)]

# このセットから中心座標と高さは絞り込める


def compute_diff_from_top(x, y, cx, cy):
    # -4 + -77
    return ((-1 * abs(x - cx)) + (-1 * abs(y - cy)))


ans = 0
ans_x = None
ans_y = None
for i in range(101):
    for j in range(101):
        nums = []
        for high_set in high_sets:
            # i == 55 j == 80
            # high_set_x = 59 high_set_y = 3
            # high_set[2] == 0の時は、区別が必要。
            num = high_set[2] + (-1 * compute_diff_from_top(i, j, high_set[0], high_set[1]))
            if high_set[2] == 0:
                nums.append(-1)
            else:
                nums.append(num)
        # if i == 32:
        #     print(i, j, nums)
        if len(set(nums)) == 1:
            ans_x, ans_y = i, j
            ans = nums.pop()
        else:
            if len(set(nums)) == 2 and -1 in nums:
                nums = set(nums)
                nums.remove(-1)
                top = nums.pop()
                check = True
                for high_set in high_sets:
                    # if i == 32 and j == 68:
                    #     print(top, compute_diff_from_top(i, j, high_set[0], high_set[1]))
                    if max(0, top + compute_diff_from_top(i, j, high_set[0], high_set[1])) != high_set[2]:
                        check = False
                if check:
                    ans_x, ans_y = i, j
                    ans = top


print(ans_x, ans_y, ans)
# 55 80 79


Measured memory_bytes: 9188
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     string s;cin>>s;
     int sum=0;
     for(int i=0;i<s.size();i++){
         sum += (s[i]-'0');
     }
     //cout<<sum;
     if(sum%9==0){
         cout<<"Yes"<<endl;
     }
     else{
         cout<<"No"<<endl;
     }
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 3752
n = int(input())

divisors = []
for i in range(1, int(n**0.5)+1):
  if n%i == 0:
    divisors.append((i, n//i))

ans = 11
for key in divisors:
  a, b = str(key[0]), str(key[1])
  ans = min([ans, max([len(a), len(b)])])

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <queue>
using namespace std;

int N, A, B, C, X;
vector<int> randomnum;

int main(void){
  while(true){
    cin >> N >> A >> B >> C >> X;
    if(N == 0) break;
    int i, j = 0;
    randomnum.clear();
    for(i = 0; i < N; i++){
      int tmp;
      cin >> tmp;
      randomnum.push_back(tmp);
    }
    i = 0;
    while(true){
      if(randomnum[i] == X){
        if(i == N - 1){
          break;
        }
        i++;
      }
      X = (A * X + B) % C;
      j++;
      if(j > 10000) break;
    }
    if(j > 10000) cout << -1 << endl;
    else cout << j << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool prime[10000000];
ll N=10000000;
void seive()
{
    int sqrtn,i,j;
    prime[0]=1,prime[1]=1,prime[2]=0;
    for(i=4;i<=N;i++)
    {
        prime[i]=0;
        if(i%2==0)
            prime[i]=1;
    }
    sqrtn=((int)sqrt((double)N));
    for(i=3;i<=sqrtn;i+=2)
    {
        if(prime[i]==0)
        {
            for(j=i*i;j<=N;j+=i+i)
            {
                prime[j]=1;
            }
        }
    }
}
int main()
{
    seive();
    ll q;
    ll a,b;
    ll sum=0;
    ll ans[100045];
    for(int i=0;i<100005;i++)
    {
        a=(i+1)/2;
        if(prime[i]==0&&prime[a]==0)
        {
            ans[i]=ans[i-1]+1;
        }
        else
        {
            ans[i]=ans[i-1];
        }
    }
   /* for(int i=0;i<10;i++)
    {
        cout<<ans[i]<<endl;
    }*/
    scanf("%lld",&q);
    for(int i=0;i<q;i++)
    {
        ll cnt=0;
        scanf("%lld %lld",&a,&b);
        cnt=ans[b]-ans[a-1];
        printf("%lld\n",cnt);
    }
    return 0;
}


Measured memory_bytes: 11136
class UnionFind():
    def __init__(self, n):
        self._n = n
        self._table = [-1]*n
        self._rank = [0]*n

    def _root(self, x):
        stack = []
        while self._table[x] >= 0:
            stack.append(x)
            x = self._table[x]
        for y in stack:
            self._table[y] = x
        return x
    
    def unite(self, x, y):
        x, y = self._root(x), self._root(y)
        if x == y:
            return
        elif self._rank[x] > self._rank[y]:
            self._table[x] += self._table[y]
            self._table[y] = x
        else:
            self._table[y] += self._table[x]
            self._table[x] = y
            if self._rank[x] == self._rank[y]:
                self._rank[y] += 1
    
    def find(self, x, y):
        return self._root(x) == self._root(y)

    def count(self, x):
        return -self._table[self._root(x)]
    
    def __str__(self):
        return str(list(self))
    def __repr__(self):           
        return repr(list(self))
    def __iter__(self):
        return (self._root(i) for i in range(n))

n, m, *AB = map(int, open(0).read().split())
ans = 0
for i in range(m):
    uf = UnionFind(n)
    for j, (a, b) in enumerate(zip(AB[::2], AB[1::2])):
        if i == j:
            continue
        uf.unite(a-1, b-1)
    ans += len(set(uf)) != 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

//最大公約数
ll gcd(ll a, ll b){
        if(b == 0) return a;
        return gcd(b, a % b);
}
// 最小公倍数
ll lcm(ll a, ll b){
        return a / gcd(a, b) * b;
}

 ll a,b,c,d,cnt=0,cd;
int main(int argc, char const *argv[]) {

  cin >> a >> b >> c >> d;

  cd=lcm(c,d);

  cout << (b-a+1) - (b/c-(a-1)/c) - (b/d - (a-1)/d) +(b/(lcm(c,d)) - (a-1)/(lcm(c,d))) << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int[] a = new int[3];
	for (int i = 0; i < 3; i++) {
	    a[i] = Integer.parseInt(scan.next());
	}

	Arrays.sort(a);
	System.out.println(a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO");
	scan.close();
    }
}


Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long n = Long.parseLong(sc.next());
        
        if(n >= b-1){
            System.out.println((a*(b-1))/b - a*((b-1)/b));
        }else{
            System.out.println((a*n)/b - a*(n/b));
        }
    }
}

Measured memory_bytes: 35628
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    long double n, nam[100], a, b[100], ans;
    int i;
    a = 1;
    ans = 0;
    cin >> n;
    for(i=0;i<n;i++)
        cin >> nam[i];
    for(i=0;i<n;i++)
    {
        a *= nam[i];
    }
    for(i=0;i<n;i++)
    {
        b[i] = a/nam[i];
        ans += b[i];
    }
    cout << fixed  << a/ans << '\n';
}

Measured memory_bytes: 256
import itertools
import math

N = int(input())
L = [list(map(int,input().split())) for n in range(N)]
I = list(itertools.permutations(L))
sum = 0

for i in I:
  for n in range(N-1):
    sum += math.sqrt((i[n+1][0]-i[n][0])**2+(i[n+1][1]-i[n][1])**2)
    
print(sum/len(I))

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

int N, M;
vector<vector<int>> tree;
map<pair<int, int>, int> mp;

void dfs(int u, int p, vector<bool>& reach, int m){
    for(int v : tree[u]){
        if(v == p) continue;
        if(mp[{u, v}] == m) continue;
        if(reach[v]) continue;

        reach[v] = true;
        dfs(v, u, reach, m);
    }
}

int main(){
    cin >> N >> M;
    tree.resize(N, vector<int>());
    for(int i=0; i<M; i++){
        int a, b;  cin >> a >> b;
        a--;  b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
        mp[{a, b}] = i;
        mp[{b, a}] = i;
    }

    int ans = 0;
    for(int m=0; m<M; m++){
        vector<bool> reach(N, false);
        reach[0] = true;
        dfs(0, -1, reach, m);

        bool ok = true;
        for(int i=0; i<N; i++){
            bool b = reach[i];
            ok = b && ok;
        }

        if(!ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A, B, C, K, count = 0;
  cin >> A >> B >> C >> K;
  for (int i = 0; i < K; i++){
    if (B >= C){
      C *= 2;
    }
    else if (A >= B){
      B *= 2;
    }
  }
  if ((A < B) && (B < C)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

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

int m[4] = {1000,100,10,1};
std::string c("mcxi");


int toint(std::string str){
	int sum = 0;
	int d = 1;
	rep(i,(int)str.size()){
		if('1'<str[i] && str[i]<='9'){
			d = str[i] - '0';
		}else{
			rep(j,4){
				if(c[j] == str[i]){
					sum += d * m[j];
					d=1;
					break;
				}
			}
		}
	}
	return sum;
}


int main(){


	int d;
	std::string str1,str2;
	int N;
	std::cin >> N;
	while(N--){
		std::cin >> str1 >> str2;
		int sum;
		sum = toint(str1) + toint(str2);
		rep(i,4){
			d=0;
			while(sum >= m[i]){
				sum -= m[i];
				d++;
			}
			if(d>1)std::cout << d << std::flush;
			if(d>0)std::cout << c[i] << std::flush;
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 928
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b;
    c=a-b;
    if(b==1)
    {
        cout<<0<<endl;
    }
    else
    {
           cout<<c<<endl;
    }

return 0;


}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let count = s.iter().filter(|&&x| x == 'B').count();
    if count != 0 && count != 3 {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
// using u_int64_t = unsigned long long;

int main()
{
	string N;
	cin >> N;
	int length = N.length();

	u_int64_t total  = stoull(N, nullptr, 10); // 合計値

	int supBit = 1 << length - 1;
	int itrBit = supBit - 1;      // ループカウンタ

	while(itrBit)
	{
		u_int64_t sum = 0;
		int pos = 0;
		
		for(int i = 1; i < length + 1; ++i)
		{
			// i番目のビットが立っていた時
			if((supBit >> i) & itrBit)
			{
				// Nのpos番目からi番目までを切り出した値を加える
				sum += stoull(N.substr(pos, i - pos), nullptr, 10);
				
				// 最終切り出し位置を更新
				pos = i;
			}
          	// 終端到達時
			if(!(supBit >> i))
			{
				sum += stoull(N.substr(pos, N.length() - pos), nullptr, 10);
			}
		}
		total += sum;
		--itrBit;
	}
	cout << total << endl;
	
	return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(false);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int L, R, d;
  cin >> L >> R >> d;
  int ans = 0;
  rep(i, L, R + 1) if (i % d == 0) ans++;
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 3608
// https://atcoder.jp/contests/abc178/tasks/abc178_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

const int MOD = 1e9 + 7;
int memo[2001];

int dfs(int a) {
    if (a <= 2) {
        return 0;
    } else if (a <= 5) {
        return 1;
    }
    if (memo[a] > 0) {
        return memo[a];
    }
    return memo[a] = (dfs(a - 1) + dfs(a - 3)) % MOD;
}

void solve() {
    int N;
    cin >> N;
    cout << dfs(N) << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3684
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------



int main(){
  int n=0;
  bool flag = false;
  cin >> n;
  for(int c=0;c<=100;c=c+4){
    for(int k=0;k<=100;k=k+7){
      if(c+k==n){
        flag=true;
      }
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(void){
	
	int i,n;
	
	scanf ("%d",&n);
	int a[n];
	
	for (i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	for (i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);
	
	for (i=1;i<n;i++){
		int v=a[i];
		int j=i-1;
		while ((j>=0) && v<a[j]){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		for(int k=0;k<n-1;k++){
			printf("%d ",a[k]);
		}
		printf("%d\n",a[n-1]);
	}
	
	return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int r;

	cin >> r;
	cout << r * r << endl;
}



Measured memory_bytes: 256
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,i,j,k;
		cin>>n;
		vector<ll>a(n);
		for(i=0;i<n;i++){
			cin>>a[i];
		}

		ll ct=0;

		for(i=0;i<n;i++){
			if(a[i]-1!=i)ct++;
		}

		if(ct<=2)cout<<"YES";
		else cout<<"NO";

	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

ll pathy(int level)
{
    return 1+2*(pow(2,level)-1);
}

ll buger(int level)
{
    if(level==0)
    {
        return 1;
    }
    return 1+4*(pow(2,level)-1);
}

int main()
{
    int n;
    ll x;
    ll ans=0;
    cin>>n>>x;
    int currentlevel=n;
    ll edge=buger(n);
    ll start=1;
    //cout<<edge<<endl;
    while(edge-start>0)
    {
        ll point=(edge+start)/2;
        if(x==point)
        {
            ans+=pathy(currentlevel-1)+1;
            cout<<ans;
            return 0;
        }
        if(x<point)
        {
            edge=point-1;
            start+=1;
        }
        else
        {
            ans+=pathy(currentlevel-1)+1;
            start=point+1;
            edge-=1;
        }
        currentlevel-=1;
        //cout<<ans<<endl;
    }
    if(edge<=x)ans++;
     
    cout<<ans;
    
    

}


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){
		x+=p.x,y+=p.y;
		return *this;
	}
	Point& operator-=(Point p){
		x-=p.x,y-=p.y;
		return *this;
	}
	Point& operator*=(double c){
		x*=c,y*=c;
		return *this;
	}
	Point& operator/=(double c){
		x/=c,y/=c;
		return *this;
	}
};
Point operator+(Point a,Point b){
	return a+=b;
}
Point operator-(Point a,Point b){
	return a-=b;
}
Point operator*(Point a,double c){
	return a*=c;
}
Point operator*(double c,Point a){
	return a*=c;
}
Point operator/(Point a,double c){
	return a/=c;
}
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}

double Abs(Point p){
	return sqrt(p.x*p.x+p.y*p.y);
}
double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Arg(Point p){
	return atan2(p.y,p.x);
}
double Dot(Point a,Point b){
	return a.x*b.x+a.y*b.y;
}
double Cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
	Line(double px,double py,double dx,double dy):pos(px,py),dir(dx,dy){}
};

Point Proj(Line l,Point p){
	Point a=p-l.pos,b=l.dir;
	return l.pos+Dot(a,b)/Abs2(b)*b;
}

int main()
{
	Line l;
	{
		double a,b,c,d; cin>>a>>b>>c>>d;
		l=Line(a,b,c-a,d-b);
	}
	int q; cin>>q;
	rep(_,q){
		Point p; cin>>p.x>>p.y;
		Point q=Proj(l,p); q+=q-p;
		printf("%.10f %.10f\n",q.x,q.y);
	}
}

Measured memory_bytes: 1236
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);	/*最大公約数*/
int lcm(int x, int y);	/*最小公倍数*/

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/



/*ここからmain関数*/

int main()
{
	int N;
	char s[100];
	cin >> N >> s;

	int r = 0;
	int b = 0;

	for (int i=0;i < N;i++)
	{
		if (s[i] == 'R')
			r++;
		else
			b++;
	}

	if (r > b)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

/*2数の大きい方を返す*/
int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

/*2数の小さい方を返す*/
int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

/*2数の最大公約数を返す*/
int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

/*2数の最小公倍数を返す*/
int lcm(int x, int y)
{
	int m;

	for (int i = 1;i <= y;i++)
	{
		if ((x*i) % y == 0) {
			m = x * i;
			break;
		}
	}

	return m;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	int a,b,k[100],i,sum=0;
	scanf("%d%d",&a,&b);
	for(i=1;i<=a;i++){
		scanf("%d",&k[i]);
	}
	sort(k+1,k+1+a);
	for(i=a-b+1;i<=a;i++){
		sum+=k[i];
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 128
N = int(input())
t_0, x_0, y_0 = 0, 0, 0

for n in range(N):
  t_1, x_1, y_1 = [int(txyz) for txyz in input().split()]
  d_01 = abs(x_1 - x_0) + abs(y_1 - y_0)
  dt = t_1 - t_0
  if dt < d_01:
    print("No")
    break
  else:
    t_d = dt - d_01
    if t_d % 2 == 0:
      t_0, x_0, y_0 = t_1, x_1, y_1
    else:
      print("No")
      break
else:
  print("Yes")

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;
int main(){
  int a[4],b[4];
  while(cin>>a[0]){
    for(int i=1;i<4;i++){
      cin>>a[i];
    }
    for(int i=0;i<4;i++){
      cin>>b[i];
    }
    int hit=0,brow=0;
    for(int i=0;i<4;i++){
      if(a[i]==b[i]){
	hit++;
      }
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(a[i]==b[j]){
	  brow++;
	}
      }
    }
    cout<<hit<<" "<<brow-hit<<endl;
  }
  return 0;   
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int getcost(int a,int b){
    return abs(a-b)*abs(a-b);
}

int N;
#define MAXN 101
int X[MAXN];

int main() {
    cin >> N ;
    rep(i,N)cin >> X[i];
    int mini=10000000,ans= 0;
    for(int i=0;i<=1000;i++) {
        ll tmp = 0;
        rep(j,N){
            tmp += (X[j]-i) * (X[j]-i);
        }
        if(mini > tmp) {
            mini = tmp;
            ans = i;
        }
    }

    cout << mini << endl;
    
    return 0;
}
// int X[MAXN];
// int main(){
//     cin >> N;
//     rep(i,N)cin >> X[i];
//     int mini = 1000000000;
//     for(int i=1;i<=100;i++){
//         int cost = 0;
//         for(int j=0;j<N;j++){
//             cost += getcost(X[j],i);
//         }
//         if(cost < mini)mini = cost;
//     }
//     cout << mini << endl;
//     return 0;
// }

Measured memory_bytes: 3620
#include <stdio.h>

int main(){

  int a,b,c,d,l1,l2;

  scanf("%d %d %d %d",&a,&b,&c,&d);

  l1=a*b;
  l2=c*d;

  if(l1<l2) printf("%d\n",l2);
  if(l2<l1) printf("%d\n",l1);
  if(l1==l2) printf("%d\n",l1);

  return 0;
}


Measured memory_bytes: 128