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

vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int h, w;

void bfs(vector<vector<char>> &s, vector<vector<int>> &d) {
  queue<pair<int, int>> q;
  q.push({0, 0});
  d.at(0).at(0) = 0;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
        if (s.at(nx).at(ny) == '.' && d.at(nx).at(ny) == -1) {
          d.at(nx).at(ny) = d.at(p.first).at(p.second) + 1;
          q.push({nx, ny});
        }
      }
    }
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> h >> w;
  
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s.at(i).at(j);
    }
  }
  
  vector<vector<int>> d(h, vector<int>(w, -1));
  bfs(s, d);
  
  if (d.at(h - 1).at(w - 1) == -1) {
    cout << "-1\n";
    return 0;
  }
  
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '.') ans++;
    }
  }
  ans -= d.at(h - 1).at(w - 1) + 1;
  
  cout << ans << '\n';
}

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    ll N, X, min_m, m;
    cin >> N >> X;
    min_m = 100000;
    int ans = 0;
    rep(i, N)
    {
        int temp;
        cin >> temp;
        X -= temp;
        min_m = min(int(min_m), temp);
        ++ans;
    }
    ans += X / min_m;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

signed main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].first >> A[i].second;
    }
    auto sorting = [](pair<int, int> a, pair<int, int> b) {
        return a.first < b.first;
    };
    sort(A.begin(), A.end(), sorting);
    vector<vector<int>> dp(N + 5, vector<int>(T + 50, 0));
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int time = A[i - 1].first;
        int value = A[i - 1].second;
        for (int j = 0; j < T; j++) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            if (T - time > j) dp[i][j + time] = max(dp[i][j + time], dp[i - 1][j] + value);
            else ans = max(ans, dp[i - 1][j] + value);
        }
    }
    for (int i : dp[N]) ans = max(ans, i);
    cout << ans << endl;
}


Measured memory_bytes: 72064
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
int n,m,cnt0,cnt1,cnt2,c[100100];
struct edge
{
    int v;
    edge *nxt;
} pool[400100],*tp=pool,*fst[100100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

bool dfs(int x,int w)
{
    if (c[x]!=-1)
        return c[x]!=w;
    c[x]=w;
    bool ret=0;
    for (edge *i=fst[x]; i; i=i->nxt)
        ret|=dfs(i->v,w^1);
    return ret;
}

int main()
{
    for (scanf("%d%d",&n,&m); m--;)
    {
        int u=getint(),v=getint();
        *tp=(edge){v,fst[u]},fst[u]=tp++;
        *tp=(edge){u,fst[v]},fst[v]=tp++;
    }
    memset(c,255,sizeof(c));
    repu(i,1,n)
        if (c[i]==-1)
            if (!fst[i])
                ++cnt0;
            else
                dfs(i,0)?++cnt2:++cnt1;
    LL ans=LL(cnt0)*n*2-LL(cnt0)*cnt0;
    ans+=LL(cnt1)*cnt1*2;
    ans+=LL(cnt1*2+cnt2)*cnt2;
    printf("%lld\n",ans);
    return 0;
}

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

long long arr[100005];

int main(){
long long n;
scanf("%lld",&n);
long long sum=0;
for (int x = 0; x<n; x++){
    scanf("%lld",&arr[x]);
    sum += arr[x];
}
if (sum%((n*(n+1LL))/2LL)!=0LL){
    printf("NO");
    return 0;
}
long long t = sum/((n*(n+1))/2);
for (int x = 0; x<n; x++){
    long long diff;
    if (x==0) diff = arr[0]-arr[n-1];
    else diff = arr[x]-arr[x-1];
    if (diff>t){
        printf("NO");
        return 0;
    }
    diff-=t;
    diff = -diff;
    if (diff%n!=0){
        printf("NO");
        return 0;
    }
}
printf("YES");
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String n = sc.next();

		if ( n.charAt(0)=='7' || n.charAt(1)=='7' || n.charAt(2)=='7' ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26908
# -*- coding: utf-8 -*-
"""
A - Shik and Stone
https://atcoder.jp/contests/agc007/tasks/agc007_a

"""
import sys


def solve(H, W, grid):
    x, y = 0, 0
    while True:
        grid[y][x] = '@'
        if x+1 < W and grid[y][x+1] == '#':
            x += 1
        elif y+1 < H and grid[y+1][x] == '#':
            y += 1
        else:
            break
    for row in grid:
        if '#' in row:
            return 'Impossible'
    return 'Possible'


def main(args):
    H, W = map(int, input().split())
    grid = [list(input()) for _ in range(H)]
    ans = solve(H, W, grid)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

int main()
{
  int h,w,k;cin>>h>>w>>k;
  vector<vector<ll>> dp(h+1,vector<ll>(w,0));
  dp[0][0]=1;
  int i,j,l;
  for(i=1;i<=h;i++)
  {
    for(j=0;j<(1<<(w-1));j++)
    {
      bool warp=false;
      for(l=0;l<w-2;l++)
      {
        if((j&(1<<l))&&(j&(1<<(l+1))))warp=true;
      }
      if(warp)continue;
      for(l=0;l<w;l++)
      {
        bool con=false;
        if(l>0&&(j&(1<<(l-1))))
        {
          dp[i][l]+=dp[i-1][l-1];
          dp[i][l]%=MOD;
          con=true;
        }
        if(l<w-1&&(j&(1<<l)))
        {
          dp[i][l]+=dp[i-1][l+1];
          dp[i][l]%=MOD;
          con=true;
        }
        if(!con)
        {
          dp[i][l]+=dp[i-1][l];
          dp[i][l]%=MOD;
        }
      }
    }
  }
  cout<<dp[h][k-1]<<endl;
}


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

set<int> list753{};

void dfs(long long x) {
    if(x >= 1000000000) return;
    vector<int> a(10, 0);
    string sx = to_string(x);
    for(int i = 0; i < sx.length(); i++) a[sx[i]-'0']++;
    if(a[3]>=1 && a[5]>=1 && a[7]>=1) {
        list753.insert(x);
    }    
    dfs(10*x + 3);
    dfs(10*x + 5);
    dfs(10*x + 7);
}

int main() {
    long long n; cin >> n;
    dfs(0);
    int ans = 0;
    for(auto it = list753.begin(); it != list753.end(); ++it) {
        if(*it <= n) {
//            cout << *it << endl;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

const int MAX=200010;


int main() {
    ios_base::sync_with_stdio(false); 

    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a),q(b),r(c+x+y);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    sort(p.begin(),p.end(),greater<>());
    sort(q.begin(),q.end(),greater<>());
    rep(i,c) cin >> r[i];
    int xx=min(x,a),yy=min(y,b);
    rep(i,xx) r[i+c]=p[i];
    rep(i,yy) r[i+c+x]=q[i];
    sort(r.begin(),r.end(),greater<>());
    ll ans=0;
    rep(i,x+y) ans+=r[i];
    cout << ans << endl;
    
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  
  for(int i = 0; i<n; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int Alice = 0;
  int Bob = 0;
  
  for(int i = 0; i<n; i++){
    if(i%2 == 0)
      Alice += a.at(i);
    else
      Bob += a.at(i);
  }
  cout << Alice - Bob << endl;
}

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

import math
import sys
from operator import itemgetter
input = sys.stdin.readline


# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

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

t_diff = []
for h in H:
	t_diff.append(abs(float(T - A - 0.006 * h)))
print(t_diff.index(min(t_diff))+1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> k(n);
    ll ans = 0;
    rep(i, n){
        cin >> k.at(i);
    }
    rep(i, n-1){
        ll sum = k.at(i)+k.at(i+1);
        if(sum > x){
            if(k.at(i+1) - (sum-x) > 0){
                k.at(i+1) -= sum-x;
                ans += sum-x;
            }else{
                k.at(i+1) = 0;
                ans += sum-x;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

template<class T>
class d_heap{
	static const int N_MAX=3000; // !!
	int n,d;
	T a[N_MAX];
public:
	d_heap(int d):n(0),d(d){}
	const T &find_min()const{ return a[0]; }
	void insert(const T &x){
		int u=n++;
		a[u]=x;
		while(u!=0 && a[(u-1)/d]>a[u]) swap(a[(u-1)/d],a[u]), u=(u-1)/d;
	}
	void delete_min(){
		a[0]=a[--n];
		for(int u=0;;){
			int v=u;
			for(int w=d*u+1;w<=d*u+d;w++) if(w<n && a[v]>a[w]) v=w;
			if(v==u) break;
			swap(a[v],a[u]);
			u=v;
		}
	}
	bool empty()const{ return n==0; }
	int size()const{ return n; }
};

#define define_heap d_heap< pair<int,int> > H(30);

const int INF=1<<29;

struct edge{ int v,cost1,cost2; };

int main(){
	for(int m,n;scanf("%d%d",&m,&n),n;){
		vector<edge> G[100];
		rep(i,m){
			int u,v,cost1,cost2; scanf("%d%d%d%d",&u,&v,&cost1,&cost2); u--; v--;
			G[u].push_back((edge){v,cost1,cost2});
			G[v].push_back((edge){u,cost1,cost2});
		}

		int q; scanf("%d",&q);
		while(q--){
			int s,t,type; scanf("%d%d%d",&s,&t,&type); s--; t--;

			int d[100];
			rep(u,n) d[u]=(u==s?0:INF);
			define_heap;
			H.insert(make_pair(0,s));
			while(!H.empty()){
				int d_now=H.find_min().first,u=H.find_min().second;
				H.delete_min();

				if(d[u]<d_now) continue;

				rep(i,G[u].size()){
					const edge &e=G[u][i];
					int d2=d_now+(type==0?e.cost1:e.cost2);
					if(d[e.v]>d2){
						d[e.v]=d2;
						H.insert(make_pair(d2,e.v));
					}
				}
			}

			printf("%d\n",d[t]);
		}
	}

	return 0;
}

Measured memory_bytes: 1168
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)


//0-index ?????????????????¶?????°?????????(????????????) verified AOJ DSL_2_G, (((CODEFESTIVAL2015-D)))
template<class T>
class lazySegmentTree{
private:
    vector<T> dat, lazy;
    int _size;  //the number of leaves
    T _init;
    
public:
    lazySegmentTree( vector<T> vec, T init = numeric_limits<T>::max() ): _init(init){
        if( vec.size()==0 )return ;
        
        _size = 1;
        while(_size<vec.size())_size*=2;
        dat.resize(_size*2);
        rep(i,vec.size())dat[i+_size] = vec[i];
        lazy.resize(_size*2,_init);
    }
    
    
    void eval(int num, int l, int r){
        if( lazy[num]==0 ) return ;
        dat[num] += lazy[num];
        
        if(r-l>1){  //?????§?????????
            lazy[num*2] += lazy[num]/2;
            lazy[num*2+1] += lazy[num]/2;
        }
        lazy[num] = 0;
    }
    
    
    
    T update(int s, int t, T x, int num=1, int l=0, int r=-1){
        if(r==-1)r =_size;
        eval(num,l,r);
        
        if(r<=s || t<=l) return dat[num];   //????±??????????
        if(s<=l && r<=t){
            lazy[num] += x * (r-l);
            eval(num,l,r);
        }
        else{
            dat[num] = update(s, t, x, num*2, l, (l+r)/2) + update(s, t, x, num*2+1, (l+r)/2, r);
        }
        return dat[num];
    }
    
    
    T find(int s, int t, int num=1, int l=0, int r=-1){
        if(r==-1)r = _size;
        eval(num,l,r);
        
        if(r<=s || t<=l) return _init;  //????±??????????
        if(s<=l && r<=t) return dat[num];
        else{
            return find(s, t, num*2, l, (l+r)/2) + find(s, t, num*2+1, (l+r)/2, r);
        }
    }
    
    int size(){ return _size; }
};

signed main(){
    int n,q;
    cin>>n>>q;
    
    lazySegmentTree<int> seg(vector<int>(n,0), 0);
    
    rep(i,q){
        int type,s,t,x;
        cin>>type;
        if(type==0){
            cin>>s>>t>>x;
            s--;
            seg.update(s,t,x);
        }else{
            cin>>s>>t;
            s--;
            cout<<seg.find(s,t)<<endl;
        }
    }
}

Measured memory_bytes: 7596
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

N,A = ilint()
ans = INF
for x in range(-100,101):
    tmp = 0
    for y in A:
        tmp += (x-y)**2
    ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 68132
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll   long long
#define pi pair<ll,ll>
ll a[2000000];
int main()
{
    IO;
    ll i, j, k, l=0, n, m, h, mod=1e9+7, cnt=0, mx = 0, t, ans=0, tc=0,r , b;

        cin>>n;
        for(i=1; i*i<=n; i++){
            for(j=1; j*j<=n; j++){
            for(k=1; k*k<=n; k++){
            l = i*i+j*j+k*k+i*j+k*j+k*i; a[l]++;
        }
        }
        }
        for(i=1; i<=n; i++) cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
int main() {
  char s;
  cin >> s;
  switch (s) {
    case 'A':
      cout << "T" << endl;
      break;
    case 'C':
      cout << "G" << endl;
      break;
    case 'G':
      cout << "C" << endl;
      break;
    case 'T':
      cout << "A" << endl;
      break;
  }
}

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

int main() {
    int n;cin>>n;
    long a[n],b[n];
    
    for(int i=0;i<n;++i){
        cin>>a[i];
        b[i]=0;
        while(a[i]>0){
            if(a[i]%2==0){
                a[i]/=2;
                b[i]+=1;
            }
            else break;
        }
    }
    sort(b,b+n);
    cout<<b[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>

using namespace std;

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

typedef vector<int> vi;

void eratos(int n, vi& a)
{
	vi isprime(n+1, 1);
	isprime[0] = isprime[1] = 0;
	reep(i, 2, n){
		if(isprime[i]){
			for(int j=i*2; j<=n; j+=i)
				isprime[j] = 0;
		}
	}

	rep(i, n+1){
		if(isprime[i])
			a.push_back(i);
	}
}

int main()
{
	vi prime;
	eratos(104743, prime);
	reep(i, 1, prime.size())
		prime[i] += prime[i-1];

	int n;
	while(scanf("%d", &n), n)
		printf("%d\n", prime[n-1]);

	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
A.sort()

lsum = 0
cnt = 0
for i in range(N-1):
    if (A[i] + lsum) * 2 >= A[i+1]:
        cnt += 1
    else:
        cnt = 0
    lsum += A[i]

print(cnt+1)


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vi A(N);
    REP(i, 0, N) cin >> A[i];

    long stock = 0;
    long cash = 1000;
    REP(i, 0, N-1){
        if(A[i] > A[i+1]){ //高値
            cash += A[i] * stock;
            stock = 0;
        }else{ //底値
            stock += cash/A[i];
            cash -= A[i] * (long)(cash/A[i]);
        }
        //cout << cash << " " << stock << endl;
    }
    cash += A[N-1] * stock;
    cout << cash << endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	string s,t;
	cin>>s>>t;

	string ans="";
	int flag=-1;
	rep(i,s.size()){
		if(s[i]=='?' || s[i]==t[0]){
			int j=i+1;
			while(j<s.size() && j-i<t.size()){
				if(s[j]==t[j-i] || s[j]=='?')j++;
				else break;
			}
			if(j-i==t.size())flag=i;
		}
	}
	
	if(flag==-1)cout<<"UNRESTORABLE";
	else {
		rep(i,s.size()){
			if(i==flag){
				cout<<t;
				i+=t.size()-1;
			}
			else if(s[i]=='?')cout<<'a';
			else cout<<s[i];
		}
	}
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int func(int a, int b) {
    if(a == 0) return 1;
    return b;
}

signed main() {
    int N; cin >> N;
    vector<int> vc(N);
    for(int i=0; i<N; i++) {
        char c; cin >> c;
        if(c == 'T') vc[i] = 1;
        else vc[i] = 0;
    }

    int ans = func(vc[0], vc[1]);
    for(int i=2; i<N; i++) {
        ans = func(ans, vc[i]);
    }
    cout << (ans ? "T" : "F") << endl;
    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
 
using namespace std;
 
struct segtree {
    vector<long long> dat;
    int n;
 
    segtree(int n_) {
        n = 1;
 
        while (n < n_) n *= 2;
 
        dat.resize(2*n, 0);
    }
 
    void update(int i, int x) {
        i += n - 1;
        int diff = x - dat[i];
        dat[i] = x;
 
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] += diff;
        }
    }
 
    long long query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r == -1) r = n;
 
        if (r <= a || l >= b) return 0;
 
        if (a <= l && r <= b) {
            return dat[k];
        }
 
        long long lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
        long long rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
 
        return lv + rv;
    }
};

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

    int N; cin >> N;
    vector<int> a(N), b(N);
 
    segtree P(N), Q(N);
    vector<pair<int, int>> A, B;
 
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
        A.push_back(make_pair(a[i], b[i]));
    }
 
    sort(begin(A), end(A));
 
    for (int i = 0; i < N; ++i) {
        B.push_back(make_pair(A[i].second, i));
    }
 
    sort(begin(B), end(B));
     
    for (int i = 0; i < N; ++i) {
        P.update(i, A[i].first);
        Q.update(i, 1);
    }
 
    long long ma = 0;
 
    for (pair<int, int>& d : B) {
        int l = 0, r = N;

        long long PP, QQ;
 
        for (int j = 0; j < 20; ++j) {
            int mid = (l + r) / 2;

            PP = P.query(0, mid + 1);
            QQ = Q.query(0, mid + 1);
 
            if (PP <= d.first * QQ) {
                l = mid;
            } else {
                r = mid;
            }
        }

        if (PP <= d.first * QQ) {
            ma = max(ma, QQ);
        }
 
        P.update(d.second, 0);
        Q.update(d.second, 0);
    }
 
    cout << ma << endl;
}

Measured memory_bytes: 29872
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node
{
    int p, l, r;
};
Node T[MAX];
int n;

void preParse(int u)
{
    if (u == NIL)
        return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u)
{
    if (u == NIL)
        return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u)
{
    if (u == NIL)
        return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main()
{
    int i, v, l, r, root;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++)
    {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL)
            T[l].p = v;
        if (r != NIL)
            T[r].p = v;
    }

    for (i = 0; i < n; i++)
        if (T[i].p == NIL)
            root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2740
#include <stdio.h>
#define FOR(x,n) for(int i=(x);i<(n);i++)
int main(void){
    int cap,ans=0;
    scanf("%d",&cap);
    int nums[cap+1];
    int *p=nums;
	FOR(0,cap){
      scanf("%i",p);
      p++;
    }
  	int min = 200001;
  	FOR(0,cap){
      if(nums[i]<min){
        min = nums[i];
        ans++;
      }
    }
    printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    vector<ll> a(n),b(n);
    for(auto &i:a)cin>>i;
    for(auto &i:b)cin>>i;
    if(accumulate(a.begin(),a.end(),0ll)>accumulate(b.begin(),b.end(),0ll)){cout<<"No";return 0;}
    for(int i=0;i<n;i++)b[i]-=a[i];
    ll aa=0,bb=0;
    
    for(int i=0;i<n;i++){
        if(b[i]>0)aa+=(b[i])/2;
        else if(b[i]<0)bb+=-b[i];
    }
    if(aa>=bb)cout<<"Yes";
    else cout<<"No";
    
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
int n;
int res;
vector<int>v;
int lst=-1;
int match[210];
int me,mo;
int mx;
bool f[10000010];
vector<int>ok[210];
bool vis[210];
int prm[1000010];
int sz;
int l;
bool bp(int x)
{
	vis[x]=true;
	for(int i=0;i<ok[x].size();i++)
	{
		int y=ok[x][i];
		if(match[y]==-1 || (!vis[match[y]] && bp(match[y])))
		{
			match[y]=x;
			match[x]=y;
			return true;
		}
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(x!=lst+1)
		{
			if(lst+1)v.push_back(lst+1);
			v.push_back(x);
		}
		lst=x;
		mx=lst+1;
	}
	v.push_back(lst+1);
	f[1]=true;
	for(int i=2;i<=mx;i++)
	{
		if(!f[i])prm[++sz]=i;
		for(int j=1;j<=sz;j++)
		{
			if(prm[j]*i>mx)break;
			f[prm[j]*i]=true;
			if(i%prm[j]==0)break;
		}
	}
	l=v.size();
	for(int i=0;i<l;i++)
	{
		match[i]=-1;
		if(v[i]&1)mo++;else me++;
		for(int j=i+1;j<l;j++)
		{
			if(v[j]-v[i]!=2 && !f[v[j]-v[i]])
			{
				ok[i].push_back(j);
				ok[j].push_back(i);
			}
		}
	}
	for(int i=0;i<l;i++)
	{
		if(match[i]>=0)continue;
		memset(vis,false,sizeof(vis));
		if(bp(i))res++;
	}
	printf("%d",res+((me-res)/2+(mo-res)/2)*2+((me-res)%2)*3);
	return 0;
} 

Measured memory_bytes: 13952
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

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

    sort(s.begin(), s.end());

    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        map<int,int> cnt;
        FOR(i,0,n) {
            int a; cin >> a; cnt[a]++;
        }
        bool good = false;
        if (cnt.size() == 1 && cnt.begin()->first == 0)
            good = true;
        if (n%3 == 0) {
            if (cnt.size() == 2) {
                const PII x = *cnt.begin();
                const PII y = *cnt.rbegin();
                good = x.first == 0 && y.second == 2*n/3;
            }
            if (cnt.size() == 3) {
                const PII x = *cnt.begin();
                const PII y = *++cnt.begin();
                const PII z = *++++cnt.begin();
                good =
                    (x.first ^ y.first ^ z.first) == 0 &&
                    x.second == n/3 &&
                    y.second == n/3 &&
                    z.second == n/3;
            }
        }
        cout << (good ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 3840
N, K = map(int, input().split(" "))
R, S, P = map(int, input().split(" "))
T = list(input())
te = [""] * N
kinsi = ''
score = 0
for i in range(N):
    if i >= K:
        kinsi = te[i-K]
    if T[i] == 'r':
        if kinsi != 'p':
            te[i] = 'p'
            score += P
        else:
            te[i] = ''
    if T[i] == 's':
        if kinsi != 'r':
            te[i] = 'r'
            score += R
        else:
            te[i] = ''
    if T[i] == 'p':
        if kinsi != 's':
            te[i] = 's'
            score += S
        else:
            te[i] = ''
print(score)


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

map<string,int>q;

int main()
{
	int n,maxn=0,x;
	cin>>n;
	int hash[n];
	string s[n];
	
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		x=s[i].size();
		q[s[i]]++;
	}
	
	sort(s,s+n);
	
	for(int i=0;i<n;i++)
		maxn=max(maxn,q[s[i]]);
	
	for(int i=0;i<n;i++)
		if(q[s[i]]==maxn)
		{
			cout<<s[i]<<endl;
			q[s[i]]=-1;
		}
	return 0;
}

Measured memory_bytes: 26752
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    vector<Int> A(N), B(N);
    rep(i, 0, N) cin >> A[i] >> B[i];

    Int res = 0;
    rrep(i, N-1, 0) {
        A[i] += res;
        if (A[i] % B[i] == 0) continue;
        res += (B[i] - A[i]%B[i]);
    }

    cout << res << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 1e9+7;
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int c;
	cin>>c;
	if(c>29) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3600
def main():
  a,b,k = list(map(int,input().split()))
  loop=0
  if a<b:
    loop=a
  else:
    loop=b
  now=0
  for i in reversed(range(1,loop+1)):
    if a%i==0 and b%i==0:
      now+=1
      if now==k:
        print(i)
        break
main()

Measured memory_bytes: 9144
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll power(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
            res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
      
      ll n;
      cin>>n;
      vector<pair<ll,ll>>v;
      for(int i=0;i<n;i++)
      {
          ll a,b;
          cin>>a>>b;
          v.pb({b,a});
      }
      sort(v.begin(),v.end());
      ll f=0;
      ll ans=0;
      for(int i=0;i<v.size();i++)
      {
          ans+=v[i].se;
          if(ans>v[i].fr)
          {
              f=1;
              break;
          }
      }
      if(!f) cout<<"Yes";
      else
      cout<<"No";
    
    
}







Measured memory_bytes: 6512
while a = gets
	sum = 0
	c = a.split(nil)
		if c[0].to_i == 1
			sum = 6000 * c[1].to_i
		elsif c[0].to_i == 2
			sum = 4000 * c[1].to_i
		elsif c[0].to_i == 3
			sum = 3000 * c[1].to_i
		else
			sum = 2000 * c[1].to_i
		end
	puts sum
end

Measured memory_bytes: 8680
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val % MOD : val % MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
const int MOD = 1000003;
typedef ModInt<MOD> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

void solve() {
    vector<mint> fact(MOD);
    fact[0] = 1;
    FOR(i, 1, MOD)fact[i] = fact[i - 1] * i;

    int Q;
    cin >> Q;
    rep(ITER, Q) {
        int x, d, n;
        cin >> x >> d >> n;
        if (x == 0) {
            cout << 0 << endl;
        } else if (d == 0) {
            cout << mint(x).pow(n) << endl;
        } else {
            int a = (mint(x) / d).toi();
            if (a + (n - 1) >= MOD) {
                cout << 0 << endl;
            } else {
                mint ans = fact[a + (n - 1)] * mint(d).pow(n);
                if (a >= 2)ans /= fact[a - 1];
                cout << ans << endl;
            }
        }
    }
}

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

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    int a,b; cin>>a>>b;
    cout<<max<int>({2*a-1,2*b-1,a+b})<<endl;;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 100

int main(void) {
    char buf[MAX + MAX], str[MAX], ptn[MAX];
    scanf("%s %s", str, ptn);
    strcpy(buf, str), strcat(buf, str);
    printf("%s\n", strstr(buf, ptn) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    k--;
    s[k] = s[k] + ('a' - 'A');
    cout << s << endl;
}


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


int sub(string s){
  int I,J=1,k,sum=0;
  string t;
  for(I=s.size()-1;I>=0;I--){
    if(s.at(I)=='+')J=1;
    else{
      t=s.at(I);
      sum+=atoi(t.c_str())*J;
      J*=10;
    }
  }
  return sum;
}

void sumget(string s,int i,long int &sum){
  string t="+";
  if(i<s.size()){
    sumget(s,i+1,sum);
    if(s.at(i-1)!='+'&&s.at(s.size()-1)!='+'){
    s=s.insert(i,t);
    sumget(s,i+2,sum);
    }
    sum+=sub(s);
  }
}

int main() {
  long int sum=0;
  string s;
  cin >>s;
  sum+=stol(s);
  sumget(s,1,sum);
  cout <<sum <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n)     for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

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

  string s;
  cin >> s;
  unordered_map<char, int> map;
  rep (i, 4) {
    ++map[s[i]];
  }
  bool check = true;
  if (map.size() != 2) check = false;
  allrep (m, map) {
    if (m.second != 2) check = false;
  }
  cout << (check ? "Yes" : "No") << endl;
  return 0;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    string s, t;
    ll ans = 0;
    cin >> s >> t;
    if(s[0] == t[0]) ans++;
    if(s[1] == t[1]) ans++;
    if(s[2] == t[2]) ans++;
    cout << ans << endl;

}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3608
N,X = map(int,input().split())
a,p = [1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N,X):
    if N==0:
        if X<=0:
            return 0
        else:
            return 1
    elif X<= 1+a[N-1]:
        return f(N-1,X-1)
    else:
        return p[N-1]+1+f(N-1,X-2-a[N-1])
print(f(N,X))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
long long a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(b>c)
	{
	cout<<0;
	return 0;
}
if(a==1)
{
	if(b!=c)
	cout<<0;
	else
	cout<<1;
	return 0;
}
cout<<(c*(a-1)+b)-(b*(a-1)+c)+1;
return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def Main(N, K, h):
    dp =[float('inf')]*N
    dp[0] = 0
    for i in range(N):
        for j in range(1, min(N-i,K+1)):
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
    return dp[N-1]

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(Main(N, K, h))

if __name__ == '__main__':
    main()

Measured memory_bytes: 55004
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

color=[-1]*100100
G=[[] for _ in range(100100)]

def f(st):
  st_c=color[st]
  for v,d in G[st]:
    if color[v]!=-1:
      continue

    if d%2==0:
      color[v]=st_c
    else:
      color[v]=abs(st_c-1)

    f(v)

def main():
  n=I()
  for _ in range(n-1):
    a,b,c=LI()
    a-=1
    b-=1
    G[a].append((b,c))
    G[b].append((a,c))

  color[0]=0
  f(0)

  for i in range(n):
    print(color[i])

main()
# print(main())


Measured memory_bytes: 83476
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
C=0
for i in range(N):
 B[A[i]-1]+=1
for i in range(N):
 if B[i]>=2:
  C+=B[i]*(B[i]-1)//2
for i in range(N):
 print(C-B[A[i]-1]+1)

Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  long double dist = V - W;
  long double distance = abs(B - A);
  if (dist * T >= distance)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    puts("0");
    return 0;
  }
  long long k_2 = a + b;
  if (k_2 % 2 == 0) {
    cout << k_2 / 2 << endl;
    return 0;
  }
  puts("IMPOSSIBLE");
  return 0;
}


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

int main() {

	int n; cin >> n;
	vector<ll> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			if (p[i] == i + 1) {
				swap(p[i], p[i - 1]);
				ans++;
			}
			continue;
		}
		if (p[i] == i + 1 ) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve(r0,w,c,r):
    c0 = r0/w
    if c0 >= c:
        print(0)
        return
    x = math.ceil((w*c-r0)/r)
    print(x)
    return

#Solve
if __name__ == "__main__":
    while 1:
        r0,w,c,r = LI()
        if r0 == w == c == r == 0:
            break
        solve(r0,w,c,r)



Measured memory_bytes: 8168
#include <cstdio>

long long v[3001][3001];
long long f[3001][3001][4];

int main(){
    int r, c;
    int i, j, t, k;
    int p, q;
    scanf("%d%d%d", &r, &c, &k);
    for(i = 1; i <= k; ++i){
        scanf("%d%d", &p, &q);
        scanf("%lld", &v[p][q]);
    }
    for(i = 1; i <= r; ++i)
        for(j = 1; j <= c; ++j){
            f[i][j][0] = f[i][j - 1][0];
            for(t = 1; t <= 3; ++t){
                f[i][j][t] = f[i][j - 1][t];
                if(f[i][j - 1][t - 1] + v[i][j] > f[i][j][t])
                    f[i][j][t] = f[i][j - 1][t - 1] + v[i][j];
            }
            for(t = 0; t <= 3; ++t){
                if(f[i - 1][j][t]> f[i][j][0])
                    f[i][j][0] = f[i - 1][j][t];
                if(f[i - 1][j][t] + v[i][j] > f[i][j][1])
                    f[i][j][1] = f[i - 1][j][t] + v[i][j];
            }
        }
    long long ans = 0;
    for(i = 0; i <= 3; ++i)
        if(ans < f[r][c][i])
            ans = f[r][c][i];

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

Measured memory_bytes: 353368
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll N;
    cin >> N;
    vec cnt(N, 0);
    Rep (i, N) {
        ll A;
        cin >> A;
        A--;
        cnt[A]++;
    }

    map<ll, ll> m;
    for (auto e : cnt) {
        m[e]++;
    }

    vec kinds(3e5+20, 0);
    Rep (i, 3e5+10) {
        ll tmp = 0;
        for (auto e : m) {
            tmp += min(e.first, i) * e.second;
        }
        kinds[i] = tmp;
    }

    // Rep (i, 10) {
    //     cout << kinds[i] << " \n"[i==9];
    // }

    for (ll t = 1; t <= N; t++) {
        ll ok = 0, ng = 3e5+10;
        while (abs(ok-ng) > 1) {
            ll mid = (ok + ng) / 2;
            if (kinds[mid] >= mid * t) ok = mid;
            else ng = mid;
        }
        cout << ok << "\n";
    }
}

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

using namespace std;

const int N = 200005;
const long long limit = 2e12;

long long a[N], b[N];

void usain_bolt()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
}

int main()
{
    usain_bolt();

    long long n, m, mn = 2000000000005LL;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) cin >> b[i];

    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    reverse(a + 1, a + 1 + n);

    long long left = 0, right = 2000000000005LL;

    while(left <= right) {
        long long mid = (left + right) / 2LL;
        long long need = 0;

        for(int i = 1; i <= n; ++i) {
            if(b[i]) {
                    long long sterg = mid / b[i];
                    need += max(0LL, a[i] - sterg);
            }
        }
        if(need <= m) mn = min(mn, mid), right = mid - 1LL;
        else left = mid + 1LL;
    }

    cout << mn;
    return 0;
}


Measured memory_bytes: 3328