akhauriyash/Code-Regression huggingface dataset:
from collections import deque, defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write

ca = ord('a')
class AhoCorasick:
    def __init__(self):
        self.root = root = [None]*30
        root[-2] = 0; root[-3] = 0
        root[-4] = 0
        self.nodes = [root]

    def add(self, s):
        node = self.root
        nodes = self.nodes
        for c in s:
            code = ord(c) - ca
            child = node[code]
            if not child:
                node[code] = child = [None]*30
                child[-2] = node[-2] + 1
                child[-3] = 0
                child[-4] = len(nodes)
                nodes.append(child)
            node = child
        node[-3] = 1

    def suffix(self):
        root = self.root
        que = deque([root])
        while que:
            v = que.popleft()
            if v[-1]:
                v[-3] += v[-1][-3]
            for i in range(26):
                if not v[i]:
                    if v[-1]:
                        v[i] = v[-1][i]
                    else:
                        v[i] = root[i] or root
                    continue
                if v[-1]:
                    v[i][-1] = v[-1][i]
                else:
                    v[i][-1] = root
                que.append(v[i])
        root[-1] = root

def solve():
    MOD = 10**9 + 7
    N, M, K = map(int, readline().split())
    if N == M == K == 0:
        return False
    mp = {}
    G = []
    S = []
    cur = 0
    fc = lambda x: ord(x) - ca
    for i in range(N):
        f, t = readline().strip().split()
        if f not in mp:
            mp[f] = cur
            G.append([])
            S.append(list(map(fc, f)))
            cur += 1
        if t not in mp:
            mp[t] = cur
            G.append([])
            S.append(list(map(fc, t)))
            cur += 1
        G[mp[f]].append(mp[t])
    *LS, = map(len, S)
    tree = AhoCorasick()
    for i in range(K):
        s = readline().strip()
        tree.add(s)
    tree.suffix()
    L = len(S)
    K = len(tree.nodes)
    G0 = [[None]*L for i in range(K)]
    for k in range(K):
        nd0 = tree.nodes[k]
        g = G0[k]
        for i in range(L):
            s = S[i]
            if len(s) > M:
                continue
            nd = nd0
            c = 0
            for e in s:
                nd = nd[e]
                c += nd[-3]
            if c <= 1:
                g[i] = (nd[-4], c)

    dp = [defaultdict(int) for i in range(M+1)]
    root = tree.root
    v0 = root[-4]
    for i in range(L):
        e = G0[v0][i]
        if e is None:
            continue
        w, c = e
        dp[LS[i]][i, w, c] = 1
    for i in range(M):
        for (v, p, c0), v0 in dp[i].items():
            v0 %= MOD
            g = G0[p]
            for w in G[v]:
                e = g[w]
                if e is None or i+LS[w] > M:
                    continue
                q, c = e
                if c0+c <= 1:
                    dp[i+LS[w]][w, q, c0+c] += v0
    ans = 0
    for (v, p, c0), v0 in dp[M].items():
        if c0 == 1:
            ans += v0
    write("%d\n" % (ans % MOD))
    return True
while solve():
    ...


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

if n % 2 == 1:
    b = a[::2]
    c = a[1::2]
    b.reverse()
    d = b+c
    print(' '.join(map(str,d)))
else:
    b = a[::2]
    c = a[1::2]
    c.reverse()
    d = c+b
    print(' '.join(map(str,d)))

Measured memory_bytes: 31300
type Point    = Float
type Distance = Float

distance :: (Point,Point) -> Distance
distance = abs . uncurry (-)

main :: IO ()
main = do
  [x,a,b] <- map read . words <$> getLine

  let da = distance (a,x)
      db = distance (b,x)

  case compare da db of
    LT -> putChar 'A'
    GT -> putChar 'B'


Measured memory_bytes: 508
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define N               100005
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void fio(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    fio();

    ll n;
    cin>>n;

    if(n >= 30) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}

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

int cnv(int t) {
	return (t/100)*60+(t%100);
}

int main() {
	int n, p, q;
	while (cin >> n >> p >> q, n) {
		int v[1440] = {};
		int k, a, b;
		for (int i=0; i<n; ++i) {
			cin >> k;
			for (int j=0; j<k; ++j) {
				cin >> a >> b;
				++ v[cnv(a)];
				-- v[cnv(b)];
			}
		}
		for (int i=1; i<1440; ++i) {
			v[i] += v[i-1];
		}
		int ret = 0;
		int c = 0;
		for (int t=cnv(p); t<cnv(q); ++t) {
			c = (v[t]==n ? 0 : c+1);
			ret = max(ret, c);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int mypow(int x,int n){
    if(n==0)
        return 1;
    if(n%2==1)
        return mypow(x,n-1)*x;
    int tmp=mypow(x,n/2);
    return tmp*tmp;
}
signed main() {
    int N;
    cin >> N;
    int ans = INF;
    for(int i = 0; i <= N; i++) {
        int cnt = N-i;
        int res = i;
        int sum = 0;
        while(res) {
            sum+=res%6;
            res/=6;
        }
        while(cnt) {
            sum+=cnt%9;
            cnt/=9;
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3520
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e5+5;
const int MOD=1e9+7;
const double PI=acos(-1);
const double e=2.718281828459;


int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i=1;i<=1e8;i++){
        if(floor(1.0*i*0.08)==a&&floor(1.0*0.1*i)==b){
            printf("%d\n",i);return 0;
        }
    }
    printf("-1\n");
    return 0;
}


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

int main(){
    string str;
    cin >> str;
    vector<int> a(4);
    rep(i, 4){
        a[i] = str[i] - '0';
    }    
    for(int bit = 0; bit < (1<<4); bit++){
        string s;
        s += (char)a[0] + '0';
        int sum = a[0];
        for(int i = 0; i < 3; i++){
            if(bit & (1<<i)){
                s += '+';
                sum += a[i + 1];
                s += (char)'0'+ a[i+1];
            }else{
                s += '-';
                sum -= a[i+1];
                s += (char)'0'+a[i+1];
            }
        }
        if(sum == 7){
            cout << s+"=7\n";
            break;
        }

    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<ll>> dp(n, vector<ll>(13, 0LL));
    if(s[0] == '?'){
        rep(i, 10)dp[0][i] = 1;
    }else dp[0][s[0]-'0'] = 1;

    ll mod = 1000000007;
    for(int i = 1; i < n; i++){
        if(s[i] == '?'){
            rep(j, 13)rep(k, 10){
                int m = (j * 10 + k) % 13;
                dp[i][m] += dp[i-1][j];
                dp[i][m] %= mod;
            }
        }else{
            int k = s[i] - '0';
            rep(j, 13){
                int m = (j * 10 + k) % 13;
                dp[i][m] += dp[i-1][j];
                dp[i][m] %= mod;
            }
        }
    }
    cout << dp[n-1][5] << endl;
}

Measured memory_bytes: 13696
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static String file = "../in";

    public static void main(String[] args) throws Exception
    {
        int test = 10,   // 0 for local testing, 1 for std input
            _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}

        new Main().c();

    }

    void d() throws Exception
    {

    }
    void c() throws Exception
    {
        String[] sp = in.readLine().split(" ");
        int n = Integer.valueOf(sp[0]),
            m = Integer.valueOf(sp[1]);
        int[] wa = new int[n + 1];
        boolean[] ac = new boolean[n + 1];
        for(int i = 0; i < m; i++)
        {
            sp = in.readLine().split(" ");
            int q = Integer.valueOf(sp[0]);
            if(sp[1].equals("WA"))
            {
                if(!ac[q]) wa[q]++;
            }
            else
            {
                if(!ac[q]) ac[q] = true;
            }
        }
        int acount = 0, wcount = 0;
        for(int i = 1; i <= n; i++)
        {
            if(ac[i])
            {
                acount++;
                wcount += wa[i];
            }
        }
        System.out.printf("%d %d\n", acount, wcount);
        
    }
    void b() throws Exception
    {
        String[] sp = in.readLine().split(" ");
        int n = Integer.valueOf(sp[0]),
            k = Integer.valueOf(sp[1]),
            m = Integer.valueOf(sp[2]);
        sp = in.readLine().split(" ");
        int sum = m * n;
        for(int i = 0; i < n - 1; i++) {
            sum -= Integer.valueOf(sp[i]);
        }
        if(sum <= k) System.out.println(Math.max(0, sum));
        else System.out.println(-1);
    }

    void a() throws Exception
    {
        char c = in.readLine().charAt(0);
        System.out.println((char)(c + 1));
    }
}

Measured memory_bytes: 47124
import sys
bingo = list(list(map(int, input().split())) for _ in range(3))
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo[i][j] = False
for i in range(3):
    for j in range(3):
        if bingo[i][j]:
            break
    else:
        print('Yes')
        exit()

for j in range(3):
    for i in range(3):
        if bingo[i][j]:
            break
    else:
        print('Yes')
        exit()

for i in range(3):
    if bingo[i][i]:
        break
else:
    print('Yes')
    exit()

for i in range(3):
    if bingo[i][2 - i]:
        break
else:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
ll gcd(ll a, ll b){
  if (a%b == 0){
    return(b);
  }else{
    return(gcd(b, a%b));
  }
}
ll lcm(ll a, ll b){
  return a * b / gcd(a, b);
}

map<ll, int > prime_factor(ll n) {
  map<ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
int main()
{
  ll A,B;
  cin >> A >> B;

  map<ll,int> mp=prime_factor(gcd(A,B));
  cout << mp.size()+1 << endl;
}

Measured memory_bytes: 256
n=io.read("*n")

function digit(n)
  local dig=1
  local c=n
  while math.floor(c/10)~=0 do
    dig=dig+1
    c=math.floor(c/10)
  end
  return dig
end

ans=0
for i=1,n do
  if digit(i)%2==1 then
    ans=ans+1
  end
end

print(ans)

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    long long n; std::cin >> n;
    for (long long k = 2; k <= 2*n; k++) {
        if (k*(k - 1) == 2*n) {
            std::cout << "Yes" << std::endl;
            std::vector<std::vector<int>> ans(k);
            int cur = 1;
            for (int i = 0; i < k; i++) {
                for (int j = i + 1; j < k; j++) {
                    ans[i].push_back(cur);
                    ans[j].push_back(cur);
                    cur++;
                }
            }
            std::cout << k << std::endl;
            for (int i = 0; i < k; i++) {
                std::cout << ans[i].size() << " ";
                for (int j = 0; j < k - 1; j++) {
                    std::cout << ans[i][j] << " \n"[j == k - 2];
                }
            }
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}

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

int pcnt(int x) {
  return __builtin_popcount(x);
}
int f(int x) {
  if (x == 0) return 0;
  return f(x%pcnt(x))+1;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> x(n);
  rep(i,n) x[i] = s[i]-'0';
  int pc = 0;
  rep(i,n) pc += x[i];
  vector<int> ans(n);
  rep(b,2) {
    int npc = pc;
    if (b == 0) npc++; else npc--;
    if (npc <= 0) continue;
    int r0 = 0;
    rep(i,n) {
      r0 = (r0*2)%npc;
      r0 += x[i];
    }
    int k = 1;
    for (int i = n-1; i >= 0; --i) {
      if (x[i] == b) {
        int r = r0;
        if (b == 0) r = (r+k)%npc;
        else r = (r-k+npc)%npc;
        ans[i] = f(r)+1;
      }
      k = (k*2)%npc;
    }
  }

  rep(i,n) cout << ans[i] << endl;
  return 0;
}


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

using namespace std;

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

// #define MOD 1000000007
#define MOD 998244353
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

const int v = 1000000;
ll inv[v + 1];
ll w[v + 1];
vector<ll> s[v + 1];

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  REP1(i, v) inv[i] = mod_inv(i);
  REP1(i, v) {
    w[i] += inv[i], w[i] %= MOD;
    for (int j = 2 * i; j <= v; j += i) {
      w[j] -= w[i], w[j] += MOD, w[j] %= MOD;
    }
  }
  REP(i, n) s[a[i]].push_back(a[i]);
  ll ans = 0;
  REP1(i, v) {
    ll sum1 = 0, sum2 = 0;
    for (int j = i; j <= v; j += i) {
      REP(k, s[j].size()) {
        sum1 += s[j][k], sum1 %= MOD;
        sum2 += (s[j][k] * s[j][k]) % MOD, sum2 %= MOD;
      }
    }
    ll x = 0;
    x += (sum1 * sum1) % MOD, x %= MOD;
    x -= sum2, x += MOD, x %= MOD;
    ans += (x * w[i]) % MOD, ans %= MOD;
  }
  ans *= inv[2], ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 45824
from operator import add
import sys
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e, operator_func=add):
        self.e = e # 単位元
        self.size = N
        self.node = [self.e] * (2*N)
        self.operator_func = operator_func # 処理(add or xor max minなど)

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size-1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        # [l, r) についてqueryを求める
        x = self.e
        l += self.size
        r += self.size

        while l<r:
            if l&1:
                x = self.operator_func(x, self.node[l-1])
                l += 1
            if r&1:
                r -= 1
                x = self.operator_func(x, self.node[r-1])
            l >>= 1
            r >>= 1
        return x


def solve():
    N, K = map(int, input().split())
    *P, = map(int, input().split())
    INF = 10**12

    tree_max = SegTree(N, -INF, operator_func=max)
    tree_max.set_list(P)
    tree_min = SegTree(N, INF, operator_func=min)
    tree_min.set_list(P)
    tree_monoinc = SegTree(N, INF, operator_func=min)
    for i in range(N):
        tree_monoinc.update(i, P[i]-P[i-1] if i else 0)

    def isMonoinc(l, r):
        # [l, r)
        l += 1
        return tree_monoinc.get(l, r)>=0

    ans = N-K+1
    orig = 0

    for i in range(N-K+1):
        if isMonoinc(i, i+K):
            orig = 1
            ans -= 1
        elif i+K<N and tree_max.get(i, i+K+1)==P[i+K] and tree_min.get(i, i+K+1)==P[i]:
            ans -= 1

    ans += orig
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 97604
# ACB157 C

n, m = map(int, input().split())
res = ["0"] * n

S = []
C = []

for i in range(m):
    s, c= map(int, input().split())
    S.append(s)
    C.append(c)

for i in range(m):
    #s, c = map(int, input().split())
    s, c = S[i], C[i]
    
    # 同じ桁で条件が違う場合はNG
    if res[s-1] != "0" and res[s-1] != str(c):
        res = -1
        break
    # 1桁目に0を指定する場合はNG
    elif n != 1 and s == 1 and c == 0:
        res = -1
        break
    else:
        res[s-1] = str(c)

if res == -1:
    print(res)
elif n == 1 and res[0] == "0":
    print(0)
else:
    if res[0] == "0":
        res[0] = "1"
    print(int("".join(res)))

Measured memory_bytes: 3064
import bisect

N = int(input())
S = '0'+input()+'0'

lst1 = []
lst2 = [0]*(N+2)


for i in range(1,N+1):
  if S[i] == '#':
    lst1.append(i)
  if S[N+1-i] == '.':
    lst2[N+1-i] = lst2[N+2-i] + 1
  else:
    lst2[N+1-i] = lst2[N+2-i]
    

if len(lst1) == N or lst2[1] == N:
  print(0)
  exit()
  
rlt = N+1
for i in range(len(lst1)):
  rlt =  min(rlt, i+lst2[lst1[i]])
  
rlt = min(len(lst1), rlt)
  
print(rlt)

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        string s;
        cin >> s;

        long q;
        cin >> q;

        deque<char> ans;
        for (auto &c : s) ans.push_back(c);

        bool inv = false;
        while (q--) {
            long t;
            cin >> t;

            if (t == 1) {
                inv = not inv;
            } else {
                long f;
                char c;
                cin >> f >> c;

                if (not inv and f == 2 or inv and f == 1) {
                    ans.push_back(c);
                } else {
                    ans.push_front(c);
                }
            }
        }
        if (inv) {
            reverse(ans.begin(), ans.end());
        }
        for (auto &c : ans) {
            putchar(c);
        }
        puts(" ");
    }
}


Measured memory_bytes: 4012
import math

n,m=map(int,input().split())
x=m*1800+n*100
ans=0
p=1

for i in range(1,10000):
  ans+=(x*i)*(p*(0.5**m))
  p-=p*(0.5**m)
  
ans=round(ans/100)

print(ans*100)

Measured memory_bytes: 65352
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
#include<iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
ll a[114];
signed main() {
	ll n, ans = 0;
	cin >> n;
	rep(i, 2 * n)cin >> a[i];
	sort(a, a + 2 * n);
	reverse(a, a + 2 * n);
	for (int i = 1; i < 2 * n; i += 2)ans += a[i];
	cout << ans << endl;
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    string s1,s2;
    cin>>s1>>s2;
    long long int ctr=0;
    for(long long int i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
        {
            ctr++;
        }
    }
    cout<<ctr;
return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int n; cin >> n;
    VI S(n);
    REP(i,n)
    {
        cin >> S[i];
    }
    int q; cin >> q;
    VI T(q);
    int ans = 0;
    REP(i,q)
    {
        cin >> T[i];
        int left = 0;
        int right = n;
        int mid;
        while(left < right)
        {
            mid = (left + right)/2;
            if(T[i] == S[mid])
            {
                ans++;
                break;
            }
            if(T[i] > S[mid])
            {
                left = mid + 1;
            }
            if(T[i] < S[mid])
            {
                right = mid;
            }
        }
    }
    cout << ans << endl;


}



Measured memory_bytes: 3368
while True:
    a,op,b = raw_input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        print a+b
    elif op == "-":
        print a-b
    elif op == "*":
        print a*b
    elif op == "/":
        print a/b
    else :
        break

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

int main() {
  vector<int> cooking(5), adjustment(5);
  int frac = -1, ans = 0;
  bool end = false;
  for (int i = 0; i < 5; i++) {
    cin >> cooking.at(i);
    adjustment.at(i) = cooking.at(i) % 10;
  }
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < 5; j++) {
      if (adjustment.at(j) == i) {
        frac = j;
        end = true;
        break;
      }
    }
    if (end == true) break;
  }
  if (frac == -1) {
    for (int i = 0; i < 5; i++) ans += cooking.at(i);
    cout << ans << endl;
  } else {
    for (int i = 0; i < 5; i++) {
      if (i != frac && adjustment.at(i) != 0) cooking.at(i) += 10 - adjustment.at(i);
      ans += cooking.at(i);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <random>

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 all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

constexpr int dy[] = {1,0,-1,0,1,-1,-1,1};
constexpr int dx[] = {0,1,0,-1,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A, B>;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
inline int updiv(int a, int b) { return (a + b - 1) / b; }


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

    int n;
    cin >> n;
    vector<pii> a;

    rep(i,n){
        int x;
        cin >> x;
        a.emplace_back(x,i);
    }

    sort(all(a));
    int res = 0;

    rep(i,n){
        int v,p;
        tie(v,p) = a[i];
        res += ((i & 1) != (p & 1));
    }

    cout << res / 2 << '\n';

    return 0; 

}

Measured memory_bytes: 2548
n = int(input())
S = []
C0 = 0
C1 = 0
C2 = 0
C3 = 0

for i in range(n):
  m = input()
  S.append(m)
  if m == 'AC':
    C0 += 1
  elif m == 'WA':
    C1 += 1
  elif m == 'TLE':
    C2 += 1
  elif m == 'RE':
    C3 += 1
    
print('AC x', C0)
print('WA x', C1)
print('TLE x', C2)
print('RE x', C3)

Measured memory_bytes: 16316
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int n;
LL a[55][55],b[55][55],c[55][55];
LL k;
int mod = 1e9+7;

int main() {
	scanf("%d%lld",&n,&k);
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			scanf("%lld",&a[i][j]);
			b[i][j] = 0;
		}
		b[i][i] = 1;
	}
	while (k) {
		if (k%2 == 1) {
			for (int i=0; i<n; i++) {
				for (int j=0; j<n; j++) {
					c[i][j] = 0;
					for (int d=0; d<n; d++) {
						c[i][j] += (b[i][d]*a[d][j])%mod;
					}
					c[i][j] %= mod;
				}
			}
			memcpy(b,c,sizeof(c));
		}

		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				c[i][j] = 0;
				for (int d=0; d<n; d++) {
					c[i][j] += (a[i][d]*a[d][j])%mod;
				}
				c[i][j] %= mod;
			}
		}
		memcpy(a,c,sizeof(c));
		k /= 2;
	}
	LL ret = 0;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			ret += b[i][j];
			//printf("%d ",b[i][j]);
		}
		//printf("\n");
	}
	printf("%lld\n",ret%mod);
	return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    sort(a.begin(),a.end());
    
    ll sum = 0;
    ll start = 0;
    
    
    sum = a[0];
    for (int i = 1; i < n; i++) {
        if(sum*2 < a[i] ){
            start = 0;
        }else{
            start++;
        }
        sum += a[i];
    }
    start++;
    
    std::cout << start << std::endl;
}


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

int main(void){
    long long N, A, B, ans;
    std::cin >> N >> A >> B;

    if ((B - A) % 2 == 0){
        ans = (B - A) / 2;
    } else {
        ans = std::min(A - 1, N - B) + 1 + (B - A - 1) / 2;
    }
    
    std::cout << ans << std::endl;

    return 0;
}


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

void printA(int A[], int N){
    for(int i = 0; i < N - 1; ++i){
        cout << A[i] << " ";
    }
    cout << A[N - 1] << "\n";
}

int selectionSort(int A[], int N){
    int nSwap = 0;

    for(int i = 0; i < N - 1; ++i){
        int minIdx = i;
        for(int j = i; j < N; ++j){
            if(A[minIdx] > A[j]){
                minIdx = j;
            }
        }
        if(i != minIdx){
            std::swap(A[i], A[minIdx]);
            ++nSwap;
        }
    }

    printA(A, N);
    return nSwap;
}

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

    int N;
    int A[100];

    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }

    cout << selectionSort(A, N) << "\n";

    return 0;
}


Measured memory_bytes: 3216
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
      long n,m;
      {
	  	var p = Console.ReadLine().Split().Select(i=>long.Parse(i)).ToArray();
        n=p[0];
        m=p[1];
      }
      var s = new tuple[n];
      for(int i = 0;i<n;i++)
      {
        s[i] = new tuple();
        var p = Console.ReadLine().Split().Select(j=>long.Parse(j)).ToArray();
        s[i].a = p[0];
        s[i].b = p[1];
      }
      long sum = 0;
      foreach(var p in s.OrderBy(v=>v.a))
      {
        if(m>p.b)
        {
          m-=p.b;
          sum += p.a*p.b;
        }
        else
        {
          sum += p.a*m;
          break;
        }
      }
      Console.WriteLine(sum);
    }
  class tuple
  {
    public long a;
    public long b;
  }
}

Measured memory_bytes: 23344
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    if K % 7 == 0:
        K = K // 7
    j = 1
    while True:
        if pow(10, j, K*9) == 1:
            print(j)
            break
        else:
            j += 1

        

Measured memory_bytes: 63156
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {

      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      int[] arr = new int[n];
      long[] sums = new long[n];
      long sum = 0;
      
      for(int i = 0; i < n ;i++) {
        arr[i] = scanner.nextInt();
        sum += arr[i];
        sums[i] = sum;
      }
      
      
      long[][] dp = new long[n][n];
      for(int l = n - 1; l >= 0; l--) {
        for(int r = l; r < n; r++) {
          if(l == r) {
            dp[l][r] = 0;
          }
          else {
            dp[l][r] = Long.MAX_VALUE;

            for(int i = l; i < r ;i++) {
              dp[l][r] = Math.min(dp[l][r], dp[l][i] + dp[i+1][r] 
                                  + Math.abs((l - 1 >=0 ? sums[l - 1] : 0) - sums[r]));
            }
          }
        }
      }       
      
        System.out.println(dp[0][n- 1]);
    }
}

Measured memory_bytes: 24532
n,m=map(int,input().split())
max_l=0
min_r=100000
for i in range(m):
  l,r=map(int,input().split())
  max_l=max(max_l,l)
  min_r=min(min_r,r)
print(max(0,min_r-max_l+1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn=(1e5)+10;
int n,m,ans=1;
struct node {
	int l,r;
} d[maxn];
bool cmp(node x,node y) {
	return (x.r<y.r)||(x.r==y.r&&x.l>y.l);
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++)
		scanf("%d %d",&d[i].l,&d[i].r),d[i].r--;
	sort(d+1,d+(m+1),cmp);
	int R=d[1].r;
	for (int i=2;i<=m;i++)
		if (d[i].l>R) R=d[i].r,ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
h = list(map(int,input().split()))
dame=[]
a=[0]*m
b=[0]*m
ans = 0
for i in range(m):
    a[i],b[i] = map(int,input().split())

for i in range(m):
    # print(h[a[i]-1], h[b[i]-1])
    if h[a[i]-1]<h[b[i]-1] and (not a[i] in dame):
        dame.append(a[i])
    elif h[a[i]-1]>h[b[i]-1] and (not b[i] in dame):
        dame.append(b[i])
    elif h[a[i]-1]==h[b[i]-1] and (not a[i] in dame):
        dame.append(a[i])
    if h[a[i]-1]==h[b[i]-1] and (not b[i] in dame):
        dame.append(b[i])


print(n-len(dame))

Measured memory_bytes: 84904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = 0;
		int k = 0;
		int[] weights = null;

		try {
			String[] in = br.readLine().split(" ");
			n = Integer.parseInt(in[0]);
			k = Integer.parseInt(in[1]);

			weights = new int[n];
			for (int i = 0; i < n; i++) {
				weights[i] = Integer.parseInt(br.readLine());
			}

			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		int low = 0;
		int high = Integer.MAX_VALUE;
		int mid = 0;

		while(low < high - 1) {

			mid = (low+high) / 2;

			int portable = howManyPortable(weights, n, k, mid);

			if(portable < n) {
				low = mid;
			} else {
				high = mid;
			}

		}

		System.out.println(high);

	}

	private static int howManyPortable(int[] weights, int n, int k, int p) {

		int index = 0;

		while(k > 0) {
			long sum = 0;
			while(true) {

				if(index == n) {
					k = 0;
					break;
				}

				sum += weights[index];

				if(sum > p) {
					k--;
					break;
				} else {
					index++;
				}

			}
		}

		return index;
	}
}

Measured memory_bytes: 35460
import itertools
N,C=map(int,input().split())
L=[[0 for i in range(C)] for j in range(3)]
D=[]
for i in range(C):
  D.append([int(x) for x in input().split()])
for i in range(N):
  s=[int(x)-1 for x in input().split()]
  for j in range(N):
    L[(i+j)%3][s[j]]+=1
ans=float("inf")
for per in itertools.permutations(range(C),3):
  kans=sum(sum(D[x][per[i]]*L[i][x] for x in range(C))for i in range(3))
  ans=min(ans,kans)
print(ans)

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  
  int n = s.length();
  set<string> sets;
  for (int l = 0; l < n; ++l) {
    for (int r = l+1; r <= min(n, l+k); ++r) {
      sets.insert(s.substr(l, r-l));
    }
  }
  auto itr = sets.begin();
  rep(i, k-1) ++itr;
  cout << *itr << endl;
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll A, B;
  cin >> A >> B;

  cout << (A + B) % 24 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

import sys
sys.setrecursionlimit(10 ** 6)
from collections import deque
input = sys.stdin.buffer.readline
INF = float("inf")

def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    AB = [tuple(map(int,input().split())) for _ in range(M)]
    for a,b in AB:
        G[a-1].append(b-1)

    Ans = [1]*(N+1)
    
    # 全ての頂点から, 閉路が存在しないかを確認する
    for s in range(N):
        prev = [-1]*N
        dist = [-1]*N
        dist[s] = 0
        dq = deque([s])
        while dq:
            v = dq.popleft()
            for nv in G[v]:
                if dist[nv] == -1:
                    dist[nv] = dist[v] + 1
                    prev[nv] = v
                    dq.append(nv)
                # 次が 0番目(開始地点) なら閉路あり
                if dist[nv] == 0 and prev[nv] == -1:
                    prev[nv] = v

        # 開始地点の前 が -1でない => 閉路あり
        if prev[s] != -1:
            v = prev[s]
            ans = set()
            for _ in range(max(dist)+1):
                ans.add(prev[v])
                v = prev[v]
            if len(Ans) > len(ans):
                Ans = list(ans)
    
    if len(Ans) == N+1:
        print(-1)
    else:
        print(len(Ans))
        Ans.sort()
        for v in Ans:
            print(v+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll mod = 1000000007;

int main(){
    int d, t, s; cin >> d >> t >> s;
  if(d > t * s) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#define N 21
using namespace std;
 
int main(){
  int n,m,x,y,rx,ry,l,cnt,d[N][N];
  char c;
  while(1){
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++) d[i][j]=0;
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>x>>y,d[N-y-1][x]=1;
    cin>>m;
    rx=ry=10;
    cnt=0;
    while(m--){
      cin>>c>>l;
      while(l--){
    if(c=='N') ry--;
    if(c=='E') rx++;
    if(c=='S') ry++;
    if(c=='W') rx--;
    if(d[ry][rx]) d[ry][rx]=0,cnt++;
      }
    }
    if(cnt==n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#--c--#
import sys,math,collections,itertools
input = sys.stdin.readline


X,K,D=list(map(int,input().split()))

#-近い位置までに必要な移動回数 L-#
L = abs(X)//D
if L>=K:
    ans = abs(X) - K*D

else:
    if (K-L)%2 == 0:
        ans = abs(X) - L*D
    else:
        ans = abs(abs(X) -(L+1)*D)
print(ans)


Measured memory_bytes: 9480
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vaibhav ios_base::sync_with_stdio(false);cin.tie(NULL);


int main()
{ vaibhav

  int n;
  cin>>n;
  double a[n],x;
  for(int i=0;i<n;i++)
  {cin>>x;
    a[i]=1/x;
  }
  double ss=accumulate(a,a+n,(double)0);
  double tt=1/ss;
  cout<<setprecision(10)<<tt;
  return 0;
  
}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000009LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  string S;
  cin >> S;
  ll N = S.size();
  vll count(2019, 0LL);
  ll num = 0LL;
  ll keta = 1LL;
  for(int i = N-1; i >= 0; i--){
    num += keta * (S.at(i)-'0') % 2019;
    num %= 2019;
    count.at(num)++;
    keta *= 10;
    keta %= 2019;
  }
  count.at(0)++;
  ll ans = 0;
  auto func = [](ll n){
    return n * (n-1) / 2LL;
  };
  for(int i = 0; i < 2019; i++){
    ans += func(count.at(i));
  }
  cout <<ans << endl;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 998244353;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

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

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;


bool solve(){
	ll a;cin>>a;
	string ans;
	while(a!=0){
		a--;
		ans.push_back('a'+a%26);
		a/=26;
	}
	reverse(all(ans));
	cout<<ans<<endl;
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 3652
#!/usr/bin/env python
# -*- coding: utf-8 -*-

t = input().rstrip()
list_t = []

for s in t:
    list_t.append(s)

ans_str = ""
for i, s in enumerate(list_t):
    if s == "?":
        list_t[i] = "D"

print("".join(list_t))




Measured memory_bytes: 87584
#include <stdio.h>

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int h[100000];
    for(int i=0;i<n;i++) scanf("%d",&h[i]);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(h[i]>=k) ans++;
    }
    printf("%d",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, K;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    ll ok = 0;
    ll ng = K + 1;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        ll sum = mid;
        ll before = mid;
        for(int i = 2; i <= N; i++) {
            before = before / 2;
            sum += before;
            if(before == 0) break;
        }
        if(sum <= K) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}



Measured memory_bytes: 3208
/*    
 *  eat_code    
 *  IIIT Allahabad
 */
#include <bits/stdc++.h>
//#include "pretty_print.h"
using namespace std;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define CONTAINS(a, x) (a.find(x) != a.end())
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define nl cout << endl
#define F first
#define S second

#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define CASET int ___T, case_n = 1; cin >> ___T; while (___T-- > 0) 


#define rep(it, st, en) for(ll it = st; it < en; it++)
#define rep1(it, st, en) for(ll it = st; it <= en; it++)
#define per(it, st, en) for(ll it = en - 1; it >= st; it--)

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef vector<vi> vvi;

ll INF = 1E9;
ll M = 1E9 + 7;

inline ll power (ll a,ll p){
    ll res = 1, x = a;
    while ( p ) {
        if ( p & 1 ) res = ( res * x );
        x = ( x * x ); p >>= 1;
    }
    return res;
}

template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
const int maxn = 1e5 + 5;
vvi g(maxn);
vi c(maxn, -1);
ll n, m;
bool dfs(int u){
    for(int v : g[u]){
        if(c[v] == -1){
            c[v] = c[u] ^ 1;
            if(!dfs(v))return false;
        }else if(c[u] == c[v])return false;
    }
    return true;
}
int main() {
    boost;
    if(fopen("input.txt", "r")){
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    }
    cin >> n >> m;
    rep(i, 0, m){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    c[1] = 0;
    if(dfs(1)){
        ll ans = 0;
        for(int i = 1;i <= n;i++)ans += c[i];
        ans *= (n - ans);
        cout << ans - m << "\n";
    }else cout << (1LL * n * (n - 1)) / 2 - m << "\n";
    return 0;
}
//  Train Insane or Remain the same
 

Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;

    if(n%2==1){
        cout << n/2 << endl;
    } else {
        cout << n/2-1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int H[]=new int[N];
		boolean key[]=new boolean[N];
		ArrayList<ArrayList<Integer>> list=new ArrayList<ArrayList<Integer>>();
		int ans=0;
		for(int i=0;i<N;i++){
			H[i]=stdIn.nextInt();
			list.add(new ArrayList<Integer>());
		}
		for(int i=0;i<M;i++){
			int A=stdIn.nextInt()-1;
			int B=stdIn.nextInt()-1;
			ArrayList<Integer> C=new ArrayList<Integer>();
			C=list.get(A);C.add(B);list.set(A,C);
			C=list.get(B);C.add(A);list.set(B,C);
		}
		for(int i=0;i<N;i++){
			ArrayList<Integer> C=list.get(i);
			if(key[i]==false)
				for(int j=0;j<C.size();j++){
					if(H[i]<H[C.get(j)]){
						key[i]=true;
						break;
					}
					else
						if(H[i]==H[C.get(j)]){
							key[C.get(j)]=true;
							key[i]=true;
							break;
						}
						else
							key[C.get(j)]=true;
				}
		}
		for(int i=0;i<N;i++){
			if(key[i]==false)
				ans++;
		}
		System.out.println(ans);
	}
}


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

template <typename T>
long long largest_rectangle_hist(vector<T> &height) {
    stack<int> st;
    height.emplace_back(0);
    vector<int> left(height.size());
    long long ret = 0;
    for (int i = 0; i < height.size(); i++) {
        while (!st.empty() && height[st.top()] >= height[i]) {
            ret = max(ret, 1LL * (i - left[st.top()]) * height[st.top()]);
            st.pop();
        }
        left[i] = st.empty() ? 0 : st.top() + 1;
        st.emplace(i);
    }
    return ret;
}

int main() {
    int H, W; cin >> H >> W;
    vector<vector<int>> c(H, vector<int>(W));
    for (auto &ci: c) for (auto &cij: ci) cin >> cij;
    vector<vector<int>> dp(H, vector<int>(W, 0));
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (c[i][j]) dp[i][j] = 0;
            else dp[i][j] = i ? dp[i - 1][j] + 1 : 1;
        }
    }
    long long ans = 0;
    for (int i = 0; i < H; i++) {
        ans = max(ans, largest_rectangle_hist(dp[i]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24884