akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5+5;
ll n, q, pref[nax];
string a;

int main(){
	IOS
	pref[-1]=0;
	cin >> n >> q >> a;
	for(int i=1;i<n;i++){
		if(a[i]=='C'&&a[i-1]=='A'){\
			pref[i]=pref[i-1]+1;
		}
		else{
			pref[i]=pref[i-1];
		}
	}
	while(q--){
		ll l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << pref[r]-pref[l] << '\n';
	}
}


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

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

#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back

const int INF = 1e9;

int main() {
	int n;
	cin >> n;
	int a, b, c;
	cin >> a >> b >> c;
	string s[100010];
	vector<char> ans;
	rep(i, n) cin >> s[i];
	if(a+b+c!=2)
	{
		rep(i, n)
		{
			if(s[i]=="AB")
			{
				if(a>=b)
				{
					ans.pb('B');
					a--;
					b++;
				}
				else
				{
					ans.pb('A');
					b--;
					a++;
				}
			}
			else if(s[i]=="AC")
			{
				if(a>=c)
				{
					ans.pb('C');
					a--;
					c++;
				}
				else
				{
					ans.pb('A');
					c--;
					a++;
				}
			}
			else
			{
				if(b>=c)
				{
					ans.pb('C');
					b--;
					c++;
				}
				else
				{
					ans.pb('B');
					c--;
					b++;
				}
			}
			if(a<0 || b<0 || c<0)
			{
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		rep(i, n) cout << ans[i] << endl;
		return 0;
	}

	rep(i, n)
	{
		if(s[i]=="AB")
		{
			if(a==0 && b==0)
			{
				cout << "No" << endl;
				return 0;
			}
			else if(i<n-1 && a==1 && b==1)
			{
				if(s[i+1]=="AB")
				{
					ans.pb('B');
					a--;
					b++;
				}
				else if(s[i+1]=="AC")
				{
					ans.pb('A');
					b--;
					a++;
				}
				else
				{
					ans.pb('B');
					a--;
					b++;
				}
			}
			else
			{
				if(a<=b)
				{
					ans.pb('A');
					a++;
					b--;
				}
				else
				{
					ans.pb('B');
					b++;
					a--;
				}
			}
		}
		else if(s[i]=="AC")
		{
			if(a==0 && c==0)
			{
				cout << "No" << endl;
				return 0;
			}
			else if(i<n-1 && a==1 && c==1)
			{
				if(s[i+1]=="AC")
				{
					ans.pb('C');
					a--;
					c++;
				}
				else if(s[i+1]=="AB")
				{
					ans.pb('A');
					c--;
					a++;
				}
				else
				{
					ans.pb('C');
					a--;
					c++;
				}
			}
			else
			{
				if(a<=c)
				{
					ans.pb('A');
					a++;
					c--;
				}
				else
				{
					ans.pb('C');
					c++;
					a--;
				}
			}
		}
		else
		{
			if(b==0 && c==0)
			{
				cout << "No" << endl;
				return 0;
			}
			else if(i<n-1 && b==1 && c==1)
			{
				if(s[i+1]=="BC")
				{
					ans.pb('C');
					b--;
					c++;
				}
				else if(s[i+1]=="AB")
				{
					ans.pb('B');
					c--;
					b++;
				}
				else
				{
					ans.pb('C');
					b--;
					c++;
				}
			}
			else
			{
				if(b<=c)
				{
					ans.pb('B');
					b++;
					c--;
				}
				else
				{
					ans.pb('C');
					c++;
					b--;
				}
			}
		}
	}
	cout << "Yes" << endl;
	rep(i, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 6876
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        if(a>=0){
            if(d>=0){
                System.out.println(b*d);
            }else{
                System.out.println(d*a);
            }
        }else if(b<0){
            if(c>=0){
                System.out.println(b*c);
            }else{
                System.out.println(c*a);
            }
        }else{
            if(d<0){
                System.out.println(c*a);
            }else if(c>=0){
                System.out.println(b*d);
            }else{
                if(a*c>b*d){
                    System.out.println(a*c);
                }else{
                    System.out.println(b*d);
                }
            }
        }
}
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... 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 V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

int main(void) {
  int N;
  cin >> N;

  vector<int> now(N, 0);

  int g[1000][1000];
  REP(i, N) REP(j, N - 1){
    int a;
    scanf("%d", &a);
    g[i][j] = a - 1;
  }

  queue<int> que;
  queue<int> n_que;

  REP(i, N) que.push(i);

  ll ans = 0;
  while(!que.empty()){
    bool flg = true;
    vector<bool> today(N, true);

    while(!que.empty()) {
      int i = que.front();
      que.pop();

      if(!today[i]) continue;      
      if(now[i] == N - 1) continue;      
      int j = g[i][now[i]];
      if(now[j] == N - 1) continue;      
      if(i == g[j][now[j]] && today[i] && today[j]){
        n_que.push(i);
        n_que.push(j);

        now[i]++;
        now[j]++;
        today[i] = false;
        today[j] = false;
        flg = false;
      }
    }
    if(flg) break;
    ans++;

    swap(que, n_que);

  }

  bool flg = true;
  REP(i, N) {
    if(now[i] != N - 1){
      flg = false;
      break;
    }
  }

  if(flg) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll h,w; cin >> h >> w;
  vector<vector<char>> s(h,vector<char>(w,'.'));
  // あるシャープより左にあるドットの累積をsrとする。
  // sr[i][n]=i行目の左からn番目のシャープより左
  // sr[i][0]はゼロとする
  vector<vector<ll>> sr(h);
  // あるシャープより上にあるドットの累積をsc
  // sc[j][m]=j列目の上からm番目のシャープより上
  // sc[j][0]はゼロとする
  vector<vector<ll>> sc(w);
  rep(i,h){
    ll ruiseki=0;
    sr[i].push_back(0);
    rep(j,w){
      cin >> s[i][j];
      if(s[i][j]=='#'){
        sr[i].push_back(ruiseki);
      }else{
        ruiseki++;
      }
    }
    sr[i].push_back(ruiseki);
  }
  rep(j,w){
    ll ruiseki=0;
    sc[j].push_back(0);
    rep(i,h){
      char cur = s[i][j];
      if(s[i][j]=='#'){
        sc[j].push_back(ruiseki);
      }else{
        ruiseki++;
      }      
    }
    sc[j].push_back(ruiseki);
  }
  vector<vector<ll>> ans(h+1,vector<ll>(w+1,0));
  rep(i,h){
    ll sharpcnt = 0;
    rep(j,w){
      if(s[i][j]=='#'){
        sharpcnt++;
      }else{
        ans[i][j]+=sr[i][sharpcnt+1]-sr[i][sharpcnt];
      }
    }
  }
  rep(j,w){
    ll sharpcnt = 0;
    rep(i,h){
      if(s[i][j]=='#'){
        sharpcnt++;
      }else{
        ans[i][j]+=sc[j][sharpcnt+1]-sc[j][sharpcnt];
      }      
    }
  }
  ll dest=0;
  rep(i,h)rep(j,w){
    dest = max(dest, ans[i][j]-1);
  }
  cout << dest << endl;
  return 0;
}




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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> p(n);
  rep(i,n) cin >> p[i].second >> p[i].first;
  sort(p.begin(), p.end());


  int sum = 0;
  rep(i,n){
    sum += p[i].second;
    if(sum > p[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 4812
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

int n, m;

bool ok(int i, int j){
  return i >= 0 and j >= 0 and i < n and j < m;
}

void solve(){
  cin >> n >> m;
  string s[n];
  forn(i,n){
    cin >> s[i];
  }
  forn(i,n){
    forn(j,m){
      int cnt = 0;
      if (s[i][j] == '.'){
        for (auto y: {-1,0,1})
        for (auto x: {-1,0,1}){
          if (ok(i+y, j+x)){
            cnt += s[i+y][j+x] == '#';
          }
        }
        s[i][j] = '0' + cnt;
      }
    }
  }
  forn(i,n) cout << s[i] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

2 6 3
4 6 5
6 6 7
7 7 7

*/

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

int main(void){
    char s[200001];
    long long int i, j, ans=0, preb=0;
    memset(s, '\0', 200001);
    scanf("%s", s);
    for(i=0; 1; i++){
        if(s[i] == '\0') break;
        else if(s[i] == 'B') preb++;
        else ans += preb;
    }
    printf("%lld", ans);
}

Measured memory_bytes: 384
//In the name of Allah
//In the name of the compassionate of the merciful
//Ya Ali!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename Type>
using ordered_multiset = tree<Type, null_type, less_equal<Type>, rb_tree_tag, tree_order_statistics_node_update> ;

typedef long long ll ;
typedef long double ld ;

const ll maxn = 1000 * 101 ;
const ll INF = 3e18 ;

#define f first
#define s second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define endll "\n"
#define sortt(v) sort(v.begin() , v.end())
#define reversee(v) reverse(v.begin() , v.end())

// for sqrt on interval and array , always sq = maxn/80 ;
// cout << *ss.find_by_order(index) ; -> return the value that indexed in index position
// cout << ss.order_of_key(value) ; -> lower_bound in ordered_set
//ifstream fin("input.txt");
//ofstream fout("output.txt");
// fflush(stdout);
//ll mod = 1e9 + 7 , p1 = 999999929 , p2 = 999999937 ;

ll n , dpd[maxn] , dpu[maxn] , par[maxn] , mod , felan[maxn] , per[maxn] , suf[maxn] ;
vector<ll> g[maxn] ;

void dfs(ll v , ll p)
{
  vector<ll> vv ;
  dpd[v] = 1 ;
  for(auto u : g[v]){
    if(u != p){
        vv.pub(u) ;
        par[u] = v ;
        dfs(u , v) ;
        dpd[v] = (dpd[v]*1ll*(dpd[u]+1))%mod;
    }
  }
  per[-1] = 1 ;
  suf[vv.size()] = 1;
  for(int i = 0 ; i < vv.size() ; i ++)per[i] = (per[i-1]*(dpd[vv[i]]+1))%mod ;
  for(int i = vv.size()-1 ; i >= 0 ; i --)suf[i] = (suf[i+1]*(dpd[vv[i]]+1))%mod ;

  for(int i = 0 ; i < vv.size() ; i ++)felan[vv[i]] = (per[i-1]*suf[i+1])%mod ;
}

void dfs2(ll v , ll p)
{
  ll anss = 1;
  anss = felan[v]%mod ;
  anss = (anss * dpu[par[v]])%mod ;
  dpu[v] = (1 + anss)%mod ;
  for(auto u : g[v]){
    if(u != p)dfs2(u , v) ;
  }
}

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

cin >> n >> mod ;
for(int i = 1 ; i < n ; i ++){
 ll v , u ;
 cin >> v >> u ;
 g[v].pub(u) ;
 g[u].pub(v) ;
}

dfs(1,0) ;
dfs2(1,0) ;

for(int i = 1 ; i <= n ; i ++)cout << (dpd[i]*dpu[i])%mod << "\n" ;

 return 0;
}
/*
                  _     _   __
            /_\  (_    (_)  __)
           /   \  _) . (_) (__
*/


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  
  IN(N);

  if (N % 2 == 1) {
    PRINT(0);
    return 0;
  }

  ll d = 2 * 5;
  while(d <= N) {
    ret += N / d;
    d *= 5;
  }
  
  PRINT(ret);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  pii A[N];
  rep(i,N) {
    A[i].second = i;
    cin >> A[i].first;
  }
  
  sort(A,A+N);
  int maxi = A[N-1].second;

  rep(i,N) {
    if (i==maxi) cout << A[N-2].first << endl;
    else cout << A[N-1].first << endl;
    
  }
  


  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 3200
def main():
    towns, walk_fatigue, teleport_fatigue = map(int, input().split())
    town_location = list(map(int, input().split()))
    answer = 0
    for i in range(towns - 1):
        answer += min(teleport_fatigue, walk_fatigue * (town_location[i + 1] - town_location[i]))
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int q;
    cin >> q;

    vector<int> prime;
    vector<bool> b(100001, true);
    b[0] = false;
    b[1] = false;
    for (int i = 2; i <= 1000; i++) {
        if (b[i]) {
            for (int j = i + i; j <= 100000; j += i) {
                b[j] = false;
            }
        }
    }

    vector<int> bb(100001, 0);
    for (int i = 1; i <= 100000; i++) {
        if (b[i] && b[(i + 1) / 2]) {
            bb[i] = bb[i - 1] + 1;
        } else {
            bb[i] = bb[i - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << bb[r] - bb[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

#define MAX_VALUE 9223372036854775807

int solve() {
	ll n, k;
	cin >> n >> k;

	vector<ll> as(n + 1);
	ll a;
	REPD(i, 0, n) {
		cin >> a;
		--a;
		as[i + 1] = (as[i] + a) % k;
	}

	map<ll, vector<ll>> counters;
	REPD(i, 0, n + 1) {
		if (counters.count(as[i]) == 0) counters[as[i]] = vector<ll>();
		counters[as[i]].emplace_back(i);
	}

	ll res = 0;
	REPI(pairs, counters){
		auto& counter = pairs.second;
		ll j = 0;
		REPD(i, 0, counter.size()) {
			while(j < counter.size()) {
				if (counter[j] - counter[i] >= k) break;
				++j;
			}
			res += max(j - i - 1LL, 0LL);
		}
	}

	RET(res);
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


Measured memory_bytes: 26640
#include<iostream>
using namespace std;
int cel(int n,int x,int t)
{
    if(n%x==0)
    {
        return (n/x)*t;
    }
    else
    {
        return ((n/x)+1)*t;
    }
}
int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    int ans = cel(n,x,t);
    printf("%d\n",ans);
}


Measured memory_bytes: 3720
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    int M =sc.nextInt();
    long H[] =new long[N];
    int A[] =new int[M];
    int B[] =new int[M];
    int C[] =new int[N];
    long x =0;
    for(int i=0;i<N;i++){
      H[i]=sc.nextLong();}
    for(int j=0;j<M;j++){
      A[j]=sc.nextInt();
      B[j]=sc.nextInt();
      if(H[A[j]-1]>H[B[j]-1]){C[B[j]-1]=-1;}
      else if(H[A[j]-1]==H[B[j]-1]){C[B[j]-1]=-1;C[A[j]-1]=-1;}
      else{C[A[j]-1]=-1;}}
    for(int k=0;k<N;k++){
      if(C[k]==0){x=x+1;}}
    System.out.println(x);
  }
} 

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

int main(){
  int h,w;
  cin >>h >>w;
  vector<vector<char>> c(h*2, vector<char>(w*2));
  for(int i = 0; i< 2*h; i += 2){
    rep(j,w){
      cin >>c[i][j];
      c[i+1][j] = c[i][j];
    }
  }
  rep(i,2*h){
    rep(j,w) cout << c[i][j];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
A,B,K = map(int,input().split())
for i in range(K):
    if i%2==0:
        if A%2==1:
            A -= 1
        B += A//2
        A -= A//2
    else:
        if B%2==1:
            B -= 1
        A += B//2
        B -= B//2
print(A,B)

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

int main()
{
    int n, arr[100001];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int answer = unique(arr, arr + n) - arr;
    if (answer % 2 == 1) {
        cout << answer << endl;
    } else {
        cout << answer - 1 << endl;
    }
    return 0;
}

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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){    
    int N;

    scanf("%d",&N);
    vector<int> v(N);

    REPI(N){
        scanf("%d",&v[i]);
    }

    sort(v.begin(),v.end());
    
    printf("%d\n",v[N-1]-v[0]);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void reads(string &s){
	char ch=getchar();s="";
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';s+=ch,ch=getchar());
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,P,num10[200005],cnt[100004];
string s;
int main(){
	read(n),read(P),reads(s),s="$"+s,num10[0]=1;
	for (int i=1;i<=n;i++)s[i]-='0';
	for (int i=1;i<=n;i++)num10[i]=num10[i-1]*10%P;
	cnt[0]++;
	ll ans=0;
	int now=0;
	for(int i=1;i<=n;i++){
		now=(now*10+s[i])%P;
		int tmp=now*num10[n-i]%P;
		if((P!=2 && P!=5) || s[i]%P==0)ans+=cnt[tmp];
		cnt[tmp]++;
	}
	write(ans);
}

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

int main(void){
	int a, b, c;

	cin >> a >> b >> c;

	if ((a == b) && (b == c)) cout << 1;
	else if ((a == b) || (a == c) || (b == c)) cout << 2;
	else cout << 3;
	cout << endl;

	return 0;
}

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

int main() {
  int w, n;
  cin >> w >> n;
  vector<int> a(n), b(n);
  char c;
  for (int i = 0; i < n; ++i)
    cin >> a[i] >> c >> b[i];

  vector<int> ans(w + 1);
  for (int j = 1; j <= w; ++j)
    ans[j] = j;

  for (int i = 0; i < n; ++i)
    swap(ans[a[i]], ans[b[i]]);

  for (int j = 1; j <= w; ++j)
    cout << ans[j] << endl;
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int n,a;map<string,int>M;string s;
main(){
  M[""]=0;
  for(int i=1;i>-2;i-=2){
    cin>>n;
    for(;n--;M[s]+=i)cin>>s;
  }
  for(pair<string,int>p:M)a=max(a,p.second);
  cout<<a<<endl;
}

Measured memory_bytes: 256
N = int(input())
li_B = list(map(int, input().split()))
li_A = list()
li_A.append(li_B[0])
for i in range(N-2):
    li_A.append(min(li_B[i:i+2]))
li_A.append(li_B[-1])
print(sum(li_A))

Measured memory_bytes: 3060
import sys
import math 
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
S=ns()

f=int(S[0:2])
r=int(S[2:4])
#print(f,r)

if(f<=12 and f>=1 and r<=12 and r>=1):
    print("AMBIGUOUS")
elif(f<=12 and f>=1):
    print("MMYY")
elif(r<=12 and r>=1):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 14416
from collections import deque
# 縦(H)x横(W)
H, W = map(int, input().split())
# 魔法使いの座標
CH, CW = map(int, input().split())
# ゴール
DH, DW = map(int, input().split())
# マップ
S = [list(input()) for _ in range(H)]
# 移動Aの動き方
move_a = [(0, 1), (0, -1), (1, 0), (-1, 0)]
# 移動Bの動き方
move_b = [(x, y) for x in range(-2, 3)
          for y in range(-2, 3) if (x, y) not in move_a + [(0, 0)]]

INF = 10 ** 10
# 各マスへの移動コスト
path = [[INF] * W for _ in range(H)]

q = deque()
path[CH-1][CW-1] = 0
q.append((CH-1, CW-1, 0))

while q:

    x, y, s = q.popleft()

    # 移動Aについて
    for dx, dy in move_a:
        nx = x + dx
        ny = y + dy

        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))

# 移動Bについて
    for dx, dy in move_b:
        nx = x + dx
        ny = y + dy

        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and path[nx][ny] > s+1:
            path[nx][ny] = s+1
            q.append((nx, ny, s+1))


print(path[DH-1][DW-1]) if path[DH-1][DW-1] < INF else print(-1)

Measured memory_bytes: 132620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int N,Y;
    cin >> N >> Y;
    
    Y = Y/1000;
    if(Y-N < 0){
        cout << "-1 -1 -1" << endl;
        return 0;
    }
    rep(a,N+1) rep(b,N+1){
        if(9*a+4*b == Y-N){
            int c = N-a-b;
            if(c >= 0){
                cout << a << " " << b << " " << c << endl;
                return 0;
            }
        }
    }
    
    
    cout << "-1 -1 -1" << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
def I():
    return int(sys.stdin.readline().rstrip())

N = I()

if N == 0:
    print(0)
    exit()

ans = ''

r = 0
while N != 0:
    if N % 2 == 1:
        ans = '1' + ans
        N -= (-1)**r
    else:
        ans = '0' + ans
    N //= 2
    r += 1

print(ans)

Measured memory_bytes: 61844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()

#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long
int32_t main(){ fast;
	int a, b, c, k; cin>>a>>b>>c>>k;
	if(k <= a){
		cout<<k<<endl;
		return 0;
	}
	int ans = 0;
	ans = min(k, a);
	if(k >= a){
		k -= min(k, a);
	}
	//debug(k);
	if(k >= b){
		k -= min(b, k);
	}
	//debug(k);
	ans -= min(k, c);
	if(k >= c){
		k -= c;
	}
	//debug(k);
	cout<<ans<<endl;
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl h(n);
    rep(i,n)cin>>h[i];
    reverse(all(h));
    rep(i,n-1){
        if(h[i+1]>h[i])h[i+1]--;
        if(h[i+1]>h[i]){
            Yes(0);
            return 0;
        }
    }
    Yes(1);
}

Measured memory_bytes: 3972
spreadsheet = []
total = 0
r, c = list(map(int, input().split()))
for i in range(r):
    listTmp = []
    listTmp = list(map(int, input().split()))
    spreadsheet.append(listTmp)
for j in range(r):
    for k in range(c):
        print(spreadsheet[j][k], end=" ")
    print(sum(spreadsheet[j]))
for m in range(c):
    cTotal = 0
    for n in range(r):
        cTotal += spreadsheet[n][m]
    print(cTotal, end=" ")
    total += cTotal
print(total)


Measured memory_bytes: 6220
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int i=0;
    int num=0;
    while(true){
    	num=A+A*i;
          i++;
      	if(num==B){
        System.out.println(A+B);
          break;
        }else if(num>B){
          System.out.println(B-A);
          break;
        }
    }
  }
}

Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <cfloat>
#include <iomanip>
#include <stack>
#include <bitset>


using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define bitcount(n) __builtin_popcountll(n)
#define pii pair<int, int>


typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 200000 + 7;
const int M = 17;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * (inf - 1);
const double pi = acos(-1);
const double eps = 1e-6;
const bool multipleTest = false;



int a[N];

set<int> st;


void solve(){
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1) {
        puts("No");
    } else {
        puts("Yes");
        
        a[n] = x;
        if (x == n) for(int i = 1; i < 2 * n; ++i) a[i] = i;
        else {
            
            for(int i = 1; i < 2 * n; ++i) st.insert(i);
            st.erase(x); st.erase(x + 1); st.erase(x - 1);
            
            a[n + 1] = x + 1;
            a[n - 1] = x - 1;
            for(int i = n + 2; i < 2 * n; ++i) {
                a[i] = *st.begin(); st.erase(st.begin());
            }
            
            for(int i = 1; i + 1 < n; ++i) {
                a[i] = *st.begin(); st.erase(st.begin());
            }
        }
        
        for(int i = 1; i < 2 * n; ++i) printf("%d\n", a[i]);
        
        
    }
}

void createTest() {
    freopen("in.txt", "w", stdout);
    cout << 1 << "\n";
    cout << 100000 << " " << 100000 << "\n";
    for(int i = 1; i <= 100000; ++i) {
        int u = rand();
        int v = rand();
        if (u > v) swap(u, v); printf("%d %d\n", u, v);
    }
    for(int i = 1; i <= 100000; ++i) {
        int u = rand();
        int v = rand();
        if (u > v) swap(u, v); printf("%d %d\n", u, v);
    }
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    clock_t t1 = clock();
#endif
//    createTest();
//    return 0;
//    freopen("out.txt", "w", stdout);

    
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    
    for(int i = 0; i < Test; ++i) {
//        printf("Case #%d: ", i + 1);
        solve();
    }
    
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * (clock() - t1) / CLOCKS_PER_SEC<<endl;
#endif
    
}


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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 H, W, K, i, j;
  cin >> H >> W >> K;
  vector<string> B(H);
  REP(0, H, i) {
    cin >> B[i];
  }

  i64 ans = 0;
  i64 bi, bj;
  REP(0, 1LL<<H, bi) {
    REP(0, 1LL<<W, bj) {
      i64 count = 0;
      REP(0, H, i) {
	if((bi & (1LL << i)) != 0) {
	  REP(0, W, j) {
	    if((bj & (1LL << j)) != 0) {
	      if(B[i][j] == '#') {
		count++;
	      }
	    }
	  }
	}
      }
      if(count == K) {
	ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n, i, p = 0;
    int x[101], y[101];
    double D[4] = {0};
    
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d", &x[i]);
    for(i=0; i<n; i++) scanf("%d", &y[i]);
    
    do{
        
        if(p == 0){
            for(i=0; i<n; i++) D[0] = fmax(D[0], abs(x[i]-y[i]));
        }else{
            for(i=0; i<n; i++) D[p] += pow(abs(x[i]-y[i]), p);
            D[p] = pow(D[p], (1.0/(double)p));
            printf("%f\n", D[p]);
        }
        
        p++;
        
    }while(p<4);
    
    
    printf("%f\n", D[0]);
    
    return 0;
}

Measured memory_bytes: 700
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  for (auto &i : A) { std::cin >> i; }
  std::cout << (N - 1) / (K - 1) + ((N - 1) % (K - 1) ? 1 : 0) << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P =pair<long double,long double>;
int main() {
    ll N;
    cin >> N;
    vector<P> X;
    for(int i=0;i<N;i++){
        long double a,b;
        cin >> a >> b;
        X.emplace_back(a,b);
    }
    sort(X.begin(),X.end());
    long double ans =0;
    ll num =0;
    do{
        for(int i=0;i<N-1;i++){
            ans += sqrtl(powl(X[i].first-X[i+1].first,2)+powl(X[i].second-X[i+1].second,2));
        }
        num++;
    }while(next_permutation(X.begin(),X.end()));
    cout <<setprecision(10)<< ans/num << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int l;
int main(){
    scanf("%d",&l);
    double ans=1.0*l*l*l/27;
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <map>

typedef long long ll;
#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define MOD 1000000007
#define EPS 1e-7
#define INF INT_MAX
#define PI  3.14159265358979323846264338327950288
inline ll toll(std::string s) { ll v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;
typedef pair<ll, ll> pll;

int main()
{
    ll N;
    cin >> N;
    
    if (N == 1 | N == 2)
    {
        cout << N << endl;
        return 0;
    }
    
    vector<ll> sum;
    vector<ll> sum_size;
    int count = 1;
    repi(i,2,100000)
    {
        if(i == 2)
        {
            sum.push_back(i);
            sum_size.push_back(count++);
            //11cout << i << endl;
        }
        else{
            //cout << i + sum[sum.size() - 1] << endl;
            sum_size.push_back(count++);
            sum.push_back(i + sum[sum.size() - 1]);
            if (sum[sum.size()-1] > 10000000)
            {
                break;
            }
        }
    }
    
    vector<ll> ans;
    rep(i,sum.size())
    {
        if(sum[i] >= N)
        {
            //cout << sum[i] << endl;
            rep(j,sum_size[i])
            {
                ans.push_back(j + 1);
            }
            rep(j,sum_size[i] - (sum[i] - N))
            {
                ans[ans.size() - 1 - j]++;
            }
            break;
        }
    }
    
    rep(i,ans.size())
    {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 1e9 + 10;

int N, X;
bool done[55];
int len[55], dp[55];

int f(int n, int x)
{
	if (x == 0) return 0;
	if (x >= len[n]) return dp[n];

	int ans = 0;

	if (x - 1 >= len[n - 1]) {
		ans += dp[n - 1];
		x -= 1;
		x -= len[n - 1];
		if (x >= 1) {
			ans += 1;
			ans += f(n - 1, x - 1);
		}
	} else {
		ans += f(n - 1, x - 1);
	}

	return ans;
}

signed main()
{
	int N = 5; cin >> N;

	len[1] = 1;
	dp[1] = 1;

	rep1(i, N) {
		len[i + 1] = 3 + 2 * len[i];
		dp[i + 1] = 1 + 2 * dp[i];
	}

	int X; cin >> X;
	
	cout << f(N+1, X) << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  char A[10],B[10],C[10];
  scanf("%s %s %s",A,B,C);
  if(A[strlen(A)-1]==B[0]&&B[strlen(B)-1]==C[0]){
    printf("YES\n");
  } else printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue

#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

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


#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define FORl(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORN(i,n) for(int i=(0);i<(n);i++)
#define FORR(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)

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

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................

int main()
{
    fast
    
    ll n,m,i;
    cin>>n>>m;
    ll a[n];
    ll sum=0;
    for(i=0;i<n;i++)
    cin>>a[i],sum+=a[i];
    sort(a,a+n,greater<int>());
    ll k=0;
    for(i=0;i<n;i++)
    {
        if(a[i]*m*4>=sum)
        k++;
        else
        break;
    }
    if(k>=m)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    
    
    return 0;
}


Measured memory_bytes: 3648
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define pf printf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node

using namespace std;
///check n=1;
///check corner case;

int main()
{
   ll a,b,c;
   cin>>a>>b>>c;
   ll sum=a+b+c;
   if(sum>=22)cout<<"bust"<<endl;
   else cout<<"win"<<endl;
return 0;
}


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

using namespace std;
#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define var register int
#define mark asdfahsdkjhfgaskdljfh
#define fx asdfasd9owxbgs

const int N = 3001;
const int fx[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int n, m;
char s[N];
bool mark[N][N];
int have[N][N][4];

int read();

int main() {
	n = read(), m = read();
	for (var i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (var j = 1; j <= m; ++j) mark[i][j] = s[j] == '#';
	}
	for (var i = 1; i <= n; ++i) {
		for (var j = 1; j <= m; ++j) {
      if (mark[i][j]) continue;
      have[i][j][0] = have[i][j - 1][0] + 1;
    }
	}
	for (var i = 1; i <= n; ++i) {
    for (var j = m; j >= 1; --j) {
      if (mark[i][j]) continue;
      have[i][j][1] = have[i][j + 1][1] + 1;
    }
	}
  for (var j = m; j >= 1; --j) {
    for (var i = n; i >= 1; --i) {
      if (mark[i][j]) continue;
      have[i][j][2] = have[i + 1][j][2] + 1;
    }
  }
  for (var j = 1; j <= m; ++j) {
		for (var i = 1; i <= n; ++i) {
      if (mark[i][j]) continue;
      have[i][j][3] = have[i - 1][j][3] + 1;
    }
  }


  int res = 0;
	for (var i = 1; i <= n; ++i) {
		for (var j = 1; j <= m; ++j) {
      int sum = 0;
      for (var k = 0; k < 4; ++k) sum += have[i][j][k];
      res = max(res, sum);
    }
  }
	cout << res - 3 << endl;
  return 0;
}

int read() {
  int a = 0, c = 0, s = 0;
  while (!isdigit(c = getchar())) s |= c == '-';
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
	return s ? -a : a;
}


Measured memory_bytes: 102144
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

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

  for(int i = 0;i<S.size();i++){
    for(int j = 0;j<S.size();j++){
      string check = "";
      if(i==j){
        continue;
      }
      check = S.substr(0,i+1)+S.substr(j);
      if(check == "keyence"){
        cout << "YES" << endl;
        return 0;
      }
    
    }
  }

  cout << "NO" << endl;
}

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

count = 0

for i in range(n):
    if a[i] < 0:
        count += 1
        a[i] = -1*a[i]

if count % 2 == 0:
    print(sum(a))
else:
    print(sum(a)-2*min(a))


Measured memory_bytes: 14332
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int>red(a),green(b),less(c);
    for(auto& i:red)cin>>i;
    for(auto& i:green)cin>>i;
    for(auto& i:less)cin>>i;
    sort(red.rbegin(),red.rend());
    sort(green.rbegin(),green.rend());
    red.erase(red.begin()+x,red.end());
    green.erase(green.begin()+y,green.end());
    for(auto i:green)
    red.push_back(i);
    for(auto i:less)
    red.push_back(i);
    sort(red.rbegin(),red.rend());
    ll sum=0;
    for(int i=0;i<x+y;i++)
    sum+=red[i];
    cout<<sum<<endl;
}


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

int main() {
    int posC = -1;
    bool foundC = false;
    string a;
    cin >> a;
    int len = a.length();
    for (int i=0;i<len;i++) {
        if (a[i] == 'C') {
            posC = i;
            foundC = true;
            break;
        }
    }
    int foundF = false;
    if (foundC) {
        for (int i=posC; i < len; i++) {
            if (a[i] == 'F') {
                foundF = true;
                break;
            }
        }
    }
    if (foundC and foundF) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int X,c=1;
  scanf("%d",&X);
  int Y=X;
  while(c){
    c=0;
    for(int i=2;i*i<=Y;i++){
      if(Y%i==0) c=1;
    }
    Y++;
  }
  printf("%d\n",Y-1);
  return 0;
}

Measured memory_bytes: 1732
n=gets.to_i
s=gets.chomp
w=3.times.map{[]}
s.bytes.each_with_index{|c,i|
  w[(c+2)%6].push(i+1)
}
w.sort_by!(&:size)
t=w[2].size
h={}
w[2].each{|e| h[e]=true }
ans=0
w[0].each{|x|
  w[1].each{|y|
    ans+=t
    ans-=1 if (x+y).even? && h[(x+y)/2]
    ans-=1 if h[x*2-y]
    ans-=1 if h[y*2-x]
  }
}
puts ans

Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) rep2(i,0,n)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
string s;
int main()
{
	cin>>s;
	cout<<s;
	if(s[s.size()-1]=='s') cout<<'e';
	re('s')
	return 0;}

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

using namespace std;

int n, x;

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

    cin >> n >> x;
    long long sum = 0, cnt = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        sum += a;
        if(sum <= x)
            cnt++;
    }

    cout << cnt + 1;

    return 0;
}


Measured memory_bytes: 256