akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int s[100006];
int dp[1005][2][1005];
struct segtree {
	int n = 1;
	vector<int>node, lazy;
	vector<bool>lazyf;
	void init(int N) {
		while (n < N)n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1);
		lazyf.resize(2 * n * 1, false);
	}
	void eval(int k, int l, int r) {
		if (!lazyf[k])return;
		node[k] = lazy[k] * (r - l)%mod;
		if (k < n - 1) {
			rep(i, 2)lazy[2 * k + i + 1] = lazy[k];
			rep(i, 2)lazyf[2 * k + i + 1] = true;
		}
		lazyf[k] = false;
	}
	void update(int a, int b, int x, int k, int l, int r) {
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = x%mod;
			lazyf[k] = true;
			eval(k, l, r);
			return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		node[k] = (node[k * 2 + 1] + node[k * 2 + 2])%mod;
	}
	int calc(int a, int b, int k, int l, int r) {
		eval(k, l, r);
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b)return node[k];
		int vl = calc(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = calc(a, b, k * 2 + 2, (l + r) / 2, r);
		return (vl + vr)%mod;
	}
	void repl(int a, int b, int x) {
		update(a, b, x, 0, 0, n);

	}
	int getsum(int a,int b) {
		return calc(a, b, 0, 0, n);
	}
};
segtree DP[2];
signed main() {
	int n, a, b; cin >> n >> a >> b;
	rep(i, n)cin >> s[i + 1];
	DP[0].init(n + 1);
	DP[1].init(n + 1);
	s[0] = -inf;
	DP[0].repl(0, 1, 1);

	rep(i, n) {
		int maxa = upper_bound(s, s + n + 1, s[i + 1] - a)-s;
		int maxb = upper_bound(s, s + n + 1, s[i + 1] - b)-s;
		int A = DP[1].getsum(0, maxa),B=DP[0].getsum(0,maxb);
		if (s[i + 1] - s[i] < a)DP[0].repl(0, n, 0);
		if (s[i + 1] - s[i] < b)DP[1].repl(0, n, 0);
		DP[0].repl(i, i + 1, DP[0].getsum(i,i+1)+A);
		DP[1].repl(i, i + 1, DP[1].getsum(i,i+1)+B);
	}

/*	
	dp[0][0][0] = 1;
	rep(i, n) {
		rep(k, i + 1) {
			if (s[i + 1] - s[i] >= a)dp[i + 1][0][k] += dp[i][0][k];
			if (s[i + 1] - s[i] >= b)dp[i + 1][1][k] += dp[i][1][k];
		}
		rep(k, i + 1) {
			if (s[i + 1] - s[k] >= b)dp[i + 1][1][i] += dp[i][0][k];
			if (s[i + 1] - s[k] >= a)dp[i + 1][0][i] += dp[i][1][k];
		}
	}
*/	
	int sum = DP[0].getsum(0,n+1)+DP[1].getsum(0,n+1);
	sum %= mod;
	cout << sum << endl;
}

Measured memory_bytes: 10752
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
d=lnii()
m=int(input())
t=lnii()

c=Counter(d)
for i in t:
  if c[i]==0:
    print('NO')
    exit()
  else:
    c[i]-=1

print('YES')

Measured memory_bytes: 44732
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    X,Y,A,B,C = map(int, readline().split())
    p = [int(i) for i in readline().split()]
    q = [int(i) for i in readline().split()]
    r = [int(i) for i in readline().split()]

    p.sort()
    q.sort()
    r.sort()
    
    Q = p[A-X:] + q[B-Y:] + r
    Q.sort(reverse=True)
    ans = sum(Q[:X+Y])

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23200
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        HashMap<Integer, HashMap<Integer, Integer>> map = new HashMap<>();
        int N = scan.nextInt();
        for(int i = 0; i < N; i++) {
            int A = scan.nextInt();
            HashMap<Integer, Integer> subMap = new HashMap<>();
            for(int j = 0; j < A; j++) {
                int x = scan.nextInt() - 1;
                int y = scan.nextInt();
                subMap.put(x,y);
            }
            map.put(i, subMap);
        }

        int ans = 0;
        long allPattern = (long)Math.pow(2.0, N);
        for(long i = 0; i < allPattern; i++) {
            boolean isAllTrue = true;
            int numOf1 = 0;
            for(int j = 0; j < N; j++) {
                long tmp = i;
                tmp >>= j;
                if((tmp & 1) == 1) {
                    numOf1++;
                    HashMap<Integer, Integer> subMap = map.get(j);
                    boolean isTrue = true;
                    for(Entry<Integer, Integer> entry :subMap.entrySet()) {
                        tmp = i;
                        tmp >>= entry.getKey();
                        if((tmp & 1) != entry.getValue()) {
                            isTrue = false;
                            break;
                        }
                    }
                    if(!isTrue) {
                        isAllTrue = false;
                        break;
                    }
                }
            }
            if(isAllTrue) {
                if(ans < numOf1)
                    ans = numOf1;
            }
        }

        os.println(ans);
    }

}

Measured memory_bytes: 28500
#include <iostream>
#include <cstdio>

using namespace std;

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

	int a[100][100];

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

	int b[100];

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

	int c[100] = {};

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

	for (int i = 0; i < n; i++) {
		printf("%d\n", c[i]);
	}

	return 0;
}

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

int main(){
  long long N = 0;
  cin >> N;
  vector<long long> L(100,0);
  L.at(0) = 2;
  L.at(1) = 1;
  for (long long i = 2; i <= N; i++){
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }
  cout << L.at(N);
}
  

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll s = c*d/gcd(c,d);
  ll s1 = b/c-(a-1)/c;
  ll s2 = b/d-(a-1)/d;
  ll s3 = b/s-(a-1)/s;
  
  
  cout<<(b-a+1)-(s1+s2-s3)<<endl;
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const N=2333,INF=0x3f3f3f3f,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int n,m,dis[N][N];
char c[N][N];
struct node{
	int x,y,stp;
	inline bool operator==(const node&r)const{
		return x==r.x&&y==r.y;
	}
}st,ed;
queue<node>q;
void dfs(int x,int y,int k){
	dis[x][y]=k;q.push((node){x,y,k});
	for(int i=0;i<4;i++){
		int tx=x+dx[i],ty=y+dy[i];
		if(tx<1||ty<1||tx>n||ty>m||dis[tx][ty]==k||c[tx][ty]=='#')continue;
	    dfs(tx,ty,k);
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>st.x>>st.y>>ed.x>>ed.y;
	for(int i=1;i<=n;i++)
	    for(int j=1;j<=m;j++)cin>>c[i][j];
	memset(dis,INF,sizeof dis);
	dfs(st.x,st.y,0);
	while(q.size()){
		node f=q.front();q.pop();
		if(f==ed){cout<<f.stp;return 0;}
		for(int i=f.x-2;i<=f.x+2;i++)
		    for(int j=f.y-2;j<=f.y+2;j++){
		    	node t=(node){i,j,f.stp+1};
		    	if(t.x<1||t.y<1||t.x>n||t.y>m||dis[t.x][t.y]!=INF||c[t.x][t.y]=='#')continue;
		    	dfs(t.x,t.y,t.stp);
		    }
	}
	cout<<-1;
}

Measured memory_bytes: 27236
N=int(input())
AC=int(0)
WA=int(0)
TLE=int(0)
RE=int(0)
for i in range(N):
    inp=input()
    if inp=="AC":
        AC+=1
    if inp=="WA":
        WA+=1
    if inp=="TLE":
        TLE+=1
    if inp=="RE":
        RE+=1

print("AC x",AC)
print("WA x",WA)
print("TLE x",TLE)
print("RE x",RE)

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	queue<int> q;
	cin >> n;
	int a[100010] = {0};
	rep(i, n) cin >> a[i+1];
	q.push(1);
	f = 0;
	j = 0;
	while(j < n+1){
		j++;
		x = q.front();q.pop();
		
		if(a[x] == 2){
			f = 1;
			break;
		}
		q.push(a[x]);
	}
	if(f != 1) cout << -1 << endl;
	else cout << j << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
struct da
{
	int p,y,no;
}d[1111111];
bool operator <(const da &x,const da &y)
{
	return x.y<y.y;
} 
int cnt[111111];
int x[111111],y[111111];
int main()
{
	int m=io::F(),n=io::F();
	for(register int i=1;i<=n;++i)
		d[i]=(da){io::F(),io::F(),i};
	std::sort(d+1,d+n+1);
	for(register int i=1;i<=n;++i)
	{
		int no=d[i].no;
		x[no]=d[i].p,y[no]=++cnt[d[i].p];
	}
	for(register int i=1;i<=n;++i)
		printf("%06d%06d\n",x[i],y[i]);
	return 0;
}


Measured memory_bytes: 5504
<?php
  fscanf(STDIN, "%i", $n);
  $mod = pow(10, 9) + 7;

  $primes = [];
  for ($i = 2; $i <= $n; $i++)
  {
    $x = $i;
    foreach ($primes as $p => $exp)
    {
      while ($x % $p === 0)
      {
        $primes[$p]++;
        $x = $x / $p;
      }
    }
    if ($x === $i)
    {
      $primes[$i] = 2;
    }
  }

  $answer = 1;
  foreach ($primes as $exp)
  {
    $answer = ($answer * $exp) % $mod;
  }
  echo $answer.PHP_EOL;
?>


Measured memory_bytes: 3064
def solve(string):
    n, m, *xyz = map(int, string.split())
    t = [-1] * (n + 1)
    for x, y, z in zip(*[iter(xyz)] * 3):

        def union(r1, r2):
            if r1 != r2:
                t[max(r1, r2)] = min(r1, r2)

        def find(x):
            if t[x] < 0:
                return x
            t[x] = find(t[x])
            return t[x]

        union(find(x), find(y))
    return str(t[1:].count(-1))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 34884
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if(n % 2 != 0 || n < 10){
            System.out.println(0);
            return;
        }
        long ans = 0;
        int digit = (int)(Math.log10(n))+1;
        int i=0;
        while(10*Math.pow(5,i) <= n){
            long def = 10*(long)Math.pow(5,i);
            ans += n/def;
            i++;
        }
        System.out.println(ans);
    }
}



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

int main() {
  ll n, d;
  cin >> n >> d;
  ll ans = 0;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (x*x + y*y <= d*d)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000000
#define maxn 110
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n,m;
int main(){
	int a,b,c,d;
	in4(a,b,c,d);
	a+=b,c+=d;
	if(a>c)cout<<"Left";
	if(a==c)cout<<"Balanced";
	if(a<c)cout<<"Right";
}

Measured memory_bytes: 764
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int dist[101][101];
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
			if(i!=j)dist[i][j]=1e9;
	int n,k;
	cin>>n>>k;

	int prs=n*(n-1);prs/=2;
	prs-=k;
	vector<pair<int,int>> toconnect;
	for(int i=1;i<=n and prs>0;i++)
		for(int j=i+1;j<=n and prs>0;j++)
		{
			toconnect.push_back({i,j});
			prs--;
		}

	for(auto i:toconnect)
	{
		dist[i.first][i.second]=dist[i.second][i.first]=1;
	}


	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	int two=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(dist[i][j]==2)two++;

	if(two!=k)
	{
		puts("-1");
		return 0;
	}

	cout<<toconnect.size()<<"\n";
	for(auto i:toconnect)
		cout<<i.first<<" "<<i.second<<"\n";



	
	
}

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

const int MAX_V = 101;
const int INF = 1e+7;

int d[MAX_V][MAX_V];

void init(){
	for(int i=0 ; i < MAX_V ; i++ ){
		for(int j=0 ; j < MAX_V ; j++ ){
			d[i][j] = (i == j)? 0 : INF ;
		}
	}
}

int main(){
	int n, m, s, g1, g2;
	while( cin >> n >> m >> s >> g1 >> g2 , n ){
		init();
		s--; g1--; g2--;
		
		for(int i=0 ; i < m ; i++ ){
			int u, v, cost;
			cin >> u >> v >> cost;
			u--; v--;
			d[u][v] = cost;
		}
		
		for(int k=0 ; k < n ; k++ ){
			for(int i=0 ; i < n ; i++ ){
				for(int j=0 ; j < n ; j++ ){
					d[i][j] = min( d[i][j] , d[i][k] + d[k][j] );
				}
			}
		}
		int ans = INF;
		for(int i=0 ; i < n ; i++ ){
			ans = min( ans , d[s][i] + d[i][g1] + d[i][g2] );
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 908
#include <stdio.h>
#include <string.h>

#define MAX_N 25

int getRoot(int,int*);
void preorder(int,int*,int*);
void inorder(int,int*,int*);
void postorder(int,int*,int*);

int main(){
  int n,i,id,root;
    int parent[MAX_N],l[MAX_N],r[MAX_N];;

  memset(parent,-1,sizeof(parent));

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&id);
    scanf("%d%d",&l[id],&r[id]);
    if(l[id] >= 0){ parent[l[id]] = id; }
    if(r[id] >= 0){ parent[r[id]] = id; }
  }
  root = getRoot(n,parent);
  printf("Preorder\n"); preorder(root,l,r); printf("\n");
  printf("Inorder\n"); inorder(root,l,r); printf("\n");
  printf("Postorder\n"); postorder(root,l,r); printf("\n");
  return 0;
}

int getRoot(int n,int *parent){
  int i;
  for(i = 0 ; i < n ; i++){
    if(parent[i] == -1){
      return i;
    }
  }
  return -1;
}

void preorder(int x,int *l,int *r){
  if(x >= 0){
    printf(" %d",x);
    preorder(l[x],l,r);
    preorder(r[x],l,r);
  }
}

void inorder(int x,int *l,int *r){
  if(x >= 0){
    inorder(l[x],l,r);
    printf(" %d",x);
    inorder(r[x],l,r);
  }
}

void postorder(int x,int *l,int *r){
  if(x >= 0){
    postorder(l[x],l,r);
    postorder(r[x],l,r);
    printf(" %d",x);
  }
}

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

using namespace std;
int main() {
    int N;
    cin >> N;
    int a[N];
    REP(i, N) cin >> a[i];
    sort(a, a+N);
    int min = *min_element(a, a+N);
    int max = *max_element(a, a+N);
    cout << max - min << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vl x(n);
    rep(i,n) {
        cin >> x[i];
    }

    vl y(m);
    rep(i, m) {
        cin >> y[i];
    }

    ll Ax = 0;
    rep(j, n) {
        Ax = (Ax + MAX_N*mod - x[j]*j)%mod;
    }

    ll Bx = 0;
    rep(i, n) {
        Bx = (Bx + MAX_N*mod - x[i]*(n-1-i))%mod;
    }

    ll Cx = (Ax + 2*mod - Bx)%mod;

    ll Ay = 0;
    rep(j, m) {
        Ay = (Ay + MAX_N*mod - y[j]*j)%mod;
    }
    
    ll By = 0;
    rep(i, m) {
        By = (By + MAX_N*mod - y[i]*(m-1-i))%mod;
    }

    ll Cy = (Ay + 2*mod - By)%mod;

    ll ans = (Cx*Cy)%mod;

    out(ans);
    re0;
}

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

string expr(string const& s, int& p, int n);
string term(string const& s, int& p, int n);

int number(string const& s, int& p) {
    int res = 0;
    while(isdigit(s[p])) {
        res *= 10;
        res += s[p++] - '0';
    }
    return res;
}

string str(string const& s, int& p) {
    string res;
    while(isalpha(s[p])) {
        res += s[p++];
    }
    return res;
}

string expr(string const& s, int& p, int n) {
    string res;
    while(p < s.size() && res.size() <= n && s[p] != ')') {
        auto t = term(s, p, n);
        res += t;
    }
    return res;
}

string term(string const& s, int& p, int n) {
    string res;
    if(isdigit(s[p])) {
        int k = number(s, p);
        string t;
        if(s[p] == '(') {
            t = expr(s, ++p, n);
            ++p;
        } else {
            t = str(s, p);
        }
        for(int i=0; i<k && res.size() <= n; ++i) {
            res += t;
        }
    } else if(isalpha(s[p])) {
        res = str(s, p);
    } else {
        assert(false);
    }
    return res;
}


int main() {
    string s;
    while(cin >> s, s != "0") {
        int n;
        cin >> n;
        int p = 0;
        auto res = expr(s, p, n);
        if(res.size() <= n) {
            cout << 0 << endl;
        } else {
            cout << res[n] << endl;
        }
    }
}


Measured memory_bytes: 7852
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    int y = 0, x = 0;
    string s[h];
    for(int i=0;i<h;i++) cin >> s[i];
    map<pair<int,int>, int > mp;
    mp[{h-1, w-1}] = 1;
    while(!(y == h-1 && x == w-1)){
    	mp[{y, x}] = 1;
    	if(y == h-1){
    		if(s[y][x+1] == '#') x++;
    		else{
    			cout << "Impossible" << endl;
    			return 0;
    		}
    	}else if(x == w-1){
    		if(s[y+1][x] == '#') y++;
    		else{
    			cout << "Impossible" << endl;
    			return 0;
    		}
    	}else{
    		if(s[y][x+1] == '#'){
    			if(s[y+1][x] == '#'){
    			    cout << "Impossible" << endl;
    			    return 0;
    			}else{
    				x++;
    			}
    		}else{
    			if(s[y+1][x] == '#') y++;
    			else{
    				cout << "Impossible" << endl;
    			    return 0;
    			}
    		}
    	}
    }
    bool ok = true;
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		if(s[i][j] == '#' && mp[{i, j}] != 1) ok = false; 
    	}
    }
    if(ok) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	int n,t,c[514],s[514],f[514],a[514];
	cin>>n;
	for(int i=1;i<n;i++)cin>>c[i]>>s[i]>>f[i];
	for(int i=1;i<n;i++)
	{
		t=0;
		for(int j=i;j<n;j++)
		{
			t=max(t%f[j]?f[j]*(t/f[j]+1):t,s[j]);
			//cout<<t<<"+"<<c[j]<<"->";
			t+=c[j];
		}
		cout<<t<<endl;
	}
	cout<<0<<endl;
}	

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 15 == 0) continue;
    else if (i % 5 == 0) continue;
    else if (i % 3 == 0) continue;
    else ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner

fun main(args: Array<String>){
  val scn = Scanner(System.`in`) //Scannerのインスタンスを作成
  
  val n: Long = scn.nextLong()
  val a: Long = scn.nextLong()
  val b: Long = scn.nextLong()
  val g: Long = a + b
  var result: Long = 0
  val yo = n % g
  val k = (n - yo) / g
  result += k * a
  if (yo <= a) {
    result += yo
  } else {
    result += a
  }
  println(result)
}

Measured memory_bytes: 31260
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;

int cnt_digits(ll N){
	int digits=0;

	while(N>0){
	N/=10;
	digits++;
	}

	return digits;
}
int main(){
	long long n;
	cin >> n;

	int ans=cnt_digits(n);

	for(ll i=1LL; i*i<=n; ++i){
		if(n%i!=0)continue;
		const ll k=n/i;

		const int cur = max(cnt_digits(i),cnt_digits(k));

		if(ans>cur){
			ans=cur;
		}
	}

	cout << ans << endl;
/*		if(n%i==0){
			int k=n/i;
			cur=cnt_digits(k);
		}
		if(ans>cur){
			ans=cur;
		}
	}


	cout << ans << endl;
	*/
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define fo(i,s,e) for (int i=(s); i < (e); i++)
#define all(obj) (obj).begin(), (obj).end()
#define int long long
signed main () {
  int n;cin >> n;
  vector<int> a(n,0);
  rep(i,n){cin >> a[i];}
  vector<int> v=a;
  sort(a.rbegin(), a.rend());
  rep(i,n){v[i]==a[0] ? cout << a[1] << endl : cout << a[0] << endl;}
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */
//1-indexed
class BIT {
public:
  vector<ll> bit;
  ll M;

  BIT(ll M):
    bit(vector<ll>(M+1, 0)), M(M) {}

  //a[1] + a[2] + ... + a[i]を求める
  ll sum(ll i) {
    if (i==0) return 0;
    return bit[i] + sum(i-(i&-i));
  }
  //a[i] += x
  void add(ll i, ll x) {
    if (i > M) return;
    bit[i] += x;
    add(i+(i&-i), x);
  }
};

int main() {
  ll N, K; cin >> N >> K;
  vector<ll> sum(N+1, 0);
  REP(i, N) {
    ll a;
    cin >> a;
    a -= K;
    sum[i+1] = sum[i] + a;
  }

  vector<ll> vals;
  REP(i, N+1) vals.push_back(sum[i]);
  sort(ALL(vals));
  vals.erase(unique(ALL(vals)), vals.end());

  REP(i, N+1){
    ll idx = lower_bound(ALL(vals), sum[i]) - vals.begin();
    sum[i] = idx+1;
  }

  BIT b(N+1);
  ll ans = 0;
  REP(i, N+1){
    ans += b.sum(sum[i]);
    b.add(sum[i], 1);
  }
  cout << ans << endl;
}


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

int main(){
    int n, k; cin >> n >> k;
    vector<ll> lis(n);
    for(int i = 0; i < n; i++){
        cin >> lis[i];
    }
    sort(lis.begin(), lis.end(), greater<>());
    ll ans = 0;
    if(n <= k){cout << 0 << endl; return 0;}
    for(int i = k; i < n; i++){
        ans += lis[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff first
#define ss second 
#define S size()
#define mod  998244353
#define mset(a,k) memset(a,k,sizeof(a));
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dr(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll> 
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define vii vector<pii>
using namespace std;
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}  
//----------------------------------------FUNCTIONS------------------------------------- 
vi primes;
void sieve(ll n){
    vector<bool> prime(n+1,true);
    for(ll p = 2; p * p <= n; p++){
        if(prime[p] == true){
            for (ll i = p*2; i <= n; i += p)
                prime[i] = false;
        }
    }
    for (int p = 2; p <= n; p++)
       if(prime[p])
          primes.pb(p);
}

ll modexpo(ll a,ll b)
{
    if(b==0)
    return 1;
    if(b==1)
    return a;
    ll temp=modexpo(a,b/2);
    if(b%2)
    return (temp%mod*temp%mod*a)%mod;
    return (temp%mod*temp%mod)%mod;
}

ll gcd(ll x,ll y )
{
    if(y==0) return x;
    return gcd(y,x%y);
}

ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vin(ll n){vi a(n);fr(i, 0, n) cin>>a[i];return a;}

void out(vi a){
    for(int i=0;i<(ll)a.S;i++){
        cout<<a[i]<<' ';
    }
    cout<<'\n';
}
void        in(ll *a, ll n)        {for(ll i=0;i<n;i++)cin>>a[i];}
void out(ll *a,ll n){fr(i,0,n){cout<<a[i]<<" ";}}
void out1(vi v){fr(i,0,(ll)v.S){cout<<v[i]<<" ";}cout<<'\n';}
//----------------------------------------START------------------------------------------- 	
int solve(); 
vector<int> v[1001];
int main()
{
	fast();
	//clock_t start=clock();
	ll t=1;
	//cin>>t;
	while(t--)
	{
		fr(i,0,1001)v[i].clear();
		solve();
	}
	/*cout<<"--------------------------------------------\n";
      cout<<(clock() - start )/(double) CLOCKS_PER_SEC<<'\n';*/
} 
int solve()
{
	ll s,w;
	cin>>s>>w;
	if(w>=s)cout<<"unsafe";
	else cout<<"safe";
  return 0;
}  


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

// I: 1 V: 5 X: 10 L: 50 C: 100 D: 500 M: 1000

#define PI 4*atan(1);

int n[100] = {0};

void Convert(char s[]){
  for(int i = 0; s[i] != '\0'; i++){
    if(s[i] == 'I')n[i] = 1;
    if(s[i] == 'V')n[i] = 5;
    if(s[i] == 'X')n[i] = 10;
    if(s[i] == 'L')n[i] = 50;
    if(s[i] == 'C')n[i] = 100;
    if(s[i] == 'D')n[i] = 500;
    if(s[i] == 'M')n[i] = 1000;
  }
}

void clear(void) {
  for(int i = 0; n[i] != 0; i++)n[i] = 0;
}

int main(){
  char s[101];
  while(cin >> s){
    clear();
    int sum = 0;
    Convert(s);
    for(int i = 0; n[i] != 0; i++){
      if(n[i] < n[i + 1]){
        sum -= n[i];
      }
      if(n[i] >= n[i + 1]){
        sum += n[i];
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class Main {
    void solve() {
        int n = in.nextInt();
        int a = in.nextInt(), b = in.nextInt();

        if (Integer.bitCount(a) % 2 == Integer.bitCount(b) % 2) {
            out.println("NO");
            return;
        }

        out.println("YES");
        int[] res = build(n, a, b);
        for (int i = 0; i < 1 << n; i++) {
            if (i > 0) out.print(' ');
            out.print(res[i]);
        }
    }

    int[] build(int n, int a, int b) {
        if (n == 1) {
            return new int[]{a, b};
        }

        int x = Integer.numberOfTrailingZeros(a ^ b);

        int aa = (a >> x + 1) << x | (a & (1 << x) - 1);
        int bb = (b >> x + 1) << x | (b & (1 << x) - 1);
        int cc = aa ^ 1;
        int[] p = build(n - 1, aa, cc), q = build(n - 1, cc, bb);
        
        int[] res = new int[1 << n];
        for (int i = 0; i < 1 << n - 1; i++) {
            int u = p[i] & ~((1 << x) - 1);
            int v = p[i] & (1 << x) - 1;
            res[i] = u << 1 | (a & 1 << x) | v;
        }
        for (int i = 0; i < 1 << n - 1; i++) {
            int u = q[i] & ~((1 << x) - 1);
            int v = q[i] & (1 << x) - 1;
            res[(1 << n - 1) + i] = u << 1 | (b & 1 << x) | v;
        }
        return res;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Main().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 40824
N=int(input())
C = []
S = []
F = []
for i in range(N-1):
    c,s,f = list(map(int,input().split()))
    C.append(c)
    S.append(s)
    F.append(f)
    
for i in range(N):
    time = 0
    for j in range(i,N-1):
        if time < S[j]:
            time = S[j]+C[j]
        else:
            itime=int(time/F[j])
            if itime*F[j]!=time:
                time=(itime+1)*F[j]+C[j]
            else:
                time+=C[j]
    print(time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
    vll a(n);
    ll g = 0;
    forn(i,n)
    {
        cin>>a[i];
        g = gcd(g,a[i]);
    }
    if(g>1)
    {
        cout<<"not coprime";
        return 0;
    }
    set <ll> s;
    bool ok = 1;
    forn(i,n)
    {
        ll g = a[i];
        for(ll i=2;i<=sqrt(g);i++)
        {
            if(g%i==0)
            {
                if( s.count(i) ){ ok = 0; break; }
                while(g%i==0) g /= i;
                s.insert(i);
            }
        }
        if(g>1)
        {
            if( s.count(g) ) ok = 0;
            s.insert(g);
        }
        if(!ok) break;
    }
    if(ok) cout<<"pairwise coprime";
    else cout<<"setwise coprime";

	return 0;
}


Measured memory_bytes: 11172
#include <stdio.h>
#include <algorithm>
using namespace std;

constexpr int kN = int(2E5 + 10);

int p[kN], sz[kN];
int Find(int n) {return n == p[n] ? n : p[n] = Find(p[n]);}

int main() {
	int n, m, a, b, ans = 0;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) p[i] = i;
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &a, &b);
		p[Find(b)] = Find(a);
	}
	for (int i = 1; i <= n; i++) sz[Find(i)]++;
	for (int i = 1; i <= n; i++) ans = max(ans, sz[i]);
	printf("%d\n", ans);
}


Measured memory_bytes: 3292
word = list(input())

count = 0  # 入れ替える個数を用意

if len(word) % 2 == 0:  # もしアルファベットの数が偶数の時
  for i in range(0,int(len(word)/2)):
    if word[i] != word[int(len(word))-1-i]:
      count += 1    
  print(count)

else:
  for j in range(0,int((len(word)+1)/2-1)):
    if word[j] != word[int(len(word))-1-j]:
      count += 1
  print(count)


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

int main(){vector<int> n(3);int a,b;
           cin>>n[0]>>n[1]>>n[2];
           sort(n.begin(),n.end());
           a=n[1]-n[0];
           if(a<0)a=-a;
           b=n[2]-n[1];
           if(b<0)b=-b;
           cout<<a+b<<endl;}

Measured memory_bytes: 256
import sys
while True:
    n = int(input())
    if n != 0:
        jewels = [[int(i) for i in input().split()] for j in range(n)]

        n = int(input())
        moves = [[i for i in input().split()] for k in range(n)]

        for i, j in enumerate(moves):
            moves[i][1] = int(moves[i][1])

        coodinates = [[10, 10]]
        current_cell = [10, 10]

        for i, k in enumerate(moves):
            direction = moves[i][0]
            vector = moves[i][1]
            if direction == 'N':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0], current_cell[1] + j])
                current_cell[1] = current_cell[1] + vector
            elif direction == 'S':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0], current_cell[1] - j])
                current_cell[1] = current_cell[1] - vector
            elif direction == 'W':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0] - j, current_cell[1]])
                current_cell[0] = current_cell[0] - vector
            elif direction == 'E':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0] + j, current_cell[1]])
                current_cell[0] = current_cell[0] + vector

        flag = True
        for i in jewels:
            if i not in coodinates:
                flag = False
                break

        if flag:
            print('Yes')
        else:
            print('No')
    else:
        sys.exit()


Measured memory_bytes: 5636
package main

import (
  "fmt"
  "strings"
)

var S, T string
var ans int
var res string

func Split(S string, T string) string {
    s := strings.Split(S, "")    
  	slen := len(s)
	t := strings.Split(T, "")
  	// tlen := len(t)
    for i := 0; i < slen; i++ {
      if s[i] != t[i] {
      	return "No"
      }
    }
  return "Yes"
}

func main() {
  fmt.Scan(&S, &T)
  if len(S)+1 == len(T) {
    res = Split(S, T)
  } else {
  	res = "No"
  }
  fmt.Println(res)
}



Measured memory_bytes: 1824
#include <stdio.h>
#include <string.h>

int main(void)
{
    char bu[10][6] = {
        "",
        ".,!? ",
        "abc",
        "def",
        "ghi",
        "jkl",
        "mno",
        "pqrs",
        "tuv",
        "wxyz"
    };

    int n;
    scanf("%d", &n);
    int i;
    for(i = 0; i < n; i++){
        char line[1025];
        scanf("%s", line);
        int num, p = 0;
        while(line[p] != '\0'){
            num = 0;
            while(line[p] != '0'){
                num++;
                p++;
            }
            if(p > 0 && line[p - 1] != '0'){
                int but_no = line[p - 1] - '0';
                int but_index = num % strlen(bu[but_no]);
                if(but_index > 0)
                    but_index--;
                else
                    but_index += (strlen(bu[but_no]) - 1);
                printf("%c", bu[but_no][but_index]);
            }
            p++;
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 576
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 1;
		for(int i=1;i<=N;i++){
			ans=Math.min(ans*2,ans+K);
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 21972
import math


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    pos = A.index(1)
    l = math.ceil(pos / (K - 1))
    r = math.ceil((N - 1 - l * (K - 1)) / (K - 1))
    print(int(l + r))


if __name__ == "__main__":
    main()


Measured memory_bytes: 13812
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>

using namespace std;

#define pb push_back
#define ll long long
#define PI 3.14159265
const ll INF = 1e18L + 5;
void min_self(ll &a, ll &b){
	a = min(a,b);
}
void solve(){
	ll n,w;
	scanf("%lld%lld", &n, &w);
	vector<ll> weight(n+1), value(n+1);
	for(int i=0; i<n; ++i){
		scanf("%lld%lld", &weight[i], &value[i]);
	}
	int sum_value = 0;
	for(auto x:value){
		sum_value += x;

	}
	
	// dp[i] - the minimum total weight with total value exactly i

	vector<ll> dp(sum_value+1, INF);
	dp[0] = 0;
	for(int item = 0; item < n; ++item){
		for(int value_already = sum_value - value[item]; value_already>=0; --value_already){
			dp[value_already+value[item]] = min(dp[value_already+value[item]], dp[value_already] + weight[item]);
		}
	}
	
	ll answer = 0;
	for(int i=0; i<= sum_value; ++i){
		if(dp[i] <= w){
			answer = max(answer, (ll) i);
		}
	}	
	printf("%lld\n", answer);
	
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}
















Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  int mn=1e16;
  mn=min(a,min(b,min(c,min(d,min(e,mn)))));
  cout<<5+(n-1)/mn<<endl;
  
  

  return 0;
}


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

long long MOD=1000000007LL;

long long fac[2000001],finv[2000001],inv[2000001];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<2000001;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 
long long MODpow(long long a,int b){
	if(b==0)return 1;
	if(b%2==0){
		long long t=MODpow(a,b/2);
		return (t*t)%MOD;
	}
	return (a*MODpow(a,b-1))%MOD;
}

int main(){
	COMinit();
	long long N,M;
	cin >> N >> M;
	long long ans=0;
	for(auto K=0;K<=N;K++){
		long long add=fac[M-K]*finv[M-N];
		add%=MOD;
		add*=COM(N,K);
		add%=MOD;
		if(K%2)ans-=add;
		else ans+=add;
		if(ans<0)ans+=MOD*MOD;
		ans%=MOD;
	}
	
	
	cout << (ans*((fac[M]*finv[M-N])%MOD))%MOD << endl;
	return 0;
}

Measured memory_bytes: 50380
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

if(sum(a)<sum(b)):
    print(-1)
else:
    d=[a[i]-b[i] for i in range(n)]
    d.sort()

    ans=0
    minus_num=bisect.bisect_left(d, 0)
    ans+=minus_num
    minus_sum=sum(d[:minus_num])

    i=n-1
    while(minus_sum<0 and minus_num<=i):
        minus_sum+=d[i]
        i-=1
        ans+=1

    print(ans)

Measured memory_bytes: 24156
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char i){
  if(i=='a'){
    return 1;
  }
  if(i=='b'){
    return 2;
  }
  if(i=='c'){
    return 3;
  }
  if(i=='d'){
    return 4;
  }
  if(i=='e'){
    return 5;
  }
  if(i=='f'){
    return 6;
  }
  if(i=='g'){
    return 7;
  }
  if(i=='h'){
    return 8;
  }
  if(i=='i'){
    return 9;
  }
  if(i=='j'){
    return 10;
  }
  if(i=='k'){
    return 11;
  }
  if(i=='l'){
    return 12;
  }
  if(i=='m'){
    return 13;
  }
  if(i=='n'){
    return 14;
  }
  if(i=='o'){
    return 15;
  }
  if(i=='p'){
    return 16;
  }
  if(i=='q'){
    return 17;
  }
  if(i=='r'){
    return 18;
  }
  if(i=='s'){
    return 19;
  }
  if(i=='t'){
    return 20;
  }
  if(i=='u'){
    return 21;
  }
  if(i=='v'){
    return 22;
  }
  if(i=='w'){
    return 23;
  }
  if(i=='x'){
    return 24;
  }
  if(i=='y'){
    return 25;
  }
  if(i=='z'){
    return 26;
  }
  return 100;
  
}




int main() {
  int N,K;
  cin>>N>>K;
  int A[N];
  int B[200010];
  for(int i=0;i<200010;i++){
    B[i]=0;
  }
  for(int i=0;i<N;i++){
    A[i]=input();
    B[A[i]]++;
  }
  int sum=0;
  for(int i=1;i<200010;i++){
    if(B[i]>0){
      sum++;
    }
  }
  sum-=K;
  int x=0;
  if(sum>0){
    for(int i=1;i<200010;i++){
      for(int j=1;j<200010;j++){
        if(B[j]==i){
          x+=i;
          B[j]=0;
          sum--;
          if(sum==0){
        break;
      }
          
        }
        
      }
      if(sum==0){
        break;
      }
    }}
    


  cout<<x<<endl;

  


  


  

  




  
  
}

  

  



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

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 9;

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

    fast;

    string s;

    cin >> s;

    int sum = 0;

    for(int i = 0; i < s.size(); i++) sum += (s[i] - '0'), sum %= 9;

    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,av;
    ll b,bv;
    ll t;
    cin>>a>>av;
    cin>>b>>bv>>t;
    if(av*t-bv*t>=abs(b-a))
         cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


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

int main(){
	int n;
	while(cin >> n,n){
		int a[1000],b[1000],c[1000],d[1000],p,q,r,C;
		for(int i = 0;i < n;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
		bool flag = false;
		cin >> p >> q >> r >> C;
		for(int i = 0;i < n;i++){
			int t = b[i] * 4 + c[i] * 9 + d[i] * 4;
			if(t > C || b[i] > p || c[i] > q || d[i] > r) continue;
			flag = true;
			cout << a[i] << endl;
		}
		if(!flag) cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
  string data;
  int count, p;

  while(1){
    getline(cin,data);
    if(data=="END OF INPUT") break;

    count=0;
    p=0;
    for(int i=0;i<data.size();i++){
      if(data[i]==' '){
	p++;
	if(p==2){
	  //cout << 0;
	}
	cout << count;
	count=0;
	continue;
      }
      count++;
    }
    cout << count;
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
def idxoftwo(n)
  i = 0
    while n%2==0
      n = n/2
      i +=1
    end
    return i
end

n = gets.to_i
array = gets.split(" ").map{|a| a.to_i}
ary = []
answer =0
for i in(0..n-1)
  answer += idxoftwo(array[i])
end

puts answer


Measured memory_bytes: 2300
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define Pi pair<int, int>
#define Vi vector<int>

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, x, n) for(int i = x; i < n; i++)
#define repd(n) for(int i = n - 1; i >= 0; i--)

int a, b;

int main() {
	cin >> a >> b;
	if ((a + b) % 2)cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;

	return 0;
}



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

int main() {
    int N; cin >> N;
    int L[N];
    for (int i = 0; i < N; i++) cin >> L[i];
    sort(L, L + N);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            for (int k = 0; k < j; k++) {
                if (L[i] < L[j] + L[k] && (L[i] != L[j] && L[j] != L[k] && L[k] != L[i])) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main(void){
   int H,W;
   cin>>H>>W;
   vector<vector<char>> C(H,vector<char>(W));
   for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
         cin>>C[i][j];
      }
   }
   vector<vector<char>> result(2*H,vector<char>(W));
   for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
         result[i*2][j]=C[i][j];
         result[2*i+1][j]=C[i][j];
      }
   }
   for(int i=0;i<2*H;i++){
      for(int j=0;j<W;j++){
         cout<<result[i][j];
      }
      cout<<endl;
   }
   return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,o,u) for(int i = o;i < u; i++)
using namespace std;
int a[100000];
int partition(int p,int r){
	int k = p-1;
	rep(i,p,r){
		if(a[i] <= a[r]){
			k++;
			swap(a[i],a[k]);
		}
	}
	swap(a[k+1],a[r]);
	return k + 1;
}
int main(){
	int n;
	cin >> n;
	rep(i,0,n) cin >> a[i];
	int q = partition(0,n-1);
	rep(i,0,n){
		if(i == q) cout << "[";
		cout << a[i];
		if(i == q) cout << "]";
		if(i != n-1) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3492
n = gets.to_i
ret = -1000000000
j = gets.to_i
min = j
max = j
for i in 2..n
  j = gets.to_i
  if min >= j
    ret = j - min if ret < j - min
    min = j
    max = j
  end
  if max < j
    max = j
    ret = max - min if ret < max - min
  end
end
puts ret

Measured memory_bytes: 6100