akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint n, m;
    cin >> n >> m;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
        --a[i];
    }

    vector<lint> imos(m + 1);
    vector< vector<lint> > v(m);
    rep(i, n - 1){
        if(a[i] <= a[i + 1]){
            ++imos[a[i] + 1];
            --imos[a[i + 1]];
        }else{
            ++imos[a[i] + 1];
            --imos[m];
            ++imos[0];
            --imos[a[i + 1]];
        }
        v[a[i + 1]].push_back(i);
    }

    reps(i, m){
        imos[i] += imos[i - 1];
    }

    lint now = 0;
    rep(i, n - 1){
        now += min((a[i + 1] - a[i] + m) % m, a[i + 1] + 1LL);
    }

    lint ans = now;
    REP(x, 1, m){
        for(auto i : v[x - 1]){
            now += (a[i + 1] - a[i] + m) % m - 1LL;
        }
        now -= imos[x - 1];
        ans = min(ans, now);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 100011
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    ll a[SZ], sum[SZ], even[SZ];
    
    int solve(){
      ll n,q;
      cin >> n >> q;
      a[0]-=1000000000000000000LL;
      rep(i, 1, n + 1) {
        cin >> a[i];
        sum[i] = sum[i-1] + a[i];
        even[i] = even[i-1] + a[i]*(i&1 ? 0:1);
      }

      while(q--){
        ll x;
        cin >> x;

        if(x >= a[n]) { cout << (n&1 ? sum[n]-even[n] : even[n]) << endl; continue; }
        
        ll pos = lower_bound(a+1, a+n+1, x) - a;
        ll l = pos - 1, r = n;
        while(l+1<r){
          ll mid = (l+r)/2;
          ll numr = n - mid + 1;
          ll numl = mid - ( lower_bound(a, a+n+1, 2*x - a[mid]) - a );
          numr - numl <= 1 ? r = mid : l = mid;
        }
        ll qq = n- 2*(n - r + 1);
        ll ans = sum[n] - sum[r-1];
        qq&1 ? ans+=sum[qq]-even[qq] : ans+=even[qq];
        cout << ans << endl;
      }
    } 
    
   int main() {
       fastio
       solve();
    }
    /*
    1 2 3 5 7 9 12 14 16 17 18 21 25 29 34 35 48 59
    */

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


using namespace std;

int main(){
  int N,K;
  
  cin>>N>>K;
  vector<int> stick(N);
  
  for(int &x:stick){
    cin>>x;
  }
  
  sort(stick.rbegin(),stick.rend());
  int ans=0;
  for(int i=0;i<K;++i){
    ans+=stick[i];
  }
  
  
  cout<<ans<<endl;
}

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

int main()
{    
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

N, X = map(int, input().split())

def get_a(n):
    if n == 0:
        return 1
    else:
        return get_a(n - 1) * 2 + 3

def get_p(n):
    if n == 0:
        return 1
    else:
        return get_p(n - 1) * 2 + 1

def solver(n, x):
    a = get_a(n)
    p = get_p(n)
    if x >= a:
        ans = p
    elif x == 0:
        ans = 0
    elif 1 <= x < (1 + a) // 2:
        ans = solver(n - 1, x - 1)
    elif x == (1 + a) // 2:
        ans = get_p(n - 1) + 1
    elif (1 + a) // 2 < x < a:
        ans = solver(n - 1, x - get_a(n - 1) - 2) + get_p(n - 1) + 1

    return ans

def main():
    print(solver(N, X))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
X, Y = map(int, input().split())
M = 1000000007

def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result


if (2*Y - X) < 0:
    print(0)
elif (2*X - Y) < 0:
    print(0)
else:
    if (X - 2*Y) % 3 != 0 or (2*X - Y) % 3 != 0:
        print(0)
    else:
        a = (2 * Y - X) // 3
        b = (2 * X - Y) // 3
        ans = cmb(a+b, a)
        ans = ans % M
        print(ans)

Measured memory_bytes: 44032
// at_abc156d.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll mod(ll cur) {
    return (cur % MOD + MOD) % MOD;
}
ll pow2(ll base, ll cur) {
    if (cur == 0)return 1;
    ll temp = mod(pow2(base,cur / 2));
    if (cur & 1) {   
        temp = mod(temp * temp);
        temp = mod(temp * base);
        
        return mod(temp);
    }
    else {
        temp = mod(temp * temp);
        return mod(temp);
    }
    
}
ll combo(ll n, ll k) {
    ll temp = 1;
    ll idx = 0;
    while (idx<k) {
        temp *= ((ll)n - idx);temp = mod(temp);
        idx++;
    }
 //  cout << temp << " b\n";
    for (ll i = 1;i <= k;i++) {
  //      cout << i << " " << mod(pow2(i, MOD-2)) << "\n";
        temp *= mod(pow2(i,MOD-2));
        temp = mod(temp);
    }
    return temp;
}
int main()
{
   // cout << pow2(10, MOD - 2);
    ll num, a, b;cin >> num >> a >> b;
   // cout << pow2(2, 38);
    //cout << combo(num, a) << " "<<combo(num,b)<<" combos 
//cout << combo(num, b) << "\n";
//    cout << pow2(2, num)<<" "<<combo(num,a)<<" "<< combo(num,b)<<"\n";

    ll ans = (ll)pow2(2, num) - (ll)combo(num, a) - (ll)combo(num, b) - 1;
   // cout << ans << "\n";
    ans = mod(ans);
    cout << ans<<"\n";
}



Measured memory_bytes: 888
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char s;
	cin>>s;
	if(s>='a' && s<='z') cout<<'a'<<endl;
	else if(s>='A' && s<='Z') cout<<'A'<<endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
matrix mat(100050);
vi group(100050,0);
int ctr=1;
void dfs(int n){
    for(auto nxt:mat[n]){
        if(group[nxt]!=0) continue;
        group[nxt]=ctr;
        dfs(nxt);
    }
    return;
}

void solve(){
    int n,m;
    cin >> n >> m;
    rp(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--;
        y--;
        mat[x].pb(y);
        mat[y].pb(x);
    }
    
    rp(i,n){
        if(group[i]!=0) continue;
        dfs(i);
        ctr++;
    }
    print(ctr-1);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main() {
    int x;
    int i = 1;
    while(i <= 10000) {
    cin >> x;
    if ( x == 0 ) break;
        cout << "Case" << " " << i << ":" << " " << x << endl;
        i = i + 1;
    }
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
inline int read(){
	#define gc getchar
	bool f=1;
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))f^=ch==gc(),ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return f?ans:-ans;
	#undef gc
}
const int mod=998244353;
typedef long long ll;
inline int add(int a,int b){return (a+=b)<mod?a:a-mod;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline int mul(int a,int b){return (ll)a*b%mod;}
inline void Add(int&a,int b){(a+=b)<mod?a:a-=mod;}
inline void Dec(int&a,int b){(a-=b)<0?a+=mod:a;}
inline void Mul(int&a,int b){a=(ll)a*b%mod;}
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,Mul(a,a))if(p&1)Mul(ret,a);return ret;}
const int N=2505;
int n,m,P,cnt[N];
vector<int>e[N],val[N];
ll dis[N];
bool ban[N],in[N];
const double eps=1e-7;
inline bool check(double x){
	queue<int>q;
	for(ri i=1;i<=n;++i)in[i]=0,cnt[i]=0,dis[i]=-1e9;
	dis[1]=0,q.push(1);
	while(q.size()){
		int x=q.front();
		q.pop();
		in[x]=0;
		for(ri i=0,v;i<e[x].size();++i){
			if((dis[v=e[x][i]])<dis[x]+val[x][i]){
				if(ban[v])continue;
				dis[v]=dis[x]+val[x][i];
				if(!in[v]){
					in[v]=1;
					++cnt[v];
					if(cnt[v]>=n){
						puts("-1");
						exit(0);
					}
					q.push(v);
				}
			}
		}
	}
	cout<<max(0ll,dis[n]);
}
inline bool dfs(int p){
	if(in[p])return 0;
	if(p==n)return 1;
	in[p]=1;
	for(ri i=0;i<e[p].size();++i)if(dfs(e[p][i]))return 1;
	return 0;
}
int main(){
	n=read(),m=read(),P=read();
	for(ri i=1,u,v,w;i<=m;++i){
		u=read(),v=read(),w=read()-P;
		e[u].push_back(v),val[u].push_back(w);
	}
	for(ri i=1;i<=n;++i){
		memset(in,0,sizeof(in));
		if(!dfs(i))ban[i]=1;
	}
	check(0);
	return 0;
}

//test

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  double A, B, C, D, E, F, n = -1;
  cin >> A >> B >> C >> D >> E >> F; 
  pair<int, int> ans;
  A *= 100, B *= 100;

  for(int i = 0; i <= 50; i++){
    for(int j = 0; j <= 50; j++){
      double water = A*i+B*j;
      if(water >= F)continue;
      for(int k = 0; k <= 2500; k++){
	for(int l = 0; l <= 2500; l++){
	  double suger = C*k+D*l;
	  if(water+suger <= F && suger <= water/100*E && n < (100*suger)/(water+suger)){
	    n = (100*suger)/(water+suger);
	    ans = mp(water + suger, suger);
	  }
	}
      }
    }
  }

  cout << ans.first << " " << ans.second << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int sum = 0;
		int temp = i;
		while (temp) {
			sum += temp % 10;
			temp /= 10;
		}
		if (sum >= a && sum <= b) ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b;
  if(a%1000==0){
    b=a/1000;
  }
  else{
    b=a/1000+1;
  }
  cout<<b*1000-a;
}
  

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int solve(string s, char c){
    int n = s.size();
    bitset<100> bs;
    for(int i = 0; i < n; ++i)
        if(s[i] == c)
            bs.set(i);
    if(bs.count() >= n)
        return 0;
    //cout << c << ' ' << bs << '\n';
    for(int times = 1; times <= n; ++times){
        bs = bs | (bs>>1);
        //cout << bs << '\n';
        bool ok = true;
        for(int i = 0; i < n-times; ++i)
            if(bs[i] != 1)
                ok = false;
        if(ok)
            return times;
    }
    return n;
}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    //solve(s,'r');
    //return 0;
    for(char c = 'a'; c <= 'z'; ++c){
        ans = min(ans,solve(s,c));
        //cout << c << ' ' << ans << '\n';
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)

x4 = x3 - (x2-x1)
y4 = y3 - (y2-y1)

print(x3,y3,x4,y4)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
set<int>se;
int main(){
   int n,m;
   cin>>n;
   for(int i=0;i<n;i++){
   	cin>>m;
   	se.insert(m);
   }
   int len=se.size();
   if(len==n) cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int p, q, r;
	cin>>p>>q>>r;
	cout<<p+q+r-max({p, q, r})<<'\n';
	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
 
class dice{
public:
    int d[6], tmp[6];
    dice(int n[6]){
        for (int i = 0; i < 6; i++){
            d[i] = n[i];
        }
    }
    void throwdice(char c){
        for (int i = 0; i < 6; i++){
            tmp[i] = d[i];
        }
        if (c == 'N'){
            d[0] = tmp[1];
            d[1] = tmp[5];
            d[2] = tmp[2];
            d[3] = tmp[3];
            d[4] = tmp[0];
            d[5] = tmp[4];
        }
        else if (c == 'E'){
            d[0] = tmp[3];
            d[1] = tmp[1];
            d[2] = tmp[0];
            d[3] = tmp[5];
            d[4] = tmp[4];
            d[5] = tmp[2];
        }
        else if (c == 'W'){
            d[0] = tmp[2];
            d[1] = tmp[1];
            d[2] = tmp[5];
            d[3] = tmp[0];
            d[4] = tmp[4];
            d[5] = tmp[3];
        }
        else{
            d[0] = tmp[4];
            d[1] = tmp[0];
            d[2] = tmp[2];
            d[3] = tmp[3];
            d[4] = tmp[5];
            d[5] = tmp[1];
        }
    }
};
int main()
{
    int n[6];
    for (int i = 0; i < 6; i++){
        cin >> n[i];
    }
    dice dice1(n);
    string dir;
    cin >> dir;
    for (int i = 0; i < dir.length(); i++){
        dice1.throwdice(dir[i]);
    }
    cout << dice1.d[0] << endl;
 
 
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0){
            return 0;
        }
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(i==0||i==h-1||j==0||j==w-1){
                    cout<<"#";
                }
                else{
                    cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long t,i,j,n,a,b,c,d,ans,A,B;
	string s,s1,s2,s3;
	cin>>n>>t;
	long arr[n];
	ans=n*t;
	c=0;
	for(i=0;i<n;i++)cin>>arr[i];
	for(i=1;i<n;i++)
	{
	    c+=arr[i-1]+t-arr[i]>0?arr[i-1]+t-arr[i]:0;
	}
	cout<<ans-c;
    }
	return 0;
}

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

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;

int main(){
    string s; cin >> s;
    string h = "hi";

    bool f = false;
    rep(i,5){
        if(h == s) f = true;
        h += "hi";
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
using namespace std;

#define N 200000

int x[N];
int sx[N];

int main()
{
	int ans;
	int n;

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

	sort(sx, sx+n);

	int j = (n-1)/2;
	int b = sx[j];

	for( int i = 0; i < n; i++ ) {
		if( x[i] <= b ) {
			ans = sx[j+1];
		}
		else {
			ans = b;
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3712
x,k,d = map(int,input().split())
result = 0
if abs(x) > k * d:
    result = abs(x) - k*d
else:
    g = abs(x) // d
    if (k - g) % 2 == 0:
        result = abs(x) - d*g
    else:
        result = d*(g+1) - abs(x)
print(result)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	sort(A.begin(), A.end());
	vector<pair<int, int>> xy;
	for (int i = 1; i < N - 1; ++i) {
		if (A[i] > 0) {
			xy.emplace_back( A[0], A[i] );
			A[0] -= A[i];
		} else {
			xy.emplace_back( A.back(), A[i] );
			A.back() -= A[i];
		}
	}
	cout << A.back() - A[0] << "\n";
	for (auto p : xy) {
		cout << p.first << " " << p.second << "\n";
	}
	cout << A.back() << " " << A[0] << "\n";

	return 0;
}


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

using namespace std;

typedef long long int ll;

const ll MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> p(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i == 0){
			p[i] = a[i];
		}else{
			p[i] = (p[i-1] + a[i] ) % MOD;
		}
	}
	ll res = 0;
	for(int i = 0; i < n; i++){
		ll tmp = a[i] * (p[n-1] - p[i] + MOD) % MOD;
		res = (res + tmp)%MOD;
	}
	cout << res << "\n";
	return 0;
}


Measured memory_bytes: 6368
#include<stdio.h>
int main(void){
 int x, y;
 while( 1 ){
  scanf("%d %d",&x, &y);
  if(x == 0 && y == 0){
   break;
   }
  if(x < y){
   printf("%d %d\n",x, y);
   }
  if(x >= y){
   printf("%d %d\n",y ,x);
   }
 }
 return 0;
 }



Measured memory_bytes: 2044
import math

n = int(input())

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

s_abc = {}
multiple = []
count = 0
for i in range(n):
    abc_dict = dict.fromkeys(alphabet, 0)
    s = input()
    for c in s:
        abc_dict[c] += 1
    lst = []
    for x in abc_dict.values():
        lst.append(str(x))
    strlst = ''.join(lst)
    if strlst in s_abc:
        s_abc[strlst] += 1
    else:
        s_abc[strlst] = 1
for v in s_abc.values():
    if v != 1:
        count += math.factorial(v) // (math.factorial(v - 2) * 2)

print(count)


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

struct Interval {
  int start, slutt;
};
bool operator<(Interval a, Interval b) {
  return a.start < b.start;
}

Interval input[1000000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n,k,ans;
  int h[200000];
  cin >> n>>k;
  ll yn=0; 
  for (int j=0;j<n;j++){
    cin>>h[j];
  }
  std::sort(h,h+n);

  for (int j=0;j<n-k;j++){
    yn+=h[j];
  }
  cout<<yn<<endl;	  

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
const ll mod = 1000000007;

int main(){
  string L; cin >> L;
  int N = sz(L);
  // dp[i][smaller?] i桁決めて条件を満たす(a,b)
  ll dp[101000][2];
  dp[0][0] = 1;
  rep(i,N){
    if(L[i]=='0'){
      dp[i+1][1] = dp[i][1]*3;
      dp[i+1][0] = dp[i][0];
    }
    if(L[i]=='1'){
      dp[i+1][1] = dp[i][0] + dp[i][1]*3;
      dp[i+1][0] = dp[i][0]*2;
    }
    dp[i+1][0]%=mod;
    dp[i+1][1]%=mod;
  }
  cout << (dp[N][0]+dp[N][1])%mod << endl;
  return 0;
}


Measured memory_bytes: 5272
#include <iostream>

using namespace std;

int a[105];

int main()
{
   int n , x , s , ans = 1e9 , mx = 0;
   cin >> n;
   for(int i = 1 ; i <= n ; i++)
   {
       cin >> x;
       a[i] = x;
       mx = max(mx , x);
   }
   for(int i = 0 ; i <= mx ; i++)
   {
       s = 0;
       for(int j = 1 ; j <= n ; j++)
        s += (a[j] - i) * (a[j] - i);
       ans = min(ans , s);
   }
   cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let (w, h, x, y) = {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let mut input = input.split_whitespace();
        
        (
            input.next().unwrap().parse::<i32>().unwrap(),
            input.next().unwrap().parse::<i32>().unwrap(),
            input.next().unwrap().parse::<i32>().unwrap(),
            input.next().unwrap().parse::<i32>().unwrap(),
        )
    };

    let area: f64 = (w as f64)*(h as f64);

    let count = if w==x*2 && h==y*2 { 1 } else { 0 };

    println!("{} {}", area/2., count );
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x,y,m;
int main()
{
	scanf("%d",&n);
	x=n*800;
	y=n/15*200;
	m=x-y;
	printf("%d\n",m);
	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 repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int n;
   cin>>n;
   map<string, int> ma;
   rep(i, n){
      string s;
      cin>>s;
      ma[s]++;
   }

   string li[]={"AC", "WA", "TLE", "RE"};
   for(string w : li) cout << w << " x " << ma[w] << endl;
   return 0;
}


Measured memory_bytes: 3632
import heapq
n,m = map(int, raw_input().split(' '))

xis = map(int, raw_input().split())
xis.sort()
distances = [v- u for u,v in zip(xis,xis[1:])]
distances.sort(key = lambda x:-x)
print sum(distances[n-1:] or [0])

Measured memory_bytes: 89856
N = input()
A = [map(int, raw_input().split()) for _ in range(N)]
S = [0]*N
for i in range(3):
    T = [0]*101
    for j in range(N):
        T[A[j][i]] += 1
    for j in range(N):
        if T[A[j][i]]==1:
            S[j] += A[j][i]
for s in S:
    print s

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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int c = 0;
    FOR(i,0,n)
    {
        int x;
        cin>>x;
        if(x>=k) c++;
    } 
    cout<<c<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define s(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main() {
	int a, b, c,agc=0;
	cin >> a >> b >> c;
	int ans=max(a, max(b, c));
	int abc = ans - a;
	abc += ans - b;
	abc += ans - c;
	if (abc % 2 == 0)agc = abc / 2;
	else agc = abc / 2 + 2;
	cout << agc << endl;
	return 0;
}

Measured memory_bytes: 256
while 1:
    n,m=map(int,raw_input().split())
    if n+m==0:
        break
    a = dict(zip(range(m),[0]*m))
    for i in range(n):
        c=map(int,raw_input().split())
        for j in range(m):
            a[j]+=c[j]
    for k,v in sorted(a.items(),key=lambda x:x[1],reverse=1):
        print k+1,
    print

Measured memory_bytes: 4268
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var A = input[0];
            var B = input[1];
            var H = input[2];
            var M = input[3];

            var hour = 30 * H + 0.5 * M;
            var minute = 6 * M;
            var angle = Math.Abs(hour - minute);
            var radian = angle * Math.PI / 180;

            Console.WriteLine(Math.Sqrt(A * A + B * B - 2 * A * B * Math.Cos(radian)));
        }
    }
}


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

using namespace std;
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; }

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
//const int INF = 1 << 30;
const ll INF = 1LL << 60;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

ll V, E;

struct edge { ll from, to, cost; };
vector<edge> es;

vector<ll> d;
bool negative;
bool can = true;

void shortest_path(int s) {
	d.resize(V, INF);
	d[s] = 0;

	for (int i = 0; i < V; i++) {
		bool update = false;
		for (int j = 0; j < E; j++) {
			edge e = es[j];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;

				if(i == V - 1) {
					negative = true;
					if (e.to == V - 1) can = false;
				}
			}
		}
		if (!update) break;
	}
}

ll n, m;

int main(void){
	cin>>n>>m; V = n; E = m;
	for (int i = 0; i < E; i++) {
		ll a, b, c; cin>>a>>b>>c;
		a--; b--; c = -c;
		es.push_back((edge){a, b, c});
	}

	shortest_path(0);

	if (!can) cout<< "inf" <<endl;
	else cout<< (-1) * d[V - 1] <<endl;
	
	return 0;
}

Measured memory_bytes: 384
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Scanner;
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collection;


 
public class Main{
	
        static final Scanner sc=new Scanner(System.in);
        static int D=sc.nextInt();
        static int N=sc.nextInt();
        
        public static void main(String[]args){
                if(N!=100){
                int x=(int)Math.pow(100,D);
                x=x*N;
                System.out.println(x);}else{
                        if(D==0){
                                System.out.println(101);
                        }else if(D==1){
                                System.out.println(10100);
                        }else if(D==2){
                                System.out.println(1010000);
                        }
                }

                

        }
        
        
        

		
	
}


Measured memory_bytes: 21844
def main():
    x1, y1, x2, y2 = map(int, input().split())
    a, b = x1 - x2, y1 - y2
    x3, y3 = x2 + b, y2 - a
    x4, y4 = x3 + a, y3 + b
    print(x3, y3, x4, y4)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h, w;
    int field[100][100] = {{}};
   
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        string temp;
        cin >> temp;
        for(int j = 0; j < w; j++){
            if(temp[j] == '.')
                field[i][j] = 0;
            else
                field[i][j] = 1;
        }
    }
    
    for(int i = 0; i < h; i++){
        int count_white = 0;
        for(int j = 0; j < w; j++)
            if(field[i][j] == 0)
                count_white++;
        if(count_white == w)
            for(int j = 0; j < w; j++)
                field[i][j] = -1;
    }
    
    for(int i = 0; i < w; i++){
        int count_white = 0;
        for(int j = 0; j < h; j++)
            if(field[j][i] == 0 || field[j][i] == -1)
                count_white++;
        if(count_white == h)
            for(int j = 0; j < h; j++)
                field[j][i] = -1;
    }

    for(int i = 0; i < h; i++){
        int count_output = 0;
        for(int j = 0; j < w; j++){
            if(field[i][j] == 0){
                cout << '.';
                count_output++;
            }
            else if(field[i][j] == 1){
                cout << '#';
                count_output++;
            }
        }
        if(count_output > 0)
            cout << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 256
double x[100],y[100],t,u,a,b,s;n,i,j,k,c;main(m){for(;m=scanf("%d",&n),j=i=n;printf("%d\n",m)){for(;j--;scanf("%lf,%lf",x+j,y+j));for(;j=--i;)for(;j--;)for(u=acos(hypot(a=x[j]-x[i],b=y[j]-y[i])/2),s=1,t=atan2(b,a);c=0,u<9&&s+3;s-=2)for(a=x[i]+cos(b=t+s*u),b=y[i]+sin(b),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}}

Measured memory_bytes: 0
#include<iostream>
#include<string>

using namespace std;

int main() {
    string masu;
    cin >> masu;
    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (masu[i] == '1')count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFindTree:
    """Disjoint-Set Data Structure
       Union-Find Tree
       complexity:
          init: O(n)
          find, unite, same: O(alpha(n))
       used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ)
    """
    def __init__(self, n):
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
M = 10 ** 5
uft = UnionFindTree(N + 2 * M)

for i in range(N):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    uft.unite(i, x + N)
    uft.unite(i, y + N + M)
x_dict, y_dict = dict(), dict()
for x in range(N, M + N):
    par_x = uft.find(x)
    x_dict[par_x] = x_dict.get(par_x, 0) + 1
for y in range(N + M, N + 2 * M):
    par_y = uft.find(y)
    y_dict[par_y] = y_dict.get(par_y, 0) + 1
ans = -N
for r in x_dict.keys():
    ans += x_dict.get(r, 0) * y_dict.get(r, 0)
print(ans)


Measured memory_bytes: 38508
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n, m;
    scan(n, m);
    auto p = readln.split.to!(int[]);
    p[] -= 1;

    auto uf = UnionFind(n);

    foreach (i ; 0 .. m) {
        int xi, yi;
        scan(xi, yi);
        xi--, yi--;
        uf.merge(xi, yi);
    }

    int ans;

    foreach (i ; 0 .. n) {
        if (uf.same(i, p[i])) {
            ans++;
        }
    }

    ans.writeln;
}




struct UnionFind {
    private {
        int _size;
        int[] _parent;
    }

    this(int N) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
    }
}













































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	bool flag = false;
	for (int i = 0; i < 3; ++i)
	{
		if (s[i] == s[i + 1])
		{
			flag = true;
		}
	}
	if (flag)
	{
		cout << "Bad" << endl;
	}
	else
	{
		cout << "Good" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
  string s,t;
  std::cin >> s>>t;
  sort(all(s));
  sort(rall(t));
  if(s<t)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    result = 0
    for i in range(N):
        if i==0:
            result += h[0]
        elif h[i] > h[i-1]:
            result += h[i] - h[i-1]
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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 FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
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(){
    ll a,b;
    cin>>a>>b;
    if(a%2==0){
        ll k=b-a+1;
        if(k%4==0){
            cout<<0<<endl;
        }
        if(k%4==1){
            cout<<b<<endl;
        }
        if(k%4==2){
            cout<<1<<endl;
        }
        if(k%4==3){
            cout<<(1^b)<<endl;
        }
    }
    else {
        ll k=b-a;
        if(k%4==0){
            cout<<(a^0)<<endl;
        }
        if(k%4==1){
            cout<<(a^b)<<endl;
        }
        if(k%4==2){
            cout<<(a^1)<<endl;
        }
        if(k%4==3){
            cout<<(a^1^b)<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll t;
ll ret = 0;
ll p[ARRAY];
ll invp[ARRAY];

void input() {
  IN(N);
  FOR(i, 1, N+1) {
    IN(t);
    p[i] = t;
    invp[t] = i;
  }
}

void solve() {
  multiset<ll> s;
  s.insert(0);
  s.insert(0);
  s.insert(N+1);
  s.insert(N+1);
  FORR(i, N, 1) {
    ll index = invp[i];
    ll w, x, y, z;
    auto itr = s.lower_bound(index);
    y = *itr;
    itr++;
    z = *itr;
    itr--;
    itr--;
    x = *itr;
    itr--;
    w = *itr;

    ll c = (x - w)*(y - index) + (index - x)*(z - y);
    // DEBUG(i);
    // DEBUG("=>");
    // DEBUG(w);
    // DEBUG(x);
    // DEBUG(y);
    // DEBUG(z);
    // DEBUG(c);
    // LN();
    ret += c * i;
    s.insert(invp[i]);
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


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

int main() {
    int x, y;
    cin >> x >> y;
    int a[7] = {1, 3, 5, 7, 8, 10, 12};
    int b[4] = {4, 6, 9, 11};

    if (count(a, a + 7, x) + count(a, a + 7, y) == 2)
        cout << "Yes" << endl;
    else if (count(b, b + 4, x) + count(b, b + 4, y) == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var s = cin.ReadIntArray(N);
            Array.Sort(s);
            var ans = s.Sum();
            var i = 0;
            while (ans % 10 == 0 && i != N)
            {
                if (s[i] % 10 != 0)
                {
                    ans -= s[i];
                }
                i++;
            }
            if(ans == s.Sum() && ans % 10 == 0)
            {
                WriteLine(0);
            }
            else
            {
                WriteLine(ans);
            }
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13396
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))

# M回の握手の幸福度最大化
# X以上になる握手を全て採用したときに、M通りを越える
# Xの最大値を求める

import bisect

ok=-1
ng=(10**10)+2

# x以上の握手をm通り以上作れるか
def isOk(x,m):
  cnt=0
  # 左手をループする
  for i in range(len(A)):
    left=A[i]
    minright=x-left
    # minright以上の数を数える
    cnt+=n-bisect.bisect_left(A,minright)
    if cnt>=m:
      return True
  return cnt>=m

while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOk(mid,m):
    ok=mid
  else:
    ng=mid

x=ok
# x以上となる幸福度を足し合わせる
# 足し合わせた握手がMを越える場合、xぴったりを足し過ぎている

# 効率化のため累積和を作成
Asum=[0]+A
for i in range(1,len(Asum)):
  Asum[i]=Asum[i-1]+Asum[i]
  
# Aの添字i以降を全て足すときは、
# Asum[-1]-Asum[i]

ans=0
cnt=0
for i in range(len(A)):
  left=A[i]
  minright=x-left
  start=bisect.bisect_left(A,minright)
  cnt+=n-start
  ans+=left*(n-start)+(Asum[-1]-Asum[start])
  
if cnt>m:
  ans-=(cnt-m)*x
  
print(ans)


Measured memory_bytes: 56896
#pragma GCC target("avx")
#include <cstdio>
#include <vector>

#include <cstdint>

constexpr bool parity32(std::uint_fast32_t c) noexcept {
  c ^= c >> 1;
  c ^= c >> 2;
  return ((c & 0x11111111) * 0x11111111 >> 28 & 0x1) != 0;
}

int scan() {
  int r = 0;
  int c;
  while ((c = getchar_unlocked() - '0') >= 0)
    r = r * 10 + c;
  return r;
}

int main() {
  const int n = scan();
  std::vector<std::vector<int>> t(n);
  for (int i = 0; i != n - 1; i += 1) {
    const int a = scan() - 1;
    const int b = scan() - 1;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  const int m = scan();
  const int s = 1 << m;
  std::vector<int> z(s, 0);
  {
    std::vector<int> x(n, 0);
    for (int i = 0; i != m; i += 1) {
      const int u = scan() - 1;
      const int v = scan() - 1;
      x[u] ^= 1 << i;
      x[v] ^= 1 << i;
    }
    const auto dfs = [&](const auto &dfs, int v, int p) -> void {
      for (int e : t[v]) {
        if (e != p) {
          dfs(dfs, e, v);
          z[x[e]] += 1;
          x[v] ^= x[e];
        }
      }
    };
    dfs(dfs, 0, n);
  }
  for (int w = 1; w != s; w <<= 1) {
    for (int i = 0; i != s; i += w << 1) {
      const int end = i + w;
      for (int j = i; j != end; j += 1) {
        z[j + w] += z[j];
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i != 1 << m; i += 1) {
    auto res = 1LL << z[s - 1 ^ i];
    if (__builtin_parity(i))
      res = -res;
    ans += res;
  }
  printf("%lld", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
	int i,a,b,c,x;
	i = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(x = a;x <= b;x++){
		if(c%x==0){
			i++;
		}
	}
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int answer = 0;
        for (int i = 0; i < 2; i++) {
            if (A < B) {
                answer += B;
                B -= 1;
            } else {
                answer += A;
                A -= 1;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
using namespace std;
int main(){
int n;
cin >> n;
for(int i =1;i <=9;i++){
    for(int j =1;j<=9;j++){
        if(n==i*j){
            cout << "Yes" << endl;
            return 0;
        }
    }
}
cout << "No" << endl;
    return 0;

}


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

int main() {
  int N;
  cin >> N;
  string s[N];
  int t[N];
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  string x;
  cin >> x;

  int start = 0;
  for (int i = 0; i < N; i++) {
    if (x == s[i]) start = i + 1;
  }

  int ans = 0;
  for (int i = start; i < N; i++) {
    ans += t[i];
  }

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

Measured memory_bytes: 256