akhauriyash/Code-Regression huggingface dataset:
import sys
S=input()
T=input()
s=[]
t=[]
for i in S:
    s.append(i)
for i in T:
    t.append(i)
count=0
for i in range(len(s)):
    s_last=s[-1]
    s.insert(0,s_last)
    del s[-1]
    #print(s)
    #print(t)
    for p in range(len(s)):
        if s[p]==t[p]:
            count+=1
    #print(count)
    if count==len(s):
        print("Yes")
        sys.exit()
    else:
        count=0
print("No")

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

int main()
{
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> xcities(N);
  vector<int> ycities(M);
  
  for(int i = 0; i < N; ++i)
  {
    cin >> xcities.at(i);
  }
  
  for(int i = 0; i < M; ++i)
  {
    cin >> ycities.at(i);
  }
  
  sort(xcities.begin(), xcities.end());
  sort(ycities.begin(), ycities.end());
  
  if(ycities.front() - xcities.back() >= 1)
  {
    for(int i = xcities.back() + 1; i <= ycities.front(); ++i)
    {
      if(i > X && i <= Y)
      {
        cout << "No War" << endl;
        return 0;
      }
    }
    cout << "War" << endl;
  }
  else
  {
    cout << "War" << endl;
  }
  
  return 0;
}    

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	int z = abs(abs(y) - abs(x));
	int ans;
	int a = -1 * (-1 * x + z);
	int b = -1 * x + z;
	int c = x + z;
	int d = -1 * (x + z);
	if (y == c)ans = z;
	else if (y == b)ans = z + 1;
	else if (y == d)ans = z + 1;
	else if (y == a)ans = z + 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m;
	cin>>n>>m;
	int x[101010],y[101010];
	vector<int> in(n+1,0);
	vector<int> ans(n+1,0);
	vector<vector<int>> g(n+1,vector<int>());
	FOR(i,0,m){
		cin>>x[i]>>y[i];
		g[x[i]].PB(y[i]);
		in[y[i]]++;
	}
	queue<int> q;
	FOR(i,1,n+1){
		if(in[i]==0)q.push(i);
	}
	while(q.size()){
		int x=q.front();
		q.pop();
		for(const auto& to:g[x]){
			in[to]--;
			if(in[to]==0)q.push(to);
			ans[to]=max(ans[to],ans[x]+1);
		}
	}
	int mx=0;
	FOR(i,0,n+1){
		mx=max(mx,ans[i]);
	}
	cout<<mx<<endl;


    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;

ll solve(int now) {
	if (now == 0)return 1;
	if (now < 0)return 0;
	ll res = 0;
	res = solve(now - 1) + solve(now - 2) + solve(now - 3);
	return res;
}

int main() {
	while (cin >> n&&n) {
		cout << solve(n) / 3650 + 1 << endl;
	}
}

Measured memory_bytes: 3048
S = list(input())
N = len(S)
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        if S[i] == "0":
            S[i+1] = "1"
        else:
            S[i+1] = "0"
        count += 1
print(count)

Measured memory_bytes: 3956
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
n = gif

a = gi
c = 0
loop{
  break if a.select{|t|t % 2 == 0}.size != a.size
  a.map!{ |t|t/2}
  c += 1
}
puts c


Measured memory_bytes: 2428
#include<stdio.h>

#include<math.h>
int main()
{
    int a,b,c,k,i,j;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    if(k>a&&k<=a+b){
        printf("%d\n",a);
    }
    else if(k<=a){
        printf("%d\n",k);
    }

    else {
            j=a-(k-a-b);
        printf("%d\n",j);
    }


    return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <deque>
#include <vector>

using namespace std;

const int INF = 1e9;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  int rs, cs, rf, cf;
  cin >> rs >> cs >> rf >> cf;
  rs--, cs--, rf--, cf--;
  vector <vector <char>> arr(H, vector <char>(W));
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      cin >> arr[i][j];
  vector <vector <int>> d(H, vector <int>(W, INF));
  vector <vector <bool>> used(H, vector <bool>(W));
  d[rs][cs] = 0;
  deque <pair <int, int>> dq;
  dq.push_back({rs, cs});
  while (!dq.empty()) {
    int r = dq.front().first;
    int c = dq.front().second;
    dq.pop_front();
    if (used[r][c]) continue;
    used[r][c] = true;
    if (r && d[r][c] < d[r - 1][c] && arr[r - 1][c] == '.') {
      dq.push_front({r - 1, c});
      d[r - 1][c] = d[r][c];
    }
    if (c && d[r][c] < d[r][c - 1] && arr[r][c - 1] == '.') {
      dq.push_front({r, c - 1});
      d[r][c - 1] = d[r][c];
    }
    if (r + 1 < H && d[r][c] < d[r + 1][c] && arr[r + 1][c] == '.') {
      dq.push_front({r + 1, c});
      d[r + 1][c] = d[r][c];
    }
    if (c + 1 < W && d[r][c] < d[r][c + 1] && arr[r][c + 1] == '.') {
      dq.push_front({r, c + 1});
      d[r][c + 1] = d[r][c];
    }
    for (int pr = -2; pr <= 2; pr++)
      for (int pc = -2; pc <= 2; pc++) {
        if (pr == 0 && pc == 0) continue;
        if (r + pr < 0 || r + pr >= H || c + pc < 0 || c + pc >= W) continue;
        if (arr[r + pr][c + pc] == '#') continue;
        if (d[r][c] + 1 < d[r + pr][c + pc]) {
          dq.push_back({r + pr, c + pc});
          d[r + pr][c + pc] = d[r][c] + 1;
        }
      }
  }
  if  (d[rf][cf] == INF) cout << -1;
  else cout << d[rf][cf];
  return 0;
}


Measured memory_bytes: 8800
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var lVl = parseInt(input[0][0], 10);
    var lEl = parseInt(input[0][1], 10);
    var graph = [];
    for (var x of input){
        if (x.length ===  2) continue;
        x = x.map(e => parseInt(e, 10));
        if (graph[x[0]] == null) graph[x[0]] = [];
        graph[x[0]][x[1]] = x[2];
    }
    var INF = Number.MAX_SAFE_INTEGER / 2;
    var dp = [];
    for (var j = 0; j < lVl; j++){
        x = graph[j];
        dp.push([]);
        if (x == null) {
            dp[dp.length - 1] = Array(lVl).fill(INF, 0, lVl);
            dp[dp.length - 1][dp.length - 1] = 0;
            continue;
        }
        for (var i = 0; i < lVl; i++){
            if (i === dp.length - 1) dp[dp.length - 1].push(0);
            else if (x[i] == null) dp[dp.length - 1].push(INF);
            else dp[dp.length - 1].push(x[i]);
        }
    }
    for(var k = 0; k < lVl; k++){
        for(var i = 0; i < lVl; i++){
            for(var j = 0; j < lVl; j++) {
                if (dp[i][j] === INF && (dp[i][k] === INF || dp[k][j] === INF)) dp[i][j] = INF;
                else dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    var str;
    var flag = true;
    var v_ans = [];
    whole_loop:
    for (var j = 0; j < dp.length; j++){
        x = dp[j];
        for (var i = 0; i < x.length; i++){
            if (i === j && x[i] < 0){
                console.log("NEGATIVE CYCLE");
                flag = false;
                break whole_loop;
            } else if  (x[i] === INF){
                x[i] = "INF";
            }
        }
        str = x.join(" ");
        v_ans.push(str);
    }
    if (flag) {
        console.log(v_ans.join("\n"));
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 24244
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (ll i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
map<string,int> p;
int main()
{
    FastRead;
    int a,b;
    cin>>a>>b;
    cout<<6-(a+b)<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

const int INF = 100000000;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    bool f=false;
    int o;
    cin >> o;
    v[0]=o;
    int mx=o;
    int mn=o;
    
    for (int i=1;i < n;i++){
        cin >> v[i];
        mx=max(mx,v[i]);
        mn=min(mn,v[i]);
    }
    for (int j=0; j < n;j++){
        if (v[j]!=o){
            f =true;
            break;
        }
    }
    //printf("max=%d\n",mx);
    //printf("min is %d\n",mn);
    int ans;
    ans=INF;
    for (int w=mn; w < mx+1; w++){
        int pre=0;
        for (int e=0; e < n; e++){
            pre+=(v[e]-w)*(v[e]-w);
        }
        ans = min(ans,pre);
    }

    if (f){
        cout << ans << endl;
    }
    else cout << 0 << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
 
int table[14][14];
 
int main(){
    int a,b,c;
    while(~scanf("%d,%d,%d",&a,&b,&c)){
        a+=2;
        b+=2;
        switch(c){
            case 3:
                table[a-2][b]++;
                table[a+2][b]++;
                table[a][b-2]++;
                table[a][b+2]++;
            case 2:
                table[a+1][b+1]++;
                table[a-1][b-1]++;
                table[a+1][b-1]++;
                table[a-1][b+1]++;
            case 1:
                table[a][b+1]++;
                table[a][b-1]++;
                table[a-1][b]++;
                table[a+1][b]++;
                table[a][b]++;
        }
    }
    int max=0;
    int ans=0;
    for(int i=2;i<12;i++){
        for(int j=2;j<12;j++){
            if(table[i][j]>0)ans++;
            if(table[i][j]>max)max=table[i][j];
        }
    }
    printf("%d\n%d\n",100-ans,max);
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  int  a, b, c, d, X, Y;
  //  double  c;
  int  A[103]={};
  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
//char s[101][101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
  int min=1000;
  int len=0;
  int cnt=0;
  int num=0;
  double ans=1000;
  int max=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
//  cnt = strlen(t);
  //printf("%d\n",cnt);

  for(i=0;i<a;i++){
    scanf("%d", &A[i]);
    if(max<A[i]) max = A[i];
    cnt = cnt +A[i];
  }
  
//  if(flag==0)   printf("TLE\n");
    if(max < cnt - max)  printf("Yes\n");
    else  printf("No\n");
  
return 0;
}


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

const int N = 2e5;

int n,k;
int li[N+5];

priority_queue<int> max1,min1,max2,min2;
int ujk[N+5];

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
	}
	int tmp = -1;
	int kana = n;
	ujk[n] = n;
	for(int i=n-1;i>=1;i--){
		if(li[i] > li[i+1]){
			kana = i;
		}
		ujk[i] = kana;
	}
	int ans = 1;
	for(int i=1;i<=k;i++){
		max1.push(li[i]);
		min1.push(-li[i]);
	}
	if(ujk[1] >= k) tmp++;
	for(int i=k+1;i<=n;i++){
		int ilang = li[i-k];
		if(!(ilang == -min1.top() && li[i] > max1.top())){
			ans++;
//			cout << i-k+1 << " SAMPAI " << ujk[i-k+1] << endl;
			if(ujk[i-k+1] - (i-k+1) + 1 >= k){
				tmp++;
////				cout << "NAMBAH tmp \n";
			}
		}
		max2.push(ilang);
		min2.push(-ilang);
		max1.push(li[i]);
		min1.push(-li[i]);
		while(!max2.empty() && max2.top() == max1.top()){
			max2.pop();
			max1.pop();
		}
		while(!min2.empty() && min2.top() == min1.top()){
			min2.pop();
			min1.pop();
		}
	}
	tmp = max(tmp,0);
	printf("%d\n",ans-tmp);
	return 0;
}

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

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

  if (N == 1) {
    cout << "Hello World" << endl;
  } else {
    ll A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<math.h>
#include<set>
#include<map>
#include<string.h>
#include<stack>
#define n 200000
#define loop(i, a, b) for(int i = a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
bool visit[n + 50];
int arr[n + 50], a, b, c, d, e;
string str1, str2;
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
	V[a].push_back(temp);
}


//////////////////////////////////////////


void solve()
{
	cin >> a;
	int temp[a];
	loop(i, 0, a - 1)
	{
		cin >> temp[i];
		arr[i] = temp[i];
	}
	sort(arr, arr + a);
	int mid = (a - 1) / 2;
	loop(i, 0, a - 1)
	{
		if(temp[i] <= arr[mid])
		{
			cout << arr[mid + 1] << '\n';
		}
		else if(temp[i] > arr[mid])
		{
			cout << arr[mid] << '\n';
		}
	}
}
int main()
{
	int times = 1;
//	cin << times;
	loop(i, 1, times)
	{
		solve();
		printf("\n");
	}
	return 0;
}




Measured memory_bytes: 8448
#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
typedef long long ll;


int main(){
    ll T,d,cnt=0;
    scanf("%lld %lld",&T,&d);
    ll maxd = d*d;
    while(T--){
        ll a,b;
        scanf("%lld %lld",&a,&b);
        //cout<<"a= "<<a<<" "<<"b= "<<b<<" "<<"maxd= "<<maxd<<"    distance=  "<<a*a+b*b<<endl;
        if((a*a+b*b) <= maxd){
            cnt++;
           // cout<<"   "<<true<<endl;
        }
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3684
n = int(input())
strList = [input() for i in range(n)]

dict = {} 
for i in range(n):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  
 
count = 0;
for v in dict.values():
  count += (v * (v-1) // 2)
print(count)

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

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

using namespace std;

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

  int a = 0, b = 0, c = 0;
  bool ok = false;
  rep(i, 2001) {
    rep(j, 2001) {
      if (i + j > n) {
        continue;
      }
      if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
        ok = true;
        a = i;
        b = j;
        c = n - i - j;
      }
    }
  }

  if (ok) {
    std::cout << a << " " << b << " " << c << std::endl;
  } else {
    std::cout << -1 << " " << -1 << " " << -1 << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int log4(ll p, ll q, bool f = true){
  int counter = 0;
  int cc = !!(p % q) * 2;
  ll v = p / q;
  while(v >= 4){
    if(v % 4) cc++;
    v /= 4;
    counter++;
  }
  if(v > 1) cc++; 
  debug(p); debug(q); debug(cc);
  return counter + (cc >= 1) * f;
}

ll pow2(int x) {
  ll res = 1;
  for(int i=0;i<x;i++) res *= 2;
  return res;
}

int main(){
  int n;
  ll a[SIZE], dp1[SIZE], dp2[SIZE];

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%lld", a+i);
  }

  ll calc1 = 0, calc2 = 0;

  stack<pair<ll,int> > st, st2;
  st.push({LLINF, 0});
  st2.push({LLINF, n-1});

  dp1[0] = 1;
  ll prev = a[0];
  for(int i=1;i<n;i++){
    ll now = a[i];

    if(prev < now){
      ll r = log4(now, prev) * 2;
      debug(r);
      prev *= pow2(r);
      while(r){
        auto p = st.top(); st.pop();
        ll r2 = min(p.first, r);
        r -= r2;
        p.first -= r2;
        calc1 += (ll)r2 * (i - p.second);
        if(p.first > 0) st.push(p);
      }
    }

    ll e = log4(prev, now, false) * 2;
    
    if(e){
      st.push({e, i});
    }

    dp1[i] = calc1 + i + 1;
    debug(dp1[i]);
    prev = now;
  }


  dp2[n] = dp2[n-1] = 0;
  prev = a[n-1];
  for(int i=n-2;i>=0;i--){
    ll now = a[i];

    if(prev < now){
      ll r = log4(now, prev) * 2;
      prev *= pow2(r);
      while(r){
        auto p = st2.top(); st2.pop();
        ll r2 = min(p.first, r);
        r -= r2;
        p.first -= r2;
        calc2 += (ll)r2 * (p.second - i);
        if(p.first > 0) st2.push(p);
      }
    }

    ll e = log4(prev, now, false) * 2;
    
    if(e){
      st2.push({e, i});
    }

    dp2[i] = calc2;
    prev = now;
  }


  ll ans = dp2[0];
  debug(dp2[0]);
  
  for(int i=0;i<n;i++){
    ans = min(ans, dp1[i] + dp2[i+1]);
    //cerr << dp1[i] << " + " << dp2[i+1] << endl;
  }

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


Measured memory_bytes: 4992
#include<iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(0<=x-r&&W>=x+r&&0<=y-r&&H>=y+r){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    string n;
    cin >> n;
    int x = stoi(n);
    int a = x/1000;
    int b = x/100-a*10;
    int c = x/10-a*100-b*10;
    int d = x-a*1000-b*100-c*10;
    if(a+b+c+d == 7){cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;}
    else if(a-b+c+d == 7){cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;}
    else if(a-b-c+d == 7){cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;}
    else if(a-b-c-d == 7){cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;}
    else if(a+b+c-d == 7){cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;}
    else if(a+b-c-d == 7){cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;}
    else if(a+b-c+d == 7){cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;}
    else if(a-b+c-d == 7){cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;}
    return 0;
}

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

int main(void)
{
	int n,a=0,b=0,ab=0,o=0;
	char t[3];
	while(scanf("%d,%s",&n,t) != EOF){
		if(strcmp(t,"A")==0){
			a++;
		}
		if(strcmp(t,"B")==0){
			b++;
		}
		if(strcmp(t,"AB")==0){
			ab++;
		}
		if(strcmp(t,"O")==0){
			o++;
		}
	}
	printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
		
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <string>


int main() {

    std::string s; std::cin >> s;

    if (s.substr(0, 1) != "A") {
        std::cout << "WA" << std::endl;
        return 0;
    }
    
    long long length = s.length() - 3;
    std::string slicedS = s.substr(2, length);
    long long cCounter = 0;
    for (long long i = 0; i < slicedS.length(); i++) {
        if (slicedS.substr(i, 1) == "C") {
            cCounter++;
            s.erase(s.begin() + i + 2);
            if (cCounter > 2) {
                std::cout << "WA" << std::endl;
                return 0;
            }
        }
    }
    
    if (cCounter != 1) {
        std::cout << "WA" << std::endl;
        return 0;
    }
    
    s.erase(s.begin());
    std::string sCopy = s;
    std::transform(s.begin(), s.end(), s.begin(), tolower);
    if (s != sCopy) {
        std::cout << "WA" << std::endl;
        return 0;
    }
    std::cout << "AC" << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
            Scanner sc = new Scanner(System.in);
            System.out.println(gcd(sc.nextInt(), sc.nextInt()));
            sc.close();
    }
    public static int gcd(int a, int b) {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}


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

int main(){
	int res[100],rankt[100],i,rank = 0,point,a,b;
	for(i = 0;i <100;i++) {
		res[i] = 0;
		rankt[i] = 0;
	}
	while(1){
		scanf("%d,%d",&a,&b);
		if(!a && !b) break;
		res[a] = b * 1000 + a;
	}
	sort(res,res + 100,greater<int>());
	point = res[0] / 1000;
	for(i = 0;i < 100;i++){
		if(!res[i]) break;
		if(res[i] / 1000 != point) {
			point = res[i] / 1000;
			rank++;
		}
		rankt[res[i] % 1000] = rank + 1;
	}
	while(scanf("%d",&i) != EOF) printf("%d\n",rankt[i]);
	return 0;
}

Measured memory_bytes: 1044
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
	public static void main(String[] args) {
		
		FastReader sc = new FastReader();
		//Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int[] a = new int[n+1];
	    for(int i=0;i<=n;++i) a[i] = sc.nextInt();
	    int[] b = new int[n];
	    for(int i=0;i<n;++i) b[i] = sc.nextInt();
	    long ans = 0;
	    for(int i=0;i<n;++i) {
	    	int temp = Math.min(a[i], b[i]);
	    	b[i]-=temp;
	    	ans+=temp;
	    	temp = Math.min(a[i+1], b[i]);
	        a[i+1]-=temp;
	    	ans+=temp;
	    }
	    out.print(ans);
		out.close();
		}
	
	
	
}
	

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

#define ll long long
#define endl '\n'

// void max_self(ll &a, ll b){a = max(a, b);}
// void min_self(ll &a, ll b){a = min(a, b);}

void solve(){
	int n, m; cin>>n>>m;
	if(m >= n){
		cout<<"unsafe"<<endl;
	}else{
		cout<<"safe"<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1; //cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A+B > C+D) puts("Left");
    if (A+B < C+D) puts("Right");
    if (A+B == C+D) puts("Balanced");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
    int A, B;
    std::cin >> A >> B;

    int coin = 0;

    for(int i = 0; i < 2; ++i)
    {
        if(A >= B)
        {
            coin += A--;
        }

        else
        {
            coin += B--;
        }
    }

    std::cout << coin << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;

int N, K, L;

class UnionFind{
 public:
    int parent[200000];
    UnionFind(){
        for(int i = 0; i < N; i++){
            parent[i] = i;
        }
    }

    int root(int x){
        if(parent[x] == x){
            return x;
        }
        return parent[x] = root(parent[x]);
    }
    bool is_same_set(int x, int y){
        return root(x) == root(y);
    }
    void unite(int x, int y){
        parent[root(x)] = root(y);
    }
};


int main(){
    cin >> N >> K >> L;
    UnionFind road = UnionFind(), rail = UnionFind();
    for(int i = 0; i < K; i++){
        int x, y;
        cin >> x >> y;
        road.unite(x-1, y-1);
    }
    for(int i = 0; i < L; i++){
        int x, y;
        cin >> x >> y;
        rail.unite(x-1, y-1);
    }
    for(int i = 0; i < N; i++){
        road.root(i);
        rail.root(i);
    }
    map<pair<int, int>, int > m;
    for(int i = 0; i < N; i++){
        m[make_pair(road.root(i), rail.root(i))]++;
    }
    for(int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << m[make_pair(road.root(i), rail.root(i))];
    }
    cout << endl;
    

}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string foo; cin >> foo;
    for (int i = 0; i < 3; ++i) {
        if (foo[i] == foo[i+1]) {
            cout << "Bad\n";
            return 0;
        }
    }
    cout << "Good\n";
    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

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

	int n, m;
	cin >> n >> m;

	vector<ll> x(n), y(n), z(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	ll ans = -INF64;
	for (int i = 0; i < 8; i++) {
		vector<ll> scores;
		for (int j = 0; j < n; j++) {
			ll score = i & (1 << 2) ? x[j] : -x[j];
			score += i & (1 << 1) ? y[j] : -y[j];
			score += i & (1 << 0) ? z[j] : -z[j];

			scores.emplace_back(score);
		}

		sort(begin(scores), end(scores), greater<ll>());

		ll ei1333 = 0;
		for (int i = 0; i < m; i++) {
			ei1333 += scores[i];
		}

		ans = max(ans, ei1333);
	}

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


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

using namespace std;

typedef long long ll;
 
int main(){
    ll n,a,b,l,r;
    cin>>n>>a>>b>>l>>r;
    int flag = 1;
    ll x,y;
    for(ll i = 0; i <= n-1;i++){
        x = a+l*i-(n-i-1)*r;
        y = a+r*i-(n-i-1)*l;
        if(x <= b && b <= y){
            flag = 0;
        }
    }
    if(flag)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import log10
def nsn(N):
    K = sum( list( map( int, list( str(N)))))
    return N/K

def snuke(N):
    k = int( log10(N))+1
    s = N
    now = nsn(N)
    for d in range(k+1):
        x = (10**(d+1))*(N//(10**(d+1)) + 1) - 1
        y = nsn(x)
        if y < now:
            s = x
            now = y
    return s

K = int( input())
ans = 1
print(1)
for i in range(K-1):
    ans = snuke( ans + 1)
    print(ans)



Measured memory_bytes: 3316
#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string>
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> >
#define vb vector<bool> 
#define vvb vector<vector<bool> >
#define INF 1145141919810
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b:i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
using namespace std;

int main(){
	string a,b,c; cin>>a>>b>>c;
	printf("%c%c%c",a[0]-'a'+'A',b[0]-'a'+'A',c[0]-'a'+'A');
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n,l;
	cin>>n>>l;
	vector<int> a(n);
	rep(i,n)a[i]=l+i;
	int s=0;
	rep(i,n)s+=a[i];
	int ans=1e9;
	rep(i,n){
		int t=s-a[i];
		if(abs(t-s)<abs(ans-s))ans=t;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10 ;

int main () {
    string s;
    cin >> s;
    if (s.size() % 2) return !puts("No");
    for (int i  = 0 ; i < (int)s.size() ; i += 2) {
        if (!(s[i] == 'h' && s[i + 1] == 'i')) return !puts("No");
    }
    puts("Yes");
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
n, k = gets.strip.split.map(&:to_i)
s = gets.strip.split('')

rl = []
count = 0
c = s.first
s.each do |cc|
  if c==cc
    count+=1
  else
    rl << count
    count=1
    c=cc
  end
end
rl << count

if rl.length < k*2+1
  p rl.inject(:+)-1
  exit
end

p rl.map {|e|e-1}.inject(:+) + k*2



Measured memory_bytes: 8572
down_positions = []
ponds = []
for index, value in enumerate(raw_input()):
    if value == '\\':
        down_positions.append(index)
    elif value == '/' and down_positions:
        right = index
        left = down_positions.pop()
        area = right - left
        candidate_area = 0
        while ponds and left < ponds[-1][0]:
           candidate_area += ponds.pop(-1)[1]

        ponds.append((left, area + candidate_area))

print sum(x[1] for x in ponds)
print len(ponds), 
for pond in ponds:
    print pond[1], 

Measured memory_bytes: 6940
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream> 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;

#define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b))
using ll = long long;
const int INF = 1e9;

const int N = 3000;
double dp[N+1][2*N + 10];
int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<double> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    const int EQ = 3000;
    dp[0][EQ] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int balance = EQ-i; balance <= EQ+i; ++balance) {
            if (balance-1 >= EQ-(i-1)) {
                dp[i][balance] += dp[i-1][balance-1] * p[i-1];
            }
            if (balance+1 <= EQ+(i-1)) {
                dp[i][balance] += dp[i-1][balance+1] * (1-p[i-1]);
            }
        }
    }
    double res = 0;
    for (int balance = EQ+1; balance <= EQ+n; ++balance) {
        res += dp[n][balance];
    }
    cout.precision(12);
    cout << fixed;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 139264
#include <iostream>

using namespace std;

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

	int p = 0;

	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == '+')
		{
			p++;
		}
		else
		{
			p--;
		}
	}

	cout << p << endl;
}

Measured memory_bytes: 256
n = int(input())
al = []

for _ in range(n):
    s = input()
    if '.' not in s:
        a = int(s)*(10**9)
        al.append(a)
    else:
        syousu = s.split('.')[1]
        rem0 = 9 - len(syousu)
        a = int(s.replace('.',''))*(10**rem0)
        al.append(a)

ans = 0
two_five_cnts = {}
for i in range(19):
    for j in range(19):
        two_five_cnts[(i,j)] = 0

for a in al:
    num = a
    two = 0
    five = 0
    for i in range(18):
        if num%2 == 0:
            num = num//2
            two += 1
        else:
            break
    for i in range(18):
        if num%5 == 0:
            num = num//5
            five += 1
        else:
            break
    
    for i in range(18-two,19):
        for j in range(18-five,19):
            ans += two_five_cnts[(i,j)]
    two_five_cnts[(two,five)] += 1

print(ans)

Measured memory_bytes: 88416
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct NODE{
	int to,cost,x;
	NODE(int to,int cost,int x) : to(to) , cost(cost) , x(x) {}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}

int q[20][100];
int r[20][100];
int num[20];
int dist[20][20010];

int main(){
	int n,m,c,s,g;
	while(cin >> n >> m >> c >> s >> g && n){
		s--,g--;
		int wf[20][100][100] = {};
		for(int k = 0 ; k < 20 ; k++)
			for(int i = 0 ; i < 100 ; i++)
				for(int j = 0 ; j < 100 ; j++)
					wf[k][i][j] = i == j ? 0 : 1e9;
		for(int i = 0 ; i < m ; i++){
			int a,b,c,d;
			cin >> a >> b >> c >> d;
			a--,b--,d--;
			wf[d][a][b] = wf[d][b][a] = min(wf[d][a][b],c);
		}
		for(int i = 0 ; i < c ; i++){
			cin >> num[i];
		}
		for(int i = 0 ; i < c ; i++){
			for(int j = 0 ; j < num[i] - 1 ; j++) cin >> q[i][j];
			for(int j = 0 ; j < num[i] ; j++) cin >> r[i][j];
			q[i][num[i]-1] = 1e9;
		}
		for(int i = 0 ; i < c ; i++){
			int cost = 0 , cur = q[i][0] , idx = 0;
			for(int j = 0 ; j <= 20000 ; j++){
				dist[i][j] = cost;
				while( j >= q[i][idx] ) idx++;
				cost += r[i][idx];
			}
		}
		
		for(int p = 0 ; p < c ; p++){
			for(int i = 0 ; i < n ; i++)
				for(int j = 0 ; j < n ; j++)
					for(int k = 0 ; k < n ; k++)
						wf[p][j][k] = min(wf[p][j][k],wf[p][j][i]+wf[p][i][k]);
		}
		
		int wf2[100][100] = {};
		for(int i = 0 ; i < 100 ; i++)
			for(int j = 0 ; j < 100 ; j++)
				wf2[i][j] = i == j ? 0 : 1e9;
		
		for(int p = 0 ; p < c ; p++){
			for(int i = 0 ; i < n ; i++){
				for(int j = 0 ; j < n ; j++){
					if( wf[p][i][j] != 1e9 ) wf2[i][j] = min(wf2[i][j],dist[p][wf[p][i][j]]);
				}
			}
		}
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				for(int k = 0 ; k < n ; k++)
					wf2[j][k] = min(wf2[j][k],wf2[j][i]+wf2[i][k]);
		if( wf2[s][g] == 1e9){
			cout << -1 << endl;
		}else{
			cout << wf2[s][g] << endl;
		}
	}
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    deque<int> que;
    rep(i, n){
        int a;
        cin >> a;
        if(i % 2 == 0) que.push_back(a);
        else que.push_front(a);
    }

    if(n % 2 == 0) rep(i, n) cout << que[i] << " ";
    else rep(i, n) cout << que[n - i - 1] << " ";
    cout << endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
int main() {
	int n, d,x,i;
	cin >> n >> d;
	i = d * 2 + 1;
	x = n / i;
	if (n%i != 0) {
		x++;
	}
	cout << x << endl;
}

Measured memory_bytes: 764
import java.util.Scanner;
import java.util.Set;

public class Main {

	/** 七五三の数字のセット */
	private static final Set<Integer> SET = Set.of(3, 5, 7);

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int x = scanner.nextInt();
			System.out.println(SET.contains(x) ? "YES" : "NO");
		}
	}
}


Measured memory_bytes: 35780
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }

int N;
int A[2000];

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];

	int ans = 0;
	while (true)
	{
		bool f = false;
		REP(i, N)
		{
			if (A[i] % 2 != 0)
			{
				f = true;
			}
			A[i] /= 2;
		}
		if (f) break;
		ans++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 3568
#include <bits/stdc++.h>
//#include<iostream>
//#include<vector>
//#include<map>
//#include<math.h>
//#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

ll solve1(ll n, int p)
{
    if(n==0) { return 0; }
    return n/p + solve1(n/p, p);
}

ll solve2(ll n, int p)
{
    if(n%2==1) {
        return solve1(n, p) - solve2(n-1, p);
    }

    ll res = solve1(n/2, p);
    if(p==2) { res += n/p; }

    return res;
}

int main(void)
{
    ll n;
    cin >> n;
    
    ll ans = min(solve2(n, 2), solve2(n, 5)); 
    cout << ans << endl;

    return 0;
} /*atcoder*/



Measured memory_bytes: 3628
/*
	- 20.3.2
	A - Frog 1
	Atcoder-Educational DP Contest-A - Frog 1
	20.3.2-Atcoder-Educational DP Contest-A - Frog 1-
	- 
	-
	- 
*/
#include <bits/stdc++.h>
using namespace std;
int f[100010],h[100010];
int n;

int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		cin>>h[i];
		if (i>=3) f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
		else if (i==2) f[i]=f[i-1]+abs(h[i]-h[i-1]);
		else f[i]=0;
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
using System;

namespace _755
{
    class Program
    {
        static double N;
        static void Main(string[] args)
        {
            N = double.Parse(Console.ReadLine());
            Console.WriteLine(Dfs("0"));
        }

        public static int Dfs(string s)
        {
            if (double.Parse(s) > N) { return 0; }

            int result = 0;
            if (s.Contains("7") && s.Contains("5") && s.Contains("3")) { result++; }

            foreach (var item in "753")
            {
                result += Dfs(s + item);
            }
            return result;
        }
    }
}


Measured memory_bytes: 15312
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		float min = 1000000;
		float max = -1;
		for(; scanner.hasNext();)
		{
			float h = scanner.nextFloat();
			
			if(h > max)
			{
				max = h;
			}
			if(h < min)
			{
				min = h;
			}
		}
		System.out.println(String.format("%1$.1f", max-min));
	}
}

Measured memory_bytes: 28012
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    print(0)
    sys.stdout.flush()
    s = S()
    if s == "Vacant":
        return
    x = s
    ok = 0
    ng = n
    while 1:
        mid = (ok + ng) // 2
        print(mid)
        sys.stdout.flush()
        s = S()
        if s == "Vacant":
            return
        if mid & 1 == ok & 1:
            if s == x:
                ok = mid
            else:
                ng = mid
        else:
            if s == x:
                ng = mid
            else:
                ok = mid
                x = s

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39108
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum,ans=0;
	if (c == 1) {
		cout << gcd(a, b) << endl;
	}
	else {
		for (int i = min(a, b); i > 0; i--) {
			if (a%i == 0 && b%i == 0) {
				sum = i; ans++;
				if (ans == c) {
					cout << sum << endl; endre;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	while (b > 0) {
		if (b & 1) {res = (res * a); b--;}
		a = (a * a);
		b >>= 1;
	}
	return res;
}
ll n;
ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}


int main() {
	ll ww;
	cin>>n>>ww;
	vl v(n),w(n);
	for(ll i=0;i<n;i++)
		cin>>w[i]>>v[i];
	ll vmax=0;
	for(ll i=0;i<n;i++)
		vmax+=v[i];
	vector < vector <ll> > dp (n+1,vector <ll> (vmax+1,1000000000));
	// dp[i][j]=min weight with total value j upto i th element
	// 
	for(ll i=0;i<n;i++){
		for(ll j=0;j<=vmax;j++){
			if(j==0){
				dp[i][j]=0;
				continue;
			}
			if(i==0){
				dp[i][j]=v[i]>=j?w[i]:1000000000;
				continue;
			}
			if(v[i]<=j)
				dp[i][j]=min(dp[i-1][j],w[i]+dp[i-1][j-v[i]]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	ll ans=0;
	for(ll i=0;i<=vmax;i++){
		if(dp[n-1][i]<=ww)
			ans=i;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 83156
#include<bits/stdc++.h>
using namespace std;
int main()
{int n,k;
 cin>>n>>k;
 long long a[n];
 for(int i=0;i<n;i++)
   cin>>a[i];
 long long INF=10e9+5;
 vector<long long>dp(n,INF);
int i,j;
 dp[0]=0;
 for(i=0;i<n;i++)
 { 
     for(j=i+1;j<=i+k;j++)
 { 
   if(j<n)
 dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
 }
   
 }
 cout<<dp[n-1];
  
}


Measured memory_bytes: 4836