akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define F first
#define S second

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-8, INF=1e12;

typedef complex<double> P;
bool sameline(int a,int b,int c,int p,int q,int r){
	if(a*q!=b*p)return 0;
	if(a==0)return b*r==c*q;
	return a*r==c*p;
}
void push(vector<P> &v,const P &p){
	rep(i,v.size())if(abs(v[i]-p)<EPS)return;
	v.pb(p);
}
P crosspoint(const pair<pi,int> &a,const pair<pi,int> &b){
	int a1=a.F.F,b1=a.F.S,c1=a.S,a2=b.F.F,b2=b.F.S,c2=b.S;
	double x=(-b2*c1+b1*c2)*1.0/(a1*b2-a2*b1),y=(a2*c1-a1*c2)*1.0/(a1*b2-a2*b1);
	return P(x,y);
}

int n,a,b,c,d,e,f;
vector<pair<pi,int> > ls;
vector<P> cps[20],cp;
vector<P> pts;

vector<P> cpLC(const pair<pi,int> &l){
	int a1=a,b1=b,c1=c,d1=d,e1=e,f1=f,d2=l.F.F,e2=l.F.S,f2=l.S;
	if(e2==0){
		swap(a1,c1); swap(d1,e1); swap(d2,e2);
	}
	vector<P> res;
	int p=a1*e2*e2-b1*e2*d2+c1*d2*d2;
	int q=-b1*e2*f2+2*c1*d2*f2+d1*e2*e2-e1*e2*d2;
	int r=c1*f2*f2-e1*e2*f2+f1*e2*e2;
	if(p==0){
		double x=-r*1.0/q, y=(-f2-d2*x)/e2;
		res.pb(P(x,y));
	}
	else{
		ll D=(ll)q*q-4ll*p*r;
		if(D==0){
			double x=-q/2.0/p,y=(-f2-d2*x)/e2;
			res.pb(P(x,y));
		}
		else if(D>0){
			double x1=(-q+sqrt(q*1.0*q-4.0*p*r))/2/p,y1=(-f2-d2*x1)/e2;
			double x2=(-q-sqrt(q*1.0*q-4.0*p*r))/2/p,y2=(-f2-d2*x2)/e2;
			res.pb(P(x1,y1)); res.pb(P(x2,y2));
		}
	}
	return res;
}

int main(){
	cin>>n>>a>>b>>c>>d>>e>>f;
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		rep(j,ls.size())if(sameline(ls[j].F.F,ls[j].F.S,ls[j].S,a,b,c)){
			n--;
			goto NEXT;
		}
		ls.pb(mp(mp(a,b),c)); NEXT:;
	}
	rep(i,n)rep(j,i)if(ls[i].F.F*ls[j].F.S!=ls[i].F.S*ls[j].F.F){
		push(cps[i],crosspoint(ls[i],ls[j]));
		push(cps[j],crosspoint(ls[i],ls[j]));
	}
	rep(i,n){
		vector<P> tmp=cpLC(ls[i]);
		rep(j,tmp.size())push(cp,tmp[j]), push(cps[i],tmp[j]);
	}
	rep(i,n)rep(j,cps[i].size())push(pts,cps[i][j]);

	int ans=1-(int)pts.size();
	rep(i,n)ans+=cps[i].size()+1;
	if(b*b<4*a*c)ans+=max(1,(int)cp.size());
	else if(b*b==4*a*c)ans+=cp.size()+1;
	else ans+=cp.size()+2;
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

int main()
{
    //
    ll A, B;
    string S;
    cin >> A >> B;
    cin >> S;
    rep(i, 0, A)
    {
        char ch = S[i];
        if (!('0' <= ch && ch <= '9')) goto no;
    }
    if (S[A] != '-') goto no;
    rep(i, A + 1, A + B + 1)
    {
        char ch = S[i];
        if (!('0' <= ch && ch <= '9')) goto no;
    }
    cout << "Yes" << endl;
    return 0;
no:
    cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())

que = []
edges = {i:[] for i in range(1,N+1)}
visited = {i:False for i in range(1,N+1)}
ans = {i:None for i in range(1,N+1)}

while True:
  s = list(map(int,input().split()))
  if len(s) > 2: 
    break
  edges[s[0]].append(s[1])
  edges[s[1]].append(s[0])
s = sorted(s)
ans1 = sum(s[:-1])

que.append(1)

while que:
  temp = que.pop(0)
  if visited[temp]:
    continue
  visited[temp] = True
  ans[temp] = s.pop()
  que += edges[temp]

s = ""
for key in ans:
  if key>1:
    s+= " "
  s += str(ans[key])
print(ans1)
print(s)
    
   

Measured memory_bytes: 8328
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<a)
        cout<<k<<endl;
    else if(k>=a&&k<=a+b)
        cout<<a<<endl;
    else if(k>a+b)
    {
        int t=k-(a+b);
        cout<<a-t<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(){
	int s, a, b, c, d;
	scanf("%d", &s);
	
	a = s % 10;
	b = s / 10 % 10;
	c = s / 100 % 10;
	d = s / 1000;
	
	if(a == b || b == c || c == d){
		printf("Bad");
	}else{
		printf("Good");
	}
	return 0;
}

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

using namespace std;

using ll = long long;

template <class SemiGroup>
struct DisjointSparseTable {
    using T = typename SemiGroup::T;

    int n;
    vector< vector<T> > table;
    vector<int> msb_table;

    DisjointSparseTable() {}
    DisjointSparseTable(const vector<T>& v) {
        n = v.size();

        table.emplace_back(n);
        for (int i = 0; i < n; i++) {
            table[0][i] = v[i];
        }

        for (int i = 1; (1 << i) < n; i++) {
            table.emplace_back(n);
            int shift = (1 << i);
            for (int j = 0; j < n; j += (shift << 1)) {
                int m = min(j + shift, n);
                table[i][m - 1] = v[m - 1];
                for (int k = m - 2; k >= j; --k) table[i][k] = SemiGroup::merge(v[k], table[i][k + 1]);

                if (m >= n) break;

                int r = min(m + shift, n);
                table[i][m] = v[m];
                for (int k = m + 1; k < r; ++k) table[i][k] = SemiGroup::merge(table[i][k - 1], v[k]);
            }
        }
    }

    //区間[l, r)に対するクエリに答える
    T query(int l, int r) {
        assert(l < r && r <= n);

        if (l == --r) return table[0][l];
        int msb = 31 - __builtin_clz(l ^ r);
        return SemiGroup::merge(table[msb][l], table[msb][r]);
    }
};

//以下、SemiGroupの例
template <class U = ll>
struct RSQSG {
    using T = U;
    static T merge(T a, T b) { return a + b; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> cnt(n + 1, 0);
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            cnt[i + 2] = 1;
        }
    }

    DisjointSparseTable< RSQSG<int> > st(cnt);

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << st.query(l + 1, r + 1) << "\n";
    }
    return 0;
}


Measured memory_bytes: 8144
a = [input() for i in range(3)]
ave = int(a[1])/2
move = 0
#print(a)
for i in a[2].split():
    if float(i) <= ave:
        move += (2 * float(i))
    else:
        move += (2 * (float(a[1]) - (float(i))))
print(int(move))
    

Measured memory_bytes: 2940
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    n =int(input())
    a = [int(i) for i in input().split()]

    ans = (sum(a))

    m =int(input())

    for i in range(m):
        b, c = map(int, input().split())
        print(ans -a[b-1] +c )


Measured memory_bytes: 5144
#include <iostream>
#include <string>
#include <sstream>
#include <map>
using namespace std;
int main(){
        map <char,int> table;
        string number="0123456789";
        for(int i=0 ; i<10 ; i++ )
                table[number[i]]=i;
        string str;
        cin >> str;
        string ans="";
        int count,max=0;
        bool sign=true;
        for(int i=str.size()-1 ; i>=0 ; i--){
                map <char,int> mp;
                for(int l=0 ; l<str.size() ; l++ ){
                        mp[str[l]]++;
                }count=0;
                for(int l=0 ; l<number.size() ; l++ ){
                        count+=(mp[number[l]]*l);
                }
                if(max<count)max=count;
                if(i==0)continue;
                str[i-1]=number[table[str[i-1]]-1];
                str[i]='9';
        }
        cout << max << endl;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
    int n;
    int a[100];
    int sum = 0;
    cin >> n;

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

    double ave = (double)sum / n;
    double min = 10000000;
    int idx;

    // cout << ave << endl;

    for(int i = 0; i < n; i++){
        if(abs(ave-a[i]) < min){
            idx = i;
            min = abs(ave-a[i]);
        }
        // cout << min << endl;
    }

    cout << idx << endl;

    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	int l = s.size();

	if (l <= k) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "..." << endl;
	}
	return 0;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 
  string S;
  ll K,index=0;
  cin >> S >> K;
  
  for(int i=0;i<S.size();i++){
      if(S[i] =='1')index++;
      else break;
  }
  
  if(K <= index) cout << 1 << endl;
  else cout << S[index] << endl;
  
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			long H = Integer.parseInt(sc.next());
			long W = Integer.parseInt(sc.next());
			if(H==1||W==1) {
				System.out.println(1);
			}else {				
				System.out.println((H*W+1)/2);
			}
		}	
	}
}

Measured memory_bytes: 35644
#include<iostream>
#include<cinttypes>
#include<vector>

using ull = unsigned long long;
using ui = std::uint16_t;


struct pos {
	ui left, right;
	friend auto& operator>>(std::istream&is, pos&p) {
		return is >> p.left >> p.right;
	}
};

int main() {


	std::vector<std::vector<ull>> LR{};
	std::vector<std::vector<ull>> tab{};
//	std::vector<pos> pv;
//	pv.resize(505);

	LR.resize(505);
	tab.resize(505);

	for (auto&e : LR)
		e.resize(505);

	for (auto&e : tab)
		e.resize(505);

	ull n, m, q;

	std::cin >> n >> m >> q;

	for (ull i{1}; i <= m; ++i) {
		pos p;
		std::cin >> p;
//		std::cout << "\t>>" << p.left << ", " << p.right << "\n";
		++LR[p.left][p.right];
	}

	for (ull i{ 1 }; i < 505; ++i)
		for (ull j{ 1 }; j < 505; ++j)
			tab[i][j] = tab[i][j - 1] + LR[i][j];

/*
	for (int i{1}; i <= n; ++i) {
		for (int j{}; j <= n; ++j)
			std::cout << LR[i][j] << " ";
		std::cout << " | ";

		for (int j{1}; j <= n; ++j)
			std::cout << tab[i][j] << " ";

		std::cout << "\n";
	} 
*/

	for (ull i{1}; i <= q; ++i) {
		ull pi, qi;
		std::cin >> pi >> qi;
		
		ull c{};
		for (ull j{ pi }; j <= qi; ++j) {
			auto here = tab[j][qi]
				, pre = tab[j][pi - 1];
			
			c += here - pre;

//			std::cout << i << ", " << j << " here-pre "
//				<< here << ", " << pre << "\n";
		}
		std::cout << c << "\n";

	}


	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato is cute
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.


int main(){
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[0]<<c[0]<<endl;}

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

int main() {
	char T[256][11], U[256][11];
	int n, N, i, j, close = 1, flag;

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

	scanf("%d", &N);
	for (i = 0; i<N; i++) {
		scanf("%s", U[i]);
	}
	for (j = 0; j<N; j++) {
		flag = 0;
		for (i = 0; i<n; i++) {
			if (strcmp(T[i], U[j]) == 0) {
				close = (close == 1) ? 0 : 1;
				flag = 1;
			}
		}
		if (close == 1 && flag == 1)
			printf("Closed by %s\n", U[j]);
		else if (flag == 1)
			printf("Opened by %s\n", U[j]);
		else
			printf("Unknown %s\n", U[j]);
	}

	return 0;
}
/*
<input example>
3 //register three ID
Ant
Antonio
Android
4 //Check four ID
Android
Anko
Antonio
Alex
<output>//At first door is closed.
Android Opened
Anko is Unknown
Antonio Closed
Alex is Unknown
*/


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

ll n,k;

int main(){
    cin >> k;
    n=50;
    vector<ll> vec;
    for(ll i=0;i<50;i++) vec.push_back(i);
    for(ll i=0;i<k%50;i++){
        sort(vec.begin(),vec.end());
        vec[0]+=n;
        for(ll j=1;j<50;j++) vec[j]--;
    }
    for(ll i=0;i<n;i++) vec[i]+=k/n;
    sort(vec.begin(),vec.end());
    cout << n << endl;
    for(ll i=0;i<n;i++){
        if(i!=n-1) cout << vec[i] << " ";
        else cout << vec[i] << endl;
    }
}  


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	int n;
	char a[105];
	scanf("%d",&n);
	scanf("%s",a);
	if(n%2==1)
        printf("No\n");
    else
    {
        int f=1;
        for(int i=0;i<n/2;i++)
        {
            if(a[i]!=a[i+n/2])
            {
                f=0;
                break;

            }

        }
        if(f==0)
            printf("No\n");
        else
            printf("Yes\n");
    }
	return 0;

}

/*





*/


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;
ll f(ll x,ll y,ll z){
    return y/z-(x-1)/z;
}
int main(){
    cs
    ll a,b,c,d,t,t1,t2,t3;cin>>a>>b>>c>>d;
    t=b-a+1;
    t1=f(a,b,c);
    t2=f(a,b,d);
    t3=c/__gcd(c,d)*d;
    t3=f(a,b,t3);
    cout<<t-t1-t2+t3;
}

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

const int MOD = 1000000007;

int64_t modpow(int64_t x, int64_t n) {
    //const int MOD = 1000000007;
    //const int MAX = 1000000010;
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが半分になるよ！やったね！
}

int64_t comb(int64_t n, int64_t k) {
    int64_t x = 1;
    for(int i=n-k+1; i<=n; i++) {
        x = x*i%MOD;
    }

    int64_t y = 1;
    for(int i=1; i<=k; i++) {
        y = y*i%MOD;
    }
    y = modpow(y, MOD-2);

    return x*y%MOD;
}

int main() {
    int n,a,b;
    cin>>n>>a>>b;

    int all = modpow(2,n) -1;
    int muri = comb(n,a) + comb(n,b);

    int ans = all - muri;
    while(ans<0) {
        ans += MOD;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define MAX 1000000000000000000
#define N 100000

int main(void)
{
  int n, i = 0;
  long long tmp[N+1], r = 1;
  
  scanf("%d", &n);
  while(i < n)
  {
    scanf("%lld", &tmp[i]);
    if(tmp[i] == 0)
    {
      printf("0");
      return 0;
    }
    i++;
  }
  tmp[n] = -1;
  i = 0;
  while(tmp[i] > 0)
  {
    if(MAX / r < tmp[i])
    {
      r = -1;
      break;
    }
    r *= tmp[i];
    i++;
  }
  printf("%lld", r);
  return 0;
}

Measured memory_bytes: 2456
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  int ans;
  for (int x = 1; x <= 54000; ++x) {
    //if (n <= (double)x*1.08 && (double)x*1.08 < n) 
    if (100*n <= x*108 && x*108 < 100*(n+1)) {
      cout << dup(100*n,108) << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
def d_ScoreAttack(N, M, R):
    INF = float('inf')
    # ベルマン-フォード法
    dist = [INF] * N
    dist[0] = 0
    # 解説におけるdistとnegativeの更新を一度に行う
    for i in range(N):
        for a, b, cost in R:
            u, v, c = a - 1, b - 1, -cost
            if dist[u] != INF and dist[u] + c < dist[v]:
                dist[v] = dist[u] + c
                if i == N - 1 and v == N - 1:
                    # この条件が満たされたとき、頂点1と頂点Nのパスの中に負閉路があった
                    # このループを使ってスコアをいくらでも大きくできる
                    return 'inf'
    return -dist[-1]

N,M = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(M)]
print(d_ScoreAttack(N, M, R))

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int m,n,k; cin>>n>>k;
  vector<int> a(n);
  for(int i=0; i<n; ++i) {cin>>a[i]; if(a[i]==1) m=i+1;}
  int res=2147483647;
  for(int i=m-k; i<m; ++i){
    if(i<0) continue;
    int dis1=i,dis2=n-i-k;
    res=min(res,(dis1+k-2)/(k-1)+(dis2+k-2)/(k-1)+1);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3724
import sys
def input():
	return sys.stdin.readline().strip()




class Union_Find():
	def __init__(self, n):
		self.union = [i for i in range(n)]
		self.level = [0 for i in range(n)]

	def root(self, i, mode=0):
		keiro = [i]
		ans = i
		while ans != self.union[ans]:
			ans = self.union[ans]
			keiro.append(ans)
		if mode == 0:
			return ans
		else:
			return ans, keiro

	def unite(self, i, j):
		root_i, list_i = self.root(i, 1)
		root_j, list_j = self.root(j, 1)
		if root_i != root_j:
			if self.level[root_i] < self.level[root_j]:
				self.level[root_j] = max(self.level[root_i] + 1, self.level[root_j])
				for node in list_i:
					self.union[node] = root_j
			else:
				self.level[root_i] = max(self.level[root_j] + 1, self.level[root_i])
				for node in list_j:
					self.union[node] = root_i

N, M = list(map(int, input().split()))
UF = Union_Find(N)
p = list(map(int, input().split()))
for i in range(M):
	x, y = list(map(int, input().split()))
	x -= 1
	y -= 1
	UF.unite(x, y)

num = 0
for i in range(N):
	if UF.root(i) == UF.root(p[i] - 1):
		num += 1

print(num)


Measured memory_bytes: 66224
#include<bits/stdc++.h>
using namespace std;
main(){
  int A[1050];
  int n;
  int j;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  for(int i=1;i<n;i++){
    int v=A[i];
    for(j=0;j<n;j++){
      cout<<A[j];
      if(j!=n-1){
	cout<<" ";
      }
      else{
	cout<<"\n";
      }
    }
    for(j=i-1;j>=0&&A[j]>v;j--){
      A[j+1]=A[j];
    }
    A[j+1]=v;
  }
  for(j=0;j<n;j++){
    cout<<A[j];
    if(j!=n-1){
      cout<<" ";
    }
    else{
      cout<<"\n";
    }
  }
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int cnt = 1;
	bool noChange = false;
	vector<bool> sorted(n); 
	for (int i = 1; i < n; i++) {
		if (A[i] > A[i - 1]) {
			cnt++;
		}
		else {
			cnt = 1;
		}
		if (cnt >= k) {
			sorted[i] = true;
			noChange = true;
		}
	}
	int ans = noChange;
	set<int> st;
	for (int i = 0; i < k; i++) {
		st.insert(A[i]);
	}
	ans += !sorted[k - 1];
	for (int i = k; i < n; i++) {
		st.erase(A[i - k]);
		if ((*st.begin() < A[i - k] || *st.rbegin() > A[i]) && !sorted[i]) {
			ans++;
		}
		st.insert(A[i]);
	}
	cout << ans;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int calcConbination(int n, int r) {
  int ans = 1;
  for (int i = 1; i <= r; i++)
  {
    ans = ans * (n - i + 1) / i;
  }
  return ans;
}
 
 
 
int calcFactorial(int n) {
  int num = 1;
  for (int i = 2; i <= n; i++) num = num * i;
  return num;
}
 
 
 
void AverageLength()
{
  int n;
  double res = 0;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++)
  {
    cin >> x[i] >> y[i];
    v[i] = i + 1;
  }
 
  int c = calcConbination(n, 2);
  int f = calcFactorial(n);
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      res += sqrt(pow((x[i] - x[j]), 2) + pow((y[i] - y[j]), 2))*100;
 
    }
  }
  
  cout << fixed << setprecision(16) << res * (n - 1) / (c*100) << endl;
  return;
}
 
  int main()
{
  AverageLength();
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(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 << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll inv(ll n)       { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

vector<ll>graph[N];
ll dist[N];

void bfs(ll src)
{
	dist[src] = 0;
	queue<ll>Q;
	Q.push(src);

	while(!Q.empty())
	{
		ll v = Q.front();
		Q.pop();

		for(auto u : graph[v])
		{
			if(dist[u]==-1)
			{
				dist[u] = dist[v]+1;
				Q.push(u);
			}
		}
	}
}

int main()
{
    fast
    ll n,m;
    cin>>n>>m;
    
    ll src,dest,a,b;
    forn(i,0,m)
    {
    	cin>>a>>b;
    	graph[a].pb(b+n);
    	graph[a+n].pb(b+2*n);
    	graph[a+2*n].pb(b);
    }

    cin>>src>>dest;

    reset(dist,-1);
    bfs(src);

    if(dist[dest]==-1)
    	cout<<-1;
    else
    	cout<<dist[dest]/3;

    
    return 0;
}

Measured memory_bytes: 25216
N = int(input())
b_list = list(map(int,input().split()))
s = True
if (b_list[0] > 1):
  b_list[0] -= 1
for i in range(1,len(b_list)):
  if (b_list[i-1] < b_list[i]):
    b_list[i] -= 1
for i in range(len(b_list)-1):
  if (b_list[i] > b_list[i+1]):
    s = False
if (s):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 15020
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn readln<T>() -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().parse().unwrap()
}

fn main() {
    let a: u64 = readln();
    let b: u64 = readln();
    let h: u64 = readln();

    println!("{}", (a + b) * h / 2);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	int N;

	std::cin >> N;

	int cntx = 0;
	for (int i = 0; i < N; i++)
	{
		int tmpPX;
		std::cin >> tmpPX;
		if (tmpPX != i+1)
		{
			cntx += 1;
		}
	}

	if (cntx < 3)
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;

	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

string S, T;
map<int, int> MP_S, MP_T;
vi S_cnt,T_cnt;

bool compare(){
    if(S_cnt.size()!=T_cnt.size())
        return false;

    rep(i, S_cnt.size())
        if(S_cnt[i]!=T_cnt[i]) return false;

    return true;
}

void solve(){
    rep(i, S.size())
        MP_S[S[i]]++;

    for(auto itr=MP_S.begin(); itr!=MP_S.end(); itr++)
        S_cnt.push_back(itr->second);

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

    rep(i, T.size())
        MP_T[T[i]]++;

    for(auto itr=MP_T.begin(); itr!=MP_T.end(); itr++)
        T_cnt.push_back(itr->second);

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

    if(compare())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    cin >> S >> T;

    solve();
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  
  int i = (n +111 -1)/111;
  cout << i*111 << "\n";

}


Measured memory_bytes: 256
S = input()
slist = "abcdefghijklmnopqrstuvwxyz"

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

lis =[]
T = S
if len(S)<26:
    Sset = set(S)
    for s in slist:
        if s not in Sset:
            print(S+s)
            exit()
else:
    while len(S)>0:
        lis.append(S[-1])
        lis.sort()
        S = S[:-1]
        for s in lis:
            if S + s > T:
                print(S + s)
                exit()


Measured memory_bytes: 9012
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  map<char, int> cnt1, cnt2;

  for (int i = 0; i < (int)s.length(); i++) {
    cnt1[s[i]]++;
    cnt2[t[i]]++;
  }

  if (cnt1.size() != cnt2.size()) {
    cout << "No" << endl;
    return 0;
  }
  map<char, char> table;
  for (int i = 0; i < (int)s.length(); i++) {
    if (table.find(t[i]) != table.end()) {
      if (table[t[i]] != s[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    table[t[i]] = s[i];
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
using System;
using System.Collections.Generic;

namespace abc165
{
    class Program
    {
        static void Main()
        {
            var nmq = Console.ReadLine().Split(' ');
            var n = int.Parse(nmq[0]);
            var m = int.Parse(nmq[1]);
            var q = int.Parse(nmq[2]);
            var table = new int[q][];
            for (var i = 0; i < q; ++i)
            {
                var strList = Console.ReadLine().Split(' ');
                table[i] = new int[4];
                for (var j = 0; j < 4; ++j)
                {
                    table[i][j] = int.Parse(strList[j]);
                }
            }
            var a = new int[n];
            a[0] = 1;
            Console.WriteLine(DFS(n - 1, m, table, a, 0));
        }
        static int DFS(int n, int m, int[][] queries, int[] a, int len)
        {
            if (len == n)
            {
                return Calc(queries, a);
            }
            var max = 0;
            for (var i = a[len]; i <= m; ++i)
            {
                a[len + 1] = i;
                var current = DFS(n, m, queries, a, len + 1);
                if (max < current)
                {
                    max = current;
                }
            }
            return max;
        }
        static int Calc(int[][] queries, int[] a)
        {
            var total = 0;
            foreach (var query in queries)
            {
                if (a[query[1] - 1] - a[query[0] - 1] == query[2])
                {
                    total += query[3];
                }
            }
            return total;
        }
    }
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> T>>p>>Q;
	T[0] -= 32;
	p[0] -= 32;
	Q[0] -= 32;
	cout << T[0]<<p[0]<<Q[0];
}

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

int main(){
	int i;
	char a[4];
	cin>>a;
	for(i=0;i<=2;i++){
		if(a[i]=='1') a[i]='9';
		else if(a[i]=='9') a[i]='1';
	}
	cout<<a[0]<<a[1]<<a[2]<<endl;
} 

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

int main(){
  string S, T;
  cin >> S >> T;
  int s, t;
  s = S.size();
  t = T.size();
  vector<int> ans(s-t+1);
  for(int i=0; i <= s-t; i++){
    for(int j=0; j<t; j++){
      if(T.at(j) != S.at(i+j)){
        ans.at(i) += 1;
      }
    }
  }
  for(int i=0; i< s-t; i++){
    if(ans.at(i) < ans.at(i+1)){
      ans.at(i+1) = ans.at(i);
    }
  }
  cout << ans.at(s-t) << endl;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  cin.ignore();
  string line;
  string s = "Hoshina";
  while(getline(cin, line))
 {
    while(line.find("Hoshino")!=string::npos)
      {
      line.replace(line.find("Hoshino"), s.size(), s);
    }
    cout<<line<<endl;
  }
  return 0;
}

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


using namespace std;


typedef long long LL;
typedef pair<LL,LL> pp;

void fail() { cout << "No" << endl; exit(0); }

int main()
{
	int N;
	cin >> N;
	vector<int> v(N);
	vector<int> even, odd, four;
	for (int i = 0; i < N; i++) {
		scanf("%d", &v[i]);
		if (v[i]%4 == 0)
			four.push_back(v[i]);
		else if (v[i]%2 == 0)
			even.push_back(v[i]);
		else
			odd.push_back(v[i]);
	}
	int i = 0, j = 0, k = 0;
	int last = -1;
	if (odd.size() > 0) {
		last = odd[k++];
	}
	else if (even.size() > 0) {
		last = even[j++];
	}
	else {
		last = four[i++];
	}
	while (i+j+k < N) {
		if (last%2 == 1) { // last was odd, need a 4
			if (i == four.size()) fail();
			last = four[i++];
		}
		else if (last%4 == 0) { // last was %4==0, so use up an odd
			if (k < odd.size())
				last = odd[k++];
			else if (j < even.size())
				last = even[j++];
			else
				last = four[i++];
		}
		else { // last was even, so use up an even if possible, else a four
			if (j < even.size())
				last = even[j++];
			else if (k < four.size())
				last = four[k++];
			else
				fail();
		}
	}
	cout << "Yes" << endl;
	exit(0);
}



Measured memory_bytes: 1404
/*
auhtor:hbohra98
chandigarh univeristy
*/
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define VP vector < pair < ll , ll > >
#define VI vector< ll >
#define VS vector< string >
#define mk make_pair

using namespace std;
int main(){
ll t;cin>>t;
  cout<<t*t*3;

    
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){

        long long int a,b,n;
        scanf("%lld%lld%lld",&a,&b,&n);

        //xの制約は 0からb-1 && 0からn

        if(n>=b){               //0からb-1だけ調べればok
                n = b-1;//f(x)は短調増加
        }   
        long long int ans = (a*n)/b;//0からb-1の間のときfloor(x/B)が0より

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

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, a, b;
    cin >> n >> a >> b;
    lint ret = n / (a + b) * a;
    n -= n / (a + b) * (a + b);
    ret += min(a, n);
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 2e5 + 10;
int n;
LL a[maxn];
int main() {
	while(~scanf("%d", &n)) {
		LL sum = 0;
		for(int i = 1; i <= n; i++) {
			scanf("%lld", &a[i]);
			sum += a[i];
		}
		LL ans = 1e+18;
		LL temp = 0;
		for(int i = 1; i < n; i++) {
			temp += a[i];
			ans = min(ans, abs(sum - 1LL * 2 * temp));
		}
		printf("%lld\n", ans);
	}
	return 0;
} 

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

int main(){
  long long n;
  cin >> n;
  long long ans = 1e12;
  for (int i = 1;i <= 1e6;i++){
    if (n%i == 0){
      ans = min(ans,((i-1) + (n/i - 1)));
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main(int argc, char const *argv[])
{

    vector<int> v(3);
    for (auto &x : v)
    {
        cin >> x;
    }

    sort(v.begin(), v.end());
    if(v[0]==v[1]&&v[2]!=v[1]||v[2]==v[1]&&v[1]!=v[0]){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	int n,k;
	cin>>n>>k;
	int w[n+5],v[n+5];
	for(int i=1; i<=n; i++) cin>>w[i]>>v[i];
	int dp[n+5][k+5];
	memset(dp,0,sizeof(dp));
	for(int i=1; i<=n; i++){
		for(int j=0; j<=k; j++){
			dp[i][j] = dp[i-1][j];
			if(j!=0) dp[i][j]=max(dp[i][j],dp[i][j-1]);
			if(j>=w[i]) dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
		}
	}
	cout<<dp[n][k];
}

Measured memory_bytes: 82304
import os

def main():
	
	N,M = map(int, input().split())
	ac = [0]*N
	wa = [0]*N
	for i in range(M):
		p,s = input().split()
		if s == 'AC':
			if ac[int(p) - 1] != 0:
				continue
			else:	
				ac[int(p) - 1] = 1
		else:
			if ac[int(p) - 1] != 0:
				continue
			else:
				wa[int(p) - 1] += 1
	AC,WA = 0,0

	for i in range(N):
		AC += ac[i]
		if ac[i] >= 1:
			WA += wa[i]
	print(AC,WA)

if __name__ == '__main__':
	main()


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

int main()
{ 
   int n;
   int a[200010]={};
   int b[200010]={};
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>a[i];
       b[i]=a[i];
   }
   sort(b,b+n);
   int l=b[n/2-1],r=b[n/2];
   for(int i=0;i<n;i++){
       if(a[i]<=l) cout<<r<<endl;
       else cout<<l<<endl;
   }

}


Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>

using namespace std;

const int ROW_MAX = 10;
const int COL_MAX = 10000;
int col_cnt[COL_MAX];
bitset<COL_MAX> mat[ROW_MAX];
int r, c;
int result;

void dfs(int row_id, bool flip) {
    if (row_id == r) {
        int res = 0;
        for (int i = 0; i < c; i++) {
            res += max(col_cnt[i], r-col_cnt[i]);
        }
        result = max(result, res);
        return;
    }
    if (flip) {
        for (int i = 0; i < c; i++) {
            if (mat[row_id][i]) {
                mat[row_id][i] = 0;
                col_cnt[i]--;
            } else {
                mat[row_id][i] = 1;
                col_cnt[i]++;
            }
        }
    }
    dfs(row_id+1, false);
    dfs(row_id+1, true);
    if (flip) {
        for (int i = 0; i < c; i++) {
            if (mat[row_id][i]) {
                mat[row_id][i] = 0;
                col_cnt[i]--;
            } else {
                mat[row_id][i] = 1;
                col_cnt[i]++;
            }
        }
    }
}

int main() {
    while (1) {
        scanf("%d%d", &r, &c);
        if (!r) break;
        memset(col_cnt, 0, COL_MAX*sizeof(int));
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int k;
                scanf("%d", &k);
                if (k) {
                    mat[i][j] = 1;
                    col_cnt[j]++;
                } else {
                    mat[i][j] = 0;
                }
            }
        }
        result = 0;
        dfs(0, false);
        dfs(0, true);
        printf("%d\n", result);
    }
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	for(int i=0; i<30; i++){
		for(int j=0; j<30; j++){
			if(n==i*4+j*7){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b){
        cout<<"YES"<<endl;
    }
    else if(c-b==b-a){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    for(int i=0; i<n; i++) {
      A[i] = sc.nextInt();
    }
    boolean flag = true;
    int cnt = 0;
    
    while(flag) {
      for(int i=0; i<n; i++) {
        if(A[i] % 2 == 0) {
          A[i] /= 2;
        } else {
          flag = false;
        }
      }
      if(flag) {
      	cnt += 1;
      }
    }
    System.out.println(cnt);
  }
}

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

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

    int D, N; cin >> D >> N;
    if (N == 100) ++N;
    if (D == 1) N *= 100;
    if (D == 2) N *= 10000;
    cout << N << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 #include <iomanip>
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }


int n,m;
void solve(istream& cin, ostream& cout) {
	cin >>n;
	vector<int> A(n);
	cin >>A;
	// i2-i = H[i]+H[i2] -> i2-H[i2] = H[i]+i
	ll ans = 0;
	map<int, int> M;
	REP(i, n) {
		ans += M[i-A[i]];
		M[i+A[i]]++;
	}
	cout <<ans<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 20692
import java.util.*;

public class Main {

public static final int[] PRIME = new int[]{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[PRIME.length];
		for (int i = 1; i <= n; i++) {
			int target = i;
			int j = 0;
			while (j < PRIME.length && PRIME[j] <= target) {
				if (target % PRIME[j] == 0) {
					arr[j]++;
					target /= PRIME[j];
				} else {
					j++;
				}
			}
		
		}
		int count = 0;
		
		//4,4,2
		for (int i = 0; i < PRIME.length; i++) {
			if (arr[i] >= 4) {
				for (int j = i + 1; j < PRIME.length; j++) {
					if (arr[j] >= 4) {
						for (int k = 0; k < PRIME.length; k++) {
							if (arr[k] >=2 && k != i && k != j) {
								count++;
							}
						}
					}
				}
			}
		}
		
		//14, 4
		for (int i = 0; i < PRIME.length; i++) {
			if (arr[i] >= 14) {
				for (int j = 0; j < PRIME.length; j++) {
					if (arr[j] >= 4 && j != i) {
						count++;
					}
				}
			}
		}
		
		// 24, 2
		for (int i = 0; i < PRIME.length; i++) {
			if (arr[i] >= 24) {
				for (int j = 0; j < PRIME.length; j++) {
					if (arr[j] >= 2 && j != i) {
						count++;
					}
				}
			}
		}
		
		// 74
		for (int i = 0; i < PRIME.length; i++) {
			if (arr[i] >= 74) {
				count++;
			}
		}
		
		System.out.println(count);
	}
	
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll s;
    cin>>s;
    int x=0,y=0;
    int n=1e9;
    x=(n-s%n)%n;
    y=(s+x)/n;
    cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}

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

int main(){
int l;
while(scanf("%d\n",&l)!=0){
	if(l==0)break;
	int i,p,q=0,max=0,min=1000;
	for(i=0;i<l;i++){
		scanf("%d\n",&p);
		if(max<p)max=p;
		if(min>p)min=p;
		q+=p;
	}
	printf("%d\n",(int)floor((q-max-min)/(l-2)));
}
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = 0;
    if (b - 1 <= n) {
        ans = a * (b - 1);
    } else {
        ans = a * (n == b ? n - 1 : n);
    }
    ans /= b;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
signed main(){
    int K,T;
    int a[104];
    int suma=0;
    cin >> K >> T;
    REP(i,T){cin >> a[i];suma+=a[i];}
    sort(a,a+T);
    suma-=a[T-1];
    cout << max((int)0,a[T-1]-suma-1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
const double P=acos(-1.0);
int main(){
	double a,b,h,m,h1,m1,c,d,e;
	cin>>a>>b>>h>>m;
	m1=m*6.0;h1=h*30.0+(m*0.5);
	if(abs(m1-h1)>=180){
		d=360-abs(m1-h1);
	} 
	else d=abs(m1-h1);
	e=d*P/180;
	c=sqrt(a*a+b*b-2*a*b*cos(e));
	cout<<fixed<<setprecision(20)<<c<<endl;
}

Measured memory_bytes: 4148
n = int(input())
dice = [list(map(int,input().split())) for _ in range(n)]
flag = False

a = 0
for i in range(n):
    if dice[i][0] == dice[i][1]:
        a += 1
    else:
        a = 0
    if a >= 3:
        flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9128