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

using namespace std;

int main()
{
    std::string n;
    cin >> n;
    /*
    int a[n];
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }
    */
    if(n =="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <deque>

using namespace std;

#define ll long long

int main(void){
    deque<char> s;
    string tmp;
    cin >> tmp;
    for(int i = 0;i < tmp.size();++i){
        s.push_back(tmp[i]);
    }

    int q;
    cin >> q;
    int t, f;
    char c;
    int back_flag = 0;
    for(int i = 0;i < q;++i){
        cin >> t;
        if(t == 1){
            back_flag = back_flag ^ 1;
        }else{
            cin >> f >> c;
            if(f == 1){
                if(back_flag == 1){
                    s.push_back(c);
                }else{
                    s.push_front(c);
                }
            }else{
                if(back_flag == 1){
                    s.push_front(c);
                }else{
                    s.push_back(c);
                }
            }
        }
    }

    if(back_flag == 1){
        for(auto ite = s.rbegin();ite != s.rend(); ite++){
            cout << *ite;
        }
        cout << endl;
    }else{
        for(auto ite = s.begin(); ite != s.end(); ite++){
            cout << *ite;
        }
        cout << endl;
    }



    return 0;
}

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


def main():
    A = int(input())
    B = int(input())
    if 1 != A and 1 != B:
        print(1)
    if 2 != A and 2 != B:
        print(2)
    if 3 != A and 3 != B:
        print(3)



if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,K;
int cur[20],a[20][20];
int res=1e9;
int t[20];
int main()
{
	cin >>n>>m>>K;
	for (int i=0;i<n;i++)
	{
		cin >>cur[i];
		for (int j=0;j<m;j++) cin >>a[i][j];
	} 
	for (int i=0;i<(1<<n);i++)
	{
		memset(t,0,sizeof(t));
		int sum=0;
		for (int j=0;j<n;j++)
		{
			if (!(i & (1<<j))) continue;
			for (int k=0;k<m;k++) t[k]+=a[j][k];
			sum+=cur[j];
		}
		if (*min_element(t,t+m)>=K) res=min(res,sum); 
	}
	cout <<(res==1e9 ? -1 : res);
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#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 Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int ans = 0;
    vector<vector<int>> s(n);
    rep(i,m){
        int k;
        cin >> k;
        rep(j,k){
            int a;
            cin >> a; a--;
            s[a].emplace_back(i);
        }
    }
    vector<int> p(m);
    rep(i,m) cin >> p[i];
    rep(bit,(1<<n)){
        vector<int> onf(m,0);
        rep(i,n){
            if(bit&(1<<i)){
                rep(j,s[i].size()){
                    onf[s[i][j]]++;
                }
            }
        }
        int flag = 0;
        rep(i,m){
            if(onf[i]%2==p[i]) flag++;
        }
        if(flag==m) ans++;
    }
    cout << ans << endl; 
}

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

int main() {
  long n, k;
  cin >> n >> k;
  long ans = 0;
  
  vector<long> h(n+1);
  for(int i=1; i<n+1; i++){
    cin >> h.at(i);
    if(h.at(i)>=k) ans++;
  }
  
  cout << ans <<endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n % 10 == 7 || (n % 100)/10 == 7 || (n % 1000)/100 == 7)
    cout << "Yes";
  else
	cout << "No";
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;


const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int N = 2e5 + 5;
int ara[N], rec1[N], rec2[N];


int k[N], l[N], r[N];

vector<int>lt[N], rt[N];


int main() {
    fastio;
    
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;

		for(int i =1; i <=n ; i++ ) lt[i].clear(), rt[i].clear();

        ll ans = 0;

        for(int i =1 ; i <= n ; i++ ) {
            cin>>k[i]>>l[i]>>r[i];
            int mn = min(l[i], r[i]);
			ans += mn;
			l[i] -= mn;
			r[i] -= mn;

			if(k[i] == n) ans += l[i];
            else if(l[i]) lt[ k[i] ].push_back(l[i]);
            else rt[ n - k[i] ].push_back(r[i]);
        }
		// cout<<ans<<'\n';

		priority_queue<int, vector<int>, greater<int> >pq1, pq2;

        int baki1 = 0, baki2 = 0;

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

            baki1++;
            baki2++;

            sort(lt[i].rbegin(), lt[i].rend());
            sort(rt[i].rbegin(), rt[i].rend());

            for(auto x : lt[i]) {
				if(baki1) {
					pq1.push(x);
					baki1--;
				}
				else if(x > pq1.top() ) {
					pq1.pop();
					pq1.push(x);
				}
			}

            for(auto x : rt[i]) {
				if(baki2) {
					pq2.push(x);
					baki2--;
				}
				else if(x > pq2.top() ) {
					pq2.pop();
					pq2.push(x);
				}
			}          
        }

		while(!pq1.empty()) {
			// cout<<pq1.top()<<'\n';
			ans += pq1.top();
			pq1.pop();
		}
		// cout<<'\n';
		while(!pq2.empty()) {
			// cout<<pq2.top()<<'\n';
			ans += pq2.top();
			pq2.pop();
		}

        cout<<ans<<'\n';
    }
    return 0;
}


Measured memory_bytes: 20600
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  vector<pair<int,int>> p(n);
  rep(i,n){
    int a;cin >> a;
    p[i] = {a,i+1};
  }
  sort(p.begin(), p.end());
  rep(i,n) cout << p[i].second << " ";
  cout  << "\n";
  return 0;
}


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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

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

	LL count = 0;
	REP(i, N) {
		set<char> cs;
		cs.insert(A[i]);
		cs.insert(B[i]);
		cs.insert(C[i]);

		if (cs.size() == 1) {
			count += 0;
		}
		else if (cs.size() == 2) {
			count += 1;
		}
		else if (cs.size() == 3) {
			count += 2;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> b(n-1); for(int i = 0; i < n-1; ++i) cin >> b[i];
    int sum = 0;
    for(int i = 0;i < n; ++i){
        if(i == 0) sum += b[0];
        else if(i == n-1) sum += b[n-2];
        else {
            sum += min(b[i],b[i-1]);
        }
    }
    cout << sum << endl;
    return 0;
}

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

#define INF 1000000000000000
#define MAX_V 100000

struct edge {
    long long to;
    long long cost;
};

// <最短距離, 頂点の番号>
using P = pair<long long, long long>;

long long V;
vector<edge> G[MAX_V +1];
long long d[MAX_V +1];

void dijkstra(long long s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V+1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first) continue;
        //if prim,
        //d[v] = -d[v];
        //for keep tree
        for (long long i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<edge> GG[MAX_V +1];
long long dd[MAX_V +1];

void dijkstradijkstra(long long s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(dd, dd+V+1, INF);
    dd[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (dd[v] < p.first) continue;
        //if prim,
        //d[v] = -d[v];
        //for keep tree
        for (long long i=0; i<GG[v].size(); ++i) {
            edge e = GG[v][i];
            if (dd[e.to] > dd[v] + e.cost) {
                dd[e.to] = dd[v] + e.cost;
                que.push(P(dd[e.to], e.to));
            }
        }
    }
}

int main(){
    //input
    long long n,m,s,t;
    cin >> n >> m >> s >> t;
    V=n;
    long long u,v,a,b;
    long long i;
    for(i=1; i<=m; i++){
        cin >> u >> v >> a >> b;
        edge e1={v,a};
        G[u].push_back(e1);
        edge e2={u,a};
        G[v].push_back(e2);
        edge e3={v,b};
        GG[u].push_back(e3);
        edge e4={u,b};
        GG[v].push_back(e4);
    }
    
    //calc
    long long costmin[V+1];
    dijkstra(s);
    dijkstradijkstra(t);
    costmin[V]=d[V]+dd[V];
    for(i=V-1; i>=1; i--){
        costmin[i]=min(costmin[i+1],d[i]+dd[i]);
    }

    //output
    for(i=1; i<=V; i++){
        cout << (long long)INF-costmin[i] << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 21128
#include <iostream> // cout, endl, cin
#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
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

ll H, W;
char maze[25][25];
ll dist[25][25];
const ll dx[4] = { 1,0,0,-1 };
const ll dy[4] = { 0,1,-1,0 };
ll sx, sy;

ll bfs() {
    queue<P> que;
    rep(i, H)
        rep(j, W)dist[i][j] = INF;
    que.push(P(sx, sy));
    dist[sx][sy] = 0;
    ll res = 0;
    while (que.size()) {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            ll dh = p.first + dx[i];
            ll dw = p.second + dy[i];
            if (dh < 0 || dw < 0 || dh >= H || dw >= W)continue;
            if (dist[dh][dw] == INF && maze[dh][dw] != '#') {
                que.push(P(dh, dw));
                dist[dh][dw] = dist[p.first][p.second] + 1;
                res = max(res, dist[dh][dw]);
            }
        }
    }
    return res;
}

int main() {
    cin >> H >> W;
    rep(i, H)
        rep(j, W)cin >> maze[i][j];
    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (maze[i][j] != '#') {
                sx = i; sy = j;
                ll cnt = bfs();
                ans = max(ans, cnt);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(0,H):
            for j in range(0,W):
                print("#",end="") if (i+j) % 2 == 0 else print(".",end="")
            print()
    print()


Measured memory_bytes: 7008
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.func(self.stage[i][j], self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func)
  self.func = func
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = {0, 0} end
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = {0, 0}
    end
  end
end
SegTree.setValue = function(self, idx, value)
  self.stage[self.stagenum][idx][1] = value
  self.stage[self.stagenum][idx][2] = value
end
SegTree.right_bound = function(self, val, left, right)
  local ret, retpos = {0, 0}, left - 1
  local stage, l, r = 1, left, right
  local stagenum = self.stagenum
  local tmp = {0, 0}
  while true do
    local sz = bls(1, stagenum - stage)
    while (l - 1) % sz ~= 0 or r + 1 - l < sz do
      stage = stage + 1
      sz = bls(1, stagenum - stage)
    end
    tmp[1], tmp[2] = ret[1], ret[2]
    self.func(tmp, ret, self.stage[stage][mce(l / sz)])
    if tmp[1] - tmp[2] < val then
      retpos = l + sz - 1
      ret[1], ret[2] = tmp[1], tmp[2]
      if retpos == right then break end
      if l + sz <= r then stage, l, r = 1, l + sz, r
      else break end
    else
      if sz ~= 1 then stage, l, r = stage + 1, l, l + sz - 2
      else break end
    end
  end
  return retpos + 1
end
SegTree.new = function(n, func)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func)
  return obj
end

local n = io.read("*n")
local xor = bit.bxor
local function merge(dst, a, b)
  dst[1] = a[1] + b[1]
  dst[2] = xor(a[2], b[2])
end
local st = SegTree.new(n, merge)
for i = 1, n do
  local a = io.read("*n")
  st:setValue(i, a)
end
st:updateAll()
local ret = 0
for i = 1, n do
  local rpos = st:right_bound(1, i, n)
  ret = ret + rpos - i
end
print(ret)


Measured memory_bytes: 57576
HW = input().split()
H = int(HW[0])
W = int(HW[1])

while H != 0 or W != 0:
    str1 = ["."]
    str2 = ["#"]
    for j in range(W):
        if j%2 == 0:
            str1.append("#")
            str2.append(".")
        else:
            str1.append(".")
            str2.append("#")
    for i in range(H):
        if i%2 == 0:
            for k in range(W):
                print(str2[k], end = "")
        else:
            for k in range(W):
                print(str1[k], end = "")
        print("")  
    HW = input().split()
    H = int(HW[0])
    W = int(HW[1])
    print("")

Measured memory_bytes: 9116
# ABC081B - Shift only
from functools import reduce
from operator import or_


def main():
    # bitwise or of sequenc -> find least 1-bit
    _ = input()
    A = reduce(or_, map(int, input().rstrip().split()))
    ans = bin(A)[::-1].find("1")
    print(ans)


if __name__ == "__main__":
    main()

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

int n,m,k;
int a[200005],b[200005];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long tot=0;
    for(int i=1;i<=m;i++){
        cin>>b[i];
        tot+=b[i];
    }
    int ans=0;
    for(int ia=0,ib=m;ia<=n;ia++){
        tot+=a[ia];
        while(tot>k&&ib>0)tot-=b[ib--];
        if(tot>k)break;
        ans=max(ans,ia+ib);
    }
    cout<<ans<<endl;

return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b,c,d; cin>>n>>a>>b>>c>>d;
  string s; cin>>s;
  a--,b--,c--,d--;
  if(b<c && c<d){
    irep(i,a,d){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
  }else if(b<d&&d<c){
    irep(i,a,c){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout<<"No"<<endl;
        return 0;
      }
    }
    irep(i,b,d+1){
      if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
    cout<<"No"<<endl;
  }else{
    irep(i,a,c){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout<<"No"<<endl;
        return 0;
      }
    }
    irep(i,b,d){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
  }

  
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int h,w;
    cin>>h>>w;

    vector<string> s(h);
    vector<vector<int> > dp(h, vector<int>(w, INT_MAX));

    for(int i = 0; i < h; i++) {
        cin>>s[i];
    }

    if(s[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(i == 0 && j == 0) continue;

            if(i > 0) {
                dp[i][j] = min(dp[i][j], dp[i-1][j] + ((s[i-1][j] == '.') && (s[i][j] == '#')));
            }

            if(j > 0) {
                dp[i][j] = min(dp[i][j], dp[i][j-1] + ((s[i][j-1] == '.') && (s[i][j] == '#')));
            }
        }
    }

    cout<<dp[h-1][w-1]<<endl;

}


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

s = input()
n = len(s)
ind = n-1
cnt = 0
res = 0
f = False
while ind >= 0:
    if ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C'):
        f = True
        cnt += 1
        ind -= 2
    elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
    else:
        f = False
        cnt = 0
        ind -= 1
print(res)


Measured memory_bytes: 10604
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
vector<int> a[N];
int sz[N];
deque<int> d[N], e[N];
int inv2;

int64 power_mod(int64 a, int n) {
  int64 ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * a % MOD;
    a = a * a % MOD;
  }
  return ret;
}

int64 inv_mod(int64 a) {
  return power_mod(a, MOD - 2);
}

int D[N];
void DFS(int u) {
  int w = -1;
  sz[u] = 1;
  for (auto& v : a[u]) {
    DFS(v);
    sz[u] += sz[v];
    if (w < 0 || d[v].size() > d[w].size()) {
      w = v;
    }
  }
  if (w < 0) {
    d[u] = e[u] = {inv2};
    return;
  }
  int len = 1;
  for (int i = 0; ; ++i) {
    int cnt = 0;
    int prod = 1;
    for (auto& v : a[u]) {
      if (e[v].size() <= i) continue;
      prod = (int64)prod * e[v][i] % MOD;
      ++cnt;
    }
    if (cnt <= 1) break;
    D[len] = 0;
    for (auto& v : a[u]) {
      if (e[v].size() <= i) continue;
      D[len] += prod * inv_mod(e[v][i]) % MOD * d[v][i] % MOD;
      D[len] %= MOD;
    }
    ++len;
  }
  d[u] = std::move(d[w]);
  e[u] = std::move(e[w]);
  d[u].push_front(inv2);
  e[u].push_front(inv2);
  for (int i = 1; i < len; ++i) {
    d[u][i] = D[i];
    e[u][i] = (1 + MOD - D[i]) % MOD;
  }
}

int main() {
  inv2 = inv_mod(2LL);
  int n;
  scanf("%d", &n);
  ++n;
  for (int i = 1; i < n; ++i) {
    int j;
    scanf("%d", &j);
    a[j].push_back(i);
  }
  DFS(0);
  int ret = 0;
  for (int i = 0; i < d[0].size(); ++i) {
    ret = (ret + d[0][i]) % MOD;
  }
  printf("%d\n", (int64)ret * power_mod(2, sz[0]) % MOD);
  return 0;
}


Measured memory_bytes: 481528
N = int(input())
S = list(input())
T = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
t = len(T)
n = len(S)
S2 = []
for i in range(n):
  for j in range(t):
    if S[i] == T[j]:
      a = T[(j+N)%t]
      S2.append(a)
      break
k = S2[0]
for i in range(1,n):
  k += S2[i]
print(k)


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node
{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k)
{
    while (u != NIL && k != u->key)
    {
        if (k < u->key)
        {
            u = u->left;
        }
        else
        {
            u = u->right;
        }
    }
    return u;
}

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL)
    {
        root = z;
    }
    else
    {
        if (z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

void inorder(Node *u)
{
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main()
{
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        cin >> com;
        if ( com[0] == 'f')
        {
            scanf("%d", &x);
            Node *t = find(root, x);
            if (t != NIL)
            {
                printf("yes\n");
            }
            else
            {
                printf("no\n");
            }
        }
        else if (com == "insert")
        {
            scanf("%d", &x);
            insert(x);
        }
        else if (com == "print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 21948
#include<stdio.h>
#include<algorithm>
#include<functional>

using namespace std;
int main()
{
    int p[10];
    int i;
    for(i=0;i<10;i++)
        scanf("%d",&p[i]);

        sort(p,p+10,greater<int>());

        for(i=0;i<3;i++)

        printf("%d\n",p[i]);
        return 0;

}

Measured memory_bytes: 1044
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
d = [0] * n
for i in range(m):
    a, b = na()
    d[a - 1] += 1
    d[b - 1] += 1
for i in range(n):
    print(d[i])

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
#define pb push_back
#define mp make_pair
#define endl "\n"
#define mem(x) memset(x, -1, sizeof(x))
const int MOD = 1e9+7;

template <typename T>
void print(T AA[], int nn){for(int ii=0; ii<nn; ii+=1){cout<<AA[ii]<<" ";}cout<<endl;}
template <typename T> inline void print(T nn){ cout << nn << endl;}
/* ----------------------------------------------------------------------------------- */

const int N = 3005;
int A[N], n, cache[N][N][2];

int fn(int i, int j, int turn){
    if(i>j) return 0;
    int &ans = cache[i][j][turn];
    if(ans!=-1) return ans;
    if(turn == 0){
        ans = max(A[i]+fn(i+1, j, 1), A[j]+fn(i, j-1, 1));
    }
    else{
        ans = min(-A[i]+fn(i+1, j, 0), -A[j]+fn(i, j-1, 0));
    }
    return ans;
}


int32_t main(){

    IOS

    mem(cache);
    cin >> n;
    for(int i=0; i<n; i+=1) cin >> A[i];
    print(fn(0, n-1,0));

    return 0;
}

Measured memory_bytes: 141568
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
	cpp();
	ll n, k;
	cin >> n >> k;
	vector<ll> v(n);
	for (ll i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<ll> dp(n);
	for (ll i = 1; i < n; i++) {
		ll tans = INT_MAX;
		for (ll j = 1; j <= k; j++) {
			if (i - j >= 0) {
				tans = min(tans, abs(v[i] - v[i - j]) + dp[i - j]);
			}
		}
		dp[i] = tans;
	}
	cout << dp[n - 1] << endl;
	return 0;
}







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

int main() {
    int n;
    scanf("%d", &n);
    vector<ll> a(n);
    for (ll &i: a) scanf("%lld", &i);
    vector<vector<ll>> dp(n+5, vector<ll>(n+5));
    for (int i=n-1; i>=0; i--) {
        for (int j=0; j<n; j++) {
            if (j<i) dp[i][j] = 0;
            else if (j==i) {
                if (n&1) dp[i][j] = a[i];
                else dp[i][j] = -a[i];
            } else if ((n-(j-i+1)) & 1) {
                dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j]);
                
            } else {
                dp[i][j] = max(a[i]+dp[i+1][j], a[j]+dp[i][j-1]);
            }
        }
    }

    printf("%lld\n", dp[0][n-1]);
}

Measured memory_bytes: 71040
r, c = map(int, input().split())

L = [list(map(int, input().split())) for _ in range(r)]

for i in range(r):
    tmp = 0
    for j in range(c):
        tmp += L[i][j]

    L[i].append(tmp)

for i in range(r):
    for j in range(c+1):
        print(L[i][j], end="")

        if j != c:
            print(" ", end="")

    print()

for i in range(c+1):
    tmp = 0
    for j in range(r):
        tmp += L[j][i]

    print(tmp, end="")

    if i != c:
        print(" ", end="")

print()
    



Measured memory_bytes: 6756
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define srt(a) sort(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vpulli vector <pair <ulli,ulli> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pair <int,int>> >
#define vvb vector <vector <bool> >
#define fr(i,n) for (int i = 0; i < (n); i++)
#define frbig(i,n) for (lli i = 0; i < (n); i++)
#define fra(i,a,n) for (lli i = a; i < (n); i++)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
const lli MOD = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    lli a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a>=k) cout << k;
    else if(a+b>=k) cout << a;
    else{ lli ans=a+(a+b-k); cout << ans;}
    return 0;
}

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

int N;
string s[10004];

int X, Y, Z;


int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> s[i];
	}

	for (int i = 1; i <= N; i++) {
		int num = s[i].size();
		if ((s[i][0] == 'B') && s[i][num - 1] == 'A') { X++; }
		else if (s[i][num - 1] == 'A') { Y++; }
		else if (s[i][0] == 'B') { Z++; }
	}

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int num = s[i].size();

		for (int j = 0; j + 1 <= num - 1; j++) {
			if (s[i].substr(j, 2) == "AB") { ans++; }
		}
	}

	if (X >= 2) {
		ans += X - 1;
		X = 1;
	}


	if (X > 0) { if (Y > 0) { ans++; Y--; }
	if (Z > 0) { ans++; Z--; }
	}

	ans += min(Y, Z);

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

Measured memory_bytes: 768
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	for i := 0; i <= 100; i += 4 {
		sum = i
		for j := 0; sum <= n; j += 7 {
			sum += j
			if sum == n {
				fmt.Println("Yes")
				return
			}
		}
		sum = 0
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public void BFS() { BFS(0);
	// yuh} 
	}
	
	public void BFS(int n) {
		
		boolean[] visited = new boolean[totalVertex];
		int[] distance = new int[totalVertex];
		int len = 0;
		int currParent = 0;
		
		
		LinkedList<Integer> queue = new LinkedList<Integer>();
		LinkedList<Integer> parent = new LinkedList<Integer>();
		
		
		visited[n] = true;
		queue.add(n);
		parent.add(n);

		
		while (queue.size() != 0) {
			
			n = queue.poll();
			int p = parent.poll();
			
			len = distance[n] + 1;
			
			//System.out.print("parent node: " + p + ", current parent: " + currParent + ", ");
			
			
			
			//System.out.print(n+" ");
				
			Iterator<Integer> iter = adjList.get(n).listIterator();
			while (iter.hasNext()) {
				int x = iter.next();
								
				if (!visited[x] || len < distance[x]) {
					visited[x] = true;
					distance[x] = len;
					
					queue.add(x);
					parent.add(n);
				}
			}
		}	
	
		for (int i = 0; i < totalVertex; i++) {
			if (i != 0 && distance[i] == 0) {
				distance[i] = -1;
			}
			System.out.println("" + (i + 1) + " " + distance[i]);
		}
	
	
	
	}
}






public class Main {

	
	
	
	public static void main(String[] args) {
		
		Graph g = new Graph();
		g.loadAdjList();
		g.BFS();
		
	}
	
	
}




Measured memory_bytes: 28252
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn check(a: &Vec<usize>, m: usize, k: usize) -> bool {
    let mut n = 0;
    for &item in a {
        let c = (item + m - 1) / m;
        n += c - 1;
    }
    mydbg!(n, m);
    if n <= k {
        return true;
    } else {
        return false;
    }
}

fn main() {
    use itertools_num::ItertoolsNum as _;
    input! {
       N: usize,
       K:usize,
       A:[usize;N],
    }

    let mut ans: usize = 0;
    let mut l = 0;
    let mut r = *A.iter().max().unwrap();
    while r - l > 1 {
        let m = (l + r) / 2;
        if check(&A, m, K) {
            r = m;
        } else {
            l = m;
        }
    }

    echo!(r);
}


Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string S; cin >> S;
	int an = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == '1') an++;
	}
	cout << an << endl;
}

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

const double pi=acos(-1.0);
const double eps=1e-9;
int dcmp(double x)
{
    if (x<=eps&&x>=-eps) return 0;
    return (x>0)?1:-1;
}
struct Vector
{
    double x,y;
    Vector(double X=0,double Y=0)
    {
        x=X,y=Y;
    }
};
typedef Vector Point;
Vector operator + (Vector a,Vector b) {return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector b) {return Vector(a.x-b.x,a.y-b.y);}
Vector operator * (Vector a,double b) {return Vector(a.x*b,a.y*b);}
Vector operator / (Vector a,double b) {return Vector(a.x/b,a.y/b);}

int n;
double r;
Point c,p[N];

double Dot(Vector a,Vector b)
{
    return a.x*b.x+a.y*b.y;
}
double Cross(Vector a,Vector b)
{
    return a.x*b.y-a.y*b.x;
}
double Len(Vector a)
{
    return sqrt(Dot(a,a));
}
Vector rotate(Vector a,double rad)
{
    return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
Point GLI(Point P,Vector v,Point Q,Vector w)
{
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}
Point TC(Point A,Point B,Point C)
{
    Point P=(A+B)/2,Q=(A+C)/2;
    Vector v=rotate(B-A,pi/2),w=rotate(C-A,pi/2);
    if (dcmp(Len(Cross(v,w)))==0)
    {
        if (dcmp(Len(A-B)+Len(B-C)-Len(A-C))==0)
            return (A+C)/2;
        if (dcmp(Len(A-C)+Len(B-C)+Len(A-B))==0)
            return (A+B)/2;
        if (dcmp(Len(A-B)+Len(A-C)-Len(B-C))==0)
            return (B+C)/2;
    }
    return GLI(P,v,Q,w);
}
void mcc()
{
    random_shuffle(p+1,p+n+1);
    c=p[1],r=0;
    for (int i=2;i<=n;++i)
        if (dcmp(Len(c-p[i])-r)>0)
        {
            c=p[i],r=0;
            for (int j=1;j<i;++j)
                if (dcmp(Len(c-p[j])-r)>0)
                {
                    c=(p[i]+p[j])/2,r=Len(c-p[i]);
                    for (int k=1;k<j;++k)
                        if (dcmp(Len(c-p[k])-r)>0)
                        {
                            c=TC(p[i],p[j],p[k]);
                            r=Len(c-p[i]);
                        }
                }
        }
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%lf%lf",&p[i].x,&p[i].y);
    mcc();
    printf("%lf\n",r);
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
static const int MAX = 100;
 
int main(){
    int a[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = n; i > 0; i--) {
        cout << a[i-1];
        if (i-1) cout << ' ';
        else cout << endl;
    }
    return 0;
}


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

using namespace std;

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

const int INF = 1e9;

signed main() {
    string str;
    cin>>str;
    if(str[2]==str[3] && str[4]==str[5]) {
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))

dp=['']*n

dp[0]=0
dp[1]=abs(d[1]-d[0])

for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(d[i]-d[i-1]),dp[i-2]+abs(d[i]-d[i-2]))

print(dp[n-1])

Measured memory_bytes: 89068
#include <iostream>
#include <vector>

using ll = long long;

static ll const P = 998244353;

template<typename INT, INT P>
class Modulo {
  INT val;

  friend
  std::ostream&
  operator<<(std::ostream& os, Modulo const& m) {
    return os << m.val;
  }

  friend
  bool
  operator==(Modulo<INT, P> const& a, Modulo<INT, P> const& b) {
    return a.val == b.val;
  }

  friend
  bool
  operator==(Modulo<INT, P> const& a, INT b) {
    return a.val == b;
  }

  friend
  bool
  operator==(INT a, Modulo<INT, P> const& b) {
    return a == b.val;
  }

  friend
  Modulo<INT, P>
  operator*(Modulo<INT, P> const& a, Modulo<INT, P> const& b) {
    return a.val * b.val;
  }

  friend
  Modulo<INT, P>
  operator+(Modulo<INT, P> const& a, Modulo<INT, P> const& b) {
    return a.val + b.val;
  }

  static std::vector<INT> _facts;

public:
  Modulo(INT v) : val(v % P) {};

  Modulo<INT, P>& operator+=(Modulo<INT, P> const& other) {
    val += other.val;
    val %= P;
    return *this;
  }

  static INT facts(size_t n) {
    auto s = _facts.size();
    if (s < n+1) {
      _facts.resize(n+1);
      for (size_t i=s; i<n+1; i++) {
        if (i==0) {
          _facts[0] = 1;
        } else {
          _facts[i] = (_facts[i-1] * i) % P;
        }
      }
    }
    return _facts[n];
  }
};

template<typename INT, INT P>
std::vector<INT> Modulo<INT, P>::_facts;

template <typename INT, INT P>
Modulo<INT, P>
power(INT a, INT b) {
  if (b == 0) {
    return 1;
  }

  if (b % 2 == 0) {
    auto d = power<INT, P>(a, b/2);
    return d*d;
  }

  return a * power<INT, P>(a, b-1);
}

template <typename INT, INT P>
Modulo<INT, P>
comb(INT n, INT k) {
  if (n<0 || k<0 || n<k) return 0;
  if (n==0 || k==0) return 1;

  auto a = Modulo<INT, P>::facts(n);
  auto b = Modulo<INT, P>::facts(k);
  auto c = Modulo<INT, P>::facts(n-k);

  return a * power<INT, P>(b, P-2) * power<INT, P>(c, P-2);;
}

int main() {
  ll N, A, B, K;

  std::cin >> N;
  std::cin >> A;
  std::cin >> B;
  std::cin >> K;

  Modulo<ll, P> ans(0);

  for (ll a=0; a<N+1; a++) {
    if (K >= A * a && (K - A * a) % B == 0) {
      ll b=(K - A * a) / B;
      if (b>N) continue;
      auto c=comb<ll, P>(N, a);
      auto d=comb<ll, P>(N, b);
      // std::cout << N << 'C' << a << '=' << c << std::endl;
      // std::cout << N << 'C' << b << '=' << d << std::endl;
      ans += (c*d);
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
string a;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a;
	if (a=="Sunny")
		cout<<"Cloudy";
	else if (a=="Cloudy")
		cout<<"Rainy";
	else 
		cout<<"Sunny";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    int n, m;
    cin >> n >> m;
    vector<P> p;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j, b){
            int c;
            cin >> c;
            c--;
            s += 1 << c;
        }
        p.emplace_back(s, a);
    }
    vector<ll> dp(1 << n, INF);
    dp[0] = 0;
    rep(i, 1 << n){
        rep(j, m){
            int t = (i | p[j].first);
            dp[t] = min(dp[t], dp[i] + p[j].second);
        }
    }
  	//rep(i, 1 << n)cout << dp[i] << endl;
  	if(dp[(1 << n) - 1] == INF)cout << -1 << endl;
    else cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

ll ans=1;

struct DSU {
	struct node{ int p; ll sz; };
	vector<node> dsu; int cc;
	node& operator[](int id){ return dsu[id]; }
	DSU(int n){ dsu.resize(n);
		forn(i,0,n){ cc=n; dsu[i].p=i; dsu[i].sz=1;}
	}
	int rt(int u){ return (dsu[u].p==u) ? u : dsu[u].p=rt(dsu[u].p); }
	bool sameset(int u, int v){ return rt(u)==rt(v); }
	void merge(int u, int v){
		u = rt(u); v = rt(v);
		if(u == v) return;
		if(dsu[u].sz < dsu[v].sz) swap(u,v);
		dsu[v].p = u;
		dsu[u].sz += dsu[v].sz;
		ans=max(ans, dsu[u].sz);
		cc--;
	}
	//ll get(int u){ return dsu[rt(u)].sz; }
	//void set(int u, ll val){ dsu[rt(u)].sz = val; }
};

const bool DEBUG = 0;
const int MAXN = 200005;

int n,m;
DSU dsu(0);

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>m;
	dsu=DSU(n);
	
	forn(i,0,m)
	{
		int u,v; cin>>u>>v; u--; v--;
		dsu.merge(u,v);
	}
	
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 6344