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

using namespace std;

//4
//1 1 2
//2 1 4
//3 0
//4 1 3

//1 1 8
//2 2 7
//3 4 5
//4 3 6

const int MAX = 100;

int n;

int t = 0;

int G[MAX + 1][MAX + 1];
int d[MAX + 1];
int f[MAX + 1];

int color[MAX + 1];
int WHITE = 0;
int GRAY = 1;
int BLACK = 2;

void dfs(int v) {
	color[v] = GRAY;
	d[v] = ++t;

	for (int i = 1; i <= n; ++i) {
		if (G[v][i] == 1 && color[i] == WHITE)
			dfs(i);
	}

	color[v] = BLACK;
	f[v] = ++t;
}

int main() {

	scanf("%d", &n);

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j)
			G[i][j] = 0;
	}

	for (int i = 1; i <= n; ++i) {
		int u, k;
		scanf("%d %d", &u, &k);
		for (int j = 0; j < k; ++j) {
			int v;
			scanf("%d", &v);
			G[i][v] = 1;
		}
	}

	for (int i = 1; i <= n; ++i) {
		if (color[i] == WHITE)
			dfs(i);
	}

	for (int i = 1; i <= n; ++i) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 3112
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


x, k, d = LI()
x = abs(x)
r = x % d
if abs(x) // d > k:
    print(x - d * k)
else:
    if (k - x // d) % 2:
        print(d - r)
    else:
        print(r)






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

int main()
{
  int N, K, x, base, count=0;
  
  cin >> N >> K;
  base = K/2;
  for(int i=0; i<N; i++)
  {
    cin >> x;
    
    if(x>base) count += (K-x)*2;
    else count += x*2;
    
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,a,b;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>a>>b;
    print(min(n*a,b));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
typedef long long int Int;
#define INF 999999999
using ll = long long;
using VI = vector<int>;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  ll ans = 0;
  while(!(a==b&&b==c)||ans%2==1){
    ans+=1;
    if(a<=b&&a<=c) a+=1;
    else if(b<=a&&b<=c) b+=1;
    else c+=1;
  }
  ans/=2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    t = s.replace('9', '2').replace('1', '9').replace('2', '1')

    return t


print(main())


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

ans = 0
sub = sum(s)
if sub % 10 != 0:
    print(sub)
else:
    l = []
    for i in range(n):
        if s[i] % 10 != 0:
            l.append(s[i])
    l.sort()
    for j in l:
        sub -= j
        if sub % 10 != 0:
            break
    
    if sub % 10 == 0:
        print("0")
    else:
        print(sub)

Measured memory_bytes: 3060
n = int(input())
s = list(input())
w, e = [0] * (n + 1), [0] * (n + 1)
ans = float("inf")
for i in range(n):
    if s[i] == "W":
        w[i + 1] = w[i] + 1
    else:
        w[i + 1] = w[i]

    if s[n - i - 1] == "E":
        e[i + 1] = e[i] + 1
    else:
        e[i + 1] = e[i]

for j in range(1, n + 1):
    ans = min(ans, w[j] + e[n - j + 1])

print(ans - 1)


Measured memory_bytes: 25416
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{

    ll i,j,k=0,c1=0,c2=0;
    string s,one="10",zero="01";
    cin>>s;
    j=s.size();
    for(i=0;i<j;i++)
    {
        if(i%2==0&&s[i]=='1')
            c1++;
        if(i%2==1&&s[i]=='0')
            c1++;
    }
    cout<<min(c1,j-c1)<<endl;

}


Measured memory_bytes: 3752
int main()
{
	int A[99][99]={0},i,j,N,t;
	char s,F[4]="SHCD";
	scanf("%d\n",&N);
	for(i=0;i<N;A[s][t]=1,i++)
		scanf("%c %d\n",&s,&t);
	for(i=0;i<4;i++)
		for(j=1;j<14;j++)
			if(!A[F[i]][j])
				printf("%c %d\n",F[i],j);
	return 0;
}






Measured memory_bytes: 2044
import sys
INF = float("inf")
readline = sys.stdin.readline
min_r = INF
ans = -INF
n = int(readline())
for _ in [0] * n:
    r = int(readline())
    if ans < r - min_r:
        ans = r - min_r
    if min_r > r:
        min_r = r
print(ans)

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

int main()
{

        string s;
        cin >> s;

        int len = s.length();
        int cnt = 0;
        string ans;
        for (int i = 0; i < len; ++i) {

                if (s[i] == '0') {
                        ans += '0';
                        cnt++;
                }
                else if (s[i] == '1') {
                        ans += '1';
                        cnt++;
                }
                else {
                        if (cnt > 0) {
                                cnt--;
                                ans = ans.substr(0, cnt);
                        }
                }

        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

void right_triangle(int x, int y, int z)
{
    int xx = x * x;
    int yy = y * y;
    int zz = z * z;
    if (xx == yy + zz) {
        printf("YES\n");
    } else if (yy == xx + zz) {
        printf("YES\n");
    } else if (zz == xx + yy) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}    

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int r[3];
        scanf("%d %d %d", &r[0], &r[1], &r[2]);
        right_triangle(r[0], r[1], r[2]);
    }
    return 0;
}    

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

int main(){
	string S, T, U;
  	int A, B;
  	cin >> S >> T >> A >> B >> U;
  
  if(S == U){
  	A--;
  }
  if(T == U){
  	B--;
  }
  
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
// youngjinp20
// 2020 03

#include <bits/stdc++.h>
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define byr(x) [](const auto& a, const auto& b) { return a.x > b.x; }
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
using namespace std;

typedef long long ll;

int N;
double A[3000];
double dp[3000][3000];

int main() {
	cin >> N;
	for (int i=1; i<=N; i++) {
		cin >> A[i];
	}
	dp[0][0] = 1;
	for (int i=1; i<=N; i++) {
		for (int j=0; j<=N; j++) {
			dp[i][j] += dp[i-1][j] * A[i];
			dp[i][j+1] += dp[i-1][j] * (1-A[i]);
		}
	}

	double sum = 0;
	for (int i=0; i<=N/2; i++) {
		sum += dp[N][i];
	}
	printf("%.9lf", sum);

	return 0;
}


Measured memory_bytes: 70528
#!/usr/bin/env python3

X, N = map(int, input().split())
P = list(map(int, input().split()))

P2 = []

for i in range(0, 102):
    if i in P:
        continue
    P2.append(i)
sa = 10**9
ret = -1
for p in P2:
    if abs(X-p) < sa:
        sa = abs(X-p)
        ret = p

print(ret)


Measured memory_bytes: 9188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>

#define REP(i,N) for(i = 0; i < N; i++)

int main(void)
{
	int n;
	scanf("%d", &n);
	printf("%s\n", n < 1000 ? "ABC" : "ABD");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
using namespace std;
const int MAXN = 100005;
ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

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

  for(int i=0;i<n;i++) for(int j=0;j<3;j++) cin >> a[i][j];

  for(int i=0;i<3;i++) dp[0][i]=a[0][i];
  for(int i=1;i<n;i++)
  {
    for(int j=0;j<3;j++)
    {
      if(j==0)
        dp[i][j]=a[i][j]+max(dp[i-1][1],dp[i-1][2]);
      if(j==1)
        dp[i][j]=a[i][j]+max(dp[i-1][0],dp[i-1][2]);
      if(j==2)
        dp[i][j]=a[i][j]+max(dp[i-1][0],dp[i-1][1]);
    }
  }
  cout << *max_element(all(dp[n-1]))<<endl;

}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;
int cnt[26];

signed main() {
  string s = readString();
  for (auto &c : s)
    cnt[c - 'a']++;
  for (int i = 0; i < 26; i++)
    if (cnt[i] > 1) {
      std::cout << "no" << std::endl;
      return 0;
    }
  std::cout << "yes" << std::endl;
}


Measured memory_bytes: 2304
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;const int N=1e5+10;int n;map <int,int> mp;
int a[N];int b[N];int c[N];int d[N];int S;int ans;
struct bcj
{
	int fa[N];int siz[N];
	inline void ih(){for(int i=1;i<=S;i++)fa[i]=i;for(int i=1;i<=S;i++)siz[i]=1;}
	inline int f(const int& x){return fa[x]=(x==fa[x])?x:f(fa[x]);}
	inline void u(int x,int y)
	{x=f(x);y=f(y);
	//printf("u %d %d\n",x,y);
	if(x==y)return;
	
	ans--;siz[y]+=siz[x];fa[x]=y;}
	inline int getsiz(int x){return siz[f(x)];}
}s;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)a[n+1]^=a[i];for(int i=1;i<=n;i++)b[n+1]^=b[i];
	for(int i=1;i<=n+1;i++)c[i]=a[i];for(int i=1;i<=n+1;i++)d[i]=b[i];
	sort(c+1,c+n+2);sort(d+1,d+n+2);
	for(int i=1;i<=n+1;i++)if(c[i]!=d[i]){printf("-1");return 0;}
	for(int i=1;i<=n+1;i++)if(a[i]!=b[i]||i==n+1){mp[a[i]]=1;mp[b[i]]=1;}
	map <int,int> :: iterator it,it1;S=mp.size();
	if(S==0){printf("0");return 0;}
	for(it=mp.begin(),it1=it,++it1;it1!=mp.end();++it,++it1)it1->second+=it->second;
	ans=S;s.ih();ans--;//printf("%d ",ans);
	for(int i=1;i<=n+1;i++)a[i]=mp[a[i]];
	for(int i=1;i<=n+1;i++)b[i]=mp[b[i]];
	for(int i=1;i<=n+1;i++)if(a[i]!=b[i]){ans++;s.u(a[i],b[i]);}
	if(a[n+1]!=b[n+1]){ans--;}printf("%d",ans);return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);
int main(){
  int n;cin>>n;
  double ans=0;
  for(int i=0;i<n;i++){
    double t;cin>>t;
    ans += 1.0/t;
  }
  cout<<fixed<<setprecision(7)<<1.0/ans<<endl;
}

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

int main()
{
    string S;
    int Q;
    cin >> S >> Q;

    deque<string> dq;
    bool rev = false;
    for (char c : S) {
        string tmp = "";
        tmp += c;
        dq.push_back(tmp);
    }
    rep(i, Q) {
        int t, f;
        string c;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        }
        else {
            cin >> f >> c;
            if ((f == 1) != rev) {
                dq.push_front(c);
            }
            else {
                dq.push_back(c);
            }
        }
    }
    string s;
    for (string c : dq)s += c;
    if (rev)reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


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

int main() {
    int N;
    string s, t;
    cin >> N >> s >> t;

    string ans = "";
    REP(i, 0, N) {
        if (s.substr(i) == t.substr(0, N - i)) {
            ans = s.substr(0, i) + t;
            break;
        }
    }
    if (ans == "") ans = s + t;
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N=3000005;
int n,k,a[N],p[N],h[N],cnt,d[N],tot;
struct xds
{
	int l,r,p;
}t[N];
struct qwe
{
	int ne,to;
}e[N];
int read()
{
	int r=0,f=1;
	char p=getchar();
	while(p>'9'||p<'0')
	{
		if(p=='-')
			f=-1;
		p=getchar();
	}
	while(p>='0'&&p<='9')
	{
		r=r*10+p-48;
		p=getchar();
	}
	return r*f;
}
void build(int ro,int l,int r)
{
	t[ro].l=l,t[ro].r=r,t[ro].p=n+1;
	if(l==r)
		return;
	int mid=(l+r)>>1;
	build(ro<<1,l,mid);
	build(ro<<1|1,mid+1,r);
}
void update(int ro,int p,int v)
{
	if(t[ro].l==t[ro].r)
	{
		t[ro].p=v;
		return;
	}
	int mid=(t[ro].l+t[ro].r)>>1;
	if(p<=mid)
		update(ro<<1,p,v);
	else
		update(ro<<1|1,p,v);
	t[ro].p=min(t[ro<<1].p,t[ro<<1|1].p);
}
int ques(int ro,int l,int r)
{
	if(t[ro].l==l&&t[ro].r==r)
		return t[ro].p;
	int mid=(t[ro].l+t[ro].r)>>1;
	if(r<=mid)
		return ques(ro<<1,l,r);
	else if(l>mid)
		return ques(ro<<1|1,l,r);
	else
		return min(ques(ro<<1,l,mid),ques(ro<<1|1,mid+1,r));
}
void add(int u,int v)
{//cerr<<u<<" "<<v<<endl;
	cnt++;
	e[cnt].ne=h[u];
	e[cnt].to=v;
	d[v]++;
	h[u]=cnt;
}
int main()
{
	n=read(),k=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),p[a[i]]=i;
	build(1,1,n);
	for(int i=n;i>=1;i--)
	{
		int x=ques(1,p[i],min(n,p[i]+k-1)),y=ques(1,max(1,p[i]-k+1),p[i]);
		if(x<=n)
			add(p[i],p[x]);
		if(y<=n)
			add(p[i],p[y]);
		update(1,p[i],i);
	}
	priority_queue<int,vector<int>,greater<int> >q;
	for(int i=1;i<=n;i++)
		if(!d[i])
			q.push(i);
	while(!q.empty())
	{
		int u=q.top();
		p[++tot]=u;
		q.pop();
		for(int i=h[u];i;i=e[i].ne)
			if(!(--d[e[i].to]))
				q.push(e[i].to);
	}
	for(int i=1;i<=n;i++)
		a[p[i]]=i;
	for(int i=1;i<=n;i++)
		printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 42748
#include <bits/stdc++.h>
using namespace std;
const int MAXP = 10005;

using ll = long long;

deque<char> d;
string s;
bool inv;
int q;



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> s >> q;
  for(auto c : s){
    d.push_back(c);
  }
  for(int i=0; i<q; i++){
  	int type;
    cin >> type;
    if(type == 1) inv = !inv;
    else{
      int f;
      char c;
      cin >> f >> c;
      if(inv) f = 3 - f;
      if(f == 1){
        d.push_front(c);
      }else{
        d.push_back(c);
      }
    }
  }
  if(inv){
    do cout << d.back(), d.pop_back();
    while(!d.empty());  
  }else{
    do cout << d.front(), d.pop_front();
    while(!d.empty());
  }
  return 0;
}


Measured memory_bytes: 976
def connect(blist, a):
	x = []
	for i in range(len(blist)):
		if blist[i][0]==a:
			x.append(blist[i][1])
	for j in range(len(blist)):
		if blist[j][1]==a:
			x.append(blist[j][0])
	return(x)

n,m = (int(i) for i in input().split())
y = [[int(i) for i in input().split()] for i in range(m)]
answer = m
for j in range(len(y)):
	y2,z = [],set()
	for k in range(1,n+1):
		y2.append(connect(y[:j]+y[min(j+1,len(y)):],k))
	for j2 in y2[y[j][0]-1]:
		z.add(j2)
	num = 0
	while y[j][1] not in z and len(z) != num:
		num,z2 = len(z),list(z)
		for k in z2:
			for k2 in y2[k-1]:
				z.add(k2)
	if y[j][1] in z:
		answer -= 1
print(answer)


Measured memory_bytes: 3064
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=5005;
ll f[N],res,ret;int a[N],n,A,B;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&A,&B);
	fp(i,1,n)scanf("%d",&a[i]);
	++n,a[n]=n;
	fp(i,1,n){
		f[i]=1e18,ret=0;
		fd(j,i-1,0)a[j]<a[i]?(cmin(f[i],f[j]+ret),ret+=B):ret+=A;
	}
	printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, A, B;
        cin >> N >> A >> B;
        ll ans = 0;
        rep(i, 1, N+1) {
                ll cnt = 0;
                string digits = to_string(i);
                rep(j, 0, len(digits)) {
                        cnt += digits[j] - '0';
                }
                if (A <= cnt and cnt <= B) ans += i;
        }       
        cout << ans << endl;
}

Measured memory_bytes: 256
import math
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

def countdic(n):
    cn=1
    p = 1
    for j in range(N-1):
        cn = sum(n[j]>x for x in n[j+1:len(n)])
        p +=cn*math.factorial(len(n)-1-j)
    return p
print(abs(countdic(P)-countdic(Q)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	string s = "aiueo";
	char c;
	cin >> c;
	for (auto x : s) {
		if (c == x) {
			cout << "vowel" << endl;
			return 0;
		}
	}
	cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int N,M;
	cin >> N>>M;
	string R="No";
	if (N == M) {
		R ="Yes";
	}
	cout << R << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          var s = Input.ScanStr();
          for(int i=s.Length/2-1;i>=0;i--)
            if(s.Substring(0,i) == s.Substring(i,i)) { Out(i*2); return; }
        }
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

    static class MyMath {
        public static int DistanceL1(int[] a, int[] b){
            if(a.Length != b.Length) return -1;
            int[] c = new int[a.Length];
            for(int i=0;i<a.Length;i++)
              c[i] = Math.Abs(a[i]-b[i]);
            return c.Sum();
        }

        public static double DistanceL2(int[] a, int[] b){
            if(a.Length != b.Length) return -1;
            int[] c = new int[a.Length];
            for(int i=0;i<a.Length;i++)
              c[i] = (a[i]-b[i])*(a[i]-b[i]);
            return Math.Sqrt(c.Sum());
        }
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    	int n;
    	cin >> n;
    	set<int> s;
    	for(int i = 0; i < n; i++)
    	{
    		int x;
    		cin >> x;
    		s.insert(x);
    	}
    	if(s.size() == n)
    	cout << "YES";
    	else
    	cout << "NO";
    	
    	return 0;
    }

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, k, ans;

int main() {
    cin >> n >> k;
    if (k % 2 == 0) {
        ll a = (n - k / 2) / k + (k / 2 <= n ? 1 : 0);
        ll b = n / k;
        cout << a * a * a + b * b * b << endl;
    } else {
        ll a = n / k;
        cout << a * a * a << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

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


inline int encode(const vector<string> &state) {
	const int n = state.size();

	int index;
	int res = 0;

	for(int y = 0; y < n; ++y) {
		for(int x = 0; x < n; ++x) {
			res = (res << 1) + (state[y][x] == '#' ? 1 : 0);
			if(state[y][x] == '@') {
				index = x + y * n;
			}
		}
	}

	res |= (index << (n * n));
	return res;
}

inline vector<string> decode(int code, int n) {
	vector<string> res(n, string(n, '.'));
	for(int y = n - 1; y >= 0; --y) {
		for(int x = n - 1; x >= 0; --x) {
			if(code & 1) res[y][x] = '#';
			code >>= 1;
		}
	}

	res[code / n][code % n] = '@';
	return res;
}

inline bool out(int x, int y, int n) {
	return x < 0 || y < 0 || x >= n || y >= n;
}

vector<string> update(const vector<string> &state) {
	const int n = state.size();
	vector<string> res(n, string(n, '.'));

	for(int y = 0; y < n; ++y) {
		for(int x = 0; x < n; ++x) {
			if(state[y][x] == '@') {
				res[y][x] = '@';
				continue;
			}

			int cnt = 0;
			for(int d = 0; d < 8; ++d) {
				const int nx = x + dx[d];
				const int ny = y + dy[d];

				if(!out(nx, ny, n) && state[ny][nx] != '.') ++cnt;
			}

			if(cnt == 3 || (cnt == 2 && state[y][x] == '#')) {
				res[y][x] = '#';
			}
		}
	}

	return res;
}

int bfs(const vector<string> &start) {
	const int n = start.size();
	const int s = encode(start);
	const int goal_mask = (1 << (n * n)) - 1;

	if((s & goal_mask) == 0) return 0;

	unordered_map<int, int> dist;
	queue<int> que;

	dist.insert({s, 0});
	que.push(s);

	while(!que.empty()) {
		const int code = que.front();
		que.pop();

		const int current_dist = dist[code];
		const auto state = decode(code, n);
		const int x = (code >> (n * n)) % n;
		const int y = (code >> (n * n)) / n;

		for(int d = 0; d < 8; ++d) {
			const int nx = x + dx[d];
			const int ny = y + dy[d];

			if(out(nx, ny, n) || state[ny][nx] == '#') continue;

			vector<string> next_state(state);
			swap(next_state[ny][nx], next_state[y][x]);
			next_state = update(move(next_state));
			const int next_code = encode(next_state);

			if(!dist.count(next_code)) {
				if((next_code & goal_mask) == 0) return current_dist + 1;
				dist.insert({next_code, current_dist + 1});
				que.push(next_code);
			}
		}
	}

	return -1;
}

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

	int cnt = 0;
	for(int n; cin >> n && n;) {
		vector<string> start(n);
		for(auto &e : start) cin >> e;
		cout << bfs(start) << endl;
	}

	return EXIT_SUCCESS;
}

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

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

bool isLeap(int i){
	return i % 400 == 0
			? true : i % 100 == 0
			? false : i % 4 == 0
			? true : false;
}

int getSum(int y,int m,int d,const int* month){
	int sum=0;
	for(int i=0;i<y;i++){
		sum += isLeap(i) ? 366 : 365;
	}

	for(int i=1;i<m;i++){
		sum += i != 2 ? month[i] :
			isLeap(y) ? month[i] + 1 : month[i];
	}

	sum += d;

	return sum;
}

int main(){
	const int month[] = {-1,31,28,31,30,31,30,31,31,30,31,30,31};
	int y1, m1, d1, y2, m2, d2;
	while(~scanf("%d %d %d %d %d %d",&y1, &m1, &d1, &y2, &m2, &d2)){
		if(y1 < 0 || m1 < 0 || d1 < 0
			|| y2 < 0 || m2 < 0 || d2 < 0) break;

		cout << abs(getSum(y1,m1,d1,month) - getSum(y2,m2,d2,month)) << endl;
	}
}

Measured memory_bytes: 3040
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	aMap := map[int]int{}
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		// fmt.Println(a)
		aMap[a]++
	}
	// pp.Print(aMap)
	var result = 0
	for _, v := range aMap {
		if v%2 == 1 {
			result++
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 8064
def main():
    A, B, C = map(int, input().split())
    K = int(input())
    if A < B < C:
        print('Yes')
        exit()
    cnt = 0
    while cnt <= K:
        if A >= B:
            B *= 2
            cnt += 1
        else:
            break

    if A < B < C and cnt <= K:
        print('Yes')
        exit()

    while cnt <= K:
        if B >= C:
            C *= 2
            cnt += 1
        else:
            break
 
    if A < B < C and cnt <= K:
        print('Yes')
        exit()
    print('No')


    

if __name__ == "__main__":
    main()

Measured memory_bytes: 61748
(let ((s (read-line)))
  (princ (if (and (char= (char s 0) #\A)
                  (= 1 (count #\C s :start 2 :end (- (length s) 1) :test #'char=))
                  (not (some #'upper-case-p (remove #\C (subseq s 1) :count 1))))
    "AC"
    "WA")))

Measured memory_bytes: 7396
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int power(int i){
    int a;
    for(a=1;a<=i;a++){
        if(a*a==i){
            return 1;
        }
        else if(a*a*a==i){
            return 1;
        }
        else if(a*a*a*a==i){
            return 1;
        }
        else if(a*a*a*a*a==i){
            return 1;
        }
         else if(a*a*a*a*a*a==i){
            return 1;
        }
    }
    return -1;
}

int main(void){
    int X;
    scanf("%d",&X);
    int i,judge;
    for(i=X;i>0;i--){
        judge=power(i);
        if(judge>0){
            printf("%d",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        String ans = "No";

        for(int i= 0;i<K;i++){
            if(A >= B){
                B = 2*B;
            } else if (B >= C){
                C = 2*C;
            }
        }
        if(A < B && B < C){
            ans = "Yes";
        }

        System.out.println(ans);



    }

}




Measured memory_bytes: 35644
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function arrayOfEmptyArray(size:number){
  let arr=Array(size);
  for(let i=0;i<size;i++){
    arr[i]=[];
  }
  return arr;
}
function solve(N:number,A:number,B:number,C:number,D:number,S:string){
  if(C<D){
    return !(S.substring(A,C-1).includes("##")) &&
    !(S.substring(B,D-1).includes("##"));
  }else{
    return !(S.substring(A,C-1).includes("##")) &&
    S.substring(B-2,D+1).includes("...");
  }
}
function Main(_: NormalInput) {
  const [N,A,B,C,D]=[_.int(),_.int(),_.int(),_.int(),_.int()];
  const S=_.str();
  console.log(solve(N,A,B,C,D,S)?"Yes":"No");
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;
int main(){
    int N,K,ans=0; cin >> N >> K;
    int L[N+10];
    for(int i=0; i<N; i++){
        cin >> L[i];
    }sort(L,L+N,greater<int>());
    for(int i=0; i<K; i++){
        ans+=L[i];
}
cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
 

int main()
{
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ret = 0;
  REP(a, A + 1) REP(b, B + 1) REP(c, C + 1) {
    if (a * 500 + b * 100 + c * 50 == X) ret++;
  }
  cout << ret << endl;
}


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

int main() {
  int h, w;
  string t;
  cin >> h >> w;
  
  for (int i = 0; i < h+2; i++) {
    if (i==0||i==h+1) {
      for (int j = 0; j < w+2; j++) {
        cout << "#";
      }
      cout << endl;
    }
    else {
      cin >> t;
      cout << "#" << t << "#"<< endl;
    }
  }
}


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

int main(){
    int N; cin >> N;
    vector<pair<int, int> > red(N), blue(N);
    for(size_t i = 0; i < N; i++)
    {
        cin >> red[i].first >> red[i].second;
    }
    for(size_t i = 0; i < N; i++)
    {
        cin >> blue[i].first >> blue[i].second;
    }
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    int ret = 0;
    for(size_t i = 0; i < N; i++)
    {
        auto it = lower_bound(red.begin(), red.end(), blue[i]);
        if (it == red.begin())
            continue; // no pair
        bool found = false;
        auto max_second_it = it;
        int max_second = -1;
        while(true){
            it--;
            if ((*it).second < blue[i].second && (*it).second > max_second) {
                found = true;
                max_second = (*it).second;
                max_second_it = it;
            }

            if(it == red.begin())
                break;
        }
        if(found){
            ret++;
            red.erase(max_second_it);
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(),a.end());
  if(a.at(0) + a.at(1) == a.at(2)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
vi dp,v;
ll n;
ll fun(ll ind)
{
    if(ind==n-1)
    {
        return dp[ind]=0;
    }
    if(ind>n-1)
    {
        return LLONG_MAX;
    }
    if(dp[ind]!=-1)
    {
        return dp[ind];
    }
    ll l=LLONG_MAX,r=LLONG_MAX;
    l=abs(v[ind]-v[ind+1])+fun(ind+1);
    if(ind+2<n)
    {
        r=abs(v[ind]-v[ind+2])+fun(ind+2);
    }
    return dp[ind]=min(l,r);
}
void solve()
{
    cin>>n;
    fr(i,0,n)
    {
        ll o;
        cin>>o;
        v.pub(o);
        dp.pub(-1);
    }
    cout<<fun(0);
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
*/


Measured memory_bytes: 7996
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll  long long int
#define  inf INT_MAX
#define  minf INT_MIN
#define setbits(x) __builtin_popcountll(x)
#define pres(x,y) fixed<<setprecision(y)<<x
#define pair1 pair<long long int,long long int>
#define mp make_pair
#define mk(arr,n,type) type *arr=new type[n];
#define mod  1000000009
#define ins insert
#define w(t) long long int t;t=1; while(t--)



void solve() {

  ll n;
  cin >> n;
  vi v(n + 1), dp(n + 1);
  for (ll i = 1; i <= n; i++) {
    cin >> v[i];
  }

  dp[1] = 0;
  for (ll i = 2; i <= n; i++) {

    ll opt1 = abs(v[i] - v[i - 1]) + dp[i - 1];
    ll opt2 = (i == 2) ? inf : abs(v[i] - v[i - 2]) + dp[i - 2];
    dp[i] = min(opt1, opt2);
  }

  cout << dp[n] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  w(t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 4756
#include <stdio.h>

int partition(int[], int, int);

int A[100000], n;

int main(){
  int i, q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  q=partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i>=1) printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");

  return 0;
}


int partition(int A[], int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i=i+1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

Measured memory_bytes: 992
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int x = sc.nextInt() - 1;
		int y = sc.nextInt() - 1;
		int[][] min = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (j <= x) {
					min[i][j] = j - i;
				} else if (i <= x && j <= y) {
					min[i][j] = Math.min(j - i, x - i + 1 + y - j);
				} else if (i <= x && j > y) {
					min[i][j] = x - i + 1 + j - y;
				} else if (i > x && j <= y) {
					min[i][j] = Math.min(j - i, i - x + 1 + y - j);
				} else if (i > x && i <= y && j > y) {
					min[i][j] = Math.min(j - i, i - x + 1 + j - y);
				} else if (i > y) {
					min[i][j] = j - i;
				} else {
					assert false;
				}
			}
		}
		int[] ans = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ans[min[i][j]]++;
			}
		}
		for (int i = 1; i < n; i++) {
			System.out.println(ans[i]);
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 54484
n, m = map(int, input().split())
a = [list(map(int, input().split())) for x in range(m)]
field = [0 for x in range(n + 2)]
cfield = field[:]

for a1, a2 in a:
    field[a1] += 1
    field[a2] -= 1

for i in range(1, n):
    cfield[i] = field[i] + cfield[i - 1]
    if cfield[i] & 1:
        print("NO")
        break
else:
    print("YES")



Measured memory_bytes: 30888
#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];
  vector<int>dp(n,0);
  if(n>1)
    dp[1]=abs(a[0]-a[1]);
  for(int i=2;i<n;i++)
    dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    
  cout<<dp[n-1];
}

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

using namespace std;
typedef long long ll;
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)

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

	vector<ll> animal(N); // 0:- 1:S(本) 2:W(噓)
	ll x[4]={1,2,1,2},y[4]={1,1,2,2};
	rep(k,4){
		rep(j,N) animal[j]=0;
		animal[0]=x[k];
		animal[1]=y[k];

		//調査
		rep1(i,N-2){
			if((s[i]=='o' && animal[i]==1) || (s[i]=='x' && animal[i]==2)){
				animal[i+1]=animal[i-1];
			}
			else{
				animal[i+1]=((animal[i-1]-1)^1)+1;
			}
		}

		// 0とN-1の証言正しいか
		// 0
		if((animal[0]==1 && s[0]=='o') || (animal[0]==2 && s[0]=='x')){
			if(animal[1]!=animal[N-1]) continue;
		}
		else{
			if(animal[1]==animal[N-1]) continue;
		}

		// N-1
		if((animal[N-1]==1 && s[N-1]=='o') || (animal[N-1]==2 && s[N-1]=='x')){
			if(animal[0]!=animal[N-2]) continue;
		}
		else{
			if(animal[0]==animal[N-2]) continue;
		}

		rep(i,N){
			if(animal[i]==1) cout<<"S";
			else cout<<"W";
		}
		return 0;
	}
	cout<<-1;
}

Measured memory_bytes: 1408