akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int A[200000]={0};
int W[200000]={0};

using llong = long long;
llong inversion_num(int l,int r);
llong merge(int l,int r);

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

  cout << inversion_num(0,n) << endl;
  return 0;
}

llong inversion_num(int l,int r){
  //cout << "[" << l << "," << r << ")" << endl;
  if(l>=r-1) return 0;
  
  int m = (l+r)/2;

  llong l_invn = inversion_num(l,m);
  llong r_invn = inversion_num(m,r);
  llong m_invn = merge(l,r);

  return l_invn + r_invn + m_invn;
}

llong merge(int l,int r){
  int m = (l+r)/2;
  int i=l,j=m,k=0;
  llong cnt = 0;
  // l <= i && i < m , m <= j && j < r
  // 0 < k && k < r-l
  while(i<m&&j<r&&k<r-l){
    if(A[i]<=A[j]){
      W[k++] = A[i++];
    }else{
      W[k++] = A[j++];
      cnt += m-i;
    }
  }

  while(i<m){
    W[k++] = A[i++];
    //cnt += m-i;
  }
  while(j<r){
    W[k++] = A[j++];
    //cnt += m-i;
  }
  
  copy(W,W+(r-l),A+l);
  return cnt;
}

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

int main(){
	int N;
	cin>>N;
	vector<vector<int>>Days(N+10);
	vector<vector<int>>DP(N+10,vector<int>(3));
	int i,j,k;
	int a,b,c;
	for(i=1;i<=N;i++){
		cin>>a>>b>>c;
		Days[i].push_back(a);
		Days[i].push_back(b);
		Days[i].push_back(c);
		//cout<<"Day "<<i<<": "<<Days[i][0]<<" "<<Days[i][1]<<" "<<Days[i][2]<<endl;
	}
	DP[0].push_back(0);
	DP[0].push_back(0);
	DP[0].push_back(0);
	//cout<<"Maximums of day 0: "<<DP[0][0]<<" "<<DP[0][1]<<" "<<DP[0][2]<<endl;
	int maxi=0;
	for(i=1;i<=N;i++){
		for(j=0;j<3;j++){
			for(k=0;k<3;k++){
				if(DP[i-1][k]>maxi&&k!=j){
					maxi=DP[i-1][k];
				}
			}
			//cout<<"Maximum of day "<<i-1<<": "<<maxi<<endl;
			DP[i][j]=maxi+Days[i][j];
			maxi=0;
		}
		//cout<<"Maximums of day "<<i<<": "<<DP[i][0]<<" "<<DP[i][1]<<" "<<DP[i][2]<<endl;
	}
	for(i=0;i<3;i++){
		if(DP[N][i]>maxi){
			maxi=DP[N][i];
		}
	}
	cout<<maxi;
	return 0;
}


Measured memory_bytes: 11136
n = int(input())
ans = [0] * n
count = 0
for i in range(n):
    x = i + 1
    xx = x * x
    if  x * x >= n:
        break
    for j in range(n):
        y = j + 1
        yy = y * y
        if xx + yy + x * y>= n:
            break
        for k in range(n):
            z = k + 1
            zz = z * z
            kotae = xx + yy + zz + x * y + y * z + z * x
            if kotae > n:
                break
            ans[kotae-1] += 1
for i in range(n):
    print(ans[i])



Measured memory_bytes: 9440
// C - Tax increase
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    int a, b;
    cin >> a >> b;
    int ans = -1;
    for(int i=1010; i>0; i--){
        int ad=i*0.08, bd=i*0.1;
        if(ad==a && bd==b) ans = i;
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

int main(void){
    char s[305][305];
    ll h,w,k;
    scanf("%lld%lld%lld",&h,&w,&k);
    ll num[h][w],st[k][2],p=0;
    rep(i,0,h){
        scanf("%s",s[i]);
    }
    rep(i,0,h){
        rep(j,0,w){
            if(p==k) break;
            if(s[i][j]=='#'){
                st[p][0]=i;
                st[p][1]=j;
                p++;
            }
        }
    }
    p=0;
    ll late=-1;
    rep(i,0,h){
        if(p==k || i!=st[p][0]){
            if(p==0) late=i; 
            else{
                rep(j,0,w){
                    num[i][j]=num[i-1][j];
                }
            }
        }
        if(i==st[p][0]){
            if(p==k-1 || st[p+1][0]!=i){
                rep(j,0,w){
                    num[i][j]=p+1;
                }
                p++;
            }else{
                ll j=0;
                while(j<w){
                    rep(k,j,st[p][1]+1){
                        num[i][k]=p+1;
                    }
                    j=st[p][1]+1;
                    p++;
                    if(st[p][0]!=i) break;
                }
                rep(k,j,w){
                    num[i][k]=p;
                }
            }
        }
    }
    rrep(i,late,0){
        rep(j,0,w){
            num[i][j]=num[i+1][j];
        }
    }
    rep(i,0,h){
        rep(j,0,w) printf("%lld ",num[i][j]);
        PN;
    }
    // printf("\n");
    return 0;
}


Measured memory_bytes: 2816
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(" ");
            int n = int.Parse(input[0]);

            string[] arrayStr = new string[n];

            for (int i = 0; i < n; i++)
            {
                arrayStr[i] = Console.ReadLine();
            }

            Array.Sort(arrayStr);

            Console.WriteLine(string.Join("", arrayStr));
        }
    }
}


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

int main() {
  
  int n, m, l; cin >> n >> m >> l; int64_t A[n][m], B[m][l];
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      int64_t sum = 0;
      for (int k = 0; k < m; k++) {
        sum += A[i][k] * B[k][j];
      }
      cout << sum;
      if (j != l - 1) cout << " ";
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=b&&a<=c)cout<<a+max(b,c)*10+min(b,c)<<endl;
    else if(b<=c&&b<=a)cout<<b+max(a,c)*10+min(a,c)<<endl;
    else if(c<=b&&c<=a)cout<<c+max(b,a)*10+min(b,a)<<endl;
    return 0;
}

Measured memory_bytes: 256
def check(arr, mid, maxV):
    if arr[mid] < maxV:
        return True
    else:
        return False


def binSearch(arr, maxV):
    ok = -1
    ng = len(arr)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(arr, mid, maxV):
            ok = mid
        else:
            ng = mid
    return ok


def resolve():
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    B = sorted([int(i) for i in input().split()])
    C = sorted([int(i) for i in input().split()])
    BoverA = [0 for _ in range(N)]
    sumA = 0
    for i in range(N):
        a = binSearch(A, B[i])
        sumA += (a + 1)
        BoverA[i] = sumA
    sumA = 0
    for i in range(N):
        b = binSearch(B, C[i])
        if b >= 0:
            sumA += 1 * 1 * BoverA[b]
    print(sumA)


resolve()


Measured memory_bytes: 28916
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("Heisei")
    else:print("TBD")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


n = ip()                              #入力整数1つ
#n,k= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので
r = sum(a)
l = a[0]
r-= a[0]
s = abs(l-r)
for i in range(1,n-1):
	l+=a[i]
	r-=a[i]
	s = min(s,abs(l-r))
print(s)

Measured memory_bytes: 33912
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main() {
  int p,q,r;
  cin >> p >> q >> r;

  cout << (p+q+r)-max({p,q,r});
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long  A = sc.nextLong();
        long  B = sc.nextLong();

        System.out.println(calc(B) ^ calc(A-1));

    }
    static long calc(long lng){

        long ans = 0;
        for(int i=1; i< 50;i++){
            long period=  1L << i;
            long count2 = (lng+1)/period * period/2;
            long count = count2+ Math.max(0, (lng+1)%period - period/2);
//            System.out.println("period:"+period+" "+i+" "+count +" "+ count2 +" remainder:"+(lng+1)%period + " zeros:" + period/2);
            if(count % 2 ==1 ){
                ans += (1L << (i-1) );
            }
        }
//        System.out.println(lng +" "+ans);
        return ans;
    }

}


Measured memory_bytes: 22868
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] w = new int[n];
    int min = Integer.MAX_VALUE;
    for(int i=0; i<n; i++) {
      w[i] = Integer.parseInt(str[i]);
    } 
    Arrays.parallelPrefix(w,Integer::sum);
    
    for(int i=0; i<n; i++) {
      min = Math.min(min,Math.abs(w[i]-(w[n-1]-w[i])));
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 29780
#include <stdio.h>
int main(void){

    int sum , i;
    char num[1000];
    
    while(1){
        scanf("%s",num);
        if (num[0]=='0')break;
        for (sum=0,i=0; num[i]!='\0'; i++) {
            sum+=(num[i]-'0');
        }
        printf("%d\n",sum);
        }

    return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#define FOR(x,n) for(int x = 0; x < n; x++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
  int N; cin >> N;
  vector<pair<int,int>> A(N);
  FOR(x,N) cin >> A[x].first, A[x].second = x;
  sort(ALL(A));
  int cnt = 0;
  FOR(x,N)
    cnt += A[x].second % 2 != x % 2;
  cout << cnt/2 << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
char s[maxn];
ll val[maxn],premod[maxn];
int n;
ll P;
ll cnt[maxn];
inline ll quickpow(ll base,ll ind)
{
	ll ans=1;
//	base%=P;
//	if(!base)return 1;
	while(ind>0)
	{
		if(ind&1)ans=ans*base%P;
		ind>>=1;
		base=base*base%P;
	}
	return ans;
}
inline ll inv(ll base)
{
	return quickpow(base,P-2);
}
ll invten[maxn];
int main()
{
	scanf("%d%lld",&n,&P);
	scanf("%s",s);
	
	if(P==2)
	{
		ll ans=0;
		for(int i=0;i<n;i++)
		{
			if((s[i]-'0')%2==0)
			{
				ans+=(i+1);
			}
		}
		printf("%lld\n",ans);
		return 0;
	}
	else if(P==5)
	{
		ll ans=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='0'||s[i]=='5')
			{
				ans+=(i+1);
			}
		}
		printf("%lld\n",ans);
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		val[i]=(s[i-1]-'0')%P;
	}
	premod[0]=0;
	for(int i=1;i<=n;i++)
	{
		premod[i]=(premod[i-1]*10+val[i])%P;
//		cout<<i<<" "<<premod[i]<<endl;
	}
	invten[0]=1;
	invten[1]=inv(10);
	for(int i=2;i<=n;i++)
		invten[i]=(invten[i-1]*invten[1])%P;
	
	for(int i=1;i<=n;i++)
	{
		premod[i]=premod[i]*invten[i]%P;
//		cout<<premod[i]<<endl;
	}
	
	cnt[premod[0]]++;
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=cnt[premod[i]];
		cnt[premod[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

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

if n == 1:
	print(a[0])
elif n % 2 == 0:
	print(" ".join(map(str, a[1::2][::-1] + a[0::2])))
else:
	print(" ".join(map(str, a[0::2][::-1] + a[1::2])))

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

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

    int n, a, b;
    cin >> n >> a >> b;

    int train = n * a;
    int taxi = b;
    cout << min(train, taxi);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define ll long long 
#define mp make_pair
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const long double PI = acos(-1.0);
const ll Ma=1000000007;
const ll Maxi=1e18;
const ll Mini=-1e18;

int main()
{
   IOS;
  // #ifndef ONLINE_JUDGE
  //freopen("input.txt","r",stdin);
   //#endif
  ll ti;
  //cin>>ti;
  ti=1;
  
  while(ti>0)
  {
   ll n;
   cin>>n;
   ll dp[n+1][61];
   memset(dp,0,sizeof(dp));
   ll i,j;
   ll a[n+1];
   for(i=1;i<=n;i++)
   {
    cin>>a[i];
    ll x=a[i];
    for(j=0;j<=60;j++)
    {
      if(((x>>j)&1ll)==1)
        dp[i][j]=1;
      else
        dp[i][j]=0;

    }
   }
   for(i=n-1;i>=1;i--)
   {
    for(j=0;j<=60;j++)
    {
      dp[i][j]+=dp[i+1][j];
    }
   }
   
   ll ans=0;
   for(i=1;i<=n-1;i++)
   {
     ll x=a[i];
       for(j=0;j<=60;j++)
       {
        if(((x>>j)&1ll)==1)
        {
           ll zer=n-i-dp[i+1][j];
           ll val=(1ll<<j);
           val%=Ma;
           val=val*zer;
           val%=Ma;
           ans+=val;
           ans%=Ma;
        }
      else
        {

           ll one=dp[i+1][j];
           ll val=(1ll<<j);
           val%=Ma;
           val=val*one;
           val%=Ma;
           ans+=val;
           ans%=Ma;
        }

       }
   }
   cout<<ans<<endl;
   ti--;
  }
  
}

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

class DICE
{
private:
	const int dice_tem[5][6] = { { 3,2,6,1,5,4 },{ 2,6,3,4,1,5 },
	{ 5,1,3,4,6,2 },{ 4,2,1,6,5,3 },{1,2,3,4,5,6} }; //{0}:W {1}:N {2}:S {3}:E {4}:defalut   
	const string dice_rl = "AWWWNWWWNWWWWNWWWSWWWSWWW";
	const int n = 6;
	int dice_i[6] = { 0 };
	int dice_j[6] = { 0 };
	int a = 4;

	void setup() {
		for (int i = 0; i < n; i++) {
			cin >> dice[i];
			dice_i[i] = dice[i];
		}
	}

public:
	int dice[6];
	int num = 0;
	const int dice_suffle_num = dice_rl.length();
	DICE() {
	
	}
	void roll_dice() {
		switch (dice_rl[num])
		{
		case 78: //N
			a = 1;
			break;
		case 83: //S
			a = 2;
			break;
		case 87: //W
			a = 0;
			break;
		case 69: //E
			break;
			a = 3;
		default:
			a = 4;
			break;
		}

		for (int i = 0; i < n; i++) dice_j[i] = dice_i[dice_tem[a][i] - 1];
		for (int i = 0; i < n; i++) dice_i[i] = dice_j[i];
		num++;
		if (num > dice_suffle_num) num = 0;
	}
	int check(int i) {
		return dice_i[i];
	}
	void set()
	{
		setup();
	}
};

int main() {
	const int n = 6;
	bool flag = true;
	int num;
	cin >> num;
	const int con_num = num;
	DICE dice[100];
	for (int i = 0; i < num ; i++)dice[i].set();
	for (int i = 0; i < num - 1; i++) {
		for (int j = i+1; j < num; j++) {
			for (int k = 0; k < dice[0].dice_suffle_num;k++) {
				dice[j].roll_dice();
				for (int l = 0; l < n; l++) {
					if (dice[i].dice[l] != dice[j].check(l)) {
						flag = true;
						break;
					}
					flag = false;
				}
				if (flag == false)break;
			}
			if (flag == false)break;
		}
		if (flag == false)break;
	}

	if (flag == true) {
		cout << "Yes" << endl;
	}
	else if (flag == false) {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3184
import qualified Data.Map as Map
g=1000000007

f::[Int]->Int->Int
f [] p1=p1
f (_:[]) p1=p1
f (x:y:zs) p1
    |x+1==y=((f zs p1) + (f (y:zs) p1)) `mod` g
    |otherwise=f (y:zs) p1

f2::Int->Int->[Int]->Map.Map Int Int->Map.Map Int Int
f2 0 _ _ ms=ms
f2 h w xs ms=let ls=Map.toList ms
                 ts=[(e1+1,f (filter (\e->(not (e==e1) && not (e==e1+1))) xs) e2)|(e1,e2)<-ls,e1+1<=w]
                 ts2=[(e1,f (filter (\e->(not (e==e1))) xs) e2)|(e1,e2)<-ls]
                 ts3=[(e1-1,f (filter (\e->(not (e==e1) && not (e==e1-1))) xs) e2)|(e1,e2)<-ls,e1-1>0]
             in f2 (h-1) w xs (Map.fromListWith (+) (ts++ts2++ts3))

main = do
       e1<-getLine
       let (h:w:k:[])=map read (words e1)::[Int]
           xs=[1..w]
           ms=Map.fromList [(1,1)]
           ans=Map.toList $ f2 h w xs ms
       print $ (snd (ans!!(k-1))) `mod` g

Measured memory_bytes: 1148
#include<stdio.h>
int main(){
  int a,b;
  char op;
  while(scanf("%d %c %d",&a,&op,&b)){
    if(op=='?')break;
    else if(op=='+')printf("%d\n",a+b);
    else if(op=='-')printf("%d\n",a-b);
    else if(op=='*')printf("%d\n",a*b);
    else if(op=='/')printf("%d\n",a/b);
  }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
int main()
{
    int a[3],i,k=0;
    for(i=0;i<3;i++)
    cin>>a[i];
    sort(a,a+3);
    for(i=0;i<3;i++)
    k+=abs(a[i]-a[1]);
    cout<<k<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n;
    int[] sq;
    int ans;

    void run(){
	sq = new int[200]; // under 1024*32
	for(int i=0; i<sq.length; i++)
	    sq[i] = i*i;

	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n!=0){
		ans = 0;
		int level = sq.length-1;
		while(n < sq[level]) level--;
		int use = 0;
		solve(n, level, use);
		System.out.println(ans);
	    }
	}
    }

    void solve(int n, int level, int use){
	// hajiki kokokara
	if(level==0 || use>=4 || n<0) return;
	if(use==3 && sq[level]<n) return;
	// hajiki kokomade

	solve(n, level-1, use);

	n -= sq[level];
	use++;
	if(n==0 && use<=4){
	    ans++;
	    return;
	}

	if(n>=sq[level]) solve(n, level, use);
	else solve(n, level-1, use);
    }
}

Measured memory_bytes: 21316
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int N;
char swap;

void bubbleSort(char c[][3])
{
	for(int i = 0; i<=N-1; i++)
	{
		for(int j = N-1; j>=i+1; j-- )
		{
			if(c[j][1] < c[j-1][1])
			{
				//number
				swap = c[j][1];
				c[j][1] = c[j-1][1];
				c[j-1][1] = swap;
				//char
				swap = c[j][0];
				c[j][0] = c[j-1][0];
				c[j-1][0] = swap;
			}
		}
	}
}

void selectionSort(char A[][3])
{
	int mini,swap;
	for(int i=0; i<=N-1; i++)
    {
      mini = i;
      for(int j = i; j<=N-1; j++)
	{
	  if(A[j][1] < A[mini][1])
	  {
	    mini = j;
	  }
	}	
    swap=A[i][1];
	A[i][1] = A[mini][1];
	A[mini][1] = swap;
	swap=A[i][0];
	A[i][0] = A[mini][0];
	A[mini][0] = swap;
	
    }
}

int isStable(char in[][3], char out[][3])
{
	for(int i = 0; i<= N-1; i++)
	{
		for(int j = i+1; j<= N-1; j++)
		{
			for(int a = 0; a<=N-1; a++)
			{
				for(int b = a + 1; b<=N-1; b++)
				{
					if(in[i][1] == in[j][1])
					    if(in[i][1] == out[b][1] && in[i][0] == out[b][0])
					        if(in[j][1] == out[a][1] && in[j][0] == out[a][0])
					            return 0;
				}
			}
		}
	}
	return 1;
}

int main()
{
	scanf("%d", &N);
	char put[3]; //a once input to copy the input to three
	char in[N][3]; //this is coll for comparing input(un-sorted) and output(sorted)
	char inb[N][3]; 
	char ins[N][3];
	for(int i = 0; i < N; i++) 
	{
		scanf("%s", put);
		strcpy(in[i],put);
		strcpy(inb[i],put);
		strcpy(ins[i],put);
	}
	//bubbleSort thing
	bubbleSort(inb);
	for(int i = 0; i < N; i++) 
	{
		printf("%s",inb[i]);
		if(i!=N-1) printf(" ");
	}
	printf("\n");
	if(isStable(in, inb) == 1) printf("Stable\n");
	else printf("Not stable\n");
	//selectionSort thing
	selectionSort(ins);
	for(int i = 0; i < N; i++) 
	{
		printf("%s",ins[i]);
		if(i!=N-1) printf(" ");
	}
	printf("\n");
	if(isStable(in, ins) == 1) printf("Stable\n");
	else printf("Not stable\n");
	return 0;
}


Measured memory_bytes: 2120
from collections import Counter
H, W, M = list(map(int, input().split()))
h = [0]*M
w = [0]*M
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))
hc = Counter(h)
wc = Counter(w)
hmax = max(hc.values())
wmax = max(wc.values())
lh = {k[0] for k in hc.items() if k[1] == hmax}
lw = {k[0] for k in wc.items() if k[1] == wmax}

ct = 0
for i in range(M):
    if h[i] in lh and w[i] in lw:
        ct += 1
if ct >= len(lh)*len(lw):
    print(hmax+wmax-1)
else:
    print(hmax+wmax)

Measured memory_bytes: 200876
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
    A[i]--;
  }
  vector<i64> cnt(N);
  rep(i,0,N) {
    cnt[A[i]]++;
  }
  i64 sum = 0;
  rep(i,0,N) {
    sum += cnt[i] * (cnt[i] - 1) / 2;
  }
  rep(i,0,N) {
    sum -= cnt[A[i]] * (cnt[A[i]] - 1) / 2;
    cnt[A[i]]--;
    sum += cnt[A[i]] * (cnt[A[i]] - 1) / 2;
    cout << sum << endl;
    sum -= cnt[A[i]] * (cnt[A[i]] - 1) / 2;
    cnt[A[i]]++;
    sum += cnt[A[i]] * (cnt[A[i]] - 1) / 2;
  }
}


Measured memory_bytes: 5760
N = int(input())
A = [0] + [int(input()) for i in range(N)]
 
now = 1
count = 0
pushed = {1}
while now != 2:
  now = A[now]
  count += 1
  if now in pushed:
    print(-1)
    quit()
  pushed.add(now)
 
print(count)

Measured memory_bytes: 19708
/* 
 * Author: Priyadarshini
 */
 
/*
 * Run in Mac using the following command:
 * g++ -std=c++14 <cpp_filename>
 * A binary will be generated. Then run:
 * ./a.out
 */
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <fstream>
#include <cstring>
 
using namespace std;
typedef long long int ll;
 
// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>
 
// Global //
 
 
// Functions //
 
 
// Main //
int main(){
    int n;
    cin >>n;
    string a;
    cin >> a;

    string ans;
    int ch;
    // cout<<int('A')<<" "<< int('Z')<<endl;
    for(int i = 0; i < a.size(); i++){
        ch = int(a[i]) + n;
        if(ch > 90)ch = ch - 90 + 64;
        ans.push_back(char(ch));
    }
    cout<<ans;


    return 0;
}

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

def cost(number):
    res = 0
    for x in a:
        res += (x - number) ** 2
    return res

ans = 1001001001
for i in range(-100, 101):
    tmp = cost(i)
    if tmp < ans:
        ans = tmp

print(ans)


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

using namespace std;

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

int main(){
 long n,m;
  cin >> n >> m;

  vector<pair<long,long>> p(n);
  
  rep(i,0,n){
    long a,b;
    cin >> a >> b;
    p[i]=make_pair(a,b);
  
  }
    
  sort(p.begin(),p.end());
  
  
  long res=0;
  long num=0;
  rep(i,0,n){
    if(num+p[i].second<=m){
   res+=(p[i].first)*(p[i].second);
      num+=p[i].second;
    }
    else{
    res+=(p[i].first)*(m-num);
      break;
    }
  } 

  
  
  cout << res << endl;
  
   

}


Measured memory_bytes: 1792
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n,_ = strconv.Atoi(NextLine())
  return n
}

func main() {
  var n,a int
  m := make(map[int]struct{},n)
  n = NextInt()
  for i:=0;i<n;i++ {
    a = NextInt()
    if _,ok := m[a];ok {
      delete(m,a)
    } else {
      m[a] = struct{}{}
    }
  }
  fmt.Println(len(m))
}

Measured memory_bytes: 5888
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = int(input())
data = list(map(int, input().split()))
cnt = count(data)
mod = 10**9 + 7

ans = 1
for k, v in cnt.items():
    if k == 0:
        if v > 1 or n %2 == 0:
            print(0)
            exit()
        continue
    else:
        if v <= 2:
            ans *= 2
        else:
            print(0)
            exit()

print(ans%mod)


Measured memory_bytes: 20492
n, k = map(int, raw_input().split())
pb = n - (k + 1)
combi = 0
for b in range(k+1, n+1):
    combi += (n/b)*(b-k)
    if n % b >= k:
        combi += (n%b) - (k-1)
    if k == 0:
        combi -=1
print combi

Measured memory_bytes: 5892
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
s=a,b,c,d,e,f
if s.count(1)==3:
    print('NO')
elif s.count(2)==3:
    print('NO')
elif s.count(3)==3:
    print('NO')
elif s.count(4)==3:
    print('NO')
else :
    print('YES')


Measured memory_bytes: 3064
# ABC149d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()[:-1]
    flag = [False]*n
    # dp[i][T][J]=k手前にJを出してi番目でTを出すときの最高得点
    # dp[i][0][1]=dp[i-1][0][1]

    def tokuten(aite):
        if aite == 'r':
            return p
        if aite == 's':
            return r
        if aite == 'p':
            return s

    ans = t.count('r')*tokuten('r')+t.count('s') * \
        tokuten('s')+t.count('p')*tokuten('p')
    for i in range(n):
        if i - k >= 0 and t[i] == t[i - k] and not flag[i-k]:
            ans -= tokuten(t[i])
            flag[i] = True
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42352
import sys
input = sys.stdin.readline
A,B=map(int,input().split())
from fractions import gcd

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
p=prime_factorize(gcd(A,B))
if len(p)==0:
    print(1)
    exit()
cnt=1
#print(p)
for i in range(1,len(p)):
    if p[i]!=p[i-1]:
        cnt+=1
print(cnt+1)


Measured memory_bytes: 66412
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rs(a, b) ((a) >> (b))
#define ls(a, b) ((a) << (b))
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

int sum[300001];
int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int a[n];
    scan(a, n);
    int c = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((a[i] > a[i - 1] && a[i + 1] > a[i]) || (a[i] < a[i - 1] && a[i + 1] < a[i]))
            c++;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int a,b;
    scanf("%d%d",&a,&b);

    int ans = a-b;
    int tmp = a;
    if(ans<0){
        tmp = b;
        ans = ans * -1;
    }
    if(ans%2==0)
        printf("%d\n",tmp-ans/2);
    else
        printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 128
{-# LANGUAGE TypeApplications #-}

import qualified Data.HashMap.Strict as H

main = do
    n <- readLn @Int
    xs <- map read.words <$> getLine :: IO [Int]
    print $ answer n xs

answer :: Int -> [Int] -> Int
answer n hs = sum.H.elems $ H.intersectionWith (*) is js where
    is = hist $ zipWith (-) [1..n] hs
    js = hist $ zipWith (+) [1..n] hs

hist xs = H.fromListWith (+) $ zip xs (repeat 1)

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

#define int 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; }

signed main(){
	int n, m;
	cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int cnt = 0;
    REP(i, N - 1) if (S[i] != S[i + 1]) cnt++;

    cout << cnt + 1 << endl;
}


Measured memory_bytes: 512
function main(input) {
  input=input.trim();
  var x = input.split(" ")[0];
  var y = input.split(" ")[1];
  function change(n){
    if(n=="A")return 0
    if(n=="B")return 1
    if(n=="C")return 2
    if(n=="D")return 3
    if(n=="E")return 4
    if(n=="F")return 5
  }
  x=change(x)
  y=change(y)

  if(x==y){
    console.log("=");
  }else if(x>y){
    console.log(">");
  }else if(x<y){
    console.log("<");
  }


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<int,ll> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;
int main() {
	int n,k;
	cin>>n>>k;
	int a[50]={};
	for(int i=0;i<n;++i)cin>>a[i];
	sort(a,a+n);
	int t=0;
	for(int i=n-1;i>n-1-k;--i)t+=a[i];
	cout<<t<<endl;
	return 0;
}


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

int main(void)
{
  int N,i;
  
  scanf("%d",&N);
  
  int A[200001]={},B[200001]={};
  
  for(i=2;i<=N;i++)
  {
    scanf("%d",&A[i]);
    B[A[i]]++;
  }
    
  for(i=1;i<=N;i++)
  {
    printf("%d\n",B[i]);
  }
  return 0;
}

Measured memory_bytes: 3256
N, C, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])

in_bus = 0
first = 0
last = 0
bus_count = 0
for i in range(N):
    if (i == 0):
        first = T[i]
        last = T[i] + K
        in_bus += 1
        bus_count += 1
        continue

    if (in_bus == C):
        bus_count += 1
        in_bus = 1
        first = T[i]
        last = T[i] + K
        continue

    if (T[i] >= first and last >= T[i]):
        in_bus += 1
    else:
        first = T[i]
        last = T[i] + K
        in_bus = 1
        bus_count += 1


print(bus_count)


Measured memory_bytes: 13944
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=0;
	if(a<=b){
		x=x+a;
	}
	else if(b<=a){
		x=x+b;
	}
	if(c<=d){
		printf("%d\n",x+c);
	}
	else if(d<=c){
		printf("%d\n",x+d);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
    data.at(i) -= i + 1;
  }
  sort(data.begin(), data.end());
  long sum = 0, a = data.at(N / 2);
  for(int i = 0; i < N; i++) {
    data.at(i) -= a;
    sum += abs(data.at(i));
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
	
	int n, k, x, y; cin >> n >> k >> x >> y;
	int ans = 0;
	if (k < n) {
		ans = k * x + (n - k) * y;
	}
	else {
		ans = n * x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string S;
    cin >>S;
    string check = S.substr(0,1);
    for(int i = 1; i < S.size();i++){
        if(check == S.substr(i,1)){
            cout << "Bad" << endl;
            return 0;
        }
        check = S.substr(i,1);
    }
    
    cout <<"Good"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  int a,b,c,k; cin >> a >> b >> c >> k;

  if(a >= k) {
    cout << k << endl;
    return 0;
  }

  if(a + b >= k) {
    cout << a << endl;
    return 0;
  }

  cout << a - (k - a - b) << endl;
}


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

int main() {
    std::size_t N;
    std::cin >> N;
    std::size_t ans = 0;
    for (std::size_t A = 1; A <= N - 1; ++A) {
        if (N%A == 0) {
            ans += N/A - 1;
        } else {
            ans += (N-1)/A;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
    a[i]-=i;
  }
  ll res=0;
  ll res2=0;
  vector<int> b(n);
  rep(i,n) b[i]=a[i];
  sort(b.begin(),b.end());
  int p=b.size()/2;
  int q=p-1;
  rep(i,n){
    res+=abs(a[i]-b[p]);
    res2+=abs(a[i]-b[q]);
  }
  cout<<min(res,res2)<<endl;
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L > R) {
    cout << "Left " << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3656
import sys
bin = []

for i in range(3):
  lst = list(map(int,input().split()))
  bin.append(lst)
  
n = int(input())
for i in range(n):
  m = int(input())
  for j in range(3):
    for k in range(3):
      if m == bin[j][k]:
        bin[j][k] = 't'
        break
    
    
for i in range(3):
  if bin[i][0] == 't' and bin[i][1] == 't' and bin[i][2] == 't':
    print('Yes')
    sys.exit()
    
for j in range(3):
  if bin[0][j] == 't' and bin[1][j] == 't' and bin[2][j] == 't':
    print('Yes')
    sys.exit()
    
if (bin[0][0] == 't' and bin[1][1] == 't' and bin[2][2] == 't') or (bin[0][2] == 't' and bin[1][1] == 't' and bin[2][0] == 't'):  
  print('Yes')
  sys.exit()
  
print('No')  




Measured memory_bytes: 62216
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,s=0;
    cin>>n;
    vector<ll> a(n,0),b(n-1);
    for(ll i=0;i<n-1;i++) cin>>b[i];
    a[0]=b[0];
    a[n-1]=b[n-2];
    for(ll i=1;i<n-1;i++) a[i]=min(b[i-1],b[i]);
    for(ll i=0;i<n;i++) s+=a[i];
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define ffor(n) for(ll i=0;i<n;i++)
#define rfor(x,y) for(ll i=x;i<y;i++)
#define ff first
#define ss second
#define pb push_back
void solve()
{
    ll n;
    cin>>n;
    int arr[n];
    ffor(n)
    cin>>arr[i];
    ll dp[n+1];
    dp[0]=0;
    dp[1] = abs(arr[1]-arr[0]);
    rfor(2,n)
    {
        dp[i] = min(dp[i-2] + abs(arr[i-2]-arr[i]) , dp[i-1] + abs(arr[i-1]-arr[i]));
    }
    cout<<dp[n-1]<<endl;
    return;

}
int main()
{
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4772
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<map>
#include<set> 
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main()
{
	ll S[2005]={0,0,0,1,1};
	int s;
	cin>>s; 
	for(int i=4;i<=s;i++)
	{
		S[i]=(S[i-1]+S[i-3])%mod;
	}
	cout<<S[s]<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int M,N;
  cin>>M>>N;
  char g[20][21];
  for(int i=0;i<M;i++){
    cin>>g[i];
  }
  static int dp[2][2][1<<20];
  dp[0][0][0]=1;
  int s=M*N;
  int MOD=100000;
  int all=1;
  for(int i=0;i<s;i++){
    int y=i/N;
    int x=i%N;
    bool q=g[y][x]=='?';
    all=(all*(q?3:1))%MOD;
    int bx=i%2;
    int dx=bx^1;
    fill(dp[dx][0],dp[dx+1][0],0);
    for(int k=0;k<2;k++){
      for(int l=0;l<1<<20;l++){
	if(!dp[bx][k][l])continue;
	int db=l&~(1<<x);
	if(q||g[y][x]=='J'){
	  dp[dx][1][db]=(dp[dx][1][db]+dp[bx][k][l])%MOD;
	}
	if(q||g[y][x]=='O'){
	  dp[dx][0][db|k<<x]=(dp[dx][0][db|k<<x]+dp[bx][k][l])%MOD;
	}
	if(!(l>>x+1&1)&&(q||g[y][x]=='I')){
	  dp[dx][0][db]=(dp[dx][0][db]+dp[bx][k][l])%MOD;
	}
      }
    }
    if(x==s%N-1){
      for(int k=0;k<1<<20;k++){
	dp[dx][0][k]+=dp[dx][1][k];
	dp[dx][1][k]=0;
      }
    }
  }
  int a=0;
  for(int i=0;i<2;i++){
    for(int j=0;j<1<<20;j++){
      a=(a+dp[s%2][i][j])%MOD;
    }
  }
  cout<<(all-a+MOD)%MOD<<endl;
}

Measured memory_bytes: 17548
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;


const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

void kekek()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef EBUCHKA
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
}


bool is_gl(char c) {
	return c == 'a' || c == 'o' || c == 'u' || c == 'i' || c == 'e';
}

int main() {
	kekek();
	cout.precision(20);
	int n;
	int sm = 0;
	cin >> n;
	vector<int> nums(n);
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
		sm += nums[i];
	}
	for (int i = 0 ; i < n; i++) {
		if (nums[i] >= sm - nums[i]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	a := nextInt64()
	b := nextInt64()
	c := nextInt64()

	if (c-a-b) > 0 && 4*a*b < (c-a-b)*(c-a-b) {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


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

using namespace std;

int main(int argc, char* argv[]) {
  string s, t;
  cin >> s >> t;

  if (t.size() != s.size() + 1) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;


  return 0;
}

Measured memory_bytes: 3628
#include <iostream> 
#include <string> 
using std::cin; 
using std::cout; 
using std::endl; 
using std::string;
 int main(void){ 
   string s;
 cin >> s;
 bool isgood = true; 
   if (s[0] == s[1]) isgood = false; 
   if (s[1] == s[2]) isgood = false; 
   if (s[2] == s[3]) isgood = false;
   if (isgood) { 
     cout << "Good" << endl;
} else { 
     cout << "Bad" << endl; 
   }
 return 0; 
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
using namespace std;

constexpr int INF = 1e9;

vector<int> find_cycle(const vector<vector<int>> &G, int s){
  vector<int> D(G.size(),INF);
  queue<pair<int,int>> Q;
  Q.emplace(0,s);
  while(Q.size()){
    int d, v;
    tie(d,v) = Q.front();
    Q.pop();
    if(d > D[v]) continue;
    for(auto v_ : G[v]){
      int d_ = d+1;
      if(D[v_] > d_){
        D[v_] = d_;
        Q.emplace(d_,v_);
      }
    }
  }
  if(D[s] >= INF) return {};
  vector<vector<int>> G_(G.size());
  for(size_t i = 0; i < G.size(); ++i){
    for(auto v : G[i]){
      G_[v].push_back(i);
    }
  }
  int d = D[s], v = s;
  vector<int> C = {s};
  while(d > 0){
    --d;
    for(auto v_ : G_[v]){
      if(D[v_] == d){
        C.push_back(v_);
        v = v_;
        break;
      }
    }
  }
  return C;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for(int i = 0; i < M; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    G[a].push_back(b);
  }
  vector<int> A;
  for(int i = 0; i < N; ++i){
    vector<int> C = find_cycle(G,i);
    if(C.empty()) continue;
    if(A.empty() or C.size() < A.size()) swap(A,C);
  }
  if(A.empty()){
    cout << -1 << endl;
    return 0;
  }
  cout << A.size() << endl;
  for(auto a : A)
    cout << a+1 << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  bool ok = false;
  if (s == "hi") ok = true;
  if (s == "hihi") ok = true;
  if (s == "hihihi") ok = true;
  if (s == "hihihihi") ok = true;
  if (s == "hihihihihi") ok = true;
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, t, a; cin >> n >> t >> a;
  t *= 1000;
  a *= 1000;
  vector<int> vals(n);
  int dist = 1<<30;
  for(int i = 0; i < n; i++){
    cin >> vals[i]; vals[i] *= 6;
    dist = min(dist, abs(a - (t - vals[i])));
  }
  for(int i = 0; i < n; i++){
    if(dist == abs(a - (t - vals[i]))){
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int maxn=1e5+5;
struct Node {
    int p,y,id,ans;
}node[maxn];

bool cmp1(Node a,Node b) {
    if(a.p!=b.p) return a.p<b.p;
    return a.y<b.y;
}

bool cmp2(Node a,Node b) {
    return a.id<b.id;
}

int main()
{
    int n,m;cin>>n>>m;
    for(int i=1;i<=m;i++) cin>>node[i].p>>node[i].y,node[i].id=i;
    sort(node+1,node+1+m,cmp1);
    node[1].ans=1;
    for(int i=2;i<=m;i++) {
        if(node[i].p==node[i-1].p) node[i].ans=node[i-1].ans+1;
        else node[i].ans=1;
    }
    sort(node+1,node+1+m,cmp2);
    for(int i=1;i<=m;i++) {
        printf("%06d%06d\n",node[i].p,node[i].ans);
    }
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int ht[26];
int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        ht[s[i]-'a']++;
    }
    for(int i=0;i<26;i++)
    {
        if(ht[i]%2==1)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;


}


Measured memory_bytes: 256