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

typedef long long int ll;
#define    mod      1000000007
#define    speed    ios_base::sync_with_stdio(false);
#define    up       cin.tie(NULL);
#define    pb       push_back
#define    mp       make_pair
#define    T        int t; cin >> t; while(t--)

ll dp[5][100005];

int main(){
  speed up
  int n;
  cin >> n;
  for(int i = 1 ; i <= n; i++){
      cin >> dp[1][i] >> dp[2][i] >> dp[3][i];
      dp[1][i] = max(dp[2][i-1] + dp[1][i] , dp[3][i-1] + dp[1][i]);
      dp[2][i] = max(dp[1][i-1] + dp[2][i] , dp[3][i-1] + dp[2][i]);
      dp[3][i] = max(dp[2][i-1] + dp[3][i] , dp[1][i-1] + dp[3][i]);
  }
  cout << max (dp[1][n] , max(dp[2][n] , dp[3][n])) << '\n';
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

string solve(int M, const vector<int>& xs)
{
    int total = accumulate(xs.begin(), xs.end(), 0), ans = 0;

    for (int x : xs)
        if (x * 4 * M >= total)
            ++ans;

    return ans >= M ? "Yes" : "No";
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<int> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(M, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3652
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let a = get!(u32);
    let b = get!(u32);
    let c = get!(u32);
    let d = get!(u32);
    let v = vec![a+c, a+d, b+c, b+d];
    println!("{}", v.iter().min().unwrap());
}


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

using namespace std;

struct UnionFind {
	int n;
	vector<int> v;
	
	UnionFind(int n) : n(n){
		v.resize(n);
		fill(v.begin(), v.end(), -1);
	}
	
	int find(int x){
		if (v[x] < 0){
			return (x);
		}
		return (v[x] = find(v[x]));
	}
	bool same(int x, int y){
		return (find(x) == find(y));
	}
	void merge(int x, int y){
		x = find(x); y = find(y);
		if (x == y) return;
		v[y] += v[x];
		v[x] = y;
	}
	int size(int x){
		return (-v[find(x)]);
	}
};

int main()
{
	int n, m;
	
	while (scanf("%d %d", &n, &m) && n){
		int h[1024], a[200 * 200], b[200 * 200], c[200 * 200], d[200 * 200] = {0};
		int hrec[1024], alive[1024], dead[1024] = {0};
		
		for (int i = 0; i < n; i++){
			scanf("%d", h + i);
			hrec[i] = h[i];
			alive[i] = 0;
		}
		
		sort(hrec, hrec + n);
		
		for (int i = 0; i < m; i++){
			scanf("%d %d %d", a + i, b + i, c + i);
			--a[i]; --b[i];
		}
		int x = n - 2;
		
		for (int i = 0; i < n - 1; i++){
			if (hrec[i] == hrec[i + 1]) continue;
			UnionFind tmp(n);
			int v;
			
			for (int j = 0; j < n; j++){
				if (h[j] == hrec[i]) dead[j] = true;
				if (!dead[j]) v = j;
			}
			
			for (int j = 0; j < m; j++){
				if (!dead[a[j]] && !dead[b[j]]) tmp.merge(a[j], b[j]);
			}
			
			if (tmp.size(v) != n - i - 1){
				x = i;
				break;
			}
		}
		
		int tot = 0;
		
		UnionFind uf(n);
		priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > pq;
		
		for (int i = n - 1; i >= 0; i--){
			int tmp, cnt = 0;
			for (int j = 0; j < n; j++){
				if (hrec[i] == h[j]) alive[j] = true;
			}
			for (int j = 0; j < m; j++){
				if (alive[a[j]] && alive[b[j]] && !d[j]){
					d[j] = 1;
					pq.push(make_pair(c[j], make_pair(a[j], b[j])));
				}
			}
			if (i > x) continue;
			for (; !pq.empty(); pq.pop()){
				pair<int, pair<int, int> > x = pq.top();
				if (!uf.same(x.second.first, x.second.second)){
					uf.merge(x.second.first, x.second.second);
					tot += x.first;
				}
			}
		}
		
		if (uf.size(0) == n) printf("%d\n", tot);
		else printf("0\n");
	}
	
	return (0);
}

Measured memory_bytes: 2108
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str, W;
		int result = -1;// ?????????
		int sum = 0;// ????¨????

		W = scan.next().toLowerCase();

		while (true) {

			str = scan.next();

			// END_OF_TEXT??§????????????
			if (str.equals("END_OF_TEXT")) {
				break;
			}
			// END_OF_TEXT??????????????£????????????????????????????????§?°??????????
			str = str.toLowerCase();

			// 1????????????????????????0?????¨??????????????????
			result = str.indexOf(W);
			if ((result == 0) & (str.length() == W.length())) {
				sum++;
				result = -1;
			}
		}

		System.out.println(sum);

	}
}

Measured memory_bytes: 26176
n,m = map(int,input().split())
ac,wa = 0,0
d = {}
for i in range(m):
  p,s = input().split()
  if p in d:
    if d[p][1]:
      pass
    else:
      if s=="WA":
          d[p][0]+=1
      elif s=="AC":
          d[p][1]=True
          ac+=1
          wa+=d[p][0]
  else:
    if s=="WA":
      d[p]=[1,False]
    elif s=="AC":
      d[p]=[0,True]
      ac+=1
print(ac,wa)

Measured memory_bytes: 25312
def partition(arr, p, r)
  q = arr[r]
  i = p - 1 # ????????????
  for j in p..(r - 1) # ??????????±?
    if arr[j] <= q then
      i = i + 1
      tmp = arr[i]
      arr[i] = arr[j]
      arr[j] = tmp
    end
  end
  z = i + 1
  tmp = arr[z]
  arr[z] = arr[r]
  arr[r] = tmp
  arr[z] = "[#{arr[z]}]"
  puts arr.join(' ')
  z
end


n = STDIN.gets.to_i
arr = STDIN.gets.split(' ').map { |x| x.to_i }

partition(arr, 0, arr.size - 1)

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int num = 0;
    int max = 0;
    for (string::iterator itr = S.begin(); itr != S.end(); itr++)
    {
        if (*itr == 'I')
        {
            num++;
        }else
        {
            num--;
        }
        
        if (num > max) max = num;

    }
    
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    map<string,int> mp;
    for(ll i=0;i<n;i++)
    {
        string x;
        cin>>x;
        mp[x]++;
    } 
        cout<<"AC"<<" x "<<mp["AC"]<<endl;
        cout<<"WA"<<" x "<<mp["WA"]<<endl;
        cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
        cout<<"RE"<<" x "<<mp["RE"]<<endl;
        
        
    }

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int N, K;
    scanf("%d %d", &N, &K);
    if(2*K - 1 <= N) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

using namespace std;

int d[110];

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; ++i) {cin >> d[i];}
  int ans = 0;
  int cnt = 0;
  for(int i = 0; i < N-1; ++i) {
    for(int j = i+1; j < N; ++j) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,st,e;
    string u;
    cin>>u;
    int l=u.length();
    for(int i=0;i<l;i++)
    {
        if(u[i]=='A')
        {
            st=i+1;
            break;
        }
    }
    for(int i=0;i<l;i++)
    {
        if(u[i]=='Z')
        {
            e=i+1;
        }
    }
    x=e-st+1;
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = k;

		for(int i=0; i<n-1; i++){
			ans *= k-1;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 9796
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define itrep(itr, base) for (auto itr = base.begin(); itr != base.end(); itr++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char 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;}

int main() {
  string t;
  cin >> t;
  int ans = 0;
  rep (i, t.size()) {
    if (t[i] == '?') t[i] = 'D';
  }
  P(t);
  return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


signed main(){ 
    char c; cin>>c;

    if(c>=97){
        cout<<'a'<<endl;
    }else{
        cout<<'A'<<endl;
    }
}  

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

bool check(const vl& L,const ll& N){
	FOR(i,0,N-1)if(L[i+1] < L[i])return 0;
	return 1;
}

vl Sort(vl L,ll N){
	random_device rnd;
	while(!check(L,N)){
		ll a = rnd()%N;
		ll b = rnd()%N;
		if(a-b)swap(L[a],L[b]);
	}
	return L;
}

signed main(){
	ll N;
	cin >> N;
	vl L(N);
	FOR(i,0,N)cin >> L[i];
	vl ans = Sort(L,N);
	ll SUM = 0;
	DEBUG(ans)
	FOR(i,0,N)SUM += ans[i];
	Yes(SUM-ans[N-1] > ans[N-1]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a;
  set<int> st;
  for (int i = 1; i * i <= 1000; i++)
    a.push_back(i);

  while (a[1] <= 1000)
  {
    for (int i = 0; i < a.size(); i++)
    {
      a[i] *= i + 1;
      if (a[i] > 1000)
        break;
      st.insert(a[i]);
    }
  }
  int ans = 1;
  for (int i = N; i >= 1; i--)
  {
    if (st.find(i) != st.end())
    {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int posi(long long x){
	if(x>0)return 1;
	if(x<0)return -1;
	return 0;
}

int main(){
	int N;
	cin >> N;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	long long ans=0,tmp=0;
	long long sum=a[0];
	if(a[0]==0){
		tmp=1;
		sum=-1;
	}
	for(int i=1;i<N;i++){
		if(posi(sum+a[i])*posi(sum)!=-1 || sum+a[i]==0){
			tmp+=abs(sum+a[i])+1;
			sum=(sum>0)?-1:1;
		}
		else sum+=a[i];
	}
	ans=tmp;
	
	tmp=abs(a[0])+1;
	sum=(a[0]>0)?-1:1;
	for(int i=1;i<N;i++){
		if(posi(sum+a[i])*posi(sum)!=-1 || sum+a[i]==0){
			tmp+=abs(sum+a[i])+1;
			sum=(sum>0)?-1:1;
		}
		else sum+=a[i];
	}
	ans=min(ans,tmp);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#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 watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ll n,k,mini=1e6,maxi=-1e6,sum=0;
	cin>>n;
	for (ll i=0;i<n;i++) {
		cin>>k;
		mini=min(mini,k);
		maxi=max(maxi,k);
		sum+=k;
	}
	cout<<mini<<' '<<maxi<<' '<<sum<<endl;
}
	


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int l;
    cin >> l;

    double d = (l * 1.0) / 3;
    cout << fixed << setprecision(10) << d * d * d << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s == "MON") cout << 6;
  if (s == "TUE") cout << 5;
  if (s == "WED") cout << 4;
  if (s == "THU") cout << 3;
  if (s == "FRI") cout << 2;
  if (s == "SAT") cout << 1;
  if (s == "SUN") cout << 7;
	return 0;
}


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

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    cout << (y % 2 == 0 && x * 2 <= y && y <= x * 4 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 

vector<int> v;
int main() {
  long long n;
  cin >> n;
  int tmp;
  for(int i = 0;i <n;i++){
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end());
  vector<int> l(100001,0);
  int c = 0;
  int t;
  for(int i = 0;i<n;i++){
    c = 1;
    t = v[i];
    
    while(t == v[i+1]){
      c+=1;
      i+=1;
    }
    l[t] = c;
  }
  int q;
  cin >> q;
  
  int x,y;
  
  ll res = 0;
  for(int i = 1;i<100001;i++){
    res += i*l[i];
  }
  //cout << res << endl;
  for(int i = 0;i<q;i++){
    cin >> x >> y;
    //cout << x << " " << y << endl;
    //cout << (l[x]+l[y])*y << " " << l[x]*x << endl;
    res += l[x]*y -l[x]*x;
    cout << res << endl;
    l[y] += l[x];
    l[x] = 0;
  }
  
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#include<cstdio>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<set>
#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)
#define INF9                1000000010
#define INF18               1000000000000000010
#define dist(ax,ay,bx,by)   sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define gcd(a,b)            __gcd(a,b)
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define m_p(a,b)            make_pair(a,b)
#define sqr(a)              ((a)*(a))
#define pb                  push_back
#define bpll(a)             __builtin_popcountll(a)
#define MX                  100006
#define PI                  acos(-1)
#define mod                  1000000007
#define cnt_bin(n)          __builtin_clzll(0ll) - __builtin_clzll(n)

typedef long long lli;
using namespace std;

string s,t;

int main()
{
    cin>>s>>t;

    lli ans= INF9;
    bool flag= true;

    for(lli i=0; i<s.size() && flag; i++)
    {
        lli cnt=0;

        for(lli j=i, k=0; k<t.size() && flag; k++, j++)
        {
            if(j>=s.size())
            {
                flag=false;
                break;
            }

            if(s[j]!=t[k]) cnt++;
        }

        if(flag) ans= min(ans, cnt);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3628
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1);
  var n = s.length;
  var ans = xArray(1,n);
  for(var i = 0; i < n; i++){
    if(s[i] === "R"){
      if(s[i+1] === "L")continue;
      ans[i+2] += ans[i];
      ans[i] = 0;
    }
  }
  for(var i = n; i--;){
    if(s[i] === "L"){
      if(s[i-1] === "R")continue;
      ans[i-2] += ans[i];
      ans[i] = 0;
    }
  }
  return ans.join(" ");
}

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

int arr[1000];
int pointer = 0;
void push(int num){
    arr[pointer++] = num;
}

int pop() {
    if(pointer < 0) return 0;
    int val = arr[--pointer];
    return val;
}

int main(void){
    // Your code here!
    char s[10];
    int v1, v2;
    while(true){
        if(scanf("%s", s) == EOF) break;
        if(s[0] == '+'){
            v1 = pop();
            v2 = pop();
            push(v1+v2);
        } else if(s[0] == '-') {
            v1 = pop();
            v2 = pop();
            push(v2-v1);
        } else if(s[0] == '*') {
            v1 = pop();
            v2 = pop();
            push(v1*v2);
        } else{
            push(atoi(&s[0]));
        }
    }
    
    cout << arr[pointer-1] << endl;
    /*
    while(scanf("%s", s) != EOF){
        cout << scanf("%s", s) << endl;
        if(s[0] == '+'){
            v1 = pop();
            v2 = pop();
            push(v1+v2);
        } else if(s[0] == '-') {
            v1 = pop();
            v2 = pop();
            push(v2-v1);
        } else if(s[0] == '*') {
            v1 = pop();
            v2 = pop();
            push(v1+v2);
        } else{
            push(atoi(&s[0]));
        }
    }
    cout << arr[pointer] << endl;*/
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Y "YES\n"
#define N "NO\n"
#define pi acos(-1.0)
#define pb push_back
#define lcm (a*b)/__gcd(a,b)
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
	    int a;
	    cin>>a;
	    cout<<a+(a*a)+(a*a*a);
	    //cout<<Y;
	    //cout<<N;
	}
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int main(){
  double ans;
  double a,b,x;
  cin>>a>>b>>x;
  if(2*(a*a*b-x)/(a*a*a)<b/a){
    ans=atan(2*(a*a*b-x)/(a*a*a));
    cout<<fixed<<setprecision(7)<<ans*180.0/M_PI<<endl;
  }
  else{
    ans = atan(b*b*a/2/x);
    cout<<fixed<<setprecision(7)<<ans*180.0/M_PI<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
 public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
   
  String a=sc.next();
  String b=sc.next();
   
  if(a.equals("H") && b.equals("H")){
   System.out.println("H");
  }else if(a.equals("H") && b.equals("D")){
   System.out.println("D");
  }else if(a.equals("D") && b.equals("H")){
   System.out.println("D");
  }else if(a.equals("D") && b.equals("D")){
   System.out.println("H");
  }
 }
}

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

int main(){
    int n,k = 0;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    // bool flag = 1;

    // if (n==1) {
    //     flag = 0;
    // }
    // int dummy = 0;
    // while(flag){
    //     flag = 0;
    //     rep(i,n-1){
    //         if (a[i] > a[i+1]){
    //             dummy = a[i];
    //             a[i] = a[i+1];
    //             a[i+1] = dummy;
    //             flag = 1;
    //         }

    //     }
    // }
    sort(a.begin(),a.end());
    int ans = 0;
    rep(i,k)ans += a[i];
    cout << ans <<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,m;
    cin >> n >> m;
    if(n>2 && m>2)cout << (n-2)*(m-2) << endl;
    else if(n==1 && m==1)cout << 1 << endl;
    else if(min(n,m)==1 && max(n,m)>1)cout << max(n,m)-2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	x = 0
	for i in 1:n
		x = xor(x,a[i])
	end
	for i in 1:n-1
		print(xor(a[i],x)," ")
	end
	println(xor(a[n],x))
end

main()

Measured memory_bytes: 202856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct UnionFind {
    vector<int> par, s;
    UnionFind(int n=2e5) { init(n); }
    void init(int n) { 
        s.assign(n, 1); par.resize(n); 
        iota(par.begin(), par.end(), 0);
    }
    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;
        if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
        else par[y] = x, s[x] = s[x] + s[y];
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return s[find(x)]; }
};

bool memo[1005][1005][2], dp[1005][1005][2];
int main(void) {
    ll n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) cin >> s[i];

    ll m = 0;
    UnionFind uf(n);
    REP(i, n) FOR(j, i+1, n) if(s[i][j] == 'Y') uf.unite(i, j), m++;
    ll odd = 0, even = 0, rest = 0;
    REP(i, n) if(uf.find(i) == i) {
        ll sz = uf.size(i);
        if(sz%2) odd++;
        else even++;
        rest ^= sz*(sz-1)/2%2;
    }
    rest ^= m%2;

    function<bool(ll,ll,ll)> dfs = [&](ll x, ll y, ll z) {
        if(memo[x][y][z]) return dp[x][y][z];
        if(x+y==2) return z==1;

        bool ret = false;
        if(x+y>2 && x>=1) ret |= !dfs(x-1, y, !z);  // 偶数同士
        // ret |= !dfs(x-1, y, z);                  // 偶数と奇数
        if(x+y>2 && y>=2) ret |= !dfs(x+1, y-2, z); // 奇数同士
        if(z==1) ret |= !dfs(x, y, !z);             // 同じ連結成分内の辺

        memo[x][y][z] = true;
        dump(x, y, z, ret);
        return dp[x][y][z] = ret;
    };
    bool ret = dfs(even, odd, rest);

    if(ret) cout << "Taro" << endl;
    else cout << "Hanako" << endl;

    return 0;
}


Measured memory_bytes: 6180
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
import heapq
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,M):
    kouho_list = [[] for i in range(M+1)]
    for i in range(len(A)):
        if(A[i]<=M):
            kouho_list[A[i]].append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

kouho_list = kouho(A,B,M)
for m in range(1,M+1):
    kouho_ = kouho_list[m]
    add(q,kouho_)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)

Measured memory_bytes: 23128
n,m = map(int,input().split())
l = [-1]*(m)
r = [-1]*m
for i in range(m):
    a,b = map(int,input().split())
    l[i]=a
    r[i]=b
right = n
left = 0 
#print(r)
#print(l)
count = 0
k = 0
for i in range(m):
    right = min(r[i],right)
    left = max(l[i],left)

ans = max(0,right -left +1)
print(ans)


Measured memory_bytes: 10868
//Ash180-AtCoder:6 ~ Revisited ~ saira D - Replacing [Beginner Contest 171]
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define clock cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
#define forie(a,n) for(int i=(a);i<=(n);i++)
#define forje(b,m) for(int j=(b);j<=(m);j++)
#define forke(c,g) for(int k=(c);k<=(g);k++)
#define ffe(a,n,b,m) forie(a,n) forje(b,m)
#define fori(n) for(int i=0;i<n;++i)
#define forj(n) for (int j=0;j<n;++j)
#define fork(n) for (int k=0;k<n;++k)
#define rev(s)  reverse(s.begin(), s.end()) 
#define initblock(v,d) memset(v,d,sizeof(v))
#define ll long long
#define ull unsigned long long
#define re return 
using namespace std;
void Ash() 
{ 	
#ifndef ONLINE_JUDGE 
freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); freopen("output.txt", "w", stdout); 
#endif 
}

void solve()
{
	ll freq[100001] = { 0 };
	ll n, x, q, a, b, sum = 0; cin >> n;
	fori(n) cin >> x, ++freq[x], sum += x;
	cin >> q;
	fori(q)
	{
		cin >> a >> b;
		if (freq[a] != 0)
		{
			sum += freq[a]*(b-a);
			freq[b] += freq[a];
			freq[a] = 0;
		}
		cout << sum << "\n";
	}
}

int main() { fast; Ash(); solve(); clock; return 0; } 


Measured memory_bytes: 4580
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

  static int mod = 1000000007;

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int island = cin.nextInt();
    int bridge = cin.nextInt();
    UnionFind UF = new UnionFind(island);

    int[][] connect = new int[bridge][2];

    for (int i=0;i<bridge;i++) {
      int a = cin.nextInt();
      int b = cin.nextInt();
      connect[i][0] = a-1;
      connect[i][1] = b-1;
    }
    long[] res = new long[bridge+1];
    res[bridge] = (long)island*(island-1)/2;
    for (int i=bridge - 1;i>=0;i--) {

      if (UF.find(connect[i][0])==UF.find(connect[i][1]))
        res[i] = res[i+1];
      else {
        res[i] = res[i+1] - (long)UF.size(connect[i][0])*UF.size(connect[i][1]);
        UF.union(connect[i][0], connect[i][1]);
      }

    }

    for (int i=1;i<res.length;i++ ) {
      System.out.println(res[i]);
    }

  }

  //TODO: UnionFind好好学习！
  public static class UnionFind {
    int[] par;
    int[] rank;
    int[] size;

    UnionFind(int n) {
      par = new int[n];
      rank = new int[n];
      size = new int[n];
      for (int i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
        size[i] = 1;
      }
    }

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

    void union(int x, int y) {
      x = find(x);
      y = find(y);
      if (x == y) {
        return;
      }
      if (rank[x] < rank[y]) {
        par[x] = y;
        size[y] += size[x];
      } else {
        par[y] = x;
        size[x] += size[y];
        if (rank[x] == rank[y]) {
          rank[x]++;
        }
      }
    }

    boolean same(int x, int y) {
      return find(x) == find(y);
    }

    int size(int x) {
      return size[find(x)];
    }
  }


}


Measured memory_bytes: 102356
#include <stdio.h>
int c_digit(int a){
  int c=0;
  int i;
  while(a!=0){
    c++;
    a=a/10;
  }
  return c;
}
int main(){
  int a,b;
  int sum;
  while(scanf("%d %d",&a,&b)!=EOF){
    sum=c_digit(a+b);
    printf("%d\n",sum);
  }
    return 0;
}

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

int main() {
  int k, s, ans = 0;
  cin >> k >> s;
  for (int i=0;i<=k;i++) {
    for (int j=0;j<=k;j++) {
      if (0 <= s - i - j && s - i - j <= k) ans++;
    }
  }
  
  cout << ans << '\n';
  return 0;
}

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


int main() {
    string s,t;
    cin>>s>>t;
    int count=0;
    rep(i,s.size()){
        if(s.at(i)!=t.at(i)){
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll i,o,t,j,l,s,z;
	cin>>i>>o>>t>>j>>l>>s>>z;

	ll ans = 0;
	ans += 2*o;

	ll ijl = min(min(i,j),l);
	ll res = 0;
	if(ijl>0){ // ijlを１個使う
		res += 6 + ((i-1)/2)*4 + ((j-1)/2)*4 + ((l-1)/2)*4;
	}

	ans += max(res,(i/2)*4 + (j/2)*4 + (l/2)*4);
	cout << ans/2 << endl;

	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt=1;
	char l=s[0];
	for(int i=1; i<n; i++)
	{
		if(s[i]!=l) cnt++, l=s[i];
	}
	cout<<cnt;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

const int MAX_V = 105;
int d[MAX_V][MAX_V];

struct Road {
  int from;
  int to;
  int cost;
};
vector<Road> roads;

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

  int n, x;
  cin >> n >> x;

  map<int, int> tokubetu;
  map<int, bool> isTokubetu;

  
  if (n <= 2 && x == n) {
    cout << "Yes" << endl;
    rep(i, n*2-1) {
      cout << i+1 << " ";
    }
    cout << endl;
  } else if (x > 1 && x < 2*n-1) {
    cout << "Yes" << endl;
    int idx = 1;
    if (x < n) {
      tokubetu[n-3] = x+2; 
      tokubetu[n-2] = x; 
      tokubetu[n-1] = x-1; 
      tokubetu[n] = x+1;

      isTokubetu[x+2] = true;
      isTokubetu[x+1] = true;
      isTokubetu[x] = true;
      isTokubetu[x-1] = true;
    } else {
      tokubetu[n-3] = x-2; 
      tokubetu[n-2] = x; 
      tokubetu[n-1] = x+1; 
      tokubetu[n] = x-1;

      isTokubetu[x-2] = true;
      isTokubetu[x-1] = true;
      isTokubetu[x] = true;
      isTokubetu[x+1] = true;
    }
    rep(i, 2*n-1) {
      if (tokubetu[i]) {
        cout << tokubetu[i] << " ";
      } else {
        while(isTokubetu[idx]) idx++;
        cout << idx << " ";
        idx++;
      }
    }
    cout << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 20224
#include <stdio.h>
#define N 200000

int a[N] = { 0 };
int b[N] = { 0 };

int main(void) {
	int n, m;
	int x, y;

	scanf("%d %d", &n,&m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		if (x == 1) a[y]++;
		if (y == n) b[x]++;
	}
	for (int i = 1; i < n; i++) {
		if ((a[i] != 0) && (b[i] != 0)) {
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool operator==(const mint& a, const mint& b) { return a.x == b.x;}

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

    int n, k;
    cin >> n >> k;
    vector<mint> cnt(k+1);
    for (int i = 1; i <= k; ++i) {
        cnt[i] = mint(k / i).pow(n);
    }

    mint ans = 0;
    for (int i = k; i >= 1; --i) {
        for (int j = 2; i * j <= k; ++j) {
            cnt[i] -= cnt[i*j];
        }
        ans += mint(i) * cnt[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3968
#include <stdio.h>

#define SQ(x) ((x) * (x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))

int main(void)
{
	int len, wid, hite;
	int r;
	int n;
	
	while (1){
		int couch;
		scanf("%d%d%d", &len, &wid, &hite);
		
		if (len == 0){
			break;
		}
		
		couch = MIN(SQ(len) + SQ(wid), MIN(SQ(len) + SQ(hite), SQ(wid) + SQ(hite)));
		
		scanf("%d", &n);
		
		for (int i = 0; i < n; i++){
			scanf("%d", &r);
			
			if (couch < SQ(2 * r)){
				puts("OK");
			}
			else {
				puts("NA");
			}
		}
	}
	
	return (0);
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

long long rec(int n, ll x)
{
  if (n == 0)
    return 1;
  ll len = (1LL << (n + 1)) - 3; // レベルn-1のバーガーの層数
  ll num = (1LL << n) - 1;       // レベルn-1のパティの数
  if (x == 1)
    return 0;
  else if (x <= len + 1)
    return rec(n - 1, x - 1); // 一番下のパン + その上のレベルN - 1バーガーの下からx - 1層
  else if (x == len + 2)
    return num + 1; // 一番下のパン + その上のレベルN - 1バーガー + その上のパティ
  else if (x <= (len + 1) * 2)
    return num + 1 + rec(n - 1, x - (len + 2)); // 前のやつ + その上のレベルN - 1バーガーの下からX - (len + 2)層
  else
    return num * 2 + 1; // 全て
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  ll X;
  cin >> N >> X;
  cout << rec(N, X) << endl;
  return 0;
}

Measured memory_bytes: 256
N, S = gets.split.map(&:to_i)
xs, ps = N.times.map{gets.split.map(&:to_i)}.transpose

pts = []
while xs.size > 0
    if S <= xs[0]
        pts.push(xs.pop)
    elsif xs[-1] <= S
        pts.push(xs.shift)
    elsif ps[0] >= ps[-1]
        ps[0] += ps[-1]
        pts.push(xs.pop)
        ps.pop
    else
        ps[-1] += ps[0]
        pts.push(xs.shift)
        ps.shift
    end
end
pts.push(S)

ans = 0
N.times do |i|
    ans += (pts[i] - pts[i+1]).abs
end
puts ans

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  if(n == 3) {
    cout << 2 << " " << 5 << " " << 63 << endl;
    return 0;
  }
  if(n == 4) {
    cout << 2 << " " << 5 << " " << 20 << " " << 63 << endl;
    return 0;
  }
  int sum = 54;
  vector<int> v;
  int i = 3;
  map<int, int> mp;
  v.pb(22);
  v.pb(27);
  v.pb(5);
  mp[22] = 1;
  mp[27] = 1;
  mp[5] = 1;
  while(v.size() < n && i < 20000) {
    if(mp[i]) {
      i++;
      continue;
    }
    if(i % 2 == 0 && i % 3 != 0 && i % 5 != 0) {
      mp[i] = 1;
      v.pb(i);
      sum += i;
    }
    if(i % 2 != 0 && i % 3 == 0 && i % 5 != 0) {
      mp[i] = 1;
      v.pb(i);
      sum += i;
    }
    if(i % 2 != 0 && i % 3 != 0 && i % 5 == 0) {
      mp[i] = 1;
      v.pb(i);
      sum += i;
    }
    i++;
  }
  i = 3;
  while(v.size() < n) {
    if(mp[i]) {
      i++;
      continue;
    }
    if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0) {
      mp[i] = 1;
      v.pb(i);
      sum += i;
    }
    i++;
  }
  int am = 30 - (sum % 30);
  while(am != 0) {
    if(am >= 5) {
      am -= 5;
      dep(i, n - 1, 0) {
        if(v[i] % 5 == 0) {
          mp[v[i] + 5] = 1;
          mp[v[i] - 5] = 0;
          v[i] += 5;
          break;
        }
      }
    }else if(am >= 3) {
      am -= 3;
      dep(i, n - 1, 0) {
        if(v[i] % 3 == 0) {
          if(mp[v[i] + 3]) continue;
          mp[v[i] + 3] = 1;
          mp[v[i] - 3] = 0;
          v[i] += 3;
          break;
        }
      }
    }else if(am >= 2) {
      am -= 2;
      dep(i, n - 1, 0) {
        if(v[i] % 2 == 0) {
          if(mp[v[i] + 2]) continue;
          mp[v[i] + 2] = 1;
          mp[v[i] - 2] = 0;
          v[i] += 2;
          break;
        }
      }
    }else {
      dep(i, n - 1, 0) {
        if(v[i] % 3 == 0) {
          if(mp[v[i] + 3]) continue;
          mp[v[i] + 3] = 1;
          mp[v[i] - 3] = 0;
          v[i] += 3;
          break;
        }
      }
      rep(i, 0, n) {
        if(v[i] % 2 == 0) {
          if(mp[v[i] - 2]) continue;
          mp[v[i] - 2] = 1;
          mp[v[i] + 2] = 0;
          v[i] -= 2;
          break;
        }
      }
      break;
    }
  }
  rep(i, 0, n) {
    cout << v[i] << " ";
  }
  cout << endl;
}


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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int n, m;
string M[10];

int dfs(int x, int y)
{
    M[x][y] = '.';
    if(x != n-1 && M[x+1][y] == '#') dfs(x+1, y);
    else if(y != m-1 && M[x][y+1] == '#') dfs(x, y+1);
}

int main()
{
    in >> n >> m;
    REP(i, n) in >> M[i];

    dfs(0, 0);

    bool flag = true;
    REP(i, n) REP(j, m) if(M[i][j] == '#') flag = false;

    out << (flag ? "Possible" : "Impossible") << "\n";

    return 0;
}


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

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)

using namespace std;
using ll = long long;
using pos = pair<ll, ll>;

ll h, w, n;
vector<ll> a;

void solve();

int main() {

   solve();
   return 0;

}

void solve() {

	cin >> h >> w >> n;
	a.resize(n+1);
	FOR(i, 1, n + 1) {
		cin >> a[i];
	}

	pos p = make_pair(0, 0);
	vector<vector<ll>> v(w);
	for (auto& x : v) {
		x.resize(h);
		for (auto& y : x) {
			y = -1;
		}
	}
	vector<ll> dx = { 1,0,-1,0 };
	vector<ll> dy = { 0,1,0,-1 };
	ll dp = 0;
	ll cc = 1;
	ll gnum = h*w;
	
	FOR(i, 1, n + 1) {
		while (a[i]) {
			v[p.first][p.second] = cc;
			a[i]--;
			gnum--;
			if (gnum) {
				while (1) {
					if (-1 < p.first + dx[dp] && p.first + dx[dp] < w && -1 < p.second + dy[dp] && p.second + dy[dp] < h && v[p.first + dx[dp]][p.second + dy[dp]] == -1) {
						p.first += dx[dp];	p.second += dy[dp];
						break;
					}
					else {
						dp == 3 ? dp = 0 : dp++;
					}
				}
			}
		}
		cc++;
	}

	REP(i, h) {
		REP(j, w) {
			cout << v[j][i] << (j == (w - 1) ? "\n" : " ");
		}
	}


}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n) - 1; i >= k; i--)

#define debug(x) cerr <<#x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;
const ll inf = 900900900100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int MID = 255;
using namespace std;

int main(){
    ll n,x,a,b,c;
    while(cin >> n >> a >> b >> c >> x,n) {
        int f = 0;
        int y[110] = {};
        rep(i,n) cin >> y[i];
        int k = 0;
        rep(i,10001) {
            if(x == y[k]) k += 1;
            if(k >= n) break;
            x = (a * x + b) % c;
            f++;
        }
        if(f > 10000) cout << -1 << endl;
        else cout << f << endl;
    }
    return 0;
}



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

int main(){
	string n;
	cin>>n;
	char start=n[0];
	string ans;
	for(int i=1;i<4;i++){
		if(n[i]==start){
			ans="Bad";
			break;
		}
		start=n[i];
		ans="Good";
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    
    size_t size = s.length();
    int A = 0;
    int Z = 0;
    
    for(int i=0;i<size;i++){
        if(s[i]=='A'){
            A = i;
            break;
        }
    }
    for(int i=0;i<size;i++){
        if(s[i]=='Z'){
            Z = i;
        }
    }
    
        cout << Z-A+1 << endl;
        return 0;
}


Measured memory_bytes: 640