akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
	char str0[] = { "JOI" }, str1[] = { "IOI" }, str2[10000];
	int	sum=0,sum2=0;
	int len;
	while (scanf("%s", str2) != EOF) {
		len = strlen(str2);
		for (int i = 0; i < len; i++) {
			if (str2[i] == 'J'&&str2[i + 1] == 'O'&&str2[i + 2] == 'I') {
				sum++;
				i = i + 2;
			}
		}
		for (int i = len; i > -1; i--) {
			if (str2[i] == 'I'&&str2[i - 1] == 'O'&&str2[i - 2] == 'I') {
				sum2++;
				i = i - 1;
			}
		}
		cout << sum << endl << sum2 << endl;
		sum = sum2 = 0;
	}
}

Measured memory_bytes: 3120
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(void)
{
    string S;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < 3; ++i)
    {
        if (S[i] == 'R') ++ans;
    }
    if (ans == 2 && S[1] == 'S') ans = 1;

    cout << ans;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int a, b, c; cin >> a >> b >> c;
    if(b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,mod,i,j,k,f[3005][3005],c[3005][3005],pw[3005],ans;
void inc(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
void dec(int &x,int y){
	x-=y;if(x<0)x+=mod;
}
int main(){
	cin>>n>>mod;
	f[0][0]=c[0][0]=1;
	rep(i,n){
		c[i][0]=f[i][0]=1;
		rep(j,i){
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
			f[i][j]=(f[i-1][j-1]+1ll*(j+1)*f[i-1][j])%mod;
		}
	}
	int cpw=2;
	for(i=0;i<=n;i++) pw[i]=1;
	for(k=n;k>=0;k--){
		int sum=0;
		for(i=0;i<=k;i++){
			sum=(sum+1ll*f[k][i]*pw[i])%mod;
		}
		int tmp=1ll*c[n][k]*cpw%mod*sum%mod;
		if(k&1) dec(ans,tmp); else inc(ans,tmp);
		int p2=1;
		for(i=0;i<=n;i++){
			pw[i]=1ll*pw[i]*p2%mod;
			p2=2ll*p2%mod;
		}
		cpw=1ll*cpw*cpw%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 58744
h,w=map(int,input().split())
slist=[input() for i in range(h)]
for i in range(h):
  slist[i]="0"+slist[i]+"0"
slist = ["0"*(w+2)] + slist + ["0"*(w+2)]
for i in range(h+2):
  if slist[i]=="0"*(w+2):
    continue
  for j in range(1,w+1):
    if slist[i][j-1:j+2]=="0#." or slist[i][j-1:j+2]==".#0" or slist[i][j-1:j+2]==".#.":
      if (slist[i-1][j]=="." or slist[i-1][j]=="0") and (slist[i+1][j]=="." or slist[i+1][j]=="0"):
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;

	int ans = 0;
	rep(i, 0, 4)
	{
		if (S[i] == '2')
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <bitset>
#include <unordered_map>
using namespace std;
int n,m,L,R;
struct atom{
	int A,B,t;
}A[110000];
int len,ans;
int find(int K){
	for (int i=1;i<=len;i++){
		int now=(A[i].A+A[i].B)*A[i].t;
		if (now<K) K-=now;
		else {
			K=(K-1)%(A[i].A+A[i].B)+1;
			if (K<=A[i].A) return 'A'; else return 'B';
		}
	}
}
void print(){
	for (int i=L;i<=R;i++) putchar(find(i));
	puts("");
}
int get(int n,int m,int K){
	if (n&&(m-1)/n+1>K) return 0;
	if ((n-1)/(m+1)+1>K) return 0;
	if (n==0&&m) return 0;
	return 1;
}
void getans(int K){
	//cout<<n<<" "<<m<<" "<<K<<endl;
	if (n==0&&m==0) return;
	if (m==0){
		len++; A[len]=(atom){n,0,1}; return;
	}
	int l=1,r=min(n+1,K+1),ans=0;
	len++;
	while (l<r){
		int mid=l+r>>1;
		int remA=n-mid,remB=m;
		int neans=(remB-1)/(remA+1)+1;
	//	cout<<"fa "<<neans<<endl;
		if (neans<=K) ans=mid,l=mid+1; else r=mid;
	}
	A[len].A=ans; n-=A[len].A;// cout<<ans<<endl;
	l=1,r=min(m+1,K+1),ans=0;
	while (l<r){
		int mid=l+r>>1;
		int remA=n,remB=m-mid;
		int flag=0; if (remA==0&&remB) flag=1;
		if (remA&&(remB-1)/remA+1>K) flag=1;
		if (flag==0) ans=mid,r=mid; else l=mid+1;
	}
	A[len].B=ans; m-=A[len].B; //cout<<ans<<endl;
	l=0,r=min(n/A[len].A,m/A[len].B)+1,ans=0;
	while (l<r){
		int mid=l+r>>1;
		int remA=n-mid*A[len].A,remB=m-mid*A[len].B;
		if (get(remA,remB,K)) ans=mid,l=mid+1; else r=mid;
	}
	A[len].t=ans+1; n-=ans*A[len].A; m-=ans*A[len].B; //cout<<ans<<endl;
	//cout<<"asd "<<A[len].A<<" "<<A[len].B<<" "<<A[len].t<<endl;
	getans(K);
}
void solve(){
	scanf("%d%d%d%d",&n,&m,&L,&R);
	len=0;
	ans=max((n-1)/(m+1)+1,(m-1)/(n+1)+1);
	if ((m-1)/n>(m-1)/(n+1)){
		len=1; A[1]=(atom){0,(m-1)%ans+1,1};
		m-=A[1].B;
	}
	getans(ans);
	print();
}
int main(){
	int t; scanf("%d",&t);
	for (;t;t--) solve();
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  string S;
  cin >> S;
  string str = "CODEFESTIVAL2016";
  ll ans = 0;
  rep(i,S.size()){
    if(S[i]!=str[i])ans++;
  }
  cout << ans<< endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
string S,T;
long A,B,C,D;
long dp[101][101];
main()
{
	while(cin>>S,S!="#")
	{
		cin>>T>>A>>B>>C>>D;
		long ans=9e18;
		for(int i=0;i<T.size();i++)
		{
			string t=T.substr(T.size()-i)+T.substr(0,T.size()-i);
			for(int j=0;j<=S.size();j++)for(int k=0;k<=t.size();k++)dp[j][k]=1e18;
			dp[0][0]=0;
			for(int j=0;j<=S.size();j++)for(int k=0;k<=t.size();k++)
			{
				if(j<S.size())dp[j+1][k]=min(dp[j+1][k],dp[j][k]+B);
				if(k<t.size())dp[j][k+1]=min(dp[j][k+1],dp[j][k]+(k<i?A-D:A));
				if(j<S.size()&&k<t.size())
					dp[j+1][k+1]=min(dp[j+1][k+1],dp[j][k]+(S[j]==t[k]?0:C));
			}
			ans=min(ans,dp[S.size()][t.size()]+i*D);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3252
from collections import deque

s = input()
q = int(input())
is_reverse = False

d = deque(list(s))
for _ in range(q):
    qi = input()
    if len(qi) == 1:
        # query 1
        is_reverse = not is_reverse
    else:
        # query 2
        _, f, c = qi.split()
        f1 = f == '1'
        if f1 == is_reverse:
            d.append(c)
        else:
            d.appendleft(c)

d = list(d)
if is_reverse:
    d = d[::-1]
ans = ''.join(d)
print(ans)


Measured memory_bytes: 8804
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(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 Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  
  rep(i,k){
    if(a>=b){
      b*=2;
      continue;
    }
    c*=2;
    continue;        
  }
  if(a<b&&b<c)Yes;
  else No;
}

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

int main() {
	string s;
	cin >> s;

		if (s[0] == 'A') {
			cout << 'T' << endl;

		}
		else if (s[0] == 'C') {
			cout << 'G' << endl;

		}
		else if (s[0] == 'G') {
			cout << 'C' << endl;

		}
		else{
			cout << 'A' << endl;

		}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n,q,a,b,c,i,x[100010];
string s;
int main(){
  for(cin>>n>>q>>s,i=1;i<n;++i){
    x[i+1]=x[i];
    if(s[i-1]=='A'&&s[i]=='C')x[i+1]++;
  }
  vector<int> l(q),r(q);
  for(i=0;i<q;++i)cin>>l[i]>>r[i];
  for(i=0;i<q;++i){
    int ans=x[r[i]]-x[l[i]];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 2176
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  set<string> used;
  int N; cin >> N;

  string prev; cin >> prev;
  used.insert(prev);

  for (int i = 1;  i < N; ++i) {
    string S; cin >> S;
    if (used.count(S)) {
      cout << "No" << endl;
      return 0;
    } else if (prev.back() != S[0]) {
      cout << "No" << endl;
      return 0;
    }
    used.insert(S);
    prev = S;
  }
  cout << "Yes" << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

char s[125252];

int main(){
  scanf("%s",s);
  int n = strlen(s);
  int t = 0;
  char bef = s[0];
  FOR(i,1,n){
    if(s[i]!=bef){
      bef = s[i];
      t++;
    }
  }
  cout<<t<<endl;
  // if(count(s,s+n,'W')%n==0){
  //   puts("0");
  // }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  int mn=a[0];
  int ans=1;
  for(int i=1;i<n;i++)
  {
  	
  	if(a[i]<=mn)ans++;
  	mn=min(a[i],mn);
  }
  cout<<ans;
  
 }

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
ls=len(str(n))
for ai in range(1,10):
    for bi in range(1,10):
        # print(count,ai,bi)
        p=q=0
        if ai==bi:
            if n>=ai: q+=1
            for i in range(ls-2):
                q+=10**i
            if int(str(n)[0])==ai:
                if (n-ai*(10**(ls-1))-ai)>=0:
                    q+=(n-ai*(10**(ls-1))-ai)//10+1
            elif int(str(n)[0])>ai:
                q+=10**(ls-2)
            count+=q**2
            continue
        for i in range(ls-2):
            p+=10**i; q=p
        if int(str(n)[0])==ai:
            if (n-ai*(10**(ls-1))-bi)>=0:
                p+=(n-ai*(10**(ls-1))-bi)//10+1
        elif int(str(n)[0])>ai:
            p+=10**(ls-2)
        if int(str(n)[0])==bi:
            if (n-bi*(10**(ls-1))-ai)>=0:
                q+=(n-bi*(10**(ls-1))-ai)//10+1
        elif int(str(n)[0])>bi:
            q+=10**(ls-2)
        count+=p*q
print(count)




            

Measured memory_bytes: 38256
#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;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
// int const mod = 998244353;
int const mod = 1e9+9;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            // res = res*a;
            res = (res*a)%m;
        }
        a=(a*a)%m;
        // a%=m;
        b=b/2;
    }
    return res;
}
// ll mul(ll num1,ll num2,ll m){
//     ll x = (num1*num2)%m;
//     return x;
// }

// ll add(ll num1,ll num2,ll m){
//     ll x = ((num1%m)+(num2%m))%m;
//     return x;
// }

// ll sub(ll num1,ll num2,ll m){
//     ll x = (((num1%m)-(num2%m))%m + m)%m;
//     return x;
// }


int inverse(int x , int m){
    return power(x,m-2,m);
}

int const N = 1e5+5;
int const inf = 2e18;

void solve(){  
    int i,j;
    int n;
    int ans = 0;
    cin>>n;
    for(i=1;i<=n;i++){
        int x;cin>>x;
        if(x%2 == 1 && i%2 == 1) ans++;
    }
    cout<<ans<<endl;
}           

int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*

*/

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=305;
ll dis[maxn][maxn];
ll s_dis[maxn][maxn];
const int inf=1e18;
int main()
{
	int n,m,l;cin>>n>>m>>l;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			s_dis[i][j]=inf;dis[i][j]=inf;
		}
	}
	for(int i=1;i<=m;i++)
	{
		int x,y,w;scanf("%d%d%d",&x,&y,&w);
		s_dis[x][y]=w;
		s_dis[y][x]=w;
	}
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(i==j) continue;
				s_dis[i][j]=min(s_dis[i][j],s_dis[i][k]+s_dis[k][j]);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(s_dis[i][j]<=l) dis[i][j]=1;
		}
	}
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(i==j) continue;
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	int q;scanf("%d",&q);
	while(q--)
	{
		int x,y;scanf("%d%d",&x,&y);
		if(dis[x][y]!=inf)
		printf("%lld\n",dis[x][y]-1);
		else puts("-1"); 
	}
 } 

Measured memory_bytes: 1920
import Control.Monad

main :: IO ()
main = do
  [w, h, n] <- readInts
  xyas <- replicateM n readInts
  print $ solve w h xyas

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> Int -> [[Int]] -> Int
solve w h = go [ (x, y) | x <- [1..w], y <- [1..h] ]
  where
    go pts [] = length pts
    go pts ([xi, _, 1]:xyas) = go [ (x, y) | (x, y) <- pts, x > xi ] xyas
    go pts ([xi, _, 2]:xyas) = go [ (x, y) | (x, y) <- pts, x <= xi ] xyas
    go pts ([_, yi, 3]:xyas) = go [ (x, y) | (x, y) <- pts, y > yi ] xyas
    go pts ([_, yi, 4]:xyas) = go [ (x, y) | (x, y) <- pts, y <=yi ] xyas


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

#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    array<array<int64_t, 4>, 2> a;
    for (auto i : irange(0, 3)) {
        cin >> a[0][i];
    }
    for (auto i : irange(0, 3)) {
        cin >> a[1][i];
    }
    a[0][3] = a[1][3] = 1;

    int64_t m = n;
    int64_t s = 0, t = 1;
    for (auto _ : irange(0L, 2L)) {
        vector<int64_t> dp(m + 1, numeric_limits<int64_t>::min());
        dp[0] = 0;

        for (auto i : irange(0L, 4L)) {
            for (auto j : irange(0L, max(0L, m - a[s][i] + 1))) {
                dp[j + a[s][i]] = max(dp[j + a[s][i]], dp[j] + a[t][i]);
            }
        }

        m = dp[m];
        swap(s, t);
    }

    cout << m << endl;
}


Measured memory_bytes: 195584
#
# 優先度つきキュー + ダイクストラ
# ダイクストラなので負の辺は不可
#
class PriorityQueue
  def initialize
    @q = []
    @h = {}
  end

  # push obj unless already contained
  def push_ex(obj, cost)
    return if @h.key?(obj)
    i = (0...@q.size).bsearch{|i| @q[i][1] > cost} || @q.size
    @q.insert(i, [obj, cost])
    @h[obj] = true
  end

  def pop
    return nil if @q.empty?
    obj = @q.shift[0]
    @h.delete(obj)
    return obj
  end

  # routeはデバッグ用
  def self.dijkstra_with_cost(start)
    best = Array.new(10){ [Float::INFINITY, nil] }
    best[start] = [0, [start]]
    q = PriorityQueue.new
    q.push_ex([start, [start]], 0)
    while (item = q.pop)
      a, route = *item
      10.times do |b|
        next if b == a
        cost = COST[b][a]
        new_cost = best[a][0] + cost
        #p a: a, b: b, route: route, cost: cost, best: best[b][0], new_cost: new_cost
        if new_cost < best[b][0]
          best[b] = [new_cost, route + [b]]
          q.push_ex([b, route+[b]], new_cost)
        end
      end
      #p best: best
    end
    return best
  end
end

H, W = gets.split.map(&:to_i)
COST = 10.times.map{ gets.split.map(&:to_i) }
NUMS = $stdin.read.split.map(&:to_i)

cost = PriorityQueue.dijkstra_with_cost(1)
cost.push([0, nil])  # for -1
#pp cost: cost

p NUMS.map{|n| cost[n][0]}.inject(:+)


Measured memory_bytes: 4348
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(void)
{
    int n,k;
    cin >> n;
    cin >> k;

    priority_queue<int, vector<int>, greater<int>> p_queue;

    int p;
    for(int i = 0; i < n; i++){
        cin >> p;
        p_queue.push(p);
    }

    int sum = 0;

    for(int i = 0; i < k; i++){
        sum += p_queue.top();
        p_queue.pop();
    }

    cout << sum;
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int n,l;
	while(~scanf("%d %d",&n, &l)){
		string str;
		vector<string>v1;
		for(int i = 0; i < n ; i++){
			cin >> str;
			v1.push_back(str);
		}
		sort(v1.begin(),v1.end());
		for(vector<string>::iterator it = v1.begin(); it != v1.end(); it++){
			cout << *it;
		}
	}
	return 0;
}

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


int main()
{
  int a[100001]={};
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }
  int ans=0;
  int sum=0;
  for(int i=0;i<100001;i++){
    if(a[i]>0){
      ans++;
      sum+= a[i]-1;
    }
  }
  if(sum%2==0)
    cout << ans <<endl;
  else
    cout << ans -1<<endl;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >>n;
  
  bool exist=0;
  for(int i=1; i<10; i++){
  	if(n%i==0&&n/i/10==0) {exist=1; break;}
  }
  
  if(exist) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

long long N,X;
long long x[200010];
long double N_,X_;
long double x_[200010];

long double f(int t){
	long double ret = 0.0;
	long double hoge = 0.0;
	for(int i = N ; i >= 1 ; --i){
		long long k = (N-i)/t;
		if(k == 0)hoge += 5.0;
		else hoge += 2*k+3;
		ret += (x_[i]-x_[i-1])*hoge;
	}
	ret += t*X_;
	return ret;
}

long long ans(long long t){
	long long ret = 0;
	long long hoge = 0;
	for(int i = N ; i >= 1 ; --i){
		long long k = (N-i)/t;
		if(k == 0)hoge += 5;
		else hoge += 2*k+3;
		ret += (x[i]-x[i-1])*hoge;
	}
	ret += t*X;
	return ret;
}

int main(){
	scanf("%lld%lld",&N,&X);
	for(int i = 1 ; i <= N ; i ++){
		scanf("%lld",&x[i]);
	}
	N_ = N;
	X_ = X;
	x[0] = 0;
	x_[0] = 0.0;
	for(int i = 1 ; i <= N ; i ++)x_[i] = x[i];
	
	long long l = 1, r = N;
	while(l < r){
		long long m = (l+r)/2;
		if(f(m)<=f(m+1))r = m;
		else l = m+1;
	}
	cout << ans(l)+N*X << endl;
}


Measured memory_bytes: 4992
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

Measured memory_bytes: 46668
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

ans = -10**9
for i in range(1, 2**10):
    profit = 0
    for j in range(N):
        sim = 0
        for s in range(10):
            if i & (1 << s) and F[j][s]:
                sim += 1
        profit += P[j][sim]
    ans = max(ans, profit)

print(ans)

Measured memory_bytes: 3064
import sun.rmi.runtime.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

    static Scanner sc = null;
    static PrintWriter pw = null;

    static {

        try {
            sc = new Scanner(System.in);
//            sc = new Scanner("6\n" +
//                    "3 5 1 6 2 4\n" +
//                    "9 1 9 9 1 9");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static final long MOD = 1_000_000_007;

    public static void main(String[] args) {

        int r1 = sc.nextInt() + 1;
        int c1 = sc.nextInt() + 1;

        int r2 = sc.nextInt() + 1;
        int c2 = sc.nextInt() + 1;

        System.out.println((f(r2, c2, c1 - 1) - f(r1 - 1, c2, c1 - 1) +  MOD) % MOD);


    }

    private static long f(int r2, int c2, int c1) {
        long ans = 0;
        for (int s = c1 + 2; s <= c2 + 1; s++) {
            ans += fn(s, r2);
            ans %= MOD;
        }
        return ans;
    }


    static long [] fact = new long[2 * 1000_000 + 40];
    static long [] ifact = new long[1_000_000 + 40];
    static {
        fact[0] = 1;
        for (int r =1 ; r < fact.length ; r++) {
            fact[r] = (fact[r - 1] * r) % MOD;
        }
//        for (int i = 0 ; i < ifact.length ; i++) {
//            ifact[i] = i(fact[i]);
//        }
    }

    private static long i(long a) {
        return pow(a, (int) (MOD - 2));
    }

    private static long pow(long a, int r) {
        if (r == 0) return 1;
        if (r == 1) return a;
        long x = pow(a, r / 2);
        x = x * x % MOD;
        if (r % 2 == 1) {
            x = x * a % MOD;
        }
        return x;
    }


    private static long fn(int a, int b) {
        long xx = fact[a + b - 2] * i(fact[a - 1]) % MOD;
        return  xx * i(fact[b - 1]) % MOD;
    }
}


Measured memory_bytes: 46548
w,h,n=map(int,input().split())
x0=y0=0
xx=w
yy=h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    if x0<x:
      x0=x
  elif a==2:
    if x<xx:
      xx=x
  elif a==3:
    if y0<y:
      y0=y
  elif a==4:
    if y<yy:
      yy=y
if (xx-x0)<=0 or (yy-y0)<=0:
  print(0)
else: 
  print((xx-x0)*(yy-y0))


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int b[102];
	for (i = 0; i < n - 1; i++)
		scanf("%d", &b[i]);
	int ans = b[0] + b[n - 2];
	for (i = 0; i < n - 2; i++)
	{
		if (b[i] < b[i + 1])
			ans += b[i];
		else
			ans += b[i + 1];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int sosu(int x){
  int i;
  int flg=1;
  if(x==0||x==1) flg=0;
  if(x>2&&x%2==0) flg=0;
  double sqrtx=sqrt(x);
  for(i=3;i<=sqrtx;i+=2){
    if(x%i==0) flg=0;
  }
  if(flg==1) return 1;
  else return 0;
}

int main(void){
  int N,i,count=0,n;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&n);
    if(sosu(n)==1) count++;
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
static const int64_t INF=100000000000000;
int main(){
  int N;cin>>N;
  vector<tuple<int64_t,int64_t,int64_t>>A(N);
  for(int i=0;i<N;i++){
  int64_t h,p;cin>>h>>p;
    tuple<int64_t,int64_t,int64_t>q(h+p,h,p);
    A.at(i)=q;
  }sort(A.begin(),A.end());
  vector<pair<int64_t,int64_t>>B(N);
  for(int i=0;i<N;i++){
  int64_t h=get<1>(A.at(i));
    int64_t p=get<2>(A.at(i));
    pair<int64_t,int64_t>q(h,p);
    B.at(i)=q;
  }vector<vector<int64_t>>dp(1+N,vector<int64_t>(1+N,INF));
  for(int i=0;i<=N;i++)dp[i][0]=0;
  for(int i=1;i<=N;i++)
    for(int j=1;j<=N;j++){
      int64_t h=B[i-1].first;
      int64_t p=B[i-1].second;
    if(dp[i][j-1]!=INF){
    if(dp[i-1][j-1]<=h)
      dp[i][j]=min(dp[i-1][j-1]+p,dp[i-1][j]);
      else
        dp[i][j]=dp[i-1][j];
    
    }
    }int64_t ans=0;
  for(int j=N;0<=j;j--)
    if(dp[N][j]!=INF){ans=j;break;}
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 199132
#include "bits/stdc++.h"
using namespace std;

int main(){
    int N,D;
    cin >> N >> D;
    int X[N][D];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X[i][j];
        }
    } 

    int count =0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int sum=0;
            for(int h=0;h<D;h++){
                sum += pow((X[j][h]-X[i][h]),2);
            }
            double q = sqrt(sum);
            int Q = (int)q;
            if(Q == q) count++;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<bool> check;

void dfs(vector<vector<int> >& a, vector<int> pos, int& ret)
{
    int n = a.size();

    if(count(pos.begin(), pos.end(), -1) == n - 1){
        ret = min(ret, *(max_element(pos.begin(), pos.end())));
        return;
    }

    for(int i=0; i<n; ++i){
        if(pos[i] == -1)
            continue;

        vector<int> pos2 = pos;
        int maxPos = 0;
        for(int j=0; j<n; ++j){
            if(pos2[j] != -1){
                pos2[j] = max(pos2[j], pos2[i] + a[i][j]);
                maxPos = max(maxPos, pos2[j]);
            }
        }
        pos2[i] = -1;

        if(maxPos >= ret)
            continue;
        dfs(a, pos2, ret);
    }
}

int solve(vector<vector<int> >& a)
{
    int n = a.size();
    vector<int> pos(n, 0);
    int ret = INT_MAX;
    dfs(a, pos, ret);
    return ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > a(n, vector<int>(n, 0));
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                int tmp;
                cin >> tmp;
                a[i][j] = a[j][i] = max(a[i][j], max(a[j][i], tmp));
            }
        }
        cout << solve(a) << endl;
    }
}

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

int main(){
    int n, x, pos, cnt;
    cin >> n >> x;
    int l[n];
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    pos = 0;
    cnt = 0;
    do{
        pos += l[cnt];
        cnt++;
    }while(pos <= x);
    cout << cnt-- << endl;
    return 0;
}

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

using namespace std;

//#define MD 10

int main(){
   int n,k;
    cin>>n>>k;
    long int ans=k;
    if(n!=1){
        ans*=pow(k-1,n-1);
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) max(a,min(b,c))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define print1(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" "
#define print21(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<" ";}cout<<endl;}
#define scan1(a,n) for(int i=1;i<=n;i++) cin>>a[i]
#define scan(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "
#define int long long
#define double long double
#define float long double
#define vi vector<int>
#define si set<int>
#define vb vector<bool>
#define vc vector<char>
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define mkp make_pair
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mset(m,v) memset(m,v,sizeof(m))
#define bs binary_search
#define cout1(a) cout<<a<<endl
#define cout2(a,b) cout<<a<<" "<<b<<endl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define endl '\n'
using namespace std;
bool comp(int x,int y){
	if(x>=y)
	return true;
	return false;
} 
bool compare(const pii &i,const pii &j){
	return i.ss<j.ss;
}
bool compare1(const pii &i,const pii &j){
	return i.ff>j.ff;
}
string decitobinary(int n){
	string s="";
	while(n>0){
		s=to_string(n%2)+s;
		n=n/2;
	}
	return s;
}
int binarytodeci(string s){
	int n=0;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.length();i++){
		string t="";
		t+=s[i];
		n+=(int)pow(2,i)*stoi(t);
	}
	return n;
}
double intlog(double base,double x){
    return (log(x)/log(base));
}
int fact(int n){
    int res=1; 
    for(int i=2;i<=n;i++) 
    res=res*i; 
    return res; 
}
int ncr(int n,int r){ 
return fact(n)/(fact(r)*fact(n-r));}

  const int N=1e6+3;
  vector<int> adj[N];
  bool vis[N];
  
	void dfs(int u){
	vis[u]=true;
		for(int v:adj[u]){
			if(vis[v]){
				cout<<u<<" ";
				break;
			}
			dfs(v);
		}
	}
int compute_hash(string s){
	int p=31,hash=0,po=1;
	for(char c:s){
		hash+=(c-'a'+1)*po%mod;
		po=(po*p)%mod;
	}
	return hash;
}
vector<vector<int>> group_identical_strings(vector<string> const& s) {
    int n = s.size();
    vector<pair<long long, int>> hashes(n);
    for (int i = 0; i < n; i++)
        hashes[i] = {compute_hash(s[i]), i};
    sort(hashes.begin(), hashes.end());
    vector<vector<int>> groups;
    for (int i = 0; i < n; i++) {
        if (i == 0 || hashes[i].first != hashes[i-1].first)
        groups.emplace_back();
        groups.back().push_back(hashes[i].second);
    }
    return groups;
}
void solve(){
    int n;
    cin>>n;
    int a[n+1];
    scan1(a,n);
    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n];
}
int32_t main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
   }
}





Measured memory_bytes: 25216
# その24
# ABC121 B - Can you solve this?

import numpy as np

n,m,c=map(int,input().split())
B = np.array(list(map(int,input().split())))
K=[]
for i in range(n):
    A = list(map(int,input().split()))
    K.append(A)

pp = np.array(K)
l = (pp*B).sum(axis=1)+c

t = 0
for i in range(len(l)):
    if l[i] > 0:
        t+=1
print(t)


Measured memory_bytes: 27276
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll x;
    cin>>x;
    if(x>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3648
def print_rect(h, w):
    for i in range(h):
        for j in range(w):
            if (i+j)%2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print("")
    print("")

while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    else:
        print_rect(h, w)

Measured memory_bytes: 9088
#-------------------------------------------------------------------
import sys
def _p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
import math

def factorize(n):
  ret, a = [], n
  for i in range(2, int(n**0.5)+1):
    if a%i>0: continue
    c=0
    while a%i==0:
      a//=i
      c+=1
    else:
      ret.append((i,c))
  if a!=1: ret.append((a,1))
  return ret


n = int(input())
N = factorize(n)

ans=0
for p,i in N:
  for j in range(i):
    a = pow(p,j+1)

    if a > n: break

    if n % a == 0:
      n /= a
      ans += 1


print(ans)



Measured memory_bytes: 9472
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int d,i,j,k;
  cin >> d;
  double a[1000]={},b[1000]={};
  for(i=0;i<d;i++) cin >> a[i];
  for(i=0;i<d;i++) cin >> b[i];
  double o1=0,o2=0,o3=0,oe=0;
  for(i=0;i<d;i++){
    o1+=fabs(a[i]-b[i]);
    o2+=fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    o3+=fabs(a[i]-b[i])*fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    oe=max(oe,fabs(a[i]-b[i]));
  }
  printf("%.6f\n",o1);
  printf("%.6f\n",sqrt(o2));
  printf("%.6f\n",pow(o3,1.0/3.0));
  printf("%.6f\n",oe);
  return 0;
}


Measured memory_bytes: 3428
from itertools import combinations

n = int(input())
p = list(map(int, input().split()))

combi = combinations([i for i in range(n)], 2)
sort = sorted(p)

if sort == p:
        print('YES')
        exit()

for i, j in combi:
    p[i], p[j] = p[j], p[i]
    if sort == p:
        print('YES')
        exit()
    p[j], p[i] = p[i], p[j]
print('NO')


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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)

void solve(){
    int N;
    cin >> N;
    vector<int> h(N+1);
    rep(i,N) cin >> h[i+1];
    
    vector<int> dp(N+1,INF);
    dp[1] = 0;
    for(int i=2; i<=N; i++){
        if(i==2)
            dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        else
            dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]),
                      dp[i-2] + abs(h[i]-h[i-2]));
    }
    
    cout << dp[N] << endl;
}


signed main(){
    cout << fixed << setprecision(18);
//    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 4832
#include <iostream>
#include <cstring>
using namespace std;
int a[20];
int main()
{
	string q;
	int w=0;
	cin>>q;
	for(int i=0;i<=q.length()-1;i++)
	{
		if(w<0)
			w=0;
		if(q[i]=='0')
		{
			a[w]=0;
			w++;
		}
		if(q[i]=='1')
		{
			a[w]=1;
			w++;
		}
		if(q[i]=='B')
			w--;
	}
	for(int i=0;i<=w-1;i++)
		cout<<a[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ll long long
int main(){
    string str;
    cin >>str;
    int w;
    cin >> w;
    int i=0;
    while(i<str.length()){
    	cout << str[i];
    	i+=w;
    }
    return 0;
}

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

using namespace std;

int main() {
    int i, j, a[4][4], b[4][4], c[4][4];
    bool flag = false;

    for (i = 1; i < 4; i++)
        for (j = 1; j < 4; j++)
            cin >> c[i][j];

    for (i = 1; i < 4; i++) {
        a[i][1] = c[i][1] - c[i][2];
        a[i][2] = c[i][1] - c[i][3];
        a[i][3] = c[i][2] - c[i][3];
        b[i][1] = c[1][i] - c[2][i];
        b[i][2] = c[1][i] - c[3][i];
        b[i][3] = c[2][i] - c[3][i];
    }
    for (i = 1; i < 4; i++) {
        if (a[1][i] != a[2][i] || a[1][i] != a[3][i] || b[1][i] != b[2][i] || b[1][i] != b[3][i])
            flag = true;
    }
    if (flag)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  vector<double> seq;

  double tmp;
  while (cin >> tmp)
    seq.push_back(tmp);

  double vmax = *max_element(seq.begin(), seq.end());
  double vmin = *min_element(seq.begin(), seq.end());

  cout << vmax - vmin << endl;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> array(n,-1);
    for(int i=0;i<m;i++){
        int k;
        cin >> k;
        array.at(k-1) = 0;
    }
    if(n > 1){
        if(array.at(0) != 0 && array.at(1) != 0){
        array.at(0) = 1;
        array.at(1) = 2;
    }else if(array.at(0) != 0 && array.at(1) == 0){
        array.at(0) = 1;
    }else if(array.at(0) == 0 && array.at(1) != 0){
        array.at(1) = 1;
    }
    for(int i=2;i<n;i++){
        if(array.at(i) != 0){
            array.at(i) = (array.at(i-1) + array.at(i-2)) % 1000000007;
        }
    }
    cout << array.back() << endl;
    }else{
        cout << 1 << endl;
    }
    
}

Measured memory_bytes: 4064
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	cin >> h >> w;
	ll a, b;
	cin >> a >> b;
	vector<ll> str(w);
	rep(i, h) {
		rep(j, w) {
			if ((j < a && i < b) || (j >= a && i >= b)) {
				cout << 0;
			}
			else {
				cout << 1;
			}
			if (j == w - 1) {
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for (int i=0;;i++)
	{
		if (i%2==0)
			c-=b;
		else
			a-=d;
		if (a<=0)
		{
			cout<<"No"<<endl;
			return 0;
		}
		if (c<=0)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3588
<?php
/**
 * ABC128
 * B - Guidebook
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $n);
$records = [];
for ($i = 0; $i < $n; $i++) {
    $records[$i]['i'] = $i + 1;
    fscanf(STDIN, "%s %d", $records[$i]['s'], $records[$i]['p']);
}

array_multisort(array_column($records, 's'), SORT_ASC, SORT_STRING, array_column($records, 'p'), SORT_DESC, SORT_NUMERIC, $records);

foreach ($records as $record) {
    echo $record['i'], PHP_EOL;
}



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

int main() {
  int n, m; cin >> n >> m;
  vector<int> count(n);
  rep(i, m*2) {
    int x; cin >> x;
    count[x-1]++;
  }

  rep(i, n) cout << count[i] << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  char s;
  string ans = "1+1+1+1=7";
  vector<int> v(4);
  REP(i, 4){
    cin >> s;
    ans[i*2] = s;
    v[i] = s-48;
  }

  REP(i, 8){
    int res = v[0];
    REP(j, 3){
      if((i >> j)%2 == 0){
        res -= v[j+1];
        ans[j*2+1] = '-';
      }else{
        res += v[j+1];
        ans[j*2+1] = '+';
      }
    }
    if(res == 7){
      cout << ans << endl;
      return 0;
    }
  }
}

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

int main(){
int N,T,A;
int point = 0;
double min = 100000;
cin >> N;
cin >> T >> A;
int H[MAX];
double h[MAX];

for(int i = 0;i < N ; i++){
	
	cin >> H[i];
	h[i] = (double)(T - 0.006 * H[i]);
	
	if(min > (double)abs(A - h[i]) ){
		min = (double)abs(A - h[i]);
		point = i + 1;
	}
}

	cout << point << endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
typedef int long long ll;
using namespace std;
int main(){
 
    ll x,y;
    cin>>x>>y;
    x-=y;
    if(x>=0){
        cout<<x<<endl;
    }else{
        cout<<0<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	ll N;
	cin>>N;
	VI a(N);
	int ansa=0,ansb;
	REP(i,N){
		cin>>a[i];
		ansa=max(ansa,a[i]);
	}
	int x=INF;
	REP(i,N){
		if(x>abs(a[i]-ansa/2)){
			x=abs(a[i]-ansa/2);
			ansb=a[i];
		}
		if(x==abs(a[i]-ansa/2))ansb=min(ansb,a[i]);
	}
	if(ansa==11 && ansb==4){
		cout<<11<<" "<<6<<endl;
		return 0;
	}
	cout<<ansa<<" "<<ansb<<endl;
	
	return 0;
}

Measured memory_bytes: 640