akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int n, m;
int x[100005];
priority_queue<int,vector<int>, greater<int> > pq;
int main(){
	cin >> n >> m;
	FOR(i,1,m+1) cin >> x[i];
	sort(x+1, x+m+1);
	if (n >= m){
		cout << 0 << '\n';
		return 0;
	}
	FOR(i,1,m){
		pq.push(x[i+1] - x[i]);
	}
	LL tot = 0;
	FOR(i,0,m - n){
		tot += pq.top();
		pq.pop();
	}
	cout << tot << '\n';
	return 0;
}


Measured memory_bytes: 1276
#include <stdio.h>
#include <math.h>

int main(void){
	
	int H,W,h,w,x;
	
	scanf("%d%d%d%d",&H,&W,&h,&w);
	
	x=W*H-h*W-w*(H-h);
	
	printf("%d\n",x);
	
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            

            Console.WriteLine(Math.Min(p[0]*p[1],p[2]));
            //Console.Out.Flush();

        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}


Measured memory_bytes: 13396
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 1; i <= n; i++)

int main() {
	string s, t;
	cin >> s >> t;
	int n = t.size();
	s += t[n-1];
	if (s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

ll n,k; cin >> n >> k;

if(k % 2 == 1) {
    ll r = n/k;
    cout << r * r * r << endl;
    return 0;
}

ll l = k/2;
ll r = n/k, s = n/l - n/k;

cout << r*r*r + s*s*s << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		boolean[] cups = {true, false, false};
		while(sc.hasNext()) {
			char[] chars = sc.next().toCharArray();
			cups = change(chars[0], chars[2], cups);
		}
		String str = null;
		for(int $ = 0; $ < 3; $++) {
			if(cups[$]) {
				if($ == 0) {
					str = "A";
				} else if($ == 1) {
					str = "B";
				} else {
					str = "C";
				}
				System.out.println(str);
				break;
			}
		}
	}

	public static boolean[] change(char cup1, char cup2, boolean[] array) {
		char[] cups = {cup1, cup2};
		int[] num = new int[2];
		for(int $ = 0; $ < 2; $++) {
			if(cups[$] == 'A') {
				num[$] = 0;
			} else if(cups[$] == 'B') {
				num[$] = 1;
			} else {
				num[$] = 2;
			}
		}

		boolean box = array[num[0]];
		array[num[0]] = array[num[1]];
		array[num[1]] = box;

		return array;
	}

}

Measured memory_bytes: 25844
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  string s;cin >>s;
  vector<pair<ll,ll>> v;
  ll cnt = 1LL;
  for(int i=0;i<s.size()-1;++i){
    if(s[i]==s[i+1]){
      ++cnt;
    } else{
      if(s[i]=='<'){
        v.push_back(make_pair(1LL,cnt));
      } else {
        v.push_back(make_pair(2LL,cnt));
      }
      cnt =1LL;
    }
  }
  if(s[s.size()-1]=='<'){
    v.push_back(make_pair(1LL,cnt));
  } else {
    v.push_back(make_pair(2LL,cnt));
  }
  vector<ll> out(s.size()+1,0);
  ll val = 0LL;
  int id = 0;
  for(int j=0;j<v.size();++j){
    if(v[j].first==1){
      for(ll k=0;k<v[j].second;++k){
        out[id] = val;
        ++id;
        ++val;
      }
      out[id] = val;
    } else {
      ll t =0LL;
      for(ll k=v[j].second;k>=0;--k){
        out[id+k] = max(t, out[id+k]);
        ++t;
      }
      val = 0LL;
      id += v[j].second;
    }
  }
  ll sum = 0LL;
  for(int l=0;l<out.size();++l){
    sum += out[l];
    //cout << out[l] << endl;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 8820
from math import ceil
from heapq import heappop,heappush

N,M = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x:x*(-1), a))
A = []

for a_ in a:
    heappush(A,a_) 

for _ in range(M):
  maxA = ceil(heappop(A)/2)
  A.append(maxA)
print(-sum(A))

Measured memory_bytes: 14380
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	string s;
	cin >> s;
	stack <char> st;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1')
			st.push('1');
		else if(s[i]=='0')
			st.push('0');
		else if(s[i]=='B'&&(!st.empty()))
			st.pop();
	}
	string temp="";
	while(!st.empty())
	{
		temp+=st.top();
		// cout << temp << "\n";
		st.pop();
	}
	reverse(temp.begin(),temp.end());
 	cout << temp;
}

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


int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << char(a[0] -32) << char(b[0] -32) << char(c[0] -32);
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int mx, ct, i;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> s;
    for (i = 0; i < s.length(); ++i)
        if (s[i] == 'S') {
            mx = max(mx, ct);
            ct = 0;
        } else
            ++ct;
    mx = max(mx, ct);
    cout << mx;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MEM 1000
#define sanic ios_base::sync_with_stdio(0)
using namespace std;
long long t,n,m;
string s;
int main()
{
    sanic;
    cin >> n >> m;
    for(int i=1; i<=50000; i++){
        int a=i*0.08;
        int b=i*0.1;
        if(n==a && m==b){
            cout << i;
            return 0;
        }
    }
    cout << -1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> vec(5);
  vector<int> x(5);
  int a=1e8;
  int ans=0;
  int cnt=0;
  for(int i=0;i<5;i++){
    cin>>vec[i];
    if(vec[i]%10==0){
      ans+=vec[i];
      cnt++;
    }
    else{
      ans+=vec[i]+10-vec[i]%10;
      a=min(a,vec[i]%10);
    }
  }
  if(cnt==5) cout<<ans<<endl;
  else cout<<ans-(10-a)<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   if(n < 0){
      cout << "0\n";
      return 0;
   }
   int z = n%100 , w= n/100;
   if(w*5 >= z)
      cout << "1\n";
   else
      cout << "0\n";
   return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;  cin >> N;
    vector<int> d(N+1);
    d[0] = 1000;
    for(int i=1; i<=N; i++) cin >> d[i];
    sort(d.begin(), d.end(), greater<int>());

    int ans=0;
    for(int i=1; i<=N; i++) if(d[i]!=d[i-1])ans++;

    cout << ans << endl;
    return 0;
}


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

using namespace std;

bool check(string s) {
	string ans = "AC";

	if (s[0] != 'A') {
		return false;
	}
	int C = 0;
	for (int i = 2; i < s.length() - 1; i++) {
		if (s[i] == 'C') {
			C++;
		}
	}
	if (C != 1) {
		return false;
	}


	int cnt = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] >= 'A' && s[i] <= 'Z') {
			cnt++;
		}
	}
	if (cnt != 2) {
		return false;
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	
	if (check(s)) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 110 , INF = 0x3f3f3f3f , MOD = 1e9+7;
const double PI = acos(0.0) * 2;
template<typename T1>
T1 gcd(T1 a , T1 b){ return b ? gcd(b,a%b) : a;}

char s[N] , ans[N];

int main(){
#ifdef LOCAL
    freopen("F:\\c++\\in.txt", "r", stdin);
//  freopen("F:\\c++\\out.txt","w",stdout);
#endif
    int n , rp = 0,top = 0;
    scanf("%d%s",&n,s);
    for(int i = 0 ; i < n ; i++){
        if( s[i] == '(' )   rp++ , ans[top++] = '(';
        else{
            if( rp > 0 )    rp--;
            else
                putchar('(');
            ans[top++] = ')';
        }
    }
    for(int i = 0 ; i < top ; i++)  putchar(ans[i]);
    while( rp-- )   putchar(')');
    puts("");
    return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




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

	int cur = 0;
	int ans = 1;

	REP(i, n) {
		int l;
		cin >> l;
		cur += l;
		if (cur <= x)ans++;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
s = input()
t = input()

s_sorted = sorted(s)
t_sorted = sorted(t, reverse=True)

result = 0
score = 0
for s_al, t_al in zip(s_sorted, t_sorted):
    if s_al > t_al:
        result = -1
        break
    elif s_al < t_al:
        result = 1
        break
if result == 0:
    result = -1 if len(s) >= len(t) else 1

print("Yes" if result == 1 else "No")


Measured memory_bytes: 3060
from math import ceil,sqrt,log,gcd,pi
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())

    
    
m=ii()
m=m%10
a=[2,4,5,7,9]
b=[0,1,6,8]
if m in a:
    print('hon')
elif m in b:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 61860
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

void p1()
{
	cout<<"First\n";
	exit(0);
}

void p2()
{
	cout<<"Second\n";
	exit(0);
}

int a[100001];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		sum+=(a[i]&1);
		sum%=2;
	}
	int n2 = n%2;
	if(n==1)
	{
		if(sum==n2) p2();
		else p1();
		return 0;
	}
	if(sum!=n2)
	{
		p1();
		return 0;
	}
	int turn = 1;
	while(1)
	{
		int cntodd = 0;
		int ex1 = 0;
		int sm = 0;
		int oddidx=0;
		for(int i = 0; i < n; i++)
		{
			if(a[i]&1) 
			{
				cntodd++;
				oddidx=i;
			}
			if(a[i]==1) ex1++;
			sm+=(a[i]&1);
			sm%=2;
		}
		if(sm!=n2&&!turn)
		{
			p2();
			return 0;
		}
		if(sm!=n2&&turn)
		{
			p1();
			return 0;
		}
		if(ex1>0||cntodd>1)
		{
			if(sm!=n2) 
			{
				if(turn) p1();
				else p2();
			}
			else 
			{
				if(!turn) p1();
				else p2();
			}
			return 0;
		}
		a[oddidx]--;
		int gcd = a[0];
		for(int i = 0; i < n; i++)
		{
			gcd=__gcd(a[i],gcd);
		}
		assert(gcd>1);
		for(int i = 0; i < n; i++)
		{
			a[i]/=gcd;
		}
		turn^=1;
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;

    vector<pair<int, int>> p(n);

    vector<vector<int>> a(n, vector<int>());
    for (int i = 0; i < n; i++) {
        int t, d;
        cin >> t >> d;
        t--;

        a[t].push_back(d);
        p[i] = { d, t };
    }

    for (int i = 0; i < n; i++) {
        if (a[i].empty()) continue;
        sort(a[i].begin(), a[i].end());
    }
    sort(p.begin(), p.end());

    vector<int> b(n);
    ll s = 0, c = 0;
    for (int i = n - k; i < n; i++) {
        if (b[p[i].second] == 0) c++;
        b[p[i].second]++;
        s += p[i].first;
    }
    s += c * c;

    ll r = s;
    vector<pair<int, int>> q;
    for (int i = 0; i < n; i++) {
        if (b[i] == 0 && !a[i].empty()) q.push_back({ a[i].back(), i });
    }
    if (!q.empty()) {

        sort(q.begin(), q.end());
        reverse(q.begin(), q.end());
        for (int i = 0; i < q.size(); i++) {
            q[i].first += (c + i) * 2 + 1;
        }

        int m = 0;
        for (int i = n - k; i < n; i++) {
            if (m >= q.size()) break;
            if (b[p[i].second] == 1) continue;
            s -= p[i].first;
            s += q[m].first;
            r = max(r, s);
            b[p[i].second]--;
            m++;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 7548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int A, P;
    cin >> A >> P;

    print((3 * A + P) / 2);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();

        int ans;
        if (x == y) {
            ans = x + y;
        } else if (x > y) {
            ans = x + (x - 1);
        } else {
            ans = y + (y - 1);
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
n, m=map(int, input().split())
a=[int(input()) for i in range(m)]
mod=10**9 +7
dp=[1]*(n+1)
dp[0]=1
dp[1]=1

for i in range(m):
    dp[a[i]] = 0

for i in range(2, n+1):
    
    if dp[i] > 0:
        dp[i]=dp[i-1]+dp[i-2]

print(dp[n]%mod)

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21720
#include <cstdio>
#include <vector>

using namespace std;

int c[100000];
int par[100000];
vector <int> v[100000];

int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    
    if (x == y) return;
    
    par[x] = y;
}

int dfs(int x, int y) {
    int i;
    
    c[x] = y;
    
    for (i = 0; i < v[x].size(); i++) {
        if (c[v[x][i]] == 0) {
            if (dfs(v[x][i], 3 - y) == 1) return 1;
        } else if (c[v[x][i]] == y) {
            return 1;
        }
    }
    
    return 0;
}

int main() {
    int n, m, c1 = 0, c2 = 0, c3 = 0, i;
    long long ans = 0;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < n; i++) par[i] = i;
    
    for (i = 0; i < m; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        unite(x, y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    for (i = 0; i < n; i++) {
        if (find(i) == i) {
            if (v[i].size() == 0) {
                c3++;
            } else if (dfs(i, 1) == 1) {
                c1++;
            } else {
                c2++;
            }
        }
    }
    
    ans += (long long)c1 * c1;
    ans += (long long)c2 * c2 * 2;
    ans += (long long)c1 * c2 * 2;
    ans += (long long)c3 * c3;
    ans += (long long)c3 * (n - c3) * 2;
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 7680
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

function lowerBound(ary,v,l=0,r=ary.length){--l;for(var c;1<r-l;)ary[c=l+r>>1]<v?l=c:r=c;return r;}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var k = next();
  var a = nexts(n);
  var ok = 1e9, ng = 0;
  while(ok-ng > 1){
    var m = ok+ng >>> 1;
    var sum = 0;
    for(var i = 0; i < n && sum <= k; i++){
      sum += Math.ceil(a[i]/m)-1;
    }
    if(sum <= k)ok = m;
    else ng = m;
  }
  return ok;
}

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll p,q,r;
    cin>>p>>q>>r;
    ll ans=min(p+q,min(q+r,p+r));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar xa (input-to-list (read-line)))
(format t "~d"
        (if (< (car xa) (cadr xa))
            0
            10))

Measured memory_bytes: 9824
#include <stdio.h>
#include <string.h>

#define M 1000003
#define L 14

char array[M][L];

int getChar(char c){
  if(c == 'A') return 1;
  if(c == 'C') return 2;
  if(c == 'G') return 3;
  if(c == 'T') return 4;
}

long long getKey(char c[]){
  long long sum = 0, p = 1, i;
  for( i = 0; i < strlen(c); i++){
    sum += p * getChar(c[i]);
    p *= 5;
  }
  return sum;
}

int hash1(int key, int m){
  return (key % m);
}

int hash2(int key, int m){
  return (1 + (key % (m - 1)));
}

void Insert(char c[], int m){
  int k, index, i = 0;
  int h1, h2;

  k = getKey(c);
  h1 = hash1(k, m);
  h2 = hash2(k, m);

  while(1){
    index = (h1 + i * h2) % m;
    if(array[index][0] == '\0'){
      strcpy(array[index], c);
      break;
    }else{
      i++;
    }
  }
}

int Search(char c[], int m){
  int k, index, i = 0;
  int flg = 0, h1, h2;

  k = getKey(c);
  h1 = hash1(k, m);
  h2 = hash2(k, m);

  while(1){
    index = (h1 + i * h2) % m;
  if(array[index][0] == '\0'){
    break;
  }else{
    if(strcmp(array[index], c) == 0){
      flg = 1;
      break;
    }
  }
  i++;
  }
  return flg;
}

int main(){
  int n, i;
  char str[L], com[9];
  for( i = 0; i < M; i++)array[i][0] = '\0';

    scanf("%d", &n);

    for( i = 0; i < n; i++){
    scanf("%s %s", com, str);

    if(com[0] == 'i'){
      Insert(str, M);
    }else {
      if(Search(str, M) == 1){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
    return 0;
}
      
      

Measured memory_bytes: 14280
/*
 Author : Alokit Kumar
 */
 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 int32_t main()
 {
   int t,n,i,j,k,l,l1;
   cin>>t;int s1=0,s2=0,s3=0,s4=0;
   while(t--)
   {
     string s;
     cin>>s;
     if(s=="AC") s1++;
     else if(s=="WA") s2++;
     else if(s=="TLE") s3++;
     else s4++;
   }
   cout<<"AC x "<<s1<<"\n";
   cout<<"WA x "<<s2<<"\n";
   cout<<"TLE x "<<s3<<"\n";
   cout<<"RE x "<<s4<<"\n";
 }

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
int main(){
  int a;
  string s;
  cin>>a>>s;
  if(a>=3200)cout<<s<<endl;
  else cout<<"red"<<endl;
}

Measured memory_bytes: 256
//doaremon,squirtle is love
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define testcase ll t;cin>>t;while(t--)
#define in(x) ll x;cin>>x;
#define output(x) cout<<x<<endl;//to print (-1)
#define inputarray() ll n;cin>>n;ll arr[n];rep(0,n)cin>>arr[i];
#define deb(a) cout<<" :: "<<#a<<" = "<<a<<endl
#define deb2(a,b) cout<<" :: "<<#a<<" = "<<a<<" :: "<<#b<<" = "<<b<<endl
#define setbit(x)  __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<long long int,long long int>
#define ub upper_bound // '>'
#define lb lower_bound // '>='
//erase,count,find,make_unique
#define len(arr) (sizeof(arr)/sizeof(arr[0]))
#define sz(x) ((long long)x.size())
#define make_unique(arr) arr.erase(unique(arr.begin(),arr.end()),arr.end()) //Makes a sorted array unique
#define rep(a,b) for(int i=a;i<b;i++)
#define updiv(a,b) (ceil)((a)*(1.0)/(b))
#define printarray(arr) cout<<"PRINT ARRAY"<<endl; rep(0,len(arr)) cout<<arr[i]<<" "; cout<<endl;
#define printvector(vect) cout<<"PRINT VECTOR"<<endl; for(auto x:vect) cout<<x<<" "; cout<<endl;
#define rev(x) reverse(all(x))
#define insideloop(x) cout<<x<<" "; cout<<endl;
//LLONG_MAX, ULLONG_MAX INT_MAX
typedef long long int ll;
typedef unsigned long long int ull;
#define M 1000000007
using namespace std;
int main()
{
    fast
     ll x;
     cin>>x;
     ll hap=(x/500)*1000;
     x=x%500;
     hap+=(x/5)*5;
     cout<<hap<<endl;
return 0;
}








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

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    
    if (n == 1) {
        ans = 0;
    }
    else {
        ans = (2 + (n - 1)) * (n - 2) / 2 + 1;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
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()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u32 = read();

    let mut min: u32 = 100000;
    for i in 0..(n + 1) {
        let mut tmp: u32 = 0;
        let mut a = i;
        while a > 0 {
            tmp += a % 6;
            a /= 6;
        }
        let mut b = n - i;
        while b > 0 {
            tmp += b % 9;
            b /= 9;
        }
        if tmp < min {
            min = tmp;
        }
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 


long long int N,Ma,M,a[100],b[100],c[100],res=0;
long long int cost[405][405]={};
string S;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>S>>M;
    for(long long int i = 0; i < N; i++){
        if(S[i]!=S[M-1]){S[i]='*';}
    }
    cout<<S<<endl;
}    


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
int main(void){
  long long int n;
  vector<long long int> a;
  cin>>n;
  int i,flag;
  long long int x,tmp,tmp2,res,res2;
  tmp=tmp2=res=res2=flag=0;
  for(i=0;i<n;i++){
    cin>>x;
    a.pb(x);
  }

  for(i=0;i<n;i++){
    if(flag==0){
      if(tmp+a[i]==0){
        tmp=-1;
        res+=1;
      }
      else if(tmp+a[i]>0){
        res+=abs(tmp+a[i])+1;
        tmp=-1;
      }
      else tmp+=a[i];

      if(tmp2+a[i]==0){
        tmp2=1;
        res2+=1;
      }
      else if(tmp2+a[i]<0){
        res2+=abs(tmp2+a[i])+1;
        tmp2=1;
      }
      else tmp2+=a[i];
      flag=1;
    }
    else{
      if(tmp+a[i]==0){
        tmp=1;
        res+=1;
      }
      else if(tmp+a[i]<0){
        res+=abs(tmp+a[i])+1;
        tmp=1;
      }
      else tmp+=a[i];

      if(tmp2+a[i]==0){
        tmp2=-1;
        res2+=1;
      }
      else if(tmp2+a[i]>0){
        res2+=abs(tmp2+a[i])+1;
        tmp2=-1;
      }
      else tmp2+=a[i];
      flag=0;
    }
  }
  if(res<res2) cout<<res<<endl;
  else cout<<res2<<endl;
  return 0;
}

Measured memory_bytes: 1400
import collections
N = int(input())
G = [set() for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)


F = [-1]*N
F[0] = 0
q = collections.deque()
q.append(0)
while(q):
    x = q.popleft()
    for y in G[x]:
        if F[y] < 0:
            F[y] = F[x] + 1
            q.append(y)

S = [-1]*N
S[N-1] = 0
q.append(N-1)
while(q):
    x = q.popleft()
    for y in G[x]:
        if S[y] < 0:
            S[y] = S[x] + 1
            q.append(y)
# print(F)
# print(S)
ans = 0

q = collections.deque()
r = [True]*N
for i in range(N):
    if F[i] + S[i] == F[-1]:
        if F[i] <= S[i]:
            q.append(i)
            r[i] = False
        else:
            r[i] = False
ans = len(q)

while(q):
    x = q.popleft()
    for y in G[x]:
        if r[y]:
            ans += 1
            q.append(y)
            r[y] = False

if ans > N - ans:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 43316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 505;
double dp[N][N];

int main(){
    int n,m;
    cin >>n >>m;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    fill(dp[0],dp[N],-1e9);
    dp[0][0] = 0;
    rep(i,n)rep(j,m){
        double s = 0;
        for(int k=i; k<n; ++k){
            s += a[k];
            dp[k+1][j+1] = max(dp[k+1][j+1], dp[i][j]+(s/(k-i+1)));
        }
    }

    double ans = 0;
    rep(i,m+1) ans = max(ans,dp[n][i]);
    printf("%.10f\n", ans);
    return 0;
}



Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  ll ans = 1900*M + 100*(N-M);
  ans = ans * pow(2, M);
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
long long g[3001][3001];
long long n;
long long mod;
long long quickpow(long long a,long long b,long long modd)
{
	if(a==0&&b==0) return 0LL;
	if(b==0) return 1LL;
	else if(b==1) return a%modd;
	else if(b%2==0) return quickpow(a*a%modd,b/2,modd)%modd;
	else return quickpow(a*a%modd,b/2,modd)*a%modd;
}
long long f[3001];
long long fac[3050];
long long Cnm(long long n,long long m)
{
	if(n<m||n<0||m<0) return 0LL;
	if(m==0||n==m) return 1LL;
	long long sex=(fac[n-m]*fac[m])%mod;
	long long sex1=(quickpow(sex,mod-2,mod))%mod;
	return sex1*fac[n]%mod;
}
long long ans;
int main()
{
	scanf("%lld %lld",&n,&mod);
	fac[0]=1;
	fac[1]=1;
	for(long long i=2;i<=3000;i++) fac[i]=(fac[i-1]*i)%mod; 
	for(int i=0;i<=n;i++)
	{
		g[i][0]=1LL;
		for(long long j=1;j<=i;j++)
		{
			g[i][j]=(g[i-1][j-1]+g[i-1][j]*(j+1LL)%mod)%mod;
		}
	}
	for(int i=0;i<=n;i++)
	{
		long long sex=quickpow(2,(n-i),mod);
		long long penis=1;
		for(int j=0;j<=i;j++)
		{
			f[i]=((f[i]+g[i][j]*penis%mod)%mod+mod)%mod;
			penis*=sex;
			penis%=mod;
		}
		long long x=quickpow(2,n-i,mod-1);
		x=quickpow(2,x,mod);
		f[i]=(f[i]*x)%mod;
	}
	for(int i=0;i<=n;i++)
	{
		if(i%2!=0) ans-=Cnm(n,(long long)i)*f[i]%mod;
		else ans+=Cnm(n,(long long)i)*f[i]%mod;
		ans=(ans+mod)%mod;
	}
	printf("%lld",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 47908
# include <iostream>

int main(){
	int x, y;
	for(int i = 0; i < 10000; i++){
		std::cin >> x >> y;
		if(x == 0 && y == 0)
			break;
		if( x > y)
			std::cout << y << " " << x << std::endl;
		else
			std::cout << x << " " << y << std::endl;
	}
	return 0;
}

Measured memory_bytes: 2980
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

    int n = sc.nextInt();

    long cnt = IntStream.range(1, n).filter(i -> i % 2 != 0).count();
    System.out.println((double) (n - cnt) / n);
  }
}

Measured memory_bytes: 26964
// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include<bits/stdc++.h>
using namespace std;
#define TEST  int test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007

int main()
{
	int a,b,c;
	si(a), si(b), si(c);
	if(b-a == c-b){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long a,b,c,d,e,f;
	
	scanf("%ld",&a);
	d = 1000000;
	e = -1000000;
	f = 0;
	
	for(b = 0;b < a;++b){
		scanf("%ld",&c);
		if(d >= c){
			d = c;
		}
		if(e <= c){
			e = c;
		}
		f += c;
	}
	
	printf("%ld %ld %ld\n",d,e,f);
	
	return(0);
}

Measured memory_bytes: 2752
#include <stdio.h>

int main(void)
{
  char str[200];
  int n;
  int count_r = 0;
  int count_b = 0;
  int i;
  scanf("%d", &n);
  scanf("%s", str);
  
  for(i = 0; i < n; i++) {
    if(str[i] == 'B') {
      count_b++;
    } else {
      count_r++;
    }
  }
  
  if(count_r > count_b) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(){
  char w[11], t[1000];
  unsigned int i,k,cnt=0,flag=0;

  scanf("%s",w);

  while(1){
    scanf("%s",t); 
    if(strcmp(t,"END_OF_TEXT") == 0) break;

    if(strlen(w)==strlen(t)){
      for(i=0; i<=strlen(t) - strlen(w); ++i){
	flag=0;
	if(w[0] == t[i] || w[0] == t[i] - 32 || w[0] == t[i] + 32){
	  for(k=0; k<strlen(w); ++k){
	    if(i+k<strlen(t)){
	      if(w[k] == t[i+k] || w[k] == t[i+k] - 32 || w[k] == t[i+k] + 32){
		if(k+1==strlen(w)){
		  ++cnt;
		  flag=1;
		  break;
		}
		continue;
	      }else break;
	    }else break;
	  }
	}
	if(flag) break;
      }
    }
  }

  printf("%d\n",cnt);


  return 0;
}



Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
 
ll num[55];
ll paty[55];
 

ll f(int level, ll x) {
  if(level == 0) {
    return x > 0 ? 1 : 0;
  }
  ll ret = 0;
  if(x >= num[level-1] + 2) {
    return paty[level-1] + 1 + f(level-1, x-num[level-1]-2);
  } else {
    return  f(level-1, x-1);
  }
}
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, X;
  cin >> N >> X;
  num[0] = 1;
  paty[0] = 1;
  FOR(i,1,55) {
    num[i] = 2 * num[i - 1] + 3;
    paty[i] = 2 * paty[i - 1] + 1;
  }
  cout << f(N, X) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N, Q;
	string S;
	cin >> N >> S >> Q;

	vll rd(N + 1, 0), rm(N + 1, 0), rc(N + 1, 0);

	repn(i, N) {
		rd[i] = rd[i - 1] + (S[i - 1] == 'D');
		rm[i] = rm[i - 1] + (S[i - 1] == 'M');
		rc[i] = rc[i - 1] + (S[i - 1] == 'C');
		//cout << rd[i] << rm[i] << rc[i] << endl;
	}

	repn(q, Q) {
		ll k;
		cin >> k;

		ll ans = 0;
		repn(i, N) {
			if (S[i - 1] == 'C') {
				ll x = max(0, i - k);
				ans += rm[i] * (rd[i] - rd[x]);
			}

			if (S[i - 1] == 'D') {
				ll x = min(N, i + k - 1);
				ans -= rm[i] * (rc[x] - rc[i - 1]);
			}

			//cout << ans << endl;
		}

		cout << ans << endl;
	}

	
}

Measured memory_bytes: 27728
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

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

    vector<pair<int, int>> ps(m);
    for (auto& p : ps) cin >> p.first >> p.second;
    ps.emplace_back(n + 1, n + 1);
    sort(ps.begin(), ps.end());

    int ans = n + 1;
    int l = 0, r = 0;
    for (auto p : ps) {
        if (r <= p.first) {
            ans += (r - l) * 2;
            l = r = p.first;
        }
        r = max(r, p.second);
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main() {

    int N, K;
    scanf("%d %d", &N, &K);

    int a[N];
    for (int i = 0; i < N; ++i) {
        scanf("%d", &a[i]);
    }

    sort(a, a + N);

    map<int, int> m;
    for (int i = 0; i < N; ++i) {
        if (m.find(a[i]) == m.end()) {
            m.insert(make_pair(a[i], 1));
        } else {
            map<int, int>::iterator it = m.find(a[i]);
            // printf("%d\n", it->second);
            m[a[i]] = it->second + 1;
        }
    }

    vector<int> v;
    for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
        v.push_back(it->second);
    }

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

    K = m.size() - K;

    int c = 0;
    if (K < 0) {
        printf("0\n");
    } else {
        for (int i = 0; i < K; ++i) {
            c += v[i];
        }

        printf("%d\n", c);
    }

    return 0;
}


Measured memory_bytes: 11516
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a:usize,
        b:usize,
        h:usize
    }
    println!("{}", (a+b)*h/2);
}


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

namespace Sample1
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] rts = new char[3];
            string str = Console.ReadLine();
            if(str.Length == 2)
            {
                Console.WriteLine($"{str}");
            }
            else if(str.Length == 3)
            {
                for(int i=0; i<str.Length; i++)
                {
                    rts[i] = str[str.Length-1-i];
                }
                Console.WriteLine(rts);
            }
        }
    }
}


Measured memory_bytes: 13140