akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+5;
const int mod=1e9+7;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,a,b,c;
inline int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ans;
}
int rec[maxn],inv[maxn];
int C(int n,int m){
	return 1ll*rec[n]*inv[m]%mod*inv[n-m]%mod;
}
int alfa[maxn],beta[maxn];
signed main(){
	n=read();
	a=read(),b=read(),c=read();
	rec[0]=inv[0]=1;
	for(int i=1;i<=n+n;i++){
		rec[i]=1ll*rec[i-1]*i%mod;
	}
	inv[n+n]=ksm(rec[n+n],mod-2);
	for(int i=n+n-1;i>=1;i--){
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
	}
	int tmpa=1ll*a*ksm(a+b,mod-2)%mod,tmpb=1ll*b*ksm(a+b,mod-2)%mod;
	for(int i=0;i<n;i++){
		alfa[i]=1ll*C(n+i-1,i)*ksm(tmpa,n)%mod*ksm(tmpb,i)%mod;
		beta[i]=1ll*C(n+i-1,i)*ksm(tmpb,n)%mod*ksm(tmpa,i)%mod;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans=(ans+1ll*alfa[i]*(n+i)%mod)%mod;
		ans=(ans+1ll*beta[i]*(n+i)%mod)%mod;
	}
	ans=1ll*ans*100%mod*ksm(a+b,mod-2)%mod;
	printf("%lld\n",ans);
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    int i = min(a, k);
    ans += i * 1;
    k -= i;
    i = min(b, k);
    k -= i;
    i = min(c, k);
    ans += i * -1;
    k -= i;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;
 
int main()
{
 ll n,ans;
 cin >> n;
 ans=(n*(n-1))/2;
 cout << ans;
 return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = (1ll << 31) - 1;
const int mod = 998244353;
typedef pair<int, int> P;
typedef pair<int, P> PP;

struct segtree {
	vector<int>node;
	int n;
	void init(int N) {
		n = 1;
		while (n < N)n *= 2;
		node.resize(2 * n, inf);
	}
	void update(int x,int a) {
		x += n - 1;
		node[x] = a;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = min(node[x * 2 + 1], node[x * 2 + 2]);
		}
	}
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return inf;
		if (a <= l&&r <= b)return node[k];
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	int get(int a, int b) {
		return query(a, b, 0, 0, n);
	}

};
segtree seg;
signed main() {
	int n, q; cin >> n >> q;
	seg.init(n);
	rep(i, q) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a) {
			cout << seg.get(b, c + 1) << endl;
		}
		else {
			seg.update(b, c);
		}
	}
}


Measured memory_bytes: 4868
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,ans=0;
	cin>>n;
	lol(i,n){
		int a,b;cin>>a>>b;
		ans+=b-a+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
input1 = str(input())

if input1 == "SSS":
    print("0")
    
if input1 == "SSR":
    print("1")
    
if input1 == "SRS":
    print("1")
    
if input1 == "RSS":
    print("1")
    
if input1 == "RRS":
    print("2")
    
if input1 == "RSR":
    print("1")
    
if input1 == "SRR":
    print("2")
    
if input1 == "RRR":
    print("3")
    


Measured memory_bytes: 9044
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    W, H, x, y = list(map(int, input().split()))
    flag = int(W / 2 == x and H / 2 == y)
    return 0.5 * W * H, flag


def main():
    ans = solve()
    print(ans[0], ans[1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const int maxn = 1e9+5;
const dd eps = 1e-6;
const ll mod = 1e9+7;

int n,m,fa[N],pos[N],sta[N],l,r,vis[N];
vector<pair<int,int> > g[N];
pair<int,int> li[N];
vector<int> ans;
int find(int x){
  return fa[x] == x ? x : fa[x] = find(fa[x]);
}

bool unite(int u,int v){
  int x = find(u),y = find(v);
  if(x == y) return false;
  fa[x] = y;
  return true;
}

bool dfs(int now){
  int res = sta[now];
  vis[now] = 1;
  for(int i = 0;i < g[now].size();i++){
    int u = g[now][i].first;
    if(vis[u]) continue;
    bool nex = dfs(u);
    if(nex) ans.push_back(g[now][i].second);
    res ^= nex;
  }
  return res;
}

int main(){
  // freopen("input.txt","r",stdin);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  for(int i = 1;i <= n;i++) {cin>>li[i].first>>li[i].second;fa[i] = i;}
  sort(li+1,li+1+n);
  for(int i = 1;i <= n;i++) pos[i] = li[i].first,sta[i] = li[i].second;
  for(int i = n;i;i--) sta[i]^=sta[i-1];
  for(int i = 1;i <= m;i++){
    cin>>l>>r;
    l = lower_bound(pos+1,pos+1+n,l) - pos;r = upper_bound(pos+1,pos+1+n,r)-pos;
    if(unite(l,r)) g[l].push_back({r,i}),g[r].push_back({l,i});
  }
  dfs(n+1);
  for(int i = 1;i <= n;i++){
    if(vis[i]) continue;
    if(dfs(i)){
      cout<<"-1"<<endl;
      return 0;
    }
  }
  cout<<ans.size()<<endl;
  sort(ans.begin(),ans.end());
  for(auto i:ans) cout<<i<<" ";
  if(ans.size()) cout<<endl;
  return 0;
}


Measured memory_bytes: 9212
N = int(input())
A = [0, 0, 0, 0, 0]
for i in range(N):
  S = input()
  if S[0] =='M':
    A[0] += 1
  if S[0] =='A':
    A[1] += 1
  if S[0] =='R':
    A[2] += 1
  if S[0] =='C':
    A[3] += 1
  if S[0] =='H':
    A[4] += 1
ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j + 1, 5):
      ans += A[i] * A[j] * A[k]
print(ans)
  

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, b = 0;
    rep(i, n) {
        if (s[i] == 'R') ++r;
        else ++b;
    }
    if(r>b) cout << "Yes" << endl;
    else cout << "No" << endl; 

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i--)
#define F first
#define S second
int main()
{    
  double n,k;
  cin>>n>>k;
  vector<double>A(n);
  for(double i=0;i<n;i++)
  {
      cin>>A[i];
  }
 double sum=0; 
  for(double j=0;j<k;j++)
      {
         sum+=(A[j]+1)/2; 
      }
     double j=0;
      double overallsum=sum;
  for(double i=k;i<n;i++)
  {
      sum-=(A[j]+1)/2;j++;
      sum+=(A[i]+1)/2;
      if(sum>overallsum){overallsum=sum;}
  }
  cout<<fixed<<setprecision(12)<<overallsum;
    return 0;
}

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

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

  vector<int> p(M, 0);
  vector<bool> S(M, 0);
  vector<int> penalty(N, 0);
  vector<bool> status(N, false);
  rep(i, M) {
    string temp = "";
    cin >> p[i] >> temp;
    p[i]--;
    if (temp == "AC") {
      S[i] = true;
    } else {
      S[i] = false;
    }
  }

  int ac = 0;
  int sum_penalty = 0;
  rep(i, M) {
    if (S[i] && !(status[p[i]])) { // 未ACでACした
      status[p[i]] = true;
      sum_penalty += penalty[p[i]];
      ac++;
    } else if (S[i] && status[p[i]]) { // 既ACでACした
      continue;
    } else if (!(S[i]) && !(status[p[i]])) { // 未ACでWAした
      penalty[p[i]]++;
    } else if (!(S[i]) && status[p[i]]) { // 既ACでWAした
      continue;
    }
  }

  cout << ac << " " << sum_penalty << endl;
}

Measured memory_bytes: 4048
# -*- coding: utf-8 -*-
from operator import itemgetter
# input
n, k = map(int, input().split())
temp_array = []
addlist = temp_array.append
for i in range(n):
    addlist(list(map(int, input().split())))
temp_array.sort(key=itemgetter(0))
o = 0
for i in temp_array:
    o += i[1]
    if o >= k:
        print(i[0])
        exit()



Measured memory_bytes: 29096
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vector<int>a(q);
	vector<int>b(q);
	vector<int>c(q);
	vector<int>d(q);
	for(int i=0;i<q;++i)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	vector<int>A(n);
	int ans=0;
	function<void(int,int)>dfs=[&](int p,int low){
		if(p==n){
			int tot=0;
			for(int i=0;i<q;++i)
				tot+=(A[b[i]-1]-A[a[i]-1]==c[i])*d[i];
			ans=max(ans,tot);
			return;
		}
		for(int i=low;i<=m;++i) {
			A[p]=i;
			dfs(p+1,i);
			A[p]=0;
		}
	};
	dfs(0,1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3604
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var Q = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        var amax = a[n - 1];
        var amin = a[0];
        var b = new int[amax + 1];
        setB(a, b );
        for (int i = 0; i < Q; i++)
        {
            var q = int.Parse(Console.ReadLine().Trim());
            getAns(b, amin, q);
        }
    }
    public static void getAns (int [] b,int amin , int q)
    {
        var bL = b.Length;
        var na = b[bL - 1];
        var ans = na % q;
        if (ans == q - 1) { Console.WriteLine(q - 1); return; }
        if (ans == 0) na -= 1;
        else na -= ans;
        if (na <= 0) { Console.WriteLine(ans); return; }
        while (true)
        {
            na = b[na];
            var w = na % q;
            if (w == q - 1) { Console.WriteLine(q-1); return; }
            ans = Max(ans, w);
            if (w == 0) na -= 1;
            else na -= w;
            if (na == 0) break;
        }
        Console.WriteLine(ans);
    }
    public static void setB(int[] a, int[] b)
    {
        var aL = a.Length;
        var bL = b.Length;
        for (int i = 0; i < aL; i++)
            b[a[i]] = a[i];
        for (int i = a[0] + 1; i < bL  ; i++)
            if (b[i] == 0) b[i] = b[i - 1];
    }
}





Measured memory_bytes: 41632
def aa
    n = gets.chomp.to_i

    r = []
    for i in 1..n
        r.push(gets.chomp.to_i)
    end

    ma = -1000000000
    mi = r[0]
    for j in 1..(n-1)
        ma = [ma, r[j]-mi].max
        mi = [mi, r[j]].min
    end

    puts ma
end

aa


Measured memory_bytes: 8552
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
 
int main() {
  int n, t;
  cin >> n >> t;
  int sum = 0;
  int ray = 0;
  int count = 0;
  rep ( i, n ) {
    int shower;
    cin >> shower;
    if ( (shower - ray) >= t ) sum += t;
    else sum += (shower - ray);
    ray = shower;
    count ++;
    if (count == n ) sum += t;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	priority_queue <ll,vector<ll> , greater<ll>> q;
	ll n,x,y,m,b,c=0;
	cin>>n>>m;
	for(ll i=0;i<n;i++)
	{
		cin>>x;
		q.push(x);
	}
	ll c1=0;
	multimap<ll,ll, greater<ll>> ma;
	for(ll i=0; i<m; i++)
	{
		cin>>x>>y;
		ma.insert(pair<ll,ll>(y,x));
	}
	multimap<ll,ll, greater<ll>> :: iterator it;
	it=ma.begin();
	for(ll i=0; it!=ma.end(); i++)
	{	

		if(q.top() < it->first && c < it->second)
		{
			q.pop();
			q.push(it->first);
			c++; c1++;
		}
		else if(q.top() < it->first && c >= it->second )
			{ 	it++; 
				c=0;
			}
		else if(q.top() >= it->first)
			{ break; }
		if(c1>=n) break;		
	}
//for(it=ma.begin(); it!=ma.end(); it++)
//	cout<<it->second<<" "<<it->first<<endl;

ll sum=0;
	for(ll i=0; i<n; i++){
		sum+=q.top();
		//cout<<q.top()<<" ";
		q.pop();

	}
cout<<sum;
	/*for(ll i=0; i<n; i++)
	{
		cout<<q.top()<<" ";
		q.pop();
	} */
	return 0;
}

Measured memory_bytes: 7284
#include<stdio.h>

int main(void)
{
    long long int a,b,c,d,x,y,p[4];
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    p[0] = a*c;
    p[1] = a*d;
    p[2] = b*c;
    p[3] = b*d;
    int i,j,k;
    for(i = 0 ; i < 3 ; i++)
    {
        for(j = i + 1 ; j < 4 ; j++)
        {
            if(p[i] < p[j])
            {
                k = p[i];
                p[i] = p[j];
                p[j] = k;
            }
        }
    }
    printf("%lld\n",p[0]);
    return 0;
}

Measured memory_bytes: 1732
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = 0; i * d <= r; ++i) {
		if (d * i >= l) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long dp[11][11][11];
int main(){
  #define int long long
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans=0;
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      for(int k=0;k<=9;k++){
        int check=0;
        for(int h=0;h<N;h++){
          if(check==0){
            if(S.at(h)-'0'==i){
              check++;
              continue;
            }
          }
          if(check==1){
            if(S.at(h)-'0'==j){
              check++;
              continue;
            }
          }
          if(check==2){
            if(S.at(h)-'0'==k){
              check++;
              break;
            }
          }
        }
        if(check==3 && dp[i][j][k]==0){
          dp[i][j][k]=1;
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main(void){

int S;
int top, under;

scanf("%d", &S);

top = S / 100;
under = S % 100;

if(top <= 12 && 0 < top && under <= 12 && 0 < under){
    printf("AMBIGUOUS\n");
}
else if(top <= 12 && 0 < top && under > 12){
    printf("MMYY\n");
}
else if(top <= 12 && 0 < top && under == 0){
    printf("MMYY\n");
}
else if(under <= 12 && 0 < under && top > 12){
    printf("YYMM\n");
}
else if(under <= 12 && 0 < under && top == 0){
    printf("YYMM\n");
}
else{
    printf("NA\n");
}


return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int k, length, pointer;
string S, s[100005];

int main(){

    cin >> S >> k;
    length = S.size();

    for (int i = 1; i <= 5; i++){
        for (int j = 0; j <= length-i; j++){
            s[pointer++] = S.substr(j,i);
        }
    }

    sort(s, s+pointer);
    unique(s, s+pointer);

    cout << s[k-1] << endl;;

    return 0;

}

Measured memory_bytes: 2176
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int result = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int a = sc.nextInt();

			int count = 0;
			while(a % 2 == 0){
				a /= 2;
				count++;
			}

			result = Math.min(result, count);
		}

		System.out.println(result);
	}
}


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

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

using namespace std;

typedef long double ld;
#define MAX_V 1000
int V;

vector<int> g[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  REP(i, g[v].size()) {
    int u = g[v][i], w = match[u];
    if (w < 0 || (!used[w] && dfs(w))) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(void) {
  int res = 0;
  memset(match, -1, sizeof(match));
  REP(v, V) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) res++;
    }
  }
  return res;
}

int main() {
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n)break;
    V = n;
    vector<tuple<ld, ld, ld>> troop;
    REP(i,n){
      int x,y,v;
      cin>>x>>y>>v;
      troop.emplace_back(x,y,v);
    }
    vector<tuple<ld, ld>> base;
    REP(i,m){
      int x,y;
      cin>>x>>y;
      base.emplace_back(x,y);
    }
    ld lv = 0.0, rv = 20000.0;
    REP(i,50) {
      REP(j,MAX_V) g[j].clear();
      ld mid = (lv + rv) / 2.0;
      REP(j,n)REP(k,m) {
        ld tx,ty,tv,bx,by;
        tie(tx,ty,tv) = troop[j];
        tie(bx,by) = base[k];
        if ((tx-bx)*(tx-bx)+(ty-by)*(ty-by)<tv*tv*mid*mid) {
          add_edge(j,n+k);
        }
      }
      if (bipartite_matching() >= m) rv = mid;
      else lv = mid;
    }
    cout << setprecision(10) << fixed << lv << endl;
  }
  return 0;
}

Measured memory_bytes: 1436
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define ll long long
#define ld long double

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()

#define endl '\n'
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const int MOD=1e9+7;
const ll INF=1e18;
const double PI=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  ll n,a,b;
  cin >> n >> a >> b;
  
  ll ans = 0;
  ans += (n/(a+b))*a;
  n%=(a+b);
  ans += min(n,a);
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int N;
	cin >> N;
	int count = 0;
	for (int i = 1; i <= N; ++i) {
		string s;
		s = to_string(i);
		if (s.length() % 2 == 1) {
			++count;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
	int n,m,i,k,x=0;
	scanf("%d %d",&n,&m);
	int a[m],b[m][n],point[n];
	//m??????????????°???n????????°
	for(i = 0;i < m;i++){
		scanf("%d",&a[i]);
	}
	for(i = 0;i < n;i++){
		point[i]=0;
	}
	for(i = 0;i < m;i++){
		for(k = 0;k < n;k++){
			scanf("%d",&b[i][k]);
		}
	}
	for(i = 0;i < m;i++){
		x=0;
		for(k = 0;k < n;k++){
			if(b[i][k] == a[i]){
				point[k]++;
			}else{
				point[a[i]-1]++;
			}
//			printf("%d",point[i]);
		}
//		printf("__%d\n",point[i]);
	}
//	printf("\n\n\n\n");
	for(i = 0;i < n;i++){
		printf("%d\n",point[i]);
	}
	return 0;
}

Measured memory_bytes: 632
#ITP1_6_C
A=[[[0 for k in range(10)]for j in range(3)]for i in range(4)]
format(A)
n=int(input())
for m in range(n):
  b,f,r,v=map(int,input().split())
  S=A[b-1][f-1][r-1]+v
  A[b-1][f-1][r-1]=S
for i in range(4):
  for j in range(3):
    for k in range(10):
      print ("",A[i][j][k],end='')
    print("")
  if i<3:
    print("####################")
  




Measured memory_bytes: 5636
#include<iostream>
using namespace std;
int main(){
long n,i,max,min,sum=0;
cin >>n;
n--;
int a[n];
for(i=0;i<=n;i++){
cin>>a[i];
}
max=a[0];
min=a[0];
i=0;
for(i=0;i<=n;i++){
if(a[i]<min){
min=a[i];
}else if(a[i]>=max){
max=a[i];
}
sum=sum+a[i];
}
cout<<min<<" "<<max<<" "<<sum<<endl;
return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;
map<set<int>,int>memo;

int M,N;
vector<string>v;
int dfs(set<int> &t){
	if(t.size()==1)return 0;
	if(memo.find(t)!=memo.end())return memo[t];
	int r=1<<30;
	for(int j=0;j<M;j++){
		set<int>a,b;
		for(auto &e:t)(v[e][j]=='0'?a:b).insert(e);
		if(a.size()&&b.size())r=min(r,max(dfs(a),dfs(b))+1);
	}
	return memo[t]=r;
}

int main(){
	for(;cin>>M>>N,M;){
		v.resize(N);
		for(int i=0;i<N;i++)cin>>v[i];
		set<int>t;
		for(int i=0;i<N;i++)t.insert(i);
		memo.clear();
		printf("%d\n",dfs(t));
	}
}

Measured memory_bytes: 8664
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    int[] M = new int[10];
    private void Scan()
    {
        for (int i = 0; i < 10; i++)
        {
            M[i] = int.Parse(Console.ReadLine());
        }
    }

    public void Solve()
    {
        Scan();
        Array.Sort(M);
        Console.WriteLine("{0}\n{1}\n{2}", M[9], M[8], M[7]);
    }
}

Measured memory_bytes: 9304
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong(), y = sc.nextLong();
        long cur = x;
        long cnt = 0;
        while (cur <= y) {
            if(cur <=  Long.MAX_VALUE - cur) {
                cur += cur;
            }
            else {
                break;
            }
            cnt ++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
N, K = map(int, input().split())
A = list(map(int, input().split()))

v, p, s = [-1] * N, 1, K
while s > 0:
    if v[p - 1] == -1:
        v[p - 1] = s
    else:
        p = v.index(v[p - 1] - s % (v[p - 1] - s)) + 1
        break
    p, s = A[p - 1], s - 1
print(p)


Measured memory_bytes: 32236
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int x,y,z;
	int ans=0;
	
	cin>>x>>y>>z;
	x -= z;
	ans = x/(y+z);
	cout<<ans<<endl;
	return 0;
}

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++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    string s; cin>>s;
    ll n=s.size();
    bool kita=false, minami=false, nishi=false, higashi=false;
    rep(i,n){
        if(s[i]=='N') kita=true;
        if(s[i]=='S') minami=true;
        if(s[i]=='W') nishi=true;
        if(s[i]=='E') higashi=true;
    }
    if(kita==minami){
        if(nishi==higashi){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    long long int dp[100010][13];
    int i, j, k;
    for(i = 0; i < 100010; i++){
        for(j = 0; j < 13; j++){
            dp[i][j] = 0;
        }
    }

    if(s[0] == '?'){
        for(i = 0; i < 10; i++){
            dp[0][i] += 1;
        }
    }else{
        dp[0][(int)s[0]-(int)'0'] += 1;
        //cout << "a" << endl;
    }

    int mod = 1;
    int num;
    for(i = 1; i < s.size(); i++){
        mod = (mod * 10) % 13;
        if(s[i] == '?'){
            for(j = 0; j < 13; j++){
                for(k = 0; k < 10; k++){
                    dp[i][(j+mod*k)%13] = (dp[i][(j+mod*k)%13] + dp[i-1][j])%1000000007;
                }
            }
        }else{
            num = (int)s[i] - (int)'0';
            for(j = 0; j < 13; j++){
                dp[i][(j+num*mod)%13] = (dp[i][(j+num*mod)%13] + dp[i-1][j])%1000000007;
            }
        }
    }

    cout << dp[s.size()-1][5] << endl;
}




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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n,ma,mb;
  cin >> n >> ma >> mb;
  vll a(n),b(n),c(n);
  REP(i, n)
    cin >> a[i] >> b[i] >> c[i];

  ll N = 410;
  ll dp[N][N];
  REP(i, N){
    REP(j, N)
      dp[i][j] = INF;
  }

  dp[0][0]=0;
  REP(k, n){
    for(ll i = N-1-a[k]; i>=0; i--){
      for(ll j = N-1-b[k]; j>=0; j--)
        dp[i+a[k]][j+b[k]] = min(dp[i+a[k]][j+b[k]], dp[i][j]+c[k]);
    }
  }

  ll ans = LLINF;
  REP1(i, N){
    REP1(j, N){
      if(i%ma==0 && j%mb==0 && i/ma==j/mb)
        ans = min(ans, dp[i][j]);
    }
  }


  if(ans == INF)
    ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    
    ll XOR = 0;
    for(int i = 0; i < N;i++){
        XOR ^= a[i];
    }
    // cout << XOR << endl;
    
    for(int i = 0; i < N;i++){
        res.emplace_back(XOR^a[i]);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<vector<ll>>() << endl;
    return 0;
}


Measured memory_bytes: 6796
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef priority_queue<int> Pr; typedef vector<int> Vi; typedef vector<Pi> Vp;
typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef vector<Int> VI;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n; cin>>n; set<Int> a;
    for (int i = 0; i < n; i++){
        Int k; cin>>k; a.insert(k);
    }
    while(a.size()>1){
        int m=*a.begin();
        for(auto it=a.begin(); it!=a.end(); it++){
            if((++it)==a.end())break;
            if(*it%m==0)a.erase(it);
            else {a.insert(*it%m); a.erase(it);}
        }
    }
    cout<<*a.begin()<<'\n';
}

Measured memory_bytes: 4992
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		
		ArrayList<Long> list = new ArrayList<Long>();
		list.add(1L);
		list.add(2L);
		list.add(3L);
		list.add(4L);
		list.add(5L);
		list.add(6L);
		list.add(7L);
		list.add(8L);
		list.add(9L);
		
		int i = 0;
		while(list.size() < k) {
			long x = list.get(i);
			if (x % 10 != 0) list.add((10*x) + (x % 10) - 1);
			list.add((10*x) + (x % 10));
			if (x % 10 != 9) list.add((10*x) + (x % 10) + 1);
			i++;
		}
		
		
		System.out.println(list.get(k-1));
	}
}

Measured memory_bytes: 25428
n = gets.to_i
h = {}
n.times do
  s = gets
  h[s.chomp]=2
end

for m in ["S", "H", "C", "D"] do
  for i in 1..13 do
    puts "#{m} #{i}" if !h.has_key?(m+" "+i.to_s)
  end
end


Measured memory_bytes: 6864
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

const int INF = 1<<28;

struct edge_t {
    int from, to, cost;
    edge_t(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const edge_t &o) const {
        return (cost < o.cost);
    }
    bool operator>(const edge_t &o) const {
        return (cost > o.cost);
    }
};
struct state_t {
    int v;
    int min_cost;
    state_t(int v, int min_cost) : v(v), min_cost(min_cost) {}
    bool operator<(const state_t &o) const {
        return (min_cost < o.min_cost);
    }
    bool operator>(const state_t &o) const {
        return (min_cost > o.min_cost);
    }
};
typedef vector<edge_t> vertex_t;
struct graph_t {
    vector<vertex_t> g;

    graph_t() {}

    graph_t(int vertex_count) {
        g.resize(vertex_count);
    }
    graph_t(vector<vertex_t> g) : g(g) {}

    inline vertex_t& operator[](int index) {
        return g[index];
    }

    inline void push_back(vertex_t v) {
        g.push_back(v);
    }

    void dijkstra(int s, vector<int> &min_cost) {
        min_cost.resize(g.size());
        priority_queue< state_t, vector<state_t>, greater<state_t> > q;
        
        fill(min_cost.begin(), min_cost.end(), INF);

        min_cost[s] = 0;
        q.push(state_t(s, 0));

        while (!q.empty()) {
            state_t p = q.top(); q.pop();
            int v = p.v;
            if (min_cost[v] < p.min_cost) continue;
            for (int i = 0; i < g[v].size(); i++) {
                edge_t e = g[v][i];
                if (min_cost[e.to] > min_cost[v] + e.cost)  {
                    min_cost[e.to] = min_cost[v] + e.cost;
                    q.push(state_t(e.to, min_cost[e.to]));
                }
            }
        }
    }
};

int main() {
    int n; cin >> n;
    graph_t graph(n+1);
    for (int i = 1; i <= n; i++) {
        int r; cin >> r;
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int t; cin >> t;
            graph[r].push_back(edge_t(r, t, 1));
        }
    }

    vector<int> min_cost;
    int p; cin >> p;
    for (int i = 0; i < p; i++) {
        int s, d, v;
        cin >> s >> d >> v;
        graph.dijkstra(s, min_cost);
        if (min_cost[d] < v) {
            cout << min_cost[d]+1 << endl;
        } else {
            cout << "NA" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  vector<vector<int>> A(N,vector<int>(3));
  REP(i, N){
    REP(j, 3){
      cin >> A.at(i).at(j);
    }
  }
  
  REP(i,101){
    REP(j,101){
      vector<ll> vec;
      ll MIN = INF;
      REP(k,N){
        if(A.at(k).at(2)==0){
          MIN=min(MIN,(ll)abs(i-A.at(k).at(1))+abs(j-A.at(k).at(0)));
          continue;
        }
        vec.push_back(A.at(k).at(2)+abs(i-A.at(k).at(1))+abs(j-A.at(k).at(0)));
      }
      ll H = vec.at(0);
      int flag = 0;
      for(auto x:vec){
        if(x!=H||MIN<x){
          flag=1;
        }
      }

      if(flag==0){
        cout << j << " " << i << " " << H << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3628
#include<cstdio>
#define MAX 10000
#define NIL -1
struct Node {int parent,left,right;};
Node T[MAX];
int n,D[MAX],H[MAX];
void setDepth(int u,int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left != NIL)
    h1=setHeight(T[u].left)+1;
  if(T[u].right != NIL)
    h2=setHeight(T[u].right)+1;
  return H[u]=(h1 > h2 ? h1 : h2);
}
int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}
void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  if(T[u].parent == NIL){
    printf("root\n");
  }else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}
int main(){
  int v,l,r,root=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent=NIL;
  for(int i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }
  for(int i=0;i<n;i++) if(T[i].parent == NIL) root=i;
  setDepth(root,0);
  setHeight(root);
  for(int i=0;i<n;i++) print(i);
  return 0;
}



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

int main(){
	int a, b, n;
	while (cin >> a >> b >> n){
		int sum = 0;
		for (int i = 1; i <= n; i++){
			a *= 10;
			sum += a / b % 10;
			a %= b;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1148
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
	string b;
	cin >> b;
	std::vector<int> cnt(b.size(), 0);

	for (int i = 0; i < b.size(); i++) {
		bool ok = false;
		if (b.at(i) == 'A') {
			ok = true;
		}
		else if (b.at(i) == 'C') {
			ok = true;
		}
		else if (b.at(i) == 'G') {
			ok = true;
		}
		else if (b.at(i) == 'T') {
			ok = true;
		}
		if (ok) {
			if (i == 0) {
				cnt.at(0) = 1;
			}
			else {
				cnt.at(i) = cnt.at(i - 1) + 1;
			}
		}
	}
	int c = 0;
	for (int i = 0; i < b.size(); i++) {
		if (c < cnt.at(i)) {
			c = cnt.at(i);
		}
	}
	cout << c;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define VE vector<int>
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
//
LL mod_pow(LL x,LL n,LL mod){
  if(n==0){
    return 1;
  }
  LL res=mod_pow(x*x%mod,n/2,mod);
  if(n&1){
    res=res*x%mod;
  }
  return res;
}
int main(){
  LL M,N;
  cin>>M>>N;
  cout<<mod_pow(M,N,INF)<<endl;
  return 0;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    ll ans=0;
    rep(i,n){
        ll a; cin>>a;
        ans+=a-1;
    }
    cout<<ans<<endl;
    return 0;
}

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

int N;
int A[210];

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

  cin >> N;
  for(int i =0; i < N; i++) cin >> A[i];
  
  int res = 0;
  
  while(true){
    bool exist_odd = false; //A[i]がすべて偶数かどうかを判定
    for(int i = 0; i < N; i++){
      if(A[i] % 2 != 0) exist_odd = true ;
    }
    
    if(exist_odd) break;
    
    for(int i =0; i < N; i++){
      A[i] /= 2;
    }
    
    res++;
  }
  cout << res << endl;

}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    int[] ansCount = new int[n];
    for (int i = 0; i < q; i++) {
      int a = Integer.parseInt(sc.next());
      ansCount[a - 1] += 1;
    }
    for (int i = 0; i < n; i++) {
      int score = k - (q - ansCount[i]);
      pw.println(score > 0 ? "Yes" : "No");
    }
  }
}


Measured memory_bytes: 52148
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=1e5 + 10;
ll f(ll x)
{
    return x*1LL*(x+1)/2LL;
}
int main ()
{
    int a,b;cin >> a >> b;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<=100000;i++){
        if(i*a - (i - 1) >=b){
            //cout<<"tot = "<<i*a<<" empty = "<<i*a - (i-1)<<endl;
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}
/*
*/






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

struct Edge {
  int to;
  string lab;
  Edge() {}
  Edge(int to, string lab) : to(to), lab(lab) {}
};

const int MAX_N = 41;


vector<Edge> E[MAX_N], rE[MAX_N];
bool can[MAX_N];
int n, a, s, g;

void bfs(int src, vector<Edge> e[], bool vis[]) {
  queue<int> que;
  que.push(src);
  fill(vis, vis+n, false);
  vis[src] = true;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    for(int i = 0; i < e[p].size(); ++i) {
      Edge &tmp = e[p][i];
      if(vis[tmp.to]) continue;
      que.push(tmp.to);
      vis[tmp.to] = true;
    }
  }
}

struct State {
  int v, e, c;
  State() {}
  State(int v, int e, int c) : v(v), e(e), c(c) {}
  bool operator < (const State &s) const {
    if(v != s.v) return v < s.v;
    if(e != s.e) return e < s.e;
    return c < s.c;
  }
};

int main() {
  while(true) {
    for(int i = 0; i < MAX_N; ++i) {
      E[i].clear();
      rE[i].clear();
    }
    cin >> n >> a >> s >> g;
    if(n|a|s|g); else break;
    for(int i = 0; i < a; ++i) {
      int x, y;
      string lab;
      cin >> x >> y >> lab;
      E[x].push_back(Edge(y, lab));
      rE[y].push_back(Edge(x, lab));
    }

    bfs(g, rE, can);
    if(!can[s]) {
      cout << "NO" << endl;
      continue;
    }

    E[n].push_back(Edge(s, ""));

    set<State> vis[2];
    vis[0].insert(State(n,0,0));
    string res = "";

    for(int p = 0; ; p = 1-p) {
      if(res.size() > 300) {
        res = "NO";
        break;
      }
      int q = 1-p;
      vis[q].clear();
      char mini = 127;
      for(set<State>::iterator it = vis[p].begin();
          it != vis[p].end(); ++it) {
        State s = *it;
        Edge &tmp = E[s.v][s.e];
        if(s.c == tmp.lab.size()) {
          s.v = tmp.to;
          if(s.v == g) {
            vis[q].clear();
            mini = 0;
            break;
          }
          for(int i = 0; i < E[s.v].size(); ++i) {
            Edge &tmp2 = E[s.v][i];
            if(!can[tmp2.to]) continue;
            if(tmp2.lab[0] <= mini) {
              if(tmp2.lab[0] < mini) {
                vis[q].clear();
                mini = tmp2.lab[0];
              }
              vis[q].insert(State(s.v, i, 1));
            }
          }
        } else {
          State s = *it;
          Edge &tmp2 = E[s.v][s.e];
          if(tmp2.lab[s.c] <= mini) {
            if(tmp2.lab[s.c] < mini) {
              vis[q].clear();
              mini = tmp2.lab[s.c];
            }
            ++s.c;
            vis[q].insert(s);
          }
        }
      }
      if(mini == 0) {
        break;
      } else {
        res += mini;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1412
#include<stdio.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

ll judge(ll a,ll b){
    if(a>b)return a-b;
    if(b>a)return b-a;
    return a;
}

int main(void){
    int n;
    scanf("%d",&n);
    ll a[500000]={};
    ll k[500000]={};
    REP(i,1<<n)scanf("%lld",&a[i]);
    for(int i=n;i>=1;i--){
        ll num=1<<i;
        //printf("%lld\n",num);
        REP(j,num/2){
            k[j]=judge(a[j*2],a[j*2+1]);
            //printf("###%lld\n",k[j]);
        }
        //REP(j,num/2)printf("######%lld\n",k[j]);
        REP(j,num/2)a[j]=k[j];
    }
    printf("%lld\n",a[0]);
    return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
struct edge{ll from, to, cost;};
// v:=頂点数 es:=辺の集合 cost:=始点からの最短経路のコストを格納する配列
// s:=始点(指定しなければ頂点0) g:=終点(指定しなければ頂点v-1)
// 始点から到達可能な負閉路が検出された場合falseを、それ以外の場合trueを返す
bool bell(int v,vector<edge>& es,vector<ll>& cost,ll s=0,ll g=-1){
    if(g==-1)g=v-1;
    cost.assign(v,INF);//負閉路検出は０に初期化
    cost[s] = 0;
    rep(i,v*2){
        for(auto& e : es){
            if(cost[e.from]<INF&&cost[e.from]+e.cost<cost[e.to]){
                if(i>=v-1){
                    //return false;
                    //始点から到達可能で、かつ終点へ到達可能な負閉路が検出された場合falseを、それ以外の場合trueを返す
                    if(e.to==g) return false;
                    else cost[e.to] = -INF;
                }
                else{
                    cost[e.to]=cost[e.from]+e.cost;
                }
            }
        }
    }
    return true;
}
int main(){
    ll n,m,p;cin >> n >>m >>p;
    vector<edge> v(m);
    rep(i,m){
        cin >> v[i].from >>v[i].to >>v[i].cost;
        v[i].from--;v[i].to--;v[i].cost=-(v[i].cost-p);
    }
    vl cost;
    if(bell(n,v,cost))cout << max(0LL,-cost[n-1]) <<endl;
    else cout << -1 <<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
using namespace std;
 
 bool F(int n){
	 bool b=false;
	 string s;
	 s=to_string(n);
	 for(int i=0;i<s.size();i++){
		 if(s[i]=='3')b=true;
		 }
		return b; 
	 }
 
int main(){
    int n;
    cin>>n;
  for(int i=1;i<=n;i++){
	  if(i%3==0||F(i)==true){
		  cout<<" "<<i;
	  }else{
	  }
  }
  cout<<endl;
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	double xa, ya, ra, xb, yb, rb, r;
	while (n--){
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		r = sqrt((xb - xa)*(xb - xa) + (yb - ya)*(yb - ya));
		if (r > ra + rb) cout << 0 << "\n";
		else if (r + ra < rb) cout << -2 << "\n";
		else if (r + rb < ra) cout << 2 << "\n";
		else if (r <= ra + rb) cout << 1 << "\n";
	}
	return 0;
}

Measured memory_bytes: 1236
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, a, min = 1000000000, max = 0;
  cin >> n;

  while(n--) {
    cin >> a;
    if (a < min) {
      min = a;
    }
    if (a > max) {
      max = a;
    }
  }

  cout << max - min << endl;
  return 0;
}


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

int main() {
    int H,W,N; cin >> H >> W >> N;
    vector<vector<int>> C(W, vector<int>(H));
    bool right = true;
    int x = 0, y = 0;
    rep(i,N) {
        int a; cin >> a;
        rep(j, a) {
            C[x][y] = i + 1;
            if (right) {
                if (x + 1 == W) {
                    right = false;
                    y++;
                } else {
                    x++;
                }
            } else {
                if (x == 0) {
                    right = true;
                    y++;
                } else {
                    x--;
                }
            }
        }
    }

    rep (y, H) {
        rep (x, W) {
            cout << C[x][y] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3664