akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

using namespace std;
using p=pair<int,int>;
typedef long long ll;
const double pi=3.14159265;

int main() {
  ll x,y;
  cin >> x;
  y=0;
  
  while(x>=500){
    x-=500;
    y+=1000;
  }
  while(5<=x && x<500){
    x-=5;
    y+=5;
  }
  cout << y << endl;
  return 0;
 
}
    

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const int MOD=1e9+7;

struct UnionFind {
  int N;
  vector<ll> par,ranc,ecnt;
  
  UnionFind(int N) : N(N),par(N),ranc(N,0),ecnt(N,1) { REP(i,N) par[i]=i; }
  
  int root(int s) {
    if (par[s]==s) return s;
    else return root(par[s]);
  }
  
  bool same(int x, int y) { return root(x)==root(y); }
  
  bool connected() {
    int base = root(0);
    REP(i,N) if (root(i)!=base) return false;
    return true;
  }
  
  void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x==y) return;
    if (ranc[x]>ranc[y]) {
      par[y] = x;
      ecnt[x] += ecnt[y];
    } else {
      par[x] = y;
      if (ranc[x]==ranc[y]) ranc[y]++;
      ecnt[y] += ecnt[x];
    }
  }
};

int main() {
  // 不便さの数を順番に求める
  // 逆から見ていって、UnionFindで調査
  ll N,M;cin>>N>>M;
  vector<P> bridges(M);
  REP(i,M) {
    int a,b;cin>>a>>b;
    a--;b--;
    bridges[i] = {a,b};
  }
  reverse(ALL(bridges));

  UnionFind uf(N);

  vector<ll> ans;
  ll tmp = N*(N-1)/2;
  REP(i,M) {
    ans.push_back(tmp);
    P bridge = bridges[i];
    if (uf.same(bridge.first,bridge.second)) continue;

    tmp -= uf.ecnt[uf.root(bridge.first)]*uf.ecnt[uf.root(bridge.second)];
    uf.merge(bridge.first, bridge.second);
  }
  reverse(ALL(ans));
  REP(i,M) OUT(ans[i]);

  return 0;
}

Measured memory_bytes: 6132
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<long> A = Console.ReadLine()
                              .Split()
                              .Select((x, i) => long.Parse(x) - i - 1)
                              .OrderBy(i => i)
                              .ToList();
            int middle = (N - 1) / 2;
            long b = A[middle];
            long ans = A.Select(i => Math.Abs(i - b)).Sum();
            Console.WriteLine(ans);
        }
    }
}


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

typedef long long LLONG;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;
//#define TDEBUG
#ifdef TDEBUG
#define tout(x) std::cerr << #x << " = " << x << std::endl;
#define tdebug(args...) { std::cerr << "(" << #args << ") => "; dbg, args; std::cerr << std::endl; }
#else
#define tout(x) //skip all
#define tdebug(args...)
#endif
struct Debuger {
  template<typename T>
  Debuger& operator, (const T& v) {
    std::cerr << v << " ";
    return *this;
  }
} dbg;

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int a[N];
char s[N];

VI edge[N];
int parent[N];
char t[N];

int main() {
  int n, m, q;
  scanf("%d%s%s", &n, s, t);
  int rlt = n + n;
  for(int i = 0; i < n; ++i) {
    bool mark = true;
    for(int j = i, k = 0; j < n; ++j, ++k) {
      if(s[j] != t[k]) {
        tdebug(i, j)
        mark = false;
        break;
      }
    }
    if(mark) {
      tdebug(i)
      rlt = std::min(rlt, n + i);
      break;
    }
  }
  printf("%d\n", rlt);
  return 0;
}


Measured memory_bytes: 2560
# coding: utf-8
# hello worldと表示する
a,b=map(int,input().split())
ans=True
for i in range(a+1):
    for j in range(a+1-i):
        s=10000*i+5000*j+1000*(a-i-j)
        if s == b:
            print(str(i)+" "+str(j)+" "+str(a-i-j))    
            ans = False
            exit()
if ans==True:
    print("-1 -1 -1")

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

#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////



int main(){fastio
    ll x;cin>>x;
    ll t=x/200;
    cout<<10-t<<endl;
    
    return 0;
}



Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, A, B;
string s;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> A >> B;
	cin >> s;
	lint cnt = 0;
	REP(i, N) {
		if (s[i] == 'a' && A + B > 0) {
			cout << "Yes" << endl;
			A--;
		}
		else if(s[i] == 'b' && A + B > 0 && B > 0){
			cout << "Yes" << endl;
			B--;
		}
		else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int L,R,D;
    cin>>L>>R>>D;
    int ans=R/D-L/D;
    if(L%D==0){
        ans++;
    }

    cout<<ans<<endl;
    //cout<<R/D<<" "<<L/D<<endl;
    return 0;
}



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

void solve(){
    int n,m; cin>>n>>m;
    map<int,pair<int,int>> mm;
    for(int i=0;i<m;i++){
        int p;cin>>p;
        string s; cin>>s;
        if(mm.count(p)){
            if(s=="AC") mm[p].first=1;
            if(s=="WA" && mm[p].first==0)mm[p].second++;

        }else{
            if(s=="AC") mm.insert(make_pair(p,make_pair(1,0)));
            else mm.insert(make_pair(p,make_pair(0,1)));
        }
    }
    int noOfAc=0, noOfWA=0;
    for(auto m : mm){
        if(m.second.first==1) noOfAc++;
        if(m.second.second>0 && m.second.first==1) noOfWA += m.second.second;
    }

    cout <<noOfAc << " " <<  noOfWA;



}

int main(){
    solve();
}

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-

S = input()

ans = 0
stack = 0
height = 0
last_c = '>'
for c in S:
    if last_c == '<' and c == '<':
        stack += 1
    elif last_c == '>' and c == '>':
        stack += 1

    elif last_c == '>' and c == '<':
        # always 0
        ans += stack * (stack - 1) // 2
        ans += max(height, stack)
        stack = 1

    elif last_c == '<' and c == '>':  # < a >
        # bigger
        height = stack
        ans += stack * (stack - 1) // 2
        stack = 1

    last_c = c

if last_c == '<':
    ans += stack * (stack + 1) // 2
else:
    ans += stack * (stack - 1) // 2
    ans += max(height, stack)

print(ans)


Measured memory_bytes: 4116
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define REP(i,a,b) for(register int i=(a); i<(b); i++)
#define REPE(i,a,b) for(register int i=(a); i<=(b); i++)
#define PERE(i,a,b) for(register int i=(a); i>=(b); i--)
using namespace std;
#define MAXN 5007
int main() {
	int h,w;
	scanf("%d%d", &h, &w);
	if(h==1 || w==1) {puts("1"); return 0;}
	if((h&1) && (w&1)) {
		long long ans=(long long)h*w/2+1;
		printf("%lld\n", ans);
	} else {
		long long ans=(long long)h*w/2;
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 128
import time
st=time.time()
d=int(input())
c=[0]+[int(j)for j in input().split()]
s=[[0]+[int(j)for j in input().split()]for i in range(d)]
s2=[sorted([[j,idx]for idx,j in enumerate(s[i])],reverse=True)for i in range(d)]
t=[i[0][1]for i in s2]
ans=0
p=1
q=t[0]-1
se=set()
while time.time()-st<1.8:
    if len(se)==26:
        p+=1
        if p>d:p=1
        se=set()
        q=t[p-1]
    se.add(q)
    l=[0]*27
    tmp=0
    pre=t[p-1]
    t[p-1]=q
    for i,j in enumerate(t,1):
        tmp+=s[i-1][j]
        l[j]=i
        for k in range(1,27):
            tmp-=(i-l[k])*c[k]
    if ans<tmp:
        ans=tmp
    else:
        t[p-1]=pre
    nextq=list(set(range(1,27))-se)
    if nextq!=[]:
        q=nextq[0]

for i in t:
    print(i)



Measured memory_bytes: 70692
n = input()
k = input()
n = int(n)
k = int(k)
xs = input().split(" ")

l = list()
for x in xs:
	l.append(int(x))

cost = 0
for arg in l:
	if (2 * arg) <= (2 * abs(k - arg)):
		cost += (2 * arg)
	else:
		cost += (2 * abs(k - arg))

print(cost)

Measured memory_bytes: 3064
// This template code suggested by KT BYTE Computer Science Academy
//   for use in reading and writing files for USACO problems.

// https://content.ktbyte.com/problem.java

import java.util.*;
import java.io.*;

public class Main {

    static StreamTokenizer in;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }

    public static void main(String[] args) throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = nextInt();

        int num1 = 0;
        int num2 = 0;
        int num3 = 0;

        for (int i = 0; i < n; i++) {
            int next = nextInt();

            if (next == 1) num1++;
            else if (next == 2) num2++;
            else num3++;
        }

        double[][][] dp = new double[n+3][n+3][n+3];
        double[][][] ev = new double[n+3][n+3][n+3];

        dp[num1][num2][num3] = 1;

        for (int k = n; k >= 0; k--) {
            for (int j = n; j >= 0; j--) {
                for (int i = n; i >= 0; i--) {
                    if (k == 0 && j == 0 && i == 0) break;
                    if (k + j + i > n) continue;

                    double p_waste = (double) (n - (i + k + j)) / n;
                    double ev_wasted = p_waste / (1 - p_waste) + 1;

                    ev[i][j][k] += ev_wasted * dp[i][j][k];

                    if (i != 0) {
                        double prob = ((double) i / (i + j + k));
                        dp[i-1][j][k] += dp[i][j][k] * prob;
                        ev[i-1][j][k] += ev[i][j][k] * prob;
                    }
                    if (j != 0) {
                        double prob = ((double) j / (i + j + k));
                        dp[i+1][j-1][k] += dp[i][j][k] * prob;
                        ev[i+1][j-1][k] += ev[i][j][k] * prob;
                    }
                    if (k != 0) {
                        double prob = ((double) k / (i + j + k));
                        dp[i][j+1][k-1] += dp[i][j][k] * prob;
                        ev[i][j+1][k-1] += ev[i][j][k] * prob;
                    }
                }
            }
        }

        out.println(ev[0][0][0]);

        out.close();
    }
}




Measured memory_bytes: 588544
#include<stdio.h>
int main()
{
	int m,a,b,c,max=0;
	scanf("%d",&m);
	a=m/100;
	b=(m-a*100)/10;
	c=m%10;
	if(b<a||(b==a&&c<=a))printf("%d%d%d\n",a,a,a);
	else printf("%d%d%d\n",a+1,a+1,a+1);
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()

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; }

ll MOD = 1000000007;


int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll ans = 0;
    REP(i, 1000) {
        string str = to_string(i);
        while(str.length() < 3) str = "0" + str;
        ll cnt = 0;
        REP(j, N) {
            if (S[j] == str[cnt]) {
                cnt++;
                if (cnt == 3) {
                    ans++;
                    break;
                }
            }
        }
    }
    PRINT(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#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>
    
#define int  long long 
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 1e18
    
const int N=2e5+5; 
const int M=1e9+7;
void solve()
{
	int s,w;
	cin>>s>>w;
	if(w>=s)
	cout<<"unsafe";
	else
	cout<<"safe";
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}



Measured memory_bytes: 3648
import collections

class Dinic:
    def __init__(self, n):
        self.n = n
        self.g = [[] for i in range(n)]
    def add_edge(self, fr, to, cap):
        self.g[fr].append([to, cap, len(self.g[to])])
        self.g[to].append([fr, 0, len(self.g[fr])-1])
    def add_multi_edge(self, v1, v2, cap1, cap2):
        self.g[v1].append([v2, cap1, len(self.g[v2])])
        self.g[v2].append([v1, cap2, len(self.g[v1])-1])
    def bfs(self, s):
        level = [-1]*self.n
        deq = collections.deque()
        level[s] = 0
        deq.append(s)
        while deq:
            v = deq.popleft()
            for e in self.g[v]:
                if e[1]>0 and level[e[0]]<0:
                    level[e[0]] = level[v] + 1
                    deq.append(e[0])
        self.level = level
    def dfs(self, v, t, f):
        if v==t: return f
        es = self.g[v]
        level = self.level
        for i in range(self.it[v], len(self.g[v])):
            e = es[i]
            if e[1]>0 and level[v]<level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d>0:
                    e[1] -= d
                    self.g[e[0]][e[2]][1] += d
                    self.it[v] = i
                    return d
        self.it[v] = len(self.g[v])
        return 0
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0: break
            self.it = [0]*self.n
            while True:
                f = self.dfs(s, t, 10**9+7)
                if f>0:
                    flow += f
                else:
                    break
        return flow

n = int(input())

reds = []
for i in range(n):
    a, b = map(int, input().split())
    reds.append((a, b))
blues = []
for i in range(n):
    c, d = map(int, input().split())
    blues.append((c, d))

B = 100
dinic = Dinic(B * 2 + 2)
for i in range(n):
    dinic.add_edge(0, 2 + i, 1)
for j in range(n):
    dinic.add_edge(2 + n + j, 1, 1)
    
for i in range(n):
    for j in range(n):
        if reds[i][0] < blues[j][0] and reds[i][1] < blues[j][1]:
            dinic.add_edge(2 + i, 2 + n + j, 1)

f = dinic.max_flow(0, 1)
print(f)




Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;

void solve()
  {
   int n;
   cin>>n;
   pii a[n];
   loop(i,0,n)
   {
    a[i].ss = i+1;
    cin>>a[i].ff;
   }
   sort(a,a+n);
   loop(i,0,n)
    cout<<a[i].ss<<" ";
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 

     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 5064
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())

ans_l=[0]*(10**5)
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            ans_l[i*i+j*j+k*k+i*j+j*k+k*i]+=1


for i in range(1,N+1):
    print(ans_l[i])


Measured memory_bytes: 11172
import sys
sys.setrecursionlimit(10 ** 9)

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())
uf = UnionFind(N)
FG = [0] * N
BG = [0] * N
for _ in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  uf.union(a, b)
  FG[a] += 1
  FG[b] += 1

for _ in range(K):
  c, d = map(int, input().split())
  c, d = c-1, d-1
  if uf.same(c, d):
    BG[c] += 1
    BG[d] += 1

ans = []
for i in range(N):
  ans.append(uf.size(i) - FG[i] - BG[i] - 1)
  
print(*ans)

Measured memory_bytes: 15008
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;

int n;
bool s[500], t[500], u[500], v[500];
int a[500][500];
ull ans[500][500];
void end(){
    cout << -1 << endl;
    exit(0);
}
void solve(){
    memset(a, 0xff, sizeof(a));
    vector<int> x(n), y(n);
    auto px = x.begin(), py = y.begin();
    for(int i = 0; i < n; i++) x[i] = y[i] = i;
    for(int i = 0; i < n; i++){
        if(s[i] ^ u[i]){
            for(int j = 0; j < n; j++) a[i][j] = u[i];
            px = x.erase(px);
        }
        else px++;
    }
    for(int j = 0; j < n; j++){
        if(t[j] ^ v[j]){
            for(int i = 0; i < n; i++){
                if(a[i][j] == (v[j] ^ 1)) end();
                a[i][j] = v[j];
            }
            py = y.erase(py);
        }
        else py++;
    }
    if(x.size() > 1 && y.size() > 1){
        bool b = 0;
        for(int i : x){
            bool c = b;
            for(int j : y){
                a[i][j] = c;
                c = !c;
            }
            b = !b;
        }
    }
    else if(x.size() == 1){
        const int i = x[0];
        for(int j : y){
            a[i][j] = u[i];
            bool flag = 1;
            for(int i = 0; i < n; i++) if(a[i][j] == v[j]) flag = 0;
            if(flag) a[i][j] = v[j];
        }
    }
    else if(y.size() == 1){
        const int j = y[0];
        for(int i : x){
            a[i][j] = v[j];
            bool flag = 1;
            for(int j = 0; j < n; j++) if(a[i][j] == u[i]) flag = 0;
            if(flag) a[i][j] = u[i];
        }
    }
    for(int i : x){
        bool flag = 1;
        for(int j = 0; j < n; j++) if(a[i][j] == u[i]) flag = 0;
        if(flag) end();
    }
    for(int j : y){
        bool flag = 1;
        for(int i = 0; i < n; i++) if(a[i][j] == v[j]) flag = 0;
        if(flag) end();
    }
}
int main(){
    cin >> n;
    vector<ull> u_(n), v_(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    for(int i = 0; i < n; i++) cin >> t[i];
    for(ull& i : u_) cin >> i;
    for(ull& i : v_) cin >> i;
    for(int bit = 64; bit--; ){
        for(int i = 0; i < n; i++) u[i] = u_[i] >> bit & 1;
        for(int i = 0; i < n; i++) v[i] = v_[i] >> bit & 1;
        solve();
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
            ans[i][j] <<= 1;
            ans[i][j] |= a[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) cout << ans[i][j] << ' ';
        cout << '\n';
    }
}

Measured memory_bytes: 8416
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

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

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int A, B, K;

void solve(){
	for(int i = A; i <= B; i++){
		if(i - A < K or B - i < K)
			cout << i << endl;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> A >> B >> K;
		solve();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for(int i = n - 1; i >= 1; i--)
            {
                Console.Write("{0} ",array[i]);
            }
            Console.Write(array[0]);
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9604
while True:
        k=map(int,raw_input().split())
        H=k[0]
        W=k[1]
        if H+W==0:
                break
        else:
                print '#'*W
                if H==1:
                        break
                if H==2:
                        print '#'*W
                if H>2:
                        for i in range(H-2):
                                print '#'+ '.'*(W-2)+'#'
                        print '#'*W
        print ""

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

using namespace std;

typedef long long ll;

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

	int m;
	cin >> m;

	ll digsum = 0;
	ll csum = 0;
	rep(i, m){
		ll d, c;
		cin >> d >> c;

		digsum += d * c;
		csum += c;
	}

	cout << (digsum-1) / 9 + csum - 1 << endl;
}


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

using namespace std;

int main() {
    int arr[10];
    for(int i = 0; i < 10; ++i) cin >> arr[i];
    sort(arr, arr+10);
    for(int i = 9; i >= 7; --i) cout << arr[i] << endl;
    return 0;
}

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

bool calc(vector<int> p1, vector<int> p2)
{
    int sum = 0;
    for (int i = 0; i < p1.size(); i++) {
        sum += (p1[i] - p2[i]) * (p1[i] - p2[i]);
    }
    double a = sqrt(sum);
    return floor(a) == ceil(a);
}

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

    vector<vector<int>> x(n, vector<int>(d));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int count = 0;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (calc(x[i], x[j])) {
                count++;
            }
        }
    }

    cout << count;
}

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

// as + bt = GCD(a,b) a,b:const s,t:var(any)
// return GCD(a,b)
long long extGCD(long long a, long long b, long long& s,
                 long long& t) {
  s = 1, t = 0;
  while(b) {
    long long tmp = a / b;
    a -= b * tmp;
    s -= t * tmp;
    swap(a, b);
    swap(s, t);
  }
  return a;
}

// (mod)x+ay=1, calculate y -> a^-1 (mod m) (a,m : coprime)
long long calcinv(long long a, long long m) {
  long long s, t;
  extGCD(a, m, s, t);
  return (s + m) % m;
}

long long M = 0;

// x=b_i(mod m_i) calc min x,lcm(m_i).
// if not exist, return (-1,-1)
pair<long long, long long> ChineseRem(
    const vector<long long>& b,
    const vector<long long>& m) {
  long long r = 0, lcm = 1;
  assert(b.size() == m.size());
  long long bsize = b.size();
  for(int i = 0; i < bsize; ++i) {
    long long p, q, d, now;
    d = extGCD(lcm, m[i], p, q);
    if((b[i] - r) % d != 0) return make_pair(-1, -1);
    now = (b[i] - r) / d * p % (m[i] / d);
    r += lcm * now;
    if(r > M) return make_pair(-1, -1);
    lcm *= m[i] / d;
  }
  return make_pair((r + lcm) % lcm, lcm);
}

long long n, m;
vector<long long> a, b;

long long solve();

int main() {
  cin >> n >> m;
  M = m;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  for(int i = 0; i < n; ++i) b.push_back(a[i] / 2);
  pair<long long, long long> res = ChineseRem(b, a);
  if(res == make_pair(-1LL, -1LL) || res.first > m)
    return 0;
  return (m - res.first) / res.second + 1;
}

Measured memory_bytes: 2168
#include <stdio.h>
#include <string.h>
#define N 200002
#define M 2019

char a[N];
int c[M] = {1};

int main()
{		
	int n, i, p10, x;
	long long ans = 0;
		
	scanf("%s", a);
	i = strlen(a) - 1;
	c[x = a[i] - 48] = p10 = 1;
	for(i--; i >= 0; i--){
		p10 = p10 * 10 % M;
		x += p10 * (int)(a[i] - 48) % M;
		if(x >= M) x -= M;
		ans += c[x];
		c[x]++;
	}
	printf("%lld\n", ans);
			
	return 0;
}

Measured memory_bytes: 1928
A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      tmp = 500*i + 100*j + 50*k
      if tmp==X:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <limits>
using namespace std;
// numeric_limits<double>::epsilon()
 
#define int int64_t
#define pr(x) cout << x << endl;
#define vi vector<int>
#define vii vector< vector<int> >
#define mp make_pair
#define f(i,n) for(i =0 ; i< n ; i++)
#define ff first
#define ss second
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
void solve();


int power(int a, int b)
{
    if(b==0) return 1;
    else if(b&1) return a*power(a*a,b/2);
    else return power(a*a, b/2);
}
 


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}
bool AreSame(double a, double b) {
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}
 
int  j=1, n, t, m=0, dot=0, i, k, q, a, x, y, n1, m1;

void extendGcd(int m, int n)
{
    if(n==0)
    {
        x=1;
        y=0;
        dot=m;
    }
    else
    {
        extendGcd(n,m%n);
        q = x;
        x = y;
        y = q - (m/n)*y;
    }
    

}

string s1, s2,s3;
void solve()
{
    // cin >> t;while(t--)
    {
        cin >> x>> y;
        y = 2*y +1;
        if(x%y) cout << (x/y)+1;
        else cout << x/y; 
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N,M;
int a[200001];
int b[200001];
vector<int>G[200001];
bool used[200001];
int main(){
    cin>>N>>M;
    REP(i,M){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    bool check=false;
    REP(i,N){
        used[i]=false;
    }
    REP(i,G[0].size()){
        used[G[0][i]]=true;
    }
    REP(i,G[N-1].size()){
        if(used[G[N-1][i]]==true)check=true;
    }
    //REP(i,G[a[0]].size())cout<<G[a[0]][i]<<endl;
    //cout<<"aa"<<N-1<<endl;
    //REP(i,G[a[N-1]].size())cout<<G[a[N-1]][i]<<endl;
    if(check){
       cout<<"POSSIBLE"<<endl;
    }else{
       cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 13680
// --------------
// Tejas Pandey  |
// 26 - 01 - 20  |
// ATCODER #153  |
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		ll h,n,k;
		cin >> n >> k;
		ll a[n];
		for(int i = 0;i < n;i++)
			cin >> a[i];
		sort(a,a+n);
		ll s = 0;
		for(int i = 0;i < n - k;i++)
			s += a[i];
		cout << s << "\n";
	}
	return 0;
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

LL n, k, a[11], x;
Vl v;
Vl ans;

void gen(LL N, LL xx, LL l)
{
    if(l == xx){
        if(N >= n)
            ans.Pb(N);
        return;
    }

    for(auto i: v){
        gen(N * 10 + i, xx, l + 1);
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> k;

    LL A;
    for(LL i = 0; i < k; i++)
        cin >> A, a[A]++;

    for(LL i = 0; i <= 9; i++)
        if(!a[i])
            v.Pb(i);

    LL N = n;
    while(N){
        N /= 10;
        x++;
    }

    gen(0, x, 0);
    gen(0, x + 1, 0);

    LL mn = 1e14;

    for(auto i: ans)
        mn = min(mn, i);

    cout << mn << '\n';
    return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n;
    double ave=0.0,ans=9999999999,tmp=0;
    cin >> n;
    vector<double> a(n);
    rep(i,n){
        cin >> a[i];
        ave+=a[i];
    }
    ave/=n;
    repr(i,n){
        if(ans>=abs(a[i]-ave)){
            ans=abs(a[i]-ave);
            tmp=i;
        }
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256
d=[];
A=[];
N,K=input().split();
N=int(N);
K=int(K);
for i in range(K):
  d.append(input())
  A.append(input().split());
count=0;
for i in range(N):#i君がおかしを持っているか確認
  flag=0;
  for j in range(K):
    if(str(i+1) in A[j]):#i君が種類kのお菓子を持ってるか。
      flag=1;
  if (flag == 0):
    count+=1;
print(count);
  

Measured memory_bytes: 9532
import math
x,n = map(int,input().split())
p = [0]*n
if n != 0:
	p = list(map(int,input().split()))
X = x
y = x
while x in p:
	x += 1
while y in p: 
	y -= 1
if x-X >= X-y:
	print(y)
else:
	print(x)

Measured memory_bytes: 9196
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    for(int i=0;i<n;i++){
      arr[i]=sc.nextInt();
    }
    int count=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(arr[j]!=arr[i]){
          long a = arr[j]+arr[i];
          for(int k=j+1;k<n;k++){
          	if(arr[k]!=arr[i] && arr[k]!=arr[j] && valid(arr[i],arr[j],arr[k])){
            count++;
          	}
          }
      	}
      }
    }
    System.out.println(count);
  }
  public static boolean valid(int i, int j, int k){
    if(i+j<=k || i+k<=j || j+k<=i){
      return false;
    }
    return true;
  }
}


Measured memory_bytes: 36816
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n][2];
	for(int i=0;i<n;i++)
	cin>>a[i][0]>>a[i][1];
	int flag=0;
	for(int i=0;i<n-2;i++)
	{
		if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1])
		{
			flag++;
			break;
		}
	}
	if(flag==0)
	cout<<"No\n";
	else
	cout<<"Yes\n";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(){
	kaijo[0]=1;
	for(int i=1;i<=2000000;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}

int comb(int a,int b){
	if(!kaijo[0])init_fact();
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}

double dist(double ax,double ay,double bx,double by){
	return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
signed main(){
	int x,y;
	cin>>x>>y;
	if(x==1&&y==1)cout<<1000000<<endl;
	else{
		int a,b;
		if(x==1)a=300000;
		else if(x==2)a=200000;
		else if(x==3)a=100000;
		else a=0;
		if(y==1)b=300000;
		else if(y==2)b=200000;
		else if(y==3)b=100000;
		else b=0;
		cout<<a+b<<endl;
	}
	return 0;
}


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

void BubbleSort(string C[], int N)
{
  for(int i = 0; i < N; i++)
    for(int j = N - 1; j > i; j--)
      if(C[j][1] < C[j - 1][1])
	swap(C[j], C[j - 1]);
}

void SelectionSort(string C[], int N)
{
  for(int i = 0, minj; i < N; i++){
    minj = i;
    for(int j = i; j < N; j++)
      if(C[j][1] < C[minj][1])
	minj = j;
    swap(C[i], C[minj]);
  }
}

int main()
{
  int N;
  cin >> N;
  string a[N];
  string b[N];
  for(int i = 0; i < N; i++)
    cin >> a[i];
  copy(a, a + N, b);
  BubbleSort(a, N);
  for(int i = 0; i < N; i++)
    if(i)
      cout << " " << a[i];
    else 
      cout << a[i];
  cout << endl << "Stable" << endl;
  SelectionSort(b, N);
  for(int i = 0; i < N; i++)
    if(i)
      cout << " " << b[i];
    else 
      cout << b[i];
  cout << endl; 
  if(includes(a, a + N, b, b + N))
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;
}

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

int main()
{
	string s;
	cin >> s;
	int counter = 0;
	for (int i = 0; i < s.size(); i++)
		if (s[i] == '1') ++counter;
	cout << counter << endl;
	
	return 0;
}

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

using namespace std;

int main() {
    int n, x, ans = 0;
    scanf("%d %d", &n, &x);
    int arr[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    sort(arr, arr + n);

    for (int i = 0; i < n && x >= arr[i]; i++)
        i < n - 1 ? x -= arr[i], ans++ : x == arr[i] ? ans++ : ans = ans;

    printf("%d\n", ans);
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL burger[51];
LL Pcount[51];

LL dfs(LL depth, LL idx, LL X, LL prev_idx){
    //cout << depth << " : " << idx << " : " << X << " : " << prev_idx << endl;
    if(X == 0) return 0;
    if(depth == 1) {
        if(1 <= X - idx) return 3;
        if(0 == X - idx) return 2;
        if(-1 == X - idx) return 1;
        return 0;
    }
    if(idx == X) { return Pcount[depth - 1] + 1; }
    if(idx < X){ return Pcount[depth - 1] + 1 + dfs(depth-1, idx + burger[depth - 1] / 2 + 1, X, idx); }
    return dfs(depth - 1, (idx - prev_idx + 1) / 2 + prev_idx - 1, X - 1, prev_idx);
}

void solve(long long N, long long X){
    burger[0] = 1;
    Pcount[0] = 1;

    REP(i, N){
        burger[i+1] = burger[i] * 2 + 3;
        Pcount[i+1] = Pcount[i] * 2 + 1;
    }

    LL ans = dfs(N, burger[N-1]+1, X-1, 0);
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    solve(N, X);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))


Measured memory_bytes: 238680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S, T;
  cin >> S >> T;
  cout << T + S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
}
//1~n-1の総和の式がn*(n-1)/2

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  float money = 100.0f;
  const float RATE = 0.05f;
  int week;

  scanf("%d",&week);
  for(int i = 0;i < week;i++){
    money += money*RATE;
    if(money*1000.0f - (int)money*1000 > 0){
      money = (int)money + 1.0f;
    }
  }

  printf("%d\n",(int)money*1000);
  
return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

int  N;
ll D[100010];
int n[100010];

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

  cin >> N;
  rrep(i,N) cin >> D[i];

  vi ind(N);
  vi par(N+1);
  rep(i,N) ind[i] = i+1;
  sort(&ind[0], &ind[N], [](int i1, int i2) {
    return D[i1] > D[i2];
  });
  rep(i,N-1) {
    int ii = ind[i];
    ++n[ii];
    ll Dj = D[ii] + n[ii] * 2 - N;
    srep(j,i+1,N+1) {
      int ij = ind[j];
      if (D[ij] == Dj) {
        par[ii] = ij;
        n[ij] += n[ii];
        break;
      }
    }
    if (par[ii]==0) {
      cout << "-1\n";
      return 0;
    }
  }
  vpii ans;
  v(ll) s(N+1);
  rep(i,N-1) {
    int ii = ind[i];
    s[par[ii]] += s[ii] + n[ii];
    ans.pb(pii(ii, par[ii]));
  }
  if (s[ind[N-1]] != D[ind[N-1]]) {
    cout << "-1\n";
  } else {
    for (auto e : ans) {
      cout << e.fi << " " << e.se << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 5108
h,w=map(int,input().split())
while h:
    h-=1
    n=input()
    c=-1
    for i in range(w-1):
        if n[i]=='c':c=0
        print(c,end=" ")
        if c!=-1:c+=1
        if n[i+1]=='c':c=0
    print(c)

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

int main()
{
	int N,i,ans;
	cin >> N;
	int V[N],C[N];
	for(i=0;i<N;i++){
		cin >> V[i];
	}
	for(i=0;i<N;i++){
		cin >> C[i];
		if(V[i]>C[i]){
			ans += V[i]-C[i];
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1
count=0
m=0
Acount=0
#print(T)
for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T)
print(count)


Measured memory_bytes: 55884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)

bool check(vector<P> s){
    ll h = 0;
    for (P p : s){
        ll b = h + p.first;
        if (b < 0) return false;
        h += p.second;
    }
    return true;
}


int main() {
    ll n, sum = 0;
    cin >> n;
    string s;
    vector<P> ls, rs;
    rep1(i,n){
        cin >> s;
        ll m = 0, d = 0;
        rep1(j, s.size()){
            if (s[j] == '(') ++d;
            else --d;
            m = min(m,d);
        }
        if (d>0) ls.emplace_back(m, d);
        else rs.emplace_back(m-d, -d);
        sum += d;
    }
    sort(ls.rbegin(), ls.rend());
    sort(rs.rbegin(), rs.rend());
    string ans = "No";
    if (check(rs) && check(ls) && sum == 0) ans = "Yes";
    cout << ans << endl;
}

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

using pii = pair<int, int>;

int main() {
    int n;
    while(cin >> n, n) {
        vector<pii> scores;
        for(int i = 0; i < n; ++i) {
            int id; cin >> id;
            int t = 0;
            for(int j = 0; j < 4; ++j) {
                int m, s; cin >> m >> s;
                t += m * 60 + s;
            }
            scores.emplace_back(t, id);
        }
        sort(begin(scores), end(scores));

        cout << scores[0].second << endl;
        cout << scores[1].second << endl;
        cout << scores[n - 2].second << endl;
    }
}



Measured memory_bytes: 3184