akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int	A, B, M;
	cin >> A >> B >> M;
	
	int mina = 100000000;
	vector<int> av(A);
	for (auto& a : av) {
		cin >> a;
		mina = min(mina, a);
	}
	int minb = 100000000;
	vector<int> bv(B);
	for (auto& b : bv) {
		cin >> b;
		minb = min(minb, b);
	}

	int ret = mina + minb;
	for (int i = 0; i < M; ++i) {
		int x, y, c;
		cin >> x >> y >> c;

		ret = min(ret, av[x-1] + bv[y-1] - c);
	}

	cout << ret << endl;


	return 0;
}

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

typedef struct{
    int a,b,c;
}peso;

vector<peso> dia;
long long dp[100005][3];

int n;

long long solve(int pos, int ant){
    if(dp[pos][ant]) return dp[pos][ant];
    
    if(pos == n){
        return 0;
    }
    
    if(ant == 0){
        dp[pos][ant] = dia[pos].a + max(solve(pos+1, 1), solve(pos+1, 2));     
    }else if(ant == 1){
        dp[pos][ant] = dia[pos].b + max(solve(pos+1, 0), solve(pos+1, 2));
    }else{
        dp[pos][ant] = dia[pos].c + max(solve(pos+1, 0), solve(pos+1, 1));
    }
    return dp[pos][ant];
    
}

int main() {
    cin >> n;
	for(int i = 0; i < n; i++){
        peso p; cin >>p.a >> p.b >> p.c;
        dia.push_back(p);
    }
    long long res = 0;
    for(int i = 0; i < 3; i++){
        res = max(res, solve(0,i));
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

void warshall(vector<vector<int> >& cost)
{
  for (int k = 0; k < 10; ++k) {
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }
}

int main()
{
  int h, w;
  scanf("%d %d", &h, &w);
  vector<vector<int> > cost(10, vector<int>(10, 0));
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      scanf("%d", &cost[i][j]);
    }
  }

  warshall(cost);
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int val;
      scanf("%d", &val);
      if (val == -1) { continue; }
      ans += cost[val][1];
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

deque<int> d;
int main() {
    int q;
    cin >> q;
    while(q--) {
        int op, key;
        cin >> op >> key;

        // push
        if ( op == 0 ) {
            int val;
            cin >> val;
            if ( key == 0 ) d.push_front(val);
            else if ( key == 1 ) d.push_back(val);
        } 
        
        // random access
        else if ( op == 1 ) {
            cout << d[key] << endl;
        }
        
        // pop
        else if ( op == 2 ) {
            if (key == 0) d.pop_front();
            else if (key == 1) d.pop_back();
        }
    }
    return 0;
}



Measured memory_bytes: 4616
using System;

namespace ABC055
{
    class B
    {
        static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());
            const long MOD = 1000000007;

            long power = 1;
            for (long i = 1; i <= N; i++)
            {
                power = (power * i) % MOD;
            }

            Console.WriteLine(power);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
 
using namespace std;
 
int find (int a, int b, int c) {
  if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
    return 0;
  } else {
    return find((a + b) / 2, (a + c) / 2, (b + c) / 2) + 1;
  }
}
 
int main () {
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
    cout << 0 << endl;
  } else if (a == b & b == c) {
    cout << -1 << endl;
  } else {
    cout << find(a, b, c) << endl;
  }
}


Measured memory_bytes: 3644
function Main(input) {
  line = input.split(' ');
  a = line[0] * 1
  b = line[1] * 1
  c = line[2] * 1
  ans = false
  if (a < b) {
     if (a < c && c < b) {
        ans = true
     }
  } else {
     if (b < c && c < a) {
        ans = true
     }
  }
  if (ans) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
# 4, 0, 608200469

waru = 1_000_000_007 # あまりを出す
n, m = gets.split.map &:to_i # N段目まで行きたい
a = []
while aa = gets # 壊れてる階段
  a << aa.to_i
end
# p [n, m]

arr = Array.new(n, -1)

a.each do |aa|
  arr[aa] = 0
end
0.upto(n) do |i|
  next if arr[i] == 0
  if i == 0 || i == 1
    arr[i] = 1
    next
  end
  arr[i] = arr[i - 1] + arr[i - 2]
end

# p arr
p (arr[-1] % waru)


Measured memory_bytes: 433020
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
#define MAX 100003
ll calculate(ll k, vector<ll> v,vector<ll> temp)
{
    ll val= (1LL<<k+1) ; val--;    // 2^k+1 - 1  
    for(int i=0;i<v.size();i++) v[i]=v[i] & val , temp[i]=temp[i] & val;  //change into k bits
    sort(v.begin(),v.end());   // sum should be max 2 ^ (k+2) -2   and for k th bit set sum should be 2^ k to 2^(k+1)-1 
                                                                        //                2^k + 2^(k+1) to 2 ^ (k+2)-2
    ll x = (1LL<<k);
    ll ans=0;
    ll mx=(1LL<<k+2)-2;
    for(int i=0;i<v.size();i++){
        ll a=temp[i];
        int j=lower_bound(v.begin(),v.end(),x-a)-v.begin();
        int y=upper_bound(v.begin(),v.end(),val-a)-v.begin();
        y--;
        if(j<=y) ans+=(y-j+1);
        j=lower_bound(v.begin(),v.end(),x+val+1-a)-v.begin();
        y=upper_bound(v.begin(),v.end(),mx-a)-v.begin();
        y--;
        if(j<=y) ans+=(y-j+1);
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    vector<ll> v,temp;
    for(int i=0;i<n;i++) { ll a;  cin>>a ;  temp.push_back(a); }
    for(int i=1;i<=n;i++){
        ll a; cin>>a;
        v.push_back(a);
    }
    ll ans=0;
    for(ll i=0;i<29;i++){
        ll val=calculate(i,v,temp);
        if(val%2==1) ans=ans+(1LL<<i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
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;
}
const int INF=1e18;
const int MOD=1e9+7;

struct Edge{
    int from,to,cost;
    Edge(int from,int to,int cost):from(from),to(to),cost(cost){};
};
vector<Edge> Graph;

int log2(int n){
    int ret=0;
    while(n>=2){
        ret++;
        n/=2;
    }
    return ret;
}

signed main(){
    int L;cin>>L;
    int C=L;
    int N=20;
    REPS(i,N-1){
        Graph.eb(i,i+1,0);
    }
    REP(i,log2(L)){
        Graph.eb(N-i-1,N-i,pow(2,i));
    }
    int t=N-log2(L);
    while(L>0){
        L-=pow(2,log2(L));
        int Z=C-L;
      	if(Z==C)break;
        Graph.eb(t,N-log2(L),Z);
    }
    cout<<N<<" "<<Graph.size()<<endl;
    REP(i,Graph.size()){
        cout<<Graph[i].from<<" "<<Graph[i].to<<" "<<Graph[i].cost<<endl;
    }
}

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

int main(){
	int n;
	scanf("%d",&n);
	n%=10;
	if(n==3){
		printf("bon");
	}
	else if(n==0 || n==1 || n==6 || n==8){
		printf("pon");
	}
	else {
		printf("hon");
	}
}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
 
ll calc_count(ll x, ll y, ll L, ll T){
  if(T*2 < abs(x-y)) return 0;
  ll remain = T*2 - abs(x-y);
  return 1+remain/L;
}
 
int main(){
  int N, L, T;
  cin >> N >> L >> T;
  vector<ll> X, W;
  vector<int> ans;
 
  rep(i,N){
    int x, w;
    cin >> x >> w;
    X.push_back(x);
    W.push_back(w);
 
    if(w == 1){
      ans.push_back((x+T)%L);
    }else{
      ans.push_back(((x-T)%L+L)%L);
    }
  }

  int base = ans[0];
  sort(ALLOF(ans));

  int SZ = ans.size();
  vector<int> ret(SZ);
  int cnt = 0;

  if(W[0] == 1){
    rep(i,X.size()){
      if(W[i] == 2){
        cnt += calc_count(X[0], X[i], L, T);
      }
    }

    int b = 0;
    rep(i,ans.size()){
      if(ans[i] == base){
        b = i;
      }
    }
    rep(j,ans.size()){
      ret[(cnt+j)%SZ] = ans[(b+j)%SZ];
    }    
  }else{
    rep(i,X.size()){
      if(W[i] == 1){
        cnt += calc_count(X[0]+L, X[i], L, T);
      }
    }

    int b = 0;
    rep(i,ans.size()){
      if(ans[i] == base){
        b = i;
        break;
      }
    }
    rep(j,ans.size()){
      ret[((-cnt+j)%SZ+SZ)%SZ] = ans[(b+j)%SZ];
    }
  }
  
  rep(i,ret.size()){
    cout << ret[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

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

  int cnt = 0;
  for (int a = 1; a < n; ++a) {
    for (int b = 1; b < n; ++b) {
      if (a * b >= n) break;
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,K;cin >> N >> K;
    vector<int> h(N);
    rep(i,N)cin >> h[i];
    sort(rall(h));
    int ct = 0;
    rep(i,N){
        if(K <= h[i])ct++;
        else break;
    }
    cout << ct << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
vint a;
vint b;
vint c;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans;
    ll suma=0;
    ll sumb=0;
    vint a(n);
    vint b(n);
    ll s=0;
    REP(i,n){
        cin >> a[i];
        suma+=a[i];
    }
    REP(i,n){
        cin >> b[i];
        sumb+=b[i];
        if(a[i]>=b[i]){
            c.pb(a[i]-b[i]);
        }else{
            s+=(ll)(b[i]-a[i]);
        }
    }
    if(sumb>suma){
        ans = -1;
    }else{
        ans=0;
        sort(ALL(c));
        int k = c.size();
        for(int i=k-1;i>=0;i--){
            if(s<=0){
                break;
            }
            s-=c[i];
            ans++;
        }
        ans = n-k+ans;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1660
//前処理してやるのはすぐわかったけど　うまいことacを表現してやることができず
/* 悩んでいた　右端の計算は　右端を一個内側に動かせばよかった　そして普通にacになるaの数の累積和考える


string で手間取っていたところ つまるところstringを参照する時に　二つ参照したいが幅から出ちゃう


for (int i = 1; i < N; ++i) {
		ac[i] = ac[i - 1];
		if (S[i - 1] == 'A' && S[i] == 'C') {

            i= 1~~~ i< nととって
            i-i iとして
            やっていた



.size　とかを積極的に使いたい*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    
    int n,q;
    string str;
    cin >> n >> q >> str;
    vector<int> t(n,0);
    for(int i = 1; i< n; i++){
        if(str[i-1] == 'A' && str[i] == 'C'){
            t.at(i) = t.at(i-1)+1;
        }else t.at(i) = t.at(i-1);
    }

    REP(i,q){
        int l,r;
        cin >> l >> r;

        int ans = t.at(r-1);
        if(l > 1){
            ans -= t.at(l);
            if(str[l-1] == 'A' && str[l] == 'C'){
                ans++;
            }
        }


        cout << ans << endl;
    }



    

    return 0;
}

Measured memory_bytes: 1408
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
D = []
for a, b in AB:
    D.append((a + b, a, b))
D.sort(reverse=True)
ans = 0
p = 0
for c, a, b in D:
    if p % 2 == 0:
        ans += a
    else:
        ans -= b
    p += 1
print(ans)


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

int main()
{
    int n,i,l[1001],r[1001];
    cin >> n;
    for(i=0;i<n;i++)
    {
        scanf("%d %d", &l[i], &r[i]);
    }
    
    int sum=0;
    for(i=0;i<n;i++)
    {
        sum += r[i]-l[i]+1;
    }
    cout << sum << endl;
    return 0;
}

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

const ll mod = 1e9+7;

int main(){
    int s;
    cin >> s;
    vector<ll> dp(s+1);
    dp[0] = 1;
    for(int i = 0; i <= s; i++){
        for(int j = 0; j <= i-3; j++){
            dp[i] += dp[j];
            dp[i] %= mod;
        }
    }
    cout << dp[s] << endl;
    return 0; 
}


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


int min(int a, int b)
{
    if( a < b ) return a;
    else return b;
}


int main()
{
    int N, K;
    int x[100];
    cin >> N >> K;
    for( int i = 0; i < N; ++i ) cin >> x[i];

    int ans = 0;
    for( int i = 0; i < N; ++i ){
        ans += 2*min(x[i], K-x[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

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

  vector<int> x_i;
  x_i.push_back(x);
  for (int i = 0; i < n; i++){
    int xx;
    cin >> xx;
    x_i.push_back(xx);
  }
  sort(x_i.begin(), x_i.end());

  int d = x_i[1] - x_i[0];
  for (int i = 2; i < x_i.size(); i++){
    d = gcd(d, x_i[i] - x_i[i-1]);
  }
  cout << d << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int>a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    ll MOD=1e9+7;
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        cnt+=a[i];
    }
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        cnt-=a[i];
        ans+=(a[i]*(cnt%MOD))%MOD;
        ans%=MOD;
        //cerr<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;

  for (ll i = 1; i*(i+1) < n; ++i)
  {
   if(n%i==0)
   {
      ans+=(n/i-1); 
   }   
  }
  
  cout<<ans<<" ";
}

signed main(){
   
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


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

using namespace std;

const int CoinType[] = { 500,100,50,10,5,1 };

int getCoin(int &rest, int coinVal) {
	int cnt;

	cnt = rest / coinVal;
	rest %= coinVal;

	return cnt;
}

int main() {
	int n, rest, sum;

	while (cin >> n, n) {
		sum = 0;
		rest = 1000 - n;
		for (int i = 0; i < 6;++i){
			sum += getCoin(rest, CoinType[i]);
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        String[] s = new String[n];
        int[] t = new int[n];
        for(int i = 0; i < n; i++){
            s[i] = sc.next();
            t[i] = Integer.parseInt(sc.next());
        }
        String x = sc.next();
        
        boolean b = false;
        int ans = 0;
        for(int i = 0; i < n; i++){
            if(b) ans += t[i];
            if(s[i].equals(x)) b = true;
        }
        
        System.out.println(ans);
    }
}

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

int main(void){
	string S = "AIDUNYAN";
	string d;cin>>d;
	int h[26]={},H[26]={};
	set<int> ps;
	for(int i=0;i<S.size();++i) ++H[S[i]-'A'];
	for(int i=0;i<d.size();++i){
		++h[d[i]-'A'];
		if(i>=S.size()){
			--h[d[i-S.size()]-'A'];
		}
		bool f=true;
		for(int j=0;j<S.size();++j){
			if(h[S[j]-'A']!=H[S[j]-'A']){
				//cerr<<S[j]<<endl;
				f=false;
			}
		}
		if(f){
			//cerr<<H['N'-'A']<<endl;
			ps.insert(i-S.size()+1);
		}
	}
	for(int i=0;i<d.size();++i){
		if(ps.find(i) != ps.end()){
			cout<<"AIZUNYAN";i+=S.size()-1;
		}
		else cout<<d[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;

int dp[100001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// dp[i] == minimum cost incurred to reach the stone i
    int n; cin >> n;
    vector<int> h(n+1);
    for(int i = 1; i <= n; i++)
        cin >> h[i];

    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i = 3; i <= n; i++)
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

    cout << dp[n] << '\n';
}


Measured memory_bytes: 4048
import java.util.Hashtable;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] a = new String[n];
        String[] b = new String[n];
        for (int i = 0; i < n; i++) {
            String next = in.next();
            a[i] = next;
            b[i] = next;
        }
        bubbleSort(a);
        selectionSort(b);
    }

    private static void bubbleSort(String[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if (compareCards(a[j], a[j-1]) < 0) {
                    String swap = a[j-1];
                    a[j-1] = a[j];
                    a[j] = swap;
                }
            }
        }
        System.out.println(printArray(a));
        System.out.println("Stable");
    }

    private static void selectionSort(String[] a) {
        int n = a.length;
        boolean stable = true;
        Hashtable<Integer, Integer> hash = new Hashtable<>();
        for (int i = 0; i < n; i++) {
            int min = i;
            for (int j = i; j < n; j++) {
                if (compareCards(a[j], a[min]) < 0) {
                    min = j;
                }
            }
            int key = Character.getNumericValue(a[i].charAt(1));
            if (hash.containsKey(key) && i < hash.get(key)) {
                stable = false;
            }
            hash.put(key, min);
            String swap = a[i];
            a[i] = a[min];
            a[min] = swap;
        }
        System.out.println(printArray(a));
        if (stable) {
            System.out.println("Stable");
        } else {
            System.out.println("Not stable");
        }
    }

    private static int compareCards(String c1, String c2) {
        int c1Val = Character.getNumericValue(c1.charAt(1));
        int c2Val = Character.getNumericValue(c2.charAt(1));
        return Integer.compare(c1Val, c2Val);
    }

    private static String printArray(String[] a) {
        int length = a.length;
        String arrayString = "";
        for (int i = 0; i < length - 1; i++) {
            arrayString = arrayString + a[i] + " ";
        }
        arrayString = arrayString + a[length - 1];
        return arrayString;
    }
}



Measured memory_bytes: 26320
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG // checks for container overflows
#pragma GCC optimize "trapv" // to chcek for int overflow
#pragma -Wduplicated-cond // dupilcate conditions
#endif

#include "bits/stdc++.h"
using namespace std;
using namespace chrono;
typedef unsigned long long int ull;
typedef long long ll;
int main()
{
#ifndef ONLINE_JUDGE
    auto start = high_resolution_clock::now();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    register int test;
    int n;

    cin >> n;

    if (n >= 400 && n <= 599)
        cout << "8";
    else if (n >= 600 && n <= 799)
        cout << "7";
    else if (n >= 800 && n <= 999)
        cout << "6";
    else if (n >= 1000 && n <= 1199)
        cout << "5";
    else if (n >= 1200 && n <= 1399)
        cout << "4";
    else if (n >= 1400 && n <= 1599)
        cout << "3";
    else if (n >= 1600 && n <= 1799)
        cout << "2";
    else
        cout << "1";

#ifndef ONLINE_JUDGE
    auto end = high_resolution_clock::now();
    double time_taken = duration_cast<nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nTime : " << fixed << time_taken << setprecision(9);
#endif
    return 0;
}

Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	k := scanInt()
	x := scanInt()
	y := scanInt()

	if k&1==0 && (x+y)&1==1 {
		fmt.Fprintln(wr, -1)
		return
	}

	xs,ys := 1,1
	if x < 0 {
		xs = -1
		x = -x
	}
	if y < 0 {
		ys = -1
		y = -y
	}

	f := false
	if x < y {
		f = true
		x,y = y,x
		xs,ys = ys,xs
	}

	n := (x+y+k-1)/k+(k-(x+y)%k)%k%2
	a := (n*k-(x+y))/2

	nx,ny := 0,0

	print := func() {
		if !f {
			fmt.Fprintln(wr, xs*nx,ys*ny)
		} else {
			fmt.Fprintln(wr, ys*ny,xs*nx)
		}
	}

	if a+x < k && a!=0 {
		c := x-y+(x-y)%2*k
		fmt.Fprintln(wr, (x+y+(k-x)*2+c)/k)
		c /= 2

		ny = -k+x
		nx = x
		if k-x+y + c < k {
			ny -= c
			nx -= c
		}
		print()

		nx += c
		ny += k-c
		print()

		if nx != x && ny != y {
			ny = y
			nx = x
			print()
		}

		return
	}

	fmt.Fprintln(wr, n)

	if a != 0 {
		ny -= a
		nx += k-a
		print()
	}

	for nx+k < x {
		nx += k
		print()
	}

	ny += k-(x-nx)
	nx = x
	print()

	for ny < y {
		ny += k
		print()
	}

}


Measured memory_bytes: 5888
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**19
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    AB = [LI() for _ in range(N)]
    d = {}

    ans = 0
    zero = 0
    for i in range(N):
        a,b = AB[i]
        if a == 0:
            if b == 0:
                zero += 1
                continue
            b = 1
            s = 1
        elif b == 0:
            a = 1
            s = -1
        else:
            s = (a*b>0) - (a*b<0)
            a = abs(a); b = abs(b)
            x = math.gcd(a,b)
            a = a // x; b = b // x
        if (a,b,s) in d:
            d[(a,b,s)] += 1
        else:
            d[(a,b,s)] = 1

    ans = 1
    for (a,b,s),data in d.items():
        if data == 0: continue
        if (b, a, -s) in d:
            m = d[(b,a,-s)]
            d[(b, a, -s)] = 0
        else:
            m = 0
        x = pow(2,data,MOD) + pow(2,m,MOD) - 1
        ans = (ans * x) % MOD

    print((ans-1+zero)%MOD)

if __name__ == '__main__':
    main()

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

int main() {
    int n; cin >> n;
    vector<int64_t> a(n);
    rep(i,n) cin >> a[i];
    int64_t maxn = 1000000000000000000ll;
    bool in0 = false;
    rep(i,n) if(a[i] == 0) in0 = true;

    if(in0) cout << 0 << endl;
    else{
        int64_t ans = 1;
        bool bk = false;
        rep(i,n){
            if(maxn/a[i] < ans-1){
                cout << -1 << endl;
                bk = true;
                break;
            }
            ans *= a[i];
        }
        if(!bk){
            if(maxn < ans) cout << -1 << endl;
            else cout << ans << endl;
        }
    }
}


Measured memory_bytes: 4028
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 3e2 + 3, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int h, w, e[N][N] = { }, cntb;
bool vis[N][N] = { };
char grid[N][N] = { };
inline bool check(int x, int y) {
	return (x >= 1 && x <= h && y >= 1 && y <= w && grid[x][y] == '.'
			&& !vis[x][y]);
}
inline void BFS(pii node) {
	queue<pii> q;
	q.push(node);
	vis[node.F][node.S] = true;
	e[node.F][node.S] = 1;
	while (!q.empty()) {
		pii a = q.front();
		q.pop();
		lp(i,0,3)
		{
			int x = dx[i] + a.F;
			int y = dy[i] + a.S;
			if (check(x, y)) {
				q.push( { x, y });
				vis[x][y] = true;
				e[x][y] = e[a.F][a.S] + 1;
				if (x == h && y == w)
					break;
			}
		}
	}
	if (!vis[h][w])
		puts("-1");
	else
		cout << (h * w - cntb - e[h][w]) << "\n";
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	cin >> h >> w;
	lp(i,1,h)
	{
		lp(j,1,w)
		{
			cin >> grid[i][j];
			cntb += (grid[i][j] == '#');
		}
	}
	BFS( { 1, 1 });
	return 0;
}


Measured memory_bytes: 384
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
res = 0
for i, a in enu(A):
    v1 = i+a
    v2 = i-a
    res += d[v2]
    d[v1] += 1
print(res)

Measured memory_bytes: 61720
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        
        System.out.println(a + (int)Math.pow(a,2) + (int)Math.pow(a,3));
    }
}


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

using namespace std;

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if(a[0] == 5 and a[1] == 5 and a[2] == 7) {
    puts("YES");
  } else {
    puts("NO");
  }
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,k,a[MAXN],sum[MAXN];
ll preodd[MAXN],preeven[MAXN],sufodd[MAXN],sufeven[MAXN];
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    for(ll i=1;i<=n;i++)
    {
        preodd[i]=min(preeven[i-1]+(1-(a[i]&1)),min(preodd[i-1]+(1-(a[i]&1)),sum[i]));
        preeven[i]=min(preeven[i-1]+(a[i]<2?2-a[i]:a[i]&1),sum[i]);
    }
    for(ll i=n;i>=1;i--)
    {
        sufodd[i]=min(sufeven[i+1]+(1-(a[i]&1)),min(sufodd[i+1]+(1-(a[i]&1)),sum[n]-sum[i-1]));
        sufeven[i]=min(sufeven[i+1]+(a[i]<2?2-a[i]:a[i]&1),sum[n]-sum[i-1]);
    }
    ll ans=INF;
    for(ll i=0;i<=n;i++) 
    {
        ans=min(ans,preodd[i]+sufeven[i+1]);
        ans=min(ans,preeven[i]+sufodd[i+1]);
        ans=min(ans,preeven[i]+sufeven[i+1]);
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    
    int a[M],b[M];
    
    for(int i=0 ; i<M ; i++){
        cin >> a[i] >> b[i];
    }
    
    bool r1[N+10],r2[N+10];
    
    for(int i=0 ; i<N+10 ; i++){
        r1[i] = r2[i] = 0;
    }
    
    for(int i=0 ; i<M ; i++){
        if(a[i] == 1){
            r1[b[i]] = true;
        }
        
        if(b[i] == N){
            r2[a[i]] = true;
        }
    }
    
    
    bool res = false;
    for(int i=1 ; i<N ; i++){
        if(r1[i]&& r2[i]) res = true;
    }
    
    if(res) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int l,m=0,a[62][3],tot=0,n=1,x=1;
inline void add(int aa,int b,int c){
	a[++m][0]=aa;
	a[m][1]=b;
	a[m][2]=c;
	return ;
}
int main(){
    scanf("%d",&l);
    l--;
    for(int i=1;i<20&&l;i++,x<<=1){
        if(x>l) break;
        add(i,i+1,x),add(i,i+1,0);
        l-=x;
		tot+=x;
		n=i+1;
    }
    if(l){
        for(int i=n;i;i--){
            if(1<<(i-1)<=l){
                l-=(1<<(i-1));
                add(i,n,tot+1);
                tot+=(1<<(i-1));
            }
        }
    }
    printf("%d %d\n",n,m);
    for(int i=1;i<=m;i++) printf("%d %d %d\n",a[i][0],a[i][1],a[i][2]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l,n;
    ll ans[61][3];
    cin >> l;
    rep(i,1,20){
        if ((1<<i) <= l && l < (1<<(i+1))){
            n = i;
            break;
        }
    }
    rep(i,n){
        ans[2*i][0] = i+1;
        ans[2*i][1] = i+2;
        ans[2*i][2] = (1<<i);
        ans[2*i+1][0] = i+1;
        ans[2*i+1][1] = i+2;
        ans[2*i+1][2] = 0;
    }
    ll c = 2*n;
    ll d = (1<<n);
    rep(i,n){
        if ((1<<i)&(l-(1<<n))){
            ans[c][0] = i+1;
            ans[c][1] = n+1;
            ans[c][2] = d;
            d += (1<<i);
            c++;
        }
    }
    PRINT(n+1 << " " << c);
    rep(i,c){
        PRINT(ans[i][0] << " " << ans[i][1] << " " << ans[i][2]);
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=6e6+10;

int n,a[N],val[N],suf[N];
int pos[N][2],mx[2],mn[2][2],le[2][2];
char ans[N];

struct BIT{
	int t[N],tg[M],vl[M],cnt;
	inline void ad(int x,int vv)
	{
		for(;x<=n;x+=(x&(-x))){
			tg[++cnt]=x;vl[cnt]=t[x];
			t[x]=max(t[x],vv);
		}
	}
	inline int get(int x)
	{
		int re=-1e9;
		for(x=min(x,n);x;x-=(x&(-x))) re=max(re,t[x]);
		return re;
	}
	inline void reback(int x){for(;cnt>x;t[tg[cnt]]=vl[cnt--]);}

}bit[2];

int main(){
	scanf("%d",&n);
	int i,j,k,x,y,cur=n+1,ptr,nq=0;
    for(i=1;i<=n;++i){
    	scanf("%d",&a[i]);
    	a[i]=n+1-a[i];
    	if(cur>a[i]){
    		cur=a[i];val[i]=2;
    	}else val[i]=1;
    }
    memset(bit[1].t,0x8f,sizeof(bit[1].t));
    for(i=n;i;--i) suf[i]=suf[i+1]+(val[i]==2);
    for(i=n;i>1;--i){
    	 for(j=0;j<2;++j) mx[j]=max(0,bit[j].get(a[i]));
    	 for(j=0;j<2;++j){
    	 	x=mx[j]+val[i];
    	 	bit[x&1].ad(a[i],x);
    	 }
    	 for(j=0;j<2;++j) pos[i][j]=bit[j].cnt;
    }
    mn[0][0]=mn[0][1]=n+1;
    for(i=1;i<=n;++i){
    	nq^=1;
        if(i<n)	for(j=0;j<2;++j) bit[j].reback(pos[i+1][j]);
		for(j=0;j<2;++j){
			for(k=0;k<2;++k) mn[nq][k]=mn[nq^1][k],le[nq][k]=le[nq^1][k];
    		if(a[i]<mn[nq^1][j]){mn[nq][j]=a[i];le[nq][j]=le[nq^1][j]+1;}
    		ptr= i==n?(le[nq][0]==le[nq][1]):0;
    		if(i<n){
    			for(k=0;k<2;++k){
    				x=le[nq][k]-le[nq][k^1]+suf[i+1];
    				if(x>=0 && x<=bit[x&1].get(mn[nq][k^1])){ptr=1;break;}
    			}
    		}
    		if(ptr){ans[i]='0'+j;break;}
    	}
    	if(!ans[i]){printf("-1");return 0;}
    }
    for(i=1;i<=n;++i) putchar(ans[i]);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    set<string> s;
    for (int i = 0; i < n; i++) {
        string a;
        cin >> a;
        s.insert(a);
    }
    cout << s.size();
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> g1(n), g2(n);

  g1[0] = a[0];
  for(int i = 1; i < n; ++i) g1[i] = __gcd(g1[i-1], a[i]);

  reverse(ALL(a));
  g2[0] = a[0];
  for(int i = 1; i < n; ++i) g2[i] = __gcd(g2[i-1], a[i]);

  reverse(ALL(g2));
  reverse(ALL(a));

  ll ans = max(g1[n-2], g2[1]);
  for(int i = 1; i < n-1; ++i) {
    chmax(ans, __gcd(g1[i-1], g2[i+1]));
  }

  cout << ans << endl;
}


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

int main() {
	int n;
	cin >> n;
	bool kaeru = false;
	for(int i=0;i<n/7+1;i++){
		for(int j=0;j<n/4+1;j++){
			if((i*7+j*4)==n){
				kaeru = true;
				break;
			}
		}
		if(kaeru == true) break;
	}
	
	if(kaeru) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define VMAX 50
#define EMAX 500
#define DMAX 20
#define TRUE 1
#define FALSE 0
#define NOTUSED 0
#define END -1
#define ROOT -1

void insertionSort(vector<int> a, int n){
    REP(i,n){
        int v=a[i];
        int j=i-1;
        // bool restored=false;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
            // restored=true;
        }
        a[j+1]=v;
        // if(restored){
            REP(j,n){
                cout<<a[j];
                if(j<n-1){
                    cout<<" ";
                }else{
                    cout<<endl;
                }
            }
        // }        
    }
}

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

    vector<int> a(n);
    REP(i,n){
        cin>>a[i];
    }

    // REP(i,n){
    //     cout<<a[i];
    //     if(i<n-1){
    //         cout<<" ";
    //     }else{
    //         cout<<endl;
    //     }
    // }

    insertionSort(a,n);
}


Measured memory_bytes: 3152
N=int(input())
B=[1]*55556

B[0]=0
B[1]=0
for i in range(2,55556):
    if B[i]==0:continue
    temp=i
    cnt=2
    while temp*cnt<=55555:
        B[temp*cnt]=0
        cnt+=1
PN=[]
for i in range(2,55556):
    if B[i]:
        PN.append(i)

for i in range(1,10,2):
    cnt=1
    ans=[2]
    for p in PN:
        if p%10==i:
            ans.append(p)
            cnt+=1
            if cnt==N:
                print(*ans)
                exit()



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

using namespace std;
using ll=long long;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h.rbegin(),h.rend());
    for(int i=0;i<k;i++){
        if(i>=n){
            break;
        }
        h[i]=0;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import numpy as np
import bisect
INF = 10**11
def solve(a, b, q, s, t, x):
    for xi in x:
        si = bisect.bisect_left(s, xi)
        ti = bisect.bisect_left(t, xi)
        sl = s[si-1]
        tl = t[ti-1]
        sr = s[si]
        tr = t[ti]
        ans = min([
            max(sr-xi, tr-xi),
            max(xi-sl, xi-tl),
            (sr-xi+sr-tl),
            (xi-tl+sr-tl),
            (tr-xi+tr-sl),
            (xi-sl+tr-sl)
        ])
        print(ans)

a, b, q = map(int, input().split())
s = np.asarray([int(input()) for i in range(a)] + [-INF, INF], dtype=int)
t = np.asarray([int(input()) for i in range(b)] + [-INF, INF], dtype=int)
x = np.asarray([int(input()) for i in range(q)], dtype=int)
s.sort()
t.sort()
solve(a,b,q,s,t,x)

Measured memory_bytes: 18308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    auto a = make_vec<int>(3, 3);
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    while (n--) {
        int b;
        cin >> b;
        rep(i, 3) rep(j, 3) if (a[i][j] == b) a[i][j] = 0;
    }
    bool ok = 0;
    ok |= (a[0][0] + a[0][1] + a[0][2] == 0);
    ok |= (a[1][0] + a[1][1] + a[1][2] == 0);
    ok |= (a[2][0] + a[2][1] + a[2][2] == 0);

    ok |= (a[0][0] + a[1][0] + a[2][0] == 0);
    ok |= (a[0][1] + a[1][1] + a[2][1] == 0);
    ok |= (a[0][2] + a[1][2] + a[2][2] == 0);

    ok |= (a[0][0] + a[1][1] + a[2][2] == 0);
    ok |= (a[2][0] + a[1][1] + a[0][2] == 0);
    cout << (ok ? "Yes" : "No") << endl;
}


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

int main()
{   int n;
int flag[105]={0};
    cin>>n;
    int ans = 0;
    while(n--)
    {
        int t;
        scanf("%d",&t);
        if(flag[t] == 0 )
            ans++;
        flag[t]++;
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
def main():
    K, N = map(int, input().split())
    *a, = map(int, input().split())
    a.append(K + a[0])

    b = [a1 - a0 for a1, a0 in zip(a[1:], a)]
    tot = sum(b)
    ret = tot - max(b)
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

using namespace std;

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

  int A, B;
  cin >> A >> B;

  string U;
  cin >> U;

  if (U == S) {
    A--;
  } else {
    B--;
  }

  cout << A << " " << B << endl;

  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(){

  int h,i,j,k,flag,N,cnt=0;

  scanf("%d",&N);
  int A[N];

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  flag=1;
  i=0;
  while(flag){
    flag=0;
    for(j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
	h=A[j];
	A[j]=A[j-1];
	A[j-1]=h;
	flag=1;
	cnt++;
      }
    }
    i++;
  }

  printf("%d",A[0]);
  for(k=1;k<N;k++){
    printf(" %d",A[k]);
  }
  printf("\n%d\n",cnt);

  return 0;
}
    
	



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

//typedef long long ll;
int main(){
    int N;
    cin>>N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin>>L.at(i);
    }
    sort(L.begin(),L.end());
    reverse(L.begin(),L.end());
    int cnt=0;
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            if(L.at(i)>2*L.at(j)){
                break;
            }
            int c=j+1;
            for(int k=j+1;k<N;k++){
                if(L.at(i)-L.at(j)<L.at(k)){
                    cnt++;
                }
                else{
                    break;
                }
            }
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 384
program main;
var	
	n, m, i, cnt, sum : longint;
    a : array[1..1000] of longint;
begin
	readln(n, m);
    cnt := 0;
    sum := 0;
    for i := 1 to n do begin
    	read(a[i]);
        sum := sum + a[i];
   end;
   for i := 1 to n do begin
   		if(a[i]*4*m >= sum)
        	then inc(cnt);
   end;
   if cnt >= m
   		then writeln('Yes')
        else writeln('No');
end.

Measured memory_bytes: 1380