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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif
}

#define debug(x)    cerr << #x << ": <" << (x) << ">\n"
#define dotc()      int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second
#define mod         1000000007

using ll = long long;
using vi = vector<int>;

int main() {
  ioThings();

  ll h; cin >> h;
  ll cnt = 0;
  while (h) {
    cnt += cnt + 1;
    h /= 2;
  }
  cout << cnt;

  return 0;
}


Measured memory_bytes: 256
a=input()
b=int(input())
c=1
if a[0]!="1":
  print(a[0])
if a[0]=="1":
  for i in range(len(a)-1):
    if a[i]=="1" and a[i+1]=="1":
      c=c+1
    else:
      break
  if c>=b:
    print(1)
  else:
    print(a[c])

Measured memory_bytes: 9128
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        boolean[] a = new boolean[n + 1];
        
        for(int i = 0; i < m; i++) {
            int s = sc.nextInt();
            
            a[s] = true;
        }
        
        int mod = (int)1e9+7;
        
        int[] dp = new int[n + 1];
        
        dp[0] = 1;
        dp[1] = a[1] ? 0 : 1;
        
        for(int i = 2; i <= n; i++){
            if(!a[i]){
                dp[i] = (dp[i - 2] + dp[i - 1]) % mod;
            }
        }
        
        System.out.println(dp[n]);
        
    }
}


Measured memory_bytes: 46364
#include <stdio.h>

int main(void)
{
	int n;
	int chan;
	int coin;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		coin = 0;
		chan = 1000 - n;
		
		while (1){
			if (chan - 500 >= 0){
				chan -= 500;
				coin++;
			}
			else if (chan - 100 >= 0){
				chan -= 100;
				coin++;
			}
			else if (chan - 50 >= 0){
				chan -= 50;
				coin++;
			}
			else if (chan - 10 >= 0){
				chan -= 10;
				coin++;
			}
			else if (chan - 5 >= 0){
				chan -= 5;
				coin++;
			}
			else if (chan - 1 >= 0){
				chan -= 1;
				coin++;
			}
			if (chan == 0){
				break;
			}
		}
		printf("%d\n", coin);
	}
	
	return (0);
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scanner  = new Scanner(System.in);
		int[][] a = new int[3][3];
		String ans = "No";


		for(int i=0 ; i<3 ; i++) {
			for(int j=0 ; j<3 ; j++) {
				a[i][j] = scanner.nextInt();
			}
		}
		int n = scanner.nextInt();
		int[] b=new int[n];
		for(int i=0 ; i<n ; i++) {
			b[i] = scanner.nextInt();
		}

		for(int i=0 ; i<n ; i++) {
			for(int j=0 ; j<3 ; j++) {
				for(int k=0 ; k<3 ; k++) {
					if(b[i] == a[j][k]) {
						a[j][k] = 0;
					}
				}
			}
		}

		for(int i=0 ; i<3 ; i++) {
			if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0){
				ans = "Yes";
				break;
			}
			if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0 ) {
				ans = "Yes";
				break;
			}
			if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0 ) {
				ans = "Yes";
				break;
			}
			if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0 ) {
				ans = "Yes";
				break;
			}
		}

		System.out.println(ans);

		scanner.close();

	}
}

Measured memory_bytes: 35636
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, A, B;
ll ans;

int main() {
	scanf("%lld %lld %lld", &N, &A, &B);
	ans = min(N * A, B);
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int N, a[112];

int main()
{
	in >> N;
	rep(i, N) { in >> a[i]; }

	std::sort(a, a + N);

	out << a[N - 1] - a[0] << std::endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var d = new Dictionary<string, int>()
	    {
		{"SUN", 7},
		{"MON", 6},
		{"TUE", 5},
		{"WED", 4},
		{"THU", 3},
		{"FRI", 2},
		{"SAT", 1}
	    };

	string s = ReadLine();
	WriteLine(d[s]);
    }
}

Measured memory_bytes: 13268
from functools import reduce
from operator import mul

def two(a,ans):
    if a%2==0:
        return two(a//2,ans+1)
    else:
        return ans

N=int(input())
A=list(map(int,input().split()))

#ans1=0
ans2=0
#p=reduce(mul,A)
#ans1=two(p,ans1)
for i in range(N):
    ans2=two(A[i],ans2)
print(ans2)

Measured memory_bytes: 4708
n = int(input())
d = list(map(int, input().split()))
d.sort()
smallnum = int(len(d)/2) - 1
largenum = int(len(d)/2)
if d[smallnum] == d[largenum]:
    ans = 0
else: 
    ans = d[largenum] - d[smallnum]
print(ans)

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

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

    vi cs(S.size());
    vi ct(T.size());
    rep(i, S.size()) {
        cs[i] = S[i] - 'a';
    }
    rep(i, T.size()) {
        ct[i] = T[i] - 'a';
    }

    sort(cs.begin(), cs.end());
    sort(ct.begin(), ct.end());
    reverse(ct.begin(), ct.end());

    bool ok;
    if (S.size() < T.size()) {
        ok = true;
        for (int i = 0; i < S.size(); i++) {
            if (cs[i] < ct[i]) {
                ok = true;
                break;
            } else if (cs[i] > ct[i]) {
                ok = false;
                break;
            }
        }
    } else {
        ok = false;
        for (int i = 0; i < T.size(); i++) {
            if (cs[i] < ct[i]) {
                ok = true;
                break;
            } else if (cs[i] > ct[i]) {
                ok = false;
                break;
            }
        }
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int n; cin >> n;
    int sum = 0;
    int num;
    for(int i = 1; i <= n; i++){
        sum += i;
        if(sum >= n){
            num = i;
            break;
        }
    }
    vector<int> ans;
    for(int i = num; i >= 1; i--){
        if(n >= i){
            ans.push_back(i);
            n -= i;
        }
    }

    for(int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << endl;
    return 0;
}

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

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

  set<int> s;
  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    if (s.count(n) != 0) s.erase(n);//要素nの個数をcount
    else s.insert(n);
  }

  cout << s.size() << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int h, w; cin >> h >> w;

    int n; cin >> n;

    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        p[i] = make_pair(a, i+1);
    }

    sort(p.rbegin(), p.rend());

    vector<int> a;

    for (auto t : p) {
        for (int i = 0; i < t.first; ++i) {
            a.push_back(t.second);
        }
    }

    for (int i = 0; i < h; ++i) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; ++j) {
                cout << a[i * w + j] << ' ';
            }
        } else {
            for (int j = w-1; j >= 0; --j) {
                cout << a[i * w + j] << ' ';
            }
        }

        cout << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (b < c) {
    // a b c d
    cout << 0 << endl;
  } else if (a <= c and c <= b and b <= d) {
    // a c b d
    cout << b - c << endl;
  } else if (a <= c and d <= b) {
    // a c d b
    cout << d - c << endl;
  } else if (c <= a and b <= d) {
    // c a b d
    cout << b - a << endl;
  } else if (c <= a and a <= d and d <= b) {
    // c a d b
    cout << d - a << endl;
  } else {
    // c d a b
    cout << 0 << endl;
  }
  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int64 n,ans=0;
  cin>>n;
  int a[n];
  rep(i,n){
    cin>>a[i];
  }
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]++;
  }
  for(auto p:mp){
    int a=p.first,b=p.second;
    if(a<=b){
      ans+=b-a;
    }else{
      ans+=b;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n)cin>>a.at(i);
    sort(all(a));
    reverse(all(a));
    ll ans=0;
   ans+=a.at(0);
   if(n%2==0){
       for(int i=1;i<=(n-2)/2;i++){
           ans+=a.at(i)*2;
       }
   }else{ 
       int ashu=(n-2)/2;
       int i;
   for(i=1;i<=ashu;i++){
       ans+=a.at(i)*2;
   }
   ans+=a.at(i);
   }
    cout<<ans<<endl;
 }


Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);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 pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll a[220000];
vector<ll> p,m,r;
int main(){
    ll n,k,ans=1,tmp=0;
    cin>>n>>k;
    rep(i,0,n){
        cin>>tmp;
        tmp>=0?p.pb(tmp):m.pb(tmp);
    }
    sort(p.rbegin(),p.rend());
    sort(m.begin(),m.end());

    if(p.size()==0&&k%2==1){
       irep(i,n-1,n-k)ans=(ans*m[i])%mod;
    }
    else if(k==n){
        rep(i,0,p.size())ans=(ans*p[i])%mod;
        rep(i,0,m.size())ans=(ans*m[i])%mod;
    }
    else if(k%2==0) {
        ll cnt=0;
        ll ppos=0,mpos=0;
        while(cnt<k){
            ll pv=-1,mv=-1;
            if(p.size()>ppos+1)pv=p[ppos]*p[ppos+1];
            if(m.size()>mpos+1)mv=m[mpos]*m[mpos+1];

            if(pv>=mv){ans=(ans*(p[ppos]*p[ppos+1]%mod))%mod;ppos+=2;cnt+=2;}
            else {ans=(ans*(m[mpos]*m[mpos+1]%mod))%mod;mpos+=2;cnt+=2;}
        }
    }
    else{
        ans=p[0];
        ll cnt=1;
        ll ppos=1,mpos=0;
        while(cnt<k){
            ll pv=-1,mv=-1;
            if(p.size()>ppos+1)pv=p[ppos]*p[ppos+1];
            if(m.size()>mpos+1)mv=m[mpos]*m[mpos+1];

            if(pv>=mv){ans=(ans*(p[ppos]*p[ppos+1]%mod))%mod;ppos+=2;cnt+=2;}
            else {ans=(ans*(m[mpos]*m[mpos+1]%mod))%mod;mpos+=2;cnt+=2;}
        }
    }
    cout<<(mod+ans)%mod;

}




Measured memory_bytes: 5468
#include <cstdio>
#define INF 1e9
#define eps 1e-6
#define N 100010
typedef long long ll;

struct Edge{
	int to, next, val;
}e[N << 1];
int n, fir[N], cnt, maxx;
bool vis[N];

void add(int x, int y){
	e[++cnt].to = y;
	e[cnt].next = fir[x];
	fir[x] = cnt;
}

inline int max(int a, int b){
	return a > b ? a : b;
}

void dfs(int x, int fa, int v){
	//printf("%d %d %d\n", x, fa, v);
	for(int i = fir[x]; i; i = e[i].next){
		if(e[i].to == fa || vis[e[i].to]) continue;
		v = v % maxx + 1;
		e[i].val = v;
		vis[e[i].to] = 1;
		dfs(e[i].to, x, v);
	}
}

int main(){

	scanf("%d", &n);
	for(int i = 1, u, v; i < n; i++)
		scanf("%d%d", &u, &v), add(u, v), add(v, u);
	for(int i = 1; i <= n; i++){
		int s = 0;
		for(int j = fir[i]; j; j = e[j].next)
			s++;
		maxx = max(maxx, s);
	}
	for(int i = 1; i <= n; i++){
		int s = 0;
		for(int j = fir[i]; j; j = e[j].next)
			s++;
		if(maxx == s){
			s = 0;
			for(int j = fir[i]; j; j = e[j].next)
				vis[i] = 1, s++, e[j].val = s, dfs(e[j].to, 0, s);
			break;
		}
	}
	printf("%d\n", maxx);
	for(int i = 1; i < n; i++)
		printf("%d\n", max(e[i * 2 - 1].val, e[i * 2].val));

	return 0;
}


Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int N,M;
int X[100],Y[100],h[100];

void gcl(int& x,int& y){
    if(x<y) swap(x,y);
    while(y>0){
        int t=x%y;
        x=y;
        y=t;
    }
    return;
}


int main(){
    int N,K;
    cin>>N>>K;
    vector<int> x(N);
    rep(i,0,N) cin>>x[i];
    int ans=1000000000;
    rep(i,0,N-K+1){
        int j=i+K-1;
        ans=min(ans,x[j]-x[i]+min(abs(x[i]),abs(x[j])));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
N = int(input())
task = [list(map(int, input().split())) for i in range(N)]
task.sort(key=lambda x:x[1])
time = 0
for i in range(N):
  time += task[i][0]
  if time > task[i][1]:
    print("No")
    exit()
else:
  print("Yes")

Measured memory_bytes: 53600
import java.util.Scanner;

public class Main {
	public static int[] CountingSort(int[] A, int n, int k) {
		int[] B = new int[n], C = new int[k + 1];
		for (int i = 0; i < n; i++) {
			C[A[i]]++;
		}
		for (int i = 1; i < k + 1; i++) {
			C[i] += C[i - 1];
		}
		for (int i = n - 1; i >= 0; i--) {
			B[C[A[i]] - 1] = A[i];
			C[A[i]]--;
		}
		return B;
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = 10000;
		int[] A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		int[] B = CountingSort(A, n, k);
		StringBuilder sb = new StringBuilder();
		sb.append(B[0]);
		for (int i = 1; i < n; i++) {
			sb.append(" " + B[i]);
		}
		System.out.println(sb.toString());
	}
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int k[m];
    int tmp;
    vector<vector<bool> > s(m, vector<bool>(n, false));
    for(int i = 0; i < m; i++) {
        cin >> k[i];
        for(int j = 0; j < k[i]; j++) {
            cin >> tmp;
            s[i][tmp-1] = true;
        }
    }
    int p[m];
    for(int i = 0; i < m; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); i++) {
        vector<int> bit(m, 0);
        for(int j = 0; j < m; j++) {
            for(int k = 0; k < n; k++) {
                if((1 & (i >> k)) && s[j][k]) {
                    bit[j]++;
                }
            }
        }
        bool f = true;
        for(int j = 0; j < m; j++) {
            if(bit[j] % 2 != p[j]) f = false;
        }
        if(f) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, R;
    cin >> N >> R;
    if(N >= 10) cout << R << endl;
    else cout << R + 100 * (10 - N) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>21)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

Measured memory_bytes: 256
def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True

if __name__=='__main__':
    n,k = list(map(int, input().split()))
    W = list(map(int,[input() for _ in range(n)]))
    Pmax = sum(W)
    Pmin = max(W)
    while Pmin < Pmax:
        P = (Pmax + Pmin) // 2
        if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
    print(Pmax)

Measured memory_bytes: 17876
(function() {
  var isInRange, isNum, reader;

  isNum = function(n) {
    return n.match(/\d{1,3}/);
  };

  isInRange = function(n) {
    return n >= 1 && n <= 100;
  };

  reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
  });

  reader.on('line', function(line) {
    var a, b, sp;
    sp = line.split(/\s/);
    a = isNum(sp[0]) ? parseInt(sp[0], 10) : void 0;
    b = isNum(sp[1]) ? parseInt(sp[1], 10) : void 0;
    if (isInRange(a) && isInRange(b)) {
      return console.log((a * b) + " " + ((a + b) * 2));
    }
  });

}).call(this);

Measured memory_bytes: 15636
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x

a,b=map(int,input().split())
c=list(map(int,input().split()))
c.append(b)
c.sort()
for i in range(a):
    c[-1-i]-=c[-2-i]
b=0
for i in range(a):
    b=gcd(c[i+1],b)
print(b)

Measured memory_bytes: 14228
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
#include <string.h>
using namespace std;
#define INF 11000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

ll p[60];
ll num[60];
ll solve(int n,ll x){
    if(x==0) return 0;
    else if(n==0) return 1;
    else if(x<num[n-1]+2) return solve(n-1,x-1);
    else if(x==num[n-1]+2) return p[n-1]+1;
    else if(x<num[n-1]*2+3) return p[n-1]+1+solve(n-1,x-num[n-1]-2);
    else if(x==num[n-1]*2+3) return p[n-1]*2+1;
}

int main(){
    int N;
    ll X;
    cin>>N>>X;
    p[0]=1; num[0]=1;
    for(int i=1;i<=N;i++){
        p[i]=p[i-1]*2+1;
        num[i]=num[i-1]*2+3;
    }
    cout<<solve(N,X)<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	vector<ll> sum(n+1);
	rep(i,n) sum[i+1] = sum[i] + v[i];
	map<ll, ll> mp;
	rep(i,n+1) mp[sum[i]]++;
	ll ans = 0;
	for (auto p: mp) {
		ans += (p.second * (p.second - 1)) / 2ll;
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 18676
#include "stdio.h"
#include<iostream>

using namespace std;
#define NIL -1

struct Node{
  int parent;
  int left; //most left child 
  int right; //next right brother
  int depth;
};

void initNode(Node tree[], int N){
  for(int i=0;i<N;i++){
    tree[i].parent = NIL;
    tree[i].left = NIL;
    tree[i].right = NIL;
    tree[i].depth = NIL;
  }
}

void setDepth(Node tree[], int id, int depth){
  tree[id].depth = depth;

  int childId_now   = tree[id].left;
  int brotherId_now = tree[id].right;

  if(childId_now != NIL){
    setDepth(tree, childId_now, depth+1);
  }
  if(brotherId_now != NIL){
    setDepth(tree, brotherId_now, depth);
  }

}

int getRootId(Node tree[]){
  int i=0;
  while( tree[i].parent != NIL ){
    i++;
  }
  return i;
}

void outputTree(Node tree[], int N){
  for(int i=0;i<N;i++){
    cout << "node " << i << ": ";
    cout << "parent = " << tree[i].parent << ", ";
    cout << "depth = " << tree[i].depth << ", ";
    
    if(tree[i].parent == NIL){
      cout << "root" << ", ";
    }else if(tree[i].left == NIL){
      cout << "leaf" << ", ";
    }else{
      cout << "internal node" << ", ";
    }

    int dummy_id;
    dummy_id = tree[i].left;

    cout << "[";

    int counter;
    for(int j=0, counter=tree[i].left;counter!=NIL;j++, counter=tree[counter].right){
      if(j>0){
        cout << ", ";
      }
      cout << counter;
    }
    cout << "]" << endl;

    }
}


int main(void){
    
  int N;
  scanf("%d", &N);

  Node* tree = new Node [N];
  initNode(tree, N);
  
  int id, depth, child_id, left_brotherId;
  for(int i=0;i<N;i++){
    cin >> id >> depth;
    for(int j=0;j<depth;j++){
      cin >> child_id;
      
      if(j==0){
        tree[id].left = child_id;
      }else{
        tree[left_brotherId].right = child_id;  
      }
      
      left_brotherId = child_id;
      tree[child_id].parent = id;
    }
  }


  int root_id;
  root_id = getRootId(tree);

  setDepth(tree, root_id, 0);   

  outputTree(tree, N);
  
  delete [] tree;
  
  return 0;

}


Measured memory_bytes: 4392
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;

int main(){
  
  int a,b; cin >> a >> b;
  
  cout << max({a+a-1,a+b,b+b-1});
 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
#include <map>
#include <ctime>
#include <set>
 
#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) a.begin(),a.end()
 
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> co(200000,0),dp(n,0),da(n);
	int c;
	cin >> c;
	da[0]=c;
	dp[0]=1;
	co[c-1]=1;
	rip(i,n,1){
		cin >> c;
		da[i]=c;
		dp[i]=dp[i-1];
		if(da[i]!=da[i-1]){
			dp[i]=(co[c-1]+dp[i])%1000000007;
			co[c-1]=(dp[i-1]+co[c-1])%1000000007;
		}
	}
	cout << dp[n-1] << endl;
	//deb(dp);
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);

        int number = scn.nextInt();
        int [] box;
        box = new int[number];
        for(int i = 0; i < number; i++) box[i] = scn.nextInt();

        int count = scn.nextInt();
        for(int j = 0; j < count; j++){
            int check = scn.nextInt();
            if(solve(0,check,box,number)) System.out.println("yes");
            else System.out.println("no");
        }
    }
    static boolean solve(int i, int check,int[] box,int num){
        if(check == 0) return true;
        if(i >= num) return false;
        boolean result = solve((i + 1), check,box,num) || solve((i + 1),(check - box[i]),box,num);
        return result;
    }
}



Measured memory_bytes: 26696
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll r,g,c,x,y,i,j,k,sum=0;
    vector<ll>red,green,col;
    cin>>x>>y>>r>>g>>c;

    for(i=0; i<r; i++)
    {
        cin>>j;
        red.push_back(j);
    }
    sort(red.begin(),red.end(),greater<ll>());

    for(i=0; i<g; i++)
    {
        cin>>j;
        green.push_back(j);
    }
    sort(green.begin(),green.end(),greater<ll>());

    for(i=0; i<c; i++)
    {
        cin>>j;
        col.push_back(j);
    }
    sort(col.begin(),col.end(),greater<ll>());

    vector<ll>vec;
    for(i=0; i<x; i++)
        vec.push_back(red[i]);
    for(i=0; i<y; i++)
        vec.push_back(green[i]);
    for(i=0;i<c;i++)
        vec.push_back(col[i]);
    sort(vec.begin(),vec.end(),greater<ll>());

    for(i=0; i<x+y; i++)
        sum+=vec[i];
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 8944
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const char B = '#';
    const char W = '.';
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    REP(i,h) cin >> v[i];

    bool ans = true;
    REP(i,h) {
        REP(j,w) {
            if (v[i][j] == B) {
                bool tmp = false;
                if (i != 0  ) if (v[i-1][j  ] == B) tmp = true;
                if (i != h-1) if (v[i+1][j  ] == B) tmp = true;
                if (j != 0  ) if (v[i  ][j-1] == B) tmp = true;
                if (j != w-1) if (v[i  ][j+1] == B) tmp = true;
                if (!tmp) {
                    ans = false;
                    break;
                }
            }
        }
        if (!ans) break;
    }

    ATYN(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n,d[10000100][3];
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int p=a+max(d[i-1][1],d[i-1][2]); d[i][0]=p;
		int q=b+max(d[i-1][0],d[i-1][2]); d[i][1]=q;
		int r=c+max(d[i-1][1],d[i-1][0]); d[i][2]=r;
	}
	int ans=max(d[n][0],max(d[n][1],d[n][2]));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	int a,b;
	cin>>a>>b;
	cout<<a*b;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D, N;
  cin >> D >> N;
  if (N == 100) N++;
  cout << (ll)pow(100, D) * N << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include <numeric>
#include <iomanip>

#define ll long long
#define int long long
#define ld long double
#define endl "\n"
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(p) cerr<<#p<<'='<<(p.first)<<" "<<p.second<<endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
const ll MOD = 1e9 + 7;
const int N = 1e4+5;
const int demo = 10;
using namespace std;
const ll cfmod=998244353;
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
char button[4]={'L','R','U','D'};

// Ahhiya thi lakhvanu chalu thasse....

int arr[N];

signed main() {
    FAST
    int q = 1;
    //cin>>q;
    while (q--) {
        int n;
        cin>>n;
        memset(arr,0,sizeof(arr));
        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                for(int k=1;k<=100;k++){
                    int sum=(i*i)+(j*j)+(k*k);
                    sum+=(i*j)+(j*k)+(k*i);
                    if(sum<N){
                        arr[sum]++;
                    }
                }
            }
        }
        for(int i=1;i<=n;i++){
            cout<<arr[i]<<endl;
        }
    }
}

Measured memory_bytes: 3272
import sys
def solve(balls):
    if distribute(balls, [], []): print('YES')
    else: print("NO")
        
def distribute(balls, R, L):    
    if len(balls) != 0:
        next = balls[0]
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            if distribute(balls[1:], neoR, L): return True
        
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            if distribute(balls[1:], R, neoL): return True
    else:
        return isOrdered(R) and isOrdered(L)

def isMutch(next, lis):
    if len(lis) != 0:
        return next >= lis[len(lis)-1]
    return True
    
def isOrdered(lis):
    #check both R and L are ordered
    checker = sorted(lis)
    return checker == lis

sys.setrecursionlimit(2**11)
size = int(input());
for i in range(size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)

Measured memory_bytes: 7588
#include<map>
	#include<iostream>
	#include<deque>
	#include<algorithm>
	#include<string>
	#include<cctype>
	#include<iomanip>
	#include<vector>
	#include<queue>
	#include<tuple>
	#include<stdio.h>
	#include<math.h>
	
	using namespace std;
	#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
	#define rep0(i,n) REP(i,0ll,n)
	#define rep1(i,n) REP(i,1ll,n+1)
	
	#define shosu setprecision(10)
	
	typedef long long ll;
	typedef pair<ll,ll> P;
	typedef pair<P,ll> Q;
	typedef pair<Q,ll> R;
	ll longinf=1ll<<60;
	int inf=1<<29;
	//mleしなければぜんぶllでかく。


	int main(){
		string s;
		cin>>s;
		int n=s.size();
		int m=0;
		rep0(i,n){
			if(i%2==0){
				if(s[i]=='0'){
					m++;
				}
			}
			else{
				if(s[i]=='1'){
					m++;
				}
			}
		}
		cout<<min(m,n-m)<<endl;
		return 0;
	}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <limits>
#include <queue>
#include <utility>


using ll = long long;
using namespace std;
ll L;

template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = std::vector< Edge< T > >;
template< typename T >
using Graph = std::vector< Edges< T > >;

vector<vector<ll>> dists(1000);
const ll inf = std::numeric_limits<ll>::max()/2;

template < typename T >
struct Dijkstra {
  using P = std::pair<T, int>; // <始点からの距離, 点のid>
  const int V; // 頂点数
  const T INF; // 十分に大きいがoverflowしない値として、型Tの最大値の半分を使う
  Graph<T> g;
  std::vector<T> dist; // 始点からの距離
  std::vector<bool> visit; // すでに探索済みの点か
  Dijkstra(Graph<T> &g): INF(std::numeric_limits<T>::max()/2), V(g.size()), g(g), dist(V), visit(V) {}
  Dijkstra(Graph<T> &g, int V): INF(std::numeric_limits<T>::max()/2), V(V), g(g), dist(V), visit(V) {}
  void init(int s) {
    std::fill(dist.begin(), dist.end(), INF);
    std::fill(visit.begin(), visit.end(), false);
    dist[s] = T(); // 始点の距離を0で初期化
    std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
    pq.push({dist[s], s});
    while (!pq.empty()) {
      P node = pq.top(); pq.pop();
      int from = node.second;
      if (visit[from]) continue;
      visit[from] = true;
      for (auto &e : g[from]) {
        if (visit[e.to]) continue;
        T d = node.first;
        T rem = d%(L+1);
        // cerr << s << " " << e.to << " " << d << " " << rem << " " << e.cost << endl;
        if (rem + e.cost > L) {
          d = (d-rem)+(L+1)+e.cost;
        }
        else { 
          d += e.cost;
        }
        if (d >= dist[e.to]) continue;
        // cerr << s << " " << e.to << " " << d << endl;
        dist[e.to] = d;
        pq.push({d, e.to});
      }
    }
    dists[s] = dist;
  }
};


int main() {
  int n, m; cin >> n >> m >> L;
  Graph<ll> g(n);
  for (int i = 0; i < m; ++i) {
    int a, b; ll c;
    cin >> a >> b >> c;
    --a; --b;
    if (c > L) continue;
    g[a].emplace_back(a,b,c);
    g[b].emplace_back(b,a,c);
  }
  Dijkstra<ll> di(g);
  for (int i = 0; i < n; ++i) {
    di.init(i);
  }
  int q; cin >> q;
  for (int i = 0; i < q; ++i) {
    int s, t; cin >> s >> t;
    --s; --t;
    ll d = dists[s][t];
    if (d == inf) cout << -1 << endl;
    else cout << d/(L+1) << endl;
  }
}


Measured memory_bytes: 5832
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    
    vector<int>a(N);
    for(int i = 0; i < N; i++)
        a.at(i) = 0;
    int b;
    
    for(int i = 0; i < N - 1; i++){
        cin >> b;
        a.at(b - 1)++;
    }
    for(int i = 0; i < N; i++)
        cout << a.at(i) << endl;
}


Measured memory_bytes: 4048
import java.util.*;
class Main
{
    static long[] p = new long[51], b = new long[51];
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        p[0] = 1;
        b[0] = 1;
        for(int i = 1; i <= 50; i++){
            p[i] = p[i-1] * 2 + 3;
            b[i] = b[i-1] * 2 + 1;
        }
        System.out.println(func(n, x));
    }
    static long func(int n, long x){
        if(n == 0){
            if(x <= 0) return 0;
            else return 1;
        }
        else{
            if(x <= 1) return 0;
            else if(1 < x && x < 2 + p[n-1]) return func(n-1, x-1);
            else if(x == 2 + p[n-1]) return b[n-1] + 1;
            else if(2 + p[n-1] < x && x < 2 * p[n-1] + 3) return b[n-1] + 1 + func(n-1, x - p[n-1] - 2);
            else return 2 * b[n-1] + 1;
        }
    }
}

Measured memory_bytes: 25044
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>

using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    string command;
    int key;
    priority_queue<int> pq;

    while (1)
    {
        cin >> command;
        if (command == "end")
            break;
        else if (command == "insert")
        {
            cin >> key;
            pq.push(key);
        }
        else if (command == "extract")
        {
            cout << pq.top() << endl;
            pq.pop();
        }
    }

    return 0;
}



Measured memory_bytes: 7036
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
#define int int64_t
using namespace std;
int n, aux, res, p;
int nrdiv(int n)
{
    int p = 1, d = 2, Exp = 0;
    if (n % d == 0) {
        while (n % d == 0) {
            ++Exp;
            n /= d;
        }
        p *= (Exp + 1);
    }
    d = 3;
    while (n != 1) {
        if (n % d == 0) {
            Exp = 0;
            while (n % d == 0) {
                ++Exp;
                n /= d;
            }
            p *= (Exp + 1);
        }
        d += 2;
        if (n != 1 && d * d > n) {
            p *= 2;
            break;
        }
    }
    return p;
}
main() {
    DAU
    cin >> n;
    for (int k = 2; k * k <= n; ++k)
        if (n % k == 0) {
            aux = n;
            while (n % k == 0)
                 n /= k;
            if (n % k == 1)
                ++res;
            n = aux;
    }
    res += nrdiv(n - 1);
    cout << res;
    PLEC
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()
li = list(S)
kaigai = 0
tsuka = 0
for x in li:
    if x == 'a':
        if tsuka + 1 <= A+B:
            print('Yes')
            tsuka += 1
        else:
            print('No')
    elif x == 'b':
        if tsuka +1 <= A+B and kaigai + 1 <=B :
            print('Yes')
            tsuka += 1
        else:
            print('No')
        kaigai += 1
    else:
        print('No')

Measured memory_bytes: 4784
def q2(data, num_list):
    data = [int(num) for d in data for num in d.split()]
    num_list = [int(n) for n in num_list]

    for num in num_list:
        data = [d if d != num else 0 for d in data]
        if check_bingo(data):
            return 'Yes'

    else:
        return 'No'


def check_bingo(data):
    # case1
    if sum(data[:3]) == 0: return True
    if sum(data[3:6]) == 0: return True
    if sum(data[6:]) == 0: return True
    if sum([data[0], data[3], data[6]]) == 0: return True
    if sum([data[3*i+1] for i in range(3)]) == 0: return True
    if sum([data[3*i + 2] for i in range(3)]) == 0: return True
    if sum([data[0], data[4], data[8]]) == 0: return True
    if sum([data[2], data[4], data[6]]) == 0: return True

    return False
  

data = [input() for _ in range(3)]

num = int(input())

num_list = [int(input()) for _ in range(num)]

print(q2(data, num_list))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>




#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

//B

int main(void) {
	int n;
	cin >> n;
	vector<int> h = vector<int>(n);
	rep(0, n) {
		cin >> h[i];
	}
	int max = 0;
	int ans = 0;
	rep(0, n) {
		if (h[i] >= max) {
			ans++;
			max = h[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

void solve(){
    int n;
    cin>>n;
    vector<int> x(n),y(n),p(n);
    for(int i{};i<(n);++i){
        cin>>x[i]>>y[i];
    }
    dsu d(n);
    iota(p.begin(),p.end(),0);
    sort(p.begin(),p.end(),[&](int i,int j){
        return x[i]<x[j];
    });
    set<pair<int,int>> st;
    for(auto&i:p){
        auto it=st.lower_bound(make_pair(y[i],i));
        int Y=y[i];
        if(it!=st.begin()) Y=st.begin()->first;
        for(auto itt=st.begin();itt!=it;){
            d.merge(i,itt->second);
            itt=st.erase(itt);
        }
        st.emplace(Y,i);
    }
    for(int i{};i<(n);++i){
        cout<<d.size(i)<<'\n';
    }
}

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

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    Int y, x;
} p_t;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    Int cnt = 0;
    for (Int i = 0; i < n; i++) {
        if (cnt + 1 == a[i]) {
            cnt++;
        }
    }
    dump(cnt == 0 ? -1 : n - cnt);
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
const long long INF = 1LL<<60;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

int main(){
    int n;  cin >> n;
    vector<double> x(n),y(n); rep(i,n) cin >> x[i] >> y[i];
    vector<vector<double>> d(n,vector<double>(n)), sam(n,vector<double>(n));
    double total=0;
    rep(i,n){
        reps(j,i+1,n){
            d[i][j] = d[j][i] = sqrt( pow(x[i]-x[j],2) + pow(y[i]-y[j],2) );
            total += d[i][j];
        }
    }
    rep(i,n){
        reps(j,i+1,n){
            sam[i][j] = sam[j][i] = total - d[i][j];
        }
    }
    double fact = 1;
    for(int i=n;i>0;--i) fact *= i;
    
    double ans = total*2/n;
    printf("%.10lf",ans);

        

    return 0;
}




Measured memory_bytes: 256
S = input()
K = int(input())
N = len(S)

# MLE対策
if K * 2 >= N-1:
    print(N)
    exit()

dp = [[[0 for _ in range(K+1)] for _ in range(N)] for _ in range(N)]
for i in range(N):
    for k in range(K+1):
        dp[i][i][k] = 1

for _j in range(1, N):
    for i in range(N):
        j = i + _j
        if j < N:
            for k in range(K+1):
                dp[i][j][k] = max(dp[i][j][k], dp[i+1][j][k], dp[i][j-1][k])
                if _j == 1:
                    if S[i] == S[j]:
                        dp[i][j][k] = 2
                    else:
                        if k+1 <= K:
                            dp[i][j][k+1] = 2
                else:
                    if S[i] == S[j]:
                        dp[i][j][k] = max(dp[i][j][k], dp[i+1][j-1][k] + 2)
                    else:
                        if k+1 <= K:
                            dp[i][j][k+1] = max(dp[i][j][k], dp[i+1][j-1][k] + 2)

print(max(dp[0][N-1]))



Measured memory_bytes: 147720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		scanner.close();
		if (8 >= A && 8 >= B)
			System.out.println("Yay!");
		else
			System.out.println(":(");
	}
}

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

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  int n=0;
  while(n<a){
    n+=k;
  }
  if(n<=b){
   cout << "OK" << endl; 
  }else{
   cout << "NG" << endl; 
  }
}

Measured memory_bytes: 3036
import math

A, B, H, M = map(int, input().split(' '))

#print(A, B, H, M)

# c²=a²+b²−2abcosΘ

# 角度さえ求まればいける
# Aは1分で0.5度づつ
# Bは1分で6度づつ
# AとBのどっちが左側にあるかもポイント

angle_a = (H * 30) + (M * 0.5)
angle_b = M * 6

#print("angle_a", angle_a)
#print("angle_b", angle_b)

cos = 0
ret = 0

if(angle_a == angle_b):
  #print("ぴったり")
  ret = abs(A - B)
else:
  if(angle_a > angle_b):
    cos = math.cos(math.radians(angle_a - angle_b))
    #print("時針のほうが先いってる", cos)
  else:
    cos = math.cos(math.radians(angle_b - angle_a))
    #print("分針のほうが先いってる", cos)
  
  ret = math.sqrt(A**2 + B**2 - 2 * A * B * cos)

print(ret)


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

int d[100], a[100];
map<vector<int>, int>id;
vector<int>re[5040];
int dp[100][5040];

int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	rep(i, n)scanf("%d", &a[i]);
	vector<int>v(7); iota(v.begin(), v.end(), 0);
	int p = 0;
	do {
		id[v] = p; re[p] = v;
		int cnt = 0, t = 0;
		for (int i : v) {
			rep(j, 7) {
				if ((t >> j & 1) && abs(j - i) <= d[j])cnt += a[j];
			}
			t |= 1 << i;
		}
		dp[0][p] = cnt;
		p++;
	} while (next_permutation(v.begin(), v.end()));
	int ans = 0;
	for (int i = 1; i + 6 < n; i++)rep(j, 5040)rep(k, 8) {
		auto t = re[j].begin();
		int cnt = 0, p = 0, o = 0;
		vector<int>q(7);
		rep(l, 8) {
			if (k == l) {
				rep(y, 8) {
					if ((p >> y & 1) && y + d[i - 1 + y] >= 7)
						cnt += a[i - 1 + y];
				}
				p |= 1 << 7; q[o++] = 6;
			}
			else {
				if ((p >> 7 & 1) && 7 - d[i + 6] <= *t)cnt += a[i + 6];
				p |= 1 << *t;
				if (*t)q[o++] = *t - 1;
				t++;
			}
		}
		int v = id[q];
		dp[i][v] = max(dp[i][v], dp[i - 1][j] + cnt);
		ans = max(ans, dp[i][v]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 5980
data = Array.new
i = 0

while (str = gets.chomp) != "0 0"
    data[i] = str.split " "
    i += 1
end

data.each do |status|
    for count1 in 1..status[0].to_i
        for count2 in 1..status[1].to_i
            print '#'
        end
        print "\n"
    end
    print "\n"
end

Measured memory_bytes: 6112
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
int n;
int x[102],cnt=0;

int main(){

int n,q;
cin>>n>>q;
string s;cin>>s;
int l[q],r[q];
rep(i,q){cin>>l[i]>>r[i];l[i]--;r[i]--;}
ll num[n];
num[0] = 0;
for (int i = 1; i < n; i++)
{
    if(s[i-1]=='A'&&s[i]=='C')num[i] = num[i-1]+1;
    else num[i] = num[i-1];
}
ll ans =0;
rep(i,q){
    if(l[i]>0&&s[l[i]]=='C'&&s[l[i]-1]=='A'){
        ans = num[r[i]]-num[l[i]-1]-1;
    }
    else{
        if(l[i]==0)ans = num[r[i]];
        else ans = num[r[i]]-num[l[i]-1];
    }
    cout << ans << endl;
}

return 0;
}

Measured memory_bytes: 2560
# ABC166_C.py
n,m=map(int,input().split())
h=list(map(int,input().split()))
G=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
from collections import deque
ans=0
for i in range(n):
  q=deque()
  q.append(i)
  while q:
    cur=q.popleft()
    ok=True
    for nx in G[cur]:
      if h[cur]>h[nx]:
        pass
      else:
        ok=False
    if ok:
      ans+=1
print(ans)




Measured memory_bytes: 29672
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;


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

const double EPS = 1e-11;
const double INF = 100000000;




int main(){
    int n;
    cin>>n;
    rep(i,n){
        double x[4],y[4],ax,ay,bx,by,ans;
        
        rep(j,4){
            cin>>x[j]>>y[j];
        }
        
        ax=x[1]-x[0];
        ay=y[1]-y[0];
        bx=x[3]-x[2];
        by=y[3]-y[2];
        
        ans=ax*by-bx*ay;
        if(fabs(ans)<=EPS)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1220