akhauriyash/Code-Regression huggingface dataset:
from queue import Queue
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]

white=sum([1 if s[y][x]=='.' else 0 for x in range(W) for y in range(H)])
used=[[False for x in range(W)] for y in range(H)]
q=Queue()
q.put((0,0,1))
while True:
    if q.empty():
        print(-1)
        break
    x,y,l=q.get()
    if used[y][x]:
        continue
    if x==W-1 and y==H-1:
        print(white-l)
        break
    used[y][x]=True
    for d in [(1,0),(0,1),(-1,0),(0,-1)]:
        nx=x+d[0]
        ny=y+d[1]
        if ny>=0 and ny<H and nx>=0 and nx<W:
            if s[ny][nx]=='.':
                q.put((nx,ny,l+1))
    


Measured memory_bytes: 3952
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const int N_MAX = 110;

int X[N_MAX];
int Y[N_MAX];
ll H[N_MAX];
int main(){
    int N;
    cin >> N;
    int ref_x, ref_y;
    ll ref_h;
    REP(i,N){
        int x,y;
        ll h;
        cin >> x >> y >> h;
        X[i] = x;
        Y[i] = y;
        H[i] = h;
        if(h > 0){
            ref_x = x;
            ref_y = y;
            ref_h = h;
        }
    }

    int x,y;
    ll h;
    for(x = 0; x <= 100; x++){
        for(y = 0; y <= 100; y++){
            h = ref_h + abs(x - ref_x) + abs(y - ref_y);
            bool end = true;
            for(int i = 0; i < N; i++){
                if(H[i] != max(0LL, h - abs(x - X[i]) - abs(y - Y[i]))) end = false;
            }
            if(end) goto success;
        }
    }

success:
    printf("%d %d %lld\n", x, y, h);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define _GLIBCXX_DEBUG
const int INF=1e18;

signed main(){
  	int A,B,C;cin>>A>>B>>C;
    if(A==B)cout<<C<<endl;
    else{
        if(A==C)cout<<B<<endl;
        else cout<<A<<endl;
    }
}

Measured memory_bytes: 256
//fold
/*Bismillahir Rahmanir Rahim.
first prove the logic, second write the code. Always challenge your logic and be ready to write new logic*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#include <tr1/unordered_set>
#define ll	long long int
#define ull unsigned long long int
// #define ld long double
#define inf 1000000007
#define si(a)	  scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a)	  scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pi(a)	  printf("%d\n", a)
#define pl(a)	  printf("%lld\n", a)

using namespace std;
using namespace std::tr1;
//end


int n, m, t;


int main(){
	cin.tie (NULL);
	cout.tie (NULL);

	si(n);
	ll arr[n+5];
	ll cs[n+5];
	for (int i = 0; i<n; i++) {
		sl(arr[i]);
		cs[i]=(i==0?0:cs[i-1])+arr[i];
	}
	ll os=LLONG_MAX;
	for (int i=0; i<n-1; i++){
		os=min(os,llabs(cs[n-1]-cs[i]-cs[i]));
	}
	pl(os);
	
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define int long long int 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
using namespace std;
int32_t main()
{
    IOS;
  int n;
  cin>>n;
  string s;
  cin>>s;
  int c=1;
  for(int i=1;i<n;i++)
  {
      if(s[i]!=s[i-1])
      c++;
  }
  cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
//B - TAKOYAKI FESTIVAL 2019

int main(int argc, const char * argv[]) {
    int N=0;
    int D[100+5];
    long long sum = 0;
    
    cin >> N;
    
    for(int i=0; i<N; i++){
        cin >> D[i];
    }

    
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            sum += D[i]*D[j];
        }
    }

    cout << sum <<endl;
    
    return 0;
}


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


#define vt vector
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define ar array
#define inf() ifstream cin("d.txt")
#define onf() ofstream cout("test.txt")
#define mod 1000000007
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" "
#define prt2(a,b) cout<<a<<" "<<b<<" "
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" "
#define in(a) cin>>a
#define inn(a,b) cin>>a>>b
#define innn(a,b,c) cin>>a>>b>>c 
#define rep(i,st,end) for(int i=st;i<end;i++)
#define repv(i,st,end) for( i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define TEST ll tc;cin>>tc;while(tc--)
#define EACH(x, a) for (auto& x: a)

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"\n";
    err(++it, args...);
}

ll spf[1000005]={0} ;
void sieve()
{
   spf[1] = 1;
   for(int i = 2 ; i<1000005;i++)
      spf[i] = i;

      for(int i = 4 ; i<1000005;i+=2)
      spf[i] = 2;

      for(int i = 3 ;i*i<1000005;i++)
      {
         if(spf[i] ==i)
         {
            for(int j=i*i;j<1000005;j+=i)
            {
               if(spf[j]==j)
               spf[j] = i;
            }
         }
      }
   }

map<ll,ll>prime ;

void primefactor(ll x)
{
   ll cnt= 0;
   set<ll>s;
   unordered_map<ll,ll>mp;

   while(x!=1)
   {
    s.insert(spf[x]);
      x=x/spf[x];
   }
   for(auto it: s)
    prime[it]++;
}


void solve()
{

  ll n;
  read(n);
  vt<ll>v(n) ;
  read(v);
  ll g= v[0];
  rep(i,1,n)
  g=__gcd(g,v[i]);

  rep(i,0,n)
  primefactor(v[i]);
  // for(auto it:prime)
  //   cout<<it.first<<" "<<it.second<<"\n";

  ll f= 0;
  for(auto it:prime)
  {
    if(it.second>1)
    {
      f= 1;
      break ;
    }
  }
  if(f==0)
    cout<<"pairwise coprime";
  else if(g==1)
    cout<<"setwise coprime";
  else
    cout<<"not coprime";


}


 int main()
 {
    fio;
    ll k = 1;
    ll tc = 1;
    sieve();
    // cin>>tc;
    while(tc--){
       // cout<<"Case #"<<k<<": ";k++;
        solve();
        endl;
    }
    
 }




Measured memory_bytes: 23716
//標準入力(n)
//let n:i64=read();
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn main() {
    let r:i64=read();
    let s =
        if r<1200{"ABC"} else if r<2800{"ARC"} else {"AGC"};
    println!("{}", &s);
}


Measured memory_bytes: 4352
def main():
    N = int(input())
    h = [int(i) for i in input().split()]
    c = [0]*N

    c[0]=0
    c[1]=abs(h[1]-h[0])
    for i in range(2,N):
        c[i] = min(abs(h[i]-h[i-1])+c[i-1],abs(h[i]-h[i-2])+c[i-2])

    print(c[N-1])

main()

Measured memory_bytes: 13976
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
string S;

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

  cin >> S;

  ll cnt = 0ll;
  ll ans = 0ll;
  rep(i, S.size()){
    char s = S[i];
    if (s=='B') cnt += 1ll;
    else ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <vector>

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

  std::vector<long> xs(n),ys(m);
  for(auto &&x:xs) std::cin>>x;
  for(auto &&y:ys) std::cin>>y;

  std::sort(xs.begin(),xs.end());
  std::sort(ys.begin(),ys.end());

  unsigned long sx = 0,sy=0;
  for(int i=0;i<n;++i){
    sx += i*xs[i]-(n-i-1)*xs[i];
  }
  for(int i=0;i<m;++i){
    sy += i*ys[i]-(m-i-1)*ys[i];
  }
  sx %= 1000000007;
  sy %= 1000000007;
  std::cout<<sx*sy%1000000007<<std::endl;
  return 0;
}

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

int main(){
  string S;
  cin>>S;
  int G=0,P=0,ans=0;
  for(int i=0;i<S.size();++i){
    if(S[i]=='g'){
      if(G>=P+1){
        ++ans;
        ++P;
      }
      else if(G==P)++G;
    }
    if(S[i]=='p'){
     if(G>=P+1) ++P;
     else if(G==P){
        --ans;
        ++G;
      }
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 512
a,b=map(int,input().split())
c=0
for i in range(a+1):
    if b-i<1:
        c+=1
        break
    elif b-i<=2*a:
        if b-i<a:
            c+=b-i+1
        else:
            c+=2*a+1-b+i
print(c)

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

char a[3][110],b[110],c[110];
int p[3];

main()
{
	
	scanf("%s %s %s",a[0],a[1],a[2]);
	int nw=0;
	while(1)
	{
		if(p[nw]==strlen(a[nw]))
		{
			printf("%c",'A'+nw);
			break;
		}
		p[nw]++;
		if(a[nw][p[nw]-1]=='a')
		{
			nw=0;
		}
		else if(a[nw][p[nw]-1]=='b')
		{
			nw=1;
		}
		else if(a[nw][p[nw]-1]=='c')
		{
			nw=2;
		}
		
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m, a, b, c, d;
  in2(n, m);
  a = 0;
  b = n;
  rep(i, m){
    in2(c, d);
    a = max(a, c);
    b = min(b, d);
  }
  if(b >= a)
    out(b - a + 1);
  else
    out(0);
  memi;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define itr ::iterator
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fne(i,a,b) for(ll i=a;i>=b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007
#define pi 3.14159265358979323846

int main()
{  
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   IOS;
   
   int T=1;
   //cin>>T;
   f(t,0,T)
    { 
      ll n=0,W=0,i=0,j=0,k=0,flag=0;
      cin>>n>>W;

      ll wt[n],cost[n];
      ll dp[n+1][W+1]={0};

       f(i,0,n+1)
       {
          f(j,0,W+1)
            { 
              dp[i][j] = 0;
            }
       }

      f(i,0,n)
       cin>>wt[i]>>cost[i];

      f(i,1,n+1)
       {
          f(j,0,W+1)
            {
              if(wt[i-1]>j)
                {
                  dp[i][j] = dp[i-1][j];
                }
              else 
                {
                  dp[i][j] = max((cost[i-1] + dp[i-1][j-wt[i-1]]),dp[i-1][j]);
                }
            }
       }

      cout<<dp[n][W]<<endl;
    }
  return 0;
}


Measured memory_bytes: 82368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N, M; cin >> N >> M;
  vector<int> P(M);
  vector<string> S(M);
  rep(i,M) cin >> P[i] >> S[i];
  rep(i,M) P[i]--;
  vector<bool> aced(N, false);
  vector<int> pen(N, 0);
  int acnum = 0;
  int allpen = 0;
  rep(i,M){
    int prob = P[i];
    cerr << prob << endl;
    if(S[i] == "AC"){
      if(aced[prob]){}
      else{
        aced[prob] = true;
        acnum++;
      }
    }
    else{

      if(aced[prob]){}
      else{
        pen[prob]++;
      }
    }
  }
  rep(i,N){
    if(aced[i]) allpen += pen[i];
  }
  cout << acnum << " " << allpen << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>

using namespace std;

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

	int max, min;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int temp; cin >> temp;
		if (i == 0)	{
			max = temp; min = temp;
		}
		if (max < temp)	max = temp;
		if (min > temp) min = temp;
		sum += temp;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){

    int n;
    cin >> n;
    vector<pair<int,int>> ad[n];
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        ad[a].emplace_back(make_pair(b,c));
        ad[b].emplace_back(make_pair(a,c));
    }
    bool visited[n];
    ll dis[n];
    rep(i,n){
        visited[i]=false;
        dis[i]=0;
    }
    int Q,K;
    cin >> Q >> K;
    K--;
    
    queue<int> q;
    q.push(K);
    visited[K]=true;
    while(!q.empty()){
        int t=q.front();
        q.pop();
        auto vec=ad[t];
        for(auto &e:vec){
            ll node=e.first;
            ll d=e.second;
            if(!visited[node]) {
                dis[node]=dis[t]+d;
                visited[node]=true;
                q.push(node);
            }
        }
    }

    int xi[Q];
    int yi[Q];
    rep(i,Q){
        cin >> xi[i] >> yi[i];
    }

    /*
    rep(i,n){
        cout << dis[i] << endl;
    }
    */

    rep(i,Q){
        int x,y;
        x=xi[i];
        y=yi[i];
        x--;
        y--;
        cout << dis[x]+dis[y] << endl;
    }

}

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


Measured memory_bytes: 9700
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int N, K; cin >> N >> K;
    vector<int> L(N); REP(i, N) cin >> L[i];
    sort(L.rbegin(), L.rend());
    cout << accumulate(L.begin(), L.begin() + K, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    r, g, b = map(int, readline().split())
    N = r * 100 + g * 10 + b
    if N % 4 == 0:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
   ll n,i,s=0;
   cin>>n;
   ll ara[n+1];
   for(i=1;i<=n;i++)cin>>ara[i];
   s=ara[1];
   for(i=2;i<=n;i++)
   {
       s=s^ara[i];
   }
   for(i=1;i<=n;i++)
   {
       printf("%lld ",s^ara[i]);
   }
   cout<<endl;
}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int N;
vector<int> edges[100000];

int dfs(int i, int p){
    vector<int> values;
    for(int j : edges[i]) if(j != p) values.push_back(dfs(j, i));

    int myvalue = -1;
    for(int k=0; k<30; k++){
        int num = 0;
        for(int n : values) if(nth_bit(n, k)) num++;
        if(num >= 2){
            myvalue = -1;
        }else if(num == 0 && myvalue == -1){
            myvalue = 1<<k;
        }
    }
    int ret = myvalue;
    for(int n : values) ret |= n;
    ret = ret / myvalue * myvalue;
    return ret;
}

int main(){
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    int ret = dfs(0, -1);
    for(int k=29; k>=0; k--) if(nth_bit(ret, k)){
        cout << k << endl;
        return 0;
    }
}

Measured memory_bytes: 12544
class Sieve:
    """区間[2,n]の値を素因数分解する"""

    def __init__(self, n=1):
        primes = []
        f = [0] * (n + 1)
        f[0] = f[1] = -1
        for i in range(2, n + 1):  # 素数を探す
            if f[i]: continue
            primes.append(i)
            f[i] = i  # 素数には自身を代入
            for j in range(i * i, n + 1, i):  # 合成数に素因数を書き込む
                if not f[j]:
                    f[j] = i  # 最小の素因数を代入
        self.primes = primes
        self.f = f

    def is_prime(self, x) -> bool:  # 素数判定
        return self.f[x] == x

    def factor_list(self, x) -> list:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        fl = self.factor_list(x)
        if not fl: return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res


n = int(input())
s = Sieve(n)

ret = 0
for x in range(1, n + 1, 2):
    t = 1
    for prime, cnt in s.factor(x):
        t *= cnt + 1

    if t == 8:
        ret += 1

print(ret)


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

struct Data {
  int v,f;
  bool operator < ( const Data &d ) const {
    return f > d.f;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec[i];
  map<int,int> mp[2];
  rep(i,n) mp[i&1][vec[i]]++;
  vector<Data> a[2];
  set<int> S[2];
  rep(i,n) {
    int type = i & 1;
    if( !S[type].count(vec[i]) ) {
      S[type].insert(vec[i]);
      a[type].push_back((Data){vec[i],mp[type][vec[i]]});
    }
  }
  rep(i,2) sort(ALL(a[i]));
  int m = n / 2;
  if( a[0][0].v != a[1][0].v ) {
    cout << ( m - a[0][0].f ) + ( m - a[1][0].f ) << endl;
  } else {
    int mini = ( m - a[0][0].f );
    if( a[1].size() >= 2 ) mini += ( m - a[1][1].f );
    else                   mini += m;
    int cost = ( m - a[1][0].f );
    if( a[0].size() >= 2 ) cost += ( m - a[0][1].f );
    else                   cost += m;
    mini = min(mini,cost);
    cout << mini << endl;
  }
  compute();
  return 0;
}


Measured memory_bytes: 10736
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll N;
  cin >> N;
  vector<P> BA(N);
  for(auto&& ba : BA){
    cin >> ba.second >> ba.first;
  }
  iikae jikokujikan = BA;
  sort(BA.begin(), BA.end());
  ll goukeijikan{}, maniau{1};
  rep(i, 0, N){
    iikae jikoku = BA.at(i).first;
    iikae jikan = BA.at(i).second;
    goukeijikan += jikan;
    //cout << goukeijikan << jikoku << rt;
    if(goukeijikan > jikoku){
      maniau = 0;
      break;
    }
  }
  if(maniau) cout << "Yes" << rt;
  else cout << "No" << rt;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vecctor<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W, K;
    cin >> H >> W >> K;
    VS s(H);
    rep(i, 0, H) cin >> s[i];

    ll ans = 1e18;
    VL ord(H, 0);
    for(int bit = 0; bit < (1<<(H-1)); bit++){
        ll cnt = 0;
        bool gok = true;
        for(int i = 0; i < H-1; i++){
            if(!(bit & (1<<i))){
                ord[i+1] = ord[i];
            }else{
                ord[i+1] = ord[i] + 1;
                cnt++;
            }
        }
        int add = 0;
        VL nums(cnt+1, 0);
        rep(w, 0, W){
            VL one(cnt+1, 0);
            bool ok = true;
            rep(h, 0, H){
                one[ord[h]] += s[h][w] - '0';
                nums[ord[h]] += s[h][w] - '0';
                if(one[ord[h]] > K) gok = false;
                if(nums[ord[h]] > K) ok = false;
            }
            if(!ok){
                add++;
                nums = one;
            }
        }
        if(gok) ans = min(ans, cnt + add);
    }

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

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#include <string>
#include <deque>
#include <map>
#include <algorithm>

using namespace std;


int gcd(int a,int b) {
    return  b == 0 ? a : gcd(b,a % b); 
}

void func() {
    int N;
    cin >> N;
    vector<int> arr = vector<int>(N, 0);

    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }
    int prefix[N];
    int suffix[N];
    for (int j = 0; j < N; ++j) {
        prefix[j] = j == 0 ? arr[0] : gcd(prefix[j - 1],arr[j]);
    }
    for (int k = N - 1; k >= 0; --k) {
        suffix[k] = k == N - 1 ? arr[N -1] : gcd(suffix[k + 1],arr[k]);
    }
    int ans = 0;
    for (int l = 0; l < N; ++l) {
        int g;
        if (l == 0){
            g = suffix[1];
        } else if (l == N - 1) {
            g = prefix[N - 2];
        } else {
            g = gcd(prefix[l - 1],suffix[l + 1]);
        }
        ans = max(ans,g);
    }
    cout << ans << endl;
}

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

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

int main() {
	int N;
	cin >> N;
	if (N % 10 == 9)cout << "Yes";
	else {
		N -= N % 10;
		if (N / 10 == 9)cout << "Yes";
		else cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){for(Scanner s=new Scanner(System.in);s.hasNext();){Map<Long,Long>m=new HashMap<Long,Long>();long i,r=1;for(;(i=s.nextInt())>0;)m.put(i,m.containsKey(i)?m.get(i)+1:1);s.next();for(long k:m.keySet())if((k<3&&m.get(k)%2<1)||(k>2&&m.get(k)%2>0))r=0;System.out.println(r>0?"OK":"NG");}}}

Measured memory_bytes: 12000
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<ll> A(M);
    rep(i,M) cin >> A[i];

    ll S= accumulate(all(A),0LL);
    if (S > N) {
        cout << -1 << ln;
        return 0;
    }
    cout << N - S << ln;
}

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back

const int N = 200005;

const int mod = 1000000007;
int fact[N], invfact[N];
inline int add(int x, int y) { x += y; return x % mod;}
inline int sub(int x, int y) { x -= y; x %= mod; x += mod; return x % mod;}
inline int mul(int x, int y) { return  (x * y) % mod;}
inline int powr(int a, int b) {
	int x = 1 % mod;
	b %= (mod - 1);
	while (b) {
		if (b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a) { return powr(a, mod - 2);}
void pre() {
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for (int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k) {
	if (n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int give(int x) {
	return mul(mul(x, x + 1), inv(2));
}

void solve() {
	int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
	cin >> n >> k;
	n++;
	for (i = k; i <= n; i++) {
		// ans = add(ans, C(n, i));
		cnt = (give(n - 1) - give(n - 1 - i)) - give(i - 1) + 1;
		// db(i, cnt);
		ans = add(ans, cnt);
	}
	ans += mod;
	cout << ans % mod;
	return ;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t; cin >> t; while (t--)
	pre();
	solve();
	return 0;
}

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

signed main(){
	int n;
	cin>>n;
	vector<int>v(n);
	r(i,n)v[i]=i+1;
	do{
		r(i,n){
			if(i)cout<<' ';
			cout<<v[i];
		}
		cout<<endl;
	}while(next_permutation(v.begin(),v.end()));
}


Measured memory_bytes: 3120
# coding: utf-8
N, X, Y = list(map(int, input().split()))
x=min([X,Y])
y=max([X,Y])
dists = [0] * (N-1)
 
for i in range(0,N-1):
  for j in range(i+1,N):
    dists[min([abs(j-i), abs(x-i-1)+1+abs(j+1-y)])-1] += 1

for s in dists:
  print(s)

Measured memory_bytes: 3444
use std::io;


fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut a = Vec::new();
    let mut b = Vec::new();

    for _ in 0..n {
        a.push(read_one::<String>().chars().collect::<Vec<char>>());
    }
    for _ in 0..m {
        b.push(read_one::<String>().chars().collect::<Vec<char>>());
    }

    let mut flg = false;
    // println!("a: {:?}", a);
    // println!("b: {:?}", b);
    for i in 0..(n - m + 1) { for j in 0..(n - m + 1) {
        let mut tmp = true;
        for l in 0..m { for m in 0..m {
            if a[l + i][m + j] != b[l][m] { tmp = false; }
        }}
        if tmp == true { flg = true; break; }
    }}
    if flg { println!("Yes"); }
    else { println!("No"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		TreeSet<Integer> tset=new TreeSet<>();
		tset.add(scn.nextInt());
		tset.add(scn.nextInt());
		tset.add(scn.nextInt());
		tset.add(scn.nextInt());
		tset.add(scn.nextInt());

		int k=scn.nextInt();
		int first=tset.first();
		if(tset.ceiling(first+k+1)!=null) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}
	}

}


Measured memory_bytes: 21588
import sys, math
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

class Combination:
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def factorization(n):
    if n == 1: print("n must be > 1")
    arr = []
    temp = n
    for i in range(2, int(round(n ** 0.5))+1):
        cnt = 0
        while temp % i == 0:
            cnt += 1
            temp //= i
        if cnt > 0: arr.append([i, cnt])
    if temp != 1: arr.append([temp, 1])
    if arr == []: arr.append([n, 1])
    return arr


def main():
    comb = Combination(10**6)
    N, M = map(int, input().split())
    if M == 1:
        print(1)
        return
        
    primes = factorization(M)
    ans = 1
    for _, num in primes:
        ans *= comb(num + (N - 1), num)
        ans %= mod
    print(ans)





if __name__ == "__main__":
    main()


Measured memory_bytes: 126280
import Control.Monad
import Data.Array.IArray

main :: IO ()
main = do
    [n,t] <- map read . words <$> getLine :: IO [Int]
    ts <- map read . words <$> getLine :: IO [Int]
    let ta = listArray (0,n-1) ts :: Array Int Int
    print . (+t) . sum . map (\i -> min ((ta!i) - (ta!(i-1))) t) $ [1..n-1]


Measured memory_bytes: 117116
#include <bits/stdc++.h>
//#include "rail.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%Id",&x)
#define SF2(x,y) scanf("%Id%Id",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()

using namespace std;
const long long INF = 1e16;
const long long MOD = 1e9+7;
const int MAX=200015;
vector<int> v1,v2;
ll a[1000005];
ll b[1000005];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int j=0;j<n;j++)cin>>b[j];
    for(int i=0;i<n;i++){
        if(a[i]>b[i])v1.pb(a[i]-b[i]);
        if(a[i]<b[i])v2.pb(b[i]-a[i]);
    }
    int p1=0,p2=0;
    int s=0;
    W(p1<v1.size()&&p2<v2.size()){
        int &j=v1[p1],&i=v2[p2];
        int x=min(j,i/2);
        j-=x;
        i-=x*2;
        if(i==1){i=0;}
        if(i==0&&j==0){p1++; p2++; continue;}
        if(i==0){p2++; continue;}
        if(j==0){p1++; continue;}

    }
    if(p1==v1.size())cout<<"Yes";
    else cout<<"No";
}


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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}

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

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;
int main(){
    string L;
    cin>>L;
    int N = (int)L.size();
    vector<vector<ll>> dp(N+5,vector<ll>(2));
    dp[0][0] = 2ll;
    dp[0][1] = 1ll;
    for(int i=1;i<N;++i){
        if(L[i] == '1'){
            dp[i][0] = dp[i-1][0] * 2ll; dp[i][0] %= mod;
            dp[i][1] = (dp[i-1][1] * 3ll)%mod + dp[i-1][0]; dp[i][1] %= mod;
        }else{
            dp[i][0] = dp[i-1][0]; dp[i][0] %= mod;
            dp[i][1] = dp[i-1][1] * 3ll; dp[i][1] %= mod;
        }
    }
    cout << (dp[N-1][0] + dp[N-1][1])%mod << endl;
    return 0;
}



Measured memory_bytes: 5760
n = int(input())
a = list(map(int, input().split()))

balls = [0] * n

def get_b(num):
    cnt=0
    now=num
    while True:
        cnt+=balls[now-1]
        now+=num
        if now > n:
            break
    return cnt

for i in range(n,0,-1):
    now_cnt=get_b(i)
    if now_cnt%2 != a[i-1]:
        balls[i-1]=1

print(sum(balls))

for i in range(n):
    if balls[i] != 0:
        print(i+1,end=" ")

Measured memory_bytes: 68188
n, m = gets.chomp.split(" ").map(&:to_i)
arr = []
n.times do |i|
    a = gets.chomp.split(" ").map(&:to_i)
    arr << a
end

arr = arr.sort
i = 0
count = 0
me = 0
# p arr
while true
    a, b = arr.shift
    # p a
    # p b
    me = i + b
    if me < m
        i += b
        count += a * b
    else
        sa = m - i
        count += a * sa
        puts count
        break
    end
    # p i
    # p count
end



Measured memory_bytes: 22560
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll N;
ll A[200000];
ll B[200000];
ll ans = 1LL;

int main()
{
  cin>>N;
  rep(i,N){
    cin>>A[i];
    A[i]--;
    B[A[i]]=i;
  }
  ll cnt = 1LL;
  rep(i,N-1){
    if(B[i]<B[i+1]) cnt++;
    else{
      cnt=1LL;
    }
    ans=max(cnt,ans);
  }
  cout<<N-ans<<endl;
}


Measured memory_bytes: 3328
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    n = int(input())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    d1 = [0]*n
    d2 = [0]*n
    d3 = [0]*n
    for i in range(n):
        x, y, z = map(int, input().split())
        if not i:
            d1[i] = x
            d2[i] = y
            d3[i] = z
            continue

        d1[i] = max(d2[i-1], d3[i-1]) + x
        d2[i] = max(d1[i-1], d3[i-1]) + y
        d3[i] = max(d1[i-1], d2[i-1]) + z

    print(max(d1[-1], d2[-1], d3[-1]))

Measured memory_bytes: 83668
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

#define INF (1e9)

vvvi G;
vector<bool> visited;
vi ans;

void dfs(int v) {
    visited[v] = true;
    for (auto nv : G[v]) {
        if (visited[nv[0]]) continue;
        if (nv[1] == 0) {
            ans[nv[0]] = ans[v];
        } else {
            ans[nv[0]] = 1 - ans[v];
        }
        dfs(nv[0]);
    }
}

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

    int N;
    cin >> N;

    G = vvvi(N, vvi(0));
    visited = vector<bool>(N);

    int u, v, w;

    for (int i = 0; i < N - 1; i++) {
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(vi{v, w % 2});
        G[v].push_back(vi{u, w % 2});
    }

    ans = vi(N);
    dfs(0);

    for (int a : ans) cout << a << endl;
    return 0;
}


Measured memory_bytes: 18432
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <unordered_map>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <limits.h>
#include <tgmath.h>

using namespace std;

typedef uint16_t ui16;
typedef uint32_t ui32;
typedef uint64_t ui64;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef long double ld;
typedef pair<int, int> pr;

//template<typename T> inline T abs(T a) { return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a) { return a * a; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) {for (int i = 0; i < v.size(); ++i) cout << v[i] << " "; cout << endl; return cout; }
void print() { cout << endl; }
template<typename T, typename... Ts> void print(T x, Ts... xs) { cout << x << " "; print(xs...); };
template<typename T> void read(vector<T>& v) { for (int i = 0; i < v.size(); ++i) cin >> v[i]; };


int main() {
    int N, W;
    cin >> N >> W;
    vector<long long> v(N + 1, 0);
    vector<long long> w(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        cin >> w[i] >> v[i];
    }

    long long dp[N + 1][W + 1];
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (i == 0 || j == 0) {
                dp[i][j] = 0;
                continue;
            }

            dp[i][j] = dp[i - 1][j];
            if (w[i] <= j) {
                dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
            }
        }

    }

    cout << dp[N][W];

    return 0;
}









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

bool harshad(int n) {
    int x = n;
    int s = 0;
    while (x > 0) {
        s += x % 10;
        x /= 10;
    }
    return (n % s == 0);
}

int main() {
    int n;
    cin >> n;
    if (harshad(n)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {

  int N;
  cin >> N;
  
  int x = 1000000000;
  int A, c;
  
  for (int i = 0; i < N; i++) {
    
    cin >> A;
    
    c = 0;
    
    while (A % 2 == 0) {
      c++;
      A /= 2;
    }
    
    if (c < x)
      x = c;        
  }
    
  cout << x << endl;
    
}


Measured memory_bytes: 256
def clas(kg)
  if kg <= 48
    puts "light fly"
  elsif kg <= 51
    puts "fly"
  elsif kg <= 54
    puts "bantam"
  elsif kg <= 57
    puts "feather"
  elsif kg <= 60
    puts "light"
  elsif kg <= 64
    puts "light welter"
  elsif kg <= 69
    puts "welter"
  elsif kg <= 75
    puts "light middle"
  elsif kg <= 81
    puts "middle"
  elsif kg <= 91
    puts "light heavy"
  else
    puts "heavy"
  end
end
while kg = gets
  clas(kg.to_f)
end

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
#define dg(x) cerr << #x << " = " << x <<endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fore(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,m;
vector<int> G[10];
int main(){
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
    #define endl '\n'
#endif
    cin>>n>>m;
    forn(i,m){
        int u,v;
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
    string path="";
    fore(i,2,n)path+='0'+i;
    ll cnt=0;
    do{
        bool ok=1;
        int last=1;
        forn(i,n-1){
            if(find(all(G[path[i]-'0']),last)==G[path[i]-'0'].end()){
                ok=0;
                break;
            }
            last=path[i]-'0';

        }
        if(ok)cnt++;
    }while(next_permutation(all(path)));
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793



int main(){
  ll N, M, V, P; cin >> N >> M >> V >> P; ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  sort(a, a+N); ll ok=1e18, ng=-1;
  while(abs(ok-ng)>1){
    ll mid = (ok+ng)/2; ll tmp=0;
    tmp+=(P-1)*M; ll lasti=-1;
    rep(i, N){
      if(a[i]<=mid && i<=N-P){
        tmp+=min(M, mid-a[i]); lasti=i;
      }
    }
    if(lasti<N-P){
      ng = mid; continue;
    }
    if(tmp<(V*M)){
      ng = mid; continue;
    }
    ok = mid; continue;
  }
  rep(i, N){
    if(a[i]>=ok-M){
      cout << N-i << endl; return 0;
    }
  }
}

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

#define int long long
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
//const int MOD = 10000;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
int gcd(int x,int y){if(y==0) return x; return gcd(y, x%y);}
int lcm(int x,int y){return x/gcd(x,y)*y;}

long double a, b, x;

long double f1(long double theta){
    theta *= M_PI/180;
    return x-b*b*tan(M_PI/2 - theta)/2.0;
}

long double f2(long double theta){
    theta *= M_PI/180;
    return a*a*tan(theta)/2-(a*b-x);
}

signed main() {
    cin >> a >> b >> x;
    x /= a;
  
    auto f = (x < a*b/2) ? f1 : f2;
  
    long double l = 0, r = 90;
    while(r - l > 1e-9){
        long double c = (l+r)/2;
        (f(c) > 0 ? r : l) = c;
    }
    
    printf("%.10Lf\n", l);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  int sumA = 0;
  vector<int> A(N, 0);
  REP(i, N){
    cin >> A[i];
    sumA += A[i];
  }
  int cnt = 0;
  REP(i, N){
    if(A[i] * 4 * M >= sumA) cnt++;
  }
  if(cnt >= M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    map<long long int, int> mp;
    for(int n=0; n<N; n++) {
        long long int A;
        cin >> A;
        mp[A]++;
    }
    long long int ans=0;
    long long int tmp=0;
    for(auto itr=mp.rbegin(); itr!=mp.rend(); itr++) {
        if(itr->second>=4) {
            if(tmp==0) {
                ans = itr->first*itr->first;
                break;
            } else {
                ans = tmp*itr->first;
              	break;
            }
        } else if(itr->second>=2) {
            if(tmp==0) {
                tmp = itr->first;
            } else {
                ans = tmp*itr->first;
                break;
            }
        }
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
long long int m1k=0,m5k=0,m10k=0;
double a[100002][2]= {0};

int main()
{
    int n,m,Maxa=0;
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {
        cin>>a[i][0]>>a[i][1];
        if(a[Maxa][0]<a[i][0])
            Maxa=i;
    }
    priority_queue<int> s;
    for(int i=0; i<n; i++)
    {
        if(a[Maxa][0]<a[i][1])
            s.push(a[i][1]);
    }
    int num=0;
    while(m)
    {
        if(s.empty()==0)
        {
            m-=s.top();
            s.pop();
            num++;
            if(m<=0)
                m=0;
        }
        else
        {
            num+=ceil(m/a[Maxa][0]);
            m=0;
        }
    }
    cout<<num;
}

Measured memory_bytes: 2428
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
using namespace std;
template <typename lx> inline void read(lx &x){
	x = 0;int f = 1;char c = getchar();
	for(;c < '0' || '9' < c; c = getchar()) if(c == '-') f = -1;
	for(;'0' <= c && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;return;
}
template <typename lx> inline void print(lx x){
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + 48);
	return;
}
#define rg register
#define ll long long
#define r_2(a,b) read(a),read(b)
#define r_3(a,b,c) read(a),read(b),read(c)
#define print_n(a) print(a),puts("")
#define print_(a) print(a),putchar(' ')
const int inf = 2147483647;
const ll lit = 1e9;
ll s,k,a,b;
int main()
{
	read(s);
	k = sqrt(s);
	if(k * k != s) k++;
	ll w = k * k - s;
	if(w != 0)
	{
		ll q = sqrt(w);
		for(;q >= 1; q--){
			if(w % q == 0){
				a = q;
				b = w / q;
				break;
			}
		}
	}
	printf("0 0 %lld %lld %lld %lld",k,a,b,k);
	return 0;
}

Measured memory_bytes: 256