akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
int main() {
  int n,l;
  string ans="";
  cin >> n>>l;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s[i];
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++) ans += s[i];
  cout << ans <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

//		long ans2 = 0;
//		long ans = 0;
		int ans = 0;

		Scanner sc = new Scanner(System.in);


		int n = sc.nextInt();
		int k = sc.nextInt();
//		int k = sc.nextInt();

//		String string = sc.next();
//		StringBuilder s = new StringBuilder(string);

		boolean f = false;

//

//		int[] b = new int[n];
//		int[][] aa = new int[h][w];
//		int[] bb = new int[n];
//		for (int i = 0; i < h; i++) {
//			for(int j = 0; j < w; j++) {
//				a[i][j] = sc.nextInt();
//			}
//		}
//		for (int i = 0; i < n; i++) {
//			b[i] = sc.nextInt();
//			bb[i] = b[i];
//		}

		if(n == 1 || k == 1) {
			if(k == 2 || n == 2) {
				ans = 3;
			} else {
				ans = 2;
			}
		} if (n == 2||k == 2) {
			if(n == 3|| k == 3) {
				ans = 1;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 22868
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int ans = min(B / A, C);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

char maze[1000][1000];
int H;
int W;

int score[1000][1000];
const int dh[] = {1, -1, 0, 0,1,1,-1,-1,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2};
const int dw[] = {0, 0, 1, -1,1,-1,1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1};
  
void bfs(int i, int j) {
  deque<pair<int,int> > Q;
  score[i][j] = 0;
  Q.push_back(make_pair(i, j));
  while(!Q.empty()) {
    pair<int,int> q = Q.front();
    Q.pop_front();
    int h = q.first;
    int w = q.second;
    for (int k = 0; k < 24; k++) {
      int nh = h + dh[k];
      int nw = w + dw[k];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) {
        continue;
      }
      if(maze[nh][nw]=='#') continue;
      if (k<4 && score[nh][nw]>score[h][w]){
        Q.push_front(make_pair(nh, nw));
        score[nh][nw] = score[h][w];
      }
      if(score[nh][nw]>score[h][w]+1){
        Q.push_back(make_pair(nh, nw));
        score[nh][nw] = score[h][w]+1;
      }
    }
  }
}
  
int main() {
  cin >> H >> W;
  
  ll ch,dh,cw,dw;
  cin>>ch>>dh>>cw>>dw;
  ch--,dh--,cw--,dw--;
  
  rep(i,1000){
    rep(j,1000) score[i][j]=1e9;
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> maze[i][j];
  }
  
  bfs(ch, dh);
  
  if(score[cw][dw]==1e9) cout<<-1<<endl;
  else cout<<score[cw][dw]<<endl;

  return 0;
}

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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int l = a + b, r = c + d;
	if (r == l) cout << "Balanced";
	else if (r > l) cout << "Right";
	else cout << "Left";
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
 
int main(){
int b[4][3][10];
int n;

memset(b,0,sizeof(b));

scanf("%d",&n);
for(int i=0;i<n;i++){
	int c,d,e,f;
	scanf("%d%d%d%d",&c,&d,&e,&f);
	b[c-1][d-1][e-1]+=f;
	}

for(int i=0;i<4;i++){
	if(i)puts("####################");
	for(int j=0;j<3;j++){
		for(int k=0;k<10;k++){
			printf(" %d",b[i][j][k]);
		}
		puts("");
	}
}


//scanf("%d",&n);

return 0;
 
}

Measured memory_bytes: 1036
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
p_list = _li()

cur_min = 10**7
count = 0
for p in p_list:
    if p <= cur_min:
        count += 1
    if p < cur_min:
        cur_min = p
print(count)


Measured memory_bytes: 23572
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;
long long power(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n%2 == 1) {
    return (x * power(x, n-1));
  } else {
    long long half = power(x, n/2);
    return (half * half);
  }
}

int main () {
  ll N;
  cin >> N;
  int A[110];
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }
  ll ans = power(3, N);
  ll amari = 1;
  for (auto i = 0; i < N; ++i) {
    if (A[i]%2 == 0) {
      amari *= 2;
    }
  }
  ans -= amari;
  cout << ans << endl;
}


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 P = pair<int, int>;

int main() {
  int k, s;
  cin >> k >> s;
  ll ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (0 <= s - x - y && s - x - y <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define inver(a,mod) power(a,mod-2,mod)
using namespace std;
inline char nc()
{
    // return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
typedef long long ll;
const int maxn=3000+50;
int mod,phi;
int n;
int fac[maxn],inv[maxn];
int S[maxn][maxn];
inline int add(int x) {return x>=mod?x-mod:x;}
ll power(ll x,ll y,int mod)
{
    ll re=1;
    while(y)
    {
        if(y&1) re=re*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return re;
}
inline ll binom(int x,int y)
{
    return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
void init(int n)
{
    fac[0]=1;
    for(int i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
    inv[n]=inver(fac[n],mod);
    for(int i=n;i>=1;--i) inv[i-1]=(ll)inv[i]*i%mod;
    S[0][0]=1;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=i;++j)
        {
            S[i][j]=(S[i-1][j-1]+(ll)S[i-1][j]*j)%mod;
        }
    }
}
int ways(int i)
{
    int re=0,w1=power(2,n-i,mod),w=1;
    for(int j=0;j<=i;++j) 
    {
        re=(re+(ll)S[i+1][j+1]*w)%mod;
        w=(ll)w*w1%mod;
    }
    re=(ll)re*power(2,power(2,n-i,phi),mod)%mod;
    return re;
}
int main()
{
    read(n),read(mod),phi=mod-1;
    init(n+1);
    int an=0;
    for(int i=0,f=1;i<=n;++i)
    {
        an=(an+f*binom(n,i)%mod*ways(i))%mod;
        f=mod-f;
    }
    printf("%d\n",an);
    return 0;
}

Measured memory_bytes: 34688
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()


 
void solve(){
 ll n,m,x;
  cin >> n >> m >> x;
  vll c(n);
  vvll a(n,vll(m));
  rep(i,0,n){
   cin >> c[i];
    rep(j,0,m) cin >> a[i][j];
  }
  
  ll res=inf;
  rep(bit,0,(1<<n)){
   vll und(m,0);
    ll cost=0;
    rep(i,0,n) {
      if((bit&(1<<i))==0) continue;
      cost+=c[i];
      rep(j,0,m) und[j]+=a[i][j];
    }
    ll flag=1;
    rep(j,0,m) if(und[j]<x) flag=0; 
    if(flag) chmin(res,cost);
  }
  
  if(res==inf) cout << -1 << endl;
  else cout << res << endl;
  
 
}

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


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+10;
const int B=316;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(LL x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int h,w;
int sx,sy,tx,ty;
char s[1010];
int mp[1010][1010];
int f[1010][1010];
struct P{
	int x,y,z;
}p,A;
deque< P > Q;
int xx[4]={-1,0,1,0};
int yy[4]={0,1,0,-1};
int main(){
	memset(f,60,sizeof(f));
	//cout<<f[1][1]<<endl;
	scanf("%d%d%d%d%d%d",&h,&w,&sx,&sy,&tx,&ty);
	for(int i=1;i<=h;++i){
		scanf("%s",s+1);
		for(int j=1;j<=w;++j)
			if(s[j]=='#') mp[i][j]=1;
	}
	p.x=sx;p.y=sy;p.z=0;
	Q.push_back(p);
	while(!Q.empty()){
		p=Q[0];
		Q.pop_front();
		if(p.z<f[p.x][p.y]){
			f[p.x][p.y]=p.z;
			for(int k=0;k<4;++k){
				A.x=p.x+xx[k];
				A.y=p.y+yy[k];
				A.z=p.z;
				if(mp[A.x][A.y]==0&&A.x>=1&&A.y>=1&&A.x<=h&&A.y<=w) Q.push_front(A);
			}
			for(int i=p.x-2;i<=p.x+2;++i){
				for(int j=p.y-2;j<=p.y+2;++j){
					if(mp[i][j]==0&&i>=1&&j>=1&&i<=h&&j<=w){
						A.x=i;A.y=j;A.z=p.z+1;
						Q.push_back(A);
					}
				}
			}
		}
	}
	if(f[tx][ty]<1e9) cout<<f[tx][ty]<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 13076
#include <bits/stdc++.h>
#define pb push_back
#define PI 3.1415926535897932
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i, a, n) for (int i = a; i < n; i++)
using namespace std;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n; cin>>n;
    vi v(n);
    f(i,2,n+1) {
        int x; cin>>x;
        v[x-1]++;
    }
    f(i,0,n) cout<<v[i]<<endl;

    return 0;
}

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

int main()
{
    int N; cin >> N;
    long long sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0 | i % 5 == 0) continue;
        else sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3644
import collections,sys
def s():
 d=collections.deque()
 input()
 for e in sys.stdin:
  if'i'==e[0]:d.appendleft(e.split()[1])
  else:
   if' '==e[6]:
    m=e.split()[1]
    if m in d:d.remove(m)
   elif len(e)%2:d.pop()
   else:d.popleft()
 print(*d)
if'__main__'==__name__:s()


Measured memory_bytes: 69732
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort()
lmx = len(bin(a[-1])) - 2
cnt = [[0,0] for _ in range(lmx)]
for i in a:
    for j in range(lmx):
        tt = 1 if (i>>j)&1 else 0
        cnt[j][tt] += 1

res = 0
for i,bit in enumerate(cnt):
    x,y = bit
    res += x*y*pow(2,i)
    res %= mod
print(res)

Measured memory_bytes: 119980
#include <iostream>

using namespace std;

int main()
{
    int n,k,ans=1;
    scanf("%d%d",&n,&k);
    while (n--)
        {
            if (ans<k) ans=ans*2;
            else ans=ans+k;
        }
    printf("%d",ans);
    return 0;
}


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

int ctoi(char c) {
  if( c >= '0' && c <= '9' ) return c-'0';
  else return -1;
}

signed main() {
  int N, K;
  cin >> N >> K;
  
  string S;
  cin >> S;
  
  vector<int> num;
  int start = ctoi(S.at(0));
  int cnt = 1;
  bool fg;
  if( S.at(0) == '1' ) fg = 1;
  else fg = 0;
  for( int i = 1; i < S.size(); i++ ){
    if( S.at(i) == S.at(i-1) ) cnt++;
    else{
      num.push_back(cnt);
      cnt = 1;
    }
  }
  num.push_back(cnt);
  
  int k = 0;
  int ans = 0; 
  int now = 0;
  for( int i = 0; i < num.size(); i++ ){
    now += num.at(i);
    if( start == 0 && i%2 == 0 ) k++;
    else if( start == 1 && i%2 == 1 ) k++;
    if( k > K ){
      now -= num.at(i-2*K);
      if( i-2*K-1 >= 0 ) now -= num.at(i-2*K-1);
      k--;
    }
    ans = max(ans, now);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1528
#include <iostream>
#include <cmath>

int main() {
    int D, N;
    std::cin >> D >> N;
    
    int base = std::pow(100, D);
    
    if (N < 100)
        std::cout << base * N << std::endl;
    else
        std::cout << base * (N+1) << std::endl;
}

Measured memory_bytes: 256
N = int( input() )
A, B = map( int, input().split() )
P = list( map( int, input().split() ) )

ans = [0]*3
for p in P:
    if p <= A: ans[0] += 1
    if A < p and p <= B: ans[1] += 1
    if B < p: ans[2] += 1

print( min(ans) )

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    x = II()
    print(1-x)

if __name__ == '__main__':
    solve()



Measured memory_bytes: 9220
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A = [int(x) for x in readline().split()]
s = max(A) * 3 - sum(A)
print(s // 2 if s % 2 == 0 else (s + 3) // 2)


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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);

const int N = 200100;

ll n,q,a[N],seg[N<<2];

ll mrg(ll x1,ll x2){
    return max(x1 , x2);
}

void build(int idx,int from,int to){
    if( from == to ){
        seg[idx] = a[from];
        return;
    }
    int mid = (from+to)>>1;
    build( idx<<1   , from  , mid );
    build( idx<<1|1 , mid+1 , to  );
    seg[idx] = mrg( seg[idx<<1] , seg[idx<<1|1] );
}

ll query(int idx,int from,int to,int l,int r){
    if( from>=l && to<=r )
        return seg[idx];
    if( from>r || to<l )
        return 0LL;
    int mid = (from+to)>>1;
    ll x1 = query( idx<<1   , from  , mid , l , r );
    ll x2 = query( idx<<1|1 , mid+1 , to  , l , r );
    return mrg( x1 , x2 );
}

int main(){
    SPEED
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    build(1,1,n);
    cout<<query(1,1,n,2,n)<<endl;
    for(int i=2;i<n;i++){
        cout<<max(query(1,1,n,1,i-1),query(1,1,n,i+1,n))<<endl;
    }
    cout<<query(1,1,n,1,n-1);
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

string G[15];

void dfs(int y, int x) {
   G[y][x] = '0';
   for (int i = 0; i < 4; i++) {
      int ny = y+dy[i], nx = x+dx[i];
      if (ny>=0 && ny<12 && nx>=0 && nx<12 && G[ny][nx]=='1') {
         dfs(ny, nx);
      }
   }
}

int main() {
   while (cin >> G[0]) {
      rep (i, 1, 12) {
         cin >> G[i];
      }

      int cnt = 0;
      for (int i = 0; i < 12; i++) {
         for (int j = 0; j < 12; j++) {
            if (G[i][j] == '1') {
               dfs(i, j);
               cnt++;
            }
         }
      }
      cout << cnt << endl;
   }

   return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	for (auto& x : L) cin >> x;
	int r = 0;
	for (int i = 0; i < N; ++ i) for (int j = i+1; j < N; ++ j) for (int k = j+1; k < N; ++ k) {
		if (L[i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
			vector<int> a = {L[i], L[j], L[k]};
			sort(a.begin(), a.end());
			if (a[0] + a[1] > a[2]) ++ r;
		}
	}
	cout << r << endl;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	int N; std::cin >> N;
	std::vector<int> a(N); for (auto& v : a)std::cin >> v;
	std::sort(a.begin(), a.end(), std::greater<int>());
	int alice = 0;
	int bob = 0;
	rep(i, N) {
		if (i % 2 == 0)alice += a[i];
		else bob += a[i];
	}

	std::cout << alice - bob;

	return 0;
}

Measured memory_bytes: 892
import java.util.*;

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();
      }

      int ans1 = 101;
      ///////////////////////////////////////////////
      for(int j=0;j<3;j++){
        if(a[j]<ans1){
          ans1 = a[j];
        }
      }
      for(int j=0;j<3;j++){
        if(a[j]==ans1){
          a[j] = 101;
          break;
        }
      }
      ///////////////////////////////////////////////

      int ans2 = 101;
      ///////////////////////////////////////////////
      for(int j=0;j<3;j++){
        if(a[j]<ans2){
          ans2 = a[j];
        }
      }
      for(int j=0;j<3;j++){
        if(a[j]==ans2){
          a[j] = 101;
          break;
        }
      }
      ///////////////////////////////////////////////


      System.out.println(ans1+ans2);

    }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
const int INF = 1e9;
int n, p[maxn];
pii Min[2][maxn << 2];
struct Seg
{
	int l, r;
	pii pos;
};
struct cmp
{
	bool operator () (const Seg & i, const Seg & j)
	{
		return p[i.pos.first] > p[j.pos.first];
	}
};
priority_queue<Seg, vector<Seg>, cmp> Q;
void pushup(int rt)
{
	Min[0][rt] = min(Min[0][ls], Min[0][rs]);
	Min[1][rt] = min(Min[1][ls], Min[1][rs]);
}
void build(int rt, int l, int r)
{
	if(l == r)
	{
		int id = l & 1;
		Min[id][rt] = mp(p[l], l);
		Min[id ^ 1][rt] = mp(INF, l);
		return;
	}
	int mid = l + r >> 1;
	build(ls, l, mid); build(rs, mid + 1, r);
	pushup(rt);
}
pii query(int rt, int l, int r, int a, int b)
{
	if(a <= l && r <= b) return Min[a & 1][rt];
	int mid = l + r >> 1;
	if(b <= mid) return query(ls, l, mid, a, b);
	if(a > mid) return query(rs, mid + 1, r, a, b);
	return min(query(ls, l, mid, a, b), query(rs, mid + 1, r, a, b));
}
pii getPos(int l, int r)
{
	pii p1 = query(1, 1, n, l, r);
	pii p2 = query(1, 1, n, p1.second + 1, r);
	return mp(p1.second, p2.second);
}
void ins(int l, int r)
{
	if(l > r) return;
	Q.push(Seg{l, r, getPos(l, r)});
}
void solve()
{
	vector<int> ans;
	ins(1, n);
	while(!Q.empty())
	{
		Seg x = Q.top(); Q.pop();
		ans.push_back(p[x.pos.first]);
		ans.push_back(p[x.pos.second]);
		ins(x.l, x.pos.first - 1);
		ins(x.pos.first + 1, x.pos.second - 1);
		ins(x.pos.second + 1, x.r);
	}
	for(auto v : ans) printf("%d ", v);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
	build(1, 1, n);
	solve();
	return 0;
}
	

Measured memory_bytes: 14196
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int N;
map<int, ll> M;
vector<int> Prime;

void enum_factor(){
    for(int i=2; i<=N; i++){
        bool OK = true;
        for(int j=2; j<=(int)sqrt(i); j++){
            if(i%j==0) OK = false;
        }
        if(OK) Prime.push_back(i);
    }
}

void factorization(int i){
    while(true){
        if(i==1) break;
        for(int p:Prime){
            if(i%p==0){
                M[p]++;
                i /= p;
                break;
            }
        }
    }
}

int main() {
    cin >> N;
    enum_factor();
    for(int i=2; i<=N; i++)
        factorization(i);
    
    ll ans = 1;
    for(auto m:M)
        ans = ans * (m.second + 1) % MOD;

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


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<i64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn convination(n: u64, m: u64) -> u64 {
    let mut ret = 1;
    if n < m {
        return 0;
    }
    for i in 0..m {
        ret *= n - i;
    }
    ret / m
}

fn main() {
    let _: u64 = input();
    let a_vec = input_vec();
    let mut cumulations: Vec<i64> = Vec::new();
    cumulations.push(0);

    let mut pre = 0;
    for a in a_vec { 
        let n = a + pre;
        cumulations.push(n);
        pre = n;
    }

    let mut nums_map: HashMap<i64, u64> = HashMap::new();
    for c in cumulations {
        let n = nums_map.entry(c).or_insert(0);
        *n += 1;
    }
    let mut sum = 0;
    for v in nums_map.values() {
        sum += convination(*v, 2);
    }
    println!("{}", sum);
}


Measured memory_bytes: 18052
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;

int Sumketa(long long x){
  int keta = 0;
  while(x!=0){
    x /= 10;
    keta++;
  }
  return keta;
}

int main(){
  long long n;
  cin >> n;
  int Max = Sumketa(n);

  for(long long a=1LL; a*a<=n; ++a){
    if(n%a!=0) continue;
    const long long b=n/a;

    const int cur = max(Sumketa(a),Sumketa(b));
    
    if(Max>cur){
      Max = cur;
    }
  }

  cout << Max << endl;
  return 0;

}


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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    long sum = 0;
    string s;
    for (int i = 1; i <= N; i++)
    {
        s = to_string(i);
        int sum_i = 0;
        for (int j = 0; j < s.size(); j++)
        {
            sum_i += s[j] - '0';
        }
        if (sum_i >= A && sum_i <= B)
        {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int n,k,a[105],i,j,l;
bool res[100005][2];
using namespace std;
int main(){
	cin>>n>>k;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=1;i<=k;i++)
	for(j=0;j<2;j++)
	for(l=0;l<n;l++)
	if(i>=a[l]&&!res[i-a[l]][j^1])res[i][j]=1;
	if(res[k][0])cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

longs = []
edges = {}
def graph_DP(node_to):
    global longs
    if longs[node_to] != -1:
        return longs[node_to]
    else:
        nodes_next = edges[node_to]
        if not nodes_next:
            longs[node_to] = 0
            return 0
        else:
            long_max_t = 0
            for node_next in nodes_next:
                if longs[node_next] != -1:
                    long_max_t = max(long_max_t, longs[node_next] + 1)
                else:
                    long_max_t = max(long_max_t, graph_DP(node_next) + 1)
            longs[node_to] = long_max_t
            return long_max_t

def main():
    global longs, edges
    n, m = map(int, input().split())
    edges = {e:set() for e in range(1, n + 1)}
    for _ in range(m):
        s, g = map(int, input().split())
        edges[s].add(g)
    longs = [-1] * (n + 1)

    for i1 in range(1, n + 1):
        if longs[i1] == -1:
            graph_DP(i1)
    print(max(longs))

if __name__ == '__main__':
    main()

Measured memory_bytes: 79456
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s[3];
  rep(i,3) R s[i];
  string t="";
  t+=s[0][0];
  t+=s[1][1];
  t+=s[2][2];
  pr(t);
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, d, i, p, k, j, tmp, sum, t=0;
	double dist;
	scanf("%d%d", &n, &d);
	int x[n][d];

	rep(i,n){
		rep(j,d){
			scanf("%d", &x[i][j]);
		}
	}

	rep(i,n-1){
		loop(p, i+1, n){
			sum = 0;
			rep(j,d){
				tmp = x[p][j] - x[i][j];
				sum += tmp*tmp;
			}
			dist = pow((double)sum, 0.5);
			if(dist == (int)dist){
				t++;
			}
		}
	}
	printf("%d", t);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, S = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
dp = [0] * (S + 1)
for l in range(N):
  r = N - l
  x = a[l]
  if x > S: continue
  for i in range(S, 0, -1):
    if i + x > S: continue
    if i + x == S:
      dp[S] += dp[i] * r
      dp[S] %= mod
    else:
      dp[i + x] += dp[i]
      dp[i + x] %= mod
  if x == S:
    dp[S] += (l + 1) * r
    dp[S] %= mod
  else:
    dp[x] += l + 1
    dp[x] %= mod
  #print(dp)
print(dp[-1])

Measured memory_bytes: 42092
# -*- coding: utf-8 -*-
import sys
from math import gcd

N, *AB = map(int, sys.stdin.buffer.read().split())

dict_F = {}
count_0 = 0

def insert(A,B,s): # A>=0, B>0, s=0or1
  if (A,B) not in dict_F.keys():
    dict_F[(A,B)] = [0,0]
  dict_F[(A,B)][s] += 1

def make_power2(N):
  result = 1
  list_result = [1]
  for _ in range(N):
    result = (2*result)%mod
    list_result.append(result)
  return list_result

for i in range(N):
  A,B = AB[2*i:2*i+2]
  if A==0 and B==0:
    count_0 += 1
    continue
  g = gcd(A,B)
  A //= g
  B //= g
  if A>=0 and B>0:
    insert(A,B,0)
  elif A>0 and B<=0:
    insert(-B,A,1)
  elif A<=0 and B<0:
    insert(-A,-B,0)
  elif A<0 and B>=0:
    insert(B,-A,1)

mod = 1000000007
power2 = make_power2(N)
answer = 1

for A,B in dict_F.values():
  answer = (answer*(power2[A]+power2[B]-1))%mod
answer = (answer+count_0-1)%mod

print(answer)

Measured memory_bytes: 92996
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A = list(map(int, readline().split()))

    Asum = sum(A)
    Amax = max(A)

    if Asum % 2 == 3 * Amax % 2:
        ans = (3 * Amax - Asum) // 2
    else:
        ans = (3 * (Amax + 1) - Asum) // 2

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8960
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
#define Maxn 45
int rel[Maxn][Maxn];
ll dp[Maxn][Maxn][Maxn];
char ch[Maxn];

ll dfs(ll l,ll r,ll m){
	if(~dp[l][r][m])return dp[l][r][m];
	if(l==r)return dp[l][r][m]=1;
	if(l==m||r==m)return dp[l][r][m]=0;
	ll res=0;
	for(int i=l;i<m;++i)
	    for(int q=m+1;q<=r;++q){
	    	ll tmp1=0;
	    	for(int p=i;p<m;++p)tmp1+=dfs(l,p,i)*dfs(p+1,q-1,m);
	    	ll tmp2=0;
	    	for(int j=q;j<=r;++j)
			    if(rel[i][j])tmp2+=dfs(q,r,j);
			res+=tmp1*tmp2;
		}
	return dp[l][r][m]=res;
}

int main(){
	scanf("%d",&n);
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=2*n;++i){
		scanf("%s",ch+1);
		for(int j=1;j<=2*n;++j)rel[i][j]=ch[j]-'0';
	}
	ll Ans=0;
	for(int i=2;i<=n*2;++i)
	    if(rel[1][i]){
	    	ll now=dfs(2,2*n,i);
	    	Ans+=now;
	    }
	printf("%lld\n",Ans);
	return 0;
} 


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


def solve(N: int, M: int, V: int, P: int, A: "List[int]"):
    A.sort(reverse = True)

    used_vote = (P-1)*M
    res = M*V-used_vote

    # res を振り分けていく
    a = A[P-1:]
    r = a[0]+1
    l = -1
    while r - l > 1:
        mid = (r+l)//2
        goal = mid+M

        # 絶対入れない
        if a[0] > goal:
            l = mid
            continue

        need= 0 
        for aa in a:
            need+=min(M,goal-aa)
        
        if need >=res: ##成功
            r = mid
        else:
            l = mid
    
    # l が最小の値
    for i in range(N):
        if A[i] > l:
            continue
        else:
            print(i)
            return
    print(N)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    V = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, V, P, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16244
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    rep(i,0,4) if(s[i]=='2') ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Print(x)      cerr << #x << "is " << x << '\n';
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 107;
const int M = 1e5 + 7;
const int mod = 1e9 + 7;

int n, k, a[N];
ll s[M], f[N][M];

void Enter()
{
     Cin(n, k);
     For(i, 1, n) Cin(a[i]);
}

ll Sum(int l, int r)
{
    if(l > r) return 0;
    r = min(r, k);
    if(l) return s[r] - s[l - 1];
    return s[r];
}

void Solve()
{
     f[0][k] = s[k] = 1;
     For(i, 1, n)
     {
         For(j, 0, k) f[i][j] += Sum(j, a[i] + j) % mod;
         s[0] = f[i][0];
         For(j, 1, k) s[j] = (f[i][j] + s[j - 1]) % mod;
     }
     cout << (f[n][0] % mod + mod) % mod;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


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

int main(){
	int w, h, i, j, k, c;
	
	while(1){
		int a[70][70] = {};
		cin>>w>>h;
		
		if(w == 0 && h == 0)break;
		
		
		for(i = 2; i <= w * 2; i += 2){
			a[0][i - 1] = 1;
			a[h * 2][i - 1] = 1;
		}
		
		for(j = 2; j <= h * 2; j += 2){
			a[j - 1][0] = 1;
			a[j - 1][w * 2] = 1;
		}
		
		for(i = 1; i <=  h; i++){
			for(j = 1; j < w; j++){
				cin>>a[i * 2 - 1][j * 2];
			}
			if(i != h){
				for(j = 1; j <= w; j++){
					cin>>a[i * 2][j * 2 - 1];
				}
			}
		}
		
		
		a[1][1] = 1;
		
		k = 1; c = 1;
		while(k >= 1){
			k = 0;
			for(i = 1; i < 2 * h; i +=2){
				for(j = 1; j < 2 * w; j +=2){
					if(a[i][j] == c){
						if(a[i-1][j] == 0){ if(a[i-2][j] == 0 ){ a[i-2][j] = c + 1;   k++;}}
						if(a[i+1][j] == 0){ if(a[i+2][j] == 0 ){ a[i+2][j] = c + 1;   k++;}}
						if(a[i][j+1] == 0){ if(a[i][j+2] == 0 ){ a[i][j+2] = c + 1;   k++;}}
						if(a[i][j-1] == 0){ if(a[i][j-2] == 0 ){ a[i][j-2] = c + 1;   k++;}}
					}
				}
			}
			c++;
			if(a[h * 2 - 1][w * 2 - 1] != 0) break;
		}
		
		cout<<a[h * 2 - 1][w * 2 - 1]<<endl;
	}
	
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

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

  vector<bool> ac(n+1);
  REP(i,n+1)ac[i]=false;
  vector<int> wa(n+1);
  REP(i,n+1)wa[i]=0;

  int ok=0;
  REP(i,m){
    int p;
    string s;
    cin >> p >> s;
    if(ac[p])continue;

    if(s=="AC"){
      ac[p]=true;
      ok++;
    }else{
      wa[p]++;
    }
  }

  int ng=0;
  REP(i,n+1){
    if(ac[i]==false)continue;
    ng+=wa[i];
  }
  cout << ok << " " << ng << endl;


}



Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string.h>

#define loop(lp) for(int lp2 = 0; lp2 < lp; lp2 ++) 
#define ascent(i,a,b) for(int i = a; i < b; i ++)

#define pb push_back

#define MAX 10000010

using namespace std;

bool flg[200000];
int  isprime[MAX];

int main() {
  //  vector<int> p1,p2;
  vector<int> p;

  ascent(i, 0, MAX) {
     isprime[i] = 1;
  }
   isprime[0] =  isprime[1] = 0;
  
  int cnt = 0;
  ascent(i, 2, MAX) {
    if(isprime[i]) {
      for(int j = 2*i; j <= MAX; j += i) {
	 isprime[j] = 0;
      }
    }
  }
  
  int N, P;
  while(cin >> N >> P) {
    if(N == -1 && P == -1) break;

    memset(flg, true, sizeof(flg));

    int k = N+1;
    int l = 0;
    p.clear();
    while(l < P) {
      if(isprime[k]) {
	p.pb(k);
	l ++;
      }
      k ++;
    }

    vector<int> vec;
    vec.clear();
    ascent(i, 0, p.size()) {
      ascent(j, i, p.size()) {
	  vec.pb(p[i] + p[j]);
	  //	  cout << p[i] + p[j] << endl;
      }
    }

    sort(vec.begin(), vec.end());
    cout << vec[P-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 40536
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        if(h % a == 0){
        System.out.println(h / a);
        }else{
        System.out.println(h / a + 1);
        }


    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int hr[1005],l[1005],r[1005];
int main(){
	int i,ans=0,n;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>l[i]>>r[i];
		hr[i]=r[i]-l[i]+1;
	}
	for(i=1;i<=n;i++) ans+=hr[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
h =list(map(int,input().split()))+[0]*10
inf = float('inf')
dp=[inf for _ in range(n+10)]
dp[0] = 0
for i in range(1,n):
    if i >=2:
        dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1]+abs(h[i]-h[i-1]))
    else:
        dp[i] = abs(h[i]-h[i-1])
print(dp[n-1])

Measured memory_bytes: 56312
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll umax(ll a ,ll b)
{
	if(a>b)return a;return b;
}
ll a[100001];
int main()
{
	ll n,w;cin >> n >> w;
	for(ll i=0;i<n;i++)
	{
		ll ww,vv;cin >> ww >> vv;
		for(ll j=w;j>=ww;j--)
		{
			a[j]=umax(a[j],a[j-ww]+vv);
		}
	}
	ll ans =0;
	for(ll i=0;i<100001;i++)
		ans=umax(ans,a[i]);
	cout << ans;

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
using namespace std;

int main()
{
	stack<int> s;
	int a, b;
	char ch[110];
	
	while(scanf("%s", ch) != EOF)
	{
		if(ch[0] == '+')
		{
			a = s.top();
			s.pop();
			b = s.top();
			s.pop();
			s.push(a + b);
		}
		else if(ch[0] == '-')
		{
			a = s.top();
			s.pop();
			b = s.top();
			s.pop();
			s.push(b - a);
		}
		else if(ch[0] == '*')
		{
			a = s.top();
			s.pop();
			b = s.top();
			s.pop();
			s.push(a * b);
		}
		else
		{
			s.push(atoi(ch));
		}
	}
	
	printf("%d\n", s.top());
	
	while(!s.empty())
	{
		s.pop();
	}
	
	return 0;
}


Measured memory_bytes: 3220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            try
            {

                // 整数配列の入力
                long[] ary = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

                var x = ary[0];
                var y = ary[1];

                if (y % 2 == 1)
                {
                    Console.WriteLine("No");
                    return;
                }

                if (x * 2 <= y && y <= x * 4)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                Console.WriteLine("No");
            }
            finally
            {


                Console.Out.Flush();
            }
        }
    }
}


Measured memory_bytes: 28228
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;
#define INFTY 1<<21

int main() {
  int W, H, N;
  int x, y, a;
  int xmin, xmax, ymin, ymax;
  cin >> W >> H >> N;

  xmax = W;
  ymax = H;
  xmin = 0;
  ymin = 0;

  for (int i = 0; i < N; i++) {
	cin >> x >> y >> a;
	if (a == 1) xmin = max(xmin, x);
	else if (a == 2)xmax = min(xmax, x);
	else if (a == 3)ymin = max(ymin, y);
	else if (a == 4)ymax = min(ymax, y);
  }
  if (xmax<xmin || ymax<ymin) {
	cout << 0 << endl;
  }
  else {
	cout << (xmax - xmin)*(ymax - ymin) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n;
	int x;
	int t;
	cin >> n>>x>>t;
	if (n%x == 0){
		cout << n/x*t  <<endl;
	}
	else {
		cout << (n/x+1)*t <<endl;
	}
}

Measured memory_bytes: 3192
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 3e18
#define ULMAX 18446744073709551615
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
#define deb1(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;

inline int add(int a, int b){a = (a+b); if(a>=mod)a-=mod; return a;}
inline int sub(int a, int b){a = a-b; if(a<0)a+=mod; return a;}
inline int mul(int a, int b){a = (a*b)%mod; return a;}



void mymain(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int sum = 0;
  if(k > 0)
    sum += min(k,a);
  k -= sum;
  if(k > 0){
    k -= min(k,b);
  }
  if(k > 0){
    sum -= min(k,c);
  }
  cout << sum <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;

for(int tt=0;tt<t;tt++){
   //cout << "Case #" << tt+1 <<": ";
   mymain();
}
return 0;
}
/*

*/


Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <atcoder/all>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, Q;

ll op( ll a, ll b ) {
  return std::max(a,b);
}

ll e() {
  return -1;
}

ll B;

bool f( ll x ) {
  return x < B;
}

int main() {
  std::cin >> N >> Q;
  
  std::vector<ll> A(N);

  for( auto &x : A )
    std::cin >> x;

  atcoder::segtree<ll, op, e> seg(A);

  rep( q, Q ) {
    ll T;
    std::cin >> T;

    if( T == 1 ) {
      ll X, V;
      std::cin >> X >> V;
      --X;

      seg.set( X, V );
    } else if( T == 2 ) {
      ll L, R;
      std::cin >> L >> R;
      --L;
      std::cout << seg.prod( L, R ) << endl;
    } else {
      ll X;
      std::cin >> X >> B;
      --X;

      std::cout << seg.max_right<f>(X)+1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 8792
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    ans=pow(10,N,mod)
    ans-=pow(9,N,mod)*2
    ans+=pow(8,N,mod)
    
    print(ans%mod)

main()


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

int main()
{
    string str;
    int len;
    int q;
    string cmd;
    int p1;
    int p2;
    string para;

    cin >> str;                     // 文字列
    len = str.length();

    cin >> q;                       // 命令数

    if (q < 1 || q > 100) return -1;

    for (int i = 0; i < q; i++) {
        cin >> cmd;

        if (cmd == "replace") {
            cin >> p1 >> p2 >> para;
            if (p1 <= p2 && p2 < len) {
                str.replace(p1, p2-p1+1, para, 0, p2-p1+1);
            }
            continue;
        }
 
        if (cmd == "reverse") {
            cin >> p1 >> p2;
            if (p1 < p2 && p2 < len) {
                while (p1 < p2) {
                    string c;
                    c = str.at(p1);
                    str.at(p1) = str.at(p2);
                    str.at(p2) = c.at(0);
                    p1++;
                    p2--;
                }
            }
            continue;
       }

        if (cmd == "print") {
            cin >> p1 >> p2;
            if (p1 <= p2 && p2 < len) {
                string s;
                s = str.substr(p1, p2-p1+1);
                cout << s << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3216
program sample
    implicit none
    character(100)::s
    integer(8) :: i,j,m,n,k,d,x
    
  
    read(*,*) x,k,d
    x=abs(x)
    if(x/d>=k)then
        write(*,*)x-k*d
    else
        m=x/d
        if(mod(k-m,2)==0)then
            write(*,*)x-m*d
        
        else
            write(*,*)(m+1)*d-x
        end if
    end if
    stop
end program sample
  



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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> x(m), diff(m);
  diff[0] = (int)1e6;
  for (int i = 0; i < m; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  for (int i = 1; i < m; i++) {
    diff[i] = abs(x[i] - x[i - 1]);
  }
  sort(diff.begin(), diff.end());
  int ans = 0;
  if (n >= m) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 0; i < m - n; i++) {
    ans += diff[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3988
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = Integer.MAX_VALUE;
        for(int i=1;i<=n/2;i++){
            ans = Math.min(ans,help(i)+help(n-i));
        }
        System.out.println(ans);
    }
    public static int help(int p){
        int ans = 0;
        while(p>0){
            ans += p%10;
            p /= 10;
        }
        return ans;
    }
}


Measured memory_bytes: 20556