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

using namespace std;

const int INF = 1e8;

int main(){
    int n;
    cin>>n;
    vector<int> r(n), a(n), w(n), t(n);
    for( int i=0; i<n; ++i ){
        cin>>r[i]>>a[i]>>w[i]>>t[i];
    }



    for( int i=0; i<n; ++i ){
        int idx = -1;
        int maxi = t[i]+r[i];
        for( int j=i+1; j<n; ++j ){
            if( t[j]+r[j]>maxi ){
                idx = j;
                maxi = t[j]+r[j];
            }
        }
        if( idx != -1 ){
            swap(r[i],r[idx]);
            swap(a[i],a[idx]);
            swap(w[i],w[idx]);
            swap(t[i],t[idx]);
        }
    }

    static int dp[2001][2001][2];

    for (int i=0; i<n; ++i ){
        for( int time=0; time<=2000; ++time){
            for( int f=0; f<=1; ++f ){
                dp[i][time][f] = -INF;
            }
        }
    }
    for( int i=0; i<n; ++i ){
        dp[i][t[i]][1] = a[i];
    }

    for( int i=0; i<n; ++i ){
        for( int time=2000; time>=0; --time ){
            if( time-r[i]>=0 ){
                dp[i][min(time-r[i], t[i])][1] = max( dp[i][min(time-r[i], t[i])][1], dp[i][time][0] + a[i] );    //iを使う
                dp[i][min(time-r[i], t[i])][1] = max( dp[i][min(time-r[i], t[i])][1], dp[i][time][1] + w[i] ); //iをもう一度使う
            }
            if( i+1<n ){
                dp[i+1][time][0] = max( dp[i+1][time][0], max( dp[i][time][0], dp[i][time][1] ) ); //iをもう使わない
            }        
        }
    }
    int ans = 0;
    for( int time=1; time<=2000; ++time ){
        for( int f=0; f<=1; ++f ){
            ans = max( ans, dp[n-1][time][f] );    
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 34420
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#define MAX 100005
using namespace std;
static const int INF = 1000000005;

int main(){
  string s;

  cin >> s;

  s.erase(s.end()-8, s.end());
  
  cout << s << endl;    

  return 0;

}


Measured memory_bytes: 888
#include <stdio.h>

int main() {
  int n,a[101],i,j,m;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  int cnt=0;
  for(i=0; i<n; i++) {
    m=i;
    for(j=i+1; j<n; j++) {
      if(a[j]<a[m]) m=j;
    }
    if(a[i]>a[m]) {
      int tmp=a[i];
      a[i]=a[m];
      a[m]=tmp;
      cnt++;
    }
  }
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2096
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;

int main(){
    while(true){
        int N;
        cin>>N;
        if(N==0) break;
        stack<int> bla;
        stack<int> whi;
        bla.push(-1);
        whi.push(-1);
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            if(i%2==0){
                int B=bla.top();
                int W=whi.top();
                if(a==1){
                    if(B==-1){
                        bla.push(1);
                        if(!whi.empty()) whi.pop();
                    }else{
                        if(B<W){
                            whi.pop();
                        }
                    }
                }else{
                    if(W==-1){
                        whi.push(1);
                        if(!bla.empty()) bla.pop();
                    }else{
                        if(W<B){
                            bla.pop();
                        }
                    }
                }
            }else{
                int B=bla.top();
                int W=whi.top();
                if(a==1){
                    if(B==-1){
                        bla.push(i);
                    }else{
                        if(B<W){
                            bla.push(i);
                        }
                    }
                }else{
                    if(W==-1){
                        whi.push(i);
                    }else{
                        if(W<B){
                            whi.push(i);
                        }
                    }
                }
            }
        }
        bla.push(N+1);
        int ans=0;
        int now=N+1;
        while(true){
            int B=bla.top();
            int W=whi.top();
            if(B==-1 && W==-1) break;
            if(B<W){
                ans+=now-W;
                now=W;
                whi.pop();
            }else{
                now=B;
                bla.pop();
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3048
from sys import exit
# A,B,C =
G = [[int(n) for n in input().split()]for _ in range(3)]#H,W
ptr = [ [0,1],[1,2], [0,2]]
e1 = G[0][0] - G[1][0]#a1 - a2
for p in ptr:
    e = G[0][p[0]] - G[0][p[1]]
    for h in range(1,3):
        if(e !=G[h][p[0]] - G[h][p[1]]):
            print("No")
            exit()
for p in ptr:
    e = G[p[0]][0] - G[p[1]][0]
    for w in range(1,3):
        if(e !=G[p[0]][w] - G[p[1]][w]):
            print("No")
            exit()
print("Yes")
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
exit()


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int N = s.length(),ans=0;
    for(int i = 0;i < N/2;i++)
    {
        if(s[i] != s[N-i-1])
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
h.append(10**10)
temp = 0
temp_max = 0

for i in range(n):
  if h[i] >= h[i+1]:
    temp = temp + 1
      
  elif h[i+1] > h[i]:
    if temp_max < temp:
      temp_max = temp

    temp = 0
      
print(temp_max)

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

int main(){
	int n;
	cin >> n;
	vector<int> v;
	int input;
	for(int i=0; i<n ;i++)
	{
		cin >> input;
		if(input % 2 != 0)
		{
			cout << 0;
			return 0;
		}
		v.push_back(input);
	}
	int sum=0;
	for(auto itr = v.begin(); ; ++itr) {
		/*
		先に下記のif文をしておかないと、
		v.begin()をv.end()+1のでたらめな値で上書きすることになる?
		*/
		if(itr == v.end())
		{
			sum++;
			itr = v.begin();
		}
        if(*itr % 2 != 0)break;
		else *itr/=2;
    }
	cout << sum;
	return 0;
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if (k <= a) {
    cout << k << endl;
    return 0;
  } else if (k > a && k <= a+b) {
    cout << a << endl;
    return 0;
  } else if (k > a+b && k <= a+b+c) {
    cout << a - (k - a - b) << endl;
    return 0;
  } else {
    cout << a - b << endl;
    return 0;
  }


  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef pair<long long int, long long int> P;

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

	vector<long long int> a;

	for (long long int i = 2; i*i <= p; i++) {
		if (p % i == 0) {
			a.push_back(i);
			a.push_back(p / i);
		}
	}

	sort(a.begin(), a.end());

	a.push_back(p);

	long long int cc = 0;

	vector<P> b;
	P pp = P(0, 0);

	while (p > 1) {
		if (p % a[cc] == 0) {
			if (pp.second > 0) {
				pp.second++;
			}
			else {
				pp = P(a[cc], 1);
			}
			p /= a[cc];
		}
		else {
			cc++;
			if (pp.second > 0) {
				b.push_back(pp);
				pp = P(0, 0);
			}
		}
	}


	if (pp.second > 0) {
		b.push_back(pp);
		pp = P(0, 0);
	}

	long long int ans = 1;

	for (long long int i = 0; i < b.size(); i++) {
		//cout << b[i].first << ' ' << b[i].second << endl;
		if (b[i].second >= n) {
			ans *= pow(b[i].first, (b[i].second / n));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	long long n, d, x, y;
	cin >> n >> d;
	long long count = 0;
	for(long long i = 0; i < n; ++i) {
		cin >> x >> y;
		if(x * x + y * y <= d * d) count++;
	} 
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=3e5+5;
int c[N],ans[N];
struct info{
	int l,r,id;
	bool operator <(const info &rhs)const{
		return r==rhs.r?id>rhs.id:r<rhs.r;
	}
}a[N*20];
#define lowbit(i) (i&-i)
void add(int x){
	for(int i=x;i;i-=lowbit(i)) c[i]++;
}
int find(int x){
	int res=0;
	for(int i=x;i<N;i+=lowbit(i)) res+=c[i];
	return res;
}
int main(){
	int n=read(),m=read(),k=0;
	For(i,1,n) a[++k]=(info){read(),read(),0};
	For(i,1,m){
		for(int j=i;j<=m;j+=i){
			a[++k]=(info){j-i,j,i};
			if(j+i>m) a[++k]=(info){j,m+1,i};
		}
	}
	sort(a+1,a+k+1);
	int pos=1;
	For(i,1,m+1){
		while(pos<=k&&a[pos].r==i){
			if(a[pos].id){
				ans[a[pos].id]+=find(a[pos].l+1);
			}else add(a[pos].l);
			pos++;
		}
	}
	For(i,1,m) writeln(n-ans[i]);
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int a[3],d,z,x,y;
int main(){
    cin>>a[0]>>a[1]>>a[2]>>d;
    z=abs(a[0]-a[1]);
    x=abs(a[1]-a[2]);
    y=abs(a[0]-a[2]);
    if(z<=d&&x<=d)cout<<"Yes"<<endl;
    else if(y<=d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

long long n;

int cnt(long long n) {
    int a = 0;
    while (n > 0) {
        n /= 10;
        a++;
    }
    return a;
}

int main() {
    cin >> n;
    int ans = cnt(n);

    for (long long i = 1; i * i <= n; i++) {
        if (n % i != 0) continue;
        long long j = n / i;

        int b = max(cnt(i), cnt(j));

        ans = min(ans, b);
    }

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

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

"""
URL : https://atcoder.jp/contests/keyence2020/tasks/keyence2020_d
解説AC

きもすぎBit全探索および転倒数
    （転倒数に結びついたら強い
    　隣通しを入れ替えてsortの操作数→バブルソートの操作数→転倒数
    　これの徹底）

AC例1: 最初に考え付いたのはこっち
    maskでどのindexが裏返しになっているかを保持。
    その状況下で生成される表面の数の配列を作成し(これをLとする)ソート。
    iを[0,n)で回して各A[i],B[i]に対して
    maskをもとにAかBが使用されているかを見る。
    Lにおけるその数のindexとiの差の偶奇は奇数B偶数ならA。
    defalutdictかなんかで各Lの数字とそのindexの偶奇の数とそのindexを保持
    indexとiの差の偶奇とdictからLの各indexが元どの番号にいたかを保持。
    あとは元の番号の配列の転倒数を求めればそのmaskにおける操作数が出る

AC例2: 解説はこっち
    maskではどのindexがすでに左側で固定化されたかを保持。
    巡回セールスマンのようにどこを決めて最後に決めたindexは何か
    というDPでいける。（は？）
    というのもmaskだけではそのマスク内の順番はわからないからね。
    欲しいのはその固定化された物の最大の値なので最悪なんかうまくできるかも
    すごすぎ
    こっちを実装します
    700点をACしたいね(2020/3/25/ 20:05)

    Reference: https://atcoder.jp/contests/keyence2020/submissions/9567775 By:yutaka1999
"""

#solve
def solve():
    n = II()
    A = LI()
    B = LI()
    bit_length = [0] 
    for i in range(n):
        bit_length += [x + 1 for x in bit_length]
    dp = [[-1] * n for _ in range(1 << n)]
    for i in range(n):
        dp[1 << i][i] = 0
    for mask in range(1 << n):
        dpm = dp[mask]
        c = bit_length[mask]
        for i in range(n):
            if not((1 << i) & mask) or dpm[i] == -1: continue
            w = B[i] if 1 & i == c & 1 else A[i]
            cost = c
            for j in range(n):
                if 1 & (mask >> j):
                    cost -= 1
                else:
                    v = B[j] if 1 & j != c & 1 else A[j]
                    if v >= w:
                        vl = dpm[i] + cost
                        if dp[mask | (1 << j)][j] == -1 or dp[mask | (1 << j)][j] > vl:
                            dp[mask | (1 << j)][j] = vl

    ans = -1
    for i in range(n):
        if dp[-1][i] != -1:
            if ans == -1 or ans > dp[-1][i]:
                ans = dp[-1][i]
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int k;
    cin >> k;
    Int n = 50;
    dump(n);
    vector<Int> res(n, 49 + k / n);
    k %= n;
    for (Int i = 0; i < k; i++) {
        res[i] += n;
        for (Int j = 0; j < n; j++) {
            if (j == i) continue;
            res[j]--;
        }
    }
    for (Int i = 0; i < n; i++) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
words = input().strip().split(' ')
num = []
for i in range(len(words)):
    word = words[i]
    if word == "+":
        num.append(num.pop() + num.pop())
    elif word == "-":
        num.append(-(num.pop() - num.pop()))
    elif word == "*":
        num.append(num.pop() * num.pop())
    else:
        num.append(int(word))
print(num[0])


Measured memory_bytes: 5600
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto s = sread();
    sort(cast(ubyte[])s);
    if(s[0] == s[1] && s[2] == s[3] && s[1] && s[1] != s[2])
        writeln("Yes");
    else
        writeln("No");
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  int n;
  cin >> n;
  int total = 1;
  int bad = 1;
  forn(i,n){
    int a;
    cin >> a;
    total *= 3;
    if (a%2){
      bad *= 1;
    } else {
      bad *= 2;
    }
  }
  cout << total - bad;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)



*/

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

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

    int minCard = 1, maxCard = 100000;

    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;

        if (minCard > r)
        {
            minCard = r;
            maxCard = r - 1;
            break;
        }
        else if (maxCard < l)
        {
            minCard = l + 1;
            maxCard = l;
            break;
        }
        else
        {
            minCard = max(minCard, l);
            maxCard = min(maxCard, r);
        }
    }

    cout << maxCard - minCard + 1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>

using namespace std;

int lcm(int a, int b) {
    if (a > b) {
        int buf = a;
        a = b;
        b = buf;
    }
    return a == 0 ? b : lcm(a, b%a);
}

int main() {
    int N, A, min;
    scanf("%d", &N);
    scanf("%d", &min);
    for (int i=1; i<N; i++) {
        scanf("%d", &A);
        min = lcm(A, min);
    }
    printf("%d\n",min);
    return 0;
}

Measured memory_bytes: 128
// Problem : B - Card Game for Three (ABC Edit)
// Contest : AtCoder - AtCoder Beginner Contest 045
// URL : https://atcoder.jp/contests/abc045/tasks/abc045_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	vector<string> s(3);
	vector<int> sz(3);
	vector<int> p(3, 0);
	int old;
	for(auto &it:s){
	    cin >> it;
	}
	for(int i = 0; i<3; i++){
	    sz[i] = s[i].size();
	}
	int curr = 0;
	while(1){
	    if(p[curr]==sz[curr])
            break;
        old = p[curr];
	    p[curr]+=1;
	    curr = s[curr][old] - 'a';
	}
	cout << char(curr+'A');
	return 0;
}

Measured memory_bytes: 256
# include<iostream>
# include<vector>
# include<time.h>
# include<random>
using namespace std;
using vector1 = vector<int>;
using vector2 = vector<vector1>;
int last(int d, int j, vector1 t){ //d日目から数えてタイプjのコンテストが最後に開催された日を計算
  for(int i=d; i>=1; i--){
    if(t[i] == j) return i;
  }
  return 0;
}
int penalty(vector1 c, int d, vector1 t){ //ペナルティの合計を計算
  int m = 0;
  for(int i=1; i<=26; i++){
    m += c[i] * (d - last(d, i, t));
  }
  return m;
}
int calc_score(int d, int j, int c, vector1 t){ //開催されるコンテストが変更された場合のスコア差を算出
  int s = 1;
  if(d > 1) s = d - last(d-1, j, t);

  int r = s * c; //1日分のスコア差
  int sum = 0;  //スコア差の合計
  int i = d;
  do{
    sum += r;
    i++;
    if((int)t.size() < i) break;
  }while(t[i] != j);
  return sum;
}
void swap_(int d1, int d2, vector1& t){
  int tmp = t[d1]; t[d1] = t[d2]; t[d2] = tmp;
  return;
}
int main(){
  clock_t start = clock();
  int D; cin >> D; //日数d
  vector1 c(26+1, 0); for(int i=1; i<=26; i++) cin >> c[i]; //ペナルティc
  vector2 s(D+1, vector1(26+1)); //あるコンテストが開催された場合の満足度s
  for(int i=1; i<=D; i++){
    for(int j=1; j<=26; j++){
      cin >> s[i][j];
    }
  }
  vector1 t(D+1, 0); for(int i=1; i<=D; i++) t[i] = (i % 26) + 1;
/*  vector1 v(D+1, 0); //スコアv
  for(int i=1; i<=D; i++){
    v[i] = s[i][t[i]];
    v[i] -= penalty(c, i, t);
  }*/
  int score = 0;
  for(int i=1; i<=D; i++){
    score += s[i][t[i]];
    score -= penalty(c, i, t);
  }
  clock_t end = clock();
//  cout << score <<"\n";
  random_device random_a;
  auto num = random_a();
  mt19937 random_b;
  //num = 3180901575;
  random_b.seed(num);
//  cout <<"num: "<< num <<"\n";

  while((double)(end - start) / CLOCKS_PER_SEC < 1.9){
    int r = (int)random_b();
    if(r > 0){
      int p = ((int)random_b() * random_b() % 26) + 1;
      int d = ((int)random_b() * random_b() % D) + 1;
      int old = t[d];
      t[d] = p;
      int up = calc_score(d, p, c[p], t); //増えるスコア
      int down = calc_score(d, old, c[old], t); //減るスコア
      int l = up - down + s[d][p] - s[d][old];
      if(l > 0){
        score += l;
      }else{
        t[d] = old;
      }
    }else{
      int d1 = ((int)random_b() * random_b() % D) + 1;
      int d2 = ((int)random_b() * random_b() % D) + 1;
      int l_old_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_old_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      //cout << t[d1] <<"  "<< t[d2] <<"\n";
      swap_(d1, d2, t);
      //cout << t[d1] <<"  "<<t[d2] <<"\n";
     // break;
      int l_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      int l = l_d1 + l_d2 - l_old_d1 - l_old_d2 + s[d1][t[d1]] - s[d1][t[d2]] + s[d2][t[d2]] - s[d2][t[d1]];
      if(l >0){
        score += l;
      }else{
        swap_(d1, d2, t);
      }
    }
    end = clock();
  }
  for(int i=1; i<=D; i++){
    cout << t[i] <<"\n";
  }
  /*cout << score <<"\n";
  int score2=0;
  for(int i=1; i<=D; i++){
    score2 += s[i][t[i]];
    score2 -= penalty(c, i, t);
  }
  cout <<score2 <<"\n";*/
  return 0;
}


Measured memory_bytes: 3244
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

memo = {}
for i in range(n):
  if s[i] not in memo:
    memo[s[i]] = 1
  else:
    memo[s[i]] +=1

for i in range(m):
  if t[i] in memo:
    memo[t[i]] -=1

ans=0
for i in memo:
  ans = max(memo[i],ans)
print(ans)



Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n,cnt=0,ans=0,i;
    bool b=true;
    cin >> n;
    int h[n];
    rep(i,n) cin >> h[i];
    while(b){
        rep(i,n){
            if(h[i]==0) cnt++;
        }
        if(cnt==n) break;
        cnt=0;
        for(i=0;i<n;i++){
            if(h[i]!=0){
                h[i]--;
                if(h[i+1]==0 || i==(n-1)) ans++;
            }
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
T=input().split()
M=int(input())

for i in range(M):
  time=0
  P=input().split()
  drink=int(P[0])
  for k in range(N):
    if(k+1 == drink):
      time+=int(P[1])
    else:
      time+=int(T[k])
  print(time)
    


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  ll money = 1000, stock = 0;
  for (int i = 1; i < n; i++) {
    if (a.at(i - 1) < a.at(i)) {
      money += (a.at(i) - a.at(i - 1)) * (money / a.at(i - 1));
    }
  }
  
  cout << money << '\n';
}

Measured memory_bytes: 3652
n = int(input())
v_list = list(map(int, input().split()))

v_even, v_odd = v_list[::2], v_list[1::2]

from collections import Counter

so_ev = Counter(v_even).most_common(2)
so_od = Counter(v_odd).most_common(2)

if so_ev[0][0] == so_od[0][0]:
    if (len(so_ev) == 1) and (len(so_od) == 1):
        print(n - so_ev[0][1])
    else:
        print(min(n - so_ev[1][1] - so_od[0][1], n - so_ev[0][1] - so_od[1][1]))
else:
    print(n - so_ev[0][1] - so_od[0][1])


Measured memory_bytes: 15860
#include <bits/stdc++.h>
using namespace std;
#define psi pair<string,int>

int main()
{
    int n,q,time=0;
    cin>>n>>q;
    queue <psi> que;
    for(int i=0;i<n;i++)
    {
        string s;
        int t;
        cin>>s>>t;
        psi p = make_pair(s,t);
        que.push(p);
    }

    while(!que.empty())
    {
        psi p = que.front();
        que.pop();
        if(p.second>q)
        {
            time += q;
            p.second -= q;
            que.push(p);
        }
        else
        {
            time+= p.second;
            cout<<p.first<<" "<<time<<endl;
        }
        
    }
}


Measured memory_bytes: 6296
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  long long S; std::cin >> S;
  std::vector<long long> ans;
  constexpr long long max = 1'000'000'000;
  if (S == max * max) {
    ans = {0, 0, max, 0, 0, max};
  } else {
    auto q = S / max;
    auto r = S % max;
    auto x = r, y = q + 1;
    ans = {0, 1, max, 0, x, y};
  }
  assert(std::all_of(ans.begin(), ans.end(), [max](auto x){
    return 0LL <= x && x <= max;
  }));
  int sz = 6;
  assert(ans.size() == 6);
  for (int i = 0; i < sz; i++) {
    std::cout << (i > 0 ? " " : "") << ans.at(i);
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll x, y;
  cin >> x >> y;
  
  ll ans = INF;
  if(x <= y) ans = min(ans, y-x);
  if(-x <= y) ans = min(ans, y-(-x)+1);
  if(x <= -y) ans = min(ans, -y-x+1);
  if(-x <= -y) ans = min(ans, -y-(-x)+2);
  cout << ans << endl;
  return 0;
}

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

N=int(input())
B=[list(map(int,input().split())) for i in range(N)]

B.sort(key=lambda x:x[0]+x[1])
#W+Sの順にソートすると無駄がない。

DP=[0]*(10**4+2)
#重さの合計がWのときの価値。
#W=10**4+1ならそれ以上更新されないので、W>=10**4+1以上のものはそこに置く

for w,s,v in B:
    for i in range(s,-1,-1):
        if i+w<=10**4:
            if DP[i+w]<DP[i]+v:
                DP[i+w]=DP[i]+v

        else:
            if DP[-1]<DP[i]+v:
                DP[-1]=DP[i]+v

print(max(DP))

Measured memory_bytes: 41676
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,i,sum=0;
    cin>>n;
    map<long long,long long>m;
    vector <int >a(n);
    for(i=0;i<n;i++){
        cin>>a[i];sum+=a[i];
        m[a[i]]++;
    }
    sort(a.begin(),a.end());
    long long q;
    cin>>q;
    for(i=0;i<q;i++){
        long long b,c;cin>>b>>c;
        if(m.count(b)==0)cout<<sum<<endl;
        else{
            long long p=m[b];
            sum+=p*(c-b);
            m.erase(b);
            m[c]+=p;
            cout<<sum<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 7760
N=int(input())

def hukano():
    print(":(")
def zeikomi(n):
    return n*1.08//1

N_min=N*9//10

k=N_min
while True:
    teika=int(zeikomi(k))
    if int(teika)==N:
        print(k)
        break
    elif teika<N:
        k=k+1
    else:
        hukano()
        break

Measured memory_bytes: 3060
N, K = [int(i) for i in input().split()]
L = []
for i in range(N):
  a, b = [int(j) for j in input().split()]
  L.append([a, b])
L.sort(key=lambda x: x[0])
#print(L)

cnt = 0
for x, y in L:
  cnt += y
  if cnt >= K:
    ans = x
    break
print(ans)

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

cnt = 0

for i in range(n):
    t = min(a[i], b[i])
    cnt += t
    a[i] -= t
    b[i] -= t

    s = min(a[i+1], b[i])
    cnt += s
    a[i+1] -= s
    b[i] -= s

print(cnt)

Measured memory_bytes: 24200
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
vector<pair<int,pii> > p;
struct node{
    node *l,*r;
    LL tag;
    LL Max;
    int a,b;
    node(int _a,int _b):l(NULL),r(NULL){
        a=_a;
        b=_b;
        Max=tag=0;
    }
}*root;
void build(node *n){
    if(n->a==n->b){
        return ;
    }
    int mid=(n->a+n->b)/2;
    n->l=new node(n->a,mid);
    n->r=new node(mid+1,n->b);
    build(n->l);
    build(n->r);
}
void push(node *n){
    n->l->tag+=n->tag;
    n->r->tag+=n->tag;
    n->tag=0;
}
LL Max(node *n){
    return n->Max+n->tag;
}
void pull(node *n){
    n->Max=max(Max(n->l),Max(n->r));
}
void add(node *n,int l,int r,LL k){
    if(n->a>=l&&n->b<=r){
        n->tag+=k;
        return;
    }
    if(n->b<l||n->a>r){
        return ;
    }
    push(n);
    add(n->l,l,r,k);
    add(n->r,l,r,k);
    pull(n);
}
LL query(node *n,int x){
    if(n->b<=x){
        return Max(n);
    }
    int mid=(n->a+n->b)/2;
    if(x<=mid)
    return query(n->l,x);
    else
    return max(query(n->l,x),query(n->r,x));
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        int l,r,a;
        scanf("%d %d %d",&l,&r,&a);
        p.pb(mp(l,mp(l-1,a)));
        p.pb(mp(r+1,mp(l-1,-a)));
    }
    sort(p.begin(),p.end());
    int index=0;
    root = new node(0,n);
    build(root);
    LL ans=0;
    for(int i=1;i<=n;i++){
        while(index!=p.size()&&p[index].x==i){
            add(root,0,p[index].y.x,p[index].y.y);
          //  printf("l:%d %d %d\n",0,p[index].y.x,p[index].y.y);
            index++;
        }
        ans=max(query(root,i-1),ans);
       // printf("%d %d\n",i,Max(root));
        add(root,i,i,query(root,i-1));
       // printf("l:%d %d %d\n",i,i,Max(root));
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 25068
#include<bits/stdc++.h>
using namespace std;
const int N = 2*1e5+5;
typedef long long ll;
vector<ll> fact(N,0);
ll mod= 998244353;
ll modpow(ll a,ll b){
        if(!a&&!b) return 1;
        else if(!a) return 0;
        ll res=1;a%=mod;
        while(b){
                if(b&1) { res=(res*a)%mod; }
                a=(a*a)%mod;
                b>>=1;
        }
        return res;
}
ll inv(ll a){
        return modpow(a,mod-2);
}
ll choose(ll a,ll b){
        if(a<0||b<0||a<b) return 0;
        ll val=((fact[a]*inv(fact[a-b]))%mod*inv(fact[b]))%mod;
        return val;
}
void compute(){
        fact[0]=1;
        for(ll i=1;i<N;i++)
                fact[i]=(fact[i-1]*i)%mod;

}
int main(){
        ll n,m,k;
        cin>>n>>m>>k;
        compute();
        ll res=0;
        for(int i=0;i<=min(n-1,k);i++)
                res=(res+((m*choose(n-1,i))%mod*modpow(m-1,n-i-1))%mod)%mod;
        cout<<res<<endl;
}



Measured memory_bytes: 4708
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int a,b;cin>>a>>b;
    for(double i;i<1000000;i+=1){
        if(floor(i*0.08)==a and floor(i*0.10)==b){
            cout<<(int)(i)<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N;
    cin >> N;
    if (N > 999) {
        out("ABD");
    } else {
        out("ABC");
    }
}


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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;

int gcd(int a, int b){return b?gcd(b, a % b):a;}
/*-------------------------------*/

int main(void)
{
  int list[6] = {500, 100, 50, 10, 5, 1};
  int n;
  int cnt;

  while (true){
    cin >> n;
    if (n == 0) break;
    n = 1000 - n;
    cnt = 0;
    REP(i, 6){
      if (i % 2 == 0){
        if (n - list[i] >= 0){
          cnt++;
          n -= list[i];
        }
      }
      else{
        if (n / list[i] != 0){
          cnt += n / list[i];
          n -= (n / list[i]) * list[i];
        }
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 3000
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
int main(){
int a ,b ,c ,d;
    cin >> a >> b >> c >> d;
    cout << (b + c - d) << " " << c + d -a  <<  " "  << a + b - d <<  " " << b + c - a;
return 0;
}
 










Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
#s = readline().rstrip().decode('utf-8')
#n = int(readline())
n,a,b = map(int,readline().split())

mod = 10**9+7


def pow(n, p): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


case_all = pow(2,n) -1 #少なくとも1つは選ぶ為-1
case_a_n = 1
for i in range(n-a+1,n+1):
    case_a_n *= i
    case_a_n %= mod
case_a_r = 1
for i in range(1,a+1):
    case_a_r *= i
    case_a_r %= mod
case_a = case_a_n*pow(case_a_r,mod-2)%mod

case_b_n = 1
for i in range(n-b+1,n+1):
    case_b_n *= i
    case_b_n %= mod
case_b_r = 1
for i in range(1,b+1):
    case_b_r *= i
    case_b_r %= mod
case_b = case_b_n*pow(case_b_r,mod-2)%mod

case_all-=case_a+case_b
while case_all<0:
    case_all += mod
print(case_all)

Measured memory_bytes: 39236
N=int(input())

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

pos = 0

cost = [0]

for i in range(1,N):
  back_1 = abs(h_list[i] - h_list[i-1])
  if i>1:
    back_2 = abs(h_list[i] - h_list[i-2])
  if i>1:
    cost.append( (back_2 + cost[i-2] )if (back_1 + cost[i-1]) > (back_2 + cost[i-2] ) else (back_1 + cost[i-1]))
  else:
    cost.append( back_1 + cost[i-1])
    
  
print(cost[N-1])


Measured memory_bytes: 13908
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    X = np.array(list(map(int, args[1].split())))

    ret = 10**10
    for i in range(1, 101):
        ret = min(ret, np.power((X-i), 2).sum())
    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 20620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string S, T;

// g++ a.cpp -std=gnu++17

int main() {
  INCANT;
  cin >> S >> T;
  int sz = S.size();
  int cnt=0;
  rep(i, sz) {
    if (S[i]!=T[i]) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <climits>
#include <string>

typedef long long ll;

using namespace std;

void solve(){
    const int magic = 26;
    int alphabet[magic];
    string x;

    for(int i = 0; i < magic; i++){
        alphabet[i] = 0;
    }
    while(getline(cin, x)){
        if(x == ""){
            break;
        }
        for(int i = 0; i < x.length(); i++){
            alphabet[tolower(x[i])-'a']++;
        }
    }
    for(char j = 'a'; j <= 'z'; j++){
        cout << j << " : " << alphabet[j-'a'] << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3200
n=int(input())
l=[int(i) for i in input().split()]
def check(x):
    sm=0 
    for i in range(n):
        sm+=abs(l[i]-(i+x+1))
    return sm 
lo=-(10**10)
hi=10**10 
while lo<=hi:
    mi=(lo+hi)>>1 
    a=check(mi)
    b=check(mi-1)
    c=check(mi+1)
   # print(mi,a,b,c)
    if b<=a: 
        hi=mi-1 
        ans=b
    elif c<=a:
        ans=c
        lo=mi+1 
    else:
        ans=a 
        break
print(ans)

Measured memory_bytes: 86868
A, B, M = [int(i) for i in input().split()]
Aa = [int(i) for i in input().split()]
Bb = [int(i) for i in input().split()]
XYCm = [[int(i) for i in input().split()] for _ in range(M)]

minA = min(Aa)
minB = min(Bb)

min_value = minA + minB
for x, y, c in XYCm:
  tot = Aa[x-1] + Bb[y-1] - c
  min_value = min(min_value, tot)
print(min_value)




Measured memory_bytes: 32496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int[] H = new int[N+1];
		
		String[] S = br.readLine().split(" ");
		for(int i = 0; i < N ; i++) {
			H[i+1] = Integer.parseInt(S[i]);
		}
		System.out.println(minCostJump(N, H));
	}
	
	public static int minCostJump(int N, int[] H) {
		int[] cache = new int[N+1];
		
		cache[2] = Math.abs(H[1] - H[2]);
		for(int i = 3; i <= N; i++) {
			cache[i] = Math.min(cache[i-1] + Math.abs(H[i-1] - H[i]), cache[i-2] + Math.abs(H[i-2]-H[i]));
		}
		
		return cache[N];
	}
}


Measured memory_bytes: 38328
#include<stdio.h>
int main()
{
  int x1,x2,x3,x4,x5;
  scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
  int temp = x1+x2+x3+x4+x5;
  printf("%d",15-temp);
}

Measured memory_bytes: 1708
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1e5 + 10;
char s[N], t[N];
int s1[N], s2[N];
int main() {
	scanf("%s",s + 1); int n = strlen(s + 1);
	scanf("%s",t + 1); int m = strlen(t + 1);
	rep(i,1,n) s1[i] = s1[i - 1] + (s[i] == 'A' ? 1 : -1);
	rep(i,1,m) s2[i] = s2[i - 1] + (t[i] == 'A' ? 1 : -1);
	int q; scanf("%d",&q);
	rep(i,1,q) {
		int a, b, c, d; scanf("%d%d%d%d",&a,&b,&c,&d);
		int k1 = s1[b] - s1[a - 1]; int k2 = s2[d] - s2[c - 1];
		k1 = (k1 % 3 + 3) % 3, k2 = (k2 % 3 + 3) % 3;
		if (k1 == k2) printf("YES\n"); else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 1536
def main():
    S = input()
    if len(S) == 1:
        return 1
    dp1 = [0] * len(S)
    dp2 = [0] * len(S)
    dp1[0] = 1
    dp2[1] = 1
    if S[0] != S[1]:
        dp1[1] = 2

    for i, s in enumerate(S[1:], 1):
        if s != S[i - 1]:
            dp1[i] = max(dp1[i], dp1[i - 1] + 1)
        dp1[i] = max(dp1[i], dp2[i - 1] + 1)
        dp2[i] = dp1[i - 2] + 1
        if S[i - 1:i + 1] != S[i - 3:i - 1]:
            dp2[i] = max(dp2[i], dp2[i - 2] + 1)
    return max(dp1[-1], dp2[-1])
        

print(main())



Measured memory_bytes: 19204
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int A, B,X;
char op;
int N, M;

int main(){
	cin >> X >> A >> B;

	if (B - A <= -0) cout << "delicious" << endl;
	else if (B - A < X + 1) cout << "safe";
	else if (B - A >= X + 1) cout << "dangerous";

	}
	

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define VI vector<int>

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

int n,m;

using namespace std;


int main(){
	while(1){
		int num[10]={};
		int a=0;
		cin>>a;
		if(a==0)break;
		for(int cou=0;cou<a;cou++){
			int n;
			cin>>n;
			num[n]++;
		}
		rep(i,10){
			if(num[i]==0)cout<<"-"<<endl;
			else{
				rep(j,num[i])cout<<"*";
				cout<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
"""

https://atcoder.jp/contests/abc176/tasks/abc176_f

dp[i][c1][c2] = 先頭2枚がc1とc2(c1<=c2)の時の答えの最大
で解けるようだ
毎回の処理をO(N)に抑えなくてはいけない

3枚が同じときは取っちゃえばいいので、3枚みたいな変数を用意しておいて答えに足せばいい
2枚が同じな時、更新するべきはc1とc2のうち片方以上が同じな場合
→残る2枚は確定するので、O(N)の更新が必要
1枚あるのをセットにする場合、c1=c2である。残りの2枚は確定するので、O(1)で更新できる。

セットにせず、カードを交換する場合も考える
新しいカードでそろえる場合は、渡される2枚は関係ないので、maxを持っておき、それで置き換えればいい
新しい+古いカードの場合は、そのカードを含む最大で更新すればいい？
→O(N)で更新するために、あるカードを含む数値の最大をもっておく

"""

import sys
from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
for i in range(3*N):
    A[i] -= 1

nmax = 0 #現在のdp配列中の最大値
maxin = [float("-inf")] * N #あるカードが入っている場合の最大値
three = 0 #3枚が同じ場合

dp = [ [float("-inf")] * N for i in range(N) ]
c1,c2 = A[:2]
if c1 > c2:
    c1,c2 = c2,c1
dp[c1][c2] = 0
maxin[c1] = 0
maxin[c2] = 0
#print ("dp:",dp,file=sys.stderr)

for i in range(N-1):

    cards = A[2+3*i:5+3*i]
    cards.sort()

    #全てが同じ場合、処理をパスする
    if cards[0] == cards[1] and cards[1] == cards[2]:
        three += 1
        continue

    change = [] #更新個所を覚えて置き、最後に一気に更新する (c1,c2,値)

    #2枚が同じ場合を処理する
    if cards[0] == cards[1]:
        nc = cards[0]
        for i in range(N):
            c1 = cards[2]
            c2 = i
            if c1 > c2:
                c1,c2 = c2,c1
            if nc <= i:
                change.append((c1,c2,dp[nc][i]+1))
            else:
                change.append((c1,c2,dp[i][nc]+1))
    if cards[1] == cards[2]:
        nc = cards[1]
        for i in range(N):
            c1 = cards[0]
            c2 = i
            if c1 > c2:
                c1,c2 = c2,c1
            if nc <= i:
                change.append((c1,c2,dp[nc][i]+1))
            else:
                change.append((c1,c2,dp[i][nc]+1))

    #1枚が同じ場合を処理する
    c1 = cards[1]
    c2 = cards[2]
    change.append((c1,c2,dp[cards[0]][cards[0]]+1))
    c1 = cards[0]
    c2 = cards[2]
    change.append((c1,c2,dp[cards[1]][cards[1]]+1))
    c1 = cards[0]
    c2 = cards[1]
    change.append((c1,c2,dp[cards[2]][cards[2]]+1))

    #新しいカードでそろえる場合
    c1 = cards[0]
    c2 = cards[1]
    change.append((c1,c2,nmax))
    c1 = cards[1]
    c2 = cards[2]
    change.append((c1,c2,nmax))
    c1 = cards[0]
    c2 = cards[2]
    change.append((c1,c2,nmax))

    #新しいカード+1の場合
    for c1 in cards:
        for c2 in range(N):
            tmpmax = maxin[c2]
            if c1 > c2:
                change.append((c2,c1,tmpmax))
            else:
                change.append((c1,c2,tmpmax))

    #dp配列の更新作業
    #nmaxとmaxinも更新する

    for c1,c2,tmp in change:
        nmax = max(nmax,tmp)
        dp[c1][c2] = max(dp[c1][c2],tmp)
        maxin[c1] = max(maxin[c1],tmp)
        maxin[c2] = max(maxin[c2],tmp)

    #print ("dp:",dp,file=sys.stderr)

nmax = max(nmax , dp[A[-1]][A[-1]] + 1)
print (nmax + three)
        



Measured memory_bytes: 226028
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<std::string> s(n);
  for (auto& x : s) {
    std::cin >> x;
    std::sort(x.begin(), x.end());
  }
  std::sort(s.begin(), s.end());
  s.push_back(std::string{});
  auto prv = std::string{};
  long long ret = 0, tmp = 0;
  for (auto x : s) {
    if (x != prv) {
      ret += tmp * (tmp - 1) / 2;
      tmp = 0;
    }
    tmp++;
    prv = x;
  }
  std::cout << ret << std::endl;
  return 0;
}

Measured memory_bytes: 6528
/*input
1000000

*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const ll mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;cin>>n;
    ll ans =0 ;
    for(ll i=1;i<=n;i++){
    	if(i%3==0 && i%5==0)continue;
    	else if(i%3==0) continue;
    	else if(i%5==0)continue;
    	else ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}		

Measured memory_bytes: 3628