akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int zerocnt = 0;
        int onecnt = 0;
        int test = 0;
    	ArrayList<String> Stringlist = new ArrayList<String>(Arrays.asList(S.split("")));
    	for(String i : Stringlist) {
    		if("0".equals(i)) {
    			zerocnt++;
    		}else {
    			onecnt++;
    		}
    	}
        System.out.println(Math.min(zerocnt, onecnt) * 2);
	}
}


Measured memory_bytes: 34616
N,M,X,Y=map(int,input().split())
x_l=list(map(int,input().split()))
y_l=list(map(int,input().split()))
if max(x_l)<min(y_l) and X<min(y_l) and max(x_l)<Y:print("No War")
else:print("War")
    

Measured memory_bytes: 2940
using System;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long ans=(s[0]-gcd(s[0],s[1]))*3;
		Console.WriteLine(ans);
	}
	static long gcd(long a,long b){
		long c=Math.Max(a,b)%Math.Min(a,b);
		b=Math.Min(a,b);
		while(c!=0){
			a=b%c;
			b=c;
			c=a;
		}
		return b;
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

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

    int w;cin>>w;
    vector<int> a(w);
    for(int i=0;i<w;i++) cin>>a[i];
    vector<int> dp(w,0);
    if(a[0]==0) dp[0]=INF;
    if(a[w-1]==0) dp[w-1]=INF;
    for(int i=1;i<w;i++){
        if(a[i]==0) dp[i]=INF;
        else if(a[i]<0){
            dp[i]=min(dp[i-1]-1, abs(a[i]));
        }
        else{
            dp[i]=dp[i-1]-1;
        }
    }
    for(int i=w-2;i>=0;i--){
        if(a[i]==0) dp[i]=INF;
        else if(a[i]<0){
            int tmp=min(dp[i+1]-1,abs(a[i]));
            dp[i]=max(dp[i],tmp);
        }
        else{
            dp[i]=max(dp[i],dp[i+1]-1);
        }
    }
    int res=0;
    for(int i=0;i<w;i++){
        //cout<<" "<<a[i]<<" "<<dp[i]<<endl;
        if(a[i]==0 || a[i]<0) continue;
        if(dp[i]<0) continue;
        res+=min(a[i],dp[i]);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int>> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 1e5; // CAMBIAR ESTE

// GJNM

int main(){
	int a,b,c,d;
	rii(a,b); // health strength
	rii(c,d);
	while(true){
		c -= b;
		if ( c<=0 ){
			printf("Yes\n");
			break;
		}
		a -= d;
		if ( a<=0 ){
			printf("No\n");
			break;
		}
	}

	return 0;
}

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

using namespace std;

int n;
char s[15];

int main() {
	scanf("%d", &n);
	
	int res = 0;
	int ba = 0;
	int b_ = 0;
	int _a = 0;
	
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		int l = strlen(s);
		
		for (int j = 0; j < l - 1; j++) {
			if (j + 1 < l && s[j] == 'A' && s[j + 1] == 'B') res++;
		}
		
		if (s[0] == 'B' && s[l - 1] == 'A') ba++;
		else if (s[0] == 'B') b_++;
		else if (s[l - 1] == 'A') _a++;
	}
	res += max(0, ba - 1);
	
	if (ba > 0 && _a > 0) {
		_a--;
		res++;
	}
	
	if (ba > 0 && b_ > 0) {
		b_--;
		res++;
	}
	
	res += min(_a, b_);
	
	printf("%d\n", res);
}


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

using namespace std;
#define ll long long int
int const mod=1000000007;

int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll a[n+1]={0},red=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
        {
            a[i+1]=a[i]+1;
        }
        else
        {
            a[i+1]=a[i];
            red++;
        }
    }
    ll ans=n;
    for(int i=red;i<=n;i++)
    {
        ans=min(ans,a[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 5296
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var slice []int
var dp []float64

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	slice = make([]int, n+3)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}

	dp = make([]float64, 100000000)
	for i := 0; i < len(dp); i++ {
		dp[i] = math.Inf(1)
	}

	dp[0] = 0.0
	for i := 1; i < n; i++ {
		chmin(&dp[i], dp[i-1]+float64(abs(slice[i]-slice[i-1])))
		if i > 1 {
			chmin(&dp[i], dp[i-2]+float64(abs(slice[i]-slice[i-2])))
		}
	}

	fmt.Println(int(dp[n-1]))

}

func abs(a int) int {
	if a < 0 {
		return -1 * a
	}

	return a
}

func chmin(a *float64, b float64) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func chmax(a *float64, b float64) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}


Measured memory_bytes: 808320
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
a.sort(key=lambda x:x[1])
t=[0]*n#iを終えた時の時間
t[0]=a[0][0]
for i in range(n-1):
    t[i+1]=t[i]+a[i+1][0]
judge=True
for i in range(n):
    if a[i][1]<t[i]:
        judge=False
print("Yes") if judge else print("No")


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

const int MAXN = 100005;
const ll MOD = 1000000007;


ll s[MAXN];
ll prefx[MAXN];
ll prefy[MAXN];
ll dpx[MAXN];
ll dpy[MAXN];

int main()
{
    int n;
    ll A, B;
    cin >> n >> A >> B;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
    }

    int lx = 0;
    int rx = 0;
    int ly = 0;
    int ry = 0;

    dpx[0] = 1;
    dpy[0] = 1;

    prefx[1] = 1;
    prefy[1] = 1;

    for (int i = 1; i <= n-1; i++)
    {
        while (s[i+1] - s[rx] >= B && rx < i) rx++;
        while (s[i+1] - s[ry] >= A && ry < i) ry++;
        rx--; ry--;
        rx = max(0, rx); rx = max(lx-1, rx);
        ry = max(0, ry); ry = max(ly-1, ry);
        dpx[i] = (prefy[ry+1] - prefy[ly] + MOD) % MOD;
        dpy[i] = (prefx[rx+1] - prefx[lx] + MOD) % MOD;

        prefx[i+1] = (prefx[i] + dpx[i]) % MOD;
        prefy[i+1] = (prefy[i] + dpy[i]) % MOD;

        if (s[i+1] - s[i] < A) lx = i;
        if (s[i+1] - s[i] < B) ly = i;

    //    cout << dpx[i] << " " << dpy[i] << endl;
    }

    cout << (prefx[n] - prefx[lx] + prefy[n] - prefy[ly] + 2*MOD) % MOD;

    return 0;
}


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

int main(){
  int n, d;
  cin >> n >> d;
  double x[n][d];
  rep(i, n){
    rep(j, d){
      cin >> x[i][j];
    }
  }
  
  int count = 0;
  rep(i, n-1){
    for(int j=i+1; j<n; ++j){
      double insideRoot = 0;
      rep(k, d){
        insideRoot += pow(x[i][k]-x[j][k], 2);
      }
      double distance = sqrt(insideRoot);
      int distance_int = distance;
      double judge_num = distance - distance_int;
      if(judge_num == 0.0) ++ count;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
         cout << std::fixed << std::setprecision(15);
int n,a,b;
cin>>n>>a>>b;
if(a<b)swap(a,b);
int x[a+1];
x[0]=1;

for(int i=1;i<a+1;i++){
     x[i]=x[i-1];
     for(int j=0;j+b+1<=i;j++){
          x[i]=(x[i]+x[j])%MOD;
     }
}
int y[2][n+1];
y[1][0]=1;y[0][0]=1;
for(int i=1;i<n+1;i++){
     y[1][i]=0;y[0][i]=0;
     for(int j=i-1;j>=0&&i-j<b;j--){
          y[0][i]=(y[0][i]+y[1][j])%MOD;
     }
     if(i!=n){
     for(int j=i-1;j>=0&&i-j<a;j--){
        if(j!=0) y[1][i]=(y[1][i]+y[0][j]*x[i-j-1]%MOD)%MOD;
         else  y[1][i]=(y[1][i]+x[i-j]%MOD)%MOD;
     }
     }else{
          for(int j=i-1;j>=0&&i-j<a;j--){
        if(j!=0) y[1][i]=(y[1][i]+y[0][j]*x[i-j]%MOD)%MOD;
         else y[1][i]=(y[1][i]+x[i-j+1]%MOD)%MOD;
     }
     }
}

//for(int i=0;i<=n;i++)cerr<<y[0][i]<<' ';
//cerr<<endl;
////for(int i=0;i<=n;i++)cerr<<y[1][i]<<' ';
//cerr<<endl;
//for(int i=0;i<a-1;i++)cerr<<x[i]<<' ';
//cerr<<endl;
cout<<(modpow(2,n,MOD)+MOD-y[0][n]+MOD-y[1][n])%MOD<<endl;


     }

 


 






    





      

        


Measured memory_bytes: 3704
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N;
	string a;
	set<string>S;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>a;
		S.insert(a);
	}
	puts(S.size()==3?"Three":"Four");
}


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

#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define drp(i,st,ed) for (int i=st;i>=ed;--i)
#define copy(x,t) memcpy(x,t,sizeof(x))

const int N=100005;

char s[N];

int rec[N][26],size[N],len[N],fa[N];
int b[N],rk[N],last,tot;

void extend(int ch) {
	int p,q,np,nq;
	p=last; last=np=++tot;
	len[np]=len[p]+1;
	for (;p&&!rec[p][ch];p=fa[p]) rec[p][ch]=np;
	if (!p) fa[np]=1;
	else {
		q=rec[p][ch];
		if (len[q]==len[p]+1) fa[np]=q;
		else {
			nq=++tot; len[nq]=len[p]+1;
			copy(rec[nq],rec[q]);
			fa[nq]=fa[q];
			fa[np]=fa[q]=nq;
			for (;p&&rec[p][ch]==q;p=fa[p]) rec[p][ch]=nq;
		}
	}
}

void build() {
	rep(i,1,tot) b[len[i]]++;
	rep(i,1,tot) b[i]+=b[i-1];
	rep(i,1,tot) rk[b[len[i]]--]=i;
	drp(ti,tot,1) {
		int x=rk[ti]; size[x]++;
		rep(i,0,25) size[x]+=size[rec[x][i]];
	}
}

void kth(int k) {
	for (int x=1;k;) {
		rep(i,0,25) if (rec[x][i]) {
			int y=rec[x][i];
			if (size[y]<k) k-=size[y];
			else {
				putchar('a'+i);
				k--,x=y; break;
			}
		}
	}
}

int main(void) { tot=last=1;
	int k; scanf("%s%d",s+1,&k);
	int n=strlen(s+1);
	rep(i,1,n) {
		extend(s[i]-'a');
	}
	build();
	kth(k);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2560
/* ex5_3
    riverstone*/

#include<stdio.h>
#include <stdbool.h>

#define LIM 100 //行数、列数の上限

int main(void){
    
    int height, width, i, j;
    //多次元配列の定義
    //black_rowとblack_colは各行と各列に1つ以上の黒が存在するかを記録
    char block[LIM][LIM];
    int black_row[LIM]={}, black_col[LIM]={};

    //入力の受け取り
    scanf("%d %d", &height, &width);

    //行列の各マスを読み取る
    //各行と各列に1つ以上の黒が存在するかをblack_rowとblack_colに記録
    for(i = 0; i < height; i++){
        for(j = 0; j < width; j++){
            scanf(" %c", &block[i][j]);
            if(block[i][j] == '#'){
                //マス(i,j)が黒のとき,black_row[i],black_col[j]を1にする
                black_row[i] = 1;
                black_col[j] = 1;
            }
        }   
    }
    
    //black_rowとblack_colを見て共に1であるようなマスの場合のみ出力
    for(i = 0; i < height; i++){
        if(black_row[i] == 1){
            for(j = 0; j < width; j++){
                if(black_col[j] == 1){
                    //black_row[i] = tureかつblack_col[j] = 0のときblock[i][j]を表示
                    printf("%c", block[i][j]);
                }
            }
            printf("\n"); //1行の処理が全て終わると改行する

        } 
    }
 
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define REP(i,b,c) for(int i=0;i<b;i+=c)

int main(){
	char p[9][9];
	int n;
	cin >> n;
	while(n--){
		char a[9][9];
		REP(i,9,1)REP(j,9,1)a[j][i]=' ';
		REP(i,9,1)REP(j,9,1)cin >> p[j][i];
		
		REP(j,9,3){
			REP(i,9,3){			
				int c[9]={0};
				REP(x,3,1){
					REP(y,3,1){
						c[p[i+x][j+y]-'0'-1]++;
						if(c[p[i+x][j+y]-'0'-1]>1){
							REP(t,3,1){
								REP(l,3,1){
									if(p[i+x][j+y]==p[i+t][j+l]){
										a[i+t][j+l]='*';
									}
								}
							}
						}
					}
				}	
			}
		}
		REP(i,9,1){
			int c[9]={0},c2[9]={0};
			REP(j,9,1){
				c[p[j][i]-'0'-1]++;
				if(c[p[j][i]-'0'-1]>1){
					REP(t,9,1){
						if(p[j][i]==p[t][i]){
							a[t][i]='*';
						}
					}
				}
				c2[p[i][j]-'0'-1]++;
				if(c2[p[i][j]-'0'-1]>1){
					REP(t,9,1){
						if(p[i][j]==p[i][t]){
							a[i][t]='*';
						}
					}
				}
			}
		}
		REP(i,9,1){
			REP(j,9,1)cout << a[j][i] << p[j][i];
			cout << endl;
		}
		if(n)cout << endl;
	}
}
		

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

using namespace std;

struct cake_set{
    int one;
    int two;
    int three;
    long long score;
};

int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<long long> a(x);
    vector<long long> b(y);
    vector<long long> c(z);
    for(int i=0;i<x;i++){
        cin >> a[i];
    }
    for(int i=0;i<y;i++){
        cin >> b[i];
    }
    for(int i=0;i<z;i++){
        cin >> c[i];
    }
    sort(a.begin(),a.end(),greater<long long>());
    sort(b.begin(),b.end(),greater<long long>());
    sort(c.begin(),c.end(),greater<long long>());

    auto compare=[](cake_set cake1,cake_set cake2){
        return cake1.score < cake2.score;
    };
    
    priority_queue<
        cake_set,
        vector<cake_set>,
        decltype(compare)> q {compare};

    set<vector<int>> s;

    int l,m,n;
    l=0;m=0;n=0;
    q.push((cake_set){l,m,n,a[l]+b[m]+c[n]});
    s.insert({0,0,0});

    for(int i=0;i<k;i++){
        cake_set next=q.top();
        l=next.one;
        m=next.two;
        n=next.three;
        //cout << "l=" << l << " m=" << m << " n=" << n << endl;
        //cout << "a=" << a[l] << " b=" << b[m] << " c=" << c[n] << endl;
        cout << next.score << endl;
        
        q.pop();

        if(l+1<x){
            if(s.count({l+1,m,n})==0){
                q.push((cake_set){l+1,m,n,a[l+1]+b[m]+c[n]});
                s.insert({l+1,m,n});
            }
        }

        if(m+1<y){
            if(s.count({l,m+1,n})==0){
                q.push((cake_set){l,m+1,n,a[l]+b[m+1]+c[n]});
                s.insert({l,m+1,n});
            }
        }

        if(n+1<z){
            if(s.count({l,m,n+1})==0){
                q.push((cake_set){l,m,n+1,a[l]+b[m]+c[n+1]});
                s.insert({l,m,n+1});
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i ++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i --)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return 1;}return 0;}

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    REP(i, n){
        cin >> h[i];
    }
    vector<unordered_set<ll>> michi(n);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        michi[a].insert(b);
        michi[b].insert(a);
    }

    ll ans = 0;
    REP(i, n){
        ll flag = true;
        for(ll tonari : michi[i]){
            if(h[tonari] >= h[i]){
                flag = false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }

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

Measured memory_bytes: 19072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// ここにコードを挿入
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int i=0;
		if(n<10) {
			i=n;
		}else if(n<100) {
			i=9;
		}else if(n<1000) {
			i=10+n-100;
		}else if(n<10000) {
			i=909;
		}else if(n<100000) {
			i=910+n-10000;
		}else {
			i=90909;
		}
		System.out.print(i);
	}

}


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

int main(){
  long long a, b, x;
  cin >> a >> b >> x;

  if(a == 0){
    cout << b / x + 1 << endl;
  }
  else{
    cout <<  b / x - ((a - 1) / x) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define debug(a) cout<<a<<endl
#define clr(a) memset(a,0,sizeof(a))
#define clrne(a) memset(a,-1,sizeof(a))
#define clrinf(a) memset(a,0x3f,sizeof(a))
#define clrneinf(a) memset(a,0xc0,sizeof(a))
#define pb(a) push_back(a)
#define maxn 100005
#define mod 1000000007
#define eps 1e-9
#define inf 0x7fffffff
ll a[maxn];
ll b[maxn];
int  main()
{
//  freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
    ll n,h;
    scanf("%lld%lld",&n,&h);
    for (ll i = 1; i<=n; i++)
        scanf("%lld%lld",&a[i],&b[i]);
    ll maxi;
    ll maxval = 0;
    for (ll i = 1; i<=n; i++)
        if (maxval<a[i])
        {
            maxi = i;
            maxval = a[i];
        }
    ll cnt = 0;
    sort(b+1,b+1+n);
    reverse(b+1,b+1+n);
    for (ll i = 1; i<=n; i++)
    {
        if (b[i]>maxval)
        {
            h-=b[i];
            cnt++;
            if (h<=0) break;
        }
        else break;
    }
    if (h>0) cnt += (h+maxval-1)/maxval;
    cout<<max(0ll,cnt)<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  char s[N];
  for(int i=0;i<N;i++)cin>>s[i];
  if(s[K-1]=='A')s[K-1]='a';
  if(s[K-1]=='B')s[K-1]='b';
  if(s[K-1]=='C')s[K-1]='c';
  for(int i=0;i<N;i++)cout<<s[i];
}
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner in = new Scanner(System.in);

	String before;
	int order;
	int num;
	String str1,str2;
	

	while(true){
	    before = in.next();
	   if(before.equals("-"))break;
	   num = in.nextInt();

	    for(int i=0;i<num;i++){
		order = in.nextInt();
	    
		str2 = before.substring(0,order);
		str1 = before.substring(order,before.length());
		before = str1+str2;
	    }
	    System.out.println(before);

	}
    }
}



Measured memory_bytes: 26624
import java.util.Scanner;
 
    class Main {
    public static void main(String args[] )  {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();	
	    int b = sc.nextInt();
            int i = a * b;
            int o = (a+b)*2;
            System.out.printf("%d %d%n",i,o);
        }
    }

Measured memory_bytes: 26124
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	string S, T;
	int i;
	cin >> S >> T;
	if (S.size() > T.size()) {
		for (i = 0; i < T.size(); i++)cout << S[i] << T[i];
		cout << S[i];
	}
	else for (i = 0; i < T.size(); i++)cout << S[i] << T[i];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int main(){
	//freopen("in.txt","r",stdin);
	for(int i=1;i<102;i++){
		for(int j=1;j<102;j++){
			for(int m=1;m<102;m++){
				if(i*i + j*j + m*m + i*j + i*m + j*m < 10004)
				a[i*i + j*j + m*m + i*j + i*m + j*m]++;
			}
		}
	}
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  map<int,int> count;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(count.count(A)==0){
      count[A]=1;
    }else{
      count[A]++;
    }
  }

  int ans=0;
  for(auto m : count){
    if(m.second%2==1){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4992
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

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




/*
constant values
*/

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

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    LL N;cin >> N;
    LL ans;
    ans = N*(N-1)/2;

    cout << ans << endl;
    return;
}



// ----------------------------------------------
int main(){

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main()
{
    int n;
    cin >> n;
    map<int, int> a;
    vector<int> b(n);
    rep(i, n)
    {
        cin >> b[i];
    }
    rep(i, n)
    {
        a[b[i]]++;
    }
    int ans = 0;
    for (auto itr = a.begin(); itr != a.end(); itr++)
    {
        if (itr->first <= itr->second)
            ans += itr->second - itr->first;
        else
        {
            ans += itr->second;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 1e9+7;

ll add(ll a, ll b)
{
	//return a+b;
	a+=b; a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	if(a>MOD) a%=MOD;
	if(b>MOD) b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}

const bool DEBUG = 0;
const int MAXN = 105;
const int MAXK = 100005;

int n,K;
ll a[MAXN];
ll dp[MAXN][MAXK];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>K;
	fore(i,1,n) cin>>a[i];
	dp[0][0]=1;
	
	fore(i,1,n)
	{
		fore(j,0,K)
		{
			dp[i][j]=add(dp[i][j], dp[i-1][j]-(j-a[i]-1>=0 ? dp[i-1][j-a[i]-1] : 0LL));
			if(j) dp[i][j]=add(dp[i][j], dp[i][j-1]);
		}
	}
	
	cout<<dp[n][K]<<'\n';
	
	/*fore(i,0,n)
	{
		fore(j,0,K) cout<<dp[i][j]<<" ";
		cout<<'\n';
	}*/
	
	return 0;
}


Measured memory_bytes: 81660
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF            1e9
#define INFLL          1e18
#define EPS            1e-9
#define REP(i,n)       for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)      for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(ll i=(n);i>0;--i)
#define REPC(i,obj)    for(auto i:obj)
#define ALL(obj)       (obj).begin(),(obj).end()
#define SETP(n)        cout<<fixed<<setprecision(n)
#define VV(T,h,w)      move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i)   move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T, ll h, ll w>using vec2 = vector<vector<T>>;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n;
	for (ll h = 0; n = in(); ++h) {
		if (h != 0)cout << endl;
		vector<string>name(n);
		vector<pair<ll, ll>>point(n);
		REP(i, n) {
			ll w, l, d;
			cin >> name[i] >> w >> l >> d;
			point[i] = make_pair(w * 3 + d, -i);
		}
		sort(ALL(point), greater<pair<ll, ll>>());
		REPC(i, point) cout << name[-i.second] << ',' << i.first << endl;
	}
}


Measured memory_bytes: 3136
# ABC125D - Flipping Signs
def main():
    # neg % 2 == 0 -> all negatives disappear
    # 0 in A -> move all neg there
    # else -> move all neg to the smallest one (abs(i))
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = abs(min(A, key=abs))
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    if 0 in A or neg % 2 == 0:
        print(abs_sum)
    else:
        print(abs_sum - mi * 2)


if __name__ == "__main__":
    main()

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < b+2; i++) {
        cout << '#';
    }
    cout << "\n";
    for (int i = 0; i < a; i++) {
        cout << '#';
        string s;
        cin >> s;
        cout << s;
        cout << '#' << "\n";
    }
    for (int i = 0; i < b+2; i++) {
        cout << '#';
    }
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3592
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tmp, _ := reader.ReadString('\n')
	tmp = strings.Trim(tmp, "\n")
	nk := strings.Split(tmp, " ")

	n, _ := strconv.Atoi(nk[0])
	x, _ := strconv.Atoi(nk[1])

	if n >= x {
		fmt.Println("10")
	} else {
		fmt.Println("0")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<int,int> position;
 
const int INF = 1e+8;
 
int D[50][50];
int G[50][50];
int H, W;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main(void){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> H >> W;
	int s = 0;
	for(int i = 0;i < H;++i){
		for(int j = 0;j < W;++j){
			char c;
			cin >> c;
			if(c == '.'){
				G[i][j] = 0;
			}else if(c == '#'){
				G[i][j] = 1;
				s += 1;
			}
			D[i][j] = INF;
		}
	}
 
	//迷路を解く
	queue<position> que;
	que.push(position(0, 0));
	D[0][0] = 0;
 
	while( !que.empty() ){
		position p = que.front();
		que.pop();
		int x = p.first;
		int y = p.second;
		if( x == H-1 && y == W-1 ) break;
		for(int i=0 ; i < 4 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			if( mx < 0 || my < 0 || mx >= W || my >= H ) continue;
 
			if( G[my][mx] != 1 && D[my][mx] == INF ){
				que.push( position(mx,my) );
				D[my][mx] = D[y][x] + 1;
			}
		}
	}
	if(D[H-1][W-1] == INF){
		cout << -1 << endl;
	}else{
		cout << (H*W) - s - D[H-1][W-1] - 1 << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};





int main(void) {
    string s;
    cin >> s;
    Int k;
    cin >> k;
    bool flag = true;
    REP(s.size(),i){
        char c = s.at(i);
        if (c != 'a') {
            if ('z' - c + 1 <= k) {
                k -= 'z' - c + 1;
                s.at(i) = 'a';
            }
        }
        if (k <= 0) {
            flag = false;
            break;
        }
    }
    if (flag){
        char c = s.at(s.size()-1) - 'a';
        c = (char)((Int)(c + k) % 26);
        s.at(s.size() - 1) = c + 'a';
    }
    cout << s << endl;

}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();

int main(void) {
    int n; cin >> n;
    vector<int> v;

    for (int i = 0; i < n; i++) {
        int t; cin >> t;
        v.push_back(t);
    }

    int c = 0;
    bool f = true;

    while (1) {
        for (int i = 0; i < n; i++) {
            if (v[i] % 2 == 0) {
                v[i] /= 2;
            } else {
                f = false;
                break;
            }
        }
        if (!f) break;
        c++;
    }

    cout << c << endl;

    return 0;
}

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

int main(){
    int n,h,w;cin>>n>>h>>w;
    int ans = 0;
    int a,b;
    rep(i,n){
        cin>>a>>b;
        if(a>=h&&b>=w)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3548
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
l = max(a).bit_length()
ans = 0
M = 10**9+7
for j in range(l):
    v0 = 0
    v1 = 0    
    for i in range(n):
        if (a[i]>>j)&1:
            v1 += 1
        else:
            v0 += 1
    ans += v0*v1*pow(2,j,M)
    ans %= M
print(ans%M)

Measured memory_bytes: 124700
#include <stdio.h>

int main(void) {
	char s[32];
	int i;
	if (scanf("%31s", s) != 1) return 1;
	for (i = 0; s[i] != '\0'; i++) {
		if (s[i] == ',') s[i] = ' ';
	}
	puts(s);
	return 0;
}


Measured memory_bytes: 128
#include "iostream"
using namespace std;

int main(){
	int n,m,ans=0;
	cin >> n;
	m = n;
	for (int i = 0; i < 10; i++) {
		ans += m % 10;
		m = m / 10;
	}
	if (n%ans == 0)cout << "Yes";
	else cout << "No";
	return 0;
}

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

int main() {
    const int MAX_COLOR_COUNT = 8;
    vector<int> existing_color(MAX_COLOR_COUNT, 0);

    int N;
    cin >> N;
    vector<int> a(N);
    for (auto& ai : a) cin >> ai;

    int count_over_red = 0;
    for (auto& ai : a) {
        int d = ai / 400;
        if (d >= MAX_COLOR_COUNT) {
            ++count_over_red;
            continue;
        }
        existing_color[d] = 1;
    }

    int min = 0;
    for (auto& c : existing_color) if (c) ++min;

    int max = min + count_over_red;

    cout << (min ? : 1) << " " << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <deque>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7, INF = 1e9 * 1e9 + 100;

ll check(ll vl, ll a, ll b) {
    /*vector<ll> vec1, vec2;
    for (int i = 1; i <= vl; i++) {
        if (i != a) vec1.push_back(i);
    }

    for (int i = 1; i <= vl; i++) {
        if (i != b) vec2.push_back(i);
    }
    if (vec1.size() < vl) vec1.push_back(vl + 1);
    if (vec2.size() < vl) vec2.push_back(vl + 1);
*/
    ll q = 0;
    ll q2 = 0, vl1 = (vl - 1) / 2, vl2 = (vl - 1) / 2;

    if (vl == 14) {
        cout << "";
    }
    if (vl % 2 != 0) {
        vl1 = (vl / 2) + 1;
        vl2 = vl1;
        if (vl1 >= a) vl1++;
        if (vl2 >= b) vl2++;
        q2 = vl1 * vl2;
    }
    else {
        vl1 = (vl - 1) / 2 + 1, vl2 = vl1 + 1;
        if (vl1 >= a) vl1++;
        if (vl2 >= b) vl2++;
        if (vl2 < b) {
            ll q = b - vl2, v1 = vl1, v2 = vl2;
            v1 -= q;
            v2 = b + 1;
            q2 = v2 * v1;
        }
        if (vl1 < a) {
            ll q = a - vl1, v1 = vl1, v2 = vl2;
            v1 = a + 1;
            v2 -= q;
            q2 = max(v2, v2 * v1);
        }
        q2 = max(q2, vl2 * vl1);
        vl1 = (vl - 1) / 2 + 1, vl2 = vl1 + 1;
        vl1--;
        //if (vl2 < b) {
        //    ll q = b - vl2, v1 = vl1, v2 = vl2;
        //    v1 -= q;
        //    v2 = b + 1;
        //    q2 = v2 * v1;
        //}
        //if (vl1 < a) {
        //    ll q = a - vl1, v1 = vl1, v2 = vl2;
        //    v1 = a + 1;
        //    v2 -= q;
        //    q2 = max(v2, v2 * v1);
        //}
        if (vl1 >= a) vl1++;
        if (vl2 >= b) vl2++;
        
        q2 = max(q2, vl2 * vl1);
    }

   /* for (int i = 0; i < vl; i++) q = max(q, vec1[i] * vec2[vl - i - 1]);
*//*
    if (q != q2) {
        cout << "sdhfb";
    }*/
    q = q2;
    return q;
}

int main() {
    fastInp;

    ll n, k;
    cin >> n >> k;

    ll ans = 0;

    for (int i = k + 1; i <= n; i++) {
        ll l = -1, r = n + 1;
        ll am = (i - k);
        while (r - l > 1) {
            ll mid = (l + r) / 2;
            ll val = (mid / am) * i + (k + mid % am);
            if (val <= n) {
                l = mid;
            } else{
                r = mid;
            }
        }
        if (k == 0) ans--;
        ans += l + 1;
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 256
s = list(input())

a = int(s[0]+s[1])
b = int(s[2]+s[3])

if  1<=a<=12 and 1<=b<=12:
  print('AMBIGUOUS')
elif (a>12 or a==0) and 1<=b<=12:
  print('YYMM')
elif (b>12 or b==0) and 1<=a<=12:
  print('MMYY')
elif (a>12 or a==0) and (b>12 or b==0):
  print('NA')

Measured memory_bytes: 3064
package main

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

func main() {
	var n int
	fmt.Scanf("%d", &n)

	reader := bufio.NewReader(os.Stdin)
	R := make([]int, n) 
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &R[i])
	}

	var minv, maxv int
	maxv = -10e9
	minv = R[0]
	for i := 1; i < n; i++ {
		maxv = Max(maxv, R[i] - minv)
		minv = Min(minv, R[i])
	}

	fmt.Printf("%d\n", maxv)
}

func Max(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Min(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}


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

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}


int n;
vector<int> v;
int dp[1000000 + 4];

int solve(int i) {

    if(i == 0) return 0;
    if(dp[i] != -1) return dp[i];
    int dp_1 = abs(v[i-1] - v[i]) + solve(i-1);
    if(i-2 < 0) return dp[i] = dp_1;
    int dp_2 = abs(v[i-2] - v[i]) + solve(i-2);
    return dp[i] = min(dp_1, dp_2);
}


//Read through the messages at the end when you're done

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    
    cin>> n;
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < n; ++i) {
        int x; cin>> x;
        v.pb(x);
    }

    cout << solve(n-1) << '\n';

    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



Measured memory_bytes: 9336
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int n, a;
  vector<tuple<int,int>> as;
  cin >> n;

  REP(i, n) {
    cin >> a;
    as.push_back(make_pair(i+1,a));
  }

  sort(ALL(as), [](tuple<int,int> a, tuple<int,int> b) -> bool { return get<1>(a) < get<1>(b); });

  cout << get<0>(as[0]);
  REP(i, n-1) {
    cout << " " << get<0>(as[i+1]);
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 1780
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;

int bubble_sort(int A[], int N) {
    int count = 0;
	for (int i = 1; i < N; ++i) {
		bool flag = true;
		while (flag) {
            flag = false;
			for (int j = N - 1; j > 0; --j) {
				int tmp = A[j - 1];
				if (A[j] < tmp) {
					A[j - 1] = A[j];
					A[j] = tmp;
					flag = true;
                    ++count;
				}
			}
		}
	}
    return count;
}

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

	int A[100] = {};
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int count = bubble_sort(A, N);
    for(int i = 0; i < N; ++i){
        if(i != 0) cout << " ";
        cout << A[i];
    }
    cout << "\n";
    cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3204
import java.util.Scanner;

import java.util.ArrayList;
import java.util.List;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		int[] flag = new int[26];
		String str = "";
		// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// try{
		// str = br.readLine();
		// }catch(IOException e){

		// }
		Scanner scan = new Scanner(System.in);
		try{
		while (scan.hasNextLine()) {
			String tmp = "";
			tmp = scan.nextLine();
				str = str + tmp;
				// System.out.println(tmp.length());
				if(tmp.length() == 0){
					break;
				}
		}
	}finally{
	}
		int cnt = 0;
		while (cnt < str.length()) {
			char s = str.charAt(cnt);
			// if((int)s >= 65 && (int)s <= 122){
			if ((int) s >= 65 && (int) s <= 90) {
				flag[s - 65]++;
			} else if ((int) s >= 97 && (int) s <= 122) {
				flag[s - 97]++;
			}
			// }
			cnt++;
		}
		for (int i = 0; i < 26; i++) {
			System.out.println((char) (i + 97) + " : " + flag[i]);
		}
	}

}



Measured memory_bytes: 26284
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int i,j,k,n,m;
void read(int &x){
	char c;x=0;do c=getchar();while(c>57||c<48);
	do x=x*10+c-48,c=getchar();while(c<=57&&c>=48);
}
void read(ll &x){
	char c;x=0;do c=getchar();while(c>57||c<48);
	do x=x*10+c-48,c=getchar();while(c<=57&&c>=48);
}
int f(int x){
	if(x==0)return 0;
	return f(x/10)+1;
}
int main() {
    cin>>n;
	int ans=0;
	for(i=1;i<=n;i++)ans+=f(i)%2;
	cout<<ans<<endl;
    return 0;
}

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

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var s = Reads();
            if(s.Contains("P")&& s.Contains("W") && s.Contains("G") && s.Contains("Y"))
            {
                WriteLine("Four");
            }
            else
            {
                WriteLine("Three");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 13268
import java.util.*;
import java.util.Arrays;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a[] = new int[3];
        for (int i=0;i<3;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[0]+a[1]);
    }
}

Measured memory_bytes: 23252
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main{
    static int sx = 0, sy = 0;
    static int ans = 11;
    static int[] dx = {1, 0, -1, 0};
    static int[] dy = {0, 1, 0, -1};
    static int[][] field;
    static int w;
    static int h;

    public static int dfs(int x, int y, int m) {
        for (int dir = 0; dir < 4; dir++) {
            int nh = y;
            int nw = x;
            for(int i = 0; i < 21; i++){
                nh = nh + dy[dir];
                nw = nw + dx[dir];
                if(nh < 0 || nh >= h || nw < 0 || nw >= w) break;
                if(i==0 && field[nh][nw] == 1) break;

                if(field[nh][nw] == 1){
                    field[nh][nw] = 0;
                    nh = nh - dy[dir];
                    nw = nw - dx[dir];
                    if(m<=10)dfs(nw, nh, m + 1);
                    nh = nh + dy[dir];
                    nw = nw + dx[dir];
                    field[nh][nw] = 1;
                    break;
                }
                if(field[nh][nw] == 3){
                    if(m < ans) ans = m;
                    break;
                }
            }
        }
        return ans;
    }

	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            ans = 11;
            if(w == 0&&h == 0) break;
            field = new int[h][w];

            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    field[i][j] = sc.nextInt();
                    if(field[i][j] == 2){
                        sx = j;
                        sy = i;
                    }
                }
            }

            int m = 1;
            int t = dfs(sx, sy, m);
            
            if(t <= 10) System.out.println(t);
            else System.out.println(-1);
    
        }
        
        sc.close();
    }
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n, g;
    cin >> n;
    vector<int>student(n);
    rep(i, n) {
        cin >> g;
        student[g - 1] = i+1;
    }
    rep(i, n - 1)cout << student[i] << " ";
    cout << student[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1152
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
sum = 0
for i in range(0, N+1):
	sum += abs(A[i+1]-A[i])
for i in range(1, N+1):
	print(sum - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1]))

Measured memory_bytes: 64876