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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

int main(int argc, char ** argv) {
	ll n;
	cin >> n;
	vi a(n,0);
	vector<bool> col(8, false);
	ll num_pros = 0;
	for(ll i=0; i<n; i++) {
		cin >> a[i];
		if(a[i] < 3200) col[a[i]/400] = true;
		else num_pros++;
	}
	ll min_cols = 0;
	for(ll i=0; i<8; i++) if(col[i]) min_cols++;
	if(min_cols == 0) cout << 1 << " " << num_pros << endl;
	else cout << min_cols << " " << min_cols+num_pros << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  
  if(s.at(0) == t.at(2) &&
     s.at(1) == t.at(1) &&
     s.at(2) == t.at(0)){
    cout << "YES" <<  endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
[k,n] = list(map(int, input().split()))

li = list(map(int, input().split()))

distances = []
for i in range(n):
    if i == 0:
        distances.append(li[n-1] - li[i])
    else:
        distances.append(k - (li[i] - li[i-1]))

print(min(distances))


Measured memory_bytes: 26436
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 10005;
const int inf = (int) 1e9;

int h, n;
int memo[N];
vector < pair <int, int> > vec;

int dp(int h) {
  if (h <= 0) return 0;
  if (memo[h] != -1) return memo[h];
  int ans = inf;
  for (int i = 0; i < vec.size(); i++) {
    ans = min(ans, dp(h - vec[i].first) + vec[i].second);
  }
  return memo[h] = ans;
}

int main() {
  cin >> h >> n;
  memset(memo, -1, sizeof memo);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vec.push_back({x, y});
  }
  cout << dp(h) << endl;
  return 0;
}


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

using namespace std;

#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz(a) int((a).size())
#define F first
#define S second

#define rep(i, a, b) for(int i = a; i < b; ++i)
#define per(i, a, b) for(int i = a; i >= b; --i)
#define travel(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define INDEX(arr,ind)          (lower_bound(all(arr),ind)-arr.begin())

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;


typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

inline ll powmod(ll x, ll n, ll _mod){ 
  ll res = 1; 
  while (n){
    if (n & 1)res = (res*x) % _mod; 
    x = (x*x) % _mod; 
    n >>= 1;
    }
    return res; 
  }

#define N 200005

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int a,b;
    cin>>a>>b;
    if(max(a,b)>8)cout<<":(\n";
    else cout<<"Yay!\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<ll,ll>
const ll N = 1e5+4 , M=N,inf=(ll)1e9;
const ll mod=1e9+7;
ll fastAbs(ll n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
//map< pair<ll,ll> , ll > mp;
const ll dx[4] = {1,0,0,-1};
const ll dy[4] = {0,-1,1,0};
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
void solve( int y ){
    string s , t ;
    cin >> s >> t ;
    int n = s.size() ;
    map < char , int > mp ;
    vector < pair < char , int  > > a(n) ;
    for( int i = 0 ; i < n ; i++){
        a[i].ff = s[i] ;
        a[i].ss = i ;
    }
    for( int i = n-1 ; i >= 0 ; i--)
        mp[s[i]] = i ;
    sort(st(a));
//    for( int i = 0 ; i < n; i++){
//        cout << a[i].ff << " " << a[i].ss << "\n";
//    }
    int start = 0 , end = n-1 ;
    ll answer = 0 ;
    for( int i = 0 ; i < t.size() ; i++){
       // cout << start << " " << end << "\n";
        char x = t[i] ;
        int l = 0 , r = n-1 ;
        int ans = -1 ;
        while(l<=r){
            int mid = (l+r)/2 ;
            if(a[mid].ff==x){
                    int k = a[mid].ss;
                    if(start<=k && k<=end){
                        ans = k;
                        r = mid - 1 ;
                    }
                    else if(end<k){
                        r = mid - 1 ;
                    }
                    else
                        l = mid + 1 ;
            }
            else if(a[mid].ff > x){
                r = mid - 1 ;
            }
            else
                l = mid + 1 ;
        }
        if(ans!=-1){
            answer+=ans-start+1;
            start = ans + 1 ;
            if(start>n-1)
                start = 0 ;
        }
        else{
            if(mp.find(x)!=mp.end()){
                answer+=end-start+1;
                start=mp[x]+1;
                answer+=start;
            }
            else{
                cout << "-1";
                return ;
            }
        }
    }
    cout << answer << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q=1;
    //cin >> q;
//    while(q--)
//        solve();
    for( int i = 1 ; i <= q ; i++) solve(i);
}


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

char ans[100000000];
int main(){
	int n;
	while (cin >> n, n){
		char conv[128] = {}, input;
		int m;
		for (int i = 0; i < n; i++){
			cin >> input;
			cin >> conv[input];
		}
		cin >> m;
		for (int i = 0; i < m; i++){
			cin >> input;
			if (conv[input] != 0) ans[i] = conv[input];
			else ans[i] = input;
			/*if (conv[input] != 0) printf("%c\n", conv[input]);
			else printf("%c\n", input);*/
		}
		for (int i = 0; i < m; i++){
			printf("%c", ans[i]);
		}puts("");
	}
}

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

int main() 
{
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 or B % 3 == 0 or (A+B) % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
}

Measured memory_bytes: 256
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

void selection(int *a,int n,int &d)
{
	int idx;
	for(int i=0 ; i<n-1 ; i++)
	{
		idx=i;
		for(int j=i+1 ; j<n ; j++)
		{
			if(a[idx]>a[j])
			{
				idx=j;
			}
		}
		if(idx!=i)
		{
			int tmp=a[i];
			a[i]=a[idx];
			a[idx]=tmp;
			d++;
		}
	}
	forin(i,0,n-1)
	printf("%d ",a[i]);
	printf("%d",a[n-1]);
	newline;
}

int main()
{
	int n;
	scd(n);
	int a[20000];
	scarrd(a,n);
	int d=0;
	selection(a,n,d);
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 3208
N,K=map(int,input().split())
V=list(map(int,input().split()))
r=min(N,K)
ans=0
for a in range(r+1):
    for b in range(r-a+1):
        tmp,minus=0,[]
        for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
        for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
        tmp-=sum(sorted(minus)[:K-(a+b)])
        ans=max(ans,tmp)
print(ans)


Measured memory_bytes: 9116
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>

using namespace std;


int main(){

	string str;
	getline(cin, str);

	for(int i=0 ; i<str.size() ; i++){
		if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] = str[i] + 'A' - 'a';
		}
	}
	cout << str << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }
    sort(a.rbegin(),a.rend());
    int alice = 0;
    int bob = 0;
    for(int i=0;i<N;i++){
        if(i%2 == 0){
            alice+=a.at(i);
        }
        else{
            bob+=a.at(i);
        }
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 764
s = input()
totalre = 0
q = int(input())
gm = []
gu = []
for _ in range(q):
    query = list(input().split())
    if int(query[0])==1:
        totalre += 1
    else:
        if (totalre + int(query[1]))%2 != 0:
            gm.append(query[2])
        else:
            gu.append(query[2])

if totalre%2==0:
    ans = ''.join(gm)[::-1] + s + ''.join(gu)
else:
    ans = ''.join(gu)[::-1] + s[::-1] + ''.join(gm)
print(ans)

Measured memory_bytes: 5724
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
ll dp[400][400];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    ll a[N];
    rep(i,0,N) cin>>a[i];
    ll s[N+1];
    s[0]=0;
    rep(i,1,N+1) s[i]=s[i-1]+a[i-1];
    rep(k,0,N){
        rep(i,0,N-k){
            if(k==0){
                dp[i][i+k]=0;
            }
            else{
                ll res=1e15;
                rep(j,i,i+k){
                    res=min(res,dp[i][j]+dp[j+1][i+k]);
                }
                dp[i][i+k]=res+s[i+k+1]-s[i];
            }
        }
    }
    cout <<dp[0][N-1]<<"\n";
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

template<typename T>
using reversed_priority_queue = \
    std::priority_queue<T, std::vector<T>, std::greater<T> >;

signed main() {
  ll n;
  cin>>n;
  reversed_priority_queue<double> q;
  rep(i,n) {
    double x;
    cin>>x;
    q.push(x);
  }
  rep(i,n-1){
    double x = q.top(); q.pop();
    double y = q.top(); q.pop();
    q.push((x+y)/2.0);
  }
  cout<<q.top()<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = cin.nextInt();
		Arrays.sort(a);
		cout.println(a[a.length - 1] - a[0]);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 20820
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1 == 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int maxl = 1e18;
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (a[i] == 0)
                c++;
        }
        if (c > 0) {
            cout << 0 << endl;
            continue;
        }
        int sum = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] > maxl / sum) {
                sum = -1;
                break;
            }
            else {
                sum *= a[i];
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 4320
import itertools

N, M = map(int, input().split())
E = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)

count = 0
for V in itertools.permutations(range(1, N)):
    if V[0] in E[0] and all(V[i] in E[V[i-1]] for i in range(1, N-1)):
        count += 1
print(count)


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

using namespace std;

class Node {
public:
	int parent, left, right;

	Node() {
		parent = left = right = -1;
	}
};

Node TreeInfo[25];

void showTreeByPreorder(int num) {

	if (num == -1) {
		return;
	}
	cout << " " << num;
	showTreeByPreorder(TreeInfo[num].left);
	showTreeByPreorder(TreeInfo[num].right);
}

void showTreeByInorder(int num) {

	if (num == -1) {
		return;
	}
	showTreeByInorder(TreeInfo[num].left);
	cout << " " << num;
	showTreeByInorder(TreeInfo[num].right);
}

void showTreeByPostorder(int num) {

	if (num == -1) {
		return;
	}
	showTreeByPostorder(TreeInfo[num].left);
	showTreeByPostorder(TreeInfo[num].right);
	cout << " " << num;
}

int main() {
	int n, id, left, right, rootId;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> left >> right;
		TreeInfo[id].left = left;
		TreeInfo[id].right = right;
		if (left != -1) {
			TreeInfo[left].parent = id;
		}
		if (right != -1) {
			TreeInfo[right].parent = id;
		}
	}
	
	for (rootId = 0; rootId < n; ++rootId) {
		if (TreeInfo[rootId].parent == -1) {
			break;
		}
	}

	cout << "Preorder" << endl;
	showTreeByPreorder(rootId);

	cout << endl << "Inorder" << endl;
	showTreeByInorder(rootId);

	cout << endl << "Postorder" << endl;
	showTreeByPostorder(rootId);
	cout << endl;

	return 0;
}


Measured memory_bytes: 3100
n,m=map(int,input().split())
a=[[int(b) for b in input().split()] for _ in range(n)]
c=[[int(d) for d in input().split()] for _ in range(m)]
for i in range(n):
    p=a[i]
    tmp=10**10
    pos=-1
    for j in range(m):
        cp=c[j]
        dist=abs(cp[0]-p[0])+abs(cp[1]-p[1])
        if dist < tmp:
            tmp=dist
            pos=j+1
    print(pos)

Measured memory_bytes: 3064
N = int(input())
A = input().split()
A = [int(i) for i in A]

c = 0 

while True:
  exist_odd = False
  for a in A:
    if a % 2 != 0:
      exist_odd = True
    
  if exist_odd: break

  for i in range(N):
    A[i] = A[i] / 2
  
  c = c + 1
print(c)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0; i<h; ++i)
        cin >> s[i];

    vector<string> red = s;
    vector<string> blue = s;

    for(int x=0; x<w; ++x){
        red[0][x] = '#';
        blue[h-1][x] = '#';
        if(x % 2 == 0){
            for(int y=1; y<h-1; ++y)
                red[y][x] = '#';
        }
        else{
            for(int y=1; y<h-1; ++y)
                blue[y][x] = '#';
        }
    }

    for(int i=0; i<h; ++i)
        cout << red[i] << endl;
    cout << endl;
    for(int i=0; i<h; ++i)
        cout << blue[i] << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
    #include <vector>
    #include <string>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <unordered_map>
    #include <algorithm>
    #include <functional>
    #include <numeric>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <cassert>
    #define bogo_sort std::sort
    #define bozo_sort std::stable_sort
    #define alles(obj) obj.begin(), obj.end()
    #define elif else if
    #define unless(flg) if(!(flg))
    #define elless(flg) else if(!(flg))
    #define echo std::cout <<
    #define read std::cin >>
    #define endl std::endl
    #define fin << '\n'
    #define bash push_back
    #define makePair std::make_pair
    #define _ << ' ' <<
    // type-define
    #define Stack std::stack
    #define Queue std::queue
    #define Set std::set
    #define PQueue std::priority_queue
    #define Vector std::vector
    #define Pair std::pair
    #define Map std::map
    #define UMap std::unordered_map
    #define Greater std::greater
    using String = std::string;
    using llong = long long;
    using boolean = bool;
    using Pii = Pair<int, int>;
    using Vi = Vector<int>;
    using Vii = Vector<Pii>;
    // utils
    constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
    constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
    constexpr int INF = 0x3f3f3f3f;
    constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;
     
    namespace {
    llong power ( llong x, llong n, llong mod ) {
    llong ans = 1;
    while ( n > 0 ) {
    if ( n & 1 ) ans = ( ans * x ) % mod;
    x = ( x * x ) % mod;
    n >>= 1;
    }
    return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs ( llong n ) { return ( n < 0 ) ? -n : n; }
    boolean chmax ( llong &a, llong b ) { return a<b ? a=b, true : false; }
    boolean chmin ( llong &a, llong b ) { return b<a ? a=b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
    return ( x >= 0 && y >= 0 && x < w && y < h );
    }
    }
     
    namespace Rlyeh {
     
    int h[110];
     
    signed call_of_Cthulhu( signed datum ) {
     
    int cnt = 0;
    int left = 0;
    int n;
    read n;
    for ( int i = 0; i < n; i++ ) {
    read h[i];
    if ( h[i] ) {
    left++;
    }
    }
     
    while ( left ) {
    for ( int i = 0; i < n; i++ ) {
    if ( h[i] ) {
    cnt++;
    for ( int j = i; h[j]; j++ ) {
    h[j]--;
    unless(h[j]) left--;
    }
    goto hori;
    }
    }
    hori:;
    }
     
    echo cnt fin;
     
    return 0;
    }
    }
     
    signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}

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

int main() {
    ll N;
    cin >> N;

    vl D(1e5+9, 0);
    ll ans = 0;
    ll A;
    rep(i, N) {
        cin >> A;
        D[A]++;
        ans += A;
    }

    ll Q;
    cin >> Q;
    ll B, C;
    rep(i, Q) {
        cin >> B >> C;
        ans -= (B*D[B]);
        ans += (C*D[B]);
        D[C] += D[B];
        D[B] = 0;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4048
N, M = map(int, input().split())
A = list(map(int, input().split()))
import collections
mod_table=collections.defaultdict(int)
com_sum = [0] * (N+1)
for i in range(N):
    com_sum[i+1] = A[i] + com_sum[i]
ans = 0
for i in range(N+1):
    mod = com_sum[i] % M
    mod_table[mod]+=1
    
for x in mod_table:
  y = mod_table[x]
  if y > 1:
    ans += y*(y-1)//2

print(ans)


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

int main() {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans1 = x * a + y * b;
  ll ans2;
  if (x >= y) {
    ans2 = y * (2 * c) + (x - y) * a;
  } else {
    ans2 = x * (2 * c) + (y - x) * b;
  }
  ll ans3 = max(x, y) * (2 * c);
  cout << min({ans1, ans2, ans3}) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read

N, *A = map(int, read().split())

answer = 0
for i in range(N - 1):
    if A[i] % 2 == 1:
        if A[i + 1] != 0:
            A[i + 1] += 1
    answer += A[i] // 2

answer += A[-1] // 2
print(answer)

Measured memory_bytes: 14092
#include<stdio.h>
int main()
{
    int a, b;scanf("%d%d", &a, &b);
    int k = (a+b)/2;
    if((a%2==0)&&(b%2==0))
    {
        printf("%d\n", k);
    }
    else if(((a%2==1)&&(b%2==1)))
        {
        printf("%d\n", k);
    }
    else
    {
        printf("%d\n", k+1);
    }
}


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

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll n, k, b, cnt = 0;
    cin >> n >> k;
    //b = pow(10,k);
    while(n > 0){
        n = n / k;
    //    cout << n << endl;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}
/*
         ,--"""",--.__,---[],-------._
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int h, w, n;
	cin >> h >> w >> n;
	int num = max(h,w);
	int ans;
	if(n%num == 0){
		ans = n/num;
	}else{
		ans = n/num + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import re
S = input()
q = int(input())
C = []
for i in range(q):
    C.append(re.split('\s',input()))
for i in C:
    if i[0] == 'replace':
        a = int(i[1])
        b = int(i[2])
        S = S[0:a] + i[3][0:b-a+1] + S[b+1:len(S)]
    elif i[0] == 'reverse':
        a = int(i[1])
        b = int(i[2])
        S = S[0:a] + S[a:b+1][::-1] + S[b+1:len(S)]
    else:
        a = int(i[1])
        b = int(i[2])
        print(S[a:b+1])


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

int main() {
    int N, cnt = 0, tmp;
    cin >> N;

    vector<int> Button(N);
    for (int i = 0; i < N; i++) {
        cin >> Button.at(i);
    }
    
    //入力層終わり

    for (cnt = 0; cnt < N; cnt++) {
        if (cnt == 0) tmp = 1;
        
        if (tmp == 2) {
            break;
        }

        tmp = Button.at(tmp - 1);
    }

    if (cnt == N && tmp != 2) {
        cnt = -1;
    }

    else if (cnt == N && tmp == 2) {
        cnt--;
    }
    cout << cnt << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (u == s){
    a--;
  } else if (u == t){
    b--;
  }
  cout << a << " " << b << "\n";
  return 0;
}

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

int n,m,q;
vector<int> a,b,c,d;
ll ans;

void dfs(vector<int> A){
  if(A.size()==n+1){
    ll now = 0;
    rep(i,q){
      if(A[b[i]]-A[a[i]]==c[i]){
	//ans+=d[i];
	now += d[i];
      }
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while(A.back()<=m){
    dfs(A);
    A.back()++;
  }
  
}

int main(void){
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  //vector<int> a(q),b(q),c(q),d(q);
  rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];

  dfs(vector<int>(1,1)); //The first "1" is a dummy var.
                         //1 * * *. "*"が配列Aを表している
  cout << ans << endl;
  
  return 0;
}


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

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

    if(n > m){
        int tmp = n;
        n = m;
        m = tmp;
    }

    long long int ans = 0;
    if(n == 1){
        if(m == 1) ans = 1;
        else if(m >= 3) ans = m-2;
    }else if(n == 2){
        ans = 0;
    }else{
        ans = (long long int)(m-2)*(n-2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{ 
    ll a,ans=0;
cin>>a;
     for (ll i = 0; i <= a; i++)
     {
         if (i%15==0||i%3==0||i%5==0)
         {
             continue;
         }
         ans+=i;
     }
     
      cout<<ans<<endl;
      
      
    return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a,b,c;
  cin >> a >> b >> c;
  ll ans = 0;
  if(a==b) ans++;
  if(a==c) ans++;
  if(b==c) ans++;
  if(ans==1)pri("Yes");
  else pri("No");

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define PI 3.14159265358979323844
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define int long long int 
#define forr(i,a,b) for (int i= a; i <b; ++i)
using namespace std; 
 signed main(){
 int n;cin>>n;
  int a[n];
  int b[n];
  forr(i,0,n)cin>>a[i];
    forr(i,0,n)cin>>b[i];
  int dp[n];
  memset(dp,0,sizeof dp);
  map<int,int> mean;
  mean[a[0]]=b[0];
  dp[0]=b[0];
  forr(i,1,n){
      dp[i]=b[i];
   auto it = mean.lower_bound(a[i]+1);
        if(it!=mean.begin())   
        {   it--;
            dp[i]+=(it->second);
        }
       mean[a[i]]= dp[i];
      it = mean.upper_bound(a[i]);
      
      while(it!=mean.end() &&it->second<=dp[i]){
          auto temp=it;
          temp++;
          mean.erase(it);
           it=temp;
      }
  }
  int maxx=0;
  forr(i,0,n)maxx=max(maxx,dp[i]);
 cout<<maxx;}

Measured memory_bytes: 17408
N = int(input())
robots = []
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x-l, x+l))

robots.sort(key=lambda x: x[1])  # 終端を昇順ソート
# print(robots)
cnt = 0
last = -10**18  # 最初、最右のものははるか左側にあると考える
for left, right in robots:
    if left >= last:  # 残せるのであれば
        cnt += 1
        last = right
print(cnt)


Measured memory_bytes: 18260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=214514;
bool visit[N];
vector<vector<ll>> con(N);
ll cnt[N];
void dfs(ll x){
	visit[x]=1;
	for(int i=0;i<con[x].size();i++){
		if(!visit[con[x][i]]){
			cnt[con[x][i]]+=cnt[x];
			dfs(con[x][i]);
		}
	}
}
int main() {
	ll n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		ll a,b;
		cin>>a>>b;
		con[a].push_back(b);
		con[b].push_back(a);
	}
	for(int i=0;i<q;i++){
		ll p,x;
		cin>>p>>x;
		cnt[p]+=x;
	}
	dfs(1);
	for(int i=1;i<=n;i++){
			cout<<cnt[i]<<' ';
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 21632
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        final int  MX = (int)(1e5);
        int[] card = new int[MX+1];
        int remove = 0;
        int mem = 0;
        for(int i = 0;i<n;i++){
            card[in.nextInt()]++;
        }
        int ans = 0;
        for(int i = 1;i<=MX;i++){
            if (card[i]>=2){
                if(card[i]%2==0){
                    card[i]=2;
                }
                else {
                    card[i]=1;
                }

            }
            if(card[i]==2){
                if(remove==0){
                    remove=2;
                    mem=i;
                }
                else
                {
                    card[mem]=1;
                    card[i]=1;
                    remove=0;
                    ans--;
                }
            }
            ans+=card[i];
        }
        if(remove>0){
            ans-=2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 52720
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f
typedef long long ll;
const int maxn = 1e2+5;
ll n,k;
int main(){
	cin >> n >> k;
	n %= k;
	ll ans = min(abs(n - k),abs(abs(n- k) - k));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next(); //予報の天気
        String T = sc.next(); //実際の天気
        int count = 0;

        for (int i = 0; i < 3; i++) {
            if (S.charAt(i) == T.charAt(i)) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int d, g, a = 1e9;
  cin >> d >> g; g /= 100;
  v1i n(d), b(d), p(d), c(d);
  rep(i, d){
    cin >> n[i] >> b[i];
    b[i] /= 100;
    p[i] = (i+1)*n[i]+b[i];
    c[i] = (i+1)*(n[i]-1);
  }
  rep(i, pow(3, d)){
    int tmp = 0, e = i, f = 0, h = 0;
    bool k = 1, l = 0;
    rep(j, d){
      if(e % 3 == 1){
        tmp += p[j];
        f += n[j];
      }
      else if(k && e % 3 == 2){
        tmp += c[j];
        h = j+1;
        k = 0;
      }
      else if(e % 3 == 2){
        l = 1;
        break;
      }
      e /= 3;
    }
    if(l) continue;
    if(tmp >= g){
      if(h > 0){
        tmp -= c[h-1];
        if(tmp < g) f += (g-tmp-1)/h+1;
      }
      a = min(a, f);
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

struct Card{
	char suit;
	int value;
};


void bubbleSort(struct Card x[], int N)
{
	int i, j;
	struct Card tmp;
	for(i=0; i<N-1; i++){
		for(j=N-1; j>i; j--){
			if(x[j].value < x[j-1].value)
			{
				tmp = x[j];
				x[j] = x[j-1];
				x[j-1] = tmp;
			}
		}
	}
}


void selectionSort(struct Card x[], int N)
{
	int i, j, minj;
	struct Card tmp;
	for(i=0; i<N; i++){
		minj = i;
		for(j=i; j<N; j++){
			if(x[j].value < x[minj].value)
			{
				minj = j;
			}
		}
		tmp = x[i];
		x[i] = x[minj];
		x[minj] = tmp;
	}
}


int main(void)
{
	int N;
	struct Card c1[36], c2[36];
	
	scanf("%d", &N);
	
	int i;
	for(i=0; i<N; i++){
		scanf(" %c%d", &c1[i].suit, &c1[i].value);
	}
	
	for(i=0; i<N; i++){
		c2[i] = c1[i];
	}
	
	for(i=0; i<N-1; i++){
		bubbleSort(c1, N);
		printf("%c%d ", c1[i].suit, c1[i].value);
	}
	printf("%c%d\n", c1[N-1].suit, c1[N-1].value);
	printf("Stable\n");
	
	for(i=0; i<N-1; i++){
		selectionSort(c2, N);
		printf("%c%d ", c2[i].suit, c2[i].value);
	}
	printf("%c%d\n", c2[N-1].suit, c2[N-1].value);
	int count=0;
	for(i=0; i<N; i++){
		if(c1[i].suit != c2[i].suit) count++;
	}
	if(count == 0) printf("Stable\n");
	else printf("Not stable\n");
	
	return 0;
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e8+1, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,i;
	cin>>n;
	vector<int> dp(n),a(n);
	for(i=0;i<n;i++) cin>>a[i];
	if(n>1)dp[1]=abs(a[0]-a[1]);
	for(i=2;i<n;i++){
		dp[i]=min( dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2]+ abs(a[i]-a[i-2]) );
	}
	cout<<dp[n-1];
}
// check for any potential overflow before submitting



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int d = gcd(a, b);
    if(c % d == 0) YES(); else NO();
}

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

int main() {
  ll a,b,c,d; cin >> a >> b >> c >> d;
  ll ans;
  if (a>0) {
    if (c>0) {
      ans = b * d;
    } else {
      if (d<=0) ans = a * d;
      else ans = max(a * c, b * d);
    }
  }
  else {
    if (b<0) {
      if (c>0) ans = b * c;
      else ans = a * c;
    } else {
      if (c>0) {
        ans = b * d;
      } else {
        if (d>0) ans = max(a * c, b * d);
        else ans = a * c;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define int long long

const int N = 3005;
const int INF = 1e9;
int dp[N][N];
string s, t;

int sol(int i, int j) {
    if (i == s.size() || j == t.size()) return dp[i][j] = 0;
    int &ans = dp[i][j];
    if (ans != -1) return ans;
    if (s[i] == t[j]) return ans = sol(i + 1, j + 1) + 1;
    return ans = max(sol(i + 1, j), sol(i, j + 1));
}

void get(int i, int j) {
    if (i == s.size() || j == t.size()) return;
    if (s[i] == t[j]) {
        cout << s[i];
        get(i + 1, j + 1);
    } else {
        int a2 = dp[i + 1][j];
        int a3 = dp[i][j + 1];
        if (a2 >= a3) get(i + 1, j);
        else get(i, j + 1);
    }
}

void solve() {
    cin >> s >> t;
    memset(dp, -1, sizeof(dp));
    sol(0, 0);
    get(0, 0);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 71040
//2019.7.26 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
#define Pi 2.0*acos(-1.0)
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG __int128 x){
//    if(x>10)write(x/10);
//    putchar(x%10+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=5e2+10;
namespace MAIN{
    int n,kcz;
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int Add(const res &x,const res &y){
        return x+y>=kcz?x+y-kcz:x+y;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    Pair a[N];
    int buc[N],top,ans;
    inline int F(const res &x,const res &y){
        res i=0;
        while(i<(n<<1)&&i*i+y*y<x*x)i++;
        return i;
    }
    inline int G(const res &x,const res &y){
        res i=0;
        while(i<(n<<1)&&i*i+y*y<=x*x)i++;
        return i;
    }
    int dp[N];
    inline void MAIN(){
        n=read(),kcz=read();
        for(res i=0;i<n;i++)a[++top]=mp(F(n,i),-i);
        for(res i=n;i<n<<1;i++)a[++top]=mp(G(n<<1,i),1);
        for(res i=0;i<n;i++)buc[i]=G(n<<1,i);
        sort(a+1,a+top+1);
        for(res k=0;k<=n;k++){
            for(res i=0;i<=k;i++)dp[i]=0;
            dp[0]=1;
            res s1=0,s2=0;
            for(res i=1;i<=top;i++)
                if(a[i].se==1){
                    for(res j=0;j<=min(k,s2);j++)dp[j]=mul(dp[j],Add(a[i].fi,kcz-s1-j));
                    s1++;
                }
                else {
                    for(res j=min(k,s2);~j;j--)add(dp[j+1],mul(dp[j],Add(a[i].fi,kcz-s1-j))),dp[j]=mul(dp[j],Add(buc[-a[i].se],kcz-n-k-s2+j));
                    s2++;
                }
            add(ans,(k&1)?kcz-dp[k]:dp[k]);
        }
        printf("%d\n",ans);
    }
}
int main(){
//    freopen("compound1.in","r",stdin);
//    freopen("compound.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256