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


int main(){
    int a=1,n,k;
    cin>>n>>k;
    while(n/k>0){
        n=n/k;
        a++;
    }
    cout<<a<<endl;
    return 0;
}

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

typedef long long ll;

const ll mod = 1000*1000*1000+7;
int N;
vector<vector<char> > G;

int main() {
    scanf("%d", &N);
    G = vector<vector<char> >(2, vector<char>(N));
    for(int i = 0; i < 2; i++) {
        scanf("\n");
        for(int j = 0; j < N; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    int pos = 0;
    int pre = -1;
    ll ans = 1;
    while(pos < N) {
        if(G[0][pos] == G[1][pos]) {
            if(pre == -1) ans *= 3, ans %= mod;
            if(pre == 0) ans *= 2, ans %= mod;
            if(pre == 1) ans *= 1;
            pre = 0;
            pos++;
        }
        else {
            if(pre == -1) ans *= 6, ans %= mod;;
            if(pre == 0) ans *= 2, ans %= mod;
            if(pre == 1) ans *= 3, ans %= mod;
            pre = 1;
            pos += 2;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
import numpy as np
h, w = map(int, input().split())
arr = np.array([list(input()) for _ in range(h)]) == "."

l = np.zeros((h, w), dtype=int)
r = np.zeros((h, w), dtype=int)
u = np.zeros((h, w), dtype=int)
d = np.zeros((h, w), dtype=int)

for i in range(h):
    u[i] = (u[i - 1] + 1) * arr[i]
    d[- i - 1] = (d[- i] + 1) * arr[- i - 1]

for j in range(w):
    l[:, j] = (l[:, j-1] + 1) * arr[:, j]
    r[:, - j - 1] = (r[:, - j] + 1) * arr[:, - j - 1]

print(np.max(u + d + l + r) - 3)

Measured memory_bytes: 219800
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    int a, b, c;
    while(cin >> a >> b >> c && (a || b || c) ) {
        int r = min( min(a * a + b * b, a * a + c * c), b * b + c * c);
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) {
            int d;
            cin >> d;
            if ( r >= d * d * 4 ) {
                cout << "NA" << endl;
            } else {
                cout << "OK" << endl;
            }
        }
    }
     
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N,K;
  cin>>N>>K;
  vector<int> V(N);
  rep(i,N) cin>>V[i];
  int ans=0;
  rep(i,min(N,K)+1){
    rep(j,min(N,K)+1-i){
      vector<int> A;
      rep(k,i) A.push_back(V[k]);
      rep(k,j) A.push_back(V[N-1-k]);
      sort(all(A));
      int tmp=0;
      rep(k,i+j){
        if(k<K-(i+j)&&A[k]<0) tmp+=0;
        else tmp+=A[k];
      }
      ans=max(ans,tmp);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
int n,x;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		scanf("%d",&x);
		if (x%2==0) 
			if (x%3!=0&&x%5!=0) {
				printf("DENIED");
				return 0; 
			}
	}
	printf("APPROVED");
	return 0;
} 

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
  	cout << "Balanced" << endl;
  }
  else if (A + B < C + D) {
  	cout << "Right" << endl;
  }
}

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

using namespace std;

int dfs(int k, int last, int rest){
    if(k == 0 && rest == 0) return 1;
    if(k == 0) return 0;
    int res = 0;
    for(int i = last - 1; i > 0; i--){
        if(rest - i >= 0){
            res += dfs(k - 1, i, rest - i);
        }
    }
    return res;
} 
int main(){
    int N, K, S;
    while(cin >> N >> K >> S && N){
        cout << dfs(K, N + 1, S) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import collections
import math

N = int(input())
word_dict = {}

ans = 0

for _ in range(N):
    s = input()
    s = "".join(sorted(s))
    if s in word_dict:
        ans += word_dict[s]
        word_dict[s] += 1
    else:
        word_dict[s] = 1
    
print(ans)

Measured memory_bytes: 18188
N = int(input())
A = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

ex = []
if N % 2 == 1:
    ex.append(0)
    for i in range(1, N//2 + 1):
        ex.append(i*2)
        ex.append(i*2)
    ans = 2 ** (N//2)
    ans %= MOD
else:
    for i in range(N//2):
        ex.append(i*2 + 1)
        ex.append(i*2 + 1)
    ans = 2 ** (N//2)
    ans %= MOD

A.sort()
if A != ex:
    ans = 0


print(ans)

Measured memory_bytes: 13880
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

L, R = MAP()

if abs(L-R)+1 >= 2019:
	print(0)
	exit()

a = list(range(L, R+1))
ans = 2019

for x, y in combinations(a, 2):
	ans = min(ans, (x*y)%2019)

print(ans)


Measured memory_bytes: 5196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ')
				.Select(x => int.Parse(x))
				.ToArray();
			int a = input[0];
			int b = input[1];

			Console.WriteLine(b % a == 0 ? a + b : b - a);
		}
	}
}

Measured memory_bytes: 13268
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        int input =int.Parse(Console.ReadLine());
        Console.WriteLine(input/3);


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long ans = 1;
		int[] cnt = new int[n + 1];
		for (int i = 0; i < n; i++) {
			int c = cnt[a[i]]++;
			int c1 = Math.max(3 - c, 0);
			if (a[i] == 0) {
				ans *= c1;
				ans %= 1000000007;
			} else {
				int d = cnt[a[i] - 1];
				if (c > d) {
					System.out.println(0);
					return;
				}
				int d1 = Math.max(3 - d, 0);
				ans *= (c1 - d1);
				ans %= 1000000007;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 36700
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			double d = sc.nextDouble();
			if(d<=48.0)System.out.println("light fly");
			if(d>48.0 && d<=51.0)System.out.println("fly");
			if(d>51.0 && d<=54.0)System.out.println("bantam");
			if(d>54.0 && d<=57.0)System.out.println("feather");
			if(d>57.0 && d<=60.0)System.out.println("light");
			if(d>60.0 && d<=64.0)System.out.println("light welter");
			if(d>64.0 && d<=69.0)System.out.println("welter");
			if(d>69.0 && d<=75.0)System.out.println("light middle");
			if(d>75.0 && d<=81.0)System.out.println("middle");
			if(d>81.0 && d<=91.0)System.out.println("light heavy");
			if(d>91.0)System.out.println("heavy");
		}
	}
}

Measured memory_bytes: 19440
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
using namespace std;

int main() {
	int H, W, i, j, k, l;
	vector<vector<string>> str(26, vector<string>(26));
	string ans="",in,s = "snuke";
	char w;

	cin >> H >> W;


	for (k = 0; k < H; k++) {
		for (l = 0; l < W; l++) {
			cin >> str[k][l];
			
			}
		}

	for (k = 0; k < H; k++) {
		for (l = 0; l < W; l++) {
			in = str[k][l];
			if (in == s) {
				w = l + 65;
				cout << w << k + 1;
			}

		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> v(n), w(n);
  rep(i, n) cin >> v[i] >> w[i];

  //ll m = 3;
  ll m = min(n, (1LL << 9));
  vector<vector<ll>> dp(m, vector<ll>(100001, 0));
  FOR(j, w[0], 100001) dp[0][j] = v[0];
  FOR(i, 1, m) {
    rep(j, 100001) {
      dp[i][j] = dp[(i - 1) / 2][j];
      if (j - w[i] >= 0) chmax(dp[i][j], dp[(i - 1) / 2][j - w[i]] + v[i]);
    }
  }

  ll q;
  cin >> q;
  while (q--) {
    ll vs, l;
    cin >> vs >> l;
    vs--;

    vector<ll> resv, resw;
    while (vs >= m) {
      resv.push_back(v[vs]);
      resw.push_back(w[vs]);
      vs = (vs - 1) / 2;
    }
    ll ans = 0;
    ll vn = resv.size();
    rep(S, (1 << vn)) {
      ll rv = 0, rw = 0;
      rep(i, vn) {
        if (S >> i & 1) {
          rv += resv[i];
          rw += resw[i];
        }
      }
      if (l - rw >= 0) chmax(ans, rv + dp[vs][l - rw]);
    }
    cout << ans << '\n';
  }

  




  
  return 0;
}


Measured memory_bytes: 409456
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> a2b;

    for (int i=0; i < n; i++){
        int a, b;
        cin >> a >> b;
        a2b[a].push_back(b);
    }

    priority_queue<int> pri_que;
    int ans = 0;

    for (int day=m; day>=0; day--) {
        int deadline = m - day;
        if (deadline >= 0) {
            vector<int> rewards = a2b[deadline];
            for(auto r: rewards) pri_que.push(r);
            if(!pri_que.empty()){
                ans += pri_que.top();
                pri_que.pop();
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10880
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e5+5,INF=1e18;

void solve()
{
    string s;
    cin >> s;
    ll l =sz(s),c=0;

    f(i,0,l-1)
    {
        if(s[i]!=s[l-1-i])
            c++;
    }

    cout << c/2 ;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

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

int N;
string s;

int main() {
	cin >> N >> s;
	int left_west[300010], right_east[300010], cnt = 0;
	int ans = 100000000;
	for (int i = 0; i < N; i++) {
		left_west[i] = cnt;
		if (s[i] == 'W')cnt++;
	}
	cnt = 0;
	for (int i = N - 1; i >= 0; i--) {
		right_east[i] = cnt;
		if (s[i] == 'E')cnt++;
		ans = min(ans, left_west[i] + right_east[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1796
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long int
#define int ll
#define ft    front()
#define ps(a) push(a)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define inf_1 0x7FFFFFFF
#define inf_2 0x7FFFFFFFFFFFFFFFL
#define out(a) (cout << a << endl)
#define hello(a) (cout << "hello" << a << endl)
#define out_v(v) {for(int ___i = 0; ___i < v.size(); ++___i) cout << v[___i] << " "; cout << endl;}
#define fastio {ios::sync_with_stdio(0); cin.tie(0);}
#define mm(a, b) memset(a, 0, sizeof(c));
const int maxn = 20;
vector<int> g[maxn];
int calc(vector<int> &money, int bit, int n, int m, int x){
    
    vector<int> us = vector<int>(m, 0);
    
    int cost = 0;
    for(int i = 0; i < n; ++i){
        if(bit & (1 << i)){
            cost += money[i];
            for(int j = 0; j < m; ++j){
                us[j] += g[i][j];
            }
        }
    }

    bool ok_flag = true;
    for(int i = 0; i < m; ++i){
        if(us[i] < x){
            ok_flag = false;
            break;
        }
    }
    
    if(ok_flag == false){
        cost = inf_2;
    }
    return cost;
}
signed main(){

    fastio;
    
    int n, m, x;
    
    cin >> n >> m >> x;
    vector<int> money;
    
    for(int i = 0; i < n; ++i){
        
        int c;
        cin >> c;
        
        money.pb(c);
        for(int j = 0; j < m; ++j){
            int a;
            cin >> a;
            g[i].pb(a);
        }
    }

    int ans = inf_2;
    for(int i = 0; i < (1 << n); ++i){
        int cost = calc(money, i, n, m, x);
        ans = min({ans, cost});
    }
    
    if(ans != inf_2){
        out(ans);
    }
    else{
        out("-1");
    }
    return 0;
}

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

int dp(int n,int k,int arr[]){
	int result[n]={0};
	result[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
	    int min = INT_MAX;
	    for(int j=1;j<=k && (i-j)>=0;j++){
	        if(min > (result[i-j]+abs(arr[i]-arr[i-j]))){
	            min = result[i-j]+abs(arr[i]-arr[i-j]);
	        }
	    }
	    result[i] = min;
	}
	return result[n-1];
}

int main(){
  	int n,k;
  	cin >> n >> k;
  	int arr[n];
  	for(int i=0;i<n;i++){
    	cin >> arr[i];
    }
  	cout << dp(n,k,arr);
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**8)
N = int(input())
A = list(map(int,input().split()))
UV = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for u,v in UV:
    u,v = u-1,v-1
    es[u].append(v)
    es[v].append(u)

from bisect import bisect_left
lis = [A[0]]
stack = []
ans = [1] * N
def dfs(v,p=-1):
    for to in es[v]:
        if to==p: continue
        i = bisect_left(lis, A[to])
        if i == len(lis):
            stack.append((i,-1))
            lis.append(A[to])
        else:
            stack.append((i,lis[i]))
            lis[i] = A[to]
        ans[to] = len(lis)

        dfs(to,v)

        i,a = stack.pop()
        if a < 0:
            lis.pop()
        else:
            lis[i] = a

dfs(0)
print(*ans, sep='\n')

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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define dupli(a)     unique(all(a)),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " is " << x << endl;
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;


int main(){

 //    #ifndef ONLINE_JUDGE
 //    freopen("../input.txt", "r", stdin);
 //    freopen("../output.txt", "w", stdout);
	// #endif
 //    fast

    int n;
    cin>>n;
    int a[n],b[n];
    loop1(i,n){
    	cin>>a[i];
    	b[i]=i;
    }
    int c=0;
    loop1(i,n){
    	if(a[i]!=b[i]) c++;
    }
    if(c>2) pt("NO");
    else pt("YES");
    
    

}


/*

// 

*/

Measured memory_bytes: 3620
import sys
import math
import bisect

def main():
    n, k = map(int, input().split())
    s = set()
    for i in range(1, n + 1):
        s.add(i)
    for i in range(k):
        d = int(input())
        for a in list(map(int, input().split())):
            if a in s:
                s.remove(a)
    print(len(s))

if __name__ == "__main__":
    main()


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    if(B%A==0) cout << A+B << endl;
    else cout << B-A << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`


		`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */

	s := nextInt()
	a := map[int]int{s: 1}
	n := s

	f := func(n int) int {
		if n%2 == 0 {
			return n / 2
		}
		return 3*n + 1
	}

	for {
		n = f(n)
		c, _ := a[n]
		if c == 1 {
			break
		}
		a[n] = 1
	}
	ans := len(a) + 1

	//fmt.Fprintln(out, "[DEBUG]", d)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w, d;
  cin >> h >> w >> d;
  ll n = h * w;
  vector<P> p(n + 1);
  rep(i, h) rep(j, w) {
    ll a;
    cin >> a;
    p[a] = P(i, j);
  }
  ll q;
  cin >> q;
  vl l(q), r(q);
  rep(i, q) cin >> l[i] >> r[i];
  vl cost(n + 1, 0);
  rep2(i, 1, d + 1) {
    ll j = i;
    while(j + d <= n) {
      ll xf = p[j].first;
      ll yf = p[j].second;
      ll xt = p[j + d].first;
      ll yt = p[j + d].second;
      cost[j + d] = cost[j] + abs(xt - xf) + abs(yt - yf);
      j += d;
    }
  }
  rep(i, q) cout << cost[r[i]] - cost[l[i]] << '\n';
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int A[n+1];
    int B[n];

    REP(i,n+1){
        cin >> A[i];
    }
    REP(i,n) cin >> B[i];


    int ans = 0;

    REPR(i,n-1){
        //cout << ans << endl;
        ans += min(B[i],A[i+1]);
        B[i] -= min(B[i],A[i+1]);

        //cout << ans << endl;

        ans += min(A[i],B[i]);
        A[i] -= min(A[i],B[i]);
        //cout << ans << endl;
        //cout << endl;
    }   

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll h, w, n;
  cin >> h >> w >> n;
  ll a, b;
  a = max(h,w);
  ll ans = (n + a - 1) / a;
  cout << ans << endl;
}


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

using namespace std;

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

	int n = 0;
	int v = 0;
	int total = 0;
	for (int i = A; i <= B; i++) {
		int pos = i % 10;
		n = i / 10000 % 10;
		int a = i / 10 % 10;
		v = i / 1000 % 10;
		if (pos == n && a == v) {
			total++;
		}
	}

	cout << total << endl;

	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	bool ans = true;
	for(int i = 0; i < n; ++i){
		int a;
		cin >> a;
		if(a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)){
			ans = false;
		}
	}
	cout << (ans ? "APPROVED" : "DENIED") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 29
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

ll N, M;

class UnionFind {
    public:
    vector<int> par;
    UnionFind(int n) : par(n) {
        for(int i = 0; i < n; i++) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin >> N >> M;
    vector<ll> p(N), x(M), y(M);
    REP(i, N) {
        cin >> p[i];
        p[i]--;
    }
    REP(i, M) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    UnionFind uf = UnionFind(N);    
    REP(i, M) {
        uf.unite(x[i], y[i]);
    }
    map<int, int> d;
    priv(p);
    priv(uf.par);
    REP(i, N) {
        int root = uf.root(i);
        if(d.find(uf.root(i)) == d.end()) d[root] = 0;
        if(uf.same(i, p[i])) d[root]++;
    }
    int ans = 0;
    for(auto p : d) ans += p.second;
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7664
#include<bits/stdc++.h>
using namespace std;
long long a[1100],na,n;
bool p(int x){for (int i=2;i<x;i++)if (x%i==0)return 0;return 1;}
int main(){
	for (int i=2;i<=8000;i++)if (p(i))a[++na]=i;
	cin>>n;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++)
			if ((i+j)%2==0)cout<<a[(i+j)/2]*a[(i-j+n)/2+n+1]<<' ';
			else cout<<a[(i+j)/2]*a[(i-j+n+1)/2+n+1]*a[(i+j+1)/2]*a[(i-j+n-1)/2+n+1]+1<<' ';
		cout<<endl;
	}
	return 0;
}

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

int main(){
    int m,n;
    int b[100];
    int A[100][100];

    cin >> n >> m;

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

    for(int j=0;j<m;j++){
        cin >> b[j];
   }

    for(int i=0;i<n;i++){
        int c=0;
        for(int j=0;j<m;j++){
            c+=A[i][j]*b[j];
        }
        cout << c << endl;
    } 

    return 0;
}


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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n,m,c=0;
    cin>>n;
    ll a[n+10];
    ll mi=1e18;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mi=min(a[i],mi);
        if(mi==a[i])
            c++;
    }    
    cout<<c<<"\n";
  return 0;
 }

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lli long long int
#define MAX(A,B) A>B?A:B
#define MIN(A,B) A<B?A:B
#define gcd(A,B) __gcd(A,B)
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-12
#define ld long double
#define modulo 998244353
#define tmplarge (lli)1e4
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<int,double> pid;



int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",lcm(2,n));
}

Measured memory_bytes: 256
n = int(input())
s = input()

R_i = {}
G_i = {}
B_i = {}

ans = 0
for i in range(n) :
  if s[i] == 'R' :
    R_i[i] = 1
  if s[i] == 'G' :
    G_i[i] = 1
  if s[i] == 'B' :
    B_i[i] = 1

ans = len(R_i)*len(G_i)*len(B_i)

for ri in R_i :
  for gi in G_i :
    # Rが真ん中
    if 2*ri-gi in B_i :
      ans -= 1
    # Gが真ん中
    if 2*gi-ri in B_i :
      ans -= 1
    # Bが真ん中
    if (ri+gi)%2 == 0 :
      if (ri+gi)//2 in B_i :
        ans -= 1
    
print(ans)

Measured memory_bytes: 73852
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    string s,ss,sss;
    cin>>s>>ss>>sss; 
    if (s[sz(s)-1]==ss[0] and ss[sz(ss)-1]==sss[0])
        cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,M,C;
    cin >> N >> M >> C;
    
    int B[20] = {};
    for(int i=0;i<M;i++){
        cin >> B[i];
    }
     int tmp = 0,ans = 0;
    int A[20][20] = {};
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[i][j];
            tmp = tmp + A[i][j]*B[j];
        }
        if(tmp+C>0){
            ans++;
        }
        tmp = 0;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int 
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define fr(i,x) for(int i=0;i<x;i++)
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}
ll ar[MAX];
void divisor(){
    for (int i = 1; i <= MAX; i++)
    {
        for (int j = i; j <= MAX;j+=i)
        {
            ar[j]++;
            
        }
        
        
    }
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    ll h,n,k,x,c = 0;
    cin >>n >> k;
    vector<ll>a;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(),a.end(),greater<int>());
    for (int i = k; i < n; i++)
    {
        c += a[i];
    }
    cout << c << endl;
    
    
    
        
}

Measured memory_bytes: 5304
import numpy as np
A = []
for _ in range(3):
    A += list(map(int,input().split()))
# print('List of A: {}'.format(A))
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))
for v in b:
    if v in A:
        index = A.index(v)
        A[index] = 0
# print('List of A: {}'.format(A))
bingo_list = [[0,1,2],[3,4,5],[6,7,8],
        [0,3,6],[1,4,7],[2,5,8],
        [0,4,8],[2,4,6]]
for bingo in bingo_list:
    # print((np.array(A)[bingo]))
    # print(sum((np.array(A)[bingo])))
    if sum((np.array(A)[bingo])) == 0:
        print('Yes')
        exit()
print("No")

Measured memory_bytes: 12504
#include <iostream>
char whichClass(int math, int eng, int jpn)
{
    if (math == 100 || eng == 100 || jpn == 100) {
        return 'A';
    }
    if (math + eng >= 180) {
        return 'A';
    }
    int sum = math + eng + jpn;
    if (sum >= 240) {
        return 'A';
    }
    if (sum >= 210) {
        return 'B';
    }
    if (sum >= 150 && (math >= 80 || eng >= 80)) {
        return 'B';
    }
    return 'C';
}

int main()
{
    int n;
    int pm, pe, pj;
    while (true) {
        std::cin >> n;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < n; i++) {
            std::cin >> pm >> pe >> pj;
            std::cout << whichClass(pm, pe, pj) << std::endl;
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    int l,m,n;
    cin>>n>>m>>l;
    int a[n][m]={};
    int b[m][l]={};
    REP(i,n)REP(j,m){
        cin>>a[i][j];
    }
    REP(i,m)REP(j,l){
        cin>>b[i][j];
    }

    ll c[n][l]={};

    REP(i,n){
        REP(j,l){
            REP(k,m){
                c[i][j]+=a[i][k]*b[k][j];
            }
            cout<<c[i][j];
            if(j<l-1)cout<<" ";
            else cout<<endl;
            //DEBUG(c[i][j]);
        }
    }

    return 0;
}


Measured memory_bytes: 3236
a, b, h, m = gets.split(' ').map(&:to_i)

hmav = 360.to_f / (60 * 12)
mav = 360 / 60

hangle = (hmav * (60 * h + m)) % 360

mangle = mav * m

angle = (hangle - mangle).abs
angle = [angle, (360 - angle).abs].min

def rad(degree)
  degree * Math::PI / 180
end

result = Math.sqrt(a ** 2 + b ** 2 - (2 * a * b * Math.cos(rad(angle))))

puts result


Measured memory_bytes: 14580
n = int(input())
c = sorted(list(map(int, input().split())))[::-1]
M = int(1e9+7)
power = [1]
for i in range(200005):
    power.append(2*power[i] % M)
ans = 0
for i in range(n):
    ans += 2 * power[i] * (i * power[i-1] + power[i]) * c[i] * power[n-i-1]**2 % M
    ans %= M
print(ans)

Measured memory_bytes: 27108
#include <bits/stdc++.h>
 
using namespace std;
 
int n, m, cnt[100005], ans1, ans2, a[100005];
string b[100005];
bool bl[100005];
 
int main () {
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
	}
	for(int i = 1; i <= m; i++) {
		if(b[i] == "AC") {
			bl[a[i]] = 1;
		}
		else if(bl[a[i]] == 0) {
			cnt[a[i]]++;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(bl[i] == 1) {
			ans1++;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(bl[i] == 1) {
			ans2 += cnt[i];
		}
	}
	cout << ans1 << " " << ans2;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
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 n;

int main(){
  cin>>n;
  Q a(n);
  rep(i,n) cin>>a[i].second>>a[i].first;
  sort(a.begin(),a.end());

  ll time=0;
  bool flag=true;

  rep(i,n){
    time+=a[i].second;
    if(time>a[i].first){
      flag=false;
      break;
    }
  }

  if(flag) cout<<"Yes";
  else cout<<"No";
  cout<<endl;


  //rep(i,n) cout<<a[i].first<<a[i].second<<endl;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int N, M;
pair<int, Pair> LRC[POW_10_5];
int cost[POW_10_5+1];

int Ans() {
  sort(LRC, LRC+M);

  cost[1] = 0;
  FOR(i, 2, N) { cost[i] = INF; }

  REP(i, M) {
    int L = LRC[i].first;
    int R = LRC[i].second.first;
    int C = LRC[i].second.second;

    int j = R;
    while (j > L && cost[L] + C < cost[j]) {
      cost[j] = cost[L] + C;
      j -= 1;
    }
  }

  if (cost[N] == INF) {
    return -1;
  } else {
    return cost[N];
  }
}

signed main() {
  cin >> N >> M;
  REP(i, M) {
    cin >> LRC[i].first >> LRC[i].second.first >> LRC[i].second.second;
  }

  auto ans = Ans();

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


Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(10000)

n, x, y = map(int, input().split())
adj = [[] for _ in range(n)]
for i in range(n-1):
	adj[i].append(i+1)
	adj[i+1].append(i)
adj[x-1].append(y-1)
adj[y-1].append(x-1)


def dfs(x, r):
	for v in adj[x]:
		if dist[r][v] > dist[r][x] + 1:
			dist[r][v] = dist[r][x] + 1
			dfs(v, r)
	return

dist = [[10000 for _ in range(n)] for _ in range(n)]
for i in range(n):
	dist[i][i] = 0
	dfs(i, i)

ans = [0 for _ in range(n)]
for i in range(n):
	for j in range(i+1, n):
		ans[dist[i][j]] += 1
print(*ans[1:], sep="\n")

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

int main() {
    int a, b;
    cin >> a >> b;
  
    string s;
    s = to_string(a) + to_string(b);
    int n = stoi(s);

    for (int i=1; i<n; i++) {
        if (i * i == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int X; cin >> X;
	int res = 1;
	for (int base = 2; base * base <= X; base++) {
		int v = 1;
		while (v * base <= X) {
			v *= base;
		}
		res = max(res, v);
	}
	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
long long int a[60];//層の数
long long int p[60];//パティの数

long long int f(long long int N,long long int X){
  if(N==0)return 1;
  else if(X==1)return 0;
  else if(X<=1+a[N-1])f(N-1,X-1);
  else if(X==2+a[N-1])return p[N-1]+1;
  else if(X<=2+2*a[N-1])return p[N-1]+1+f(N-1,X-2-a[N-1]);
  else return 2*p[N-1]+1;
}

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

 a[0]=1;
 p[0]=1;
 for(int i=1; i<=50; i++){
   a[i]=3+2*a[i-1];
   p[i]=1+2*p[i-1];
 }
 cout<<f(N,X)<<endl;
 return 0;
}

Measured memory_bytes: 256
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    k = I()

    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for i in range(1, 10 ** 5 + 1):
        ln = q.popleft()

        if i == k:
            print(ln)
            break

        r = ln % 10
        new_ln = ln * 10 + r
        if r != 0:
            q.append(new_ln - 1)
        q.append(new_ln)
        if r != 9:
            q.append(new_ln + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
# after editorial
h,w = gets.strip.split.map(&:to_i)
c = gets.strip.split.map{|e| e.to_i + 1}
d = gets.strip.split.map{|e| e.to_i + 1}
s = [Array.new(w+4,-1),Array.new(w+4,-1)]
h.times do
  t = [-1,-1]
  gets.strip.each_char do |e|
    case e
    when '#'
      t.push -1
    when '.'
      t.push 0
    end
  end
  t.push -1
  t.push -1
  s.push t
end
s.push Array.new(w+4,-1)
s.push Array.new(w+4,-1)
q = [[c[0],c[1]]]
ct = 1
qq = []
loop do
  while q.size > 0
    hh,ww = q.shift
    if s[hh][ww] == 0
      if hh == d[0] && ww == d[1]
        p ct - 1
        exit
      end
      s[hh][ww] = ct
      qq.push [hh,ww] if s[hh][ww+1] == -1 || s[hh][ww-1] == -1 || s[hh+1][ww] == -1 || s[hh-1][ww] == -1
      q.push [hh,ww+1]
      q.push [hh,ww-1]
      q.push [hh+1,ww]
      q.push [hh-1,ww]
    end
  end
  ct += 1
  while qq.size > 0
    hh,ww = qq.shift
    5.times do |i|
      5.times do |j|
        hi = hh+i-2
        wj = ww+j-2
        if s[hi][wj] == 0
          q.push [hi,wj]
        end
      end
    end
  end
  q.uniq!
  if q.size == 0
    p -1
    exit
  end
end

Measured memory_bytes: 28856
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int64_t a, b, c;
	if (scanf("%" SCNd64 "%" SCNd64 "%" SCNd64, &a, &b, &c) != 3) return 1;
	puts(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b) ? "Yes" : "No");
	return 0;
}

/*

  (s(a) + s(b))^2
= a + b + 2 * s(a*b)

a + b + 2 * s(a*b) < c
2 * s(a*b) < c - a - b

c -a - b > 0 && 4 * a * b < (c - a - b)^2

*/


Measured memory_bytes: 1648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	cout << max(A * B,C * D) << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline int read() {
    int res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int main() {
    int n, lt, lx, ly;
    bool flag;
    std::cin >> n;
    lt = lx = ly = 0;
    flag = true;
    for (int i = 1; i <= n; i++) {
        int t, x, y;
        scanf("%d %d %d", &t, &x, &y);
        int dist = std::abs(x - lx) + std::abs(y - ly);
        int ts = t - lt;
        if (dist <= ts && (dist - ts) % 2 == 0) {
            continue;
        } else {
            flag = false;
            break;
        }
        lx = x, ly = y, lt = t;
    }
    if (flag) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
/**
 * Analyzing Login/Logout Records
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while (!(line = br.readLine()).equals("0 0")) {

			// record logs.
			Map<Integer, List<int[]>> log = new HashMap<Integer, List<int[]>>();
			StringTokenizer st;

			int r = parseInt(br.readLine());
			for (int i = 0; i < r; i++) {
				st = new StringTokenizer(br.readLine());
				int t, n, m, s;
				t = parseInt(st.nextToken());
				n = parseInt(st.nextToken());//not use
				m = parseInt(st.nextToken());
				s = parseInt(st.nextToken());
				if (!log.containsKey(m)) {
					log.put(m, new ArrayList<int[]>());
				}
				log.get(m).add(new int[]{t, s == 1 ? 1 : -1});
			}

			// answer
			int q = parseInt(br.readLine());
			for (int i = 0; i < q; i++) {
				st = new StringTokenizer(br.readLine());
				int ts, te, m;
				ts = parseInt(st.nextToken());
				te = parseInt(st.nextToken());
				m = parseInt(st.nextToken());
				int login = 0, total = 0;
				if (log.containsKey(m)) {
					for (int[] t : log.get(m)) {
						login += t[1];
						if (t[0] <= ts) {
							total = login > 0 ? te - ts : 0;
						} else if (ts < t[0] && t[0] < te) {
							if (t[1] == 1 && login == 1) {
								total += te - t[0];
							}
							if (t[1] == -1 && login == 0) {
								total -= te - t[0];
							}
						} else {
							break;
						}
					}
				}
				System.out.println(total);
			}
		}//end while
	}//end main
}

Measured memory_bytes: 26876
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vvll edges;
vll col;

bool isBipartite() {
    col[0] = 0;
    queue<ll> que; que.push(0);
    while (!que.empty()) {
        ll q = que.front(); que.pop();
        for (ll e: edges[q]) {
            if (col[e] == -1) {
                col[e] = col[q]^1;
                que.push(e);
            } else {
                if (col[e] == col[q]) return false;
            }
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    edges.resize(n);
    col.resize(n, -1);
    REP(i, m) {
        ll a, b; cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    if (isBipartite()) {
        ll bc=0, wc=0;
        REP(i, n) if (col[i]==0) wc++; else bc++;
        cout << bc * wc - m << '\n';
    } else {
        cout << n * (n-1) / 2 - m << '\n';
    }
    return 0;
}


Measured memory_bytes: 7168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, d;
		n = in.nextInt();
		d = in.nextInt();
		if (n % (2 * d + 1) == 0) {
			System.out.println(n / (2 * d + 1));
		} else {
			System.out.println(n / (2 * d + 1) + 1);
		}
		in.close();
	}
}


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

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

    vector<ll> A(N);
    for (size_t i = 1; i < N; i++)
    {
        cin >> A[i];
    }

    vector<ll> ans(N);
    for (size_t i = 1; i < N; i++)
    {
        ans[A[i] - 1]++;
    }

    for (size_t i = 0; i < N; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 6428