akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

const ll MOD = 1e9+7;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll N, Q;
string S;
vector<set<ll>> V;
int main(int argc, char **argv)
{
	cin >> N >> S >> Q;
	V.assign(26, set<ll>({INF}));
	REP(i, N)
		V[S[i] - 'a'].insert(i);

	REP(_, Q)
	{
		ll a;
		cin >> a;
		if (a == 1)
		{
			ll ind;
			char ac;
			cin >> ind >> ac;
			--ind;
			char bc = S[ind];
			S[ind] = ac;
			V[bc-'a'].erase(ind);
			V[ac-'a'].insert(ind);
		}
		else
		{
			ll l, r; cin >> l >> r;
			ll res{0};
			REP(c, 26)
			{
				if (V[c].empty()) continue;
				ll lid = *V[c].lower_bound(l-1);
				ll rid = *V[c].lower_bound(r);
				if (rid > lid) ++res;
			}
			std::cout << res << std::endl;
		}
	}
}


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

int main()
{
    int n;
    cin >> n;
    int a[2003];
    int s = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    bitset<4194304> b(1);
    for(int i = 0; i < n; i++) b = (b | (b << a[i]));
    for(int j = (s + 1) / 2; j <= s; j++) if(b[j] == 1){
        cout << j << endl;
        return 0;
    }
}

Measured memory_bytes: 2432
INF = 10**18

def solve(n, a):
    # 現在の位置 x 選んだ個数 x 直前を選んだかどうか
    dp = [{j: [-INF, -INF] for j in range(i//2-1, (i+1)//2 + 1)} for i in range(n+1)]
    dp[0][0][False] = 0
    for i in range(n):
        for j in dp[i].keys():
            if (j+1) in dp[i+1]:
                dp[i+1][j+1][True] = max(dp[i+1][j+1][True], dp[i][j][False] + a[i])
            if j in dp[i+1]:
                dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][False])
                dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][True])
    return max(dp[n][n//2])

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Measured memory_bytes: 173544
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   创 建 者： badcw
*   创建日期： 2020/1/26
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 2e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n, k;
int a[maxn];

int main(int argc, char* argv[]) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    ll res = 0;
    for (int i = n - k; i >= 1; --i) {
        res += a[i];
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=105;
int c[N][N],d[15][15];
bool judge(int a,int b)
{
    int i,j,k,l;
    for(i=1;i<=a;i++)
        for(j=1;j<=b;j++)
	{
            int dist=1e9;
            for(k=0;k<=100;k++)
                for(l=0;l<=100;l++)
                    dist=min(dist,i*k+j*l+c[k][l]);
            if(dist!=d[i][j]) return 0;
        }
    return 1;
}
int main()
{
    int a,b,i,j,k,l;
    a=ri(),b=ri();
    for(i=1;i<=a;i++)
        for(j=1;j<=b;j++)
            d[i][j]=ri();
    for(i=1;i<=a;i++) 
        for(j=1;j<=b;j++) 
            for(k=0;k<=100;k++) 
                for(l=0;l<=100;l++)
                    c[k][l]=max(c[k][l],d[i][j]-i*k-j*l);
    if(judge(a,b))
    {
        puts("Possible");
        printf("%d %d\n",202,101*101+200);
        for(i=1;i<=100;i++)
	    printf("%d %d X\n",i,i+1);
        for(i=102;i<202;i++)
	    printf("%d %d Y\n",i+1,i);
        for(i=0;i<=100;i++)
            for(j=0;j<=100;j++)
		printf("%d %d %d\n",i+1,j+102,c[i][j]);
        printf("%d %d\n",1,102);
    }
    else	puts("Impossible");
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------

    ll n;
    cin >> n ;
   
    ll ans = 1;
    for (ll i=1; i<=n;i++){
         ans = ans * i % mod;
    }
    pri(ans);
    return 0;
}



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

int sumDigits(int number) {
    int sum = 0;
    while (number > 0) {
        sum += number % 10;
        number /= 10;
    }
    return sum;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int sum = 0;
    rep(i, N) {
        if (A <= sumDigits(i + 1) && sumDigits(i + 1) <= B) {
            sum += i + 1;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
const int N=205;
inline int SG(ri x,ri k){
	if(x<k) return 0;
	if(x%k==0) return x/k;
	ri res=x/k+1;
	if(x%k%res==0) return x/k; // return (x-(x%k))/k;
	ri nxt=x/k*k-1;
	x-=(x-nxt+res-1)/res*res;
	return SG(x,k);
}
int main(){
	ri n,x,k,sg;
	sg=0;
	scanf("%d",&n);
	while(n--) scanf("%d%d",&x,&k),sg^=SG(x,k);
	puts(sg?"Takahashi":"Aoki");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#define endl '\n'
using namespace std;
const int sz=1e3+1;
int h,w,warp[sz][sz],ch,cw,dh,dw,nh,nw;
char g[sz][sz];
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>pq;
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
int wd[5]={-2,-1,0,1,2};

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

    cin>>h>>w;
    for(int i=1;i<=h;++i)fill(warp[i],warp[i]+w+1,h*w+1);
    cin>>ch>>cw;
    cin>>dh>>dw;
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j)cin>>g[i][j];
    }
    pq.push(make_pair(0,make_pair(ch,cw)));
    while(!pq.empty()){
        auto curr=pq.top();
        pq.pop();
        int currwarp=curr.first;
        int currh=curr.second.first;
        int currw=curr.second.second;
        for(int i=0;i<4;++i){
            nh=currh+dx[i];
            nw=currw+dy[i];
            if(nh>0 && nh<=h && nw>0 && nw<=w && g[nh][nw]=='.' && warp[nh][nw]>currwarp){
                warp[nh][nw]=currwarp;
                pq.push(make_pair(currwarp,make_pair(nh,nw)));
            }
        }
        currwarp++;
        for(int i=0;i<5;++i){
            nh=currh+wd[i];
            for(int j=0;j<5;++j){
                nw=currw+wd[j];
                if(nh>0 && nh<=h && nw>0 && nw<=w && g[nh][nw]=='.' && warp[nh][nw]>currwarp){
                    warp[nh][nw]=currwarp;
                    pq.push(make_pair(currwarp,make_pair(nh,nw)));
                }
            }
        }
    }
    if(warp[dh][dw]<h*w+1)cout<<warp[dh][dw]<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 8572
#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)


vector<pair<int,int>> P;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int c[4] = {0};
	REP(i,3){
		int x,y;
		cin >> x >> y;
		c[x - 1]++;
		c[y - 1]++;
	}

	bool f = false;
	bool a = true;

	REP(i,4){
		if(c[i] == 0) a = false;
	}

	if(a){
		int cnt = 0;
		REP(i,4){
			if(c[i] == 2) cnt++;
		}
	
		if(cnt == 2) f = true;
	}

	if(f){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}


}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;

int main(){
    string s,t;
    cin>>s>>t;
    int x=s[s.size()-1];
    
    bool can=false;
    rep(i,0,s.size()){
        if(s==t){
            can=true;
            break;
        }else{
            rep(j,0,s.size()){
                if(j==s.size()-1)s[0]=x;
                else {
                    s[s.size()-1-j]=s[s.size()-2-j];
                }
            }
        }
        x=s[s.size()-1];
    }
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

#00* , 01* , ... , 99* が存在するかを考えていけば良い O(3*10^6)
ans = 0
for i in range(10):
 for j in range(10):
  judge1,judge2 = 0,0 #0:未発見, 1:発見
  tmp_list = []
  
  for k in range(N):
    if(judge1 == 0):
     if(i == int(S[k])): judge1 = 1
    else:
     if(judge2 == 0): #judge1 == 1 and judge2 == 0
      if(j == int(S[k])): judge2 = 1
     else: #judge1 == 1 and judge2 == 1
      tmp_list.append(int(S[k]))
      
  tmp_list = list(set(tmp_list))
  ans += len(tmp_list)
  
print(ans)

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<pair<int,int>> vec(5);
  int i;
  for(i=0;i<5;i++){
    int a;
    cin >> a;
    vec.at(i)=make_pair(a%10,a);
    if(vec.at(i).first==0){
      vec.at(i).first=10;
    }
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int sum=0;
  for(i=0;i<4;i++){
    if(vec.at(i).first==10){
      sum+=vec.at(i).second;
    }else{
      sum+=vec.at(i).second-vec.at(i).second%10+10;
    }
  }
  sum+=vec.at(4).second;
  cout << sum;
}


Measured memory_bytes: 256
package main

// https://atcoder.jp/contests/abc146/tasks/abc146_b

import (
	"fmt"
)

func main() {
	var (
		n int32
		s string
	)

	const (
		ALPHABET_NUM = 26
		Z_CODEPOINT  = 90
	)
	fmt.Scan(&n, &s)

	for _, v := range s {
		if v+n > Z_CODEPOINT {
			fmt.Print(string(v + n - ALPHABET_NUM))
		} else {
			fmt.Print(string(v + n))
		}
	}
	fmt.Print("\n")
}


Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
ll deg(ll n){
    ll count = 0;
    while(n!= 0){
        n/=10;
        count++;
    }
    return count;
}

int main(){
    ll n,m;
    cin >> n >> m;
    ll y[m],p[m];
    for(int i = 0;i < m;i++) cin >> p[i] >> y[i];
    vector<pair<ll,ll> > pi(m);
    for(int i = 0;i < m;i++){
        pi[i] = make_pair(p[i],y[i]);
    }
    sort(pi.begin(), pi.end());
    map<pair<ll,ll>, ll>mp;
    int cur = 1;
    for(int i = 0;i < m;i++){
        if(i-1 >= 0)
        if(pi[i-1].first != pi[i].first){
            cur = 1;
        }
        mp[pi[i]] = cur;
        cur++;
    }

    for(int i = 0;i < m;i++){
        int id = mp[make_pair(p[i],y[i])];
        printf("%0.6lld", p[i]);
        printf("%0.6d\n", id);
    } 

    
}

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

int main(){
 int A[5][4][11], n;
  for( int i = 1; i<= 4; i++ )
   for( int j = 1; j <= 3; j++ )
    for( int k = 1; k <= 10; k++ ) A[i][j][k] = 0;
 
    cin >> n;
     for ( int i = 0; i < n; i++ ){
      int b,f,r,v;
      cin >> b >> f >> r >> v;
      A[b][f][r] += v;
     }
    
    for ( int f = 1; f <= 4; f++ ){
     if ( f > 1 ) cout << "####################\n";
        for ( int b = 1; b <= 3; b++ ){
         for ( int r = 1; r <= 10; r++ ){
          cout << " " << A[f][b][r];
         }
        cout << endl;
        }
    }

  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

int main(int argc, char **argv)
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int p, q; cin >> p >> q;

  while(q-p >= 2019*2) {
    q -= 2019;
  }

  ll res = 2019;
  for(int i=p; i<=q; i++) {
    for(int j=i+1; j<=q; j++) {
      res = min(res, 1LL*i*j%2019);
    }
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
n=gets.chomp.to_i
w=gets.chomp.split(" ").map{|a| a.to_i}
ans=w.inject(:+)
for kugiri in 0..n-2 do
  ans=[ans,(w.slice(0..kugiri).inject(:+)-w.slice(kugiri+1..n-1).inject(:+)).abs].min
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i) cin >> vec[i];
    sort(vec.begin(), vec.end());
 
    int ans = 0;
 
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                if (vec[k] != vec[j] and vec[i] != vec[j] and
                    vec[k] + vec[j] > vec[i]) {
                    ans++;
                }
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

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

s = b[0]
for i in range(1, n - 1):
    if b[i] >= b[i - 1]:
        s += b[i - 1]
    else:
        s += b[i]
s += b[n - 2]
print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cnt1=0,cnt2=0;
  for(int i=0; i<n; i++){
    cin>>s[i];
    if(s[i]=='('){cnt1++;}
    else{
      if(cnt1>0){cnt1--;}
      else cnt2++;
    }
  }
  if(cnt2>0){
    for(int i=0; i<cnt2; i++){
      cout<<'(';
    }
  }
  cout<<s;
  if(cnt1>0){
    for(int i=0; i<cnt1; i++){
      cout<<')';
    }
  }
    cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int x;
  cin>>x;
  if(x%11==0)cout<<x/11*2<<endl;
  else if(x%11<=6)cout<<x/11*2+1<<endl;
  else cout<<x/11*2+2<<endl;
}

Measured memory_bytes: 3528
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), a = scanner.nextInt();
        int m = n % 500;
        if (m <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

typedef long long ll;

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

    int a[3][3];
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin >> a[i][j];
    int n; cin >> n;
    vector<int> b(n);
    for(int i=0;i<n;i++) cin >> b[i];
    bool check[3][3];
    memset(check,0,sizeof(check));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(b[i]==a[j][k]) check[j][k] = true;
            }
        }
    }
    if(check[0][0]==true && check[0][1]==true && check[0][2]==true) cout << "Yes" << endl;
    else if(check[1][0]==true && check[1][1]==true && check[1][2]==true) cout << "Yes" << endl;
    else if(check[2][0]==true && check[2][1]==true && check[2][2]==true) cout << "Yes" << endl;
    else if(check[0][0]==true && check[1][0]==true && check[2][0]==true) cout << "Yes" << endl;
    else if(check[0][1]==true && check[1][1]==true && check[2][1]==true) cout << "Yes" << endl;
    else if(check[0][2]==true && check[1][2]==true && check[2][2]==true) cout << "Yes" << endl;
    else if(check[0][0]==true && check[1][1]==true && check[2][2]==true) cout << "Yes" << endl;
    else if(check[0][2]==true && check[1][1]==true && check[2][0]==true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll D,c[27],s[366][27];
ll t[366];
set<ll> tst[26];
int main(){
	srand(time(NULL));
	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
	int nowtime=0;
	int TIMEMAX=1950;
	nowtime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();

	scan(D);
	rep(i,26) scan(c[i]);
	rep(i,D){
		rep(j,26){
			scan(s[i][j]);
		}
	}
	ll pt=0;
	rep(i,26){
		tst[i].insert(-1);
		tst[i].insert(D);
	}
	rep(i,D){
		scan(t[i]); t[i]--;
		tst[t[i]].insert(i);
		pt+=s[i][t[i]];
	}
	rep(i,26){
		for(auto itr=tst[i].begin();itr!=tst[i].end();itr++){
			if(itr==tst[i].begin()) continue;
			auto itr2=itr; itr2--;
			pt-=((*itr)-(*itr2))*((*itr)-(*itr2)-1)*c[i]/2;
		}
	}
	int M;
	scan(M);
	rep(k,M){
		ll d,q;
		scan(d>>q);
		d--; q--;
		ll befq=t[d];
		t[d]=q;
		pt+=s[d][q]-s[d][befq];
		auto itr=tst[befq].lower_bound(d);
		auto itrb=itr; itrb--;
		auto itrn=itr; itrn++;
		pt-=((*itrn)-(*itr))*((*itr)-(*itrb))*c[befq];
		tst[befq].erase(itr);
		tst[q].insert(d);
		auto nitr=tst[q].lower_bound(d);
		auto nitrb=nitr; nitrb--;
		auto nitrn=nitr; nitrn++;
		pt+=((*nitrn)-(*nitr))*((*nitr)-(*nitrb))*c[q];
		debug(befq,*itrb,*itr,*itrn,((*itrn)-(*itr))*((*itr)-(*itrb))*c[befq]);
		debug(q,*nitrb,*nitr,*nitrn,((*itrn)-(*itr))*((*itr)-(*itrb))*c[q]);

		prin(pt);
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    if(n%k==0) cout << "0" << "\n";
    else cout << "1" << "\n";

    return 0;
}

Measured memory_bytes: 3604
from sys import exit, stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = Counter([int(_) for _ in stdin.readline().rstrip().split()])
M = int(stdin.readline().rstrip())
T = Counter([int(_) for _ in stdin.readline().rstrip().split()])
for k, v in T.items():
    if k not in D or D[k] < v:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 55264
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long int

int main(void)
{
  int X;
  scanf("%d",&X);
  int div = X/500;
  int remain = X%500;
  int sum = div*1000 + (remain/5)*5;
  printf("%d",sum);

    return EXIT_SUCCESS;
}

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

using T = tuple<double, double, double>;
double d(T a, T b) {
    double x, y, z, xx, yy, zz;
    tie(x, y, z) = a;
    tie(xx, yy, zz) = b;
    return sqrt(pow(x - xx, 2) + pow(y - yy, 2) + pow(z - zz, 2));
}

struct star {
    double x, y, z;
    double vx, vy, vz;
    double r, vr;
    double t;
    void get() {
        cin >> x >> y >> z >> vx >> vy >> vz >> r >> vr;
        t = r / vr;
    }
    T p(double s) { return T{x + s * vx, y + s * vy, z + s * vz}; }
};

main() {
    cout << setprecision(15) << fixed;
    while(1) {
        int n;
        cin >> n;
        if(!n) return 0;
        vector<star> s(n);
        rep(i, n) s[i].get();
        vector<pair<double, pair<int, int>>> v;
        using pii = pair<int, int>;
        rep(i, n) { v.emplace_back(s[i].t, pii(i, -1)); }
        rep(i, n) {
            rep2(j, i + 1, n - 1) {
                double l = 0, r = min(s[i].t, s[j].t);
                auto f = [&](double t) {
                    return d(s[i].p(t), s[j].p(t)) - (s[i].r - s[i].vr * t) -
                           (s[j].r - s[j].vr * t);
                };
                rep(_, 70) {
                    double tl = (l * 2 + r) / 3, tr = (l + r * 2) / 3;
                    if(f(tl) > f(tr))
                        l = tl;
                    else
                        r = tr;
                }
                if(f(l) > 0) continue;
                double low = 0, high = l;
                rep(_, 70) {
                    double mid = (low + high) / 2;
                    if(f(mid) < 0)
                        high = mid;
                    else
                        low = mid;
                }
                v.emplace_back(low, pii(i, j));
            }
        }
        sort(v.begin(),v.end());
        vector<double> ans(n,-100);
        for(auto e:v){
            int i = e.second.first;
            int j = e.second.second;
            if(j == -1) {
                if(ans[i] < 0) ans[i] = e.first;
            } else {
                if(!(ans[i] > 0 or ans[j] > 0)){
                    ans[i] = e.first;
                    ans[j] = e.first;
                }
            }
        }
        rep(i, n) cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3296
h,w = map(int,input().split())
gazo = []
for i in range(h):
    s = str(input())
    s_i = []
    s_i.append(s[0])
    for j in range(1,w):
        if s[j] == '.':
            s_i.append(s[j])
        else:
            if s[j-1]=='#' and s[j]=='#':
                s_i[j-1]='-'
                s_i.append('-')
            elif s[j-1]=='-' and s[j]=='#':
                s_i.append('-')
            else:
                s_i.append(s[j])
    gazo.append(s_i)

for j in range(0,w):
    for i in range(1,h):
        if gazo[i-1][j]=='#' and gazo[i][j]=='#':
            gazo[i-1][j]='-'
            gazo[i][j]='-'
        elif gazo[i-1][j]=='-' and gazo[i][j]=='#':
            gazo[i][j]='-'
        elif gazo[i-1][j]=='#' and gazo[i][j]=='-':
            gazo[i-1][j]='-'
#for i in range(h):
#    print(gazo[i])
isError = False
for i in range(h):
    for j in range(w):
        if gazo[i][j]=='#':
            isError = True
            break

if isError:
    print('No')
else:
    print('Yes')
    

Measured memory_bytes: 9024
/*
ID: htc9811
LANG: C++
TASK:
*/

#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

const int N=2e5+5;
int n,cur;
long long a[N];
long long d,ans;

struct Seg{
	long long length;
	int x,y;
	Seg(){};
	Seg(long long length,int x,int y):length(length),x(x),y(y){};
};

struct UF{
	int p[N],rnk[N];
	void init(int n){
		memset(p,0,sizeof(p));
		memset(rnk,0,sizeof(rnk));
		for(int i=0;i<n;i++) p[i]=i;
		for(int i=0;i<n;i++) rnk[i]=0;
	}
	int fp(int x){
		return x==p[x]?x:p[x]=fp(p[x]);
	}
	void un(int x,int y){
		if(rnk[x]>rnk[y]) p[y]=x;
		if(rnk[x]<rnk[y]) p[x]=y;
		if(rnk[x]==rnk[y]) p[x]=y,rnk[y]++;
	}
};

inline bool comp(Seg &x,Seg &y){
	return x.length<y.length;
}

vector<Seg> seg;
UF uf;

void solve(int left,int right){
	if(left==right) return;
	int middle=(left+right)>>1;
	int pl=left;
	long long vl=a[left]-d*left;
	for(int i=left+1;i<=middle;i++){
		long long cv=a[i]-d*i;
		if(cv<vl){
			vl=cv;
			pl=i;
		}
	}
	int pr=middle+1;
	long long vr=a[middle+1]+d*(middle+1);
	for(int i=middle+2;i<=right;i++){
		long long cv=a[i]+d*i;
		if(cv<vr){
			vr=cv;
			pr=i;
		}
	}
	for(int i=left;i<=middle;i++) seg.push_back(Seg(a[i]-d*i+vr,i,pr));
	for(int i=middle+1;i<=right;i++) seg.push_back(Seg(a[i]+d*i+vl,pl,i));
	solve(left,middle);
	solve(middle+1,right);
}

int main(){
//	freopen("cc3.in","r",stdin);
//	freopen("cc1.out","w",stdout);
	scanf("%d%lld",&n,&d);
	uf.init(n);
	for(int i=0;i<n;i++) scanf("%lld",a+i);
	solve(0,n-1);
	sort(seg.begin(),seg.end(),comp);
	for(int i=1;i<n;i++){
		while(true){
			int nx=seg[cur].x;
			int ny=seg[cur].y;
			long long len=seg[cur].length;
			nx=uf.fp(nx);
			ny=uf.fp(ny);
			cur++;
			if(nx!=ny){
				uf.un(nx,ny);
//				printf("%lld\n",len);
				ans+=len;
				break;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 71008
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if x[j] == y[z[i][j]] and x[-j-1] == y[-z[i][j]-1]:
            if x[j] == x[-j-1]:
                order[j] = 2
        elif x[j] == y[-z[i][j]-1] and x[-j-1] == y[z[i][j]]:
            order[j] = 1
        else:
            break
    else:
        if 2 in order:
            print('Yes')
            break
        if z[i][3] in [0, 3] and not sum(order) % 2:
            print('Yes')
            break
        if z[i][3] == 1 and sum(order) % 2:
            print('Yes')
            break
else:
    print('No')

Measured memory_bytes: 7716
// You either die a hero, or you live long enough to see yourself become the villain.

/**
 *   author:  Blind_is_love
 *   created: 12.10.2019, 16:52
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

#define endl "\n"
#define vll vector<int>
#define max_heap priority_queue<int>
#define min_heap priority_queue<int , vector<int>, greater<int> >
#define pb push_back
#define all(container) container.begin(), container.end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define printArr(name,from,to) for(int x = from; x < to; x++) {cout << name[x] << " ";} cout << endl;
#define fi first
#define se second
#define mp make_pair
#define prime1 304933
#define prime2 15486277 
#define mod2 179424691
#define int ll

typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

const ll MOD = 1000000007;
const ll MAX = 3005;
const double PI = 3.1415926;
const ll INF = 1e18;
const double EPS = 1e-5;

int n;
double prob[MAX];
double dp[MAX][MAX];
bool seen[MAX][MAX];

double solve(int i, int ch){
	if (i == n){
		if (ch > n/2) return 1.0;
		return 0.0;
	}
	if (seen[i][ch]) return dp[i][ch];
	seen[i][ch] = true;
	return dp[i][ch] = prob[i] * solve(i+1, ch+1) + (1 - prob[i]) * solve(i+1, ch);
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	clock_t t1, t2;
	t1 = clock();
	cin >> n;
	for(int i = 0 ; i < n; ++i){
		cin >> prob[i];
	}
	cout << setprecision(9) << fixed;
	cout << solve(0,0) << endl;
	t2 = clock(); cerr << "time taken: " << (t2-t1)/(long double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 79744
#include <iostream>

using namespace std;

int countDivisor(int n){
    int ans=0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(i*i==n){
                ans++;
            }
            else ans+=2;
        }
    }
    return ans;
}

int main()
{
    int n;
    cin>> n;
    int  ans=0;
    for (int i=1;i<=n;i+=2){
        if(countDivisor(i)==8){
            ans++;
        }

    }
    cout << ans << endl;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int a,b,c;cin>>a>>b>>c;

    cout<<max(0,c-(a-b))<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(){
  int *x,n,i,p=0,j;
 
  while(1){
    scanf("%d",&n);
    if(1<=n && n<=10000)
      break;
  }
 
  x=(int*)malloc(sizeof(int)*n);
 
  for(i=0;i<=n-1;i++){
 
    scanf("%d",&x[i]);
    if(x[i]<2 && x[i]>pow(10,8)){ 
      i--;
    } 
 
    if(x[i]==2){
      p++;
      continue;
    }
    else if(x[i]<2 || x[i]%2==0){ 
      continue;
    }
 
    else{
      j = 3;
 
      while(j<=sqrt(x[i])){
	if(x[i]%j==0){
	  break;
	}
	j=j+2;
      }
      if(j>sqrt(x[i])) p++;
    }
 
  }
   
  printf("%d\n",p);
 
  return 0;
}

Measured memory_bytes: 628
use proconio::{input, fastout};

macro_rules! chmin {
    ($base:expr, $($cmps:expr),+ $(,)*) => {{
        let cmp_min = min!($($cmps),+);
        if $base > cmp_min {
            $base = cmp_min;
            true
        } else {
            false
        }
    }};
}

macro_rules! chmax {
    ($base:expr, $($cmps:expr),+ $(,)*) => {{
        let cmp_max = max!($($cmps),+);
        if $base < cmp_max {
            $base = cmp_max;
            true
        } else {
            false
        }
    }};
}

macro_rules! min {
    ($a:expr $(,)*) => {{
        $a
    }};
    ($a:expr, $b:expr $(,)*) => {{
        std::cmp::min($a, $b)
    }};
    ($a:expr, $($rest:expr),+ $(,)*) => {{
        std::cmp::min($a, min!($($rest),+))
    }};
}

macro_rules! max {
    ($a:expr $(,)*) => {{
        $a
    }};
    ($a:expr, $b:expr $(,)*) => {{
        std::cmp::max($a, $b)
    }};
    ($a:expr, $($rest:expr),+ $(,)*) => {{
        std::cmp::max($a, max!($($rest),+))
    }};
}

#[fastout]
fn main() {
    input! {
        n: usize,
        abc: [[i64; 3]; n],
    }

    let mut dp = vec![vec![0; 3]; n];
    for i in 0..3 {
        dp[0][i] = abc[0][i];
    }

    for i in 1..n {
        for j in 0..3 {
            for k in 0..3 {
                if j == k { continue; }
                chmax!(dp[i][j], dp[i-1][k] + abc[i][j]);
            }
        }
    }

    let mut ans: i64 = -1;
    for i in 0..3 {
        chmax!(ans, dp[n-1][i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 14720
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  std::string s; std::cin >> s;
  int y = std::stoi(s.substr(0, 4));
  int m = std::stoi(s.substr(5, 2));
  int d = std::stoi(s.substr(8, 2));

  if (y>2019) {
    std::cout << "TBD" << std::endl;
    return 0;
  } else if (y<2019) {
    std::cout << "Heisei" << std::endl;
    return 0;
  }


  if (m>4) {
    std::cout << "TBD" << std::endl;
    return 0;
  } else {
    std::cout << "Heisei" << std::endl;
    return 0;
  }
}


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

using namespace std;
vector<vector<int>> dp;
int sol(vector<vector<int>> &a,int i,int k){
	if(i>=(int)a.size())
		return 0;

	if(dp[i][k]!=-1)
		return dp[i][k];

	// cout<<i<<" "<<k<<endl;
	// for(auto l:dp){
	// 	for(auto j:l){
	// 		cout<<j<<" ";
	// 	}
	// 	cout<<endl;
	// }
	// cout<<endl;

	if(k==0)
		dp[i][k]=max(sol(a,i+1,1),sol(a,i+1,2))+a[i][k];
	else if(k==1)
		dp[i][k]=max(sol(a,i+1,0),sol(a,i+1,2))+a[i][k];
	else
		dp[i][k]=max(sol(a,i+1,1),sol(a,i+1,0))+a[i][k];

	return dp[i][k];
}

int main(){
	int n;
	cin>>n;
	vector<vector<int>> a(n,vector<int>(3));
	dp.resize(n);

	for(int i=0;i<n;i++){
		dp[i].resize(3,-1);
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}

	dp[n-1][0]=a[n-1][0],dp[n-1][1]=a[n-1][1],dp[n-1][2]=a[n-1][2];

	dp[0][0]=sol(a,0,0);
	dp[0][1]=sol(a,0,1);
	dp[0][2]=sol(a,0,2);
	int ans=max(dp[0][0],max(dp[0][1],dp[0][2]));
	cout<<ans<<endl;
}

Measured memory_bytes: 18756
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
    int t, n, i, a, b;
    string s;

    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7')
        cout << "Yes" << "\n";
    else
        cout << "No" << "\n";


    return 0;
}
  

Measured memory_bytes: 3544
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
int N,b,min,tmp,cou;cou=0;
int num[101]={};
cin>>N;
for(int i=0;i<N;i++)
{cin>>b;num[i]=b;}
for(int i=0;i<N;i++)
{

min=i;
for(int j=i;j<N;j++)
{if(num[min]>num[j])min=j;

}
{tmp=num[i];num[i]=num[min];num[min]=tmp;
if(i!=min)cou++;}
}
for(int i=0;i<N;i++)
{if(i)cout<<" ";
cout<<num[i];
}
cout<<endl;cout<<cou<<endl;
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  sort(a.rbegin(), a.rend());
  int ans = 0;
  for(int i = 1; i < n; i++){
    ans += a[i / 2];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4832
// fahadmd16(IIEST Shibpur)
#include<bits/stdc++.h>
using namespace std;

#define ll                                      long long
#define pb                                      push_back
#define pf                                      push_front
#define eb                                      emplace_back
#define mp                                      make_pair
#define ff                                      first
#define ss                                      second
#define db                                      double
#define pll                                     pair<ll, ll>
#define ALL(a)                                  (a).begin(),(a).end()
#define endl                                    "\n"

#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define ford(i, n) for (ll i = n - 1; i >= 0; i--)
#define ford1(i, n) for (ll i = n - 1; i >= 1; i--)
#define forab(i, a, b) for(ll i = a; i < b; i++)
#define forabd(i, a, b) for(ll i = a; i >= b; i--)
#define eps 1e-10

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)


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

#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define tracen( x , n ){ cout<<(#x)<<":";for(int i=0;i<n;i++)cout<<(#x)<<"["<<i<<"]:"<< x[i] << "    "; cout<<endl;}
#define tracenm( x , n , m ){ cout<<(#x)<<endl;for(int i=0;i<n;i++){ cout<<"Row #"<<i<<":"; for(int j=0;j<m;j++) cout<<x[i][j]<<"     "; cout << endl;}}
using namespace std;



const ll sz = 2000 + 2;
const ll mod = 1e9 + 7;
const db PI = acos(-1);



typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;



ll power(ll n, ll k, ll m) {
    ll ans = 1;
    while (k) {
        if (k & 1)ans = (ans * n) % m;
        k /= 2;
        n = (n * n) % m;
    }
    return ans;
}


void solver() {
    ll n; cin >> n;
    VL a(n);
    forn(i, n)cin >> a[i];
    VL dp(n, INT_MAX);
    dp[0] = 0; dp[1] = abs(a[1] - a[0]);
    forab(i, 2, n)dp[i] = min(abs(a[i - 1] - a[i]) + dp[i - 1], abs(a[i - 2] - a[i]) + dp[i - 2]);
    // tracen(dp, n);
    cout << dp[n - 1] << endl;
// cout << "Case #" << test << ": " << ans << endl;
}


int main() {

    IOS;
    ll T = 1; //cin >> T;
    forn1(i, T + 1) {
        clock_t z = clock();
        solver();
        debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
    }
    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

map < ll , ll  > h ;

ll f ( ll n )
{
    if ( h.count ( n ) )
        return h[n] ;

    ll bak = n ;

    n >>= 1 ;
    h[bak] = 2LL * f ( n ) + 1 ;

    return h[bak] ;
}

void solve ( int test_case )
{
    ll n ; cin >> n ;
    h[1] = 1 ;

    ll ans = f ( n ) ;
    cout << ans ;

    line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;

#define Rep(i,l,r) for (int i = (l); i <= (r); ++ i)
#define RepD(i,r,l) for (int i = (r); i >= (l); -- i)
#define RepG(i,x) for (int i = hd[x]; i; i = e[i].nxt)
#define mkp make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair <ll, ll> pll;

const int N = 2e4+5;
const ll inf = 1e15+7;

int n, cnt = 1, hd[N], vis[N], cur[N], S, T, qu[N*100];
ll d[N];
struct edge {int tt, nxt, c, f, w;} e[N<<1];

void addedge (int u, int v, int c, int w) {
	e[++ cnt] = (edge){v,hd[u],c,0,w}, hd[u] = cnt;
	e[++ cnt] = (edge){u,hd[v],0,0,-w}, hd[v] = cnt;
}

bool spfa () {
	int fr = 1, ta = 0;
	Rep(i,1,T) vis[i] = 0, d[i] = -inf, cur[i] = hd[i];
	d[S] = 0, qu[++ ta] = S, vis[S] = 1;
	while (fr<=ta) {
		int x = qu[fr ++]; vis[x] = 0;
		RepG(i,x) {
			int v = e[i].tt, cl = e[i].c-e[i].f;
			if (cl && d[v]<d[x]+e[i].w) {
				d[v] = d[x]+e[i].w;
				if (!vis[v]) vis[v] = 1, qu[++ ta] = v;
			}
		}
	}
	return d[T]>-inf;
}

ll dfs (int x, ll ff, ll &cst) {
	vis[x] = 1;
	if (x==T || !ff) return ff;
	ll res = 0;
	for (int &i = cur[x]; i; i = e[i].nxt) {
		int v = e[i].tt, cl = e[i].c-e[i].f;
		if (!vis[v] && cl && d[v]==d[x]+e[i].w) {
			ll fl = dfs (v, min (ff, 1ll*cl), cst);
			e[i].f += fl, e[i^1].f -= fl;
			res += fl, ff -= fl, cst += e[i].w*fl;
		}
		if (!ff) break;
	}
	return res;
}

ll mcfl () {
	ll cst = 0;
	while (spfa ()) dfs (S, inf, cst);
	return cst;
}

int main () {
	scanf ("%d", &n);
	S = 2*n+5, T = 2*n+6;
	Rep(i,1,n) {
		int x, y, c;
		scanf ("%d%d%d", &x, &y, &c);
		addedge (S, i, c, 0);
		addedge (i, 2*n+1, c, x+y);
		addedge (i, 2*n+2, c, x-y);
		addedge (i, 2*n+3, c, y-x);
		addedge (i, 2*n+4, c, -x-y);
	}
	Rep(i,1,n) {
		int x, y, c;
		scanf ("%d%d%d", &x, &y, &c);
		addedge (n+i, T, c, 0);
		addedge (2*n+1, n+i, c, -x-y);
		addedge (2*n+2, n+i, c, y-x);
		addedge (2*n+3, n+i, c, x-y);
		addedge (2*n+4, n+i, c, x+y);
	}
	printf ("%lld\n", mcfl ());
	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#define ll long long
#define INF 0x3f3f3f3f
#define N 1005
using namespace std;
int r,c;
int a[50][50];
int main()
{
	scanf("%d%d",&r,&c);
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<=9;j++)
		scanf("%d",&a[i][j]);
	}
	for(int k=0;k<=9;k++)
	{
		for(int i=0;i<=9;i++)
		for(int j=0;j<=9;j++)
		{
			if(a[i][k]+a[k][j]<a[i][j]){
				a[i][j]=a[i][k]+a[k][j];
			}
		}
	}
	int ans=0;
	for(int i=0;i<r;i++)
	{
		for(int j=0;j<c;j++)
		{
			int x;
			scanf("%d",&x);
			if(x==-1) continue;
			ans+=a[x][1];
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int i, start, max, num;
    char S[3];
    start = 0;
    max = 0;
    num = 0;
    scanf("%s", S);
    for (i = 0; i < 3; i++)
    {
        if (S[i] == 'R')
        {
            if (i > 0 && S[i - 1] != 'R')
            {
                num = 0;
            }
            num++;
        }
    }
    printf("%d\n", num);
    return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int l[n];
    for(int i=0; i<n; i++)
    {
        cin >> l[i];
    }
    sort(l, l+n);
    int ans = 0;
    for(int i=0; i<n-2; i++)
    {
        for(int j=i+1; j<n-1; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k])
                    continue;
                if(l[k] >= l[i] + l[j])
                    continue;
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _for(i, 1, 10) { _for(j, 1, 10) { cout << i << "x" << j << "=" << i * j << endl; } }
    }
    return 0;
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {

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

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n; i++) {

            for (int j = i + 1; j < n; j++) {

                int sum = 0;
                for (int k = 0; k < d; k++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844